Unable to get USB bsdname from macOS Monterey 12 Bate4 of Intel processor

I can’t get USB bsdname from macOS Monterey 12 Bate4 of Intel processor: I have use the "IORegistryEntrySearchCFProperty" function to get the bsdName of the io_service_t, It worked fine on macOS Big Sur's M1 and Intel MBP. Also it worked fine on macOS Monterey App M1. But it always returned nil on macOS Monterey Intel MBP. It involves the following code:

void getBsdName(io_service_t usbDevice)

{

	CFStringRef bsdName = NULL;

        for(int i = 0; i < 500; i++)

        {

            bsdName = (CFStringRef)IORegistryEntrySearchCFProperty(usbDevice,

                                                                   kIOServicePlane,

                                                                   CFSTR( kIOBSDNameKey ),

                                                                   kCFAllocatorDefault,

                                                                   kIORegistryIterateRecursively );

            if(!bsdName) {

                // If don't get a bsd name, keep waiting in 5s.

                usleep(10000);

                continue;

            }

            

            printf("[%s]: Found bsd name for device %d.\n”, __func__, usbDevice);

            break;

        }

}

Why it happened? Or is there another way to get it?

Replies

I’m not sure why this is failing on macOS 12 beta but I’d like to clarify your goals here. Can you explain more about the big picture? Why are you trying to map in this direction?

I’m curious because any algorithm that involves a usleep is suspect in my opinion.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Same problem here. It seems like kIORegistryIterateRecursively is not working as intended. I tried to dig into the IOUSBDevice entry's children using IORegistryEntryGetChildEntry recursively, but it fails to go deeper than one child (i.e. no grandchildren), so it seems like the IOSerialBSDClient child entry is no longer visible at all from that standpoint.

  • I solved this issue by other ways.

    Since the device I'm looking for is an IOMedia object. I found its BSD name by enumerating the kIOMediaClass object. And I looked up IOMedia's parent device to determine the USB device I'm interested in.

    Hope this answer can help you~

  • Yes, this is what I ended up doing; iterating over kIOSerialBSDServiceValue objects (which contain the BSD name), climbing up the parents of each one using IORegistryEntryGetParentEntry, until I find an entry with a "sessionID" property that is identical to the one from my original IOUSBDevice object.

Add a Comment

It seems like kIORegistryIterateRecursively is not working as intended. I tried to dig into the IOUSBDevice entry's children using IORegistryEntryGetChildEntry recursively

I’m confused by the above. IORegistryEntryGetChildEntry doesn’t work in terms of iterators. Are you saying that you tried to use it as a workaround for kIORegistryIterateRecursively? If so, what does your original code look like?

And it’d also help if you posted a description of your high-level goal. Many I/O Kit problems problems have easier solutions that don’t involve low-level I/O registry calls.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Yes, I tried to use it as a workaround, but it failed and hit a dead-end after just one level down. I don’t fully understand the high-level goal of the code I’m dealing with, I’m just trying to fix some legacy method that unexpectedly started behaving differently in Monterey. I’ve only first started coding on macOS a month ago, so I’m still throwing things at the wall to see what sticks. Here's what I ended up doing, all the code I added is contained between the “Temporary fix” comments: https://gist.github.com/PhilCS/878c446a18b510397444ea770d6d1044

Add a Comment

I solved this issue by other ways.

Since the device I'm looking for is an IOMedia object. I found its BSD name by enumerating the kIOMediaClass object. And I looked up IOMedia's parent device to determine the USB device I'm interested in.


CFStringRef mediaDevBsdName = NULL;

mediaDevBsdName = (CFStringRef)IORegistryEntryCreateCFProperty(mediaDevice,

                                                                 CFSTR(kIOBSDNameKey),

                                                                 kCFAllocatorDefault,0);

Hope this answer can help someone~

  • Yes, this is what I ended up doing; iterating over kIOSerialBSDServiceValue objects (which contain the BSD name), climbing up the parents of each one using IORegistryEntryGetParentEntry, until I find an entry with a "sessionID" property that is identical to the one from my original IOUSBDevice object.

Add a Comment

Here's what I ended up doing

Unfortunately I need a bit more context here. Specifically, how did you set up the io_iterator_t that’s passed in to the -serialDevicesForIOIterator: method?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Add a Comment