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.

488 lines
13 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. PFILE_OBJECT AddressFileObject;
  131. PVOID ClientContext;
  132. PVOID IrlmpContext;
  133. IRDA_CONN_STATES ConnState;
  134. BOOLEAN IsServer;
  135. LIST_ENTRY RecvIrpList;
  136. LIST_ENTRY SendIrpList;
  137. LIST_ENTRY SendIrpPassiveList;
  138. #if DBG
  139. unsigned Sig;
  140. int LockLine;
  141. int TotalFramesCnt;
  142. int CreditsExtended;
  143. int TotalByteCount;
  144. #endif
  145. TDI_ADDRESS_IRDA LocalAddr;
  146. int LocalLsapSel;
  147. TDI_ADDRESS_IRDA RemoteAddr;
  148. int RemoteLsapSel;
  149. int SendMaxSDU;
  150. int SendMaxPDU;
  151. int TtpRecvCreditsLeft;
  152. int RetryConnCount;
  153. IRDA_TIMER RetryConnTimer;
  154. REF_CNT RefCnt;
  155. CTEEvent SendEvent;
  156. LIST_ENTRY RecvBufList;
  157. BOOLEAN RecvBusy;
  158. BOOLEAN ConnectionUp;
  159. } IRDA_CONN_OBJ, *PIRDA_CONN_OBJ;
  160. typedef struct
  161. {
  162. LIST_ENTRY Linkage;
  163. UINT Len;
  164. UINT Offset;
  165. UCHAR Data[IRDA_MAX_DATA_SIZE];
  166. UINT FinalSeg;
  167. } IRDA_RECV_BUF, *PIRDA_RECV_BUF;
  168. typedef struct
  169. {
  170. LIST_ENTRY Linkage;
  171. PVOID AttribHandle;
  172. PFILE_OBJECT pFileObject;
  173. } IRDA_IAS_ATTRIB, *PIRDA_IAS_ATTRIB;
  174. #if DBG
  175. #define GET_CONN_LOCK(pConn, Handle) { \
  176. CTEGetLock(&(pConn)->Lock, Handle); \
  177. (pConn)->LockLine = __LINE__; \
  178. }
  179. #define FREE_CONN_LOCK(pConn, Handle) { \
  180. CTEAssert((pConn)->LockLine != 0) \
  181. (pConn)->LockLine = 0; \
  182. CTEFreeLock(&(pConn)->Lock, Handle); \
  183. }
  184. #define GET_ADDR_LOCK(pAddr, Handle) { \
  185. CTEGetLock(&(pAddr)->Lock, Handle); \
  186. (pAddr)->LockLine = __LINE__; \
  187. }
  188. #define FREE_ADDR_LOCK(pAddr, Handle) { \
  189. CTEAssert((pAddr)->LockLine != 0); \
  190. (pAddr)->LockLine = 0; \
  191. CTEFreeLock(&(pAddr)->Lock, Handle); \
  192. }
  193. #else
  194. #define GET_CONN_LOCK(pConn,Handle) CTEGetLock(&(pConn)->Lock, Handle)
  195. #define FREE_CONN_LOCK(pConn,Handle) CTEFreeLock(&(pConn)->Lock, Handle)
  196. #define GET_ADDR_LOCK(pAddr,Handle) CTEGetLock(&(pAddr)->Lock, Handle)
  197. #define FREE_ADDR_LOCK(pAddr,Handle) CTEFreeLock(&(pAddr)->Lock, Handle)
  198. #endif
  199. NTSTATUS
  200. DriverEntry(
  201. PDRIVER_OBJECT pDriverObject,
  202. PUNICODE_STRING pRegistryPath);
  203. VOID
  204. DriverUnload(
  205. PDRIVER_OBJECT pDriverObject);
  206. NTSTATUS
  207. IrDADispatch(
  208. PDEVICE_OBJECT pDeviceObject,
  209. PIRP pIrp);
  210. NTSTATUS
  211. IrDACreate(
  212. PDEVICE_OBJECT pDeviceObject,
  213. PIRP pIrp,
  214. PIO_STACK_LOCATION pIrpSp);
  215. FILE_FULL_EA_INFORMATION UNALIGNED *
  216. FindEA(
  217. PFILE_FULL_EA_INFORMATION pStartEA,
  218. CHAR *pTargetName,
  219. USHORT TargetNameLength);
  220. NTSTATUS
  221. IrDACleanup(
  222. PDEVICE_OBJECT pDeviceObject,
  223. PIRP pIrp,
  224. PIO_STACK_LOCATION pIrpSp);
  225. void
  226. IrDACloseObjectComplete(
  227. void *pContext,
  228. unsigned int Status,
  229. unsigned int UnUsed);
  230. NTSTATUS
  231. IrDAClose(
  232. PIRP pIrp,
  233. PIO_STACK_LOCATION pIrpSp);
  234. NTSTATUS
  235. IrDADispatchInternalDeviceControl(
  236. PDEVICE_OBJECT pDeviceObject,
  237. PIRP pIrp);
  238. NTSTATUS
  239. IrDADispatchDeviceControl(
  240. PIRP pIrp,
  241. PIO_STACK_LOCATION pIrpSp);
  242. NTSTATUS
  243. TdiDispatch(
  244. PIRP pIrp,
  245. PIO_STACK_LOCATION pIrpSp,
  246. BOOLEAN Pendable,
  247. BOOLEAN Cancelable);
  248. void
  249. TdiDispatchReqComplete(
  250. void *pContext,
  251. unsigned int Status,
  252. unsigned int ByteCount);
  253. void
  254. TdiCancelIrp(
  255. PDEVICE_OBJECT pDeviceObject,
  256. PIRP pIrp);
  257. NTSTATUS
  258. TdiQueryInformation(
  259. PIRP pIrp,
  260. PIO_STACK_LOCATION pIrpSp);
  261. NTSTATUS
  262. TdiSetInformation(
  263. PIRP pIrp,
  264. PIO_STACK_LOCATION pIrpSp);
  265. NTSTATUS
  266. TdiSetEvent(
  267. PIRDA_ADDR_OBJ pAddrObj,
  268. int Type,
  269. PVOID pHandler,
  270. PVOID pContext);
  271. int
  272. GetLsapSelServiceName(
  273. CHAR *ServiceName);
  274. VOID
  275. FreeConnObject(
  276. PIRDA_CONN_OBJ pConn);
  277. NTSTATUS
  278. TdiOpenAddress(
  279. PIRDA_ADDR_OBJ *ppNewAddrObj,
  280. TRANSPORT_ADDRESS UNALIGNED *pAddrList,
  281. USHORT AddrListLen);
  282. NTSTATUS
  283. TdiOpenConnection(
  284. PIRDA_CONN_OBJ *ppNewConnObj,
  285. PVOID pContext,
  286. USHORT ContextLen);
  287. NTSTATUS
  288. TdiCloseAddress(
  289. PIRDA_ADDR_OBJ pAddrObj);
  290. NTSTATUS
  291. TdiCloseConnection(
  292. PIRDA_CONN_OBJ pConnObj);
  293. NTSTATUS
  294. TdiAssociateAddress(
  295. PIRP pIrp,
  296. PIO_STACK_LOCATION pIrpSp);
  297. NTSTATUS
  298. TdiDisassociateAddress(
  299. PIRP pIrp,
  300. PIO_STACK_LOCATION pIrpSp);
  301. NTSTATUS
  302. TdiConnect(
  303. PIRP pIrp,
  304. PIO_STACK_LOCATION pIrpSp);
  305. NTSTATUS
  306. TdiDisconnect(
  307. PIRP pIrp,
  308. PIO_STACK_LOCATION pIrpSp,
  309. PIRDA_CONN_OBJ pConn);
  310. NTSTATUS
  311. TdiSend(
  312. PIRP pIrp,
  313. PIO_STACK_LOCATION pIrpSp);
  314. VOID
  315. TdiSendAtPassiveCallback(
  316. struct CTEEvent *Event,
  317. PVOID Arg);
  318. NTSTATUS
  319. TdiSendAtPassive(
  320. PIRP pIrp,
  321. PIO_STACK_LOCATION pIrpSp);
  322. NTSTATUS
  323. TdiReceive(
  324. PIRP pIrp,
  325. PIO_STACK_LOCATION pIrpSp);
  326. VOID
  327. PendingIasRequestCallback(
  328. struct CTEEvent *Event,
  329. PVOID Arg);
  330. VOID
  331. IrlmpGetValueByClassConf(
  332. IRDA_MSG *pMsg);
  333. ULONG
  334. GetMdlChainByteCount(
  335. PMDL pMdl);
  336. VOID
  337. CancelIrp(
  338. PDEVICE_OBJECT DeviceObject,
  339. PIRP pIrp);
  340. VOID
  341. CancelConnObjIrp(
  342. PDEVICE_OBJECT DeviceObject,
  343. PIRP pIrp);
  344. VOID
  345. PendIrp(
  346. PLIST_ENTRY pList,
  347. PIRP pIrp,
  348. PIRDA_CONN_OBJ pConn,
  349. BOOLEAN LockHeld);
  350. NTSTATUS
  351. InitiateIasQuery(
  352. PIRP pIrp,
  353. PIO_STACK_LOCATION pIrpSp,
  354. PIRDA_CONN_OBJ pConn);
  355. int
  356. GetUnusedLsapSel();
  357. VOID
  358. SetLsapSelAddr(
  359. int LsapSel,
  360. CHAR *ServiceName);
  361. BOOLEAN
  362. MyStrEqual(
  363. CHAR *Str1,
  364. CHAR *Str2,
  365. int Len);
  366. VOID
  367. RetryConnection(
  368. PIRDA_CONN_OBJ pConn,
  369. PIRP pIrp
  370. );
  371. VOID
  372. RetryConnTimerExp(
  373. PVOID Context);
  374. VOID
  375. LazyDscvTimerExp(PVOID Context);
  376. #if 1
  377. char *
  378. IrpMJTxt(
  379. PIO_STACK_LOCATION pIrpSp);
  380. char *
  381. IrpTdiTxt(
  382. PIO_STACK_LOCATION pIrpSp);
  383. char *
  384. IrpTdiObjTypeTxt(
  385. PIO_STACK_LOCATION pIrpSp);
  386. char *
  387. TdiEventTxt(
  388. int EventType);
  389. void
  390. DumpObjects(void);
  391. char *
  392. IrDAPrimTxt(
  393. IRDA_SERVICE_PRIM Prim);
  394. char *
  395. TdiQueryTxt(LONG Type);
  396. #else
  397. #define DumpObjects()
  398. #endif