int main(int argc, char* argv[]) { PrintHello(); if (ProcessCmdLine(argc, argv) != 0) return -1; OpenUsbDevice(); if (dwRC == USBIO_ERR_SUCCESS) { GetDeviceDescriptor(); } if (dwRC == USBIO_ERR_SUCCESS) { GetConfigurationDescriptor(); } if (dwRC == USBIO_ERR_SUCCESS) { GetStringDescriptor(); } if (dwRC == USBIO_ERR_SUCCESS) { SetConfiguration(); } if (dwRC == USBIO_ERR_SUCCESS) { // In order to give the USB device-side program (t_usb) // enough time after getting configured to carry out // some device tests, we wait here for a short while // before proceeding: Delay(2000); GetConfigurationInfo(); } if (dwRC == USBIO_ERR_SUCCESS) { OpenPipes(); } if (dwRC == USBIO_ERR_SUCCESS) { ExchangeVersions(); } if (dwRC == USBIO_ERR_SUCCESS) { DoTransfers(); } if (dwRC == USBIO_ERR_SUCCESS) { ClosePipes(); } CloseUsbDevice(); return 0; }
XHCIDevice::XHCIDevice(XHCIController& controller, XHCIPortRegister& port, unsigned portId, unsigned slotType) : _portId(portId), _port(port), _controller(controller), _tRing(nullptr), _inputContext(nullptr), _devContext(nullptr) { _slotID = _controller.EnableSlot(slotType); if(!_slotID) throw upan::exception(XLOC, "Failed to get SlotID"); _tRing = new TransferRing(64); uint32_t trRingPtr = KERNEL_REAL_ADDRESS(_tRing->RingBase()); _inputContext = new InputContext(_controller.CapReg().IsContextSize64(), port, portId, 0, trRingPtr); _devContext = new DeviceContext(_controller.CapReg().IsContextSize64()); //set A0 and A1 -> Slot and EP0 are affected by command _inputContext->Control().SetAddContextFlag(0x3); _controller.SetDeviceContext(_slotID, _devContext->Slot()); //TODO: to deal with older devices - you may have to send 2 AddressDevice twice //first, with block bit set and then with block bit cleared //With first request, address should be set and slot stat is default (1) //With second request, slot state should change to Addressed (2) _controller.AddressDevice((unsigned)&_inputContext->Control(), _slotID, false); if(_devContext->EP0().EPState() != EndPointContext::Running) throw upan::exception(XLOC, "After AddressDevice, EndPoint0 is in %d state", _devContext->EP0().EPState()); if(_devContext->Slot().SlotState() != SlotContext::Addressed) throw upan::exception(XLOC, "After AddressDevice, Slot is in %d state", _devContext->Slot().SlotState()); printf("\n USB Device Address: %x, PortMaxPkSz: %u, ControlEP MaxPktSz: %u", _devContext->Slot().DevAddress(), port.MaxPacketSize(), _devContext->EP0().MaxPacketSize()); GetDeviceDescriptor(); GetStringDescriptorZero(); SetLangId(); GetDeviceStringDesc(_manufacturer, _deviceDesc.indexManufacturer); GetDeviceStringDesc(_product, _deviceDesc.indexProduct); GetDeviceStringDesc(_serialNum, _deviceDesc.indexSerialNum); PrintDeviceStringDetails(); // inputContext->Control().SetAddContextFlag(0x1); // ConfigureEndPoint((unsigned)&inputContext->Control(), slotID); }
EHCIDevice::EHCIDevice(EHCIController& controller) : _controller(controller), _pControlQH(controller.CreateDeviceQueueHead(64, 0, 0)), _bFirstBulkRead(true), _bFirstBulkWrite(true) { if(!SetAddress()) throw upan::exception(XLOC, "SetAddress Failed"); USBStandardDeviceDesc devDesc; if(!GetDeviceDescriptor(&devDesc)) throw upan::exception(XLOC, "GetDevDesc Failed"); devDesc.DebugPrint(); char bConfigValue = 0; if(!GetConfigValue(bConfigValue)) throw upan::exception(XLOC, "GetConfigVal Failed") ; printf("\n ConfifValue: %d", bConfigValue) ; if(!CheckConfiguration(bConfigValue, devDesc.bNumConfigs)) throw upan::exception(XLOC, "CheckConfig Failed"); if(!GetConfigDescriptor(devDesc.bNumConfigs, &_pArrConfigDesc)) throw upan::exception(XLOC, "GeConfigDesc Failed"); USBDataHandler_CopyDevDesc(&_deviceDesc, &devDesc, sizeof(USBStandardDeviceDesc)) ; if(GetStringDescriptorZero()) SetLangId(); else // throw upan::exception(XLOC, "GetStringDescZero Failed"); printf("\n String DESC not supported!"); _iConfigIndex = 0 ; for(int i = 0; i < devDesc.bNumConfigs; i++) { if(_pArrConfigDesc[ i ].bConfigurationValue == bConfigValue) { _iConfigIndex = i; break ; } } GetDeviceStringDesc(_manufacturer, _deviceDesc.indexManufacturer); GetDeviceStringDesc(_product, _deviceDesc.indexProduct); GetDeviceStringDesc(_serialNum, _deviceDesc.indexSerialNum); PrintDeviceStringDetails(); }
// Initialize usb device. NTSTATUS UsbDev::InitializeUsbDevice(PVOID pDevExt) // shawn 2011/05/06 modify { NTSTATUS ntStatus = STATUS_SUCCESS; m_pDevExtTmp = pDevExt; // shawn 2011/05/06 add DBGU_TRACE(">>>UsbDev::InitializeUsbDevice !\n"); ntStatus = GetDeviceDescriptor(); if(NT_SUCCESS(ntStatus)) { ntStatus = GetConfigurationDescriptor(); if(NT_SUCCESS(ntStatus)) { ntStatus = SetConfiguration(); } } DBGU_TRACE("UsbDev::InitializeUsbDevice return %X\n", ntStatus); return ntStatus; }
NTSTATUS EXTERNAL HbtnInternalIoctl( IN PDEVICE_OBJECT DevObj, IN PIRP Irp ) { NTSTATUS status = STATUS_SUCCESS; PDEVICE_EXTENSION devext = GET_MINIDRIVER_DEVICE_EXTENSION(DevObj); PIO_STACK_LOCATION irpsp = IoGetCurrentIrpStackLocation(Irp); TEnter(Func,("(DevObj=%p,Irp=%p,IrpSp=%p,Ioctl=%s)\n", DevObj, Irp, irpsp, LookupName(irpsp->Parameters.DeviceIoControl.IoControlCode, HidIoctlNames))); Irp->IoStatus.Information = 0; status = IoAcquireRemoveLock(&devext->RemoveLock, Irp); if (!NT_SUCCESS(status)) { LogError(ERRLOG_DEVICE_REMOVED, status, UNIQUE_ERRID(0x10), NULL, NULL); TWarn(("received IRP after device was removed.\n")); Irp->IoStatus.Status = status; IoCompleteRequest(Irp, IO_NO_INCREMENT); } else if (!(devext->dwfHBtn & HBTNF_DEVICE_STARTED)) { IoReleaseRemoveLock(&devext->RemoveLock, Irp); status = STATUS_DEVICE_NOT_READY; LogError(ERRLOG_DEVICE_NOT_STARTED, status, UNIQUE_ERRID(0x20), NULL, NULL); TWarn(("digitizer is not started.\n")); Irp->IoStatus.Status = status; IoCompleteRequest(Irp, IO_NO_INCREMENT); } else { switch(irpsp->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_HID_GET_DEVICE_DESCRIPTOR: status = GetDeviceDescriptor(devext, Irp); break; case IOCTL_HID_GET_REPORT_DESCRIPTOR: status = GetReportDescriptor(devext, Irp); break; case IOCTL_HID_READ_REPORT: status = ReadReport(devext, Irp); break; case IOCTL_HID_WRITE_REPORT: status = OemWriteReport(devext, Irp); break; case IOCTL_HID_GET_STRING: status = GetString(devext, Irp); break; case IOCTL_HID_GET_DEVICE_ATTRIBUTES: status = GetAttributes(devext, Irp); break; case IOCTL_HID_ACTIVATE_DEVICE: case IOCTL_HID_DEACTIVATE_DEVICE: status = STATUS_SUCCESS; break; default: status = STATUS_NOT_SUPPORTED; LogError(ERRLOG_NOT_SUPPORTED, status, UNIQUE_ERRID(0x30), NULL, NULL); TWarn(("unsupported (IOCTL=%x).\n", irpsp->Parameters.DeviceIoControl.IoControlCode)); break; } if (status != STATUS_PENDING) { IoReleaseRemoveLock(&devext->RemoveLock, Irp); Irp->IoStatus.Status = status; IoCompleteRequest(Irp, IO_NO_INCREMENT); } else { IoMarkIrpPending(Irp); } } TExit(Func,("=%x\n", status)); return status; } //HbtnInternalIoctl