Thanks to everyone who replied. I found the IORegistry documentation
and sort of came up with something. There may be a memory leak or three
in here, but it at least appears to work.
The one thing that appears magical is the need to go up two parents.
Without doing that, the bundle ID winds up being
com.apple.iokit.IOSerialFamily rather than the bundle ID for the actual
USB-to-serial kext for the device.
char *getBundleNameForDevice(char *fname) {
static char retval[1024]; // that really ought to be enough. I'm
too lazy to alloc and release.
mach_port_t masterPort;
io_iterator_t matchingServices;
CFMutableDictionaryRef classesToMatch;
kern_return_t kernResult;
io_object_t device;
CFStringRef CFfname;
// We want to find the BSD serial device with the given name.
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
CFfname = CFStringCreateWithCString(NULL, fname,
kCFStringEncodingASCII);
CFDictionarySetValue(classesToMatch,
CFSTR(kIODialinDeviceKey),
CFfname);
CFRelease(CFfname);
// Now we go up two levels and look for the bundle ID.
if (IORegistryEntryGetParentEntry(device, kIOServicePlane,
&parent) != KERN_SUCCESS)
continue;
if (IORegistryEntryGetParentEntry(parent, kIOServicePlane,
&superParent) != KERN_SUCCESS)
continue;
bundleIDAsCFString =
IORegistryEntryCreateCFProperty(superParent,
kIOBundleIdentifierKey,
kCFAllocatorDefault,
0);
if (bundleIDAsCFString == NULL)
continue;
result = CFStringGetCString(bundleIDAsCFString,
retval,
sizeof(retval) - 1,
kCFStringEncodingASCII);
CFRelease(bundleIDAsCFString);
if (result)
return retval;
}
return NULL;
}
_______________________________________________
usb mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/usb
Do not post admin requests to the list. They will be ignored.