阅读:2311回复:0
求教,urb = USBD_CreateConfigurationRequestEx(Descriptors,ilist);
为什么第一次调用urb = USBD_CreateConfigurationRequestEx(Descriptors,ilist);时能成功的返回,但第二次却返回失败。
///////////////////////////////////////////////////////////////////////////////// // UsbSelectConfiguration: Select first config ///////////////////////////////////////////////////////////////////////////////// NTSTATUS UsbSelectConfiguration(IN PDEVICE_EXTENSION dx) { // Get all first configuration descriptors PUSB_CONFIGURATION_DESCRIPTOR Descriptors = NULL; ULONG size; NTSTATUS status; PUSB_INTERFACE_DESCRIPTOR id; USBD_INTERFACE_LIST_ENTRY ilist[2]; PURB urb; PUSBD_INTERFACE_INFORMATION InterfaceInfo; PUSBD_PIPE_INFORMATION pi; dx->UsbPipeHandle = NULL; Descriptors = dx->UsbConfigurationDescriptor; /* status = UsbGetConfigurationDescriptors(dx,Descriptors,0,&size); if( !NT_SUCCESS(status)) { DebugPrint(\"UsbGetConfigurationDescriptors failed = 0x%x\", status); FreeIfAllocated(Descriptors); return status; } */ // FreeIfAllocated(Descriptors); // DebugPrint(\"USB Configuration Descriptor size=0x%x(%d)\\n\",size,size); DebugPrint(\"USB Configuration Descriptor\\n\"); DebugPrint(\"-------------------------------------------------------\\n\"); DebugPrint(\"bLength = 0x%x(%d)\\n\", Descriptors->bLength,Descriptors->bLength); DebugPrint(\"bDescriptorType = 0x%x\\n\", Descriptors->bDescriptorType); DebugPrint(\"wTotalLength = 0x%x\\n\", Descriptors->wTotalLength); DebugPrint(\"bNumInterfaces = 0x%x\\n\", Descriptors->bNumInterfaces); DebugPrint(\"bConfigurationValue = 0x%x\\n\", Descriptors->bConfigurationValue); DebugPrint(\"iConfiguration = 0x%x\\n\", Descriptors->iConfiguration); DebugPrint(\"bmAttributes = 0x%x\\n\", Descriptors->bmAttributes); DebugPrint(\"MaxPower = 0x%x,(%d mA)\\n\", Descriptors->MaxPower,Descriptors->MaxPower); // Search for an interface Number = 0x81 /* //searches a given configuration descriptor and //returns a pointer to an interface that matches the given search criteria. USBD_ParseConfigurationDescriptorEx( //Points to a USB configuration descriptor that contains the interface for which to search IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, //Points to the address within the configuration descriptor, provided at ConfigurationDescriptor, to begin searching from IN PVOID StartPosition, //Specifies the device-defined index of the interface to be retrieved IN LONG InterfaceNumber, //Specifies the device-defined alternate-setting index of the interface to be retrieved IN LONG AlternateSetting, //Specifies the device- or USB-defined identifier for the interface class of the interface to be retrieved. IN LONG InterfaceClass, //Specifies the device- or USB-defined identifier for the interface subclass of the interface to be retrieved. IN LONG InterfaceSubClass, //Specifies the device- or USB-defined identifier for the interface protocol of the interface to be retrieved// Search for a HID device, boot protocol, keyboard IN LONG InterfaceProtocol ); */ id = USBD_ParseConfigurationDescriptorEx(Descriptors, Descriptors, -1, -1, 0x03, -1, -1); if(id==NULL) { DebugPrintMsg(\"No matching interface found\"); FreeIfAllocated(Descriptors); return STATUS_NO_SUCH_DEVICE; } // Build list of interfaces we are interested in ilist[0].InterfaceDescriptor = id; ilist[0].Interface = NULL; // Will point to urb->UrbUsbSelectConfiguration.Interface ilist[1].InterfaceDescriptor = NULL; DebugPrintMsg(\"Selecting configuration\"); // Create select configuration URB urb = USBD_CreateConfigurationRequestEx(Descriptors,ilist); status = CallUSBDI(dx, urb,IOCTL_INTERNAL_USB_SUBMIT_URB,0); if(!NT_SUCCESS(status) || !USBD_SUCCESS( urb->UrbHeader.Status)) { DebugPrint(\"Selecting configuration Error status=0x%x URB_status=0x%x\", status, urb->UrbHeader.Status); status = STATUS_UNSUCCESSFUL; } else { // Select config worked DebugPrintMsg(\"Select configuration worked\"); dx->UsbConfigurationHandle = urb->UrbSelectConfiguration.ConfigurationHandle; // Find pipe handle of first pipe, ie interrupt pipe that returns input HID reports InterfaceInfo = &urb->UrbSelectConfiguration.Interface; DebugPrint(\"interface Class = %d ,NumberOfPipes = %d\\n\", InterfaceInfo->Class, InterfaceInfo->NumberOfPipes); if(InterfaceInfo->NumberOfPipes>0) { pi = &InterfaceInfo->Pipes[0]; dx->UsbPipeHandle = pi->PipeHandle; DebugPrint(\"PipeHandle = 0x%x\\n\", dx->UsbPipeHandle); DebugPrint(\"Pipes[0] EndpointAddress = 0x%2x Interval = %dms PipeType = %d MaximumTransferSize = %d\\n\", pi->EndpointAddress, pi->Interval, pi->PipeType, pi->MaximumTransferSize); } if(dx->UsbPipeHandle==NULL) status = STATUS_UNSUCCESSFUL; } FreeIfAllocated(urb); return status; } |
|
|