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.

1024 lines
39 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. Module Name:
  4. Wandefs.h
  5. Abstract:
  6. This file contains defines for the NdisWan driver.
  7. Author:
  8. Tony Bell (TonyBe) June 06, 1995
  9. Environment:
  10. Kernel Mode
  11. Revision History:
  12. TonyBe 06/06/95 Created
  13. --*/
  14. #ifndef _NDISWAN_DEFS_
  15. #define _NDISWAN_DEFS_
  16. //
  17. // This needs to be added into ndis.h
  18. //
  19. #define SAP_TYPE_NDISWAN_PPP 0x00000004
  20. //
  21. // Device class currently used by RAS to query TAPI
  22. // miniports for the connection wrapper ID
  23. //
  24. #define DEVICECLASS_NDISWAN_SAP L"NDIS"
  25. //
  26. // Define if we are going to pull the miniport name out of
  27. // an ndis wrapper control structure!!!!!! (kinda dirty)
  28. //
  29. #define MINIPORT_NAME 1
  30. //
  31. // Version stuff
  32. //
  33. #define NDISWAN_MAJOR_VERSION 5
  34. #define NDISWAN_MINOR_VERSION 0
  35. //
  36. // Maximum number of protocols we can support
  37. //
  38. #define MAX_PROTOCOLS 32
  39. //
  40. // Identifiers for protocol type being added to the
  41. // protocol lookup table
  42. //
  43. #define PROTOCOL_TYPE 0
  44. #define PPP_TYPE 1
  45. //
  46. // Flags for Send packet properties
  47. //
  48. #define SEND_ON_WIRE 0x00000001
  49. #define SELF_DIRECTED 0x00000002
  50. #define MAC_HEADER_LENGTH 14
  51. #define PROTOCOL_HEADER_LENGTH 128
  52. //
  53. // Maximum length possible for a ppp header
  54. // No addr/ctrl comp (2)
  55. // No proto id comp
  56. // multilink large sequence #'s (6)
  57. // MPPC/MPPE (6)
  58. // Protocol (2)
  59. //
  60. #define MAX_PPP_HEADER_LENGTH 14
  61. // No addr/ctrl comp (4)
  62. // No proto id comp
  63. // multilink large sequence #'s (6)
  64. // MPPC/MPPE (6)
  65. // Protocol (2)
  66. //
  67. #define MAX_PPP_LLC_HEADER_LENGTH 16
  68. //
  69. // Known protocol ID's
  70. //
  71. #define PROTOCOL_PRIVATE_IO 0xAB00
  72. #define PROTOCOL_IP 0x0800
  73. #define PROTOCOL_IPX 0x8137
  74. #define PROTOCOL_NBF 0x80D5
  75. #define PROTOCOL_APPLETALK 0x80F3
  76. //
  77. // Returned from protocol table lookup if value is
  78. // not found
  79. //
  80. #define RESERVED_PROTOCOLCB (IntToPtr(0xFFFFFFFF))
  81. //
  82. // OID Masks
  83. //
  84. #define OID_GEN 0x00000000
  85. #define OID_CO_GEN 0x00000000
  86. #define OID_802_3 0x01000000
  87. #define OID_WAN 0x04000000
  88. #define OID_PNP 0xFD000000
  89. #define OID_QOS 0xFB000000
  90. #define DEFAULT_MRU 1614
  91. #define DEFAULT_MRRU 1614
  92. #define DEFAULT_TUNNEL_MTU 1400
  93. #define MAX_RECVDESC_COUNT 64
  94. //
  95. // Known PPP protocol ID's
  96. //
  97. #define PPP_PROTOCOL_PRIVATE_IO 0x00AB
  98. #define PPP_PROTOCOL_IP 0x0021
  99. #define PPP_PROTOCOL_APPLETALK 0x0029
  100. #define PPP_PROTOCOL_UNCOMPRESSED_TCP 0x002F
  101. #define PPP_PROTOCOL_COMPRESSED_TCP 0x002D
  102. #define PPP_PROTOCOL_IPX 0x002B
  103. #define PPP_PROTOCOL_NBF 0x003F
  104. #define PPP_PROTOCOL_COMPRESSION 0x00FD
  105. #define PPP_PROTOCOL_COMP_RESET 0x80FD
  106. //
  107. //
  108. //
  109. #define DEFAULT_MTU 1500
  110. #define MAX_OUTSTANDING_PACKETS 10
  111. #define ONE_HUNDRED_MILS 1000000
  112. #define ONE_SECOND 10000000
  113. #define TEN_SECONDS 100000000
  114. #define MILS_TO_100NANOS 10000
  115. #define SAMPLE_ARRAY_SIZE 10
  116. #define DEFAULT_PACKETQUEUE_DEPTH 128*1024
  117. #define DEFAULT_MIN_FRAG_SIZE 64
  118. //
  119. // Multilink defines
  120. //
  121. #define MULTILINK_BEGIN_FRAME 0x80
  122. #define MULTILINK_END_FRAME 0x40
  123. #define MULTILINK_COMPLETE_FRAME 0xC0
  124. #define MULTILINK_FLAG_MASK 0xC0
  125. #define MULTILINK_HOLE_FLAG 0x01
  126. #define SHORT_SEQ_MASK 0x0FFF
  127. #define TEST_SHORT_SEQ 0x0800
  128. #define LONG_SEQ_MASK 0x0FFFFFF
  129. #define TEST_LONG_SEQ 0x00800000
  130. #define MCML_SHORTCLASS_MASK 0x30
  131. #define MCML_LONGCLASS_MASK 0x3C
  132. #define MAX_MCML 1
  133. //
  134. // Memory tags
  135. //
  136. #define BUNDLECB_TAG 'AnaW'
  137. #define LINKPROTOCB_TAG 'BnaW'
  138. #define SMALLDATADESC_TAG 'CnaW'
  139. #define MEDIUMDATADESC_TAG 'DnaW'
  140. #define LARGEDATADESC_TAG 'EnaW'
  141. #define WANREQUEST_TAG 'FnaW'
  142. #define LOOPBACKDESC_TAG 'GnaW'
  143. #define VJCOMPRESS_TAG 'HnaW'
  144. #define MINIPORTCB_TAG 'InaW'
  145. #define OPENCB_TAG 'JnaW'
  146. #define IOPACKET_TAG 'KnaW'
  147. #define LINEUPINFO_TAG 'Lnaw'
  148. #define NDISSTRING_TAG 'MnaW'
  149. #define PROTOCOLTABLE_TAG 'NnaW'
  150. #define CONNECTIONTABLE_TAG 'OnaW'
  151. #define POOLDESC_TAG 'PnaW'
  152. #define DATABUFFER_TAG 'QnaW'
  153. #define WANPACKET_TAG 'RnaW'
  154. #define AFSAPVCCB_TAG 'SnaW'
  155. #define TRANSDRV_TAG 'TnaW'
  156. #define BONDALLOC_TAG 'UnaW'
  157. #define ENCRYPTCTX_TAG 'VnaW'
  158. #define COMPCTX_TAG 'XnaW'
  159. #define PROTOCOLCB_TAG 'ZnaW'
  160. #define CACHEDKEY_TAG 'ANaW'
  161. #if DBG
  162. #define DBGPACKET_TAG 'znaW'
  163. #define WANTRCEVENT_TAG 'ynaW'
  164. #endif
  165. #define RECVDESC_SIG 'vceR'
  166. #define SENDESC_SIG 'dneS'
  167. #define CLAFSAP_SIG ' lC'
  168. #define CMAFSAP_SIG ' mC'
  169. #define CMVC_SIG 'cVmC'
  170. #define LINKCB_SIG 'kniL'
  171. #define PROTOCB_SIG 'torP'
  172. #define SEQ_EQ(_a, _b) ((int)((_a) - (_b)) == 0)
  173. #define SEQ_LT(_a, _b, _t) (!SEQ_EQ(_a, _b) && ((int)((_a) - (_b)) & _t))
  174. #define SEQ_LTE(_a, _b, _t) (SEQ_EQ(_a, _b) || ((int)((_a) - (_b)) & _t))
  175. #define SEQ_GT(_a, _b, _t) (!SEQ_EQ(_a, _b) && !((int)((_a) - (_b)) & _t))
  176. #define SEQ_GTE(_a, _b, _t) (SEQ_EQ(_a, _b) || !((int)((_a) - (_b)) & _t))
  177. //
  178. // Link State's
  179. //
  180. typedef enum _LinkState {
  181. LINK_DOWN,
  182. LINK_GOING_DOWN,
  183. LINK_UP
  184. } LinkState;
  185. //
  186. // Bundle State's
  187. //
  188. typedef enum _BundleState {
  189. BUNDLE_DOWN,
  190. BUNDLE_GOING_DOWN,
  191. BUNDLE_UP
  192. } BundleState;
  193. //
  194. // Protocol State's
  195. //
  196. typedef enum _ProtocolState {
  197. PROTOCOL_UNROUTED,
  198. PROTOCOL_UNROUTING,
  199. PROTOCOL_ROUTING,
  200. PROTOCOL_ROUTED
  201. } ProtocolState;
  202. //
  203. // Cm Vc State's
  204. //
  205. typedef enum _CmVcState {
  206. CMVC_CREATED,
  207. CMVC_ACTIVE,
  208. CMVC_CLOSE_DISPATCHED,
  209. CMVC_CLOSING,
  210. CMVC_DEACTIVE
  211. } CmVcState;
  212. typedef enum _ClCallState {
  213. CL_CALL_CLOSED,
  214. CL_CALL_CLOSE_PENDING,
  215. CL_CALL_CONNECTED
  216. } ClCallState;
  217. typedef enum _TransDrvState {
  218. TRANSDRV_OPENING,
  219. TRANSDRV_REGISTERING,
  220. TRANSDRV_OPENED,
  221. TRANSDRV_CLOSED
  222. } TransDrvState;
  223. //
  224. // Wan request types
  225. //
  226. typedef enum _WanRequestType {
  227. ASYNC,
  228. SYNC
  229. } WanRequestType;
  230. typedef enum _WanRequestOrigin {
  231. NDISWAN,
  232. NDISTAPI
  233. } WanRequestOrigin;
  234. typedef enum _RECV_TYPE {
  235. RECV_LINK,
  236. RECV_BUNDLE_PPP,
  237. RECV_BUNDLE_DATA
  238. } RECV_TYPE;
  239. typedef enum _SEND_TYPE {
  240. SEND_LINK,
  241. SEND_BUNDLE_PPP,
  242. SEND_BUNDLE_DATA
  243. } SEND_TYPE;
  244. typedef enum _BandwidthOnDemandState {
  245. BonDSignaled,
  246. BonDIdle,
  247. BonDMonitor
  248. } BandwithOnDemandState;
  249. #ifdef CHECK_BUNDLE_LOCK
  250. #define AcquireBundleLock(_pbcb) \
  251. { \
  252. NdisAcquireSpinLock(&(_pbcb)->Lock); \
  253. ASSERT(!(_pbcb)->LockAcquired); \
  254. (_pbcb)->LockLine = __LINE__; \
  255. (_pbcb)->LockFile = __FILE_SIG__; \
  256. (_pbcb)->LockAcquired = TRUE; \
  257. }
  258. #define ReleaseBundleLock(_pbcb) \
  259. { \
  260. (_pbcb)->LockLine = __LINE__; \
  261. (_pbcb)->LockAcquired = FALSE; \
  262. NdisReleaseSpinLock(&(_pbcb)->Lock); \
  263. }
  264. #else
  265. #define AcquireBundleLock(_pbcb) \
  266. NdisAcquireSpinLock(&(_pbcb)->Lock)
  267. #define ReleaseBundleLock(_pbcb) \
  268. NdisReleaseSpinLock(&(_pbcb)->Lock)
  269. #endif
  270. #define REF_NDISWANCB()\
  271. InterlockedIncrement(&NdisWanCB.RefCount)
  272. #define DEREF_NDISWANCB() \
  273. NdisWanInterlockedDec(&NdisWanCB.RefCount)
  274. #define REF_BUNDLECB(_pbcb) \
  275. { \
  276. (_pbcb)->RefCount++; \
  277. }
  278. //
  279. // Decrement the reference count on the bundle. If the count
  280. // goes to zero we need to remove the bundle from the connection
  281. // table and free it.
  282. //
  283. #define DEREF_BUNDLECB(_pbcb) \
  284. { \
  285. if ((_pbcb) != NULL) { \
  286. AcquireBundleLock(_pbcb); \
  287. ASSERT((_pbcb)->RefCount > 0); \
  288. if (--(_pbcb)->RefCount == 0) { \
  289. DoDerefBundleCBWork(_pbcb); \
  290. } else { \
  291. ReleaseBundleLock(_pbcb); \
  292. } \
  293. } \
  294. }
  295. //
  296. // Decrement the reference count on the bundle. If the count
  297. // goes to zero we need to remove the bundle from the connection
  298. // table and free it.
  299. //
  300. // Called with BundleCB->Lock held but returns with it released!
  301. //
  302. #define DEREF_BUNDLECB_LOCKED(_pbcb) \
  303. { \
  304. if ((_pbcb) != NULL) { \
  305. ASSERT((_pbcb)->RefCount > 0); \
  306. if (--(_pbcb)->RefCount == 0) { \
  307. DoDerefBundleCBWork(_pbcb); \
  308. } else { \
  309. ReleaseBundleLock(_pbcb); \
  310. } \
  311. } \
  312. }
  313. #define REF_LINKCB(_plcb) \
  314. { \
  315. ASSERT((_plcb)->RefCount > 0); \
  316. (_plcb)->RefCount++; \
  317. }
  318. //
  319. // Decrement the reference count on the link. If the count
  320. // goes to zero we need to remove the link from the connection
  321. // table and free it.
  322. //
  323. #define DEREF_LINKCB(_plcb) \
  324. { \
  325. if ((_plcb) != NULL) { \
  326. NdisAcquireSpinLock(&(_plcb)->Lock); \
  327. ASSERT((_plcb)->RefCount > 0); \
  328. if (--(_plcb)->RefCount == 0) { \
  329. DoDerefLinkCBWork(_plcb); \
  330. } else { \
  331. NdisReleaseSpinLock(&(_plcb)->Lock); \
  332. } \
  333. } \
  334. }
  335. //
  336. // Decrement the reference count on the link. If the count
  337. // goes to zero we need to remove the link from the connection
  338. // table and free it.
  339. //
  340. // Called with LinkCB->Lock held but returns with it released!
  341. //
  342. #define DEREF_LINKCB_LOCKED(_plcb) \
  343. { \
  344. if ((_plcb) != NULL) { \
  345. PBUNDLECB _pbcb = (_plcb)->BundleCB; \
  346. ASSERT((_plcb)->RefCount > 0); \
  347. if (--(_plcb)->RefCount == 0) { \
  348. DoDerefLinkCBWork(_plcb); \
  349. } else { \
  350. NdisReleaseSpinLock(&(_plcb)->Lock); \
  351. } \
  352. } \
  353. }
  354. #define REF_PROTOCOLCB(_ppcb) \
  355. { \
  356. ASSERT((_ppcb)->RefCount > 0); \
  357. (_ppcb)->RefCount++; \
  358. }
  359. #define DEREF_PROTOCOLCB(_ppcb) \
  360. { \
  361. ASSERT((_ppcb)->RefCount > 0); \
  362. if (--(_ppcb)->RefCount == 0) { \
  363. ASSERT((_ppcb)->OutstandingFrames == 0); \
  364. ASSERT((_ppcb)->State == PROTOCOL_UNROUTING); \
  365. NdisWanSetSyncEvent(&(_ppcb)->UnrouteEvent); \
  366. RemoveProtocolCBFromBundle(ProtocolCB); \
  367. } \
  368. }
  369. #define REF_OPENCB(_pocb) \
  370. InterlockedIncrement(&(_pocb)->RefCount)
  371. #define DEREF_OPENCB(_pocb) \
  372. { \
  373. if (InterlockedDecrement(&(_pocb)->RefCount) == 0) { \
  374. NdisAcquireSpinLock(&(_pocb)->Lock); \
  375. ProtoCloseWanAdapter(_pocb); \
  376. } \
  377. }
  378. #define REF_MINIPORTCB(_pmcb) \
  379. InterlockedIncrement(&(_pmcb)->RefCount)
  380. #define DEREF_MINIPORTCB(_pmcb) \
  381. { \
  382. if (InterlockedDecrement(&(_pmcb)->RefCount) == 0) { \
  383. NdisWanFreeMiniportCB(_pmcb); \
  384. } \
  385. }
  386. #define REF_CMVCCB(_pvccb) \
  387. InterlockedIncrement(&(_pvccb)->RefCount)
  388. #define DEREF_CMVCCB(_pvccb) \
  389. { \
  390. if (InterlockedDecrement(&(_pvccb)->RefCount) == 0) { \
  391. DoDerefCmVcCBWork(_pvccb); \
  392. } \
  393. }
  394. #define REF_CLAFSAPCB(_pclaf) \
  395. (_pclaf)->RefCount++;
  396. #define DEREF_CLAFSAPCB(_pclaf) \
  397. { \
  398. NdisAcquireSpinLock(&((_pclaf)->Lock)); \
  399. if (--(_pclaf)->RefCount == 0) { \
  400. DoDerefClAfSapCBWork(_pclaf); \
  401. } else { \
  402. NdisReleaseSpinLock(&((_pclaf)->Lock)); \
  403. } \
  404. }
  405. #define DEREF_CLAFSAPCB_LOCKED(_pclaf) \
  406. { \
  407. if (--(_pclaf)->RefCount == 0) { \
  408. DoDerefClAfSapCBWork(_pclaf); \
  409. } else { \
  410. NdisReleaseSpinLock(&((_pclaf)->Lock)); \
  411. } \
  412. }
  413. #define BUNDLECB_FROM_LINKCB(_ppbcb, _plcb) \
  414. { \
  415. *(_ppbcb) = (PBUNDLECB)_plcb->BundleCB; \
  416. }
  417. #define BUNDLECB_FROM_BUNDLEH(_ppbcb, _bh) \
  418. { \
  419. LOCK_STATE _ls; \
  420. PBUNDLECB _bcb = NULL; \
  421. NdisAcquireReadWriteLock(&ConnTableLock, FALSE, &_ls); \
  422. if ((ULONG_PTR)(_bh) <= ConnectionTable->ulArraySize) { \
  423. _bcb = *(ConnectionTable->BundleArray + (ULONG_PTR)(_bh));\
  424. } \
  425. if (_bcb != NULL) { \
  426. NdisDprAcquireSpinLock(&(_bcb)->Lock); \
  427. REF_BUNDLECB(_bcb); \
  428. NdisDprReleaseSpinLock(&(_bcb)->Lock); \
  429. } \
  430. NdisReleaseReadWriteLock(&ConnTableLock, &_ls); \
  431. *(_ppbcb) = _bcb; \
  432. }
  433. #define LINKCB_FROM_LINKH(_pplcb, _lh) \
  434. { \
  435. LOCK_STATE _ls; \
  436. PLINKCB _lcb = NULL; \
  437. NdisAcquireReadWriteLock(&ConnTableLock, FALSE, &_ls); \
  438. if ((ULONG_PTR)(_lh) <= ConnectionTable->ulArraySize) { \
  439. _lcb = *(ConnectionTable->LinkArray + (ULONG_PTR)(_lh));\
  440. } \
  441. if (_lcb != NULL) { \
  442. NdisDprAcquireSpinLock(&(_lcb)->Lock); \
  443. REF_LINKCB(_lcb); \
  444. NdisDprReleaseSpinLock(&(_lcb)->Lock); \
  445. } \
  446. NdisReleaseReadWriteLock(&ConnTableLock, &_ls); \
  447. *(_pplcb) = _lcb; \
  448. }
  449. #define InsertTailGlobalList(_gl, _ple) \
  450. { \
  451. NdisAcquireSpinLock(&(_gl.Lock)); \
  452. InsertTailList(&(_gl.List), (_ple)); \
  453. _gl.ulCount++; \
  454. if (_gl.ulCount > _gl.ulMaxCount) { \
  455. _gl.ulMaxCount = _gl.ulCount; \
  456. } \
  457. NdisReleaseSpinLock(&(_gl.Lock)); \
  458. }
  459. #define InsertTailGlobalListEx(_gl, _ple, _t, _pt) \
  460. { \
  461. NdisAcquireSpinLock(&(_gl.Lock)); \
  462. InsertTailList(&(_gl.List), (_ple)); \
  463. _gl.ulCount++; \
  464. if (_gl.ulCount > _gl.ulMaxCount) { \
  465. _gl.ulMaxCount = _gl.ulCount; \
  466. } \
  467. if (!_gl.TimerScheduled) { \
  468. LARGE_INTEGER _ft; \
  469. _gl.TimerScheduled = TRUE; \
  470. _ft.QuadPart = Int32x32To64(_t, -10000); \
  471. KeSetTimerEx(&_gl.Timer, _ft, _pt, &_gl.Dpc); \
  472. } \
  473. NdisReleaseSpinLock(&(_gl.Lock)); \
  474. }
  475. #define InsertHeadGlobalList(_gl, _ple) \
  476. { \
  477. NdisAcquireSpinLock(&(_gl.Lock)); \
  478. InsertHeadList(&(_gl.List), (_ple)); \
  479. _gl.ulCount++; \
  480. if (_gl.ulCount > _gl.ulMaxCount) { \
  481. _gl.ulMaxCount = _gl.ulCount; \
  482. } \
  483. NdisReleaseSpinLock(&(_gl.Lock)); \
  484. }
  485. #define InsertHeadGlobalListEx(_gl, _ple, _t, _pt) \
  486. { \
  487. NdisAcquireSpinLock(&(_gl.Lock)); \
  488. InsertHeadList(&(_gl.List), (_ple)); \
  489. _gl.ulCount++; \
  490. if (_gl.ulCount > _gl.ulMaxCount) { \
  491. _gl.ulMaxCount = _gl.ulCount; \
  492. } \
  493. if (!_gl.TimerScheduled) { \
  494. LARGE_INTEGER _ft; \
  495. _gl.TimerScheduled = TRUE; \
  496. _ft.QuadPart = Int32x32To64(_t, -10000); \
  497. KeSetTimerEx(&_gl.Timer, _ft, _pt, &_gl.Dpc); \
  498. } \
  499. NdisReleaseSpinLock(&(_gl.Lock)); \
  500. }
  501. #define RemoveHeadGlobalList(_gl, _pple) \
  502. { \
  503. NdisAcquireSpinLock(&(_gl.Lock)); \
  504. *(_pple) = RemoveHeadList(&(_gl.List)); \
  505. _gl.ulCount--; \
  506. NdisReleaseSpinLock(&(_gl.Lock)); \
  507. }
  508. #define RemoveEntryGlobalList(_gl, _ple) \
  509. { \
  510. NdisAcquireSpinLock(&(_gl.Lock)); \
  511. RemoveEntryList(_ple); \
  512. _gl.ulCount--; \
  513. NdisReleaseSpinLock(&(_gl.Lock)); \
  514. }
  515. #if 0
  516. //
  517. // The Remote address (DEST address) is what we use to mutilplex
  518. // sends across our single adapter/binding context. The address
  519. // has the following format:
  520. //
  521. // XX XX YY YY YY YY
  522. //
  523. // XX = Randomly generated OUI
  524. // YY = ProtocolCB
  525. //
  526. #define FillNdisWanHdrContext(_pAddr, _ppcb) \
  527. *((ULONG UNALIGNED*)(&_pAddr[2])) = *((ULONG UNALIGNED*)(&_ppcb))
  528. #define GetNdisWanHdrContext(_pAddr, _pppcb) \
  529. *((ULONG UNALIGNED*)(_pppcb)) = *((ULONG UNALIGNED*)(&_pAddr[2]))
  530. #endif
  531. //
  532. // The Remote address (DEST address) is what we use to mutilplex
  533. // sends across our single adapter/binding context. The address
  534. // has the following format:
  535. //
  536. // XX XX XX YY YY ZZ
  537. //
  538. // XX = Randomly generated OUI
  539. // YY = Index into the active bundle connection table to get bundlecb
  540. // ZZ = Index into the protocol table of a bundle to get protocolcb
  541. //
  542. #define FillNdisWanIndices(_pAddr, _bI, _pI) \
  543. { \
  544. _pAddr[3] = (UCHAR)((USHORT)_bI >> 8); \
  545. _pAddr[4] = (UCHAR)_bI; \
  546. _pAddr[5] = (UCHAR)_pI; \
  547. }
  548. #define GetNdisWanIndices(_pAddr, _bI, _pI) \
  549. { \
  550. _bI = ((USHORT)_pAddr[3] << 8) | _pAddr[4]; \
  551. _pI = _pAddr[5]; \
  552. ASSERT(_pI < MAX_PROTOCOLS); \
  553. }
  554. //
  555. // In the Src address (from a NdisSend) the bundle index
  556. // is stashed in the two high order bytes as shown below
  557. // with the mask of valid bits given by the x's. The
  558. // high byte is shifted to the left one bit so the number
  559. // of possible bundles is now 0x7FFF
  560. //
  561. // XX XX YY YY YY YY
  562. //
  563. // XX = Bytes described below owned by NdisWan
  564. // YY = Transports Receive context
  565. //
  566. // 0 1
  567. // 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  568. // x x x x x x x 0 x x x x x x x x
  569. //
  570. #define FillTransportBundleIndex(_pAddr, _Index) \
  571. { \
  572. _pAddr[0] = (UCHAR)((USHORT)_Index >> 7) & 0xFE; \
  573. _pAddr[1] = (UCHAR)_Index; \
  574. }
  575. #define GetTransportBundleIndex(_pAddr) \
  576. (((USHORT)_pAddr[0] << 7) & 0x7F) | _pAddr[1]
  577. #define GetProtocolCBFromProtocolList(_pl, _pt, _pppcb) \
  578. { \
  579. PPROTOCOLCB _pP; \
  580. for (_pP = (PPROTOCOLCB)(_pl)->Flink; \
  581. (PLIST_ENTRY)_pP != _pl; \
  582. _pP = (PPROTOCOLCB)(_pP)->Linkage.Flink) { \
  583. \
  584. if (_pP->ProtocolType == _pt) { \
  585. *(_pppcb) = _pP; \
  586. break; \
  587. } \
  588. } \
  589. if ((PVOID)_pP == (PVOID)_pl) { \
  590. *(_pppcb) = NULL; \
  591. } \
  592. }
  593. #define PROTOCOLCB_FROM_PROTOCOLH(_pBCB, _pPCB, _hP) \
  594. { \
  595. if (_hP < MAX_PROTOCOLS) { \
  596. _pPCB = _pBCB->ProtocolCBTable[_hP]; \
  597. } else { \
  598. _pPCB = NULL; \
  599. } \
  600. }
  601. #define NetToHostShort(_ns) ( ((_ns & 0x00FF) << 8) | ((_ns & 0xFF00) >> 8) )
  602. #define HostToNetShort(_hs) ( ((_hs & 0x00FF) << 8) | ((_hs & 0xFF00) >> 8) )
  603. #define IsLinkSendWindowOpen(_plcb) \
  604. ((_plcb)->SendWindow > (_plcb)->OutstandingFrames)
  605. #define IsSampleTableFull(_pST) ((_pST)->ulSampleCount == (_pST)->ulSampleArraySize)
  606. #define IsSampleTableEmpty(_pST) ((_pST)->ulSampleCount == 0)
  607. #define PMINIPORT_RESERVED_FROM_NDIS(_packet) \
  608. ((PNDISWAN_MINIPORT_RESERVED)((_packet)->MiniportReserved))
  609. #define PPROTOCOL_RESERVED_FROM_NDIS(_packet) \
  610. ((PNDISWAN_PROTOCOL_RESERVED)((_packet)->ProtocolReserved))
  611. #define PRECV_RESERVED_FROM_NDIS(_packet) \
  612. ((PNDISWAN_RECV_RESERVED)((_packet)->ProtocolReserved))
  613. #define IsCompleteFrame(_fl) \
  614. ((_fl & MULTILINK_BEGIN_FRAME) && (_fl & MULTILINK_END_FRAME))
  615. #define AddPPPProtocolID(_finf, _usID) \
  616. { \
  617. PUCHAR _cp = _finf->ProtocolID.Pointer; \
  618. if (_finf->ProtocolID.Length != 0) { \
  619. ASSERT(_cp); \
  620. if (!(_finf->FramingBits & PPP_COMPRESS_PROTOCOL_FIELD) || \
  621. (_finf->Flags & (DO_COMPRESSION | DO_ENCRYPTION))) { \
  622. *_cp++ = (UCHAR)(_usID >> 8); \
  623. } \
  624. *_cp = (UCHAR)_usID; \
  625. } \
  626. }
  627. #define AddMultilinkInfo(_finf, _f, _seq, _mask) \
  628. { \
  629. PUCHAR _cp = _finf->Multilink.Pointer; \
  630. if (_finf->Multilink.Length != 0) { \
  631. ASSERT(_cp); \
  632. if (!(_finf->FramingBits & PPP_COMPRESS_PROTOCOL_FIELD)) { \
  633. _cp++; \
  634. } \
  635. _cp++; \
  636. _seq &= _mask; \
  637. if (_finf->FramingBits & PPP_SHORT_SEQUENCE_HDR_FORMAT) { \
  638. *_cp++ = _f | (UCHAR)(_finf->Class << 4) | (UCHAR)((_seq >> 8) & SHORT_SEQ_MASK); \
  639. *_cp++ = (UCHAR)_seq; \
  640. } else { \
  641. *_cp++ = _f | (UCHAR)(_finf->Class << 2); \
  642. *_cp++ = (UCHAR)(_seq >> 16); \
  643. *_cp++ = (UCHAR)(_seq >> 8); \
  644. *_cp = (UCHAR)_seq; \
  645. } \
  646. } \
  647. }
  648. #define AddCompressionInfo(_finf, _usCC) \
  649. { \
  650. PUCHAR _cp = _finf->Compression.Pointer; \
  651. if (_finf->Compression.Length != 0) { \
  652. ASSERT(_cp); \
  653. if (!(_finf->FramingBits & PPP_COMPRESS_PROTOCOL_FIELD)) { \
  654. _cp++; \
  655. } \
  656. _cp++; \
  657. *_cp++ = (UCHAR)(_usCC >> 8); \
  658. *_cp = (UCHAR)_usCC; \
  659. } \
  660. }
  661. #define UpdateFramingInfo(_finf, _pd) \
  662. { \
  663. PUCHAR _sdb = (_pd); \
  664. (_finf)->AddressControl.Pointer = (_sdb); \
  665. (_sdb) += (_finf)->AddressControl.Length; \
  666. (_finf)->Multilink.Pointer = (_sdb); \
  667. (_sdb) += (_finf)->Multilink.Length; \
  668. (_finf)->Compression.Pointer = (_sdb); \
  669. (_sdb) += (_finf)->Compression.Length; \
  670. (_finf)->ProtocolID.Pointer = (_sdb); \
  671. }
  672. #define NdisWanChangeMiniportAddress(_a, _addr) \
  673. { \
  674. PNDIS_MINIPORT_BLOCK Miniport; \
  675. \
  676. Miniport = (PNDIS_MINIPORT_BLOCK)((_a)->MiniportHandle); \
  677. ETH_COPY_NETWORK_ADDRESS(Miniport->EthDB->AdapterAddress, _addr); \
  678. }
  679. //
  680. // Queue routines for the ProtocolCB's NdisPacket queues
  681. //
  682. #define InsertHeadPacketQueue(_ppq, _pnp, _pl) \
  683. { \
  684. PMINIPORT_RESERVED_FROM_NDIS(_pnp)->Next = \
  685. (_ppq)->HeadQueue; \
  686. if ((_ppq)->HeadQueue == NULL) { \
  687. (_ppq)->TailQueue = _pnp; \
  688. } \
  689. (_ppq)->HeadQueue = _pnp; \
  690. (_ppq)->ByteDepth += (_pl-14); \
  691. (_ppq)->PacketDepth += 1; \
  692. if ((_ppq)->PacketDepth > (_ppq)->MaxPacketDepth) { \
  693. (_ppq)->MaxPacketDepth = (_ppq)->PacketDepth; \
  694. } \
  695. }
  696. #define InsertTailPacketQueue(_ppq, _pnp, _pl) \
  697. { \
  698. PMINIPORT_RESERVED_FROM_NDIS(_pnp)->Next = NULL;\
  699. if ((_ppq)->HeadQueue == NULL) { \
  700. (_ppq)->HeadQueue = _pnp; \
  701. } else { \
  702. PMINIPORT_RESERVED_FROM_NDIS((_ppq)->TailQueue)->Next = _pnp; \
  703. } \
  704. (_ppq)->TailQueue = _pnp; \
  705. (_ppq)->ByteDepth += (_pl-14); \
  706. (_ppq)->PacketDepth += 1; \
  707. if ((_ppq)->PacketDepth > (_ppq)->MaxPacketDepth) { \
  708. (_ppq)->MaxPacketDepth = (_ppq)->PacketDepth; \
  709. } \
  710. }
  711. #define RemoveHeadPacketQueue(_ppq) \
  712. (_ppq)->HeadQueue; \
  713. { \
  714. PNDIS_PACKET _cp = (_ppq)->HeadQueue; \
  715. PNDIS_PACKET _np = \
  716. PMINIPORT_RESERVED_FROM_NDIS(_cp)->Next; \
  717. if (_np == NULL) { \
  718. (_ppq)->TailQueue = NULL; \
  719. } \
  720. (_ppq)->HeadQueue = _np; \
  721. (_ppq)->ByteDepth -= ((_cp)->Private.TotalLength-14); \
  722. (_ppq)->PacketDepth -= 1; \
  723. }
  724. #define IsPacketQueueEmpty(_ppq) ((_ppq)->HeadQueue == NULL)
  725. #define NdisWanDoReceiveComplete(_pa) \
  726. { \
  727. NdisReleaseSpinLock(&(_pa)->Lock); \
  728. NdisMEthIndicateReceiveComplete((_pa)->MiniportHandle); \
  729. NdisAcquireSpinLock(&(_pa)->Lock); \
  730. }
  731. //
  732. // OS specific code
  733. //
  734. #ifdef NT
  735. //
  736. // NT stuff
  737. //
  738. #define NdisWanInitializeNotificationEvent(_pEvent) \
  739. KeInitializeEvent(_pEvent, NotificationEvent, FALSE)
  740. #define NdisWanSetNotificationEvent(_pEvent) \
  741. KeSetEvent(_pEvent, 0, FALSE)
  742. #define NdisWanClearNotificationEvent(_pEvent) \
  743. KeClearEvent(_pEvent)
  744. #define NdisWanWaitForNotificationEvent(_pEvent) \
  745. KeWaitForSingleObject(_pEvent, Executive, KernelMode, TRUE, NULL)
  746. #define NdisWanInitializeSyncEvent(_pEvent) \
  747. KeInitializeEvent(_pEvent, SynchronizationEvent, FALSE)
  748. #define NdisWanSetSyncEvent(_pEvent) \
  749. KeSetEvent(_pEvent, 1, FALSE)
  750. #define NdisWanClearSyncEvent(_pEvent) \
  751. KeClearEvent(_pEvent)
  752. #define NdisWanWaitForSyncEvent(_pEvent) \
  753. KeWaitForSingleObject(_pEvent, UserRequest, KernelMode, FALSE, NULL)
  754. #if 0
  755. #if DBG && !defined(_WIN64)
  756. #define CheckDataBufferList(_e) \
  757. { \
  758. PSINGLE_LIST_ENTRY _le; \
  759. KIRQL _irql; \
  760. KeAcquireSpinLock(&DataBufferList.Lock, &_irql); \
  761. _le = DataBufferList.L.ListHead.Next.Next; \
  762. while (_le != NULL) { \
  763. if ((PSINGLE_LIST_ENTRY)_e == _le) { \
  764. DbgPrint("NDISWAN: Corrupt DataBufferList Free!\n"); \
  765. DbgPrint("NDISWAN: List %x Entry %x\n", &DataBufferList, _e);\
  766. DbgBreakPoint(); \
  767. } \
  768. _le = _le->Next; \
  769. } \
  770. KeReleaseSpinLock(&DataBufferList.Lock, _irql); \
  771. }
  772. #else
  773. #define CheckDataBufferList(_e)
  774. #endif
  775. #endif
  776. #if 0
  777. #define NdisWanFreeDataBuffer(_e) \
  778. { \
  779. NdisFreeToNPagedLookasideList(&DataBufferList, _e); \
  780. }
  781. #define NdisWanAllocateDataBuffer() \
  782. NdisAllocateFromNPagedLookasideList(&DataBufferList)
  783. #endif
  784. #define NdisWanAllocateMemory(_AllocatedMemory, _Size, _t) \
  785. { \
  786. (PVOID)*(_AllocatedMemory) = (PVOID)ExAllocatePoolWithTag(NonPagedPool, _Size, _t); \
  787. if ((PVOID)*(_AllocatedMemory) != NULL) { \
  788. NdisZeroMemory((PUCHAR)*(_AllocatedMemory), _Size); \
  789. } \
  790. }
  791. #define NdisWanAllocatePriorityMemory(_AllocatedMemory, _Size, _t, _p) \
  792. { \
  793. (PVOID)*(_AllocatedMemory) = (PVOID)ExAllocatePoolWithTagPriority(NonPagedPool, _Size, _t, _p);\
  794. if ((PVOID)*(_AllocatedMemory) != NULL) { \
  795. NdisZeroMemory((PUCHAR)*(_AllocatedMemory), _Size); \
  796. } \
  797. }
  798. #define NdisWanFreeMemory(_AllocatedMemory) \
  799. ExFreePool(_AllocatedMemory)
  800. #define NdisWanAllocateNdisBuffer(_ppnb, _pd, _dl) \
  801. { \
  802. NDIS_STATUS _s; \
  803. NdisAllocateBuffer(&(_s), _ppnb, NULL, _pd, _dl); \
  804. if (_s != NDIS_STATUS_SUCCESS) { \
  805. *(_ppnb) = NULL; \
  806. } \
  807. }
  808. #define NdisWanFreeNdisBuffer(_pnb) NdisFreeBuffer(_pnb)
  809. #define NdisWanMoveMemory(_Dest, _Src, _Length) \
  810. RtlMoveMemory(_Dest, _Src, _Length)
  811. #define NdisWanGetSystemTime(_pTime) \
  812. { \
  813. LARGE_INTEGER _tc; \
  814. ULONG _ti; \
  815. KeQueryTickCount(&_tc); \
  816. _ti = KeQueryTimeIncrement(); \
  817. (_pTime)->QuadPart = _tc.QuadPart * _ti; \
  818. }
  819. #define NdisWanCalcTimeDiff(_pDest, _pEnd, _pBegin) \
  820. (_pDest)->QuadPart = (_pEnd)->QuadPart - (_pBegin)->QuadPart
  821. #define NdisWanInitWanTime(_pTime, _Val) \
  822. (_pTime)->QuadPart = _Val
  823. #define NdisWanMultiplyWanTime(_pDest, _pMulti1, _pMulti2) \
  824. (_pDest)->QuadPart = (_pMulti1)->QuadPart * (_pMulti2)->QuadPart
  825. #define NdisWanDivideWanTime(_pDest, _pDivi1, _pDivi2) \
  826. (_pDest)->QuadPart = (_pDivi1)->QuadPart / (_pDivi2)->QuadPart
  827. #define NdisWanIsTimeDiffLess(_pTime1, _pTime2) \
  828. ((_pTime1)->QuadPart < (_pTime2)->QuadPart)
  829. #define NdisWanIsTimeDiffGreater(_pTime1, _pTime2) \
  830. ((_pTime1)->QuadPart > (_pTime2)->QuadPart)
  831. #define NdisWanIsTimeEqual(_pTime1, _pTime2) \
  832. ((_pTime1)->QuadPart == (_pTime2)->QuadPart)
  833. #define NdisWanUppercaseNdisString(_pns1, _pns2, _b) \
  834. RtlUpcaseUnicodeString(_pns1, _pns2, _b)
  835. #define MDL_ADDRESS(_MDL_) MmGetSystemAddressForMdl(_MDL_)
  836. #define NdisWanInterlockedInc(_pul) \
  837. InterlockedIncrement(_pul)
  838. #define NdisWanInterlockedDec(_pul) \
  839. InterlockedDecrement(_pul)
  840. #define NdisWanInterlockedExchange(_pul, _ul) \
  841. InterlockedExchange(_pul, _ul)
  842. #define NdisWanInterlockedExchangeAdd(_pul, _ul) \
  843. InterlockedExchangeAdd(_pul, _ul)
  844. #define NdisWanInterlockedInsertTailList(_phead, _pentry, _plock) \
  845. ExInterlockedInsertTailList(_phead, _pentry, _plock)
  846. #define NdisWanInterlockedInsertHeadList(_phead, _pentry, _plock) \
  847. ExInterlockedInsertHeadList(_phead, _pentry, _plock)
  848. #define NdisWanInterlockedRemoveHeadList(_phead, _plock) \
  849. ExInterlockedRemoveHeadList(_phead, _plock)
  850. #define NdisWanRaiseIrql(_pirql) \
  851. KeRaiseIrql(DISPATCH_LEVEL, _pirql)
  852. #define NdisWanLowerIrql(_irql) \
  853. KeLowerIrql(_irql)
  854. //
  855. // Wait for event structure. Used for async completion notification.
  856. //
  857. typedef KEVENT WAN_EVENT;
  858. typedef WAN_EVENT *PWAN_EVENT;
  859. typedef LARGE_INTEGER WAN_TIME;
  860. typedef WAN_TIME *PWAN_TIME;
  861. typedef KIRQL WAN_IRQL;
  862. typedef WAN_IRQL *PWAN_IRQL;
  863. #else // end NT stuff
  864. //
  865. // Win95 stuff
  866. //
  867. typedef ULONG WAN_TIME;
  868. typedef WAN_TIME *PWAN_TIME;
  869. #endif // end of Win95 stuff
  870. #endif // end of _NDISWAN_DEFS_