usbatm xusbatm.c,1.7,1.8

Duncan Sands baldrick at free.fr
Thu Apr 21 12:46:35 EDT 2005


> +static int usb_intf_has_ep(const struct usb_interface *intf, u8 ep)
> +{
> +	struct usb_host_interface *alt = intf->altsetting;
> +	u8 i, n_eps = alt->desc.bNumEndpoints;
> +
> +	for (i = 0; i < n_eps; i++)
> +		if ((alt->endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) == ep)
> +			return 1;
> +	return 0;
> +}

This is from devio.c:

static int findintfep(struct usb_device *dev, unsigned int ep)
{
        unsigned int i, j, e;
        struct usb_interface *intf;
        struct usb_host_interface *alts;
        struct usb_endpoint_descriptor *endpt;

        if (ep & ~(USB_DIR_IN|0xf))
                return -EINVAL;
        if (!dev->actconfig)
                return -ESRCH;
        for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
                intf = dev->actconfig->interface[i];
                for (j = 0; j < intf->num_altsetting; j++) {
                        alts = &intf->altsetting[j];
                        for (e = 0; e < alts->desc.bNumEndpoints; e++) {
                                endpt = &alts->endpoint[e].desc;
                                if (endpt->bEndpointAddress == ep)
                                        return alts->desc.bInterfaceNumber;
                        }
                }
        }
        return -ENOENT;
}

I guess the point is that an endpoint may not exist in some altsettings
for the interface, and can exist in several.  This complicates things...

>  static int xusbatm_bind(struct usbatm_data *usbatm_instance,
>  			struct usb_interface *intf, const struct usb_device_id *id,
>  			int *need_heavy_init)

The logic in this routine seems convoluted.  Rather than having a
routine that checks whether an ep is in an interface, why not have
one that, given an ep, returns the interface containing it?  Then
you can check whether either one (or both) equals the current intf,
and claim the other interface if needs be.

Ciao,

D.




More information about the Usbatm mailing list