void LibUSB::InterfaceImpl::Claim() { if (m_pDeviceImpl.expired()) { throw std::logic_error("LibUSB::InterfaceImpl::Claim(): Called with expired DeviceImpl."); } // Claim the interface int Result = libusb_claim_interface(m_pDeviceImpl.lock()->m_pHandle.get(), m_pInterface->altsetting[m_alternateSetting].bInterfaceNumber); switch(Result) { case LIBUSB_SUCCESS: { m_bClaimed = true; SetAlternate(m_alternateSetting); } break; case LIBUSB_ERROR_NOT_FOUND: // The requested interface does not exist. throw std::runtime_error("LibUSB::InterfaceImpl::Claim(): The requested interface does not exist."); break; case LIBUSB_ERROR_NO_DEVICE: // The device has been disconnected. throw std::runtime_error("LibUSB::InterfaceImpl::Claim(): Device has been disconnected."); break; default: throw LibUSBException("LibUSB::InterfaceImpl::Claim(): Failed: ", Result); break; } }
//2006/3/7 support Choice Full Speed Bandwidth NTSTATUS UsbDev::SelectUsbBandwidth(PINT pSelectedBandwidth, BOOL fHasAudio) { NTSTATUS ntStatus=STATUS_SUCCESS; PIRP irp; KEVENT event; IO_STATUS_BLOCK ioStatus; PIO_STACK_LOCATION nextStack; PUSB_BUS_NOTIFICATION pBandwidthInfo; LARGE_INTEGER timeout = {(ULONG)(USB_COMMAND_TIMEOUT * 1000 * -10), -1}; UINT AudioBandwidth=0; UINT AvailableBandwidth; DBGU_TRACE ( "UsbDev::SelectUsbBandwidth\n"); if (fHasAudio) AudioBandwidth = 64; // ISO0, ISO1, ISO2, ISO3, ISO4, ISO5, ISO6, ISO7, ISO8 UINT Bandwith_Require[] = { 0, 128, 256, 384, 512, 680, 800, 900, 1023}; //2006/3/14 check pSelectedBandwidth if (pSelectedBandwidth == NULL) return STATUS_UNSUCCESSFUL; //2006/03/22 free bandwidth before query it ntStatus = SetAlternate(0,0); if (!NT_SUCCESS(ntStatus)) return ntStatus; // if((pBandwidthInfo = (PUSB_BUS_NOTIFICATION)ExAllocatePoolWithTag(NonPagedPool, sizeof(USB_BUS_NOTIFICATION), USBDEV_POOLTAG))==NULL) // return STATUS_UNSUCCESSFUL; pBandwidthInfo = (PUSB_BUS_NOTIFICATION)ExAllocatePoolWithTag(NonPagedPool, sizeof(USB_BUS_NOTIFICATION), USBDEV_POOLTAG); if(pBandwidthInfo==NULL) { DBGU_TRACE ( "pBandwidthInfo == NULL\n"); return STATUS_UNSUCCESSFUL; } memset(pBandwidthInfo, 0, sizeof(USB_BUS_NOTIFICATION)); pBandwidthInfo->NotificationType = AcquireBusInfo; // // issue a synchronous request // KeInitializeEvent(&event, SynchronizationEvent, FALSE); irp = IoBuildDeviceIoControlRequest( IOCTL_INTERNAL_USB_GET_BUS_INFO, m_pLdo, NULL, 0, NULL, 0, TRUE, &event, &ioStatus); if (irp == NULL ) { if (pBandwidthInfo) ExFreePoolWithTag(pBandwidthInfo,USBDEV_POOLTAG); return STATUS_UNSUCCESSFUL; } // // Call the class driver to perform the operation. If the returned status // is PENDING, wait for the request to complete. // nextStack= IoGetNextIrpStackLocation(irp); if (nextStack == NULL ) { if (pBandwidthInfo) ExFreePoolWithTag(pBandwidthInfo,USBDEV_POOLTAG); return STATUS_UNSUCCESSFUL; } // // pass the URB to the USB driver stack // nextStack->Parameters.Others.Argument1 = pBandwidthInfo; ntStatus= IoCallDriver(m_pLdo,irp); DBGU_TRACE ("return from IoCallDriver USBD %x\n", ntStatus); if (ntStatus == STATUS_PENDING) { DBGU_TRACE ( "Wait for single object\n"); ntStatus = KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, &timeout); if (ntStatus == STATUS_TIMEOUT) { // // // USBD did not complete this request in 30 milliseconds, assume // that the USBD is hung and return an // error. // if (pBandwidthInfo) ExFreePoolWithTag(pBandwidthInfo,USBDEV_POOLTAG); return(STATUS_UNSUCCESSFUL); } DBGU_TRACE ("Wait for single object, returned %x\n", ntStatus); } else { ioStatus.Status = ntStatus; } // // USBD maps the error code for us // ntStatus = ioStatus.Status; if(ntStatus == STATUS_SUCCESS) { DBGU_TRACE ("System Usb Total Bandwidth is %d, ConsumedBandwidth is %d\n",pBandwidthInfo->TotalBandwidth, pBandwidthInfo->ConsumedBandwidth); AvailableBandwidth = (pBandwidthInfo->TotalBandwidth - pBandwidthInfo->ConsumedBandwidth)/10 - AudioBandwidth; DBGU_TRACE ("System Usb Available ISO Bandwidth is %d bytes\n",AvailableBandwidth); for(int i=8; i > 0 ; i--) { if (AvailableBandwidth > Bandwith_Require[i]) { *pSelectedBandwidth = i; break; } } } if (pBandwidthInfo) ExFreePoolWithTag(pBandwidthInfo,USBDEV_POOLTAG); return ntStatus; }