Source code of Windows XP (NT5)
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.

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