comparison libcommon/apdu.c @ 0:f7145c77b7fb

starting libcommon: factored out of fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 22:28:45 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f7145c77b7fb
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <pcsclite.h>
5 #include <winscard.h>
6 #include "cardif.h"
7
8 u_char sim_resp_data[258];
9 unsigned sim_resp_data_len, sim_resp_sw;
10
11 apdu_exchange(cmd_apdu, cmd_apdu_len)
12 u_char *cmd_apdu;
13 unsigned cmd_apdu_len;
14 {
15 LONG rv;
16 DWORD dwRecvLength;
17 u_char *sw;
18
19 dwRecvLength = 258;
20 rv = SCardTransmit(hCard, SCARD_PCI_T0, cmd_apdu, cmd_apdu_len, NULL,
21 sim_resp_data, &dwRecvLength);
22 if (rv != SCARD_S_SUCCESS) {
23 fprintf(stderr, "SCardTransmit: %s\n",
24 pcsc_stringify_error(rv));
25 return(-1);
26 }
27 if (dwRecvLength < 2) {
28 fprintf(stderr,
29 "error: SCardTransmit response is shorter than 2 SW bytes\n");
30 return(-1);
31 }
32 sim_resp_data_len = dwRecvLength - 2;
33 sw = sim_resp_data + sim_resp_data_len;
34 sim_resp_sw = (sw[0] << 8) | sw[1];
35 return(0);
36 }