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

Changeset 11658b64 in mainline for uspace/lib/usbvirt/src/stdreq.c


Ignore:
Timestamp:
2010-12-16T11:54:53Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
557c7d0, 5863a95, 82122f3, a8b7dfd, f2962621
Parents:
a9b6bec (diff), 70e5ad5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged vojtechhorky/ - libusbvirt clean-up

File:
1 moved

Legend:

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

    ra9b6bec r11658b64  
    4040#include "private.h"
    4141
    42 
    43 
    4442/*
    4543 * All sub handlers must return EFORWARD to inform the caller that
     
    5149/** GET_DESCRIPTOR handler. */
    5250static int handle_get_descriptor(usbvirt_device_t *device,
    53     uint8_t type, uint8_t index, uint16_t language,
    54     uint16_t length)
     51    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
    5552{
     53        uint8_t type = setup_packet->value_high;
     54        uint8_t index = setup_packet->value_low;
     55
    5656        /*
    5757         * Standard device descriptor.
     
    110110/** SET_ADDRESS handler. */
    111111static int handle_set_address(usbvirt_device_t *device,
    112     uint16_t new_address,
    113     uint16_t zero1, uint16_t zero2)
     112    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
    114113{
     114        uint16_t new_address = setup_packet->value;
     115        uint16_t zero1 = setup_packet->index;
     116        uint16_t zero2 = setup_packet->length;
     117
    115118        if ((zero1 != 0) || (zero2 != 0)) {
    116119                return EINVAL;
     
    128131/** SET_CONFIGURATION handler. */
    129132static int handle_set_configuration(usbvirt_device_t *device,
    130     uint16_t configuration_value,
    131     uint16_t zero1, uint16_t zero2)
     133    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
    132134{
     135        uint16_t configuration_value = setup_packet->value;
     136        uint16_t zero1 = setup_packet->index;
     137        uint16_t zero2 = setup_packet->length;
     138
    133139        if ((zero1 != 0) || (zero2 != 0)) {
    134140                return EINVAL;
     
    151157       
    152158        if (configuration_value == 0) {
     159                if (DEVICE_HAS_OP(device, on_state_change)) {
     160                        device->ops->on_state_change(device, device->state,
     161                            USBVIRT_STATE_ADDRESS);
     162                }
    153163                device->state = USBVIRT_STATE_ADDRESS;
    154164        } else {
     
    157167                * user selected existing configuration.
    158168                */
     169                if (DEVICE_HAS_OP(device, on_state_change)) {
     170                        device->ops->on_state_change(device, device->state,
     171                            USBVIRT_STATE_CONFIGURED);
     172                }
    159173                device->state = USBVIRT_STATE_CONFIGURED;
    160174                if (device->descriptors) {
     
    167181}
    168182
    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)
    184 
    185 /** Handle standard device request. */
    186 int handle_std_request(usbvirt_device_t *device,
    187     usb_device_request_setup_packet_t *request, uint8_t *data)
    188 {
    189         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;
    208 }
     183
     184#define MAKE_BM_REQUEST(direction, recipient) \
     185        USBVIRT_MAKE_CONTROL_REQUEST_TYPE(direction, \
     186            USBVIRT_REQUEST_TYPE_STANDARD, recipient)
     187#define MAKE_BM_REQUEST_DEV(direction) \
     188        MAKE_BM_REQUEST(direction, USBVIRT_REQUEST_RECIPIENT_DEVICE)
     189
     190usbvirt_control_transfer_handler_t control_pipe_zero_local_handlers[] = {
     191        {
     192                .request_type = MAKE_BM_REQUEST_DEV(USB_DIRECTION_IN),
     193                .request = USB_DEVREQ_GET_DESCRIPTOR,
     194                .name = "GetDescriptor()",
     195                .callback = handle_get_descriptor
     196        },
     197        {
     198                .request_type = MAKE_BM_REQUEST_DEV(USB_DIRECTION_OUT),
     199                .request = USB_DEVREQ_SET_ADDRESS,
     200                .name = "SetAddress()",
     201                .callback = handle_set_address
     202        },
     203        {
     204                .request_type = MAKE_BM_REQUEST_DEV(USB_DIRECTION_OUT),
     205                .request = USB_DEVREQ_SET_CONFIGURATION,
     206                .name = "SetConfiguration()",
     207                .callback = handle_set_configuration
     208        },
     209        USBVIRT_CONTROL_TRANSFER_HANDLER_LAST
     210};
    209211
    210212/**
Note: See TracChangeset for help on using the changeset viewer.