const char *mfg, /* Manufacturer */
*mdl, /* Model */
*des = NULL, /* Description */
- *sern; /* Serial number */
+ *sern = NULL; /* Serial number */
size_t mfglen; /* Length of manufacturer string */
- char tempmfg[256], /* Temporary manufacturer string */
+ char tempmdl[256], /* Temporary model string */
+ tempmfg[256], /* Temporary manufacturer string */
tempsern[256], /* Temporary serial number string */
*tempptr; /* Pointer into temp string */
num_values = _cupsGet1284Values(device_id, &values);
- if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL)
- if ((sern = cupsGetOption("SERN", num_values, values)) == NULL)
- sern = cupsGetOption("SN", num_values, values);
+ memset(&devdesc, 0, sizeof(devdesc));
- if ((!sern || !*sern) && ((libusb_get_device_descriptor(printer->device, &devdesc) >= 0) && devdesc.iSerialNumber))
+ if (libusb_get_device_descriptor(printer->device, &devdesc) >= 0 && devdesc.iSerialNumber)
{
- /*
- * Try getting the serial number from the device itself...
- */
-
+ // Try getting the serial number from the device itself...
int length = libusb_get_string_descriptor_ascii(printer->handle, devdesc.iSerialNumber, (unsigned char *)tempsern, sizeof(tempsern) - 1);
if (length > 0)
{
}
}
+ if (!sern)
+ {
+ // Fall back on serial number from IEEE-1284 device ID, which on some
+ // printers (Issue #170) is a bogus hardcoded number.
+ if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL)
+ if ((sern = cupsGetOption("SERN", num_values, values)) == NULL)
+ sern = cupsGetOption("SN", num_values, values);
+ }
+
if ((mfg = cupsGetOption("MANUFACTURER", num_values, values)) == NULL)
- mfg = cupsGetOption("MFG", num_values, values);
+ {
+ if ((mfg = cupsGetOption("MFG", num_values, values)) == NULL && devdesc.iManufacturer)
+ {
+ int length = libusb_get_string_descriptor_ascii(printer->handle, devdesc.iManufacturer, (unsigned char *)tempmfg, sizeof(tempmfg) - 1);
+ if (length > 0)
+ {
+ tempmfg[length] = '\0';
+ mfg = tempmfg;
+ }
+ }
+ }
if ((mdl = cupsGetOption("MODEL", num_values, values)) == NULL)
- mdl = cupsGetOption("MDL", num_values, values);
+ {
+ if ((mdl = cupsGetOption("MDL", num_values, values)) == NULL && devdesc.iProduct)
+ {
+ int length = libusb_get_string_descriptor_ascii(printer->handle, devdesc.iProduct, (unsigned char *)tempmdl, sizeof(tempmdl) - 1);
+ if (length > 0)
+ {
+ tempmdl[length] = '\0';
+ mdl = tempmdl;
+ }
+ }
+ }
/*
* To maintain compatibility with the original character device backend on