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.

1125 lines
28 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. usbdiag.h
  5. Environment:
  6. Kernel & user mode
  7. Revision History:
  8. 5-10-96 : created
  9. --*/
  10. #ifndef __USBDIAG_H__
  11. #define __USBDIAG_H__
  12. #define IRP_TYPE_READ_PIPE 0
  13. #define IPR_TYPE_OTHER 1
  14. #define FDO_FROM_DEVICE_HANDLE(dev) (((PDEVICE_LIST_ENTRY)(dev))->DeviceObject)
  15. #define USBDIAG_NAME_MAX 64
  16. #define NAME_MAX 256
  17. #define MAX_INTERFACE 8
  18. #define USBDIAG_MAX_PIPES 256
  19. #define MAX_DOWNSTREAM_DEVICES 10
  20. #define USBD_WIN98_GOLD_VERSION 0x0101
  21. #define USBD_WIN98_SE_VERSION 0x0200
  22. #define USBD_WIN2K_VERSION 0x0200
  23. typedef struct _IRPNODE {
  24. LIST_ENTRY entry;
  25. PIRP Irp;
  26. struct _IRPNODE * next;
  27. } IRPNODE, * PIRPNODE;
  28. typedef struct _COMPLETION_CONTEXT {
  29. PDEVICE_OBJECT DeviceObject;
  30. PIRP Irp;
  31. PIO_COMPLETION_ROUTINE CompletionRoutine;
  32. PVOID Context;
  33. KEVENT DoneEvent;
  34. } COMPLETION_CONTEXT, *PCOMPLETION_CONTEXT;
  35. typedef struct _DEVICE_LIST_ENTRY {
  36. PDEVICE_OBJECT PhysicalDeviceObject;
  37. PDEVICE_OBJECT DeviceObject;
  38. struct _DEVICE_LIST_ENTRY *Next;
  39. ULONG DeviceNumber;
  40. } DEVICE_LIST_ENTRY, *PDEVICE_LIST_ENTRY;
  41. typedef struct _USBDIAG_WORKITEM {
  42. WORK_QUEUE_ITEM WorkItem;
  43. PDEVICE_OBJECT DeviceObject;
  44. } USBDIAG_WORKITEM, *PUSBDIAG_WORKITEM;
  45. typedef struct _DEVICE_EXTENSION
  46. {
  47. PDEVICE_OBJECT PhysicalDeviceObject; // physical device object
  48. PDEVICE_OBJECT StackDeviceObject; // stack device object
  49. PDEVICE_LIST_ENTRY DeviceList;
  50. ULONG ulInstance; // keeps track of device instance
  51. // Name buffer for our named Functional device object link
  52. WCHAR DeviceLinkNameBuffer[USBDIAG_NAME_MAX];
  53. // descriptors for device instance
  54. PUSB_CONFIGURATION_DESCRIPTOR pUsbConfigDesc;
  55. PUSBD_INTERFACE_INFORMATION Interface[MAX_INTERFACE];
  56. ULONG OpenFRC;
  57. PUSB_DEVICE_DESCRIPTOR pDeviceDescriptor;
  58. KTIMER TimeoutTimer;
  59. KDPC TimeoutDpc;
  60. ULONG DeviceHackFlags;
  61. PIRP PowerIrp;
  62. KEVENT WaitWakeEvent;
  63. // handle to configuration that was selected
  64. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  65. ULONG numPipesInUse; // number of pipes in use
  66. LIST_ENTRY ListHead;
  67. KSPIN_LOCK SpinLock;
  68. KEVENT CancelEvent;
  69. PKEVENT SelfRequestedPowerIrpEvent;
  70. BOOLEAN Stopped; // keeps track of device status
  71. BOOLEAN bTestDevice; // flag for test devices
  72. PDEVICE_OBJECT RootHubPdo;
  73. PDEVICE_OBJECT TopOfHcdStackDeviceObject;
  74. //BOOLEAN WaitWakePending;
  75. PIRP WaitWakeIrp;
  76. DEVICE_CAPABILITIES DeviceCapabilities;
  77. POWER_STATE CurrentSystemState;
  78. POWER_STATE CurrentDeviceState;
  79. // remember the irp corresponding to the interrupt pipe
  80. PIRP InterruptIrp;
  81. PUSBD_DEVICE_DATA DeviceData[MAX_DOWNSTREAM_DEVICES+1]; // pointers to downstream devices
  82. PUSB_CONFIGURATION_DESCRIPTOR DownstreamConfigDescriptor[MAX_DOWNSTREAM_DEVICES+1];
  83. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  84. #if DBG
  85. #define USBDIAG_KdPrint(_x_) DbgPrint _x_ ;
  86. #define TRAP() DbgBreakPoint()
  87. #else
  88. #define USBDIAG_KdPrint(_x_)
  89. #define TRAP()
  90. #endif
  91. PVOID
  92. USBDIAG_ExAllocatePool(
  93. IN POOL_TYPE PoolType,
  94. IN ULONG NumberOfBytes
  95. );
  96. VOID
  97. USBDIAG_ExFreePool(
  98. IN PVOID P
  99. );
  100. NTSTATUS
  101. USBDIAG_Dispatch(
  102. IN PDEVICE_OBJECT DeviceObject,
  103. IN PIRP Irp
  104. );
  105. NTSTATUS
  106. USBDIAG_PnP(
  107. IN PDEVICE_OBJECT DeviceObject,
  108. IN PIRP Irp
  109. );
  110. NTSTATUS
  111. USBDIAG_Power(
  112. IN PDEVICE_OBJECT DeviceObject,
  113. IN PIRP Irp
  114. );
  115. VOID
  116. USBDIAG_Unload(
  117. IN PDRIVER_OBJECT DriverObject
  118. );
  119. NTSTATUS
  120. USBDIAG_StartDevice(
  121. IN PDEVICE_OBJECT DeviceObject
  122. );
  123. NTSTATUS
  124. USBDIAG_StopDevice(
  125. IN PDEVICE_OBJECT DeviceObject
  126. );
  127. NTSTATUS
  128. USBDIAG_CallUSBD(
  129. IN PDEVICE_OBJECT DeviceObject,
  130. IN PURB Urb
  131. );
  132. NTSTATUS
  133. USBDIAG_PnPAddDevice(
  134. IN PDRIVER_OBJECT DriverObject,
  135. IN OUT PDEVICE_OBJECT PhysicalDeviceObject
  136. );
  137. NTSTATUS
  138. USBDIAG_CreateDeviceObject(
  139. IN PDRIVER_OBJECT DriverObject,
  140. IN PDEVICE_OBJECT *DeviceObject,
  141. BOOLEAN Global
  142. );
  143. NTSTATUS
  144. USBDIAG_ProcessIOCTL(
  145. IN PDEVICE_OBJECT DeviceObject,
  146. IN PIRP Irp
  147. );
  148. NTSTATUS
  149. USBDIAG_Configure_Device (
  150. IN PDEVICE_OBJECT DeviceObject,
  151. IN PIRP Irp);
  152. NTSTATUS
  153. USBDIAG_SelectInterfaces(
  154. IN PDEVICE_OBJECT DeviceObject,
  155. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  156. IN PUSBD_INTERFACE_INFORMATION Interface,
  157. IN OUT struct _REQ_SET_DEVICE_CONFIG * REQSetDeviceConfig
  158. );
  159. NTSTATUS
  160. USBDIAG_Chap9Control(
  161. IN PDEVICE_OBJECT DeviceObject,
  162. IN PIRP Irp
  163. );
  164. NTSTATUS
  165. USBDIAG_HIDP_GetCollection(
  166. IN PDEVICE_OBJECT DeviceObject,
  167. IN PIRP Irp
  168. );
  169. NTSTATUS
  170. USBDIAG_RemoveGlobalDeviceObject(
  171. );
  172. NTSTATUS
  173. USBDIAG_Ch9CallUSBD(
  174. IN PDEVICE_OBJECT DeviceObject,
  175. IN PURB Urb,
  176. IN BOOLEAN fBlock,
  177. PIO_COMPLETION_ROUTINE CompletionRoutine,
  178. PVOID pvContext,
  179. BOOLEAN fWantTimeOut
  180. );
  181. NTSTATUS
  182. USBDIAG_SendPacket(
  183. IN PDEVICE_OBJECT DeviceObject,
  184. IN CHAR SetUpPacket[],
  185. PVOID TxBuffer,
  186. ULONG * TxBufferLen,
  187. ULONG * pulUrbStatus
  188. );
  189. VOID
  190. USBDIAG_SyncTimeoutDPC(
  191. IN PKDPC Dpc,
  192. IN PVOID DeferredContext,
  193. IN PVOID SystemArgument1,
  194. IN PVOID SystemArgument2
  195. );
  196. VOID
  197. USBDIAG_IoCancelRoutine (
  198. PDEVICE_OBJECT DeviceObject,
  199. PIRP Irp
  200. );
  201. NTSTATUS
  202. USBDIAG_IoGenericCompletionRoutine (
  203. PDEVICE_OBJECT DeviceObject,
  204. PIRP Irp,
  205. PVOID context
  206. );
  207. NTSTATUS
  208. USBDIAG_IssueWaitWake(
  209. IN PDEVICE_OBJECT DeviceObject
  210. );
  211. NTSTATUS
  212. USBDIAG_RequestWaitWakeCompletion(
  213. IN PDEVICE_OBJECT DeviceObject,
  214. IN UCHAR MinorFunction,
  215. IN POWER_STATE PowerState,
  216. IN PVOID Context,
  217. IN PIO_STATUS_BLOCK IoStatus
  218. );
  219. NTSTATUS
  220. USBDIAG_PoRequestCompletion(
  221. IN PDEVICE_OBJECT DeviceObject,
  222. IN UCHAR MinorFunction,
  223. IN POWER_STATE PowerState,
  224. IN PVOID Context,
  225. IN PIO_STATUS_BLOCK IoStatus
  226. );
  227. NTSTATUS
  228. USBDIAG_PowerIrpCompletionRoutine(
  229. IN PDEVICE_OBJECT DeviceObject,
  230. IN PIRP Irp,
  231. IN PVOID Context
  232. );
  233. NTSTATUS
  234. USBDIAG_SetDevicePowerState(
  235. IN PDEVICE_OBJECT DeviceObject,
  236. IN ULONG ulPowerState
  237. );
  238. NTSTATUS
  239. USBDIAG_PoSelfRequestCompletion(
  240. IN PDEVICE_OBJECT DeviceObject,
  241. IN UCHAR MinorFunction,
  242. IN POWER_STATE PowerState,
  243. IN PVOID Context,
  244. IN PIO_STATUS_BLOCK IoStatus
  245. );
  246. NTSTATUS
  247. USBDIAG_SaveIrp(
  248. IN PDEVICE_EXTENSION deviceExtension,
  249. IN PIRP irp
  250. );
  251. NTSTATUS
  252. USBDIAG_ClearSavedIrp(
  253. IN PDEVICE_EXTENSION deviceExtension,
  254. IN PIRP irp
  255. );
  256. NTSTATUS
  257. USBDIAG_ResetParentPort(
  258. IN PDEVICE_OBJECT DeviceObject
  259. );
  260. NTSTATUS
  261. USBDIAG_CancelAllIrps(
  262. PDEVICE_EXTENSION deviceExtension
  263. );
  264. NTSTATUS
  265. USBDIAG_WaitWakeCompletionRoutine (
  266. IN PDEVICE_OBJECT DeviceObject,
  267. IN PIRP Irp,
  268. IN PVOID Context
  269. );
  270. VOID
  271. USBDIAG_WaitWakeCancelRoutine(
  272. IN PDEVICE_OBJECT DeviceObject,
  273. IN PIRP Irp
  274. );
  275. NTSTATUS
  276. USBDIAG_RemoveDownstreamDevice(
  277. IN PUSBD_DEVICE_DATA DeviceData,
  278. IN PDEVICE_OBJECT DeviceObject
  279. );
  280. NTSTATUS
  281. USBDIAG_Chap11SetConfiguration(
  282. IN PUSBD_DEVICE_DATA DeviceData,
  283. IN PDEVICE_OBJECT DeviceObject
  284. );
  285. NTSTATUS
  286. USBDIAG_Chap11EnableRemoteWakeup(
  287. IN PUSBD_DEVICE_DATA DeviceData,
  288. IN PDEVICE_OBJECT DeviceObject
  289. );
  290. NTSTATUS
  291. USBDIAG_Chap11SendPacketDownstream(
  292. IN PUSBD_DEVICE_DATA DeviceData,
  293. IN PDEVICE_OBJECT DeviceObject,
  294. IN PREQ_SEND_PACKET_DOWNSTREAM pSendPacketDownstream
  295. );
  296. // ********************************************
  297. #if DBG
  298. #define DEBUG_LOG
  299. #define DEBUG_HEAP
  300. #endif
  301. #define SIG_DEVICE 0x56454455 //"UDEV" signature for device handle
  302. #if DBG
  303. #define ASSERT_DEVICE(d) ASSERT((d)->Sig == SIG_DEVICE)
  304. ULONG
  305. _cdecl
  306. USBD_KdPrintX(
  307. PCH Format,
  308. ...
  309. );
  310. extern ULONG USBD_Debug_Trace_Level;
  311. #define USBD_KdPrint(l, _x_) if ((l) <= USBD_Debug_Trace_Level) \
  312. {USBD_KdPrintX _x_;\
  313. }
  314. VOID
  315. USBD_Assert(
  316. PVOID FailedAssertion,
  317. PVOID FileName,
  318. ULONG LineNumber,
  319. PCHAR Message
  320. );
  321. #define USBD_ASSERT( exp ) \
  322. if (!(exp)) \
  323. USBD_Assert( #exp, __FILE__, __LINE__, NULL )
  324. #define USBD_ASSERTMSG( msg, exp ) \
  325. if (!(exp)) \
  326. USBD_Assert( #exp, __FILE__, __LINE__, msg )
  327. // TEST_TRAP() is a code coverage trap these should be removed
  328. // if you are able to 'g' past the OK
  329. //
  330. // TRAP() breaks in the debugger on the debugger build
  331. // these indicate bugs in client drivers or fatal error
  332. // conditions that should be debugged. also used to mark
  333. // code for features not implemented yet.
  334. //
  335. // KdBreak() breaks in the debugger when in MAX_DEBUG mode
  336. // ie debug trace info is turned on, these are intended to help
  337. // debug drivers devices and special conditions on the
  338. // bus.
  339. #ifdef NTKERN
  340. // Ntkern currently implements DebugBreak with a global int 3,
  341. // we really would like the int 3 in our own code.
  342. #define DBGBREAK() _asm { int 3 }
  343. #else
  344. #define DBGBREAK() DbgBreakPoint()
  345. #endif /* NTKERN */
  346. #define TEST_TRAP() { DbgPrint( " Code Coverage Trap %s %d\n", __FILE__, __LINE__); \
  347. DBGBREAK(); }
  348. #ifdef MAX_DEBUG
  349. #define USBD_KdBreak(_x_) { DbgPrint("USBD:"); \
  350. DbgPrint _x_ ; \
  351. DBGBREAK(); }
  352. #else
  353. #define USBD_KdBreak(_x_)
  354. #endif
  355. #define USBD_KdTrap(_x_) { DbgPrint( "USBD: "); \
  356. DbgPrint _x_; \
  357. DBGBREAK(); }
  358. #else /* DBG not defined */
  359. #define USBD_KdBreak(_x_)
  360. #define USBD_KdTrap(_x_)
  361. #define TEST_TRAP()
  362. #define ASSERT_DEVICE(d)
  363. #define USBD_ASSERT( exp )
  364. #define USBD_ASSERTMSG( msg, exp )
  365. #endif /* DBG */
  366. #ifndef __HCDI_H__
  367. #define __HCDI_H__
  368. typedef NTSTATUS ROOT_HUB_POWER_FUNCTION(PDEVICE_OBJECT DeviceObject,
  369. PIRP Irp);
  370. typedef NTSTATUS HCD_DEFFERED_START_FUNCTION(PDEVICE_OBJECT DeviceObject,
  371. PIRP Irp);
  372. typedef NTSTATUS HCD_SET_DEVICE_POWER_STATE(PDEVICE_OBJECT DeviceObject,
  373. PIRP Irp,
  374. DEVICE_POWER_STATE DeviceState);
  375. typedef struct _USBD_EXTENSION {
  376. // ptr to true device extension or NULL if this
  377. // is the true extension
  378. PVOID TrueDeviceExtension;
  379. // size of this structure
  380. ULONG Length;
  381. ROOT_HUB_POWER_FUNCTION *RootHubPower;
  382. HCD_DEFFERED_START_FUNCTION *HcdDeferredStartDevice;
  383. HCD_SET_DEVICE_POWER_STATE *HcdSetDevicePowerState;
  384. DEVICE_POWER_STATE HcCurrentDevicePowerState;
  385. KEVENT PnpStartEvent;
  386. //
  387. // Owner of frame length control for this HC
  388. //
  389. PVOID FrameLengthControlOwner;
  390. //
  391. // HCD device object we are connected to.
  392. //
  393. PDEVICE_OBJECT HcdDeviceObject;
  394. // wake irp passed to us by the hub driver
  395. // for the root hub
  396. PIRP PendingWakeIrp;
  397. // wakeup irp we send down the HC stack
  398. PIRP HcWakeIrp;
  399. //
  400. // device object for top of the HCD stack
  401. // this = HcdDeviceObject when no filters
  402. // are present.
  403. //
  404. PDEVICE_OBJECT HcdTopOfStackDeviceObject;
  405. PDEVICE_OBJECT HcdTopOfPdoStackDeviceObject;
  406. //
  407. // copy of the host controller device
  408. // capabilities
  409. //
  410. DEVICE_CAPABILITIES HcDeviceCapabilities;
  411. DEVICE_CAPABILITIES RootHubDeviceCapabilities;
  412. PIRP PowerIrp;
  413. //
  414. // Used to serialize open/close endpoint and
  415. // device configuration
  416. //
  417. KSEMAPHORE UsbDeviceMutex;
  418. //
  419. // Bitmap of assigned USB addresses
  420. //
  421. ULONG AddressList[4];
  422. //
  423. // Remember the Root Hub PDO we created.
  424. //
  425. PDEVICE_OBJECT RootHubPDO;
  426. PDRIVER_OBJECT DriverObject;
  427. //
  428. // symbolic link created for HCD stack
  429. //
  430. UNICODE_STRING DeviceLinkUnicodeString;
  431. BOOLEAN DiagnosticMode;
  432. BOOLEAN DiagIgnoreHubs;
  433. BOOLEAN Reserved; // used to be supportNonComp
  434. UCHAR HcWakeFlags;
  435. ULONG DeviceHackFlags;
  436. //
  437. // Store away the PDO
  438. //
  439. PDEVICE_OBJECT HcdPhysicalDeviceObject;
  440. PVOID RootHubDeviceData;
  441. DEVICE_POWER_STATE RootHubDeviceState;
  442. // current USB defined power state of the bus
  443. // during last suspend.
  444. DEVICE_POWER_STATE SuspendPowerState;
  445. UNICODE_STRING RootHubSymbolicLinkName;
  446. } USBD_EXTENSION, *PUSBD_EXTENSION;
  447. #define HC_ENABLED_FOR_WAKEUP 0x01
  448. #define HC_WAKE_PENDING 0x02
  449. // device hack flags, these flags alter the stacks default behavior
  450. // in order to support certain broken "legacy" devices
  451. #define USBD_DEVHACK_SLOW_ENUMERATION 0x00000001
  452. #define USBD_DEVHACK_DISABLE_SN 0x00000002
  453. //
  454. // This macro returns the true device object for the HCD give
  455. // either the true device_object or a PDO owned by the HCD/BUS
  456. // driver.
  457. //
  458. //
  459. // HCD specific URB commands
  460. //
  461. #define URB_FUNCTION_HCD_OPEN_ENDPOINT 0x1000
  462. #define URB_FUNCTION_HCD_CLOSE_ENDPOINT 0x1001
  463. #define URB_FUNCTION_HCD_GET_ENDPOINT_STATE 0x1002
  464. #define URB_FUNCTION_HCD_SET_ENDPOINT_STATE 0x1003
  465. #define URB_FUNCTION_HCD_ABORT_ENDPOINT 0x1004
  466. // this bit is set for all functions that must be handled by HCD
  467. #define HCD_URB_FUNCTION 0x1000
  468. // this bit is set in the function code by USBD to indicate that
  469. // this is an internal call originating from USBD
  470. #define HCD_NO_USBD_CALL 0x2000
  471. //
  472. // values for HcdEndpointState
  473. //
  474. //
  475. // set if the current state of the endpoint in the HCD is 'stalled'
  476. //
  477. #define HCD_ENDPOINT_HALTED_BIT 0
  478. #define HCD_ENDPOINT_HALTED (1<<HCD_ENDPOINT_HALTED_BIT)
  479. //
  480. // set if the HCD has any transfers queued for the endpoint
  481. //
  482. #define HCD_ENDPOINT_TRANSFERS_QUEUED_BIT 1
  483. #define HCD_ENDPOINT_TRANSFERS_QUEUED (1<<HCD_ENDPOINT_TRANSFERS_QUEUED_BIT)
  484. //
  485. // set if the HCD should reset the data toggle on the host side
  486. //
  487. #define HCD_ENDPOINT_RESET_DATA_TOGGLE_BIT 2
  488. #define HCD_ENDPOINT_RESET_DATA_TOGGLE (1<<HCD_ENDPOINT_RESET_DATA_TOGGLE_BIT )
  489. //
  490. // HCD specific URBs
  491. //
  492. struct _URB_HCD_OPEN_ENDPOINT {
  493. struct _URB_HEADER;
  494. USHORT DeviceAddress;
  495. BOOLEAN LowSpeed;
  496. BOOLEAN NeverHalt;
  497. PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
  498. ULONG MaxTransferSize;
  499. PVOID HcdEndpoint;
  500. };
  501. struct _URB_HCD_CLOSE_ENDPOINT {
  502. struct _URB_HEADER;
  503. PVOID HcdEndpoint;
  504. };
  505. struct _URB_HCD_ENDPOINT_STATE {
  506. struct _URB_HEADER;
  507. PVOID HcdEndpoint;
  508. ULONG HcdEndpointState;
  509. };
  510. struct _URB_HCD_ABORT_ENDPOINT {
  511. struct _URB_HEADER;
  512. PVOID HcdEndpoint;
  513. };
  514. //
  515. // Common transfer request definition, all transfer
  516. // requests passed to the HCD will be mapped to this
  517. // format. The HCD will can use this structure to
  518. // reference fields that are common to all transfers
  519. // as well as fields specific to isochronous and
  520. // control transfers.
  521. //
  522. typedef struct _COMMON_TRANSFER_EXTENSION {
  523. union {
  524. struct {
  525. ULONG StartFrame;
  526. ULONG NumberOfPackets;
  527. ULONG ErrorCount;
  528. USBD_ISO_PACKET_DESCRIPTOR IsoPacket[0];
  529. } Isoch;
  530. UCHAR SetupPacket[8];
  531. } u;
  532. } COMMON_TRANSFER_EXTENSION, *PCOMMON_TRANSFER_EXTENSION;
  533. struct _URB_HCD_COMMON_TRANSFER {
  534. struct _URB_HEADER;
  535. PVOID UsbdPipeHandle;
  536. ULONG TransferFlags;
  537. ULONG TransferBufferLength;
  538. PVOID TransferBuffer;
  539. PMDL TransferBufferMDL;
  540. struct _HCD_URB *UrbLink; // link to next urb request
  541. // if this is a chain of requests
  542. struct _URB_HCD_AREA hca; // fields for HCD use
  543. COMMON_TRANSFER_EXTENSION Extension;
  544. /*
  545. //BUGBUG add fields for isoch and
  546. //control transfers
  547. UCHAR SetupPacket[8];
  548. ULONG StartFrame;
  549. // number of packets that make up this request
  550. ULONG NumberOfPackets;
  551. // number of packets that completed with errors
  552. ULONG ErrorCount;
  553. USBD_ISO_PACKET_DESCRIPTOR IsoPacket[0];
  554. */
  555. };
  556. typedef struct _HCD_URB {
  557. union {
  558. struct _URB_HEADER UrbHeader;
  559. struct _URB_HCD_OPEN_ENDPOINT HcdUrbOpenEndpoint;
  560. struct _URB_HCD_CLOSE_ENDPOINT HcdUrbCloseEndpoint;
  561. struct _URB_GET_FRAME_LENGTH UrbGetFrameLength;
  562. struct _URB_SET_FRAME_LENGTH UrbSetFrameLength;
  563. struct _URB_GET_CURRENT_FRAME_NUMBER UrbGetCurrentFrameNumber;
  564. struct _URB_HCD_ENDPOINT_STATE HcdUrbEndpointState;
  565. struct _URB_HCD_ABORT_ENDPOINT HcdUrbAbortEndpoint;
  566. //formats for USB transfer requests.
  567. struct _URB_HCD_COMMON_TRANSFER HcdUrbCommonTransfer;
  568. //formats for specific transfer types
  569. //that have fields not contained in
  570. //CommonTransfer.
  571. //BUGBUG this will be merged with commontransfer
  572. struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer;
  573. };
  574. } HCD_URB, *PHCD_URB;
  575. //
  576. // bandwidth related definitions
  577. //
  578. // overhead in bytes/ms
  579. #define USB_ISO_OVERHEAD_BYTES 9
  580. #define USB_INTERRUPT_OVERHEAD_BYTES 13
  581. #endif /* __HCDI_H__ */
  582. #define USBD_TAG 0x44425355 /* "USBD" */
  583. #if DBG
  584. #define DEBUG_LOG
  585. #endif
  586. //enable pageable code
  587. #ifndef PAGE_CODE
  588. #define PAGE_CODE
  589. #endif
  590. #define _USBD_
  591. //
  592. // Constents used to format USB setup packets
  593. // for the default pipe
  594. //
  595. //
  596. // Values for the bmRequest field
  597. //
  598. #define USB_HOST_TO_DEVICE 0x00
  599. #define USB_DEVICE_TO_HOST 0x80
  600. #define USB_STANDARD_COMMAND 0x00
  601. #define USB_CLASS_COMMAND 0x20
  602. #define USB_VENDOR_COMMAND 0x40
  603. #define USB_COMMAND_TO_DEVICE 0x00
  604. #define USB_COMMAND_TO_INTERFACE 0x01
  605. #define USB_COMMAND_TO_ENDPOINT 0x02
  606. #define USB_COMMAND_TO_OTHER 0x03
  607. //
  608. // USB standard command values
  609. // combines bmRequest and bRequest fields
  610. // in the setup packet for standard control
  611. // transfers
  612. //
  613. #define STANDARD_COMMAND_REQUEST_MASK 0xff00
  614. #define STANDARD_COMMAND_GET_DESCRIPTOR ((USB_DEVICE_TO_HOST | \
  615. USB_COMMAND_TO_DEVICE) | \
  616. (USB_REQUEST_GET_DESCRIPTOR<<8))
  617. #define STANDARD_COMMAND_SET_DESCRIPTOR ((USB_HOST_TO_DEVICE | \
  618. USB_COMMAND_TO_DEVICE) | \
  619. (USB_REQUEST_SET_DESCRIPTOR<<8))
  620. #define STANDARD_COMMAND_GET_STATUS_ENDPOINT ((USB_DEVICE_TO_HOST | \
  621. USB_COMMAND_TO_ENDPOINT) | \
  622. (USB_REQUEST_GET_STATUS<<8))
  623. #define STANDARD_COMMAND_GET_STATUS_INTERFACE ((USB_DEVICE_TO_HOST | \
  624. USB_COMMAND_TO_INTERFACE) | \
  625. (USB_REQUEST_GET_STATUS<<8))
  626. #define STANDARD_COMMAND_GET_STATUS_DEVICE ((USB_DEVICE_TO_HOST | \
  627. USB_COMMAND_TO_DEVICE) | \
  628. (USB_REQUEST_GET_STATUS<<8))
  629. #define STANDARD_COMMAND_SET_CONFIGURATION ((USB_HOST_TO_DEVICE | \
  630. USB_COMMAND_TO_DEVICE) | \
  631. (USB_REQUEST_SET_CONFIGURATION<<8))
  632. #define STANDARD_COMMAND_SET_INTERFACE ((USB_HOST_TO_DEVICE | \
  633. USB_COMMAND_TO_INTERFACE) | \
  634. (USB_REQUEST_SET_INTERFACE<<8))
  635. #define STANDARD_COMMAND_SET_ADDRESS ((USB_HOST_TO_DEVICE | \
  636. USB_COMMAND_TO_DEVICE) | \
  637. (USB_REQUEST_SET_ADDRESS<<8))
  638. #define STANDARD_COMMAND_CLEAR_FEATURE_ENDPOINT ((USB_HOST_TO_DEVICE | \
  639. USB_COMMAND_TO_ENDPOINT) | \
  640. (USB_REQUEST_CLEAR_FEATURE<<8))
  641. // added by kk
  642. #define STANDARD_COMMAND_SET_DEVICE_FEATURE ((USB_HOST_TO_DEVICE | \
  643. USB_COMMAND_TO_DEVICE) | \
  644. (USB_REQUEST_SET_FEATURE<<8))
  645. //
  646. // USB class command macros
  647. //
  648. #define CLASS_COMMAND_GET_DESCRIPTOR ((USB_CLASS_COMMAND | \
  649. USB_DEVICE_TO_HOST | \
  650. USB_COMMAND_TO_DEVICE) | \
  651. (USB_REQUEST_GET_DESCRIPTOR<<8))
  652. #define CLASS_COMMAND_GET_STATUS_OTHER ((USB_CLASS_COMMAND | \
  653. USB_DEVICE_TO_HOST | \
  654. USB_COMMAND_TO_OTHER) | \
  655. (USB_REQUEST_GET_STATUS<<8))
  656. #define CLASS_COMMAND_SET_FEATURE_TO_OTHER ((USB_CLASS_COMMAND | \
  657. USB_HOST_TO_DEVICE | \
  658. USB_COMMAND_TO_OTHER) | \
  659. (USB_REQUEST_SET_FEATURE<<8))
  660. //
  661. // Macros to set transfer direction flag
  662. //
  663. #define USBD_SET_TRANSFER_DIRECTION_IN(tf) ((tf) |= USBD_TRANSFER_DIRECTION_IN)
  664. #define USBD_SET_TRANSFER_DIRECTION_OUT(tf) ((tf) &= ~USBD_TRANSFER_DIRECTION_IN)
  665. //
  666. // Flags for the URB header flags field used
  667. // by USBD
  668. //
  669. #define USBD_REQUEST_IS_TRANSFER 0x00000001
  670. #define USBD_REQUEST_MDL_ALLOCATED 0x00000002
  671. #define USBD_REQUEST_USES_DEFAULT_PIPE 0x00000004
  672. #define USBD_REQUEST_NO_DATA_PHASE 0x00000008
  673. typedef struct _USB_STANDARD_SETUP_PACKET {
  674. USHORT RequestCode;
  675. USHORT wValue;
  676. USHORT wIndex;
  677. USHORT wLength;
  678. } USB_STANDARD_SETUP_PACKET, *PUSB_STANDARD_SETUP_PACKET;
  679. //
  680. // instance information for a device
  681. //
  682. #define PIPE_CLOSED(ph) ((ph)->HcdEndpoint == NULL)
  683. #define GET_DEVICE_EXTENSION(DeviceObject) (((PUSBD_EXTENSION)(DeviceObject->DeviceExtension))->TrueDeviceExtension)
  684. //#define GET_DEVICE_EXTENSION(DeviceObject) ((PUSBD_EXTENSION)(DeviceObject->DeviceExtension))
  685. #define HCD_DEVICE_OBJECT(DeviceObject) (DeviceObject)
  686. #define DEVICE_FROM_DEVICEHANDLEROBJECT(UsbdDeviceHandle) (PUSBD_DEVICE_DATA) (UsbdDeviceHandle)
  687. #define SET_USBD_ERROR(err) ((err) | USBD_STATUS_ERROR)
  688. #define HC_URB(urb) ((PHCD_URB)(urb))
  689. //
  690. // we use a semaphore to serialize access to the configuration functions
  691. // in USBD
  692. //
  693. #define InitializeUsbDeviceMutex(de) KeInitializeSemaphore(&(de)->UsbDeviceMutex, 1, 1);
  694. #define USBD_WaitForUsbDeviceMutex(de) { USBD_KdPrint(3, ("'***WAIT dev mutex %x\n", &(de)->UsbDeviceMutex)); \
  695. KeWaitForSingleObject(&(de)->UsbDeviceMutex, \
  696. Executive,\
  697. KernelMode, \
  698. FALSE, \
  699. NULL); \
  700. }
  701. #define USBD_ReleaseUsbDeviceMutex(de) { USBD_KdPrint(3, ("'***RELEASE dev mutex %x\n", &(de)->UsbDeviceMutex));\
  702. KeReleaseSemaphore(&(de)->UsbDeviceMutex,\
  703. LOW_REALTIME_PRIORITY,\
  704. 1,\
  705. FALSE);\
  706. //
  707. //Function Prototypes
  708. //
  709. #if DBG
  710. VOID
  711. USBD_Warning(
  712. PUSBD_DEVICE_DATA DeviceData,
  713. PUCHAR Message,
  714. BOOLEAN DebugBreak
  715. );
  716. #else
  717. #define USBD_Warning(x, y, z)
  718. #endif
  719. NTSTATUS
  720. USBD_Internal_Device_Control(
  721. IN PDEVICE_OBJECT DeviceObject,
  722. IN PIRP Irp,
  723. IN PUSBD_EXTENSION DeviceExtension,
  724. IN PBOOLEAN IrpIsPending
  725. );
  726. NTSTATUS
  727. USBD_SendCommand(
  728. IN PUSBD_DEVICE_DATA DeviceData,
  729. IN PDEVICE_OBJECT DeviceObject,
  730. IN USHORT RequestCode,
  731. IN USHORT WValue,
  732. IN USHORT WIndex,
  733. IN USHORT WLength,
  734. IN PVOID Buffer,
  735. IN ULONG BufferLength,
  736. OUT PULONG BytesReturned,
  737. OUT USBD_STATUS *UsbStatus
  738. );
  739. #if 0
  740. NTSTATUS
  741. USBDIAG_CreateDevice(
  742. IN OUT PUSBD_DEVICE_DATA *DeviceData,
  743. IN PDEVICE_OBJECT DeviceObject,
  744. IN BOOLEAN DeviceIsLowSpeed,
  745. IN ULONG MaxPacketSize_Endpoint0,
  746. IN OUT PULONG NonCompliantDevice
  747. );
  748. #endif
  749. NTSTATUS
  750. USBD_ProcessURB(
  751. IN PDEVICE_OBJECT DeviceObject,
  752. IN PIRP Irp,
  753. IN PURB Urb,
  754. OUT PBOOLEAN IrpIsPending
  755. );
  756. NTSTATUS
  757. USBD_MapError_UrbToNT(
  758. IN PURB Urb,
  759. IN NTSTATUS NtStatus
  760. );
  761. NTSTATUS
  762. USBD_Irp_Complete(
  763. IN PDEVICE_OBJECT DeviceObject,
  764. IN PIRP Irp,
  765. IN PVOID Context
  766. );
  767. #if 0
  768. USHORT
  769. USBD_AllocateUsbAddress(
  770. IN PDEVICE_OBJECT DeviceObject
  771. );
  772. #endif
  773. NTSTATUS
  774. USBDIAG_CreateInitDownstreamDevice(
  775. PREQ_ENUMERATE_DOWNSTREAM_DEVICE pEnumerate,
  776. PDEVICE_EXTENSION deviceExtension
  777. );
  778. NTSTATUS
  779. USBD_GetDescriptor(
  780. IN PUSBD_DEVICE_DATA Device,
  781. IN PDEVICE_OBJECT DeviceObject,
  782. OUT PUCHAR DescriptorBuffer,
  783. IN USHORT DescriptorBufferLength,
  784. IN USHORT DescriptorTypeAndIndex
  785. );
  786. NTSTATUS
  787. USBD_CloseEndpoint(
  788. IN PUSBD_DEVICE_DATA Device,
  789. IN PDEVICE_OBJECT DeviceObject,
  790. IN PUSBD_PIPE PipeHandle,
  791. OUT USBD_STATUS *UsbStatus
  792. );
  793. NTSTATUS
  794. USBD_SubmitSynchronousURB(
  795. IN PURB Urb,
  796. IN PDEVICE_OBJECT DeviceObject,
  797. IN PUSBD_DEVICE_DATA DeviceData
  798. );
  799. NTSTATUS
  800. USBD_GetEndpointState(
  801. IN PUSBD_DEVICE_DATA DeviceData,
  802. IN PDEVICE_OBJECT DeviceObject,
  803. IN PUSBD_PIPE PipeHandle,
  804. OUT USBD_STATUS *UsbStatus,
  805. OUT PULONG EndpointState
  806. );
  807. NTSTATUS
  808. USBDIAG_SyncGetRootHubPdo(
  809. IN PDEVICE_OBJECT DeviceObject,
  810. IN PDEVICE_OBJECT PhysicalDeviceObject,
  811. IN OUT PDEVICE_OBJECT *RootHubPdo,
  812. IN OUT PDEVICE_OBJECT *TopOfHcdStackDeviceObject
  813. );
  814. NTSTATUS
  815. USBDIAG_PowerIrp_Complete(
  816. IN PDEVICE_OBJECT NullDeviceObject,
  817. IN PIRP Irp,
  818. IN PVOID Context
  819. );
  820. NTSTATUS
  821. USBDIAG_SetCfgEnableRWu(
  822. PDEVICE_EXTENSION deviceExtension,
  823. PREQ_ENUMERATE_DOWNSTREAM_DEVICE pEnumerate
  824. );
  825. NTSTATUS
  826. USBDIAG_WaitForWakeup(
  827. PDEVICE_EXTENSION deviceExtension
  828. );
  829. NTSTATUS
  830. USBD_SetPdoRegistryParameter (
  831. IN PDEVICE_OBJECT PhysicalDeviceObject,
  832. IN PWCHAR KeyName,
  833. IN ULONG KeyNameLength,
  834. IN PVOID Data,
  835. IN ULONG DataLength,
  836. IN ULONG KeyType,
  837. IN ULONG DevInstKeyType
  838. );
  839. NTSTATUS
  840. USBD_SetRegistryKeyValue (
  841. IN HANDLE Handle,
  842. IN PUNICODE_STRING KeyNameUnicodeString,
  843. IN PVOID Data,
  844. IN ULONG DataLength,
  845. IN ULONG KeyType
  846. );
  847. NTSTATUS
  848. USBDIAG_DisableRemoteWakeupEnable(
  849. IN PDEVICE_OBJECT DeviceObject,
  850. IN BOOLEAN bDisable
  851. );
  852. NTSTATUS
  853. USBDIAG_PassDownIrp (
  854. IN PDEVICE_OBJECT DeviceObject,
  855. IN PIRP Irp
  856. );
  857. NTSTATUS
  858. USBDIAG_QueryCapabilitiesCompletionRoutine(
  859. IN PDEVICE_OBJECT NullDeviceObject,
  860. IN PIRP Irp,
  861. IN PVOID Context
  862. );
  863. NTSTATUS
  864. USBDIAG_GenericCompletionRoutine(
  865. IN PDEVICE_OBJECT DeviceObject,
  866. IN PIRP Irp,
  867. IN PVOID Context
  868. );
  869. #endif //__USBDIAG_H__