LibUsb::LibUsb(int type) : type(type) { intf = NULL; readBufIndex = 0; readBufSize = 0; // Initialize the library. usb_init(); usb_set_debug(0); usb_find_busses(); usb_find_devices(); }
usb_dev_handle * open_usb_device(int vid, int pid) { struct usb_bus *bus; struct usb_device *dev; usb_dev_handle *h; char buf[128]; int r; usb_init(); usb_find_busses(); usb_find_devices(); //printf_verbose("\nSearching for USB device:\n"); for (bus = usb_get_busses(); bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { //printf_verbose("bus \"%s\", device \"%s\" vid=%04X, pid=%04X\n", // bus->dirname, dev->filename, // dev->descriptor.idVendor, // dev->descriptor.idProduct //); if (dev->descriptor.idVendor != vid) continue; if (dev->descriptor.idProduct != pid) continue; h = usb_open(dev); if (!h) { printf_verbose("Found device but unable to open"); continue; } #ifdef LIBUSB_HAS_GET_DRIVER_NP r = usb_get_driver_np(h, 0, buf, sizeof(buf)); if (r >= 0) { r = usb_detach_kernel_driver_np(h, 0); if (r < 0) { usb_close(h); printf_verbose("Device is in use by \"%s\" driver", buf); continue; } } #endif // Mac OS-X - removing this call to usb_claim_interface() might allow // this to work, even though it is a clear misuse of the libusb API. // normally Apple's IOKit should be used on Mac OS-X r = usb_claim_interface(h, 0); if (r < 0) { usb_close(h); printf_verbose("Unable to claim interface, check USB permissions"); continue; } return h; } } return NULL; }
int ftdi_context_refresh(ftdi_context_t* context) { struct usb_bus* libusb_bus; struct usb_device* libusb_device; struct ftdi_context* libftdi_context; int i = 0; error_clear(&context->error); if (context->num_references) { if (context->num_devices) { for (i = 0; i < context->num_devices; ++i) ftdi_device_destroy(&context->devices[i]); free(context->devices); context->devices = 0; context->num_devices = 0; } usb_init(); if ((usb_find_busses() > 0) && (usb_find_devices() > 0)) { for (libusb_bus = usb_get_busses(); libusb_bus; libusb_bus = libusb_bus->next) for (libusb_device = libusb_bus->devices; libusb_device; libusb_device = libusb_device->next) if (libusb_device->descriptor.idVendor == FTDI_VENDOR_ID) context->num_devices++; } if (context->num_devices) { context->devices = malloc(context->num_devices*sizeof(ftdi_device_t)); i = 0; for (libusb_bus = usb_get_busses(); libusb_bus; libusb_bus = libusb_bus->next) for (libusb_device = libusb_bus->devices; libusb_device; libusb_device = libusb_device->next) if (libusb_device->descriptor.idVendor == FTDI_VENDOR_ID) { libftdi_context = ftdi_new(); ftdi_init(libftdi_context); ftdi_device_init(&context->devices[i], libftdi_context, libusb_bus, libusb_device); i++; } } } else error_set(&context->error, FTDI_ERROR_INVALID_CONTEXT); return error_get(&context->error); }
//-------------------------------------------------------------------------- void find_device(t_heavybox *x) { usb_dev_handle *handle = NULL; struct usb_bus *bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); for(bus=usb_busses; bus; bus=bus->next){ for(dev=bus->devices; dev; dev=dev->next){ if(dev->descriptor.idVendor == USBDEV_SHARED_VENDOR && dev->descriptor.idProduct == USBDEV_SHARED_PRODUCT){ char string[256]; int len; handle = usb_open(dev); /* we need to open the device in order to query strings */ if(!handle){ error ("Warning: cannot open USB device: %s", usb_strerror()); continue; } /* now find out whether the device actually is heavybox */ len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string)); if(len < 0){ post("heavybox: warning: cannot query manufacturer for device: %s", usb_strerror()); goto skipDevice; } if(strcmp(string, USB_CFG_VENDOR_NAME) != 0) goto skipDevice; len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string)); if(len < 0){ post("heavybox: warning: cannot query product for device: %s", usb_strerror()); goto skipDevice; } if(strcmp(string, USB_CFG_DEVICE_NAME) == 0) break; skipDevice: usb_close(handle); handle = NULL; } } if(handle) break; } if(!handle){ post("Could not find USB device workinprogress.ca/heavybox"); x->dev_handle = NULL; } else { x->dev_handle = handle; post("Found USB device workinprogress.ca/heavybox"); } }
static usb_dev_handle *find_usb_device(uint16_t VID, uint16_t PID, uint8_t interface, char *serialstring, char *productstring) { usb_dev_handle *dev_handle = NULL; struct usb_bus *busses; struct usb_bus *bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == VID) && (dev->descriptor.idProduct == PID)) { dev_handle = usb_open(dev); if (NULL == dev_handle) { LOG_ERROR("failed to open %04X:%04X, %s", VID, PID, usb_strerror()); continue; } /* check description string */ if ((productstring != NULL && !usb_check_string(dev_handle, dev->descriptor.iProduct, productstring, NULL, 0)) || (serialstring != NULL && !usb_check_string(dev_handle, dev->descriptor.iSerialNumber, serialstring, NULL, 0))) { usb_close(dev_handle); dev_handle = NULL; continue; } if (usb_claim_interface(dev_handle, interface) != 0) { LOG_ERROR(ERRMSG_FAILURE_OPERATION_MESSAGE, "claim interface", usb_strerror()); usb_close(dev_handle); dev_handle = NULL; continue; } if (dev_handle != NULL) return dev_handle; } } } return dev_handle; }
int _ykusb_start(void) { int rc; usb_init(); rc = usb_find_busses(); if (rc >= 0) rc = usb_find_devices(); if (rc >= 0) return 1; yk_errno = YK_EUSBERR; return 0; }
int main(int argc, char *argv[]) { struct usb_bus *bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); for(bus = usb_get_busses(); bus; bus = bus->next) { for(dev = bus->devices; dev; dev = dev->next) { if((dev->descriptor.idVendor == LCD2USB_VID) && (dev->descriptor.idProduct == LCD2USB_PID)) { handle = usb_open(dev); break; } } } if(!handle) { fprintf(stderr, "Error: Could not find LCD2USB device\n"); exit(-1); } lcd_clear(); int i = 0; while (!feof(stdin)) { char line[1024]; fgets(line, sizeof(line), stdin); if (feof(stdin)) break; line[strlen(line)-1] = '\0'; if(strlen(line) == 0) { lcd_clear(); lcd_clear(); i = 0; continue; } lcd_write(line); i += strlen(line); while (i % 20 != 0) { lcd_write(" "); i++; } } usb_close(handle); return 0; }
static void xusb_init() { if (!initizalized) { xtalk_parse_options(); if (!xtalk_option_no_lock()) xusb_lock_usb(); usb_init(); usb_find_busses(); usb_find_devices(); initizalized = 1; if (!xtalk_option_no_lock()) xusb_unlock_usb(); } }
static int gp_port_usb_init (GPPort *port) { port->pl = malloc (sizeof (GPPortPrivateLibrary)); if (!port->pl) return (GP_ERROR_NO_MEMORY); memset (port->pl, 0, sizeof (GPPortPrivateLibrary)); port->pl->config = port->pl->interface = port->pl->altsetting = -1; usb_init (); usb_find_busses (); usb_find_devices (); return (GP_OK); }
// This is an example of an exported function. APN_USB_TYPE ApnUsbOpen( unsigned short /*DevNumber*/ ) { /*char deviceName[128];*/ struct usb_bus *bus; struct usb_device *dev; struct usb_dev_handle *hDevice(NULL); usb_init(); usb_find_busses(); usb_find_devices(); /*char string[256];*/ int found = 0; /* find ALTA device */ for(bus = usb_busses; bus && !found; bus = bus->next) { for(dev = bus->devices; dev && !found; dev = dev->next) { if (dev->descriptor.idVendor == USB_ALTA_VENDOR_ID && dev->descriptor.idProduct == USB_ALTA_PRODUCT_ID) { hDevice = usb_open(dev); // cerr << "Found ALTA USB. Attempting to open... "; found = 1; if (hDevice) { // if (!usb_get_string_simple(hDevice, // dev->descriptor.iSerialNumber, // string, sizeof(string))) // throw DevOpenError(); // cerr << "Success.\n"; // cerr << "Serial number: " << string << endl; } else return APN_USB_ERR_OPEN; } } } if (!found) return APN_USB_ERR_OPEN; // if (!usb_set_configuration(hDevice, 0x0)) return APN_USB_ERR_OPEN; if (!usb_claim_interface(hDevice, 0x0)) return APN_USB_ERR_OPEN; g_hSysDriver = hDevice; g_UsbImgSizeBytes = 0; // printf("DRIVER: opened device\n"); return APN_USB_SUCCESS; // Success }
transport_t rf2500_open(const char *devpath, const char *requested_serial) { struct rf2500_transport *tr = malloc(sizeof(*tr)); struct usb_device *dev; char buf[64]; if (!tr) { pr_error("rf2500: can't allocate memory"); return NULL; } tr->base.destroy = usbtr_destroy; tr->base.send = usbtr_send; tr->base.recv = usbtr_recv; usb_init(); usb_find_busses(); usb_find_devices(); if (devpath) dev = usbutil_find_by_loc(devpath); else dev = usbutil_find_by_id(USB_FET_VENDOR, USB_FET_PRODUCT, requested_serial); if (!dev) { free(tr); return NULL; } if (open_device(tr, dev) < 0) { printc_err("rf2500: failed to open RF2500 device\n"); return NULL; } /* Flush out lingering data. * * The timeout apparently doesn't work on OS/X, and this loop * just hangs once the endpoint buffer empties. */ #ifndef __APPLE__ while (usb_bulk_read(tr->handle, USB_FET_IN_EP, buf, sizeof(buf), 100) > 0); #endif return (transport_t)tr; }
void *p_trbs_thread(void *parameters) { struct usb_bus *bus; struct usb_device *device; struct usb_dev_handle *handler; struct s_exception *exception = NULL; struct s_trbs_parameters *local_parameters = (struct s_trbs_parameters *)parameters; int index, append; while ((p_trbs_thread_continue(local_parameters->object)) && (usleep(local_parameters->sleep)==0)) { d_object_lock(local_parameters->object->search_semaphore); if ((usb_find_busses()) | (usb_find_devices())) { for (bus = usb_get_busses(); bus; bus = bus->next) for (device = bus->devices; device; device = device->next) if (!p_trbs_thread_already(local_parameters->object, device)) { append = d_false; if ((handler = usb_open(device))) { if (p_trb_check(device, handler, NULL)) { d_try { if ((local_parameters->trb_handle) && (local_parameters->trb_handle(f_trb_new(NULL, device, handler), local_parameters->trb_data))) append = d_true; else usb_close(handler); } d_catch(exception) { /* here we have an already acquired device */ usb_close(handler); } d_endtry; } else if ((local_parameters->dev_handle) && (local_parameters->dev_handle(device, handler, local_parameters->dev_data))) append = d_true; else usb_close(handler); } if (append) for (index = 0; index < d_trbs_slots_size; index++) if (!local_parameters->object->devices[index].device) { local_parameters->object->devices[index].device = device; local_parameters->object->devices[index].referenced = d_true; break; } } for (index = 0; index < d_trbs_slots_size; index++) { if (local_parameters->object->devices[index].device) if (!local_parameters->object->devices[index].referenced) local_parameters->object->devices[index].device = NULL; local_parameters->object->devices[index].referenced = d_false; } }
/* find a compatible USB receiver and return a usb_device, * or NULL on failure. */ static struct usb_device* find_usb_device(void) { struct usb_bus* usb_bus; struct usb_device* dev; usb_init(); usb_find_busses(); usb_find_devices(); for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) { for (dev = usb_bus->devices; dev; dev = dev->next) if (is_device_ok(dev)) return dev; } return NULL; /* no suitable device found */ }
int main(void) { usb_dev_handle *dev = NULL; /* the device handle */ char tmp[BUF_SIZE]; usb_init(); /* initialize the library */ usb_find_busses(); /* find all busses */ usb_find_devices(); /* find all connected devices */ if(!(dev = open_dev())) { printf("error: device not found!\n"); return 0; } if(usb_set_configuration(dev, 1) < 0) { printf("error: setting config 1 failed\n"); usb_close(dev); return 0; } if(usb_claim_interface(dev, 0) < 0) { printf("error: claiming interface 0 failed\n"); usb_close(dev); return 0; } if(usb_bulk_write(dev, EP_OUT, tmp, sizeof(tmp), 5000) != sizeof(tmp)) { printf("error: bulk write failed\n"); } if(usb_bulk_read(dev, EP_IN, tmp, sizeof(tmp), 5000) != sizeof(tmp)) { printf("error: bulk read failed\n"); } usb_release_interface(dev, 0); usb_close(dev); return 0; }
void initialize(void){ int i, ret; usb_set_debug(0); usb_init(); usb_find_busses(); usb_find_devices(); t = TemperCreateFromDeviceNumber(0, USB_TIMEOUT, 0); if(!t) { perror("TemperCreate"); exit(-1); } }
static int drv_BW_open(void) { struct usb_bus *busses, *bus; struct usb_device *dev; lcd = NULL; info("%s: scanning USB for BWCT LCD...", Name); usb_set_debug(0); usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { int c; if (dev->descriptor.idVendor != LCD_USB_VENDOR) continue; /* Loop through all of the configurations */ for (c = 0; c < dev->descriptor.bNumConfigurations; c++) { int i; for (i = 0; i < dev->config[c].bNumInterfaces; i++) { int a; for (a = 0; a < dev->config[c].interface[i].num_altsetting; a++) { if ((dev->descriptor.idProduct == LCD_USB_DEVICE) || ((dev->config[c].interface[i].altsetting[a].bInterfaceClass == 0xff) && (dev->config[c].interface[i].altsetting[a].bInterfaceSubClass == 0x01))) { info("%s: found BWCT USB LCD on bus %s device %s", Name, bus->dirname, dev->filename); interface = i; lcd = usb_open(dev); if (usb_claim_interface(lcd, interface) < 0) { error("%s: usb_claim_interface() failed!", Name); return -1; } return 0; } } } } } } return -1; }
transport_t olimex_open(const char *devpath, const char *requested_serial) { struct olimex_transport *tr = malloc(sizeof(*tr)); struct usb_device *dev; char buf[64]; if (!tr) { pr_error(__FILE__": can't allocate memory"); return NULL; } tr->base.destroy = usbtr_destroy; tr->base.send = usbtr_send; tr->base.recv = usbtr_recv; usb_init(); usb_find_busses(); usb_find_devices(); if (devpath) { dev = usbutil_find_by_loc(devpath); } else { dev = usbutil_find_by_id(USB_FET_VENDOR, V1_PRODUCT, requested_serial); if (!dev) dev = usbutil_find_by_id(USB_FET_VENDOR, V2_PRODUCT, requested_serial); } if (!dev) { free(tr); return NULL; } if (open_device(tr, dev) < 0) { printc_err(__FILE__ ": failed to open Olimex device\n"); return NULL; } /* Flush out lingering data */ while (usb_bulk_read(tr->handle, tr->in_ep, buf, sizeof(buf), 100) > 0); return (transport_t)tr; }
HardwareThunder::HardwareThunder(QObject *parent) : Hardware(parent), m_usbHandler(NULL) { usb_init(); usb_find_busses(); usb_find_devices(); struct usb_bus *busses = usb_get_busses(); for (struct usb_bus *bus = busses; bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.idVendor == 0x2123 && dev->descriptor.idProduct == 0x1010) { qDebug() << "Found USB Raketenwerfer"; m_usbHandler = usb_open(dev); if (m_usbHandler) { int claimed = usb_claim_interface(m_usbHandler, 0); if (claimed == 0) { qDebug() << "USB claimed"; // TODO return; } else { qWarning() << "Error claiming USB interface:" << usb_strerror(); } } else { qWarning() << "Could not open USB device:" << usb_strerror(); } } } } qWarning() << "Could not find USB device"; }
static struct usb_device *findDev(uint16_t vendor, uint16_t product) { struct usb_bus *bus; struct usb_device *dev; struct usb_bus *busses; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) for (dev = bus->devices; dev; dev = dev->next) if ((dev->descriptor.idVendor == vendor) && (dev->descriptor.idProduct == product)) { return dev; } return NULL; }
bool LibUsb::find() { usb_set_debug(0); usb_find_busses(); usb_find_devices(); switch (type) { // Search USB busses for USB2 ANT+ stick host controllers default: case TYPE_ANT: return findAntStick(); break; case TYPE_FORTIUS: return findFortius(); break; } }
static struct usb_device *device_init(void) { struct usb_bus *usb_bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) { for (dev = usb_bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == G9X_VENDOR_ID) && (dev->descriptor.idProduct == G9X_PRODUCT_ID)) return dev; } } return NULL; }
usb_dev_handle* setup_libusb_access() { usb_dev_handle *lvr_winusb; if (debug) { usb_set_debug(255); } else { usb_set_debug(0); } usb_init(); usb_find_busses(); usb_find_devices(); if (!(lvr_winusb = find_lvr_winusb())) { printf("Couldn't find the USB device, exiting.\n"); return NULL; } usb_detach(lvr_winusb, INTERFACE1); usb_detach(lvr_winusb, INTERFACE2); // reset device if (usb_reset(lvr_winusb) != 0) { printf("Could not reset device.\n"); return NULL; } if (usb_set_configuration(lvr_winusb, 0x01) < 0) { printf("Could not set configuration 1.\n"); return NULL; } // Microdia tiene 2 interfaces if (usb_claim_interface(lvr_winusb, INTERFACE1) < 0) { printf("Could not claim interface.\n"); return NULL; } if (usb_claim_interface(lvr_winusb, INTERFACE2) < 0) { printf("Could not claim interface.\n"); return NULL; } return lvr_winusb; }
void UDMXOut::rescanDevices() { struct usb_device* dev; struct usb_bus* bus; /* Treat all devices as dead first, until we find them again. Those that aren't found, get destroyed at the end of this function. */ QList <UDMXDevice*> destroyList(m_devices); usb_find_busses(); usb_find_devices(); /* Iterate thru all buses */ for (bus = usb_get_busses(); bus != NULL; bus = bus->next) { /* Iterate thru all devices in each bus */ for (dev = bus->devices; dev != NULL; dev = dev->next) { UDMXDevice* udev; udev = device(dev); if (udev != NULL) { /* We already have this device and it's still there. Remove from the destroy list and continue iterating. */ destroyList.removeAll(udev); continue; } else if (UDMXDevice::isUDMXDevice(dev) == true) { /* This is a new device. Create and append. */ udev = new UDMXDevice(this, dev); m_devices.append(udev); } } } /* Destroy those devices that were no longer found. */ while (destroyList.isEmpty() == false) { UDMXDevice* udev = destroyList.takeFirst(); m_devices.removeAll(udev); delete udev; } }
int usb_ingenic_init(struct ingenic_dev *ingenic_dev, const char *bus_filter, const char *dev_filter) { int num_ingenic, status = -1; usb_init(); /* usb_set_debug(255); */ usb_find_busses(); usb_find_devices(); num_ingenic = get_ingenic_device(ingenic_dev, bus_filter, dev_filter); if (num_ingenic == 0) { fprintf(stderr, "Error - no XBurst device found\n"); goto out; } else if (num_ingenic > 1) { fprintf(stderr, "Error - too many XBurst devices found: %i\n", num_ingenic); goto out; } ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev); if (!ingenic_dev->usb_handle) { fprintf(stderr, "Error - can't open XBurst device: %s\n", usb_strerror()); goto out; } if (get_ingenic_interface(ingenic_dev)) { fprintf(stderr, "Error - can't find XBurst interface\n"); goto out; } if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface)) { fprintf(stderr, "Error - can't claim XBurst interface: %s\n", usb_strerror()); goto out; } status = 0; out: return status; }
/* This project uses the free shared default VID/PID. If you want to see an * example device lookup where an individually reserved PID is used, see our * RemoteSensor reference implementation. */ static usb_dev_handle *findDevice(void) { struct usb_bus *bus; struct usb_device *dev; usb_dev_handle *handle = 0; usb_find_busses(); usb_find_devices(); for(bus=usb_busses; bus; bus=bus->next){ for(dev=bus->devices; dev; dev=dev->next){ if(dev->descriptor.idVendor == USBDEV_SHARED_VENDOR && dev->descriptor.idProduct == USBDEV_SHARED_PRODUCT){ char string[256]; int len; handle = usb_open(dev); /* we need to open the device in order to query strings */ if(!handle){ fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror()); continue; } len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string)); if(len < 0){ fprintf(stderr, "warning: cannot query manufacturer for device: %s\n", usb_strerror()); goto skipDevice; } if(strcmp(string, "www.fischl.de") != 0) goto skipDevice; len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string)); if(len < 0){ fprintf(stderr, "warning: cannot query product for device: %s\n", usb_strerror()); goto skipDevice; } // fprintf(stderr, "seen product ->%s<-\n", string); if(strcmp(string, "AVRUSBBoot") == 0) break; skipDevice: usb_close(handle); handle = NULL; } } if(handle) break; } if(!handle) fprintf(stderr, "Could not find USB device www.fischl.de/AVRUSBBoot\n"); return handle; }
micronucleus* micronucleus_connect() { micronucleus *nucleus = NULL; struct usb_bus *busses; // intialise usb and find micronucleus device usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); struct usb_bus *bus; for (bus = busses; bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { /* Check if this device is a micronucleus */ if (dev->descriptor.idVendor == MICRONUCLEUS_VENDOR_ID && dev->descriptor.idProduct == MICRONUCLEUS_PRODUCT_ID) { nucleus = malloc(sizeof(micronucleus)); nucleus->version.major = (dev->descriptor.bcdUSB >> 8) & 0xFF; nucleus->version.minor = dev->descriptor.bcdUSB & 0xFF; if (nucleus->version.major > MICRONUCLEUS_MAX_MAJOR_VERSION) { fprintf(stderr, "Warning: device with unknown new version of Micronucleus detected.\n"); fprintf(stderr, "This tool doesn't know how to upload to this new device. Updates may be available.\n"); fprintf(stderr, "Device reports version as: %d.%d\n", nucleus->version.major, nucleus->version.minor); return NULL; } nucleus->device = usb_open(dev); // get nucleus info unsigned char buffer[6]; int res = usb_control_msg(nucleus->device, 0xC0, 0, 0, 0, buffer, 6, MICRONUCLEUS_USB_TIMEOUT); assert(res >= 4); nucleus->flash_size = (buffer[0]<<8) + buffer[1]; nucleus->data_length = (buffer[5]<<8) + buffer[4]; nucleus->page_size = buffer[2]; nucleus->pages = (nucleus->flash_size / nucleus->page_size); if (nucleus->pages * nucleus->page_size < nucleus->flash_size) nucleus->pages += 1; nucleus->write_sleep = buffer[3]; nucleus->erase_sleep = nucleus->write_sleep * nucleus->pages; } } }
static int bulk_init(const char *device) { struct usb_bus *bus; struct usb_device *dev; usb_init(); if (verbose) usb_set_debug(verbose); usb_find_busses(); usb_find_devices(); xsv_handle = NULL; for (bus = usb_busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if (device && strcmp(dev->filename, device) != 0) continue; if (dev->descriptor.idVendor == 0x2207 && (dev->descriptor.idProduct == 0x290a || dev->descriptor.idProduct == 0x292a || dev->descriptor.idProduct == 0x281a)) { xsv_handle = usb_open(dev); if (verbose) { printf("using rockchip device @ %s\n", dev->filename); } break; } } } if (xsv_handle) { usb_set_configuration(xsv_handle,1); usb_claim_interface(xsv_handle,0); usb_set_altinterface(xsv_handle,0); return 0; } else { return -1; } }
int littlewire_search() { struct usb_bus *bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); lw_totalDevices = 0; for (bus = usb_busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { usb_dev_handle *udev; char description[256]; char string[256]; int ret, i; if((dev->descriptor.idVendor == VENDOR_ID) && (dev->descriptor.idProduct == PRODUCT_ID)) { udev = usb_open(dev); if (udev) { if (dev->descriptor.iSerialNumber) { ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string)); if (ret > 0) { lwResults[lw_totalDevices].serialNumber = atoi(string); lwResults[lw_totalDevices].lw_device = dev; lw_totalDevices++; } else { printf("Connection error! Try creating a udev rule or running with sudo.\n"); } } usb_close(udev); } } } } return lw_totalDevices; }
/** * Opens driver and returns the handle. Returns NULL on failure. */ V2U_HANDLE v2u_open_driver_idx(int idx) { int index = 0; struct usb_bus * bus; usb_init(); usb_find_busses(); usb_find_devices(); for (bus = usb_get_busses(); bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { if (VGA2USB_IS_ANY( dev->descriptor.idVendor, dev->descriptor.idProduct, dev->descriptor.iProduct, dev->descriptor.iManufacturer)) { if (index == idx) { int fd; char name[256]; sprintf(name,"/proc/bus/usb/%s/%s", dev->bus->dirname, dev->filename); fd = open(name, O_RDWR); if (fd < 0) { #if DEBUG fprintf(stderr,"cannot open %s: %s\n",name,strerror(errno)); #endif } else { V2U_DRIVER* driver = malloc(sizeof(V2U_DRIVER)); if (driver) { driver->fd = fd; return driver; } close(fd); } break; } else { index++; } } } } return NULL; }
int usbsign_open(int vendorid, int productid, int interface, usbsign_handle** dev) { usb_init(); usb_find_busses(); usb_find_devices(); struct usb_bus* bus; struct usb_device* usbdev; int found = 0; for (bus = usb_get_busses(); bus; bus = bus->next) { config_debug("BUS: %s",bus->dirname); for (usbdev = bus->devices; usbdev; usbdev = usbdev->next) { struct usb_device_descriptor *desc = &(usbdev->descriptor); config_debug(" Device: %s", usbdev->filename); config_debug(" %x:%x",desc->idVendor,desc->idProduct); if (usbdev->descriptor.idVendor == vendorid && usbdev->descriptor.idProduct == productid) { found = 1; break; } } if (found > 0) { break; } } if (found > 0) { *dev = usb_open(usbdev); } else { *dev = NULL; } if (*dev == NULL) { config_error("Could not find/open USB device with vid=0x%X pid=0x%X. Is the sign plugged in?", vendorid, productid); return -1; } int ret = usb_claim_interface(*dev, interface); if (ret < 0) { config_error("Could not claim device (%d)", ret); return ret; } return 0; }