Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vuhid/main.c

    reb34d8e r920d0fc  
    4040#include <errno.h>
    4141#include <str_error.h>
    42 #include <getopt.h>
    4342
    4443#include <usb/usb.h>
     
    5352#include "stdreq.h"
    5453
    55 #define DEFAULT_CONTROLLER   "/virt/usbhc/virtual"
    56 
    5754static usbvirt_control_request_handler_t endpoint_zero_handlers[] = {
    5855        {
    59                 STD_REQ_IN(USB_REQUEST_RECIPIENT_INTERFACE, USB_DEVREQ_GET_DESCRIPTOR),
     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,
    6060                .name = "Get_Descriptor",
    6161                .callback = req_get_descriptor
    6262        },
    6363        {
    64                 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_PROTOCOL),
     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,
    6568                .name = "Set_Protocol",
    6669                .callback = req_set_protocol
    6770        },
    6871        {
    69                 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_REPORT),
     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,
    7076                .name = "Set_Report",
    7177                .callback = req_set_report
     
    145151
    146152
    147 static 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 };
    153 static const char *short_options = "hc:l";
    154 
    155 static 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 
    172 static 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 
    182 static const char *controller = DEFAULT_CONTROLLER;
    183 
    184153int main(int argc, char * argv[])
    185154{
    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 
     155        int rc;
    211156
    212157        log_init("vuhid");
     
    216161
    217162        /* Determine which interfaces to initialize. */
    218         for (int i = optind; i < argc; i++) {
    219                 int rc = add_interface_by_id(available_hid_interfaces, argv[i],
     163        int i;
     164        for (i = 1; i < argc; i++) {
     165                rc = add_interface_by_id(available_hid_interfaces, argv[i],
    220166                    &hid_dev);
    221167                if (rc != EOK) {
     
    227173        }
    228174
    229         for (int i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {
     175        for (i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {
    230176                usb_log_debug("Found extra descriptor: %s.\n",
    231177                    usb_debug_str_buffer(
     
    235181        }
    236182
    237         const int rc = usbvirt_device_plug(&hid_dev, controller);
     183        rc = usbvirt_device_plug(&hid_dev, "/virt/usbhc/hc");
    238184        if (rc != EOK) {
    239                 printf("Unable to start communication with VHCD `%s': %s.\n",
    240                     controller, str_error(rc));
     185                printf("Unable to start communication with VHCD: %s.\n",
     186                    str_error(rc));
    241187                return rc;
    242188        }
    243189       
    244         printf("Connected to VHCD `%s'...\n", controller);
     190        printf("Connected to VHCD...\n");
    245191
    246192        wait_for_interfaces_death(&hid_dev);
Note: See TracChangeset for help on using the changeset viewer.