comparison simtool/readcmd.c @ 91:226b231d00f3

fc-simtool: readrec command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jan 2021 18:46:11 +0000
parents 53e2c00566af
children 0ead9444a698
comparison
equal deleted inserted replaced
90:53e2c00566af 91:226b231d00f3
43 return(-1); 43 return(-1);
44 } 44 }
45 display_sim_resp_in_hex(); 45 display_sim_resp_in_hex();
46 return(0); 46 return(0);
47 } 47 }
48
49 cmd_readrec(argc, argv)
50 char **argv;
51 {
52 unsigned recno, len;
53 u_char cmd[5];
54 int rc;
55
56 recno = strtoul(argv[1], 0, 0);
57 if (recno < 1 || recno > 255) {
58 fprintf(stderr,
59 "error: record number argument is out of range\n");
60 return(-1);
61 }
62 if (argv[2]) {
63 len = strtoul(argv[2], 0, 0);
64 if (len < 1 || len > 255) {
65 fprintf(stderr,
66 "error: length argument is out of range\n");
67 return(-1);
68 }
69 } else {
70 if (!curfile_record_len) {
71 fprintf(stderr,
72 "error: no current file record length is available\n");
73 return(-1);
74 }
75 len = curfile_record_len;
76 }
77 /* READ RECORD command APDU */
78 cmd[0] = 0xA0;
79 cmd[1] = 0xB2;
80 cmd[2] = recno;
81 cmd[3] = 0x04;
82 cmd[4] = len;
83 rc = apdu_exchange(cmd, 5);
84 if (rc < 0)
85 return(rc);
86 if (sim_resp_sw != 0x9000) {
87 fprintf(stderr, "bad SW response to READ RECORD: %04X\n",
88 sim_resp_sw);
89 return(-1);
90 }
91 if (sim_resp_data_len != len) {
92 fprintf(stderr,
93 "error: READ RECORD returned %u bytes, expected %u\n",
94 sim_resp_data_len, len);
95 return(-1);
96 }
97 display_sim_resp_in_hex();
98 return(0);
99 }