/************************************************************************* * FUNCTION * custom_usb_create * * DESCRIPTION * Customize usb create function. * Return KAL_FALSE directly if usb should not be created. * * PARAMETERS * * RETURNS * * GLOBALS AFFECTED * *************************************************************************/ kal_bool custom_usb_create(comptask_handler_struct **handle) { #ifdef __USB_ENABLE__ return usb_create(handle); #else return KAL_FALSE; #endif }
static USBDevice *usb_serial_init(USBBus *bus, const char *filename) { USBDevice *dev; CharDriverState *cdrv; uint32_t vendorid = 0, productid = 0; char label[32]; static int index; while (*filename && *filename != ':') { const char *p; char *e; if (strstart(filename, "vendorid=", &p)) { vendorid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { error_report("bogus vendor ID %s", p); return NULL; } filename = e; } else if (strstart(filename, "productid=", &p)) { productid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { error_report("bogus product ID %s", p); return NULL; } filename = e; } else { error_report("unrecognized serial USB option %s", filename); return NULL; } while(*filename == ',') filename++; } if (!*filename) { error_report("character device specification needed"); return NULL; } filename++; snprintf(label, sizeof(label), "usbserial%d", index++); cdrv = qemu_chr_new(label, filename, NULL); if (!cdrv) return NULL; dev = usb_create(bus, "usb-serial"); if (!dev) { return NULL; } qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); if (vendorid) qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid); if (productid) qdev_prop_set_uint16(&dev->qdev, "productid", productid); qdev_init_nofail(&dev->qdev); return dev; }
static USBDevice *usb_msd_init(const char *filename) { static int nr=0; char id[8]; QemuOpts *opts; DriveInfo *dinfo; USBDevice *dev; int fatal_error; const char *p1; char fmt[32]; /* parse -usbdevice disk: syntax into drive opts */ snprintf(id, sizeof(id), "usb%d", nr++); opts = qemu_opts_create(&qemu_drive_opts, id, 0); p1 = strchr(filename, ':'); if (p1++) { const char *p2; if (strstart(filename, "format=", &p2)) { int len = MIN(p1 - p2, sizeof(fmt)); pstrcpy(fmt, len, p2); qemu_opt_set(opts, "format", fmt); } else if (*filename != ':') { printf("unrecognized USB mass-storage option %s\n", filename); return NULL; } filename = p1; } if (!*filename) { printf("block device specification needed\n"); return NULL; } qemu_opt_set(opts, "file", filename); qemu_opt_set(opts, "if", "none"); /* create host drive */ dinfo = drive_init(opts, NULL, &fatal_error); if (!dinfo) { qemu_opts_del(opts); return NULL; } /* create guest device */ dev = usb_create(NULL /* FIXME */, "usb-storage"); if (!dev) { return NULL; } qdev_prop_set_drive(&dev->qdev, "drive", dinfo); if (qdev_init(&dev->qdev) < 0) return NULL; return dev; }
static USBDevice *usb_braille_init(USBBus *bus, const char *unused) { USBDevice *dev; CharDriverState *cdrv; cdrv = qemu_chr_new("braille", "braille", NULL); if (!cdrv) return NULL; dev = usb_create(bus, "usb-braille"); qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); return dev; }
USBDevice *usb_host_device_open(USBBus *bus, const char *devname) { struct USBAutoFilter filter; USBDevice *dev; char *p; dev = usb_create(bus, "usb-host"); if (strstr(devname, "auto:")) { if (parse_filter(devname, &filter) < 0) { goto fail; } } else { p = strchr(devname, '.'); if (p) { filter.bus_num = strtoul(devname, NULL, 0); filter.addr = strtoul(p + 1, NULL, 0); filter.vendor_id = 0; filter.product_id = 0; } else { p = strchr(devname, ':'); if (p) { filter.bus_num = 0; filter.addr = 0; filter.vendor_id = strtoul(devname, NULL, 16); filter.product_id = strtoul(p + 1, NULL, 16); } else { goto fail; } } } qdev_prop_set_uint32(&dev->qdev, "hostbus", filter.bus_num); qdev_prop_set_uint32(&dev->qdev, "hostaddr", filter.addr); qdev_prop_set_uint32(&dev->qdev, "vendorid", filter.vendor_id); qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id); return dev; fail: object_unparent(OBJECT(dev)); return NULL; }
/*----------------------------------------------------------------------------- * Name : usb_create_from_uri * Purpose : Create USB port from URI string * Inputs : p : port structure * uri : URI string * Outputs : <> * Return : APS_OK or error code * -----------------------------------------------------------------------------*/ int usb_create_from_uri(aps_port_t *p,struct aps_uri *su) { libusb_device * dev; libusb_device_handle * h; int r; ssize_t cnt; int i; const char *vidstr; const char *pidstr; int vid, pid; p->set.usb.busnum = 0; p->set.usb.devaddr = 0; vidstr = uri_get_opt(su,"vid"); pidstr = uri_get_opt(su,"pid"); #ifdef DEBUG fprintf(stderr, "DEBUG: in %s()\n", __func__); #endif if (devcnt == 0) { return APS_USB_DEVICE_NOT_FOUND; } if (vidstr == 0 || pidstr == 0) { return APS_INVALID_URI; } if (sscanf(vidstr,"%i",&vid)!=1) { return APS_INVALID_URI; } if (sscanf(pidstr,"%i",&pid)!=1) { return APS_INVALID_URI; } i = 0; while ((dev = devs[i]) != NULL) { struct libusb_device_descriptor desc; r = libusb_get_device_descriptor(dev, &desc); if (r < 0) { fprintf(stderr, "ERROR: failed to get device descriptor"); libusb_free_device_list(devs, 1); libusb_exit(NULL); return APS_USB_DEVICE_NOT_FOUND; } //if (desc.idVendor == APS_VENDOR_ID || desc.idVendor == APS_VENDOR_ID0) if (desc.idVendor == vid && desc.idProduct == pid) { #ifdef DEBUG fprintf(stderr, "DEBUG: ok, aps printer found...\n"); #endif break; } i ++; } if (dev == 0) { #ifdef DEBUG fprintf(stderr, "DEBUG: aps printer not found, exiting\n"); #endif libusb_free_device_list(devs, 1); libusb_exit(NULL); devs = 0; devcnt = 0; return APS_USB_DEVICE_NOT_FOUND; } #ifdef DEBUG fprintf(stderr, "DEBUG: printer at bus: %i\n", libusb_get_bus_number(dev)); fprintf(stderr, "DEBUG: printer at address: %i\n", libusb_get_device_address(dev)); #endif /* shopov(04072011) - added */ p->set.usb.busnum = libusb_get_bus_number(dev); p->set.usb.devaddr = libusb_get_device_address(dev); return APS_OK; /* shopov(04072011) - end added */ #if 0 if (libusb_open(dev, &h)) { fprintf(stderr, "DEBUG: aps printer not found, exiting\n"); libusb_free_device_list(devs, 1); libusb_exit(NULL); devs = 0; devcnt = 0; return APS_USB_DEVICE_NOT_FOUND; } r = libusb_kernel_driver_active(h, 0); if (r != 0 && r != 1) { close_and_return: libusb_close(h); fprintf(stderr, "DEBUG: aps printer not found, exiting\n"); libusb_free_device_list(devs, 1); libusb_exit(NULL); devs = 0; devcnt = 0; return APS_IO_ERROR; } p->set.usb.was_kernel_driver_attached = r; if (r) { r = libusb_detach_kernel_driver(h, 0); if (r != 0) goto close_and_return; } r = libusb_claim_interface(h, 0); if (r != 0) goto close_and_return; p->set.usb.pdev = dev; p->set.usb.hdev = h; return APS_OK; #endif #if 0 struct stat st; const char *device; const char *usbfs; const char *path; const char *vidstr; const char *pidstr; /*get device name*/ device = uri_get_device(su); printf("Device:%s\n",device); if (stat(device,&st)<0) { return APS_IO_ERROR; } printf("stats ok!:\n"); if (S_ISCHR(st.st_mode)) { printf("S_ISCHR =============ok!:\n"); /*build connection path from device name*/ return usb_create(p,device); } else if (S_ISDIR(st.st_mode)) { printf("S_ISDIR ok!:\n"); usbfs = device; } else { printf("Ke dall ! ok!:\n"); return APS_INVALID_URI; } /*get path, vendor ID and product ID parameters*/ path = uri_get_opt(su,"path"); vidstr = uri_get_opt(su,"vid"); pidstr = uri_get_opt(su,"pid"); if (path!=NULL) { /*create USB port from connection path*/ /*just copy path into port structure*/ /*set usbfs parameter*/ if (strlen(usbfs)>sizeof(p->set.usb.usbfs)-1) { return APS_NAME_TOO_LONG; } else { strcpy(p->set.usb.usbfs,usbfs); } /*copy connection path*/ if (strlen(path)>sizeof(p->set.usb.path)-1) { return APS_NAME_TOO_LONG; } else { strcpy(p->set.usb.path,path); } } else if (vidstr!=NULL && pidstr!=NULL) { /*create USB port from (vendor ID,product ID) pair*/ /*build connection path*/ int vid; int pid; if (sscanf(vidstr,"%i",&vid)!=1) { return APS_INVALID_URI; } if (sscanf(pidstr,"%i",&pid)!=1) { return APS_INVALID_URI; } return usb_create_from_id(p,usbfs,vid,pid); } else { return APS_INVALID_URI; } return APS_OK; #endif return APS_OK; }