Changeset 1866945 in mainline
- Timestamp:
- 2011-05-07T13:47:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4d20ef7
- Parents:
- 95285378 (diff), 6fb003e (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. - Files:
-
- 3 added
- 10 deleted
- 32 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
r95285378 r1866945 140 140 $(USPACE_PATH)/app/stats/stats \ 141 141 $(USPACE_PATH)/app/sysinfo/sysinfo \ 142 $(USPACE_PATH)/app/tasks/tasks \143 142 $(USPACE_PATH)/app/top/top \ 144 143 $(USPACE_PATH)/app/usbinfo/usbinfo \ 145 $(USPACE_PATH)/app/virtusbkbd/vuk \146 144 $(USPACE_PATH)/app/vuhid/vuh \ 147 145 $(USPACE_PATH)/app/websrv/websrv -
uspace/Makefile
r95285378 r1866945 51 51 app/top \ 52 52 app/usbinfo \ 53 app/virtusbkbd \54 53 app/vuhid \ 55 54 app/netecho \ -
uspace/app/vuhid/device.c
r95285378 r1866945 77 77 { 78 78 vuhid_interface_t *iface = arg; 79 vuhid_data_t *hid_data = iface->vuhid_data; 79 80 80 81 if (iface->live != NULL) { 81 82 iface->live(iface); 82 83 } 84 85 fibril_mutex_lock(&hid_data->iface_count_mutex); 86 hid_data->iface_died_count++; 87 fibril_condvar_broadcast(&hid_data->iface_count_cv); 88 fibril_mutex_unlock(&hid_data->iface_count_mutex); 83 89 84 90 return EOK; … … 110 116 if ((iface->in_data_size == 0) && (iface->out_data_size == 0)) { 111 117 return EEMPTY; 118 } 119 120 // FIXME - we shall set vuhid_data to NULL in the main() rather 121 // than to depend on individual interfaces 122 /* Already used interface. */ 123 if (iface->vuhid_data != NULL) { 124 return EEXISTS; 112 125 } 113 126 … … 252 265 253 266 /* Launch the "life" fibril. */ 267 iface->vuhid_data = hid_data; 254 268 fid_t life_fibril = fibril_create(interface_life_fibril, iface); 255 269 if (life_fibril == 0) { … … 310 324 += total_descr_size; 311 325 326 hid_data->iface_count++; 312 327 fibril_add_ready(life_fibril); 313 328 … … 331 346 } 332 347 348 void wait_for_interfaces_death(usbvirt_device_t *dev) 349 { 350 vuhid_data_t *hid_data = dev->device_data; 351 352 fibril_mutex_lock(&hid_data->iface_count_mutex); 353 while (hid_data->iface_died_count < hid_data->iface_count) { 354 fibril_condvar_wait(&hid_data->iface_count_cv, 355 &hid_data->iface_count_mutex); 356 } 357 fibril_mutex_unlock(&hid_data->iface_count_mutex); 358 } 333 359 334 360 /** @} -
uspace/app/vuhid/hids/bootkbd.c
r95285378 r1866945 39 39 #include <usb/classes/hidut.h> 40 40 41 #include "../ ../virtusbkbd/report.h"41 #include "../report.h" 42 42 43 43 uint8_t report_descriptor[] = { … … 169 169 .on_data_out = on_data_out, 170 170 171 .live = live 171 .live = live, 172 173 .vuhid_data = NULL 172 174 }; 173 175 -
uspace/app/vuhid/main.c
r95285378 r1866945 132 132 .in_endpoint_first_free = 1, 133 133 .out_endpoints_mapping = { NULL }, 134 .out_endpoint_first_free = 1 135 }; 134 .out_endpoint_first_free = 1, 135 136 .iface_count = 0, 137 .iface_died_count = 0 138 // mutex and CV must be initialized elsewhere 139 }; 140 136 141 137 142 /** Keyboard device. … … 151 156 152 157 usb_log_enable(USB_LOG_LEVEL_DEBUG2, "vusbhid"); 158 159 fibril_mutex_initialize(&vuhid_data.iface_count_mutex); 160 fibril_condvar_initialize(&vuhid_data.iface_count_cv); 153 161 154 162 /* Determine which interfaces to initialize. */ … … 182 190 printf("Connected to VHCD...\n"); 183 191 184 while (true) { 185 async_usleep(10 * 1000 * 1000); 186 } 192 wait_for_interfaces_death(&hid_dev); 187 193 188 194 printf("Terminating...\n"); 189 195 196 usbvirt_device_unplug(&hid_dev); 197 190 198 return 0; 191 199 } -
uspace/app/vuhid/virthid.h
r95285378 r1866945 38 38 #include <usb/usb.h> 39 39 #include <usbvirt/device.h> 40 #include <fibril_synch.h> 40 41 41 42 #define VUHID_ENDPOINT_MAX USB11_ENDPOINT_MAX … … 43 44 44 45 typedef struct vuhid_interface vuhid_interface_t; 46 47 typedef struct { 48 vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX]; 49 size_t in_endpoint_first_free; 50 vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX]; 51 size_t out_endpoint_first_free; 52 vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX]; 53 54 fibril_mutex_t iface_count_mutex; 55 fibril_condvar_t iface_count_cv; 56 size_t iface_count; 57 size_t iface_died_count; 58 } vuhid_data_t; 45 59 46 60 struct vuhid_interface { … … 63 77 64 78 void *interface_data; 79 80 vuhid_data_t *vuhid_data; 65 81 }; 66 67 typedef struct {68 vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX];69 size_t in_endpoint_first_free;70 vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX];71 size_t out_endpoint_first_free;72 vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX];73 } vuhid_data_t;74 82 75 83 typedef struct { … … 84 92 85 93 int add_interface_by_id(vuhid_interface_t **, const char *, usbvirt_device_t *); 94 void wait_for_interfaces_death(usbvirt_device_t *); 86 95 87 96 #endif -
uspace/drv/ohci/hc.c
r95285378 r1866945 49 49 static int interrupt_emulator(hc_t *instance); 50 50 static void hc_gain_control(hc_t *instance); 51 static void hc_init_hw(hc_t *instance);52 51 static int hc_init_transfer_lists(hc_t *instance); 53 52 static int hc_init_memory(hc_t *instance); … … 92 91 usb_log_error("Failed add root hub match-id.\n"); 93 92 } 93 ret = ddf_fun_bind(hub_fun); 94 94 return ret; 95 95 } … … 111 111 ret, str_error(ret)); 112 112 113 list_initialize(&instance->pending_batches); 113 114 usb_device_keeper_init(&instance->manager); 114 115 ret = usb_endpoint_manager_init(&instance->ep_manager, … … 117 118 str_error(ret)); 118 119 119 hc_gain_control(instance);120 120 ret = hc_init_memory(instance); 121 121 CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n", 122 122 str_error(ret)); 123 hc_init_hw(instance); 123 #undef CHECK_RET_RETURN 124 125 126 // hc_init_hw(instance); 127 hc_gain_control(instance); 124 128 fibril_mutex_initialize(&instance->guard); 125 129 … … 132 136 } 133 137 134 list_initialize(&instance->pending_batches);135 #undef CHECK_RET_RETURN136 138 return EOK; 137 139 } … … 287 289 { 288 290 assert(instance); 289 usb_log_debug("OHCI interrupt: %x.\n", status);291 usb_log_debug("OHCI(%p) interrupt: %x.\n", instance, status); 290 292 if ((status & ~I_SF) == 0) /* ignore sof status */ 291 293 return; … … 339 341 (uint32_t*)((char*)instance->registers + 0x100); 340 342 usb_log_debug("OHCI legacy register %p: %x.\n", 341 ohci_emulation_reg, *ohci_emulation_reg); 342 *ohci_emulation_reg &= ~0x1; 343 ohci_emulation_reg, *ohci_emulation_reg); 344 /* Do not change A20 state */ 345 *ohci_emulation_reg &= 0x100; 346 usb_log_debug("OHCI legacy register %p: %x.\n", 347 ohci_emulation_reg, *ohci_emulation_reg); 343 348 344 349 /* Interrupt routing enabled => smm driver is active */ … … 350 355 } 351 356 usb_log_info("SMM driver: Ownership taken.\n"); 357 instance->registers->control &= (C_HCFS_RESET << C_HCFS_SHIFT); 358 async_usleep(50000); 352 359 return; 353 360 } … … 375 382 } 376 383 /*----------------------------------------------------------------------------*/ 377 void hc_ init_hw(hc_t *instance)384 void hc_start_hw(hc_t *instance) 378 385 { 379 386 /* OHCI guide page 42 */ … … 474 481 { 475 482 assert(instance); 483 484 bzero(&instance->rh, sizeof(instance->rh)); 476 485 /* Init queues */ 477 486 hc_init_transfer_lists(instance); -
uspace/drv/ohci/hc.h
r95285378 r1866945 80 80 uintptr_t regs, size_t reg_size, bool interrupts); 81 81 82 void hc_start_hw(hc_t *instance); 83 82 84 /** Safely dispose host controller internal structures 83 85 * -
uspace/drv/ohci/main.c
r95285378 r1866945 75 75 return ret; 76 76 } 77 device->driver_data = ohci; 77 // device->driver_data = ohci; 78 hc_register_hub(&ohci->hc, ohci->rh_fun); 78 79 79 80 usb_log_info("Controlling new OHCI device `%s'.\n", device->name); … … 93 94 { 94 95 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 95 sleep(5);96 96 return ddf_driver_main(&ohci_driver); 97 97 } -
uspace/drv/ohci/ohci.c
r95285378 r1866945 54 54 { 55 55 assert(dev); 56 assert(dev->driver_data); 56 57 hc_t *hc = &((ohci_t*)dev->driver_data)->hc; 57 58 uint16_t status = IPC_GET_ARG1(*call); … … 152 153 usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n", 153 154 (void *) mem_reg_base, mem_reg_size, irq); 154 155 ret = pci_disable_legacy(device);156 CHECK_RET_DEST_FUN_RETURN(ret,157 "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));158 155 159 156 bool interrupts = false; … … 212 209 "Failed(%d) to create root hub function.\n", ret); 213 210 214 hc_register_hub(&instance->hc, instance->rh_fun);215 211 216 212 instance->rh_fun->ops = &rh_ops; 217 213 instance->rh_fun->driver_data = NULL; 218 ret = ddf_fun_bind(instance->rh_fun);219 CHECK_RET_FINI_RETURN(ret,220 "Failed(%d) to register OHCI root hub.\n", ret); 221 214 215 device->driver_data = instance; 216 217 hc_start_hw(&instance->hc); 222 218 return EOK; 223 219 #undef CHECK_RET_FINI_RETURN -
uspace/drv/ohci/pci.c
r95285378 r1866945 136 136 return enabled ? EOK : EIO; 137 137 } 138 /*----------------------------------------------------------------------------*/139 /** Implements BIOS handoff routine as decribed in OHCI spec140 *141 * @param[in] device Device asking for interrupts142 * @return Error code.143 */144 int pci_disable_legacy(ddf_dev_t *device)145 {146 /* TODO: implement */147 return EOK;148 }149 /*----------------------------------------------------------------------------*/150 138 /** 151 139 * @} -
uspace/drv/usbhid/generic/hiddev.c
r95285378 r1866945 39 39 #include <errno.h> 40 40 #include <str_error.h> 41 #include <bool.h> 41 42 42 43 #include <usbhid_iface.h> … … 64 65 size_t size, size_t *act_size, unsigned int flags); 65 66 67 static int usb_generic_hid_client_connected(ddf_fun_t *fun); 68 66 69 /*----------------------------------------------------------------------------*/ 67 70 … … 72 75 73 76 static ddf_dev_ops_t usb_generic_hid_ops = { 74 .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface 77 .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface, 78 .open = usb_generic_hid_client_connected 75 79 }; 76 80 … … 104 108 105 109 /*! @todo This should probably be atomic. */ 106 memcpy(buffer, hid_dev->input_report, hid_dev->input_report_size); 107 *act_size = hid_dev->input_report_size; 110 if (usb_hid_report_ready()) { 111 memcpy(buffer, hid_dev->input_report, 112 hid_dev->input_report_size); 113 *act_size = hid_dev->input_report_size; 114 usb_hid_report_received(); 115 } 108 116 109 117 // clear the buffer so that it will not be received twice 110 memset(hid_dev->input_report, 0, hid_dev->input_report_size);118 //memset(hid_dev->input_report, 0, hid_dev->input_report_size); 111 119 120 // note that we already received this report 121 // report_received = true; 122 123 return EOK; 124 } 125 126 /*----------------------------------------------------------------------------*/ 127 128 static int usb_generic_hid_client_connected(ddf_fun_t *fun) 129 { 130 usb_hid_report_received(); 112 131 return EOK; 113 132 } -
uspace/drv/usbhid/kbd/kbddev.c
r95285378 r1866945 255 255 256 256 if (hid_dev == NULL || hid_dev->data == NULL) { 257 usb_log_debug("default_connection_handler: " 258 "Missing parameter.\n"); 257 259 async_answer_0(icallid, EINVAL); 258 260 return; … … 267 269 268 270 if (kbd_dev->console_phone != -1) { 271 usb_log_debug("default_connection_handler: " 272 "console phone already set\n"); 269 273 async_answer_0(icallid, ELIMIT); 270 274 return; … … 272 276 273 277 kbd_dev->console_phone = callback; 278 279 usb_log_debug("default_connection_handler: OK\n"); 274 280 async_answer_0(icallid, EOK); 275 281 return; 276 282 } 277 283 284 usb_log_debug("default_connection_handler: Wrong function.\n"); 278 285 async_answer_0(icallid, EINVAL); 279 286 } … … 555 562 usb_log_debug2("Key pressed: %d (keycode: %d)\n", key, 556 563 kbd_dev->keys[i]); 557 usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key);558 564 if (!usb_kbd_is_lock(key)) { 559 565 usb_kbd_repeat_start(kbd_dev, key); 560 566 } 567 usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key); 561 568 } else { 562 569 // found, nothing happens -
uspace/drv/usbhid/mouse/mousedev.c
r95285378 r1866945 43 43 #include <str_error.h> 44 44 #include <ipc/mouse.h> 45 #include <io/console.h> 46 47 #include <ipc/kbd.h> 48 #include <io/keycode.h> 45 49 46 50 #include "mousedev.h" … … 61 65 62 66 const char *HID_MOUSE_FUN_NAME = "mouse"; 67 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel"; 63 68 const char *HID_MOUSE_CLASS_NAME = "mouse"; 69 const char *HID_MOUSE_WHEEL_CLASS_NAME = "keyboard"; 64 70 65 71 /** Default idle rate for mouses. */ … … 119 125 120 126 if (hid_dev == NULL || hid_dev->data == NULL) { 127 usb_log_debug("default_connection_handler: Missing " 128 "parameters.\n"); 121 129 async_answer_0(icallid, EINVAL); 122 130 return; … … 127 135 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data; 128 136 137 int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) 138 ? &mouse_dev->mouse_phone : &mouse_dev->wheel_phone; 139 129 140 if (method == IPC_M_CONNECT_TO_ME) { 130 141 int callback = IPC_GET_ARG5(*icall); 131 142 132 if (mouse_dev->console_phone != -1) { 143 if (*phone != -1) { 144 usb_log_debug("default_connection_handler: Console " 145 "phone to mouse already set.\n"); 133 146 async_answer_0(icallid, ELIMIT); 147 //async_answer_0(icallid, EOK); 134 148 return; 135 149 } 136 150 137 mouse_dev->console_phone = callback;151 *phone = callback; 138 152 usb_log_debug("Console phone to mouse set ok (%d).\n", callback); 139 153 async_answer_0(icallid, EOK); … … 141 155 } 142 156 157 usb_log_debug("default_connection_handler: Invalid function.\n"); 143 158 async_answer_0(icallid, EINVAL); 144 159 } … … 152 167 return NULL; 153 168 } 154 mouse->console_phone = -1; 169 mouse->mouse_phone = -1; 170 mouse->wheel_phone = -1; 155 171 156 172 return mouse; … … 164 180 165 181 // hangup phone to the console 166 if ((*mouse_dev)->console_phone >= 0) { 167 async_hangup((*mouse_dev)->console_phone); 182 if ((*mouse_dev)->mouse_phone >= 0) { 183 async_hangup((*mouse_dev)->mouse_phone); 184 } 185 186 if ((*mouse_dev)->wheel_phone >= 0) { 187 async_hangup((*mouse_dev)->wheel_phone); 168 188 } 169 189 … … 174 194 /*----------------------------------------------------------------------------*/ 175 195 176 static bool usb_mouse_process_boot_report(usb_hid_dev_t *hid_dev, 177 uint8_t *buffer, size_t buffer_size) 196 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel) 197 { 198 console_event_t ev; 199 200 ev.type = KEY_PRESS; 201 ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0; 202 ev.mods = 0; 203 ev.c = 0; 204 205 if (mouse_dev->wheel_phone < 0) { 206 usb_log_warning( 207 "Connection to console not ready, key discarded.\n"); 208 return; 209 } 210 211 int count = (wheel < 0) ? -wheel : wheel; 212 int i; 213 214 for (i = 0; i < count * 3; ++i) { 215 usb_log_debug2("Sending key %d to the console\n", ev.key); 216 async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, ev.type, 217 ev.key, ev.mods, ev.c); 218 // send key release right away 219 async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, KEY_RELEASE, 220 ev.key, ev.mods, ev.c); 221 } 222 } 223 224 /*----------------------------------------------------------------------------*/ 225 226 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, uint8_t *buffer, 227 size_t buffer_size) 178 228 { 179 229 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data; … … 182 232 usb_debug_str_buffer(buffer, buffer_size, 0)); 183 233 184 if (mouse_dev-> console_phone < 0) {234 if (mouse_dev->mouse_phone < 0) { 185 235 usb_log_error(NAME " No console phone.\n"); 186 236 return false; // ?? … … 252 302 253 303 if ((shift_x != 0) || (shift_y != 0)) { 254 async_req_2_0(mouse_dev-> console_phone,304 async_req_2_0(mouse_dev->mouse_phone, 255 305 MEVENT_MOVE, shift_x, shift_y); 256 306 } 307 308 /* 309 * Wheel 310 */ 311 int wheel = 0; 312 313 path = usb_hid_report_path(); 314 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 315 USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 316 317 usb_hid_report_path_set_report_id(path, report_id); 318 319 field = usb_hid_report_get_sibling( 320 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 321 USB_HID_REPORT_TYPE_INPUT); 322 323 if (field != NULL) { 324 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 325 field->usage); 326 wheel = field->value; 327 } 328 329 usb_hid_report_path_free(path); 330 331 // send arrow up for positive direction and arrow down for negative 332 // direction; three arrows for difference of 1 333 usb_mouse_send_wheel(mouse_dev, wheel); 334 257 335 258 336 /* … … 274 352 if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0 275 353 && field->value != 0) { 276 async_req_2_0(mouse_dev-> console_phone,354 async_req_2_0(mouse_dev->mouse_phone, 277 355 MEVENT_BUTTON, field->usage, 1); 278 356 mouse_dev->buttons[field->usage - field->usage_minimum] … … 281 359 mouse_dev->buttons[field->usage - field->usage_minimum] != 0 282 360 && field->value == 0) { 283 async_req_2_0(mouse_dev-> console_phone,361 async_req_2_0(mouse_dev->mouse_phone, 284 362 MEVENT_BUTTON, field->usage, 0); 285 363 mouse_dev->buttons[field->usage - field->usage_minimum] … … 337 415 } 338 416 417 /* 418 * Special function for acting as keyboard (wheel) 419 */ 420 usb_log_debug("Creating DDF function %s...\n", 421 HID_MOUSE_WHEEL_FUN_NAME); 422 fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 423 HID_MOUSE_WHEEL_FUN_NAME); 424 if (fun == NULL) { 425 usb_log_error("Could not create DDF function node.\n"); 426 return ENOMEM; 427 } 428 429 /* 430 * Store the initialized HID device and HID ops 431 * to the DDF function. 432 */ 433 fun->ops = &hid_dev->ops; 434 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 435 436 rc = ddf_fun_bind(fun); 437 if (rc != EOK) { 438 usb_log_error("Could not bind DDF function: %s.\n", 439 str_error(rc)); 440 ddf_fun_destroy(fun); 441 return rc; 442 } 443 444 usb_log_debug("Adding DDF function to class %s...\n", 445 HID_MOUSE_WHEEL_CLASS_NAME); 446 rc = ddf_fun_add_to_class(fun, HID_MOUSE_WHEEL_CLASS_NAME); 447 if (rc != EOK) { 448 usb_log_error( 449 "Could not add DDF function to class %s: %s.\n", 450 HID_MOUSE_WHEEL_CLASS_NAME, str_error(rc)); 451 ddf_fun_destroy(fun); 452 return rc; 453 } 454 339 455 return EOK; 340 456 } … … 407 523 } 408 524 409 return usb_mouse_process_ boot_report(hid_dev, buffer, buffer_size);525 return usb_mouse_process_report(hid_dev, buffer, buffer_size); 410 526 } 411 527 -
uspace/drv/usbhid/mouse/mousedev.h
r95285378 r1866945 48 48 //suseconds_t poll_interval_us; 49 49 /** IPC phone to console (consumer). */ 50 int console_phone; 50 int mouse_phone; 51 int wheel_phone; 51 52 52 53 int32_t *buttons; -
uspace/drv/usbhid/subdrivers.c
r95285378 r1866945 36 36 #include "subdrivers.h" 37 37 #include "usb/classes/hidut.h" 38 #include "usb/classes/hidpath.h" 38 39 39 40 #include "lgtch-ultrax/lgtch-ultrax.h" 41 #include "mouse/mousedev.h" 40 42 41 43 static usb_hid_subdriver_usage_t path_kbd[] = { 42 44 {USB_HIDUT_PAGE_KEYBOARD, 0}, 45 {0, 0} 46 }; 47 48 static usb_hid_subdriver_usage_t path_mouse2[] = { 49 {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_X}, 43 50 {0, 0} 44 51 }; … … 79 86 } 80 87 }, 88 { 89 path_mouse2, 90 -1, 91 USB_HID_PATH_COMPARE_END 92 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 93 -1, 94 -1, 95 { 96 .init = usb_mouse_init, 97 .deinit = usb_mouse_deinit, 98 .poll = usb_mouse_polling_callback, 99 .poll_end = NULL 100 } 101 }, 81 102 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL}} 82 103 }; -
uspace/drv/usbhid/usbhid.c
r95285378 r1866945 63 63 static const int USB_HID_MAX_SUBDRIVERS = 10; 64 64 65 static fibril_local bool report_received; 66 65 67 /*----------------------------------------------------------------------------*/ 66 68 … … 412 414 } 413 415 414 // TODO: remove the mouse hack 415 if (hid_dev->poll_pipe_index == USB_HID_MOUSE_POLL_EP_NO || 416 fallback) { 416 if (fallback) { 417 417 // fall back to boot protocol 418 418 switch (hid_dev->poll_pipe_index) { … … 509 509 free(input_old); 510 510 } 511 usb_hid_new_report(); 511 512 } 512 513 } … … 589 590 /*----------------------------------------------------------------------------*/ 590 591 592 void usb_hid_new_report(void) 593 { 594 report_received = false; 595 } 596 597 /*----------------------------------------------------------------------------*/ 598 599 void usb_hid_report_received(void) 600 { 601 report_received = true; 602 } 603 604 /*----------------------------------------------------------------------------*/ 605 606 bool usb_hid_report_ready(void) 607 { 608 return !report_received; 609 } 610 611 /*----------------------------------------------------------------------------*/ 612 591 613 void usb_hid_free(usb_hid_dev_t **hid_dev) 592 614 { -
uspace/drv/usbhid/usbhid.h
r95285378 r1866945 44 44 #include <usb/devdrv.h> 45 45 #include <usb/classes/hid.h> 46 #include <bool.h> 46 47 47 48 struct usb_hid_dev; … … 128 129 //const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev); 129 130 131 void usb_hid_new_report(void); 132 133 void usb_hid_report_received(void); 134 135 bool usb_hid_report_ready(void); 136 130 137 void usb_hid_free(usb_hid_dev_t **hid_dev); 131 138 -
uspace/drv/vhc/transfer.c
r95285378 r1866945 135 135 if (transfer->direction == USB_DIRECTION_IN) { 136 136 rc = usbvirt_ipc_send_control_read(phone, 137 transfer->endpoint,138 137 transfer->setup_buffer, transfer->setup_buffer_size, 139 138 transfer->data_buffer, transfer->data_buffer_size, … … 142 141 assert(transfer->direction == USB_DIRECTION_OUT); 143 142 rc = usbvirt_ipc_send_control_write(phone, 144 transfer->endpoint,145 143 transfer->setup_buffer, transfer->setup_buffer_size, 146 144 transfer->data_buffer, transfer->data_buffer_size); -
uspace/lib/usb/include/usb/classes/hiddescriptor.h
r95285378 r1866945 78 78 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 79 79 80 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path); 80 81 #endif 81 82 /** -
uspace/lib/usb/include/usb/classes/hidpath.h
r95285378 r1866945 43 43 * Description of path of usage pages and usages in report descriptor 44 44 */ 45 #define USB_HID_PATH_COMPARE_STRICT 0 46 #define USB_HID_PATH_COMPARE_END 1 47 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 4 48 #define USB_HID_PATH_COMPARE_COLLECTION_ONLY 2 /* porovnava jenom cestu z Kolekci */ 45 /** Wanted usage path must be exactly the same as the searched one */ 46 #define USB_HID_PATH_COMPARE_STRICT 0 47 /** Wanted usage path must be the suffix in the searched one */ 48 #define USB_HID_PATH_COMPARE_END 1 49 /** */ 50 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 2 51 /** Searched usage page must be prefix of the other one */ 52 #define USB_HID_PATH_COMPARE_BEGIN 4 53 /** Searched couple of usage page and usage can be anywhere in usage path */ 54 #define USB_HID_PATH_COMPARE_ANYWHERE 8 49 55 50 56 -
uspace/lib/usb/include/usb/classes/hidtypes.h
r95285378 r1866945 165 165 /** */ 166 166 link_t link; 167 168 int in_delimiter; 167 169 } usb_hid_report_item_t; 168 170 -
uspace/lib/usb/src/hiddescriptor.c
r95285378 r1866945 41 41 #include <assert.h> 42 42 43 44 #define OUTSIDE_DELIMITER_SET 0 45 #define START_DELIMITER_SET 1 46 #define INSIDE_DELIMITER_SET 2 47 43 48 /** The new report item flag. Used to determine when the item is completly 44 49 * configured and should be added to the report structure … … 56 61 #define USB_HID_UNKNOWN_TAG -99 57 62 58 59 /** 60 * Initialize the report descriptor parser structure 61 * 62 * @param parser Report descriptor parser structure 63 * @return Error code 64 */ 65 int usb_hid_report_init(usb_hid_report_t *report) 66 { 67 if(report == NULL) { 68 return EINVAL; 69 } 70 71 memset(report, 0, sizeof(usb_hid_report_t)); 72 list_initialize(&report->reports); 73 list_initialize(&report->collection_paths); 74 75 report->use_report_ids = 0; 76 return EOK; 77 } 78 79 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item) 80 { 81 usb_hid_report_field_t *field; 82 int i; 83 84 63 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) 64 { 85 65 /* find or append current collection path to the list */ 86 66 link_t *path_it = report->collection_paths.next; … … 89 69 path = list_get_instance(path_it, usb_hid_report_path_t, link); 90 70 91 if(usb_hid_report_compare_usage_path(path, report_item->usage_path, USB_HID_PATH_COMPARE_STRICT) == EOK){71 if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){ 92 72 break; 93 73 } … … 95 75 } 96 76 if(path_it == &report->collection_paths) { 97 path = usb_hid_report_path_clone( report_item->usage_path);77 path = usb_hid_report_path_clone(cmp_path); 98 78 list_append(&path->link, &report->collection_paths); 99 79 report->collection_paths_count++; 100 } 80 81 return path; 82 } 83 else { 84 return list_get_instance(path_it, usb_hid_report_path_t, link); 85 } 86 } 87 88 /** 89 * Initialize the report descriptor parser structure 90 * 91 * @param parser Report descriptor parser structure 92 * @return Error code 93 */ 94 int usb_hid_report_init(usb_hid_report_t *report) 95 { 96 if(report == NULL) { 97 return EINVAL; 98 } 99 100 memset(report, 0, sizeof(usb_hid_report_t)); 101 list_initialize(&report->reports); 102 list_initialize(&report->collection_paths); 103 104 report->use_report_ids = 0; 105 return EOK; 106 } 107 108 109 /* 110 * 111 * 112 */ 113 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item) 114 { 115 usb_hid_report_field_t *field; 116 int i; 101 117 102 118 for(i=0; i<report_item->usages_count; i++){ … … 104 120 } 105 121 106 122 usb_hid_report_path_t *path = report_item->usage_path; 107 123 for(i=0; i<report_item->count; i++){ 108 124 … … 112 128 113 129 /* fill the attributes */ 114 field->collection_path = path;115 130 field->logical_minimum = report_item->logical_minimum; 116 131 field->logical_maximum = report_item->logical_maximum; … … 129 144 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) { 130 145 uint32_t usage; 131 if(report_item->type != USB_HID_REPORT_TYPE_OUTPUT) { 132 if(i < report_item->usages_count){ 133 usage = report_item->usages[i]; 134 } 135 else { 136 usage = report_item->usages[report_item->usages_count - 1]; 137 } 146 if(i < report_item->usages_count){ 147 usage = report_item->usages[i]; 138 148 } 139 149 else { 140 if((report_item->count - i - 1) < report_item->usages_count){ 141 usage = report_item->usages[(report_item->count - i - 1)]; 142 } 143 else { 144 usage = report_item->usages[report_item->usages_count - 1]; 145 } 150 usage = report_item->usages[report_item->usages_count - 1]; 146 151 } 147 152 … … 159 164 160 165 if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) { 161 if(report_item->type == USB_HID_REPORT_TYPE_INPUT) { 162 field->usage = report_item->usage_maximum - i; 163 } 164 else { 165 field->usage = report_item->usage_minimum + i; 166 } 167 168 } 169 166 field->usage = report_item->usage_minimum + i; 167 } 168 169 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page); 170 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage); 171 172 field->collection_path = usb_hid_report_path_try_insert(report, path); 173 170 174 field->size = report_item->size; 171 field->offset = report_item->offset + (i * report_item->size); 175 176 size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8; 177 size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size; 178 179 field->offset = 8 * offset_byte + offset_bit; 172 180 if(report_item->id != 0) { 173 181 field->offset += 8; … … 264 272 return ENOMEM; 265 273 } 274 usb_hid_report_path_append_item(usage_path, 0, 0); 266 275 267 276 while(i<size){ … … 349 358 tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link); 350 359 351 usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage); 360 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page); 361 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage); 352 362 353 363 usb_hid_report_path_free(report_item->usage_path); … … 427 437 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 428 438 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 429 { 439 { 440 usb_hid_report_usage_path_t *path_item; 441 430 442 switch(tag) 431 443 { … … 438 450 439 451 case USB_HID_REPORT_TAG_COLLECTION: 440 // TODO usage_path->flags = *data; 441 usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]); 452 // store collection atributes 453 path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 454 path_item->flags = *data; 455 456 // set last item 457 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page); 458 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]); 459 460 // append the new one which will be set by common 461 // usage/usage page 462 usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]); 442 463 usb_hid_report_reset_local_items (report_item); 443 464 return USB_HID_NO_ACTION; … … 530 551 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 531 552 { 532 switch(tag) 533 { 553 switch(tag) { 534 554 case USB_HID_REPORT_TAG_USAGE: 535 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size); 536 report_item->usages_count++; 555 switch(report_item->in_delimiter) { 556 case INSIDE_DELIMITER_SET: 557 // nothing to do 558 break; 559 case START_DELIMITER_SET: 560 report_item->in_delimiter = INSIDE_DELIMITER_SET; 561 case OUTSIDE_DELIMITER_SET: 562 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size); 563 report_item->usages_count++; 564 break; 565 } 537 566 break; 538 567 case USB_HID_REPORT_TAG_USAGE_MINIMUM: … … 575 604 break; 576 605 case USB_HID_REPORT_TAG_DELIMITER: 577 //report_item->delimiter = usb_hid_report_tag_data_uint32(data,item_size); 578 //TODO: 579 // DELIMITER STUFF 580 break; 581 606 report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size); 607 break; 608 582 609 default: 583 610 return USB_HID_NO_ACTION; 584 611 } 585 612 586 613 return EOK; 587 614 } … … 629 656 630 657 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset); 631 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 658 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 632 659 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum); 633 660 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum); … … 640 667 usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage); 641 668 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page); 642 643 // usb_log_debug("\n"); 669 670 //usb_hid_print_usage_path(report_item->collection_path); 671 672 usb_log_debug("\n"); 644 673 645 674 } … … 666 695 usb_log_debug("Report ID: %d\n", report_des->report_id); 667 696 usb_log_debug("\tType: %d\n", report_des->type); 668 usb_log_debug("\tLength: %zu\n", report_des->bit_length); 669 usb_log_debug("\tItems: %zu\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); 670 699 671 700 usb_hid_descriptor_print_list(&report_des->report_items); -
uspace/lib/usb/src/hidparser.c
r95285378 r1866945 405 405 } 406 406 407 size_t shift = offset%8;407 size_t shift = 8 - offset%8 - length; 408 408 409 409 value = value << shift; -
uspace/lib/usb/src/hidpath.c
r95285378 r1866945 149 149 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 150 150 151 item = item->next;151 item = item->next; 152 152 } 153 153 } … … 156 156 * Compares two usage paths structures 157 157 * 158 * If USB_HID_PATH_COMPARE_COLLECTION_ONLY flag is given, the last item in report_path structure is forgotten 159 * 160 * @param report_path usage path structure to compare 158 * 159 * @param report_path usage path structure to compare with @path 161 160 * @param path usage patrh structure to compare 162 161 * @param flags Flags determining the mode of comparison … … 179 178 } 180 179 180 // Empty path match all others 181 181 if(path->depth == 0){ 182 182 return EOK; … … 189 189 190 190 switch(flags){ 191 /* path must be completly identical */ 191 /* path is somewhere in report_path */ 192 case USB_HID_PATH_COMPARE_ANYWHERE: 193 if(path->depth != 1){ 194 return 1; 195 } 196 197 // projit skrz cestu a kdyz nekde sedi tak vratim EOK 198 // dojduli az za konec tak nnesedi 199 report_link = report_path->head.next; 200 path_link = path->head.next; 201 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link); 202 203 while(report_link != &report_path->head) { 204 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 205 if(report_item->usage_page == path_item->usage_page){ 206 if(only_page == 0){ 207 if(report_item->usage == path_item->usage) { 208 return EOK; 209 } 210 } 211 else { 212 return EOK; 213 } 214 } 215 216 report_link = report_link->next; 217 } 218 219 return 1; 220 break; 221 /* the paths must be identical */ 192 222 case USB_HID_PATH_COMPARE_STRICT: 193 223 if(report_path->depth != path->depth){ 194 224 return 1; 195 225 } 196 226 227 /* path is prefix of the report_path */ 228 case USB_HID_PATH_COMPARE_BEGIN: 229 197 230 report_link = report_path->head.next; 198 231 path_link = path->head.next; … … 221 254 } 222 255 223 if(((report_link == &report_path->head) && (path_link == &path->head)) || 224 (((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) && 225 (path_link = &path->head) && 226 (report_link == report_path->head.prev))) { 256 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) || 257 ((report_link == &report_path->head) && (path_link == &path->head))) { 227 258 return EOK; 228 259 } … … 232 263 break; 233 264 234 /* compare with only the end of path*/265 /* path is suffix of report_path */ 235 266 case USB_HID_PATH_COMPARE_END: 236 267 237 if((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) { 238 report_link = report_path->head.prev->prev; 239 } 240 else { 241 report_link = report_path->head.prev; 242 } 268 report_link = report_path->head.prev; 243 269 path_link = path->head.prev; 244 270 -
uspace/lib/usbvirt/Makefile
r95285378 r1866945 33 33 34 34 SOURCES = \ 35 src/ipc.c \36 35 src/ctrltransfer.c \ 36 src/device.c \ 37 src/ipc_dev.c \ 38 src/ipc_hc.c \ 37 39 src/stdreq.c \ 38 40 src/transfer.c -
uspace/lib/usbvirt/include/usbvirt/device.h
r95285378 r1866945 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
r95285378 r1866945 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
r95285378 r1866945 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
r95285378 r1866945 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
r95285378 r1866945 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
r95285378 r1866945 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.