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.

448 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1991 - 2001 Microsoft Corporation
  3. Module Name:
  4. #### ## # ###### ##### ##### ## # ### ## ## ##
  5. ## ### # ## ## ## ## ### # ### ## ## ##
  6. ## #### # ## ## ## ## #### # ## ## ## ## ##
  7. ## # #### ## ##### ##### # #### ## ## ## #######
  8. ## # ### ## ## #### # ### ####### ## ## ##
  9. ## # ## ## ## ## ## # ## ## ## ## ## ## ##
  10. #### # # ## ##### ## ## # # ## ## ##### ## ## ##
  11. Abstract:
  12. This header contains all definitions that are internal
  13. to the port driver.
  14. Author:
  15. Wesley Witt (wesw) 1-Oct-2001
  16. Environment:
  17. Kernel mode only.
  18. Notes:
  19. --*/
  20. extern "C" {
  21. #include <ntosp.h>
  22. #include <zwapi.h>
  23. #include <mountmgr.h>
  24. #include <mountdev.h>
  25. #include <ntddstor.h>
  26. #include <ntdddisk.h>
  27. #include <wdmsec.h>
  28. #include <stdio.h>
  29. }
  30. #define MINIPORT_DEVICE_TYPE 0
  31. #include "saport.h"
  32. #pragma warning(error:4101) // Unreferenced local variable
  33. #ifdef POOL_TAGGING
  34. #ifdef ExAllocatePool
  35. #undef ExAllocatePool
  36. #endif
  37. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'tpaS')
  38. #endif
  39. #define STRING_SZ(_str) (wcslen((PWSTR)_str)*sizeof(WCHAR))
  40. #define ARRAY_SZ(_ary) (sizeof(_ary)/sizeof(_ary[0]))
  41. #define SecToNano(_sec) (LONGLONG)((_sec) * 1000 * 1000 * 10)
  42. #define NanoToSec(_nano) (ULONG)((_nano) / (1000 * 1000 * 10))
  43. #define MARK_IRP_INTERNAL(_irp) (_irp)->Flags |= 0x80
  44. #define IS_IRP_INTERNAL(_irp) (((_irp)->Flags & 0x80) > 0)
  45. typedef struct _SAPORT_DRIVER_EXTENSION {
  46. SAPORT_INITIALIZATION_DATA InitData;
  47. PDRIVER_OBJECT DriverObject;
  48. UNICODE_STRING RegistryPath;
  49. } SAPORT_DRIVER_EXTENSION, *PSAPORT_DRIVER_EXTENSION;
  50. //
  51. // Device extension structures
  52. //
  53. #define DEVICE_EXTENSION_UNKNOWN (0)
  54. #define DEVICE_EXTENSION_DISPLAY (1)
  55. #define DEVICE_EXTENSION_KEYPAD (2)
  56. #define DEVICE_EXTENSION_NVRAM (3)
  57. #define DEVICE_EXTENSION_WATCHDOG (4)
  58. typedef struct _DEVICE_EXTENSION {
  59. ULONG DeviceExtensionType;
  60. ULONG DeviceType;
  61. PDEVICE_OBJECT DeviceObject;
  62. PDRIVER_OBJECT DriverObject;
  63. PDEVICE_OBJECT TargetObject;
  64. PDEVICE_OBJECT Pdo;
  65. LONG IsStarted;
  66. LONG IsRemoved;
  67. PVOID MiniPortDeviceExtension;
  68. PSAPORT_INITIALIZATION_DATA InitData;
  69. IO_REMOVE_LOCK RemoveLock;
  70. PSAPORT_DRIVER_EXTENSION DriverExtension;
  71. PKINTERRUPT InterruptObject;
  72. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  73. typedef struct _SAPORT_IOCONTEXT {
  74. NTSTATUS Status;
  75. PSA_IO_ROUTINE IoRoutine;
  76. PUCHAR IoBuffer;
  77. ULONG IoLength;
  78. LONGLONG StartingOffset;
  79. PVOID MiniPortDeviceExtension;
  80. PIRP Irp;
  81. } SAPORT_IOCONTEXT, *PSAPORT_IOCONTEXT;
  82. typedef struct _SAPORT_FSCONTEXT {
  83. ULONGLONG CurrentPosition;
  84. } SAPORT_FSCONTEXT, *PSAPORT_FSCONTEXT;
  85. PDEVICE_EXTENSION
  86. FORCEINLINE
  87. DeviceExtentionFromMiniPort(
  88. IN PVOID MiniPortDeviceExtension
  89. )
  90. {
  91. return (PDEVICE_EXTENSION)((PUCHAR)MiniPortDeviceExtension - *(PULONG)((PUCHAR)MiniPortDeviceExtension - sizeof(ULONG)));
  92. }
  93. //
  94. // IOCTL processing
  95. //
  96. #define DECLARE_IOCTL_HANDLER(_NAME) \
  97. NTSTATUS \
  98. _NAME( \
  99. IN PDEVICE_OBJECT DeviceObject, \
  100. IN PIRP Irp, \
  101. IN PDEVICE_EXTENSION DeviceExtension, \
  102. IN PVOID InputBuffer, \
  103. IN ULONG InputBufferLength, \
  104. IN PVOID OutputBuffer, \
  105. IN ULONG OutputBufferLength \
  106. )
  107. #define DO_DEFAULT() DefaultIoctlHandler( DeviceObject, Irp, DeviceExtension, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength )
  108. //
  109. // IOCTL handler prototypes
  110. //
  111. DECLARE_IOCTL_HANDLER( DefaultIoctlHandler );
  112. DECLARE_IOCTL_HANDLER( UnsupportedIoctlHandler );
  113. DECLARE_IOCTL_HANDLER( HandleGetVersion );
  114. DECLARE_IOCTL_HANDLER( HandleGetCaps );
  115. DECLARE_IOCTL_HANDLER( HandleDisplayLock );
  116. DECLARE_IOCTL_HANDLER( HandleDisplayUnlock );
  117. DECLARE_IOCTL_HANDLER( HandleDisplayBusyMessage );
  118. DECLARE_IOCTL_HANDLER( HandleDisplayShutdownMessage );
  119. DECLARE_IOCTL_HANDLER( HandleDisplayChangeLanguage );
  120. DECLARE_IOCTL_HANDLER( HandleWdDisable );
  121. DECLARE_IOCTL_HANDLER( HandleWdQueryExpireBehavior );
  122. DECLARE_IOCTL_HANDLER( HandleWdSetExpireBehavior );
  123. DECLARE_IOCTL_HANDLER( HandleWdPing );
  124. DECLARE_IOCTL_HANDLER( HandleWdQueryTimer );
  125. DECLARE_IOCTL_HANDLER( HandleWdSetTimer );
  126. DECLARE_IOCTL_HANDLER( HandleWdDelayBoot );
  127. DECLARE_IOCTL_HANDLER( HandleNvramWriteBootCounter );
  128. DECLARE_IOCTL_HANDLER( HandleNvramReadBootCounter );
  129. DECLARE_IOCTL_HANDLER( HandleDisplayStoreBitmap );
  130. //
  131. // Miniport specific header files
  132. //
  133. #include "display.h"
  134. #include "keypad.h"
  135. #include "nvram.h"
  136. #include "watchdog.h"
  137. //
  138. // OS Versioning Stuff
  139. //
  140. extern ULONG OsMajorVersion;
  141. extern ULONG OsMinorVersion;
  142. #define RunningOnWin2k (OsMajorVersion == 5 && OsMinorVersion == 0)
  143. #define RunningOnWinXp (OsMajorVersion == 5 && OsMinorVersion == 1)
  144. //
  145. // Debug Stuff
  146. //
  147. #define ERROR_RETURN(_dt_,_msg_,_status_) \
  148. { \
  149. REPORT_ERROR(_dt_,_msg_,_status_); \
  150. __leave; \
  151. }
  152. #if DBG
  153. PCHAR
  154. PnPMinorFunctionString(
  155. UCHAR MinorFunction
  156. );
  157. PCHAR
  158. IoctlString(
  159. ULONG IoControlCode
  160. );
  161. PCHAR
  162. PowerMinorFunctionString(
  163. UCHAR MinorFunction
  164. );
  165. PCHAR
  166. PowerSystemStateString(
  167. SYSTEM_POWER_STATE State
  168. );
  169. PCHAR
  170. PowerDeviceStateString(
  171. DEVICE_POWER_STATE State
  172. );
  173. PCHAR
  174. PnPMinorFunctionString(
  175. UCHAR MinorFunction
  176. );
  177. #endif
  178. //
  179. // prototypes
  180. //
  181. extern "C" {
  182. NTSTATUS
  183. DriverEntry(
  184. IN PDRIVER_OBJECT DriverObject,
  185. IN PUNICODE_STRING RegistryPath
  186. );
  187. VOID
  188. SaPortStartIo(
  189. IN PDEVICE_OBJECT DeviceObject,
  190. IN PIRP Irp
  191. );
  192. NTSTATUS
  193. SaPortCreate(
  194. IN PDEVICE_OBJECT DeviceObject,
  195. IN PIRP Irp
  196. );
  197. NTSTATUS
  198. SaPortCleanup(
  199. IN PDEVICE_OBJECT DeviceObject,
  200. IN PIRP Irp
  201. );
  202. NTSTATUS
  203. SaPortClose(
  204. IN PDEVICE_OBJECT DeviceObject,
  205. IN PIRP Irp
  206. );
  207. NTSTATUS
  208. SaPortPnp(
  209. IN PDEVICE_OBJECT DeviceObject,
  210. IN PIRP Irp
  211. );
  212. NTSTATUS
  213. SaPortAddDevice(
  214. IN PDRIVER_OBJECT DriverObject,
  215. IN OUT PDEVICE_OBJECT PhysicalDeviceObject
  216. );
  217. NTSTATUS
  218. SaPortPower(
  219. IN PDEVICE_OBJECT DeviceObject,
  220. IN PIRP Irp
  221. );
  222. NTSTATUS
  223. SaPortWrite(
  224. IN PDEVICE_OBJECT DeviceObject,
  225. IN PIRP Irp
  226. );
  227. NTSTATUS
  228. SaPortRead(
  229. IN PDEVICE_OBJECT DeviceObject,
  230. IN PIRP Irp
  231. );
  232. NTSTATUS
  233. SaPortDeviceControl(
  234. IN PDEVICE_OBJECT DeviceObject,
  235. IN PIRP Irp
  236. );
  237. NTSTATUS
  238. SaPortShutdown(
  239. IN PDEVICE_OBJECT DeviceObject,
  240. IN PIRP Irp
  241. );
  242. NTSTATUS
  243. SaPortSystemControl(
  244. IN PDEVICE_OBJECT DeviceObject,
  245. IN PIRP Irp
  246. );
  247. VOID
  248. SaPortCancelRoutine(
  249. IN PDEVICE_OBJECT DeviceObject,
  250. IN PIRP Irp
  251. );
  252. } // extern "C"
  253. //
  254. // util.cpp
  255. //
  256. VOID
  257. PrintDriverVersion(
  258. IN ULONG DeviceType,
  259. IN PDRIVER_OBJECT DriverObject
  260. );
  261. NTSTATUS
  262. CallLowerDriverAndWait(
  263. IN PIRP Irp,
  264. IN PDEVICE_OBJECT TargetObject
  265. );
  266. NTSTATUS
  267. GetBootPartitionNumber(
  268. OUT PULONG DiskNumber,
  269. OUT PULONG PartitionNumber,
  270. OUT PULONG AbsolutePartNumber
  271. );
  272. NTSTATUS
  273. CompleteRequest(
  274. PIRP Irp,
  275. NTSTATUS Status,
  276. ULONG_PTR OutputLength
  277. );
  278. NTSTATUS
  279. ForwardRequest(
  280. IN PIRP Irp,
  281. IN PDEVICE_OBJECT TargetObject
  282. );
  283. NTSTATUS
  284. CallMiniPortDriverReadWrite(
  285. IN PDEVICE_EXTENSION DeviceExtension,
  286. IN PDEVICE_OBJECT DeviceObject,
  287. IN BOOLEAN WriteIo,
  288. IN PVOID Buffer,
  289. IN ULONG Length,
  290. IN ULONG Offset
  291. );
  292. NTSTATUS
  293. CallMiniPortDriverDeviceControl(
  294. IN PDEVICE_EXTENSION DeviceExtension,
  295. IN PDEVICE_OBJECT DeviceObject,
  296. IN ULONG IoControlCode,
  297. IN PVOID InputBuffer,
  298. IN ULONG InputBufferLength,
  299. OUT PVOID OutputBuffer,
  300. IN ULONG OutputBufferLength
  301. );
  302. NTSTATUS
  303. OpenParametersRegistryKey(
  304. IN PSAPORT_DRIVER_EXTENSION DriverExtension,
  305. IN PUNICODE_STRING RegistryPath,
  306. IN ULONG AccessMode,
  307. OUT PHANDLE RegistryHandle
  308. );
  309. NTSTATUS
  310. CreateParametersRegistryKey(
  311. IN PSAPORT_DRIVER_EXTENSION DriverExtension,
  312. IN PUNICODE_STRING RegistryPath,
  313. OUT PHANDLE parametersKey
  314. );
  315. NTSTATUS
  316. ReadRegistryValue(
  317. IN PSAPORT_DRIVER_EXTENSION DriverExtension,
  318. IN PUNICODE_STRING RegistryPath,
  319. IN PWSTR ValueName,
  320. OUT PKEY_VALUE_FULL_INFORMATION *KeyInformation
  321. );
  322. NTSTATUS
  323. WriteRegistryValue(
  324. IN PSAPORT_DRIVER_EXTENSION DriverExtension,
  325. IN PUNICODE_STRING RegistryPath,
  326. IN PWSTR ValueName,
  327. IN ULONG RegistryType,
  328. IN PVOID RegistryValue,
  329. IN ULONG RegistryValueLength
  330. );
  331. VOID
  332. GetOsVersion(
  333. VOID
  334. );
  335. //
  336. // ******************************************
  337. //
  338. // From NTDDK.H
  339. //
  340. // ******************************************
  341. //
  342. extern "C" {
  343. typedef
  344. VOID
  345. (*PCREATE_PROCESS_NOTIFY_ROUTINE)(
  346. IN HANDLE ParentId,
  347. IN HANDLE ProcessId,
  348. IN BOOLEAN Create
  349. );
  350. NTSTATUS
  351. PsSetCreateProcessNotifyRoutine(
  352. IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
  353. IN BOOLEAN Remove
  354. );
  355. BOOLEAN
  356. PsGetVersion(
  357. PULONG MajorVersion OPTIONAL,
  358. PULONG MinorVersion OPTIONAL,
  359. PULONG BuildNumber OPTIONAL,
  360. PUNICODE_STRING CSDVersion OPTIONAL
  361. );
  362. }