Changeset 54d71e1 in mainline for uspace/app


Ignore:
Timestamp:
2011-04-29T07:05:30Z (15 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
361fcec
Parents:
9014dcd (diff), cd4ae1e (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 with development

Location:
uspace/app
Files:
5 added
5 edited
4 moved

Legend:

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

    r9014dcd r54d71e1  
    5555        if (str_cmp(devpath, "qemu") == 0) {
    5656                devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1";
     57        }
     58
     59        /* Hack for virtual keyboard. */
     60        if (str_cmp(devpath, "virt") == 0) {
     61                devpath = "/virt/usbhc/usb00_a1/usb00_a2";
    5762        }
    5863
  • uspace/app/virtusbkbd/Makefile

    r9014dcd r54d71e1  
    3232BINARY = vuk
    3333
    34 LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a
     34LIBS = $(LIBUSBVIRT_PREFIX)/libusbvirt.a $(LIBUSB_PREFIX)/libusb.a
    3535EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIBUSBVIRT_PREFIX)/include -I$(LIBDRV_PREFIX)/include
    3636
  • uspace/app/virtusbkbd/stdreq.c

    r9014dcd r54d71e1  
    3939#include "kbdconfig.h"
    4040
    41 int stdreq_on_get_descriptor(struct usbvirt_device *dev,
    42     usb_device_request_setup_packet_t *request, uint8_t *data)
     41int req_get_descriptor(usbvirt_device_t *device,
     42    const usb_device_request_setup_packet_t *setup_packet,
     43    uint8_t *data, size_t *act_size)
    4344{
    44         if (request->value_high == USB_DESCTYPE_HID_REPORT) {
     45        if (setup_packet->value_high == USB_DESCTYPE_HID_REPORT) {
    4546                /*
    4647                 * For simplicity, always return the same
    4748                 * report descriptor.
    4849                 */
    49                 int rc = dev->control_transfer_reply(dev, 0,
     50                usbvirt_control_reply_helper(setup_packet,
     51                    data, act_size,
    5052                    report_descriptor, report_descriptor_size);
    51                
    52                 return rc;
     53
     54                return EOK;
    5355        }
    5456       
  • uspace/app/virtusbkbd/stdreq.h

    r9014dcd r54d71e1  
    3838#include <usbvirt/device.h>
    3939
    40 int stdreq_on_get_descriptor(usbvirt_device_t *,
    41     usb_device_request_setup_packet_t *, uint8_t *);
     40int req_get_descriptor(usbvirt_device_t *device,
     41    const usb_device_request_setup_packet_t *setup_packet,
     42    uint8_t *data, size_t *act_size);
    4243
    4344#endif
  • uspace/app/virtusbkbd/virtusbkbd.c

    r9014dcd r54d71e1  
    4848#include <usb/descriptor.h>
    4949#include <usb/classes/hid.h>
     50#include <usb/debug.h>
    5051#include <usbvirt/device.h>
    51 #include <usbvirt/hub.h>
    5252
    5353#include "kbdconfig.h"
     
    6767
    6868kb_status_t status;
    69 
    70 static int on_incoming_data(struct usbvirt_device *dev,
    71     usb_endpoint_t endpoint, void *buffer, size_t size)
    72 {
    73         printf("%s: ignoring incomming data to endpoint %d\n", NAME, endpoint);
    74        
    75         return EOK;
    76 }
    77 
    7869
    7970/** Compares current and last status of pressed keys.
     
    10091}
    10192
    102 static int on_request_for_data(struct usbvirt_device *dev,
    103     usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size)
     93static int on_request_for_data(usbvirt_device_t *dev,
     94    usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
     95    void *buffer, size_t size, size_t *actual_size)
    10496{
    10597        static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE];
     
    122114        if (keypress_check_with_last_request(data, last_data,
    123115            2 + KB_MAX_KEYS_AT_ONCE)) {
    124                 *actual_size = 0;
    125                 return EOK;
     116                return ENAK;
    126117        }
    127118
     
    131122}
    132123
    133 static usbvirt_control_transfer_handler_t endpoint_zero_handlers[] = {
    134         {
    135                 .request_type = USBVIRT_MAKE_CONTROL_REQUEST_TYPE(
    136                     USB_DIRECTION_IN,
    137                     USBVIRT_REQUEST_TYPE_STANDARD,
    138                     USBVIRT_REQUEST_RECIPIENT_DEVICE),
     124static usbvirt_control_request_handler_t endpoint_zero_handlers[] = {
     125        {
     126                .req_direction = USB_DIRECTION_IN,
     127                .req_type = USB_REQUEST_TYPE_STANDARD,
     128                .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE,
    139129                .request = USB_DEVREQ_GET_DESCRIPTOR,
    140130                .name = "GetDescriptor",
    141                 .callback = stdreq_on_get_descriptor
     131                .callback = req_get_descriptor
    142132        },
    143133        {
    144                 .request_type = USBVIRT_MAKE_CONTROL_REQUEST_TYPE(
    145                     USB_DIRECTION_IN,
    146                     USBVIRT_REQUEST_TYPE_CLASS,
    147                     USBVIRT_REQUEST_RECIPIENT_DEVICE),
    148                 .request = USB_DEVREQ_GET_DESCRIPTOR,
    149                 .name = "GetDescriptor",
    150                 .callback = stdreq_on_get_descriptor
    151         },
    152         USBVIRT_CONTROL_TRANSFER_HANDLER_LAST
     134                .callback = NULL
     135        }
    153136};
    154137
     
    157140 */
    158141static usbvirt_device_ops_t keyboard_ops = {
    159         .control_transfer_handlers = endpoint_zero_handlers,
    160         .on_data = on_incoming_data,
    161         .on_data_request = on_request_for_data
     142        .control = endpoint_zero_handlers,
     143        .data_in[1] = on_request_for_data
    162144};
    163145
     
    197179        .ops = &keyboard_ops,
    198180        .descriptors = &descriptors,
    199         .lib_debug_level = 3,
    200         .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL,
    201181        .name = "keyboard"
    202182};
     
    262242       
    263243       
    264         int rc = usbvirt_connect(&keyboard_dev);
     244        int rc = usbvirt_device_plug(&keyboard_dev, "/virt/usbhc/hc");
    265245        if (rc != EOK) {
    266246                printf("%s: Unable to start communication with VHCD (%s).\n",
     
    278258        printf("%s: Terminating...\n", NAME);
    279259       
    280         usbvirt_disconnect(&keyboard_dev);
     260        //usbvirt_disconnect(&keyboard_dev);
    281261       
    282262        return 0;
  • uspace/app/vuhid/Makefile

    r9014dcd r54d71e1  
    2828
    2929USPACE_PREFIX = ../..
    30 # acronym for virtual USB hub
     30# acronym for virtual USB human input device
    3131# (it is really annoying to write long names)
    3232BINARY = vuh
    3333
    34 LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a
    35 EXTRA_CFLAGS = -DSTANDALONE_HUB \
    36         -DHUB_PORT_COUNT=10 \
    37         -I$(LIBUSB_PREFIX)/include -I$(LIBUSBVIRT_PREFIX)/include -I$(LIBDRV_PREFIX)/include
     34LIBS = \
     35        $(LIBUSBVIRT_PREFIX)/libusbvirt.a \
     36        $(LIBUSB_PREFIX)/libusb.a
     37EXTRA_CFLAGS = \
     38        -I$(LIBUSB_PREFIX)/include \
     39        -I$(LIBUSBVIRT_PREFIX)/include \
     40        -I$(LIBDRV_PREFIX)/include
     41
     42
     43SOURCES_INTERFACES = \
     44        hids/bootkbd.c
    3845
    3946SOURCES = \
    4047        main.c \
    41         $(STOLEN_VHC_SOURCES)
    42 
    43 STOLEN_VHC_SOURCES = \
    44         vhc_hub/hub.c \
    45         vhc_hub/virthub.c \
    46         vhc_hub/virthubops.c
    47 STOLEN_VHC_HEADERS = \
    48         vhc_hub/hub.h \
    49         vhc_hub/virthub.h
    50 
    51 PRE_DEPEND = $(STOLEN_VHC_SOURCES) $(STOLEN_VHC_HEADERS)
    52 
    53 EXTRA_CLEAN = $(STOLEN_VHC_SOURCES) $(STOLEN_VHC_HEADERS)
    54 
    55 HUB_IN_VHC = $(USPACE_PREFIX)/drv/vhc/hub
     48        device.c \
     49        ifaces.c \
     50        stdreq.c \
     51        $(SOURCES_INTERFACES)
     52       
    5653
    5754include $(USPACE_PREFIX)/Makefile.common
    58 
    59 vhc_hub/%.h: $(HUB_IN_VHC)/%.h
    60         ln -sfn ../$(HUB_IN_VHC)/$*.h $@
    61 vhc_hub/%.c: $(HUB_IN_VHC)/%.c
    62         ln -sfn ../$(HUB_IN_VHC)/$*.c $@
  • uspace/app/vuhid/ifaces.h

    r9014dcd r54d71e1  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusbvirt
     29/** @addtogroup usbvirthid
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief Debugging support.
     33 *
    3434 */
    35 #include <stdio.h>
    36 #include <bool.h>
     35#ifndef VUHID_IFACES_H_
     36#define VUHID_IFACES_H_
    3737
    38 #include "private.h"
     38#include "virthid.h"
    3939
     40extern vuhid_interface_t *available_hid_interfaces[];
    4041
    41 static void debug_print(int level, uint8_t tag,
    42     int current_level, uint8_t enabled_tags,
    43     const char *format, va_list args)
    44 {
    45         if (level > current_level) {
    46                 return;
    47         }
    48        
    49         if ((tag & enabled_tags) == 0) {
    50                 return;
    51         }
    52        
    53         bool print_prefix = true;
    54        
    55         if ((format[0] == '%') && (format[1] == 'M')) {
    56                 format += 2;
    57                 print_prefix = false;
    58         }
    59        
    60         if (print_prefix) {
    61                 printf("[vusb]: ");
    62                 while (--level > 0) {
    63                         printf(" ");
    64                 }
    65         }
    66        
    67         vprintf(format, args);
    68        
    69         if (print_prefix) {
    70                 printf("\n");
    71         }
    72 }
    73 
    74 
    75 void user_debug(usbvirt_device_t *device, int level, uint8_t tag,
    76     const char *format, ...)
    77 {
    78         va_list args;
    79         va_start(args, format);
    80        
    81         debug_print(level, tag,
    82             device->debug_level, device->debug_enabled_tags,
    83             format, args);
    84        
    85         va_end(args);
    86 }
    87 
    88 void lib_debug(usbvirt_device_t *device, int level, uint8_t tag,
    89     const char *format, ...)
    90 {
    91         va_list args;
    92         va_start(args, format);
    93        
    94         debug_print(level, tag,
    95             device->lib_debug_level, device->lib_debug_enabled_tags,
    96             format, args);
    97        
    98         va_end(args);
    99 }
    100 
     42#endif
    10143/**
    10244 * @}
  • uspace/app/vuhid/stdreq.h

    r9014dcd r54d71e1  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup drvusbvhc
     29/** @addtogroup usbvirthid
    3030 * @{
    31  */ 
     31 */
    3232/** @file
    33  * @brief Virtual device management.
     33 * Device request handlers.
    3434 */
    35 #ifndef VHCD_DEVICES_H_
    36 #define VHCD_DEVICES_H_
     35#ifndef VUHID_STDREQ_H_
     36#define VUHID_STDREQ_H_
    3737
    38 #include <adt/list.h>
    39 #include <usb/usb.h>
     38#include <usbvirt/device.h>
    4039
    41 #include "hc.h"
     40int req_get_descriptor(usbvirt_device_t *device,
     41    const usb_device_request_setup_packet_t *setup_packet,
     42    uint8_t *data, size_t *act_size);
    4243
    43 /** Connected virtual device. */
    44 typedef struct {
    45         /** Phone used when sending data to device. */
    46         int phone;
    47         /** Unique identification. */
    48         sysarg_t id;
    49         /** Linked-list handle. */
    50         link_t link;
    51 } virtdev_connection_t;
     44int req_set_protocol(usbvirt_device_t *device,
     45    const usb_device_request_setup_packet_t *setup_packet,
     46    uint8_t *data, size_t *act_size);
    5247
    53 virtdev_connection_t *virtdev_add_device(int, sysarg_t);
    54 virtdev_connection_t *virtdev_find(sysarg_t);
    55 void virtdev_destroy_device(virtdev_connection_t *);
    56 int virtdev_send_to_all(transaction_t *);
     48int req_set_report(usbvirt_device_t *device,
     49    const usb_device_request_setup_packet_t *setup_packet,
     50    uint8_t *data, size_t *act_size);
    5751
    5852#endif
  • uspace/app/vuhid/virthid.h

    r9014dcd r54d71e1  
    2727 */
    2828
    29 /** @addtogroup usbvirthub
     29/** @addtogroup usbvirthid
    3030 * @{
    3131 */
    32 /**
    33  * @file
    34  * @brief Virtual USB hub.
     32/** @file
     33 *
    3534 */
    36 
    37 #include <stdio.h>
    38 #include <stdlib.h>
    39 #include <errno.h>
    40 #include <str_error.h>
    41 #include <bool.h>
     35#ifndef VUHID_VIRTHID_H_
     36#define VUHID_VIRTHID_H_
    4237
    4338#include <usb/usb.h>
    44 #include <usb/descriptor.h>
    45 #include <usb/classes/hub.h>
    4639#include <usbvirt/device.h>
    47 #include <usbvirt/hub.h>
    4840
    49 #include "vhc_hub/virthub.h"
     41#define VUHID_ENDPOINT_MAX USB11_ENDPOINT_MAX
     42#define VUHID_INTERFACE_MAX 8
    5043
    51 #define NAME "vuh"
     44typedef struct vuhid_interface vuhid_interface_t;
    5245
    53 static usbvirt_device_t hub_device;
     46struct vuhid_interface {
     47        const char *name;
     48        const char *id;
     49        int usb_subclass;
     50        int usb_protocol;
    5451
    55 #define VERBOSE_SLEEP(sec, msg, ...) \
    56         do { \
    57                 char _status[HUB_PORT_COUNT + 2]; \
    58                 printf(NAME ": doing nothing for %zu seconds...\n", \
    59                     (size_t) (sec)); \
    60                 fibril_sleep((sec)); \
    61                 virthub_get_status(&hub_device, _status, HUB_PORT_COUNT + 1); \
    62                 printf(NAME ": " msg " [%s]\n" #__VA_ARGS__, _status); \
    63         } while (0)
     52        uint8_t *report_descriptor;
     53        size_t report_descriptor_size;
    6454
    65 static void fibril_sleep(size_t sec)
    66 {
    67         while (sec-- > 0) {
    68                 async_usleep(1000*1000);
    69         }
    70 }
     55        size_t in_data_size;
     56        size_t out_data_size;
    7157
    72 static int dev1 = 1;
     58        int (*on_data_in)(vuhid_interface_t *, void *, size_t, size_t *);
     59        int (*on_data_out)(vuhid_interface_t *, void *, size_t);
     60        void (*live)(vuhid_interface_t *);
    7361
    74 int main(int argc, char * argv[])
    75 {
    76         int rc;
     62        int set_protocol;
    7763
    78         printf(NAME ": virtual USB hub.\n");
     64        void *interface_data;
     65};
    7966
    80         rc = virthub_init(&hub_device);
    81         if (rc != EOK) {
    82                 printf(NAME ": Unable to start communication with VHCD (%s).\n",
    83                     str_error(rc));
    84                 return rc;
    85         }
    86        
    87         while (true) {
    88                 VERBOSE_SLEEP(8, "will pretend device plug-in...");
    89                 virthub_connect_device(&hub_device, &dev1);
     67typedef struct {
     68        vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX];
     69        size_t in_endpoint_first_free;
     70        vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX];
     71        size_t out_endpoint_first_free;
     72        vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX];
     73} vuhid_data_t;
    9074
    91                 VERBOSE_SLEEP(8, "will pretend device un-plug...");
    92                 virthub_disconnect_device(&hub_device, &dev1);
    93         }
     75typedef struct {
     76        uint8_t length;
     77        uint8_t type;
     78        uint16_t hid_spec_release;
     79        uint8_t country_code;
     80        uint8_t descriptor_count;
     81        uint8_t descriptor1_type;
     82        uint16_t descriptor1_length;
     83} __attribute__ ((packed)) hid_descriptor_t;
    9484
    95         usbvirt_disconnect(&hub_device);
    96        
    97         return 0;
    98 }
     85int add_interface_by_id(vuhid_interface_t **, const char *, usbvirt_device_t *);
    9986
    100 
    101 /** @}
     87#endif
     88/**
     89 * @}
    10290 */
Note: See TracChangeset for help on using the changeset viewer.