pcsc-lite  1.8.20
readerfactory.h
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
3  *
4  * Copyright (C) 1999
5  * David Corcoran <corcoran@musclecard.com>
6  * Copyright (C) 2002-2011
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12 
13 1. Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 2. 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.
18 3. 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 
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS 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  {
51  char *pcDevicename;
52  char *pcLibpath;
53  int channelId;
54  } SerialReader;
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  {
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  {
118  FCT_MAP_V2 psFunctions_v2;
119  FCT_MAP_V3 psFunctions_v3;
120  } psFunctions;
122  LPVOID vHandle;
123  int version;
124  int port;
125  int slot;
126  volatile SCARDHANDLE hLockId;
127  int LockCount;
128  int32_t contexts;
129  int * pFeeds;
130  int * pMutex;
132  pthread_mutex_t powerState_lock;
133  int reference;
134  pthread_mutex_t reference_lock;
137  /* we can't use READER_STATE * here since eventhandler.h can't be
138  * included because of circular dependencies */
139  };
140 
141  typedef struct ReaderContext READER_CONTEXT;
142 
143  LONG _RefReader(READER_CONTEXT * sReader);
144  LONG _UnrefReader(READER_CONTEXT * sReader);
145 
146 #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; }
147 #define UNREF_READER(reader) {Log2(PCSC_LOG_DEBUG, "UnrefReader() count was: %d", reader->reference); _UnrefReader(reader);}
148 
149  LONG RFAllocateReaderSpace(unsigned int);
150  LONG RFAddReader(const char *, int, const char *, const char *);
151  LONG RFRemoveReader(const char *, int);
152  LONG RFSetReaderName(READER_CONTEXT *, const char *, const char *, int);
153  LONG RFReaderInfo(const char *, /*@out@*/ struct ReaderContext **);
154  LONG RFReaderInfoById(SCARDHANDLE, /*@out@*/ struct ReaderContext **);
155  LONG RFCheckSharing(SCARDHANDLE, READER_CONTEXT *);
156  LONG RFLockSharing(SCARDHANDLE, READER_CONTEXT *);
157  LONG RFUnlockSharing(SCARDHANDLE, READER_CONTEXT *);
158  LONG RFUnlockAllSharing(SCARDHANDLE, READER_CONTEXT *);
159  LONG RFLoadReader(READER_CONTEXT *);
160  LONG RFBindFunctions(READER_CONTEXT *);
161  LONG RFUnBindFunctions(READER_CONTEXT *);
162  LONG RFUnloadReader(READER_CONTEXT *);
163  LONG RFInitializeReader(READER_CONTEXT *);
164  void RFUnInitializeReader(READER_CONTEXT *);
165  SCARDHANDLE RFCreateReaderHandle(READER_CONTEXT *);
166  LONG RFAddReaderHandle(READER_CONTEXT *, SCARDHANDLE);
167  LONG RFRemoveReaderHandle(READER_CONTEXT *, SCARDHANDLE);
168  void RFSetReaderEventState(READER_CONTEXT *, DWORD);
169  LONG RFCheckReaderEventState(READER_CONTEXT *, SCARDHANDLE);
170  LONG RFClearReaderEventState(READER_CONTEXT *, SCARDHANDLE);
171  LONG RFCheckReaderStatus(READER_CONTEXT *);
172  void RFCleanupReaders(void);
173  void RFWaitForReaderInit(void);
174  int RFStartSerialReaders(const char *readerconf);
175  void RFReCheckReaderConf(void);
176 
177 #endif
struct pubReaderStatesList * readerState
link to the reader state
list object
Definition: simclist.h:181
int32_t contexts
Number of open contexts.
volatile SCARDHANDLE hLockId
Lock Id.
int port
Port ID.
pthread_t pthThread
Event polling thread.
FCT_MAP_V2 psFunctions_v2
API V2.0.
DWORD dwEventStatus
Recent event that must be sent.
int slot
Current Reader Slot.
int * pMutex
Number of client to mutex.
pthread_mutex_t handlesList_lock
lock for the above list
struct _SCARD_IO_HEADER SCARD_IO_HEADER
Use by SCardTransmit()
char * library
Library Path.
char * pcLibpath
LIBPATH.
Definition: readerfactory.h:52
FCT_MAP_V3 psFunctions_v3
API V3.0.
int * pFeeds
Number of shared client to lib.
int version
IFD Handler version number.
pthread_mutex_t * mMutex
Mutex for this connection.
int powerState
auto power off state
LONG SCARDHANDLE
hCard returned by SCardConnect()
Definition: pcsclite.h:55
int LockCount
number of recursive locks
LPVOID vHandle
Dlopen handle.
This keeps a list of defines for pcsc-lite.
pthread_mutex_t reference_lock
reference mutex
Define an exported public reader state structure so each application gets instant notification of cha...
Definition: eventhandler.h:48
char * device
Device Name.
int channelId
CHANNELID.
Definition: readerfactory.h:53
char * pcDevicename
DEVICENAME.
Definition: readerfactory.h:51
int reference
number of users of the structure
pthread_mutex_t powerState_lock
powerState mutex
char * pcFriendlyname
FRIENDLYNAME.
Definition: readerfactory.h:50
Use by SCardTransmit()
Definition: ifdhandler.h:311
SCARDHANDLE hCard
hCard for this connection