Changes in / [74d6e90:621afdb] in mainline
- Location:
- uspace
- Files:
-
- 5 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dump.c
r74d6e90 r621afdb 96 96 void dump_usb_descriptor(uint8_t *descriptor, size_t size) 97 97 { 98 printf("Device descriptor:\n");99 98 usb_dump_standard_descriptor(stdout, get_indent(0), "\n", 100 99 descriptor, size); -
uspace/app/usbinfo/info.c
r74d6e90 r621afdb 38 38 #include <errno.h> 39 39 #include <usb/usbdrv.h> 40 #include <usb/pipes.h>41 #include <usb/request.h>42 40 #include "usbinfo.h" 43 41 44 int dump_device( devman_handle_t hc_handle, usb_address_t address)42 int dump_device(int hc_phone, usb_address_t address) 45 43 { 46 int rc;47 usb_device_connection_t wire;48 usb_endpoint_pipe_t ctrl_pipe;49 ctrl_pipe.hc_phone = -1;50 51 int hc_phone = devman_device_connect(hc_handle, 0);52 if (hc_phone < 0) {53 fprintf(stderr,54 NAME ": failed to connect to host controller (%zu): %s.\n",55 (size_t) hc_handle, str_error(hc_phone));56 return hc_phone;57 }58 59 44 /* 60 45 * Dump information about possible match ids. … … 62 47 match_id_list_t match_id_list; 63 48 init_match_ids(&match_id_list); 64 rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);49 int rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address); 65 50 if (rc != EOK) { 66 51 fprintf(stderr, 67 52 NAME ": failed to fetch match ids of the device: %s.\n", 68 53 str_error(rc)); 69 goto leave;54 return rc; 70 55 } 71 56 dump_match_ids(&match_id_list); 72 73 /*74 * Initialize pipes.75 */76 rc = usb_device_connection_initialize(&wire, hc_handle, address);77 if (rc != EOK) {78 fprintf(stderr,79 NAME ": failed to create connection to the device: %s.\n",80 str_error(rc));81 goto leave;82 }83 rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe, &wire);84 if (rc != EOK) {85 fprintf(stderr,86 NAME ": failed to create default control pipe: %s.\n",87 str_error(rc));88 goto leave;89 }90 rc = usb_endpoint_pipe_start_session(&ctrl_pipe);91 if (rc != EOK) {92 fprintf(stderr,93 NAME ": failed to start session on control pipe: %s.\n",94 str_error(rc));95 goto leave;96 }97 57 98 58 /* … … 100 60 */ 101 61 usb_standard_device_descriptor_t device_descriptor; 102 rc = usb_request_get_device_descriptor(&ctrl_pipe, &device_descriptor); 62 usb_dprintf(NAME, 1, 63 "usb_drv_req_get_device_descriptor(%d, %d, %p)\n", 64 hc_phone, (int) address, &device_descriptor); 65 66 rc = usb_drv_req_get_device_descriptor(hc_phone, address, 67 &device_descriptor); 103 68 if (rc != EOK) { 104 69 fprintf(stderr, 105 70 NAME ": failed to fetch standard device descriptor: %s.\n", 106 71 str_error(rc)); 107 goto leave;72 return rc; 108 73 } 109 74 dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor)); … … 114 79 usb_standard_configuration_descriptor_t config_descriptor; 115 80 int config_index = 0; 116 rc = usb_request_get_bare_configuration_descriptor(&ctrl_pipe, 117 config_index, &config_descriptor); 81 usb_dprintf(NAME, 1, 82 "usb_drv_req_get_bare_configuration_descriptor(%d, %d, %d, %p)\n", 83 hc_phone, (int) address, config_index, &config_descriptor); 84 85 rc = usb_drv_req_get_bare_configuration_descriptor(hc_phone, address, 86 config_index, &config_descriptor ); 118 87 if (rc != EOK) { 119 88 fprintf(stderr, 120 89 NAME ": failed to fetch standard configuration descriptor: %s.\n", 121 90 str_error(rc)); 122 goto leave;91 return rc; 123 92 } 124 93 //dump_standard_configuration_descriptor(config_index, &config_descriptor); 125 94 126 95 void *full_config_descriptor = malloc(config_descriptor.total_length); 127 rc = usb_request_get_full_configuration_descriptor(&ctrl_pipe, 96 usb_dprintf(NAME, 1, 97 "usb_drv_req_get_full_configuration_descriptor(%d, %d, %d, %p, %zu)\n", 98 hc_phone, (int) address, config_index, 99 full_config_descriptor, config_descriptor.total_length); 100 101 rc = usb_drv_req_get_full_configuration_descriptor(hc_phone, address, 128 102 config_index, 129 103 full_config_descriptor, config_descriptor.total_length, NULL); … … 132 106 NAME ": failed to fetch full configuration descriptor: %s.\n", 133 107 str_error(rc)); 134 goto leave;108 return rc; 135 109 } 136 110 … … 138 112 config_descriptor.total_length); 139 113 140 rc = EOK; 141 leave: 142 /* Ignoring errors here. */ 143 ipc_hangup(hc_phone); 144 usb_endpoint_pipe_end_session(&ctrl_pipe); 145 146 return rc; 114 return EOK; 147 115 } 148 116 -
uspace/app/usbinfo/main.c
r74d6e90 r621afdb 77 77 } 78 78 79 static int get_host_controller_handle(const char *path, 80 devman_handle_t *hc_handle) 79 static int set_new_host_controller(int *phone, const char *path) 81 80 { 82 81 int rc; 83 84 devman_handle_t handle; 85 rc = devman_device_get_handle(path, &handle, 0); 86 if (rc != EOK) { 87 fprintf(stderr, 88 NAME ": failed getting handle of `devman::/%s'.\n", 89 path); 90 return rc; 91 } 92 *hc_handle = handle; 82 int tmp_phone; 83 84 if (path[0] != '/') { 85 int hc_class_index = (int) strtol(path, NULL, 10); 86 char *dev_path; 87 rc = asprintf(&dev_path, "class/usbhc\\%d", hc_class_index); 88 if (rc < 0) { 89 internal_error(rc); 90 return rc; 91 } 92 devmap_handle_t handle; 93 rc = devmap_device_get_handle(dev_path, &handle, 0); 94 if (rc < 0) { 95 fprintf(stderr, 96 NAME ": failed getting handle of `devman://%s'.\n", 97 dev_path); 98 free(dev_path); 99 return rc; 100 } 101 tmp_phone = devmap_device_connect(handle, 0); 102 if (tmp_phone < 0) { 103 fprintf(stderr, 104 NAME ": could not connect to `%s'.\n", 105 dev_path); 106 free(dev_path); 107 return tmp_phone; 108 } 109 free(dev_path); 110 } else { 111 devman_handle_t handle; 112 rc = devman_device_get_handle(path, &handle, 0); 113 if (rc != EOK) { 114 fprintf(stderr, 115 NAME ": failed getting handle of `devmap::/%s'.\n", 116 path); 117 return rc; 118 } 119 tmp_phone = devman_device_connect(handle, 0); 120 if (tmp_phone < 0) { 121 fprintf(stderr, 122 NAME ": could not connect to `%s'.\n", 123 path); 124 return tmp_phone; 125 } 126 } 127 128 *phone = tmp_phone; 93 129 94 130 return EOK; 95 131 } 96 132 97 static int get_device_address(const char *str_address, usb_address_t *address)98 { 99 usb_address_t addr = (usb_address_t) strtol(str_address, NULL, 0);100 if ((addr < 0) || (addr>= USB11_ADDRESS_MAX)) {133 static int connect_with_address(int hc_phone, const char *str_address) 134 { 135 usb_address_t address = (usb_address_t) strtol(str_address, NULL, 0); 136 if ((address < 0) || (address >= USB11_ADDRESS_MAX)) { 101 137 fprintf(stderr, NAME ": USB address out of range.\n"); 102 138 return ERANGE; 103 139 } 104 140 105 *address = addr; 106 return EOK; 141 if (hc_phone < 0) { 142 fprintf(stderr, NAME ": no active host controller.\n"); 143 return ENOENT; 144 } 145 146 return dump_device(hc_phone, address); 107 147 } 108 148 … … 110 150 int main(int argc, char *argv[]) 111 151 { 112 devman_handle_t hc_handle = (devman_handle_t) -1; 113 usb_address_t device_address = (usb_address_t) -1; 152 int hc_phone = -1; 114 153 115 154 if (argc <= 1) { … … 136 175 case 'a': 137 176 case ACTION_DEVICE_ADDRESS: { 138 int rc = get_device_address(optarg, 139 &device_address); 177 int rc = connect_with_address(hc_phone, optarg); 140 178 if (rc != EOK) { 141 179 return rc; … … 146 184 case 't': 147 185 case ACTION_HOST_CONTROLLER: { 148 int rc = get_host_controller_handle(optarg,149 &hc_handle);186 int rc = set_new_host_controller(&hc_phone, 187 optarg); 150 188 if (rc != EOK) { 151 189 return rc; … … 164 202 } while (i != -1); 165 203 166 if ((hc_handle == (devman_handle_t) -1)167 || (device_address == (usb_address_t) -1)) {168 fprintf(stderr, NAME ": no target specified.\n");169 return EINVAL;170 }171 172 dump_device(hc_handle, device_address);173 174 204 return 0; 175 205 } -
uspace/app/usbinfo/usbinfo.h
r74d6e90 r621afdb 47 47 void dump_match_ids(match_id_list_t *matches); 48 48 void dump_usb_descriptor(uint8_t *, size_t); 49 int dump_device( devman_handle_t, usb_address_t);49 int dump_device(int, usb_address_t); 50 50 void dump_descriptor_tree(uint8_t *, size_t); 51 51 -
uspace/drv/usbhid/descdump.h
r74d6e90 r621afdb 37 37 #define USBHID_DESCDUMP_H_ 38 38 39 #include "hid.h"39 #include <usb/classes/hid.h> 40 40 41 41 void dump_standard_configuration_descriptor( -
uspace/drv/usbhid/descparser.h
r74d6e90 r621afdb 37 37 #define USBHID_DESCPARSER_H_ 38 38 39 #include "hid.h"39 #include <usb/classes/hid.h> 40 40 41 41 int usbkbd_parse_descriptors(const uint8_t *data, size_t size, -
uspace/drv/usbhid/main.c
r74d6e90 r621afdb 43 43 #include <io/console.h> 44 44 #include <errno.h> 45 #include <str_error.h>46 45 #include <fibril.h> 47 46 #include <usb/classes/hid.h> … … 50 49 #include <usb/descriptor.h> 51 50 #include <io/console.h> 52 #include "hid.h"53 51 #include "descparser.h" 54 52 #include "descdump.h" … … 381 379 if (rc < 0) { 382 380 printf("Problem setting phone to HC.\n"); 383 goto error_leave; 381 free(kbd_dev); 382 return NULL; 384 383 } 385 384 … … 387 386 if (rc < 0) { 388 387 printf("Problem getting address of the device.\n"); 389 goto error_leave; 388 free(kbd_dev); 389 return NULL; 390 390 } 391 391 … … 397 397 // } 398 398 399 // default endpoint 400 kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT; 401 399 402 /* 400 403 * will need all descriptors: … … 407 410 usbkbd_process_descriptors(kbd_dev); 408 411 409 410 411 /*412 * Initialize the backing connection to the host controller.413 */414 rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);415 if (rc != EOK) {416 printf("Problem initializing connection to device: %s.\n",417 str_error(rc));418 goto error_leave;419 }420 421 /*422 * Initialize device pipes.423 */424 rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,425 GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);426 if (rc != EOK) {427 printf("Failed to initialize interrupt in pipe: %s.\n",428 str_error(rc));429 goto error_leave;430 }431 432 433 412 return kbd_dev; 434 435 error_leave:436 free(kbd_dev);437 return NULL;438 413 } 439 414 … … 460 435 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 461 436 { 462 int rc, sess_rc; 437 int rc; 438 usb_handle_t handle; 463 439 uint8_t buffer[BUFFER_SIZE]; 464 440 size_t actual_size; 441 //usb_endpoint_t poll_endpoint = 1; 442 443 // usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone, 444 // dev); 445 // if (my_address < 0) { 446 // return; 447 // } 448 449 usb_target_t poll_target = { 450 .address = kbd_dev->address, 451 .endpoint = kbd_dev->poll_endpoint 452 }; 465 453 466 454 printf("Polling keyboard...\n"); … … 468 456 while (true) { 469 457 async_usleep(1000 * 1000 * 2); 470 471 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);472 if (sess_rc != EOK) { 473 printf("Failed to start a session: %s.\n",474 str_error(sess_rc));458 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 459 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 460 461 if (rc != EOK) { 462 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 475 463 continue; 476 464 } 477 465 478 rc = usb_endpoint_pipe_read(&kbd_dev->poll_pipe, buffer, 479 BUFFER_SIZE, &actual_size); 480 sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->poll_pipe); 481 466 rc = usb_drv_async_wait_for(handle); 482 467 if (rc != EOK) { 483 printf("Error polling the keyboard: %s.\n", 484 str_error(rc)); 485 continue; 486 } 487 488 if (sess_rc != EOK) { 489 printf("Error closing session: %s.\n", 490 str_error(sess_rc)); 468 printf("Error in usb_drv_async_wait_for(): %d\n", rc); 491 469 continue; 492 470 } -
uspace/drv/vhc/connhost.c
r74d6e90 r621afdb 42 42 #include "hc.h" 43 43 44 45 44 typedef struct { 46 45 usb_direction_t direction; … … 48 47 usbhc_iface_transfer_in_callback_t in_callback; 49 48 device_t *dev; 50 size_t reported_size;51 49 void *arg; 52 50 } transfer_info_t; 53 51 54 typedef struct {55 usb_direction_t direction;56 usb_target_t target;57 usbhc_iface_transfer_out_callback_t out_callback;58 usbhc_iface_transfer_in_callback_t in_callback;59 device_t *dev;60 void *arg;61 void *data_buffer;62 size_t data_buffer_size;63 } control_transfer_info_t;64 65 52 static void universal_callback(void *buffer, size_t size, 66 53 usb_transaction_outcome_t outcome, void *arg) 67 54 { 68 55 transfer_info_t *transfer = (transfer_info_t *) arg; 69 70 if (transfer->reported_size != (size_t) -1) {71 size = transfer->reported_size;72 }73 56 74 57 switch (transfer->direction) { … … 101 84 transfer->arg = arg; 102 85 transfer->dev = dev; 103 transfer->reported_size = (size_t) -1;104 105 return transfer;106 }107 108 static void control_abort_prematurely(control_transfer_info_t *transfer,109 size_t size, usb_transaction_outcome_t outcome)110 {111 switch (transfer->direction) {112 case USB_DIRECTION_IN:113 transfer->in_callback(transfer->dev,114 outcome, size,115 transfer->arg);116 break;117 case USB_DIRECTION_OUT:118 transfer->out_callback(transfer->dev,119 outcome,120 transfer->arg);121 break;122 default:123 assert(false && "unreachable");124 break;125 }126 }127 128 static void control_callback_two(void *buffer, size_t size,129 usb_transaction_outcome_t outcome, void *arg)130 {131 control_transfer_info_t *ctrl_transfer = (control_transfer_info_t *) arg;132 133 if (outcome != USB_OUTCOME_OK) {134 control_abort_prematurely(ctrl_transfer, outcome, size);135 free(ctrl_transfer);136 return;137 }138 139 transfer_info_t *transfer = create_transfer_info(ctrl_transfer->dev,140 ctrl_transfer->direction, ctrl_transfer->arg);141 transfer->out_callback = ctrl_transfer->out_callback;142 transfer->in_callback = ctrl_transfer->in_callback;143 transfer->reported_size = size;144 145 switch (ctrl_transfer->direction) {146 case USB_DIRECTION_IN:147 hc_add_transaction_to_device(false, ctrl_transfer->target,148 USB_TRANSFER_CONTROL,149 NULL, 0,150 universal_callback, transfer);151 break;152 case USB_DIRECTION_OUT:153 hc_add_transaction_from_device(ctrl_transfer->target,154 USB_TRANSFER_CONTROL,155 NULL, 0,156 universal_callback, transfer);157 break;158 default:159 assert(false && "unreachable");160 break;161 }162 163 free(ctrl_transfer);164 }165 166 static void control_callback_one(void *buffer, size_t size,167 usb_transaction_outcome_t outcome, void *arg)168 {169 control_transfer_info_t *transfer = (control_transfer_info_t *) arg;170 171 if (outcome != USB_OUTCOME_OK) {172 control_abort_prematurely(transfer, outcome, size);173 free(transfer);174 return;175 }176 177 switch (transfer->direction) {178 case USB_DIRECTION_IN:179 hc_add_transaction_from_device(transfer->target,180 USB_TRANSFER_CONTROL,181 transfer->data_buffer, transfer->data_buffer_size,182 control_callback_two, transfer);183 break;184 case USB_DIRECTION_OUT:185 hc_add_transaction_to_device(false, transfer->target,186 USB_TRANSFER_CONTROL,187 transfer->data_buffer, transfer->data_buffer_size,188 control_callback_two, transfer);189 break;190 default:191 assert(false && "unreachable");192 break;193 }194 }195 196 static control_transfer_info_t *create_control_transfer_info(device_t *dev,197 usb_direction_t direction, usb_target_t target,198 void *data_buffer, size_t data_buffer_size,199 void *arg)200 {201 control_transfer_info_t *transfer202 = malloc(sizeof(control_transfer_info_t));203 204 transfer->direction = direction;205 transfer->target = target;206 transfer->in_callback = NULL;207 transfer->out_callback = NULL;208 transfer->arg = arg;209 transfer->dev = dev;210 transfer->data_buffer = data_buffer;211 transfer->data_buffer_size = data_buffer_size;212 86 213 87 return transfer; … … 319 193 } 320 194 321 static int control_write(device_t *dev, usb_target_t target,322 void *setup_packet, size_t setup_packet_size,323 void *data, size_t data_size,324 usbhc_iface_transfer_out_callback_t callback, void *arg)325 {326 control_transfer_info_t *transfer327 = create_control_transfer_info(dev, USB_DIRECTION_OUT, target,328 data, data_size, arg);329 transfer->out_callback = callback;330 331 hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL,332 setup_packet, setup_packet_size,333 control_callback_one, transfer);334 335 return EOK;336 }337 338 195 static int control_read_setup(device_t *dev, usb_target_t target, 339 196 void *data, size_t size, … … 360 217 NULL, 0, 361 218 callback, arg); 362 }363 364 static int control_read(device_t *dev, usb_target_t target,365 void *setup_packet, size_t setup_packet_size,366 void *data, size_t data_size,367 usbhc_iface_transfer_in_callback_t callback, void *arg)368 {369 control_transfer_info_t *transfer370 = create_control_transfer_info(dev, USB_DIRECTION_IN, target,371 data, data_size, arg);372 transfer->in_callback = callback;373 374 hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL,375 setup_packet, setup_packet_size,376 control_callback_one, transfer);377 378 return EOK;379 219 } 380 220 … … 450 290 .control_write_status = control_write_status, 451 291 452 .control_write = control_write,453 454 292 .control_read_setup = control_read_setup, 455 293 .control_read_data = control_read_data, 456 .control_read_status = control_read_status, 457 458 .control_read = control_read 294 .control_read_status = control_read_status 459 295 }; 460 296 -
uspace/lib/drv/generic/remote_usbhc.c
r74d6e90 r621afdb 1 1 /* 2 * Copyright (c) 2010 -2011Vojtech Horky2 * Copyright (c) 2010 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 52 52 static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *); 53 53 static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *); 54 static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *);55 static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *);56 54 static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 57 55 static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 83 81 remote_usbhc_control_read_setup, 84 82 remote_usbhc_control_read_data, 85 remote_usbhc_control_read_status, 86 87 remote_usbhc_control_write, 88 remote_usbhc_control_read 83 remote_usbhc_control_read_status 89 84 }; 90 85 … … 100 95 ipc_callid_t caller; 101 96 void *buffer; 102 void *setup_packet;103 97 size_t size; 104 98 } async_transaction_t; 105 106 static void async_transaction_destroy(async_transaction_t *trans)107 {108 if (trans == NULL) {109 return;110 }111 112 if (trans->setup_packet != NULL) {113 free(trans->setup_packet);114 }115 if (trans->buffer != NULL) {116 free(trans->buffer);117 }118 119 free(trans);120 }121 122 static async_transaction_t *async_transaction_create(ipc_callid_t caller)123 {124 async_transaction_t *trans = malloc(sizeof(async_transaction_t));125 if (trans == NULL) {126 return NULL;127 }128 129 trans->caller = caller;130 trans->buffer = NULL;131 trans->setup_packet = NULL;132 trans->size = 0;133 134 return trans;135 }136 99 137 100 void remote_usbhc_get_address(device_t *device, void *iface, … … 167 130 if (trans->buffer == NULL) { 168 131 ipc_answer_0(callid, EINVAL); 169 async_transaction_destroy(trans);132 free(trans); 170 133 return; 171 134 } … … 175 138 if (!async_data_read_receive(&cid, &accepted_size)) { 176 139 ipc_answer_0(callid, EINVAL); 177 async_transaction_destroy(trans);178 140 return; 179 141 } … … 186 148 ipc_answer_1(callid, EOK, accepted_size); 187 149 188 async_transaction_destroy(trans); 150 free(trans->buffer); 151 free(trans); 189 152 } 190 153 … … 279 242 async_transaction_t *trans = (async_transaction_t *)arg; 280 243 244 // FIXME - answer according to outcome 281 245 ipc_answer_0(trans->caller, outcome); 282 246 283 async_transaction_destroy(trans);247 free(trans); 284 248 } 285 249 … … 289 253 async_transaction_t *trans = (async_transaction_t *)arg; 290 254 291 if (outcome != USB_OUTCOME_OK) { 292 ipc_answer_0(trans->caller, outcome); 293 async_transaction_destroy(trans); 294 return; 295 } 255 // FIXME - answer according to outcome 256 ipc_answer_1(trans->caller, outcome, (sysarg_t)trans); 296 257 297 258 trans->size = actual_size; 298 ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);299 259 } 300 260 … … 334 294 } 335 295 336 async_transaction_t *trans = async_transaction_create(callid); 337 if (trans == NULL) { 296 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 297 trans->caller = callid; 298 trans->buffer = buffer; 299 trans->size = len; 300 301 int rc = transfer_func(device, target, buffer, len, 302 callback_out, trans); 303 304 if (rc != EOK) { 305 ipc_answer_0(callid, rc); 338 306 if (buffer != NULL) { 339 307 free(buffer); 340 308 } 341 ipc_answer_0(callid, ENOMEM); 342 return; 343 } 344 345 trans->buffer = buffer; 346 trans->size = len; 347 348 int rc = transfer_func(device, target, buffer, len, 349 callback_out, trans); 350 351 if (rc != EOK) { 352 ipc_answer_0(callid, rc); 353 async_transaction_destroy(trans); 309 free(trans); 354 310 } 355 311 } … … 377 333 }; 378 334 379 async_transaction_t *trans = async_transaction_create(callid); 380 if (trans == NULL) { 381 ipc_answer_0(callid, ENOMEM); 382 return; 383 } 335 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 336 trans->caller = callid; 384 337 trans->buffer = malloc(len); 385 338 trans->size = len; … … 390 343 if (rc != EOK) { 391 344 ipc_answer_0(callid, rc); 392 async_transaction_destroy(trans); 345 free(trans->buffer); 346 free(trans); 393 347 } 394 348 } … … 434 388 }; 435 389 436 async_transaction_t *trans = async_transaction_create(callid); 437 if (trans == NULL) { 438 ipc_answer_0(callid, ENOMEM); 439 return; 440 } 390 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 391 trans->caller = callid; 392 trans->buffer = NULL; 393 trans->size = 0; 441 394 442 395 int rc; … … 457 410 if (rc != EOK) { 458 411 ipc_answer_0(callid, rc); 459 async_transaction_destroy(trans); 460 } 412 free(trans); 413 } 414 return; 461 415 } 462 416 … … 542 496 } 543 497 544 void remote_usbhc_control_write(device_t *device, void *iface,545 ipc_callid_t callid, ipc_call_t *call)546 {547 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;548 assert(usb_iface != NULL);549 550 if (!usb_iface->control_write) {551 ipc_answer_0(callid, ENOTSUP);552 return;553 }554 555 usb_target_t target = {556 .address = DEV_IPC_GET_ARG1(*call),557 .endpoint = DEV_IPC_GET_ARG2(*call)558 };559 560 int rc;561 562 void *setup_packet = NULL;563 void *data_buffer = NULL;564 size_t setup_packet_len = 0;565 size_t data_buffer_len = 0;566 567 rc = async_data_write_accept(&setup_packet, false,568 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);569 if (rc != EOK) {570 ipc_answer_0(callid, rc);571 return;572 }573 rc = async_data_write_accept(&data_buffer, false,574 1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);575 if (rc != EOK) {576 ipc_answer_0(callid, rc);577 free(setup_packet);578 return;579 }580 581 async_transaction_t *trans = async_transaction_create(callid);582 if (trans == NULL) {583 ipc_answer_0(callid, ENOMEM);584 free(setup_packet);585 free(data_buffer);586 return;587 }588 trans->setup_packet = setup_packet;589 trans->buffer = data_buffer;590 trans->size = data_buffer_len;591 592 rc = usb_iface->control_write(device, target,593 setup_packet, setup_packet_len,594 data_buffer, data_buffer_len,595 callback_out, trans);596 597 if (rc != EOK) {598 ipc_answer_0(callid, rc);599 async_transaction_destroy(trans);600 }601 }602 603 604 void remote_usbhc_control_read(device_t *device, void *iface,605 ipc_callid_t callid, ipc_call_t *call)606 {607 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;608 assert(usb_iface != NULL);609 610 if (!usb_iface->control_read) {611 ipc_answer_0(callid, ENOTSUP);612 return;613 }614 615 size_t data_len = DEV_IPC_GET_ARG3(*call);616 usb_target_t target = {617 .address = DEV_IPC_GET_ARG1(*call),618 .endpoint = DEV_IPC_GET_ARG2(*call)619 };620 621 int rc;622 623 void *setup_packet = NULL;624 size_t setup_packet_len = 0;625 626 rc = async_data_write_accept(&setup_packet, false,627 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);628 if (rc != EOK) {629 ipc_answer_0(callid, rc);630 return;631 }632 633 async_transaction_t *trans = async_transaction_create(callid);634 if (trans == NULL) {635 ipc_answer_0(callid, ENOMEM);636 free(setup_packet);637 return;638 }639 trans->setup_packet = setup_packet;640 trans->size = data_len;641 trans->buffer = malloc(data_len);642 if (trans->buffer == NULL) {643 ipc_answer_0(callid, ENOMEM);644 async_transaction_destroy(trans);645 return;646 }647 648 rc = usb_iface->control_read(device, target,649 setup_packet, setup_packet_len,650 trans->buffer, trans->size,651 callback_in, trans);652 653 if (rc != EOK) {654 ipc_answer_0(callid, rc);655 async_transaction_destroy(trans);656 }657 }658 659 498 660 499 -
uspace/lib/drv/include/usbhc_iface.h
r74d6e90 r621afdb 201 201 IPC_M_USBHC_CONTROL_READ_STATUS, 202 202 203 /** Issue control WRITE transfer.204 * See explanation at usb_iface_funcs_t (OUT transaction) for205 * call parameters.206 * This call is immediately followed by two IPC data writes207 * from the caller (setup packet and actual data).208 */209 IPC_M_USBHC_CONTROL_WRITE,210 211 /** Issue control WRITE transfer.212 * See explanation at usb_iface_funcs_t (IN transaction) for213 * call parameters.214 * This call is immediately followed by IPC data read from the caller215 * (setup packet).216 * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER.217 */218 IPC_M_USBHC_CONTROL_READ,219 203 220 204 /* IPC_M_USB_ */ … … 265 249 int (*control_read_status)(device_t *, usb_target_t, 266 250 usbhc_iface_transfer_out_callback_t, void *); 267 268 int (*control_write)(device_t *, usb_target_t,269 void *, size_t, void *, size_t,270 usbhc_iface_transfer_out_callback_t, void *);271 272 int (*control_read)(device_t *, usb_target_t,273 void *, size_t, void *, size_t,274 usbhc_iface_transfer_in_callback_t, void *);275 251 } usbhc_iface_t; 276 252 -
uspace/lib/usb/Makefile
r74d6e90 r621afdb 43 43 src/hidparser.c \ 44 44 src/localdrv.c \ 45 src/pipes.c \46 45 src/recognise.c \ 47 46 src/remotedrv.c \ 48 src/request.c \49 47 src/usb.c \ 50 48 src/usbdrvreq.c \ -
uspace/lib/usb/include/usb/classes/hid.h
r74d6e90 r621afdb 37 37 38 38 #include <usb/usb.h> 39 #include <driver.h> 39 40 #include <usb/classes/hidparser.h> 40 41 #include <usb/descriptor.h> … … 100 101 } __attribute__ ((packed)) usb_standard_hid_descriptor_t; 101 102 103 /** 104 * 105 */ 106 typedef struct { 107 usb_standard_interface_descriptor_t iface_desc; 108 usb_standard_endpoint_descriptor_t *endpoints; 109 usb_standard_hid_descriptor_t hid_desc; 110 uint8_t *report_desc; 111 //usb_standard_hid_class_descriptor_info_t *class_desc_info; 112 //uint8_t **class_descs; 113 } usb_hid_iface_t; 114 115 /** 116 * 117 */ 118 typedef struct { 119 usb_standard_configuration_descriptor_t config_descriptor; 120 usb_hid_iface_t *interfaces; 121 } usb_hid_configuration_t; 122 123 /** 124 * @brief USB/HID keyboard device type. 125 * 126 * Quite dummy right now. 127 */ 128 typedef struct { 129 device_t *device; 130 usb_hid_configuration_t *conf; 131 usb_address_t address; 132 usb_endpoint_t poll_endpoint; 133 usb_hid_report_parser_t *parser; 134 } usb_hid_dev_kbd_t; 135 136 // TODO: more configurations! 102 137 103 138 #endif -
uspace/lib/usb/include/usb/debug.h
r74d6e90 r621afdb 47 47 /** Logging level. */ 48 48 typedef enum { 49 USB_LOG_LEVEL_FATAL, 50 USB_LOG_LEVEL_ERROR, 51 USB_LOG_LEVEL_WARNING, 52 USB_LOG_LEVEL_INFO, 53 USB_LOG_LEVEL_DEBUG, 54 USB_LOG_LEVEL_DEBUG2, 55 USB_LOG_LEVEL_MAX 49 USB_LOG_LEVEL_FATAL, 50 USB_LOG_LEVEL_ERROR, 51 USB_LOG_LEVEL_WARNING, 52 USB_LOG_LEVEL_INFO, 53 USB_LOG_LEVEL_DEBUG, 54 USB_LOG_LEVEL_DEBUG2 56 55 } usb_log_level_t; 57 56 -
uspace/lib/usb/include/usb/usb.h
r74d6e90 r621afdb 37 37 38 38 #include <sys/types.h> 39 #include <byteorder.h>40 39 #include <ipc/ipc.h> 41 42 /** Convert 16bit value from native (host) endianness to USB endianness. */43 #define uint16_host2usb(n) host2uint16_t_le((n))44 45 /** Convert 32bit value from native (host) endianness to USB endianness. */46 #define uint32_host2usb(n) host2uint32_t_le((n))47 48 /** Convert 16bit value from USB endianness into native (host) one. */49 #define uint16_usb2host(n) uint16_t_le2host((n))50 51 /** Convert 32bit value from USB endianness into native (host) one. */52 #define uint32_usb2host(n) uint32_t_le2host((n))53 54 40 55 41 /** USB transfer type. */ … … 66 52 typedef enum { 67 53 USB_DIRECTION_IN, 68 USB_DIRECTION_OUT, 69 USB_DIRECTION_BOTH 54 USB_DIRECTION_OUT 70 55 } usb_direction_t; 71 56 -
uspace/lib/usb/include/usb/usbdrv.h
r74d6e90 r621afdb 70 70 usb_handle_t *); 71 71 72 int usb_drv_async_control_write(int, usb_target_t,73 void *, size_t, void *, size_t, usb_handle_t *);74 75 72 int usb_drv_psync_control_write_setup(int, usb_target_t, void *, size_t); 76 73 int usb_drv_psync_control_write_data(int, usb_target_t, void *, size_t); … … 80 77 void *, size_t, void *, size_t); 81 78 79 82 80 int usb_drv_async_control_read_setup(int, usb_target_t, 83 81 void *, size_t, usb_handle_t *); … … 86 84 int usb_drv_async_control_read_status(int, usb_target_t, 87 85 usb_handle_t *); 88 89 int usb_drv_async_control_read(int, usb_target_t,90 void *, size_t, void *, size_t, size_t *, usb_handle_t *);91 86 92 87 int usb_drv_psync_control_read_setup(int, usb_target_t, void *, size_t); -
uspace/lib/usb/src/debug.c
r74d6e90 r621afdb 67 67 /** Serialization mutex for logging functions. */ 68 68 static FIBRIL_MUTEX_INITIALIZE(log_serializer); 69 static FILE *log_stream = NULL;70 69 71 70 /** Find or create new tag with given name. … … 172 171 log_prefix = message_prefix; 173 172 log_level = level; 174 if (log_stream == NULL) {175 char *fname;176 int rc = asprintf(&fname, "/log/%s", message_prefix);177 if (rc > 0) {178 log_stream = fopen(fname, "w");179 free(fname);180 }181 }182 173 } 183 174 … … 206 197 void usb_log_printf(usb_log_level_t level, const char *format, ...) 207 198 { 199 if (level > log_level) { 200 return; 201 } 202 208 203 FILE *stream = NULL; 209 204 switch (level) { … … 221 216 va_start(args, format); 222 217 223 /*224 * Serialize access to log files.225 * Always print to log file, to screen print only when the enabled226 * log level is high enough.227 */228 218 fibril_mutex_lock(&log_serializer); 229 230 const char *level_name = log_level_name(level); 231 232 if (log_stream != NULL) { 233 fprintf(log_stream, "[%s]%s: ", log_prefix, level_name); 234 vfprintf(log_stream, format, args); 235 } 236 237 if (level <= log_level) { 238 fprintf(stream, "[%s]%s: ", log_prefix, level_name); 239 vfprintf(stream, format, args); 240 } 241 219 fprintf(stream, "[%s]%s: ", log_prefix, log_level_name(level)); 220 vfprintf(stream, format, args); 242 221 fibril_mutex_unlock(&log_serializer); 243 222 -
uspace/lib/usb/src/usbdrv.c
r74d6e90 r621afdb 495 495 } 496 496 497 /** Issue whole control write transfer. */498 int usb_drv_async_control_write(int phone, usb_target_t target,499 void *setup_packet, size_t setup_packet_size,500 void *buffer, size_t buffer_size,501 usb_handle_t *handle)502 {503 // FIXME - check input parameters instead of asserting them504 assert(phone > 0);505 assert(setup_packet != NULL);506 assert(setup_packet_size > 0);507 assert(buffer != NULL);508 assert(buffer_size > 0);509 assert(handle != NULL);510 511 transfer_info_t *transfer512 = (transfer_info_t *) malloc(sizeof(transfer_info_t));513 if (transfer == NULL) {514 return ENOMEM;515 }516 517 transfer->size_transferred = NULL;518 transfer->buffer = NULL;519 transfer->size = 0;520 transfer->phone = phone;521 522 int rc;523 524 transfer->request = async_send_3(phone,525 DEV_IFACE_ID(USBHC_DEV_IFACE),526 IPC_M_USBHC_CONTROL_WRITE,527 target.address, target.endpoint,528 &transfer->reply);529 530 rc = async_data_write_start(phone, setup_packet, setup_packet_size);531 if (rc != EOK) {532 async_wait_for(transfer->request, NULL);533 return rc;534 }535 536 rc = async_data_write_start(phone, buffer, buffer_size);537 if (rc != EOK) {538 async_wait_for(transfer->request, NULL);539 return rc;540 }541 542 *handle = (usb_handle_t) transfer;543 544 return EOK;545 }546 547 497 /** Start control read transfer. */ 548 498 int usb_drv_async_control_read_setup(int phone, usb_target_t target, … … 580 530 } 581 531 582 /** Issue whole control read transfer. */583 int usb_drv_async_control_read(int phone, usb_target_t target,584 void *setup_packet, size_t setup_packet_size,585 void *buffer, size_t buffer_size, size_t *actual_size,586 usb_handle_t *handle)587 {588 // FIXME - check input parameters instead of asserting them589 assert(phone > 0);590 assert(setup_packet != NULL);591 assert(setup_packet_size > 0);592 assert(buffer != NULL);593 assert(buffer_size > 0);594 assert(handle != NULL);595 596 transfer_info_t *transfer597 = (transfer_info_t *) malloc(sizeof(transfer_info_t));598 if (transfer == NULL) {599 return ENOMEM;600 }601 602 transfer->size_transferred = actual_size;603 transfer->buffer = buffer;604 transfer->size = buffer_size;605 transfer->phone = phone;606 607 int rc;608 609 transfer->request = async_send_4(phone,610 DEV_IFACE_ID(USBHC_DEV_IFACE),611 IPC_M_USBHC_CONTROL_READ,612 target.address, target.endpoint,613 buffer_size,614 &transfer->reply);615 616 rc = async_data_write_start(phone, setup_packet, setup_packet_size);617 if (rc != EOK) {618 async_wait_for(transfer->request, NULL);619 return rc;620 }621 622 *handle = (usb_handle_t) transfer;623 624 return EOK;625 }626 627 532 /** 628 533 * @}
Note:
See TracChangeset
for help on using the changeset viewer.