From c2e00928759b77e38411f58913402afd3424dac4 Mon Sep 17 00:00:00 2001 From: Elijah Insua Date: Sat, 10 Oct 2015 23:02:34 -0400 Subject: [PATCH] add support for osx el capitan It appears as though the registry topology has changed in 10.11. In order to fix that, this code assumes nothing about the path, but instead works on the assumption that we can already find the registry entry as soon as the device is enumerated. By increasing the bounds of the search we have a better chance of finding the registry entry that we are looking for refs: voodootikigod/node-serialport#552 --- src/serialport_unix.cpp | 82 +++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 52 deletions(-) diff --git a/src/serialport_unix.cpp b/src/serialport_unix.cpp index 22e157f..2a5bba6 100644 --- a/src/serialport_unix.cpp +++ b/src/serialport_unix.cpp @@ -420,7 +420,7 @@ void EIO_Close(uv_work_t* req) { // Function prototypes static kern_return_t FindModems(io_iterator_t *matchingServices); -static io_registry_entry_t GetUsbDevice(char *pathName); +static io_service_t GetUsbDevice(io_service_t service); static stDeviceListItem* GetSerialDevices(); @@ -441,56 +441,35 @@ static kern_return_t FindModems(io_iterator_t *matchingServices) return kernResult; } -static io_registry_entry_t GetUsbDevice(char* pathName) +static io_service_t GetUsbDevice(io_service_t service) { - io_registry_entry_t device = 0; - - CFMutableDictionaryRef classesToMatch = IOServiceMatching(kIOUSBDeviceClassName); - if (classesToMatch != NULL) - { - io_iterator_t matchingServices; - kern_return_t kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault, classesToMatch, &matchingServices); - if (KERN_SUCCESS == kernResult) - { - io_service_t service; - Boolean deviceFound = false; - - while ((service = IOIteratorNext(matchingServices)) && !deviceFound) - { - CFStringRef bsdPathAsCFString = (CFStringRef) IORegistryEntrySearchCFProperty(service, kIOServicePlane, CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, kIORegistryIterateRecursively); - - if (bsdPathAsCFString) - { - Boolean result; - char bsdPath[MAXPATHLEN]; - - // Convert the path from a CFString to a C (NUL-terminated) - result = CFStringGetCString(bsdPathAsCFString, - bsdPath, - sizeof(bsdPath), - kCFStringEncodingUTF8); - - CFRelease(bsdPathAsCFString); - - if (result && (strcmp(bsdPath, pathName) == 0)) - { - deviceFound = true; - //memset(bsdPath, 0, sizeof(bsdPath)); - device = service; - } - else - { - // Release the object which are no longer needed - (void) IOObjectRelease(service); - } - } - } - // Release the iterator. - IOObjectRelease(matchingServices); - } - } + IOReturn status; + io_iterator_t iterator = 0; + io_service_t device = 0; + if (!service) { return device; + } + + status = IORegistryEntryCreateIterator(service, + kIOServicePlane, + (kIORegistryIterateParents | kIORegistryIterateRecursively), + &iterator); + + if (status == kIOReturnSuccess) + { + io_service_t currentService; + while ((currentService = IOIteratorNext(iterator))) + { + io_name_t serviceName; + status = IORegistryEntryGetNameInPlane(currentService, kIOServicePlane, serviceName); + if (status == kIOReturnSuccess && (IOObjectConformsTo(currentService, kIOUSBDeviceClassName))) { + device = currentService; + break; + } + } + } + return device; } static void ExtractUsbInformation(stSerialDevice *serialDevice, IOUSBDeviceInterface **deviceInterface) @@ -583,14 +562,13 @@ static stDeviceListItem* GetSerialDevices() uv_mutex_lock(&list_mutex); - io_registry_entry_t device = GetUsbDevice(bsdPath); + io_service_t device = GetUsbDevice(modemService); if (device) { - CFStringRef manufacturerAsCFString = (CFStringRef) IORegistryEntrySearchCFProperty(device, - kIOServicePlane, + CFStringRef manufacturerAsCFString = (CFStringRef) IORegistryEntryCreateCFProperty(device, CFSTR(kUSBVendorString), kCFAllocatorDefault, - kIORegistryIterateRecursively); + 0); if (manufacturerAsCFString) {