简体   繁体   中英

Can't get real IOKit entries on Mac OS X 10.11

I need to find the IO Kit service for my USB device. I look for all USB devices like this:

CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBDeviceClassName);

IONotificationPortRef notificationObject = IONotificationPortCreate(kIOMasterPortDefault);

CFRunLoopSourceRef notificationRunLoopSource;
//Use the notification object received from IONotificationPortCreate
notificationRunLoopSource =
IONotificationPortGetRunLoopSource(notificationObject);

CFRunLoopAddSource(CFRunLoopGetCurrent(), notificationRunLoopSource,
                   kCFRunLoopDefaultMode);

io_iterator_t iterator;
kern_return_t kr;
kr = IOServiceAddMatchingNotification(notificationObject, kIOFirstPublishNotification, matchingDict,
                                      DeviceAppearedCallback, nil, &iterator);
if (kIOReturnSuccess == kr)
    DeviceAppearedCallback(nil, iterator);

On 10.10 and earlier, when I look for IOUSBDevices I am returned services under the AppleACPIPlatformExpert class.

> ioreg -r -n MyDevice -i -t
+-o Root  <class IORegistryEntry, id 0x100000100, retain 9>
  +-o MacBookPro11,2  <class IORegistryEntry:IOService:IOPlatformExpertDevice, id 0x100000112, registered, matched, active, busy 0 (1191243 ms), retain 42>
    +-o AppleACPIPlatformExpert  <class IORegistryEntry:IOService:IOPlatformExpert:IODTPlatformExpert:IOACPIPlatformExpert:AppleACPIPlatformExpert, id 0x100000113, registered, matched, active, busy 0 (1174729 ms), retain 44>
      +-o PCI0@0  <class IORegistryEntry:IOService:IOPlatformDevice:IOACPIPlatformDevice, id 0x10000013c, registered, matched, active, busy 0 (1171678 ms), retain 40>
        +-o AppleACPIPCI  <class IORegistryEntry:IOService:IOPCIBridge:AppleACPIPCI, id 0x100000244, registered, matched, active, busy 0 (1171663 ms), retain 33>
          +-o XHC1@14  <class IORegistryEntry:IOService:IOPCIDevice, id 0x10000023a, registered, matched, active, busy 0 (1167511 ms), retain 10>
            +-o AppleUSBXHCI  <class IORegistryEntry:IOService:IOUSBBus:IOUSBController:IOUSBControllerV2:IOUSBControllerV3:AppleUSBXHCI, id 0x100000269, registered, matched, active, busy 0 (1166957 ms), retain 30>
              +-o MyDevice@14527130  <class IORegistryEntry:IOService:IOUSBNub:IOUSBDevice, id 0x1000503ee, registered, matched, active, busy 0 (316 ms), retain 16>
                | {
                |   "sessionID" = 262856664715859
                |   "idProduct" = 555
                |   "bNumConfigurations" = 1
                |   "iManufacturer" = 1
                |   "bcdDevice" = 1280
                |   "Bus Power Available" = 250
                |   "bMaxPacketSize0" = 8
                |   "USB Product Name" = "MyDevice"
                |   "iProduct" = 2
                |   "iSerialNumber" = 3
                |   "bDeviceClass" = 0
                |   "IOUserClientClass" = "IOUSBDeviceUserClientV2"
                |   "bDeviceSubClass" = 0
                |   "USB Address" = 19
                |   "bcdUSB" = 512
                |   "locationID" = 340947248
                |   "PortNum" = 3
                |   "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
                |   "bDeviceProtocol" = 0
                |   "USB Vendor Name" = "FTDI"
                |   "Device Speed" = 1
                |   "idVendor" = 1027
                |   "USB Serial Number" = "sn123456"
                |   "IOGeneralInterest" = "IOCommand is not serializable"
                |   "Requested Power" = 45
                |   "Low Power Displayed" = No
                | }
                | 
                +-o IOUSBDeviceUserClientV2  <class IORegistryEntry:IOService:IOUserClient:IOUSBDeviceUserClientV2, id 0x1000503ef, !registered, !matched, active, busy 0, retain 7>
                +-o IOUSBCompositeDriver  <class IORegistryEntry:IOService:IOUSBCompositeDriver, id 0x1000503f3, !registered, !matched, active, busy 0, retain 4>
                +-o MyDevice@0  <class IORegistryEntry:IOService:IOUSBNub:IOUSBInterface, id 0x1000503f4, registered, matched, active, busy 0 (125 ms), retain 9>
                | | {
                | |   "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
                | |   "bcdDevice" = 1280
                | |   "IOUserClientClass" = "IOUSBInterfaceUserClientV3"
                | |   "idProduct" = 555
                | |   "bInterfaceSubClass" = 255
                | |   "bConfigurationValue" = 1
                | |   "locationID" = 340947248
                | |   "USB Interface Name" = "MyDevice"
                | |   "idVendor" = 1027
                | |   "iInterface" = 2
                | |   "bAlternateSetting" = 0
                | |   "bInterfaceProtocol" = 255
                | |   "bInterfaceNumber" = 0
                | |   "bInterfaceClass" = 255
                | |   "bNumEndpoints" = 2
                | | }
                | | 
                | +-o AppleUSBFTDI  <class IORegistryEntry:IOService:IOSerialDriverSync:AppleUSBFTDI, id 0x1000503fa, !registered, !matched, active, busy 0 (1 ms), retain 6>
                |   +-o IORS232SerialStreamSync  <class IORegistryEntry:IOService:IOSerialStreamSync:IORS232SerialStreamSync, id 0x1000503fb, registered, matched, active, busy 0 (1 ms), retain 6>
                |     +-o IOSerialBSDClient  <class IORegistryEntry:IOService:IOSerialBSDClient, id 0x1000503fd, registered, matched, active, busy 0 (0 ms), retain 5>
                +-o MyDevice@1  <class IORegistryEntry:IOService:IOUSBNub:IOUSBInterface, id 0x1000503f7, registered, matched, active, busy 0 (12 ms), retain 9>
                | | {
                | |   "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
                | |   "bcdDevice" = 1280
                | |   "IOUserClientClass" = "IOUSBInterfaceUserClientV3"
                | |   "idProduct" = 555
                | |   "bInterfaceSubClass" = 255
                | |   "bConfigurationValue" = 1
                | |   "locationID" = 340947248
                | |   "USB Interface Name" = "MyDevice"
                | |   "idVendor" = 1027
                | |   "iInterface" = 2
                | |   "bAlternateSetting" = 0
                | |   "bInterfaceProtocol" = 255
                | |   "bInterfaceNumber" = 1
                | |   "bInterfaceClass" = 255
                | |   "bNumEndpoints" = 2
                | | }
                | | 
                | +-o AppleUSBFTDI  <class IORegistryEntry:IOService:IOSerialDriverSync:AppleUSBFTDI, id 0x1000503fe, !registered, !matched, active, busy 0 (0 ms), retain 6>
                |   +-o IORS232SerialStreamSync  <class IORegistryEntry:IOService:IOSerialStreamSync:IORS232SerialStreamSync, id 0x1000503ff, registered, matched, active, busy 0 (0 ms), retain 6>
                |     +-o IOSerialBSDClient  <class IORegistryEntry:IOService:IOSerialBSDClient, id 0x100050401, registered, matched, active, busy 0 (0 ms), retain 5>
                +-o IOUSBDeviceUserClientV2  <class IORegistryEntry:IOService:IOUserClient:IOUSBDeviceUserClientV2, id 0x100050403, !registered, !matched, active, busy 0, retain 7>
                +-o IOUSBDeviceUserClientV2  <class IORegistryEntry:IOService:IOUserClient:IOUSBDeviceUserClientV2, id 0x100050404, !registered, !matched, active, busy 0, retain 7>

On 10.11, when I look for IOUSBDevices using ioreg or IORegistryExplorer I am returned services not only under the AppleACPIPlatformExpert class, but also under the IOResources class.

$ ioreg -r -n MyDevice -t -i
+-o Root  <class IORegistryEntry, id 0x100000100, retain 14>
  +-o Macmini7,1  <class IORegistryEntry:IOService:IOPlatformExpertDevice, id 0x100000112, registered, matched, active, busy 0 (23064 ms), retain 39>
    +-o AppleACPIPlatformExpert  <class IORegistryEntry:IOService:IOPlatformExpert:IODTPlatformExpert:IOACPIPlatformExpert:AppleACPIPlatformExpert, id 0x100000113, registered, matched, active, busy 0 (9879 ms), retain 37>
      +-o PCI0@0  <class IORegistryEntry:IOService:IOPlatformDevice:IOACPIPlatformDevice, id 0x10000013c, registered, matched, active, busy 0 (9850 ms), retain 42>
        +-o AppleACPIPCI  <class IORegistryEntry:IOService:IOPCIBridge:AppleACPIPCI, id 0x10000024b, registered, matched, active, busy 0 (9836 ms), retain 35>
          +-o XHC1@14  <class IORegistryEntry:IOService:IOPCIDevice, id 0x10000023e, registered, matched, active, busy 0 (5991 ms), retain 13>
            +-o XHC1@14000000  <class IORegistryEntry:IOService:AppleUSBHostController:AppleUSBXHCI:AppleUSBXHCIPCI:AppleUSBXHCILPT, id 0x100000267, registered, matched, active, busy 0 (5067 ms), retain 183>
              +-o HS01@14100000  <class IORegistryEntry:IOService:AppleUSBHostPort:AppleUSBXHCIPort:AppleUSB20XHCIPort, id 0x1000002d9, registered, matched, active, busy 0 (99 ms), retain 14>
                +-o MyDevice@14100000  <class IORegistryEntry:IOService:IOUSBNub:IOUSBDevice, id 0x100000a95, registered, matched, active, busy 0 (7 ms), retain 26>
                  | {
                  |   "sessionID" = 145657060387527
                  |   "USBSpeed" = 1
                  |   "idProduct" = 555
                  |   "bDeviceClass" = 0
                  |   "IOPowerManagement" = {"PowerOverrideOn"=Yes,"CapabilityFlags"=32768,"MaxPowerState"=2,"DevicePowerState"=2,"ChildrenPowerState"=1,"DriverPowerState"=0,"CurrentPowerState"=2}
                  |   "bcdDevice" = 1280
                  |   "USB Product Name" = "MyDevice"
                  |   "AppleUSBAlternateServiceRegistryID" = 4294970007
                  |   "locationID" = 336592896
                  |   "kUSBSerialNumberString" = "54df18d4"
                  |   "bDeviceSubClass" = 0
                  |   "kUSBCurrentConfiguration" = 1
                  |   "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
                  |   "bDeviceProtocol" = 0
                  |   "USBPortType" = 0
                  |   "USB Vendor Name" = "FTDI"
                  |   "idVendor" = 1027
                  |   "USB Serial Number" = "54df18d4"
                  |   "IOGeneralInterest" = "IOCommand is not serializable"
                  |   "kUSBVendorString" = "FTDI"
                  |   "IOClassNameOverride" = "IOUSBDevice"
                  | }
                  | 
                  +-o AppleUSBHostLegacyClient  <class IORegistryEntry:IOService:AppleUSBHostLegacyClient, id 0x100000a98, !registered, !matched, active, busy 0, retain 8>
                  +-o AppleUSBHostCompositeDevice  <class IORegistryEntry:IOService:AppleUSBHostCompositeDevice, id 0x100000aa0, !registered, !matched, active, busy 0, retain 4>
                  +-o MyDevice@0  <class IORegistryEntry:IOService:IOUSBNub:IOUSBInterface, id 0x100000aa1, registered, matched, active, busy 0 (2 ms), retain 11>
                  | | {
                  | |   "USBPortType" = 0
                  | |   "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
                  | |   "bcdDevice" = 1280
                  | |   "USBSpeed" = 1
                  | |   "idProduct" = 555
                  | |   "bConfigurationValue" = 1
                  | |   "bInterfaceSubClass" = 255
                  | |   "locationID" = 336592896
                  | |   "IOGeneralInterest" = "IOCommand is not serializable"
                  | |   "IOClassNameOverride" = "IOUSBInterface"
                  | |   "AppleUSBAlternateServiceRegistryID" = 4294970019
                  | |   "idVendor" = 1027
                  | |   "bInterfaceProtocol" = 255
                  | |   "bAlternateSetting" = 0
                  | |   "bInterfaceNumber" = 0
                  | |   "bInterfaceClass" = 255
                  | | }
                  | | 
                  | +-o AppleUSBFTDI  <class IORegistryEntry:IOService:IOSerialDriverSync:AppleUSBFTDI, id 0x100000aa8, !registered, !matched, active, busy 0 (0 ms), retain 5>
                  |   +-o IORS232SerialStreamSync  <class IORegistryEntry:IOService:IOSerialStreamSync:IORS232SerialStreamSync, id 0x100000aa9, registered, matched, active, busy 0 (0 ms), retain 6>
                  |     +-o IOSerialBSDClient  <class IORegistryEntry:IOService:IOSerialBSDClient, id 0x100000aaa, registered, matched, active, busy 0 (0 ms), retain 5>
                  +-o MyDevice@1  <class IORegistryEntry:IOService:IOUSBNub:IOUSBInterface, id 0x100000aa2, registered, matched, active, busy 0 (2 ms), retain 11>
                    | {
                    |   "USBPortType" = 0
                    |   "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
                    |   "bcdDevice" = 1280
                    |   "USBSpeed" = 1
                    |   "idProduct" = 555
                    |   "bConfigurationValue" = 1
                    |   "bInterfaceSubClass" = 255
                    |   "locationID" = 336592896
                    |   "IOGeneralInterest" = "IOCommand is not serializable"
                    |   "IOClassNameOverride" = "IOUSBInterface"
                    |   "AppleUSBAlternateServiceRegistryID" = 4294970023
                    |   "idVendor" = 1027
                    |   "bInterfaceProtocol" = 255
                    |   "bAlternateSetting" = 0
                    |   "bInterfaceNumber" = 1
                    |   "bInterfaceClass" = 255
                    | }
                    | 
                    +-o AppleUSBFTDI  <class IORegistryEntry:IOService:IOSerialDriverSync:AppleUSBFTDI, id 0x100000aac, !registered, !matched, active, busy 0 (0 ms), retain 5>
                      +-o IORS232SerialStreamSync  <class IORegistryEntry:IOService:IOSerialStreamSync:IORS232SerialStreamSync, id 0x100000aad, registered, matched, active, busy 0 (0 ms), retain 6>
                        +-o IOSerialBSDClient  <class IORegistryEntry:IOService:IOSerialBSDClient, id 0x100000aae, registered, matched, active, busy 0 (0 ms), retain 5>

+-o Root  <class IORegistryEntry, id 0x100000100, retain 14>
  +-o Macmini7,1  <class IORegistryEntry:IOService:IOPlatformExpertDevice, id 0x100000112, registered, matched, active, busy 0 (23064 ms), retain 39>
    +-o IOResources  <class IORegistryEntry:IOService:IOResources, id 0x100000115, registered, matched, active, busy 0 (4082 ms), retain 33>
      +-o AppleUSBHostResources  <class IORegistryEntry:IOService:AppleUSBHostResources, id 0x100000257, registered, matched, active, busy 0 (1530 ms), retain 37>
        +-o AppleUSBLegacyRoot  <class IORegistryEntry:IOService:AppleUSBHostResourcesClient:AppleUSBLegacyRoot, id 0x10000025a, registered, matched, active, busy 0 (1529 ms), retain 26>
          +-o AppleUSBXHCI@14000000  <class IORegistryEntry:IOService:IOUSBBus:IOUSBController:IOUSBControllerV2:IOUSBControllerV3:AppleUSBController, id 0x1000002ff, registered, matched, active, busy 0 (1529 ms), retain 26>
            +-o MyDevice@14100000  <class IORegistryEntry:IOService:IOUSBNub:IOUSBDevice, id 0x100000a97, registered, matched, active, busy 0 (7 ms), retain 16>
              | {
              |   "sessionID" = 145657060387527
              |   "iManufacturer" = 1
              |   "bNumConfigurations" = 1
              |   "Built-In" = No
              |   "bcdDevice" = 1280
              |   "Bus Power Available" = 500
              |   "idProduct" = 555
              |   "bMaxPacketSize0" = 8
              |   "iProduct" = 2
              |   "iSerialNumber" = 3
              |   "USB Address" = 18
              |   "bDeviceClass" = 0
              |   "locationID" = 336592896
              |   "bDeviceSubClass" = 0
              |   "bcdUSB" = 512
              |   "USB Product Name" = "MyDevice"
              |   "non-removable" = "no"
              |   "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
              |   "IOUserClientClass" = "IOUSBDeviceUserClientV2"
              |   "bDeviceProtocol" = 0
              |   "IOPowerManagement" = {"DevicePowerState"=0,"CurrentPowerState"=3,"CapabilityFlags"=65536,"MaxPowerState"=4,"DriverPowerState"=3}
              |   "Device Speed" = 1
              |   "USB Vendor Name" = "FTDI"
              |   "idVendor" = 1027
              |   "IOGeneralInterest" = "IOCommand is not serializable"
              |   "USB Serial Number" = "54df18d4"
              |   "IOClassNameOverride" = "IOUSBDevice"
              | }
              | 
              +-o MyDevice@0  <class IORegistryEntry:IOService:IOUSBNub:IOUSBInterface, id 0x100000aa3, registered, matched, active, busy 0 (2 ms), retain 5>
              |   {
              |     "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
              |     "bcdDevice" = 1280
              |     "IOUserClientClass" = "IOUSBInterfaceUserClientV3"
              |     "idProduct" = 555
              |     "bInterfaceSubClass" = 255
              |     "bConfigurationValue" = 1
              |     "locationID" = 336592896
              |     "USB Interface Name" = "MyDevice"
              |     "IOClassNameOverride" = "IOUSBInterface"
              |     "bInterfaceProtocol" = 255
              |     "idVendor" = 1027
              |     "bAlternateSetting" = 0
              |     "iInterface" = 2
              |     "bInterfaceNumber" = 0
              |     "bInterfaceClass" = 255
              |     "bNumEndpoints" = 2
              |   }
              |   
              +-o MyDevice@1  <class IORegistryEntry:IOService:IOUSBNub:IOUSBInterface, id 0x100000aa7, registered, matched, active, busy 0 (2 ms), retain 5>
              |   {
              |     "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
              |     "bcdDevice" = 1280
              |     "IOUserClientClass" = "IOUSBInterfaceUserClientV3"
              |     "idProduct" = 555
              |     "bInterfaceSubClass" = 255
              |     "bConfigurationValue" = 1
              |     "locationID" = 336592896
              |     "USB Interface Name" = "MyDevice"
              |     "IOClassNameOverride" = "IOUSBInterface"
              |     "bInterfaceProtocol" = 255
              |     "idVendor" = 1027
              |     "bAlternateSetting" = 0
              |     "iInterface" = 2
              |     "bInterfaceNumber" = 1
              |     "bInterfaceClass" = 255
              |     "bNumEndpoints" = 2
              |   }

However, on 10.11, when I search for devices of class IOUSBDevice using the code above, I only get the results under the IOResources/AppleUSBLegacyRoot provider. This means when I go looking for the child object of class IOSerialBSDClient, it cannot be found.

Any idea how I can get the "real" entries on 10.11?

On 10.11, you have to look for IOUSBHostDevice instead of IOUSBDevice to get the same results you would on 10.10 and earlier.

    NSOperatingSystemVersion needHostDeviceVersion = {10,11,0};
    if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:needHostDeviceVersion])
        matchingDict = IOServiceMatching("IOUSBHostDevice");
    else
        matchingDict = IOServiceMatching(kIOUSBDeviceClassName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM