Changeset d97d209 in mainline
- Timestamp:
- 2010-10-10T22:01:32Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2c970ee
- Parents:
- 0e41957
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/virtusbkbd.c
r0e41957 rd97d209 47 47 #include <usb/hcd.h> 48 48 #include <usb/device.h> 49 #include <usb/hid.h> 49 50 #include <usbvirt/device.h> 50 51 #include <usbvirt/hub.h> … … 70 71 } 71 72 73 static int on_class_request(struct usbvirt_device *dev, 74 usb_device_request_setup_packet_t *request, uint8_t *data) 75 { 76 printf("%s: class request (%d)\n", NAME, (int) request->request); 77 78 return EOK; 79 } 80 72 81 static usb_standard_device_descriptor_t std_descriptor = { 73 82 .length = sizeof(usb_standard_device_descriptor_t), … … 85 94 */ 86 95 static usbvirt_device_ops_t keyboard_ops = { 96 .on_devreq_class = on_class_request, 87 97 .on_data = on_incoming_data 88 98 }; -
uspace/lib/usbvirt/ctrlpipe.c
r0e41957 rd97d209 45 45 ((value & GET_MIDBITS_MASK(size, shift)) >> shift) 46 46 47 static usb_direction_t request_get_direction(uint8_t request_type)48 {49 int bit7 = GET_MIDBITS(request_type, 1, 7);50 return bit7 ? USB_DIRECTION_IN : USB_DIRECTION_OUT;51 }52 53 47 static int request_get_type(uint8_t request_type) 54 48 { … … 56 50 } 57 51 58 static int request_get_recipient(uint8_t request_type)59 {60 return GET_MIDBITS(request_type, 5, 0);61 }62 52 63 64 typedef struct {65 uint8_t request_type;66 uint8_t request;67 uint16_t value;68 uint16_t index;69 uint16_t length;70 } __attribute__ ((packed)) devreq_setup_packet_t;71 53 72 54 int control_pipe(void *buffer, size_t size) 73 55 { 74 if (size < sizeof( devreq_setup_packet_t)) {56 if (size < sizeof(usb_device_request_setup_packet_t)) { 75 57 return ENOMEM; 76 58 } 77 59 78 devreq_setup_packet_t *request = (devreq_setup_packet_t *) buffer;79 uint8_t *remaining_data = ((uint8_t *) request) + sizeof( devreq_setup_packet_t);60 usb_device_request_setup_packet_t *request = (usb_device_request_setup_packet_t *) buffer; 61 uint8_t *remaining_data = ((uint8_t *) request) + sizeof(usb_device_request_setup_packet_t); 80 62 81 usb_direction_t direction = request_get_direction(request->request_type);82 63 int type = request_get_type(request->request_type); 83 int recipient = request_get_recipient(request->request_type);84 85 64 86 65 switch (type) { 87 66 case REQUEST_TYPE_STANDARD: 88 return handle_std_request(direction, recipient, 89 request->request, request->value, 90 request->index, request->length, 91 remaining_data); 67 return handle_std_request(request, remaining_data); 92 68 break; 93 69 case REQUEST_TYPE_CLASS: 94 70 if (DEVICE_HAS_OP(device, on_devreq_class)) { 95 71 return device->ops->on_devreq_class(device, 96 direction, recipient, 97 request->request, request->value, 98 request->index, request->length, 99 remaining_data); 72 request, remaining_data); 100 73 } 101 74 break; -
uspace/lib/usbvirt/device.h
r0e41957 rd97d209 42 42 struct usbvirt_device; 43 43 44 typedef int (*usbvirt_on_devreq_t)(struct usbvirt_device *dev, 45 usb_direction_t, int recipient, 46 uint8_t request, uint16_t value, uint16_t index, uint16_t length, 47 uint8_t *remaining_data); 44 typedef int (*usbvirt_on_device_request_t)(struct usbvirt_device *dev, 45 usb_device_request_setup_packet_t *request, 46 uint8_t *data); 48 47 49 48 typedef struct { 50 usbvirt_on_dev req_t on_devreq_std;51 usbvirt_on_dev req_t on_devreq_class;49 usbvirt_on_device_request_t on_devreq_std; 50 usbvirt_on_device_request_t on_devreq_class; 52 51 int (*on_data)(struct usbvirt_device *dev, 53 52 usb_endpoint_t endpoint, void *buffer, size_t size); -
uspace/lib/usbvirt/private.h
r0e41957 rd97d209 55 55 int control_pipe(void *buffer, size_t size); 56 56 57 int handle_std_request(usb_direction_t direction, int recipient, 58 uint16_t request, uint16_t value, uint16_t index, uint16_t length, 59 uint8_t *remaining_data); 57 int handle_std_request(usb_device_request_setup_packet_t *request, uint8_t *data); 60 58 61 59 #endif -
uspace/lib/usbvirt/stdreq.c
r0e41957 rd97d209 81 81 } 82 82 83 int handle_std_request(usb_direction_t direction, int recipient, 84 uint16_t request, uint16_t value, uint16_t index, uint16_t length, 85 uint8_t *remaining_data) 83 int handle_std_request(usb_device_request_setup_packet_t *request, uint8_t *data) 86 84 { 87 85 int rc; 88 86 89 switch (request ) {87 switch (request->request) { 90 88 case USB_DEVREQ_GET_DESCRIPTOR: 91 rc = handle_get_descriptor(value >> 8, (uint8_t) value, 92 index, length); 89 rc = handle_get_descriptor( 90 request->value_low, request->value_high, 91 request->index, request->length); 93 92 break; 94 93 95 94 case USB_DEVREQ_SET_ADDRESS: 96 rc = handle_set_address(value, index, length); 95 rc = handle_set_address(request->value, 96 request->index, request->length); 97 97 break; 98 98 … … 108 108 if (rc == EFORWARD) { 109 109 if (DEVICE_HAS_OP(device, on_devreq_std)) { 110 return device->ops->on_devreq_std(device, direction, 111 recipient, 112 request, value, index, 113 length, remaining_data); 110 return device->ops->on_devreq_std(device, 111 request, data); 114 112 } 115 113 }
Note:
See TracChangeset
for help on using the changeset viewer.