Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 56b962d in mainline for uspace/lib/usbvirt/src/stdreq.c


Ignore:
Timestamp:
2010-11-26T11:26:35Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
84439d7
Parents:
0eddb76
Message:

Standard request callbacks use array in libusbvirt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/src/stdreq.c

    r0eddb76 r56b962d  
    4141
    4242
     43typedef int (*usbvirt_stdreq_handler_t)(usbvirt_device_t *,
     44usb_device_request_setup_packet_t *, uint8_t *);
    4345
    4446/*
     
    5153/** GET_DESCRIPTOR handler. */
    5254static int handle_get_descriptor(usbvirt_device_t *device,
    53     uint8_t type, uint8_t index, uint16_t language,
    54     uint16_t length)
    55 {
     55    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
     56{
     57        uint8_t type = setup_packet->value_high;
     58        uint8_t index = setup_packet->value_low;
     59
    5660        /*
    5761         * Standard device descriptor.
     
    110114/** SET_ADDRESS handler. */
    111115static int handle_set_address(usbvirt_device_t *device,
    112     uint16_t new_address,
    113     uint16_t zero1, uint16_t zero2)
    114 {
     116    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
     117{
     118        uint16_t new_address = setup_packet->value;
     119        uint16_t zero1 = setup_packet->index;
     120        uint16_t zero2 = setup_packet->length;
     121
    115122        if ((zero1 != 0) || (zero2 != 0)) {
    116123                return EINVAL;
     
    128135/** SET_CONFIGURATION handler. */
    129136static int handle_set_configuration(usbvirt_device_t *device,
    130     uint16_t configuration_value,
    131     uint16_t zero1, uint16_t zero2)
    132 {
     137    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
     138{
     139        uint16_t configuration_value = setup_packet->value;
     140        uint16_t zero1 = setup_packet->index;
     141        uint16_t zero2 = setup_packet->length;
     142
    133143        if ((zero1 != 0) || (zero2 != 0)) {
    134144                return EINVAL;
     
    167177}
    168178
    169 #define HANDLE_REQUEST(request, data, type, dev, user_callback, default_handler) \
    170         do { \
    171                 if ((request)->request == (type)) { \
    172                         int _rc = EFORWARD; \
    173                         if (((dev)->ops) && ((dev)->ops->standard_request_ops) \
    174                             && ((dev)->ops->standard_request_ops->user_callback)) { \
    175                                 _rc = (dev)->ops->standard_request_ops->\
    176                                     user_callback(dev, request, data); \
    177                         } \
    178                         if (_rc == EFORWARD) { \
    179                                 default_handler; \
    180                         } \
    181                         return _rc; \
    182                 } \
    183         } while (false)
     179static usbvirt_stdreq_handler_t local_handlers[USB_DEVREQ_LAST_STD] = {
     180        [USB_DEVREQ_GET_DESCRIPTOR] = handle_get_descriptor,
     181        [USB_DEVREQ_SET_ADDRESS] = handle_set_address,
     182        [USB_DEVREQ_SET_CONFIGURATION] = handle_set_configuration
     183};
    184184
    185185/** Handle standard device request. */
    186186int handle_std_request(usbvirt_device_t *device,
    187     usb_device_request_setup_packet_t *request, uint8_t *data)
    188 {
     187    usb_device_request_setup_packet_t *request_packet, uint8_t *data)
     188{
     189        int request = request_packet->request;
     190
    189191        device->lib_debug(device, 3, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
    190             "handling standard request %d", request->request);
    191        
    192         HANDLE_REQUEST(request, data, USB_DEVREQ_GET_DESCRIPTOR,
    193             device, on_get_descriptor,
    194             handle_get_descriptor(device, request->value_high, request->value_low,
    195                 request->index, request->length));
    196        
    197         HANDLE_REQUEST(request, data, USB_DEVREQ_SET_ADDRESS,
    198             device, on_set_address,
    199             handle_set_address(device, request->value,
    200                 request->index, request->length));
    201        
    202         HANDLE_REQUEST(request, data, USB_DEVREQ_SET_CONFIGURATION,
    203             device, on_set_configuration,
    204             handle_set_configuration(device, request->value,
    205                 request->index, request->length));
    206        
    207         return ENOTSUP;
     192            "handling standard request %d", request);
     193
     194        if (request >= USB_DEVREQ_LAST_STD) {
     195                return ENOTSUP;
     196        }
     197       
     198        int rc = EFORWARD;
     199        if ((device->ops)
     200            && (device->ops->on_standard_request[request])) {
     201                rc = device->ops->on_standard_request[request](device,
     202                    request_packet, data);
     203        }
     204
     205        if (rc == EFORWARD) {
     206                if (local_handlers[request]) {
     207                        rc = local_handlers[request](device,
     208                            request_packet, data);
     209                } else {
     210                        rc = ENOTSUP;
     211                }
     212        }
     213
     214        assert(rc != EFORWARD);
     215        return rc;
    208216}
    209217
Note: See TracChangeset for help on using the changeset viewer.