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.

1008 lines
32 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. Module Name:
  4. wrapper.h
  5. Abstract:
  6. NDIS wrapper definitions
  7. Author:
  8. Environment:
  9. Kernel mode, FSD
  10. Revision History:
  11. Jun-95 Jameel Hyder Split up from a monolithic file
  12. --*/
  13. #ifndef _WRAPPER_
  14. #define _WRAPPER_
  15. #pragma warning(disable:4214) // bit field types other than int
  16. #pragma warning(disable:4201) // nameless struct/union
  17. #pragma warning(disable:4115) // named type definition in parentheses
  18. #pragma warning(disable:4514) // unreferenced inline function has been removed
  19. #pragma warning(disable:4127) // conditional expression is constant
  20. #pragma warning(disable:4213) // nonstandard extension used : cast on l-value
  21. #pragma warning(disable:4054) // cast of function pointer to PVOID
  22. #pragma warning(disable:4055) // cast of function pointer to PVOID
  23. // take care of ks
  24. #pragma warning(disable:4244) // conversion from 'int' to 'BOOLEAN', possible loss of data
  25. #include <ntosp.h>
  26. #include <zwapi.h>
  27. #pragma warning(disable:4514) // unreferenced inline function has been removed
  28. #include <netpnp.h>
  29. #include <ndismain.h>
  30. #include <ndisprot.h>
  31. #include <ndisprv.h>
  32. #if DBG
  33. #undef FASTCALL
  34. #define FASTCALL
  35. #endif
  36. //
  37. // Ndis Major and Minor version
  38. //
  39. #define NDIS_MAJOR_VERSION 5
  40. #define NDIS_MINOR_VERSION 1
  41. #define NDIS_MAX_CPU_COUNT 32
  42. typedef union _FILTER_LOCK_REF_COUNT
  43. {
  44. UINT RefCount;
  45. UCHAR cacheLine[16]; // want one refCount per cache line
  46. } FILTER_LOCK_REF_COUNT;
  47. typedef struct _NDIS_M_OPEN_BLOCK NDIS_M_OPEN_BLOCK, *PNDIS_M_OPEN_BLOCK;
  48. #include <ndismini.h>
  49. //
  50. // The following structure is used to queue closeadapter calls to
  51. // worker threads so that they can complete at PASSIVE_LEVEL.
  52. //
  53. typedef struct _QUEUED_CLOSE
  54. {
  55. NDIS_STATUS Status;
  56. WORK_QUEUE_ITEM WorkItem;
  57. } QUEUED_CLOSE, *PQUEUED_CLOSE;
  58. #include <filter.h>
  59. #include <ndisco.h>
  60. #include <ndis_co.h>
  61. #include <ndismac.h>
  62. #include <macros.h>
  63. #include <ndiswan.h>
  64. #include <ndisdbg.h>
  65. #include <ndistags.h>
  66. //
  67. // ndispnp.h sets the following back to default, disable them again
  68. //
  69. #include <ndispnp.h>
  70. // #pragma warning(disable:4201)
  71. // #pragma warning(disable:4214)
  72. // #pragma warning(disable:4514)
  73. #include <ntddpcm.h>
  74. #if !DBG
  75. #if ASSERT_ON_FREE_BUILDS
  76. extern
  77. VOID
  78. ndisAssert(
  79. IN PVOID exp,
  80. IN PUCHAR File,
  81. IN UINT Line
  82. );
  83. #undef ASSERT
  84. #define ASSERT(exp) \
  85. if (!(exp)) \
  86. { \
  87. ndisAssert( #exp, __FILE__, __LINE__); \
  88. }
  89. #endif // ASSERT_ON_FREE_BUILDS
  90. #endif // DBG
  91. //
  92. // values for ndisFlags
  93. //
  94. #define NDIS_GFLAG_INIT_TIME 0x00000001
  95. #define NDIS_GFLAG_RESERVED 0x00000002
  96. #define NDIS_GFLAG_INJECT_ALLOCATION_FAILURE 0x00000004
  97. #define NDIS_GFLAG_SPECIAL_POOL_ALLOCATION 0x00000008
  98. #define NDIS_GFLAG_DONT_VERIFY 0x00000100
  99. #define NDIS_GFLAG_BREAK_ON_WARNING 0x00000200
  100. #define NDIS_GFLAG_TRACK_MEM_ALLOCATION 0x00000400
  101. #define NDIS_GFLAG_ABORT_TRACK_MEM_ALLOCATION 0x00000800
  102. #define NDIS_GFLAG_WARNING_LEVEL_MASK 0x00000030
  103. #define NDIS_GFLAG_WARN_LEVEL_0 0x00000000
  104. #define NDIS_GFLAG_WARN_LEVEL_1 0x00000010
  105. #define NDIS_GFLAG_WARN_LEVEL_2 0x00000020
  106. #define NDIS_GFLAG_WARN_LEVEL_3 0x00000030
  107. #if DBG
  108. #define NDIS_WARN(_Condition, _M, _Level, Fmt) \
  109. { \
  110. if ((_Condition) && \
  111. MINIPORT_PNP_TEST_FLAG(_M, fMINIPORT_VERIFYING) && \
  112. ((ndisFlags & NDIS_GFLAG_WARNING_LEVEL_MASK) >= _Level)) \
  113. { \
  114. DbgPrint Fmt; \
  115. if (ndisFlags & NDIS_GFLAG_BREAK_ON_WARNING) \
  116. DbgBreakPoint(); \
  117. } \
  118. }
  119. #else
  120. #define NDIS_WARN(_Condition, _M, Level, Fmt)
  121. #endif
  122. #define PACKET_TRACK_COUNT 1032
  123. #define BYTE_SWAP(_word) ((USHORT) (((_word) >> 8) | ((_word) << 8)))
  124. #define LOW_WORD(_dword) ((USHORT) ((_dword) & 0x0000FFFF))
  125. #define HIGH_WORD(_dword) ((USHORT) (((_dword) >> 16) & 0x0000FFFF))
  126. #define BYTE_SWAP_ULONG(_ulong) ((ULONG)((ULONG)(BYTE_SWAP(LOW_WORD(_ulong)) << 16) + \
  127. BYTE_SWAP(HIGH_WORD(_ulong))))
  128. //
  129. // A set of macros to manipulate bitmasks.
  130. //
  131. //VOID
  132. //CLEAR_BIT_IN_MASK(
  133. // IN UINT Offset,
  134. // IN OUT PMASK MaskToClear
  135. // )
  136. //
  137. ///*++
  138. //
  139. //Routine Description:
  140. //
  141. // Clear a bit in the bitmask pointed to by the parameter.
  142. //
  143. //Arguments:
  144. //
  145. // Offset - The offset (from 0) of the bit to altered.
  146. //
  147. // MaskToClear - Pointer to the mask to be adjusted.
  148. //
  149. //Return Value:
  150. //
  151. // None.
  152. //
  153. //--*/
  154. //
  155. #define CLEAR_BIT_IN_MASK(Offset, MaskToClear) *(MaskToClear) &= (~(1 << Offset))
  156. //VOID
  157. //SET_BIT_IN_MASK(
  158. // IN UINT Offset,
  159. // IN OUT PMASK MaskToSet
  160. // )
  161. //
  162. ///*++
  163. //
  164. //Routine Description:
  165. //
  166. // Set a bit in the bitmask pointed to by the parameter.
  167. //
  168. //Arguments:
  169. //
  170. // Offset - The offset (from 0) of the bit to altered.
  171. //
  172. // MaskToSet - Pointer to the mask to be adjusted.
  173. //
  174. //Return Value:
  175. //
  176. // None.
  177. //
  178. //--*/
  179. #define SET_BIT_IN_MASK(Offset, MaskToSet) *(MaskToSet) |= (1 << Offset)
  180. //BOOLEAN
  181. //IS_BIT_SET_IN_MASK(
  182. // IN UINT Offset,
  183. // IN MASK MaskToTest
  184. // )
  185. //
  186. ///*++
  187. //
  188. //Routine Description:
  189. //
  190. // Tests if a particular bit in the bitmask pointed to by the parameter is
  191. // set.
  192. //
  193. //Arguments:
  194. //
  195. // Offset - The offset (from 0) of the bit to test.
  196. //
  197. // MaskToTest - The mask to be tested.
  198. //
  199. //Return Value:
  200. //
  201. // Returns TRUE if the bit is set.
  202. //
  203. //--*/
  204. #define IS_BIT_SET_IN_MASK(Offset, MaskToTest) ((MaskToTest & (1 << Offset)) ? TRUE : FALSE)
  205. //BOOLEAN
  206. //IS_MASK_CLEAR(
  207. // IN MASK MaskToTest
  208. // )
  209. //
  210. ///*++
  211. //
  212. //Routine Description:
  213. //
  214. // Tests whether there are *any* bits enabled in the mask.
  215. //
  216. //Arguments:
  217. //
  218. // MaskToTest - The bit mask to test for all clear.
  219. //
  220. //Return Value:
  221. //
  222. // Will return TRUE if no bits are set in the mask.
  223. //
  224. //--*/
  225. #define IS_MASK_CLEAR(MaskToTest) ((MaskToTest) ? FALSE : TRUE)
  226. //VOID
  227. //CLEAR_MASK(
  228. // IN OUT PMASK MaskToClear
  229. // );
  230. //
  231. ///*++
  232. //
  233. //Routine Description:
  234. //
  235. // Clears a mask.
  236. //
  237. //Arguments:
  238. //
  239. // MaskToClear - The bit mask to adjust.
  240. //
  241. //Return Value:
  242. //
  243. // None.
  244. //
  245. //--*/
  246. #define CLEAR_MASK(MaskToClear) *(MaskToClear) = 0
  247. //
  248. // This constant is used for places where NdisAllocateMemory
  249. // needs to be called and the HighestAcceptableAddress does
  250. // not matter.
  251. //
  252. #define RetrieveUlong(Destination, Source) \
  253. { \
  254. PUCHAR _S = (Source); \
  255. *(Destination) = ((ULONG)(*_S) << 24) | \
  256. ((ULONG)(*(_S+1)) << 16) | \
  257. ((ULONG)(*(_S+2)) << 8) | \
  258. ((ULONG)(*(_S+3))); \
  259. }
  260. //
  261. // This is the number of extra OIDs that ARCnet with Ethernet encapsulation
  262. // supports.
  263. //
  264. #define ARC_NUMBER_OF_EXTRA_OIDS 2
  265. //
  266. // ZZZ NonPortable definitions.
  267. //
  268. #define AllocPhys(s, l) NdisAllocateMemory((PVOID *)(s), (l), 0, HighestAcceptableMax)
  269. #define FreePhys(s, l) NdisFreeMemory((PVOID)(s), (l), 0)
  270. //
  271. // Internal wrapper data structures.
  272. //
  273. #define NDIS_PROXY_SERVICE L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\NDProxy"
  274. #if NDIS_NO_REGISTRY
  275. #define NDIS_DEFAULT_EXPORT_NAME L"\\Device\\DefaultNic"
  276. #endif
  277. //
  278. // NDIS_PKT_POOL
  279. //
  280. // Moved from ndis.h where it existed as NDIS_PACKET_POOL which is now a NDIS_HANDLE.
  281. //
  282. typedef struct _NDIS_PKT_POOL NDIS_PKT_POOL, *PNDIS_PKT_POOL;
  283. typedef enum _POOL_BLOCK_TYPE
  284. {
  285. NDIS_PACKET_POOL_BLOCK_FREE,
  286. NDIS_PACKET_POOL_BLOCK_USED,
  287. NDIS_PACKET_POOL_BLOCK_AGING
  288. } POOL_BLOCK_TYPE;
  289. #if defined(_WIN64)
  290. typedef struct DECLSPEC_ALIGN(16) _NDIS_PKT_POOL_HDR
  291. #else
  292. typedef struct _NDIS_PKT_POOL_HDR
  293. #endif
  294. {
  295. LIST_ENTRY List; // linked from NDIS_PKT_POOL
  296. LARGE_INTEGER TimeStamp; // via KeQueryTickCount (normalized)
  297. SLIST_HEADER FreeList; // linked list of free blocks in pool
  298. POOL_BLOCK_TYPE State; // what (free/used/aging) pool this block belongs to
  299. } NDIS_PKT_POOL_HDR, * PNDIS_PKT_POOL_HDR;
  300. #if defined(_WIN64)
  301. C_ASSERT(sizeof(NDIS_PKT_POOL_HDR) % 16 == 0);
  302. #endif
  303. typedef struct _NDIS_PKT_POOL
  304. {
  305. ULONG Tag; // Protocol supplied pool tag, 'NDpp' by default
  306. USHORT PacketLength; // amount needed in each packet
  307. USHORT PktsPerBlock; // # of packets in each block. Each block is page size
  308. USHORT MaxBlocks; // maximum # of blocks
  309. USHORT StackSize; // stack size for packets allocated on this pool
  310. LONG BlocksAllocated;// # of blocks in use (incl. ones on aging list)
  311. ULONG ProtocolId; // Id of the owning protocol.
  312. ULONG BlockSize; // does not have to be page size
  313. PVOID Allocator; // Address of pool allocator
  314. KSPIN_LOCK Lock; // Protects the NDIS_PKT_POOL entries
  315. LIST_ENTRY FreeBlocks; // These have atleast one free packet in them
  316. LIST_ENTRY UsedBlocks; // These are completely used and have no free packets
  317. LIST_ENTRY AgingBlocks; // These are completely free and will age out over time
  318. LIST_ENTRY GlobalPacketPoolList; // to link all the packet pools allocated by Ndis
  319. LARGE_INTEGER NextScavengeTick;
  320. #ifdef NDIS_PKT_POOL_STATISTICS
  321. ULONG cAllocatedNewBlocks;
  322. ULONG cAllocatedFromFreeBlocks;
  323. ULONG cMovedFreeBlocksToUsed;
  324. ULONG cMovedUsedBlocksToFree;
  325. ULONG cMovedFreeBlocksToAged;
  326. ULONG cMovedAgedBlocksToFree;
  327. ULONG cFreedAgedBlocks;
  328. #endif
  329. } NDIS_PKT_POOL, * PNDIS_PKT_POOL;
  330. //
  331. // we need to make the size of _STACK_INDEX structure a multiple of 16 for
  332. // WIN64 to make sure the packets fall on 16 byte boundary. if we do this
  333. // by making the structure 16 bytes aligned, it does the job but will move the
  334. // Index fields to the beginning of the structure. to avoid any regression
  335. // at this point. pad the structure at the beginning.
  336. //
  337. typedef union _STACK_INDEX
  338. {
  339. ULONGLONG Alignment;
  340. struct _PACKET_INDEXES
  341. {
  342. #if defined(_WIN64)
  343. ULONGLONG Reserved; // to make the _STACK_INDEX size 16 bytes
  344. #endif
  345. ULONG XferDataIndex;
  346. ULONG Index;
  347. };
  348. } STACK_INDEX;
  349. #if defined(_WIN64)
  350. C_ASSERT(sizeof(STACK_INDEX) % 16 == 0);
  351. #endif
  352. typedef struct _NDIS_PACKET_WRAPPER
  353. {
  354. STACK_INDEX StackIndex;
  355. NDIS_PACKET Packet;
  356. } NDIS_PACKET_WRAPPER;
  357. #define POOL_AGING_TIME 60 // In seconds
  358. #define SIZE_PACKET_STACKS (sizeof(STACK_INDEX) + (sizeof(NDIS_PACKET_STACK) * ndisPacketStackSize))
  359. /*
  360. #define PUSH_PACKET_STACK(_P) (*(((PULONG)(_P)) - 1)) ++
  361. #define POP_PACKET_STACK(_P) (*(((PULONG)(_P)) - 1)) --
  362. #define CURR_STACK_LOCATION(_P) *(((PULONG)(_P)) - 1)
  363. */
  364. #define PUSH_PACKET_STACK(_P) \
  365. (CONTAINING_RECORD(_P, NDIS_PACKET_WRAPPER, Packet)->StackIndex.Index ++)
  366. #define POP_PACKET_STACK(_P) \
  367. (CONTAINING_RECORD(_P, NDIS_PACKET_WRAPPER, Packet)->StackIndex.Index --)
  368. #define CURR_STACK_LOCATION(_P) \
  369. (CONTAINING_RECORD(_P, NDIS_PACKET_WRAPPER, Packet)->StackIndex.Index)
  370. #define PUSH_XFER_DATA_PACKET_STACK(_P) \
  371. (CONTAINING_RECORD(_P, NDIS_PACKET_WRAPPER, Packet)->StackIndex.XferDataIndex ++)
  372. #define POP_XFER_DATA_PACKET_STACK(_P) \
  373. (CONTAINING_RECORD(_P, NDIS_PACKET_WRAPPER, Packet)->StackIndex.XferDataIndex --)
  374. #define CURR_XFER_DATA_STACK_LOCATION(_P) \
  375. (CONTAINING_RECORD(_P, NDIS_PACKET_WRAPPER, Packet)->StackIndex.XferDataIndex)
  376. #define GET_CURRENT_PACKET_STACK(_P, _S) \
  377. { \
  378. UINT _SL; \
  379. \
  380. *(_S) = (PNDIS_PACKET_STACK)((PUCHAR)(_P) - SIZE_PACKET_STACKS); \
  381. _SL = CURR_STACK_LOCATION(_P); \
  382. if (_SL < ndisPacketStackSize) \
  383. { \
  384. *(_S) += _SL; \
  385. } \
  386. else \
  387. { \
  388. *(_S) = NULL; \
  389. } \
  390. }
  391. #define GET_CURRENT_XFER_DATA_PACKET_STACK(_P, _O) \
  392. { \
  393. UINT _SL; \
  394. PNDIS_PACKET_STACK _SI; \
  395. \
  396. _SI = (PNDIS_PACKET_STACK)((PUCHAR)(_P) - SIZE_PACKET_STACKS); \
  397. _SL = CURR_XFER_DATA_STACK_LOCATION(_P); \
  398. if (_SL < ndisPacketStackSize * 3) \
  399. { \
  400. _SI += _SL / 3; \
  401. (_O) = ((PNDIS_STACK_RESERVED)_SI->NdisReserved)->Opens[_SL % 3]; \
  402. } \
  403. else \
  404. { \
  405. (_O) = NULL; \
  406. } \
  407. }
  408. #define GET_CURRENT_XFER_DATA_PACKET_STACK_AND_ZERO_OUT(_P, _O) \
  409. { \
  410. UINT _SL, _SLX; \
  411. PNDIS_PACKET_STACK _SI; \
  412. \
  413. _SI = (PNDIS_PACKET_STACK)((PUCHAR)(_P) - SIZE_PACKET_STACKS); \
  414. _SL = CURR_XFER_DATA_STACK_LOCATION(_P); \
  415. if (_SL < ndisPacketStackSize * 3) \
  416. { \
  417. _SI += _SL / 3; \
  418. _SLX = _SL % 3; \
  419. (_O) = ((PNDIS_STACK_RESERVED)_SI->NdisReserved)->Opens[_SLX]; \
  420. ((PNDIS_STACK_RESERVED)_SI->NdisReserved)->Opens[_SLX] = 0; \
  421. } \
  422. else \
  423. { \
  424. (_O) = NULL; \
  425. } \
  426. }
  427. #define SET_CURRENT_XFER_DATA_PACKET_STACK(_P, _O) \
  428. { \
  429. UINT _SL; \
  430. PNDIS_PACKET_STACK _SI; \
  431. \
  432. _SI = (PNDIS_PACKET_STACK)((PUCHAR)(_P) - SIZE_PACKET_STACKS); \
  433. _SL = CURR_XFER_DATA_STACK_LOCATION(_P); \
  434. if (_SL < ndisPacketStackSize * 3) \
  435. { \
  436. _SI += _SL / 3; \
  437. ((PNDIS_STACK_RESERVED)_SI->NdisReserved)->Opens[_SL % 3] = (_O); \
  438. } \
  439. }
  440. //
  441. // this macro returns the current stack location as well whether or not
  442. // there is any stack locations left. (_SR) parameter
  443. //
  444. #define GET_CURRENT_PACKET_STACK_X(_P, _S, _SR) \
  445. { \
  446. UINT _SL; \
  447. \
  448. *(_S) = (PNDIS_PACKET_STACK)((PUCHAR)(_P) - SIZE_PACKET_STACKS); \
  449. _SL = CURR_STACK_LOCATION(_P); \
  450. if (_SL < ndisPacketStackSize) \
  451. { \
  452. *(_S) += _SL; \
  453. *(_SR) = (ndisPacketStackSize - _SL - 1) > 0;\
  454. } \
  455. else \
  456. { \
  457. *(_S) = NULL; \
  458. *(_SR) = FALSE; \
  459. } \
  460. }
  461. #undef NDIS_WRAPPER_HANDLE
  462. #undef PNDIS_WRAPPER_HANDLE
  463. typedef struct _NDIS_WRAPPER_HANDLE
  464. {
  465. PDRIVER_OBJECT DriverObject;
  466. UNICODE_STRING ServiceRegPath;
  467. } NDIS_WRAPPER_HANDLE, *PNDIS_WRAPPER_HANDLE;
  468. typedef struct _POWER_QUERY
  469. {
  470. KEVENT Event;
  471. NTSTATUS Status;
  472. } POWER_QUERY, *PPOWER_QUERY;
  473. #define MINIPORT_DEVICE_MAGIC_VALUE 'PMDN'
  474. #define CUSTOM_DEVICE_MAGIC_VALUE '5IDN'
  475. typedef struct _NDIS_DEVICE_LIST
  476. {
  477. //
  478. // The signature field must be at the same place as the one in the MINIPORT_BLOCK
  479. //
  480. PVOID Signature; // To identify this as a device created for driver
  481. LIST_ENTRY List;
  482. PNDIS_M_DRIVER_BLOCK MiniBlock;
  483. PDEVICE_OBJECT DeviceObject;
  484. PDRIVER_DISPATCH MajorFunctions[IRP_MJ_MAXIMUM_FUNCTION+1];
  485. NDIS_STRING DeviceName;
  486. NDIS_STRING SymbolicLinkName;
  487. } NDIS_DEVICE_LIST, *PNDIS_DEVICE_LIST;
  488. //
  489. // NDIS_WRAPPER_CONTEXT
  490. //
  491. // This data structure contains internal data items for use by the wrapper.
  492. //
  493. typedef struct _NDIS_WRAPPER_CONTEXT
  494. {
  495. //
  496. // Mac/miniport defined shutdown context.
  497. //
  498. PVOID ShutdownContext;
  499. //
  500. // Mac/miniport registered shutdown handler.
  501. //
  502. ADAPTER_SHUTDOWN_HANDLER ShutdownHandler;
  503. //
  504. // Kernel bugcheck record for bugcheck handling.
  505. //
  506. KBUGCHECK_CALLBACK_RECORD BugcheckCallbackRecord;
  507. //
  508. // HAL common buffer cache.
  509. //
  510. PVOID SharedMemoryPage[2];
  511. ULONG SharedMemoryLeft[2];
  512. NDIS_PHYSICAL_ADDRESS SharedMemoryAddress[2];
  513. } NDIS_WRAPPER_CONTEXT, *PNDIS_WRAPPER_CONTEXT;
  514. //
  515. // This is the structure pointed to by the FsContext of an
  516. // open used for query statistics.
  517. //
  518. typedef struct _OID_LIST
  519. {
  520. ULONG StatsOidCount;
  521. ULONG FullOidCount;
  522. PNDIS_OID StatsOidArray;
  523. PNDIS_OID FullOidArray;
  524. } OID_LIST, *POID_LIST;
  525. typedef struct _NDIS_USER_OPEN_CONTEXT
  526. {
  527. PDEVICE_OBJECT DeviceObject;
  528. PNDIS_MINIPORT_BLOCK Miniport;
  529. POID_LIST OidList;
  530. BOOLEAN AdminAccessAllowed;
  531. } NDIS_USER_OPEN_CONTEXT, *PNDIS_USER_OPEN_CONTEXT;
  532. typedef struct _NDIS_DEVICE_OBJECT_OPEN_CONTEXT
  533. {
  534. BOOLEAN AdminAccessAllowed;
  535. UCHAR Padding[3];
  536. } NDIS_DEVICE_OBJECT_OPEN_CONTEXT, *PNDIS_DEVICE_OBJECT_OPEN_CONTEXT;
  537. //
  538. // Used to queue configuration parameters
  539. //
  540. typedef struct _NDIS_CONFIGURATION_PARAMETER_QUEUE
  541. {
  542. struct _NDIS_CONFIGURATION_PARAMETER_QUEUE* Next;
  543. NDIS_CONFIGURATION_PARAMETER Parameter;
  544. } NDIS_CONFIGURATION_PARAMETER_QUEUE, *PNDIS_CONFIGURATION_PARAMETER_QUEUE;
  545. //
  546. // Configuration Handle
  547. //
  548. typedef struct _NDIS_CONFIGURATION_HANDLE
  549. {
  550. PRTL_QUERY_REGISTRY_TABLE KeyQueryTable;
  551. PNDIS_CONFIGURATION_PARAMETER_QUEUE ParameterList;
  552. } NDIS_CONFIGURATION_HANDLE, *PNDIS_CONFIGURATION_HANDLE;
  553. //
  554. // This is used during addadapter/miniportinitialize so that when the
  555. // driver calls any NdisImmediatexxx routines we can access its driverobj.
  556. //
  557. typedef struct _NDIS_WRAPPER_CONFIGURATION_HANDLE
  558. {
  559. RTL_QUERY_REGISTRY_TABLE ParametersQueryTable[5];
  560. PDRIVER_OBJECT DriverObject;
  561. PDEVICE_OBJECT DeviceObject;
  562. PUNICODE_STRING DriverBaseName;
  563. } NDIS_WRAPPER_CONFIGURATION_HANDLE, *PNDIS_WRAPPER_CONFIGURATION_HANDLE;
  564. //
  565. // one of these per protocol registered
  566. //
  567. typedef struct _NDIS_PROTOCOL_BLOCK
  568. {
  569. PNDIS_OPEN_BLOCK OpenQueue; // queue of opens for this protocol
  570. REFERENCE Ref; // contains spinlock for OpenQueue
  571. PKEVENT DeregEvent; // Used by NdisDeregisterProtocol
  572. struct _NDIS_PROTOCOL_BLOCK * NextProtocol; // Link to next
  573. NDIS50_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics;// handler addresses
  574. WORK_QUEUE_ITEM WorkItem; // Used during NdisRegisterProtocol to
  575. // notify protocols of existing drivers.
  576. KMUTEX Mutex; // For serialization of Bind/Unbind requests
  577. ULONG MutexOwner; // For debugging
  578. PNDIS_STRING BindDeviceName;
  579. PNDIS_STRING RootDeviceName;
  580. PNDIS_M_DRIVER_BLOCK AssociatedMiniDriver;
  581. PNDIS_MINIPORT_BLOCK BindingAdapter;
  582. } NDIS_PROTOCOL_BLOCK, *PNDIS_PROTOCOL_BLOCK;
  583. //
  584. // Context for Bind Adapter.
  585. //
  586. typedef struct _NDIS_BIND_CONTEXT
  587. {
  588. struct _NDIS_BIND_CONTEXT * Next;
  589. PNDIS_PROTOCOL_BLOCK Protocol;
  590. PNDIS_MINIPORT_BLOCK Miniport;
  591. NDIS_STRING ProtocolSection;
  592. PNDIS_STRING DeviceName;
  593. WORK_QUEUE_ITEM WorkItem;
  594. NDIS_STATUS BindStatus;
  595. KEVENT Event;
  596. KEVENT ThreadDoneEvent;
  597. } NDIS_BIND_CONTEXT, *PNDIS_BIND_CONTEXT;
  598. //
  599. // Describes an open NDIS file
  600. //
  601. typedef struct _NDIS_FILE_DESCRIPTOR
  602. {
  603. PVOID Data;
  604. KSPIN_LOCK Lock;
  605. BOOLEAN Mapped;
  606. } NDIS_FILE_DESCRIPTOR, *PNDIS_FILE_DESCRIPTOR;
  607. #if defined(_ALPHA_)
  608. typedef struct _NDIS_LOOKAHEAD_ELEMENT
  609. {
  610. ULONG Length;
  611. struct _NDIS_LOOKAHEAD_ELEMENT *Next;
  612. } NDIS_LOOKAHEAD_ELEMENT, *PNDIS_LOOKAHEAD_ELEMENT;
  613. #endif
  614. typedef struct _PKG_REF
  615. {
  616. LONG ReferenceCount;
  617. BOOLEAN PagedIn;
  618. PVOID Address;
  619. PVOID ImageHandle;
  620. } PKG_REF, *PPKG_REF;
  621. //
  622. // Structures for dealing with making the module specific routines pagable
  623. //
  624. typedef enum _PKG_TYPE
  625. {
  626. NDSP_PKG,
  627. NDSM_PKG,
  628. NPNP_PKG,
  629. NDCO_PKG,
  630. NDSE_PKG,
  631. NDSF_PKG,
  632. NDST_PKG,
  633. #if ARCNET
  634. NDSA_PKG,
  635. #endif
  636. MAX_PKG
  637. } PKG_TYPE;
  638. #define NDIS_PNP_MINIPORT_DRIVER_ID 'NMID'
  639. #define NDIS_PNP_MAC_DRIVER_ID 'NFID'
  640. #define MINIPORT_SIGNATURE 'MPRT'
  641. typedef struct _NDIS_SHARED_MEM_SIGNATURE
  642. {
  643. ULONG Tag;
  644. ULONG PageRef;
  645. } NDIS_SHARED_MEM_SIGNATURE, *PNDIS_SHARED_MEM_SIGNATURE ;
  646. #define NDIS_MAXIMUM_SCATTER_GATHER_SEGMENTS 16
  647. __inline
  648. VOID
  649. ConvertSecondsToTicks(
  650. IN ULONG Seconds,
  651. OUT PLARGE_INTEGER Ticks
  652. );
  653. #if defined(_WIN64)
  654. typedef struct _NDIS_INTERFACE32
  655. {
  656. UNICODE_STRING32 DeviceName;
  657. UNICODE_STRING32 DeviceDescription;
  658. } NDIS_INTERFACE32, *PNDIS_INTERFACE32;
  659. typedef struct _NDIS_ENUM_INTF32
  660. {
  661. UINT TotalInterfaces;
  662. UINT AvailableInterfaces;
  663. UINT BytesNeeded;
  664. UINT Reserved;
  665. NDIS_INTERFACE32 Interface[1];
  666. } NDIS_ENUM_INTF32, *PNDIS_ENUM_INTF32;
  667. typedef struct _NDIS_VAR_DATA_DESC32
  668. {
  669. USHORT Length;
  670. USHORT MaximumLength;
  671. ULONG Offset;
  672. } NDIS_VAR_DATA_DESC32, *PNDIS_VAR_DATA_DESC32;
  673. typedef struct _NDIS_PNP_OPERATION32
  674. {
  675. UINT Layer;
  676. UINT Operation;
  677. union
  678. {
  679. ULONG ReConfigBufferPtr;
  680. ULONG ReConfigBufferOff;
  681. };
  682. UINT ReConfigBufferSize;
  683. NDIS_VAR_DATA_DESC32 LowerComponent;
  684. NDIS_VAR_DATA_DESC32 UpperComponent;
  685. NDIS_VAR_DATA_DESC32 BindList;
  686. } NDIS_PNP_OPERATION32, *PNDIS_PNP_OPERATION32;
  687. #endif // _WIN64
  688. //
  689. // These are now obsolete. Use Deserialized driver model for optimal performance.
  690. //
  691. EXPORT
  692. NDIS_STATUS
  693. NdisIMQueueMiniportCallback(
  694. IN NDIS_HANDLE MiniportAdapterHandle,
  695. IN W_MINIPORT_CALLBACK CallbackRoutine,
  696. IN PVOID CallbackContext
  697. );
  698. EXPORT
  699. BOOLEAN
  700. NdisIMSwitchToMiniport(
  701. IN NDIS_HANDLE MiniportAdapterHandle,
  702. OUT PNDIS_HANDLE SwitchHandle
  703. );
  704. EXPORT
  705. VOID
  706. NdisIMRevertBack(
  707. IN NDIS_HANDLE MiniportAdapterHandle,
  708. IN NDIS_HANDLE SwitchHandle
  709. );
  710. typedef struct _NDIS_MAC_CHARACTERISTICS
  711. {
  712. UCHAR MajorNdisVersion;
  713. UCHAR MinorNdisVersion;
  714. USHORT Filler;
  715. UINT Reserved;
  716. PVOID OpenAdapterHandler;
  717. PVOID CloseAdapterHandler;
  718. SEND_HANDLER SendHandler;
  719. TRANSFER_DATA_HANDLER TransferDataHandler;
  720. RESET_HANDLER ResetHandler;
  721. REQUEST_HANDLER RequestHandler;
  722. PVOID QueryGlobalStatisticsHandler;
  723. PVOID UnloadMacHandler;
  724. PVOID AddAdapterHandler;
  725. PVOID RemoveAdapterHandler;
  726. NDIS_STRING Name;
  727. } NDIS_MAC_CHARACTERISTICS, *PNDIS_MAC_CHARACTERISTICS;
  728. typedef struct _NDIS_MAC_BLOCK
  729. {
  730. PVOID AdapterQueue; // queue of adapters for this MAC
  731. NDIS_HANDLE MacMacContext; // Context for calling MACUnload and
  732. // MACAddAdapter.
  733. REFERENCE Ref; // contains spinlock for AdapterQueue
  734. PVOID PciAssignedResources;
  735. PVOID NextMac;
  736. //
  737. // The offset to MacCharacteristics need to be preserved. Older protocols directly referenced this.
  738. //
  739. NDIS_MAC_CHARACTERISTICS MacCharacteristics; // handler addresses
  740. PVOID NdisMacInfo; // Mac information.
  741. KEVENT AdaptersRemovedEvent; // used to find when all adapters are gone.
  742. BOOLEAN Unloading; // TRUE if unloading
  743. } NDIS_MAC_BLOCK, *PNDIS_MAC_BLOCK;
  744. PVOID
  745. GetSystemRoutineAddress (
  746. IN PUNICODE_STRING SystemRoutineName
  747. );
  748. PVOID
  749. FindExportedRoutineByName (
  750. IN PVOID DllBase,
  751. IN PANSI_STRING AnsiImageRoutineName
  752. );
  753. typedef struct _NDIS_TRACK_MEM
  754. {
  755. LIST_ENTRY List;
  756. ULONG Tag;
  757. UINT Length;
  758. PVOID Caller;
  759. PVOID CallersCaller;
  760. } NDIS_TRACK_MEM, *PNDIS_TRACK_MEM;
  761. typedef struct _NDIS_DEFERRED_REQUEST_WORKITEM
  762. {
  763. NDIS_WORK_ITEM WorkItem;
  764. PVOID Caller;
  765. PVOID CallersCaller;
  766. PNDIS_REQUEST Request;
  767. PNDIS_OPEN_BLOCK Open;
  768. NDIS_OID Oid;
  769. PVOID InformationBuffer;
  770. } NDIS_DEFERRED_REQUEST_WORKITEM, *PNDIS_DEFERRED_REQUEST_WORKITEM;
  771. // #define NDIS_MINIPORT_USES_MAP_REGISTERS 0x01000000
  772. // #define NDIS_MINIPORT_USES_SHARED_MEMORY 0x02000000
  773. // #define NDIS_MINIPORT_USES_IO 0x04000000
  774. // #define NDIS_MINIPORT_USES_MEMORY 0x08000000
  775. #if !NDIS_RECV_SCALE
  776. //
  777. // move this to ndismini.w for blackcomb
  778. //
  779. typedef struct _NDIS_MINIPORT_INTERRUPT_EX
  780. {
  781. PKINTERRUPT InterruptObject;
  782. KSPIN_LOCK DpcCountLock;
  783. union
  784. {
  785. PVOID Reserved;
  786. PVOID InterruptContext;
  787. };
  788. W_ISR_HANDLER MiniportIsr;
  789. W_HANDLE_INTERRUPT_HANDLER MiniportDpc;
  790. KDPC InterruptDpc;
  791. PNDIS_MINIPORT_BLOCK Miniport;
  792. UCHAR DpcCount;
  793. BOOLEAN Filler1;
  794. //
  795. // This is used to tell when all the Dpcs for the adapter are completed.
  796. //
  797. KEVENT DpcsCompletedEvent;
  798. BOOLEAN SharedInterrupt;
  799. BOOLEAN IsrRequested;
  800. struct _NDIS_MINIPORT_INTERRUPT_EX *NextInterrupt;
  801. } NDIS_MINIPORT_INTERRUPT_EX, *PNDIS_MINIPORT_INTERRUPT_EX;
  802. NDIS_STATUS
  803. NdisMRegisterInterruptEx(
  804. OUT PNDIS_MINIPORT_INTERRUPT_EX Interrupt,
  805. IN NDIS_HANDLE MiniportAdapterHandle,
  806. IN UINT InterruptVector,
  807. IN UINT InterruptLevel,
  808. IN BOOLEAN RequestIsr,
  809. IN BOOLEAN SharedInterrupt,
  810. IN NDIS_INTERRUPT_MODE InterruptMode
  811. );
  812. VOID
  813. NdisMDeregisterInterruptEx(
  814. IN PNDIS_MINIPORT_INTERRUPT_EX MiniportInterrupt
  815. );
  816. //
  817. // for interrupts registered with NdisMRegisterInterruptEx
  818. // BOOLEAN
  819. // NdisMSynchronizeWithInterruptEx(
  820. // IN PNDIS_MINIPORT_INTERRUPT_EX Interrupt,
  821. // IN PVOID SynchronizeFunction,
  822. // IN PVOID SynchronizeContext
  823. // );
  824. #define NdisMSynchronizeWithInterruptEx(_Interrupt, _SynchronizeFunction, _SynchronizeContext) \
  825. NdisMSynchronizeWithInterrupt((PNDIS_MINIPORT_INTERRUPT)(_Interrupt), _SynchronizeFunction, _SynchronizeContext)
  826. #endif
  827. #define NDIS_ORIGINAL_STATUS_FROM_PACKET(_Packet) ((PVOID)(_Packet)->Reserved[0])
  828. #define NDIS_DOUBLE_BUFFER_INFO_FROM_PACKET(_P) NDIS_PER_PACKET_INFO_FROM_PACKET(_P, NdisReserved)
  829. #define NDIS_MAX_USER_OPEN_HANDLES 0x01000000
  830. #define NDIS_MAX_ADMIN_OPEN_HANDLES 0x01000000
  831. #define NDIS_RESERVED_REF_COUNTS (0xffffffff - NDIS_MAX_USER_OPEN_HANDLES - NDIS_RESERVED_REF_COUNTS)
  832. #define NDIS_USER_OPEN_WAIT_TIME 50 // wait time in milliseconds
  833. /*
  834. #define WPP_CONTROL_GUIDS \
  835. WPP_DEFINE_CONTROL_GUID(Ndis,(5b5a3f4e,a33b,4d79,bbb7,97f46ac4d889), \
  836. WPP_DEFINE_BIT(NdisDebugFatal) \
  837. WPP_DEFINE_BIT(NdisDebugError) \
  838. WPP_DEFINE_BIT(NdisDebugWarn) \
  839. WPP_DEFINE_BIT(NdisDebugLog) \
  840. WPP_DEFINE_BIT(NdisDebugInfo) \
  841. )
  842. */
  843. /*
  844. NTSTATUS
  845. ndisSetWmiSecurity(
  846. IN PNDIS_GUID NdisGuid
  847. );
  848. */
  849. #endif // _WRAPPER_