SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback __sane_unused__ authorize) { SANE_Status ret; SANE_Word vendor_id, product_id; DBG_INIT(); DBG (1, "SANE backed for HP ScanJet 4500C/4570C/5500C/5550C/5590/7650 %u.%u.%u\n", SANE_CURRENT_MAJOR, V_MINOR, BUILD); DBG (1, "(c) Ilia Sotnikov <*****@*****.**>\n"); if (version_code) *version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, V_MINOR, BUILD); sanei_usb_init(); sanei_usb_set_timeout (USB_TIMEOUT); scanners_list = NULL; ret = hp5590_vendor_product_id (SCANNER_HP4570, &vendor_id, &product_id); if (ret != SANE_STATUS_GOOD) return ret; ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp4570); if (ret != SANE_STATUS_GOOD) return ret; ret = hp5590_vendor_product_id (SCANNER_HP5550, &vendor_id, &product_id); if (ret != SANE_STATUS_GOOD) return ret; ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp5550); if (ret != SANE_STATUS_GOOD) return ret; ret = hp5590_vendor_product_id (SCANNER_HP5590, &vendor_id, &product_id); if (ret != SANE_STATUS_GOOD) return ret; ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp5590); if (ret != SANE_STATUS_GOOD) return ret; ret = hp5590_vendor_product_id (SCANNER_HP7650, &vendor_id, &product_id); if (ret != SANE_STATUS_GOOD) return ret; ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp7650); if (ret != SANE_STATUS_GOOD) return ret; return SANE_STATUS_GOOD; }
/** here we roam through our list of supported devices and * cross check with the ones the system reports... * @param vendor - pointer to receive vendor ID * @param product - pointer to receive product ID * @return SANE_TRUE if a matching device has been found or * SANE_FALSE if nothing supported found... */ static SANE_Bool usbDev_autodetect( SANE_Word *vendor, SANE_Word *product ) { int i; SANE_Word p, v; DBG( _DBG_INFO, "Autodetection...\n" ); for( i = 0; NULL != u12Devices[i].name; i++ ) { v = strtol( &(u12Devices[i].vp)[0], 0, 0 ); p = strtol( &(u12Devices[i].vp)[7], 0, 0 ); DBG( _DBG_INFO, "* checking for 0x%04x-0x%04x\n", v, p ); sanei_usb_find_devices( v, p, u12if_usbattach ); if( USB_devname[0] != '\0' ) { *vendor = v; *product = p; DBG( _DBG_INFO, "* using device >%s<\n", USB_devname ); return SANE_TRUE; } } return SANE_FALSE; }
/* Get device list */ SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool __sane_unused__ local_only) { if (devlist) { int i; for (i = 0; devlist[i]; i++) { free ((void *) devlist[i]->name); free ((void *) devlist[i]); } free ((void *) devlist); devlist = NULL; } for (curr_scan_dev = 0; curr_scan_dev < sizeof (known_devices) / sizeof (known_devices[0]); curr_scan_dev++) { sanei_usb_find_devices (PANASONIC_ID, known_devices[curr_scan_dev].id, attach); } for (curr_scan_dev = 0; curr_scan_dev < sizeof (known_devices) / sizeof (known_devices[0]); curr_scan_dev++) { sanei_scsi_find_devices (known_devices[curr_scan_dev].scanner.vendor, known_devices[curr_scan_dev].scanner.model, NULL, -1, -1, -1, -1, attach); } if(device_list) *device_list = (const SANE_Device **) devlist; return SANE_STATUS_GOOD; }
static int u12if_open( U12_Device *dev ) { char devStr[50]; int result; SANE_Int handle; SANE_Word vendor, product; SANE_Bool was_empty; DBG( _DBG_INFO, "u12if_open(%s,%s)\n", dev->name, dev->usbId ); USB_devname[0] = '\0'; #ifdef _FAKE_DEVICE dev->name = strdup( "auto" ); dev->sane.name = dev->name; was_empty = SANE_FALSE; result = SANE_STATUS_UNSUPPORTED; #else if( !strcmp( dev->name, "auto" )) { if( dev->usbId[0] == '\0' ) { if( !usbDev_autodetect( &vendor, &product )) { DBG( _DBG_ERROR, "No supported device found!\n" ); return -1; } } else { vendor = strtol( &dev->usbId[0], 0, 0 ); product = strtol( &dev->usbId[7], 0, 0 ); sanei_usb_find_devices( vendor, product, u12if_usbattach ); if( USB_devname[0] == '\0' ) { DBG( _DBG_ERROR, "No matching device found!\n" ); return -1; } } if( SANE_STATUS_GOOD != sanei_usb_open( USB_devname, &handle )) { return -1; } /* replace the old devname, so we are able to have multiple * auto-detected devices */ free( dev->name ); dev->name = strdup( USB_devname ); dev->sane.name = dev->name; } else { if( SANE_STATUS_GOOD != sanei_usb_open( dev->name, &handle )) return -1; } was_empty = SANE_FALSE; result = sanei_usb_get_vendor_product( handle, &vendor, &product ); #endif if( SANE_STATUS_GOOD == result ) { sprintf( devStr, "0x%04X-0x%04X", vendor, product ); DBG(_DBG_INFO,"Vendor ID=0x%04X, Product ID=0x%04X\n",vendor,product); if( dev->usbId[0] != '\0' ) { if( 0 != strcmp( dev->usbId, devStr )) { DBG( _DBG_ERROR, "Specified Vendor and Product ID " "doesn't match with the ones\n" "in the config file\n" ); sanei_usb_close( handle ); return -1; } } else { sprintf( dev->usbId, "0x%04X-0x%04X", vendor, product ); was_empty = SANE_TRUE; } } else { DBG( _DBG_INFO, "Can't get vendor & product ID from driver...\n" ); /* if the ioctl stuff is not supported by the kernel and we have * nothing specified, we have to give up... */ if( dev->usbId[0] == '\0' ) { DBG( _DBG_ERROR, "Cannot autodetect Vendor an Product ID, " "please specify in config file.\n" ); sanei_usb_close( handle ); return -1; } vendor = strtol( &dev->usbId[0], 0, 0 ); product = strtol( &dev->usbId[7], 0, 0 ); DBG( _DBG_INFO, "... using the specified: " "0x%04X-0x%04X\n", vendor, product ); } /* before accessing the scanner, check if supported! */ if( !u12if_IsDeviceSupported( dev )) { DBG( _DBG_ERROR, "Device >%s<, is not supported!\n", dev->usbId ); sanei_usb_close( handle ); return -1; } dev->mode = _PP_MODE_SPP; dev->fd = handle; /* is it accessible ? */ if( SANE_STATUS_GOOD != u12hw_CheckDevice( dev )) { dev->fd = -1; sanei_usb_close( handle ); return -1; } DBG( _DBG_INFO, "Detected vendor & product ID: " "0x%04X-0x%04X\n", vendor, product ); if( was_empty ) dev->usbId[0] = '\0'; /* now initialize the device */ if( SANE_STATUS_GOOD != u12_initDev( dev, handle, vendor )) { dev->fd = -1; sanei_usb_close( handle ); return -1; } if( _PLUSTEK_VENID == vendor ) { if( dev->Tpa ) dev->sane.model = "UT12"; } dev->initialized = SANE_TRUE; return handle; }
SANE_Status sane_get_devices (const SANE_Device * **device_list, SANE_Bool __sane_unused__ local_only) { struct device_s *iter; int i; devlist_count = 0; if (devlist_head) { iter = devlist_head->next; free (devlist_head); devlist_head = NULL; while (iter) { struct device_s *tmp = iter; iter = iter->next; free (tmp); } } /* Rebuild our internal scanner list */ for (cur_idx = 0; usbid[cur_idx].vendor_id; cur_idx++) sanei_usb_find_devices (usbid[cur_idx].vendor_id, usbid[cur_idx].product_id, attach); if (devlist) { for (i = 0; devlist[i]; i++) free (devlist[i]); free (devlist); } /* rebuild the sane-API scanner list array */ devlist = malloc (sizeof (devlist[0]) * (devlist_count + 1)); if (!devlist) return SANE_STATUS_NO_MEM; memset (devlist, 0, sizeof (devlist[0]) * (devlist_count + 1)); for (i = 0, iter = devlist_head; i < devlist_count; i++, iter = iter->next) { devlist[i] = malloc (sizeof (SANE_Device)); if (!devlist[i]) { int j; for (j = 0; j < i; j++) free (devlist[j]); free (devlist); devlist = NULL; return SANE_STATUS_NO_MEM; } devlist[i]->name = iter->devname; devlist[i]->vendor = usbid[iter->idx].vendor_s; devlist[i]->model = usbid[iter->idx].model_s; devlist[i]->type = usbid[iter->idx].type_s; } if (device_list) *device_list = (const SANE_Device **) devlist; return SANE_STATUS_GOOD; }