X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=macosx.c;h=a0df84e6b079d4e5ff9fa969a27020631115bbfe;hb=a06a765515482976bcbd60526bd638b3d10b14e7;hp=38495fd970fb2df49ec311fd3233966b61d10035;hpb=48a4076f692ffe34026c37815580a32b2f70592b;p=libserialport.git
diff --git a/macosx.c b/macosx.c
index 38495fd..a0df84e 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"
-enum sp_return get_port_details(struct sp_port *port)
+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];
@@ -57,9 +60,20 @@ enum sp_return get_port_details(struct sp_port *port)
IOObjectRelease(ioport);
continue;
}
- DEBUG("Found port %s", path);
+ 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))) {
@@ -86,7 +100,7 @@ enum sp_return get_port_details(struct sp_port *port)
CFSTR(kIOTTYDeviceKey), kCFAllocatorDefault, 0))) {
if (CFStringGetCString(cf_property, description, sizeof(description),
kCFStringEncodingASCII)) {
- DEBUG("Found description %s", description);
+ DEBUG_FMT("Found description %s", description);
port->description = strdup(description);
}
CFRelease(cf_property);
@@ -107,12 +121,14 @@ enum sp_return get_port_details(struct sp_port *port)
if (cf_bus && cf_address &&
CFNumberGetValue(cf_bus , kCFNumberIntType, &bus) &&
CFNumberGetValue(cf_address, kCFNumberIntType, &address)) {
- DEBUG("Found matching USB bus:address %03d:%03d", bus, address);
+ DEBUG_FMT("Found matching USB bus:address %03d:%03d", bus, address);
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,19 +143,21 @@ 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("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,
kIORegistryIterateRecursively | kIORegistryIterateParents))) {
if (CFStringGetCString(cf_property, manufacturer, sizeof(manufacturer),
kCFStringEncodingASCII)) {
- DEBUG("Found manufacturer %s", manufacturer);
+ DEBUG_FMT("Found manufacturer %s", manufacturer);
port->usb_manufacturer = strdup(manufacturer);
}
CFRelease(cf_property);
@@ -150,7 +168,7 @@ enum sp_return get_port_details(struct sp_port *port)
kIORegistryIterateRecursively | kIORegistryIterateParents))) {
if (CFStringGetCString(cf_property, product, sizeof(product),
kCFStringEncodingASCII)) {
- DEBUG("Found product name %s", product);
+ DEBUG_FMT("Found product name %s", product);
port->usb_product = strdup(product);
}
CFRelease(cf_property);
@@ -161,7 +179,7 @@ enum sp_return get_port_details(struct sp_port *port)
kIORegistryIterateRecursively | kIORegistryIterateParents))) {
if (CFStringGetCString(cf_property, serial, sizeof(serial),
kCFStringEncodingASCII)) {
- DEBUG("Found serial number %s", serial);
+ DEBUG_FMT("Found serial number %s", serial);
port->usb_serial = strdup(serial);
}
CFRelease(cf_property);
@@ -175,7 +193,7 @@ enum sp_return get_port_details(struct sp_port *port)
RETURN_OK();
}
-enum sp_return list_ports(struct sp_port ***list)
+SP_PRIV enum sp_return list_ports(struct sp_port ***list)
{
CFMutableDictionaryRef classes;
io_iterator_t iter;
@@ -207,9 +225,9 @@ enum sp_return list_ports(struct sp_port ***list)
kCFStringEncodingASCII);
CFRelease(cf_path);
if (result) {
- DEBUG("Found port %s", path);
+ 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;
}