Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.enter image description here

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;

}

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).

Thanks in advance...

share|improve this question
    
Whether there is any built in function for getting the Device descriptor, Configuration descriptor, Interface decriptor? – DILi Oct 3 '11 at 7:21
    
There is a USBDeviceDescriptor in usb.h. I tried to call a pointer of that type so that i would get all the parameters but I failed. Any help? – DILi Oct 4 '11 at 9:19
    
I also tried with functions available by IOUSBDeviceInterface. But it do not provide functions to extract all the parameters – DILi Oct 4 '11 at 9:20
    
I then tried using IORegistryEntryCreateCFProperty but here too failed to get all parameter. Any idea about tis, pls reply – DILi Oct 4 '11 at 9:22
    
For getting pointer to configuration Decriptor we can use GetConfigurationDescriptor() in IOUSBDeviceInterface. developer.apple.com/library/mac/#documentation/Darwin/Refere‌​nce/…. – DILi Oct 6 '11 at 8:45
up vote 4 down vote accepted

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

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

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

share|improve this answer
    
i tired USBprober. I couldnot understand its flow correctly, then since i was looking for simple program. I tried the functions provided by the classes under USB in mac. – DILi Oct 20 '11 at 8:37
1  
I have write an example to get all the information shows in the USB Prober->USB Probe, what u want to get are denfinitly inside it.<br/>Following is the main step get generate the Demo.<br/>1. Import the source files from the USB Prober project. Don't forget the USBVendor.txt, which used to decode the vendor.<br/>2. Import the required Framework, just follow the USB Prober project.<br/>3. Add an interface to output the log in BusProbeController. U can search "IvanDebug" to find the interface.<br/>4. Write the main.m file to use the BusProbeController. <br/> – Ivan Oct 22 '11 at 16:42
    
Let me know how to send u the demo if needed. 0_- – Ivan Oct 22 '11 at 16:46
    
Please sent the demo to my mail:mdileep1989@gmail.com. It will be very helpful. – DILi Oct 24 '11 at 4:10
1  
I have send u the demo. – Ivan Oct 24 '11 at 15:16

For getting device descriptor and configuration decriptor, we can use functions in IOUSBDeviceInterface class

Link: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/IOKit/IOUSBLib_h/Classes/IOUSBDeviceInterface/index.html#//apple_ref/doc/com/intfm/IOUSBDeviceInterface/

For getting interface descriptor and end point descriptor, we can use functions in IOUSBInterfaceInterface class

Link: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/IOKit/IOUSBLib_h/Classes/IOUSBInterfaceInterface/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.