1

Background:
We have an application which is written using the QT framework. One key requirement is that we can correctly detect the hardware serial number of the USB flash drive used (not an external hard drive). This function has been working correctly for 4 years and worked on Windows XP, Windows Vista, Windows 2007 and on all Mac versions.

To our surprise we got clients complaining that the USB hardware ID was not being read and shown completely. After testing extensively it turns out that ONLY the combination of Mac OS mountain Lion + Mac Book (Pro) does NOT detect the hardware ID.

Mountain Lion on an iMac, on a Mini Mac, works fine. Leopard, Snow Leopard and Lion work fine on all Macs, including the Mac Book Pro.

We have been looking for a fix for nearly 1 one month but without results. Can anyone provide a small piece of code that works or give information what causes this issue (and really only on this combination) and how to fix it.

Note Several resources can be found on the internet of other USB hardware that has issues with mountain lion but nowhere an answer was given to the solution to exactly the problem as described above.

Additional info: We use the following code at the moment which works correctly on all Macs except those that have a USB3.0 port.

matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (matchingDict == NULL)
{
    return uret; // fail
}

/* Now we have a dictionary, get an iterator.*/
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS)
{
    return uret;
}

/* iterate */
/* scan all USB device in Mac machine*/
while ((device = IOIteratorNext(iter)))
{
    int vendorId;
    int productId;
    getVidAndPid(device, &vendorId, &productId);
/*Get USB serial number by CFTypeRef*/
    CFTypeRef  serialNoRef = IORegistryEntryCreateCFProperty(device, CFSTR("USB Serial   Number"), 0, 0);
/*Get USB bsd name by CFStringRef */
    CFStringRef bsdNameRef = (CFStringRef)IORegistryEntrySearchCFProperty(device,  kIOServicePlane,CFSTR(kIOBSDNameKey),kCFAllocatorDefault, kIORegistryIterateRecursively );
    char* bsdName = cfStringRefToCString(bsdNameRef) ;
qDebug() << "bsd Name " << bsdName ;
    if (bsdName != NULL)
    {
           char* serialNo = cfTypeToCString(serialNoRef);
        qDebug() << "serialNo " << serialNo ;
/*Get USB manufacturerRef by CFTypeRef */
        CFTypeRef manufacturerRef =IORegistryEntrySearchCFProperty(device,     kIOServicePlane, CFSTR(kUSBVendorString), kCFAllocatorDefault, 0);
        char* manufacrurer = cfTypeToCString(manufacturerRef);
       qDebug() << "manufacrurer " << manufacrurer ;
    }
    IOObjectRelease(device);
}

/* Done, release the iterator */
 IOObjectRelease(iter);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • A little more input on this topic. After further testing it appears that ONLY Mac Books that have a USB 3.0 port do return the USB Serial number. When we run the following command in terminal: [code]system_profiler SPUSBDataType| grep -A 10 '^.*Removable Media: Yes'| grep 'Serial Number:' | sed -e 's/^.*Number: //'[code] it returns the serial number on all other Macs but on a Mac Book with a USB 3.0 port it returns nothing. Any clue what needs to be changed to the above command to get the correct serial number? – Edward Green Feb 25 '13 at 03:51

0 Answers0