Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 72cd53d in mainline


Ignore:
Timestamp:
2011-05-17T07:18:11Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
3375bd4
Parents:
50cd285 (diff), e913cc9 (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:

Small fixes and improvements

Fixed buffer overflow in lsusb.
lsusb scans all adresses, not only first ones.
Played with logging levels, now it is configurable.
VHC prints name of connected device and destroys pending transfers
when device is unplugged.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    r50cd285 r72cd53d  
    555555! [CONFIG_STRIP_BINARIES!=y] CONFIG_LINE_DEBUG (n/y)
    556556
     557# USB settings
     558
     559% USB release build (less logging)
     560! CONFIG_USB_RELEASE_BUILD (n/y)
     561
    557562% Start virtual USB host controller
    558563! CONFIG_RUN_VIRTUAL_USB_HC (n/y)
  • uspace/app/lsusb/main.c

    r50cd285 r72cd53d  
    4949#define NAME "lsusb"
    5050
     51#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
    5152#define MAX_FAILED_ATTEMPTS 10
    5253#define MAX_PATH_LENGTH 1024
     
    7677        }
    7778        usb_address_t addr;
    78         for (addr = 1; addr < 5; addr++) {
     79        for (addr = 1; addr < MAX_USB_ADDRESS; addr++) {
    7980                devman_handle_t dev_handle;
    8081                rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
  • uspace/drv/usbhid/main.c

    r50cd285 r72cd53d  
    202202        printf(NAME ": HelenOS USB HID driver.\n");
    203203
    204         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     204        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    205205
    206206        return usb_driver_main(&usb_hid_driver);
  • uspace/drv/vhc/conndev.c

    r50cd285 r72cd53d  
    3737#include <errno.h>
    3838#include <ddf/driver.h>
     39#include <usbvirt/ipc.h>
    3940#include "conn.h"
    4041
    4142static fibril_local uintptr_t plugged_device_handle = 0;
     43#define PLUGGED_DEVICE_NAME_MAXLEN 256
     44static fibril_local char plugged_device_name[PLUGGED_DEVICE_NAME_MAXLEN + 1] = "<unknown>";
     45
     46/** Receive device name.
     47 *
     48 * @warning Errors are silently ignored.
     49 *
     50 * @param phone Phone to the virtual device.
     51 */
     52static void receive_device_name(int phone)
     53{
     54        aid_t opening_request = async_send_0(phone, IPC_M_USBVIRT_GET_NAME, NULL);
     55        if (opening_request == 0) {
     56                return;
     57        }
     58
     59
     60        ipc_call_t data_request_call;
     61        aid_t data_request = async_data_read(phone,
     62             plugged_device_name, PLUGGED_DEVICE_NAME_MAXLEN,
     63             &data_request_call);
     64
     65        if (data_request == 0) {
     66                async_wait_for(opening_request, NULL);
     67                return;
     68        }
     69
     70        sysarg_t data_request_rc;
     71        sysarg_t opening_request_rc;
     72        async_wait_for(data_request, &data_request_rc);
     73        async_wait_for(opening_request, &opening_request_rc);
     74
     75        if ((data_request_rc != EOK) || (opening_request_rc != EOK)) {
     76                return;
     77        }
     78
     79        size_t len = IPC_GET_ARG2(data_request_call);
     80        plugged_device_name[len] = 0;
     81}
    4282
    4383/** Default handler for IPC methods not handled by DDF.
     
    65105                async_answer_0(icallid, EOK);
    66106
    67                 usb_log_info("New virtual device `%s' (id = %" PRIxn ").\n",
    68                     rc == EOK ? "XXX" : "<unknown>", plugged_device_handle);
     107                receive_device_name(callback);
     108
     109                usb_log_info("New virtual device `%s' (id: %" PRIxn ").\n",
     110                    plugged_device_name, plugged_device_handle);
    69111
    70112                return;
     
    85127
    86128        if (plugged_device_handle != 0) {
    87                 usb_log_info("Virtual device disconnected (id = %" PRIxn ").\n",
    88                     plugged_device_handle);
     129                usb_log_info("Virtual device `%s' disconnected (id: %" PRIxn ").\n",
     130                    plugged_device_name, plugged_device_handle);
    89131                vhc_virtdev_unplug(vhc, plugged_device_handle);
    90132        }
  • uspace/drv/vhc/transfer.c

    r50cd285 r72cd53d  
    161161}
    162162
     163static vhc_transfer_t *dequeue_first_transfer(vhc_virtdev_t *dev)
     164{
     165        assert(fibril_mutex_is_locked(&dev->guard));
     166        assert(!list_empty(&dev->transfer_queue));
     167
     168        vhc_transfer_t *transfer = list_get_instance(dev->transfer_queue.next,
     169            vhc_transfer_t, link);
     170        list_remove(&transfer->link);
     171
     172        return transfer;
     173}
     174
     175
     176static void execute_transfer_callback_and_free(vhc_transfer_t *transfer,
     177    size_t data_transfer_size, int outcome)
     178{
     179        assert(outcome != ENAK);
     180
     181        usb_log_debug2("Transfer %p ended: %s.\n",
     182            transfer, str_error(outcome));
     183
     184        if (transfer->direction == USB_DIRECTION_IN) {
     185                transfer->callback_in(transfer->ddf_fun, outcome,
     186                    data_transfer_size, transfer->callback_arg);
     187        } else {
     188                assert(transfer->direction == USB_DIRECTION_OUT);
     189                transfer->callback_out(transfer->ddf_fun, outcome,
     190                    transfer->callback_arg);
     191        }
     192
     193        free(transfer);
     194}
    163195
    164196int vhc_transfer_queue_processor(void *arg)
     
    174206                }
    175207
    176                 vhc_transfer_t *transfer = list_get_instance(dev->transfer_queue.next,
    177                     vhc_transfer_t, link);
    178                 list_remove(&transfer->link);
     208                vhc_transfer_t *transfer = dequeue_first_transfer(dev);
    179209                fibril_mutex_unlock(&dev->guard);
    180210
     
    214244
    215245                if (rc != ENAK) {
    216                         usb_log_debug2("Transfer %p ended: %s.\n",
    217                             transfer, str_error(rc));
    218                         if (transfer->direction == USB_DIRECTION_IN) {
    219                                 transfer->callback_in(transfer->ddf_fun, rc,
    220                                     data_transfer_size, transfer->callback_arg);
    221                         } else {
    222                                 assert(transfer->direction == USB_DIRECTION_OUT);
    223                                 transfer->callback_out(transfer->ddf_fun, rc,
    224                                     transfer->callback_arg);
    225                         }
    226                         free(transfer);
     246                        execute_transfer_callback_and_free(transfer,
     247                            data_transfer_size, rc);
    227248                }
    228249
     
    231252        }
    232253
     254        /* Immediately fail all remaining transfers. */
     255        while (!list_empty(&dev->transfer_queue)) {
     256                vhc_transfer_t *transfer = dequeue_first_transfer(dev);
     257                execute_transfer_callback_and_free(transfer, 0, EBADCHECKSUM);
     258        }
     259
    233260        fibril_mutex_unlock(&dev->guard);
    234261
    235         // TODO - destroy pending transfers
    236 
    237262        return EOK;
    238263}
  • uspace/lib/c/generic/devman.c

    r50cd285 r72cd53d  
    415415        }
    416416
     417        /* To be on the safe-side. */
    417418        path[path_size - 1] = 0;
    418419
    419         if (IPC_GET_ARG2(data_request_call) >= path_size) {
     420        size_t transferred_size = IPC_GET_ARG2(data_request_call);
     421
     422        if (transferred_size >= path_size) {
    420423                return ELIMIT;
    421424        }
     425
     426        /* Terminate the string (trailing 0 not send over IPC). */
     427        path[transferred_size] = 0;
    422428
    423429        return EOK;
  • uspace/lib/usb/include/usb/debug.h

    r50cd285 r72cd53d  
    8181
    8282/** Default log level. */
    83 #define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_DEBUG
    84 
     83#ifdef CONFIG_USB_RELEASE_BUILD
     84#  define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_INFO
     85#else
     86#  define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_DEBUG
     87#endif
    8588
    8689void usb_log_enable(usb_log_level_t, const char *);
  • uspace/lib/usb/src/debug.c

    r50cd285 r72cd53d  
    116116        /*
    117117         * Serialize access to log files.
    118          * Always print to log file, to screen print only when the enabled
    119          * log level is high enough.
     118         * Print to screen only messages with higher level than the one
     119         * specified during logging initialization.
     120         * Print also to file, to it print one more (lower) level as well.
    120121         */
    121122        fibril_mutex_lock(&log_serializer);
     
    123124        const char *level_name = log_level_name(level);
    124125
    125         if (log_stream != NULL) {
     126        if ((log_stream != NULL) && (level <= log_level + 1)) {
    126127                va_start(args, format);
    127128
  • uspace/lib/usbvirt/include/usbvirt/ipc.h

    r50cd285 r72cd53d  
    3939#include <usb/usb.h>
    4040#include <bool.h>
     41#include <usbvirt/device.h>
    4142
    4243/** IPC methods communication between host controller and virtual device. */
Note: See TracChangeset for help on using the changeset viewer.