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