Changeset 56b962d in mainline
- Timestamp:
- 2010-11-26T11:26:35Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 84439d7
- Parents:
- 0eddb76
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/stdreq.c
r0eddb76 r56b962d 39 39 #include "kbdconfig.h" 40 40 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, 41 int stdreq_on_get_descriptor(struct usbvirt_device *dev, 60 42 usb_device_request_setup_packet_t *request, uint8_t *data) 61 43 { -
uspace/app/virtusbkbd/stdreq.h
r0eddb76 r56b962d 38 38 #include <usbvirt/device.h> 39 39 40 extern usbvirt_standard_device_request_ops_t standard_request_ops; 40 int stdreq_on_get_descriptor(usbvirt_device_t *, 41 usb_device_request_setup_packet_t *, uint8_t *); 41 42 42 43 #endif -
uspace/app/virtusbkbd/virtusbkbd.c
r0eddb76 r56b962d 111 111 */ 112 112 static 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, 114 115 .on_class_device_request = on_class_request, 115 116 .on_data = on_incoming_data, -
uspace/drv/vhc/hubops.c
r0eddb76 r56b962d 65 65 void *buffer, size_t size, size_t *actual_size); 66 66 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 = NULL80 };81 82 67 /** Hub operations. */ 83 68 usbvirt_device_ops_t hub_ops = { 84 . standard_request_ops = &standard_request_ops,69 .on_standard_request[USB_DEVREQ_GET_DESCRIPTOR] = on_get_descriptor, 85 70 .on_class_device_request = on_class_request, 86 71 .on_data = NULL, -
uspace/lib/usbvirt/include/usbvirt/device.h
r0eddb76 r56b962d 47 47 uint8_t *data); 48 48 49 /** Callbacks for standard device requests.50 * When these functions are NULL or return EFORWARD, this51 * 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 67 49 /** Device operations. */ 68 50 typedef 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]; 71 55 /** Callback for class-specific USB request. */ 72 56 usbvirt_on_device_request_t on_class_device_request; -
uspace/lib/usbvirt/src/private.h
r0eddb76 r56b962d 38 38 #include <usbvirt/device.h> 39 39 #include <usbvirt/hub.h> 40 #include <assert.h> 40 41 41 42 -
uspace/lib/usbvirt/src/stdreq.c
r0eddb76 r56b962d 41 41 42 42 43 typedef int (*usbvirt_stdreq_handler_t)(usbvirt_device_t *, 44 usb_device_request_setup_packet_t *, uint8_t *); 43 45 44 46 /* … … 51 53 /** GET_DESCRIPTOR handler. */ 52 54 static 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 56 60 /* 57 61 * Standard device descriptor. … … 110 114 /** SET_ADDRESS handler. */ 111 115 static 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 115 122 if ((zero1 != 0) || (zero2 != 0)) { 116 123 return EINVAL; … … 128 135 /** SET_CONFIGURATION handler. */ 129 136 static 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 133 143 if ((zero1 != 0) || (zero2 != 0)) { 134 144 return EINVAL; … … 167 177 } 168 178 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) 179 static 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 }; 184 184 185 185 /** Handle standard device request. */ 186 186 int 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 189 191 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; 208 216 } 209 217
Note:
See TracChangeset
for help on using the changeset viewer.