Skip to content

Commit

Permalink
Try getting USB descriptors for manufacturer and model
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelq committed Nov 4, 2022
1 parent 3591cf6 commit e2b5f69
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions pappl/device-usb.c
Expand Up @@ -368,9 +368,10 @@ pappl_usb_find(
const char *make, // Pointer to make
*model, // Pointer to model
*serial = NULL; // Pointer to serial number
char *ptr, // Pointer into device ID
char *ptr_did, // Pointer into device ID
copy_did[1024], // Copy of device ID
temp[256]; // Temporary string for serial #
tmp[1024]; // Temporary string for make/model/serial
char *ptr_tmp = tmp; // Pointer into temporary string

papplCopyString(copy_did, device_id, sizeof(copy_did));

Expand All @@ -391,36 +392,67 @@ pappl_usb_find(
else if ((serial = strstr(copy_did, "SN:")) != NULL)
serial += 3;

if (serial)
if (make)
{
if ((ptr = strchr(serial, ';')) != NULL)
*ptr = '\0';
if ((ptr_did = strchr(make, ';')) != NULL)
*ptr_did = '\0';
}
else
{
int length = libusb_get_string_descriptor_ascii(device->handle, devdesc.iSerialNumber, (unsigned char *)temp, sizeof(temp) - 1);
if (length > 0)
int length;
if ((length = sizeof(tmp) - (ptr_tmp - tmp)) > 0)
{
temp[length] = '\0';
serial = temp;
if ((length = libusb_get_string_descriptor_ascii(device->handle, devdesc.iManufacturer, (unsigned char *)ptr_tmp, length)) > 0)
{
make = ptr_tmp;
ptr_tmp += length + 1;
}
else
make = "Unknown";
}
else
make = "Unknown";
}

if (make)
if (model)
{
if ((ptr = strchr(make, ';')) != NULL)
*ptr = '\0';
if ((ptr_did = strchr(model, ';')) != NULL)
*ptr_did = '\0';
}
else
make = "Unknown";
{
int length;
if ((length = sizeof(tmp) - (ptr_tmp - tmp)) > 0)
{
if ((length = libusb_get_string_descriptor_ascii(device->handle, devdesc.iProduct, (unsigned char *)ptr_tmp, length)) > 0)
{
model = ptr_tmp;
ptr_tmp += length + 1;
}
else
model = "Unknown";
}
else
model = "Unknown";
}

if (model)
if (serial)
{
if ((ptr = strchr(model, ';')) != NULL)
*ptr = '\0';
if ((ptr_did = strchr(serial, ';')) != NULL)
*ptr_did = '\0';
}
else
model = "Unknown";
{
int length;
if ((length = sizeof(tmp) - (ptr_tmp - tmp)) > 0)
{
if ((length = libusb_get_string_descriptor_ascii(device->handle, devdesc.iSerialNumber, (unsigned char *)ptr_tmp, length)) > 0)
{
serial = ptr_tmp;
ptr_tmp += length + 1;
}
}
}

if (serial)
httpAssembleURIf(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri), "usb", NULL, make, 0, "/%s?serial=%s", model, serial);
Expand Down

0 comments on commit e2b5f69

Please sign in to comment.