Author Topic: Read endpoint descriptor using control transfer  (Read 12716 times)

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Read endpoint descriptor using control transfer
« on: June 06, 2015, 09:40:29 am »
I am not sure if I setuppacket information is correct or not:

        Public Function GetEndpointDescriptor_new() As String
            Dim setuppacket As WINUSB_SETUP_PACKET
            Dim buffer As Byte() = New Byte(255) {}
            Dim transfered As UInteger
            Dim success As Boolean

            setuppacket.RequestType = CByte(Hex2Dec("80"))
            setuppacket.Request = 6
            setuppacket.Value = CUShort(CInt(Hex2Dec("500")))
            setuppacket.Index = CUShort(0)
            setuppacket.Length = CUShort(7)
            success = WinUsb_ControlTransfer(myDevInfo.winUsbHandle, setuppacket, buffer, CUInt(buffer.Length), transfered, IntPtr.Zero)

*Hex2Dec = Long.Parse(junk, Globalization.NumberStyles.AllowHexSpecifier)

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Read endpoint descriptor using control transfer
« Reply #1 on: June 06, 2015, 09:43:46 am »
My device endpoint descriptor information:

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x01  -> Direction: OUT - EndpointID: 1
bmAttributes:                      0x02  -> Bulk Transfer Type
wMaxPacketSize:                  0x0200 = 0x200 max bytes
bInterval:                         0x01

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x81  -> Direction: IN - EndpointID: 1
bmAttributes:                      0x02  -> Bulk Transfer Type
wMaxPacketSize:                  0x0200 = 0x200 max bytes
bInterval:                         0x01

       ---===>Full Configuration Descriptor<===---

          ===>Configuration Descriptor<===
bLength:                           0x09
bDescriptorType:                   0x02
wTotalLength:                    0x0020  -> Validated
bNumInterfaces:                    0x01
bConfigurationValue:               0x01
iConfiguration:                    0x00
bmAttributes:                      0x80  -> Bus Powered
MaxPower:                          0xFA = 500 mA

          ===>Interface Descriptor<===
bLength:                           0x09
bDescriptorType:                   0x04
bInterfaceNumber:                  0x00
bAlternateSetting:                 0x00
bNumEndpoints:                     0x02
bInterfaceClass:                   0xFF  -> Interface Class Unknown to USBView
bInterfaceSubClass:                0xFF
bInterfaceProtocol:                0xFF
iInterface:                        0x00

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read endpoint descriptor using control transfer
« Reply #2 on: June 06, 2015, 09:52:54 pm »
Most bulk endpoints set bInterval = 0.

wMaxPacketSize = 0x200 assumes high speed or higher.

What problem are you seeing?

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Read endpoint descriptor using control transfer
« Reply #3 on: June 07, 2015, 09:06:01 am »
success = WinUsb_ControlTransfer(myDevInfo.winUsbHandle, setuppacket, buffer, CUInt(buffer.Length), transfered, IntPtr.Zero) failed to read the data at all.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read endpoint descriptor using control transfer
« Reply #4 on: June 07, 2015, 09:36:47 am »
What error message did the API call return?

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getlastwin32error%28v=vs.100%29.aspx

Use a protocol analyzer or whatever debugging tools you have to find out if the device received the setup packet and if firmware detected the request, placed the requested data in the endpoint's buffer, and armed the endpoint to return the data in the request's Data stage.

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Read endpoint descriptor using control transfer
« Reply #5 on: June 07, 2015, 10:26:32 am »
Found the answer where I have to use this:

            setuppacket.RequestType = CByte(Hex2Dec("80"))
            setuppacket.Request = 6
            setuppacket.Value = CUShort(CInt(Hex2Dec("200")))
            setuppacket.Index = CUShort(0)
            setuppacket.Length = CUShort(255)
            success = WinUsb_ControlTransfer(myDevInfo.winUsbHandle, setuppacket, buffer, CUInt(buffer.Length), transfered, IntPtr.Zero)

From USB 2.0: A request for a configuration descriptor returns the configuration descriptor, all interface descriptors, and endpoint descriptors for all of the interfaces in a single request.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read endpoint descriptor using control transfer
« Reply #6 on: June 07, 2015, 12:47:04 pm »
Glad you got it working. Thanks for reporting what you found.