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.

274 lines
8.6 KiB

  1. ////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // sysvars.h
  7. //
  8. // Abstract:
  9. // Definitions for driver portion of tdi sample driver
  10. //
  11. /////////////////////////////////////////////////////////////////
  12. #include "glbconst.h"
  13. extern "C"
  14. {
  15. #pragma warning(disable: NAMELESS_STRUCT_UNION)
  16. #include "wdm.h"
  17. #include "tdikrnl.h"
  18. #pragma warning(default: NAMELESS_STRUCT_UNION)
  19. }
  20. #include "glbtypes.h"
  21. #include <tdistat.h>
  22. /////////////////////////////////////////////////////////////////
  23. // debugging macros
  24. /////////////////////////////////////////////////////////////////
  25. #define DebugPrint0(fmt) DbgPrint(fmt)
  26. #define DebugPrint1(fmt,v1) DbgPrint(fmt,v1)
  27. #define DebugPrint2(fmt,v1,v2) DbgPrint(fmt,v1,v2)
  28. #define DebugPrint3(fmt,v1,v2,v3) DbgPrint(fmt,v1,v2,v3)
  29. #define DebugPrint4(fmt,v1,v2,v3,v4) DbgPrint(fmt,v1,v2,v3,v4)
  30. #define DebugPrint5(fmt,v1,v2,v3,v4,v5) DbgPrint(fmt,v1,v2,v3,v4,v5)
  31. #define DebugPrint6(fmt,v1,v2,v3,v4,v5,v6) DbgPrint(fmt,v1,v2,v3,v4,v5,v6)
  32. #define DebugPrint7(fmt,v1,v2,v3,v4,v5,v6,v7) \
  33. DbgPrint(fmt,v1,v2,v3,v4,v5,v6,v7)
  34. #define DebugPrint8(fmt,v1,v2,v3,v4,v5,v6,v7,v8) \
  35. DbgPrint(fmt,v1,v2,v3,v4,v5,v6,v7,v8)
  36. ///////////////////////////////////////////////////////////////////////
  37. // constant definitions
  38. ///////////////////////////////////////////////////////////////////////
  39. //
  40. // constants for GenericHeader->ulSignature
  41. //
  42. const ULONG ulINVALID_OBJECT = 0x00000000;
  43. const ULONG ulControlChannelObject = 0x00001000;
  44. const ULONG ulAddressObject = 0x00002000;
  45. const ULONG ulEndpointObject = 0x00004000;
  46. //
  47. // number of irps in irp pool
  48. //
  49. const ULONG ulIrpPoolSize = 32;
  50. //
  51. // max number of open object handles
  52. //
  53. const ULONG ulMAX_OBJ_HANDLES = 256;
  54. const USHORT usOBJ_HANDLE_MASK = 0x00FF; // = 255
  55. const USHORT usOBJ_TYPE_MASK = 0xF000;
  56. ///////////////////////////////////////////////////////////////////////
  57. // type definitions
  58. ///////////////////////////////////////////////////////////////////////
  59. //
  60. // forward definitions
  61. //
  62. struct DEVICE_CONTEXT;
  63. struct ENDPOINT_OBJECT;
  64. struct RECEIVE_DATA;
  65. struct USERBUF_INFO;
  66. //
  67. // structure used for spinlocks
  68. //
  69. struct TDI_SPIN_LOCK
  70. {
  71. KSPIN_LOCK SpinLock;
  72. KIRQL OldIrql;
  73. };
  74. typedef TDI_SPIN_LOCK *PTDI_SPIN_LOCK;
  75. //
  76. // event structure
  77. //
  78. typedef KEVENT TDI_EVENT, *PTDI_EVENT;
  79. //
  80. // structure used for list of address/device objects that can be opened
  81. // (maintained via the TSPnpAdd/DelAddressCallback functions
  82. //
  83. struct TDI_DEVICE_NODE
  84. {
  85. PTA_ADDRESS pTaAddress; // address of object
  86. UNICODE_STRING ustrDeviceName; // name of object
  87. ULONG ulState;
  88. };
  89. typedef TDI_DEVICE_NODE *PTDI_DEVICE_NODE;
  90. //
  91. // states for device nodes
  92. //
  93. const ULONG ulDEVSTATE_UNUSED = 0;
  94. const ULONG ulDEVSTATE_DELETED = 1;
  95. const ULONG ulDEVSTATE_INUSE = 2;
  96. const ULONG ulMAX_DEVICE_NODES = 64;
  97. //
  98. // actual array structure
  99. //
  100. struct TDI_DEVNODE_LIST
  101. {
  102. TDI_SPIN_LOCK TdiSpinLock; // protects DeviceNode list
  103. TDI_DEVICE_NODE TdiDeviceNode[ulMAX_DEVICE_NODES];
  104. };
  105. typedef TDI_DEVNODE_LIST *PTDI_DEVNODE_LIST;
  106. // structure used for IRP array, used with AddressObjects and Endpoints
  107. // so that we don't have to allocates IRPs in a callback.
  108. //
  109. struct IRP_POOL
  110. {
  111. TDI_SPIN_LOCK TdiSpinLock; // protects rest of structure
  112. BOOLEAN fMustFree; // true if stangler must free pool
  113. ULONG ulPoolSize; // number of entries in pool
  114. PIRP pAvailIrpList; // irps available to be used
  115. PIRP pUsedIrpList; // irps that have been used
  116. PIRP pAllocatedIrp[1]; // all irps in pool
  117. };
  118. typedef IRP_POOL *PIRP_POOL;
  119. //
  120. // this structure is at the beginning of all the nodes, allows generic functions
  121. // to be used for inserting/deleting nodes
  122. //
  123. struct GENERIC_HEADER
  124. {
  125. ULONG ulSignature; // type of block
  126. BOOLEAN fInCommand; // true if dealing with command
  127. GENERIC_HEADER *pPrevNode; // ptr to previous node -- same type
  128. GENERIC_HEADER *pNextNode; // ptr to next node -- same type
  129. TDI_EVENT TdiEvent; // event for CloseAddress/CloseEndpoint
  130. NTSTATUS lStatus;
  131. HANDLE FileHandle; // handle of device
  132. PFILE_OBJECT pFileObject; // ptr to file object for handle
  133. PDEVICE_OBJECT pDeviceObject; // ptr to device object for handle
  134. };
  135. typedef GENERIC_HEADER *PGENERIC_HEADER;
  136. //
  137. // structure for control channel object
  138. //
  139. struct CONTROL_CHANNEL
  140. {
  141. GENERIC_HEADER GenHead;
  142. };
  143. typedef CONTROL_CHANNEL *PCONTROL_CHANNEL;
  144. //
  145. // structure for address object
  146. //
  147. struct ADDRESS_OBJECT
  148. {
  149. GENERIC_HEADER GenHead;
  150. ENDPOINT_OBJECT *pEndpoint; // associate connection endpoint, if any
  151. TDI_SPIN_LOCK TdiSpinLock; // protects receive queue
  152. RECEIVE_DATA *pHeadReceiveData; // head of normal rcv queue
  153. RECEIVE_DATA *pTailReceiveData; // tail of normal rcv queue
  154. RECEIVE_DATA *pHeadRcvExpData; // head of expedited rcv queue
  155. RECEIVE_DATA *pTailRcvExpData; // tail of expedited rcv queue
  156. PIRP_POOL pIrpPool; // preallocated irps
  157. USERBUF_INFO *pHeadUserBufInfo; // linked list of posted buffers
  158. USERBUF_INFO *pTailUserBufInfo;
  159. };
  160. typedef ADDRESS_OBJECT *PADDRESS_OBJECT;
  161. //
  162. // structure for endpoint connection object
  163. //
  164. struct ENDPOINT_OBJECT
  165. {
  166. GENERIC_HEADER GenHead;
  167. PADDRESS_OBJECT pAddressObject; // associate address object (if any)
  168. BOOLEAN fIsConnected; // true if connection established
  169. BOOLEAN fAcceptInProgress; // true if in process of accepting connection
  170. BOOLEAN fIsAssociated; // true if associated with address object
  171. BOOLEAN fStartedDisconnect;
  172. };
  173. typedef ENDPOINT_OBJECT *PENDPOINT_OBJECT;
  174. //
  175. // structure used to store data received (used for both receive
  176. // and receive datagram)
  177. //
  178. struct RECEIVE_DATA
  179. {
  180. RECEIVE_DATA *pNextReceiveData; // next in list
  181. RECEIVE_DATA *pPrevReceiveData; // prev in list
  182. PUCHAR pucDataBuffer; // buffer of received data
  183. ULONG ulBufferLength; // total length of buffer
  184. ULONG ulBufferUsed; // bytes used in buffer
  185. TRANSADDR TransAddr; // address received from (rd only)
  186. };
  187. typedef RECEIVE_DATA *PRECEIVE_DATA;
  188. //
  189. // all objects opened by this driver
  190. //
  191. struct OBJECT_LIST
  192. {
  193. TDI_SPIN_LOCK TdiSpinLock; // protects openinfo array
  194. PGENERIC_HEADER GenHead[ulMAX_OBJ_HANDLES]; // open handles controlled by driver
  195. };
  196. typedef OBJECT_LIST *POBJECT_LIST;
  197. //
  198. // Device Driver data struct definition
  199. //
  200. // Device Context - hanging off the end of the DeviceObject for the
  201. // driver the device context contains the control structures used
  202. // to administer the tdi sample
  203. //
  204. struct DEVICE_CONTEXT
  205. {
  206. DEVICE_OBJECT DeviceObject; // the I/O system's device object.
  207. ULONG ulOpenCount; // Number of outstanding opens of driver
  208. PIRP pLastCommandIrp; // irp of last submitted command
  209. BOOLEAN fInitialized; // TRUE if TdiTestInit succeeded
  210. };
  211. typedef DEVICE_CONTEXT *PDEVICE_CONTEXT;
  212. //////////////////////////////////////////////////////////////////////
  213. // externs for global variables
  214. //////////////////////////////////////////////////////////////////////
  215. #ifdef _IN_MAIN_
  216. ULONG ulDebugLevel; // show command info?
  217. PVOID pvMemoryList; // head of alloced memory list
  218. TDI_SPIN_LOCK MemTdiSpinLock; // protects pvMemoryList
  219. PTDI_DEVNODE_LIST pTdiDevnodeList; // list of devices
  220. POBJECT_LIST pObjectList; // list of opened objects
  221. #else
  222. extern ULONG ulDebugLevel;
  223. extern PVOID pvMemoryList;
  224. extern TDI_SPIN_LOCK MemTdiSpinLock;
  225. extern PTDI_DEVNODE_LIST pTdiDevnodeList;
  226. extern POBJECT_LIST pObjectList;
  227. #endif
  228. #include "sysprocs.h"
  229. /////////////////////////////////////////////////////////////////////
  230. // end of file sysvars.h
  231. /////////////////////////////////////////////////////////////////////