Mirror USB serial number change to macOS USB backend.
@@ -1670,11 +1670,34 @@ static CFStringRef copy_printer_interface_deviceid(printer_interface_t printer,
CFStringAppendFormat(extras, NULL, CFSTR("MDL:%@;"), model);
}
- if (serial == NULL && desc.iSerialNumber != 0)
+ if (desc.iSerialNumber != 0)
{
- serial = copy_printer_interface_indexed_description(printer, desc.iSerialNumber, kUSBLanguageEnglish);
- if (serial && CFStringGetLength(serial) > 0)
- CFStringAppendFormat(extras, NULL, CFSTR("SERN:%@;"), serial);
+ // Always look at the USB serial number since some printers
+ // incorrectly include a bogus static serial number in their
+ // IEEE-1284 device ID string...
+ CFStringRef userial = copy_printer_interface_indexed_description(printer, desc.iSerialNumber, kUSBLanguageEnglish);
+ if (userial && CFStringGetLength(userial) > 0 && (serial == NULL || CFStringCompare(serial, userial, kCFCompareCaseInsensitive) != kCFCompareEqualTo))
+ {
+ if (serial != NULL)
+ {
+ // 1284 serial number doesn't match USB serial number, so replace the existing SERN: in device ID
+ CFRange range = CFStringFind(ret, serial, 0);
+ CFMutableStringRef deviceIDString = CFStringCreateMutableCopy(NULL, 0, ret);
+ CFStringReplace(deviceIDString, range, userial);
+ CFRelease(ret);
+ ret = deviceIDString;
+
+ CFRelease(serial);
+ }
+ else
+ {
+ // No 1284 serial number so add SERN: with USB serial number to device ID
+ CFStringAppendFormat(extras, NULL, CFSTR("SERN:%@;"), userial);
+ }
+ serial = userial;
+ }
+ else if (userial != NULL)
+ CFRelease(userial);
}
if (ret != NULL)
