6 #define NDEBUG_USBPORT_CORE
11 USBPORT_MPStatusToRHStatus(IN MPSTATUS MPStatus
)
13 RHSTATUS RHStatus
= RH_STATUS_SUCCESS
;
15 //DPRINT("USBPORT_MPStatusToRHStatus: MPStatus - %x\n", MPStatus);
19 RHStatus
= (MPStatus
!= MP_STATUS_FAILURE
);
28 USBPORT_RH_SetFeatureUSB2PortPower(IN PDEVICE_OBJECT FdoDevice
,
31 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
32 PUSBPORT_REGISTRATION_PACKET Packet
;
33 PDEVICE_RELATIONS CompanionControllersList
;
34 PUSBPORT_REGISTRATION_PACKET CompanionPacket
;
35 PDEVICE_OBJECT CompanionFdoDevice
;
36 PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension
;
37 PUSBPORT_RHDEVICE_EXTENSION PdoExtension
;
39 PDEVICE_OBJECT
* Entry
;
40 ULONG NumController
= 0;
42 DPRINT("USBPORT_RootHub_PowerUsb2Port: FdoDevice - %p, Port - %p\n",
46 FdoExtension
= FdoDevice
->DeviceExtension
;
47 Packet
= &FdoExtension
->MiniPortInterface
->Packet
;
49 CompanionControllersList
= USBPORT_FindCompanionControllers(FdoDevice
,
53 if (!CompanionControllersList
)
55 Packet
->RH_SetFeaturePortPower(FdoExtension
->MiniPortExt
, Port
);
56 return MP_STATUS_SUCCESS
;
59 Entry
= &CompanionControllersList
->Objects
[0];
61 while (NumController
< CompanionControllersList
->Count
)
63 CompanionFdoDevice
= *Entry
;
65 CompanionFdoExtension
= CompanionFdoDevice
->DeviceExtension
;
66 CompanionPacket
= &CompanionFdoExtension
->MiniPortInterface
->Packet
;
68 PdoExtension
= CompanionFdoExtension
->RootHubPdo
->DeviceExtension
;
71 (PdoExtension
->CommonExtension
.PnpStateFlags
& USBPORT_PNP_STATE_STARTED
) &&
72 ix
< PdoExtension
->RootHubDescriptors
->Descriptor
.bNumberOfPorts
;
75 CompanionPacket
->RH_SetFeaturePortPower(CompanionFdoExtension
->MiniPortExt
,
83 Packet
->RH_SetFeaturePortPower(FdoExtension
->MiniPortExt
, Port
);
85 if (CompanionControllersList
)
87 ExFreePoolWithTag(CompanionControllersList
, USB_PORT_TAG
);
90 return MP_STATUS_SUCCESS
;
95 USBPORT_RootHubClassCommand(IN PDEVICE_OBJECT FdoDevice
,
96 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
98 IN PULONG BufferLength
)
100 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
101 PUSBPORT_RHDEVICE_EXTENSION PdoExtension
;
102 PUSBPORT_REGISTRATION_PACKET Packet
;
106 RHSTATUS RHStatus
= RH_STATUS_UNSUCCESSFUL
;
109 DPRINT("USBPORT_RootHubClassCommand: USB command - %x, *BufferLength - %x\n",
110 SetupPacket
->bRequest
,
113 FdoExtension
= FdoDevice
->DeviceExtension
;
114 PdoExtension
= FdoExtension
->RootHubPdo
->DeviceExtension
;
115 Packet
= &FdoExtension
->MiniPortInterface
->Packet
;
117 Port
= SetupPacket
->wIndex
.W
;
119 switch (SetupPacket
->bRequest
)
121 case USB_REQUEST_GET_STATUS
:
130 if (SetupPacket
->bmRequestType
.Recipient
== BMREQUEST_TO_OTHER
)
132 ASSERT(*BufferLength
>= 4);
134 if (Port
> PdoExtension
->RootHubDescriptors
->Descriptor
.bNumberOfPorts
||
136 SetupPacket
->wLength
< 4)
141 KeAcquireSpinLock(&FdoExtension
->MiniportSpinLock
, &OldIrql
);
143 MPStatus
= Packet
->RH_GetPortStatus(FdoExtension
->MiniPortExt
,
144 SetupPacket
->wIndex
.W
,
147 KeReleaseSpinLock(&FdoExtension
->MiniportSpinLock
, OldIrql
);
151 KeAcquireSpinLock(&FdoExtension
->MiniportSpinLock
, &OldIrql
);
153 MPStatus
= Packet
->RH_GetHubStatus(FdoExtension
->MiniPortExt
,
156 KeReleaseSpinLock(&FdoExtension
->MiniportSpinLock
, OldIrql
);
159 RHStatus
= USBPORT_MPStatusToRHStatus(MPStatus
);
163 case USB_REQUEST_CLEAR_FEATURE
:
164 Feature
= SetupPacket
->wValue
.W
;
166 if ((SetupPacket
->bmRequestType
.Recipient
) != USBPORT_RECIPIENT_ROOT_PORT
)
168 if (Feature
== FEATURE_C_HUB_LOCAL_POWER
)
170 RHStatus
= RH_STATUS_SUCCESS
;
174 if (Feature
== FEATURE_C_HUB_OVER_CURRENT
)
176 MPStatus
= Packet
->RH_ClearFeaturePortOvercurrentChange(FdoExtension
->MiniPortExt
,
178 RHStatus
= USBPORT_MPStatusToRHStatus(MPStatus
);
188 case FEATURE_PORT_ENABLE
:
189 MPStatus
= Packet
->RH_ClearFeaturePortEnable(FdoExtension
->MiniPortExt
,
193 case FEATURE_PORT_SUSPEND
:
194 MPStatus
= Packet
->RH_ClearFeaturePortSuspend(FdoExtension
->MiniPortExt
,
198 case FEATURE_PORT_POWER
:
199 MPStatus
= Packet
->RH_ClearFeaturePortPower(FdoExtension
->MiniPortExt
,
203 case FEATURE_C_PORT_CONNECTION
:
204 MPStatus
= Packet
->RH_ClearFeaturePortConnectChange(FdoExtension
->MiniPortExt
,
208 case FEATURE_C_PORT_ENABLE
:
209 MPStatus
= Packet
->RH_ClearFeaturePortEnableChange(FdoExtension
->MiniPortExt
,
213 case FEATURE_C_PORT_SUSPEND
:
214 MPStatus
= Packet
->RH_ClearFeaturePortSuspendChange(FdoExtension
->MiniPortExt
,
218 case FEATURE_C_PORT_OVER_CURRENT
:
219 MPStatus
= Packet
->RH_ClearFeaturePortOvercurrentChange(FdoExtension
->MiniPortExt
,
223 case FEATURE_C_PORT_RESET
:
224 MPStatus
= Packet
->RH_ClearFeaturePortResetChange(FdoExtension
->MiniPortExt
,
229 DPRINT1("USBPORT_RootHubClassCommand: Not supported feature - %x\n",
234 RHStatus
= USBPORT_MPStatusToRHStatus(MPStatus
);
237 case USB_REQUEST_SET_FEATURE
:
238 if (SetupPacket
->bmRequestType
.Recipient
!= USBPORT_RECIPIENT_ROOT_PORT
)
243 Feature
= SetupPacket
->wValue
.W
;
247 case FEATURE_PORT_ENABLE
:
248 MPStatus
= Packet
->RH_SetFeaturePortEnable(FdoExtension
->MiniPortExt
,
252 case FEATURE_PORT_SUSPEND
:
253 MPStatus
= Packet
->RH_SetFeaturePortSuspend(FdoExtension
->MiniPortExt
,
257 case FEATURE_PORT_RESET
:
258 MPStatus
= Packet
->RH_SetFeaturePortReset(FdoExtension
->MiniPortExt
,
262 case FEATURE_PORT_POWER
:
263 if (Packet
->MiniPortFlags
& USB_MINIPORT_FLAGS_USB2
)
265 MPStatus
= USBPORT_RH_SetFeatureUSB2PortPower(FdoDevice
, Port
);
269 MPStatus
= Packet
->RH_SetFeaturePortPower(FdoExtension
->MiniPortExt
,
276 DPRINT1("USBPORT_RootHubClassCommand: Not supported feature - %x\n",
281 RHStatus
= USBPORT_MPStatusToRHStatus(MPStatus
);
284 case USB_REQUEST_GET_DESCRIPTOR
:
286 SetupPacket
->wValue
.W
== 0 &&
287 SetupPacket
->bmRequestType
.Dir
== BMREQUEST_DEVICE_TO_HOST
)
289 SIZE_T DescriptorLength
;
291 DescriptorLength
= PdoExtension
->RootHubDescriptors
->Descriptor
.bDescriptorLength
;
293 if (*BufferLength
< DescriptorLength
)
294 DescriptorLength
= *BufferLength
;
296 RtlCopyMemory(Buffer
,
297 &PdoExtension
->RootHubDescriptors
->Descriptor
,
300 *BufferLength
= DescriptorLength
;
301 RHStatus
= RH_STATUS_SUCCESS
;
307 DPRINT1("USBPORT_RootHubClassCommand: Not supported USB request - %x\n",
308 SetupPacket
->bRequest
);
309 //USB_REQUEST_SET_ADDRESS 0x05
310 //USB_REQUEST_SET_DESCRIPTOR 0x07
311 //USB_REQUEST_GET_CONFIGURATION 0x08
312 //USB_REQUEST_SET_CONFIGURATION 0x09
313 //USB_REQUEST_GET_INTERFACE 0x0A
314 //USB_REQUEST_SET_INTERFACE 0x0B
315 //USB_REQUEST_SYNC_FRAME 0x0C
324 USBPORT_RootHubStandardCommand(IN PDEVICE_OBJECT FdoDevice
,
325 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
327 IN OUT PULONG TransferLength
)
329 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
330 PUSBPORT_RHDEVICE_EXTENSION PdoExtension
;
331 PUSBPORT_REGISTRATION_PACKET Packet
;
334 SIZE_T DescriptorLength
;
336 RHSTATUS RHStatus
= RH_STATUS_UNSUCCESSFUL
;
339 DPRINT("USBPORT_RootHubStandardCommand: USB command - %x, TransferLength - %p\n",
340 SetupPacket
->bRequest
,
343 FdoExtension
= FdoDevice
->DeviceExtension
;
344 PdoExtension
= FdoExtension
->RootHubPdo
->DeviceExtension
;
345 Packet
= &FdoExtension
->MiniPortInterface
->Packet
;
347 switch (SetupPacket
->bRequest
)
349 case USB_REQUEST_GET_DESCRIPTOR
:
350 if (SetupPacket
->wValue
.LowByte
||
351 !(SetupPacket
->bmRequestType
.Dir
))
356 switch (SetupPacket
->wValue
.HiByte
)
358 case USB_DEVICE_DESCRIPTOR_TYPE
:
359 Descriptor
= &PdoExtension
->RootHubDescriptors
->DeviceDescriptor
;
360 DescriptorLength
= sizeof(USB_DEVICE_DESCRIPTOR
);
363 case USB_CONFIGURATION_DESCRIPTOR_TYPE
:
364 Descriptor
= &PdoExtension
->RootHubDescriptors
->ConfigDescriptor
;
365 DescriptorLength
= sizeof(USB_CONFIGURATION_DESCRIPTOR
) +
366 sizeof(USB_INTERFACE_DESCRIPTOR
) +
367 sizeof(USB_ENDPOINT_DESCRIPTOR
);
371 DPRINT1("USBPORT_RootHubStandardCommand: Not supported Descriptor Type - %x\n",
372 SetupPacket
->wValue
.HiByte
);
381 if (*TransferLength
>= DescriptorLength
)
382 Length
= DescriptorLength
;
384 Length
= *TransferLength
;
386 RtlCopyMemory(Buffer
, Descriptor
, Length
);
387 *TransferLength
= Length
;
389 RHStatus
= RH_STATUS_SUCCESS
;
392 case USB_REQUEST_GET_STATUS
:
393 if (!SetupPacket
->wValue
.W
&&
394 SetupPacket
->wLength
== sizeof(USHORT
) &&
395 !SetupPacket
->wIndex
.W
&&
396 SetupPacket
->bmRequestType
.Dir
== BMREQUEST_DEVICE_TO_HOST
)
398 KeAcquireSpinLock(&FdoExtension
->MiniportSpinLock
, &OldIrql
);
400 MPStatus
= Packet
->RH_GetStatus(FdoExtension
->MiniPortExt
,
403 KeReleaseSpinLock(&FdoExtension
->MiniportSpinLock
, OldIrql
);
405 *TransferLength
= sizeof(USHORT
);
406 RHStatus
= USBPORT_MPStatusToRHStatus(MPStatus
);
411 case USB_REQUEST_GET_CONFIGURATION
:
412 if (SetupPacket
->wValue
.W
||
413 SetupPacket
->wIndex
.W
||
414 SetupPacket
->wLength
!= 1 ||
415 SetupPacket
->bmRequestType
.Dir
== BMREQUEST_HOST_TO_DEVICE
)
422 if (*TransferLength
>= 1)
425 RtlCopyMemory(Buffer
, &PdoExtension
->ConfigurationValue
, Length
);
428 *TransferLength
= Length
;
430 RHStatus
= RH_STATUS_SUCCESS
;
433 case USB_REQUEST_SET_CONFIGURATION
:
434 if (!SetupPacket
->wIndex
.W
&&
435 !SetupPacket
->wLength
&&
436 !(SetupPacket
->bmRequestType
.Dir
== BMREQUEST_DEVICE_TO_HOST
))
438 if (SetupPacket
->wValue
.W
== 0 ||
439 SetupPacket
->wValue
.W
==
440 PdoExtension
->RootHubDescriptors
->ConfigDescriptor
.bConfigurationValue
)
442 PdoExtension
->ConfigurationValue
= SetupPacket
->wValue
.LowByte
;
443 RHStatus
= RH_STATUS_SUCCESS
;
449 case USB_REQUEST_SET_ADDRESS
:
450 if (!SetupPacket
->wIndex
.W
&&
451 !SetupPacket
->wLength
&&
452 !(SetupPacket
->bmRequestType
.Dir
))
454 PdoExtension
->DeviceHandle
.DeviceAddress
= SetupPacket
->wValue
.LowByte
;
455 RHStatus
= RH_STATUS_SUCCESS
;
462 DPRINT1("USBPORT_RootHubStandardCommand: Not supported USB request - %x\n",
463 SetupPacket
->bRequest
);
464 //USB_REQUEST_CLEAR_FEATURE 0x01
465 //USB_REQUEST_SET_FEATURE 0x03
466 //USB_REQUEST_SET_DESCRIPTOR 0x07
467 //USB_REQUEST_GET_INTERFACE 0x0A
468 //USB_REQUEST_SET_INTERFACE 0x0B
469 //USB_REQUEST_SYNC_FRAME 0x0C
478 USBPORT_RootHubEndpoint0(IN PUSBPORT_TRANSFER Transfer
)
480 PDEVICE_OBJECT FdoDevice
;
481 SIZE_T TransferLength
;
484 PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
;
488 DPRINT("USBPORT_RootHubEndpoint0: Transfer - %p\n", Transfer
);
490 TransferLength
= Transfer
->TransferParameters
.TransferBufferLength
;
492 FdoDevice
= Transfer
->Endpoint
->FdoDevice
;
494 if (TransferLength
> 0)
495 Buffer
= Urb
->UrbControlTransfer
.TransferBufferMDL
->MappedSystemVa
;
499 SetupPacket
= (PUSB_DEFAULT_PIPE_SETUP_PACKET
)Urb
->UrbControlTransfer
.SetupPacket
;
501 Type
= SetupPacket
->bmRequestType
.Type
;
503 if (Type
== BMREQUEST_STANDARD
)
505 RHStatus
= USBPORT_RootHubStandardCommand(FdoDevice
,
510 else if (Type
== BMREQUEST_CLASS
)
512 RHStatus
= USBPORT_RootHubClassCommand(FdoDevice
,
519 return RH_STATUS_UNSUCCESSFUL
;
522 if (RHStatus
== RH_STATUS_SUCCESS
)
523 Transfer
->CompletedTransferLen
= TransferLength
;
530 USBPORT_RootHubSCE(IN PUSBPORT_TRANSFER Transfer
)
532 PUSBPORT_ENDPOINT Endpoint
;
533 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
534 PUSBPORT_RHDEVICE_EXTENSION PdoExtension
;
535 PUSBPORT_REGISTRATION_PACKET Packet
;
536 ULONG TransferLength
;
537 USBHUB_PORT_STATUS PortStatus
;
538 USB_HUB_STATUS_AND_CHANGE HubStatus
;
540 PULONG AddressBitMap
;
543 RHSTATUS RHStatus
= RH_STATUS_NO_CHANGES
;
544 PUSB_HUB_DESCRIPTOR HubDescriptor
;
547 DPRINT("USBPORT_RootHubSCE: Transfer - %p\n", Transfer
);
549 Endpoint
= Transfer
->Endpoint
;
551 FdoExtension
= Endpoint
->FdoDevice
->DeviceExtension
;
552 PdoExtension
= FdoExtension
->RootHubPdo
->DeviceExtension
;
553 Packet
= &FdoExtension
->MiniPortInterface
->Packet
;
555 HubDescriptor
= &PdoExtension
->RootHubDescriptors
->Descriptor
;
556 NumberOfPorts
= HubDescriptor
->bNumberOfPorts
;
558 PortStatus
.AsULONG
= 0;
559 HubStatus
.AsUlong32
= 0;
562 TransferLength
= Transfer
->TransferParameters
.TransferBufferLength
;
566 Buffer
= Urb
->UrbControlTransfer
.TransferBufferMDL
->MappedSystemVa
;
573 /* Check parameters */
577 /* Not valid parameter */
578 DPRINT1("USBPORT_RootHubSCE: Error! Buffer is NULL\n");
579 return RH_STATUS_UNSUCCESSFUL
;
582 if ((TransferLength
< (NumberOfPorts
/ 8 + 1)))
584 /* Not valid parameters */
585 DPRINT1("USBPORT_RootHubSCE: Error! TransferLength - %x, NumberOfPorts - %x\n",
589 return RH_STATUS_UNSUCCESSFUL
;
592 RtlZeroMemory(Buffer
, TransferLength
);
594 AddressBitMap
= Buffer
;
596 /* Scan all the ports for changes */
597 for (Port
= 1; Port
<= NumberOfPorts
; Port
++)
599 DPRINT_CORE("USBPORT_RootHubSCE: Port - %p\n", Port
);
601 /* Request the port status from miniport */
602 if (Packet
->RH_GetPortStatus(FdoExtension
->MiniPortExt
,
606 /* Miniport returned an error */
607 DPRINT1("USBPORT_RootHubSCE: RH_GetPortStatus failed\n");
608 return RH_STATUS_UNSUCCESSFUL
;
611 if (PortStatus
.UsbPortStatusChange
.ConnectStatusChange
||
612 PortStatus
.UsbPortStatusChange
.PortEnableDisableChange
||
613 PortStatus
.UsbPortStatusChange
.SuspendChange
||
614 PortStatus
.UsbPortStatusChange
.OverCurrentIndicatorChange
||
615 PortStatus
.UsbPortStatusChange
.ResetChange
)
617 /* At the port status there is a change */
618 AddressBitMap
[Port
>> 5] |= 1 << (Port
& 0x1F);
619 RHStatus
= RH_STATUS_SUCCESS
;
623 /* Request the hub status from miniport */
624 if (!Packet
->RH_GetHubStatus(FdoExtension
->MiniPortExt
, &HubStatus
))
626 if (HubStatus
.HubChange
.LocalPowerChange
== 1 ||
627 HubStatus
.HubChange
.OverCurrentChange
== 1)
629 /* At the hub status there is a change */
630 AddressBitMap
[0] |= 1;
631 RHStatus
= RH_STATUS_SUCCESS
;
634 if (RHStatus
== RH_STATUS_SUCCESS
)
637 Urb
->UrbControlTransfer
.TransferBufferLength
= TransferLength
;
638 return RH_STATUS_SUCCESS
;
641 if (RHStatus
== RH_STATUS_NO_CHANGES
)
643 /* No changes. Enable IRQs for miniport root hub */
644 Packet
->RH_EnableIrq(FdoExtension
->MiniPortExt
);
650 /* Miniport returned an error */
651 DPRINT1("USBPORT_RootHubSCE: RH_GetHubStatus failed\n");
652 return RH_STATUS_UNSUCCESSFUL
;
657 USBPORT_RootHubEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint
)
659 PDEVICE_OBJECT FdoDevice
;
660 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
661 PUSBPORT_REGISTRATION_PACKET Packet
;
662 PUSBPORT_TRANSFER Transfer
;
664 USBD_STATUS USBDStatus
;
667 DPRINT_CORE("USBPORT_RootHubEndpointWorker: Endpoint - %p\n", Endpoint
);
669 FdoDevice
= Endpoint
->FdoDevice
;
670 FdoExtension
= FdoDevice
->DeviceExtension
;
671 Packet
= &FdoExtension
->MiniPortInterface
->Packet
;
673 KeAcquireSpinLock(&FdoExtension
->MiniportSpinLock
, &OldIrql
);
674 if (!(FdoExtension
->Flags
& USBPORT_FLAG_HC_SUSPEND
))
676 Packet
->CheckController(FdoExtension
->MiniPortExt
);
678 KeReleaseSpinLock(&FdoExtension
->MiniportSpinLock
, OldIrql
);
680 KeAcquireSpinLock(&Endpoint
->EndpointSpinLock
, &Endpoint
->EndpointOldIrql
);
682 Transfer
= CONTAINING_RECORD(Endpoint
->TransferList
.Flink
,
686 if (IsListEmpty(&Endpoint
->TransferList
) ||
687 Endpoint
->TransferList
.Flink
== NULL
||
690 if (Endpoint
->StateLast
== USBPORT_ENDPOINT_REMOVE
)
692 ExInterlockedInsertTailList(&FdoExtension
->EndpointClosedList
,
693 &Endpoint
->CloseLink
,
694 &FdoExtension
->EndpointClosedSpinLock
);
697 KeReleaseSpinLock(&Endpoint
->EndpointSpinLock
, Endpoint
->EndpointOldIrql
);
699 USBPORT_FlushCancelList(Endpoint
);
703 if (Transfer
->Flags
& (TRANSFER_FLAG_ABORTED
| TRANSFER_FLAG_CANCELED
))
705 RemoveEntryList(&Transfer
->TransferLink
);
706 InsertTailList(&Endpoint
->CancelList
, &Transfer
->TransferLink
);
708 KeReleaseSpinLock(&Endpoint
->EndpointSpinLock
, Endpoint
->EndpointOldIrql
);
709 USBPORT_FlushCancelList(Endpoint
);
713 KeReleaseSpinLock(&Endpoint
->EndpointSpinLock
, Endpoint
->EndpointOldIrql
);
715 if (Endpoint
->EndpointProperties
.TransferType
== USBPORT_TRANSFER_TYPE_CONTROL
)
716 RHStatus
= USBPORT_RootHubEndpoint0(Transfer
);
718 RHStatus
= USBPORT_RootHubSCE(Transfer
);
720 if (RHStatus
!= RH_STATUS_NO_CHANGES
)
722 if (RHStatus
== RH_STATUS_SUCCESS
)
723 USBDStatus
= USBD_STATUS_SUCCESS
;
725 USBDStatus
= USBD_STATUS_STALL_PID
;
727 KeAcquireSpinLock(&Endpoint
->EndpointSpinLock
, &Endpoint
->EndpointOldIrql
);
728 USBPORT_QueueDoneTransfer(Transfer
, USBDStatus
);
729 KeReleaseSpinLock(&Endpoint
->EndpointSpinLock
, Endpoint
->EndpointOldIrql
);
731 USBPORT_FlushCancelList(Endpoint
);
735 USBPORT_FlushCancelList(Endpoint
);
740 USBPORT_RootHubCreateDevice(IN PDEVICE_OBJECT FdoDevice
,
741 IN PDEVICE_OBJECT PdoDevice
)
743 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
744 PUSBPORT_RHDEVICE_EXTENSION PdoExtension
;
745 PUSBPORT_REGISTRATION_PACKET Packet
;
746 PUSBPORT_DEVICE_HANDLE DeviceHandle
;
747 USBPORT_ROOT_HUB_DATA RootHubData
;
749 ULONG DescriptorsLength
;
750 PUSBPORT_RH_DESCRIPTORS Descriptors
;
751 PUSB_DEVICE_DESCRIPTOR RH_DeviceDescriptor
;
752 PUSB_CONFIGURATION_DESCRIPTOR RH_ConfigurationDescriptor
;
753 PUSB_INTERFACE_DESCRIPTOR RH_InterfaceDescriptor
;
754 PUSB_ENDPOINT_DESCRIPTOR RH_EndPointDescriptor
;
755 PUSB_HUB_DESCRIPTOR RH_HubDescriptor
;
757 PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
760 DPRINT("USBPORT_RootHubCreateDevice: FdoDevice - %p, PdoDevice - %p\n",
764 FdoExtension
= FdoDevice
->DeviceExtension
;
765 PdoExtension
= PdoDevice
->DeviceExtension
;
766 Packet
= &FdoExtension
->MiniPortInterface
->Packet
;
768 DeviceHandle
= &PdoExtension
->DeviceHandle
;
769 USBPORT_AddDeviceHandle(FdoDevice
, DeviceHandle
);
771 InitializeListHead(&DeviceHandle
->PipeHandleList
);
773 DeviceHandle
->IsRootHub
= TRUE
;
774 DeviceHandle
->DeviceSpeed
= UsbFullSpeed
;
775 DeviceHandle
->Flags
= DEVICE_HANDLE_FLAG_ROOTHUB
;
777 RtlZeroMemory(&RootHubData
, sizeof(RootHubData
));
779 Packet
->RH_GetRootHubData(FdoExtension
->MiniPortExt
, &RootHubData
);
781 ASSERT(RootHubData
.NumberOfPorts
!= 0);
782 NumMaskByte
= ((RootHubData
.NumberOfPorts
- 1) >> 3) + 1;
784 DescriptorsLength
= sizeof(USB_DEVICE_DESCRIPTOR
) +
785 sizeof(USB_CONFIGURATION_DESCRIPTOR
) +
786 sizeof(USB_INTERFACE_DESCRIPTOR
) +
787 sizeof(USB_ENDPOINT_DESCRIPTOR
) +
788 (sizeof(USB_HUB_DESCRIPTOR
) + 2 * NumMaskByte
);
790 Descriptors
= ExAllocatePoolWithTag(NonPagedPool
,
796 RtlZeroMemory(Descriptors
, DescriptorsLength
);
798 PdoExtension
->RootHubDescriptors
= Descriptors
;
800 RH_DeviceDescriptor
= &PdoExtension
->RootHubDescriptors
->DeviceDescriptor
;
802 RH_DeviceDescriptor
->bLength
= sizeof(USB_DEVICE_DESCRIPTOR
);
803 RH_DeviceDescriptor
->bDescriptorType
= USB_DEVICE_DESCRIPTOR_TYPE
;
804 RH_DeviceDescriptor
->bcdUSB
= 0x100;
805 RH_DeviceDescriptor
->bDeviceClass
= USB_DEVICE_CLASS_HUB
;
806 RH_DeviceDescriptor
->bDeviceSubClass
= 0x01;
807 RH_DeviceDescriptor
->bDeviceProtocol
= 0x00;
808 RH_DeviceDescriptor
->bMaxPacketSize0
= 0x08;
809 RH_DeviceDescriptor
->idVendor
= FdoExtension
->VendorID
;
810 RH_DeviceDescriptor
->idProduct
= FdoExtension
->DeviceID
;
811 RH_DeviceDescriptor
->bcdDevice
= FdoExtension
->RevisionID
;
812 RH_DeviceDescriptor
->iManufacturer
= 0x00;
813 RH_DeviceDescriptor
->iProduct
= 0x00;
814 RH_DeviceDescriptor
->iSerialNumber
= 0x00;
815 RH_DeviceDescriptor
->bNumConfigurations
= 0x01;
817 RH_ConfigurationDescriptor
= &PdoExtension
->RootHubDescriptors
->ConfigDescriptor
;
819 RH_ConfigurationDescriptor
->bLength
= sizeof(USB_CONFIGURATION_DESCRIPTOR
);
820 RH_ConfigurationDescriptor
->bDescriptorType
= USB_CONFIGURATION_DESCRIPTOR_TYPE
;
822 RH_ConfigurationDescriptor
->wTotalLength
= sizeof(USB_CONFIGURATION_DESCRIPTOR
) +
823 sizeof(USB_INTERFACE_DESCRIPTOR
) +
824 sizeof(USB_ENDPOINT_DESCRIPTOR
);
826 RH_ConfigurationDescriptor
->bNumInterfaces
= 0x01;
827 RH_ConfigurationDescriptor
->bConfigurationValue
= 0x01;
828 RH_ConfigurationDescriptor
->iConfiguration
= 0x00;
829 RH_ConfigurationDescriptor
->bmAttributes
= USB_CONFIG_SELF_POWERED
;
830 RH_ConfigurationDescriptor
->MaxPower
= 0x00;
832 RH_InterfaceDescriptor
= &PdoExtension
->RootHubDescriptors
->InterfaceDescriptor
;
834 RH_InterfaceDescriptor
->bLength
= sizeof(USB_INTERFACE_DESCRIPTOR
);
835 RH_InterfaceDescriptor
->bDescriptorType
= USB_INTERFACE_DESCRIPTOR_TYPE
;
836 RH_InterfaceDescriptor
->bInterfaceNumber
= 0x00;
837 RH_InterfaceDescriptor
->bAlternateSetting
= 0x00;
838 RH_InterfaceDescriptor
->bNumEndpoints
= 0x01;
839 RH_InterfaceDescriptor
->bInterfaceClass
= USB_DEVICE_CLASS_HUB
;
840 RH_InterfaceDescriptor
->bInterfaceSubClass
= 0x01;
841 RH_InterfaceDescriptor
->bInterfaceProtocol
= 0x00;
842 RH_InterfaceDescriptor
->iInterface
= 0x00;
844 RH_EndPointDescriptor
= &PdoExtension
->RootHubDescriptors
->EndPointDescriptor
;
846 RH_EndPointDescriptor
->bLength
= sizeof(USB_ENDPOINT_DESCRIPTOR
);
847 RH_EndPointDescriptor
->bDescriptorType
= USB_ENDPOINT_DESCRIPTOR_TYPE
;
848 RH_EndPointDescriptor
->bEndpointAddress
= 0x81;
849 RH_EndPointDescriptor
->bmAttributes
= USB_ENDPOINT_TYPE_INTERRUPT
; // SCE endpoint
850 RH_EndPointDescriptor
->wMaxPacketSize
= 0x0008;
851 RH_EndPointDescriptor
->bInterval
= 0x0C; // 12 msec
853 RH_HubDescriptor
= &PdoExtension
->RootHubDescriptors
->Descriptor
;
855 RH_HubDescriptor
->bDescriptorLength
= sizeof(USB_HUB_DESCRIPTOR
) + 2 * NumMaskByte
;
857 if (Packet
->MiniPortVersion
== USB_MINIPORT_VERSION_OHCI
||
858 Packet
->MiniPortVersion
== USB_MINIPORT_VERSION_UHCI
||
859 Packet
->MiniPortVersion
== USB_MINIPORT_VERSION_EHCI
)
861 RH_HubDescriptor
->bDescriptorType
= 0x29; // #define USB_20_HUB_DESCRIPTOR_TYPE 0x29 - need add in .h file
863 else if (Packet
->MiniPortVersion
== USB_MINIPORT_VERSION_XHCI
)
865 RH_HubDescriptor
->bDescriptorType
= 0x2A; // #define USB_30_HUB_DESCRIPTOR_TYPE 0x2A - need add in .h file
869 DPRINT1("USBPORT_RootHubCreateDevice: Unknown MiniPortVersion - %x\n",
870 Packet
->MiniPortVersion
);
875 RH_HubDescriptor
->bNumberOfPorts
= RootHubData
.NumberOfPorts
;
876 RH_HubDescriptor
->wHubCharacteristics
= RootHubData
.HubCharacteristics
.AsUSHORT
;
877 RH_HubDescriptor
->bPowerOnToPowerGood
= RootHubData
.PowerOnToPowerGood
;
878 RH_HubDescriptor
->bHubControlCurrent
= RootHubData
.HubControlCurrent
;
880 for (ix
= 0; ix
< NumMaskByte
; ix
+= 2)
882 RH_HubDescriptor
->bRemoveAndPowerMask
[ix
] = 0;
883 RH_HubDescriptor
->bRemoveAndPowerMask
[ix
+ 1] = -1;
886 EndpointDescriptor
= &DeviceHandle
->PipeHandle
.EndpointDescriptor
;
888 EndpointDescriptor
->bLength
= sizeof(USB_ENDPOINT_DESCRIPTOR
);
889 EndpointDescriptor
->bDescriptorType
= USB_ENDPOINT_DESCRIPTOR_TYPE
;
890 EndpointDescriptor
->bEndpointAddress
= 0x00;
891 EndpointDescriptor
->bmAttributes
= USB_ENDPOINT_TYPE_CONTROL
;
892 EndpointDescriptor
->wMaxPacketSize
= 0x0040;
893 EndpointDescriptor
->bInterval
= 0x00;
895 Status
= USBPORT_OpenPipe(FdoDevice
,
897 &DeviceHandle
->PipeHandle
,
902 Status
= STATUS_INSUFFICIENT_RESOURCES
;
910 USBPORT_InvalidateRootHub(PVOID Context
)
912 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
913 PDEVICE_OBJECT FdoDevice
;
914 PDEVICE_OBJECT PdoDevice
;
915 PUSBPORT_RHDEVICE_EXTENSION PdoExtension
;
916 PUSBPORT_ENDPOINT Endpoint
= NULL
;
918 DPRINT("USBPORT_InvalidateRootHub ... \n");
920 FdoExtension
= (PUSBPORT_DEVICE_EXTENSION
)((ULONG_PTR
)Context
-
921 sizeof(USBPORT_DEVICE_EXTENSION
));
923 FdoDevice
= FdoExtension
->CommonExtension
.SelfDevice
;
925 if (FdoExtension
->Flags
& USBPORT_FLAG_HC_SUSPEND
&&
926 FdoExtension
->Flags
& USBPORT_FLAG_HC_WAKE_SUPPORT
&&
927 FdoExtension
->MiniPortFlags
& USBPORT_MPFLAG_SUSPENDED
&&
928 FdoExtension
->TimerFlags
& USBPORT_TMFLAG_WAKE
)
930 USBPORT_HcQueueWakeDpc(FdoDevice
);
934 FdoExtension
->MiniPortInterface
->Packet
.RH_DisableIrq(FdoExtension
->MiniPortExt
);
936 PdoDevice
= FdoExtension
->RootHubPdo
;
940 PdoExtension
= PdoDevice
->DeviceExtension
;
941 Endpoint
= PdoExtension
->Endpoint
;
945 USBPORT_InvalidateEndpointHandler(FdoDevice
,
946 PdoExtension
->Endpoint
,
947 INVALIDATE_ENDPOINT_WORKER_THREAD
);
956 USBPORT_RootHubPowerAndChirpAllCcPorts(IN PDEVICE_OBJECT FdoDevice
)
958 PUSBPORT_DEVICE_EXTENSION FdoExtension
;
959 PUSBPORT_REGISTRATION_PACKET Packet
;
960 USBPORT_ROOT_HUB_DATA RootHubData
;
962 PDEVICE_RELATIONS CompanionControllersList
;
963 PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension
;
964 PUSBPORT_REGISTRATION_PACKET CompanionPacket
;
965 ULONG CompanionPorts
;
967 PDEVICE_OBJECT
* Entry
;
970 DPRINT("USBPORT_RootHub_PowerAndChirpAllCcPorts: FdoDevice - %p\n",
973 FdoExtension
= FdoDevice
->DeviceExtension
;
975 Packet
= &FdoExtension
->MiniPortInterface
->Packet
;
977 RtlZeroMemory(&RootHubData
, sizeof(RootHubData
));
979 Packet
->RH_GetRootHubData(FdoExtension
->MiniPortExt
,
982 NumPorts
= RootHubData
.NumberOfPorts
;
984 for (Port
= 1; Port
<= NumPorts
; ++Port
)
986 Packet
->RH_SetFeaturePortPower(FdoExtension
->MiniPortExt
, Port
);
989 USBPORT_Wait(FdoDevice
, 10);
991 CompanionControllersList
= USBPORT_FindCompanionControllers(FdoDevice
,
995 if (CompanionControllersList
)
997 Entry
= &CompanionControllersList
->Objects
[0];
999 for (NumController
= 0;
1000 NumController
< CompanionControllersList
->Count
;
1003 CompanionPacket
= &FdoExtension
->MiniPortInterface
->Packet
;
1005 CompanionFdoExtension
= (*Entry
)->DeviceExtension
;
1007 CompanionPacket
->RH_GetRootHubData(CompanionFdoExtension
->MiniPortExt
,
1010 CompanionPorts
= RootHubData
.NumberOfPorts
;
1012 for (Port
= 1; Port
<= CompanionPorts
; ++Port
)
1014 CompanionPacket
->RH_SetFeaturePortPower(CompanionFdoExtension
->MiniPortExt
,
1021 ExFreePoolWithTag(CompanionControllersList
, USB_PORT_TAG
);
1024 USBPORT_Wait(FdoDevice
, 100);
1026 for (Port
= 1; Port
<= NumPorts
; ++Port
)
1028 if (FdoExtension
->MiniPortInterface
->Version
< 200)
1033 InterlockedIncrement((PLONG
)&FdoExtension
->ChirpRootPortLock
);
1034 Packet
->RH_ChirpRootPort(FdoExtension
->MiniPortExt
, Port
);
1035 InterlockedDecrement((PLONG
)&FdoExtension
->ChirpRootPortLock
);