void DVS128Interface::sendVendorRequest(UCHAR req, const char *buf, DWORD bufSize){ CUsbIo dev; DWORD status; // open the device if(!dev.IsOpen()){ status = dev.Open(devIndex,devList,&usbIoID); if ( status != USBIO_ERR_SUCCESS ) { printf("Could not open device: %x",status); return; } } printf("Sending Vendor Request: %x\n", req); USBIO_CLASS_OR_VENDOR_REQUEST request; ZeroMemory(&request,sizeof(request)); request.Flags = 0; request.Type = RequestTypeVendor; request.Recipient = RecipientDevice; request.RequestTypeReservedBits = 0; request.Request = req; request.Value = 4; request.Index = 0; status = dev.ClassOrVendorOutRequest( buf, bufSize, &request ); printf("Status: %x\n",status); dev.Close(); }
void DVS128Interface::startReading(){ CUsbIo dev; USB_DEVICE_DESCRIPTOR devDesc; DWORD status; bool found = false; devList = CUsbIo::CreateDeviceList(&usbIoID); if (devList == NULL){ printf("Unable to build a device list!\n"); } // Open and query usb devices to find the right one for (int i = 0; i < 127; i++){ status = dev.Open(i,devList,&usbIoID); if ( status != USBIO_ERR_SUCCESS ) { if ( status != USBIO_ERR_NO_SUCH_DEVICE_INSTANCE ){ fprintf(stdout,"UsbDev.Open returned with error 0x%08X\n",status); } break; } // Query device descriptor for comparison with PID and VID status = dev.GetDeviceDescriptor(&devDesc); if ( status == USBIO_ERR_SUCCESS ){ found = true; if ( devDesc.iSerialNumber!=0 ){ dev.Close(); if (devDesc.idVendor == VID && devDesc.idProduct == PID){ fprintf(stdout,"Device found, starting reader.\n"); devIndex = i; startReaderThread(devIndex); break; } else { fprintf(stdout,"Device not recognized\n"); } } else { fprintf(stdout,"Querying device descriptor failed, status:0x%08X\n",status); dev.Close(); } } if ( !found ) { fprintf(stdout,"There are no USB devices attached to the USBIO driver.\n"); } else fprintf(stdout,"Device found..."); CUsbIo::DestroyDeviceList(devList); } }
static void OpenUsbDevice() { CUsbIo::DestroyDeviceList(g_DevList); // Enumerate attached USB devices supported by USBIO g_DevList = CUsbIo::CreateDeviceList(&g_UsbioID); // Open first device in list dwRC = g_UsbDev.Open(0, g_DevList, &g_UsbioID); PRINT_IF_VERBOSE1("\nCUsbIo::Open returned <0x%X>\n", dwRC); if (dwRC == USBIO_ERR_VERSION_MISMATCH) { printf("\n* Error: \"The API version reported by the USBRFLCT driver\n" \ "* does not match the expected version.\"\n"); printf("* The driver will need to be updated as follows:\n"); printf("* 1. Connect the device to the PC & start T_USB,\n" \ "* then find the USB device in the Windows Device Manager\n" \ "* ('Control Panel'->'System'->'Hardware'->'Device Manager').\n" \ "* Right click on the device name and choose 'Uninstall...'.\n"); printf("* 2. In c:\\winnt\\inf\\, find (by searching for \"Symbian\") and\n" \ "* delete the *.INF file that was used to install the existing\n" \ "* version of USBRFLCT.SYS. Make sure to also delete the\n" \ "* precompiled version of that file (<samename>.PNF).\n"); printf("* 3. In c:\\winnt\\system32\\drivers\\, delete the file USBRFLCT.SYS.\n"); printf("* Then unplug & reconnect the USB device and, when prompted, install\n" \ "* the new USBRFLCT.SYS driver using the .INF file from this distribution.\n" \ "* (All files can be found under e32test\\win32\\usbrflct_distribution\\.)\n"); } }
static void SetConfiguration() { USBIO_SET_CONFIGURATION SetConfig; memset(&SetConfig, 0, sizeof(USBIO_SET_CONFIGURATION)); // Set the first configuration as active SetConfig.ConfigurationIndex = 0; SetConfig.NbOfInterfaces = 1; SetConfig.InterfaceList[0].InterfaceIndex = 0; SetConfig.InterfaceList[0].AlternateSettingIndex = 0; SetConfig.InterfaceList[0].MaximumTransferSize = KBufferSize; dwRC = g_UsbDev.SetConfiguration(&SetConfig); PRINT_IF_VERBOSE1("CUsbIo::SetConfiguration returned <0x%X>\n", dwRC); }
static void GetDeviceDescriptor() { USB_DEVICE_DESCRIPTOR DeviceDescriptor; memset(&DeviceDescriptor, 0, sizeof(USB_DEVICE_DESCRIPTOR)); // Get device descriptor dwRC = g_UsbDev.GetDeviceDescriptor(&DeviceDescriptor); PRINT_IF_VERBOSE1("CUsbIo::GetDeviceDescriptor returned <0x%X>\n", dwRC); if (VerboseMode && (dwRC == USBIO_ERR_SUCCESS)) { printf("\nDEVICE DESCRIPTOR:\n" "bLength = <%u>\n" "bDescriptorType = <%u>\n" "bcdUSB = <%u>\n" "bDeviceClass = <%u>\n" "bDeviceSubClass = <%u>\n" "bDeviceProtocol = <%u>\n" "bMaxPacketSize0 = <%u>\n" "idVendor = <%u>\n" "idProduct = <%u>\n" "bcdDevice = <%u>\n" "iManufacturer = <%u>\n" "iProduct = <%u>\n" "iSerialNumber = <%u>\n" "bNumConfigurations = <%u>\n\n", DeviceDescriptor.bLength, DeviceDescriptor.bDescriptorType, DeviceDescriptor.bcdUSB, DeviceDescriptor.bDeviceClass, DeviceDescriptor.bDeviceSubClass, DeviceDescriptor.bDeviceProtocol, DeviceDescriptor.bMaxPacketSize0, DeviceDescriptor.idVendor, DeviceDescriptor.idProduct, DeviceDescriptor.bcdDevice, DeviceDescriptor.iManufacturer, DeviceDescriptor.iProduct, DeviceDescriptor.iSerialNumber, DeviceDescriptor.bNumConfigurations); } }
void DVS128Interface::startReaderThread(int devIndex){ CUsbIo dev; //Device instance USBIO_SET_CONFIGURATION config; // Device config DWORD status; // open the device status = dev.Open(devIndex,devList,&usbIoID); if ( status != USBIO_ERR_SUCCESS ) { printf("Could not open device: %x\n",status); return; } // set up the configuration request ZeroMemory(&config,sizeof(config)); config.ConfigurationIndex = CFG_INDEX; config.NbOfInterfaces = CFG_NUM_INTERFACES; config.InterfaceList[0].InterfaceIndex = CFG_INTERFACE; config.InterfaceList[0].AlternateSettingIndex = CFG_ALTSETTING; config.InterfaceList[0].MaximumTransferSize = CFG_MAX_TRANSFER; // configure the device printf("Configuring...\n"); status = dev.SetConfiguration(&config); if ( status != USBIO_ERR_SUCCESS ) { printf("Could not configure device: %x\n",status); return; } status = reader->Bind(devIndex,ENDPOINT,devList,&usbIoID); if ( status != USBIO_ERR_SUCCESS ) { printf("Binding failed.\n"); dev.UnconfigureDevice(); return; } if ( !reader->AllocateBuffers(ENDPOINT_FIFO_SIZE, NUM_BUFFERS) ) { printf("Unable to allocate buffer pool.\n"); dev.UnconfigureDevice(); return; } // start the reader thread printf("Starting reader thread...\n"); if ( !reader->StartThread() ) { printf("Unable to start reader thread.\n"); dev.UnconfigureDevice(); return; } sendVendorRequest(START_READ); }
static void GetStringDescriptor() { CHAR szBuffer[MAX_DESCRIPTOR_BUFFER_SIZE] = ""; USB_STRING_DESCRIPTOR* pStringDescriptor = NULL; DWORD dwByteCount = MAX_DESCRIPTOR_BUFFER_SIZE; memset(szBuffer, 0, sizeof(szBuffer)); // Get string descriptor dwRC = g_UsbDev.GetStringDescriptor((USB_STRING_DESCRIPTOR*) szBuffer, dwByteCount, 1, 0); PRINT_IF_VERBOSE1("CUsbIo::GetStringDescriptor returned <0x%X>\n", dwRC); if (dwRC == USBIO_ERR_SUCCESS) { pStringDescriptor = (USB_STRING_DESCRIPTOR*) szBuffer; if (VerboseMode) { printf("\nSTRING DESCRIPTOR:\n" "bLength = <%u>\n" "bDescriptorType = <%u>\n" "bString = <", // output continues below! pStringDescriptor->bLength, pStringDescriptor->bDescriptorType); } INT i = 0; CHAR* Ptr = szBuffer; for (i = 2, Ptr += 2; i < pStringDescriptor->bLength; i += 2, Ptr += 2) { PRINT_IF_VERBOSE1("%c", *Ptr); } PRINT_IF_VERBOSE(">\n\n"); } }
static void GetConfigurationInfo() { USBIO_CONFIGURATION_INFO ConfigInfo; USHORT i = 0; memset(&ConfigInfo, 0, sizeof(USBIO_CONFIGURATION_INFO)); dwRC = g_UsbDev.GetConfigurationInfo(&ConfigInfo); PRINT_IF_VERBOSE1("CUsbIo::GetConfigurationInfo returned <0x%X>\n", dwRC); if (dwRC == USBIO_ERR_SUCCESS) { if (VerboseMode) { printf("\nCONFIGURATION INFO:\n" "NbOfInterfaces = <%lu>\n" "NbOfPipes = <%lu>\n", ConfigInfo.NbOfInterfaces, ConfigInfo.NbOfPipes); } for (i = 0; i < ConfigInfo.NbOfInterfaces; i++) { if (VerboseMode) { printf("\nINTERFACE <%u>:\n", i + 1); printf("InterfaceNumber = <%u>\n" "AlternateSetting = <%u>\n" "Class = <%u>\n" "SubClass = <%u>\n" "Protocol = <%u>\n" "NumberOfPipes = <%u>\n" "reserved1 = <%u>\n" "reserved2 = <%u>\n", ConfigInfo.InterfaceInfo[i].InterfaceNumber, ConfigInfo.InterfaceInfo[i].AlternateSetting, ConfigInfo.InterfaceInfo[i].Class, ConfigInfo.InterfaceInfo[i].SubClass, ConfigInfo.InterfaceInfo[i].Protocol, ConfigInfo.InterfaceInfo[i].NumberOfPipes, ConfigInfo.InterfaceInfo[i].reserved1, ConfigInfo.InterfaceInfo[i].reserved2); } } for (i = 0; i < ConfigInfo.NbOfPipes; i++) { PRINT_IF_VERBOSE("\n"); if ((ConfigInfo.PipeInfo[i].PipeType == PipeTypeBulk) && !(ConfigInfo.PipeInfo[i].EndpointAddress & 0x80)) { PRINT_IF_VERBOSE("Bulk OUT pipe found:\n"); g_ucBulkOutEndpoint = ConfigInfo.PipeInfo[i].EndpointAddress; maxOutPacketSize = ConfigInfo.PipeInfo[i].MaximumPacketSize; } else if ((ConfigInfo.PipeInfo[i].PipeType == PipeTypeBulk) && (ConfigInfo.PipeInfo[i].EndpointAddress & 0x80)) { PRINT_IF_VERBOSE("Bulk IN pipe found:\n"); g_ucBulkInEndpoint = ConfigInfo.PipeInfo[i].EndpointAddress; } if (VerboseMode) { printf("PIPE <%u>\n", i + 1); printf("PipeType = <%d>\n" "MaximumTransferSize = <%lu>\n" "MaximumPacketSize = <%u>\n" "EndpointAddress = <%u>\n" "Interval = <%u>\n" "InterfaceNumber = <%u>\n" "reserved1 = <%u>\n" "reserved2 = <%u>\n" "reserved3 = <%u>\n", ConfigInfo.PipeInfo[i].PipeType, ConfigInfo.PipeInfo[i].MaximumTransferSize, ConfigInfo.PipeInfo[i].MaximumPacketSize, ConfigInfo.PipeInfo[i].EndpointAddress, ConfigInfo.PipeInfo[i].Interval, ConfigInfo.PipeInfo[i].InterfaceNumber, ConfigInfo.PipeInfo[i].reserved1, ConfigInfo.PipeInfo[i].reserved2, ConfigInfo.PipeInfo[i].reserved3); } } } PRINT_IF_VERBOSE("\n"); }
static void GetConfigurationDescriptor() { CHAR szBuffer[MAX_DESCRIPTOR_BUFFER_SIZE] = ""; USB_CONFIGURATION_DESCRIPTOR* pConfigDescriptor = NULL; USB_INTERFACE_DESCRIPTOR* pInterfaceDescriptor = NULL; USB_ENDPOINT_DESCRIPTOR* pEndpointDescriptor = NULL; DWORD dwByteCount = MAX_DESCRIPTOR_BUFFER_SIZE; memset(szBuffer, 0, sizeof(szBuffer)); // Get first configuration descriptor dwRC = g_UsbDev.GetConfigurationDescriptor((USB_CONFIGURATION_DESCRIPTOR*) szBuffer, dwByteCount, 0); PRINT_IF_VERBOSE1("CUsbIo::GetConfigurationDescriptor returned <0x%X>\n", dwRC); if (dwRC == USBIO_ERR_SUCCESS) { USB_COMMON_DESCRIPTOR* Desc; ULONG rl = dwByteCount; ULONG ulDescLength = 0; CHAR* data = szBuffer; while (rl > 0) { Desc = (USB_COMMON_DESCRIPTOR*) data; ulDescLength = Desc->bLength; if ((ulDescLength > rl) || (ulDescLength == 0)) { printf("Length remaining too short!\n"); rl = 0; } else { switch (Desc->bDescriptorType) { case USB_CONFIGURATION_DESCRIPTOR_TYPE: pConfigDescriptor = (USB_CONFIGURATION_DESCRIPTOR*) data; if (VerboseMode) { printf("\nCONFIGURATION DESCRIPTOR:\n" "bLength = <%u>\n" "bDescriptorType = <%u>\n" "wTotalLength = <%u>\n" "bNumInterfaces = <%u>\n" "bConfigurationValue = <%u>\n" "iConfiguration = <%u>\n" "bmAttributes = <%u>\n" "MaxPower = <%u>\n", pConfigDescriptor->bLength, pConfigDescriptor->bDescriptorType, pConfigDescriptor->wTotalLength, pConfigDescriptor->bNumInterfaces, pConfigDescriptor->bConfigurationValue, pConfigDescriptor->iConfiguration, pConfigDescriptor->bmAttributes, pConfigDescriptor->MaxPower); } break; case USB_INTERFACE_DESCRIPTOR_TYPE: pInterfaceDescriptor = (USB_INTERFACE_DESCRIPTOR*) data; if (VerboseMode) { printf("\nINTERFACE DESCRIPTOR: \n" "bLength = <%u>\n" "bDescriptorType = <%u>\n" "bInterfaceNumber = <%u>\n" "bAlternateSetting = <%u>\n" "bNumEndpoints = <%u>\n" "bInterfaceClass = <%u>\n" "bInterfaceSubClass = <%u>\n" "bInterfaceProtocol = <%u>\n" "iInterface = <%u>\n", pInterfaceDescriptor->bLength, pInterfaceDescriptor->bDescriptorType, pInterfaceDescriptor->bInterfaceNumber, pInterfaceDescriptor->bAlternateSetting, pInterfaceDescriptor->bNumEndpoints, pInterfaceDescriptor->bInterfaceClass, pInterfaceDescriptor->bInterfaceSubClass, pInterfaceDescriptor->bInterfaceProtocol, pInterfaceDescriptor->iInterface); } break; case USB_ENDPOINT_DESCRIPTOR_TYPE: pEndpointDescriptor = (USB_ENDPOINT_DESCRIPTOR*) data; if (VerboseMode) { printf("\nENDPOINT DESCRIPTOR: \n" "bLength = <%u>\n" "bDescriptorType = <%u>\n" "bEndpointAddress = <%u>\n" "bmAttributes = <%u>\n" "wMaxPacketSize = <%u>\n" "bInterval = <%u>\n", pEndpointDescriptor->bLength, pEndpointDescriptor->bDescriptorType, pEndpointDescriptor->bEndpointAddress, pEndpointDescriptor->bmAttributes, pEndpointDescriptor->wMaxPacketSize, pEndpointDescriptor->bInterval); } break; default: break; } } data += ulDescLength; rl -= ulDescLength; } } PRINT_IF_VERBOSE("\n"); }
static void CloseUsbDevice() { // Close the device g_UsbDev.Close(); PRINT_IF_VERBOSE("CUsbIo::Close called\n"); }