Help with IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION

This is a discussion on Help with IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to get the configuration descriptor for a device I already have a PUSB_NODE_CONNECTION_INFORMATION_EX structure for. I'm working off ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    30

    Help with IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION

    I'm trying to get the configuration descriptor for a device I already have a PUSB_NODE_CONNECTION_INFORMATION_EX structure for. I'm working off of the usbview example in the Windows DDK. Here's the relevant portion of the code...

    Code:
    /******************************************************
    				* Fill the fields necessary for the request
    				******************************************************/
    				
    				// Zero out the request struct
    	
    				len = sizeof(configreqbuf);
    				memset(configreq, 0, len);
    				
    				configreq->ConnectionIndex = conninfo->ConnectionIndex;
    	
    				// descriptor type is high byte, descriptor index is low
    	
    				configreq->SetupPacket.wValue = ((USB_CONFIGURATION_DESCRIPTOR_TYPE << 8) | (unsigned char)0);
    				configreq->SetupPacket.wLength = (unsigned short)(len - sizeof(USB_DESCRIPTOR_REQUEST));
    				
    				/*****************************************************
    				* Get length, dynamically resize, and get descriptor
    				*****************************************************/
    				
    				err = DeviceIoControl(rhub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, configreq, len, configreq, len, &len, NULL);
    				
    				if(!err || configdesc->wTotalLength < sizeof(USB_CONFIGURATION_DESCRIPTOR))
    				{
    					printf("DEBUG! %d\n\n", GetLastError());
    					return(NULL);
    				}
    				configdesc = (PUSB_CONFIGURATION_DESCRIPTOR)malloc(len);
    				configreq->ConnectionIndex = conninfo->ConnectionIndex;
    				
    				configreq->SetupPacket.wValue = ((USB_CONFIGURATION_DESCRIPTOR_TYPE << 8) | (unsigned char)0);
    				configreq->SetupPacket.wLength = (unsigned short)(len - sizeof(USB_DESCRIPTOR_REQUEST));
    				
    				err = DeviceIoControl(rhub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, configdesc, len, configdesc, len, &len, NULL);
    				
    				if(!err)
    					return(NULL);
    					
    				return(configdesc);
    The declarations are here:

    Code:
    	HANDLE rhub, ctlr;
    	PUSB_DESCRIPTOR_REQUEST configreq;
    	PUSB_CONFIGURATION_DESCRIPTOR configdesc;
    	char *rhubname, *tmp, *name, *configreqbuf;
    	int numports = -1, i, len = 65536, err, x;
    	PUSB_NODE_CONNECTION_INFORMATION_EX conninfo = (PUSB_NODE_CONNECTION_INFORMATION_EX)malloc(sizeof(unsigned char) * 65536);
    It fails at the following line with error code 2 (ERROR_FILE_NOT_FOUND). Anyone know what I'm doing wrong?

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    30
    I managed to fix it by not getting the size and just allocating a large buffer. It's not the most elegant solution, but I'll free it after. I have another question, however, once I have the configuration descriptor, how do I get the interface and endpoint descriptors? According to MSDN, the UsbBuildGetDescriptorRequest macro only supports three types for the third argument, DescriptorType, and those are USB_DEVICE_DESCRIPTOR_TYPE, USB_CONFIGURATION_DESCRIPTOR_TYPE, and USB_STRING_DESCRIPTOR_TYPE.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    Check out the function on this page: WinUsb_QueryInterfaceSettings Function (Windows Driver Kit)
    It seems to give you an interface descriptor with the number of endpoints and here you seem to be able to get info about endpoints: WinUsb_QueryPipe Function (Windows Driver Kit)

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21