xref: /reactos/dll/win32/winscard/winscard.c (revision 84ccccab)
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 <precomp.h>
20 
21 #include <winternl.h>
22 
23 static HANDLE g_startedEvent = NULL;
24 
25 const SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
26 const SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
27 const SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };
28 
29 
30 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
31 {
32     TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
33 
34     switch (fdwReason)
35     {
36         case DLL_PROCESS_ATTACH:
37             DisableThreadLibraryCalls(hinstDLL);
38             /* FIXME: for now, we act as if the pcsc daemon is always started */
39             g_startedEvent = CreateEventA(NULL,TRUE,TRUE,NULL);
40             break;
41         case DLL_PROCESS_DETACH:
42             if (lpvReserved) break;
43             CloseHandle(g_startedEvent);
44             break;
45     }
46 
47     return TRUE;
48 }
49 
50 HANDLE WINAPI SCardAccessStartedEvent(void)
51 {
52     return g_startedEvent;
53 }
54 
55 LONG WINAPI SCardAddReaderToGroupA(SCARDCONTEXT context, LPCSTR reader, LPCSTR group)
56 {
57     LONG retval;
58     UNICODE_STRING readerW, groupW;
59 
60     if(reader) RtlCreateUnicodeStringFromAsciiz(&readerW,reader);
61     else readerW.Buffer = NULL;
62     if(group) RtlCreateUnicodeStringFromAsciiz(&groupW,group);
63     else groupW.Buffer = NULL;
64 
65     retval = SCardAddReaderToGroupW(context, readerW.Buffer, groupW.Buffer);
66 
67     RtlFreeUnicodeString(&readerW);
68     RtlFreeUnicodeString(&groupW);
69 
70     return retval;
71 }
72 
73 LONG WINAPI SCardAddReaderToGroupW(SCARDCONTEXT context, LPCWSTR reader, LPCWSTR group)
74 {
75     FIXME("%x %s %s\n", (unsigned int) context, debugstr_w(reader), debugstr_w(group));
76     return SCARD_S_SUCCESS;
77 }
78 
79 LONG WINAPI SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
80     LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
81 {
82     FIXME("(%x,%p,%p,%p) stub\n", dwScope, pvReserved1, pvReserved2, phContext);
83     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
84     return SCARD_F_INTERNAL_ERROR;
85 }
86 
87 LONG WINAPI SCardIsValidContext(SCARDCONTEXT context)
88 {
89     FIXME("(%lx) stub\n", context);
90     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
91     return SCARD_F_INTERNAL_ERROR;
92 }
93 
94 LONG WINAPI SCardListCardsA(SCARDCONTEXT hContext, LPCBYTE pbAtr, LPCGUID rgguidInterfaces, DWORD cguidInterfaceCount, LPSTR mszCards, LPDWORD pcchCards)
95 {
96     FIXME(": stub\n");
97     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
98     return SCARD_F_INTERNAL_ERROR;
99 }
100 
101 LONG WINAPI SCardReleaseContext(SCARDCONTEXT context)
102 {
103     FIXME("(%lx) stub\n", context);
104     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
105     return SCARD_F_INTERNAL_ERROR;
106 }
107 
108 LONG WINAPI SCardStatusA(SCARDHANDLE context, LPSTR szReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
109 {
110     FIXME("(%lx) stub\n", context);
111     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
112     return SCARD_F_INTERNAL_ERROR;
113 }
114 
115 LONG WINAPI SCardStatusW(SCARDHANDLE context, LPWSTR szReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState,LPDWORD pdwProtocol,LPBYTE pbAtr,LPDWORD pcbArtLen)
116 {
117     FIXME("(%lx) stub\n", context);
118     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
119     return SCARD_F_INTERNAL_ERROR;
120 }
121 
122 void WINAPI SCardReleaseStartedEvent(void)
123 {
124     FIXME("stub\n");
125 }
126 
127 LONG WINAPI SCardListReadersA(SCARDCONTEXT context, const CHAR *groups, CHAR *readers, DWORD *buflen)
128 {
129     FIXME("(%lx, %s, %p, %p) stub\n", context, debugstr_a(groups), readers, buflen);
130     return SCARD_E_NO_READERS_AVAILABLE;
131 }
132 
133 LONG WINAPI SCardListReadersW(SCARDCONTEXT context, const WCHAR *groups, WCHAR *readers, DWORD *buflen)
134 {
135     FIXME("(%lx, %s, %p, %p) stub\n", context, debugstr_w(groups), readers, buflen);
136     return SCARD_E_NO_READERS_AVAILABLE;
137 }
138