Changeset 9e195e2c in mainline for uspace/lib
- Timestamp:
- 2011-05-12T09:03:00Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d59d0bb
- Parents:
- 456aea3 (diff), c372e03 (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
- Files:
-
- 6 added
- 2 deleted
- 19 edited
- 53 moved
-
c/generic/devman.c (modified) (1 diff)
-
c/include/devman.h (modified) (1 diff)
-
c/include/ipc/devman.h (modified) (1 diff)
-
drv/generic/remote_usbhc.c (modified) (8 diffs)
-
drv/include/usb_iface.h (modified) (1 diff)
-
drv/include/usbhc_iface.h (modified) (2 diffs)
-
usb/Makefile (modified) (1 diff)
-
usb/include/usb/classes/hid.h (deleted)
-
usb/include/usb/ddfiface.h (modified) (1 diff)
-
usb/include/usb/descriptor.h (modified) (1 diff)
-
usb/include/usb/driver.h (moved) (moved from uspace/app/virtusbkbd/stdreq.h ) (2 diffs)
-
usb/include/usb/host.h (moved) (moved from uspace/app/virtusbkbd/descriptor.h ) (2 diffs)
-
usb/include/usb/usb.h (modified) (1 diff)
-
usb/src/ddfiface.c (modified) (1 diff)
-
usb/src/driver.c (moved) (moved from uspace/app/tester/adt/usbaddrkeep.c ) (2 diffs)
-
usb/src/dump.c (modified) (1 diff)
-
usb/src/host.c (moved) (moved from uspace/app/virtusbkbd/stdreq.c ) (2 diffs)
-
usbdev/Makefile (added)
-
usbdev/include/usb/devdrv.h (moved) (moved from uspace/lib/usb/include/usb/devdrv.h )
-
usbdev/include/usb/devpoll.h (moved) (moved from uspace/lib/usb/include/usb/devpoll.h )
-
usbdev/include/usb/dp.h (moved) (moved from uspace/lib/usb/include/usb/dp.h )
-
usbdev/include/usb/hub.h (moved) (moved from uspace/lib/usb/include/usb/hub.h ) (1 diff)
-
usbdev/include/usb/pipes.h (moved) (moved from uspace/lib/usb/include/usb/pipes.h )
-
usbdev/include/usb/recognise.h (moved) (moved from uspace/lib/usb/include/usb/recognise.h )
-
usbdev/include/usb/request.h (moved) (moved from uspace/lib/usb/include/usb/request.h ) (1 diff)
-
usbdev/include/usb/usbdevice.h (moved) (moved from uspace/lib/usb/include/usb/usbdevice.h ) (1 diff)
-
usbdev/src/altiface.c (moved) (moved from uspace/lib/usb/src/altiface.c )
-
usbdev/src/devdrv.c (moved) (moved from uspace/lib/usb/src/devdrv.c )
-
usbdev/src/devpoll.c (moved) (moved from uspace/lib/usb/src/devpoll.c )
-
usbdev/src/dp.c (moved) (moved from uspace/lib/usb/src/dp.c )
-
usbdev/src/hub.c (moved) (moved from uspace/lib/usb/src/hub.c ) (1 diff)
-
usbdev/src/pipepriv.c (moved) (moved from uspace/lib/usb/src/pipepriv.c )
-
usbdev/src/pipepriv.h (moved) (moved from uspace/lib/usb/src/pipepriv.h )
-
usbdev/src/pipes.c (moved) (moved from uspace/lib/usb/src/pipes.c ) (1 diff)
-
usbdev/src/pipesinit.c (moved) (moved from uspace/lib/usb/src/pipesinit.c )
-
usbdev/src/pipesio.c (moved) (moved from uspace/lib/usb/src/pipesio.c )
-
usbdev/src/recognise.c (moved) (moved from uspace/lib/usb/src/recognise.c )
-
usbdev/src/request.c (moved) (moved from uspace/lib/usb/src/request.c ) (1 diff)
-
usbdev/src/usbdevice.c (moved) (moved from uspace/lib/usb/src/usbdevice.c ) (1 diff)
-
usbhid/Makefile (added)
-
usbhid/include/usb/classes/hid.h (moved) (moved from uspace/app/virtusbkbd/kbdconfig.h ) (1 diff)
-
usbhid/include/usb/classes/hid/iface.h (moved) (moved from uspace/lib/usb/include/usb/classes/hid/iface.h )
-
usbhid/include/usb/classes/hid/utled.h (moved) (moved from uspace/lib/usb/include/usb/classes/hid/utled.h )
-
usbhid/include/usb/classes/hid_report_items.h (moved) (moved from uspace/lib/usb/include/usb/classes/hid_report_items.h )
-
usbhid/include/usb/classes/hiddescriptor.h (moved) (moved from uspace/lib/usb/include/usb/classes/hiddescriptor.h )
-
usbhid/include/usb/classes/hidparser.h (moved) (moved from uspace/lib/usb/include/usb/classes/hidparser.h )
-
usbhid/include/usb/classes/hidpath.h (moved) (moved from uspace/lib/usb/include/usb/classes/hidpath.h )
-
usbhid/include/usb/classes/hidreport.h (moved) (moved from uspace/lib/usb/include/usb/classes/hidreport.h )
-
usbhid/include/usb/classes/hidreq.h (moved) (moved from uspace/lib/usb/include/usb/classes/hidreq.h )
-
usbhid/include/usb/classes/hidtypes.h (moved) (moved from uspace/lib/usb/include/usb/classes/hidtypes.h )
-
usbhid/include/usb/classes/hidut.h (moved) (moved from uspace/lib/usb/include/usb/classes/hidut.h )
-
usbhid/include/usb/classes/hidutkbd.h (moved) (moved from uspace/lib/usb/include/usb/classes/hidutkbd.h )
-
usbhid/src/hiddescriptor.c (moved) (moved from uspace/lib/usb/src/hiddescriptor.c ) (2 diffs)
-
usbhid/src/hidiface.c (moved) (moved from uspace/lib/usb/src/hidiface.c )
-
usbhid/src/hidparser.c (moved) (moved from uspace/lib/usb/src/hidparser.c )
-
usbhid/src/hidpath.c (moved) (moved from uspace/lib/usb/src/hidpath.c )
-
usbhid/src/hidreport.c (moved) (moved from uspace/lib/usb/src/hidreport.c )
-
usbhid/src/hidreq.c (moved) (moved from uspace/lib/usb/src/hidreq.c )
-
usbhost/Makefile (added)
-
usbhost/include/usb/addrkeep.h (moved) (moved from uspace/lib/usb/include/usb/addrkeep.h )
-
usbhost/include/usb/host/batch.h (moved) (moved from uspace/lib/usb/include/usb/host/batch.h )
-
usbhost/include/usb/host/device_keeper.h (moved) (moved from uspace/lib/usb/include/usb/host/device_keeper.h ) (1 diff)
-
usbhost/include/usb/host/endpoint.h (moved) (moved from uspace/lib/usb/include/usb/host/endpoint.h )
-
usbhost/include/usb/host/usb_endpoint_manager.h (moved) (moved from uspace/lib/usb/include/usb/host/usb_endpoint_manager.h )
-
usbhost/src/addrkeep.c (moved) (moved from uspace/lib/usb/src/addrkeep.c )
-
usbhost/src/batch.c (moved) (moved from uspace/lib/usb/src/host/batch.c )
-
usbhost/src/device_keeper.c (moved) (moved from uspace/lib/usb/src/host/device_keeper.c ) (1 diff)
-
usbhost/src/endpoint.c (moved) (moved from uspace/lib/usb/src/host/endpoint.c )
-
usbhost/src/usb_endpoint_manager.c (moved) (moved from uspace/lib/usb/src/host/usb_endpoint_manager.c )
-
usbvirt/Makefile (modified) (1 diff)
-
usbvirt/include/usbvirt/device.h (modified) (4 diffs)
-
usbvirt/include/usbvirt/ipc.h (modified) (4 diffs)
-
usbvirt/src/ctrltransfer.c (modified) (3 diffs)
-
usbvirt/src/device.c (added)
-
usbvirt/src/ipc.c (deleted)
-
usbvirt/src/ipc_dev.c (added)
-
usbvirt/src/ipc_hc.c (added)
-
usbvirt/src/private.h (modified) (2 diffs)
-
usbvirt/src/stdreq.c (modified) (4 diffs)
-
usbvirt/src/transfer.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/devman.c
r456aea3 r9e195e2c 374 374 } 375 375 376 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size) 377 { 378 int phone = devman_get_phone(DEVMAN_CLIENT, 0); 379 380 if (phone < 0) 381 return phone; 382 383 async_serialize_start(); 384 385 ipc_call_t answer; 386 aid_t req = async_send_1(phone, DEVMAN_DEVICE_GET_DEVICE_PATH, 387 handle, &answer); 388 389 ipc_call_t data_request_call; 390 aid_t data_request = async_data_read(phone, path, path_size, 391 &data_request_call); 392 if (data_request == 0) { 393 async_wait_for(req, NULL); 394 async_serialize_end(); 395 return ENOMEM; 396 } 397 398 sysarg_t data_request_rc; 399 sysarg_t opening_request_rc; 400 async_wait_for(data_request, &data_request_rc); 401 async_wait_for(req, &opening_request_rc); 402 403 async_serialize_end(); 404 405 if (data_request_rc != EOK) { 406 /* Prefer the return code of the opening request. */ 407 if (opening_request_rc != EOK) { 408 return (int) opening_request_rc; 409 } else { 410 return (int) data_request_rc; 411 } 412 } 413 if (opening_request_rc != EOK) { 414 return (int) opening_request_rc; 415 } 416 417 path[path_size - 1] = 0; 418 419 if (IPC_GET_ARG2(data_request_call) >= path_size) { 420 return ELIMIT; 421 } 422 423 return EOK; 424 } 425 376 426 377 427 /** @} -
uspace/lib/c/include/devman.h
r456aea3 r9e195e2c 55 55 extern int devman_device_get_handle_by_class(const char *, const char *, 56 56 devman_handle_t *, unsigned int); 57 extern int devman_get_device_path(devman_handle_t, char *, size_t); 57 58 58 59 extern int devman_add_device_to_class(devman_handle_t, const char *); -
uspace/lib/c/include/ipc/devman.h
r456aea3 r9e195e2c 149 149 typedef enum { 150 150 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD, 151 DEVMAN_DEVICE_GET_HANDLE_BY_CLASS 151 DEVMAN_DEVICE_GET_HANDLE_BY_CLASS, 152 DEVMAN_DEVICE_GET_DEVICE_PATH 152 153 } client_to_devman_t; 153 154 -
uspace/lib/drv/generic/remote_usbhc.c
r456aea3 r9e195e2c 52 52 static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 53 53 static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 54 static void remote_usbhc_find_by_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 54 55 static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 55 56 static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); … … 61 62 remote_usbhc_request_address, 62 63 remote_usbhc_bind_address, 64 remote_usbhc_find_by_address, 63 65 remote_usbhc_release_address, 64 66 … … 163 165 } 164 166 167 void remote_usbhc_find_by_address(ddf_fun_t *fun, void *iface, 168 ipc_callid_t callid, ipc_call_t *call) 169 { 170 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 171 172 if (!usb_iface->find_by_address) { 173 async_answer_0(callid, ENOTSUP); 174 return; 175 } 176 177 usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call); 178 devman_handle_t handle; 179 int rc = usb_iface->find_by_address(fun, address, &handle); 180 181 if (rc == EOK) { 182 async_answer_1(callid, EOK, handle); 183 } else { 184 async_answer_0(callid, rc); 185 } 186 } 187 165 188 void remote_usbhc_release_address(ddf_fun_t *fun, void *iface, 166 189 ipc_callid_t callid, ipc_call_t *call) … … 302 325 async_transaction_t *trans = async_transaction_create(callid); 303 326 if (trans == NULL) { 327 async_answer_0(data_callid, ENOMEM); 304 328 async_answer_0(callid, ENOMEM); 305 329 return; … … 314 338 315 339 if (rc != EOK) { 340 async_answer_0(data_callid, rc); 316 341 async_answer_0(callid, rc); 317 342 async_transaction_destroy(trans); … … 460 485 async_transaction_t *trans = async_transaction_create(callid); 461 486 if (trans == NULL) { 487 async_answer_0(data_callid, ENOMEM); 462 488 async_answer_0(callid, ENOMEM); 463 489 free(setup_packet); … … 469 495 trans->buffer = malloc(data_len); 470 496 if (trans->buffer == NULL) { 497 async_answer_0(data_callid, ENOMEM); 471 498 async_answer_0(callid, ENOMEM); 472 499 async_transaction_destroy(trans); … … 480 507 481 508 if (rc != EOK) { 509 async_answer_0(data_callid, rc); 482 510 async_answer_0(callid, rc); 483 511 async_transaction_destroy(trans); -
uspace/lib/drv/include/usb_iface.h
r456aea3 r9e195e2c 49 49 * - arbitrary error code if returned by remote implementation 50 50 * - EOK - handle found, first parameter contains the USB address 51 * 52 * The handle must be the one used for binding USB address with 53 * it (IPC_M_USBHC_BIND_ADDRESS), otherwise the host controller 54 * (that this request would eventually reach) would not be able 55 * to find it. 56 * The problem is that this handle is actually assigned to the 57 * function inside driver of the parent device (usually hub driver). 58 * To bypass this problem, the initial caller specify handle as 59 * zero and the first parent assigns the actual value. 60 * See usb_iface_get_address_hub_child_impl() implementation 61 * that could be assigned to device ops of a child device of in a 62 * hub driver. 63 * For example, the USB multi interface device driver (MID) 64 * passes this initial zero without any modification because the 65 * handle must be resolved by its parent. 51 66 */ 52 67 IPC_M_USB_GET_ADDRESS, -
uspace/lib/drv/include/usbhc_iface.h
r456aea3 r9e195e2c 105 105 IPC_M_USBHC_BIND_ADDRESS, 106 106 107 /** Get handle binded with given USB address. 108 * Parameters 109 * - USB address 110 * Answer: 111 * - EOK - address binded, first parameter is the devman handle 112 * - ENOENT - address is not in use at the moment 113 */ 114 IPC_M_USBHC_GET_HANDLE_BY_ADDRESS, 115 107 116 /** Release address in use. 108 117 * Arguments: … … 207 216 int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *); 208 217 int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t); 218 int (*find_by_address)(ddf_fun_t *, usb_address_t, devman_handle_t *); 209 219 int (*release_address)(ddf_fun_t *, usb_address_t); 210 220 -
uspace/lib/usb/Makefile
r456aea3 r9e195e2c 29 29 USPACE_PREFIX = ../.. 30 30 LIBRARY = libusb 31 LIBS = $(LIBDRV_PREFIX)/libdrv.a 32 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -Iinclude 31 EXTRA_CFLAGS += \ 32 -I$(LIBDRV_PREFIX)/include \ 33 -Iinclude 33 34 34 35 SOURCES = \ 35 src/addrkeep.c \36 src/altiface.c \37 36 src/class.c \ 38 37 src/ddfiface.c \ 39 38 src/debug.c \ 40 src/devdrv.c \ 41 src/devpoll.c \ 42 src/dp.c \ 39 src/driver.c \ 43 40 src/dump.c \ 44 src/hidiface.c \ 45 src/hidpath.c \ 46 src/hidparser.c \ 47 src/hiddescriptor.c \ 48 src/hub.c \ 49 src/pipepriv.c \ 50 src/pipes.c \ 51 src/pipesinit.c \ 52 src/pipesio.c \ 53 src/recognise.c \ 54 src/request.c \ 55 src/usb.c \ 56 src/usbdevice.c \ 57 src/hidreq.c \ 58 src/hidreport.c \ 59 src/host/device_keeper.c \ 60 src/host/batch.c \ 61 src/host/endpoint.c \ 62 src/host/usb_endpoint_manager.c 41 src/host.c \ 42 src/usb.c 63 43 64 44 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/usb/include/usb/ddfiface.h
r456aea3 r9e195e2c 37 37 38 38 #include <sys/types.h> 39 #include <usb/usbdevice.h>40 39 #include <usb_iface.h> 41 40 -
uspace/lib/usb/include/usb/descriptor.h
r456aea3 r9e195e2c 167 167 } __attribute__ ((packed)) usb_standard_endpoint_descriptor_t; 168 168 169 /** Part of standard USB HID descriptor specifying one class descriptor. 170 * 171 * (See HID Specification, p.22) 172 */ 173 typedef struct { 174 /** Type of class-specific descriptor (Report or Physical). */ 175 uint8_t type; 176 /** Length of class-specific descriptor in bytes. */ 177 uint16_t length; 178 } __attribute__ ((packed)) usb_standard_hid_class_descriptor_info_t; 179 180 /** Standard USB HID descriptor. 181 * 182 * (See HID Specification, p.22) 183 * 184 * It is actually only the "header" of the descriptor, it does not contain 185 * the last two mandatory fields (type and length of the first class-specific 186 * descriptor). 187 */ 188 typedef struct { 189 /** Total size of this descriptor in bytes. 190 * 191 * This includes all class-specific descriptor info - type + length 192 * for each descriptor. 193 */ 194 uint8_t length; 195 /** Descriptor type (USB_DESCTYPE_HID). */ 196 uint8_t descriptor_type; 197 /** HID Class Specification release. */ 198 uint16_t spec_release; 199 /** Country code of localized hardware. */ 200 uint8_t country_code; 201 /** Total number of class-specific (i.e. Report and Physical) 202 * descriptors. 203 * 204 * @note There is always only one Report descriptor. 205 */ 206 uint8_t class_desc_count; 207 /** First mandatory class descriptor (Report) info. */ 208 usb_standard_hid_class_descriptor_info_t report_desc_info; 209 } __attribute__ ((packed)) usb_standard_hid_descriptor_t; 210 169 211 #endif 170 212 /** -
uspace/lib/usb/include/usb/driver.h
r456aea3 r9e195e2c 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup usbvirtkbd29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief Standard device request handlers.33 * Common definitions for USB drivers. 34 34 */ 35 #ifndef VUK_STDREQ_H_36 #define VUK_STDREQ_H_35 #ifndef LIBUSB_DRIVER_H_ 36 #define LIBUSB_DRIVER_H_ 37 37 38 #include <usbvirt/device.h> 38 #include <sys/types.h> 39 #include <ipc/devman.h> 39 40 40 int req_get_descriptor(usbvirt_device_t *device, 41 const usb_device_request_setup_packet_t *setup_packet, 42 uint8_t *data, size_t *act_size); 41 int usb_hc_find(devman_handle_t, devman_handle_t *); 43 42 44 43 #endif -
uspace/lib/usb/include/usb/host.h
r456aea3 r9e195e2c 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup usbvirtkbd29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief USB keyboard descriptors.33 * Host controller common functions. 34 34 */ 35 #ifndef VUK_DESCRIPTOR_H_36 #define VUK_DESCRIPTOR_H_35 #ifndef LIBUSB_HOST_H_ 36 #define LIBUSB_HOST_H_ 37 37 38 typedef struct { 39 uint8_t length; 40 uint8_t type; 41 uint16_t hid_spec_release; 42 uint8_t country_code; 43 uint8_t descriptor_count; 44 uint8_t descriptor1_type; 45 uint16_t descriptor1_length; 46 } __attribute__ ((packed)) hid_descriptor_t; 38 #include <sys/types.h> 39 #include <ipc/devman.h> 40 41 int usb_ddf_get_hc_handle_by_class(size_t, devman_handle_t *); 47 42 48 43 #endif -
uspace/lib/usb/include/usb/usb.h
r456aea3 r9e195e2c 172 172 } usb_packet_id; 173 173 174 /** Class name for USB host controllers. */ 175 #define USB_HC_DDF_CLASS_NAME "usbhc" 176 174 177 #endif 175 178 /** -
uspace/lib/usb/src/ddfiface.c
r456aea3 r9e195e2c 37 37 #include <async.h> 38 38 #include <usb/ddfiface.h> 39 #include <usb/driver.h> 39 40 #include <usb/debug.h> 40 41 #include <errno.h> -
uspace/lib/usb/src/driver.c
r456aea3 r9e195e2c 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <usb/addrkeep.h> 29 /** @addtogroup libusb 30 * @{ 31 */ 32 /** @file 33 * 34 */ 35 #include <devman.h> 36 #include <dev_iface.h> 37 #include <usb_iface.h> 38 #include <usb/driver.h> 32 39 #include <errno.h> 33 #include "../tester.h"34 35 #define MAX_ADDRESS 536 40 37 41 38 const char *test_usbaddrkeep(void) 42 /** Find host controller handle that is ancestor of given device. 43 * 44 * @param[in] device_handle Device devman handle. 45 * @param[out] hc_handle Where to store handle of host controller 46 * controlling device with @p device_handle handle. 47 * @return Error code. 48 */ 49 int usb_hc_find(devman_handle_t device_handle, devman_handle_t *hc_handle) 39 50 { 40 int rc; 41 usb_address_keeping_t addresses; 42 43 TPRINTF("Initializing addresses keeping structure...\n"); 44 usb_address_keeping_init(&addresses, MAX_ADDRESS); 45 46 TPRINTF("Requesting address...\n"); 47 usb_address_t addr = usb_address_keeping_request(&addresses); 48 TPRINTF("Address assigned: %d\n", (int) addr); 49 if (addr != 1) { 50 return "have not received expected address 1"; 51 int parent_phone = devman_parent_device_connect(device_handle, 52 IPC_FLAG_BLOCKING); 53 if (parent_phone < 0) { 54 return parent_phone; 51 55 } 52 56 53 TPRINTF("Releasing not assigned address...\n"); 54 rc = usb_address_keeping_release(&addresses, 2); 55 if (rc != ENOENT) { 56 return "have not received expected ENOENT"; 57 devman_handle_t h; 58 int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE), 59 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h); 60 61 async_hangup(parent_phone); 62 63 if (rc != EOK) { 64 return rc; 57 65 } 58 66 59 TPRINTF("Releasing acquired address...\n"); 60 rc = usb_address_keeping_release(&addresses, addr); 61 if (rc != EOK) { 62 return "have not received expected EOK"; 67 if (hc_handle != NULL) { 68 *hc_handle = h; 63 69 } 64 70 65 return NULL;71 return EOK; 66 72 } 73 74 /** 75 * @} 76 */ -
uspace/lib/usb/src/dump.c
r456aea3 r9e195e2c 41 41 #include <usb/descriptor.h> 42 42 #include <usb/classes/classes.h> 43 #include <usb/classes/hid.h>44 43 45 44 /** Mapping between descriptor id and dumping function. */ -
uspace/lib/usb/src/host.c
r456aea3 r9e195e2c 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup usbvirtkbd29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @brief Keyboard configuration.34 * Host controller common functions (implementation). 35 35 */ 36 #include <stdio.h> 37 #include <str_error.h> 36 38 #include <errno.h> 39 #include <assert.h> 40 #include <bool.h> 41 #include <usb/host.h> 37 42 #include <usb/descriptor.h> 38 #include "stdreq.h" 39 #include "kbdconfig.h" 43 #include <devman.h> 40 44 41 int req_get_descriptor(usbvirt_device_t *device, 42 const usb_device_request_setup_packet_t *setup_packet, 43 uint8_t *data, size_t *act_size) 45 /** Get host controller handle by its class index. 46 * 47 * @param class_index Class index for the host controller. 48 * @param hc_handle Where to store the HC handle 49 * (can be NULL for existence test only). 50 * @return Error code. 51 */ 52 int usb_ddf_get_hc_handle_by_class(size_t class_index, 53 devman_handle_t *hc_handle) 44 54 { 45 if (setup_packet->value_high == USB_DESCTYPE_HID_REPORT) { 46 /* 47 * For simplicity, always return the same 48 * report descriptor. 49 */ 50 usbvirt_control_reply_helper(setup_packet, 51 data, act_size, 52 report_descriptor, report_descriptor_size); 55 char *class_index_str; 56 devman_handle_t hc_handle_tmp; 57 int rc; 53 58 54 return EOK; 59 rc = asprintf(&class_index_str, "%zu", class_index); 60 if (rc < 0) { 61 return ENOMEM; 55 62 } 56 57 /* Let the framework handle all the rest. */ 58 return EFORWARD; 63 rc = devman_device_get_handle_by_class("usbhc", class_index_str, 64 &hc_handle_tmp, 0); 65 free(class_index_str); 66 if (rc != EOK) { 67 return rc; 68 } 69 70 if (hc_handle != NULL) { 71 *hc_handle = hc_handle_tmp; 72 } 73 74 return EOK; 59 75 } 60 61 62 76 63 77 /** @} -
uspace/lib/usbdev/include/usb/hub.h
r456aea3 r9e195e2c 63 63 const usb_hc_attached_device_t *); 64 64 int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t); 65 int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t, 66 devman_handle_t *); 65 67 66 68 #endif -
uspace/lib/usbdev/include/usb/request.h
r456aea3 r9e195e2c 142 142 143 143 int usb_request_clear_endpoint_halt(usb_pipe_t *, uint16_t); 144 int usb_pipe_clear_halt(usb_pipe_t *, usb_pipe_t *); 145 int usb_request_get_endpoint_status(usb_pipe_t *, usb_pipe_t *, uint16_t *); 144 146 145 147 #endif -
uspace/lib/usbdev/include/usb/usbdevice.h
r456aea3 r9e195e2c 50 50 } usb_hc_connection_t; 51 51 52 int usb_hc_find(devman_handle_t, devman_handle_t *);53 54 52 int usb_hc_connection_initialize_from_device(usb_hc_connection_t *, 55 53 ddf_dev_t *); -
uspace/lib/usbdev/src/hub.c
r456aea3 r9e195e2c 117 117 DEV_IFACE_ID(USBHC_DEV_IFACE), 118 118 IPC_M_USBHC_RELEASE_ADDRESS, address); 119 } 120 121 /** Get handle of USB device with given address. 122 * 123 * @param[in] connection Opened connection to host controller. 124 * @param[in] address Address of device in question. 125 * @param[out] handle Where to write the device handle. 126 * @return Error code. 127 */ 128 int usb_hc_get_handle_by_address(usb_hc_connection_t *connection, 129 usb_address_t address, devman_handle_t *handle) 130 { 131 CHECK_CONNECTION(connection); 132 133 sysarg_t tmp; 134 int rc = async_req_2_1(connection->hc_phone, 135 DEV_IFACE_ID(USBHC_DEV_IFACE), 136 IPC_M_USBHC_GET_HANDLE_BY_ADDRESS, 137 address, &tmp); 138 if ((rc == EOK) && (handle != NULL)) { 139 *handle = tmp; 140 } 141 142 return rc; 119 143 } 120 144 -
uspace/lib/usbdev/src/pipes.c
r456aea3 r9e195e2c 36 36 #include <usb/pipes.h> 37 37 #include <usb/debug.h> 38 #include <usb/driver.h> 38 39 #include <usbhc_iface.h> 39 40 #include <usb_iface.h> -
uspace/lib/usbdev/src/request.c
r456aea3 r9e195e2c 885 885 } 886 886 887 /** Clear halt bit of an endpoint pipe (after pipe stall). 888 * 889 * @param ctrl_pipe Control pipe. 890 * @param target_pipe Which pipe is halted and shall be cleared. 891 * @return Error code. 892 */ 893 int usb_pipe_clear_halt(usb_pipe_t *ctrl_pipe, usb_pipe_t *target_pipe) 894 { 895 if ((ctrl_pipe == NULL) || (target_pipe == NULL)) { 896 return EINVAL; 897 } 898 return usb_request_clear_endpoint_halt(ctrl_pipe, 899 target_pipe->endpoint_no); 900 } 901 902 /** Get endpoint status. 903 * 904 * @param[in] ctrl_pipe Control pipe. 905 * @param[in] pipe Of which pipe the status shall be received. 906 * @param[out] status Where to store pipe status (in native endianness). 907 * @return Error code. 908 */ 909 int usb_request_get_endpoint_status(usb_pipe_t *ctrl_pipe, usb_pipe_t *pipe, 910 uint16_t *status) 911 { 912 uint16_t status_tmp; 913 uint16_t pipe_index = (uint16_t) pipe->endpoint_no; 914 int rc = usb_request_get_status(ctrl_pipe, 915 USB_REQUEST_RECIPIENT_ENDPOINT, uint16_host2usb(pipe_index), 916 &status_tmp); 917 if (rc != EOK) { 918 return rc; 919 } 920 921 if (status != NULL) { 922 *status = uint16_usb2host(status_tmp); 923 } 924 925 return EOK; 926 } 927 887 928 /** 888 929 * @} -
uspace/lib/usbdev/src/usbdevice.c
r456aea3 r9e195e2c 37 37 #include <usb_iface.h> 38 38 #include <usb/usbdevice.h> 39 #include <usb/driver.h> 39 40 #include <usb/debug.h> 40 41 #include <errno.h> 41 42 #include <assert.h> 42 43 /** Find host controller handle that is ancestor of given device.44 *45 * @param[in] device_handle Device devman handle.46 * @param[out] hc_handle Where to store handle of host controller47 * controlling device with @p device_handle handle.48 * @return Error code.49 */50 int usb_hc_find(devman_handle_t device_handle, devman_handle_t *hc_handle)51 {52 int parent_phone = devman_parent_device_connect(device_handle,53 IPC_FLAG_BLOCKING);54 if (parent_phone < 0) {55 return parent_phone;56 }57 58 devman_handle_t h;59 usb_log_debug("asking for HC handle (my handle is %zu).\n", device_handle);60 int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),61 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);62 63 async_hangup(parent_phone);64 65 if (rc != EOK) {66 return rc;67 }68 69 if (hc_handle != NULL) {70 *hc_handle = h;71 }72 73 return EOK;74 }75 43 76 44 /** Initialize connection to USB host controller. -
uspace/lib/usbhid/include/usb/classes/hid.h
r456aea3 r9e195e2c 27 27 */ 28 28 29 /** @addtogroup usbvirtkbd29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief USB keyboard configuration.33 * @brief USB HID device related types. 34 34 */ 35 #ifndef VUK_KBDCONFIG_H_36 #define VUK_KBDCONFIG_H_35 #ifndef LIBUSB_HID_H_ 36 #define LIBUSB_HID_H_ 37 37 38 #include <usb/usb.h> 39 #include <usb/classes/hidparser.h> 38 40 #include <usb/descriptor.h> 39 #include "report.h"40 #include "descriptor.h"41 41 42 extern usb_standard_device_descriptor_t std_device_descriptor; 42 /** USB/HID device requests. */ 43 typedef enum { 44 USB_HIDREQ_GET_REPORT = 1, 45 USB_HIDREQ_GET_IDLE = 2, 46 USB_HIDREQ_GET_PROTOCOL = 3, 47 /* Values 4 to 8 are reserved. */ 48 USB_HIDREQ_SET_REPORT = 9, 49 USB_HIDREQ_SET_IDLE = 10, 50 USB_HIDREQ_SET_PROTOCOL = 11 51 } usb_hid_request_t; 43 52 44 extern usb_standard_configuration_descriptor_t std_configuration_descriptor; 53 typedef enum { 54 USB_HID_PROTOCOL_BOOT = 0, 55 USB_HID_PROTOCOL_REPORT = 1 56 } usb_hid_protocol_t; 45 57 46 extern usb_standard_interface_descriptor_t std_interface_descriptor; 58 /** USB/HID subclass constants. */ 59 typedef enum { 60 USB_HID_SUBCLASS_NONE = 0, 61 USB_HID_SUBCLASS_BOOT = 1 62 } usb_hid_subclass_t; 47 63 48 extern usb_standard_endpoint_descriptor_t endpoint_descriptor; 49 50 51 extern hid_descriptor_t hid_descriptor; 52 53 extern report_descriptor_data_t report_descriptor; 54 extern size_t report_descriptor_size; 64 /** USB/HID interface protocols. */ 65 typedef enum { 66 USB_HID_PROTOCOL_NONE = 0, 67 USB_HID_PROTOCOL_KEYBOARD = 1, 68 USB_HID_PROTOCOL_MOUSE = 2 69 } usb_hid_iface_protocol_t; 55 70 56 71 -
uspace/lib/usbhid/src/hiddescriptor.c
r456aea3 r9e195e2c 656 656 657 657 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset); 658 usb_log_debug("\t\tSIZE: % X\n", report_item->size);658 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 659 659 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum); 660 660 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum); … … 695 695 usb_log_debug("Report ID: %d\n", report_des->report_id); 696 696 usb_log_debug("\tType: %d\n", report_des->type); 697 usb_log_debug("\tLength: % d\n", report_des->bit_length);698 usb_log_debug("\tItems: % d\n", report_des->item_length);697 usb_log_debug("\tLength: %zu\n", report_des->bit_length); 698 usb_log_debug("\tItems: %zu\n", report_des->item_length); 699 699 700 700 usb_hid_descriptor_print_list(&report_des->report_items); -
uspace/lib/usbhost/include/usb/host/device_keeper.h
r456aea3 r9e195e2c 80 80 devman_handle_t handle); 81 81 82 bool usb_device_keeper_find_by_address(usb_device_keeper_t *instance, 83 usb_address_t address, devman_handle_t *handle); 84 82 85 usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance, 83 86 usb_address_t address); -
uspace/lib/usbhost/src/device_keeper.c
r456aea3 r9e195e2c 157 157 return ENOENT; 158 158 } 159 160 /** Find devman handled assigned to USB address. 161 * 162 * @param[in] instance Device keeper structure to use. 163 * @param[in] address Address the caller wants to find. 164 * @param[out] handle Where to store found handle. 165 * @return Whether such address is currently occupied. 166 */ 167 bool usb_device_keeper_find_by_address(usb_device_keeper_t *instance, 168 usb_address_t address, devman_handle_t *handle) 169 { 170 assert(instance); 171 fibril_mutex_lock(&instance->guard); 172 if ((address < 0) || (address >= USB_ADDRESS_COUNT)) { 173 fibril_mutex_unlock(&instance->guard); 174 return false; 175 } 176 if (!instance->devices[address].occupied) { 177 fibril_mutex_unlock(&instance->guard); 178 return false; 179 } 180 181 if (handle != NULL) { 182 *handle = instance->devices[address].handle; 183 } 184 185 fibril_mutex_unlock(&instance->guard); 186 return true; 187 } 188 159 189 /*----------------------------------------------------------------------------*/ 160 190 /** Get speed associated with the address -
uspace/lib/usbvirt/Makefile
r456aea3 r9e195e2c 30 30 LIBRARY = libusbvirt 31 31 32 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIBDRV_PREFIX)/include -Iinclude 32 EXTRA_CFLAGS = \ 33 -I$(LIBDRV_PREFIX)/include \ 34 -I$(LIBUSB_PREFIX)/include \ 35 -I$(LIBUSBDEV_PREFIX)/include \ 36 -Iinclude 33 37 34 38 SOURCES = \ 35 src/ipc.c \36 39 src/ctrltransfer.c \ 40 src/device.c \ 41 src/ipc_dev.c \ 42 src/ipc_hc.c \ 37 43 src/stdreq.c \ 38 44 src/transfer.c -
uspace/lib/usbvirt/include/usbvirt/device.h
r456aea3 r9e195e2c 31 31 */ 32 32 /** @file 33 * @briefVirtual USB device.33 * Virtual USB device. 34 34 */ 35 35 #ifndef LIBUSBVIRT_DEVICE_H_ … … 39 39 #include <usb/request.h> 40 40 41 /** Maximum number of endpoints supported by virtual USB. */ 41 42 #define USBVIRT_ENDPOINT_MAX 16 42 43 43 44 typedef struct usbvirt_device usbvirt_device_t; 44 45 45 typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *, usb_endpoint_t, 46 usb_transfer_type_t, void *, size_t); 47 typedef int (*usbvirt_on_data_from_device_t)(usbvirt_device_t *, usb_endpoint_t, 48 usb_transfer_type_t, void *, size_t, size_t *); 49 typedef int (*usbvirt_on_control_t)(usbvirt_device_t *, 50 const usb_device_request_setup_packet_t *, uint8_t *, size_t *); 51 52 typedef struct { 46 /** Callback for data to device (OUT transaction). 47 * 48 * @param dev Virtual device to which the transaction belongs. 49 * @param endpoint Target endpoint number. 50 * @param transfer_type Transfer type. 51 * @param buffer Data buffer. 52 * @param buffer_size Size of the buffer in bytes. 53 * @return Error code. 54 */ 55 typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *dev, 56 usb_endpoint_t endpoint, usb_transfer_type_t transfer_type, 57 void *buffer, size_t buffer_size); 58 59 /** Callback for data from device (IN transaction). 60 * 61 * @param dev Virtual device to which the transaction belongs. 62 * @param endpoint Target endpoint number. 63 * @param transfer_type Transfer type. 64 * @param buffer Data buffer to write answer to. 65 * @param buffer_size Size of the buffer in bytes. 66 * @param act_buffer_size Write here how many bytes were actually written. 67 * @return Error code. 68 */ 69 typedef int (*usbvirt_on_data_from_device_t)(usbvirt_device_t *dev, 70 usb_endpoint_t endpoint, usb_transfer_type_t transfer_type, 71 void *buffer, size_t buffer_size, size_t *act_buffer_size); 72 73 /** Callback for control transfer on endpoint zero. 74 * 75 * Notice that size of the data buffer is expected to be read from the 76 * setup packet. 77 * 78 * @param dev Virtual device to which the transaction belongs. 79 * @param setup_packet Standard setup packet. 80 * @param data Data (might be NULL). 81 * @param act_data_size Size of returned data in bytes. 82 * @return Error code. 83 */ 84 typedef int (*usbvirt_on_control_t)(usbvirt_device_t *dev, 85 const usb_device_request_setup_packet_t *setup_packet, 86 uint8_t *data, size_t *act_data_size); 87 88 /** Callback for control request on a virtual USB device. 89 * 90 * See usbvirt_control_reply_helper() for simple way of answering 91 * control read requests. 92 */ 93 typedef struct { 94 /** Request direction (in or out). */ 53 95 usb_direction_t req_direction; 96 /** Request recipient (device, interface or endpoint). */ 54 97 usb_request_recipient_t req_recipient; 98 /** Request type (standard, class or vendor). */ 55 99 usb_request_type_t req_type; 100 /** Actual request code. */ 56 101 uint8_t request; 102 /** Request handler name for debugging purposes. */ 57 103 const char *name; 104 /** Callback to be executed on matching request. */ 58 105 usbvirt_on_control_t callback; 59 106 } usbvirt_control_request_handler_t; … … 77 124 } usbvirt_device_configuration_t; 78 125 79 /** Standard USB descriptors . */126 /** Standard USB descriptors for virtual device. */ 80 127 typedef struct { 81 128 /** Standard device descriptor. … … 102 149 } usbvirt_device_state_t; 103 150 104 typedef struct { 151 /** Ops structure for virtual USB device. */ 152 typedef struct { 153 /** Callbacks for data to device. 154 * Index zero is ignored. 155 */ 105 156 usbvirt_on_data_to_device_t data_out[USBVIRT_ENDPOINT_MAX]; 157 /** Callbacks for data from device. 158 * Index zero is ignored. 159 */ 106 160 usbvirt_on_data_from_device_t data_in[USBVIRT_ENDPOINT_MAX]; 161 /** Array of control handlers. 162 * Last handler is expected to have the @c callback field set to NULL 163 */ 107 164 usbvirt_control_request_handler_t *control; 165 /** Callback when device changes state. 166 * 167 * The value of @c state attribute of @p dev device is not 168 * defined during call of this function. 169 * 170 * @param dev The virtual USB device. 171 * @param old_state Old device state. 172 * @param new_state New device state. 173 */ 108 174 void (*state_changed)(usbvirt_device_t *dev, 109 175 usbvirt_device_state_t old_state, usbvirt_device_state_t new_state); 110 176 } usbvirt_device_ops_t; 111 177 178 /** Virtual USB device. */ 112 179 struct usbvirt_device { 180 /** Name for debugging purposes. */ 113 181 const char *name; 182 /** Custom device data. */ 114 183 void *device_data; 184 /** Device ops. */ 115 185 usbvirt_device_ops_t *ops; 186 /** Device descriptors. */ 116 187 usbvirt_descriptors_t *descriptors; 188 /** Current device address. 189 * You shall treat this field as read only in your code. 190 */ 117 191 usb_address_t address; 192 /** Current device state. 193 * You shall treat this field as read only in your code. 194 */ 118 195 usbvirt_device_state_t state; 196 /** Phone to the host controller. 197 * You shall treat this field as read only in your code. 198 */ 199 int vhc_phone; 119 200 }; 120 201 121 202 int usbvirt_device_plug(usbvirt_device_t *, const char *); 203 void usbvirt_device_unplug(usbvirt_device_t *); 122 204 123 205 void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *, -
uspace/lib/usbvirt/include/usbvirt/ipc.h
r456aea3 r9e195e2c 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 31 31 */ 32 32 /** @file 33 * @brief Virtual USB device.33 * IPC wrappers for virtual USB. 34 34 */ 35 35 #ifndef LIBUSBVIRT_IPC_H_ … … 40 40 #include <bool.h> 41 41 42 /** IPC methods communication between host controller and virtual device. */ 42 43 typedef enum { 43 44 IPC_M_USBVIRT_GET_NAME = IPC_FIRST_USER_METHOD + 80, … … 45 46 IPC_M_USBVIRT_CONTROL_WRITE, 46 47 IPC_M_USBVIRT_INTERRUPT_IN, 47 IPC_M_USBVIRT_INTERRUPT_OUT 48 } usbvirt_ipc_t; 48 IPC_M_USBVIRT_INTERRUPT_OUT, 49 IPC_M_USBVIRT_BULK_IN, 50 IPC_M_USBVIRT_BULK_OUT 51 } usbvirt_hc_to_device_method_t; 49 52 50 int usbvirt_ipc_send_control_read(int, usb_endpoint_t,void *, size_t,53 int usbvirt_ipc_send_control_read(int, void *, size_t, 51 54 void *, size_t, size_t *); 52 int usbvirt_ipc_send_control_write(int, usb_endpoint_t,void *, size_t,55 int usbvirt_ipc_send_control_write(int, void *, size_t, 53 56 void *, size_t); 54 57 int usbvirt_ipc_send_data_in(int, usb_endpoint_t, usb_transfer_type_t, -
uspace/lib/usbvirt/src/ctrltransfer.c
r456aea3 r9e195e2c 1 /* 2 * Copyright (c) 2011 Vojtech Horky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** @addtogroup libusbvirt 30 * @{ 31 */ 32 /** @file 33 * Control transfer handling. 34 */ 1 35 #include "private.h" 2 36 #include <usb/request.h> … … 5 39 #include <errno.h> 6 40 41 /** Find and execute control transfer handler for virtual USB device. 42 * 43 * @param dev Target virtual device. 44 * @param control_handlers Array of control request handlers. 45 * @param setup Setup packet. 46 * @param data Extra data. 47 * @param data_sent_size Size of extra data in bytes. 48 * @return Error code. 49 * @retval EFORWARD No suitable handler found. 50 */ 7 51 int process_control_transfer(usbvirt_device_t *dev, 8 52 usbvirt_control_request_handler_t *control_handlers, … … 52 96 return EFORWARD; 53 97 } 98 99 100 /** 101 * @} 102 */ -
uspace/lib/usbvirt/src/private.h
r456aea3 r9e195e2c 1 /* 2 * Copyright (c) 2011 Vojtech Horky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** @addtogroup libusbvirt 30 * @{ 31 */ 32 /** @file 33 * Private definitions. 34 */ 35 #ifndef USBVIRT_PRIVATE_H_ 36 #define USBVIRT_PRIVATE_H_ 37 1 38 #include <usbvirt/device.h> 2 39 … … 7 44 8 45 extern usbvirt_control_request_handler_t library_handlers[]; 46 47 #endif 48 /** 49 * @} 50 */ -
uspace/lib/usbvirt/src/stdreq.c
r456aea3 r9e195e2c 1 /* 2 * Copyright (c) 2011 Vojtech Horky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** @addtogroup libusbvirt 30 * @{ 31 */ 32 /** @file 33 * Standard control request handlers. 34 */ 1 35 #include "private.h" 2 36 #include <usb/request.h> … … 4 38 #include <errno.h> 5 39 40 /** Helper for replying to control read transfer from virtual USB device. 41 * 42 * This function takes care of copying data to answer buffer taking care 43 * of buffer sizes properly. 44 * 45 * @param setup_packet The setup packet. 46 * @param data Data buffer to write to. 47 * @param act_size Where to write actual size of returned data. 48 * @param actual_data Data to be returned. 49 * @param actual_data_size Size of answer data (@p actual_data) in bytes. 50 */ 6 51 void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *setup_packet, 7 52 uint8_t *data, size_t *act_size, … … 144 189 } 145 190 191 /** Standard request handlers. */ 146 192 usbvirt_control_request_handler_t library_handlers[] = { 147 193 { … … 173 219 }; 174 220 221 /** 222 * @} 223 */ -
uspace/lib/usbvirt/src/transfer.c
r456aea3 r9e195e2c 31 31 */ 32 32 /** @file 33 * 33 * Transfer handling. 34 34 */ 35 35 #include <usbvirt/device.h> … … 39 39 #include "private.h" 40 40 41 /** Process a control transfer to the virtual USB device. 42 * 43 * @param dev Target device. 44 * @param setup Setup packet data. 45 * @param setup_size Size of setup packet. 46 * @param data Extra data (DATA stage). 47 * @param data_size Size of extra data in bytes. 48 * @param data_size_sent Number of actually send bytes during the transfer 49 * (only used for READ transfers). 50 * @return Error code. 51 */ 41 52 static int usbvirt_control_transfer(usbvirt_device_t *dev, 42 53 void *setup, size_t setup_size, … … 78 89 } 79 90 91 /** Issue a control write transfer to virtual USB device. 92 * 93 * @see usbvirt_control_transfer 94 * 95 * @param dev Target virtual device. 96 * @param setup Setup data. 97 * @param setup_size Size of setup packet. 98 * @param data Extra data (DATA stage). 99 * @param data_size Size of extra data buffer in bytes. 100 * @return Error code. 101 */ 80 102 int usbvirt_control_write(usbvirt_device_t *dev, void *setup, size_t setup_size, 81 103 void *data, size_t data_size) … … 85 107 } 86 108 109 /** Issue a control read transfer to virtual USB device. 110 * 111 * @see usbvirt_control_transfer 112 * 113 * @param dev Target virtual device. 114 * @param setup Setup data. 115 * @param setup_size Size of setup packet. 116 * @param data Extra data (DATA stage). 117 * @param data_size Size of extra data buffer in bytes. 118 * @param data_size_sent Number of actually send bytes during the transfer. 119 * @return Error code. 120 */ 87 121 int usbvirt_control_read(usbvirt_device_t *dev, void *setup, size_t setup_size, 88 122 void *data, size_t data_size, size_t *data_size_sent) … … 92 126 } 93 127 128 /** Send data to virtual USB device. 129 * 130 * @param dev Target virtual device. 131 * @param transf_type Transfer type (interrupt, bulk). 132 * @param endpoint Endpoint number. 133 * @param data Data sent from the driver to the device. 134 * @param data_size Size of the @p data buffer in bytes. 135 * @return Error code. 136 */ 94 137 int usbvirt_data_out(usbvirt_device_t *dev, usb_transfer_type_t transf_type, 95 138 usb_endpoint_t endpoint, void *data, size_t data_size) … … 108 151 } 109 152 153 /** Request data from virtual USB device. 154 * 155 * @param dev Target virtual device. 156 * @param transf_type Transfer type (interrupt, bulk). 157 * @param endpoint Endpoint number. 158 * @param data Where to stored data the device returns to the driver. 159 * @param data_size Size of the @p data buffer in bytes. 160 * @param data_size_sent Number of actually written bytes. 161 * @return Error code. 162 */ 110 163 int usbvirt_data_in(usbvirt_device_t *dev, usb_transfer_type_t transf_type, 111 164 usb_endpoint_t endpoint, void *data, size_t data_size, size_t *data_size_sent)
Note:
See TracChangeset
for help on using the changeset viewer.
