Debian Codegraph @

PCSCperl.h

raw symbols SCIP
1 /*******************************************************************************
2 * Author : Lionel VICTOR <[email protected]>
3 * <[email protected]>
4 * Compiler : gcc, Visual C++
5 * Target : unix, Windows
6 *
7 * Description : Perl wrapper to the PCSC API
8 *
9 * Copyright (C) 2001 - Lionel VICTOR
10 * Copyright (c) 2003-2010 - Ludovic ROUSSEAU
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 * 02111-1307 USA
26 *
27 ******************************************************************************/
28
29 /******************************************************************************
30 * Contains basic definitions for a Perl wrapper to PCSC-lite. The code
31 * here is meant to be portable to most Unices. It should as well compile
32 * under Microsoft Windows without modifications.
33 * Most macros in this file help portability.
34 ******************************************************************************/
35
36 #ifndef PCSC_PERL
37 #define PCSC_PERL
38
39 #ifdef WIN32
40 # include <windows.h>
41 # include <winscard.h>
42 # define LOAD_LIB() LoadLibrary("winscard.dll")
43 # define CLOSE_LIB FreeLibrary
44 # define DLL_HANDLE HINSTANCE
45 # define GET_FCT GetProcAddress
46 /* The following defines are only set with PCSClite, we have to
47 * declare them for use under WIN32
48 */
49 # define MAX_ATR_SIZE 33
50 # define MAX_BUFFER_SIZE 264
51
52 #else /* WIN32 */
53
54 /* WIN32 entry points are called with the WINAPI convention
55 * the following hack is to handle this shit
56 */
57 #define WINAPI
58
59 #ifdef __APPLE__
60 #include <PCSC/wintypes.h>
61 #include <PCSC/winscard.h>
62 #define LPCTSTR LPCSTR
63 #include <CoreFoundation/CFBundle.h>
64 #include <CoreFoundation/CFString.h>
65 #include <CoreFoundation/CFURL.h>
66 #include <stdio.h>
67 #define DLL_HANDLE CFBundleRef
68 DLL_HANDLE LOAD_LIB()
69 { CFStringRef bundlePath;
70 CFURLRef bundleURL;
71 CFBundleRef bundle;
72
73 bundlePath = CFStringCreateWithCString(NULL,
74 "/System/Library/Frameworks/PCSC.framework",
75 kCFStringEncodingMacRoman);
76 if (bundlePath == NULL)
77 {
78 return NULL;
79 }
80 bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
81 kCFURLPOSIXPathStyle, TRUE);
82 CFRelease(bundlePath);
83 if (bundleURL == NULL)
84 {
85 return NULL;
86 }
87
88 bundle = CFBundleCreate(NULL, bundleURL);
89 CFRelease(bundleURL);
90 if (bundle == NULL)
91 {
92 return NULL;
93 }
94
95
96 if (!CFBundleLoadExecutable(bundle))
97 {
98 CFRelease(bundle);
99 return NULL;
100 }
101 return bundle;
102 }
103
104 void* GET_FCT(CFBundleRef bundle, char *fct_name)
105 {
106 CFStringRef cfName;
107 void * fct_addr=NULL;
108 cfName = CFStringCreateWithCString(NULL, fct_name,
109 kCFStringEncodingMacRoman);
110 if (cfName == NULL)
111 {
112 return NULL;
113 }
114 fct_addr = CFBundleGetFunctionPointerForName(bundle, cfName);
115 CFRelease(cfName);
116 return fct_addr;
117 }
118
119 #else
120
121 /* other Unixes */
122 # include <dlfcn.h>
123 # include <pcsclite.h>
124 # define LOAD_LIB() dlopen("libpcsclite.so.1", RTLD_LAZY)
125 # define CLOSE_LIB(x) dlclose(x)
126 # define DLL_HANDLE void*
127 # define GET_FCT dlsym
128 #define LPCTSTR LPCSTR
129 #define LPTSTR LPSTR
130
131 #endif /* __APPLE__ */
132
133 #endif /* WIN32 */
134
135 /* extended APDU supported? (pcsc-lite >= 1.3.2 only) */
136 #ifndef MAX_BUFFER_SIZE_EXTENDED
137 #define MAX_BUFFER_SIZE_EXTENDED MAX_BUFFER_SIZE
138 #endif
139
140 /* Definitine fuctions imported from the PCSC library and used by the stub */
141 typedef LONG (WINAPI *TSCardEstablishContext) ( DWORD, LPCVOID, LPCVOID, LPSCARDCONTEXT );
142 typedef LONG (WINAPI *TSCardReleaseContext) ( SCARDCONTEXT );
143 typedef LONG (WINAPI *TSCardListReaders) ( SCARDCONTEXT, LPCTSTR, LPTSTR, LPDWORD );
144 typedef LONG (WINAPI *TSCardConnect) ( SCARDCONTEXT, LPCTSTR, DWORD, DWORD, LPSCARDHANDLE, LPDWORD );
145 typedef LONG (WINAPI *TSCardReconnect) ( SCARDHANDLE, DWORD, DWORD, DWORD, LPDWORD );
146 typedef LONG (WINAPI *TSCardDisconnect) ( SCARDHANDLE, DWORD );
147 typedef LONG (WINAPI *TSCardBeginTransaction) ( SCARDHANDLE );
148 typedef LONG (WINAPI *TSCardEndTransaction) ( SCARDHANDLE, DWORD );
149 typedef LONG (WINAPI *TSCardTransmit) ( SCARDHANDLE, LPCSCARD_IO_REQUEST, LPCBYTE, DWORD, LPSCARD_IO_REQUEST, LPBYTE, LPDWORD );
150 typedef LONG (WINAPI *TSCardControl) ( SCARDHANDLE, DWORD, LPCBYTE, DWORD, LPBYTE, DWORD, LPDWORD );
151 typedef LONG (WINAPI *TSCardStatus) ( SCARDHANDLE, LPTSTR, LPDWORD, LPDWORD, LPDWORD, LPBYTE, LPDWORD );
152 typedef LONG (WINAPI *TSCardGetStatusChange) ( SCARDHANDLE, DWORD, SCARD_READERSTATE *, DWORD );
153 typedef LONG (WINAPI *TSCardCancel) ( SCARDCONTEXT );
154
155 /* these functions are not used */
156 /*
157 LONG SCardListReaderGroups( SCARDCONTEXT, LPSTR, LPDWORD );
158 */
159
160 /* Declares a variable for any imported variable */
161 /* static LPSCARD_IO_REQUEST gpioSCardT0Pci;
162 static LPSCARD_IO_REQUEST gpioSCardT1Pci;
163 static LPSCARD_IO_REQUEST gpioSCardRawPci; */
164
165 /* Declares a variable for any imported function */
166 static TSCardEstablishContext hEstablishContext = NULL;
167 static TSCardReleaseContext hReleaseContext = NULL;
168 static TSCardListReaders hListReaders = NULL;
169 static TSCardConnect hConnect = NULL;
170 static TSCardReconnect hReconnect = NULL;
171 static TSCardDisconnect hDisconnect = NULL;
172 static TSCardBeginTransaction hBeginTransaction = NULL;
173 static TSCardEndTransaction hEndTransaction = NULL;
174 static TSCardTransmit hTransmit = NULL;
175 static TSCardControl hControl = NULL;
176 static TSCardStatus hStatus = NULL;
177 static TSCardGetStatusChange hGetStatusChange = NULL;
178 static TSCardCancel hCancel = NULL;
179
180 /* Also declares some static variables */
181 static DLL_HANDLE ghDll = NULL;
182 static LONG gnLastError = SCARD_S_SUCCESS;
183
184 /* these functions are not used */
185 /*
186 TSCardListReaderGroups hListReaderGroups = NULL;
187 */
188
189 #define SCARD_P_ALREADY_CONNECTED 0x22200001
190 #define SCARD_P_NOT_CONNECTED 0x22200002
191
192 #endif
193
194 /* End of File */
195