/* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int tripplite_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(tripplite_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: switch (hd->VendorID) { case HP_VENDORID: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } /* * this vendor makes lots of USB devices that are * not a UPS, so don't use possibly_supported here */ return 0; case TRIPPLITE_VENDORID: /* reject known non-HID devices */ /* not all Tripp Lite products are HID, some are "serial over USB". */ if (hd->ProductID == 0x0001) { /* e.g. SMART550USB, SMART3000RM2U */ upsdebugx(0, "This Tripp Lite device (%04x/%04x) is not supported by usbhid-ups.\n" "Please use the tripplite_usb driver instead.\n", hd->VendorID, hd->ProductID); return 0; } /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("TrippLite", hd); return 0; /* catch all (not really needed) */ default: return 0; } case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } }
static int device_match_func(USBDevice_t *device, void *privdata) { switch (is_usb_device_supported(richcomm_usb_id, device)) { case SUPPORTED: return 1; case POSSIBLY_SUPPORTED: case NOT_SUPPORTED: default: return 0; } }
static int subdriver_match_func(USBDevice_t *hd, void *privdata) { switch (is_usb_device_supported(tripplite_usb_device_table, hd)) { case SUPPORTED: return 1; case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } case NOT_SUPPORTED: default: return 0; } }
static int device_match_func(USBDevice_t *hd, void *privdata) { if (subdriver_command) { return 1; } switch (is_usb_device_supported(blazer_usb_id, hd)) { case SUPPORTED: return 1; case POSSIBLY_SUPPORTED: case NOT_SUPPORTED: default: return 0; } }
/* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int openups_claim(HIDDevice_t * hd) { int status = is_usb_device_supported(openups_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("openUPS", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } }
/* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int liebert_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(liebert_usb_device_table, hd->VendorID, hd->ProductID); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("Liebert", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } }
/* return NULL if error */ nutscan_device_t * nutscan_scan_usb() { int ret; char string[256]; char *driver_name = NULL; char *serialnumber = NULL; char *device_name = NULL; char *vendor_name = NULL; struct usb_device *dev; struct usb_bus *bus; usb_dev_handle *udev; nutscan_device_t * nut_dev = NULL; nutscan_device_t * current_nut_dev = NULL; if( !nutscan_avail_usb ) { return NULL; } /* libusb base init */ (*nut_usb_init)(); (*nut_usb_find_busses)(); (*nut_usb_find_devices)(); for (bus = (*nut_usb_busses); bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if ((driver_name = is_usb_device_supported(usb_device_table, dev->descriptor.idVendor, dev->descriptor.idProduct)) != NULL) { /* open the device */ udev = (*nut_usb_open)(dev); if (!udev) { fprintf(stderr,"Failed to open device, \ skipping. (%s)\n", (*nut_usb_strerror)()); continue; } /* get serial number */ if (dev->descriptor.iSerialNumber) { ret = (*nut_usb_get_string_simple)(udev, dev->descriptor.iSerialNumber, string, sizeof(string)); if (ret > 0) { serialnumber = strdup(rtrim(string, ' ')); } } /* get product name */ if (dev->descriptor.iProduct) { ret = (*nut_usb_get_string_simple)(udev, dev->descriptor.iProduct, string, sizeof(string)); if (ret > 0) { device_name = strdup(rtrim(string, ' ')); } } /* get vendor name */ if (dev->descriptor.iManufacturer) { ret = (*nut_usb_get_string_simple)(udev, dev->descriptor.iManufacturer, string, sizeof(string)); if (ret > 0) { vendor_name = strdup(rtrim(string, ' ')); } } nut_dev = nutscan_new_device(); if(nut_dev == NULL) { fprintf(stderr,"Memory allocation \ error\n"); nutscan_free_device(current_nut_dev); free(serialnumber); free(device_name); free(vendor_name); return NULL; } nut_dev->type = TYPE_USB; if(driver_name) { nut_dev->driver = strdup(driver_name); } nut_dev->port = strdup("auto"); sprintf(string,"%04X",dev->descriptor.idVendor); nutscan_add_option_to_device(nut_dev,"vendorid", string); sprintf(string,"%04X", dev->descriptor.idProduct); nutscan_add_option_to_device(nut_dev,"productid", string); if(device_name) { nutscan_add_option_to_device(nut_dev, "product", device_name); free(device_name); } if(serialnumber) { nutscan_add_option_to_device(nut_dev, "serial", serialnumber); free(serialnumber); } if(vendor_name) { nutscan_add_option_to_device(nut_dev, "vendor", vendor_name); free(vendor_name); } nutscan_add_option_to_device(nut_dev,"bus", bus->dirname); current_nut_dev = nutscan_add_device_to_device( current_nut_dev, nut_dev); memset (string, 0, sizeof(string)); (*nut_usb_close)(udev); }