source: trunk/csctapi/ifd_azbox.c@ 4149

Last change on this file since 4149 was 4149, checked in by dingo35, 13 years ago

checked some routines on threadsafety

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