pcsc-lite  2.5.0
readers.h
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3  *
4  * Copyright (C) 2026-2026
5  * Ludovic Rousseau <ludovic.rousseau@free.fr>
6  *
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10 
11 1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products
17  derived from this software without specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
36 #ifndef __READERS_H__
37 #define __READERS_H__
38 
39 #include <inttypes.h>
40 #include <pthread.h>
41 
42 #include "ifdhandler.h"
43 #include "simclist.h"
44 
49 typedef struct pubReaderState
50 {
51  char readerName[MAX_READERNAME];
52  uint32_t eventCounter;
53  uint32_t readerState;
54  _Atomic int32_t readerSharing;
57  _Atomic uint32_t cardAtrLength;
58  uint32_t cardProtocol;
59 }
61 
62 struct FctMap_V2
63 {
64  /* shared with API 3.0 */
65  RESPONSECODE (*pvfCreateChannel)(DWORD, DWORD);
66  RESPONSECODE (*pvfCloseChannel)(DWORD);
67  RESPONSECODE (*pvfGetCapabilities)(DWORD, DWORD, PDWORD, PUCHAR);
68  RESPONSECODE (*pvfSetCapabilities)(DWORD, DWORD, DWORD, PUCHAR);
69  RESPONSECODE (*pvfSetProtocolParameters)(DWORD, DWORD, UCHAR, UCHAR,
70  UCHAR, UCHAR);
71  RESPONSECODE (*pvfPowerICC)(DWORD, DWORD, PUCHAR, PDWORD);
72  RESPONSECODE (*pvfTransmitToICC)(DWORD, SCARD_IO_HEADER, PUCHAR,
73  DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
74  RESPONSECODE (*pvfICCPresence)(DWORD);
75 
76  /* API v2.0 only */
77  RESPONSECODE (*pvfControl)(DWORD, PUCHAR, DWORD, PUCHAR, PDWORD);
78 };
79 
80 typedef struct FctMap_V2 FCT_MAP_V2;
81 
82 struct FctMap_V3
83 {
84  /* the common fields SHALL be in the same order as in FctMap_V2 */
85  RESPONSECODE (*pvfCreateChannel)(DWORD, DWORD);
86  RESPONSECODE (*pvfCloseChannel)(DWORD);
87  RESPONSECODE (*pvfGetCapabilities)(DWORD, DWORD, PDWORD, PUCHAR);
88  RESPONSECODE (*pvfSetCapabilities)(DWORD, DWORD, DWORD, PUCHAR);
89  RESPONSECODE (*pvfSetProtocolParameters)(DWORD, DWORD, UCHAR, UCHAR,
90  UCHAR, UCHAR);
91  RESPONSECODE (*pvfPowerICC)(DWORD, DWORD, PUCHAR, PDWORD);
92  RESPONSECODE (*pvfTransmitToICC)(DWORD, SCARD_IO_HEADER, PUCHAR,
93  DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
94  RESPONSECODE (*pvfICCPresence)(DWORD);
95 
96  /* API V3.0 only */
97  RESPONSECODE (*pvfControl)(DWORD, DWORD, LPCVOID, DWORD, LPVOID,
98  DWORD, LPDWORD);
99  RESPONSECODE (*pvfCreateChannelByName)(DWORD, LPSTR);
100 };
101 
102 typedef struct FctMap_V3 FCT_MAP_V3;
103 
105 {
106  char *library;
107  char *device;
108  pthread_t pthThread;
109  RESPONSECODE (*pthCardEvent)(DWORD, int);
110  pthread_mutex_t *mMutex;
111  list_t handlesList;
112  pthread_mutex_t handlesList_lock;
114  union
115  {
118  } psFunctions;
120  _Atomic LPVOID vHandle;
121  int version;
122  int port;
123  int slot;
125  _Atomic int LockCount;
126  _Atomic int32_t contexts;
127  int * pFeeds;
128  int * pMutex;
130  pthread_mutex_t powerState_lock;
131  _Atomic int reference;
134 };
135 
136 typedef struct ReaderContext READER_CONTEXT;
137 
138 #endif
list object
Definition: simclist.h:181
_Atomic LPVOID vHandle
Dlopen handle.
Definition: readers.h:120
int port
Port ID.
Definition: readers.h:122
pthread_t pthThread
Event polling thread.
Definition: readers.h:108
FCT_MAP_V2 psFunctions_v2
API V2.0.
Definition: readers.h:116
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
Definition: readers.h:56
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
Definition: readers.h:109
int slot
Current Reader Slot.
Definition: readers.h:123
union ReaderContext::@3 psFunctions
driver functions
int * pMutex
Number of client to mutex.
Definition: readers.h:128
pthread_mutex_t handlesList_lock
lock for the above list
Definition: readers.h:112
struct _SCARD_IO_HEADER SCARD_IO_HEADER
Use by SCardTransmit()
_Atomic int reference
number of users of the structure
Definition: readers.h:131
char * library
Library Path.
Definition: readers.h:106
_Atomic SCARDHANDLE hLockId
Lock Id.
Definition: readers.h:124
FCT_MAP_V3 psFunctions_v3
API V3.0.
Definition: readers.h:117
int * pFeeds
Number of shared client to lib.
Definition: readers.h:127
struct pubReaderState READER_STATE
Define an exported public reader state structure so each application gets instant notification of cha...
int version
IFD Handler version number.
Definition: readers.h:121
pthread_mutex_t * mMutex
Mutex for this connection.
Definition: readers.h:110
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
Definition: readers.h:58
READER_STATE readerState
reader state
Definition: readers.h:133
uint32_t readerState
SCARD_* bit field.
Definition: readers.h:53
_Atomic int LockCount
number of recursive locks
Definition: readers.h:125
int powerState
auto power off state
Definition: readers.h:129
LONG SCARDHANDLE
hCard returned by SCardConnect()
Definition: pcsclite.h:55
Define an exported public reader state structure so each application gets instant notification of cha...
Definition: readers.h:49
_Atomic uint32_t cardAtrLength
ATR length.
Definition: readers.h:57
_Atomic int32_t contexts
Number of open contexts.
Definition: readers.h:126
char * device
Device Name.
Definition: readers.h:107
#define MAX_ATR_SIZE
Maximum ATR size.
Definition: pcsclite.h:59
char readerName[MAX_READERNAME]
reader name
Definition: readers.h:51
pthread_mutex_t powerState_lock
powerState mutex
Definition: readers.h:130
_Atomic int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
Definition: readers.h:54
uint32_t eventCounter
number of card events
Definition: readers.h:52
Use by SCardTransmit()
Definition: ifdhandler.h:310