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.

487 lines
12 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. irda.h
  5. Abstract:
  6. irda.sys
  7. Author:
  8. Zed (mikezin) 09-Sep-1996
  9. mbert Sept 97
  10. --*/
  11. #include <irdatdi.h>
  12. extern POBJECT_TYPE *IoFileObjectType;
  13. #define SHIFT10000 13
  14. #define CTEConvert100nsToMilliseconds(HnsTime) \
  15. RtlExtendedMagicDivide((HnsTime), Magic10000, SHIFT10000)
  16. #define FSCTL_IRDA_BASE FILE_DEVICE_NETWORK
  17. #define LSAPSEL_TXT "LSAP-SEL"
  18. #define LSAPSEL_TXTLEN 8
  19. #define TTP_CREDIT_ADVANCE_THRESH 8
  20. #define TTP_RECV_MAX_SDU 0 // unlimited
  21. #define DEFAULT_LAZY_DSCV_INTERVAL 4
  22. // How many times should we retry making a connection if
  23. // the link is busy? (lazy discoveries you know from peer can block connection.)
  24. #define BUSY_LINK_CONN_RETRIES 6
  25. #define BUSY_LINK_CONN_RETRY_WAIT 200 // msec before retry attempt
  26. #define EXPDEVID(Id) (Id)[0], (Id)[1], (Id)[2], (Id)[3]
  27. //
  28. // Winsock error codes are also defined in winerror.h
  29. // Hence the IFDEF
  30. //
  31. #ifndef WSABASEERR
  32. // wmz from winsock.h
  33. #define WSABASEERR 10000
  34. #define WSAEINTR (WSABASEERR+4)
  35. #define WSAEBADF (WSABASEERR+9)
  36. #define WSAEACCES (WSABASEERR+13)
  37. #define WSAEFAULT (WSABASEERR+14)
  38. #define WSAEINVAL (WSABASEERR+22)
  39. #define WSAEMFILE (WSABASEERR+24)
  40. #define WSAEWOULDBLOCK (WSABASEERR+35)
  41. #define WSAEINPROGRESS (WSABASEERR+36)
  42. #define WSAEALREADY (WSABASEERR+37)
  43. #define WSAENOTSOCK (WSABASEERR+38)
  44. #define WSAEDESTADDRREQ (WSABASEERR+39)
  45. #define WSAEMSGSIZE (WSABASEERR+40)
  46. #define WSAEPROTOTYPE (WSABASEERR+41)
  47. #define WSAENOPROTOOPT (WSABASEERR+42)
  48. #define WSAEPROTONOSUPPORT (WSABASEERR+43)
  49. #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
  50. #define WSAEOPNOTSUPP (WSABASEERR+45)
  51. #define WSAEPFNOSUPPORT (WSABASEERR+46)
  52. #define WSAEAFNOSUPPORT (WSABASEERR+47)
  53. #define WSAEADDRINUSE (WSABASEERR+48)
  54. #define WSAEADDRNOTAVAIL (WSABASEERR+49)
  55. #define WSAENETDOWN (WSABASEERR+50)
  56. #define WSAENETUNREACH (WSABASEERR+51)
  57. #define WSAENETRESET (WSABASEERR+52)
  58. #define WSAECONNABORTED (WSABASEERR+53)
  59. #define WSAECONNRESET (WSABASEERR+54)
  60. #define WSAENOBUFS (WSABASEERR+55)
  61. #define WSAEISCONN (WSABASEERR+56)
  62. #define WSAENOTCONN (WSABASEERR+57)
  63. #define WSAESHUTDOWN (WSABASEERR+58)
  64. #define WSAETOOMANYREFS (WSABASEERR+59)
  65. #define WSAETIMEDOUT (WSABASEERR+60)
  66. #define WSAECONNREFUSED (WSABASEERR+61)
  67. #define WSAELOOP (WSABASEERR+62)
  68. #define WSAENAMETOOLONG (WSABASEERR+63)
  69. #define WSAEHOSTDOWN (WSABASEERR+64)
  70. #define WSAEHOSTUNREACH (WSABASEERR+65)
  71. #define WSAENOTEMPTY (WSABASEERR+66)
  72. #define WSAEPROCLIM (WSABASEERR+67)
  73. #define WSAEUSERS (WSABASEERR+68)
  74. #define WSAEDQUOT (WSABASEERR+69)
  75. #define WSAESTALE (WSABASEERR+70)
  76. #define WSAEREMOTE (WSABASEERR+71)
  77. #define WSAEDISCON (WSABASEERR+101)
  78. #endif // ifdef WSABASEERR
  79. #define IRDA_MIN_LSAP_SEL 1
  80. #define IRDA_MAX_LSAP_SEL 127
  81. typedef enum
  82. {
  83. IRDA_CONN_CREATED, // don't change order
  84. IRDA_CONN_CLOSING,
  85. IRDA_CONN_OPENING,
  86. IRDA_CONN_OPEN
  87. } IRDA_CONN_STATES;
  88. typedef enum
  89. {
  90. CONNECTION_UP,
  91. CONNECTION_DOWN,
  92. CONNECTION_INTERRUPTED
  93. } IRDA_CONNECTION_STATUS; // Irmon taskbar status
  94. #define ADDR_OBJ_SIG 0xAAAAAAAA
  95. #define CONN_OBJ_SIG 0xCCCCCCCC
  96. #define IS_VALID_ADDR(p) (((p) != NULL) && ((p)->Sig == ADDR_OBJ_SIG))
  97. #define IS_VALID_CONN(p) (((p) != NULL) && ((p)->Sig == CONN_OBJ_SIG))
  98. #define IRLPT_MODE1 1
  99. #define IRLPT_MODE2 2
  100. #define UNMARK_IRP_PENDING(_Request) \
  101. (((IoGetCurrentIrpStackLocation(_Request))->Control) &= ~SL_PENDING_RETURNED)
  102. typedef struct _IRDA_CONN_OBJ *PIRDA_CONN_OBJ;
  103. typedef struct _IRDA_ADDR_OBJ
  104. {
  105. CTELock Lock;
  106. struct _IRDA_ADDR_OBJ *pNext;
  107. PIRDA_CONN_OBJ ConnObjList;
  108. BOOLEAN IsServer;
  109. UINT UseIrlptMode;
  110. BOOLEAN Use9WireMode;
  111. TDI_ADDRESS_IRDA LocalAddr;
  112. int LocalLsapSel;
  113. PVOID IasAttribHandle;
  114. PTDI_IND_CONNECT pEventConnect;
  115. PVOID pEventConnectContext;
  116. PTDI_IND_DISCONNECT pEventDisconnect;
  117. PVOID pEventDisconnectContext;
  118. PTDI_IND_RECEIVE pEventReceive;
  119. PVOID pEventReceiveContext;
  120. #if DBG
  121. unsigned Sig;
  122. int LockLine;
  123. #endif
  124. } IRDA_ADDR_OBJ, *PIRDA_ADDR_OBJ;
  125. typedef struct _IRDA_CONN_OBJ
  126. {
  127. CTELock Lock;
  128. struct _IRDA_CONN_OBJ *pNext;
  129. PIRDA_ADDR_OBJ pAddr;
  130. PVOID ClientContext;
  131. PVOID IrlmpContext;
  132. IRDA_CONN_STATES ConnState;
  133. BOOLEAN IsServer;
  134. LIST_ENTRY RecvIrpList;
  135. LIST_ENTRY SendIrpList;
  136. LIST_ENTRY SendIrpPassiveList;
  137. #if DBG
  138. unsigned Sig;
  139. int LockLine;
  140. int TotalFramesCnt;
  141. int CreditsExtended;
  142. int TotalByteCount;
  143. #endif
  144. TDI_ADDRESS_IRDA LocalAddr;
  145. int LocalLsapSel;
  146. TDI_ADDRESS_IRDA RemoteAddr;
  147. int RemoteLsapSel;
  148. int SendMaxSDU;
  149. int SendMaxPDU;
  150. int TtpRecvCreditsLeft;
  151. int RetryConnCount;
  152. IRDA_TIMER RetryConnTimer;
  153. REF_CNT RefCnt;
  154. CTEEvent SendEvent;
  155. LIST_ENTRY RecvBufList;
  156. BOOLEAN RecvBusy;
  157. BOOLEAN ConnectionUp;
  158. } IRDA_CONN_OBJ, *PIRDA_CONN_OBJ;
  159. typedef struct
  160. {
  161. LIST_ENTRY Linkage;
  162. UINT Len;
  163. UINT Offset;
  164. UCHAR Data[IRDA_MAX_DATA_SIZE];
  165. UINT FinalSeg;
  166. } IRDA_RECV_BUF, *PIRDA_RECV_BUF;
  167. typedef struct
  168. {
  169. LIST_ENTRY Linkage;
  170. PVOID AttribHandle;
  171. PFILE_OBJECT pFileObject;
  172. } IRDA_IAS_ATTRIB, *PIRDA_IAS_ATTRIB;
  173. #if DBG
  174. #define GET_CONN_LOCK(pConn, Handle) { \
  175. CTEGetLock(&(pConn)->Lock, Handle); \
  176. (pConn)->LockLine = __LINE__; \
  177. }
  178. #define FREE_CONN_LOCK(pConn, Handle) { \
  179. CTEAssert((pConn)->LockLine != 0) \
  180. (pConn)->LockLine = 0; \
  181. CTEFreeLock(&(pConn)->Lock, Handle); \
  182. }
  183. #define GET_ADDR_LOCK(pAddr, Handle) { \
  184. CTEGetLock(&(pAddr)->Lock, Handle); \
  185. (pAddr)->LockLine = __LINE__; \
  186. }
  187. #define FREE_ADDR_LOCK(pAddr, Handle) { \
  188. CTEAssert((pAddr)->LockLine != 0); \
  189. (pAddr)->LockLine = 0; \
  190. CTEFreeLock(&(pAddr)->Lock, Handle); \
  191. }
  192. #else
  193. #define GET_CONN_LOCK(pConn,Handle) CTEGetLock(&(pConn)->Lock, Handle)
  194. #define FREE_CONN_LOCK(pConn,Handle) CTEFreeLock(&(pConn)->Lock, Handle)
  195. #define GET_ADDR_LOCK(pAddr,Handle) CTEGetLock(&(pAddr)->Lock, Handle)
  196. #define FREE_ADDR_LOCK(pAddr,Handle) CTEFreeLock(&(pAddr)->Lock, Handle)
  197. #endif
  198. NTSTATUS
  199. DriverEntry(
  200. PDRIVER_OBJECT pDriverObject,
  201. PUNICODE_STRING pRegistryPath);
  202. VOID
  203. DriverUnload(
  204. PDRIVER_OBJECT pDriverObject);
  205. NTSTATUS
  206. IrDADispatch(
  207. PDEVICE_OBJECT pDeviceObject,
  208. PIRP pIrp);
  209. NTSTATUS
  210. IrDACreate(
  211. PDEVICE_OBJECT pDeviceObject,
  212. PIRP pIrp,
  213. PIO_STACK_LOCATION pIrpSp);
  214. FILE_FULL_EA_INFORMATION UNALIGNED *
  215. FindEA(
  216. PFILE_FULL_EA_INFORMATION pStartEA,
  217. CHAR *pTargetName,
  218. USHORT TargetNameLength);
  219. NTSTATUS
  220. IrDACleanup(
  221. PDEVICE_OBJECT pDeviceObject,
  222. PIRP pIrp,
  223. PIO_STACK_LOCATION pIrpSp);
  224. void
  225. IrDACloseObjectComplete(
  226. void *pContext,
  227. unsigned int Status,
  228. unsigned int UnUsed);
  229. NTSTATUS
  230. IrDAClose(
  231. PIRP pIrp,
  232. PIO_STACK_LOCATION pIrpSp);
  233. NTSTATUS
  234. IrDADispatchInternalDeviceControl(
  235. PDEVICE_OBJECT pDeviceObject,
  236. PIRP pIrp);
  237. NTSTATUS
  238. IrDADispatchDeviceControl(
  239. PIRP pIrp,
  240. PIO_STACK_LOCATION pIrpSp);
  241. NTSTATUS
  242. TdiDispatch(
  243. PIRP pIrp,
  244. PIO_STACK_LOCATION pIrpSp,
  245. BOOLEAN Pendable,
  246. BOOLEAN Cancelable);
  247. void
  248. TdiDispatchReqComplete(
  249. void *pContext,
  250. unsigned int Status,
  251. unsigned int ByteCount);
  252. void
  253. TdiCancelIrp(
  254. PDEVICE_OBJECT pDeviceObject,
  255. PIRP pIrp);
  256. NTSTATUS
  257. TdiQueryInformation(
  258. PIRP pIrp,
  259. PIO_STACK_LOCATION pIrpSp);
  260. NTSTATUS
  261. TdiSetInformation(
  262. PIRP pIrp,
  263. PIO_STACK_LOCATION pIrpSp);
  264. NTSTATUS
  265. TdiSetEvent(
  266. PIRDA_ADDR_OBJ pAddrObj,
  267. int Type,
  268. PVOID pHandler,
  269. PVOID pContext);
  270. int
  271. GetLsapSelServiceName(
  272. CHAR *ServiceName);
  273. VOID
  274. FreeConnObject(
  275. PIRDA_CONN_OBJ pConn);
  276. NTSTATUS
  277. TdiOpenAddress(
  278. PIRDA_ADDR_OBJ *ppNewAddrObj,
  279. TRANSPORT_ADDRESS UNALIGNED *pAddrList,
  280. USHORT AddrListLen);
  281. NTSTATUS
  282. TdiOpenConnection(
  283. PIRDA_CONN_OBJ *ppNewConnObj,
  284. PVOID pContext,
  285. USHORT ContextLen);
  286. NTSTATUS
  287. TdiCloseAddress(
  288. PIRDA_ADDR_OBJ pAddrObj);
  289. NTSTATUS
  290. TdiCloseConnection(
  291. PIRDA_CONN_OBJ pConnObj);
  292. NTSTATUS
  293. TdiAssociateAddress(
  294. PIRP pIrp,
  295. PIO_STACK_LOCATION pIrpSp);
  296. NTSTATUS
  297. TdiDisassociateAddress(
  298. PIRP pIrp,
  299. PIO_STACK_LOCATION pIrpSp);
  300. NTSTATUS
  301. TdiConnect(
  302. PIRP pIrp,
  303. PIO_STACK_LOCATION pIrpSp);
  304. NTSTATUS
  305. TdiDisconnect(
  306. PIRP pIrp,
  307. PIO_STACK_LOCATION pIrpSp,
  308. PIRDA_CONN_OBJ pConn);
  309. NTSTATUS
  310. TdiSend(
  311. PIRP pIrp,
  312. PIO_STACK_LOCATION pIrpSp);
  313. VOID
  314. TdiSendAtPassiveCallback(
  315. struct CTEEvent *Event,
  316. PVOID Arg);
  317. NTSTATUS
  318. TdiSendAtPassive(
  319. PIRP pIrp,
  320. PIO_STACK_LOCATION pIrpSp);
  321. NTSTATUS
  322. TdiReceive(
  323. PIRP pIrp,
  324. PIO_STACK_LOCATION pIrpSp);
  325. VOID
  326. PendingIasRequestCallback(
  327. struct CTEEvent *Event,
  328. PVOID Arg);
  329. VOID
  330. IrlmpGetValueByClassConf(
  331. IRDA_MSG *pMsg);
  332. ULONG
  333. GetMdlChainByteCount(
  334. PMDL pMdl);
  335. VOID
  336. CancelIrp(
  337. PDEVICE_OBJECT DeviceObject,
  338. PIRP pIrp);
  339. VOID
  340. CancelConnObjIrp(
  341. PDEVICE_OBJECT DeviceObject,
  342. PIRP pIrp);
  343. VOID
  344. PendIrp(
  345. PLIST_ENTRY pList,
  346. PIRP pIrp,
  347. PIRDA_CONN_OBJ pConn,
  348. BOOLEAN LockHeld);
  349. NTSTATUS
  350. InitiateIasQuery(
  351. PIRP pIrp,
  352. PIO_STACK_LOCATION pIrpSp,
  353. PIRDA_CONN_OBJ pConn);
  354. int
  355. GetUnusedLsapSel();
  356. VOID
  357. SetLsapSelAddr(
  358. int LsapSel,
  359. CHAR *ServiceName);
  360. BOOLEAN
  361. MyStrEqual(
  362. CHAR *Str1,
  363. CHAR *Str2,
  364. int Len);
  365. VOID
  366. RetryConnection(
  367. PIRDA_CONN_OBJ pConn,
  368. PIRP pIrp
  369. );
  370. VOID
  371. RetryConnTimerExp(
  372. PVOID Context);
  373. VOID
  374. LazyDscvTimerExp(PVOID Context);
  375. #if DBG
  376. char *
  377. IrpMJTxt(
  378. PIO_STACK_LOCATION pIrpSp);
  379. char *
  380. IrpTdiTxt(
  381. PIO_STACK_LOCATION pIrpSp);
  382. char *
  383. IrpTdiObjTypeTxt(
  384. PIO_STACK_LOCATION pIrpSp);
  385. char *
  386. TdiEventTxt(
  387. int EventType);
  388. void
  389. DumpObjects(void);
  390. char *
  391. IrDAPrimTxt(
  392. IRDA_SERVICE_PRIM Prim);
  393. char *
  394. TdiQueryTxt(LONG Type);
  395. #else
  396. #define DumpObjects()
  397. #endif