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

Changeset 56b962d in mainline


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

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/stdreq.c

    r0eddb76 r56b962d  
    3939#include "kbdconfig.h"
    4040
    41 static int on_get_descriptor(struct usbvirt_device *dev,
    42     usb_device_request_setup_packet_t *request, uint8_t *data);
    43 
    44 usbvirt_standard_device_request_ops_t standard_request_ops = {
    45         .on_get_status = NULL,
    46         .on_clear_feature = NULL,
    47         .on_set_feature = NULL,
    48         .on_set_address = NULL,
    49         .on_get_descriptor = on_get_descriptor,
    50         .on_set_descriptor = NULL,
    51         .on_get_configuration = NULL,
    52         .on_set_configuration = NULL,
    53         .on_get_interface = NULL,
    54         .on_set_interface = NULL,
    55         .on_synch_frame = NULL
    56 };
    57 
    58 
    59 static int on_get_descriptor(struct usbvirt_device *dev,
     41int stdreq_on_get_descriptor(struct usbvirt_device *dev,
    6042    usb_device_request_setup_packet_t *request, uint8_t *data)
    6143{
  • uspace/app/virtusbkbd/stdreq.h

    r0eddb76 r56b962d  
    3838#include <usbvirt/device.h>
    3939
    40 extern usbvirt_standard_device_request_ops_t standard_request_ops;
     40int stdreq_on_get_descriptor(usbvirt_device_t *,
     41    usb_device_request_setup_packet_t *, uint8_t *);
    4142
    4243#endif
  • uspace/app/virtusbkbd/virtusbkbd.c

    r0eddb76 r56b962d  
    111111 */
    112112static usbvirt_device_ops_t keyboard_ops = {
    113         .standard_request_ops = &standard_request_ops,
     113        .on_standard_request[USB_DEVREQ_GET_DESCRIPTOR]
     114            = stdreq_on_get_descriptor,
    114115        .on_class_device_request = on_class_request,
    115116        .on_data = on_incoming_data,
  • uspace/drv/vhc/hubops.c

    r0eddb76 r56b962d  
    6565    void *buffer, size_t size, size_t *actual_size);
    6666
    67 /** Standard USB requests. */
    68 static usbvirt_standard_device_request_ops_t standard_request_ops = {
    69         .on_get_status = NULL,
    70         .on_clear_feature = NULL,
    71         .on_set_feature = NULL,
    72         .on_set_address = NULL,
    73         .on_get_descriptor = on_get_descriptor,
    74         .on_set_descriptor = NULL,
    75         .on_get_configuration = NULL,
    76         .on_set_configuration = NULL,
    77         .on_get_interface = NULL,
    78         .on_set_interface = NULL,
    79         .on_synch_frame = NULL
    80 };
    81 
    8267/** Hub operations. */
    8368usbvirt_device_ops_t hub_ops = {
    84         .standard_request_ops = &standard_request_ops,
     69        .on_standard_request[USB_DEVREQ_GET_DESCRIPTOR] = on_get_descriptor,
    8570        .on_class_device_request = on_class_request,
    8671        .on_data = NULL,
  • uspace/lib/usbvirt/include/usbvirt/device.h

    r0eddb76 r56b962d  
    4747        uint8_t *data);
    4848
    49 /** Callbacks for standard device requests.
    50  * When these functions are NULL or return EFORWARD, this
    51  * framework will try to satisfy the request by itself.
    52  */
    53 typedef struct {
    54         usbvirt_on_device_request_t on_get_status;
    55         usbvirt_on_device_request_t on_clear_feature;
    56         usbvirt_on_device_request_t on_set_feature;
    57         usbvirt_on_device_request_t on_set_address;
    58         usbvirt_on_device_request_t on_get_descriptor;
    59         usbvirt_on_device_request_t on_set_descriptor;
    60         usbvirt_on_device_request_t on_get_configuration;
    61         usbvirt_on_device_request_t on_set_configuration;
    62         usbvirt_on_device_request_t on_get_interface;
    63         usbvirt_on_device_request_t on_set_interface;
    64         usbvirt_on_device_request_t on_synch_frame;
    65 } usbvirt_standard_device_request_ops_t;
    66 
    6749/** Device operations. */
    6850typedef struct {
    69         /** Callbacks for standard deivce requests. */
    70         usbvirt_standard_device_request_ops_t *standard_request_ops;
     51        /** Callbacks for standard device requests.
     52         * The callbacks are indexed by usb_stddevreq_t enum.
     53         */
     54        usbvirt_on_device_request_t on_standard_request[USB_DEVREQ_LAST_STD];
    7155        /** Callback for class-specific USB request. */
    7256        usbvirt_on_device_request_t on_class_device_request;
  • uspace/lib/usbvirt/src/private.h

    r0eddb76 r56b962d  
    3838#include <usbvirt/device.h>
    3939#include <usbvirt/hub.h>
     40#include <assert.h>
    4041
    4142
  • 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.