FreeCalypso > hg > freecalypso-hwlab
comparison simtool/readcmd.c @ 90:53e2c00566af
fc-simtool: readbin command implemented
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 24 Jan 2021 18:18:04 +0000 |
| parents | |
| children | 226b231d00f3 |
comparison
equal
deleted
inserted
replaced
| 89:fb75855a74a9 | 90:53e2c00566af |
|---|---|
| 1 #include <sys/types.h> | |
| 2 #include <stdio.h> | |
| 3 #include <stdlib.h> | |
| 4 #include <pcsclite.h> | |
| 5 #include <winscard.h> | |
| 6 #include "globals.h" | |
| 7 | |
| 8 cmd_readbin(argc, argv) | |
| 9 char **argv; | |
| 10 { | |
| 11 unsigned offset, len; | |
| 12 u_char cmd[5]; | |
| 13 int rc; | |
| 14 | |
| 15 offset = strtoul(argv[1], 0, 0); | |
| 16 if (offset > 0xFFFF) { | |
| 17 fprintf(stderr, "error: offset argument is out of range\n"); | |
| 18 return(-1); | |
| 19 } | |
| 20 len = strtoul(argv[2], 0, 0); | |
| 21 if (len < 1 || len > 256) { | |
| 22 fprintf(stderr, "error: length argument is out of range\n"); | |
| 23 return(-1); | |
| 24 } | |
| 25 /* READ BINARY command APDU */ | |
| 26 cmd[0] = 0xA0; | |
| 27 cmd[1] = 0xB0; | |
| 28 cmd[2] = offset >> 8; | |
| 29 cmd[3] = offset; | |
| 30 cmd[4] = len; | |
| 31 rc = apdu_exchange(cmd, 5); | |
| 32 if (rc < 0) | |
| 33 return(rc); | |
| 34 if (sim_resp_sw != 0x9000) { | |
| 35 fprintf(stderr, "bad SW response to READ BINARY: %04X\n", | |
| 36 sim_resp_sw); | |
| 37 return(-1); | |
| 38 } | |
| 39 if (sim_resp_data_len != len) { | |
| 40 fprintf(stderr, | |
| 41 "error: READ BINARY returned %u bytes, expected %u\n", | |
| 42 sim_resp_data_len, len); | |
| 43 return(-1); | |
| 44 } | |
| 45 display_sim_resp_in_hex(); | |
| 46 return(0); | |
| 47 } |
