tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Fwd: usb driver programming



Thank you for the information.

Below are the relevant functions of my code.

As you may see, these functions *VERY* resemble those from sys/dev/usb/if_atu.c
(I've heavily used atu as starting point for my code)

Is that, what's you've been talking about searching for endpoints in
atu_complete_attach: ?

for (i = 0; i < id->bNumEndpoints; i++) {
               ed = usbd_interface2endpoint_descriptor(sc->atu_iface, i);
               if (!ed) {
                       DPRINTF(("%s: num_endp:%d\n", USBDEVNAME(sc->atu_dev),
                           sc->atu_iface->idesc->bNumEndpoints));
                       DPRINTF(("%s: couldn't get ep %d\n",
                           USBDEVNAME(sc->atu_dev), i));
                       return;
               }
               if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
                   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
                       sc->atu_ed[ATU_ENDPT_RX] = ed->bEndpointAddress;
               } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
                          UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
                       sc->atu_ed[ATU_ENDPT_TX] = ed->bEndpointAddress;
               }
       }

1) could you please tell me where is the code showing how to open a
pipe for communication with the endpoint different that the 'control'?

2) And what to do with that stuff:
request
value
index

that goes here:

atu_usb_request
{
...
usb_device_request_t    req;
....
req.bmRequestType = type;
req.bRequest = request;
USETW(req.wValue, value);
USETW(req.wIndex, index);
USETW(req.wLength, length);
....
}

??

Thank you.

//--> MY CODE START
USB_ATTACH(wimax)
{
       USB_ATTACH_START(wimax, sc, uaa);
       char                *devinfop;
       usbd_status         err;
       usbd_device_handle      dev = uaa->device;
       u_int8_t            mode, channel;
       int i;

       printf("-->wimax_attach\n");

       sc->wimax_dev = self;
       sc->sc_state = WIMAX_S_UNCONFIG;

       devinfop = usbd_devinfo_alloc(dev, 0);
       USB_ATTACH_SETUP;
       aprint_normal_dev(self, "%s\n", devinfop);
       usbd_devinfo_free(devinfop);

       err = usbd_set_config_no(dev, WIMAX_CONFIG_NO, 1);
       if (err) {
               aprint_error_dev(self, "setting config no failed\n");
               USB_ATTACH_ERROR_RETURN;
       }

       err = usbd_device2interface_handle(dev, WIMAX_IFACE_IDX,
&sc->wimax_iface);
       if (err) {
               aprint_error_dev(self, "getting interface handle failed\n");
               USB_ATTACH_ERROR_RETURN;
       }

       sc->wimax_unit = device_unit(self);
       sc->wimax_udev = dev;

       wimax_complete_attach(sc);

       USB_ATTACH_SUCCESS_RETURN;
}

void wimax_complete_attach(struct wimax_softc *sc)
{
       //struct ieee80211com     *ic = &sc->sc_ic;
       //struct ifnet            *ifp = &sc->sc_if;
       usb_interface_descriptor_t  *id;
       usb_endpoint_descriptor_t   *ed;
       usbd_status         err;
       int             i;

       id = usbd_get_interface_descriptor(sc->wimax_iface);


               if (!ed) {
                       /*

sc->wimax_iface->idesc->bNumEndpoints)); */
                       printf(("%s: couldn't get ep %d\n",
                                               USBDEVNAME(sc->wimax_dev), i));
                       return;
               }
       }

/*
       if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
                       UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
               sc->wimax_ed[WIMAX_ENDPT_RX] = ed->bEndpointAddress;
       } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
                       UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
               sc->wimax_ed[WIMAX_ENDPT_TX] = ed->bEndpointAddress;
       }
*/
       get_proto_info(sc);

}

usbd_status
wimax_usb_request(struct wimax_softc *sc, u_int8_t type,
   u_int8_t request, u_int16_t value, u_int16_t index, u_int16_t length,
   u_int8_t *data)
{
       usb_device_request_t    req;
       usbd_xfer_handle        xfer;
       usbd_status             err;
       int                     total_len = 0, s;

       req.bmRequestType = type;
       req.bRequest = request;
       USETW(req.wValue, value);
       USETW(req.wIndex, index);
       USETW(req.wLength, length);

       printf(20, ("%s: req=%02x val=%02x ind=%02x "
                               "len=%02x\n", USBDEVNAME(sc->wimax_dev), request,
                               value, index, length));

       s = splnet();

       xfer = usbd_alloc_xfer(sc->wimax_udev);
       usbd_setup_default_xfer(xfer, sc->wimax_udev, 0, 500000, &req, data,
                       length, USBD_SHORT_XFER_OK, 0);

       err = usbd_sync_transfer(xfer);

       usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);

       if (type & UT_READ) {
               printf(20, ("%s: transfered 0x%x bytes in\n",
                                       USBDEVNAME(sc->wimax_dev), total_len));
       } else {
               if (total_len != length)
                       DPRINTF(("%s: wrote only %x bytes\n",

USBDEVNAME(sc->wimax_dev), total_len));
       }

       usbd_free_xfer(xfer);

       splx(s);
       return(err);
}

int
wimax_send_command(struct atu_softc *sc, u_int8_t *command, int size)
{
       return wimax_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, 0x0000,
                       0x0000, size, command);
}

//MY CODE END <--

2009/8/4 Iain Hibbert <plunky%rya-online.net@localhost>:
> On Tue, 4 Aug 2009, Dmitry Cherkassov wrote:
>
>> What I don't understand is where can I specify the endpoint for the
>> communication?
>
> The code you post above is using the 'default' pipe for this request which
> is the 'control' endpoint and is always open. If you want to use a
> different endpoint, you need to look for it and open a different pipe..
> see the stuff in atu_complete_attach() for searching for endpoints..
>
>> My source code is attached. (file extension should be named "tgz")
>
> I could not decode your source file, sorry.. post it in plain text?
>
> iain
>
>
>


Home | Main Index | Thread Index | Old Index