Getting Pipe information

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I remember that in the EZUSB driver you could get pipe information by:

   

 

   

DWORD nBytes;
    const bool ERROR_FLAG = ( FALSE == ::DeviceIoControl( hDevice,
        IOCTL_Ezusb_GET_PIPE_INFO,
        NULL,
        0,
        interfaceInfoBuffer,
        sizeof(interfaceInfoBuffer ),
        &nBytes,
        NULL )

   

 

   

And then cast it to PUSBD_INTERFACE_INFORMATION

   

 

   

From there the pipe information can read out and displayed.

   

 

   

However, with the new CyUsb drivers, this seems to be no longer available. Looking through the cyioctl.h, I cannot find the same command anymore, the closest I got was IOCTL_ADAPT_GET_NUMBER_ENDPOINTS, which is not able to do what I want.

   

 

   

Could you please help point me in the right direction as how to retrieve pipe information? Thank uou.

0 Likes
1 Reply
Anonymous
Not applicable

I'm posting a version of code I did to achieve get pipe info using the IOCTLs of CyUSB.sys, This get the values other than pipehandle variable of the USBD_INTERFACE_INFORMATION structure. This hasn't been extensively tested. You should be able to get rid of some part of it based on your application

   

   case IOCTL_Ezusb_GET_PIPE_INFO:
        { 
            ULONG length = sizeof(SINGLE_TRANSFER) + sizeof(USB_CONFIGURATION_DESCRIPTOR);
            PUCHAR buf = new UCHAR[length];
            ZeroMemory (buf, length);

            PSINGLE_TRANSFER pSingleTransfer = (PSINGLE_TRANSFER) buf;
            pSingleTransfer->SetupPacket.bmReqType.Direction = DIR_DEVICE_TO_HOST;
            pSingleTransfer->SetupPacket.bmReqType.Type      = 0;
            pSingleTransfer->SetupPacket.bmReqType.Recipient = 0;
            pSingleTransfer->SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR;
            pSingleTransfer->SetupPacket.wVal.hiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE;
            pSingleTransfer->SetupPacket.wVal.lowByte = 0;
            pSingleTransfer->SetupPacket.wLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
            pSingleTransfer->SetupPacket.ulTimeOut = 5;
            pSingleTransfer->BufferLength = pSingleTransfer->SetupPacket.wLength;
            pSingleTransfer->BufferOffset = sizeof(SINGLE_TRANSFER);

            bool bRetVal = IoControl(IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER, buf, length);        //Send Get Configuration descriptor request
            UsbdStatus = pSingleTransfer->UsbdStatus;
            NtStatus = pSingleTransfer->NtStatus;

            if (bRetVal) {
              PUSB_CONFIGURATION_DESCRIPTOR configDesc = (PUSB_CONFIGURATION_DESCRIPTOR)((PCHAR)pSingleTransfer + pSingleTransfer->BufferOffset);
              USHORT configDescLength= configDesc->wTotalLength;                                //Find the total length of configuration descriptor

              length = sizeof(SINGLE_TRANSFER) + configDescLength;
              PUCHAR buf2 = new UCHAR[length];
              ZeroMemory (buf2, length);
             
              pSingleTransfer = (PSINGLE_TRANSFER) buf2;
              pSingleTransfer->SetupPacket.bmReqType.Direction = DIR_DEVICE_TO_HOST;
              pSingleTransfer->SetupPacket.bmReqType.Type      = 0;
              pSingleTransfer->SetupPacket.bmReqType.Recipient = 0;
              pSingleTransfer->SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR;
              pSingleTransfer->SetupPacket.wVal.hiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE;
              pSingleTransfer->SetupPacket.wVal.lowByte = 0;
              pSingleTransfer->SetupPacket.wLength = configDescLength;
              pSingleTransfer->SetupPacket.ulTimeOut = 5;
              pSingleTransfer->BufferLength = pSingleTransfer->SetupPacket.wLength;
              pSingleTransfer->BufferOffset = sizeof(SINGLE_TRANSFER);

              bRetVal = IoControl(IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER, buf2, length);            //Get the entire configuration descriptor
              UsbdStatus = pSingleTransfer->UsbdStatus;
              NtStatus = pSingleTransfer->NtStatus;

              if (bRetVal){
                USBConfigDescriptors = (PUSB_CONFIGURATION_DESCRIPTOR)malloc(configDescLength);
                memcpy(USBConfigDescriptors, (PVOID)((PCHAR)pSingleTransfer + pSingleTransfer->BufferOffset), configDescLength);
              }

              delete[] buf2;

            }

            delete[] buf;

            USBCfgs = new CCyUSBConfig(hDevice,USBConfigDescriptors);    //Populate the descriptor table in USB_CONFIGURATION_DESCRIPTOR structure
            UCHAR a;
            bRetVal = (IoControl(IOCTL_ADAPT_GET_ALT_INTERFACE_SETTING, &a, 1));                //Find the alternate setting
            if(bRetVal)
            {
                if (USBCfgs)
                {
                    for (int j=0; j < USBCfgs->AltInterfaces; j++)        //Parse through interface descriptor to find the corresponding descriptor
                        if (USBCfgs->Interfaces->bAlternateSetting == a)
                        {
                            IntfcIndex = j;
                            IntfcClass = USBCfgs->Interfaces->bInterfaceClass;
                            IntfcSubClass = USBCfgs->Interfaces->bInterfaceSubClass;           
                            IntfcProtocol = USBCfgs->Interfaces->bInterfaceProtocol;
                        }
                }
            }
            else
                return false;
            *lpBytesReturned = (16 + ((USBCfgs->Interfaces[IntfcIndex]->bNumEndpoints)*20));
            OutputBuffer[0] = LSB((WORD)*lpBytesReturned);            //Populate the output buffer with pipe information based on the descriptor
            OutputBuffer[1] = MSB((WORD)*lpBytesReturned);
            OutputBuffer[2] = USBCfgs->Interfaces[IntfcIndex]->bInterfaceNumber;
            OutputBuffer[3] = USBCfgs->Interfaces[IntfcIndex]->bAlternateSetting;
            OutputBuffer[4] = USBCfgs->Interfaces[IntfcIndex]->bInterfaceClass;
            OutputBuffer[5] = USBCfgs->Interfaces[IntfcIndex]->bInterfaceSubClass;
            OutputBuffer[6] = USBCfgs->Interfaces[IntfcIndex]->bInterfaceProtocol;
            OutputBuffer[7] = 0;
            OutputBuffer[12] = USBCfgs->Interfaces[IntfcIndex]->bNumEndpoints;
            for(int j = 0; j<USBCfgs->Interfaces[IntfcIndex]->bNumEndpoints;j++)
                for(int i = (16 +(j*20));(i<(16+((j+1)*20)) && (i < 1024));i++)
                {
                    OutputBuffer[i++] = LSB(USBCfgs->Interfaces[IntfcIndex]->EndPoints[j+1]->MaxPktSize);
                    OutputBuffer[i++] = MSB(USBCfgs->Interfaces[IntfcIndex]->EndPoints[j+1]->MaxPktSize);
                    OutputBuffer[i++] = USBCfgs->Interfaces[IntfcIndex]->EndPoints[j+1]->Address;
                    OutputBuffer[i++] = USBCfgs->Interfaces[IntfcIndex]->EndPoints[j+1]->Interval;
                    OutputBuffer[i++] = ((USBCfgs->Interfaces[IntfcIndex]->EndPoints[j+1]->Attributes)& 0x03);
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0xFF;
                    OutputBuffer[i++] = 0xFF;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                    OutputBuffer[i++] = 0x00;
                }
            memcpy(lpOutBuffer,OutputBuffer,*lpBytesReturned);
            return true;
        break;

   

Regards,

   

Anand

0 Likes