FreeCalypso > hg > fc-sim-tools
annotate libcommon/apducmd.c @ 72:5f7377392211
doc/GrcardSIM1-notes article written
| author | Mychaela Falconia <falcon@freecalypso.org> | 
|---|---|
| date | Wed, 07 Apr 2021 05:18:17 +0000 | 
| parents | bccf028921bb | 
| children | 
| rev | line source | 
|---|---|
| 9 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 1 /* | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 2 * This module implements a low-level debug command | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 3 * for users to manually send arbitrary APDUs. | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 4 */ | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 5 | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 6 #include <sys/types.h> | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 7 #include <stdio.h> | 
| 57 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 8 #include <stdlib.h> | 
| 9 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 9 #include "simresp.h" | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 10 | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 11 cmd_apdu(argc, argv) | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 12 char **argv; | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 13 { | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 14 u_char cmd[260]; | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 15 int rc; | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 16 unsigned len; | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 17 | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 18 rc = decode_hex_data_from_string(argv[1], cmd, 5, 260); | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 19 if (rc < 0) | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 20 return(rc); | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 21 len = rc; | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 22 rc = apdu_exchange(cmd, len); | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 23 if (rc < 0) | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 24 return(rc); | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 25 printf("%04X\n", sim_resp_sw); | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 26 return(0); | 
| 
c9ef9e91dd8e
new libcommon, initial version
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 27 } | 
| 57 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 28 | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 29 cmd_apdu_checksw(argc, argv) | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 30 char **argv; | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 31 { | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 32 u_char cmd[260]; | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 33 int rc; | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 34 unsigned len, expect_sw; | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 35 | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 36 rc = decode_hex_data_from_string(argv[1], cmd, 5, 260); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 37 if (rc < 0) | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 38 return(rc); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 39 len = rc; | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 40 expect_sw = strtoul(argv[2], 0, 16); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 41 rc = apdu_exchange(cmd, len); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 42 if (rc < 0) | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 43 return(rc); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 44 if (sim_resp_sw == expect_sw) | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 45 return(0); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 46 else { | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 47 fprintf(stderr, | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 48 "SW response mismatch: expected %04X, got %04X\n", | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 49 expect_sw, sim_resp_sw); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 50 return(-1); | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 51 } | 
| 
bccf028921bb
apdu-checksw command added to both fc-simtool and fc-uicc-tool
 Mychaela Falconia <falcon@freecalypso.org> parents: 
9diff
changeset | 52 } | 
