FreeCalypso > hg > fc-sim-tools
comparison simtool/getresp.c @ 10:ddd767f6e15b
fc-simtool ported over
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 14 Mar 2021 07:11:25 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 9:c9ef9e91dd8e | 10:ddd767f6e15b |
|---|---|
| 1 /* | |
| 2 * This module implements an elementary GET RESPONSE command | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <stdio.h> | |
| 7 #include <stdlib.h> | |
| 8 #include "simresp.h" | |
| 9 | |
| 10 cmd_get_response(argc, argv, outf) | |
| 11 char **argv; | |
| 12 FILE *outf; | |
| 13 { | |
| 14 u_char cmd[5]; | |
| 15 int rc; | |
| 16 unsigned len; | |
| 17 | |
| 18 len = strtoul(argv[1], 0, 0); | |
| 19 if (len < 1 || len > 256) { | |
| 20 fprintf(stderr, "error: length argument is out of range\n"); | |
| 21 return(-1); | |
| 22 } | |
| 23 /* GET RESPONSE command APDU */ | |
| 24 cmd[0] = 0xA0; | |
| 25 cmd[1] = 0xC0; | |
| 26 cmd[2] = 0; | |
| 27 cmd[3] = 0; | |
| 28 cmd[4] = len; | |
| 29 rc = apdu_exchange(cmd, 5); | |
| 30 if (rc < 0) | |
| 31 return(rc); | |
| 32 if (sim_resp_sw != 0x9000) { | |
| 33 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n", | |
| 34 sim_resp_sw); | |
| 35 return(-1); | |
| 36 } | |
| 37 display_sim_resp_in_hex(outf); | |
| 38 return(0); | |
| 39 } | |
| 40 | |
| 41 get_response_op() | |
| 42 { | |
| 43 u_char cmd[5]; | |
| 44 int rc; | |
| 45 unsigned expect_resp_len; | |
| 46 | |
| 47 expect_resp_len = sim_resp_sw & 0xFF; | |
| 48 /* GET RESPONSE command APDU */ | |
| 49 cmd[0] = 0xA0; | |
| 50 cmd[1] = 0xC0; | |
| 51 cmd[2] = 0; | |
| 52 cmd[3] = 0; | |
| 53 cmd[4] = expect_resp_len; | |
| 54 rc = apdu_exchange(cmd, 5); | |
| 55 if (rc < 0) | |
| 56 return(rc); | |
| 57 if (sim_resp_sw != 0x9000) { | |
| 58 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n", | |
| 59 sim_resp_sw); | |
| 60 return(-1); | |
| 61 } | |
| 62 if (sim_resp_data_len != expect_resp_len) { | |
| 63 fprintf(stderr, | |
| 64 "error: GET RESPONSE returned %u bytes, expected %u\n", | |
| 65 sim_resp_data_len, expect_resp_len); | |
| 66 return(-1); | |
| 67 } | |
| 68 return(0); | |
| 69 } |
