阅读:4762回复:5
关于usb 枚举的Set_Configuration
当驱动加载后,主机会发送Set_Configuration命令给usb设备,小弟想知道在哪里发送,请列举代码示例,谢谢大虾!
|
|
沙发#
发布于:2009-12-10 17:01
怎么没有大侠指导一下呢?恳请啊,在做用usb控制ipod的驱动程序。
|
|
板凳#
发布于:2009-12-20 11:05
是总线驱动(Host Controlor?)发送set address命令,与你无关。
|
|
|
地板#
发布于:2009-12-22 15:01
我说的是 Set_Configuration哦,有谁可以详细说明下以下代码吗?
NTSTATUS StartDevice(PDEVICE_OBJECT pDeviceObject) { // StartDevice PAGED_CODE(); NTSTATUS status; PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) pDeviceObject->DeviceExtension; URB urb; // URB for use in this subroutine // Read our device descriptor. The only real purpose to this would be to find out how many // configurations there are so we can read their descriptors. In this simplest of examples, // there's only one configuration. UsbBuildGetDescriptorRequest(&urb, sizeof(_URB_CONTROL_DESCRIPTOR_REQUEST), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, &pdx->dd, NULL, sizeof(pdx->dd), NULL); status = SendAwaitUrb(pDeviceObject, &urb); if (!NT_SUCCESS(status)) { KdPrint((DRIVERNAME " - Error %X trying to read device descriptor\n", status)); return status; } // Read the descriptor of the first configuration. This requires two steps. The first step // reads the fixed-size configuration descriptor alone. The second step reads the // configuration descriptor plus all imbedded interface and endpoint descriptors. USB_CONFIGURATION_DESCRIPTOR tcd; UsbBuildGetDescriptorRequest(&urb, sizeof(_URB_CONTROL_DESCRIPTOR_REQUEST), USB_CONFIGURATION_DESCRIPTOR_TYPE, 0, 0, &tcd, NULL, sizeof(tcd), NULL); status = SendAwaitUrb(pDeviceObject, &urb); if (!NT_SUCCESS(status)) { KdPrint((DRIVERNAME " - Error %X trying to read configuration descriptor 1\n", status)); return status; } ULONG size = tcd.wTotalLength; PUSB_CONFIGURATION_DESCRIPTOR pcd = (PUSB_CONFIGURATION_DESCRIPTOR) ExAllocatePool(NonPagedPool, size); if (!pcd) { KdPrint((DRIVERNAME " - Unable to allocate %X bytes for configuration descriptor\n", size)); return STATUS_INSUFFICIENT_RESOURCES; } __try { UsbBuildGetDescriptorRequest(&urb, sizeof(_URB_CONTROL_DESCRIPTOR_REQUEST), USB_CONFIGURATION_DESCRIPTOR_TYPE, 0, 0, pcd, NULL, size, NULL); status = SendAwaitUrb(pDeviceObject, &urb); if (!NT_SUCCESS(status)) { KdPrint((DRIVERNAME " - Error %X trying to read configuration descriptor 1\n", status)); return status; } // Locate the descriptor for the one and only interface we expect to find PUSB_INTERFACE_DESCRIPTOR pid = USBD_ParseConfigurationDescriptorEx(pcd, pcd, -1, -1, -1, -1, -1); ASSERT(pid); // Create a URB to use in selecting a configuration. USBD_INTERFACE_LIST_ENTRY interfaces[2] = { {pid, NULL}, {NULL, NULL}, // fence to terminate the array }; PURB selurb = USBD_CreateConfigurationRequestEx(pcd, interfaces); if (!selurb) { KdPrint((DRIVERNAME " - Unable to create configuration request\n")); return STATUS_INSUFFICIENT_RESOURCES; } __try { // Verify that the interface describes exactly the endpoints we expect if (pid->bNumEndpoints != 4) { KdPrint((DRIVERNAME " - %d is the wrong number of endpoints\n", pid->bNumEndpoints)); return STATUS_DEVICE_CONFIGURATION_ERROR; } PUSB_ENDPOINT_DESCRIPTOR ped = (PUSB_ENDPOINT_DESCRIPTOR) pid; ped = (PUSB_ENDPOINT_DESCRIPTOR) USBD_ParseDescriptors(pcd, tcd.wTotalLength, ped, USB_ENDPOINT_DESCRIPTOR_TYPE); if (!ped || ped->bEndpointAddress != 0x81 || ped->bmAttributes != USB_ENDPOINT_TYPE_BULK || ped->wMaxPacketSize != 64) { KdPrint((DRIVERNAME " - Endpoint has wrong attributes\n")); return STATUS_DEVICE_CONFIGURATION_ERROR; } ++ped; ped = (PUSB_ENDPOINT_DESCRIPTOR) USBD_ParseDescriptors(pcd, tcd.wTotalLength, ped, USB_ENDPOINT_DESCRIPTOR_TYPE); if (!ped || ped->bEndpointAddress != 0x2 || ped->bmAttributes != USB_ENDPOINT_TYPE_BULK || ped->wMaxPacketSize != 64) { KdPrint((DRIVERNAME " - Endpoint has wrong attributes\n")); return STATUS_DEVICE_CONFIGURATION_ERROR; } ++ped; ped = (PUSB_ENDPOINT_DESCRIPTOR) USBD_ParseDescriptors(pcd, tcd.wTotalLength, ped, USB_ENDPOINT_DESCRIPTOR_TYPE); if (!ped || ped->bEndpointAddress != 0x85 || ped->bmAttributes != USB_ENDPOINT_TYPE_BULK || ped->wMaxPacketSize != 64) { KdPrint((DRIVERNAME " - Endpoint has wrong attributes\n")); return STATUS_DEVICE_CONFIGURATION_ERROR; } ++ped; ped = (PUSB_ENDPOINT_DESCRIPTOR) USBD_ParseDescriptors(pcd, tcd.wTotalLength, ped, USB_ENDPOINT_DESCRIPTOR_TYPE); if (!ped || ped->bEndpointAddress != 0x6 || ped->bmAttributes != USB_ENDPOINT_TYPE_BULK || ped->wMaxPacketSize != 64) { KdPrint((DRIVERNAME " - Endpoint has wrong attributes\n")); return STATUS_DEVICE_CONFIGURATION_ERROR; } ++ped; PUSBD_INTERFACE_INFORMATION pii = interfaces[0].Interface; // Initialize the maximum transfer size for each of the endpoints // TODO remove these statements if you're happy with the default // value provided by USBD. pii->Pipes[0].MaximumTransferSize = 4096; pii->Pipes[1].MaximumTransferSize = 4096; pii->Pipes[2].MaximumTransferSize = 4096; pii->Pipes[3].MaximumTransferSize = 4096; // Submit the set-configuration request status = SendAwaitUrb(pDeviceObject, selurb); if (!NT_SUCCESS(status)) { KdPrint((DRIVERNAME " - Error %X trying to select configuration\n", status)); return status; } // Save the configuration and pipe handles pdx->hconfig = selurb->UrbSelectConfiguration.ConfigurationHandle; pdx->Pipe0 = pii->Pipes[0].PipeHandle; pdx->Pipe1 = pii->Pipes[1].PipeHandle; pdx->Pipe2 = pii->Pipes[2].PipeHandle; pdx->Pipe3 = pii->Pipes[3].PipeHandle; // TODO If you have an interrupt endpoint, now would be the time to // create an IRP and URB with which to poll it continuously // Transfer ownership of the configuration descriptor to the device extension pdx->pcd = pcd; pcd = NULL; } __finally { ExFreePool(selurb); } } __finally { if (pcd) ExFreePool(pcd); } return STATUS_SUCCESS; } |
|
地下室#
发布于:2009-12-22 15:01
期待虾牛们赐教啊
|
|
5楼#
发布于:2009-12-22 17:29
不能上图,要不上一个用HD-USB12协议分析仪抓一下的图片,上电就发地址00
|
|