Changeset b4b534ac in mainline for uspace/app


Ignore:
Timestamp:
2016-07-22T08:24:47Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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.
Message:

Merge from lp:~jan.vesely/helenos/usb

Location:
uspace/app
Files:
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    r5b18137 rb4b534ac  
    3030#include <stdio.h>
    3131#include <stdlib.h>
     32#include <str_error.h>
    3233#include <vfs/vfs.h>
    3334#include <adt/list.h>
     
    152153        rc = vfs_mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
    153154        if (rc != EOK) {
    154                 printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n",
    155                     t_argv[1], t_argv[2], t_argv[3], rc);
     155                printf("Unable to mount %s filesystem to %s on %s (rc=%s)\n",
     156                    t_argv[1], t_argv[2], t_argv[3], str_error(rc));
    156157                return CMD_FAILURE;
    157158        }
  • uspace/app/mkbd/main.c

    r5b18137 rb4b534ac  
    4444#include <devman.h>
    4545#include <loc.h>
    46 #include <usb/dev/hub.h>
    4746#include <usbhid_iface.h>
    4847#include <usb/dev/pipes.h>
     
    219218        devman_handle_t dev_handle = 0;
    220219       
    221         int rc = usb_resolve_device_handle(devpath, NULL, NULL, &dev_handle);
     220        int rc = usb_resolve_device_handle(devpath, &dev_handle);
    222221        if (rc != EOK) {
    223222                printf("Device not found or not of USB kind: %s.\n",
  • uspace/app/usbinfo/Makefile

    r5b18137 rb4b534ac  
    4343SOURCES = \
    4444        desctree.c \
    45         dev.c \
    4645        dump.c \
    4746        hid.c \
  • uspace/app/usbinfo/hid.c

    r5b18137 rb4b534ac  
    3636#include <stdio.h>
    3737#include <str_error.h>
     38#include <usb/debug.h>
    3839#include <usb/classes/classes.h>
    3940#include <usb/dev/request.h>
     
    5051
    5152typedef struct {
    52         usbinfo_device_t *dev;
     53        usb_device_t *usb_dev;
    5354        hid_dump_type_t dump_type;
    5455        usb_standard_interface_descriptor_t *last_iface;
     
    211212
    212213        retrieve_and_dump_hid_report(context->dump_type,
    213             &context->dev->ctrl_pipe, context->last_iface->interface_number,
    214             report_size);
    215 }
    216 
    217 
    218 void dump_hidreport_raw(usbinfo_device_t *dev)
     214            usb_device_get_default_pipe(context->usb_dev),
     215            context->last_iface->interface_number, report_size);
     216}
     217
     218
     219void dump_hidreport_raw(usb_device_t *usb_dev)
    219220{
    220221        descriptor_walk_context_t context = {
    221                 .dev = dev,
     222                .usb_dev = usb_dev,
    222223                .dump_type = HID_DUMP_RAW,
    223224                .last_iface = NULL
    224225        };
    225226
    226         usb_dp_walk_simple(dev->full_configuration_descriptor,
    227             dev->full_configuration_descriptor_size,
     227        usb_dp_walk_simple(
     228            usb_device_descriptors(usb_dev)->full_config,
     229            usb_device_descriptors(usb_dev)->full_config_size,
    228230            usb_dp_standard_descriptor_nesting,
    229231            descriptor_walk_callback, &context);
    230232}
    231233
    232 void dump_hidreport_usages(usbinfo_device_t *dev)
     234void dump_hidreport_usages(usb_device_t *usb_dev)
    233235{
    234236        descriptor_walk_context_t context = {
    235                 .dev = dev,
     237                .usb_dev = usb_dev,
    236238                .dump_type = HID_DUMP_USAGES,
    237239                .last_iface = NULL
    238240        };
    239241
    240         usb_dp_walk_simple(dev->full_configuration_descriptor,
    241             dev->full_configuration_descriptor_size,
     242        usb_dp_walk_simple(
     243            usb_device_descriptors(usb_dev)->full_config,
     244            usb_device_descriptors(usb_dev)->full_config_size,
    242245            usb_dp_standard_descriptor_nesting,
    243246            descriptor_walk_callback, &context);
  • uspace/app/usbinfo/info.c

    r5b18137 rb4b534ac  
    3737#include <str_error.h>
    3838#include <errno.h>
     39#include <usb/debug.h>
    3940#include <usb/dev/pipes.h>
    4041#include <usb/dev/recognise.h>
     
    4445#include "usbinfo.h"
    4546
    46 void dump_short_device_identification(usbinfo_device_t *dev)
     47void dump_short_device_identification(usb_device_t *usb_dev)
    4748{
    4849        printf("%sDevice 0x%04x by vendor 0x%04x\n", get_indent(0),
    49             (int) dev->device_descriptor.product_id,
    50             (int) dev->device_descriptor.vendor_id);
     50            usb_device_descriptors(usb_dev)->device.product_id,
     51            usb_device_descriptors(usb_dev)->device.vendor_id);
    5152}
    5253
     
    6667        }
    6768
    68         usbinfo_device_t *dev = (usbinfo_device_t *) arg;
     69        usb_device_t *usb_dev = arg;
     70        assert(usb_dev);
    6971
    7072        usb_standard_interface_descriptor_t *iface
     
    8082        match_id_list_t matches;
    8183        init_match_ids(&matches);
    82         usb_device_create_match_ids_from_interface(&dev->device_descriptor,
    83             iface, &matches);
     84        usb_device_create_match_ids_from_interface(
     85            &usb_device_descriptors(usb_dev)->device, iface, &matches);
    8486        dump_match_ids(&matches, get_indent(1));
    8587        clean_match_ids(&matches);
    8688}
    8789
    88 void dump_device_match_ids(usbinfo_device_t *dev)
     90void dump_device_match_ids(usb_device_t *usb_dev)
    8991{
    9092        match_id_list_t matches;
    9193        init_match_ids(&matches);
    9294        usb_device_create_match_ids_from_device_descriptor(
    93             &dev->device_descriptor, &matches);
     95                &usb_device_descriptors(usb_dev)->device, &matches);
    9496        printf("%sDevice match ids (0x%04x by 0x%04x, %s)\n", get_indent(0),
    95             (int) dev->device_descriptor.product_id,
    96             (int) dev->device_descriptor.vendor_id,
    97             usb_str_class(dev->device_descriptor.device_class));
     97            usb_device_descriptors(usb_dev)->device.product_id,
     98            usb_device_descriptors(usb_dev)->device.vendor_id,
     99            usb_str_class(usb_device_descriptors(usb_dev)->device.device_class));
    98100        dump_match_ids(&matches, get_indent(1));
    99101        clean_match_ids(&matches);
    100102
    101         usb_dp_walk_simple(dev->full_configuration_descriptor,
    102             dev->full_configuration_descriptor_size,
     103        usb_dp_walk_simple(
     104            usb_device_descriptors(usb_dev)->full_config,
     105            usb_device_descriptors(usb_dev)->full_config_size,
    103106            usb_dp_standard_descriptor_nesting,
    104             dump_match_ids_from_interface,
    105             dev);
     107            dump_match_ids_from_interface, usb_dev);
    106108}
    107109
     
    224226}
    225227
    226 void dump_descriptor_tree_brief(usbinfo_device_t *dev)
    227 {
    228         dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
     228void dump_descriptor_tree_brief(usb_device_t *usb_dev)
     229{
     230        dump_descriptor_tree_callback(
     231            (const uint8_t *)&usb_device_descriptors(usb_dev)->device,
    229232            (size_t) -1, NULL);
    230         usb_dp_walk_simple(dev->full_configuration_descriptor,
    231             dev->full_configuration_descriptor_size,
     233
     234        usb_dp_walk_simple(
     235            usb_device_descriptors(usb_dev)->full_config,
     236            usb_device_descriptors(usb_dev)->full_config_size,
    232237            usb_dp_standard_descriptor_nesting,
    233             dump_descriptor_tree_callback,
    234             NULL);
    235 }
    236 
    237 void dump_descriptor_tree_full(usbinfo_device_t *dev)
    238 {
    239         dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
    240             (size_t) -1, dev);
    241         usb_dp_walk_simple(dev->full_configuration_descriptor,
    242             dev->full_configuration_descriptor_size,
     238            dump_descriptor_tree_callback, NULL);
     239}
     240
     241void dump_descriptor_tree_full(usb_device_t *usb_dev)
     242{
     243        dump_descriptor_tree_callback(
     244            (const uint8_t *)&usb_device_descriptors(usb_dev)->device,
     245            (size_t) -1, usb_dev);
     246
     247        usb_dp_walk_simple(
     248            usb_device_descriptors(usb_dev)->full_config,
     249            usb_device_descriptors(usb_dev)->full_config_size,
    243250            usb_dp_standard_descriptor_nesting,
    244             dump_descriptor_tree_callback,
    245             dev);
     251            dump_descriptor_tree_callback, usb_dev);
    246252}
    247253
     
    285291
    286292
    287 void dump_strings(usbinfo_device_t *dev)
     293void dump_strings(usb_device_t *usb_dev)
    288294{
    289295        /* Find used indexes. Devices with more than 64 strings are very rare.*/
    290296        uint64_t str_mask = 0;
    291         find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0,
     297        find_string_indexes_callback(
     298            (const uint8_t *)&usb_device_descriptors(usb_dev)->device, 0,
    292299            &str_mask);
    293         usb_dp_walk_simple(dev->full_configuration_descriptor,
    294             dev->full_configuration_descriptor_size,
     300
     301        usb_dp_walk_simple(
     302            usb_device_descriptors(usb_dev)->full_config,
     303            usb_device_descriptors(usb_dev)->full_config_size,
    295304            usb_dp_standard_descriptor_nesting,
    296             find_string_indexes_callback,
    297             &str_mask);
     305            find_string_indexes_callback, &str_mask);
    298306
    299307        if (str_mask == 0) {
     
    305313        l18_win_locales_t *langs;
    306314        size_t langs_count;
    307         int rc = usb_request_get_supported_languages(&dev->ctrl_pipe,
    308             &langs, &langs_count);
     315        int rc = usb_request_get_supported_languages(
     316            usb_device_get_default_pipe(usb_dev), &langs, &langs_count);
    309317        if (rc != EOK) {
    310318                fprintf(stderr,
     
    334342                        }
    335343                        char *string = NULL;
    336                         rc = usb_request_get_string(&dev->ctrl_pipe, idx, lang,
     344                        rc = usb_request_get_string(
     345                            usb_device_get_default_pipe(usb_dev), idx, lang,
    337346                            &string);
    338347                        if ((rc != EOK) && (rc != EEMPTY)) {
     
    351360
    352361
    353 void dump_status(usbinfo_device_t *dev)
     362void dump_status(usb_device_t *usb_dev)
    354363{
    355364        int rc;
    356         uint16_t device_status = 0;
    357         uint16_t ctrl_pipe_status = 0;
     365        uint16_t status = 0;
    358366
    359367        /* Device status first. */
    360         rc = usb_request_get_status(&dev->ctrl_pipe,
    361             USB_REQUEST_RECIPIENT_DEVICE, 0,
    362             &device_status);
     368        rc = usb_request_get_status(usb_device_get_default_pipe(usb_dev),
     369            USB_REQUEST_RECIPIENT_DEVICE, 0, &status);
    363370        if (rc != EOK) {
    364371                printf("%sFailed to get device status: %s.\n",
    365372                    get_indent(0), str_error(rc));
    366                 goto try_ctrl_pipe_status;
    367         }
    368 
    369         printf("%sDevice status 0x%04x: power=%s, remote-wakeup=%s.\n",
    370             get_indent(0),
    371             device_status,
    372             device_status & USB_DEVICE_STATUS_SELF_POWERED ? "self" : "bus",
    373             device_status & USB_DEVICE_STATUS_REMOTE_WAKEUP ? "yes" : "no");
     373        } else {
     374                printf("%sDevice status 0x%04x: power=%s, remote-wakeup=%s.\n",
     375                    get_indent(0), status,
     376                    status & USB_DEVICE_STATUS_SELF_POWERED ? "self" : "bus",
     377                    status & USB_DEVICE_STATUS_REMOTE_WAKEUP ? "yes" : "no");
     378        }
    374379
    375380        /* Interface is not interesting, skipping ;-). */
    376381
    377382        /* Control endpoint zero. */
    378 try_ctrl_pipe_status:
    379         rc = usb_request_get_status(&dev->ctrl_pipe,
    380             USB_REQUEST_RECIPIENT_ENDPOINT, 0,
    381             &ctrl_pipe_status);
     383        status = 0;
     384        rc = usb_request_get_status(usb_device_get_default_pipe(usb_dev),
     385            USB_REQUEST_RECIPIENT_ENDPOINT, 0, &status);
    382386        if (rc != EOK) {
    383387                printf("%sFailed to get control endpoint status: %s.\n",
    384388                    get_indent(0), str_error(rc));
    385                 goto leave;
    386         }
    387 
    388         printf("%sControl endpoint zero status %04X: halted=%s.\n",
    389             get_indent(0),
    390             ctrl_pipe_status,
    391             ctrl_pipe_status & USB_ENDPOINT_STATUS_HALTED ? "yes" : "no");
    392 
    393 leave:
    394         return;
     389        } else {
     390                printf("%sControl endpoint zero status %04X: halted=%s.\n",
     391                    get_indent(0), status,
     392                    status & USB_ENDPOINT_STATUS_HALTED ? "yes" : "no");
     393        }
    395394}
    396395
  • uspace/app/usbinfo/list.c

    r5b18137 rb4b534ac  
    4444#include <devman.h>
    4545#include <loc.h>
    46 #include <usb/dev/hub.h>
    47 #include <usb/hc.h>
     46#include <usb_iface.h>
    4847
    4948#include "usbinfo.h"
    5049
    51 #define MAX_USB_ADDRESS USB11_ADDRESS_MAX
    5250#define MAX_PATH_LENGTH 1024
    5351
    54 static void print_found_hc(service_id_t sid, const char *path)
     52static void print_usb_device(devman_handle_t handle)
    5553{
    56         printf("Bus %" PRIun ": %s\n", sid, path);
    57 }
    58 static void print_found_dev(usb_address_t addr, const char *path)
    59 {
    60         printf("  Device %02d: %s\n", addr, path);
     54        char path[MAX_PATH_LENGTH];
     55        int rc = devman_fun_get_path(handle, path, MAX_PATH_LENGTH);
     56        if (rc != EOK) {
     57                printf(NAME "Failed to get path for device %"PRIun"\n", handle);
     58                return;
     59        }
     60        printf("\tDevice %" PRIun ": %s\n", handle, path);
    6161}
    6262
    63 static void print_hc_devices(devman_handle_t hc_handle)
     63static void print_usb_bus(service_id_t svc)
    6464{
    65         int rc;
    66         usb_hc_connection_t conn;
    67 
    68         usb_hc_connection_initialize(&conn, hc_handle);
    69         rc = usb_hc_connection_open(&conn);
     65        devman_handle_t hc_handle = 0;
     66        int rc = devman_fun_sid_to_handle(svc, &hc_handle);
    7067        if (rc != EOK) {
    71                 printf(NAME ": failed to connect to HC: %s.\n",
    72                     str_error(rc));
     68                printf(NAME ": Error resolving handle of HC with SID %"
     69                    PRIun ", skipping.\n", svc);
    7370                return;
    7471        }
    75         usb_address_t addr;
    76         for (addr = 1; addr < MAX_USB_ADDRESS; addr++) {
    77                 devman_handle_t dev_handle;
    78                 rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
    79                 if (rc != EOK) {
    80                         continue;
    81                 }
    82                 char path[MAX_PATH_LENGTH];
    83                 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
    84                 if (rc != EOK) {
    85                         continue;
    86                 }
    87                 print_found_dev(addr, path);
     72
     73        char path[MAX_PATH_LENGTH];
     74        rc = devman_fun_get_path(hc_handle, path, sizeof(path));
     75        if (rc != EOK) {
     76                printf(NAME ": Error resolving path of HC with SID %"
     77                    PRIun ", skipping.\n", svc);
     78                return;
    8879        }
    89         usb_hc_connection_close(&conn);
     80        printf("Bus %" PRIun ": %s\n", svc, path);
     81
     82        /* Construct device's path.
     83         * That's "hc function path" - ( '/' + "hc function name" ) */
     84        // TODO replace this with something sane
     85
     86        /* Get function name */
     87        char name[10];
     88        rc = devman_fun_get_name(hc_handle, name, sizeof(name));
     89        if (rc != EOK) {
     90                printf(NAME ": Error resolving name of HC with SID %"
     91                    PRIun ", skipping.\n", svc);
     92                return;
     93        }
     94
     95        /* Get handle of parent device */
     96        devman_handle_t fh;
     97        path[str_size(path) - str_size(name) - 1] = '\0';
     98        rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
     99        if (rc != EOK) {
     100                printf(NAME ": Error resolving parent handle of HC with"
     101                    " SID %" PRIun ", skipping.\n", svc);
     102                return;
     103        }
     104
     105        /* Get child handle */
     106        devman_handle_t dh;
     107        rc = devman_fun_get_child(fh, &dh);
     108        if (rc != EOK) {
     109                printf(NAME ": Error resolving parent handle of HC with"
     110                    " SID %" PRIun ", skipping.\n", svc);
     111                return;
     112        }
     113       
     114        devman_handle_t *fhs = 0;
     115        size_t count;
     116        rc = devman_dev_get_functions(dh, &fhs, &count);
     117        if (rc != EOK) {
     118                printf(NAME ": Error siblings of HC with"
     119                    " SID %" PRIun ", skipping.\n", svc);
     120                return;
     121        }
     122
     123        for (size_t i = 0; i < count; ++i) {
     124                if (fhs[i] != hc_handle)
     125                        print_usb_device(fhs[i]);
     126        }
     127        free(fhs);
    90128}
    91129
     
    95133        service_id_t *svcs;
    96134        size_t count;
    97         size_t i;
    98135        int rc;
    99136
     
    111148        }
    112149
    113         for (i = 0; i < count; i++) {
    114                 devman_handle_t hc_handle = 0;
    115                 int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
    116                 if (rc != EOK) {
    117                         printf(NAME ": Error resolving handle of HC with SID %"
    118                             PRIun ", skipping.\n", svcs[i]);
    119                         continue;
    120                 }
    121                 char path[MAX_PATH_LENGTH];
    122                 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
    123                 if (rc != EOK) {
    124                         printf(NAME ": Error resolving path of HC with SID %"
    125                             PRIun ", skipping.\n", svcs[i]);
    126                         continue;
    127                 }
    128                 print_found_hc(svcs[i], path);
    129                 print_hc_devices(hc_handle);
     150        for (unsigned i = 0; i < count; ++i) {
     151                print_usb_bus(svcs[i]);
    130152        }
    131153
  • uspace/app/usbinfo/main.c

    r5b18137 rb4b534ac  
    4343#include <devman.h>
    4444#include <loc.h>
    45 #include <usb/hc.h>
    4645#include <usb/dev.h>
    4746#include <usb/dev/pipes.h>
     
    198197
    199198                /* The initialization is here only to make compiler happy. */
    200                 devman_handle_t hc_handle = 0;
    201                 usb_address_t dev_addr = 0;
    202                 int rc = usb_resolve_device_handle(devpath,
    203                     &hc_handle, &dev_addr, NULL);
     199                devman_handle_t handle = 0;
     200                int rc = usb_resolve_device_handle(devpath, &handle);
    204201                if (rc != EOK) {
    205202                        fprintf(stderr, NAME ": device `%s' not found "
     
    209206                }
    210207
    211                 usbinfo_device_t *dev = prepare_device(devpath,
    212                     hc_handle, dev_addr);
    213                 if (dev == NULL) {
     208                usb_device_t *usb_dev = usb_device_create(handle);
     209
     210                if (usb_dev == NULL) {
     211                        fprintf(stderr, NAME ": device `%s' not found "
     212                            "or not of USB kind, skipping.\n",
     213                            devpath);
    214214                        continue;
    215215                }
     
    221221                while (actions[action].opt != 0) {
    222222                        if (actions[action].active) {
    223                                 actions[action].action(dev);
     223                                actions[action].action(usb_dev);
    224224                        }
    225225                        action++;
    226226                }
    227227
    228                 /* Destroy the control pipe (close the session etc.). */
    229                 destroy_device(dev);
     228                usb_device_destroy(usb_dev);
    230229        }
    231230
  • uspace/app/usbinfo/usbinfo.h

    r5b18137 rb4b534ac  
    3838#include <usb/usb.h>
    3939#include <usb/descriptor.h>
    40 #include <usb/dev/pipes.h>
    41 #include <usb/debug.h>
     40#include <usb/dev/device.h>
    4241#include <usb/dev/dp.h>
    4342#include <ipc/devman.h>
    4443
    4544typedef struct {
    46         usb_hc_connection_t hc_conn;
    47         usb_device_connection_t wire;
    48         usb_pipe_t ctrl_pipe;
    49         usb_standard_device_descriptor_t device_descriptor;
    50         uint8_t *full_configuration_descriptor;
    51         size_t full_configuration_descriptor_size;
    52 } usbinfo_device_t;
    53 
    54 typedef struct {
    5545        int opt;
    56         void (*action)(usbinfo_device_t *dev);
     46        void (*action)(usb_device_t *usb_dev);
    5747        bool active;
    5848} usbinfo_action_t;
     
    7262}
    7363
    74 usbinfo_device_t *prepare_device(const char *, devman_handle_t, usb_address_t);
    75 void destroy_device(usbinfo_device_t *);
    76 
    7764typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *);
    7865void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
     
    8168void list(void);
    8269
    83 void dump_short_device_identification(usbinfo_device_t *);
    84 void dump_device_match_ids(usbinfo_device_t *);
    85 void dump_descriptor_tree_brief(usbinfo_device_t *);
    86 void dump_descriptor_tree_full(usbinfo_device_t *);
    87 void dump_strings(usbinfo_device_t *);
    88 void dump_status(usbinfo_device_t *);
    89 void dump_hidreport_raw(usbinfo_device_t *);
    90 void dump_hidreport_usages(usbinfo_device_t *);
    91 
     70void dump_short_device_identification(usb_device_t *);
     71void dump_device_match_ids(usb_device_t *);
     72void dump_descriptor_tree_brief(usb_device_t *);
     73void dump_descriptor_tree_full(usb_device_t *);
     74void dump_strings(usb_device_t *);
     75void dump_status(usb_device_t *);
     76void dump_hidreport_raw(usb_device_t *);
     77void dump_hidreport_usages(usb_device_t *);
    9278
    9379#endif
  • uspace/app/vuhid/device.c

    r5b18137 rb4b534ac  
    6060static int on_data_to_device(usbvirt_device_t *dev,
    6161    usb_endpoint_t ep, usb_transfer_type_t tr_type,
    62     void *data, size_t data_size)
     62    const void *data, size_t data_size)
    6363{
    6464        vuhid_data_t *vuhid = dev->device_data;
     
    254254
    255255        /* Extend existing extra descriptors with these ones. */
    256         usbvirt_device_configuration_extras_t *extra_descriptors
    257             = dev->descriptors->configuration->extra;
    258         extra_descriptors = realloc(extra_descriptors,
     256        usbvirt_device_configuration_extras_t *extra_descriptors;
     257        extra_descriptors = realloc(dev->descriptors->configuration->extra,
    259258            sizeof(usbvirt_device_configuration_extras_t)
    260259            * (dev->descriptors->configuration->extra_count + descr_count));
  • uspace/app/vuhid/hids/bootkbd.c

    r5b18137 rb4b534ac  
    102102
    103103static int on_data_out(vuhid_interface_t *iface,
    104     void *buffer, size_t buffer_size)
     104    const void *buffer, size_t buffer_size)
    105105{
    106106        if (buffer_size == 0) {
  • uspace/app/vuhid/main.c

    r5b18137 rb4b534ac  
    4040#include <errno.h>
    4141#include <str_error.h>
     42#include <getopt.h>
    4243
    4344#include <usb/usb.h>
     
    5253#include "stdreq.h"
    5354
     55#define DEFAULT_CONTROLLER   "/virt/usbhc/virtual"
     56
    5457static usbvirt_control_request_handler_t endpoint_zero_handlers[] = {
    5558        {
    56                 .req_direction = USB_DIRECTION_IN,
    57                 .req_type = USB_REQUEST_TYPE_STANDARD,
    58                 .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE,
    59                 .request = USB_DEVREQ_GET_DESCRIPTOR,
     59                STD_REQ_IN(USB_REQUEST_RECIPIENT_INTERFACE, USB_DEVREQ_GET_DESCRIPTOR),
    6060                .name = "Get_Descriptor",
    6161                .callback = req_get_descriptor
    6262        },
    6363        {
    64                 .req_direction = USB_DIRECTION_OUT,
    65                 .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE,
    66                 .req_type = USB_REQUEST_TYPE_CLASS,
    67                 .request = USB_HIDREQ_SET_PROTOCOL,
     64                CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_PROTOCOL),
    6865                .name = "Set_Protocol",
    6966                .callback = req_set_protocol
    7067        },
    7168        {
    72                 .req_direction = USB_DIRECTION_OUT,
    73                 .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE,
    74                 .req_type = USB_REQUEST_TYPE_CLASS,
    75                 .request = USB_HIDREQ_SET_REPORT,
     69                CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_REPORT),
    7670                .name = "Set_Report",
    7771                .callback = req_set_report
     
    151145
    152146
     147static struct option long_options[] = {
     148        {"help", optional_argument, NULL, 'h'},
     149        {"controller", required_argument, NULL, 'c' },
     150        {"list", no_argument, NULL, 'l' },
     151        {0, 0, NULL, 0}
     152};
     153static const char *short_options = "hc:l";
     154
     155static void print_help(const char* name, const char* module)
     156{
     157        if (module == NULL) {
     158                /* Default help */
     159                printf("Usage: %s [options] device.\n", name);
     160                printf("\t-h, --help [device]\n");
     161                printf("\t\to With no argument print this help and exit.\n");
     162                printf("\t\to With argument print device specific help and exit.\n");
     163                printf("\t-l, --list \n\t\tPrint list of available devices.\n");
     164                printf("\t-c, --controller \n\t\t"
     165                    "Use provided virtual hc instead of default (%s)\n",
     166                    DEFAULT_CONTROLLER);
     167                return;
     168        }
     169        printf("HELP for module %s\n", module);
     170}
     171
     172static void print_list(void)
     173{
     174        printf("Available devices:\n");
     175        for (vuhid_interface_t **i = available_hid_interfaces; *i != NULL; ++i)
     176        {
     177                printf("\t`%s'\t%s\n", (*i)->id, (*i)->name);
     178        }
     179
     180}
     181
     182static const char *controller = DEFAULT_CONTROLLER;
     183
    153184int main(int argc, char * argv[])
    154185{
    155         int rc;
     186
     187        if (argc == 1) {
     188                print_help(*argv, NULL);
     189                return 0;
     190        }
     191
     192        int opt = 0;
     193        while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) > 0) {
     194                switch (opt)
     195                {
     196                case 'h':
     197                        print_help(*argv, optarg);
     198                        return 0;
     199                case 'c':
     200                        controller = optarg;
     201                        break;
     202                case 'l':
     203                        print_list();
     204                        return 0;
     205                case -1:
     206                default:
     207                        break;
     208                }
     209        }
     210
    156211
    157212        log_init("vuhid");
     
    161216
    162217        /* Determine which interfaces to initialize. */
    163         int i;
    164         for (i = 1; i < argc; i++) {
    165                 rc = add_interface_by_id(available_hid_interfaces, argv[i],
     218        for (int i = optind; i < argc; i++) {
     219                int rc = add_interface_by_id(available_hid_interfaces, argv[i],
    166220                    &hid_dev);
    167221                if (rc != EOK) {
     
    173227        }
    174228
    175         for (i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {
     229        for (int i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {
    176230                usb_log_debug("Found extra descriptor: %s.\n",
    177231                    usb_debug_str_buffer(
     
    181235        }
    182236
    183         rc = usbvirt_device_plug(&hid_dev, "/virt/usbhc/hc");
     237        const int rc = usbvirt_device_plug(&hid_dev, controller);
    184238        if (rc != EOK) {
    185                 printf("Unable to start communication with VHCD: %s.\n",
    186                     str_error(rc));
     239                printf("Unable to start communication with VHCD `%s': %s.\n",
     240                    controller, str_error(rc));
    187241                return rc;
    188242        }
    189243       
    190         printf("Connected to VHCD...\n");
     244        printf("Connected to VHCD `%s'...\n", controller);
    191245
    192246        wait_for_interfaces_death(&hid_dev);
  • uspace/app/vuhid/virthid.h

    r5b18137 rb4b534ac  
    7171
    7272        int (*on_data_in)(vuhid_interface_t *, void *, size_t, size_t *);
    73         int (*on_data_out)(vuhid_interface_t *, void *, size_t);
     73        int (*on_data_out)(vuhid_interface_t *, const void *, size_t);
    7474        void (*live)(vuhid_interface_t *);
    7575
Note: See TracChangeset for help on using the changeset viewer.