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.

1203 lines
48 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1995 Microsoft Corporation
  4. *
  5. * File: irda.h
  6. *
  7. * Description: Definitions used across the IRDA stack
  8. *
  9. * Author: mbert
  10. *
  11. * Date: 4/15/95
  12. *
  13. * This file primarily defines the IRDA message (IRDA_MSG) used for
  14. * communicating with the stack and communication between the layers
  15. * of the stack. IRDA_MSG provides the following services:
  16. * MAC_CONTROL_SERVICE
  17. * IRLAP_DISCOVERY_SERVICE
  18. * IRDA_DISCONNECT_SERVICE
  19. * IRDA_CONNECT_SERVICE
  20. * IRDA_DATA_SERVICE
  21. * IRLMP_ACCESSMODE_SERVICE
  22. * IRLMP_IAS_SERVICE
  23. *
  24. * IRDA_MSG usage:
  25. *
  26. * +-------+
  27. * | IRLAP |
  28. * +-------+
  29. * |
  30. * | IrmacDown(IRDA_MSG)
  31. * \|/
  32. * +-------+
  33. * | IRMAC |
  34. * +-------+
  35. * |*************************************************************************|
  36. * | Prim | MsgType and parameters |
  37. * |=========================================================================|
  38. * | MAC_DATA_REQ | IRDA_DATA_SERVICE |
  39. * | | o IRDA_MSG_pHdrRead = start of IRDA headers|
  40. * | | o IRDA_MSG_pHdrWrite = end of header |
  41. * | | o IRDA_MSG_pRead = start of data |
  42. * | | o IRDA_MSG_pWrite = end of data |
  43. * |--------------------------+----------------------------------------------|
  44. * | MAC_DATA_RESP | no parms (completetion of DATA_IND) |
  45. * |--------------------------+----------------------------------------------|
  46. * | MAC_CONTROL_REQ | MAC_CONTROL_SERVICE |
  47. * | | o IRDA_MSG_Op = MAC_INITIALIZIE_LINK |
  48. * | | - IRDA_MSG_Port |
  49. * | | - IRDA_MSG_Baud |
  50. * | | - IRDA_MSG_MinTat = min turn time |
  51. * | | - IRDA_MSG_NumBOFs = # added when tx'ing |
  52. * | | - IRDA_MSG_DataSize = max rx frame |
  53. * | | - IRDA_MSG_SetIR = TRUE/FALSE (does an |
  54. * | | EscapeComm(SETIR) to select int/ext |
  55. * | | dongle) |
  56. * | | o IRDA_MSG_Op = MAC_MEDIA_SENSE |
  57. * | | - IRDA_MSG_SenseTime (in ms) |
  58. * | | o IRDA_MSG_Op = MAC_RECONFIG_LINK |
  59. * | | - IRDA_MSG_Baud |
  60. * | | - IRDA_MSG_NumBOFs = # added when tx'ing |
  61. * | | - IRDA_MSG_DataSize = max rx frame |
  62. * | | - IRDA_MSG_MinTat = min turn time |
  63. * | | o IRDA_MSG_OP = MAC_CLOSE_LINK |
  64. * |-------------------------------------------------------------------------|
  65. *
  66. * +-------+
  67. * | IRLAP |
  68. * +-------+
  69. * /|\
  70. * | IrlapUp(IRDA_MSG)
  71. * |
  72. * +-------+
  73. * | IRMAC |
  74. * +-------+
  75. * |*************************************************************************|
  76. * | Prim | MsgType and parameters |
  77. * |=========================================================================|
  78. * | MAC_DATA_IND | IRDA_DATA_SERVICE |
  79. * | | o IRDA_MSG_pRead = start of frame |
  80. * | | (includes IRLAP header)|
  81. * | | o IRDA_MSG_pWrite = end of frame |
  82. * | | (excludes FCS) |
  83. * |--------------------------+----------------------------------------------|
  84. * | MAC_CONTROL_CONF | MAC_CONTROL_SERVICE |
  85. * | | o IRDA_MSG_Op = MAC_MEDIA_SENSE |
  86. * | | - IRDA_MSG_OpStatus = MAC_MEDIA_BUSY |
  87. * | | MAC_MEDIA_CLEAR |
  88. * |--------------------------+----------------------------------------------|
  89. * | MAC_DATA_CONF | no parms |
  90. * |-------------------------------------------------------------------------|
  91. *
  92. * +-------+
  93. * | IRLMP |
  94. * +-------+
  95. * |
  96. * | IrlapDown(IRDA_MSG)
  97. * \|/
  98. * +-------+
  99. * | IRLAP |
  100. * +-------+
  101. * |*************************************************************************|
  102. * | Prim | MsgType and parameters |
  103. * |=========================================================================|
  104. * | IRLAP_DISCOVERY_REQ | IRLAP_DISCOVERY_SERVICE |
  105. * | IRLAP_Down() returns | o IRDA_MSG_SenseMedia = TRUE/FALSE |
  106. * | IRLAP_REMOTE_DISCOVERY_IN_PROGRESS_ERR or |
  107. * | IRLAP_REMOTE_CONNECT_IN_PROGRESS_ERR when indicated |
  108. * |--------------------------+----------------------------------------------|
  109. * | IRLAP_CONNECT_REQ | IRDA_CONNECT_SERVICE |
  110. * | | o IRDA_MSG_RemoteDevAddr |
  111. * | IRLAP_Down() returns | |
  112. * | IRLAP_REMOTE_DISCOVERY_IN_PROGRESS_ERR when indicated |
  113. * |--------------------------+----------------------------------------------|
  114. * | IRLAP_CONNECT_RESP | no parms |
  115. * |--------------------------+----------------------------------------------|
  116. * | IRLAP_DISCONNECT_REQ | no parms |
  117. * |--------------------------+----------------------------------------------|
  118. * | IRLAP_DATA_REQ | IRDA_DATA_SERVICE |
  119. * | IRLAP_UDATA_REQ | o IRDA_MSG_pHdrRead = start of IRLMP header|
  120. * | IRLAP_Down() returns | o IRDA_MSG_pHdrWrite = end of header |
  121. * | IRLAP_REMOTE_BUSY to | o IRDA_MSG_pRead = start of data |
  122. * | to flow off LMP. | o IRDA_MSG_pWrite = end of data |
  123. * | | o IRDA_MSG_Expedited=TRUE/FALSE |
  124. * |-------------------------------------------------------------------------|
  125. * | IRLAP_FLOWON_REQ | no parms |
  126. * |-------------------------------------------------------------------------|
  127. *
  128. * +-------+
  129. * | IRLMP |
  130. * +-------+
  131. * /|\
  132. * | IrlmpUp(IRDA_MSG)
  133. * |
  134. * +-------+
  135. * | IRLAP |
  136. * +-------+
  137. * |*************************************************************************|
  138. * | Prim | MsgType and parameters |
  139. * |=========================================================================|
  140. * | IRLAP_DISCOVERY_IND | IRLAP_DISCOVERY_SERVICE |
  141. * | | o pDevList = Discovery info of device that |
  142. * | | initiated discovery |
  143. * |--------------------------+----------------------------------------------|
  144. * | IRLAP_DISCOVERY_CONF | IRLAP_DISCOVERY_SERVICE |
  145. * | | o IRDA_MSG_pDevList = list of discovered |
  146. * | | devices, NULL when |
  147. * | | status != IRLAP_DISCOVERY_COMPLETED |
  148. * | | o IRDA_MSG_DscvStatus = |
  149. * | | MAC_MEDIA_BUSY |
  150. * | | IRLAP_REMOTE_DISCOVERY_IN_PROGRESS |
  151. * | | IRLAP_DISCOVERY_COLLISION |
  152. * | | IRLAP_REMOTE_CONNECTION_IN_PROGRESS |
  153. * | | IRLAP_DISCOVERY_COMPLETED |
  154. * |--------------------------+----------------------------------------------|
  155. * | IRLAP_CONNECT_IND | IRDA_CONNECT_SERVICE |
  156. * | | o IRDA_MSG_RemoteDevAddr |
  157. * | | o IRDA_MSG_pQos = Negotiated QOS |
  158. * |-------------------------------------------------------------------------|
  159. * | IRLAP_CONNECT_CONF | IRDA_CONNECT_SERVICE |
  160. * | | o IRDA_MSG_pQos = Negotiated QOS, only when|
  161. * | | successful |
  162. * | | o IRDA_MSG_ConnStatus = |
  163. * | | IRLAP_CONNECTION_COMPLETE|
  164. * |--------------------------+----------------------------------------------|
  165. * | IRLAP_DISCONNECT_IND | IRDA_DISCONNECT_SERVICE |
  166. * | | o IRDA_MSG_DiscStatus = |
  167. * | | IRLAP_DISCONNECT_COMPLETED |
  168. * | | IRLAP_REMOTED_INITIATED |
  169. * | | IRLAP_PRIMARY_CONFLICT |
  170. * | | IRLAP_REMOTE_DISCOVERY_IN_PROGRESS |
  171. * | | IRLAP_NO_RESPONSE |
  172. * | | IRLAP_DECLINE_RESET |
  173. * | | MAC_MEDIA_BUSY |
  174. * |--------------------------+----------------------------------------------|
  175. * | IRLAP_DATA_IND | IRDA_DATA_SERVICE |
  176. * | IRLAP_UDATA_IND | o IRDA_MSG_pRead = start of IRLMP packet |
  177. * | | o IRDA_MSG_pWrite = end of IRLMP packet |
  178. * |--------------------------+----------------------------------------------|
  179. * | IRLAP_DATA_CONF | IRDA_DATA_SERVICE |
  180. * | IRLAP_UDATA_CONF | o IRDA_MSG_DataStatus = |
  181. * | | ILAP_DATA_REQUEST_COMPLETED |
  182. * | | IRLAP_DATA_REQUEST_FAILED_LINK_RESET |
  183. * |--------------------------+----------------------------------------------|
  184. * | IRLAP_STATUS_IND | IRDA_MSG_pLinkStatus |
  185. * |-------------------------------------------------------------------------|
  186. *
  187. * +-----+
  188. * | Tdi |
  189. * +-----+
  190. * |
  191. * | IrlmpDown(IRLMPContext, IRDA_MSG)
  192. * \|/
  193. * +-------+
  194. * | IRLMP |
  195. * +-------+
  196. * |*************************************************************************|
  197. * | Prim | MsgType and parameters |
  198. * |=========================================================================|
  199. * | IRLMP_DISCOVERY_REQ | IRLAP_DISCOVERY_SERVICE |
  200. * | | o IRDA_MSG_SenseMedia = TRUE/FALSE |
  201. * |--------------------------+----------------------------------------------|
  202. * | IRLMP_CONNECT_REQ | IRDA_CONNECT_SERVICE |
  203. * | IRLMP_Down() returns | o IRDA_MSG_RemoteDevAddr |
  204. * | IRLMP_LINK_IN_USE | o IRDA_MSG_RemoteLsapSel |
  205. * | when the requested | o IRDA_MSG_pQos (may be NULL) |
  206. * | connection is to a | o IRDA_MSG_pConnData |
  207. * | remote device other | o IRDA_MSG_ConnDataLen |
  208. * | than the one the link | o IRDA_MSG_LocalLsapSel |
  209. * | is currently connected | o IRDA_MSG_pContext |
  210. * | or connecting to. | o IRDA_MSG_UseTtp |
  211. * | | * o IRDA_MSG_TtpCredits |
  212. * | | o IRDA_MSG_MaxSDUSize - Max size that this |
  213. * | | IRLMP client can receive. |
  214. * | | |
  215. * | | * even if not using TTP, TtpCredits are spec-|
  216. * | | ified for flow control in exclusive mode |
  217. * |--------------------------+----------------------------------------------|
  218. * | IRLMP_CONNECT_RESP | IRDA_CONNECT_SERVICE |
  219. * | | o IRDA_MSG_pConnData |
  220. * | | o IRDA_MSG_ConnDataLen |
  221. * | | o IRDA_MSG_pContext |
  222. * | | o IRDA_MSG_MaxSDUSize - Max size that this |
  223. * | | IRLMP client can receive. |
  224. * | | * o IRDA_MSG_TtpCredits |
  225. * | | * see above |
  226. * |--------------------------+----------------------------------------------|
  227. * | IRLMP_DISCONNECT_REQ | IRDA_DISCONNECT_SERVICE |
  228. * | | o IRDA_MSG_pDiscData |
  229. * | | o IRDA_MSG_DiscDataLen |
  230. * | | o IRDA_MSG_pDiscContext |
  231. * |--------------------------+----------------------------------------------|
  232. * | IRLMP_DATA/UDATA_REQ | IRDA_DATA_SERVICE |
  233. * | IRLMP_Down() may return| o IRDA_MSG_pDataContext =ptr to NDIS_BUFFER|
  234. * | IRLMP_REMOTE_BUSY, | o IRDA_MSG_IrCOMM_9Wire = TRUE/FALSE |
  235. * | when tx cred exhausted| |
  236. * | in multiplexed mode. | |
  237. * | IRLAP_REMOTE_BUSY, | |
  238. * | when remote IRLAP | |
  239. * | flowed off in exclMode| |
  240. * | In either case the req | |
  241. * | was successful. | |
  242. * |-------------------------------------------------------------------------|
  243. * | IRLMP_ACCESSMODE_REQ | IRLMP_ACCESSMODE_SERVICE |
  244. * | IRLMP_Down() may return| o IRDA_MSG_AccessMode = IRLMP_MULTIPLEXED |
  245. * | IRLMP_IN_EXCLUSIVE_MODE| IRLMP_EXCLUSIVE |
  246. * | if already in excl-mode| o IRDA_MSG_IrLPTMode - TRUE, doesn't send |
  247. * | IRLMP_IN_MULTIPLEXED...| the Access PDU |
  248. * | if other LSAPs exist or| |
  249. * | requesting trans to this state when already in it. |
  250. * |-------------------------------------------------------------------------|
  251. * | IRLMP_MORECREDIT_REQ | IRDA_CONNECT_SERVICE |
  252. * | | o IRDA_MSG_TtpCredits |
  253. * |-------------------------------------------------------------------------|
  254. * | IRLMP_GETVALUEBYCLASS_REQ| IRDA_IAS_SERVICE |
  255. * | | o IRDA_MSG_pIasQuery |
  256. * | | o IRDA_MSG_AttribLen |
  257. * |-------------------------------------------------------------------------|
  258. * | IRLMP_REGISTERLSAP_REQ | IRDA_CONNECT_SERVICE |
  259. * | | o IRDA_MSG_LocalLsapSel |
  260. * | | o IRDA_MSG_UseTtp |
  261. * |-------------------------------------------------------------------------|
  262. * | IRLMP_DEREGISTERLSAP_REQ | IRDA_CONNECT_SERVICE |
  263. * | | o IRDA_MSG_LocalLsapSel |
  264. * |-------------------------------------------------------------------------|
  265. * | IRLMP_ADDATTRIBUTE_REQ | IRDA_IAS_SERVICE |
  266. * | | o IRDA_MSG_pIasSet |
  267. * | | o IRDA_MSG_pAttribHandle (return value) |
  268. * |-------------------------------------------------------------------------|
  269. * | IRLMP_DELATTRIBUTE_REQ | IRDA_IAS_SERVICE |
  270. * | | o IRDA_MSG_AttribHandle |
  271. * |-------------------------------------------------------------------------|
  272. * | IRLMP_CLOSELSAP_REQ | no parms |
  273. * |-------------------------------------------------------------------------|
  274. * | IRLMP_FLUSHDSCV_REQ | no parms |
  275. * |-------------------------------------------------------------------------|
  276. * | IRLAP_STATUS_REQ | IRDA_MSG_pLinkStatus |
  277. * |-------------------------------------------------------------------------|
  278. *
  279. *
  280. * +-----+
  281. * | Tdi |
  282. * +-----+
  283. * /|\
  284. * | TdiUp(TransportAPIContext, IRDA_MSG)
  285. * |
  286. * +-------+
  287. * | IRLMP |
  288. * +-------+
  289. * |*************************************************************************|
  290. * | Prim | MsgType and parameters |
  291. * |=========================================================================|
  292. * | IRLMP_DISCOVERY_IND | IRLAP_DISCOVERY_SERVICE |
  293. * | | o pDevList = aged Discovery list |
  294. * |--------------------------+----------------------------------------------|
  295. * | IRLMP_DISCOVERY_CONF | same as IRLAP_DISCOVERY_CONF. The device list|
  296. * | | however is the one maintained in IRLMP |
  297. * |--------------------------+----------------------------------------------|
  298. * | IRLMP_DISCONNECT_IND | IRDA_DISCONNECT_SERVICE |
  299. * | | o IRDA_MSG_DiscReason = |
  300. * | | see IRLMP_DISC_REASON below |
  301. * | | o IRDA_MSG_pDiscData - may be NULL |
  302. * | | o IRDA_MSG_DiscDataLen |
  303. * |--------------------------+----------------------------------------------|
  304. * | IRLMP_CONNECT_IND | IRDA_CONNECT_SERVICE |
  305. * | | o IRDA_MSG_RemoteDevAddr |
  306. * | | o IRDA_MSG_RemoteLsapSel; |
  307. * | | o IRDA_MSG_LocalLsapSel; |
  308. * | | o IRDA_MSG_pQos |
  309. * | | o IRDA_MSG_pConnData |
  310. * | | o IRDA_MSG_ConnDataLen |
  311. * | | o IRDA_MSG_pContext |
  312. * | | o IRDA_MSG_MaxSDUSize - Max size that this |
  313. * | | IRLMP client can send to peer |
  314. * | | o IRDA_MSG_MaxPDUSize |
  315. * |--------------------------+----------------------------------------------|
  316. * | IRLMP_CONNECT_CONF | IRDA_CONNECT_SERVICE |
  317. * | | o IRDA_MSG_pQos |
  318. * | | o IRDA_MSG_pConnData |
  319. * | | o IRDA_MSG_ConnDataLen |
  320. * | | o IRDA_MSG_pContext |
  321. * | | o IRDA_MSG_MaxSDUSize - Max size that this |
  322. * | | IRLMP client can send to peer |
  323. * | | o IRDA_MSG_MaxPDUSize |
  324. * |--------------------------+----------------------------------------------|
  325. * | IRLMP_DATA_IND | IRDA_DATA_SERVICE |
  326. * | | o IRDA_MSG_pRead = start of User Data |
  327. * | | o IRDA_MSG_pWrite = end of User Data |
  328. * | | o IRDA_MSG_SegFlags = 0 or SEG_FINAL |
  329. * |--------------------------+----------------------------------------------|
  330. * | IRLMP_DATA_CONF | IRDA_DATA_SERVICE |
  331. * | | o IRDA_MSG_pDataContext =ptr to NDIS_BUFFER|
  332. * | | o IRDA_MSG_DataStatus = |
  333. * | | IRLMP_DATA_REQUEST_COMPLETED |
  334. * | | IRLMP_DATA_REQUEST_FAILED |
  335. * |--------------------------+----------------------------------------------|
  336. * | IRLMP_ACCESSMODE_IND | IRLMP_ACCESSMODE_SERVICE |
  337. * | | o IRDA_MSG_AccessMode = |
  338. * | | IRLMP_EXCLUSIVE |
  339. * | | IRLMP_MULTIPLEXED |
  340. * |--------------------------+----------------------------------------------|
  341. * | IRLMP_ACCESSMODE_CONF | IRLMP_ACCESSMODE_SERVICE |
  342. * | | o IRDA_MSG_AccessMode = |
  343. * | | IRLMP_EXCLUSIVE |
  344. * | | IRLMP_MULTIPLEXED |
  345. * | | o IRDA_MSG_ModeStatus = |
  346. * | | IRLMP_ACCESSMODE_SUCCESS |
  347. * | | IRLMP_ACCESSMODE_FAILURE |
  348. * |--------------------------+----------------------------------------------|
  349. * |IRLMP_GETVALUEBYCLASS_CONF| IRDA_DATA_SERVICE |
  350. * | | o IRDA_MSG_pIasQuery |
  351. * | | o IRDA_MSG_IASStatus = An IRLMP_DISC_REASON|
  352. * | | (see below) |
  353. * |-------------------------------------------------------------------------|
  354. */
  355. #include <ntddk.h>
  356. #include <cxport.h>
  357. #include <ndis.h>
  358. #include <af_irda.h>
  359. #include <irerr.h>
  360. #include <irmem.h>
  361. #include <dbgmsg.h>
  362. #include <refcnt.h>
  363. #define IRDA_MSG_DATA_SIZE_INTERNAL sizeof(IRDA_MSG)+128 // can this be smaller?
  364. //#define TEMPERAMENTAL_SERIAL_DRIVER // drivers busted. intercharacter delays cause
  365. // IrLAP to reset.
  366. #if DBG
  367. // Prototypes for Debugging Output
  368. void IRDA_DebugOut (TCHAR *pFormat, ...);
  369. void IRDA_DebugStartLog (void);
  370. void IRDA_DebugEndLog (void *, void *);
  371. #endif
  372. //#define DBG_CHECKSUM 1
  373. //#define DBG_BADDRIVER 1
  374. #define DBG_NDIS 0x00000002 // keep in sync with test\irdakdx
  375. #define DBG_TIMER 0x00000004
  376. #define DBG_IRMAC 0x00000008
  377. #define DBG_IRLAP 0x00000010
  378. #define DBG_IRLAPLOG 0x00000020
  379. #define DBG_RXFRAME 0x00000040
  380. #define DBG_TXFRAME 0x00000080
  381. #define DBG_IRLMP 0x00000100
  382. #define DBG_IRLMP_CONN 0x00000200
  383. #define DBG_IRLMP_CRED 0x00000400
  384. #define DBG_IRLMP_IAS 0x00000800
  385. #define DBG_DISCOVERY 0x00001000
  386. #define DBG_PRINT 0x00002000
  387. #define DBG_ADDR 0x00004000
  388. #define DBG_REF 0x00010000
  389. #define DBG_TDI 0x00020000
  390. #define DBG_TDI_IRP 0x00040000
  391. #define DBG_ALLOC 0x10000000
  392. #define DBG_FUNCTION 0x20000000
  393. #define DBG_WARN 0x40000000
  394. #define DBG_ERROR 0x80000000
  395. #define STATIC
  396. typedef struct
  397. {
  398. CTETimer CteTimer;
  399. CTEEvent CteEvent;
  400. VOID (*ExpFunc)(PVOID Context);
  401. PVOID Context;
  402. UINT Timeout;
  403. BOOLEAN Late;
  404. struct IrdaLinkCb *pIrdaLinkCb;
  405. #if DBG
  406. char *pName;
  407. #endif
  408. } IRDA_TIMER, *PIRDA_TIMER;
  409. typedef struct
  410. {
  411. CTEEvent CteEvent; // Must be first field
  412. VOID (*Callback)(PVOID Context);
  413. } IRDA_EVENT, *PIRDA_EVENT;
  414. #define IRMAC_CONTEXT(ilcb) ((ilcb)->IrmacContext)
  415. #define IRLAP_CONTEXT(ilcb) ((ilcb)->IrlapContext)
  416. #define IRLMP_CONTEXT(ilcb) ((ilcb)->IrlmpContext)
  417. // Device/Discovery Information
  418. #define IRLAP_DSCV_INFO_LEN 32
  419. #define IRDA_DEV_ADDR_LEN 4
  420. typedef struct
  421. {
  422. LIST_ENTRY Linkage;
  423. UCHAR DevAddr[IRDA_DEV_ADDR_LEN];
  424. int DscvMethod;
  425. int IRLAP_Version;
  426. UCHAR DscvInfo[IRLAP_DSCV_INFO_LEN];
  427. int DscvInfoLen;
  428. int NotSeenCnt; // used by IRLMP to determine when to remove
  429. // the device from its list
  430. } IRDA_DEVICE;
  431. #define IRDA_NDIS_BUFFER_POOL_SIZE 8
  432. #define IRDA_NDIS_PACKET_POOL_SIZE 8
  433. #define IRDA_MSG_LIST_LEN 2
  434. #define IRDA_MSG_DATA_SIZE 64
  435. typedef struct
  436. {
  437. LIST_ENTRY Linkage;
  438. struct irda_msg *pMsg;
  439. #if DBG_TIMESTAMP
  440. int TimeStamp[4];
  441. #endif
  442. MEDIA_SPECIFIC_INFORMATION MediaInfo;
  443. } IRDA_PROTOCOL_RESERVED, *PIRDA_PROTOCOL_RESERVED;
  444. #define IRDA_RX_SYSTEM_THREAD
  445. typedef struct IrdaLinkCb
  446. {
  447. LIST_ENTRY Linkage;
  448. PVOID IrlapContext;
  449. PVOID IrlmpContext;
  450. NDIS_SPIN_LOCK SpinLock;
  451. KMUTEX Mutex;
  452. NDIS_HANDLE UnbindContext;
  453. NDIS_HANDLE NdisBindingHandle;
  454. NDIS_EVENT OpenCloseEvent;
  455. NDIS_STATUS OpenCloseStatus;
  456. NDIS_EVENT ResetEvent;
  457. PVOID PnpContext;
  458. IRDA_TIMER MediaSenseTimer;
  459. int MediaBusy;
  460. NDIS_HANDLE BufferPool;
  461. NDIS_HANDLE PacketPool;
  462. LIST_ENTRY PacketList;
  463. LIST_ENTRY TxMsgFreeList;
  464. int TxMsgFreeListLen;
  465. LIST_ENTRY RxMsgFreeList;
  466. int RxMsgFreeListLen;
  467. LIST_ENTRY RxMsgList;
  468. #ifdef IRDA_RX_SYSTEM_THREAD
  469. KEVENT EvRxMsgReady;
  470. KEVENT EvKillRxThread;
  471. HANDLE hRxThread;
  472. #else
  473. IRDA_EVENT EvRxMsgReady;
  474. #endif
  475. int RxMsgDataSize;
  476. UINT ExtraBofs; // These should be per connection for
  477. UINT MinTat; // multipoint
  478. BOOLEAN WaitMinTat;
  479. BOOLEAN LowPowerSt;
  480. LONG SendOutCnt;
  481. PNET_PNP_EVENT pNetPnpEvent;
  482. REF_CNT RefCnt;
  483. #if DBG
  484. int LastTime;
  485. int DelayedRxFrameCnt;
  486. #endif
  487. } IRDA_LINK_CB, *PIRDA_LINK_CB;
  488. // IRLAP Quality of Service
  489. #define BIT_0 1
  490. #define BIT_1 2
  491. #define BIT_2 4
  492. #define BIT_3 8
  493. #define BIT_4 16
  494. #define BIT_5 32
  495. #define BIT_6 64
  496. #define BIT_7 128
  497. #define BIT_8 256
  498. #define BPS_2400 BIT_0 // Baud Rates
  499. #define BPS_9600 BIT_1
  500. #define BPS_19200 BIT_2
  501. #define BPS_38400 BIT_3
  502. #define BPS_57600 BIT_4
  503. #define BPS_115200 BIT_5
  504. #define BPS_4000000 BIT_8
  505. #define MAX_TAT_500 BIT_0 // Maximum Turnaround Time (millisecs)
  506. #define MAX_TAT_250 BIT_1
  507. #define MAX_TAT_100 BIT_2
  508. #define MAX_TAT_50 BIT_3
  509. #define MAX_TAT_25 BIT_4
  510. #define MAX_TAT_10 BIT_5
  511. #define MAX_TAT_5 BIT_6
  512. #define DATA_SIZE_64 BIT_0 // Data Size (bytes)
  513. #define DATA_SIZE_128 BIT_1
  514. #define DATA_SIZE_256 BIT_2
  515. #define DATA_SIZE_512 BIT_3
  516. #define DATA_SIZE_1024 BIT_4
  517. #define DATA_SIZE_2048 BIT_5
  518. #define FRAMES_1 BIT_0 // Window Size
  519. #define FRAMES_2 BIT_1
  520. #define FRAMES_3 BIT_2
  521. #define FRAMES_4 BIT_3
  522. #define FRAMES_5 BIT_4
  523. #define FRAMES_6 BIT_5
  524. #define FRAMES_7 BIT_6
  525. #define BOFS_48 BIT_0 // Additional Beginning of Frame Flags
  526. #define BOFS_24 BIT_1
  527. #define BOFS_12 BIT_2
  528. #define BOFS_5 BIT_3
  529. #define BOFS_3 BIT_4
  530. #define BOFS_2 BIT_5
  531. #define BOFS_1 BIT_6
  532. #define BOFS_0 BIT_7
  533. #define MIN_TAT_10 BIT_0 // Minumum Turnaround Time (millisecs)
  534. #define MIN_TAT_5 BIT_1
  535. #define MIN_TAT_1 BIT_2
  536. #define MIN_TAT_0_5 BIT_3
  537. #define MIN_TAT_0_1 BIT_4
  538. #define MIN_TAT_0_05 BIT_5
  539. #define MIN_TAT_0_01 BIT_6
  540. #define MIN_TAT_0 BIT_7
  541. #define DISC_TIME_3 BIT_0 // Link Disconnect/Threshold Time (seconds)
  542. #define DISC_TIME_8 BIT_1
  543. #define DISC_TIME_12 BIT_2
  544. #define DISC_TIME_16 BIT_3
  545. #define DISC_TIME_20 BIT_4
  546. #define DISC_TIME_25 BIT_5
  547. #define DISC_TIME_30 BIT_6
  548. #define DISC_TIME_40 BIT_7
  549. typedef struct
  550. {
  551. UINT bfBaud;
  552. UINT bfMaxTurnTime;
  553. UINT bfDataSize;
  554. UINT bfWindowSize;
  555. UINT bfBofs;
  556. UINT bfMinTurnTime;
  557. UINT bfDisconnectTime; // holds threshold time also
  558. } IRDA_QOS_PARMS;
  559. // IrDA Message Primitives
  560. typedef enum
  561. {
  562. MAC_DATA_REQ = 0, // Keep in sync with table in irlaplog.c
  563. MAC_DATA_IND,
  564. MAC_DATA_RESP,
  565. MAC_DATA_CONF,
  566. MAC_CONTROL_REQ,
  567. MAC_CONTROL_CONF,
  568. IRLAP_DISCOVERY_REQ,
  569. IRLAP_DISCOVERY_IND,
  570. IRLAP_DISCOVERY_CONF,
  571. IRLAP_CONNECT_REQ,
  572. IRLAP_CONNECT_IND,
  573. IRLAP_CONNECT_RESP,
  574. IRLAP_CONNECT_CONF,
  575. IRLAP_DISCONNECT_REQ,
  576. IRLAP_DISCONNECT_IND,
  577. IRLAP_DATA_REQ, // Don't fuss with the order, CONF must be 2 from REQ
  578. IRLAP_DATA_IND,
  579. IRLAP_DATA_CONF,
  580. IRLAP_UDATA_REQ,
  581. IRLAP_UDATA_IND,
  582. IRLAP_UDATA_CONF,
  583. IRLAP_STATUS_REQ,
  584. IRLAP_STATUS_IND,
  585. IRLAP_FLOWON_REQ,
  586. IRLMP_DISCOVERY_REQ,
  587. IRLMP_DISCOVERY_IND,
  588. IRLMP_DISCOVERY_CONF,
  589. IRLMP_CONNECT_REQ,
  590. IRLMP_CONNECT_IND,
  591. IRLMP_CONNECT_RESP,
  592. IRLMP_CONNECT_CONF,
  593. IRLMP_DISCONNECT_REQ,
  594. IRLMP_DISCONNECT_IND,
  595. IRLMP_DATA_REQ,
  596. IRLMP_DATA_IND,
  597. IRLMP_DATA_CONF,
  598. IRLMP_UDATA_REQ,
  599. IRLMP_UDATA_IND,
  600. IRLMP_UDATA_CONF,
  601. IRLMP_ACCESSMODE_REQ,
  602. IRLMP_ACCESSMODE_IND,
  603. IRLMP_ACCESSMODE_CONF,
  604. IRLMP_MORECREDIT_REQ,
  605. IRLMP_GETVALUEBYCLASS_REQ,
  606. IRLMP_GETVALUEBYCLASS_CONF,
  607. IRLMP_REGISTERLSAP_REQ,
  608. IRLMP_DEREGISTERLSAP_REQ,
  609. IRLMP_ADDATTRIBUTE_REQ,
  610. IRLMP_DELATTRIBUTE_REQ,
  611. IRLMP_CLOSELSAP_REQ,
  612. IRLMP_FLUSHDSCV_REQ
  613. } IRDA_SERVICE_PRIM;
  614. typedef enum
  615. {
  616. MAC_MEDIA_BUSY, // keep in sync with IRDA_StatStr in irlaplog.c
  617. MAC_MEDIA_CLEAR,
  618. IRLAP_DISCOVERY_COLLISION,
  619. IRLAP_REMOTE_DISCOVERY_IN_PROGRESS,
  620. IRLAP_REMOTE_CONNECT_IN_PROGRSS,
  621. IRLAP_DISCOVERY_COMPLETED,
  622. IRLAP_REMOTE_CONNECTION_IN_PROGRESS,
  623. IRLAP_CONNECTION_COMPLETED,
  624. IRLAP_REMOTE_INITIATED,
  625. IRLAP_PRIMARY_CONFLICT,
  626. IRLAP_DISCONNECT_COMPLETED,
  627. IRLAP_NO_RESPONSE,
  628. IRLAP_DECLINE_RESET,
  629. IRLAP_DATA_REQUEST_COMPLETED,
  630. IRLAP_DATA_REQUEST_FAILED_LINK_RESET,
  631. IRLAP_DATA_REQUEST_FAILED_REMOTE_BUSY,
  632. IRLMP_NO_RESPONSE,
  633. IRLMP_ACCESSMODE_SUCCESS,
  634. IRLMP_ACCESSMODE_FAILURE,
  635. IRLMP_DATA_REQUEST_COMPLETED,
  636. IRLMP_DATA_REQUEST_FAILED
  637. } IRDA_SERVICE_STATUS;
  638. // MAC Control Service Request Message - MAC_CONTROL_REQ/CONF
  639. typedef enum
  640. {
  641. MAC_INITIALIZE_LINK, // keep in sync with MAC_OpStr in irlaplog.c
  642. MAC_CLOSE_LINK,
  643. MAC_RECONFIG_LINK,
  644. MAC_MEDIA_SENSE,
  645. } MAC_CONTROL_OPERATION;
  646. typedef struct
  647. {
  648. MAC_CONTROL_OPERATION Op;
  649. int Port;
  650. int Baud;
  651. int NumBOFs;
  652. int MinTat;
  653. int DataSize;
  654. int SenseTime;
  655. IRDA_SERVICE_STATUS OpStatus;
  656. BOOLEAN SetIR;
  657. } MAC_CONTROL_SERVICE;
  658. // IRLAP Discovery Service Request Message - IRLAP_DISCOVERY_IND/CONF
  659. typedef struct
  660. {
  661. LIST_ENTRY *pDevList;
  662. IRDA_SERVICE_STATUS DscvStatus;
  663. BOOLEAN SenseMedia;
  664. } IRLAP_DISCOVERY_SERVICE;
  665. // IRDA Connection Service Request Message - IRLAP_CONNECT_REQ/IND/CONF
  666. // IRLMP_CONNECT_REQ/CONF
  667. typedef struct
  668. {
  669. UCHAR RemoteDevAddr[IRDA_DEV_ADDR_LEN];
  670. IRDA_QOS_PARMS *pQos;
  671. int LocalLsapSel;
  672. int RemoteLsapSel;
  673. UCHAR *pConnData;
  674. int ConnDataLen;
  675. void *pContext;
  676. int MaxPDUSize;
  677. int MaxSDUSize;
  678. int TtpCredits;
  679. IRDA_SERVICE_STATUS ConnStatus;
  680. BOOLEAN UseTtp;
  681. } IRDA_CONNECT_SERVICE;
  682. // IRDA Disconnection Service Request Message - IRLAP_DISCONNECT_REQ/IND
  683. // IRLMP_DISCONNECT_REQ/IND
  684. typedef enum
  685. {
  686. IRLMP_USER_REQUEST = 1,
  687. IRLMP_UNEXPECTED_IRLAP_DISC,
  688. IRLMP_IRLAP_CONN_FAILED,
  689. IRLMP_IRLAP_RESET,
  690. IRLMP_LM_INITIATED_DISC,
  691. IRLMP_DISC_LSAP,
  692. IRLMP_NO_RESPONSE_LSAP,
  693. IRLMP_NO_AVAILABLE_LSAP,
  694. IRLMP_MAC_MEDIA_BUSY,
  695. IRLMP_IRLAP_REMOTE_DISCOVERY_IN_PROGRESS,
  696. IRLMP_IAS_NO_SUCH_OBJECT, // these are added for the IAS_GetValueByClass.Conf
  697. IRLMP_IAS_NO_SUCH_ATTRIB,
  698. IRLMP_IAS_FAILED,
  699. IRLMP_IAS_SUCCESS,
  700. IRLMP_IAS_SUCCESS_LISTLEN_GREATER_THAN_ONE,
  701. IRLMP_UNSPECIFIED_DISC = 0xFF
  702. } IRLMP_DISC_REASON;
  703. typedef struct
  704. {
  705. UCHAR *pDiscData; // IRLMP_DISCONNECT_REQ/IND only
  706. int DiscDataLen; // IRLMP_DISCONNECT_REQ/IND only
  707. IRLMP_DISC_REASON DiscReason; // IRLMP_DISCONNECT_REQ/IND only
  708. IRDA_SERVICE_STATUS DiscStatus; // Indication only
  709. void *pDiscContext;
  710. } IRDA_DISCONNECT_SERVICE;
  711. // IRDA Data Service Request Message
  712. #define IRLAP_HEADER_LEN 2
  713. #define IRLMP_HEADER_LEN 6
  714. #define TTP_HEADER_LEN 8
  715. #define IRDA_HEADER_LEN IRLAP_HEADER_LEN+IRLMP_HEADER_LEN+TTP_HEADER_LEN+1
  716. // + 1 IRComm WACK!!
  717. #define SEG_FINAL 1
  718. #define SEG_LOCAL 2
  719. typedef struct
  720. {
  721. void *pOwner;
  722. int SegCount; // Number of segments
  723. UINT SegFlags;
  724. UCHAR *pBase;
  725. UCHAR *pLimit;
  726. UCHAR *pRead;
  727. UCHAR *pWrite;
  728. void *pTdiSendComp;
  729. void *pTdiSendCompCnxt;
  730. LONG RefCnt;
  731. BOOLEAN IrCOMM_9Wire;
  732. BOOLEAN Expedited;
  733. #ifdef TEMPERAMENTAL_SERIAL_DRIVER
  734. int FCS;
  735. #endif
  736. IRDA_SERVICE_STATUS DataStatus; // for CONF
  737. // |------------------------|
  738. // | pRead o-------------
  739. // |------------------------| |
  740. // | pWrite o---------- |
  741. // |------------------------| | |
  742. // | pBase o------- | |
  743. // |------------------------| | | |
  744. // | pLimit o---- | | |
  745. // |------------------------| | | | |
  746. // | | | | |
  747. // ------------------------ | | | |
  748. // | |<---- | |
  749. // | | | | |
  750. // | |<--------<-
  751. // | | |
  752. // | |<-
  753. // ------------------------
  754. UCHAR *pHdrRead;
  755. UCHAR *pHdrWrite;
  756. UCHAR Header[IRDA_HEADER_LEN];
  757. // |------------------------|
  758. // | pHdrRead o-------------
  759. // |------------------------| |
  760. // | pHdrWrite o---------- |
  761. // |------------------------| | |
  762. // Header--->| | | |
  763. // | | | |
  764. // | |<--------<-
  765. // | | |
  766. // | |<-------
  767. // ------------------------
  768. //
  769. // On the receive side, all headers are contained
  770. // at pRead, not in the above Header array
  771. //
  772. } IRDA_DATA_SERVICE;
  773. typedef enum
  774. {
  775. IRLMP_MULTIPLEXED,
  776. IRLMP_EXCLUSIVE
  777. } IRLMP_ACCESSMODE;
  778. typedef struct
  779. {
  780. IRLMP_ACCESSMODE AccessMode;
  781. IRDA_SERVICE_STATUS ModeStatus;
  782. BOOLEAN IrLPTMode; // if true don't send PDU
  783. } IRLMP_ACCESSMODE_SERVICE;
  784. typedef struct
  785. {
  786. IAS_SET *pIasSet;
  787. CHAR *pClassName;
  788. IAS_QUERY *pIasQuery;
  789. int AttribLen; // OctetSeq or UsrStr len
  790. IRLMP_DISC_REASON IASStatus;
  791. PVOID AttribHandle;
  792. PVOID *pAttribHandle;
  793. } IRLMP_IAS_SERVICE;
  794. typedef struct irda_msg
  795. {
  796. LIST_ENTRY Linkage;
  797. IRDA_SERVICE_PRIM Prim;
  798. PVOID DataContext;
  799. union
  800. {
  801. MAC_CONTROL_SERVICE MAC_ControlService;
  802. IRLAP_DISCOVERY_SERVICE IRLAP_DiscoveryService;
  803. IRDA_DISCONNECT_SERVICE IRDA_DisconnectService;
  804. IRDA_CONNECT_SERVICE IRDA_ConnectService;
  805. IRDA_DATA_SERVICE IRDA_DataService;
  806. IRLMP_ACCESSMODE_SERVICE IRLMP_AccessModeService;
  807. IRLMP_IAS_SERVICE IRLMP_IASService;
  808. PVOID pLinkStatus;
  809. } MsgType;
  810. } IRDA_MSG, *PIRDA_MSG;
  811. #define IRDA_MSG_Op MsgType.MAC_ControlService.Op
  812. #define IRDA_MSG_Port MsgType.MAC_ControlService.Port
  813. #define IRDA_MSG_Baud MsgType.MAC_ControlService.Baud
  814. #define IRDA_MSG_NumBOFs MsgType.MAC_ControlService.NumBOFs
  815. #define IRDA_MSG_MinTat MsgType.MAC_ControlService.MinTat
  816. #define IRDA_MSG_DataSize MsgType.MAC_ControlService.DataSize
  817. #define IRDA_MSG_OpStatus MsgType.MAC_ControlService.OpStatus
  818. #define IRDA_MSG_SetIR MsgType.MAC_ControlService.SetIR
  819. #define IRDA_MSG_SenseTime MsgType.MAC_ControlService.SenseTime
  820. #define IRDA_MSG_pOwner MsgType.IRDA_DataService.pOwner
  821. #define IRDA_MSG_SegCount MsgType.IRDA_DataService.SegCount
  822. #define IRDA_MSG_SegFlags MsgType.IRDA_DataService.SegFlags
  823. #define IRDA_MSG_pHdrRead MsgType.IRDA_DataService.pHdrRead
  824. #define IRDA_MSG_pHdrWrite MsgType.IRDA_DataService.pHdrWrite
  825. #define IRDA_MSG_Header MsgType.IRDA_DataService.Header
  826. #define IRDA_MSG_pBase MsgType.IRDA_DataService.pBase
  827. #define IRDA_MSG_pLimit MsgType.IRDA_DataService.pLimit
  828. #define IRDA_MSG_pRead MsgType.IRDA_DataService.pRead
  829. #define IRDA_MSG_pWrite MsgType.IRDA_DataService.pWrite
  830. #define IRDA_MSG_DataStatus MsgType.IRDA_DataService.DataStatus
  831. #define IRDA_MSG_pTdiSendComp MsgType.IRDA_DataService.pTdiSendComp
  832. #define IRDA_MSG_pTdiSendCompCnxt MsgType.IRDA_DataService.pTdiSendCompCnxt
  833. #define IRDA_MSG_RefCnt MsgType.IRDA_DataService.RefCnt
  834. #define IRDA_MSG_IrCOMM_9Wire MsgType.IRDA_DataService.IrCOMM_9Wire
  835. #define IRDA_MSG_Expedited MsgType.IRDA_DataService.Expedited
  836. #ifdef TEMPERAMENTAL_SERIAL_DRIVER
  837. #define IRDA_MSG_FCS MsgType.IRDA_DataService.FCS
  838. #endif
  839. #define IRDA_MSG_pDevList MsgType.IRLAP_DiscoveryService.pDevList
  840. #define IRDA_MSG_DscvStatus MsgType.IRLAP_DiscoveryService.DscvStatus
  841. #define IRDA_MSG_SenseMedia MsgType.IRLAP_DiscoveryService.SenseMedia
  842. #define IRDA_MSG_RemoteDevAddr MsgType.IRDA_ConnectService.RemoteDevAddr
  843. #define IRDA_MSG_pQos MsgType.IRDA_ConnectService.pQos
  844. #define IRDA_MSG_LocalLsapSel MsgType.IRDA_ConnectService.LocalLsapSel
  845. #define IRDA_MSG_RemoteLsapSel MsgType.IRDA_ConnectService.RemoteLsapSel
  846. #define IRDA_MSG_pConnData MsgType.IRDA_ConnectService.pConnData
  847. #define IRDA_MSG_ConnDataLen MsgType.IRDA_ConnectService.ConnDataLen
  848. #define IRDA_MSG_ConnStatus MsgType.IRDA_ConnectService.ConnStatus
  849. #define IRDA_MSG_pContext MsgType.IRDA_ConnectService.pContext
  850. #define IRDA_MSG_UseTtp MsgType.IRDA_ConnectService.UseTtp
  851. #define IRDA_MSG_MaxSDUSize MsgType.IRDA_ConnectService.MaxSDUSize
  852. #define IRDA_MSG_MaxPDUSize MsgType.IRDA_ConnectService.MaxPDUSize
  853. #define IRDA_MSG_TtpCredits MsgType.IRDA_ConnectService.TtpCredits
  854. #define IRDA_MSG_pDiscData MsgType.IRDA_DisconnectService.pDiscData
  855. #define IRDA_MSG_DiscDataLen MsgType.IRDA_DisconnectService.DiscDataLen
  856. #define IRDA_MSG_DiscReason MsgType.IRDA_DisconnectService.DiscReason
  857. #define IRDA_MSG_DiscStatus MsgType.IRDA_DisconnectService.DiscStatus
  858. #define IRDA_MSG_pDiscContext MsgType.IRDA_DisconnectService.pDiscContext
  859. #define IRDA_MSG_AccessMode MsgType.IRLMP_AccessModeService.AccessMode
  860. #define IRDA_MSG_ModeStatus MsgType.IRLMP_AccessModeService.ModeStatus
  861. #define IRDA_MSG_IrLPTMode MsgType.IRLMP_AccessModeService.IrLPTMode
  862. #define IRDA_MSG_pIasSet MsgType.IRLMP_IASService.pIasSet
  863. #define IRDA_MSG_pClassName MsgType.IRLMP_IASService.pClassName
  864. #define IRDA_MSG_pIasQuery MsgType.IRLMP_IASService.pIasQuery
  865. #define IRDA_MSG_AttribLen MsgType.IRLMP_IASService.AttribLen
  866. #define IRDA_MSG_IASStatus MsgType.IRLMP_IASService.IASStatus
  867. #define IRDA_MSG_AttribHandle MsgType.IRLMP_IASService.AttribHandle
  868. #define IRDA_MSG_pAttribHandle MsgType.IRLMP_IASService.pAttribHandle
  869. #define IRDA_MSG_pLinkStatus MsgType.pLinkStatus
  870. extern PDRIVER_OBJECT pIrdaDriverObject;
  871. extern LIST_ENTRY IrdaLinkCbList;
  872. extern KSPIN_LOCK gSpinLock;
  873. extern NDIS_HANDLE NdisIrdaHandle;
  874. extern PVOID IrdaMsgPool;
  875. VOID IrdaTimerInitialize(PIRDA_TIMER pTimer,
  876. VOID (*ExpFunc)(PVOID Context),
  877. UINT Timeout,
  878. PVOID Context,
  879. PIRDA_LINK_CB pIrdaLinkCb);
  880. VOID IrdaTimerStart(PIRDA_TIMER pTimer);
  881. VOID IrdaTimerStop(PIRDA_TIMER pTimer);
  882. VOID IrdaTimerRestart(PIRDA_TIMER pTimer);
  883. VOID IrdaEventInitialize(PIRDA_EVENT pIrdaEvent,
  884. VOID (*Callback)(PVOID Context));
  885. VOID IrdaEventSchedule(PIRDA_EVENT pIrdaEvent, PVOID Context);
  886. NTSTATUS
  887. IrdaInitialize(
  888. IN PNDIS_STRING,
  889. IN PUNICODE_STRING,
  890. OUT PUINT);
  891. VOID
  892. IrdaShutdown();
  893. UINT
  894. TdiUp(void *pContext, IRDA_MSG *pMsg);
  895. IRDA_MSG *
  896. AllocTxMsg(
  897. PIRDA_LINK_CB);
  898. VOID
  899. IrmacDown(
  900. IN PVOID IrmacContext,
  901. PIRDA_MSG pMsg);
  902. _inline
  903. VOID
  904. INIT_LINK_LOCK(PIRDA_LINK_CB pIrdaLinkCb)
  905. {
  906. KeInitializeMutex(&pIrdaLinkCb->Mutex, 1);
  907. }
  908. _inline
  909. VOID
  910. LOCK_LINK(PIRDA_LINK_CB pIrdaLinkCb)
  911. {
  912. NTSTATUS Status;
  913. Status = KeWaitForSingleObject(&pIrdaLinkCb->Mutex,
  914. Executive,
  915. KernelMode,
  916. FALSE,
  917. NULL);
  918. ASSERT(Status == STATUS_SUCCESS);
  919. }
  920. _inline
  921. VOID
  922. UNLOCK_LINK(PIRDA_LINK_CB pIrdaLinkCb)
  923. {
  924. KeReleaseMutex(&pIrdaLinkCb->Mutex, FALSE);
  925. }
  926. #if DBG
  927. typedef struct
  928. {
  929. NPAGED_LOOKASIDE_LIST Lookaside;
  930. UINT Allocd;
  931. } DBG_BUF_POOL, *PDBG_BUF_POOL;
  932. #endif
  933. __inline
  934. PVOID
  935. CreateIrdaBufPool(ULONG Size, ULONG Tag)
  936. {
  937. #if DBG
  938. PDBG_BUF_POOL pDbgBufPool;
  939. #else
  940. PNPAGED_LOOKASIDE_LIST pLookaside;
  941. #endif
  942. #if DBG
  943. pDbgBufPool = ExAllocatePoolWithTag(NonPagedPool,
  944. sizeof(DBG_BUF_POOL),
  945. MT_IRDA_LAL);
  946. //DEBUGMSG(1, ("Created pool %x\n", pDbgBufPool));
  947. if (!pDbgBufPool)
  948. return NULL;
  949. #else
  950. pLookaside = ExAllocatePoolWithTag(NonPagedPool,
  951. sizeof(NPAGED_LOOKASIDE_LIST),
  952. MT_IRDA_LAL);
  953. if (!pLookaside)
  954. return NULL;
  955. #endif
  956. ExInitializeNPagedLookasideList(
  957. #if DBG
  958. &pDbgBufPool->Lookaside,
  959. #else
  960. pLookaside,
  961. #endif
  962. NULL,
  963. NULL,
  964. 0,
  965. Size,
  966. Tag,
  967. 4); // doesn't do anything
  968. #if DBG
  969. pDbgBufPool->Allocd = 0;
  970. return pDbgBufPool;
  971. #else
  972. return pLookaside;
  973. #endif
  974. }
  975. __inline
  976. VOID
  977. DeleteIrdaBufPool(PVOID pBufPool)
  978. {
  979. #if DBG
  980. PDBG_BUF_POOL pDbgBufPool = pBufPool;
  981. //DEBUGMSG(1, ("Deleted pool %x\n", pDbgBufPool));
  982. ExDeleteNPagedLookasideList(&pDbgBufPool->Lookaside);
  983. ExFreePool(pDbgBufPool);
  984. #else
  985. ExDeleteNPagedLookasideList((PNPAGED_LOOKASIDE_LIST) pBufPool);
  986. ExFreePool(pBufPool);
  987. #endif
  988. }
  989. __inline
  990. PVOID
  991. AllocIrdaBuf(PVOID pBufPool)
  992. {
  993. #if DBG
  994. PDBG_BUF_POOL pDbgBufPool = pBufPool;
  995. pDbgBufPool->Allocd++;
  996. // DEBUGMSG(1, ("+Pool %x, cnt %d\n", pBufPool, pDbgBufPool->Allocd));
  997. return ExAllocateFromNPagedLookasideList(&pDbgBufPool->Lookaside);
  998. #else
  999. return ExAllocateFromNPagedLookasideList(
  1000. (PNPAGED_LOOKASIDE_LIST) pBufPool);
  1001. #endif
  1002. }
  1003. __inline
  1004. VOID
  1005. FreeIrdaBuf(PVOID pBufPool, PVOID Buf)
  1006. {
  1007. #if DBG
  1008. PDBG_BUF_POOL pDbgBufPool = pBufPool;
  1009. pDbgBufPool->Allocd--;
  1010. // DEBUGMSG(1, ("-Pool %x, cnt %d\n", pBufPool, pDbgBufPool->Allocd));
  1011. ExFreeToNPagedLookasideList(&pDbgBufPool->Lookaside, Buf);
  1012. #else
  1013. ExFreeToNPagedLookasideList((PNPAGED_LOOKASIDE_LIST)pBufPool, Buf);
  1014. #endif
  1015. }
  1016. // I'm wrapping lookaside lists so I don't have to keep track of
  1017. // which pool to free to.
  1018. /*
  1019. __inline
  1020. PVOID
  1021. CreateMsgPool(ULONG Size,
  1022. USHORT Depth,
  1023. ULONG Tag)
  1024. {
  1025. PNPAGED_LOOKASIDE_LIST pLookaside;
  1026. pLookaside = ExAllocatePool(NonPagedPool, sizeof(NPAGED_LOOKASIDE_LIST));
  1027. if (!pLookaside)
  1028. return NULL;
  1029. ExInitializeNPagedLookasideList(
  1030. pLookaside,
  1031. NULL,
  1032. NULL,
  1033. 0,
  1034. Size + sizeof(PVOID),
  1035. Tag,
  1036. Depth);
  1037. DEBUGMSG(0, ("CreateMsgPool %x\n", pLookaside));
  1038. return pLookaside;
  1039. }
  1040. __inline
  1041. VOID
  1042. DeleteMsgPool(PVOID pLookaside)
  1043. {
  1044. DEBUGMSG(0, ("DeleteMsgPool %x\n", pLookaside));
  1045. ExDeleteNPagedLookasideList((PNPAGED_LOOKASIDE_LIST) pLookaside);
  1046. ExFreePool(pLookaside);
  1047. }
  1048. __inline
  1049. PVOID
  1050. AllocFromMsgPool(PVOID pLookaside)
  1051. {
  1052. PVOID pEntry;
  1053. pEntry = ExAllocateFromNPagedLookasideList(pLookaside);
  1054. if (!pEntry)
  1055. return NULL;
  1056. // store lookaside with entry
  1057. *(PVOID *) pEntry = pLookaside;
  1058. DEBUGMSG(0, ("Alloc %x: Total %d, AllocMiss %d, FreeTot %d, FreeMiss %d Depth%d\n",
  1059. pLookaside,
  1060. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.TotalAllocates,
  1061. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.AllocateMisses,
  1062. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.TotalFrees,
  1063. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.FreeMisses,
  1064. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.Depth));
  1065. return ++(PVOID *)pEntry;
  1066. }
  1067. __inline
  1068. VOID
  1069. FreeToMsgPool(PVOID pEntry)
  1070. {
  1071. PNPAGED_LOOKASIDE_LIST pLookaside;
  1072. pEntry = --(PVOID *) pEntry;
  1073. pLookaside = *(PVOID *) pEntry;
  1074. DEBUGMSG(1, ("Listdepth %d, depth %d\n",
  1075. ExQueryDepthSList(&pLookaside->L.ListHead),
  1076. pLookaside->L.Depth));
  1077. ExFreeToNPagedLookasideList(pLookaside, pEntry);
  1078. DEBUGMSG(0, ("FREE %x: Total %d, AllocMiss %d, FreeTot %d, FreeMiss %d Depth %d\n",
  1079. pLookaside,
  1080. pLookaside->L.TotalAllocates, pLookaside->L.AllocateMisses,
  1081. pLookaside->L.TotalFrees, pLookaside->L.FreeMisses, pLookaside->L.Depth));
  1082. }
  1083. */