Changes in / [1b6e52f:2cea1045] in mainline


Ignore:
Location:
uspace
Files:
5 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/dump.c

    r1b6e52f r2cea1045  
    9696void dump_usb_descriptor(uint8_t *descriptor, size_t size)
    9797{
    98         printf("Device descriptor:\n");
    9998        usb_dump_standard_descriptor(stdout, get_indent(0), "\n",
    10099            descriptor, size);
  • uspace/app/usbinfo/info.c

    r1b6e52f r2cea1045  
    3838#include <errno.h>
    3939#include <usb/usbdrv.h>
    40 #include <usb/pipes.h>
    41 #include <usb/request.h>
    4240#include "usbinfo.h"
    4341
    44 int dump_device(devman_handle_t hc_handle, usb_address_t address)
     42int dump_device(int hc_phone, usb_address_t address)
    4543{
    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 
    5944        /*
    6045         * Dump information about possible match ids.
     
    6247        match_id_list_t match_id_list;
    6348        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);
    6550        if (rc != EOK) {
    6651                fprintf(stderr,
    6752                    NAME ": failed to fetch match ids of the device: %s.\n",
    6853                    str_error(rc));
    69                 goto leave;
     54                return rc;
    7055        }
    7156        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         }
    9757
    9858        /*
     
    10060         */
    10161        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);
    10368        if (rc != EOK) {
    10469                fprintf(stderr,
    10570                    NAME ": failed to fetch standard device descriptor: %s.\n",
    10671                    str_error(rc));
    107                 goto leave;
     72                return rc;
    10873        }
    10974        dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor));
     
    11479        usb_standard_configuration_descriptor_t config_descriptor;
    11580        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 );
    11887        if (rc != EOK) {
    11988                fprintf(stderr,
    12089                    NAME ": failed to fetch standard configuration descriptor: %s.\n",
    12190                    str_error(rc));
    122                 goto leave;
     91                return rc;
    12392        }
    12493        //dump_standard_configuration_descriptor(config_index, &config_descriptor);
    12594
    12695        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,
    128102            config_index,
    129103            full_config_descriptor, config_descriptor.total_length, NULL);
     
    132106                    NAME ": failed to fetch full configuration descriptor: %s.\n",
    133107                    str_error(rc));
    134                 goto leave;
     108                return rc;
    135109        }
    136110
     
    138112            config_descriptor.total_length);
    139113
    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;
    147115}
    148116
  • uspace/app/usbinfo/main.c

    r1b6e52f r2cea1045  
    7777}
    7878
    79 static int get_host_controller_handle(const char *path,
    80     devman_handle_t *hc_handle)
     79static int set_new_host_controller(int *phone, const char *path)
    8180{
    8281        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;
    93129
    94130        return EOK;
    95131}
    96132
    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)) {
     133static 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)) {
    101137                fprintf(stderr, NAME ": USB address out of range.\n");
    102138                return ERANGE;
    103139        }
    104140
    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);
    107147}
    108148
     
    110150int main(int argc, char *argv[])
    111151{
    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;
    114153
    115154        if (argc <= 1) {
     
    136175                        case 'a':
    137176                        case ACTION_DEVICE_ADDRESS: {
    138                                 int rc = get_device_address(optarg,
    139                                     &device_address);
     177                                int rc = connect_with_address(hc_phone, optarg);
    140178                                if (rc != EOK) {
    141179                                        return rc;
     
    146184                        case 't':
    147185                        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);
    150188                                if (rc != EOK) {
    151189                                        return rc;
     
    164202        } while (i != -1);
    165203
    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 
    174204        return 0;
    175205}
  • uspace/app/usbinfo/usbinfo.h

    r1b6e52f r2cea1045  
    4747void dump_match_ids(match_id_list_t *matches);
    4848void dump_usb_descriptor(uint8_t *, size_t);
    49 int dump_device(devman_handle_t, usb_address_t);
     49int dump_device(int, usb_address_t);
    5050void dump_descriptor_tree(uint8_t *, size_t);
    5151
  • uspace/drv/usbhid/descdump.h

    r1b6e52f r2cea1045  
    3737#define USBHID_DESCDUMP_H_
    3838
    39 #include "hid.h"
     39#include <usb/classes/hid.h>
    4040
    4141void dump_standard_configuration_descriptor(
  • uspace/drv/usbhid/descparser.h

    r1b6e52f r2cea1045  
    3737#define USBHID_DESCPARSER_H_
    3838
    39 #include "hid.h"
     39#include <usb/classes/hid.h>
    4040
    4141int usbkbd_parse_descriptors(const uint8_t *data, size_t size,
  • uspace/drv/usbhid/main.c

    r1b6e52f r2cea1045  
    4343#include <io/console.h>
    4444#include <errno.h>
    45 #include <str_error.h>
    4645#include <fibril.h>
    4746#include <usb/classes/hid.h>
    4847#include <usb/classes/hidparser.h>
    49 #include <usb/request.h>
     48#include <usb/devreq.h>
    5049#include <usb/descriptor.h>
    5150#include <io/console.h>
    52 #include "hid.h"
    5351#include "descparser.h"
    5452#include "descdump.h"
     
    280278               
    281279                // get the descriptor from the device
    282                 int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe,
    283                     USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
    284                     i, 0,
    285                     kbd_dev->conf->interfaces[i].report_desc, length,
     280                int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
     281                    kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
     282                    0, i, kbd_dev->conf->interfaces[i].report_desc, length,
    286283                    &actual_size);
    287284
     
    304301        usb_standard_configuration_descriptor_t config_desc;
    305302       
    306         int rc;
    307         rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe,
    308             0, &config_desc);
     303        int rc = usb_drv_req_get_bare_configuration_descriptor(
     304            kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
    309305       
    310306        if (rc != EOK) {
     
    320316        size_t transferred = 0;
    321317        // get full configuration descriptor
    322         rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe,
    323             0, descriptors,
     318        rc = usb_drv_req_get_full_configuration_descriptor(
     319            kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
    324320            config_desc.total_length, &transferred);
    325321       
     
    368364static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    369365{
    370         int rc;
    371 
    372366        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    373367            sizeof(usb_hid_dev_kbd_t));
     
    380374        kbd_dev->device = dev;
    381375
    382         /*
    383          * Initialize the backing connection to the host controller.
    384          */
    385         rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);
    386         if (rc != EOK) {
    387                 printf("Problem initializing connection to device: %s.\n",
    388                     str_error(rc));
    389                 goto error_leave;
    390         }
    391 
    392         /*
    393          * Initialize device pipes.
    394          */
    395         rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe,
    396             &kbd_dev->wire);
    397         if (rc != EOK) {
    398                 printf("Failed to initialize default control pipe: %s.\n",
    399                     str_error(rc));
    400                 goto error_leave;
    401         }
    402 
    403         rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,
    404             GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
    405         if (rc != EOK) {
    406                 printf("Failed to initialize interrupt in pipe: %s.\n",
    407                     str_error(rc));
    408                 goto error_leave;
    409         }
    410 
     376        // get phone to my HC and save it as my parent's phone
     377        // TODO: maybe not a good idea if DDF will use parent_phone
     378        int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
     379        if (rc < 0) {
     380                printf("Problem setting phone to HC.\n");
     381                free(kbd_dev);
     382                return NULL;
     383        }
     384
     385        rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
     386        if (rc < 0) {
     387                printf("Problem getting address of the device.\n");
     388                free(kbd_dev);
     389                return NULL;
     390        }
     391
     392        // doesn't matter now that we have no address
     393//      if (kbd_dev->address < 0) {
     394//              fprintf(stderr, NAME ": No device address!\n");
     395//              free(kbd_dev);
     396//              return NULL;
     397//      }
     398
     399        // default endpoint
     400        kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
     401       
    411402        /*
    412403         * will need all descriptors:
    413          * 1) choose one configuration from configuration descriptors
     404         * 1) choose one configuration from configuration descriptors 
    414405         *    (set it to the device)
    415406         * 2) set endpoints from endpoint descriptors
     
    417408
    418409        // TODO: get descriptors, parse descriptors and save endpoints
    419         usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    420410        usbkbd_process_descriptors(kbd_dev);
    421         usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    422411
    423412        return kbd_dev;
    424 
    425 error_leave:
    426         free(kbd_dev);
    427         return NULL;
    428413}
    429414
     
    450435static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    451436{
    452         int rc, sess_rc;
     437        int rc;
     438        usb_handle_t handle;
    453439        uint8_t buffer[BUFFER_SIZE];
    454440        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        };
    455453
    456454        printf("Polling keyboard...\n");
     
    458456        while (true) {
    459457                async_usleep(1000 * 1000 * 2);
    460 
    461                 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
    462                 if (sess_rc != EOK) {
    463                         printf("Failed to start a session: %s.\n",
    464                             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);
    465463                        continue;
    466464                }
    467465
    468                 rc = usb_endpoint_pipe_read(&kbd_dev->poll_pipe, buffer,
    469                     BUFFER_SIZE, &actual_size);
    470                 sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->poll_pipe);
    471 
     466                rc = usb_drv_async_wait_for(handle);
    472467                if (rc != EOK) {
    473                         printf("Error polling the keyboard: %s.\n",
    474                             str_error(rc));
    475                         continue;
    476                 }
    477 
    478                 if (sess_rc != EOK) {
    479                         printf("Error closing session: %s.\n",
    480                             str_error(sess_rc));
     468                        printf("Error in usb_drv_async_wait_for(): %d\n", rc);
    481469                        continue;
    482470                }
  • uspace/drv/vhc/connhost.c

    r1b6e52f r2cea1045  
    4242#include "hc.h"
    4343
    44 
    4544typedef struct {
    4645        usb_direction_t direction;
     
    4847        usbhc_iface_transfer_in_callback_t in_callback;
    4948        device_t *dev;
    50         size_t reported_size;
    5149        void *arg;
    5250} transfer_info_t;
    5351
    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 
    6552static void universal_callback(void *buffer, size_t size,
    6653    usb_transaction_outcome_t outcome, void *arg)
    6754{
    6855        transfer_info_t *transfer = (transfer_info_t *) arg;
    69 
    70         if (transfer->reported_size != (size_t) -1) {
    71                 size = transfer->reported_size;
    72         }
    7356
    7457        switch (transfer->direction) {
     
    10184        transfer->arg = arg;
    10285        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 *transfer
    202             = 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;
    21286
    21387        return transfer;
     
    319193}
    320194
    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 *transfer
    327             = 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 
    338195static int control_read_setup(device_t *dev, usb_target_t target,
    339196    void *data, size_t size,
     
    360217            NULL, 0,
    361218            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 *transfer
    370             = 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;
    379219}
    380220
     
    450290        .control_write_status = control_write_status,
    451291
    452         .control_write = control_write,
    453 
    454292        .control_read_setup = control_read_setup,
    455293        .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
    459295};
    460296
  • uspace/lib/drv/generic/remote_usbhc.c

    r1b6e52f r2cea1045  
    11/*
    2  * Copyright (c) 2010-2011 Vojtech Horky
     2 * Copyright (c) 2010 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    5252static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5353static 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 *);
    5654static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5755static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    8381        remote_usbhc_control_read_setup,
    8482        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
    8984};
    9085
     
    10095        ipc_callid_t caller;
    10196        void *buffer;
    102         void *setup_packet;
    10397        size_t size;
    10498} async_transaction_t;
     
    303297        trans->caller = callid;
    304298        trans->buffer = buffer;
    305         trans->setup_packet = NULL;
    306299        trans->size = len;
    307300
     
    343336        trans->caller = callid;
    344337        trans->buffer = malloc(len);
    345         trans->setup_packet = NULL;
    346338        trans->size = len;
    347339
     
    399391        trans->caller = callid;
    400392        trans->buffer = NULL;
    401         trans->setup_packet = NULL;
    402393        trans->size = 0;
    403394
     
    505496}
    506497
    507 void remote_usbhc_control_write(device_t *device, void *iface,
    508 ipc_callid_t callid, ipc_call_t *call)
    509 {
    510         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    511         assert(usb_iface != NULL);
    512 
    513         if (!usb_iface->control_write) {
    514                 ipc_answer_0(callid, ENOTSUP);
    515                 return;
    516         }
    517 
    518         usb_target_t target = {
    519                 .address = DEV_IPC_GET_ARG1(*call),
    520                 .endpoint = DEV_IPC_GET_ARG2(*call)
    521         };
    522 
    523         int rc;
    524 
    525         void *setup_packet = NULL;
    526         void *data_buffer = NULL;
    527         size_t setup_packet_len = 0;
    528         size_t data_buffer_len = 0;
    529 
    530         rc = async_data_write_accept(&setup_packet, false,
    531             1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    532         if (rc != EOK) {
    533                 ipc_answer_0(callid, rc);
    534                 return;
    535         }
    536         rc = async_data_write_accept(&data_buffer, false,
    537             1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
    538         if (rc != EOK) {
    539                 free(setup_packet);
    540                 ipc_answer_0(callid, rc);
    541                 return;
    542         }
    543 
    544         async_transaction_t *trans = malloc(sizeof(async_transaction_t));
    545         trans->caller = callid;
    546         trans->setup_packet = setup_packet;
    547         trans->buffer = data_buffer;
    548         trans->size = data_buffer_len;
    549 
    550         rc = usb_iface->control_write(device, target,
    551             setup_packet, setup_packet_len,
    552             data_buffer, data_buffer_len,
    553             callback_out, trans);
    554 
    555         if (rc != EOK) {
    556                 ipc_answer_0(callid, rc);
    557                 free(setup_packet);
    558                 free(data_buffer);
    559                 free(trans);
    560         }
    561 }
    562 
    563 
    564 void remote_usbhc_control_read(device_t *device, void *iface,
    565 ipc_callid_t callid, ipc_call_t *call)
    566 {
    567         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    568         assert(usb_iface != NULL);
    569 
    570         if (!usb_iface->control_read) {
    571                 ipc_answer_0(callid, ENOTSUP);
    572                 return;
    573         }
    574 
    575         size_t data_len = DEV_IPC_GET_ARG3(*call);
    576         usb_target_t target = {
    577                 .address = DEV_IPC_GET_ARG1(*call),
    578                 .endpoint = DEV_IPC_GET_ARG2(*call)
    579         };
    580 
    581         int rc;
    582 
    583         void *setup_packet = NULL;
    584         size_t setup_packet_len = 0;
    585 
    586         rc = async_data_write_accept(&setup_packet, false,
    587             1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    588         if (rc != EOK) {
    589                 ipc_answer_0(callid, rc);
    590                 return;
    591         }
    592 
    593         async_transaction_t *trans = malloc(sizeof(async_transaction_t));
    594         trans->caller = callid;
    595         trans->setup_packet = setup_packet;
    596         trans->buffer = malloc(data_len);
    597         trans->size = data_len;
    598 
    599         rc = usb_iface->control_read(device, target,
    600             setup_packet, setup_packet_len,
    601             trans->buffer, trans->size,
    602             callback_in, trans);
    603 
    604         if (rc != EOK) {
    605                 ipc_answer_0(callid, rc);
    606                 free(setup_packet);
    607                 free(trans->buffer);
    608                 free(trans);
    609         }
    610 }
    611 
    612498
    613499
  • uspace/lib/drv/include/usbhc_iface.h

    r1b6e52f r2cea1045  
    201201        IPC_M_USBHC_CONTROL_READ_STATUS,
    202202
    203         /** Issue control WRITE transfer.
    204          * See explanation at usb_iface_funcs_t (OUT transaction) for
    205          * call parameters.
    206          * This call is immediately followed by two IPC data writes
    207          * 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) for
    213          * call parameters.
    214          * This call is immediately followed by IPC data read from the caller
    215          * (setup packet).
    216          * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER.
    217          */
    218         IPC_M_USBHC_CONTROL_READ,
    219203
    220204        /* IPC_M_USB_ */
     
    265249        int (*control_read_status)(device_t *, usb_target_t,
    266250            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 *);
    275251} usbhc_iface_t;
    276252
  • uspace/lib/usb/Makefile

    r1b6e52f r2cea1045  
    4343        src/hidparser.c \
    4444        src/localdrv.c \
    45         src/pipes.c \
    4645        src/recognise.c \
    4746        src/remotedrv.c \
    48         src/request.c \
    4947        src/usb.c \
    5048        src/usbdrvreq.c \
  • uspace/lib/usb/include/usb/classes/hid.h

    r1b6e52f r2cea1045  
    3737
    3838#include <usb/usb.h>
     39#include <driver.h>
    3940#include <usb/classes/hidparser.h>
    4041#include <usb/descriptor.h>
     
    100101} __attribute__ ((packed)) usb_standard_hid_descriptor_t;
    101102
     103/**
     104 *
     105 */
     106typedef 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 */
     118typedef 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 */
     128typedef 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!
    102137
    103138#endif
  • uspace/lib/usb/include/usb/usb.h

    r1b6e52f r2cea1045  
    6666typedef enum {
    6767        USB_DIRECTION_IN,
    68         USB_DIRECTION_OUT,
    69         USB_DIRECTION_BOTH
     68        USB_DIRECTION_OUT
    7069} usb_direction_t;
    7170
  • uspace/lib/usb/include/usb/usbdrv.h

    r1b6e52f r2cea1045  
    7070    usb_handle_t *);
    7171
    72 int usb_drv_async_control_write(int, usb_target_t,
    73     void *, size_t, void *, size_t, usb_handle_t *);
    74 
    7572int usb_drv_psync_control_write_setup(int, usb_target_t, void *, size_t);
    7673int usb_drv_psync_control_write_data(int, usb_target_t, void *, size_t);
     
    8077    void *, size_t, void *, size_t);
    8178
     79
    8280int usb_drv_async_control_read_setup(int, usb_target_t,
    8381    void *, size_t, usb_handle_t *);
     
    8684int usb_drv_async_control_read_status(int, usb_target_t,
    8785    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 *);
    9186
    9287int usb_drv_psync_control_read_setup(int, usb_target_t, void *, size_t);
  • uspace/lib/usb/src/usbdrv.c

    r1b6e52f r2cea1045  
    495495}
    496496
    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 them
    504         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 *transfer
    512             = (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 
    547497/** Start control read transfer. */
    548498int usb_drv_async_control_read_setup(int phone, usb_target_t target,
     
    580530}
    581531
    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 them
    589         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 *transfer
    597             = (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 
    627532/**
    628533 * @}
Note: See TracChangeset for help on using the changeset viewer.