X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=macosx.c;h=0d22bb6fe10b4fa1877c8c80a87e79f8ddee3550;hb=HEAD;hp=1a2beb06ff64a4bccb448a1bccc7e2132ee2a886;hpb=23ef3bf125ead21c0cc4c49d70dd0b8877d8a5fe;p=libserialport.git diff --git a/macosx.c b/macosx.c index 1a2beb0..0d22bb6 100644 --- a/macosx.c +++ b/macosx.c @@ -18,13 +18,16 @@ * along with this program. If not, see . */ +#include #include "libserialport.h" #include "libserialport_internal.h" SP_PRIV enum sp_return get_port_details(struct sp_port *port) { - /* Description limited to 127 char, - anything longer would not be user friendly anyway */ + /* + * Description limited to 127 char, anything longer + * would not be user friendly anyway. + */ char description[128]; int bus, address, vid, pid = -1; char manufacturer[128], product[128], serial[128]; @@ -39,7 +42,7 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) if (!(classes = IOServiceMatching(kIOSerialBSDServiceValue))) RETURN_FAIL("IOServiceMatching() failed"); - if (IOServiceGetMatchingServices(kIOMasterPortDefault, classes, + if (IOServiceGetMatchingServices(kIOMainPortDefault, classes, &iter) != KERN_SUCCESS) RETURN_FAIL("IOServiceGetMatchingServices() failed"); @@ -60,6 +63,17 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) DEBUG_FMT("Found port %s", path); IORegistryEntryGetParentEntry(ioport, kIOServicePlane, &ioparent); + if ((cf_property=IORegistryEntrySearchCFProperty(ioparent,kIOServicePlane, + CFSTR("IOClass"), kCFAllocatorDefault, + kIORegistryIterateRecursively | kIORegistryIterateParents))) { + if (CFStringGetCString(cf_property, class, sizeof(class), + kCFStringEncodingASCII) && + strstr(class, "USB")) { + DEBUG("Found USB class device"); + port->transport = SP_TRANSPORT_USB; + } + CFRelease(cf_property); + } if ((cf_property=IORegistryEntrySearchCFProperty(ioparent,kIOServicePlane, CFSTR("IOProviderClass"), kCFAllocatorDefault, kIORegistryIterateRecursively | kIORegistryIterateParents))) { @@ -111,8 +125,10 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) port->usb_bus = bus; port->usb_address = address; } - if (cf_bus ) CFRelease(cf_bus); - if (cf_address) CFRelease(cf_address); + if (cf_bus) + CFRelease(cf_bus); + if (cf_address) + CFRelease(cf_address); cf_vendor = IORegistryEntrySearchCFProperty(ioport, kIOServicePlane, CFSTR("idVendor"), @@ -127,12 +143,14 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) if (cf_vendor && cf_product && CFNumberGetValue(cf_vendor , kCFNumberIntType, &vid) && CFNumberGetValue(cf_product, kCFNumberIntType, &pid)) { - DEBUG_FMT("Found matching USB vid:pid %04X:%04X", vid, pid); + DEBUG_FMT("Found matching USB VID:PID %04X:%04X", vid, pid); port->usb_vid = vid; port->usb_pid = pid; } - if (cf_vendor ) CFRelease(cf_vendor); - if (cf_product) CFRelease(cf_product); + if (cf_vendor) + CFRelease(cf_vendor); + if (cf_product) + CFRelease(cf_product); if ((cf_property = IORegistryEntrySearchCFProperty(ioport,kIOServicePlane, CFSTR("USB Vendor Name"), kCFAllocatorDefault, @@ -192,7 +210,7 @@ SP_PRIV enum sp_return list_ports(struct sp_port ***list) } DEBUG("Getting matching services"); - if (IOServiceGetMatchingServices(kIOMasterPortDefault, classes, + if (IOServiceGetMatchingServices(kIOMainPortDefault, classes, &iter) != KERN_SUCCESS) { SET_FAIL(ret, "IOServiceGetMatchingServices() failed"); goto out_done; @@ -209,7 +227,7 @@ SP_PRIV enum sp_return list_ports(struct sp_port ***list) if (result) { DEBUG_FMT("Found port %s", path); if (!(*list = list_append(*list, path))) { - SET_ERROR(ret, SP_ERR_MEM, "list append failed"); + SET_ERROR(ret, SP_ERR_MEM, "List append failed"); IOObjectRelease(port); goto out; }