GrixM
GrixM

Reputation: 273

GADGETFS_CLEAR_HALT freezes my gadgetfs USB device program

I have been following this guide to implement a GadgetFS device in Linux: https://blog.soutade.fr/post/2016/07/create-your-own-usb-gadget-with-gadgetfs.html

I needed to extend the configuration with a second alternate setting which has all my endpoints. So my code has defined one interface with alt setting 0, no endpoints, and another interface with alt setting 1, with two endpoints. Otherwise the code is the same as the example above.

The device seems to be recognized properly by the host, however, during initialization, it reaches the following lines of code:

case USB_REQ_SET_INTERFACE:
    printf("SET_INTERFACE\n");
    ioctl (thread_args.fd_in, GADGETFS_CLEAR_HALT);
    ioctl (thread_args.fd_out, GADGETFS_CLEAR_HALT);
    // ACK
    status = read (fd, &status, 0);

And from there it stops responding to any messages from the host. I guess it blocks at read() and never returns?

I figured out that if I simply comment out the ioctl() calls, then it seems to work fine. However, I am cautious of doing this because I don't really know what those lines do, they must be there for a reason. The API's comments merely say "resets endpoint halt+toggle; used to implement set_interface.", and I don't really find any other info anywhere else online either.

If I simply have one interface, like the original example, the problem does not occur either.

So my question is, what do these GADGETFS_CLEAR_HALT operations do? Why are they breaking my program if I specify more than one USB interface?

Upvotes: 1

Views: 67

Answers (0)

Related Questions