Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
8.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. client
  5. Abstract:
  6. This header file collects the definitions for the Calais Client DLL.
  7. Author:
  8. Doug Barlow (dbarlow) 11/21/1996
  9. Environment:
  10. Win32, C++ w/ Exceptions
  11. Notes:
  12. ?Notes?
  13. --*/
  14. #ifndef _CLIENT_H_
  15. #define _CLIENT_H_
  16. #define WINSCARDDATA
  17. #include <WinSCard.h>
  18. #include <calmsgs.h>
  19. #include <CalCom.h>
  20. #ifndef FACILITY_SCARD
  21. #define FACILITY_SCARD 16
  22. #endif
  23. // #define ErrorCode(x) (0x80000000 | (FACILITY_SCARD << 16) + (x))
  24. // #define WarnCode(x) (0x80000000 | (FACILITY_SCARD << 16) + (x))
  25. // #define InfoCode(x) (0x40000000 | (FACILITY_SCARD << 16) + (x))
  26. // #define SuccessCode(x) ((FACILITY_SCARD << 16) + (x))
  27. #define CONTEXT_HANDLE_ID 0xcd
  28. #define READER_HANDLE_ID 0xea
  29. #define SCARD_LEAVE_CARD_FORCE 0xff
  30. extern CHandleList
  31. * g_phlContexts,
  32. * g_phlReaders;
  33. extern const WCHAR
  34. g_wszBlank[];
  35. extern BOOL g_fInClientRundown;
  36. class CSCardUserContext;
  37. class CSCardSubcontext;
  38. class CReaderContext;
  39. extern void
  40. PlaceResult(
  41. CSCardUserContext *pCtx,
  42. CBuffer &bfResult,
  43. LPBYTE pbOutput,
  44. LPDWORD pcbLength);
  45. extern void
  46. PlaceResult(
  47. CSCardUserContext *pCtx,
  48. CBuffer &bfResult,
  49. LPSTR szOutput,
  50. LPDWORD pcchLength);
  51. extern void
  52. PlaceResult(
  53. CSCardUserContext *pCtx,
  54. CBuffer &bfResult,
  55. LPWSTR szOutput,
  56. LPDWORD pcchLength);
  57. extern void
  58. PlaceMultiResult(
  59. CSCardUserContext *pCtx,
  60. CBuffer &bfResult,
  61. LPSTR mszOutput,
  62. LPDWORD pcchLength);
  63. extern void
  64. PlaceMultiResult(
  65. CSCardUserContext *pCtx,
  66. CBuffer &bfResult,
  67. LPWSTR mszOutput,
  68. LPDWORD pcchLength);
  69. //
  70. //==============================================================================
  71. //
  72. // CReaderContext
  73. //
  74. class CReaderContext
  75. : public CHandle
  76. {
  77. public:
  78. // Constructors & Destructor
  79. CReaderContext();
  80. ~CReaderContext();
  81. // Properties
  82. // Methods
  83. DWORD Protocol(void) const
  84. { return m_dwActiveProtocol; };
  85. CSCardSubcontext *Context(void) const
  86. { ASSERT(NULL != m_pCtx);
  87. return m_pCtx; };
  88. void Connect(
  89. CSCardSubcontext *pCtx,
  90. LPCTSTR szReaderName,
  91. DWORD dwShareMode,
  92. DWORD dwPreferredProtocols);
  93. void Reconnect(
  94. DWORD dwShareMode,
  95. DWORD dwPreferredProtocols,
  96. DWORD dwInitialization);
  97. LONG Disconnect(
  98. DWORD dwDisposition);
  99. void BeginTransaction(
  100. void);
  101. void EndTransaction(
  102. DWORD dwDisposition);
  103. void Status(
  104. OUT LPDWORD pdwState,
  105. OUT LPDWORD pdwProtocol,
  106. OUT CBuffer &bfAtr,
  107. OUT CBuffer &bfReaderNames);
  108. void Transmit(
  109. IN LPCSCARD_IO_REQUEST pioSendPci,
  110. IN LPCBYTE pbSendBuffer,
  111. IN DWORD cbSendLength,
  112. OUT LPSCARD_IO_REQUEST pioRecvPci,
  113. OUT CBuffer &bfRecvData,
  114. IN DWORD cbProposedLength = 0);
  115. void Read(
  116. IN OUT LPSCARD_IO_REQUEST pioRequest,
  117. IN DWORD dwMaxLength,
  118. OUT CBuffer &bfData);
  119. void Write(
  120. IN OUT LPSCARD_IO_REQUEST pioRequest,
  121. IN LPCBYTE pbDataBuffer,
  122. IN DWORD cbDataLength);
  123. void Control(
  124. IN DWORD dwControlCode,
  125. IN LPCVOID pvInBuffer,
  126. IN DWORD cbInBufferSize,
  127. OUT CBuffer &bfOutBuffer);
  128. void GetAttrib(
  129. IN DWORD dwAttrId,
  130. OUT CBuffer &bfAttr,
  131. IN DWORD dwProposedLen = 0);
  132. void SetAttrib(
  133. IN DWORD dwAttrId,
  134. IN LPCBYTE pbAttr,
  135. IN DWORD cbAttrLen);
  136. void SetRedirCard(SCARDHANDLE hCard)
  137. { m_hRedirCard = hCard;};
  138. SCARDHANDLE GetRedirCard() const
  139. {return m_hRedirCard;};
  140. // Operators
  141. protected:
  142. // Properties
  143. CSCardSubcontext *m_pCtx;
  144. INTERCHANGEHANDLE m_hCard;
  145. DWORD m_dwActiveProtocol;
  146. SCARDHANDLE m_hRedirCard;
  147. // Methods
  148. };
  149. //
  150. //==============================================================================
  151. //
  152. // CSCardUserContext
  153. //
  154. class CSCardUserContext
  155. : public CHandle
  156. {
  157. public:
  158. // Constructors & Destructor
  159. CSCardUserContext(DWORD dwScope);
  160. virtual ~CSCardUserContext();
  161. // Properties
  162. // Methods
  163. void EstablishContext(void);
  164. void ReleaseContext(void);
  165. void ClosePipes(void);
  166. LPVOID AllocateMemory(DWORD cbLength);
  167. DWORD FreeMemory(LPCVOID pvBuffer);
  168. DWORD Scope(void) const
  169. { return m_dwScope; };
  170. HANDLE HeapHandle(void) const
  171. { return m_hContextHeap; };
  172. CSCardSubcontext *AcquireSubcontext(BOOL fAndAllocate = FALSE);
  173. void LocateCards(
  174. IN LPCTSTR mszReaders,
  175. IN LPSCARD_ATRMASK rgAtrMasks,
  176. IN DWORD cAtrs,
  177. LPSCARD_READERSTATE rgReaderStates,
  178. DWORD cReaders);
  179. void GetStatusChange(
  180. IN LPCTSTR mszReaders,
  181. LPSCARD_READERSTATE rgReaderStates,
  182. DWORD cReaders,
  183. DWORD dwTimeout);
  184. void Cancel(void);
  185. void StripInactiveReaders(IN OUT CBuffer &bfReaders);
  186. BOOL IsValidContext(void);
  187. BOOL InitFailed(void)
  188. { return m_csUsrCtxLock.InitFailed(); }
  189. void SetRedirContext(SCARDCONTEXT hRedirContext)
  190. { m_hRedirContext = hRedirContext;};
  191. SCARDCONTEXT GetRedirContext() const
  192. {return m_hRedirContext;};
  193. // Operators
  194. BOOL fCallUnregister;
  195. protected:
  196. // Properties
  197. DWORD m_dwScope;
  198. CHandleObject m_hContextHeap;
  199. CDynamicArray<CSCardSubcontext> m_rgpSubContexts;
  200. CCriticalSectionObject m_csUsrCtxLock;
  201. SCARDCONTEXT m_hRedirContext;
  202. // Methods
  203. private:
  204. // Properties
  205. // Methods
  206. // Friends
  207. // friend class CReaderContext;
  208. // friend class CSCardSubcontext;
  209. };
  210. //
  211. //==============================================================================
  212. //
  213. // CSCardSubcontext
  214. //
  215. class CSCardSubcontext
  216. {
  217. public:
  218. typedef enum { Invalid, Idle, Allocated, Busy } State;
  219. // Constructors & Destructor
  220. CSCardSubcontext();
  221. virtual ~CSCardSubcontext();
  222. // Properties
  223. SCARDHANDLE m_hReaderHandle;
  224. // Methods
  225. DWORD Scope(void) const
  226. { return m_pParentCtx->Scope(); };
  227. CSCardUserContext *Parent(void) const
  228. { return m_pParentCtx; };
  229. void SendRequest(CComObject *pCom);
  230. void EstablishContext(IN DWORD dwScope);
  231. void ReleaseContext(void);
  232. void ClosePipe(void);
  233. void ReleaseSubcontext(void);
  234. void LocateCards(
  235. IN LPCTSTR mszReaders,
  236. IN LPSCARD_ATRMASK rgAtrMasks,
  237. IN DWORD cAtrs,
  238. LPSCARD_READERSTATE rgReaderStates,
  239. DWORD cReaders);
  240. void GetStatusChange(
  241. IN LPCTSTR mszReaders,
  242. LPSCARD_READERSTATE rgReaderStates,
  243. DWORD cReaders,
  244. DWORD dwTimeout);
  245. void Cancel(void);
  246. void StripInactiveReaders(IN OUT CBuffer &bfReaders);
  247. void IsValidContext(void);
  248. void SetBusy(void);
  249. void WaitForAvailable(void);
  250. void Allocate(void);
  251. void Deallocate(void);
  252. BOOL InitFailed(void)
  253. { return m_csSubCtxLock.InitFailed(); }
  254. // Operators
  255. protected:
  256. // Properties
  257. State m_nInUse;
  258. State m_nLastState;
  259. CHandleObject m_hBusy; // Set => available, reset => busy.
  260. CHandleObject m_hCancelEvent;
  261. CSCardUserContext *m_pParentCtx;
  262. CComChannel *m_pChannel;
  263. CCriticalSectionObject m_csSubCtxLock;
  264. // Methods
  265. private:
  266. // Properties
  267. // Methods
  268. // Friends
  269. friend class CReaderContext;
  270. friend class CSCardUserContext;
  271. };
  272. //
  273. //==============================================================================
  274. //
  275. // CSubctxLock
  276. //
  277. class CSubctxLock
  278. {
  279. public:
  280. // Constructors & Destructor
  281. CSubctxLock(CSCardSubcontext *pSubCtx)
  282. {
  283. m_pSubCtx = NULL;
  284. pSubCtx->WaitForAvailable();
  285. m_pSubCtx = pSubCtx;
  286. };
  287. ~CSubctxLock()
  288. {
  289. if (NULL != m_pSubCtx)
  290. m_pSubCtx->ReleaseSubcontext();
  291. };
  292. // Properties
  293. // Methods
  294. // Operators
  295. protected:
  296. // Properties
  297. CSCardSubcontext *m_pSubCtx;
  298. // Methods
  299. };
  300. #endif // _CLIENT_H_