Changeset f37f811 in mainline for uspace/lib/usbvirt
- Timestamp:
- 2010-12-15T22:25:01Z (15 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. - Location:
- uspace/lib/usbvirt
- Files:
-
- 1 added
- 1 deleted
- 1 edited
- 8 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbvirt/Makefile
rea5dbaf rf37f811 31 31 32 32 LIBS = $(LIBUSB_PREFIX)/libusb.a 33 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include 33 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -Iinclude 34 34 35 35 SOURCES = \ 36 callback.c \37 ctrlpipe.c \38 debug.c \39 main.c \40 s tdreq.c \41 transaction.c36 src/callback.c \ 37 src/ctrlpipe.c \ 38 src/debug.c \ 39 src/main.c \ 40 src/stdreq.c \ 41 src/transaction.c 42 42 43 43 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/usbvirt/include/usbvirt/device.h
rea5dbaf rf37f811 40 40 #include <usb/devreq.h> 41 41 42 typedef enum { 43 USBVIRT_REQUEST_TYPE_STANDARD = 0, 44 USBVIRT_REQUEST_TYPE_CLASS = 1 45 } usbvirt_request_type_t; 46 47 typedef enum { 48 USBVIRT_REQUEST_RECIPIENT_DEVICE = 0, 49 USBVIRT_REQUEST_RECIPIENT_INTERFACE = 1, 50 USBVIRT_REQUEST_RECIPIENT_ENDPOINT = 2, 51 USBVIRT_REQUEST_RECIPIENT_OTHER = 3 52 } usbvirt_request_recipient_t; 53 54 /** Possible states of virtual USB device. 55 * Notice that these are not 1:1 mappings to those in USB specification. 56 */ 57 typedef enum { 58 USBVIRT_STATE_DEFAULT, 59 USBVIRT_STATE_ADDRESS, 60 USBVIRT_STATE_CONFIGURED 61 } usbvirt_device_state_t; 62 42 63 typedef struct usbvirt_device usbvirt_device_t; 43 64 struct usbvirt_control_transfer; … … 47 68 uint8_t *data); 48 69 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 u sbvirt_on_device_request_t on_get_status;55 u sbvirt_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; 70 typedef int (*usbvirt_control_request_callback_t)(usbvirt_device_t *dev, 71 usb_device_request_setup_packet_t *request, 72 uint8_t *data); 73 74 typedef struct { 75 uint8_t request_type; 76 uint8_t request; 77 const char *name; 78 usbvirt_control_request_callback_t callback; 79 } usbvirt_control_transfer_handler_t; 80 81 #define USBVIRT_MAKE_CONTROL_REQUEST_TYPE(direction, type, recipient) \ 82 ((((direction) == USB_DIRECTION_IN) ? 1 : 0) << 7) \ 83 | (((type) & 3) << 5) \ 84 | (((recipient) & 31)) 85 86 #define USBVIRT_CONTROL_TRANSFER_HANDLER_LAST { 0, 0, NULL, NULL } 66 87 67 88 /** Device operations. */ 68 89 typedef struct { 69 /** Callbacks for standard deivce requests. */ 70 usbvirt_standard_device_request_ops_t *standard_request_ops; 71 /** Callback for class-specific USB request. */ 72 usbvirt_on_device_request_t on_class_device_request; 73 90 /** Callbacks for transfers over control pipe zero. */ 91 usbvirt_control_transfer_handler_t *control_transfer_handlers; 92 74 93 int (*on_control_transfer)(usbvirt_device_t *dev, 75 94 usb_endpoint_t endpoint, struct usbvirt_control_transfer *transfer); … … 86 105 usb_direction_t (*decide_control_transfer_direction)( 87 106 usb_endpoint_t endpoint, void *buffer, size_t size); 107 108 /** Callback when device changes its state. 109 * 110 * It is correct that this function is called when both states 111 * are equal (e.g. this function is called during SET_CONFIGURATION 112 * request done on already configured device). 113 * 114 * @warning The value of <code>dev->state</code> before calling 115 * this function is not specified (i.e. can be @p old_state or 116 * @p new_state). 117 */ 118 void (*on_state_change)(usbvirt_device_t *dev, 119 usbvirt_device_state_t old_state, usbvirt_device_state_t new_state); 88 120 } usbvirt_device_ops_t; 89 121 … … 120 152 uint8_t current_configuration; 121 153 } usbvirt_descriptors_t; 122 123 /** Possible states of virtual USB device.124 * Notice that these are not 1:1 mappings to those in USB specification.125 */126 typedef enum {127 USBVIRT_STATE_DEFAULT,128 USBVIRT_STATE_ADDRESS,129 USBVIRT_STATE_CONFIGURED130 } usbvirt_device_state_t;131 154 132 155 /** Information about on-going control transfer. … … 157 180 usbvirt_device_ops_t *ops; 158 181 182 /** Custom device data. */ 183 void *device_data; 184 159 185 /** Reply onto control transfer. 160 186 */ -
uspace/lib/usbvirt/src/callback.c
rea5dbaf rf37f811 40 40 #include <mem.h> 41 41 42 #include "hub.h"43 #include "device.h"44 42 #include "private.h" 45 43 -
uspace/lib/usbvirt/src/debug.c
rea5dbaf rf37f811 36 36 #include <bool.h> 37 37 38 #include "device.h"39 38 #include "private.h" 40 39 -
uspace/lib/usbvirt/src/main.c
rea5dbaf rf37f811 39 39 #include <assert.h> 40 40 41 #include "hub.h"42 #include "device.h"43 41 #include "private.h" 44 42 -
uspace/lib/usbvirt/src/private.h
rea5dbaf rf37f811 36 36 #define LIBUSBVIRT_PRIVATE_H_ 37 37 38 #include "device.h" 39 #include "hub.h" 38 #include <usbvirt/device.h> 39 #include <usbvirt/hub.h> 40 #include <assert.h> 40 41 41 42 … … 86 87 } 87 88 89 extern usbvirt_control_transfer_handler_t control_pipe_zero_local_handlers[]; 90 88 91 #endif 89 92 /** -
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 /** -
uspace/lib/usbvirt/src/transaction.c
rea5dbaf rf37f811 37 37 #include <mem.h> 38 38 39 #include "hub.h"40 39 #include "private.h" 41 40
Note:
See TracChangeset
for help on using the changeset viewer.