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.

443 lines
14 KiB

  1. //**************************************************************************
  2. //
  3. // MSGAMIO.H -- Xena Gaming Project
  4. //
  5. // Version 2.XX
  6. //
  7. // Copyright (c) 1997 Microsoft Corporation. All rights reserved.
  8. //
  9. // @doc
  10. // @header MSGAMIO.H | Global includes and definitions for gameport driver interface
  11. //**************************************************************************
  12. #ifndef __MSGAMIO_H__
  13. #define __MSGAMIO_H__
  14. #ifdef SAITEK
  15. #define MSGAMIO_NAME "SAIIO"
  16. #else
  17. #define MSGAMIO_NAME "MSGAMIO"
  18. #endif
  19. //---------------------------------------------------------------------------
  20. // Version Information
  21. //---------------------------------------------------------------------------
  22. #define MSGAMIO_Major 0x02
  23. #define MSGAMIO_Minor 0x00
  24. #define MSGAMIO_Build 0x00
  25. #define MSGAMIO_Version_Rc MSGAMIO_Major,MSGAMIO_Minor,0,MSGAMIO_Build
  26. #define MSGAMIO_Version_Int ((MSGAMIO_Build << 16)+(MSGAMIO_Major << 8)+(MSGAMIO_Minor))
  27. #define MSGAMIO_Version_Str "2.00.00\0"
  28. #define MSGAMIO_Copyright_Str "Copyright � Microsoft Corporation, 1998\0"
  29. #ifdef SAITEK
  30. #define MSGAMIO_Company_Str "SaiTek Corporation\0"
  31. #define MSGAMIO_Product_Str "SaiTek Gameport Driver Interface\0"
  32. #ifdef WIN_NT
  33. #define MSGAMIO_Filename_Str "Saiio.Sys\0"
  34. #else
  35. #define MSGAMIO_Filename_Str "Saiio.Vxd\0"
  36. #endif
  37. #else
  38. #define MSGAMIO_Company_Str "Microsoft Corporation\0"
  39. #define MSGAMIO_Product_Str "SideWinder Gameport Driver Interface\0"
  40. #ifdef WIN_NT
  41. #define MSGAMIO_Filename_Str "Msgamio.Sys\0"
  42. #else
  43. #define MSGAMIO_Filename_Str "Msgamio.Vxd\0"
  44. #endif
  45. #endif
  46. //**************************************************************************
  47. #ifndef RC_INVOKED // Skip Rest of File
  48. //**************************************************************************
  49. //---------------------------------------------------------------------------
  50. // Global Limits
  51. //---------------------------------------------------------------------------
  52. #define MAX_MSGAMIO_SERVERS 4
  53. #define MAX_MSGAMIO_CLIENTS 16
  54. //---------------------------------------------------------------------------
  55. // Transaction Types
  56. //---------------------------------------------------------------------------
  57. typedef enum
  58. { // @enum MSGAMIO_TRANSACTIONS | Device transaction types
  59. MSGAMIO_TRANSACT_NONE, // @emem No transaction type
  60. MSGAMIO_TRANSACT_RESET, // @emem Reset transaction type
  61. MSGAMIO_TRANSACT_DATA, // @emem Data transaction type
  62. MSGAMIO_TRANSACT_ID, // @emem Id transaction type
  63. MSGAMIO_TRANSACT_STATUS, // @emem Status transaction type
  64. MSGAMIO_TRANSACT_SPEED, // @emem Speed transaction type
  65. MSGAMIO_TRANSACT_GODIGITAL, // @emem GoDigital transaction type
  66. MSGAMIO_TRANSACT_GOANALOG // @emem GoAnalog transaction type
  67. } MSGAMIO_TRANSACTION;
  68. //---------------------------------------------------------------------------
  69. // Types
  70. //---------------------------------------------------------------------------
  71. #ifndef STDCALL
  72. #define STDCALL _stdcall
  73. #endif
  74. //---------------------------------------------------------------------------
  75. // GUIDs
  76. //---------------------------------------------------------------------------
  77. #ifndef GUID_DEFINED
  78. #define GUID_DEFINED
  79. typedef struct
  80. {
  81. #pragma pack (1)
  82. unsigned long Data1;
  83. unsigned short Data2;
  84. unsigned short Data3;
  85. unsigned char Data4[8];
  86. #pragma pack()
  87. } GUID, *PGUID;
  88. #else
  89. typedef GUID *PGUID;
  90. #endif // GUID_DEFINED
  91. __inline BOOLEAN STDCALL IsGUIDEqual (PGUID pGuid1, PGUID pGuid2)
  92. {
  93. ULONG i = sizeof(GUID);
  94. PUCHAR p1 = (PUCHAR)pGuid1;
  95. PUCHAR p2 = (PUCHAR)pGuid2;
  96. while (i--)
  97. if (*p1++ != *p2++)
  98. return (FALSE);
  99. return (TRUE);
  100. }
  101. //---------------------------------------------------------------------------
  102. // Server GUIDs
  103. //---------------------------------------------------------------------------
  104. #ifdef SAITEK
  105. #define MSGAMIO_MSGAME_GUID \
  106. {0xcaca0c60,0xe40a,0x11d1,0x99,0x6f,0x44,0x45,0x53,0x54,0x00,0x01}
  107. #define MSGAMIO_GCKERNEL_GUID \
  108. {0xcaca0c61,0xe40a,0x11d1,0x99,0x6f,0x44,0x45,0x53,0x54,0x00,0x01}
  109. #else
  110. #define MSGAMIO_MSGAME_GUID \
  111. {0xb9292380,0x628a,0x11d1,0xaa,0xa5,0x04,0x76,0xa6,0x00,0x00,0x00}
  112. #define MSGAMIO_GCKERNEL_GUID \
  113. {0x95e69580,0x97d5,0x11d1,0x99,0x6f,0x00,0xa0,0x24,0xbe,0xbf,0xf5}
  114. #endif
  115. //---------------------------------------------------------------------------
  116. // Client GUIDs
  117. //---------------------------------------------------------------------------
  118. #define MSGAMIO_MIDAS_GUID \
  119. {0x12D41A36,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  120. #define MSGAMIO_JUNO_GUID \
  121. {0xC948CE81,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  122. #define MSGAMIO_JOLT_GUID \
  123. {0xC948CE82,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  124. #define MSGAMIO_SHAZAM_GUID \
  125. {0xC948CE83,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  126. #define MSGAMIO_FLASH_GUID \
  127. {0xC948CE84,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  128. #define MSGAMIO_TILT_GUID \
  129. {0xC948CE86,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  130. #define MSGAMIO_TILTUSB_GUID \
  131. {0xC948CE89,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  132. #define MSGAMIO_APOLLO_GUID \
  133. {0xC948CE88,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  134. #ifdef SAITEK
  135. #define MSGAMIO_LEDZEP_GUID \
  136. {0xcaca0c62,0xe40a,0x11d1,0x99,0x6f,0x44,0x45,0x53,0x54,0x00,0x01}
  137. #else
  138. #define MSGAMIO_LEDZEP_GUID \
  139. {0xC948CE87,0x9026,0x11d0,0x9F,0xFE,0x00,0xA0,0xC9,0x11,0xF5,0xAF}
  140. #endif
  141. //---------------------------------------------------------------------------
  142. // Macros
  143. //---------------------------------------------------------------------------
  144. #ifndef STILL_TO_DO
  145. #define STD0(txt) #txt
  146. #define STD1(txt) STD0(txt)
  147. #define STILL_TO_DO(txt) message("\nSTILL TO DO: "__FILE__"("STD1(__LINE__)"): "#txt"\n")
  148. #endif
  149. //---------------------------------------------------------------------------
  150. // Control Codes
  151. //---------------------------------------------------------------------------
  152. #define IOCTL_INTERNAL_MSGAMIO_BASE 0xB00
  153. #define IOCTL_INTERNAL_MSGAMIO_UNLOAD \
  154. CTL_CODE(FILE_DEVICE_UNKNOWN,IOCTL_INTERNAL_MSGAMIO_BASE+0,METHOD_NEITHER,FILE_ANY_ACCESS)
  155. #define IOCTL_INTERNAL_MSGAMIO_CONNECT_SERVER \
  156. CTL_CODE(FILE_DEVICE_UNKNOWN,IOCTL_INTERNAL_MSGAMIO_BASE+1,METHOD_NEITHER,FILE_ANY_ACCESS)
  157. #define IOCTL_INTERNAL_MSGAMIO_DISCONNECT_SERVER \
  158. CTL_CODE(FILE_DEVICE_UNKNOWN,IOCTL_INTERNAL_MSGAMIO_BASE+2,METHOD_NEITHER,FILE_ANY_ACCESS)
  159. #define IOCTL_INTERNAL_MSGAMIO_CONNECT_CLIENT \
  160. CTL_CODE(FILE_DEVICE_UNKNOWN,IOCTL_INTERNAL_MSGAMIO_BASE+3,METHOD_NEITHER,FILE_ANY_ACCESS)
  161. #define IOCTL_INTERNAL_MSGAMIO_DISCONNECT_CLIENT \
  162. CTL_CODE(FILE_DEVICE_UNKNOWN,IOCTL_INTERNAL_MSGAMIO_BASE+4,METHOD_NEITHER,FILE_ANY_ACCESS)
  163. //---------------------------------------------------------------------------
  164. // Structures
  165. //---------------------------------------------------------------------------
  166. typedef struct
  167. { // @struct DRIVERSERVICES | Device services table
  168. // @field ULONG | Size | Size of structure
  169. ULONG Size;
  170. // @field GUID | Server | Server GUID
  171. GUID Server;
  172. // @field VOID (*Connect)(ConnectInfo) | ConnectInfo | Connection service procedure
  173. VOID (STDCALL *Connect)(PVOID ConnectInfo);
  174. // @field VOID (*Disconnect)(ConnectInfo) | ConnectInfo | Disconnection service procedure
  175. VOID (STDCALL *Disconnect)(PVOID ConnectInfo);
  176. // @field VOID (*Transact)(PacketInfo) | PacketInfo | Transaction hook procedure
  177. VOID (STDCALL *Transact)(PVOID PacketInfo);
  178. // @field VOID (*Packet)(PacketData) | PacketData | Packet hook procedure
  179. VOID (STDCALL *Packet)(PVOID PacketData);
  180. // @field NTSTATUS (*ForceReset)(VOID) | None | Reset force feedback device
  181. NTSTATUS (STDCALL *ForceReset)(VOID);
  182. // @field NTSTATUS (*ForceId)(IdString) | IdString | Gets force feedback id string
  183. NTSTATUS (STDCALL *ForceId)(PVOID IdString);
  184. // @field NTSTATUS (*ForceStatus)(Status) | Status | Gets raw force feedback status
  185. NTSTATUS (STDCALL *ForceStatus)(PVOID Status);
  186. // @field NTSTATUS (*ForceAckNak)(AckNak) | AckNak | Gets force feedback ack nak
  187. NTSTATUS (STDCALL *ForceAckNak)(PUCHAR AckNak);
  188. // @field NTSTATUS (*ForceNakAck)(NakAck) | NakAck | Gets force feedback nak ack
  189. NTSTATUS (STDCALL *ForceNakAck)(PUCHAR NakAck);
  190. // @field NTSTATUS (*ForceSync)(Sync) | Sync | Reads byte from gameport to sync
  191. NTSTATUS (STDCALL *ForceSync)(PUCHAR Sync);
  192. // @field ULONG (*Register)(Device, UnitId) | Device, UnitId | Registers device with Gckernel
  193. ULONG (STDCALL *Register)(PGUID Device, ULONG UnitId);
  194. // @field VOID (*Unregister) (Handle) | Handle | Unregisters device with Gckernel
  195. VOID (STDCALL *Unregister) (ULONG Handle);
  196. // @field VOID (*Notify) (Handle, DevInfo, PollData) | Handle, DevInfo, PollData | Sends packet for Gckernel processing
  197. VOID (STDCALL *Notify) (ULONG Handle, PVOID DevInfo, PVOID PollData);
  198. } MSGAMIO_CONNECTION, *PMSGAMIO_CONNECTION;
  199. //---------------------------------------------------------------------------
  200. // Global Procedures
  201. //---------------------------------------------------------------------------
  202. // @func NTSTATUS | MSGAMIO_DoConnection | Calls MSGAMIO internal control interface
  203. // @parm ULONG | ControlCode | IO control code
  204. // @parm PMSGAMIO_CONNECTION | ConnectInfo | Connection structure
  205. // @rdesc Returns NT status code
  206. // @comm Inline function
  207. //---------------------------------------------------------------------------
  208. // Private Procedures
  209. //---------------------------------------------------------------------------
  210. NTSTATUS STDCALL MSGAMIO_DoConnection (ULONG ControlCode, PMSGAMIO_CONNECTION InputBuffer);
  211. //===========================================================================
  212. // WDM Interface
  213. //===========================================================================
  214. #ifdef _NTDDK_
  215. #ifdef SAITEK
  216. #define MSGAMIO_DEVICE_NAME TEXT("\\Device\\Saiio")
  217. #define MSGAMIO_DEVICE_NAME_U L"\\Device\\Saiio"
  218. #define MSGAMIO_SYMBOLIC_NAME TEXT("\\DosDevices\\Saiio")
  219. #define MSGAMIO_SYMBOLIC_NAME_U L"\\DosDevices\\Saiio"
  220. #else
  221. #define MSGAMIO_DEVICE_NAME TEXT("\\Device\\MsGamio")
  222. #define MSGAMIO_DEVICE_NAME_U L"\\Device\\MsGamio"
  223. #define MSGAMIO_SYMBOLIC_NAME TEXT("\\DosDevices\\MsGamio")
  224. #define MSGAMIO_SYMBOLIC_NAME_U L"\\DosDevices\\MsGamio"
  225. #endif
  226. //---------------------------------------------------------------------------
  227. __inline NTSTATUS STDCALL MSGAMIO_Connection (ULONG ControlCode, PMSGAMIO_CONNECTION ConnectInfo)
  228. //---------------------------------------------------------------------------
  229. {
  230. NTSTATUS ntStatus;
  231. PIRP pIrp;
  232. KEVENT Event;
  233. PFILE_OBJECT FileObject;
  234. PDEVICE_OBJECT DeviceObject;
  235. UNICODE_STRING ObjectName;
  236. IO_STATUS_BLOCK IoStatus;
  237. //
  238. // Validate parameters
  239. //
  240. ASSERT (ConnectInfo);
  241. ASSERT (KeGetCurrentIrql()<=DISPATCH_LEVEL);
  242. //
  243. // Retrieve the driver device object
  244. //
  245. RtlInitUnicodeString (&ObjectName, MSGAMIO_DEVICE_NAME_U);
  246. ntStatus = IoGetDeviceObjectPointer (&ObjectName, FILE_ALL_ACCESS, &FileObject, &DeviceObject);
  247. if (!NT_SUCCESS(ntStatus))
  248. {
  249. KdPrint (("%s_Connection: IoGetDeviceObjectPointer (%ws) failed, status = 0x%X", MSGAMIO_NAME, ObjectName.Buffer, ntStatus));
  250. return (ntStatus);
  251. }
  252. //
  253. // Initialize the completion event
  254. //
  255. KeInitializeEvent (&Event, SynchronizationEvent, FALSE);
  256. //
  257. // Allocate internal I/O IRP
  258. //
  259. pIrp = IoBuildDeviceIoControlRequest (ControlCode, DeviceObject, ConnectInfo, sizeof (MSGAMIO_CONNECTION), NULL, 0, TRUE, &Event, &IoStatus);
  260. //
  261. // Call MsGamIo synchronously
  262. //
  263. KdPrint (("%s_Connection: Calling %s (%lu)\n", MSGAMIO_NAME, MSGAMIO_NAME, ControlCode));
  264. ntStatus = IoCallDriver (DeviceObject, pIrp);
  265. if (ntStatus == STATUS_PENDING)
  266. ntStatus = KeWaitForSingleObject (&Event, Suspended, KernelMode, FALSE, NULL);
  267. //
  268. // Check asynchronous status
  269. //
  270. if (!NT_SUCCESS (ntStatus))
  271. KdPrint (("%s_Connection: %s (%lu) failed, Status = %X\n", MSGAMIO_NAME, MSGAMIO_NAME, ControlCode, ntStatus));
  272. //
  273. // Free file object associated with device
  274. //
  275. ObDereferenceObject (FileObject);
  276. //
  277. // Return status
  278. //
  279. return (ntStatus);
  280. }
  281. #endif
  282. //===========================================================================
  283. // VXD Definitions
  284. //===========================================================================
  285. #ifndef _NTDDK_
  286. #ifdef SAITEK
  287. #define MSGAMIO_DEVICE_ID 0x11EF
  288. #else
  289. #define MSGAMIO_DEVICE_ID 0x1EF
  290. #endif
  291. #pragma warning (disable:4003)
  292. Begin_Service_Table (MSGAMIO)
  293. Declare_Service (MSGAMIO_Service, LOCAL)
  294. End_Service_Table (MSGAMIO)
  295. #pragma warning (default:4003)
  296. //---------------------------------------------------------------------------
  297. __inline NTSTATUS STDCALL MSGAMIO_Connection (ULONG ControlCode, PMSGAMIO_CONNECTION ConnectInfo)
  298. //---------------------------------------------------------------------------
  299. {
  300. NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
  301. //
  302. // First check if Vxd present
  303. //
  304. if (ConnectInfo)
  305. {
  306. _asm stc
  307. _asm xor eax, eax
  308. _asm xor ebx, ebx
  309. VxDCall (MSGAMIO_Service);
  310. _asm {
  311. jc Failure
  312. _asm mov [ntStatus], eax
  313. Failure:
  314. }
  315. }
  316. if (!NT_SUCCESS(ntStatus))
  317. KdPrint (("%s_Connection Failed to Find %s", MSGAMIO_NAME, MSGAMIO_Filename_Str));
  318. //
  319. // Then call for service
  320. //
  321. if (NT_SUCCESS(ntStatus))
  322. {
  323. _asm mov eax, ControlCode
  324. _asm mov ebx, ConnectInfo
  325. VxDCall (MSGAMIO_Service);
  326. _asm mov [ntStatus], eax
  327. if (!NT_SUCCESS(ntStatus))
  328. KdPrint (("%s_Connection Failed Service Call %ld", MSGAMIO_NAME, ControlCode));
  329. }
  330. //
  331. // Return status
  332. //
  333. return (ntStatus);
  334. }
  335. #endif // _NTDDK_
  336. //**************************************************************************
  337. #endif // RC_INVOKED // Skip Rest of File
  338. //**************************************************************************
  339. #endif // __MSGAMIO_H__
  340. //===========================================================================
  341. // End
  342. //===========================================================================