Changeset b4b534ac in mainline for uspace/lib/usbvirt/src
- Timestamp:
- 2016-07-22T08:24:47Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f76d2c2
- Parents:
- 5b18137 (diff), 8351f9a4 (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. - Location:
- uspace/lib/usbvirt/src
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbvirt/src/ctrltransfer.c
r5b18137 rb4b534ac 50 50 */ 51 51 int process_control_transfer(usbvirt_device_t *dev, 52 usbvirt_control_request_handler_t *control_handlers,53 usb_device_request_setup_packet_t *setup,52 const usbvirt_control_request_handler_t *control_handlers, 53 const usb_device_request_setup_packet_t *setup, 54 54 uint8_t *data, size_t *data_sent_size) 55 55 { … … 60 60 return EFORWARD; 61 61 } 62 63 usb_direction_t direction = setup->request_type & 128 ? 64 USB_DIRECTION_IN : USB_DIRECTION_OUT; 65 usb_request_recipient_t req_recipient = setup->request_type & 31; 66 usb_request_type_t req_type = (setup->request_type >> 5) & 3; 67 68 usbvirt_control_request_handler_t *handler = control_handlers; 69 while (handler->callback != NULL) { 70 if (handler->req_direction != direction) { 71 goto next; 72 } 73 if (handler->req_recipient != req_recipient) { 74 goto next; 75 } 76 if (handler->req_type != req_type) { 77 goto next; 78 } 79 if (handler->request != setup->request) { 80 goto next; 62 const usbvirt_control_request_handler_t *handler = control_handlers; 63 for (;handler->callback != NULL; ++handler) { 64 if (handler->request != setup->request || 65 handler->request_type != setup->request_type) { 66 continue; 81 67 } 82 68 … … 84 70 usb_debug_str_buffer((uint8_t*) setup, sizeof(*setup), 0)); 85 71 int rc = handler->callback(dev, setup, data, data_sent_size); 86 if (rc == EFORWARD) {87 goto next;72 if (rc != EFORWARD) { 73 return rc; 88 74 } 89 75 90 return rc;91 92 next:93 handler++;94 76 } 95 77 -
uspace/lib/usbvirt/src/private.h
r5b18137 rb4b534ac 39 39 40 40 int process_control_transfer(usbvirt_device_t *, 41 usbvirt_control_request_handler_t *,42 usb_device_request_setup_packet_t *,41 const usbvirt_control_request_handler_t *, 42 const usb_device_request_setup_packet_t *, 43 43 uint8_t *, size_t *); 44 44 -
uspace/lib/usbvirt/src/stdreq.c
r5b18137 rb4b534ac 51 51 void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *setup_packet, 52 52 uint8_t *data, size_t *act_size, 53 void *actual_data, size_t actual_data_size)53 const void *actual_data, size_t actual_data_size) 54 54 { 55 55 size_t expected_size = setup_packet->length; … … 63 63 *act_size = actual_data_size; 64 64 } 65 } 66 67 /** NOP handler */ 68 int req_nop(usbvirt_device_t *device, 69 const usb_device_request_setup_packet_t *setup_packet, 70 uint8_t *data, size_t *act_size) 71 { 72 return EOK; 65 73 } 66 74 … … 98 106 } 99 107 /* Copy the data. */ 100 usbvirt_device_configuration_t *config = &device->descriptors101 ->configuration[index];108 const usbvirt_device_configuration_t *config = 109 &device->descriptors->configuration[index]; 102 110 uint8_t *all_data = malloc(config->descriptor->total_length); 103 111 if (all_data == NULL) { … … 110 118 size_t i; 111 119 for (i = 0; i < config->extra_count; i++) { 112 usbvirt_device_configuration_extras_t *extra120 const usbvirt_device_configuration_extras_t *extra 113 121 = &config->extra[i]; 114 122 memcpy(ptr, extra->data, extra->length); … … 189 197 } 190 198 199 static int req_get_dev_status(usbvirt_device_t *device, 200 const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size) 201 { 202 if (setup_packet->length != 2) 203 return ESTALL; 204 data[0] = (device->self_powered ? 1 : 0) | (device->remote_wakeup ? 2 : 0); 205 data[1] = 0; 206 *act_size = 2; 207 return EOK; 208 } 209 static int req_get_iface_ep_status(usbvirt_device_t *device, 210 const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size) 211 { 212 if (setup_packet->length != 2) 213 return ESTALL; 214 data[0] = 0; 215 data[1] = 0; 216 *act_size = 2; 217 return EOK; 218 } 219 191 220 /** Standard request handlers. */ 192 221 usbvirt_control_request_handler_t library_handlers[] = { 193 222 { 194 .req_direction = USB_DIRECTION_OUT, 195 .req_recipient = USB_REQUEST_RECIPIENT_DEVICE, 196 .req_type = USB_REQUEST_TYPE_STANDARD, 197 .request = USB_DEVREQ_SET_ADDRESS, 223 STD_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_SET_ADDRESS), 198 224 .name = "SetAddress", 199 225 .callback = req_set_address 200 226 }, 201 227 { 202 .req_direction = USB_DIRECTION_IN, 203 .req_recipient = USB_REQUEST_RECIPIENT_DEVICE, 204 .req_type = USB_REQUEST_TYPE_STANDARD, 205 .request = USB_DEVREQ_GET_DESCRIPTOR, 206 .name = "GetDescriptor", 228 STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR), 229 .name = "GetStdDescriptor", 207 230 .callback = req_get_descriptor 208 231 }, 209 232 { 210 .req_direction = USB_DIRECTION_OUT, 211 .req_recipient = USB_REQUEST_RECIPIENT_DEVICE, 212 .req_type = USB_REQUEST_TYPE_STANDARD, 213 .request = USB_DEVREQ_SET_CONFIGURATION, 233 STD_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_SET_CONFIGURATION), 214 234 .name = "SetConfiguration", 215 235 .callback = req_set_configuration 216 236 }, 217 237 { 238 STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_STATUS), 239 .name = "GetDeviceStatus", 240 .callback = req_get_dev_status, 241 }, 242 { 243 STD_REQ_IN(USB_REQUEST_RECIPIENT_INTERFACE, USB_DEVREQ_GET_STATUS), 244 .name = "GetInterfaceStatus", 245 .callback = req_get_iface_ep_status, 246 }, 247 { 248 /* virtual EPs by default cannot be stalled */ 249 STD_REQ_IN(USB_REQUEST_RECIPIENT_ENDPOINT, USB_DEVREQ_GET_STATUS), 250 .name = "GetEndpointStatus", 251 .callback = req_get_iface_ep_status, 252 }, 218 253 { .callback = NULL } 219 254 }; -
uspace/lib/usbvirt/src/transfer.c
r5b18137 rb4b534ac 51 51 */ 52 52 static int usbvirt_control_transfer(usbvirt_device_t *dev, 53 void *setup, size_t setup_size,53 const void *setup, size_t setup_size, 54 54 void *data, size_t data_size, size_t *data_size_sent) 55 55 { … … 60 60 return ESTALL; 61 61 } 62 usb_device_request_setup_packet_t *setup_packet = setup;62 const usb_device_request_setup_packet_t *setup_packet = setup; 63 63 if (data_size != setup_packet->length) { 64 64 return ESTALL; … … 100 100 * @return Error code. 101 101 */ 102 int usbvirt_control_write(usbvirt_device_t *dev, void *setup, size_t setup_size,103 void *data, size_t data_size)102 int usbvirt_control_write(usbvirt_device_t *dev, const void *setup, 103 size_t setup_size, void *data, size_t data_size) 104 104 { 105 105 return usbvirt_control_transfer(dev, setup, setup_size, … … 119 119 * @return Error code. 120 120 */ 121 int usbvirt_control_read(usbvirt_device_t *dev, void *setup, size_t setup_size,121 int usbvirt_control_read(usbvirt_device_t *dev, const void *setup, size_t setup_size, 122 122 void *data, size_t data_size, size_t *data_size_sent) 123 123 { … … 136 136 */ 137 137 int usbvirt_data_out(usbvirt_device_t *dev, usb_transfer_type_t transf_type, 138 usb_endpoint_t endpoint, void *data, size_t data_size)138 usb_endpoint_t endpoint, const void *data, size_t data_size) 139 139 { 140 140 if ((endpoint <= 0) || (endpoint >= USBVIRT_ENDPOINT_MAX)) {
Note:
See TracChangeset
for help on using the changeset viewer.