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.

1246 lines
51 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. #if 0
  364. // {2D333977-52E1-4886-801F-2D59EB8060AF}
  365. DEFINE_GUID(<<name>>,
  366. 0x2d333977, 0x52e1, 0x4886, 0x80, 0x1f, 0x2d, 0x59, 0xeb, 0x80, 0x60, 0xaf);
  367. #endif
  368. #define WPP_CONTROL_GUIDS \
  369. WPP_DEFINE_CONTROL_GUID(CtlGuid,(2D333977,52E1,4886,801F,2D59EB8060AF), \
  370. WPP_DEFINE_BIT(DBG_0x00000001) \
  371. WPP_DEFINE_BIT(DBG_NDIS) \
  372. WPP_DEFINE_BIT(DBG_TIMER) \
  373. WPP_DEFINE_BIT(DBG_IRMAC) \
  374. \
  375. WPP_DEFINE_BIT(DBG_0x00000010) \
  376. WPP_DEFINE_BIT(DBG_IRLAP) \
  377. WPP_DEFINE_BIT(DBG_IRLAPLOG) \
  378. WPP_DEFINE_BIT(DBG_RXFRAME) \
  379. \
  380. WPP_DEFINE_BIT(DBG_TXFRAME) \
  381. WPP_DEFINE_BIT(DBG_IRLMP) \
  382. WPP_DEFINE_BIT(DBG_IRLMP_CONN) \
  383. WPP_DEFINE_BIT(DBG_IRLMP_CRED) \
  384. \
  385. WPP_DEFINE_BIT(DBG_IRLMP_IAS) \
  386. WPP_DEFINE_BIT(DBG_DISCOVERY) \
  387. WPP_DEFINE_BIT(DBG_PRINT) \
  388. WPP_DEFINE_BIT(DBG_ADDR) \
  389. \
  390. WPP_DEFINE_BIT(DBG_0x00010000) \
  391. WPP_DEFINE_BIT(DBG_REF) \
  392. WPP_DEFINE_BIT(DBG_TDI) \
  393. WPP_DEFINE_BIT(DBG_TDI_IRP) \
  394. \
  395. WPP_DEFINE_BIT(DBG_0x00100000) \
  396. WPP_DEFINE_BIT(DBG_ALLOC) \
  397. WPP_DEFINE_BIT(DBG_FUNCTION) \
  398. WPP_DEFINE_BIT(DBG_WARN ) \
  399. \
  400. WPP_DEFINE_BIT(DBG_ERROR) \
  401. )
  402. #define IRDA_MSG_DATA_SIZE_INTERNAL sizeof(IRDA_MSG)+128 // can this be smaller?
  403. //#define TEMPERAMENTAL_SERIAL_DRIVER // drivers busted. intercharacter delays cause
  404. // IrLAP to reset.
  405. #if DBG
  406. // Prototypes for Debugging Output
  407. void IRDA_DebugOut (TCHAR *pFormat, ...);
  408. void IRDA_DebugStartLog (void);
  409. void IRDA_DebugEndLog (void *, void *);
  410. #endif
  411. //#define DBG_CHECKSUM 1
  412. //#define DBG_BADDRIVER 1
  413. #if 0
  414. #define DBG_NDIS 0x00000002 // keep in sync with test\irdakdx
  415. #define DBG_TIMER 0x00000004
  416. #define DBG_IRMAC 0x00000008
  417. #define DBG_IRLAP 0x00000010
  418. #define DBG_IRLAPLOG 0x00000020
  419. #define DBG_RXFRAME 0x00000040
  420. #define DBG_TXFRAME 0x00000080
  421. #define DBG_IRLMP 0x00000100
  422. #define DBG_IRLMP_CONN 0x00000200
  423. #define DBG_IRLMP_CRED 0x00000400
  424. #define DBG_IRLMP_IAS 0x00000800
  425. #define DBG_DISCOVERY 0x00001000
  426. #define DBG_PRINT 0x00002000
  427. #define DBG_ADDR 0x00004000
  428. #define DBG_REF 0x00010000
  429. #define DBG_TDI 0x00020000
  430. #define DBG_TDI_IRP 0x00040000
  431. #define DBG_ALLOC 0x10000000
  432. #define DBG_FUNCTION 0x20000000
  433. #define DBG_WARN 0x40000000
  434. #define DBG_ERROR 0x80000000
  435. #endif
  436. #define STATIC
  437. typedef struct
  438. {
  439. CTETimer CteTimer;
  440. CTEEvent CteEvent;
  441. VOID (*ExpFunc)(PVOID Context);
  442. PVOID Context;
  443. UINT Timeout;
  444. BOOLEAN Late;
  445. struct IrdaLinkCb *pIrdaLinkCb;
  446. #if DBG
  447. char *pName;
  448. #endif
  449. } IRDA_TIMER, *PIRDA_TIMER;
  450. typedef struct
  451. {
  452. CTEEvent CteEvent; // Must be first field
  453. VOID (*Callback)(PVOID Context);
  454. } IRDA_EVENT, *PIRDA_EVENT;
  455. #define IRMAC_CONTEXT(ilcb) ((ilcb)->IrmacContext)
  456. #define IRLAP_CONTEXT(ilcb) ((ilcb)->IrlapContext)
  457. #define IRLMP_CONTEXT(ilcb) ((ilcb)->IrlmpContext)
  458. // Device/Discovery Information
  459. #define IRLAP_DSCV_INFO_LEN 32
  460. #define IRDA_DEV_ADDR_LEN 4
  461. typedef struct
  462. {
  463. LIST_ENTRY Linkage;
  464. UCHAR DevAddr[IRDA_DEV_ADDR_LEN];
  465. int DscvMethod;
  466. int IRLAP_Version;
  467. UCHAR DscvInfo[IRLAP_DSCV_INFO_LEN];
  468. int DscvInfoLen;
  469. int NotSeenCnt; // used by IRLMP to determine when to remove
  470. // the device from its list
  471. } IRDA_DEVICE;
  472. #define IRDA_NDIS_BUFFER_POOL_SIZE 8
  473. #define IRDA_NDIS_PACKET_POOL_SIZE 8
  474. #define IRDA_MSG_LIST_LEN 2
  475. #define IRDA_MSG_DATA_SIZE 64
  476. typedef struct
  477. {
  478. LIST_ENTRY Linkage;
  479. struct irda_msg *pMsg;
  480. #if DBG_TIMESTAMP
  481. int TimeStamp[4];
  482. #endif
  483. MEDIA_SPECIFIC_INFORMATION MediaInfo;
  484. } IRDA_PROTOCOL_RESERVED, *PIRDA_PROTOCOL_RESERVED;
  485. #define IRDA_RX_SYSTEM_THREAD
  486. typedef struct IrdaLinkCb
  487. {
  488. LIST_ENTRY Linkage;
  489. PVOID IrlapContext;
  490. PVOID IrlmpContext;
  491. NDIS_SPIN_LOCK SpinLock;
  492. KMUTEX Mutex;
  493. NDIS_HANDLE UnbindContext;
  494. NDIS_HANDLE NdisBindingHandle;
  495. NDIS_EVENT OpenCloseEvent;
  496. NDIS_STATUS OpenCloseStatus;
  497. NDIS_EVENT ResetEvent;
  498. PVOID PnpContext;
  499. IRDA_TIMER MediaSenseTimer;
  500. int MediaBusy;
  501. NDIS_HANDLE BufferPool;
  502. NDIS_HANDLE PacketPool;
  503. LIST_ENTRY PacketList;
  504. LIST_ENTRY TxMsgFreeList;
  505. int TxMsgFreeListLen;
  506. LIST_ENTRY RxMsgFreeList;
  507. int RxMsgFreeListLen;
  508. LIST_ENTRY RxMsgList;
  509. #ifdef IRDA_RX_SYSTEM_THREAD
  510. KEVENT EvRxMsgReady;
  511. KEVENT EvKillRxThread;
  512. HANDLE hRxThread;
  513. #else
  514. IRDA_EVENT EvRxMsgReady;
  515. #endif
  516. int RxMsgDataSize;
  517. UINT ExtraBofs; // These should be per connection for
  518. UINT MinTat; // multipoint
  519. BOOLEAN WaitMinTat;
  520. BOOLEAN LowPowerSt;
  521. LONG SendOutCnt;
  522. PNET_PNP_EVENT pNetPnpEvent;
  523. REF_CNT RefCnt;
  524. #if 1 // DBG
  525. int LastTime;
  526. int DelayedRxFrameCnt;
  527. #endif
  528. } IRDA_LINK_CB, *PIRDA_LINK_CB;
  529. // IRLAP Quality of Service
  530. #define BIT_0 1
  531. #define BIT_1 2
  532. #define BIT_2 4
  533. #define BIT_3 8
  534. #define BIT_4 16
  535. #define BIT_5 32
  536. #define BIT_6 64
  537. #define BIT_7 128
  538. #define BIT_8 256
  539. #define BPS_2400 BIT_0 // Baud Rates
  540. #define BPS_9600 BIT_1
  541. #define BPS_19200 BIT_2
  542. #define BPS_38400 BIT_3
  543. #define BPS_57600 BIT_4
  544. #define BPS_115200 BIT_5
  545. #define BPS_4000000 BIT_8
  546. #define MAX_TAT_500 BIT_0 // Maximum Turnaround Time (millisecs)
  547. #define MAX_TAT_250 BIT_1
  548. #define MAX_TAT_100 BIT_2
  549. #define MAX_TAT_50 BIT_3
  550. #define MAX_TAT_25 BIT_4
  551. #define MAX_TAT_10 BIT_5
  552. #define MAX_TAT_5 BIT_6
  553. #define DATA_SIZE_64 BIT_0 // Data Size (bytes)
  554. #define DATA_SIZE_128 BIT_1
  555. #define DATA_SIZE_256 BIT_2
  556. #define DATA_SIZE_512 BIT_3
  557. #define DATA_SIZE_1024 BIT_4
  558. #define DATA_SIZE_2048 BIT_5
  559. #define FRAMES_1 BIT_0 // Window Size
  560. #define FRAMES_2 BIT_1
  561. #define FRAMES_3 BIT_2
  562. #define FRAMES_4 BIT_3
  563. #define FRAMES_5 BIT_4
  564. #define FRAMES_6 BIT_5
  565. #define FRAMES_7 BIT_6
  566. #define BOFS_48 BIT_0 // Additional Beginning of Frame Flags
  567. #define BOFS_24 BIT_1
  568. #define BOFS_12 BIT_2
  569. #define BOFS_5 BIT_3
  570. #define BOFS_3 BIT_4
  571. #define BOFS_2 BIT_5
  572. #define BOFS_1 BIT_6
  573. #define BOFS_0 BIT_7
  574. #define MIN_TAT_10 BIT_0 // Minumum Turnaround Time (millisecs)
  575. #define MIN_TAT_5 BIT_1
  576. #define MIN_TAT_1 BIT_2
  577. #define MIN_TAT_0_5 BIT_3
  578. #define MIN_TAT_0_1 BIT_4
  579. #define MIN_TAT_0_05 BIT_5
  580. #define MIN_TAT_0_01 BIT_6
  581. #define MIN_TAT_0 BIT_7
  582. #define DISC_TIME_3 BIT_0 // Link Disconnect/Threshold Time (seconds)
  583. #define DISC_TIME_8 BIT_1
  584. #define DISC_TIME_12 BIT_2
  585. #define DISC_TIME_16 BIT_3
  586. #define DISC_TIME_20 BIT_4
  587. #define DISC_TIME_25 BIT_5
  588. #define DISC_TIME_30 BIT_6
  589. #define DISC_TIME_40 BIT_7
  590. typedef struct
  591. {
  592. UINT bfBaud;
  593. UINT bfMaxTurnTime;
  594. UINT bfDataSize;
  595. UINT bfWindowSize;
  596. UINT bfBofs;
  597. UINT bfMinTurnTime;
  598. UINT bfDisconnectTime; // holds threshold time also
  599. } IRDA_QOS_PARMS;
  600. // IrDA Message Primitives
  601. typedef enum
  602. {
  603. MAC_DATA_REQ = 0, // Keep in sync with table in irlaplog.c
  604. MAC_DATA_IND,
  605. MAC_DATA_RESP,
  606. MAC_DATA_CONF,
  607. MAC_CONTROL_REQ,
  608. MAC_CONTROL_CONF,
  609. IRLAP_DISCOVERY_REQ,
  610. IRLAP_DISCOVERY_IND,
  611. IRLAP_DISCOVERY_CONF,
  612. IRLAP_CONNECT_REQ,
  613. IRLAP_CONNECT_IND,
  614. IRLAP_CONNECT_RESP,
  615. IRLAP_CONNECT_CONF,
  616. IRLAP_DISCONNECT_REQ,
  617. IRLAP_DISCONNECT_IND,
  618. IRLAP_DATA_REQ, // Don't fuss with the order, CONF must be 2 from REQ
  619. IRLAP_DATA_IND,
  620. IRLAP_DATA_CONF,
  621. IRLAP_UDATA_REQ,
  622. IRLAP_UDATA_IND,
  623. IRLAP_UDATA_CONF,
  624. IRLAP_STATUS_REQ,
  625. IRLAP_STATUS_IND,
  626. IRLAP_FLOWON_REQ,
  627. IRLMP_DISCOVERY_REQ,
  628. IRLMP_DISCOVERY_IND,
  629. IRLMP_DISCOVERY_CONF,
  630. IRLMP_CONNECT_REQ,
  631. IRLMP_CONNECT_IND,
  632. IRLMP_CONNECT_RESP,
  633. IRLMP_CONNECT_CONF,
  634. IRLMP_DISCONNECT_REQ,
  635. IRLMP_DISCONNECT_IND,
  636. IRLMP_DATA_REQ,
  637. IRLMP_DATA_IND,
  638. IRLMP_DATA_CONF,
  639. IRLMP_UDATA_REQ,
  640. IRLMP_UDATA_IND,
  641. IRLMP_UDATA_CONF,
  642. IRLMP_ACCESSMODE_REQ,
  643. IRLMP_ACCESSMODE_IND,
  644. IRLMP_ACCESSMODE_CONF,
  645. IRLMP_MORECREDIT_REQ,
  646. IRLMP_GETVALUEBYCLASS_REQ,
  647. IRLMP_GETVALUEBYCLASS_CONF,
  648. IRLMP_REGISTERLSAP_REQ,
  649. IRLMP_DEREGISTERLSAP_REQ,
  650. IRLMP_ADDATTRIBUTE_REQ,
  651. IRLMP_DELATTRIBUTE_REQ,
  652. IRLMP_CLOSELSAP_REQ,
  653. IRLMP_FLUSHDSCV_REQ
  654. } IRDA_SERVICE_PRIM;
  655. typedef enum
  656. {
  657. MAC_MEDIA_BUSY, // keep in sync with IRDA_StatStr in irlaplog.c
  658. MAC_MEDIA_CLEAR,
  659. IRLAP_DISCOVERY_COLLISION,
  660. IRLAP_REMOTE_DISCOVERY_IN_PROGRESS,
  661. IRLAP_REMOTE_CONNECT_IN_PROGRSS,
  662. IRLAP_DISCOVERY_COMPLETED,
  663. IRLAP_REMOTE_CONNECTION_IN_PROGRESS,
  664. IRLAP_CONNECTION_COMPLETED,
  665. IRLAP_REMOTE_INITIATED,
  666. IRLAP_PRIMARY_CONFLICT,
  667. IRLAP_DISCONNECT_COMPLETED,
  668. IRLAP_NO_RESPONSE,
  669. IRLAP_DECLINE_RESET,
  670. IRLAP_DATA_REQUEST_COMPLETED,
  671. IRLAP_DATA_REQUEST_FAILED_LINK_RESET,
  672. IRLAP_DATA_REQUEST_FAILED_REMOTE_BUSY,
  673. IRLMP_NO_RESPONSE,
  674. IRLMP_ACCESSMODE_SUCCESS,
  675. IRLMP_ACCESSMODE_FAILURE,
  676. IRLMP_DATA_REQUEST_COMPLETED,
  677. IRLMP_DATA_REQUEST_FAILED
  678. } IRDA_SERVICE_STATUS;
  679. // MAC Control Service Request Message - MAC_CONTROL_REQ/CONF
  680. typedef enum
  681. {
  682. MAC_INITIALIZE_LINK, // keep in sync with MAC_OpStr in irlaplog.c
  683. MAC_CLOSE_LINK,
  684. MAC_RECONFIG_LINK,
  685. MAC_MEDIA_SENSE,
  686. } MAC_CONTROL_OPERATION;
  687. typedef struct
  688. {
  689. MAC_CONTROL_OPERATION Op;
  690. int Port;
  691. int Baud;
  692. int NumBOFs;
  693. int MinTat;
  694. int DataSize;
  695. int SenseTime;
  696. IRDA_SERVICE_STATUS OpStatus;
  697. BOOLEAN SetIR;
  698. } MAC_CONTROL_SERVICE;
  699. // IRLAP Discovery Service Request Message - IRLAP_DISCOVERY_IND/CONF
  700. typedef struct
  701. {
  702. LIST_ENTRY *pDevList;
  703. IRDA_SERVICE_STATUS DscvStatus;
  704. BOOLEAN SenseMedia;
  705. } IRLAP_DISCOVERY_SERVICE;
  706. // IRDA Connection Service Request Message - IRLAP_CONNECT_REQ/IND/CONF
  707. // IRLMP_CONNECT_REQ/CONF
  708. typedef struct
  709. {
  710. UCHAR RemoteDevAddr[IRDA_DEV_ADDR_LEN];
  711. IRDA_QOS_PARMS *pQos;
  712. int LocalLsapSel;
  713. int RemoteLsapSel;
  714. UCHAR *pConnData;
  715. int ConnDataLen;
  716. void *pContext;
  717. int MaxPDUSize;
  718. int MaxSDUSize;
  719. int TtpCredits;
  720. IRDA_SERVICE_STATUS ConnStatus;
  721. BOOLEAN UseTtp;
  722. } IRDA_CONNECT_SERVICE;
  723. // IRDA Disconnection Service Request Message - IRLAP_DISCONNECT_REQ/IND
  724. // IRLMP_DISCONNECT_REQ/IND
  725. typedef enum
  726. {
  727. IRLMP_USER_REQUEST = 1,
  728. IRLMP_UNEXPECTED_IRLAP_DISC,
  729. IRLMP_IRLAP_CONN_FAILED,
  730. IRLMP_IRLAP_RESET,
  731. IRLMP_LM_INITIATED_DISC,
  732. IRLMP_DISC_LSAP,
  733. IRLMP_NO_RESPONSE_LSAP,
  734. IRLMP_NO_AVAILABLE_LSAP,
  735. IRLMP_MAC_MEDIA_BUSY,
  736. IRLMP_IRLAP_REMOTE_DISCOVERY_IN_PROGRESS,
  737. IRLMP_IAS_NO_SUCH_OBJECT, // these are added for the IAS_GetValueByClass.Conf
  738. IRLMP_IAS_NO_SUCH_ATTRIB,
  739. IRLMP_IAS_FAILED,
  740. IRLMP_IAS_SUCCESS,
  741. IRLMP_IAS_SUCCESS_LISTLEN_GREATER_THAN_ONE,
  742. IRLMP_UNSPECIFIED_DISC = 0xFF
  743. } IRLMP_DISC_REASON;
  744. typedef struct
  745. {
  746. UCHAR *pDiscData; // IRLMP_DISCONNECT_REQ/IND only
  747. int DiscDataLen; // IRLMP_DISCONNECT_REQ/IND only
  748. IRLMP_DISC_REASON DiscReason; // IRLMP_DISCONNECT_REQ/IND only
  749. IRDA_SERVICE_STATUS DiscStatus; // Indication only
  750. void *pDiscContext;
  751. } IRDA_DISCONNECT_SERVICE;
  752. // IRDA Data Service Request Message
  753. #define IRLAP_HEADER_LEN 2
  754. #define IRLMP_HEADER_LEN 6
  755. #define TTP_HEADER_LEN 8
  756. #define IRDA_HEADER_LEN IRLAP_HEADER_LEN+IRLMP_HEADER_LEN+TTP_HEADER_LEN+1
  757. // + 1 IRComm WACK!!
  758. #define SEG_FINAL 1
  759. #define SEG_LOCAL 2
  760. typedef struct
  761. {
  762. void *pOwner;
  763. int SegCount; // Number of segments
  764. UINT SegFlags;
  765. UCHAR *pBase;
  766. UCHAR *pLimit;
  767. UCHAR *pRead;
  768. UCHAR *pWrite;
  769. void *pTdiSendComp;
  770. void *pTdiSendCompCnxt;
  771. LONG RefCnt;
  772. BOOLEAN IrCOMM_9Wire;
  773. BOOLEAN Expedited;
  774. #ifdef TEMPERAMENTAL_SERIAL_DRIVER
  775. int FCS;
  776. #endif
  777. IRDA_SERVICE_STATUS DataStatus; // for CONF
  778. // |------------------------|
  779. // | pRead o-------------
  780. // |------------------------| |
  781. // | pWrite o---------- |
  782. // |------------------------| | |
  783. // | pBase o------- | |
  784. // |------------------------| | | |
  785. // | pLimit o---- | | |
  786. // |------------------------| | | | |
  787. // | | | | |
  788. // ------------------------ | | | |
  789. // | |<---- | |
  790. // | | | | |
  791. // | |<--------<-
  792. // | | |
  793. // | |<-
  794. // ------------------------
  795. UCHAR *pHdrRead;
  796. UCHAR *pHdrWrite;
  797. UCHAR Header[IRDA_HEADER_LEN];
  798. // |------------------------|
  799. // | pHdrRead o-------------
  800. // |------------------------| |
  801. // | pHdrWrite o---------- |
  802. // |------------------------| | |
  803. // Header--->| | | |
  804. // | | | |
  805. // | |<--------<-
  806. // | | |
  807. // | |<-------
  808. // ------------------------
  809. //
  810. // On the receive side, all headers are contained
  811. // at pRead, not in the above Header array
  812. //
  813. } IRDA_DATA_SERVICE;
  814. typedef enum
  815. {
  816. IRLMP_MULTIPLEXED,
  817. IRLMP_EXCLUSIVE
  818. } IRLMP_ACCESSMODE;
  819. typedef struct
  820. {
  821. IRLMP_ACCESSMODE AccessMode;
  822. IRDA_SERVICE_STATUS ModeStatus;
  823. BOOLEAN IrLPTMode; // if true don't send PDU
  824. } IRLMP_ACCESSMODE_SERVICE;
  825. typedef struct
  826. {
  827. IAS_SET *pIasSet;
  828. CHAR *pClassName;
  829. IAS_QUERY *pIasQuery;
  830. int AttribLen; // OctetSeq or UsrStr len
  831. IRLMP_DISC_REASON IASStatus;
  832. PVOID AttribHandle;
  833. PVOID *pAttribHandle;
  834. } IRLMP_IAS_SERVICE;
  835. typedef struct irda_msg
  836. {
  837. LIST_ENTRY Linkage;
  838. IRDA_SERVICE_PRIM Prim;
  839. PVOID DataContext;
  840. union
  841. {
  842. MAC_CONTROL_SERVICE MAC_ControlService;
  843. IRLAP_DISCOVERY_SERVICE IRLAP_DiscoveryService;
  844. IRDA_DISCONNECT_SERVICE IRDA_DisconnectService;
  845. IRDA_CONNECT_SERVICE IRDA_ConnectService;
  846. IRDA_DATA_SERVICE IRDA_DataService;
  847. IRLMP_ACCESSMODE_SERVICE IRLMP_AccessModeService;
  848. IRLMP_IAS_SERVICE IRLMP_IASService;
  849. PVOID pLinkStatus;
  850. } MsgType;
  851. } IRDA_MSG, *PIRDA_MSG;
  852. #define IRDA_MSG_Op MsgType.MAC_ControlService.Op
  853. #define IRDA_MSG_Port MsgType.MAC_ControlService.Port
  854. #define IRDA_MSG_Baud MsgType.MAC_ControlService.Baud
  855. #define IRDA_MSG_NumBOFs MsgType.MAC_ControlService.NumBOFs
  856. #define IRDA_MSG_MinTat MsgType.MAC_ControlService.MinTat
  857. #define IRDA_MSG_DataSize MsgType.MAC_ControlService.DataSize
  858. #define IRDA_MSG_OpStatus MsgType.MAC_ControlService.OpStatus
  859. #define IRDA_MSG_SetIR MsgType.MAC_ControlService.SetIR
  860. #define IRDA_MSG_SenseTime MsgType.MAC_ControlService.SenseTime
  861. #define IRDA_MSG_pOwner MsgType.IRDA_DataService.pOwner
  862. #define IRDA_MSG_SegCount MsgType.IRDA_DataService.SegCount
  863. #define IRDA_MSG_SegFlags MsgType.IRDA_DataService.SegFlags
  864. #define IRDA_MSG_pHdrRead MsgType.IRDA_DataService.pHdrRead
  865. #define IRDA_MSG_pHdrWrite MsgType.IRDA_DataService.pHdrWrite
  866. #define IRDA_MSG_Header MsgType.IRDA_DataService.Header
  867. #define IRDA_MSG_pBase MsgType.IRDA_DataService.pBase
  868. #define IRDA_MSG_pLimit MsgType.IRDA_DataService.pLimit
  869. #define IRDA_MSG_pRead MsgType.IRDA_DataService.pRead
  870. #define IRDA_MSG_pWrite MsgType.IRDA_DataService.pWrite
  871. #define IRDA_MSG_DataStatus MsgType.IRDA_DataService.DataStatus
  872. #define IRDA_MSG_pTdiSendComp MsgType.IRDA_DataService.pTdiSendComp
  873. #define IRDA_MSG_pTdiSendCompCnxt MsgType.IRDA_DataService.pTdiSendCompCnxt
  874. #define IRDA_MSG_RefCnt MsgType.IRDA_DataService.RefCnt
  875. #define IRDA_MSG_IrCOMM_9Wire MsgType.IRDA_DataService.IrCOMM_9Wire
  876. #define IRDA_MSG_Expedited MsgType.IRDA_DataService.Expedited
  877. #ifdef TEMPERAMENTAL_SERIAL_DRIVER
  878. #define IRDA_MSG_FCS MsgType.IRDA_DataService.FCS
  879. #endif
  880. #define IRDA_MSG_pDevList MsgType.IRLAP_DiscoveryService.pDevList
  881. #define IRDA_MSG_DscvStatus MsgType.IRLAP_DiscoveryService.DscvStatus
  882. #define IRDA_MSG_SenseMedia MsgType.IRLAP_DiscoveryService.SenseMedia
  883. #define IRDA_MSG_RemoteDevAddr MsgType.IRDA_ConnectService.RemoteDevAddr
  884. #define IRDA_MSG_pQos MsgType.IRDA_ConnectService.pQos
  885. #define IRDA_MSG_LocalLsapSel MsgType.IRDA_ConnectService.LocalLsapSel
  886. #define IRDA_MSG_RemoteLsapSel MsgType.IRDA_ConnectService.RemoteLsapSel
  887. #define IRDA_MSG_pConnData MsgType.IRDA_ConnectService.pConnData
  888. #define IRDA_MSG_ConnDataLen MsgType.IRDA_ConnectService.ConnDataLen
  889. #define IRDA_MSG_ConnStatus MsgType.IRDA_ConnectService.ConnStatus
  890. #define IRDA_MSG_pContext MsgType.IRDA_ConnectService.pContext
  891. #define IRDA_MSG_UseTtp MsgType.IRDA_ConnectService.UseTtp
  892. #define IRDA_MSG_MaxSDUSize MsgType.IRDA_ConnectService.MaxSDUSize
  893. #define IRDA_MSG_MaxPDUSize MsgType.IRDA_ConnectService.MaxPDUSize
  894. #define IRDA_MSG_TtpCredits MsgType.IRDA_ConnectService.TtpCredits
  895. #define IRDA_MSG_pDiscData MsgType.IRDA_DisconnectService.pDiscData
  896. #define IRDA_MSG_DiscDataLen MsgType.IRDA_DisconnectService.DiscDataLen
  897. #define IRDA_MSG_DiscReason MsgType.IRDA_DisconnectService.DiscReason
  898. #define IRDA_MSG_DiscStatus MsgType.IRDA_DisconnectService.DiscStatus
  899. #define IRDA_MSG_pDiscContext MsgType.IRDA_DisconnectService.pDiscContext
  900. #define IRDA_MSG_AccessMode MsgType.IRLMP_AccessModeService.AccessMode
  901. #define IRDA_MSG_ModeStatus MsgType.IRLMP_AccessModeService.ModeStatus
  902. #define IRDA_MSG_IrLPTMode MsgType.IRLMP_AccessModeService.IrLPTMode
  903. #define IRDA_MSG_pIasSet MsgType.IRLMP_IASService.pIasSet
  904. #define IRDA_MSG_pClassName MsgType.IRLMP_IASService.pClassName
  905. #define IRDA_MSG_pIasQuery MsgType.IRLMP_IASService.pIasQuery
  906. #define IRDA_MSG_AttribLen MsgType.IRLMP_IASService.AttribLen
  907. #define IRDA_MSG_IASStatus MsgType.IRLMP_IASService.IASStatus
  908. #define IRDA_MSG_AttribHandle MsgType.IRLMP_IASService.AttribHandle
  909. #define IRDA_MSG_pAttribHandle MsgType.IRLMP_IASService.pAttribHandle
  910. #define IRDA_MSG_pLinkStatus MsgType.pLinkStatus
  911. extern PDRIVER_OBJECT pIrdaDriverObject;
  912. extern LIST_ENTRY IrdaLinkCbList;
  913. extern KSPIN_LOCK gSpinLock;
  914. extern NDIS_HANDLE NdisIrdaHandle;
  915. extern PVOID IrdaMsgPool;
  916. VOID IrdaTimerInitialize(PIRDA_TIMER pTimer,
  917. VOID (*ExpFunc)(PVOID Context),
  918. UINT Timeout,
  919. PVOID Context,
  920. PIRDA_LINK_CB pIrdaLinkCb);
  921. VOID IrdaTimerStart(PIRDA_TIMER pTimer);
  922. VOID IrdaTimerStop(PIRDA_TIMER pTimer);
  923. VOID IrdaTimerRestart(PIRDA_TIMER pTimer);
  924. VOID IrdaEventInitialize(PIRDA_EVENT pIrdaEvent,
  925. VOID (*Callback)(PVOID Context));
  926. VOID IrdaEventSchedule(PIRDA_EVENT pIrdaEvent, PVOID Context);
  927. NTSTATUS
  928. IrdaInitialize(
  929. IN PNDIS_STRING,
  930. IN PUNICODE_STRING,
  931. OUT PUINT);
  932. VOID
  933. IrdaShutdown();
  934. UINT
  935. TdiUp(void *pContext, IRDA_MSG *pMsg);
  936. IRDA_MSG *
  937. AllocTxMsg(
  938. PIRDA_LINK_CB);
  939. VOID
  940. IrmacDown(
  941. IN PVOID IrmacContext,
  942. PIRDA_MSG pMsg);
  943. _inline
  944. VOID
  945. INIT_LINK_LOCK(PIRDA_LINK_CB pIrdaLinkCb)
  946. {
  947. KeInitializeMutex(&pIrdaLinkCb->Mutex, 1);
  948. }
  949. _inline
  950. VOID
  951. LOCK_LINK(PIRDA_LINK_CB pIrdaLinkCb)
  952. {
  953. NTSTATUS Status;
  954. Status = KeWaitForSingleObject(&pIrdaLinkCb->Mutex,
  955. Executive,
  956. KernelMode,
  957. FALSE,
  958. NULL);
  959. ASSERT(Status == STATUS_SUCCESS);
  960. }
  961. _inline
  962. VOID
  963. UNLOCK_LINK(PIRDA_LINK_CB pIrdaLinkCb)
  964. {
  965. KeReleaseMutex(&pIrdaLinkCb->Mutex, FALSE);
  966. }
  967. #if DBG
  968. typedef struct
  969. {
  970. NPAGED_LOOKASIDE_LIST Lookaside;
  971. UINT Allocd;
  972. } DBG_BUF_POOL, *PDBG_BUF_POOL;
  973. #endif
  974. __inline
  975. PVOID
  976. CreateIrdaBufPool(ULONG Size, ULONG Tag)
  977. {
  978. #if DBG
  979. PDBG_BUF_POOL pDbgBufPool;
  980. #else
  981. PNPAGED_LOOKASIDE_LIST pLookaside;
  982. #endif
  983. #if DBG
  984. pDbgBufPool = ExAllocatePoolWithTag(NonPagedPool,
  985. sizeof(DBG_BUF_POOL),
  986. MT_IRDA_LAL);
  987. //DEBUGMSG(1, ("Created pool %x\n", pDbgBufPool));
  988. if (!pDbgBufPool)
  989. return NULL;
  990. #else
  991. pLookaside = ExAllocatePoolWithTag(NonPagedPool,
  992. sizeof(NPAGED_LOOKASIDE_LIST),
  993. MT_IRDA_LAL);
  994. if (!pLookaside)
  995. return NULL;
  996. #endif
  997. ExInitializeNPagedLookasideList(
  998. #if DBG
  999. &pDbgBufPool->Lookaside,
  1000. #else
  1001. pLookaside,
  1002. #endif
  1003. NULL,
  1004. NULL,
  1005. 0,
  1006. Size,
  1007. Tag,
  1008. 0
  1009. );
  1010. #if DBG
  1011. pDbgBufPool->Allocd = 0;
  1012. return pDbgBufPool;
  1013. #else
  1014. return pLookaside;
  1015. #endif
  1016. }
  1017. __inline
  1018. VOID
  1019. DeleteIrdaBufPool(PVOID pBufPool)
  1020. {
  1021. #if DBG
  1022. PDBG_BUF_POOL pDbgBufPool = pBufPool;
  1023. //DEBUGMSG(1, ("Deleted pool %x\n", pDbgBufPool));
  1024. ExDeleteNPagedLookasideList(&pDbgBufPool->Lookaside);
  1025. ExFreePool(pDbgBufPool);
  1026. #else
  1027. ExDeleteNPagedLookasideList((PNPAGED_LOOKASIDE_LIST) pBufPool);
  1028. ExFreePool(pBufPool);
  1029. #endif
  1030. }
  1031. __inline
  1032. PVOID
  1033. AllocIrdaBuf(PVOID pBufPool)
  1034. {
  1035. #if DBG
  1036. PDBG_BUF_POOL pDbgBufPool = pBufPool;
  1037. pDbgBufPool->Allocd++;
  1038. // DEBUGMSG(1, ("+Pool %x, cnt %d\n", pBufPool, pDbgBufPool->Allocd));
  1039. return ExAllocateFromNPagedLookasideList(&pDbgBufPool->Lookaside);
  1040. #else
  1041. return ExAllocateFromNPagedLookasideList(
  1042. (PNPAGED_LOOKASIDE_LIST) pBufPool);
  1043. #endif
  1044. }
  1045. __inline
  1046. VOID
  1047. FreeIrdaBuf(PVOID pBufPool, PVOID Buf)
  1048. {
  1049. #if DBG
  1050. PDBG_BUF_POOL pDbgBufPool = pBufPool;
  1051. pDbgBufPool->Allocd--;
  1052. // DEBUGMSG(1, ("-Pool %x, cnt %d\n", pBufPool, pDbgBufPool->Allocd));
  1053. ExFreeToNPagedLookasideList(&pDbgBufPool->Lookaside, Buf);
  1054. #else
  1055. ExFreeToNPagedLookasideList((PNPAGED_LOOKASIDE_LIST)pBufPool, Buf);
  1056. #endif
  1057. }
  1058. // I'm wrapping lookaside lists so I don't have to keep track of
  1059. // which pool to free to.
  1060. /*
  1061. __inline
  1062. PVOID
  1063. CreateMsgPool(ULONG Size,
  1064. USHORT Depth,
  1065. ULONG Tag)
  1066. {
  1067. PNPAGED_LOOKASIDE_LIST pLookaside;
  1068. pLookaside = ExAllocatePool(NonPagedPool, sizeof(NPAGED_LOOKASIDE_LIST));
  1069. if (!pLookaside)
  1070. return NULL;
  1071. ExInitializeNPagedLookasideList(
  1072. pLookaside,
  1073. NULL,
  1074. NULL,
  1075. 0,
  1076. Size + sizeof(PVOID),
  1077. Tag,
  1078. Depth);
  1079. DEBUGMSG(0, ("CreateMsgPool %x\n", pLookaside));
  1080. return pLookaside;
  1081. }
  1082. __inline
  1083. VOID
  1084. DeleteMsgPool(PVOID pLookaside)
  1085. {
  1086. DEBUGMSG(0, ("DeleteMsgPool %x\n", pLookaside));
  1087. ExDeleteNPagedLookasideList((PNPAGED_LOOKASIDE_LIST) pLookaside);
  1088. ExFreePool(pLookaside);
  1089. }
  1090. __inline
  1091. PVOID
  1092. AllocFromMsgPool(PVOID pLookaside)
  1093. {
  1094. PVOID pEntry;
  1095. pEntry = ExAllocateFromNPagedLookasideList(pLookaside);
  1096. if (!pEntry)
  1097. return NULL;
  1098. // store lookaside with entry
  1099. *(PVOID *) pEntry = pLookaside;
  1100. DEBUGMSG(0, ("Alloc %x: Total %d, AllocMiss %d, FreeTot %d, FreeMiss %d Depth%d\n",
  1101. pLookaside,
  1102. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.TotalAllocates,
  1103. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.AllocateMisses,
  1104. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.TotalFrees,
  1105. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.FreeMisses,
  1106. ((PNPAGED_LOOKASIDE_LIST)pLookaside)->L.Depth));
  1107. return ++(PVOID *)pEntry;
  1108. }
  1109. __inline
  1110. VOID
  1111. FreeToMsgPool(PVOID pEntry)
  1112. {
  1113. PNPAGED_LOOKASIDE_LIST pLookaside;
  1114. pEntry = --(PVOID *) pEntry;
  1115. pLookaside = *(PVOID *) pEntry;
  1116. DEBUGMSG(1, ("Listdepth %d, depth %d\n",
  1117. ExQueryDepthSList(&pLookaside->L.ListHead),
  1118. pLookaside->L.Depth));
  1119. ExFreeToNPagedLookasideList(pLookaside, pEntry);
  1120. DEBUGMSG(0, ("FREE %x: Total %d, AllocMiss %d, FreeTot %d, FreeMiss %d Depth %d\n",
  1121. pLookaside,
  1122. pLookaside->L.TotalAllocates, pLookaside->L.AllocateMisses,
  1123. pLookaside->L.TotalFrees, pLookaside->L.FreeMisses, pLookaside->L.Depth));
  1124. }
  1125. */