Skip to content

Unable to retrieve Android device manufacturer and product strings #29

@Tryanks

Description

@Tryanks

On a Linux machine, I installed libusb-1.0-0-dev and started implementing the AOAv2 protocol, which I plan to use for registering a HID device on Android. However, I have not even reached the AOAv2-specific part yet. At the very first step, simply reading the USB string descriptors already fails.

Minimal reproducer
package main

import (
	"fmt"
	"log"

	libusb "github.com/gotmc/libusb/v2"
)

func main() {
	ctx, err := libusb.NewContext()
	if err != nil {
		log.Fatalf("new context failed: %v", err)
	}
	defer ctx.Close()

	dev, handle, err := ctx.OpenDeviceWithVendorProduct(0x2717, 0xff48)
	if err != nil {
		log.Fatalf("open device failed: %v", err)
	}
	defer dev.Close()
	defer handle.Close()

	desc, err := dev.DeviceDescriptor()
	if err != nil {
		log.Fatalf("read device descriptor failed: %v", err)
	}

	fmt.Printf("VID:PID = %04x:%04x\n", desc.VendorID, desc.ProductID)
	fmt.Printf("ManufacturerIndex = %d\n", desc.ManufacturerIndex)
	fmt.Printf("ProductIndex      = %d\n", desc.ProductIndex)

	manufacturer, err := handle.StringDescriptorASCII(desc.ManufacturerIndex)
	if err != nil {
		log.Fatalf("read manufacturer failed: %v", err)
	}

	product, err := handle.StringDescriptorASCII(desc.ProductIndex)
	if err != nil {
		log.Fatalf("read product failed: %v", err)
	}

	fmt.Printf("Manufacturer = %q\n", manufacturer)
	fmt.Printf("Product      = %q\n", product)
}

On my actual device, I would expect the manufacturer and product strings to be:

  • "Xiaomi"
  • "MI 8"

Instead, I get empty strings together with resource temporarily unavailable.

More specifically:

  • StringDescriptorASCII() returns "" with resource temporarily unavailable
  • StringDescriptor() returns malformed / truncated data such as "\x0e\x03X"

From reading the behavior and comparing the results, I suspect there may be implementation issues in these two methods:

  • StringDescriptorASCII() seems to have incorrect error handling
  • StringDescriptor() appears to treat the USB string descriptor as a C string, which may explain the truncation / malformed output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions