如何在Mac中获取USB设备的设备描述符和配置描述符? [英] How to get device descriptor and configuration descriptor of usb device in Mac?

查看:600
本文介绍了如何在Mac中获取USB设备的设备描述符和配置描述符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对xcode和I/Okit框架的了解最少.我已经在USB探针程序中看到了USB设备的设备描述符和配置描述符.

I have minimum exposure to xcode and I/Okit framework. I have seen device descriptor and configuration descriptor of a usb device in USB prober.

我已经使用I/O工具包框架编写了一个xcode程序,当我们提供该设备的产品ID和供应商ID作为输入时,该设备将以USB设备名称作为输出.

I have written an xcode program using I/O kit framework which gives the usb device name as output, when we give product id and vendor id of that device as input.

/*Take the vendor and product id from console*/

printf("\nEnter the vendor id : ");
scanf("%lx",&usbVendor);

printf("\nEnter the product id :");
scanf("%lx",&usbProduct);


/* Set up a matching dictionary for the class */
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (matchingDict == NULL)
{
    return -1; // fail
}
// Create a CFNumber for the idVendor and set the value in the dictionary
numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbVendor);
CFDictionarySetValue(matchingDict, 
                     CFSTR(kUSBVendorID), 
                     numberRef);
CFRelease(numberRef);

// Create a CFNumber for the idProduct and set the value in the dictionary
numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbProduct);
CFDictionarySetValue(matchingDict, 
                     CFSTR(kUSBProductID), 
                     numberRef);
CFRelease(numberRef);
numberRef = NULL;

/*Get an iterator.*/
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS)
{
    return -1;// fail
}

/* iterate */
while ((device = IOIteratorNext(iter)))
{
    /*Display the device names */

    io_name_t       deviceName;
    kr = IORegistryEntryGetName(device, deviceName);
    if (KERN_SUCCESS != kr) {
        deviceName[0] = '\0';
    }


    printf("\ndeviceName:%s",deviceName);

    /*Free the reference taken before continuing to the next item */
    IOObjectRelease(device);
}

/*Release the iterator */
IOObjectRelease(iter);
return 0;

}

我需要修改它,以便在提供USB设备的供应商和产品ID时,我将获得设备描述符和配置描述符(如USB探针中所示)作为输出.

I need to modify this, so that on giving vendor and product id of usb device, i will get the device descriptor and configuration descriptor( as shown in USB prober) as output.

这里我只是举一个例子,代码可以更改,但是输出必须是描述符(至少是设备描述符).

Here i just gave an example, code can change but the output must be the descriptor( atleast the device decriptor).

预先感谢...

推荐答案

我认为您应该下载USBProber的源代码,而不要自己弄清楚.

I think u should download the source code of USBProber rather than figure it out by yourself.

通过分析源代码,可以早晚获取USBProber中提供的所有信息.

All the information presents in the USBProber u could get sooner or later by analyzing the source code.

这里是链接,其中包含USBProber,用于下载IOUSBFamily的源代码. http://opensource.apple.com/tarballs/IOUSBFamily/

Here is link to download the source code of IOUSBFamily, with USBProber inside it. http://opensource.apple.com/tarballs/IOUSBFamily/

这篇关于如何在Mac中获取USB设备的设备描述符和配置描述符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆