FreeCalypso > hg > fc-pcsc-tools
comparison simtool/readops.c @ 1:2071b28cd0c7
simtool: first refactored version
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 11 Feb 2021 23:04:28 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:f7145c77b7fb | 1:2071b28cd0c7 |
|---|---|
| 1 #include <sys/types.h> | |
| 2 #include <stdio.h> | |
| 3 #include <stdlib.h> | |
| 4 #include "simresp.h" | |
| 5 | |
| 6 readbin_op(offset, len) | |
| 7 unsigned offset, len; | |
| 8 { | |
| 9 u_char cmd[5]; | |
| 10 int rc; | |
| 11 | |
| 12 /* READ BINARY command APDU */ | |
| 13 cmd[0] = 0xA0; | |
| 14 cmd[1] = 0xB0; | |
| 15 cmd[2] = offset >> 8; | |
| 16 cmd[3] = offset; | |
| 17 cmd[4] = len; | |
| 18 rc = apdu_exchange(cmd, 5); | |
| 19 if (rc < 0) | |
| 20 return(rc); | |
| 21 if (sim_resp_sw != 0x9000) { | |
| 22 fprintf(stderr, "bad SW response to READ BINARY: %04X\n", | |
| 23 sim_resp_sw); | |
| 24 return(-1); | |
| 25 } | |
| 26 if (sim_resp_data_len != len) { | |
| 27 fprintf(stderr, | |
| 28 "error: READ BINARY returned %u bytes, expected %u\n", | |
| 29 sim_resp_data_len, len); | |
| 30 return(-1); | |
| 31 } | |
| 32 return(0); | |
| 33 } | |
| 34 | |
| 35 readrec_op(recno, mode, len) | |
| 36 unsigned recno, mode, len; | |
| 37 { | |
| 38 u_char cmd[5]; | |
| 39 int rc; | |
| 40 | |
| 41 /* READ RECORD command APDU */ | |
| 42 cmd[0] = 0xA0; | |
| 43 cmd[1] = 0xB2; | |
| 44 cmd[2] = recno; | |
| 45 cmd[3] = mode; | |
| 46 cmd[4] = len; | |
| 47 rc = apdu_exchange(cmd, 5); | |
| 48 if (rc < 0) | |
| 49 return(rc); | |
| 50 if (sim_resp_sw != 0x9000) { | |
| 51 fprintf(stderr, "bad SW response to READ RECORD: %04X\n", | |
| 52 sim_resp_sw); | |
| 53 return(-1); | |
| 54 } | |
| 55 if (sim_resp_data_len != len) { | |
| 56 fprintf(stderr, | |
| 57 "error: READ RECORD returned %u bytes, expected %u\n", | |
| 58 sim_resp_data_len, len); | |
| 59 return(-1); | |
| 60 } | |
| 61 return(0); | |
| 62 } |
