+static io_service_t get_usb_object(io_object_t serial_device)
+{
+ io_iterator_t iterator;
+ io_service_t usb_device;
+ io_service_t service;
+ IOReturn status;
+
+ status = IORegistryEntryCreateIterator(serial_device,
+ kIOServicePlane,
+ kIORegistryIterateParents | kIORegistryIterateRecursively,
+ &iterator);
+
+ if (status != kIOReturnSuccess)
+ return 0;
+
+ while((service = IOIteratorNext(iterator))) {
+ io_name_t servicename;
+ status = IORegistryEntryGetNameInPlane(service, kIOServicePlane, servicename);
+
+ if (status == kIOReturnSuccess && IOObjectConformsTo(service, kIOUSBDeviceClassName)) {
+ IOObjectRelease(iterator);
+ return service;
+ }
+ IOObjectRelease(service);
+ }
+ IOObjectRelease(iterator);
+ return 0;
+}
+