forked from LudovicRousseau/PCSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readerfactory.h
177 lines (154 loc) · 6.87 KB
/
readerfactory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
*
* Copyright (C) 1999
* David Corcoran <[email protected]>
* Copyright (C) 2002-2011
* Ludovic Rousseau <[email protected]>
*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief This keeps track of a list of currently available reader structures.
*/
#ifndef __readerfactory_h__
#define __readerfactory_h__
#include <inttypes.h>
#include <pthread.h>
#include "ifdhandler.h"
#include "pcscd.h"
#include "simclist.h"
typedef struct
{
char *pcFriendlyname; /**< FRIENDLYNAME */
char *pcDevicename; /**< DEVICENAME */
char *pcLibpath; /**< LIBPATH */
int channelId; /**< CHANNELID */
} SerialReader;
struct FctMap_V2
{
/* shared with API 3.0 */
RESPONSECODE (*pvfCreateChannel)(DWORD, DWORD);
RESPONSECODE (*pvfCloseChannel)(DWORD);
RESPONSECODE (*pvfGetCapabilities)(DWORD, DWORD, PDWORD, PUCHAR);
RESPONSECODE (*pvfSetCapabilities)(DWORD, DWORD, DWORD, PUCHAR);
RESPONSECODE (*pvfSetProtocolParameters)(DWORD, DWORD, UCHAR, UCHAR,
UCHAR, UCHAR);
RESPONSECODE (*pvfPowerICC)(DWORD, DWORD, PUCHAR, PDWORD);
RESPONSECODE (*pvfTransmitToICC)(DWORD, SCARD_IO_HEADER, PUCHAR,
DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
RESPONSECODE (*pvfICCPresence)(DWORD);
/* API v2.0 only */
RESPONSECODE (*pvfControl)(DWORD, PUCHAR, DWORD, PUCHAR, PDWORD);
};
typedef struct FctMap_V2 FCT_MAP_V2;
struct FctMap_V3
{
/* the common fields SHALL be in the same order as in FctMap_V2 */
RESPONSECODE (*pvfCreateChannel)(DWORD, DWORD);
RESPONSECODE (*pvfCloseChannel)(DWORD);
RESPONSECODE (*pvfGetCapabilities)(DWORD, DWORD, PDWORD, PUCHAR);
RESPONSECODE (*pvfSetCapabilities)(DWORD, DWORD, DWORD, PUCHAR);
RESPONSECODE (*pvfSetProtocolParameters)(DWORD, DWORD, UCHAR, UCHAR,
UCHAR, UCHAR);
RESPONSECODE (*pvfPowerICC)(DWORD, DWORD, PUCHAR, PDWORD);
RESPONSECODE (*pvfTransmitToICC)(DWORD, SCARD_IO_HEADER, PUCHAR,
DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
RESPONSECODE (*pvfICCPresence)(DWORD);
/* API V3.0 only */
RESPONSECODE (*pvfControl)(DWORD, DWORD, LPCVOID, DWORD, LPVOID,
DWORD, LPDWORD);
RESPONSECODE (*pvfCreateChannelByName)(DWORD, LPSTR);
};
typedef struct FctMap_V3 FCT_MAP_V3;
struct RdrCliHandles
{
SCARDHANDLE hCard; /**< hCard for this connection */
DWORD dwEventStatus; /**< Recent event that must be sent */
};
typedef struct RdrCliHandles RDR_CLIHANDLES;
struct ReaderContext
{
char *library; /**< Library Path */
char *device; /**< Device Name */
pthread_t pthThread; /**< Event polling thread */
RESPONSECODE (*pthCardEvent)(DWORD, int); /**< Card Event sync */
pthread_mutex_t *mMutex; /**< Mutex for this connection */
list_t handlesList;
pthread_mutex_t handlesList_lock; /**< lock for the above list */
/**< Structure of connected handles */
union
{
FCT_MAP_V2 psFunctions_v2; /**< API V2.0 */
FCT_MAP_V3 psFunctions_v3; /**< API V3.0 */
} psFunctions; /**< driver functions */
LPVOID vHandle; /**< Dlopen handle */
int version; /**< IFD Handler version number */
int port; /**< Port ID */
int slot; /**< Current Reader Slot */
volatile SCARDHANDLE hLockId; /**< Lock Id */
int LockCount; /**< number of recursive locks */
int32_t contexts; /**< Number of open contexts */
int * pFeeds; /**< Number of shared client to lib */
int * pMutex; /**< Number of client to mutex */
int powerState; /**< auto power off state */
pthread_mutex_t powerState_lock; /**< powerState mutex */
int reference; /**< number of users of the structure */
pthread_mutex_t reference_lock; /**< reference mutex */
struct pubReaderStatesList *readerState; /**< link to the reader state */
/* we can't use READER_STATE * here since eventhandler.h can't be
* included because of circular dependencies */
};
typedef struct ReaderContext READER_CONTEXT;
LONG _RefReader(READER_CONTEXT * sReader);
LONG _UnrefReader(READER_CONTEXT * sReader);
#define REF_READER(reader) { LONG rv; Log2(PCSC_LOG_DEBUG, "RefReader() count was: %d", reader->reference); rv = _RefReader(reader); if (rv != SCARD_S_SUCCESS) return rv; }
#define UNREF_READER(reader) {Log2(PCSC_LOG_DEBUG, "UnrefReader() count was: %d", reader->reference); _UnrefReader(reader);}
LONG RFAllocateReaderSpace(unsigned int);
LONG RFAddReader(const char *, int, const char *, const char *);
LONG RFRemoveReader(const char *, int);
LONG RFSetReaderName(READER_CONTEXT *, const char *, const char *, int);
LONG RFReaderInfo(const char *, /*@out@*/ struct ReaderContext **);
LONG RFReaderInfoById(SCARDHANDLE, /*@out@*/ struct ReaderContext **);
LONG RFCheckSharing(SCARDHANDLE, READER_CONTEXT *);
LONG RFLockSharing(SCARDHANDLE, READER_CONTEXT *);
LONG RFUnlockSharing(SCARDHANDLE, READER_CONTEXT *);
LONG RFUnlockAllSharing(SCARDHANDLE, READER_CONTEXT *);
LONG RFLoadReader(READER_CONTEXT *);
LONG RFBindFunctions(READER_CONTEXT *);
LONG RFUnBindFunctions(READER_CONTEXT *);
LONG RFUnloadReader(READER_CONTEXT *);
LONG RFInitializeReader(READER_CONTEXT *);
void RFUnInitializeReader(READER_CONTEXT *);
SCARDHANDLE RFCreateReaderHandle(READER_CONTEXT *);
LONG RFAddReaderHandle(READER_CONTEXT *, SCARDHANDLE);
LONG RFRemoveReaderHandle(READER_CONTEXT *, SCARDHANDLE);
void RFSetReaderEventState(READER_CONTEXT *, DWORD);
LONG RFCheckReaderEventState(READER_CONTEXT *, SCARDHANDLE);
LONG RFClearReaderEventState(READER_CONTEXT *, SCARDHANDLE);
LONG RFCheckReaderStatus(READER_CONTEXT *);
void RFCleanupReaders(void);
void RFWaitForReaderInit(void);
int RFStartSerialReaders(const char *readerconf);
void RFReCheckReaderConf(void);
#endif