Changeset 19a1800 in mainline for uspace/lib/usb


Ignore:
Timestamp:
2011-03-01T22:20:56Z (15 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e24e7b1
Parents:
976f546 (diff), ac8285d (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 the current development

Location:
uspace/lib/usb
Files:
15 added
9 deleted
19 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/Makefile

    r976f546 r19a1800  
    3535        src/addrkeep.c \
    3636        src/class.c \
     37        src/ddfiface.c \
    3738        src/debug.c \
    3839        src/dp.c \
    39         src/drvpsync.c \
    40         src/hcdhubd.c \
    41         src/hcdrv.c \
     40        src/dump.c \
    4241        src/hidparser.c \
    43         src/localdrv.c \
     42        src/hub.c \
     43        src/pipes.c \
     44        src/pipesinit.c \
     45        src/pipesio.c \
    4446        src/recognise.c \
    45         src/remotedrv.c \
     47        src/request.c \
    4648        src/usb.c \
    47         src/usbdrvreq.c \
    48         src/usbdrv.c
     49        src/usbdevice.c \
     50        src/usbmem.c
    4951
    5052include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usb/include/usb/addrkeep.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief HC driver.
     33 * USB address keeping for host controller drivers.
    3434 */
    35 #ifndef LIBUSB_HCD_H_
    36 #define LIBUSB_HCD_H_
     35#ifndef LIBUSB_ADDRKEEP_H_
     36#define LIBUSB_ADDRKEEP_H_
    3737
    3838#include <usb/usb.h>
     
    8181    devman_handle_t);
    8282
    83 
    8483#endif
     84/**
     85 * @}
     86 */
  • uspace/lib/usb/include/usb/classes/classes.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/include/usb/classes/hid.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3737
    3838#include <usb/usb.h>
    39 #include <driver.h>
    4039#include <usb/classes/hidparser.h>
     40#include <usb/descriptor.h>
    4141
    4242/** USB/HID device requests. */
     
    5151} usb_hid_request_t;
    5252
     53typedef enum {
     54        USB_HID_REPORT_TYPE_INPUT = 1,
     55        USB_HID_REPORT_TYPE_OUTPUT = 2,
     56        USB_HID_REPORT_TYPE_FEATURE = 3
     57} usb_hid_report_type_t;
     58
     59typedef enum {
     60        USB_HID_PROTOCOL_BOOT = 0,
     61        USB_HID_PROTOCOL_REPORT = 1
     62} usb_hid_protocol_t;
     63
     64/** USB/HID subclass constants. */
     65typedef enum {
     66        USB_HID_SUBCLASS_NONE = 0,
     67        USB_HID_SUBCLASS_BOOT = 1
     68} usb_hid_subclass_t;
     69
    5370/** USB/HID interface protocols. */
    5471typedef enum {
     
    5673        USB_HID_PROTOCOL_KEYBOARD = 1,
    5774        USB_HID_PROTOCOL_MOUSE = 2
    58 } usb_hid_protocol_t;
     75} usb_hid_iface_protocol_t;
    5976
    6077/** Part of standard USB HID descriptor specifying one class descriptor.
     
    6380 */
    6481typedef struct {
    65         /** Type of class descriptor (Report or Physical). */
    66         uint8_t class_descriptor_type;
    67         /** Length of class descriptor. */
    68         uint16_t class_descriptor_length;
    69 } __attribute__ ((packed)) usb_standard_hid_descriptor_class_item_t;
     82        /** Type of class-specific descriptor (Report or Physical). */
     83        uint8_t type;
     84        /** Length of class-specific descriptor in bytes. */
     85        uint16_t length;
     86} __attribute__ ((packed)) usb_standard_hid_class_descriptor_info_t;
    7087
    7188/** Standard USB HID descriptor.
     
    7390 * (See HID Specification, p.22)
    7491 *
    75  * It is actually only the "header" of the descriptor, as it may have arbitrary
    76  * length if more than one class descritor is provided.
     92 * It is actually only the "header" of the descriptor, it does not contain
     93 * the last two mandatory fields (type and length of the first class-specific
     94 * descriptor).
    7795 */
    7896typedef struct {
    79         /** Size of this descriptor in bytes. */
     97        /** Total size of this descriptor in bytes.
     98         *
     99         * This includes all class-specific descriptor info - type + length
     100         * for each descriptor.
     101         */
    80102        uint8_t length;
    81103        /** Descriptor type (USB_DESCTYPE_HID). */
     
    85107        /** Country code of localized hardware. */
    86108        uint8_t country_code;
    87         /** Total number of class (i.e. Report and Physical) descriptors. */
    88         uint8_t class_count;
    89         /** First mandatory class descriptor info. */
    90         usb_standard_hid_descriptor_class_item_t class_descriptor;
     109        /** Total number of class-specific (i.e. Report and Physical)
     110         * descriptors.
     111         *
     112         * @note There is always only one Report descriptor.
     113         */
     114        uint8_t class_desc_count;
     115        /** First mandatory class descriptor (Report) info. */
     116        usb_standard_hid_class_descriptor_info_t report_desc_info;
    91117} __attribute__ ((packed)) usb_standard_hid_descriptor_t;
    92118
    93 
    94 /**
    95  * @brief USB/HID keyboard device type.
    96  *
    97  * Quite dummy right now.
    98  */
    99 typedef struct {
    100         device_t *device;
    101         usb_address_t address;
    102         usb_endpoint_t poll_endpoint;
    103         usb_hid_report_parser_t *parser;
    104 } usb_hid_dev_kbd_t;
    105119
    106120#endif
  • uspace/lib/usb/include/usb/classes/hidparser.h

    r976f546 r19a1800  
    3737
    3838#include <stdint.h>
    39 #include <adt/list.h>
    40 
    41 #include <hid_report_items.h>
    4239
    4340/**
    44  * Items prefix
     41 * Item prefix
    4542 */
    4643#define USB_HID_ITEM_SIZE(data)         ((uint8_t)(data & 0x3))
     
    6259#define USB_HID_ITEM_FLAG_VOLATILE(flags)       (flags & 0x80)
    6360#define USB_HID_ITEM_FLAG_BUFFERED(flags)       (flags & 0x100)
    64 
    65 
    66 /**
    67  * Collection Item Types
    68  */
    69 #define USB_HID_COLLECTION_TYPE_PHYSICAL                0x00
    70 #define USB_HID_COLLECTION_TYPE_APPLICATION             0x01
    71 #define USB_HID_COLLECTION_TYPE_LOGICAL                 0x02
    72 #define USB_HID_COLLECTION_TYPE_REPORT                  0x03
    73 #define USB_HID_COLLECTION_TYPE_NAMED_ARRAY             0x04
    74 #define USB_HID_COLLECTION_TYPE_USAGE_SWITCH    0x05
    75 
    76 /*
    77  * modifiers definitions
    78  */
    79 #define USB_HID_BOOT_KEYBOARD_NUM_LOCK          0x01
    80 #define USB_HID_BOOT_KEYBOARD_CAPS_LOCK         0x02
    81 #define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK       0x04
    82 #define USB_HID_BOOT_KEYBOARD_COMPOSE           0x08
    83 #define USB_HID_BOOT_KEYBOARD_KANA                      0x10
    8461
    8562
     
    128105
    129106
     107
    130108/** HID parser callbacks for IN items. */
    131109typedef struct {
     
    139117} usb_hid_report_in_callbacks_t;
    140118
     119
     120typedef enum {
     121        USB_HID_MOD_LCTRL = 0x01,
     122        USB_HID_MOD_LSHIFT = 0x02,
     123        USB_HID_MOD_LALT = 0x04,
     124        USB_HID_MOD_LGUI = 0x08,
     125        USB_HID_MOD_RCTRL = 0x10,
     126        USB_HID_MOD_RSHIFT = 0x20,
     127        USB_HID_MOD_RALT = 0x40,
     128        USB_HID_MOD_RGUI = 0x80,
     129        USB_HID_MOD_COUNT = 8
     130} usb_hid_modifiers_t;
     131
     132typedef enum {
     133        USB_HID_LED_NUM_LOCK = 0x1,
     134        USB_HID_LED_CAPS_LOCK = 0x2,
     135        USB_HID_LED_SCROLL_LOCK = 0x4,
     136        USB_HID_LED_COMPOSE = 0x8,
     137        USB_HID_LED_KANA = 0x10,
     138        USB_HID_LED_COUNT = 5
     139} usb_hid_led_t;
     140
     141static const usb_hid_modifiers_t
     142    usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
     143        USB_HID_MOD_LCTRL,
     144        USB_HID_MOD_LSHIFT,
     145        USB_HID_MOD_LALT,
     146        USB_HID_MOD_LGUI,
     147        USB_HID_MOD_RCTRL,
     148        USB_HID_MOD_RSHIFT,
     149        USB_HID_MOD_RALT,
     150        USB_HID_MOD_RGUI
     151};
     152
     153//static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = {
     154//      USB_HID_LED_NUM_LOCK,
     155//      USB_HID_LED_CAPS_LOCK,
     156//      USB_HID_LED_SCROLL_LOCK,
     157//      USB_HID_LED_COMPOSE,
     158//      USB_HID_LED_KANA
     159//};
     160
     161//#define USB_HID_BOOT_KEYBOARD_NUM_LOCK                0x01
     162//#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK               0x02
     163//#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK     0x04
     164//#define USB_HID_BOOT_KEYBOARD_COMPOSE         0x08
     165//#define USB_HID_BOOT_KEYBOARD_KANA                    0x10
     166
     167/*
     168 * modifiers definitions
     169 */
     170
    141171int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    142172        const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    143173
    144174int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
    145 
    146175
    147176int usb_hid_parser_init(usb_hid_report_parser_t *parser);
     
    157186
    158187void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
     188
    159189#endif
    160190/**
  • uspace/lib/usb/include/usb/classes/hidut.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/include/usb/classes/hidutkbd.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/include/usb/classes/hub.h

    r976f546 r19a1800  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2010 Matus Dekanek
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * @brief USB hub related structures.
    3434 */
    35 #ifndef LIBUSB_HUB_H_
    36 #define LIBUSB_HUB_H_
     35#ifndef LIBUSB_CLASS_HUB_H_
     36#define LIBUSB_CLASS_HUB_H_
    3737
    3838#include <sys/types.h>
    39 #include <usb/hcdhubd.h>
    40 
    4139
    4240/** Hub class feature selector.
     
    6866 *      For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2
    6967 */
    70 typedef struct hub_descriptor_type{
     68typedef struct usb_hub_descriptor_type {
    7169    /** Number of bytes in this descriptor, including this byte */
    7270    //uint8_t bDescLength;
     
    8078    /**
    8179            D1...D0: Logical Power Switching Mode
    82             00: Ganged power switching (all ports power at
     80            00: Ganged power switching (all ports power at
    8381            once)
    8482            01: Individual port power switching
     
    9189            00: Global Over-current Protection. The hub
    9290            reports over-current as a summation of all
    93             ports current draw, without a breakdown of
     91            ports current draw, without a breakdown of
    9492            individual port over-current status.
    9593            01: Individual Port Over-current Protection. The
     
    198196extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE;
    199197
    200 /**
    201  * @brief create uint8_t array with serialized descriptor
    202  *
    203  * @param descriptor
    204  */
    205 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor);
    206 
    207 /**
    208  * @brief create deserialized desriptor structure out of serialized descriptor
    209  *
    210  * The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur.
    211  *
    212  * @param sdescriptor serialized descriptor
    213  */
    214 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
    215198
    216199
  • uspace/lib/usb/include/usb/debug.h

    r976f546 r19a1800  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2010-2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3535#ifndef LIBUSB_DEBUG_H_
    3636#define LIBUSB_DEBUG_H_
     37#include <stdio.h>
     38#include <usb/usb.h>
     39#include <assert.h>
    3740
    3841void usb_dprintf(const char *tag, int level, const char *format, ...);
    3942void usb_dprintf_enable(const char *tag, int level);
    4043
     44void usb_dump_standard_descriptor(FILE *, const char *, const char *,
     45    const uint8_t *, size_t);
     46
     47/** Logging level. */
     48typedef enum {
     49        USB_LOG_LEVEL_FATAL,
     50        USB_LOG_LEVEL_ERROR,
     51        USB_LOG_LEVEL_WARNING,
     52        USB_LOG_LEVEL_INFO,
     53        USB_LOG_LEVEL_DEBUG,
     54        USB_LOG_LEVEL_DEBUG2,
     55        USB_LOG_LEVEL_MAX
     56} usb_log_level_t;
     57
     58
     59void usb_log_enable(usb_log_level_t, const char *);
     60
     61void usb_log_printf(usb_log_level_t, const char *, ...);
     62
     63#define usb_log_fatal(format, ...) \
     64        usb_log_printf(USB_LOG_LEVEL_FATAL, format, ##__VA_ARGS__)
     65
     66#define usb_log_error(format, ...) \
     67        usb_log_printf(USB_LOG_LEVEL_ERROR, format, ##__VA_ARGS__)
     68
     69#define usb_log_warning(format, ...) \
     70        usb_log_printf(USB_LOG_LEVEL_WARNING, format, ##__VA_ARGS__)
     71
     72#define usb_log_info(format, ...) \
     73        usb_log_printf(USB_LOG_LEVEL_INFO, format, ##__VA_ARGS__)
     74
     75#define usb_log_debug(format, ...) \
     76        usb_log_printf(USB_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__)
     77
     78#define usb_log_debug2(format, ...) \
     79        usb_log_printf(USB_LOG_LEVEL_DEBUG2, format, ##__VA_ARGS__)
     80
     81
    4182
    4283#endif
     84/**
     85 * @}
     86 */
     87
  • uspace/lib/usb/include/usb/descriptor.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3636#define LIBUSB_DESCRIPTOR_H_
    3737
    38 #include <ipc/ipc.h>
    3938#include <async.h>
    4039
  • uspace/lib/usb/include/usb/dp.h

    r976f546 r19a1800  
    4545} usb_dp_descriptor_nesting_t;
    4646
     47extern usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[];
     48
    4749typedef struct {
    4850        usb_dp_descriptor_nesting_t *nesting;
  • uspace/lib/usb/include/usb/request.h

    r976f546 r19a1800  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief Standard USB device requests.
     33 * Standard USB requests.
    3434 */
    35 #ifndef LIBUSB_DEVREQ_H_
    36 #define LIBUSB_DEVREQ_H_
     35#ifndef LIBUSB_REQUEST_H_
     36#define LIBUSB_REQUEST_H_
    3737
    38 #include <ipc/ipc.h>
    39 #include <async.h>
     38#include <sys/types.h>
     39#include <l18n/langs.h>
    4040#include <usb/usb.h>
     41#include <usb/pipes.h>
    4142#include <usb/descriptor.h>
    4243
     
    7071        /** Main parameter to the request. */
    7172        union {
     73                uint16_t value;
    7274                /* FIXME: add #ifdefs according to host endianess */
    7375                struct {
     
    7577                        uint8_t value_high;
    7678                };
    77                 uint16_t value;
    7879        };
    7980        /** Auxiliary parameter to the request.
     
    8586} __attribute__ ((packed)) usb_device_request_setup_packet_t;
    8687
     88int usb_control_request_set(usb_endpoint_pipe_t *,
     89    usb_request_type_t, usb_request_recipient_t, uint8_t,
     90    uint16_t, uint16_t, void *, size_t);
    8791
    88 int usb_drv_req_get_status(int, usb_address_t, usb_request_recipient_t,
    89     uint16_t, uint16_t *);
    90 int usb_drv_req_clear_feature(int, usb_address_t, usb_request_recipient_t,
    91     uint16_t, uint16_t);
    92 int usb_drv_req_set_feature(int, usb_address_t, usb_request_recipient_t,
    93     uint16_t, uint16_t);
    94 int usb_drv_req_set_address(int, usb_address_t, usb_address_t);
    95 int usb_drv_req_get_descriptor(int, usb_address_t, usb_request_type_t,
    96     uint8_t, uint8_t, uint16_t, void *, size_t, size_t *);
    97 int usb_drv_req_get_device_descriptor(int, usb_address_t,
     92int usb_control_request_get(usb_endpoint_pipe_t *,
     93    usb_request_type_t, usb_request_recipient_t, uint8_t,
     94    uint16_t, uint16_t, void *, size_t, size_t *);
     95
     96int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t);
     97int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t,
     98    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t,
     99    size_t *);
     100int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t *, usb_request_type_t,
     101    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void **, size_t *);
     102int usb_request_get_device_descriptor(usb_endpoint_pipe_t *,
    98103    usb_standard_device_descriptor_t *);
    99 int usb_drv_req_get_bare_configuration_descriptor(int, usb_address_t, int,
     104int usb_request_get_bare_configuration_descriptor(usb_endpoint_pipe_t *, int,
    100105    usb_standard_configuration_descriptor_t *);
    101 int usb_drv_req_get_full_configuration_descriptor(int, usb_address_t, int,
     106int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *, int,
    102107    void *, size_t, size_t *);
    103 int usb_drv_req_set_descriptor(int, usb_address_t, uint8_t, uint8_t, uint16_t,
    104     void *, size_t);
    105 int usb_drv_req_get_configuration(int, usb_address_t, uint8_t *);
    106 int usb_drv_req_set_configuration(int, usb_address_t, uint8_t);
    107 int usb_drv_req_get_interface(int, usb_address_t, uint16_t, uint8_t *);
    108 int usb_drv_req_set_interface(int, usb_address_t, uint16_t, uint8_t);
     108int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t);
     109
     110int usb_request_get_supported_languages(usb_endpoint_pipe_t *,
     111    l18_win_locales_t **, size_t *);
     112int usb_request_get_string(usb_endpoint_pipe_t *, size_t, l18_win_locales_t,
     113    char **);
    109114
    110115#endif
  • uspace/lib/usb/include/usb/usb.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3737
    3838#include <sys/types.h>
    39 #include <ipc/ipc.h>
     39#include <byteorder.h>
     40
     41/** Convert 16bit value from native (host) endianness to USB endianness. */
     42#define uint16_host2usb(n) host2uint16_t_le((n))
     43
     44/** Convert 32bit value from native (host) endianness to USB endianness. */
     45#define uint32_host2usb(n) host2uint32_t_le((n))
     46
     47/** Convert 16bit value from USB endianness into native (host) one. */
     48#define uint16_usb2host(n) uint16_t_le2host((n))
     49
     50/** Convert 32bit value from USB endianness into native (host) one. */
     51#define uint32_usb2host(n) uint32_t_le2host((n))
     52
    4053
    4154/** USB transfer type. */
     
    5265typedef enum {
    5366        USB_DIRECTION_IN,
    54         USB_DIRECTION_OUT
     67        USB_DIRECTION_OUT,
     68        USB_DIRECTION_BOTH
    5569} usb_direction_t;
     70
     71/** USB speeds. */
     72typedef enum {
     73        /** USB 1.1 low speed (1.5Mbits/s). */
     74        USB_SPEED_LOW,
     75        /** USB 1.1 full speed (12Mbits/s). */
     76        USB_SPEED_FULL,
     77        /** USB 2.0 high speed (480Mbits/s). */
     78        USB_SPEED_HIGH
     79} usb_speed_t;
    5680
    5781/** USB request type target. */
     
    6892        USB_REQUEST_RECIPIENT_ENDPOINT = 2
    6993} usb_request_recipient_t;
    70 
    71 /** USB transaction outcome. */
    72 typedef enum {
    73         USB_OUTCOME_OK,
    74         USB_OUTCOME_CRCERROR,
    75         USB_OUTCOME_BABBLE
    76 } usb_transaction_outcome_t;
    77 
    78 const char * usb_str_transaction_outcome(usb_transaction_outcome_t o);
    7994
    8095/** USB address type.
  • uspace/lib/usb/src/addrkeep.c

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * @brief Address keeping.
    3434 */
    35 #include <usb/hcd.h>
     35#include <usb/addrkeep.h>
    3636#include <errno.h>
    3737#include <assert.h>
     
    149149                        &addresses->default_condvar_guard);
    150150        }
     151        addresses->default_available = false;
    151152        fibril_mutex_unlock(&addresses->default_condvar_guard);
    152153}
  • uspace/lib/usb/src/class.c

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/src/debug.c

    r976f546 r19a1800  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2010-2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    6060/** Mutex guard for the list of all tags. */
    6161static FIBRIL_MUTEX_INITIALIZE(tag_list_guard);
     62
     63/** Level of logging messages. */
     64static usb_log_level_t log_level = USB_LOG_LEVEL_WARNING;
     65/** Prefix for logging messages. */
     66static const char *log_prefix = "usb";
     67/** Serialization mutex for logging functions. */
     68static FIBRIL_MUTEX_INITIALIZE(log_serializer);
     69static FILE *log_stream = NULL;
    6270
    6371/** Find or create new tag with given name.
     
    155163}
    156164
     165/** Enable logging.
     166 *
     167 * @param level Maximal enabled level (including this one).
     168 * @param message_prefix Prefix for each printed message.
     169 */
     170void usb_log_enable(usb_log_level_t level, const char *message_prefix)
     171{
     172        log_prefix = message_prefix;
     173        log_level = level;
     174        if (log_stream == NULL) {
     175                char *fname;
     176                int rc = asprintf(&fname, "/log/%s", message_prefix);
     177                if (rc > 0) {
     178                        log_stream = fopen(fname, "w");
     179                        free(fname);
     180                }
     181        }
     182}
     183
     184
     185static const char *log_level_name(usb_log_level_t level)
     186{
     187        switch (level) {
     188                case USB_LOG_LEVEL_FATAL:
     189                        return " FATAL";
     190                case USB_LOG_LEVEL_ERROR:
     191                        return " ERROR";
     192                case USB_LOG_LEVEL_WARNING:
     193                        return " WARN";
     194                case USB_LOG_LEVEL_INFO:
     195                        return " info";
     196                default:
     197                        return "";
     198        }
     199}
     200
     201/** Print logging message.
     202 *
     203 * @param level Verbosity level of the message.
     204 * @param format Formatting directive.
     205 */
     206void usb_log_printf(usb_log_level_t level, const char *format, ...)
     207{
     208        FILE *screen_stream = NULL;
     209        switch (level) {
     210                case USB_LOG_LEVEL_FATAL:
     211                case USB_LOG_LEVEL_ERROR:
     212                        screen_stream = stderr;
     213                        break;
     214                default:
     215                        screen_stream = stdout;
     216                        break;
     217        }
     218        assert(screen_stream != NULL);
     219
     220        va_list args;
     221
     222        /*
     223         * Serialize access to log files.
     224         * Always print to log file, to screen print only when the enabled
     225         * log level is high enough.
     226         */
     227        fibril_mutex_lock(&log_serializer);
     228
     229        const char *level_name = log_level_name(level);
     230
     231        if (log_stream != NULL) {
     232                va_start(args, format);
     233
     234                fprintf(log_stream, "[%s]%s: ", log_prefix, level_name);
     235                vfprintf(log_stream, format, args);
     236                fflush(log_stream);
     237
     238                va_end(args);
     239        }
     240
     241        if (level <= log_level) {
     242                va_start(args, format);
     243
     244                fprintf(screen_stream, "[%s]%s: ", log_prefix, level_name);
     245                vfprintf(screen_stream, format, args);
     246                fflush(screen_stream);
     247
     248                va_end(args);
     249        }
     250
     251        fibril_mutex_unlock(&log_serializer);
     252}
    157253
    158254/**
  • uspace/lib/usb/src/dp.c

    r976f546 r19a1800  
    3737#include <str_error.h>
    3838#include <errno.h>
    39 #include <usb/usbdrv.h>
     39#include <assert.h>
    4040#include <bool.h>
    4141#include <usb/dp.h>
     42#include <usb/descriptor.h>
     43
     44#define NESTING(parentname, childname) \
     45        { \
     46                .child = USB_DESCTYPE_##childname, \
     47                .parent = USB_DESCTYPE_##parentname, \
     48        }
     49#define LAST_NESTING { -1, -1 }
     50
     51/** Nesting of standard USB descriptors. */
     52usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[] = {
     53        NESTING(CONFIGURATION, INTERFACE),
     54        NESTING(INTERFACE, ENDPOINT),
     55        NESTING(INTERFACE, HUB),
     56        NESTING(INTERFACE, HID),
     57        NESTING(HID, HID_REPORT),
     58        LAST_NESTING
     59};
     60
     61#undef NESTING
     62#undef LAST_NESTING
    4263
    4364/** Tells whether pointer points inside descriptor data.
     
    4566 * @param data Parser data.
    4667 * @param ptr Pointer to be verified.
    47  * @return Whether @ptr points inside <code>data->data</code> field.
     68 * @return Whether @p ptr points inside <code>data->data</code> field.
    4869 */
    4970static bool is_valid_descriptor_pointer(usb_dp_parser_data_t *data,
  • uspace/lib/usb/src/hcdhubd_private.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/src/hidparser.c

    r976f546 r19a1800  
    196196}
    197197
    198 /** Free the HID report parser structure
    199  *
    200  * @param parser Opaque HID report parser structure
    201  * @return Error code
    202  */
    203 int usb_hid_free_report_parser(usb_hid_report_parser_t *parser)
    204 {
    205 
    206         return EOK;
    207 }
    208 
    209198
    210199/**
     
    237226
    238227        if (size != 8) {
    239                 return -1;//ERANGE;
     228                return ERANGE;
    240229        }
    241230
     
    540529}
    541530
    542 /**
    543  * Frees complete structure of report parser
    544  *
    545  * @param Parser to free
     531/** Free the HID report parser structure
     532 *
     533 * @param parser Opaque HID report parser structure
    546534 * @return Error code
    547535 */
     
    561549 * @}
    562550 */
    563 
    564 
    565 /**
    566  * @}
    567  */
  • uspace/lib/usb/src/recognise.c

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * @brief Functions for recognising kind of attached devices.
    3434 */
    35 #include <usb_iface.h>
    36 #include <usb/usbdrv.h>
     35#include <sys/types.h>
     36#include <fibril_synch.h>
     37#include <usb/pipes.h>
     38#include <usb/recognise.h>
     39#include <usb/ddfiface.h>
     40#include <usb/request.h>
    3741#include <usb/classes/classes.h>
    3842#include <stdio.h>
    3943#include <errno.h>
    40 
    41 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
    42 {
    43         assert(dev);
    44         assert(dev->parent != NULL);
    45 
    46         device_t *parent = dev->parent;
    47 
    48         if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
    49                 usb_iface_t *usb_iface
    50                     = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
    51                 assert(usb_iface != NULL);
    52                 if (usb_iface->get_hc_handle) {
    53                         int rc = usb_iface->get_hc_handle(parent, handle);
    54                         return rc;
    55                 }
    56         }
    57 
    58         return ENOTSUP;
    59 }
    60 
    61 static usb_iface_t usb_iface = {
    62         .get_hc_handle = usb_iface_get_hc_handle
    63 };
    64 
    65 static device_ops_t child_ops = {
    66         .interfaces[USB_DEV_IFACE] = &usb_iface
     44#include <assert.h>
     45
     46static size_t device_name_index = 0;
     47static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
     48
     49ddf_dev_ops_t child_ops = {
     50        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
    6751};
    6852
     
    129113}
    130114
     115#define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \
     116        do { \
     117                int __rc = usb_add_match_id((match_ids), (score), \
     118                    format, ##__VA_ARGS__); \
     119                if (__rc != EOK) { \
     120                        return __rc; \
     121                } \
     122        } while (0)
     123
     124/** Create device match ids based on its interface.
     125 *
     126 * @param[in] descriptor Interface descriptor.
     127 * @param[out] matches Initialized list of match ids.
     128 * @return Error code (the two mentioned are not the only ones).
     129 * @retval EINVAL Invalid input parameters (expects non NULL pointers).
     130 * @retval ENOENT Interface does not specify class.
     131 */
     132int usb_device_create_match_ids_from_interface(
     133    const usb_standard_device_descriptor_t *desc_device,
     134    const usb_standard_interface_descriptor_t *desc_interface,
     135    match_id_list_t *matches)
     136{
     137        if (desc_interface == NULL) {
     138                return EINVAL;
     139        }
     140        if (matches == NULL) {
     141                return EINVAL;
     142        }
     143
     144        if (desc_interface->interface_class == USB_CLASS_USE_INTERFACE) {
     145                return ENOENT;
     146        }
     147
     148        const char *classname = usb_str_class(desc_interface->interface_class);
     149        assert(classname != NULL);
     150
     151#define IFACE_PROTOCOL_FMT "interface&class=%s&subclass=0x%02x&protocol=0x%02x"
     152#define IFACE_PROTOCOL_ARGS classname, desc_interface->interface_subclass, \
     153    desc_interface->interface_protocol
     154
     155#define IFACE_SUBCLASS_FMT "interface&class=%s&subclass=0x%02x"
     156#define IFACE_SUBCLASS_ARGS classname, desc_interface->interface_subclass
     157
     158#define IFACE_CLASS_FMT "interface&class=%s"
     159#define IFACE_CLASS_ARGS classname
     160
     161#define VENDOR_RELEASE_FMT "vendor=0x%04x&product=0x%04x&release=" BCD_FMT
     162#define VENDOR_RELEASE_ARGS desc_device->vendor_id, desc_device->product_id, \
     163    BCD_ARGS(desc_device->device_version)
     164
     165#define VENDOR_PRODUCT_FMT "vendor=0x%04x&product=0x%04x"
     166#define VENDOR_PRODUCT_ARGS desc_device->vendor_id, desc_device->product_id
     167
     168#define VENDOR_ONLY_FMT "vendor=0x%04x"
     169#define VENDOR_ONLY_ARGS desc_device->vendor_id
     170
     171        /*
     172         * If the vendor is specified, create match ids with vendor with
     173         * higher score.
     174         * Then the same ones without the vendor part.
     175         */
     176        if ((desc_device != NULL) && (desc_device->vendor_id != 0)) {
     177                /* First, interface matches with device release number. */
     178                ADD_MATCHID_OR_RETURN(matches, 250,
     179                    "usb&" VENDOR_RELEASE_FMT "&" IFACE_PROTOCOL_FMT,
     180                    VENDOR_RELEASE_ARGS, IFACE_PROTOCOL_ARGS);
     181                ADD_MATCHID_OR_RETURN(matches, 240,
     182                    "usb&" VENDOR_RELEASE_FMT "&" IFACE_SUBCLASS_FMT,
     183                    VENDOR_RELEASE_ARGS, IFACE_SUBCLASS_ARGS);
     184                ADD_MATCHID_OR_RETURN(matches, 230,
     185                    "usb&" VENDOR_RELEASE_FMT "&" IFACE_CLASS_FMT,
     186                    VENDOR_RELEASE_ARGS, IFACE_CLASS_ARGS);
     187
     188                /* Next, interface matches without release number. */
     189                ADD_MATCHID_OR_RETURN(matches, 220,
     190                    "usb&" VENDOR_PRODUCT_FMT "&" IFACE_PROTOCOL_FMT,
     191                    VENDOR_PRODUCT_ARGS, IFACE_PROTOCOL_ARGS);
     192                ADD_MATCHID_OR_RETURN(matches, 210,
     193                    "usb&" VENDOR_PRODUCT_FMT "&" IFACE_SUBCLASS_FMT,
     194                    VENDOR_PRODUCT_ARGS, IFACE_SUBCLASS_ARGS);
     195                ADD_MATCHID_OR_RETURN(matches, 200,
     196                    "usb&" VENDOR_PRODUCT_FMT "&" IFACE_CLASS_FMT,
     197                    VENDOR_PRODUCT_ARGS, IFACE_CLASS_ARGS);
     198
     199                /* Finally, interface matches with only vendor. */
     200                ADD_MATCHID_OR_RETURN(matches, 190,
     201                    "usb&" VENDOR_ONLY_FMT "&" IFACE_PROTOCOL_FMT,
     202                    VENDOR_ONLY_ARGS, IFACE_PROTOCOL_ARGS);
     203                ADD_MATCHID_OR_RETURN(matches, 180,
     204                    "usb&" VENDOR_ONLY_FMT "&" IFACE_SUBCLASS_FMT,
     205                    VENDOR_ONLY_ARGS, IFACE_SUBCLASS_ARGS);
     206                ADD_MATCHID_OR_RETURN(matches, 170,
     207                    "usb&" VENDOR_ONLY_FMT "&" IFACE_CLASS_FMT,
     208                    VENDOR_ONLY_ARGS, IFACE_CLASS_ARGS);
     209        }
     210
     211        /* Now, the same but without any vendor specification. */
     212        ADD_MATCHID_OR_RETURN(matches, 160,
     213            "usb&" IFACE_PROTOCOL_FMT,
     214            IFACE_PROTOCOL_ARGS);
     215        ADD_MATCHID_OR_RETURN(matches, 150,
     216            "usb&" IFACE_SUBCLASS_FMT,
     217            IFACE_SUBCLASS_ARGS);
     218        ADD_MATCHID_OR_RETURN(matches, 140,
     219            "usb&" IFACE_CLASS_FMT,
     220            IFACE_CLASS_ARGS);
     221
     222#undef IFACE_PROTOCOL_FMT
     223#undef IFACE_PROTOCOL_ARGS
     224#undef IFACE_SUBCLASS_FMT
     225#undef IFACE_SUBCLASS_ARGS
     226#undef IFACE_CLASS_FMT
     227#undef IFACE_CLASS_ARGS
     228#undef VENDOR_RELEASE_FMT
     229#undef VENDOR_RELEASE_ARGS
     230#undef VENDOR_PRODUCT_FMT
     231#undef VENDOR_PRODUCT_ARGS
     232#undef VENDOR_ONLY_FMT
     233#undef VENDOR_ONLY_ARGS
     234
     235        return EOK;
     236}
     237
    131238/** Create DDF match ids from USB device descriptor.
    132239 *
     
    135242 * @return Error code.
    136243 */
    137 int usb_drv_create_match_ids_from_device_descriptor(
    138     match_id_list_t *matches,
    139     const usb_standard_device_descriptor_t *device_descriptor)
     244int usb_device_create_match_ids_from_device_descriptor(
     245    const usb_standard_device_descriptor_t *device_descriptor,
     246    match_id_list_t *matches)
    140247{
    141         int rc;
    142        
    143248        /*
    144249         * Unless the vendor id is 0, the pair idVendor-idProduct
     
    147252        if (device_descriptor->vendor_id != 0) {
    148253                /* First, with release number. */
    149                 rc = usb_add_match_id(matches, 100,
    150                     "usb&vendor=%d&product=%d&release=" BCD_FMT,
     254                ADD_MATCHID_OR_RETURN(matches, 100,
     255                    "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
    151256                    (int) device_descriptor->vendor_id,
    152257                    (int) device_descriptor->product_id,
    153258                    BCD_ARGS(device_descriptor->device_version));
    154                 if (rc != EOK) {
    155                         return rc;
    156                 }
    157259               
    158260                /* Next, without release number. */
    159                 rc = usb_add_match_id(matches, 90, "usb&vendor=%d&product=%d",
     261                ADD_MATCHID_OR_RETURN(matches, 90,
     262                    "usb&vendor=0x%04x&product=0x%04x",
    160263                    (int) device_descriptor->vendor_id,
    161264                    (int) device_descriptor->product_id);
    162                 if (rc != EOK) {
    163                         return rc;
    164                 }
    165265        }       
    166266
    167267        /*
    168268         * If the device class points to interface we skip adding
    169          * class directly.
     269         * class directly but we add a multi interface device.
    170270         */
    171271        if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
    172                 rc = usb_add_match_id(matches, 50, "usb&class=%s",
     272                ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
    173273                    usb_str_class(device_descriptor->device_class));
    174                 if (rc != EOK) {
    175                         return rc;
    176                 }
     274        } else {
     275                ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid");
    177276        }
    178277       
     
    180279}
    181280
    182 /** Create DDF match ids from USB configuration descriptor.
    183  * The configuration descriptor is expected to be in the complete form,
    184  * i.e. including interface, endpoint etc. descriptors.
    185  *
    186  * @param matches List of match ids to extend.
    187  * @param config_descriptor Configuration descriptor returned by given device.
    188  * @param total_size Size of the @p config_descriptor.
     281
     282/** Create match ids describing attached device.
     283 *
     284 * @warning The list of match ids @p matches may change even when
     285 * function exits with error.
     286 *
     287 * @param ctrl_pipe Control pipe to given device (session must be already
     288 *      started).
     289 * @param matches Initialized list of match ids.
    189290 * @return Error code.
    190291 */
    191 int usb_drv_create_match_ids_from_configuration_descriptor(
    192     match_id_list_t *matches,
    193     const void *config_descriptor, size_t total_size)
     292int usb_device_create_match_ids(usb_endpoint_pipe_t *ctrl_pipe,
     293    match_id_list_t *matches)
    194294{
    195         /*
    196          * Iterate through config descriptor to find the interface
    197          * descriptors.
    198          */
    199         size_t position = sizeof(usb_standard_configuration_descriptor_t);
    200         while (position + 1 < total_size) {
    201                 uint8_t *current_descriptor
    202                     = ((uint8_t *) config_descriptor) + position;
    203                 uint8_t cur_descr_len = current_descriptor[0];
    204                 uint8_t cur_descr_type = current_descriptor[1];
    205                
    206                 position += cur_descr_len;
    207                
    208                 if (cur_descr_type != USB_DESCTYPE_INTERFACE) {
    209                         continue;
    210                 }
    211                
    212                 /*
    213                  * Finally, we found an interface descriptor.
    214                  */
    215                 usb_standard_interface_descriptor_t *interface
    216                     = (usb_standard_interface_descriptor_t *)
    217                     current_descriptor;
    218                
    219                 int rc = usb_add_match_id(matches, 50,
    220                     "usb&interface&class=%s",
    221                     usb_str_class(interface->interface_class));
    222                 if (rc != EOK) {
    223                         return rc;
    224                 }
    225         }
    226        
     295        int rc;
     296        /*
     297         * Retrieve device descriptor and add matches from it.
     298         */
     299        usb_standard_device_descriptor_t device_descriptor;
     300
     301        rc = usb_request_get_device_descriptor(ctrl_pipe, &device_descriptor);
     302        if (rc != EOK) {
     303                return rc;
     304        }
     305
     306        rc = usb_device_create_match_ids_from_device_descriptor(
     307            &device_descriptor, matches);
     308        if (rc != EOK) {
     309                return rc;
     310        }
     311
    227312        return EOK;
    228313}
    229314
    230 /** Add match ids based on configuration descriptor.
    231  *
    232  * @param hc Open phone to host controller.
    233  * @param matches Match ids list to add matches to.
    234  * @param address USB address of the attached device.
     315/** Probe for device kind and register it in devman.
     316 *
     317 * @param[in] address Address of the (unknown) attached device.
     318 * @param[in] hc_handle Handle of the host controller.
     319 * @param[in] parent Parent device.
     320 * @param[out] child_handle Handle of the child device.
    235321 * @return Error code.
    236322 */
    237 static int usb_add_config_descriptor_match_ids(int hc,
    238     match_id_list_t *matches, usb_address_t address,
    239     int config_count)
     323int usb_device_register_child_in_devman(usb_address_t address,
     324    devman_handle_t hc_handle,
     325    ddf_dev_t *parent, devman_handle_t *child_handle,
     326    ddf_dev_ops_t *dev_ops, void *dev_data, ddf_fun_t **child_fun)
    240327{
    241         int final_rc = EOK;
    242        
    243         int config_index;
    244         for (config_index = 0; config_index < config_count; config_index++) {
    245                 int rc;
    246                 usb_standard_configuration_descriptor_t config_descriptor;
    247                 rc = usb_drv_req_get_bare_configuration_descriptor(hc,
    248                     address,  config_index, &config_descriptor);
    249                 if (rc != EOK) {
    250                         final_rc = rc;
    251                         continue;
    252                 }
    253 
    254                 size_t full_config_descriptor_size;
    255                 void *full_config_descriptor
    256                     = malloc(config_descriptor.total_length);
    257                 rc = usb_drv_req_get_full_configuration_descriptor(hc,
    258                     address, config_index,
    259                     full_config_descriptor, config_descriptor.total_length,
    260                     &full_config_descriptor_size);
    261                 if (rc != EOK) {
    262                         final_rc = rc;
    263                         continue;
    264                 }
    265                 if (full_config_descriptor_size
    266                     != config_descriptor.total_length) {
    267                         final_rc = ERANGE;
    268                         continue;
    269                 }
    270                
    271                 rc = usb_drv_create_match_ids_from_configuration_descriptor(
    272                     matches,
    273                     full_config_descriptor, full_config_descriptor_size);
    274                 if (rc != EOK) {
    275                         final_rc = rc;
    276                         continue;
    277                 }
    278                
    279         }
    280        
    281         return final_rc;
    282 }
    283 
    284 /** Create match ids describing attached device.
    285  *
    286  * @warning The list of match ids @p matches may change even when
    287  * function exits with error.
    288  *
    289  * @param hc Open phone to host controller.
    290  * @param matches Initialized list of match ids.
    291  * @param address USB address of the attached device.
    292  * @return Error code.
    293  */
    294 int usb_drv_create_device_match_ids(int hc, match_id_list_t *matches,
    295     usb_address_t address)
    296 {
    297         int rc;
    298        
    299         /*
    300          * Retrieve device descriptor and add matches from it.
    301          */
    302         usb_standard_device_descriptor_t device_descriptor;
    303 
    304         rc = usb_drv_req_get_device_descriptor(hc, address,
    305             &device_descriptor);
    306         if (rc != EOK) {
    307                 return rc;
    308         }
    309        
    310         rc = usb_drv_create_match_ids_from_device_descriptor(matches,
    311             &device_descriptor);
    312         if (rc != EOK) {
    313                 return rc;
    314         }
    315        
    316         /*
    317          * Go through all configurations and add matches
    318          * based on interface class.
    319          */
    320         rc = usb_add_config_descriptor_match_ids(hc, matches,
    321             address, device_descriptor.configuration_count);
    322         if (rc != EOK) {
    323                 return rc;
    324         }
    325 
    326         /*
    327          * As a fallback, provide the simplest match id possible.
    328          */
    329         rc = usb_add_match_id(matches, 1, "usb&fallback");
    330         if (rc != EOK) {
    331                 return rc;
    332         }
    333 
    334         return EOK;
    335 }
    336 
    337 
    338 /** Probe for device kind and register it in devman.
    339  *
    340  * @param hc Open phone to the host controller.
    341  * @param parent Parent device.
    342  * @param address Address of the (unknown) attached device.
    343  * @return Error code.
    344  */
    345 int usb_drv_register_child_in_devman(int hc, device_t *parent,
    346     usb_address_t address, devman_handle_t *child_handle)
    347 {
    348         static size_t device_name_index = 0;
    349 
    350         device_t *child = NULL;
     328        size_t this_device_name_index;
     329
     330        fibril_mutex_lock(&device_name_index_mutex);
     331        this_device_name_index = device_name_index;
     332        device_name_index++;
     333        fibril_mutex_unlock(&device_name_index_mutex);
     334
     335        ddf_fun_t *child = NULL;
    351336        char *child_name = NULL;
    352337        int rc;
    353 
    354         child = create_device();
     338        usb_device_connection_t dev_connection;
     339        usb_endpoint_pipe_t ctrl_pipe;
     340
     341        rc = usb_device_connection_initialize(&dev_connection, hc_handle, address);
     342        if (rc != EOK) {
     343                goto failure;
     344        }
     345
     346        rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
     347            &dev_connection);
     348        if (rc != EOK) {
     349                goto failure;
     350        }
     351
     352        /*
     353         * TODO: Once the device driver framework support persistent
     354         * naming etc., something more descriptive could be created.
     355         */
     356        rc = asprintf(&child_name, "usbdev%02zu", this_device_name_index);
     357        if (rc < 0) {
     358                goto failure;
     359        }
     360
     361        child = ddf_fun_create(parent, fun_inner, child_name);
    355362        if (child == NULL) {
    356363                rc = ENOMEM;
     
    358365        }
    359366
    360         /*
    361          * TODO: Once the device driver framework support persistent
    362          * naming etc., something more descriptive could be created.
    363          */
    364         rc = asprintf(&child_name, "usbdev%02zu", device_name_index);
    365         if (rc < 0) {
    366                 goto failure;
    367         }
    368         child->parent = parent;
    369         child->name = child_name;
    370         child->ops = &child_ops;
    371        
    372         rc = usb_drv_create_device_match_ids(hc, &child->match_ids, address);
    373         if (rc != EOK) {
    374                 goto failure;
    375         }
    376 
    377         rc = child_device_register(child, parent);
     367        if (dev_ops != NULL) {
     368                child->ops = dev_ops;
     369        } else {
     370                child->ops = &child_ops;
     371        }
     372
     373        child->driver_data = dev_data;
     374
     375        rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
     376        if (rc != EOK) {
     377                goto failure;
     378        }
     379
     380        rc = usb_device_create_match_ids(&ctrl_pipe, &child->match_ids);
     381        if (rc != EOK) {
     382                goto failure;
     383        }
     384
     385        rc = usb_endpoint_pipe_end_session(&ctrl_pipe);
     386        if (rc != EOK) {
     387                goto failure;
     388        }
     389
     390        rc = ddf_fun_bind(child);
    378391        if (rc != EOK) {
    379392                goto failure;
     
    383396                *child_handle = child->handle;
    384397        }
    385        
    386         device_name_index++;
     398
     399        if (child_fun != NULL) {
     400                *child_fun = child;
     401        }
    387402
    388403        return EOK;
     
    392407                child->name = NULL;
    393408                /* This takes care of match_id deallocation as well. */
    394                 delete_device(child);
     409                ddf_fun_destroy(child);
    395410        }
    396411        if (child_name != NULL) {
     
    399414
    400415        return rc;
    401 
    402416}
    403417
  • uspace/lib/usb/src/usb.c

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    5454}
    5555
    56 /** String representation of USB transaction outcome. */
    57 const char * usb_str_transaction_outcome(usb_transaction_outcome_t o)
    58 {
    59         switch (o) {
    60                 case USB_OUTCOME_OK:
    61                         return "ok";
    62                 case USB_OUTCOME_CRCERROR:
    63                         return "CRC error";
    64                 case USB_OUTCOME_BABBLE:
    65                         return "babble";
    66                 default:
    67                         return "unknown";
    68         }
    69 }
    70 
    71 
    7256/**
    7357 * @}
Note: See TracChangeset for help on using the changeset viewer.