annotate uicc/apdu.c @ 144:429a8f80426e

fc-uicc-tool: catch record length from manual select
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Feb 2021 02:03:11 +0000
parents f691a19f191d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <pcsclite.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <winscard.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "globals.h"
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 apdu_exchange(cmd_apdu, cmd_apdu_len)
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 u_char *cmd_apdu;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 unsigned cmd_apdu_len;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 {
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 LONG rv;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 DWORD dwRecvLength;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_char *sw;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 dwRecvLength = 258;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 rv = SCardTransmit(hCard, SCARD_PCI_T0, cmd_apdu, cmd_apdu_len, NULL,
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 sim_resp_data, &dwRecvLength);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (rv != SCARD_S_SUCCESS) {
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 fprintf(stderr, "SCardTransmit: %s\n",
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 pcsc_stringify_error(rv));
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(-1);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (dwRecvLength < 2) {
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 fprintf(stderr,
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 "error: SCardTransmit response is shorter than 2 SW bytes\n");
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(-1);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 sim_resp_data_len = dwRecvLength - 2;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 sw = sim_resp_data + sim_resp_data_len;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 sim_resp_sw = (sw[0] << 8) | sw[1];
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(0);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }