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.

1146 lines
29 KiB

  1. /**************************************************************************************************************************
  2. * IRCOMMON.H SigmaTel STIR4200 common USB/IR definitions
  3. **************************************************************************************************************************
  4. * (C) Unpublished Copyright of Sigmatel, Inc. All Rights Reserved.
  5. *
  6. *
  7. * Created: 04/06/2000
  8. * Version 0.9
  9. * Edited: 04/24/2000
  10. * Version 0.91
  11. * Edited: 04/27/2000
  12. * Version 0.92
  13. * Edited: 05/03/2000
  14. * Version 0.93
  15. * Edited: 05/12/2000
  16. * Version 0.94
  17. * Edited: 05/19/2000
  18. * Version 0.95
  19. * Edited: 07/27/2000
  20. * Version 1.01
  21. * Edited: 09/16/2000
  22. * Version 1.03
  23. * Edited: 09/25/2000
  24. * Version 1.10
  25. * Edited: 11/09/2000
  26. * Version 1.12
  27. * Edited: 02/20/2001
  28. * Version 1.15
  29. *
  30. **************************************************************************************************************************/
  31. #ifndef _IRCOM_H
  32. #define _IRCOM_H
  33. #include "stir4200.h"
  34. //
  35. // This is for use by check-for-hang handler and is just a reasonable guess;
  36. // Total # of USBD control errors, read aerrors and write errors;
  37. // Used by check-for-hang handler to decide if we need a reset
  38. //
  39. #define IRUSB_100ns_PER_ms 10000
  40. #define IRUSB_100ns_PER_us 10
  41. #define IRUSB_ms_PER_SEC 1000
  42. #define IRUSB_100ns_PER_SEC ( IRUSB_100ns_PER_ms * IRUSB_ms_PER_SEC )
  43. #define MAX_QUERY_TIME_100ns ( 8 * IRUSB_100ns_PER_SEC ) //8 sec
  44. #define MAX_SET_TIME_100ns MAX_QUERY_TIME_100ns
  45. #define MAX_SEND_TIME_100ns ( 20 * IRUSB_100ns_PER_SEC ) //20 sec
  46. #define MAX_TURNAROUND_usec 10000
  47. #define DEFAULT_TURNAROUND_usec 1000
  48. //
  49. // Customer data area size.
  50. // Big enough for 2 byte header (7e7e) + one byte count + 255 bytes data.
  51. // Header bytes are not sent back to app.
  52. //
  53. #define STIR4200_CUST_DATA_SIZE (2+256)
  54. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  55. #define MAX(a,b) (((a) >= (b)) ? (a) : (b))
  56. //
  57. // A receive buffer is either FREE (not holding anything) FULL
  58. // (holding undelivered data) or PENDING (holding data delivered
  59. // asynchronously)
  60. //
  61. typedef enum
  62. {
  63. RCV_STATE_FREE,
  64. RCV_STATE_FULL,
  65. RCV_STATE_PENDING
  66. } RCV_BUFFER_STATE, FIFO_BUFFER_STATE;
  67. //
  68. // Structure to keep track of receive packets and buffers to indicate
  69. // receive data to the protocol.
  70. //
  71. typedef struct
  72. {
  73. PVOID pPacket;
  74. UINT DataLen;
  75. PUCHAR pDataBuf;
  76. PVOID pThisDev;
  77. ULONG fInRcvDpc;
  78. RCV_BUFFER_STATE BufferState;
  79. #if defined(DIAGS)
  80. LIST_ENTRY ListEntry; // This will be used to do the diags queueing
  81. #endif
  82. #if defined(WORKAROUND_MISSING_C1)
  83. BOOLEAN MissingC1Detected;
  84. BOOLEAN MissingC1Possible;
  85. #endif
  86. } RCV_BUFFER, *PRCV_BUFFER;
  87. //
  88. // Structure to read data from the FIFO
  89. //
  90. typedef struct
  91. {
  92. UINT DataLen;
  93. PUCHAR pDataBuf;
  94. PVOID pThisDev;
  95. PVOID pIrp;
  96. PURB pUrb; // urb allocated by irp send routine, deallocated
  97. UINT UrbLen; // by irp completion handler
  98. FIFO_BUFFER_STATE BufferState;
  99. } FIFO_BUFFER, *PFIFO_BUFFER;
  100. //
  101. // All different sizes for data
  102. //
  103. #define IRDA_ADDRESS_FIELD_SIZE 1
  104. #define IRDA_CONTROL_FIELD_SIZE 1
  105. #define IRDA_A_C_TOTAL_SIZE ( IRDA_ADDRESS_FIELD_SIZE + IRDA_CONTROL_FIELD_SIZE )
  106. #define USB_IRDA_TOTAL_NON_DATA_SIZE ( IRDA_ADDRESS_FIELD_SIZE + IRDA_CONTROL_FIELD_SIZE )
  107. #define IRDA_MAX_DATAONLY_SIZE 2048
  108. #define MAX_TOTAL_SIZE_WITH_ALL_HEADERS ( IRDA_MAX_DATAONLY_SIZE + USB_IRDA_TOTAL_NON_DATA_SIZE )
  109. #define MAX_NUM_EXTRA_BOFS 48
  110. // Fix for MS Security Bug #533267
  111. #define MAX_POSSIBLE_IR_PACKET_SIZE_FOR_DATA(dataLen) ( \
  112. (dataLen) * 2 + (MAX_NUM_EXTRA_BOFS + 1) * \
  113. SLOW_IR_BOF_SIZE + IRDA_ADDRESS_FIELD_SIZE + IRDA_CONTROL_FIELD_SIZE + \
  114. (2 * FAST_IR_FCS_SIZE) + (2 * SLOW_IR_FCS_SIZE) + SLOW_IR_EOF_SIZE) + \
  115. sizeof(STIR4200_FRAME_HEADER)
  116. //
  117. // Note that the receive size needs to be incremented to account for
  118. // the way the decoding can use one more byte
  119. //
  120. #define MAX_RCV_DATA_SIZE (MAX_TOTAL_SIZE_WITH_ALL_HEADERS + FAST_IR_FCS_SIZE + 1)
  121. #define MAX_IRDA_DATA_SIZE MAX_POSSIBLE_IR_PACKET_SIZE_FOR_DATA(IRDA_MAX_DATAONLY_SIZE)
  122. //
  123. // Possible speeds
  124. //
  125. typedef enum _BAUD_RATE
  126. {
  127. //
  128. // Slow IR
  129. //
  130. BAUDRATE_2400 = 0,
  131. BAUDRATE_9600,
  132. BAUDRATE_19200,
  133. BAUDRATE_38400,
  134. BAUDRATE_57600,
  135. BAUDRATE_115200,
  136. //
  137. // Medium IR
  138. //
  139. #if !defined(DWORKAROUND_BROKEN_MIR)
  140. BAUDRATE_576000,
  141. BAUDRATE_1152000,
  142. #endif
  143. //
  144. // Fast IR
  145. //
  146. BAUDRATE_4000000,
  147. //
  148. // must be last
  149. //
  150. NUM_BAUDRATES
  151. } BAUD_RATE;
  152. typedef enum _IR_MODE
  153. {
  154. IR_MODE_SIR = 0,
  155. IR_MODE_MIR,
  156. IR_MODE_FIR,
  157. NUM_IR_MODES
  158. } IR_MODE;
  159. //
  160. // Speeds
  161. //
  162. #define SPEED_2400 2400
  163. #define SPEED_9600 9600
  164. #define SPEED_19200 19200
  165. #define SPEED_38400 38400
  166. #define SPEED_57600 57600
  167. #define SPEED_115200 115200
  168. #define SPEED_576000 576000
  169. #define SPEED_1152000 1152000
  170. #define SPEED_4000000 4000000
  171. #define DEFAULT_BAUD_RATE SPEED_9600
  172. #define MAX_SIR_SPEED SPEED_115200
  173. #define MAX_MIR_SPEED SPEED_1152000
  174. //
  175. // Sizes of IrLAP frame fields:
  176. // Beginning Of Frame (BOF)
  177. // End Of Frame (EOF)
  178. // Address
  179. // Control
  180. //
  181. #define SLOW_IR_BOF_TYPE UCHAR
  182. #define SLOW_IR_BOF_SIZE sizeof(SLOW_IR_BOF_TYPE)
  183. #define SLOW_IR_EOF_TYPE UCHAR
  184. #define SLOW_IR_EOF_SIZE sizeof(SLOW_IR_EOF_TYPE)
  185. #define SLOW_IR_FCS_TYPE USHORT
  186. #define SLOW_IR_FCS_SIZE sizeof(SLOW_IR_FCS_TYPE)
  187. #define SLOW_IR_BOF 0xC0
  188. #define SLOW_IR_EOF 0xC1
  189. #define SLOW_IR_ESC 0x7D
  190. #define SLOW_IR_ESC_COMP 0x20
  191. #define SLOW_IR_EXTRA_BOF_TYPE UCHAR
  192. #define SLOW_IR_EXTRA_BOF_SIZE sizeof(SLOW_IR_EXTRA_BOF_TYPE)
  193. #define SLOW_IR_EXTRA_BOF 0xC0
  194. #define MEDIUM_IR_BOF 0x7E
  195. #define MEDIUM_IR_EOF 0x7E
  196. #define MEDIUM_IR_FCS_TYPE USHORT
  197. #define MEDIUM_IR_FCS_SIZE sizeof(MEDIUM_IR_FCS_TYPE)
  198. #define FAST_IR_FCS_TYPE ULONG
  199. #define FAST_IR_FCS_SIZE sizeof(FAST_IR_FCS_TYPE)
  200. #define FAST_IR_EOF_TYPE ULONG
  201. #define FAST_IR_EOF_SIZE sizeof(FAST_IR_EOF_TYPE)
  202. //
  203. // Definition for speed masks
  204. //
  205. #define NDIS_IRDA_SPEED_MASK_2400 0x001 // SLOW IR ...
  206. #define NDIS_IRDA_SPEED_MASK_9600 0x003
  207. #define NDIS_IRDA_SPEED_MASK_19200 0x007
  208. #define NDIS_IRDA_SPEED_MASK_38400 0x00f
  209. #define NDIS_IRDA_SPEED_MASK_57600 0x01f
  210. #define NDIS_IRDA_SPEED_MASK_115200 0x03f
  211. #define NDIS_IRDA_SPEED_MASK_576K 0x07f // MEDIUM IR ...
  212. #define NDIS_IRDA_SPEED_MASK_1152K 0x0ff
  213. #define NDIS_IRDA_SPEED_MASK_4M 0x1ff // FAST IR
  214. #define GOOD_FCS ((USHORT) ~0xf0b8)
  215. #define FIR_GOOD_FCS ((ULONG) ~0xdebb20e3)
  216. typedef struct
  217. {
  218. BAUD_RATE TableIndex;
  219. UINT BitsPerSec;
  220. IR_MODE IrMode;
  221. UINT NdisCode; // bitmask element as used by ndis and in class-specific descriptor
  222. UCHAR Stir4200Divisor;
  223. } BAUDRATE_INFO;
  224. //
  225. // Struct to hold the IR USB dongle's USB Class-Specific Descriptor as per
  226. // "Universal Serial Bus IrDA Bridge Device Definition" doc, section 7.2
  227. // This is the struct returned by USBD as the result of a request with an urb
  228. // of type _URB_CONTROL_VENDOR_OR_CLASS_REQUEST, function URB_FUNCTION_CLASS_DEVICE
  229. //
  230. // Enable 1-byte alignment in the below struct
  231. #pragma pack (push,1)
  232. typedef struct _IRUSB_CLASS_SPECIFIC_DESCRIPTOR
  233. {
  234. BOOLEAN ClassConfigured;
  235. UCHAR bmDataSize; // max bytes allowed in any frame as per IrLAP spec, where:
  236. #define BM_DATA_SIZE_2048 (1 << 5)
  237. #define BM_DATA_SIZE_1024 (1 << 4)
  238. #define BM_DATA_SIZE_512 (1 << 3)
  239. #define BM_DATA_SIZE_256 (1 << 2)
  240. #define BM_DATA_SIZE_128 (1 << 1)
  241. #define BM_DATA_SIZE_64 (1 << 0)
  242. UCHAR bmWindowSize; // max un-acked frames that can be received
  243. // before an ack is sent, where:
  244. #define BM_WINDOW_SIZE_7 (1 << 6)
  245. #define BM_WINDOW_SIZE_6 (1 << 5)
  246. #define BM_WINDOW_SIZE_5 (1 << 4)
  247. #define BM_WINDOW_SIZE_4 (1 << 3)
  248. #define BM_WINDOW_SIZE_3 (1 << 2)
  249. #define BM_WINDOW_SIZE_2 (1 << 1)
  250. #define BM_WINDOW_SIZE_1 (1 << 0)
  251. UCHAR bmMinTurnaroundTime; // min millisecs required for recovery between
  252. // end of last xmission and can receive again, where:
  253. #define BM_TURNAROUND_TIME_0ms (1 << 7) // 0 ms
  254. #define BM_TURNAROUND_TIME_0p01ms (1 << 6) // 0.01 ms
  255. #define BM_TURNAROUND_TIME_0p05ms (1 << 5) // 0.05 ms
  256. #define BM_TURNAROUND_TIME_0p1ms (1 << 4) // 0.1 ms
  257. #define BM_TURNAROUND_TIME_0p5ms (1 << 3) // 0.5 ms
  258. #define BM_TURNAROUND_TIME_1ms (1 << 2) // 1 ms
  259. #define BM_TURNAROUND_TIME_5ms (1 << 1) // 5 ms
  260. #define BM_TURNAROUND_TIME_10ms (1 << 0) // 10 ms
  261. USHORT wBaudRate;
  262. //
  263. // ir speed masks as used both by NDIS and as formatted in USB class-specfic descriptor
  264. //
  265. #define NDIS_IRDA_SPEED_2400 (1 << 0) // SLOW IR ...
  266. #define NDIS_IRDA_SPEED_9600 (1 << 1)
  267. #define NDIS_IRDA_SPEED_19200 (1 << 2)
  268. #define NDIS_IRDA_SPEED_38400 (1 << 3)
  269. #define NDIS_IRDA_SPEED_57600 (1 << 4)
  270. #define NDIS_IRDA_SPEED_115200 (1 << 5)
  271. #define NDIS_IRDA_SPEED_576K (1 << 6) // MEDIUM IR ...
  272. #define NDIS_IRDA_SPEED_1152K (1 << 7)
  273. #define NDIS_IRDA_SPEED_4M (1 << 8) // FAST IR
  274. UCHAR bmExtraBofs; // #BOFS required at 115200; 0 if slow speeds <=115200 not supported
  275. #define BM_EXTRA_BOFS_0 (1 << 7)
  276. #define BM_EXTRA_BOFS_1 (1 << 6)
  277. #define BM_EXTRA_BOFS_2 (1 << 5)
  278. #define BM_EXTRA_BOFS_3 (1 << 4)
  279. #define BM_EXTRA_BOFS_6 (1 << 3)
  280. #define BM_EXTRA_BOFS_12 (1 << 2)
  281. #define BM_EXTRA_BOFS_24 (1 << 1)
  282. #define BM_EXTRA_BOFS_48 (1 << 0)
  283. } IRUSB_CLASS_SPECIFIC_DESCRIPTOR, *PIRUSB_CLASS_SPECIFIC_DESCRIPTOR;
  284. #pragma pack (pop) //disable 1-byte alignment
  285. typedef struct _DONGLE_CAPABILITIES
  286. {
  287. //
  288. // Time (in microseconds) that must transpire between
  289. // a transmit and the next receive.
  290. //
  291. LONG turnAroundTime_usec; // gotten from class-specific descriptor
  292. //
  293. // Max un-acked frames that can be received
  294. // before an ack is sent
  295. //
  296. UINT windowSize; // gotten from class-specific descriptor
  297. //
  298. // #BOFS required at 115200; 0 if slow speeds <=115200 are not supported
  299. //
  300. UINT extraBOFS; // gotten from class-specific descriptor
  301. //
  302. // max bytes allowed in any frame as per IrLAP spec
  303. //
  304. UINT dataSize; // gotten from class-specific descriptor
  305. } DONGLE_CAPABILITIES, *PDONGLE_CAPABILITIES;
  306. //
  307. // Enum of context types for SendPacket
  308. //
  309. typedef enum _CONTEXT_TYPE
  310. {
  311. CONTEXT_NDIS_PACKET,
  312. CONTEXT_SET_SPEED,
  313. CONTEXT_READ_WRITE_REGISTER,
  314. CONTEXT_DIAGS_ENABLE,
  315. CONTEXT_DIAGS_DISABLE,
  316. CONTEXT_DIAGS_READ_REGISTERS,
  317. CONTEXT_DIAGS_WRITE_REGISTER,
  318. CONTEXT_DIAGS_BULK_OUT,
  319. CONTEXT_DIAGS_BULK_IN,
  320. CONTEXT_DIAGS_SEND
  321. } CONTEXT_TYPE;
  322. typedef NTSTATUS (*WORK_PROC)(struct _IR_WORK_ITEM *);
  323. typedef struct _IR_WORK_ITEM
  324. {
  325. PVOID pIrDevice;
  326. WORK_PROC Callback;
  327. PUCHAR pInfoBuf;
  328. ULONG InfoBufLen;
  329. ULONG fInUse; // declared as ulong for use with interlockedexchange
  330. } IR_WORK_ITEM, *PIR_WORK_ITEM;
  331. //
  332. // Transceiver type definition
  333. //
  334. typedef enum _TRANSCEIVER_TYPE
  335. {
  336. TRANSCEIVER_4012 = 0,
  337. TRANSCEIVER_4000,
  338. TRANSCEIVER_VISHAY,
  339. TRANSCEIVER_VISHAY_6102F,
  340. TRANSCEIVER_INFINEON,
  341. TRANSCEIVER_HP,
  342. TRANSCEIVER_CUSTOM
  343. } TRANSCEIVER_TYPE;
  344. //
  345. // Receive mode definition
  346. //
  347. typedef enum _RXMODE
  348. {
  349. RXMODE_SLOW = 0,
  350. RXMODE_SLOWFAST,
  351. RXMODE_FAST
  352. } RXMODE;
  353. //
  354. // Chip revision definition
  355. //
  356. typedef enum _CHIP_REVISION
  357. {
  358. CHIP_REVISION_6 = 5,
  359. CHIP_REVISION_7,
  360. CHIP_REVISION_8
  361. } CHIP_REVISION;
  362. typedef struct _IR_DEVICE
  363. {
  364. //
  365. // Keep track of various device objects.
  366. //
  367. PDEVICE_OBJECT pUsbDevObj; //'Next Device Object'
  368. PDEVICE_OBJECT pPhysDevObj; // Physical Device Object
  369. //
  370. // This is the handle that the NDIS wrapper associates with a connection.
  371. // (The handle that the miniport driver associates with the connection
  372. // is just an index into the devStates array).
  373. //
  374. HANDLE hNdisAdapter;
  375. //
  376. // The dongle interface allows us to check the tranceiver type once
  377. // and then set up the interface to allow us to init, set speed,
  378. // and deinit the dongle.
  379. //
  380. // We also want the dongle capabilities.
  381. //
  382. DONGLE_CAPABILITIES dongleCaps;
  383. //
  384. // Type of transceiver installed
  385. //
  386. TRANSCEIVER_TYPE TransceiverType;
  387. //
  388. // Receive mode
  389. //
  390. RXMODE ReceiveMode;
  391. //
  392. // Revision of the installed 4200
  393. //
  394. CHIP_REVISION ChipRevision;
  395. //
  396. // Current speed setting, in bits/sec.
  397. // Note: This is updated when we ACTUALLY change the speed,
  398. // not when we get the request to change speed via
  399. // irusbSetInformation.
  400. //
  401. //
  402. // When speed is changed, we have to clear the send queue before
  403. // setting the new speed on the hardware.
  404. // These vars let us remember to do it.
  405. //
  406. UINT currentSpeed;
  407. //
  408. // Current link speed information. This also will maintain the
  409. // chosen speed if the protocol requests a speed change.
  410. //
  411. BAUDRATE_INFO *linkSpeedInfo;
  412. //
  413. // Maintain statistical debug info.
  414. //
  415. ULONG packetsReceived;
  416. ULONG packetsReceivedDropped;
  417. ULONG packetsReceivedOverflow;
  418. ULONG packetsReceivedChecksum;
  419. ULONG packetsReceivedRunt;
  420. ULONG packetsReceivedNoBuffer;
  421. ULONG packetsSent;
  422. ULONG packetsSentDropped;
  423. ULONG packetsSentRejected;
  424. ULONG packetsSentInvalid;
  425. #if DBG
  426. ULONG packetsHeldByProtocol;
  427. ULONG MaxPacketsHeldByProtocol;
  428. ULONG TotalBytesReceived;
  429. ULONG TotalBytesSent;
  430. ULONG NumYesQueryMediaBusyOids;
  431. ULONG NumNoQueryMediaBusyOids;
  432. ULONG NumSetMediaBusyOids;
  433. ULONG NumMediaBusyIndications;
  434. ULONG NumPacketsSentRequiringTurnaroundTime;
  435. ULONG NumPacketsSentNotRequiringTurnaroundTime;
  436. #endif
  437. //
  438. // used by check hang handler to track Query, Set, and Send times
  439. //
  440. LARGE_INTEGER LastQueryTime;
  441. LARGE_INTEGER LastSetTime;
  442. BOOLEAN fSetpending;
  443. BOOLEAN fQuerypending;
  444. //
  445. // Set when device has been started; use for safe cleanup after failed initialization
  446. //
  447. BOOLEAN fDeviceStarted;
  448. //
  449. // Indicates that we have received an OID_GEN_CURRENT_PACKET_FILTER
  450. // indication from the protocol. We can deliver received packets to the
  451. // protocol.
  452. //
  453. BOOLEAN fGotFilterIndication;
  454. //
  455. // NDIS calls most of the MiniportXxx function with IRQL DISPATCH_LEVEL.
  456. // There are a number of instances where the ir device must send
  457. // requests to the device which may be synchronous and
  458. // we can't block in DISPATCH_LEVEL. Therefore, we set up a thread to deal
  459. // with request which require PASSIVE_LEVEL. An event is used to signal
  460. // the thread that work is required.
  461. //
  462. HANDLE hPassiveThread;
  463. BOOLEAN fKillPassiveLevelThread;
  464. KEVENT EventPassiveThread;
  465. /*
  466. According to W2000 ddk doc:
  467. The IrDA protocol driver sets this OID to zero to request the miniport to
  468. start monitoring for a media busy condition. The IrDA protocol
  469. can then query this OID to determine whether the media is busy.
  470. If the media is not busy, the miniport returns a zero for this
  471. OID when queried. If the media is busy,that is, if the miniport
  472. has detected some traffic since the IrDA protocol driver last
  473. set OID_IRDA_MEDIA_BUSY to zero the miniport returns a non-zero
  474. value for this OID when queried. On detecting the media busy
  475. condition. the miniport must also call NdisMIndicateStatus to
  476. indicate NDIS_STATUS_MEDIA_BUSY. When the media is busy,
  477. the IrDA protocol driver will not send packets to the miniport
  478. for transmission. After the miniport has detected a busy state,
  479. it does not have to monitor for a media busy condition until
  480. the IrDA protocol driver again sets OID_IRDA_MEDIA_BUSY to zero.
  481. According to USB IrDA Bridge Device Definition Doc sec 5.4.1.2:
  482. The bmStatus field indicators shall be set by the Device as follows:
  483. Media_Busy
  484. Media_Busy shall indicate zero (0) if the Device:
  485. . has not received a Check Media Busy class-specific request
  486. . has detected no traffic on the infrared media since receiving a Check Media Busy
  487. . class-specific request
  488. . Has returned a header with Media_Busy set to one (1) since receiving a Check
  489. Media Busy class-specific request.
  490. Media_Busy shall indicate one (1) if the Device has detected traffic on the infrared
  491. media since receiving a Check Media Busy class-specific request. Note that
  492. Media_Busy shall indicate one (1) in exactly one header following receipt of each
  493. Check Media Busy class-specific request.
  494. According to USB IrDA Bridge Device Definition Doc sec 6.2.2:
  495. Check Media Busy
  496. This class-specific request instructs the Device to look for a media busy condition. If infrared
  497. traffic of any kind is detected by this Device, the Device shall set the Media_Busy field in the
  498. bmStatus field in the next Data-In packet header sent to the host. In the case where a Check
  499. Media Busy command has been received, a media busy condition detected, and no IrLAP frame
  500. traffic is ready to transmit to the host, the Device shall set the Media_Busy field and send it in a
  501. Data-In packet with no IrLAP frame following the header.
  502. bmRequestType bRequest wValue wIndex wLength Data
  503. 00100001B 3 Zero Interface Zero [None]
  504. */
  505. ULONG fMediaBusy; // declare as ULONGS for use with InterlockedExchange
  506. ULONG fIndicatedMediaBusy;
  507. //
  508. // The variable fProcessing is used to indicate that the ir device
  509. // object has an active polling thread,
  510. //
  511. // Under normal circumstances fReceiving should always be TRUE.
  512. // However sometimes the processing has to be stopped
  513. // and this variable is used to synchronize
  514. //
  515. ULONG fProcessing;
  516. //
  517. // To be set to true when really receiving packets
  518. //
  519. ULONG fCurrentlyReceiving;
  520. //
  521. // The variables fPendingHalt and fPendingReset allow the send and receive
  522. // completion routines to complete the current pending irp and
  523. // then cleanup and stop sending irps to the USB driver.
  524. //
  525. BOOLEAN fPendingHalt;
  526. BOOLEAN fPendingReset;
  527. ULONG fPendingReadClearStall;
  528. ULONG fPendingWriteClearStall;
  529. //
  530. // This is required when the part gets into a complete USB hang and a reset is required
  531. //
  532. ULONG fPendingClearTotalStall;
  533. //
  534. // We keep an array of receive buffers so that we don't continually
  535. // need to allocate buffers to indicate packets to the protocol.
  536. // Since the protocol can retain ownership of up to eight packets
  537. // and we can be receiving up to WindowSize ( 7 ) packets while the protocol has
  538. // ownership of eight packets, we will allocate 16 packets for
  539. // receiving.
  540. //
  541. #define NUM_RCV_BUFS 16
  542. RCV_BUFFER rcvBufs[NUM_RCV_BUFS];
  543. PRCV_BUFFER pCurrentRecBuf;
  544. FIFO_BUFFER PreReadBuffer;
  545. //
  546. // Can have max of NUM_RCV_BUFS packets pending + one set and one query
  547. //
  548. #define NUM_WORK_ITEMS (NUM_RCV_BUFS+3)
  549. IR_WORK_ITEM WorkItems[NUM_WORK_ITEMS];
  550. //
  551. // Since we can have multiple write irps pending with the USB driver,
  552. // we track the irp contexts for each one so we have all the info we need at each
  553. // invokation of the USB write completion routine. See the IRUSB_CONTEXT definition below
  554. // There are 128 contexts for sending, one for read/write operations, one for setting the speed
  555. // and one for diagnostic operations
  556. //
  557. #define NUM_SEND_CONTEXTS 131
  558. PVOID pSendContexts;
  559. //
  560. // Handles to the NDIS packet pool and NDIS buffer pool
  561. // for allocating the receive buffers.
  562. //
  563. HANDLE hPacketPool;
  564. HANDLE hBufferPool;
  565. BOOLEAN BufferPoolAllocated;
  566. KEVENT EventSyncUrb;
  567. KEVENT EventAsyncUrb;
  568. NTSTATUS StatusControl;
  569. NTSTATUS StatusReadWrite;
  570. NTSTATUS StatusSendReceive;
  571. //
  572. // track pending IRPS; this should be zero at halt time
  573. //
  574. UINT PendingIrpCount;
  575. ULONG NumReads;
  576. ULONG NumWrites;
  577. ULONG NumReadWrites;
  578. //
  579. // various USB errors
  580. //
  581. ULONG NumDataErrors;
  582. ULONG NumReadWriteErrors;
  583. HANDLE BulkInPipeHandle;
  584. HANDLE BulkOutPipeHandle;
  585. HANDLE hPollingThread;
  586. BOOLEAN fKillPollingThread;
  587. //
  588. // The IR USB dongle's USB Class-Specific Descriptor as per
  589. // "Universal Serial Bus IrDA Bridge Device Definition" doc, section 7.2
  590. // This is the struct returned by USBD as the result of a request with an urb
  591. // of type _URB_CONTROL_VENDOR_OR_CLASS_REQUEST, function URB_FUNCTION_CLASS_DEVICE.
  592. // Note this struct is in-line, not a pointer
  593. //
  594. IRUSB_CLASS_SPECIFIC_DESCRIPTOR ClassDesc;
  595. UINT IdVendor; // USB vendor Id read from dongle
  596. //
  597. // We don't define it here because we need to isolate USB stuff so we
  598. // can build things referencing NDIS with the BINARY_COMPATIBLE flag for win9x
  599. //
  600. PUCHAR pUsbInfo;
  601. //
  602. // Optional registry entry for debugging; limit baud rate.
  603. // The mask is set up as per the USB Class-Specific descriptor 'wBaudRate'
  604. // This is 'and'ed with value from Class descriptor to possibly limit baud rate;
  605. // It defaults to 0xffff
  606. //
  607. UINT BaudRateMask;
  608. //
  609. // Necessary to read the registry fields
  610. //
  611. NDIS_HANDLE WrapperConfigurationContext;
  612. //
  613. // IR Tranceiver Model
  614. //
  615. STIR4200_TRANCEIVER StIrTranceiver;
  616. //
  617. // Send buffers (works only if sending is serialied)
  618. //
  619. PUCHAR pBuffer;
  620. UINT BufLen;
  621. PUCHAR pStagingBuffer;
  622. //
  623. // Send FIFO count
  624. //
  625. ULONG SendFifoCount;
  626. //
  627. // Receive adaptive delay
  628. //
  629. ULONG ReceiveAdaptiveDelay;
  630. ULONG ReceiveAdaptiveDelayBoost;
  631. // MS Security issue - removed pUrb
  632. //
  633. // Receive buffer and positions
  634. //
  635. UCHAR pRawBuf[STIR4200_FIFO_SIZE];
  636. ULONG rawCleanupBytesRead;
  637. PORT_RCV_STATE rcvState;
  638. ULONG readBufPos;
  639. BOOLEAN fReadHoldingReg;
  640. ULONG PreFifoCount;
  641. //
  642. // Send lists and lock
  643. //
  644. LIST_ENTRY SendAvailableQueue;
  645. LIST_ENTRY SendBuiltQueue;
  646. LIST_ENTRY SendPendingQueue;
  647. ULONG SendAvailableCount;
  648. ULONG SendBuiltCount;
  649. ULONG SendPendingCount;
  650. KSPIN_LOCK SendLock;
  651. //
  652. // Read and write register list, shares the other send queues
  653. //
  654. LIST_ENTRY ReadWritePendingQueue;
  655. ULONG ReadWritePendingCount;
  656. //
  657. // Diagnostics
  658. //
  659. #if defined(DIAGS)
  660. ULONG DiagsActive;
  661. ULONG DiagsPendingActivation;
  662. PVOID pIOCTL;
  663. NTSTATUS IOCTLStatus;
  664. KEVENT EventDiags;
  665. LIST_ENTRY DiagsReceiveQueue;
  666. KSPIN_LOCK DiagsReceiveLock;
  667. #endif
  668. NDIS_HANDLE NdisDeviceHandle;
  669. //
  670. // Logging
  671. //
  672. #if defined(RECEIVE_LOGGING)
  673. HANDLE ReceiveFileHandle;
  674. __int64 ReceiveFilePosition;
  675. #endif
  676. #if defined(RECEIVE_ERROR_LOGGING)
  677. HANDLE ReceiveErrorFileHandle;
  678. __int64 ReceiveErrorFilePosition;
  679. #endif
  680. #if defined(SEND_LOGGING)
  681. HANDLE SendFileHandle;
  682. __int64 SendFilePosition;
  683. #endif
  684. #if !defined(WORKAROUND_BROKEN_MIR)
  685. //
  686. // Mir in software
  687. //
  688. UCHAR pRawUnstuffedBuf[STIR4200_FIFO_SIZE];
  689. UCHAR MirIncompleteByte;
  690. ULONG MirIncompleteBitCount;
  691. ULONG MirOneBitCount;
  692. ULONG MirFlagCount;
  693. #endif
  694. //
  695. // Dummy send fix
  696. //
  697. BOOLEAN GearedDown;
  698. //
  699. // Fix for FIR permanent invalid state
  700. //
  701. BOOLEAN StuckFir;
  702. //
  703. // Customer data area.
  704. //
  705. UCHAR pCustomerData[STIR4200_CUST_DATA_SIZE];
  706. BOOLEAN CustomerDataRead;
  707. //
  708. // Used in Diagnostic version.
  709. //
  710. #if defined(VARIABLE_SETTINGS)
  711. ULONG SirDpll;
  712. ULONG FirDpll;
  713. ULONG SirSensitivity;
  714. ULONG FirSensitivity;
  715. #endif
  716. } IR_DEVICE, *PIR_DEVICE;
  717. //
  718. // We use a pointer to the IR_DEVICE structure as the miniport's device context.
  719. //
  720. #define CONTEXT_TO_DEV(__deviceContext) ((PIR_DEVICE)(__deviceContext))
  721. #define DEV_TO_CONTEXT(__irdev) ((HANDLE)(__irdev))
  722. #define IRUSB_TAG 'RITS'
  723. VOID
  724. MyNdisMSetInformationComplete(
  725. IN PIR_DEVICE pThisDev,
  726. IN NDIS_STATUS Status
  727. );
  728. VOID
  729. MyNdisMQueryInformationComplete(
  730. IN PIR_DEVICE pThisDev,
  731. IN NDIS_STATUS Status
  732. );
  733. USHORT
  734. ComputeFCS16(
  735. IN PUCHAR pData,
  736. UINT DataLen
  737. );
  738. ULONG
  739. ComputeFCS32(
  740. IN PUCHAR pData,
  741. ULONG DataLen
  742. );
  743. BOOLEAN
  744. NdisToFirPacket(
  745. IN PIR_DEVICE pIrDev,
  746. IN PNDIS_PACKET pPacket,
  747. OUT PUCHAR pIrPacketBuf,
  748. ULONG IrPacketBufLen,
  749. IN PUCHAR pContigPacketBuf,
  750. OUT PULONG pIrPacketLen
  751. );
  752. BOOLEAN
  753. NdisToMirPacket(
  754. IN PIR_DEVICE pIrDev,
  755. IN PNDIS_PACKET pPacket,
  756. OUT PUCHAR pIrPacketBuf,
  757. ULONG IrPacketBufLen,
  758. IN PUCHAR pContigPacketBuf,
  759. OUT PULONG pIrPacketLen
  760. );
  761. BOOLEAN
  762. NdisToSirPacket(
  763. IN PIR_DEVICE pIrDev,
  764. IN PNDIS_PACKET pPacket,
  765. OUT PUCHAR pIrPacketBuf,
  766. ULONG IrPacketBufLen,
  767. IN PUCHAR pContigPacketBuf,
  768. OUT PULONG pIrPacketLen
  769. );
  770. BOOLEAN
  771. ReceiveFirStepFSM(
  772. IN OUT PIR_DEVICE pIrDev,
  773. OUT PULONG pBytesProcessed
  774. );
  775. BOOLEAN
  776. ReceiveMirStepFSM(
  777. IN OUT PIR_DEVICE pIrDev,
  778. OUT PULONG pBytesProcessed
  779. );
  780. #if !defined(WORKAROUND_BROKEN_MIR)
  781. BOOLEAN
  782. ReceiveMirUnstuff(
  783. IN OUT PIR_DEVICE pIrDev,
  784. IN PUCHAR pInputBuffer,
  785. ULONG InputBufferSize,
  786. OUT PUCHAR pOutputBuffer,
  787. OUT PULONG pOutputBufferSize
  788. );
  789. #endif
  790. BOOLEAN
  791. ReceiveSirStepFSM(
  792. IN OUT PIR_DEVICE pIrDev,
  793. OUT PULONG pBytesProcessed
  794. );
  795. VOID
  796. ReceiveProcessFifoData(
  797. IN OUT PIR_DEVICE pThisDev
  798. );
  799. VOID
  800. ReceiveResetPointers(
  801. IN OUT PIR_DEVICE pThisDev
  802. );
  803. NTSTATUS
  804. ReceivePreprocessFifo(
  805. IN OUT PIR_DEVICE pThisDev,
  806. OUT PULONG pFifoCount
  807. );
  808. NTSTATUS
  809. ReceiveGetFifoData(
  810. IN OUT PIR_DEVICE pThisDev,
  811. OUT PUCHAR pData,
  812. OUT PULONG pBytesRead,
  813. ULONG BytesToRead
  814. );
  815. VOID
  816. ReceiveProcessReturnPacket(
  817. OUT PIR_DEVICE pThisDev,
  818. OUT PRCV_BUFFER pReceiveBuffer
  819. );
  820. NTSTATUS
  821. ReceivePacketRead(
  822. IN PIR_DEVICE pThisDev,
  823. OUT PFIFO_BUFFER pRecBuf
  824. );
  825. NTSTATUS
  826. ReceiveCompletePacketRead(
  827. IN PDEVICE_OBJECT pUsbDevObj,
  828. IN PIRP pIrp,
  829. IN PVOID Context
  830. );
  831. VOID
  832. IndicateMediaBusy(
  833. IN PIR_DEVICE pThisDev
  834. );
  835. VOID
  836. IrUsb_IncIoCount(
  837. IN OUT PIR_DEVICE pThisDev
  838. );
  839. VOID
  840. IrUsb_DecIoCount(
  841. IN OUT PIR_DEVICE pThisDev
  842. );
  843. NTSTATUS
  844. IrUsb_GetDongleCaps(
  845. IN OUT PIR_DEVICE pThisDev
  846. );
  847. VOID
  848. IrUsb_SetDongleCaps(
  849. IN OUT PIR_DEVICE pThisDev
  850. );
  851. VOID
  852. MyMemFree(
  853. IN PVOID pMem,
  854. IN UINT size
  855. );
  856. PVOID
  857. MyMemAlloc(
  858. UINT size
  859. );
  860. VOID
  861. MyUrbFree(
  862. IN PURB pUrb,
  863. IN UINT size
  864. );
  865. PURB
  866. MyUrbAlloc(
  867. UINT size
  868. );
  869. BOOLEAN
  870. AllocUsbInfo(
  871. IN OUT PIR_DEVICE pThisDev
  872. );
  873. VOID
  874. FreeUsbInfo(
  875. IN OUT PIR_DEVICE pThisDev
  876. );
  877. VOID
  878. PollingThread(
  879. IN OUT PVOID Context
  880. );
  881. extern BAUDRATE_INFO supportedBaudRateTable[NUM_BAUDRATES];
  882. VOID
  883. ReceiveDeliverBuffer(
  884. IN OUT PIR_DEVICE pThisDev,
  885. IN PRCV_BUFFER pRecBuf
  886. );
  887. NTSTATUS
  888. InitializeProcessing(
  889. IN OUT PIR_DEVICE pThisDev,
  890. IN BOOLEAN InitPassiveThread
  891. );
  892. NTSTATUS
  893. IrUsb_ResetPipe (
  894. IN PIR_DEVICE pThisDev,
  895. IN HANDLE Pipe
  896. );
  897. BOOLEAN
  898. IrUsb_InitSendStructures(
  899. IN OUT PIR_DEVICE pThisDev
  900. );
  901. VOID
  902. IrUsb_FreeSendStructures(
  903. IN OUT PIR_DEVICE pThisDev
  904. );
  905. NDIS_STATUS
  906. SendPacketPreprocess(
  907. IN OUT PIR_DEVICE pThisDev,
  908. IN PVOID pPacketToSend
  909. );
  910. NDIS_STATUS
  911. SendPreprocessedPacketSend(
  912. IN OUT PIR_DEVICE pThisDev,
  913. IN PVOID pContext
  914. );
  915. NTSTATUS
  916. SendWaitCompletion(
  917. IN OUT PIR_DEVICE pThisDev
  918. );
  919. NTSTATUS
  920. SendCheckForOverflow(
  921. IN OUT PIR_DEVICE pThisDev
  922. );
  923. NTSTATUS
  924. SendCompletePacketSend(
  925. IN PDEVICE_OBJECT pUsbDevObj,
  926. IN PIRP pIrp,
  927. IN PVOID Context
  928. );
  929. PRCV_BUFFER
  930. ReceiveGetBuf(
  931. PIR_DEVICE pThisDev,
  932. OUT PUINT pIndex,
  933. IN RCV_BUFFER_STATE BufferState
  934. );
  935. VOID
  936. PassiveLevelThread(
  937. IN PVOID Context
  938. );
  939. BOOLEAN
  940. ScheduleWorkItem(
  941. IN OUT PIR_DEVICE pThisDev,
  942. WORK_PROC Callback,
  943. IN PVOID pInfoBuf,
  944. ULONG InfoBufLen
  945. );
  946. VOID
  947. FreeWorkItem(
  948. IN OUT PIR_WORK_ITEM pItem
  949. );
  950. VOID
  951. IrUsb_PrepareSetSpeed(
  952. IN OUT PIR_DEVICE pThisDev
  953. );
  954. NTSTATUS
  955. ResetPipeCallback (
  956. IN PIR_WORK_ITEM pWorkItem
  957. );
  958. PVOID
  959. AllocXferUrb (
  960. VOID
  961. );
  962. VOID
  963. FreeXferUrb(
  964. IN OUT PVOID pUrb
  965. );
  966. #endif // _IRCOM_H