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.

307 lines
6.1 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1999
  3. Module Name:
  4. scappdev
  5. Abstract:
  6. This module provides the device-specific operations that must be performed
  7. by the controlling resource manager application. Due to Plug 'n Play, there
  8. can't be a clean separation between device controller classes and the
  9. application driving them. This module provides the hooks to isolate these
  10. interdependencies as much as possible.
  11. Author:
  12. Doug Barlow (dbarlow) 4/3/1998
  13. Environment:
  14. Win32, C++
  15. Notes:
  16. ?Notes?
  17. --*/
  18. #include "stdafx.h"
  19. #include <winsvc.h>
  20. #include <dbt.h>
  21. #include <scardlib.h>
  22. #include <calmsgs.h>
  23. #include "SvrApp.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. static const GUID l_guidSmartcards
  30. = { // 50DD5230-BA8A-11D1-BF5D-0000F805F530
  31. 0x50DD5230,
  32. 0xBA8A,
  33. 0x11D1,
  34. { 0xBF, 0x5D, 0x00, 0x00, 0xF8, 0x05, 0xF5, 0x30 } };
  35. static HANDLE l_hService = NULL;
  36. static DWORD l_dwType = 0;
  37. static HDEVNOTIFY l_hIfDev = NULL;
  38. /*++
  39. AppInitializeDeviceRegistration:
  40. This routine is called by a controlling application in order to enable
  41. PnP and Power Management Events.
  42. Arguments:
  43. hService supplies the handle to the service application.
  44. dwType supplies the type of handle supplied.
  45. Return Value:
  46. None
  47. Author:
  48. Doug Barlow (dbarlow) 4/3/1998
  49. --*/
  50. void
  51. AppInitializeDeviceRegistration(
  52. HANDLE hService,
  53. DWORD dwType)
  54. {
  55. //
  56. // Platform-specific initialization.
  57. //
  58. ASSERT(NULL == l_hService);
  59. DEV_BROADCAST_DEVICEINTERFACE dbcIfFilter;
  60. //
  61. // Save off the application information.
  62. //
  63. l_hService = hService;
  64. l_dwType = dwType;
  65. //
  66. // Register for PnP events.
  67. //
  68. ZeroMemory(&dbcIfFilter, sizeof(dbcIfFilter));
  69. dbcIfFilter.dbcc_size = sizeof(dbcIfFilter);
  70. dbcIfFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
  71. // dbcIfFilter.dbcc_reserved = NULL;
  72. CopyMemory(
  73. &dbcIfFilter.dbcc_classguid,
  74. &l_guidSmartcards,
  75. sizeof(GUID));
  76. // dbcIfFilter.dbcc_name[1];
  77. l_hIfDev = RegisterDeviceNotification(
  78. l_hService,
  79. &dbcIfFilter,
  80. l_dwType);
  81. if (NULL == l_hIfDev)
  82. {
  83. CalaisWarning(
  84. DBGT("Initialize device registration failed to register for PnP events: %1"),
  85. GetLastError());
  86. }
  87. }
  88. /*++
  89. AppTerminateDeviceRegistration:
  90. This routine is called by a controlling application in order to terminate
  91. PnP and Power Management Events.
  92. Arguments:
  93. None
  94. Return Value:
  95. None
  96. Author:
  97. Doug Barlow (dbarlow) 4/3/1998
  98. --*/
  99. void
  100. AppTerminateDeviceRegistration(
  101. void)
  102. {
  103. //
  104. // Platform-specific initialization.
  105. //
  106. BOOL fSts;
  107. //
  108. // Unregister for PnP events.
  109. //
  110. if (NULL != l_hIfDev)
  111. {
  112. fSts = UnregisterDeviceNotification(l_hIfDev);
  113. if (!fSts)
  114. {
  115. CalaisWarning(
  116. DBGT("Terminate device registration failed to unregister from PnP events: %1"),
  117. GetLastError());
  118. }
  119. }
  120. l_hService = NULL;
  121. l_dwType = 0;
  122. l_hIfDev = NULL;
  123. }
  124. /*++
  125. AppRegisterDevice:
  126. This routine is called by a Reader Device Object to inform the controlling
  127. application that it exists and is ready to follow the OS rules for removal.
  128. Arguments:
  129. hReader supplies the handle to the open device.
  130. szReader supplies the name of the device.
  131. ppvAppState supplies a pointer to a storage location for this application
  132. associated with this device. The use of this location is specific to
  133. the application.
  134. Return Value:
  135. None
  136. Author:
  137. Doug Barlow (dbarlow) 4/3/1998
  138. --*/
  139. void
  140. AppRegisterDevice(
  141. HANDLE hReader,
  142. LPCTSTR szReader,
  143. LPVOID *ppvAppState)
  144. {
  145. //
  146. // Platform-specific initialization.
  147. //
  148. DEV_BROADCAST_HANDLE dbcHandleFilter;
  149. HDEVNOTIFY *phDevNotify = (HDEVNOTIFY *)ppvAppState;
  150. //
  151. // Register for PnP events.
  152. //
  153. ASSERT(NULL == *phDevNotify);
  154. ZeroMemory(&dbcHandleFilter, sizeof(dbcHandleFilter));
  155. dbcHandleFilter.dbch_size = sizeof(dbcHandleFilter);
  156. dbcHandleFilter.dbch_devicetype = DBT_DEVTYP_HANDLE;
  157. dbcHandleFilter.dbch_handle = hReader;
  158. *phDevNotify = RegisterDeviceNotification(
  159. l_hService,
  160. &dbcHandleFilter,
  161. l_dwType);
  162. if (NULL == *phDevNotify)
  163. {
  164. CalaisWarning(
  165. DBGT("Register device failed to register '%2' for PnP Device removal: %1"),
  166. GetLastError(),
  167. szReader);
  168. }
  169. }
  170. /*++
  171. AppUnregisterDevice:
  172. This routine is called when a device wants to let the controlling
  173. application know that it is officially ceasing to exist.
  174. Arguments:
  175. hReader supplies the handle to the open device.
  176. szReader supplies the name of the device.
  177. ppvAppState supplies a pointer to a storage location for this application
  178. associated with this device. The use of this location is specific to
  179. the application.
  180. Return Value:
  181. None
  182. Author:
  183. Doug Barlow (dbarlow) 4/3/1998
  184. --*/
  185. void
  186. AppUnregisterDevice(
  187. HANDLE hReader,
  188. LPCTSTR szReader,
  189. LPVOID *ppvAppState)
  190. {
  191. //
  192. // Platform-specific initialization.
  193. //
  194. BOOL fSts;
  195. HDEVNOTIFY *phDevNotify = (HDEVNOTIFY *)ppvAppState;
  196. //
  197. // Unregister from PnP events.
  198. //
  199. if (NULL != *phDevNotify)
  200. {
  201. fSts = UnregisterDeviceNotification(*phDevNotify);
  202. if (!fSts)
  203. {
  204. CalaisWarning(
  205. DBGT("Unregister device failed to unregister '%2' from PnP Device removal: %1"),
  206. GetLastError(),
  207. szReader);
  208. }
  209. }
  210. }