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.

330 lines
9.8 KiB

  1. /****************************************************************************
  2. *
  3. * drvproc.c
  4. *
  5. * Generic WDM Audio driver message dispatch routines
  6. *
  7. * Copyright (C) Microsoft Corporation, 1997 - 1999 All Rights Reserved.
  8. *
  9. * History
  10. * 5-12-97 - Noel Cross (NoelC)
  11. *
  12. ***************************************************************************/
  13. #include "wdmdrv.h"
  14. volatile BYTE cPendingOpens = 0 ;
  15. volatile BYTE fExiting = 0 ;
  16. #ifdef DEBUG
  17. //UINT uiDebugLevel = DL_WARNING ; // debug level
  18. static TCHAR STR_DRIVER[] = TEXT("wdmaud") ;
  19. static TCHAR STR_MMDEBUG[] = TEXT("uidebuglevel") ;
  20. #endif
  21. LRESULT _loadds CALLBACK DriverProc
  22. (
  23. DWORD id,
  24. HDRVR hDriver,
  25. WORD msg,
  26. LPARAM lParam1,
  27. LPARAM lParam2
  28. )
  29. {
  30. LPDEVICEINFO lpDeviceInfo;
  31. //DWORD dwCallback16;
  32. switch (msg)
  33. {
  34. case DRV_LOAD:
  35. //
  36. // Sent to the driver when it is loaded. Always the first
  37. // message received by a driver.
  38. //
  39. // dwDriverID is 0L.
  40. // lParam1 is 0L.
  41. // lParam2 is 0L.
  42. //
  43. // Return 0L to fail the load.
  44. //
  45. // DefDriverProc will return NON-ZERO so we don't have to
  46. // handle DRV_LOAD
  47. //
  48. DPF(DL_TRACE|FA_DRV, ("DRV_LOAD") ) ;
  49. return 1L ;
  50. case DRV_FREE:
  51. //
  52. // Sent to the driver when it is about to be discarded. This
  53. // will always be the last message received by a driver before
  54. // it is freed.
  55. //
  56. // dwDriverID is 0L.
  57. // lParam1 is 0L.
  58. // lParam2 is 0L.
  59. //
  60. // Return value is ignored.
  61. //
  62. DPF(DL_TRACE|FA_DRV, ("DRV_FREE") ) ;
  63. return 1L ;
  64. case DRV_OPEN:
  65. //
  66. // Sent to the driver when it is opened.
  67. //
  68. // dwDriverID is 0L.
  69. //
  70. // lParam1 is a far pointer to a zero-terminated string
  71. // containing the name used to open the driver.
  72. //
  73. // lParam2 is passed through from the drvOpen call.
  74. //
  75. // Return 0L to fail the open.
  76. //
  77. // DefDriverProc will return ZERO so we do have to
  78. // handle the DRV_OPEN message.
  79. //
  80. DPF(DL_TRACE|FA_DRV, ("DRV_OPEN") ) ;
  81. return 1L ;
  82. case DRV_CLOSE:
  83. //
  84. // Sent to the driver when it is closed. Drivers are unloaded
  85. // when the close count reaches zero.
  86. //
  87. // dwDriverID is the driver identifier returned from the
  88. // corresponding DRV_OPEN.
  89. //
  90. // lParam1 is passed through from the drvOpen call.
  91. //
  92. // lParam2 is passed through from the drvOpen call.
  93. //
  94. // Return 0L to fail the close.
  95. //
  96. // DefDriverProc will return ZERO so we do have to
  97. // handle the DRV_CLOSE message.
  98. //
  99. DPF(DL_TRACE|FA_DRV, ("DRV_CLOSE") ) ;
  100. return 1L ;
  101. case DRV_ENABLE:
  102. //
  103. // Sent to the driver when the driver is loaded or reloaded
  104. // and whenever Windows is enabled. Drivers should only
  105. // hook interrupts or expect ANY part of the driver to be in
  106. // memory between enable and disable messages
  107. //
  108. // dwDriverID is 0L.
  109. // lParam1 is 0L.
  110. // lParam2 is 0L.
  111. //
  112. // Return value is ignored.
  113. //
  114. DPF(DL_TRACE|FA_DRV, ("DRV_ENABLE") ) ;
  115. if (!DrvInit())
  116. return 0L ; // error
  117. //
  118. // Make sure that we don't take the critical section
  119. // in wdmaudIoControl
  120. //
  121. lpDeviceInfo = GlobalAllocDeviceInfo(L"BogusDeviceString");
  122. if( lpDeviceInfo )
  123. {
  124. lpDeviceInfo->OpenDone = 0;
  125. lpDeviceInfo->DeviceType = AuxDevice;
  126. wdmaudIoControl(lpDeviceInfo,
  127. 0,
  128. NULL,
  129. IOCTL_WDMAUD_INIT);
  130. GlobalFreeDeviceInfo(lpDeviceInfo);
  131. return 1L;
  132. } else
  133. return 0L;
  134. case DRV_DISABLE:
  135. //
  136. // Sent to the driver before the driver is freed.
  137. // and whenever Windows is disabled
  138. //
  139. // dwDriverID is 0L.
  140. // lParam1 is 0L.
  141. // lParam2 is 0L.
  142. //
  143. // Return value is ignored.
  144. //
  145. DPF(DL_TRACE|FA_DRV, ("DRV_DISABLE") ) ;
  146. //
  147. // Make sure that we don't take the critical section
  148. // in wdmaudIoControl
  149. //
  150. lpDeviceInfo = GlobalAllocDeviceInfo(L"BogusDeviceString");
  151. if( lpDeviceInfo )
  152. {
  153. lpDeviceInfo->OpenDone = 0;
  154. lpDeviceInfo->DeviceType = AuxDevice;
  155. wdmaudIoControl(lpDeviceInfo,
  156. 0,
  157. NULL,
  158. IOCTL_WDMAUD_EXIT);
  159. DrvEnd() ;
  160. GlobalFreeDeviceInfo(lpDeviceInfo);
  161. return 1L ;
  162. } else {
  163. return 0L;
  164. }
  165. #ifndef UNDER_NT
  166. case DRV_EXITSESSION:
  167. //
  168. // Sent to the driver when windows is exiting
  169. //
  170. DPF(DL_TRACE|FA_DRV, ("DRV_EXITSESSION") ) ;
  171. fExiting = 1;
  172. while (cPendingOpens != 0)
  173. {
  174. Yield();
  175. }
  176. return 1L ;
  177. #endif
  178. case DRV_QUERYCONFIGURE:
  179. //
  180. // Sent to the driver so that applications can
  181. // determine whether the driver supports custom
  182. // configuration. The driver should return a
  183. // non-zero value to indicate that configuration
  184. // is supported.
  185. //
  186. // For WDM drivers the settings dialog will be completely
  187. // tied to the Device Manager. The individual drivers will
  188. // have to register a property page that will be invoked
  189. // when the user changes the device settings via the Device
  190. // Manager.
  191. //
  192. // dwDriverID is the value returned from the DRV_OPEN
  193. // call that must have succeeded before this message
  194. // was sent.
  195. //
  196. // lParam1 is passed from the app and is undefined.
  197. // lParam2 is passed from the app and is undefined.
  198. //
  199. // Return 0L to indicate configuration NOT supported.
  200. //
  201. DPF(DL_TRACE|FA_DRV, ("DRV_QUERYCONFIGURE") ) ;
  202. return 0L ;
  203. case DRV_CONFIGURE:
  204. //
  205. // Sent to the driver so that it can display a custom
  206. // configuration dialog box.
  207. //
  208. // lParam1 is passed from the app. and should contain
  209. // the parent window handle in the loword.
  210. // lParam2 is passed from the app and is undefined.
  211. //
  212. // Return value is REBOOT, OK, RESTART.
  213. //
  214. DPF(DL_TRACE|FA_DRV, ("DRV_CONFIGURE") ) ;
  215. return 0L ;
  216. case DRV_INSTALL:
  217. //
  218. // TODO: Should wdmaud.sys be added here so that I
  219. // don't have to reboot?
  220. //
  221. DPF(DL_TRACE|FA_DRV, ("DRV_INSTALL") ) ;
  222. return DRV_OK ; // Install OK, Don't reboot
  223. case DRV_REMOVE:
  224. DPF(DL_TRACE|FA_DRV, ("DRV_REMOVE") ) ;
  225. return 0 ;
  226. //
  227. // TODO: Handle ACPI power management messages.
  228. //
  229. // Do I need to handle this case or is it
  230. // completely covered by the kernel mode driver?
  231. //
  232. }
  233. return DefDriverProc( id, hDriver, msg, lParam1, lParam2 ) ;
  234. } // DriverProc()
  235. /**************************************************************************
  236. @doc EXTERNAL
  237. @api BOOL | LibMain | Entry point for 16-bit driver.
  238. @rdesc The return value is TRUE if the initialisation completed ok,
  239. FALSE if not.
  240. **************************************************************************/
  241. BOOL FAR PASCAL LibMain
  242. (
  243. HANDLE hInstance,
  244. WORD wHeapSize,
  245. LPSTR lpszCmdLine
  246. )
  247. {
  248. #ifdef DEBUG
  249. // get debug level - default should be DL_WARNING not DL_ERROR
  250. uiDebugLevel = GetProfileInt( STR_MMDEBUG, STR_DRIVER, DL_ERROR );
  251. #endif
  252. #ifdef HTTP
  253. DPF(DL_WARNING|FA_ALL, ("************************************************************") );
  254. DPF(DL_WARNING|FA_ALL, ("* uiDebugLevel=%08X controls the debug output. To change",uiDebugLevel) );
  255. DPF(DL_WARNING|FA_ALL, ("* edit uiDebugLevel like: e uidebuglevel and set to ") );
  256. DPF(DL_WARNING|FA_ALL, ("* 0 - show only fatal error messages and asserts ") );
  257. DPF(DL_WARNING|FA_ALL, ("* 1 (Default) - Also show non-fatal errors and return codes ") );
  258. DPF(DL_WARNING|FA_ALL, ("* 2 - Also show trace messages ") );
  259. DPF(DL_WARNING|FA_ALL, ("* 4 - Show Every message ") );
  260. DPF(DL_WARNING|FA_ALL, ("* See http:\\\\debugtips\\msgs\\wdmaud.htm for more info ") );
  261. DPF(DL_WARNING|FA_ALL, ("************************************************************") );
  262. #else
  263. DPF(DL_TRACE|FA_ALL, ("************************************************************") );
  264. DPF(DL_TRACE|FA_ALL, ("* uiDebugLevel=%08X controls the debug output. To change",uiDebugLevel) );
  265. DPF(DL_TRACE|FA_ALL, ("* edit uiDebugLevel like: e uidebuglevel and set to ") );
  266. DPF(DL_TRACE|FA_ALL, ("* 0 - show only fatal error messages and asserts ") );
  267. DPF(DL_TRACE|FA_ALL, ("* 1 (Default) - Also show non-fatal errors and return codes ") );
  268. DPF(DL_TRACE|FA_ALL, ("* 2 - Also show trace messages ") );
  269. DPF(DL_TRACE|FA_ALL, ("* 4 - Show Every message ") );
  270. DPF(DL_TRACE|FA_ALL, ("************************************************************") );
  271. #endif
  272. return TRUE;
  273. }