source: trunk/csctapi/ifd_azbox.c@ 3181

Last change on this file since 3181 was 3181, checked in by dingo35, 10 years ago

Adding threadsafety FIXMEs, feel free to join checking..

  • Property svn:mime-type set to text/plain
File size: 2.0 KB
Line 
1//FIXME Not checked on threadsafety yet; after checking please remove this line
2
3#include "ifd_azbox.h"
4#include"icc_async.h"
5
6int sc_mode;
7
8int _GetStatus(struct s_reader *reader, int *in)
9{
10 unsigned char tmp[512];
11 memset (tmp, 0, sizeof(tmp));
12
13 return ioctl(reader->handle, SCARD_IOC_CHECKCARD, &tmp);
14}
15
16int Azbox_Init(struct s_reader *reader)
17{
18 cs_debug("openxcas sc: init");
19
20 if ((reader->handle = openxcas_get_smartcard_device(0)) < 0) {
21 cs_debug("openxcas sc: init failed (%d)", reader->handle);
22 return FALSE;
23 }
24
25 cs_debug("openxcas sc: init succeeded");
26
27 return OK;
28}
29
30void Azbox_SetMode(int mode)
31{
32 sc_mode = mode;
33 cs_log("openxcas sc: set mode %d", sc_mode);
34}
35
36int Azbox_GetStatus(struct s_reader *reader, int *in)
37{
38 unsigned char tmp[512];
39 memset (tmp, 0, sizeof(tmp));
40
41 int status = _GetStatus(reader, in);
42
43 if (in) {
44 if (status != 1 && status != 3)
45 *in = 0;
46 else
47 *in = 1;
48
49 //cs_debug("openxcas sc: get status = %d", *in);
50 }
51
52 return OK;
53}
54
55int Azbox_Reset(struct s_reader *reader, ATR *atr)
56{
57 int status, reset = -1, mode = 0;
58 unsigned char tmp[512];
59
60 memset(tmp, 0, sizeof(tmp));
61 tmp[0] = 3;
62 tmp[1] = 1;
63
64 ioctl(reader->handle, SCARD_IOC_WARMRESET, &tmp);
65
66 cs_sleepms(500);
67
68 while ((status = _GetStatus(reader, NULL)) != 3)
69 cs_sleepms(50);
70
71 tmp[0] = 0x02;
72 tmp[1] = sc_mode;
73 status = ioctl(reader->handle, SCARD_IOC_CHECKCARD, &tmp);
74
75 memset(tmp, 0, sizeof(tmp));
76 tmp[0] = 1;
77
78 int atr_len = ioctl(reader->handle, SCARD_IOC_CHECKCARD, &tmp);
79 if (ATR_InitFromArray(atr, tmp, atr_len) != ATR_OK)
80 return FALSE;
81
82 cs_sleepms(500);
83
84 return OK;
85}
86
87int Azbox_Transmit(struct s_reader *reader, BYTE *buffer, unsigned size)
88{
89 if (write(reader->handle, buffer, size) != size)
90 return FALSE;
91
92 return OK;
93}
94
95int Azbox_Receive(struct s_reader *reader, BYTE *buffer, unsigned size)
96{
97 if (read(reader->handle, buffer, size) != size)
98 return FALSE;
99
100 return OK;
101 }
102
103int Azbox_Close(struct s_reader *reader)
104{
105 openxcas_release_smartcard_device(0);
106
107 return OK;
108}
Note: See TracBrowser for help on using the repository browser.