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

Solution for Unable to get USB bsdname from macOS Monterey 12 Bate4 of Intel processor
is Given Below:

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;
        }
}

Does anybody know why it happened? How to make it work on MacOS 12 intel processor? Or is there any other way to do it?

I also uploaded the same question to the Apple Forum, please check on this link: Apple_forum_thread_686377

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.

bool getBsdName(io_object_t mediaDevice)
{
    // your code... ...
    CFStringRef mediaDevBsdName = NULL;
    mediaDevBsdName = (CFStringRef)IORegistryEntryCreateCFProperty(mediaDevice,
                                                                 CFSTR(kIOBSDNameKey),
                                                                 kCFAllocatorDefault,0);
    // your code... ...
}

If you use “IOUSBHostDevice” instead of kIOUSBDeviceClassName when creating the match dictionary for the IOServiceGetMatchingServices call IORegistryEntryCreateCFProperty will recurse correctly.

The Intel version of Monterey no longer honours the “IOClassNameOverride” = “IOUSBDevice” entry in the dictionary or at least that’s what I think is happening.