xref: /reactos/dll/win32/winscard/winscard.c (revision aad80191)
1 /*
2  * Copyright 2007 Mounir IDRASSI  (mounir.idrassi@idrix.fr, for IDRIX)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "config.h"
20 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wine/debug.h"
24 #include "winscard.h"
25 #include "winternl.h"
26 
27 WINE_DEFAULT_DEBUG_CHANNEL(winscard);
28 
29 static HANDLE g_startedEvent = NULL;
30 
31 const SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
32 const SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
33 const SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };
34 
35 
36 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
37 {
38     TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
39 
40     switch (fdwReason)
41     {
42         case DLL_PROCESS_ATTACH:
43             DisableThreadLibraryCalls(hinstDLL);
44             /* FIXME: for now, we act as if the pcsc daemon is always started */
45             g_startedEvent = CreateEventA(NULL,TRUE,TRUE,NULL);
46             break;
47         case DLL_PROCESS_DETACH:
48             if (lpvReserved) break;
49             CloseHandle(g_startedEvent);
50             break;
51     }
52 
53     return TRUE;
54 }
55 
56 HANDLE WINAPI SCardAccessStartedEvent(void)
57 {
58     return g_startedEvent;
59 }
60 
61 LONG WINAPI SCardAddReaderToGroupA(SCARDCONTEXT context, LPCSTR reader, LPCSTR group)
62 {
63     LONG retval;
64     UNICODE_STRING readerW, groupW;
65 
66     if(reader) RtlCreateUnicodeStringFromAsciiz(&readerW,reader);
67     else readerW.Buffer = NULL;
68     if(group) RtlCreateUnicodeStringFromAsciiz(&groupW,group);
69     else groupW.Buffer = NULL;
70 
71     retval = SCardAddReaderToGroupW(context, readerW.Buffer, groupW.Buffer);
72 
73     RtlFreeUnicodeString(&readerW);
74     RtlFreeUnicodeString(&groupW);
75 
76     return retval;
77 }
78 
79 LONG WINAPI SCardAddReaderToGroupW(SCARDCONTEXT context, LPCWSTR reader, LPCWSTR group)
80 {
81     FIXME("%x %s %s\n", (unsigned int) context, debugstr_w(reader), debugstr_w(group));
82     return SCARD_S_SUCCESS;
83 }
84 
85 LONG WINAPI SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
86     LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
87 {
88     FIXME("(%x,%p,%p,%p) stub\n", dwScope, pvReserved1, pvReserved2, phContext);
89     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
90     return SCARD_F_INTERNAL_ERROR;
91 }
92 
93 LONG WINAPI SCardIsValidContext(SCARDCONTEXT context)
94 {
95     FIXME("(%lx) stub\n", context);
96     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
97     return SCARD_F_INTERNAL_ERROR;
98 }
99 
100 LONG WINAPI SCardListCardsA(SCARDCONTEXT hContext, LPCBYTE pbAtr, LPCGUID rgguidInterfaces, DWORD cguidInterfaceCount, LPSTR mszCards, LPDWORD pcchCards)
101 {
102     FIXME(": stub\n");
103     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
104     return SCARD_F_INTERNAL_ERROR;
105 }
106 
107 LONG WINAPI SCardReleaseContext(SCARDCONTEXT context)
108 {
109     FIXME("(%lx) stub\n", context);
110     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
111     return SCARD_F_INTERNAL_ERROR;
112 }
113 
114 LONG WINAPI SCardStatusA(SCARDHANDLE context, LPSTR szReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
115 {
116     FIXME("(%lx) stub\n", context);
117     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
118     return SCARD_F_INTERNAL_ERROR;
119 }
120 
121 LONG WINAPI SCardStatusW(SCARDHANDLE context, LPWSTR szReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState,LPDWORD pdwProtocol,LPBYTE pbAtr,LPDWORD pcbArtLen)
122 {
123     FIXME("(%lx) stub\n", context);
124     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
125     return SCARD_F_INTERNAL_ERROR;
126 }
127 
128 void WINAPI SCardReleaseStartedEvent(void)
129 {
130     FIXME("stub\n");
131 }
132 
133 LONG WINAPI SCardListReadersA(SCARDCONTEXT context, const CHAR *groups, CHAR *readers, DWORD *buflen)
134 {
135     FIXME("(%lx, %s, %p, %p) stub\n", context, debugstr_a(groups), readers, buflen);
136     return SCARD_E_NO_READERS_AVAILABLE;
137 }
138 
139 LONG WINAPI SCardListReadersW(SCARDCONTEXT context, const WCHAR *groups, WCHAR *readers, DWORD *buflen)
140 {
141     FIXME("(%lx, %s, %p, %p) stub\n", context, debugstr_w(groups), readers, buflen);
142     return SCARD_E_NO_READERS_AVAILABLE;
143 }
144