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.

843 lines
42 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. arap.h
  5. Abstract:
  6. This module has defines, prototypes etc. specific to ARAP functionality
  7. Author:
  8. Shirish Koti
  9. Revision History:
  10. 15 Nov 1996 Initial Version
  11. --*/
  12. //
  13. // enable asserts when running checked stack on free builds
  14. //
  15. #if DBG
  16. #ifdef ASSERT
  17. #undef ASSERT
  18. #endif
  19. #define ASSERT(exp) \
  20. { \
  21. if (!(exp)) \
  22. { \
  23. DbgPrint( "\n*** Assertion failed: %s (File %s, line %ld)\n", \
  24. (exp),__FILE__, __LINE__); \
  25. \
  26. DbgBreakPoint(); \
  27. } \
  28. }
  29. #endif
  30. #define ATALK_CC_METHOD(_ControlCode) ((_ControlCode) & 0x03)
  31. //
  32. // Possible states for the connection (State field in ARAPCONN structure)
  33. // IMPORTANT: order of these states matters! (comparisons other than == used)
  34. //
  35. #define MNP_IDLE 0 // creation state, after Ndiswan Line_Up
  36. #define MNP_REQUEST 1 // this state never reached (client-side only)
  37. #define MNP_RESPONSE 2 // sent LR response to the client
  38. #define MNP_UP 3 // MNP connection is in data-phase
  39. #define MNP_LDISCONNECTING 4 // disconnect from local (user ioctl)
  40. #define MNP_RDISC_RCVD 5 // disconnect from remote received
  41. #define MNP_RDISCONNECTING 6 // cleanup underway because of MNP_RDISC_RCVD
  42. #define MNP_DISCONNECTED 7 // cleanup done, waiting for Ndiswan Line_Down
  43. //
  44. // possible header types (from the v42 alternative procedure spec)
  45. //
  46. #define MNP_LR 0x1
  47. #define MNP_LD 0x2
  48. #define MNP_LT 0x4
  49. #define MNP_LT_V20CLIENT 0x84
  50. #define MNP_LA 0x5
  51. #define MNP_LN 0x6
  52. #define MNP_LNA 0x7
  53. #define MNP_MINPKT_SIZE 64
  54. #define MNP_MAXPKT_SIZE 256
  55. #define MNP_LR_CONST1 2
  56. // type values for the various "variable" parms
  57. #define MNP_LR_CONST2 1
  58. #define MNP_LR_FRAMING 2
  59. #define MNP_LR_NUMLTFRMS 3
  60. #define MNP_LR_INFOLEN 4
  61. #define MNP_LR_DATAOPT 8
  62. #define MNP_LR_V42BIS 14
  63. #define MNP_FRMMODE_OCTET 2
  64. #define MNP_FRMMODE_BIT 3
  65. #define MNP_FRMTYPE_OFFSET 4
  66. #define ARAP_DGROUP_OFFSET 2
  67. #define ARAP_DATA_OFFSET 3
  68. // bit 6 is set for appletalk data, is clear for arap data
  69. #define ARAP_SFLAG_PKT_DATA 0x40
  70. #define ARAP_SFLAG_LAST_GROUP 0x10
  71. //
  72. // Flags bits (in ARAPCONN structure)
  73. //
  74. #define MNP_OPTIMIZED_DATA 0x00000001 // MNP negotiated for optimized data
  75. #define MNP_V42BIS_NEGOTIATED 0x00000002 // MNP negotiated v42bis compression
  76. #define ARAP_V20_CONNECTION 0x00000004 // v2.0 if bit set, v1.0 otherwise
  77. #define ARAP_NODE_IN_USE 0x00000008 // used while acquiring node (dynamic mode)
  78. #define ARAP_FINDING_NODE 0x00000010 // used while acquiring node (dynamic mode)
  79. #define ARAP_CALLBACK_MODE 0x00000020 // used if we are calling back
  80. #define ARAP_CONNECTION_UP 0x00000040 // ARAP connection is up, data phase entered
  81. #define ARAP_DATA_WAITING 0x00000080 // data arrived, but no irp to fill it in
  82. #define ARAP_REMOTE_DISCONN 0x00000100 // remote side issued the disconnect
  83. #define DISCONNECT_NO_IRP 0x00000200 // waiting for irp to tell dll about disc.
  84. #define RETRANSMIT_TIMER_ON 0x00000400 // retransmit timer is running
  85. #define ARAP_LINK_DOWN 0x00000800 // link went down
  86. #define ARAP_GOING_AWAY 0x00001000 // the connection is about to be freed!
  87. // BUGBUG: currently set to be 200ms (1 => 100 ms)
  88. #define ARAP_TIMER_INTERVAL 2
  89. #define ARAP_MAX_RETRANSMITS 12
  90. #define ARAP_HALF_MAX_RETRANSMITS (ARAP_MAX_RETRANSMITS/2)
  91. // retry time will depend on link speed (also on how many retranmits of the
  92. // same send have happened so far), but we'll fix min (1sec) and max (5sec)
  93. #define ARAP_MIN_RETRY_INTERVAL 10
  94. #define ARAP_MAX_RETRY_INTERVAL 50
  95. // our limits (in bytes) for outstanding sends that are sitting on the queue
  96. #define ARAP_SENDQ_LOWER_LIMIT 10000
  97. #define ARAP_SENDQ_UPPER_LIMIT 12000
  98. // our limits (in bytes) for outstanding recvs that are sitting on the queue
  99. #define ARAP_RECVQ_LOWER_LIMIT 20000
  100. #define ARAP_RECVQ_UPPER_LIMIT 30000
  101. // on low-priority sends, we wait until we collect at least these many bytes
  102. #define ARAP_SEND_COALESCE_SIZE_LIMIT 150
  103. // max number of SRPs we will put in a low-priority MNP send
  104. #define ARAP_SEND_COALESCE_SRP_LIMIT 200
  105. // on low-priority sends, we wait until so much time has passed (in 100ms units)
  106. #define ARAP_SEND_COALESCE_TIME_LIMIT 10
  107. // BUGBUG: adjust these numbers for optimum usage/perf
  108. #define ARAP_SMPKT_SIZE 100
  109. #define ARAP_MDPKT_SIZE 300
  110. #define ARAP_LGPKT_SIZE ARAP_MAXPKT_SIZE_INCOMING+10
  111. #define ARAP_SENDBUF_SIZE 1000
  112. #define ARAP_LGBUF_SIZE 4000
  113. #define ARAP_HGBUF_SIZE 8100
  114. // LAP src byte, LAP dest byte, LAP type byte
  115. #define ARAP_LAP_HDRSIZE 3
  116. // 2 srplen bytes, 1 Dgroup byte
  117. #define ARAP_HDRSIZE 3
  118. #define ARAP_NBP_BRRQ 0x11
  119. #define ARAP_NBP_LKRQ 0x21
  120. // 3rd and 4th bytes in the NBP pkt are the source network bytes
  121. #define ARAP_NBP_SRCNET_OFFSET LDDP_DGRAM_OFFSET + 2
  122. #define ARAP_NBP_OBJLEN_OFFSET LDDP_DGRAM_OFFSET + 7
  123. #define ARAP_FAKE_ETHNET_HDRLEN 14
  124. #define MNP_START_FLAG_LEN 3
  125. #define MNP_STOP_FLAG_LEN 2
  126. #define MNP_LT_HDR_LN(_pCon) ((_pCon->Flags & MNP_OPTIMIZED_DATA)? 3 : 5)
  127. #define ARAP_SEND_PRIORITY_HIGH 1
  128. #define ARAP_SEND_PRIORITY_MED 2
  129. #define ARAP_SEND_PRIORITY_LOW 3
  130. #define MNP_OVERHD(_pConn) \
  131. ( ARAP_FAKE_ETHNET_HDRLEN + \
  132. MNP_START_FLAG_LEN + \
  133. MNP_LT_HDR_LN(_pConn) + \
  134. MNP_STOP_FLAG_LEN )
  135. #define ADD_ONE(_x) (_x) = (((_x) == 0xff) ? 0 : ((_x)+1))
  136. // seq num on LT frame: 5th byte if it's an Optimized data phase: 7th otherwise
  137. #define LT_SEQ_NUM(_p, _pCon) \
  138. (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? (_p)[5] : (_p)[7])
  139. #define LT_SEQ_OFFSET(_pCon) (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? 5: 7)
  140. #define LT_SRP_OFFSET(_pCon) (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? 6: 8)
  141. // this includes 2 bytes of crc bytes
  142. #define LT_OVERHEAD(_pCon) (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? 10 : 12)
  143. // BUGBUG modify this to include any packet in the window
  144. #define LT_OK_TO_ACCEPT(_sq, _pCon, _ok) \
  145. (_ok = (_sq == _pCon->MnpState.NextToReceive))
  146. //
  147. // basically, (a > b)? except that a,b are seq numbers and wrap at 255
  148. // Within a window of 8 pkts either side of 0, we have special cases
  149. // we have assumed windowsize to be 8 here. Even if a different window
  150. // size is negotiated, this should work just fine
  151. // BUGBUG: should we use a bigger range, just to be sure?
  152. //
  153. #define LT_GREATER_THAN(_a,_b,_result) \
  154. { \
  155. if ( (_a) >= 248 && (_b) >= 0 && (_b) < 8 ) \
  156. { \
  157. _result = FALSE; \
  158. } \
  159. else if ( (_a) >= 0 && (_a) < 8 && (_b) >= 248 ) \
  160. { \
  161. _result = TRUE; \
  162. } \
  163. else \
  164. { \
  165. _result = ((_a) > (_b)); \
  166. } \
  167. }
  168. #define LT_LESS_OR_EQUAL(_x,_y,_rslt) \
  169. { \
  170. LT_GREATER_THAN(_x,_y,_rslt); \
  171. _rslt = !(_rslt); \
  172. }
  173. #define LT_MIN_LENGTH(_pCon) (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? 6 : 8)
  174. #define LA_MIN_LENGTH(_pCon) (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? 7 : 9)
  175. #define LN_MIN_LENGTH 8
  176. // seq num on LA frame: 5th byte if it's an Optimized data phase: 7th otherwise
  177. #define LA_SEQ_NUM(_p, _pCon) \
  178. (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? (_p)[5] : (_p)[7])
  179. // rcv credit on LA frame: 6th byte if it's an Optimized data phase: 8th otherwise
  180. #define LA_CREDIT(_p, _pCon) \
  181. (((_pCon)->Flags & MNP_OPTIMIZED_DATA) ? (_p)[6] : (_p)[8])
  182. // overhead for LT (optimized): 8 = 3(start flag)+3(LT hdr)+2(stop flag)
  183. // (nonoptimized): 10 = 3(start flag)+5(LT hdr)+2(stop flag)
  184. #define LN_ATTN_TYPE(_p) ((_p)[7])
  185. #define LN_ATTN_SEQ(_p) ((_p)[4])
  186. #define LN_DESTRUCTIVE 1
  187. #define LN_NON_D_E 2
  188. #define LN_NON_D_NON_E 3
  189. // The states that the stack can assume (with respect to ARAP)
  190. //
  191. // ARAP_STATE_INIT -- arap engine (dll) hasn't open the stack
  192. // ARAP_STATE_INACTIVE_WAITING -- stack inactive, but engine not notified yet
  193. // ARAP_STATE_INACTIVE -- stack inactive, and engine notified
  194. // ARAP_STATE_ACTIVE_WAITING -- stack ready, engine not notified yet (select not available)
  195. // ARAP_STATE_ACTIVE -- stack ready, engine notified about it (via select)
  196. //
  197. #define ARAP_STATE_INACTIVE_WAITING 1
  198. #define ARAP_STATE_INACTIVE 2
  199. #define ARAP_STATE_ACTIVE_WAITING 3
  200. #define ARAP_STATE_ACTIVE 4
  201. #define ARAP_PORT_READY ( (AtalkDefaultPort != NULL) && \
  202. (AtalkDefaultPort->pd_Flags & PD_ACTIVE) && \
  203. (RasPortDesc != NULL) && \
  204. (RasPortDesc->pd_Flags & PD_ACTIVE) )
  205. #define ARAP_PNP_IN_PROGRESS ( ((AtalkDefaultPort != NULL) && \
  206. (AtalkDefaultPort->pd_Flags & PD_PNP_RECONFIGURE)) || \
  207. ((RasPortDesc != NULL) && \
  208. (RasPortDesc->pd_Flags & PD_PNP_RECONFIGURE)) )
  209. #define ARAP_INVALID_CONTEXT (PVOID)0x01020304
  210. #define ARAP_GET_SNIFF_IRP(_pIrp) \
  211. { \
  212. KIRQL _OldIrqlX; \
  213. \
  214. ACQUIRE_SPIN_LOCK(&ArapSpinLock, &_OldIrqlX); \
  215. *(_pIrp) = ArapSniffIrp; \
  216. ArapSniffIrp = NULL; \
  217. RELEASE_SPIN_LOCK(&ArapSpinLock, _OldIrqlX); \
  218. }
  219. #if DBG
  220. #define ARAP_COMPLETE_IRP(_pIrp, _dwBytesToDll, _status, _returnStatus) \
  221. { \
  222. PIO_STACK_LOCATION _pIrpSp; \
  223. ULONG _IoControlCode; \
  224. \
  225. _pIrpSp = IoGetCurrentIrpStackLocation(_pIrp); \
  226. _IoControlCode = _pIrpSp->Parameters.DeviceIoControl.IoControlCode; \
  227. \
  228. _pIrp->IoStatus.Information = _dwBytesToDll; \
  229. _pIrp->IoStatus.Status = _status; \
  230. \
  231. DBGPRINT(DBG_COMP_RAS, DBG_LEVEL_INFO, \
  232. ("Arap: completing pIrp %lx, Ioctl %lx, Status=%ld, DataLen=%ld\n", \
  233. _pIrp,_IoControlCode,_status,_dwBytesToDll)); \
  234. \
  235. _pIrp->CancelRoutine = NULL; \
  236. *_returnStatus = _pIrp->IoStatus.Status; \
  237. IoCompleteRequest(_pIrp,IO_NETWORK_INCREMENT); \
  238. }
  239. #else
  240. #define ARAP_COMPLETE_IRP(_pIrp, _dwBytesToDll, _status, _returnStatus) \
  241. { \
  242. PIO_STACK_LOCATION _pIrpSp; \
  243. \
  244. _pIrpSp = IoGetCurrentIrpStackLocation(_pIrp); \
  245. \
  246. _pIrp->IoStatus.Information = _dwBytesToDll; \
  247. _pIrp->IoStatus.Status = _status; \
  248. \
  249. \
  250. _pIrp->CancelRoutine = NULL; \
  251. *_returnStatus= _pIrp->IoStatus.Status; \
  252. IoCompleteRequest(_pIrp,IO_NETWORK_INCREMENT); \
  253. }
  254. #endif
  255. #define ARAP_SET_NDIS_CONTEXT(_pSndBuf,_pSndContxt) \
  256. { \
  257. PPROTOCOL_RESD _pResd; \
  258. PNDIS_PACKET _nPkt; \
  259. \
  260. _nPkt = (_pSndBuf)->sb_BuffHdr.bh_NdisPkt; \
  261. _pResd = (PPROTOCOL_RESD)&_nPkt->ProtocolReserved; \
  262. \
  263. _pResd->Send.pr_Port = RasPortDesc; \
  264. _pResd->Send.pr_SendCompletion = ArapNdisSendComplete; \
  265. _pResd->Send.pr_BufferDesc = (PBUFFER_DESC)(_pSndBuf); \
  266. if ((_pSndContxt) != NULL) \
  267. { \
  268. RtlCopyMemory(&_pResd->Send.pr_SendInfo, \
  269. (_pSndContxt), \
  270. sizeof(SEND_COMPL_INFO)); \
  271. } \
  272. else \
  273. { \
  274. RtlZeroMemory(&_pResd->Send.pr_SendInfo, sizeof(SEND_COMPL_INFO)); \
  275. } \
  276. }
  277. //
  278. // we take a very simplistic view!
  279. //
  280. #define ARAP_ADJUST_RECVCREDIT(_pConn) \
  281. { \
  282. if (_pConn->RecvsPending >= ARAP_RECVQ_UPPER_LIMIT) \
  283. { \
  284. DBGPRINT(DBG_COMP_RAS, DBG_LEVEL_ERR, \
  285. ("ARAP (%lx): recv credit dropped to 0 (%d)\n",_pConn,_pConn->RecvsPending));\
  286. \
  287. _pConn->MnpState.RecvCredit = 0; \
  288. } \
  289. else if (_pConn->RecvsPending >= ARAP_RECVQ_LOWER_LIMIT) \
  290. { \
  291. DBGPRINT(DBG_COMP_RAS, DBG_LEVEL_ERR, \
  292. ("ARAP (%lx): recv credit dropped to 1 (%d)\n",_pConn,_pConn->RecvsPending));\
  293. \
  294. _pConn->MnpState.RecvCredit = 1; \
  295. } \
  296. else \
  297. { \
  298. _pConn->MnpState.RecvCredit = _pConn->MnpState.WindowSize; \
  299. } \
  300. }
  301. #if DBG
  302. #define ARAP_GET_RIGHTSIZE_RCVBUF(_size, _ppNewBuf) \
  303. { \
  304. UCHAR _BlkId; \
  305. PARAPBUF _pRcvBuf; \
  306. USHORT _BufSize; \
  307. DWORD _Signature; \
  308. \
  309. *(_ppNewBuf) = NULL; \
  310. _pRcvBuf = NULL; \
  311. \
  312. if ((_size) <= ARAP_SMPKT_SIZE) \
  313. { \
  314. _BlkId = BLKID_ARAP_SMPKT; \
  315. _BufSize = ARAP_SMPKT_SIZE; \
  316. _Signature = ARAPSMPKT_SIGNATURE; \
  317. } \
  318. else if ((_size) <= ARAP_MDPKT_SIZE) \
  319. { \
  320. _BlkId = BLKID_ARAP_MDPKT; \
  321. _BufSize = ARAP_MDPKT_SIZE; \
  322. _Signature = ARAPMDPKT_SIGNATURE; \
  323. } \
  324. else if ((_size) <= ARAP_LGPKT_SIZE) \
  325. { \
  326. _BlkId = BLKID_ARAP_LGPKT; \
  327. _BufSize = ARAP_LGPKT_SIZE; \
  328. _Signature = ARAPLGPKT_SIGNATURE; \
  329. } \
  330. else if ((_size) <= ARAP_LGBUF_SIZE) \
  331. { \
  332. _BlkId = BLKID_ARAP_LGBUF; \
  333. _BufSize = ARAP_LGBUF_SIZE; \
  334. _Signature = ARAPLGBUF_SIGNATURE; \
  335. } \
  336. else \
  337. { \
  338. _BlkId = ARAP_UNLMTD_BUFF_ID; \
  339. _BufSize = (USHORT)(_size); \
  340. _Signature = ARAPUNLMTD_SIGNATURE; \
  341. } \
  342. \
  343. if (_BlkId == ARAP_UNLMTD_BUFF_ID) \
  344. { \
  345. if ((_size) > 5000) \
  346. { \
  347. DBGPRINT(DBG_COMP_RAS, DBG_LEVEL_ERR, \
  348. ("Arap: allocating %ld bytes rcv buf\n",_size)); \
  349. } \
  350. \
  351. _pRcvBuf = (PARAPBUF)AtalkAllocMemory((_size) + sizeof(ARAPBUF)); \
  352. } \
  353. else \
  354. { \
  355. _pRcvBuf = (PARAPBUF)AtalkBPAllocBlock(_BlkId); \
  356. } \
  357. \
  358. if (_pRcvBuf != NULL) \
  359. { \
  360. _pRcvBuf->Signature = _Signature; \
  361. _pRcvBuf->BlockId = _BlkId; \
  362. _pRcvBuf->BufferSize = _BufSize; \
  363. _pRcvBuf->DataSize = 0; \
  364. _pRcvBuf->CurrentBuffer = &(_pRcvBuf->Buffer[0]); \
  365. *(_ppNewBuf) = _pRcvBuf; \
  366. } \
  367. }
  368. #define ARAP_FREE_RCVBUF(_pBuf) \
  369. { \
  370. ASSERT( (_pBuf->Signature == ARAPSMPKT_SIGNATURE) || \
  371. (_pBuf->Signature == ARAPMDPKT_SIGNATURE) || \
  372. (_pBuf->Signature == ARAPLGPKT_SIGNATURE) || \
  373. (_pBuf->Signature == ARAPLGBUF_SIGNATURE) || \
  374. (_pBuf->Signature == ARAPUNLMTD_SIGNATURE) ); \
  375. \
  376. _pBuf->Signature -= 0x10210000; \
  377. if (_pBuf->BlockId == ARAP_UNLMTD_BUFF_ID) \
  378. { \
  379. AtalkFreeMemory(_pBuf); \
  380. } \
  381. else \
  382. { \
  383. AtalkBPFreeBlock(_pBuf); \
  384. } \
  385. }
  386. #define ARAP_CHECK_RCVQ_INTEGRITY(_pConn) \
  387. { \
  388. ASSERT( (DbgChkRcvQIntegrity(_pConn)) ); \
  389. }
  390. #define MNP_DBG_TRACE(_pConn,_Seq,_FrmType) \
  391. { \
  392. ArapDbgMnpHist(_pConn,_Seq,(_FrmType)); \
  393. } \
  394. #define ARAP_DBG_TRACE(_pConn,_Loc,_Ptr,_D1,_D2,_D3) \
  395. { \
  396. ArapDbgTrace(_pConn,_Loc,_Ptr,_D1,_D2,_D3); \
  397. }
  398. #define ARAP_DUMP_DBG_TRACE(_pConn) ArapDumpSniffInfo(_pConn)
  399. #else
  400. #define ARAP_GET_RIGHTSIZE_RCVBUF(_size, _ppNewBuf) \
  401. { \
  402. UCHAR _BlkId; \
  403. PARAPBUF _pRcvBuf; \
  404. USHORT _BufSize; \
  405. \
  406. *(_ppNewBuf) = NULL; \
  407. _pRcvBuf = NULL; \
  408. \
  409. if ((_size) <= ARAP_SMPKT_SIZE) \
  410. { \
  411. _BlkId = BLKID_ARAP_SMPKT; \
  412. _BufSize = ARAP_SMPKT_SIZE; \
  413. } \
  414. else if ((_size) <= ARAP_MDPKT_SIZE) \
  415. { \
  416. _BlkId = BLKID_ARAP_MDPKT; \
  417. _BufSize = ARAP_MDPKT_SIZE; \
  418. } \
  419. else if ((_size) <= ARAP_LGPKT_SIZE) \
  420. { \
  421. _BlkId = BLKID_ARAP_LGPKT; \
  422. _BufSize = ARAP_LGPKT_SIZE; \
  423. } \
  424. else if ((_size) <= ARAP_LGBUF_SIZE) \
  425. { \
  426. _BlkId = BLKID_ARAP_LGBUF; \
  427. _BufSize = ARAP_LGBUF_SIZE; \
  428. } \
  429. else \
  430. { \
  431. _BlkId = ARAP_UNLMTD_BUFF_ID; \
  432. _BufSize = (USHORT)(_size); \
  433. } \
  434. \
  435. if (_BlkId == ARAP_UNLMTD_BUFF_ID) \
  436. { \
  437. _pRcvBuf = (PARAPBUF)AtalkAllocMemory((_size) + sizeof(ARAPBUF)); \
  438. } \
  439. else \
  440. { \
  441. _pRcvBuf = (PARAPBUF)AtalkBPAllocBlock(_BlkId); \
  442. } \
  443. \
  444. if (_pRcvBuf != NULL) \
  445. { \
  446. _pRcvBuf->BlockId = _BlkId; \
  447. _pRcvBuf->BufferSize = _BufSize; \
  448. _pRcvBuf->DataSize = 0; \
  449. _pRcvBuf->CurrentBuffer = &(_pRcvBuf->Buffer[0]); \
  450. *(_ppNewBuf) = _pRcvBuf; \
  451. } \
  452. }
  453. #define ARAP_FREE_RCVBUF(_pBuf) \
  454. { \
  455. if (_pBuf->BlockId == ARAP_UNLMTD_BUFF_ID) \
  456. { \
  457. AtalkFreeMemory(_pBuf); \
  458. } \
  459. else \
  460. { \
  461. AtalkBPFreeBlock(_pBuf); \
  462. } \
  463. }
  464. #define ARAP_CHECK_RCVQ_INTEGRITY(_pConn)
  465. #define MNP_DBG_TRACE(_pConn,_Seq,_FrmType)
  466. #define ARAP_DBG_TRACE(_pConn,_Loc,_Ptr,_D1,_D2,_D3)
  467. #define ARAP_DUMP_DBG_TRACE(_pConn)
  468. #endif // #if DBG
  469. #define ARAP_BYTES_ON_RECVQ(_pConn,_BytesOnQ) \
  470. { \
  471. DWORD _BytesSoFar=0; \
  472. PLIST_ENTRY _pList; \
  473. PARAPBUF _pArapBuf; \
  474. \
  475. *(_BytesOnQ) = 0; \
  476. \
  477. _pList = _pConn->ReceiveQ.Flink; \
  478. while (_pList != &_pConn->ReceiveQ) \
  479. { \
  480. _pArapBuf = CONTAINING_RECORD(_pList, ARAPBUF, Linkage); \
  481. _BytesSoFar += _pArapBuf->DataSize; \
  482. \
  483. _pList = _pArapBuf->Linkage.Flink; \
  484. } \
  485. \
  486. *(_BytesOnQ) = _BytesSoFar; \
  487. }
  488. #if DBG
  489. #define ARAPTRACE(_x) DBGPRINT(DBG_COMP_RAS, DBG_LEVEL_INFO, _x)
  490. #define DBGDUMPBYTES(_a,_b,_c,_d) DbgDumpBytes(_a,_b,_c,_d)
  491. #define DBGTRACK_SEND_SIZE(_pConn,_Size) DbgTrackInfo(_pConn,_Size,1)
  492. #else
  493. #define ARAPTRACE(_x)
  494. #define DBGDUMPBYTES(_a,_b,_c,_d)
  495. #define DBGTRACK_SEND_SIZE(_pConn,_Size)
  496. #endif
  497. #define ARAPACTION_COMPLETE_IRP 1
  498. #define ARAPACTION_CALL_COMPLETION 2
  499. typedef struct _ADDRMGMT
  500. {
  501. struct _ADDRMGMT * Next;
  502. USHORT Network;
  503. BYTE NodeBitMap[32]; // 255 nodes per net
  504. }ADDRMGMT, *PADDRMGMT;
  505. typedef struct _ARAPGLOB
  506. {
  507. DWORD LowVersion;
  508. DWORD HighVersion;
  509. DWORD MnpInactiveTime; // tell dll after Mnp is inactive for this time
  510. BOOLEAN V42bisEnabled; //
  511. BOOLEAN SmartBuffEnabled; //
  512. BOOLEAN NetworkAccess; // if FALSE, no routing (only this machine)
  513. BOOLEAN DynamicMode; // we want the stack to get node address
  514. NETWORKRANGE NetRange;
  515. PADDRMGMT pAddrMgmt; // addr allocation to clients (in static mode)
  516. USHORT OurNetwkNum; // Network number of our default port
  517. BYTE MaxLTFrames; // max LT frames outstanding (rcv window)
  518. BOOLEAN SniffMode; // if TRUE, all pkts will be given to ARAP to "sniff"
  519. BOOLEAN RouteAdded; // if in static mode, have we added a route?
  520. } ARAPGLOB, *PARAPGLOB;
  521. typedef struct _ARAPSTATS
  522. {
  523. DWORD SendPreCompMax; // largest packet we have sent (before comp)
  524. DWORD SendPostCompMax; // largest packet we have sent (after comp)
  525. DWORD SendPreCompMin; // smallest packet we have sent (before comp)
  526. DWORD SendPostCompMin; // smallest packet we have sent (after comp)
  527. DWORD RecvPostDecompMax; // largest packet we have received (after decomp)
  528. DWORD RecvPostDecomMin; // smallest packet we have received (after decomp)
  529. } ARAPSTATS, *PARAPSTATS;
  530. typedef VOID (*PARAP_SEND_COMPLETION)(
  531. struct _MNPSENDBUF * pMnpSendBuf,
  532. DWORD Status
  533. );
  534. typedef struct _MNPSTATE
  535. {
  536. // sequence numbers when we are receiving
  537. BYTE NextToReceive; // next frame we expect to receive
  538. BYTE LastSeqRcvd; // seq num of last pkt we successfully rcvd
  539. BYTE LastAckSent; // seq num for which we sent the last ack
  540. BYTE UnAckedRecvs; // how many packets we've recvd but not acked yet
  541. BYTE RecvCredit; // how many more we can receive
  542. BYTE HoleInSeq; // TRUE when we get a hole in receive sequence
  543. BYTE ReceivingDup; // TRUE the moment we start receiving dup(s)
  544. BYTE FirstDupSeq; // seq num where we started getting dup's
  545. BYTE DupSeqBitMap; // bitmap of which seq nums we've got dups for
  546. // BUGBUG: if we ever want windowsize of more than 8,
  547. // we must make this a DWORD or something!
  548. // sequence numbers when we are sending
  549. BYTE LastAckRcvd; // last frame we have received ack for
  550. BYTE NextToSend; // next frame we will send
  551. BYTE SendCredit; // how many more we can send
  552. BYTE UnAckedSends; // basically, number of sends on retransmitQ
  553. BYTE MustRetransmit; // TRUE when we want retransmission to occur
  554. BYTE RetransmitMode; // TRUE if we are in retransmit mode
  555. // when we are processing the receives
  556. BYTE NextToProcess; // next sequence we will process
  557. BYTE MustAck; // if TRUE, send ack
  558. // static info that we negotiated at connection time
  559. BYTE WindowSize; // max pkts we can buffer (parm k)
  560. BYTE UnAckedLimit; // num of unacked pkts after which we must ack
  561. USHORT MaxPktSize; // N401 parm: this can be max 256
  562. BYTE SynByte;
  563. BYTE DleByte;
  564. BYTE StxByte;
  565. BYTE EtxByte;
  566. BYTE LTByte;
  567. } MNPSTATE, *PMNPSTATE;
  568. typedef struct _ARAPDBGHISTORY
  569. {
  570. USHORT TimeStamp; // when did this happen (relative to prev event)
  571. USHORT Location; // where did this happen
  572. BYTE Info[1]; // info specific to what/where happened
  573. } ARAPDBGHISTORY, *PARAPDBGHISTORY;
  574. #define DBG_HISTORY_BUF_SIZE 4000
  575. typedef struct _DBGMNPHIST
  576. {
  577. DWORD TimeStamp;
  578. DWORD FrameInfo;
  579. } DBGMNPHIST, *PDBGMNPHIST;
  580. #define DBG_MNP_HISTORY_SIZE 80
  581. typedef struct _ARAPCONN
  582. {
  583. LIST_ENTRY Linkage;
  584. #if DBG
  585. DWORD Signature;
  586. #endif
  587. DWORD State; // connected, connecting etc
  588. DWORD RefCount; // memory freed when this goes to 0
  589. MNPSTATE MnpState; // MNP state info
  590. DWORD Flags; // general flag kind of info
  591. ATALK_NODEADDR NetAddr; // network address of the Arap client
  592. PVOID pDllContext; // Araps context
  593. PIRP pIoctlIrp; // irp sent down by the ARAP dll
  594. PIRP pRecvIoctlIrp; // receive irp from ARAP dll
  595. LIST_ENTRY MiscPktsQ; // pkts other than LT queued here
  596. LIST_ENTRY ReceiveQ; // data indicated but not yet processed
  597. LIST_ENTRY ArapDataQ; // data that's waiting for an irp from Arap
  598. LIST_ENTRY HighPriSendQ; // high priority sends
  599. LIST_ENTRY MedPriSendQ; // medium priority sends
  600. LIST_ENTRY LowPriSendQ; // low priority sends
  601. LIST_ENTRY SendAckedQ; // got ack, need to complete this send
  602. LIST_ENTRY RetransmitQ; // data sent out, but not acked yet
  603. DWORD SendsPending; // unacked/unsent sends (bytes) pending
  604. DWORD RecvsPending; // rcvs (bytes) yet to be delivered
  605. TIMERLIST RetryTimer; // the 401 timer (retransmit timer)
  606. LONG LATimer; // the 402 timer
  607. LONG T402Duration; // timer value for the 402 timer
  608. LONG InactivityTimer; // the 403 timer
  609. LONG T403Duration; // timer value for the 403 timer
  610. LONG FlowControlTimer; // the 404 timer
  611. LONG T404Duration; // timer value for the 404 timer
  612. BYTE NdiswanHeader[14]; // 14 byte ethernet-like header
  613. BYTE BlockId; // basically what size sends to use
  614. BYTE UnUsed;
  615. ULONG LinkSpeed; // link speed in 100 bps units
  616. STAT_INFO StatInfo; // statistics for this connection
  617. LONG SendRetryTime; // send timer to fire after how much time
  618. LONG SendRetryBaseTime; // send timer interval at init
  619. ATALK_SPIN_LOCK SpinLock;
  620. KEVENT NodeAcquireEvent; // use while acquiring node (dynamic mode)
  621. LONG LastNpbBrrq; // time we sent out a NBP_BRRQ pkt last
  622. v42bis_connection_t *pV42bis;
  623. #if DBG
  624. LARGE_INTEGER LastTimeStamp; // when did we last record history
  625. DWORD DbgMnpIndex;
  626. DBGMNPHIST DbgMnpHist[DBG_MNP_HISTORY_SIZE];
  627. PBYTE pDbgTraceBuffer; // where the sniff buffer starts
  628. PBYTE pDbgCurrPtr; // currently pointing here in sniff buf
  629. DWORD SniffedBytes; // how much does sniff buffer contain
  630. #endif
  631. } ARAPCONN, *PARAPCONN;
  632. typedef struct _ARAPSNIFF
  633. {
  634. DWORD Signature;
  635. DWORD TimeStamp;
  636. USHORT Length;
  637. BYTE StartSeq;
  638. BYTE EndSeq;
  639. DWORD UncompBytesSoFar;
  640. } ARAPSNIFF, *PARAPSNIFF;
  641. typedef struct _ARAPQITEM
  642. {
  643. WORK_QUEUE_ITEM WorkQItem;
  644. DWORD Action;
  645. PVOID Context1;
  646. PVOID Context2;
  647. } ARAPQITEM, *PARAPQITEM;
  648. #if DBG
  649. #define DBG_ARAP_CHECK_PAGED_CODE() \
  650. { \
  651. if (AtalkPgLkSection[ARAP_SECTION].ls_LockCount <= 0) \
  652. { \
  653. DbgPrint("Arap code section not locked, count=%d\n", \
  654. AtalkPgLkSection[ARAP_SECTION].ls_LockCount); \
  655. ASSERT(0); \
  656. } \
  657. }
  658. #define DBG_PPP_CHECK_PAGED_CODE() \
  659. { \
  660. if (AtalkPgLkSection[PPP_SECTION].ls_LockCount <= 0) \
  661. { \
  662. DbgPrint("PPP code section not locked, count=%d\n", \
  663. AtalkPgLkSection[PPP_SECTION].ls_LockCount); \
  664. ASSERT(0); \
  665. } \
  666. }
  667. #else
  668. #define DBG_ARAP_CHECK_PAGED_CODE()
  669. #define DBG_PPP_CHECK_PAGED_CODE()
  670. #endif
  671. #define ARAP_ID_BYTE1 0xAA
  672. #define ARAP_ID_BYTE2 0xBB
  673. #define PPP_ID_BYTE1 0xCC
  674. #define PPP_ID_BYTE2 0xDD
  675. typedef struct _ATCPCONN
  676. {
  677. LIST_ENTRY Linkage;
  678. #if DBG
  679. DWORD Signature;
  680. #endif
  681. DWORD Flags; // general flag kind of info
  682. DWORD RefCount; // memory freed when this goes to 0
  683. ATALK_NODEADDR NetAddr; // network address of the Arap client
  684. PVOID pDllContext; // Araps context
  685. BYTE NdiswanHeader[14]; // 14 byte ethernet-like header
  686. ATALK_SPIN_LOCK SpinLock;
  687. KEVENT NodeAcquireEvent; // use while acquiring node (dynamic mode)
  688. } ATCPCONN, *PATCPCONN;
  689. #define ATCP_NODE_IN_USE 0x1
  690. #define ATCP_FINDING_NODE 0x2
  691. #define ATCP_SUPPRESS_RTMP 0x4
  692. #define ATCP_SUPPRESS_ALLBCAST 0x8
  693. #define ATCP_DLL_SETUP_DONE 0x10
  694. #define ATCP_LINE_UP_DONE 0x20
  695. #define ATCP_CONNECTION_UP 0x40
  696. #define ATCP_CONNECTION_CLOSING 0x80
  697. // globals
  698. extern struct _PORT_DESCRIPTOR *RasPortDesc;
  699. // spinlock to guard the all the Arap global things
  700. extern ATALK_SPIN_LOCK ArapSpinLock;
  701. // global configuration info
  702. extern ARAPGLOB ArapGlobs;
  703. extern PIRP ArapSelectIrp;
  704. extern DWORD ArapConnections;
  705. extern DWORD ArapStackState;
  706. extern DWORD PPPConnections;
  707. #if DBG
  708. extern PIRP ArapSniffIrp;
  709. extern ARAPSTATS ArapStatistics;
  710. extern DWORD ArapDumpLevel;
  711. extern DWORD ArapDumpLen;
  712. extern DWORD ArapDbgMnpSendSizes[30];
  713. extern DWORD ArapDbgMnpRecvSizes[30];
  714. extern DWORD ArapDbgArapSendSizes[15];
  715. extern DWORD ArapDbgArapRecvSizes[15];
  716. extern LARGE_INTEGER ArapDbgLastTraceTime;
  717. extern UCHAR ArapDbgLRPacket[30];
  718. #endif