Changeset f37f811 in mainline for uspace/lib/usbvirt/src/stdreq.c
- Timestamp:
- 2010-12-15T22:25:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cea3fca
- Parents:
- ea5dbaf (diff), e63a4e1 (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. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbvirt/src/stdreq.c
rea5dbaf rf37f811 40 40 #include "private.h" 41 41 42 43 44 42 /* 45 43 * All sub handlers must return EFORWARD to inform the caller that … … 51 49 /** GET_DESCRIPTOR handler. */ 52 50 static 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) 55 52 { 53 uint8_t type = setup_packet->value_high; 54 uint8_t index = setup_packet->value_low; 55 56 56 /* 57 57 * Standard device descriptor. … … 110 110 /** SET_ADDRESS handler. */ 111 111 static 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) 114 113 { 114 uint16_t new_address = setup_packet->value; 115 uint16_t zero1 = setup_packet->index; 116 uint16_t zero2 = setup_packet->length; 117 115 118 if ((zero1 != 0) || (zero2 != 0)) { 116 119 return EINVAL; … … 128 131 /** SET_CONFIGURATION handler. */ 129 132 static 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) 132 134 { 135 uint16_t configuration_value = setup_packet->value; 136 uint16_t zero1 = setup_packet->index; 137 uint16_t zero2 = setup_packet->length; 138 133 139 if ((zero1 != 0) || (zero2 != 0)) { 134 140 return EINVAL; … … 151 157 152 158 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 } 153 163 device->state = USBVIRT_STATE_ADDRESS; 154 164 } else { … … 157 167 * user selected existing configuration. 158 168 */ 169 if (DEVICE_HAS_OP(device, on_state_change)) { 170 device->ops->on_state_change(device, device->state, 171 USBVIRT_STATE_CONFIGURED); 172 } 159 173 device->state = USBVIRT_STATE_CONFIGURED; 160 174 if (device->descriptors) { … … 167 181 } 168 182 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 190 usbvirt_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 }; 209 211 210 212 /**
Note:
See TracChangeset
for help on using the changeset viewer.