Changeset 400735e in mainline for uspace/lib


Ignore:
Timestamp:
2011-05-28T14:30:58Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3fb5a3e
Parents:
e8f826b (diff), 48141f0 (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 development/ changes

Location:
uspace/lib
Files:
1 added
23 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/Makefile

    re8f826b r400735e  
    4040        generic/remote_usb.c \
    4141        generic/remote_pci.c \
    42         generic/remote_usbhc.c
     42        generic/remote_usbhc.c \
     43        generic/remote_usbhid.c
    4344
    4445include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/drv/generic/dev_iface.c

    re8f826b r400735e  
    4646#include "remote_pci.h"
    4747
     48#include <stdio.h>
     49
    4850static iface_dipatch_table_t remote_ifaces = {
    4951        .ifaces = {
     
    6062{
    6163        assert(is_valid_iface_idx(idx));
     64       
    6265        return remote_ifaces.ifaces[idx];
    6366}
  • uspace/lib/drv/generic/driver.c

    re8f826b r400735e  
    405405                                /* The interface has not such method */
    406406                                printf("%s: driver_connection_gen error - "
    407                                     "invalid interface method.", driver->name);
     407                                    "invalid interface method "
     408                                    "(index %" PRIun ").\n",
     409                                    driver->name, iface_method_idx);
    408410                                async_answer_0(callid, ENOTSUP);
    409411                                break;
  • uspace/lib/drv/generic/remote_usbhid.c

    re8f826b r400735e  
    3636#include <errno.h>
    3737#include <assert.h>
     38#include <stdio.h>
    3839
    3940#include "usbhid_iface.h"
     
    4243static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4344static void remote_usbhid_get_event(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     45static void remote_usbhid_get_report_descriptor_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     46static void remote_usbhid_get_report_descriptor(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4447// static void remote_usbhid_(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4548
     
    4750static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = {
    4851        remote_usbhid_get_event_length,
    49         remote_usbhid_get_event
     52        remote_usbhid_get_event,
     53        remote_usbhid_get_report_descriptor_length,
     54        remote_usbhid_get_report_descriptor
    5055};
    5156
     
    5863};
    5964
    60 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     65//usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    6166
    6267
     
    6469    ipc_callid_t callid, ipc_call_t *call)
    6570{
     71        printf("remote_usbhid_get_event_length()\n");
     72       
    6673        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
    6774
    6875        if (!hid_iface->get_event_length) {
    69                 async_answer_0(callid, ENOTSUP);
    70                 return;
    71         }
    72 
    73         int len = hid_iface->get_event_length(fun);
    74         if (len == 0) {
    75                 len = EEMPTY;
    76         }
    77         if (len < 0) {
    78                 async_answer_0(callid, len);
    79         } else {
    80                 async_answer_1(callid, EOK, len);
    81         }
     76                printf("Get event length not set!\n");
     77                async_answer_0(callid, ENOTSUP);
     78                return;
     79        }
     80
     81        size_t len = hid_iface->get_event_length(fun);
     82//      if (len == 0) {
     83//              len = EEMPTY;
     84//      }
     85        async_answer_1(callid, EOK, len);
     86       
     87//      if (len < 0) {
     88//              async_answer_0(callid, len);
     89//      } else {
     90//              async_answer_1(callid, EOK, len);
     91//      }
    8292}
    8393
     
    100110                return;
    101111        }
    102         /* Check that length is even number. Truncate otherwise. */
    103         if ((len % 2) == 1) {
    104                 len--;
    105         }
     112//      /* Check that length is even number. Truncate otherwise. */
     113//      if ((len % 2) == 1) {
     114//              len--;
     115//      }
    106116        if (len == 0) {
    107117                async_answer_0(data_callid, EINVAL);
    108118                async_answer_0(callid, EINVAL);
     119                return;
    109120        }
    110121
    111122        int rc;
    112123
    113         size_t items = len / 2;
    114         uint16_t *usage_pages_and_usages = malloc(sizeof(uint16_t) * len);
    115         if (usage_pages_and_usages == NULL) {
     124        uint8_t *data = malloc(len);
     125        if (data == NULL) {
    116126                async_answer_0(data_callid, ENOMEM);
    117127                async_answer_0(callid, ENOMEM);
    118         }
    119 
    120         size_t act_items;
    121         int rc = hid_iface->get_event(fun, usage_pages_and_usages,
    122             usage_pages_and_usages + items, items, &act_items, flags);
     128                return;
     129        }
     130
     131        size_t act_length;
     132        int event_nr;
     133        rc = hid_iface->get_event(fun, data, len, &act_length, &event_nr, flags);
    123134        if (rc != EOK) {
    124                 free(usage_pages_and_usages);
     135                free(data);
    125136                async_answer_0(data_callid, rc);
    126137                async_answer_0(callid, rc);
    127         }
    128         if (act_items >= items) {
     138                return;
     139        }
     140        if (act_length >= len) {
    129141                /* This shall not happen. */
    130142                // FIXME: how about an assert here?
    131                 act_items = items;
    132         }
    133 
    134         async_data_read_finalize(data_callid, usage_pages_and_usages,
    135             act_items * 2 * sizeof(uint16_t));
    136 
    137         free(usage_pages_and_usages);
    138 
     143                act_length = len;
     144        }
     145
     146        async_data_read_finalize(data_callid, data, act_length);
     147
     148        free(data);
     149
     150        async_answer_1(callid, EOK, event_nr);
     151}
     152
     153void remote_usbhid_get_report_descriptor_length(ddf_fun_t *fun, void *iface,
     154    ipc_callid_t callid, ipc_call_t *call)
     155{
     156        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
     157
     158        if (!hid_iface->get_report_descriptor_length) {
     159                async_answer_0(callid, ENOTSUP);
     160                return;
     161        }
     162
     163        size_t len = hid_iface->get_report_descriptor_length(fun);
     164        async_answer_1(callid, EOK, (sysarg_t) len);
     165}
     166
     167void remote_usbhid_get_report_descriptor(ddf_fun_t *fun, void *iface,
     168    ipc_callid_t callid, ipc_call_t *call)
     169{
     170        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
     171
     172        if (!hid_iface->get_report_descriptor) {
     173                async_answer_0(callid, ENOTSUP);
     174                return;
     175        }
     176
     177        size_t len;
     178        ipc_callid_t data_callid;
     179        if (!async_data_read_receive(&data_callid, &len)) {
     180                async_answer_0(callid, EINVAL);
     181                return;
     182        }
     183
     184        if (len == 0) {
     185                async_answer_0(data_callid, EINVAL);
     186                async_answer_0(callid, EINVAL);
     187                return;
     188        }
     189
     190        uint8_t *descriptor = malloc(len);
     191        if (descriptor == NULL) {
     192                async_answer_0(data_callid, ENOMEM);
     193                async_answer_0(callid, ENOMEM);
     194                return;
     195        }
     196
     197        size_t act_len = 0;
     198        int rc = hid_iface->get_report_descriptor(fun, descriptor, len,
     199            &act_len);
     200        if (act_len > len) {
     201                rc = ELIMIT;
     202        }
     203        if (rc != EOK) {
     204                free(descriptor);
     205                async_answer_0(data_callid, rc);
     206                async_answer_0(callid, rc);
     207                return;
     208        }
     209
     210        async_data_read_finalize(data_callid, descriptor, act_len);
    139211        async_answer_0(callid, EOK);
    140 }
     212
     213        free(descriptor);
     214}
     215
     216
    141217
    142218/**
  • uspace/lib/drv/include/remote_pci.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_PCI_H_
    3737
    38 remote_iface_t remote_pci_iface;
     38extern remote_iface_t remote_pci_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usb.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USB_H_
    3737
    38 remote_iface_t remote_usb_iface;
     38extern remote_iface_t remote_usb_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usbhc.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USBHC_H_
    3737
    38 remote_iface_t remote_usbhc_iface;
     38extern remote_iface_t remote_usbhc_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usbhid.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USBHID_H_
    3737
    38 remote_iface_t remote_usbhid_iface;
     38extern remote_iface_t remote_usbhid_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/usbhid_iface.h

    re8f826b r400735e  
    4545         * Parameters: none
    4646         * Answer:
    47          * - EOK (expected always as long as device support USB HID interface)
    48          * Parameters of the answer:
    49          * - number of items
     47         * - Size of one report in bytes.
    5048         */
    5149        IPC_M_USBHID_GET_EVENT_LENGTH,
     
    6361         * It is okay if the client requests less data. Extra data must
    6462         * be truncated by the driver.
     63         *
     64         * @todo Change this comment.
    6565         */
    66         IPC_M_USBHID_GET_EVENT
     66        IPC_M_USBHID_GET_EVENT,
     67       
     68        /** Get the size of the report descriptor from the HID device.
     69         *
     70         * Parameters:
     71         * - none
     72         * Answer:
     73         * - EOK - method is implemented (expected always)
     74         * Parameters of the answer:
     75         * - Size of the report in bytes.
     76         */
     77        IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH,
     78       
     79        /** Get the report descriptor from the HID device.
     80         *
     81         * Parameters:
     82         * - none
     83         * The call is followed by data read expecting the descriptor itself.
     84         * Answer:
     85         * - EOK - report descriptor returned.
     86         */
     87        IPC_M_USBHID_GET_REPORT_DESCRIPTOR
    6788} usbhid_iface_funcs_t;
    6889
     
    7596         *
    7697         * @param[in] fun DDF function answering the request.
    77          * @return Number of events or error code.
     98         * @return Size of the event in bytes.
    7899         */
    79100        size_t (*get_event_length)(ddf_fun_t *fun);
     
    87108         * @return Error code.
    88109         */
    89         int (*get_event)(ddf_fun_t *fun, int32_t *buffer, size_t size,
    90             size_t *act_size, unsigned int flags);
     110        int (*get_event)(ddf_fun_t *fun, uint8_t *buffer, size_t size,
     111            size_t *act_size, int *event_nr, unsigned int flags);
     112       
     113        /** Get size of the report descriptor in bytes.
     114         *
     115         * @param[in] fun DDF function answering the request.
     116         * @return Size of the report descriptor in bytes.
     117         */
     118        size_t (*get_report_descriptor_length)(ddf_fun_t *fun);
     119       
     120        /** Get the report descriptor from the HID device.
     121         *
     122         * @param[in] fun DDF function answering the request.
     123         * @param[out] desc Buffer with the report descriptor.
     124         * @param[in] size Size of the allocated @p desc buffer.
     125         * @param[out] act_size Actual size of the report descriptor returned.
     126         * @return Error code.
     127         */
     128        int (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc,
     129            size_t size, size_t *act_size);
    91130} usbhid_iface_t;
    92131
  • uspace/lib/usbdev/src/hub.c

    re8f826b r400735e  
    331331                goto leave_release_free_address;
    332332        }
     333       
     334        usb_hc_connection_close(&hc_conn);
    333335
    334336        /*
  • uspace/lib/usbhid/Makefile

    re8f826b r400735e  
    4141        src/hidpath.c \
    4242        src/hidreport.c \
     43        src/consumer.c \
    4344        src/hidreq.c
    4445
  • uspace/lib/usbhid/include/usb/hid/hid_report_items.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief USB HID parser.
    34  */
    35 #ifndef LIBUSBHID_HID_REPORT_ITEMS_H_
    36 #define LIBUSBHID_HID_REPORT_ITEMS_H_
     33 * @brief USB HID Report descriptor item tags.
     34 */
     35#ifndef LIBUSB_HID_REPORT_ITEMS_H_
     36#define LIBUSB_HID_REPORT_ITEMS_H_
    3737
    3838#include <stdint.h>
    3939
    40 /**
     40/*---------------------------------------------------------------------------*/
     41/*
    4142 * Item prefix
    4243 */
     44
     45/** Returns size of item data in bytes */
    4346#define USB_HID_ITEM_SIZE(data)         ((uint8_t)(data & 0x3))
     47
     48/** Returns item tag */
    4449#define USB_HID_ITEM_TAG(data)          ((uint8_t)((data & 0xF0) >> 4))
     50
     51/** Returns class of item tag */
    4552#define USB_HID_ITEM_TAG_CLASS(data)    ((uint8_t)((data & 0xC) >> 2))
     53
     54/** Returns if the item is the short item or long item. Long items are not
     55 * supported. */
    4656#define USB_HID_ITEM_IS_LONG(data)      (data == 0xFE)
    4757
    48 
    49 /**
     58/*---------------------------------------------------------------------------*/
     59/*
    5060 * Extended usage macros
    5161 */
     62
     63/** Recognizes if the given usage is extended (contains also usage page).  */
    5264#define USB_HID_IS_EXTENDED_USAGE(usage)        ((usage & 0xFFFF0000) != 0)
     65
     66/** Cuts usage page of the extended usage. */
    5367#define USB_HID_EXTENDED_USAGE_PAGE(usage)      ((usage & 0xFFFF0000) >> 16)
     68
     69/** Cuts usage of the extended usage */
    5470#define USB_HID_EXTENDED_USAGE(usage)           (usage & 0xFFFF)
    5571
    56 /**
     72/*---------------------------------------------------------------------------*/
     73/*
    5774 * Input/Output/Feature Item flags
    5875 */
    59 /** Constant (1) / Variable (0) */
     76/**
     77 * Indicates whether the item is data (0) or a constant (1) value. Data
     78 * indicates the item is defining report fields that contain modifiable device
     79 * data. Constant indicates the item is a static read-only field in a report
     80 * and cannot be modified (written) by the host.
     81 */
    6082#define USB_HID_ITEM_FLAG_CONSTANT(flags)       ((flags & 0x1) == 0x1)
    61 /** Variable (1) / Array (0) */
     83
     84/**
     85 * Indicates whether the item creates variable (1) or array (0) data fields in
     86 * reports.
     87 */
    6288#define USB_HID_ITEM_FLAG_VARIABLE(flags)       ((flags & 0x2) == 0x2)
    63 /** Absolute / Relative*/
     89
     90/**
     91 * Indicates whether the data is absolute (0) (based on a fixed origin) or
     92 * relative (1) (indicating the change in value from the last report). Mouse
     93 * devices usually provide relative data, while tablets usually provide
     94 * absolute data.
     95 */
    6496#define USB_HID_ITEM_FLAG_RELATIVE(flags)       ((flags & 0x4) == 0x4)
    65 /** Wrap / No Wrap */
     97
     98/** Indicates whether the data “rolls over” when reaching either the extreme
     99 * high or low value. For example, a dial that can spin freely 360 degrees
     100 * might output values from 0 to 10. If Wrap is indicated, the next value
     101 * reported after passing the 10 position in the increasing direction would be
     102 * 0.
     103 */
    66104#define USB_HID_ITEM_FLAG_WRAP(flags)           ((flags & 0x8) == 0x8)
     105
     106/**
     107 * Indicates whether the raw data from the device has been processed in some
     108 * way, and no longer represents a linear relationship between what is
     109 * measured and the data that is reported.
     110 */
    67111#define USB_HID_ITEM_FLAG_LINEAR(flags)         ((flags & 0x10) == 0x10)
     112
     113/**
     114 * Indicates whether the control has a preferred state to which it will return
     115 * when the user is not physically interacting with the control. Push buttons
     116 * (as opposed to toggle buttons) and self- centering joysticks are examples.
     117 */
    68118#define USB_HID_ITEM_FLAG_PREFERRED(flags)      ((flags & 0x20) == 0x20)
     119
     120/**
     121 * Indicates whether the control has a state in which it is not sending
     122 * meaningful data. One possible use of the null state is for controls that
     123 * require the user to physically interact with the control in order for it to
     124 * report useful data.
     125 */
    69126#define USB_HID_ITEM_FLAG_POSITION(flags)       ((flags & 0x40) == 0x40)
     127
     128/**
     129 * Indicates whether the Feature or Output control's value should be changed
     130 * by the host or not.  Volatile output can change with or without host
     131 * interaction. To avoid synchronization problems, volatile controls should be
     132 * relative whenever possible.
     133 */
    70134#define USB_HID_ITEM_FLAG_VOLATILE(flags)       ((flags & 0x80) == 0x80)
     135
     136/**
     137 * Indicates that the control emits a fixed-size stream of bytes. The contents
     138 * of the data field are determined by the application. The contents of the
     139 * buffer are not interpreted as a single numeric quantity. Report data
     140 * defined by a Buffered Bytes item must be aligned on an 8-bit boundary.
     141 */
    71142#define USB_HID_ITEM_FLAG_BUFFERED(flags)       ((flags & 0x100) == 0x100)
    72143
     144/*---------------------------------------------------------------------------*/
     145
    73146/* MAIN ITEMS */
    74 #define USB_HID_TAG_CLASS_MAIN                          0x0
    75 #define USB_HID_REPORT_TAG_INPUT                        0x8
    76 #define USB_HID_REPORT_TAG_OUTPUT                       0x9
    77 #define USB_HID_REPORT_TAG_FEATURE                      0xB
     147
     148/**
     149 * Main items are used to either define or group certain types of data fields
     150 * within a Report descriptor.
     151 */
     152#define USB_HID_TAG_CLASS_MAIN                  0x0
     153
     154/**
     155 * An Input item describes information about the data provided by one or more
     156 * physical controls. An application can use this information to interpret the
     157 * data provided by the device. All data fields defined in a single item share
     158 * an identical data format.
     159 */
     160#define USB_HID_REPORT_TAG_INPUT                0x8
     161
     162/**
     163 * The Output item is used to define an output data field in a report. This
     164 * item is similar to an Input item except it describes data sent to the
     165 * device—for example, LED states.
     166 */
     167#define USB_HID_REPORT_TAG_OUTPUT               0x9
     168
     169/**
     170 * Feature items describe device configuration information that can be sent to
     171 * the device.
     172 */
     173#define USB_HID_REPORT_TAG_FEATURE              0xB
     174
     175/**
     176 * A Collection item identifies a relationship between two or more data
     177 * (Input, Output, or Feature.)
     178 */
    78179#define USB_HID_REPORT_TAG_COLLECTION           0xA
     180
     181/**
     182 * While the Collection item opens a collection of data, the End Collection
     183 * item closes a collection.
     184 */
    79185#define USB_HID_REPORT_TAG_END_COLLECTION       0xC
    80186
     187/*---------------------------------------------------------------------------*/
     188
    81189/* GLOBAL ITEMS */
    82 #define USB_HID_TAG_CLASS_GLOBAL                        0x1
     190
     191/**
     192 * Global items describe rather than define data from a control.
     193 */
     194#define USB_HID_TAG_CLASS_GLOBAL                0x1
     195
     196/**
     197 * Unsigned integer specifying the current Usage Page. Since a usage are 32
     198 * bit values, Usage Page items can be used to conserve space in a report
     199 * descriptor by setting the high order 16 bits of a subsequent usages. Any
     200 * usage that follows which is defines 16 bits or less is interpreted as a
     201 * Usage ID and concatenated with the Usage Page to form a 32 bit Usage.
     202 */
    83203#define USB_HID_REPORT_TAG_USAGE_PAGE           0x0
     204
     205/**
     206 * Extent value in logical units. This is the minimum value that a variable
     207 * or array item will report. For example, a mouse reporting x position values
     208 * from 0 to 128 would have a Logical Minimum of 0 and a Logical Maximum of
     209 * 128.
     210 */
    84211#define USB_HID_REPORT_TAG_LOGICAL_MINIMUM      0x1
     212
     213/**
     214 * Extent value in logical units. This is the maximum value that a variable
     215 * or array item will report.
     216 */
    85217#define USB_HID_REPORT_TAG_LOGICAL_MAXIMUM      0x2
    86 #define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM 0x3
    87 #define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM 0x4
     218
     219/**
     220 * Minimum value for the physical extent of a variable item. This represents
     221 * the Logical Minimum with units applied to it.
     222 */
     223#define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM     0x3
     224
     225/**
     226 * Maximum value for the physical extent of a variable item.
     227 */
     228#define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM     0x4
     229
     230/**
     231 * Value of the unit exponent in base 10. See the table later in this section
     232 * for more information.
     233 */
    88234#define USB_HID_REPORT_TAG_UNIT_EXPONENT        0x5
    89 #define USB_HID_REPORT_TAG_UNIT                         0x6
     235
     236/**
     237 * Unit values.
     238 */
     239#define USB_HID_REPORT_TAG_UNIT                 0x6
     240
     241/**
     242 * Unsigned integer specifying the size of the report fields in bits. This
     243 * allows the parser to build an item map for the report handler to use.
     244 */
    90245#define USB_HID_REPORT_TAG_REPORT_SIZE          0x7
     246
     247/**
     248 * Unsigned value that specifies the Report ID. If a Report ID tag is used
     249 * anywhere in Report descriptor, all data reports for the device are preceded
     250 * by a single byte ID field. All items succeeding the first Report ID tag but
     251 * preceding a second Report ID tag are included in a report prefixed by a
     252 * 1-byte ID. All items succeeding the second but preceding a third Report ID
     253 * tag are included in a second report prefixed by a second ID, and so on.
     254 */
    91255#define USB_HID_REPORT_TAG_REPORT_ID            0x8
     256
     257/**
     258 * Unsigned integer specifying the number of data fields for the item;
     259 * determines how many fields are included in the report for this particular
     260 * item (and consequently how many bits are added to the report).
     261 */
    92262#define USB_HID_REPORT_TAG_REPORT_COUNT         0x9
    93 #define USB_HID_REPORT_TAG_PUSH                         0xA
    94 #define USB_HID_REPORT_TAG_POP                          0xB
    95 
     263
     264/**
     265 * Places a copy of the global item state table on the stack.
     266 */
     267#define USB_HID_REPORT_TAG_PUSH                 0xA
     268
     269/**
     270 * Replaces the item state table with the top structure from the stack.
     271 */
     272#define USB_HID_REPORT_TAG_POP                  0xB
     273
     274/*---------------------------------------------------------------------------*/
    96275
    97276/* LOCAL ITEMS */
    98 #define USB_HID_TAG_CLASS_LOCAL                                 0x2
    99 #define USB_HID_REPORT_TAG_USAGE                                0x0
    100 #define USB_HID_REPORT_TAG_USAGE_MINIMUM                0x1
    101 #define USB_HID_REPORT_TAG_USAGE_MAXIMUM                0x2
    102 #define USB_HID_REPORT_TAG_DESIGNATOR_INDEX             0x3
     277
     278/**
     279 * Local item tags define characteristics of controls. These items do not
     280 * carry over to the next Main item. If a Main item defines more than one
     281 * control, it may be preceded by several similar Local item tags. For
     282 * example, an Input item may have several Usage tags associated with it, one
     283 * for each control.
     284 */
     285#define USB_HID_TAG_CLASS_LOCAL                 0x2
     286
     287/**
     288 * Usage index for an item usage; represents a suggested usage for the item or
     289 * collection. In the case where an item represents multiple controls, a Usage
     290 * tag may suggest a usage for every variable or element in an array.
     291 */
     292#define USB_HID_REPORT_TAG_USAGE                0x0
     293
     294/**
     295 * Defines the starting usage associated with an array or bitmap.
     296 */
     297#define USB_HID_REPORT_TAG_USAGE_MINIMUM        0x1
     298
     299/**
     300 * Defines the ending usage associated with an array or bitmap.
     301 */
     302#define USB_HID_REPORT_TAG_USAGE_MAXIMUM        0x2
     303
     304/**
     305 * Determines the body part used for a control. Index points to a designator
     306 * in the Physical descriptor.
     307 */
     308#define USB_HID_REPORT_TAG_DESIGNATOR_INDEX     0x3
     309
     310/**
     311 * Defines the index of the starting designator associated with an array or
     312 * bitmap.
     313 */
    103314#define USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM   0x4
     315
     316/**
     317 * Defines the index of the ending designator associated with an array or
     318 * bitmap.
     319 */
    104320#define USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM   0x5
    105 #define USB_HID_REPORT_TAG_STRING_INDEX                 0x7
    106 #define USB_HID_REPORT_TAG_STRING_MINIMUM               0x8
    107 #define USB_HID_REPORT_TAG_STRING_MAXIMUM               0x9
    108 #define USB_HID_REPORT_TAG_DELIMITER                    0xA
     321
     322/**
     323 * String index for a String descriptor; allows a string to be associated with
     324 * a particular item or control.
     325 */
     326#define USB_HID_REPORT_TAG_STRING_INDEX         0x7
     327
     328/**
     329 * Specifies the first string index when assigning a group of sequential
     330 * strings to controls in an array or bitmap.
     331 */
     332#define USB_HID_REPORT_TAG_STRING_MINIMUM       0x8
     333
     334/**
     335 * Specifies the last string index when assigning a group of sequential
     336 * strings to controls in an array or bitmap.
     337 */
     338#define USB_HID_REPORT_TAG_STRING_MAXIMUM       0x9
     339
     340/**
     341 * Defines the beginning or end of a set of local items (1 = open set, 0 =
     342 * close set).
     343 *
     344 * Usages other than the first (most preferred) usage defined are not
     345 * accessible by system software.
     346 */
     347#define USB_HID_REPORT_TAG_DELIMITER            0xA
     348
     349/*---------------------------------------------------------------------------*/
    109350
    110351#endif
  • uspace/lib/usbhid/include/usb/hid/hiddescriptor.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * USB HID report descriptor and report data parser
    3434 */
    35 #ifndef LIBUSBHID_HIDDESCRIPTOR_H_
    36 #define LIBUSBHID_HIDDESCRIPTOR_H_
     35#ifndef LIBUSB_HIDDESCRIPTOR_H_
     36#define LIBUSB_HIDDESCRIPTOR_H_
    3737
    3838#include <stdint.h>
     
    4242#include <usb/hid/hidtypes.h>
    4343
     44int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
     45                const uint8_t *data, size_t size);
    4446
    45 /*
    46  * Descriptor parser functions
    47  */
    48 
    49 /** */
    50 int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
    51                                     const uint8_t *data, size_t size);
    52 
    53 /** */
    5447void usb_hid_free_report(usb_hid_report_t *report);
    5548
    56 /** */
    5749void usb_hid_descriptor_print(usb_hid_report_t *report);
    5850
     51int usb_hid_report_init(usb_hid_report_t *report);
    5952
    60 int usb_hid_report_init(usb_hid_report_t *report);
    61 int usb_hid_report_append_fields(usb_hid_report_t *report,
    62                                  usb_hid_report_item_t *report_item);
     53int usb_hid_report_append_fields(usb_hid_report_t *report,
     54                usb_hid_report_item_t *report_item);
    6355
    64 usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type);
    65 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    66                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
    67 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    68                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
    69 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    70                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
    71 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    72                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
     56usb_hid_report_description_t * usb_hid_report_find_description(
     57                const usb_hid_report_t *report, uint8_t report_id,
     58                usb_hid_report_type_t type);
     59
     60int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data,
     61                size_t item_size, usb_hid_report_item_t *report_item,
     62                usb_hid_report_path_t *usage_path);
     63
     64int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data,
     65                size_t item_size, usb_hid_report_item_t *report_item,
     66                usb_hid_report_path_t *usage_path);
     67
     68int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data,
     69                size_t item_size, usb_hid_report_item_t *report_item,
     70                usb_hid_report_path_t *usage_path);
     71
     72int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data,
     73                size_t item_size, usb_hid_report_item_t *report_item,
     74                usb_hid_report_path_t *usage_path);
    7375
    7476void usb_hid_descriptor_print_list(link_t *head);
     77
    7578void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item);
     79
    7680void usb_hid_free_report_list(link_t *head);
    77 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item);
     81
     82usb_hid_report_item_t *usb_hid_report_item_clone(
     83                const usb_hid_report_item_t *item);
     84
    7885uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
    7986
    80 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path);
     87usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t*report,
     88                usb_hid_report_path_t *cmp_path);
     89
     90
    8191#endif
    8292/**
  • uspace/lib/usbhid/include/usb/hid/hidparser.h

    re8f826b r400735e  
    4747 * Input report parser functions
    4848 */
    49 /** */
    50 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
    51                          size_t size, uint8_t *report_id);
     49int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
     50                size_t size, uint8_t *report_id);
    5251
    5352/*
    5453 * Output report parser functions
    5554 */
    56 /** Allocates output report buffer*/
    5755uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
    58                                uint8_t report_id);
     56                uint8_t report_id);
    5957
    60 /** Frees output report buffer*/
    6158void usb_hid_report_output_free(uint8_t *output);
    6259
    63 /** Returns size of report in items */
    64 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
    65                            usb_hid_report_type_t type);
     60size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
     61                usb_hid_report_type_t type);
    6662
    67 /** Makes the output report buffer by translated given data */
    68 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
    69                                     uint8_t *buffer, size_t size);
     63size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id,
     64                usb_hid_report_type_t type);
    7065
    71 /** */
    72 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
    73                                                    usb_hid_report_field_t *field,
    74                                                    usb_hid_report_path_t *path,
    75                                                    int flags,
    76                                                    usb_hid_report_type_t type);
    7766
    78 /** */
    79 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report,
    80                                      uint8_t report_id,
    81                                      usb_hid_report_type_t type);
     67int usb_hid_report_output_translate(usb_hid_report_t *report,
     68                uint8_t report_id, uint8_t *buffer, size_t size);
     69
     70
     71/*
     72 * Report descriptor structure observing functions
     73 */
     74usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
     75                usb_hid_report_field_t *field, usb_hid_report_path_t *path,
     76                int flags, usb_hid_report_type_t type);
     77
     78uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report,
     79                uint8_t report_id, usb_hid_report_type_t type);
    8280
    8381#endif
  • uspace/lib/usbhid/include/usb/hid/hidpath.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * USB HID report descriptor and report data parser
    3434 */
    35 #ifndef LIBUSBHID_HIDPATH_H_
    36 #define LIBUSBHID_HIDPATH_H_
     35#ifndef LIBUSB_HIDPATH_H_
     36#define LIBUSB_HIDPATH_H_
    3737
    3838#include <usb/hid/hidparser.h>
     
    4040#include <adt/list.h>
    4141
     42
     43/*---------------------------------------------------------------------------*/
     44/*
     45 * Flags of usage paths comparison modes.
     46 *
     47 */
     48/** Wanted usage path must be exactly the same as the searched one.  This
     49 * option cannot be combined with the others.
     50 */
     51#define USB_HID_PATH_COMPARE_STRICT             0
     52
    4253/**
    43  * Description of path of usage pages and usages in report descriptor
     54 * Wanted usage path must be the suffix in the searched one.
    4455 */
    45 /** Wanted usage path must be exactly the same as the searched one */
    46 #define USB_HID_PATH_COMPARE_STRICT             0
    47 /** Wanted usage path must be the suffix in the searched one */
    4856#define USB_HID_PATH_COMPARE_END                1
    49 /** */
     57
     58/**
     59 * Only usage page are compared along the usage path.  This option can be
     60 * combined with others.
     61 */
    5062#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    2
    51 /** Searched usage page must be prefix of the other one */
     63
     64/**
     65 * Searched usage page must be prefix of the other one.
     66 */
    5267#define USB_HID_PATH_COMPARE_BEGIN              4
    53 /** Searched couple of usage page and usage can be anywhere in usage path */
     68
     69/**
     70 * Searched couple of usage page and usage can be anywhere in usage path.
     71 * This option is deprecated.
     72 */
    5473#define USB_HID_PATH_COMPARE_ANYWHERE           8
    5574
    56 
    57 /** Collection usage path structure */
     75/*----------------------------------------------------------------------------*/
     76/**
     77 * Item of usage path structure. Last item of linked list describes one item
     78 * in report, the others describe superior Collection tags. Usage and Usage
     79 * page of report item can be changed due to data in report.
     80 */
    5881typedef struct {
    59         /** */
     82        /** Usage page of report item. Zero when usage page can be changed. */
    6083        uint32_t usage_page;
    61         /** */ 
     84        /** Usage of report item. Zero when usage can be changed. */   
    6285        uint32_t usage;
    6386
     87        /** Attribute of Collection tag in report descriptor*/
    6488        uint8_t flags;
    65         /** */
     89
     90        /** Linked list structure*/
    6691        link_t link;
    6792} usb_hid_report_usage_path_t;
    6893
    69 /** */
     94
     95/*---------------------------------------------------------------------------*/
     96/**
     97 * USB HID usage path structure.
     98 * */
    7099typedef struct {
    71         /** */ 
     100        /** Length of usage path */     
    72101        int depth;     
     102
     103        /** Report id. Zero is reserved and means that report id is not used.
     104         * */
    73105        uint8_t report_id;
    74106       
    75         /** */ 
     107        /** Linked list structure. */   
    76108        link_t link; /* list */
    77109
    78         link_t head; /* head of list of usage paths */
     110        /** Head of the list of usage path items. */
     111        link_t head;
    79112
    80113} usb_hid_report_path_t;
    81114
    82 /** */
     115/*---------------------------------------------------------------------------*/
    83116usb_hid_report_path_t *usb_hid_report_path(void);
    84117
    85 /** */
    86118void usb_hid_report_path_free(usb_hid_report_path_t *path);
    87119
    88 /** */
    89 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path,
    90                                       uint8_t report_id);
     120int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path,
     121                uint8_t report_id);
    91122
    92 /** */
    93123int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
    94                                     int32_t usage_page, int32_t usage);
     124                int32_t usage_page, int32_t usage);
    95125
    96 /** */
    97126void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
    98127
    99 /** */
    100128void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
    101129
    102 /** */
    103130void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path,
    104                                   int32_t tag, int32_t data);
     131                int32_t tag, int32_t data);
    105132
    106 /** */
    107 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
    108                                       usb_hid_report_path_t *path, int flags);
     133int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
     134                usb_hid_report_path_t *path, int flags);
    109135
    110 /** */
    111 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
     136usb_hid_report_path_t *usb_hid_report_path_clone(
     137                usb_hid_report_path_t *usage_path);
    112138
    113139void usb_hid_print_usage_path(usb_hid_report_path_t *path);
  • uspace/lib/usbhid/include/usb/hid/hidreport.h

    re8f826b r400735e  
    4444 * report parser.
    4545 *
    46  * \param dev USB device representing a HID device.
    47  * \param parser HID Report parser.
     46 * \param[in] dev USB device representing a HID device.
     47 * \param[in/out] parser HID Report parser.
     48 * \param[out] report_desc Place to save report descriptor into.
     49 * \param[out] report_size
    4850 *
    4951 * \retval EOK if successful.
     
    5759 */
    5860int usb_hid_process_report_descriptor(usb_device_t *dev,
    59     usb_hid_report_t *report);
     61    usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size);
    6062
    6163#endif /* LIBUSB_HIDREPORT_H_ */
  • uspace/lib/usbhid/include/usb/hid/hidtypes.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * USB HID report descriptor and report data parser
    34  */
    35 #ifndef LIBUSBHID_HIDTYPES_H_
    36 #define LIBUSBHID_HIDTYPES_H_
     33 * Basic data structures for USB HID Report descriptor and report parser.
     34 */
     35#ifndef LIBUSB_HIDTYPES_H_
     36#define LIBUSB_HIDTYPES_H_
    3737
    3838#include <stdint.h>
    3939#include <adt/list.h>
    4040
     41/*---------------------------------------------------------------------------*/
     42
     43/**
     44 * Maximum amount of specified usages for one report item
     45 */
    4146#define USB_HID_MAX_USAGES      0xffff
    4247
    43 #define USB_HID_UINT32_TO_INT32(x, size)        ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1)))
    44 #define USB_HID_INT32_TO_UINT32(x, size)        (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
    45 
    46 
     48/**
     49 * Converts integer from unsigned two's complement format format to signed
     50 * one.
     51 *
     52 * @param x Number to convert
     53 * @param size Length of the unsigned number in bites
     54 * @return signed int
     55 */
     56#define USB_HID_UINT32_TO_INT32(x, size)        \
     57        ((((x) & (1 << ((size) - 1))) != 0) ?   \
     58         -(~((x) - 1) & ((1 << size) - 1)) : (x))
     59
     60/**
     61 * Convert integer from signed format to unsigned. If number is negative the
     62 * two's complement format is used.
     63 *
     64 * @param x Number to convert
     65 * @param size Length of result number in bites
     66 * @return unsigned int
     67 */
     68#define USB_HID_INT32_TO_UINT32(x, size)        \
     69        (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
     70
     71/*---------------------------------------------------------------------------*/
     72
     73/**
     74 * Enum of report types
     75 */
    4776typedef enum {
     77        /** Input report. Data are sent from device to system */
    4878        USB_HID_REPORT_TYPE_INPUT = 1,
     79
     80        /** Output report. Data are sent from system to device */
    4981        USB_HID_REPORT_TYPE_OUTPUT = 2,
     82
     83        /** Feature report. Describes device configuration information that
     84         * can be sent to the device */
    5085        USB_HID_REPORT_TYPE_FEATURE = 3
    5186} usb_hid_report_type_t;
    5287
    53 
     88/*---------------------------------------------------------------------------*/
     89
     90/**
     91 * Description of all reports described in one report descriptor.
     92 */
    5493typedef struct {
    55         /** */
     94        /** Count of available reports. */
    5695        int report_count;
    57         link_t reports;         /** list of usb_hid_report_description_t */
    58 
     96
     97        /** Head of linked list of description of reports. */
     98        link_t reports;
     99
     100        /** Head of linked list of all used usage/collection paths. */
    59101        link_t collection_paths;
     102
     103        /** Length of list of usage paths. */
    60104        int collection_paths_count;
    61105
     106        /** Flag whether report ids are used. */
    62107        int use_report_ids;
     108
     109        /** Report id of last parsed report. */
    63110        uint8_t last_report_id;
    64111       
    65112} usb_hid_report_t;
    66 
     113/*---------------------------------------------------------------------------*/
     114
     115/**
     116 * Description of one concrete report
     117 */
    67118typedef struct {
     119        /** Report id. Zero when no report id is used. */
    68120        uint8_t report_id;
     121
     122        /** Type of report */
    69123        usb_hid_report_type_t type;
    70124
     125        /** Bit length of the report */
    71126        size_t bit_length;
     127
     128        /** Number of items in report */
    72129        size_t item_length;
    73130       
    74         link_t report_items;    /** list of report items (fields) */
    75 
     131        /** Linked list of report items in report */
     132        link_t report_items;
     133
     134        /** Linked list of descriptions. */
    76135        link_t link;
    77136} usb_hid_report_description_t;
    78 
     137/*---------------------------------------------------------------------------*/
     138
     139/**
     140 * Description of one field/item in report
     141 */
    79142typedef struct {
    80 
     143        /** Bit offset of the field */
    81144        int offset;
     145
     146        /** Bit size of the field */
    82147        size_t size;
    83148
     149        /** Usage page. Zero when usage page can be changed. */
    84150        uint16_t usage_page;
     151
     152        /** Usage. Zero when usage can be changed. */
    85153        uint16_t usage;
    86154
     155        /** Item's attributes */
    87156        uint8_t item_flags;
     157
     158        /** Usage/Collection path of the field. */
    88159        usb_hid_report_path_t *collection_path;
    89160
     161        /**
     162         * The lowest valid logical value (value with the device operates)
     163         */
    90164        int32_t logical_minimum;
     165
     166        /**
     167         * The greatest valid logical value
     168         */
    91169        int32_t logical_maximum;
     170
     171        /**
     172         * The lowest valid physical value (value with the system operates)
     173         */
    92174        int32_t physical_minimum;
     175
     176        /** The greatest valid physical value */
    93177        int32_t physical_maximum;
     178
     179        /** The lowest valid usage index */
    94180        int32_t usage_minimum;
     181
     182        /** The greatest valid usage index */
    95183        int32_t usage_maximum;
     184       
     185        /** Unit of the value */
    96186        uint32_t unit;
     187
     188        /** Unit exponent */
    97189        uint32_t unit_exponent;
    98190
     191        /** Array of possible usages */
    99192        uint32_t *usages;
     193
     194        /** Size of the array of usages */
    100195        size_t usages_count;
    101196
     197        /** Parsed value */
    102198        int32_t value;
    103199
     200        /** List to another report items */
    104201        link_t link;
    105202} usb_hid_report_field_t;
    106203
    107 
    108 
    109 /**
    110  * state table
     204/*---------------------------------------------------------------------------*/
     205
     206/**
     207 * State table for report descriptor parsing
    111208 */
    112209typedef struct {
     
    114211        int32_t id;
    115212       
    116         /** */
     213        /** Extended usage page */
    117214        uint16_t extended_usage_page;
     215
     216        /** Array of usages specified for this item */
    118217        uint32_t usages[USB_HID_MAX_USAGES];
     218       
     219        /** Length of usages array */
    119220        int usages_count;
    120221
    121         /** */
     222        /** Usage page*/
    122223        uint32_t usage_page;
    123224
    124         /** */ 
     225        /** Minimum valid usage index */       
    125226        int32_t usage_minimum;
    126         /** */ 
     227       
     228        /** Maximum valid usage index */       
    127229        int32_t usage_maximum;
    128         /** */ 
     230       
     231        /** Minimum valid logical value */     
    129232        int32_t logical_minimum;
    130         /** */ 
     233       
     234        /** Maximum valid logical value */     
    131235        int32_t logical_maximum;
    132         /** */ 
     236
     237        /** Length of the items in bits*/       
    133238        int32_t size;
    134         /** */ 
     239
     240        /** COunt of items*/   
    135241        int32_t count;
    136         /** */ 
     242
     243        /**  Bit offset of the item in report */       
    137244        size_t offset;
    138         /** */ 
     245
     246        /** Unit exponent */   
    139247        int32_t unit_exponent;
    140         /** */ 
     248        /** Unit of the value */       
    141249        int32_t unit;
    142250
    143         /** */
     251        /** String index */
    144252        uint32_t string_index;
    145         /** */ 
     253
     254        /** Minimum valid string index */       
    146255        uint32_t string_minimum;
    147         /** */ 
     256
     257        /** Maximum valid string index */       
    148258        uint32_t string_maximum;
    149         /** */ 
     259
     260        /** The designator index */     
    150261        uint32_t designator_index;
    151         /** */ 
     262
     263        /** Minimum valid designator value*/   
    152264        uint32_t designator_minimum;
    153         /** */ 
     265
     266        /** Maximum valid designator value*/   
    154267        uint32_t designator_maximum;
    155         /** */ 
     268
     269        /** Minimal valid physical value*/     
    156270        int32_t physical_minimum;
    157         /** */ 
     271
     272        /** Maximal valid physical value */     
    158273        int32_t physical_maximum;
    159274
    160         /** */ 
     275        /** Items attributes*/ 
    161276        uint8_t item_flags;
    162277
     278        /** Report type */
    163279        usb_hid_report_type_t type;
    164280
    165281        /** current collection path*/   
    166282        usb_hid_report_path_t *usage_path;
    167         /** */ 
     283
     284        /** Unused*/   
    168285        link_t link;
    169286
    170287        int in_delimiter;
    171288} usb_hid_report_item_t;
    172 
    173 /** HID parser callbacks for IN items. */
    174 typedef struct {
    175         /** Callback for keyboard.
    176          *
    177          * @param key_codes Array of pressed key (including modifiers).
    178          * @param count Length of @p key_codes.
    179          * @param arg Custom argument.
    180          */
    181         void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg);
    182 } usb_hid_report_in_callbacks_t;
    183 
    184 
     289/*---------------------------------------------------------------------------*/
     290/**
     291 * Enum of the keyboard modifiers
     292 */
    185293typedef enum {
    186294        USB_HID_MOD_LCTRL = 0x01,
     
    206314        USB_HID_MOD_RGUI
    207315};
     316/*---------------------------------------------------------------------------*/
     317
    208318
    209319#endif
  • uspace/lib/usbhid/include/usb/hid/iface.h

    re8f826b r400735e  
    3838#include <sys/types.h>
    3939
    40 int usbhid_dev_get_event_length(int);
    41 int usbhid_dev_get_event(int, uint16_t *, uint16_t *, size_t, size_t *,
     40int usbhid_dev_get_event_length(int, size_t *);
     41int usbhid_dev_get_event(int, uint8_t *, size_t, size_t *, int *,
    4242    unsigned int);
     43int usbhid_dev_get_report_descriptor_length(int, size_t *);
     44int usbhid_dev_get_report_descriptor(int, uint8_t *, size_t, size_t *);
    4345
    4446#endif
  • uspace/lib/usbhid/include/usb/hid/usages/consumer.h

    re8f826b r400735e  
    11/*
    2  * Copyright (c) 2011 Jan Vesely
     2 * Copyright (c) 2011 Lubos Slovak
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28
     29/** @addtogroup libusbhid
    2930 * @{
    3031 */
    3132/** @file
    32  * @brief UHCI driver
     33 * USB multimedia key usage to string mapping.
    3334 */
    34 #ifndef DRV_UHCI_UTILS_SLAB_H
    35 #define DRV_UHCI_UTILS_SLAB_H
    3635
    37 #include <bool.h>
     36#ifndef LIBUSBHID_CONSUMER_H_
     37#define LIBUSBHID_CONSUMER_H_
    3838
    39 #define SLAB_ELEMENT_SIZE 1024
     39const char *usbhid_multimedia_usage_to_str(int usage);
    4040
    41 void * slab_malloc_g(void);
     41#endif /* LIBUSBHID_CONSUMER_H_ */
    4242
    43 void slab_free_g(void *addr);
    44 
    45 bool slab_in_range_g(void *addr);
    46 
    47 #endif
    4843/**
    4944 * @}
  • uspace/lib/usbhid/src/hiddescriptor.c

    re8f826b r400735e  
    4141#include <assert.h>
    4242
    43 
     43/*---------------------------------------------------------------------------*/
     44/*
     45 * Constants defining current parsing mode for correct parsing of the set of
     46 * local tags (usage) enclosed in delimter tags.
     47 */
     48/**
     49 * Second delimiter tag was read. The set of local items (usage) ended.
     50 */
    4451#define OUTSIDE_DELIMITER_SET   0
     52
     53/**
     54 * First delimiter tag was read. The set of local items (usage) started.
     55 */
    4556#define START_DELIMITER_SET     1
     57
     58/**
     59 * Parser is in the set of local items.
     60 */
    4661#define INSIDE_DELIMITER_SET    2
     62
     63/*---------------------------------------------------------------------------*/
    4764       
    4865/** The new report item flag. Used to determine when the item is completly
     
    6178#define USB_HID_UNKNOWN_TAG             -99
    6279
    63 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path)
    64 {
    65         /* find or append current collection path to the list */
    66         //link_t *path_it = report->collection_paths.next;
     80/*---------------------------------------------------------------------------*/
     81/**
     82 * Checks if given collection path is already present in report structure and
     83 * inserts it if not.
     84 *
     85 * @param report Report structure
     86 * @param cmp_path The collection path
     87 * @return Pointer to the result collection path in report structure.
     88 * @retval NULL If some error occurs
     89 */
     90usb_hid_report_path_t *usb_hid_report_path_try_insert(
     91                usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) {
     92       
    6793        link_t *path_it = report->collection_paths.prev->next;
    6894        usb_hid_report_path_t *path = NULL;
    6995       
     96        if((report == NULL) || (cmp_path == NULL)) {
     97                return NULL;
     98        }
    7099       
    71100        while(path_it != &report->collection_paths) {
    72                 path = list_get_instance(path_it, usb_hid_report_path_t, link);
    73                
    74                 if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
     101                path = list_get_instance(path_it, usb_hid_report_path_t,
     102                                link);
     103               
     104                if(usb_hid_report_compare_usage_path(path, cmp_path,
     105                                        USB_HID_PATH_COMPARE_STRICT) == EOK){
    75106                        break;
    76107                }                       
     
    78109        }
    79110        if(path_it == &report->collection_paths) {
    80                 path = usb_hid_report_path_clone(cmp_path);                     
     111                path = usb_hid_report_path_clone(cmp_path);
     112                if(path == NULL) {
     113                        return NULL;
     114                }
    81115                list_append(&path->link, &report->collection_paths);                                   
    82116                report->collection_paths_count++;
     
    85119        }
    86120        else {
    87                 return list_get_instance(path_it, usb_hid_report_path_t, link);
    88         }
    89 }
    90 
     121                return list_get_instance(path_it, usb_hid_report_path_t,
     122                                link);
     123        }
     124}
     125
     126/*---------------------------------------------------------------------------*/
    91127/**
    92128 * Initialize the report descriptor parser structure
     
    94130 * @param parser Report descriptor parser structure
    95131 * @return Error code
     132 * @retval EINVAL If no report structure was given
     133 * @retval EOK If report structure was successfully initialized
    96134 */
    97135int usb_hid_report_init(usb_hid_report_t *report)
     
    109147}
    110148
    111 
    112 /*
    113  *
    114  *
    115  */
    116 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
    117 {
     149/*---------------------------------------------------------------------------*/
     150
     151/**
     152 *
     153 *
     154 * @param report Report structure in which the new report items should be
     155 *               stored
     156 * @param report_item Current report descriptor's parsing state table
     157 * @return Error code
     158 * @retval EOK If all fields were successfully append to report
     159 * @retval EINVAL If invalid parameters (NULL) was given
     160 * @retval ENOMEM If there is no memmory to store new report description
     161 *
     162 */
     163int usb_hid_report_append_fields(usb_hid_report_t *report,
     164                usb_hid_report_item_t *report_item) {
     165
    118166        usb_hid_report_field_t *field;
    119167        int i;
     
    121169        uint32_t *usages;
    122170        int usages_used=0;
     171
     172        if((report == NULL) || (report_item == NULL)) {
     173                return EINVAL;
     174        }
     175
    123176        if(report_item->usages_count > 0){
    124177                usages = malloc(sizeof(int32_t) * report_item->usages_count);
    125                 memcpy(usages, report_item->usages, sizeof(int32_t) * report_item->usages_count);
     178                memcpy(usages, report_item->usages, sizeof(int32_t) *
     179                                report_item->usages_count);
    126180        }
    127181        else {
     
    144198                if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){
    145199                        /*
    146                                 Store usage array. The Correct Usage Page and Usage is depending
    147                                 on data in report and will be filled later
     200                        Store usage array. The Correct Usage Page and Usage is
     201                        depending on data in report and will be filled later
    148202                        */
    149203                        field->usage = 0;
     
    162216                        }
    163217                        else {
    164                                 usage = report_item->usages[report_item->usages_count - 1];
     218                                usage = report_item->usages[
     219                                        report_item->usages_count- 1];
    165220                        }
    166221
    167222                        if(USB_HID_IS_EXTENDED_USAGE(usage)){
    168223                                field->usage = USB_HID_EXTENDED_USAGE(usage);
    169                                 field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage);
     224                                field->usage_page =
     225                                        USB_HID_EXTENDED_USAGE_PAGE(usage);
    170226                        }
    171227                        else {
     
    176232                }
    177233               
    178                 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page);
    179                 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage);
    180 
    181                 field->collection_path = usb_hid_report_path_try_insert(report, path);
     234                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL,
     235                                field->usage_page);
     236                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL,
     237                                field->usage);
     238
     239                field->collection_path =
     240                        usb_hid_report_path_try_insert(report, path);
    182241
    183242                field->size = report_item->size;
    184243               
    185                 size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8;
    186                 size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size;
     244                size_t offset_byte = (report_item->offset + (i *
     245                        report_item->size)) / 8;
     246
     247                size_t offset_bit = 8 - ((report_item->offset + (i *
     248                        report_item->size)) % 8) - report_item->size;
    187249
    188250                field->offset = 8 * offset_byte + offset_bit;
     
    195257                /* find the right report list*/
    196258                usb_hid_report_description_t *report_des;
    197                 report_des = usb_hid_report_find_description(report, report_item->id, report_item->type);
     259                report_des = usb_hid_report_find_description(report,
     260                        report_item->id, report_item->type);
     261               
    198262                if(report_des == NULL){
    199                         report_des = malloc(sizeof(usb_hid_report_description_t));
    200                         memset(report_des, 0, sizeof(usb_hid_report_description_t));
     263                        report_des = malloc(
     264                                sizeof(usb_hid_report_description_t));
     265                        if(report_des == NULL) {
     266                                return ENOMEM;
     267                        }
     268
     269                        memset(report_des, 0,
     270                                sizeof(usb_hid_report_description_t));
    201271
    202272                        report_des->type = report_item->type;
    203273                        report_des->report_id = report_item->id;
     274                        if(report_des->report_id != 0) {
     275                                /* set up the bit length by report_id field */
     276                                report_des->bit_length = 8;
     277                        }
     278
    204279                        list_initialize (&report_des->link);
    205280                        list_initialize (&report_des->report_items);
     
    225300        return EOK;
    226301}
    227 
    228 usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
    229 {
     302/*---------------------------------------------------------------------------*/
     303/**
     304 * Finds description of report with given report_id and of given type in
     305 * opaque report structure.
     306 *
     307 * @param report Opaque structure containing the parsed report descriptor
     308 * @param report_id ReportId of report we are searching
     309 * @param type Type of report we are searching
     310 * @return Pointer to the particular report description
     311 * @retval NULL If no description is founded
     312 */
     313usb_hid_report_description_t * usb_hid_report_find_description(
     314                const usb_hid_report_t *report, uint8_t report_id,
     315                usb_hid_report_type_t type) {
     316
    230317        link_t *report_it = report->reports.next;
    231318        usb_hid_report_description_t *report_des = NULL;
    232319       
    233320        while(report_it != &report->reports) {
    234                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
    235 
    236                 if((report_des->report_id == report_id) && (report_des->type == type)){
     321                report_des = list_get_instance(report_it,
     322                                usb_hid_report_description_t, link);
     323
     324                if((report_des->report_id == report_id) &&
     325                   (report_des->type == type)) {
    237326                        return report_des;
    238327                }
     
    243332        return NULL;
    244333}
     334/*---------------------------------------------------------------------------*/
    245335
    246336/** Parse HID report descriptor.
     
    249339 * @param data Data describing the report.
    250340 * @return Error code.
     341 * @retval ENOMEM If no more memmory is available
     342 * @retval EINVAL If invalid data are founded
     343 * @retval EOK If report descriptor is successfully parsed
    251344 */
    252345int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
     
    299392                       
    300393                        ret = usb_hid_report_parse_tag(tag,class,data+i+1,
    301                                                        item_size,report_item, usage_path);
     394                                item_size,report_item, usage_path);
     395
    302396                        switch(ret){
    303                                 case USB_HID_NEW_REPORT_ITEM:
    304                                         // store report item to report and create the new one
    305                                         // store current collection path
    306                                         report_item->usage_path = usage_path;
     397                        case USB_HID_NEW_REPORT_ITEM:
     398                                /* store report item to report and create the
     399                                 * new one store current collection path
     400                                 */
     401                                report_item->usage_path = usage_path;
    307402                                       
    308                                         usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id);   
    309                                         if(report_item->id != 0){
    310                                                 report->use_report_ids = 1;
    311                                         }
     403                                usb_hid_report_path_set_report_id(
     404                                     report_item->usage_path, report_item->id);
     405                               
     406                                if(report_item->id != 0){
     407                                        report->use_report_ids = 1;
     408                                }
    312409                                       
    313                                         switch(tag) {
    314                                                 case USB_HID_REPORT_TAG_INPUT:
    315                                                         report_item->type = USB_HID_REPORT_TYPE_INPUT;
    316                                                         report_item->offset = offset_input;
    317                                                         offset_input += report_item->count * report_item->size;
    318                                                         break;
    319                                                 case USB_HID_REPORT_TAG_OUTPUT:
    320                                                         report_item->type = USB_HID_REPORT_TYPE_OUTPUT;
    321                                                         report_item->offset = offset_output;
    322                                                         offset_output += report_item->count * report_item->size;
    323 
    324                                                         break;
    325                                                 case USB_HID_REPORT_TAG_FEATURE:
    326                                                         report_item->type = USB_HID_REPORT_TYPE_FEATURE;
    327                                                         report_item->offset = offset_feature;
    328                                                         offset_feature += report_item->count * report_item->size;
    329                                                         break;
    330                                                 default:
    331                                                     usb_log_debug("\tjump over - tag %X\n", tag);
    332                                                     break;
    333                                         }
     410                                switch(tag) {
     411                                case USB_HID_REPORT_TAG_INPUT:
     412                                        report_item->type =
     413                                            USB_HID_REPORT_TYPE_INPUT;
     414
     415                                        report_item->offset = offset_input;
     416                                        offset_input += report_item->count *
     417                                            report_item->size;
     418                                        break;
     419       
     420                                case USB_HID_REPORT_TAG_OUTPUT:
     421                                        report_item->type =
     422                                            USB_HID_REPORT_TYPE_OUTPUT;
    334423                                       
    335                                         /*
    336                                          * append new fields to the report
    337                                          * structure                                     
    338                                          */
    339                                         usb_hid_report_append_fields(report, report_item);
    340 
    341                                         /* reset local items */
    342                                         usb_hid_report_reset_local_items (report_item);
    343 
     424                                        report_item->offset = offset_output;
     425                                        offset_output += report_item->count *
     426                                            report_item->size;
    344427                                        break;
    345 
    346                                 case USB_HID_RESET_OFFSET:
    347                                         offset_input = 0;
    348                                         offset_output = 0;
    349                                         offset_feature = 0;
    350                                         usb_hid_report_path_set_report_id (usage_path, report_item->id);
     428       
     429                                case USB_HID_REPORT_TAG_FEATURE:
     430                                        report_item->type =
     431                                            USB_HID_REPORT_TYPE_FEATURE;
     432
     433                                        report_item->offset = offset_feature;
     434                                        offset_feature += report_item->count *
     435                                                report_item->size;
    351436                                        break;
    352 
    353                                 case USB_HID_REPORT_TAG_PUSH:
    354                                         // push current state to stack
    355                                         new_report_item = usb_hid_report_item_clone(report_item);
    356                                         usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path);
    357                                         new_report_item->usage_path = tmp_path;
    358 
    359                                         list_prepend (&new_report_item->link, &stack);
    360                                         break;
    361                                 case USB_HID_REPORT_TAG_POP:
    362                                         // restore current state from stack
    363                                         if(list_empty (&stack)) {
    364                                                 return EINVAL;
    365                                         }
    366                                         free(report_item);
     437       
     438                                default:
     439                                        usb_log_debug2(
     440                                            "\tjump over - tag %X\n", tag);
     441                                        break;
     442                                }
     443                                       
     444                                /*
     445                                 * append new fields to the report structure                                     
     446                                 */
     447                                usb_hid_report_append_fields(report,
     448                                    report_item);
     449
     450                                /* reset local items */
     451                                usb_hid_report_reset_local_items (report_item);
     452                                break;
     453
     454                        case USB_HID_RESET_OFFSET:
     455                                offset_input = 0;
     456                                offset_output = 0;
     457                                offset_feature = 0;
     458                                usb_hid_report_path_set_report_id (usage_path,
     459                                    report_item->id);
     460                                break;
     461
     462                        case USB_HID_REPORT_TAG_PUSH:
     463                                // push current state to stack
     464                                new_report_item = usb_hid_report_item_clone(
     465                                    report_item);
     466                               
     467                                usb_hid_report_path_t *tmp_path =
     468                                    usb_hid_report_path_clone(usage_path);
     469
     470                                new_report_item->usage_path = tmp_path;
     471
     472                                list_prepend (&new_report_item->link, &stack);
     473                                break;
     474                        case USB_HID_REPORT_TAG_POP:
     475                                // restore current state from stack
     476                                if(list_empty (&stack)) {
     477                                        return EINVAL;
     478                                }
     479                                free(report_item);
    367480                                               
    368                                         report_item = list_get_instance(stack.next, usb_hid_report_item_t, link);
     481                                report_item = list_get_instance(stack.next,
     482                                    usb_hid_report_item_t, link);
    369483                                       
    370                                         usb_hid_report_usage_path_t *tmp_usage_path;
    371                                         tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
     484                                usb_hid_report_usage_path_t *tmp_usage_path;
     485                                tmp_usage_path = list_get_instance(
     486                                    report_item->usage_path->link.prev,
     487                                    usb_hid_report_usage_path_t, link);
    372488                                       
    373                                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
    374                                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
    375 
    376                                         usb_hid_report_path_free(report_item->usage_path);
    377                                         list_initialize(&report_item->usage_path->link);
    378                                         list_remove (stack.next);
     489                                usb_hid_report_set_last_item(usage_path,
     490                                    USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
     491                               
     492                                usb_hid_report_set_last_item(usage_path,
     493                                    USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
     494
     495                                usb_hid_report_path_free(report_item->usage_path);
     496                                list_initialize(&report_item->usage_path->link);
     497                                list_remove (stack.next);
    379498                                       
    380                                         break;
     499                                break;
    381500                                       
    382                                 default:
    383                                         // nothing special to do                                       
    384                                         break;
     501                        default:
     502                                // nothing special to do                                       
     503                                break;
    385504                        }
    386505
     
    399518}
    400519
     520/*---------------------------------------------------------------------------*/
    401521
    402522/**
     
    409529 * @return Code of action to be done next
    410530 */
    411 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    412                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    413 {       
     531int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data,
     532        size_t item_size, usb_hid_report_item_t *report_item,
     533        usb_hid_report_path_t *usage_path) {   
     534       
    414535        int ret;
    415536       
    416537        switch(class){
    417                 case USB_HID_TAG_CLASS_MAIN:
    418 
    419                         if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item, usage_path)) == EOK) {
    420                                 return USB_HID_NEW_REPORT_ITEM;
    421                         }
    422                         else {
    423                                 /*TODO process the error */
    424                                 return ret;
    425                            }
    426                         break;
    427 
    428                 case USB_HID_TAG_CLASS_GLOBAL: 
    429                         return usb_hid_report_parse_global_tag(tag,data,item_size,report_item, usage_path);
    430                         break;
    431 
    432                 case USB_HID_TAG_CLASS_LOCAL:                   
    433                         return usb_hid_report_parse_local_tag(tag,data,item_size,report_item, usage_path);
    434                         break;
    435                 default:
    436                         return USB_HID_NO_ACTION;
     538        case USB_HID_TAG_CLASS_MAIN:
     539
     540                if((ret=usb_hid_report_parse_main_tag(tag, data, item_size,
     541                        report_item, usage_path)) == EOK) {
     542
     543                        return USB_HID_NEW_REPORT_ITEM;
     544                }
     545                else {
     546                        return ret;
     547                }
     548                break;
     549
     550        case USB_HID_TAG_CLASS_GLOBAL: 
     551                return usb_hid_report_parse_global_tag(tag, data, item_size,
     552                        report_item, usage_path);
     553                break;
     554
     555        case USB_HID_TAG_CLASS_LOCAL:                   
     556                return usb_hid_report_parse_local_tag(tag, data, item_size,
     557                        report_item, usage_path);
     558                break;
     559       
     560        default:
     561                return USB_HID_NO_ACTION;
    437562        }
    438563}
     
    448573 */
    449574
    450 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    451                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
     575int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data,
     576        size_t item_size, usb_hid_report_item_t *report_item,
     577        usb_hid_report_path_t *usage_path)
    452578{
    453579        usb_hid_report_usage_path_t *path_item;
     
    455581        switch(tag)
    456582        {
    457                 case USB_HID_REPORT_TAG_INPUT:
    458                 case USB_HID_REPORT_TAG_OUTPUT:
    459                 case USB_HID_REPORT_TAG_FEATURE:
    460                         report_item->item_flags = *data;                       
    461                         return EOK;                     
    462                         break;
     583        case USB_HID_REPORT_TAG_INPUT:
     584        case USB_HID_REPORT_TAG_OUTPUT:
     585        case USB_HID_REPORT_TAG_FEATURE:
     586                report_item->item_flags = *data;                       
     587                return EOK;                     
     588                break;
    463589                       
    464                 case USB_HID_REPORT_TAG_COLLECTION:
    465 
    466                         // store collection atributes
    467                         path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
    468                         path_item->flags = *data;       
     590        case USB_HID_REPORT_TAG_COLLECTION:
     591
     592                /* store collection atributes */
     593                path_item = list_get_instance(usage_path->head.prev,
     594                        usb_hid_report_usage_path_t, link);
     595                path_item->flags = *data;       
    469596                       
    470                         // set last item
    471                         usb_hid_report_set_last_item(usage_path,
    472                                                      USB_HID_TAG_CLASS_GLOBAL,
    473                                                      USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1]));
    474                         usb_hid_report_set_last_item(usage_path,
    475                                                      USB_HID_TAG_CLASS_LOCAL,
    476                                                      USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1]));
     597                /* set last item */
     598                usb_hid_report_set_last_item(usage_path,
     599                        USB_HID_TAG_CLASS_GLOBAL,
     600                        USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[
     601                                report_item->usages_count-1]));
     602
     603                usb_hid_report_set_last_item(usage_path,
     604                        USB_HID_TAG_CLASS_LOCAL,
     605                        USB_HID_EXTENDED_USAGE(report_item->usages[
     606                                report_item->usages_count-1]));
    477607                       
    478                         // append the new one which will be set by common
    479                         // usage/usage page
    480                         usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);
    481                         usb_hid_report_reset_local_items (report_item);
    482                         return USB_HID_NO_ACTION;
    483                         break;
     608                /* append the new one which will be set by common usage/usage
     609                 * page */
     610                usb_hid_report_path_append_item(usage_path,
     611                        report_item->usage_page,
     612                        report_item->usages[report_item->usages_count-1]);
     613
     614                usb_hid_report_reset_local_items (report_item);
     615                return USB_HID_NO_ACTION;
     616                break;
    484617                       
    485                 case USB_HID_REPORT_TAG_END_COLLECTION:
    486                         usb_hid_report_remove_last_item(usage_path);
    487                         return USB_HID_NO_ACTION;
    488                         break;
    489                 default:
    490                         return USB_HID_NO_ACTION;
     618        case USB_HID_REPORT_TAG_END_COLLECTION:
     619                usb_hid_report_remove_last_item(usage_path);
     620                return USB_HID_NO_ACTION;
     621                break;
     622
     623        default:
     624                return USB_HID_NO_ACTION;
    491625        }
    492626
     
    503637 * @return Error code
    504638 */
    505 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    506                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    507 {
    508         // TODO take care about the bit length of data
     639int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data,
     640        size_t item_size, usb_hid_report_item_t *report_item,
     641        usb_hid_report_path_t *usage_path) {
     642       
    509643        switch(tag)
    510644        {
    511                 case USB_HID_REPORT_TAG_USAGE_PAGE:
    512                         report_item->usage_page = usb_hid_report_tag_data_uint32(data, item_size);
    513                         break;
    514                 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
    515                         report_item->logical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    516                         break;
    517                 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
    518                         report_item->logical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    519                         break;
    520                 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
    521                         report_item->physical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    522                         break;                 
    523                 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
    524                         report_item->physical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
    525 
    526                         break;
    527                 case USB_HID_REPORT_TAG_UNIT_EXPONENT:
    528                         report_item->unit_exponent = usb_hid_report_tag_data_uint32(data,item_size);
    529                         break;
    530                 case USB_HID_REPORT_TAG_UNIT:
    531                         report_item->unit = usb_hid_report_tag_data_uint32(data,item_size);
    532                         break;
    533                 case USB_HID_REPORT_TAG_REPORT_SIZE:
    534                         report_item->size = usb_hid_report_tag_data_uint32(data,item_size);
    535                         break;
    536                 case USB_HID_REPORT_TAG_REPORT_COUNT:
    537                         report_item->count = usb_hid_report_tag_data_uint32(data,item_size);
    538                         break;
    539                 case USB_HID_REPORT_TAG_REPORT_ID:
    540                         report_item->id = usb_hid_report_tag_data_uint32(data,item_size);
    541                         return USB_HID_RESET_OFFSET;
    542                         break;
    543                 case USB_HID_REPORT_TAG_PUSH:
    544                 case USB_HID_REPORT_TAG_POP:
    545                         /*
    546                          * stack operations are done in top level parsing
    547                          * function
    548                          */
    549                         return tag;
    550                         break;
     645        case USB_HID_REPORT_TAG_USAGE_PAGE:
     646                report_item->usage_page =
     647                        usb_hid_report_tag_data_uint32(data, item_size);
     648                break;
     649
     650        case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
     651                report_item->logical_minimum = USB_HID_UINT32_TO_INT32(
     652                        usb_hid_report_tag_data_uint32(data,item_size),
     653                        item_size * 8);
     654                break;
     655
     656        case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
     657                report_item->logical_maximum = USB_HID_UINT32_TO_INT32(
     658                        usb_hid_report_tag_data_uint32(data,item_size),
     659                        item_size * 8);
     660                break;
     661
     662        case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
     663                report_item->physical_minimum = USB_HID_UINT32_TO_INT32(
     664                        usb_hid_report_tag_data_uint32(data,item_size),
     665                        item_size * 8);
     666                break;                 
     667
     668        case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
     669                report_item->physical_maximum = USB_HID_UINT32_TO_INT32(
     670                        usb_hid_report_tag_data_uint32(data,item_size),
     671                        item_size * 8);
     672                break;
     673
     674        case USB_HID_REPORT_TAG_UNIT_EXPONENT:
     675                report_item->unit_exponent = usb_hid_report_tag_data_uint32(
     676                        data,item_size);
     677                break;
     678
     679        case USB_HID_REPORT_TAG_UNIT:
     680                report_item->unit = usb_hid_report_tag_data_uint32(
     681                        data,item_size);
     682                break;
     683
     684        case USB_HID_REPORT_TAG_REPORT_SIZE:
     685                report_item->size = usb_hid_report_tag_data_uint32(
     686                        data,item_size);
     687                break;
     688
     689        case USB_HID_REPORT_TAG_REPORT_COUNT:
     690                report_item->count = usb_hid_report_tag_data_uint32(
     691                        data,item_size);
     692                break;
     693
     694        case USB_HID_REPORT_TAG_REPORT_ID:
     695                report_item->id = usb_hid_report_tag_data_uint32(data,
     696                        item_size);
     697                return USB_HID_RESET_OFFSET;
     698                break;
     699       
     700        case USB_HID_REPORT_TAG_PUSH:
     701        case USB_HID_REPORT_TAG_POP:
     702                /*
     703                 * stack operations are done in top level parsing
     704                 * function
     705                 */
     706                return tag;
     707                break;
    551708                       
    552                 default:
    553                         return USB_HID_NO_ACTION;
     709        default:
     710                return USB_HID_NO_ACTION;
    554711        }
    555712
     
    566723 * @return Error code
    567724 */
    568 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    569                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
     725int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data,
     726        size_t item_size, usb_hid_report_item_t *report_item,
     727        usb_hid_report_path_t *usage_path)
    570728{
    571729        int32_t extended_usage;
    572730       
    573731        switch(tag) {
    574                 case USB_HID_REPORT_TAG_USAGE:
    575                         switch(report_item->in_delimiter) {
    576                                 case INSIDE_DELIMITER_SET:
    577                                         // nothing to do
    578                                         break;
    579                                 case START_DELIMITER_SET:
    580                                         report_item->in_delimiter = INSIDE_DELIMITER_SET;
    581                                 case OUTSIDE_DELIMITER_SET:
    582                                         extended_usage = ((report_item->usage_page) << 16);
    583                                         extended_usage += usb_hid_report_tag_data_uint32(data,item_size);
    584                                         report_item->usages[report_item->usages_count] = extended_usage;
    585                                         report_item->usages_count++;
    586                                         break;
     732        case USB_HID_REPORT_TAG_USAGE:
     733                switch(report_item->in_delimiter) {
     734                case INSIDE_DELIMITER_SET:
     735                        /* nothing to do
     736                         * we catch only the first one
     737                         */
     738                        break;
     739       
     740                case START_DELIMITER_SET:
     741                        report_item->in_delimiter = INSIDE_DELIMITER_SET;
     742                case OUTSIDE_DELIMITER_SET:
     743                        extended_usage = ((report_item->usage_page) << 16);
     744                        extended_usage += usb_hid_report_tag_data_uint32(
     745                                data,item_size);
     746
     747                        report_item->usages[report_item->usages_count] =
     748                                extended_usage;
     749
     750                        report_item->usages_count++;
     751                        break;
     752                }
     753                break;
     754               
     755        case USB_HID_REPORT_TAG_USAGE_MINIMUM:                 
     756                if (item_size == 3) {
     757                        // usage extended usages
     758                        report_item->extended_usage_page =
     759                            USB_HID_EXTENDED_USAGE_PAGE(
     760                            usb_hid_report_tag_data_uint32(data,item_size));
     761                           
     762
     763                        report_item->usage_minimum =
     764                            USB_HID_EXTENDED_USAGE(
     765                            usb_hid_report_tag_data_uint32(data,item_size));
     766                }
     767                else {
     768                        report_item->usage_minimum =
     769                            usb_hid_report_tag_data_uint32(data,item_size);
     770                }
     771                break;
     772       
     773        case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
     774                if (item_size == 3) {
     775                        if(report_item->extended_usage_page !=
     776                            USB_HID_EXTENDED_USAGE_PAGE(       
     777                            usb_hid_report_tag_data_uint32(data,item_size))) {
     778                               
     779                                return EINVAL;
    587780                        }
    588                         break;
    589                 case USB_HID_REPORT_TAG_USAGE_MINIMUM:                 
    590                         if (item_size == 3) {
    591                                 // usage extended usages
    592                                 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
    593                                 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
     781                               
     782                        // usage extended usages
     783                        report_item->extended_usage_page =
     784                                USB_HID_EXTENDED_USAGE_PAGE(
     785                                usb_hid_report_tag_data_uint32(data,item_size));
     786
     787                        report_item->usage_maximum =
     788                                USB_HID_EXTENDED_USAGE(
     789                                usb_hid_report_tag_data_uint32(data,item_size));
     790                }
     791                else {
     792                        report_item->usage_maximum =
     793                                usb_hid_report_tag_data_uint32(data,item_size);
     794                }
     795
     796                // vlozit zaznamy do pole usages
     797                int32_t i;
     798                for(i = report_item->usage_minimum;
     799                    i <= report_item->usage_maximum; i++) {
     800
     801                        if(report_item->extended_usage_page) {
     802                            report_item->usages[report_item->usages_count++] =
     803                                (report_item->extended_usage_page << 16) + i;
    594804                        }
    595                         else {
    596                                 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size);
     805                        else {                 
     806                            report_item->usages[report_item->usages_count++] =
     807                                (report_item->usage_page << 16) + i;
    597808                        }
    598                         break;
    599                 case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
    600                         if (item_size == 3) {
    601 
    602                                 if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) {
    603                                         return EINVAL;
    604                                 }
    605                                
    606                                 // usage extended usages
    607                                 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
    608                                 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
    609                         }
    610                         else {
    611                                 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    612                         }
    613 
    614                         // vlozit zaznamy do pole usages
    615                         int32_t i;
    616                         for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) {
    617                                 if(report_item->extended_usage_page) {
    618                                         report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i;
    619                                 }
    620                                 else {
    621                                        
    622                                         report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i;
    623                                 }
    624                         }
    625                         report_item->extended_usage_page = 0;
     809                }
     810                report_item->extended_usage_page = 0;
    626811                       
    627                         break;
    628                 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
    629                         report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size);
    630                         break;
    631                 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
    632                         report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size);
    633                         break;
    634                 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
    635                         report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    636                         break;
    637                 case USB_HID_REPORT_TAG_STRING_INDEX:
    638                         report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size);
    639                         break;
    640                 case USB_HID_REPORT_TAG_STRING_MINIMUM:
    641                         report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size);
    642                         break;
    643                 case USB_HID_REPORT_TAG_STRING_MAXIMUM:
    644                         report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size);
    645                         break;                 
    646                 case USB_HID_REPORT_TAG_DELIMITER:
    647                         report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size);
    648                         break;
    649 
    650                 default:
    651                         return USB_HID_NO_ACTION;
     812                break;
     813               
     814        case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
     815                report_item->designator_index =
     816                        usb_hid_report_tag_data_uint32(data,item_size);
     817                break;
     818       
     819        case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
     820                report_item->designator_minimum =
     821                        usb_hid_report_tag_data_uint32(data,item_size);
     822                break;
     823
     824        case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
     825                report_item->designator_maximum =
     826                        usb_hid_report_tag_data_uint32(data,item_size);
     827                break;
     828
     829        case USB_HID_REPORT_TAG_STRING_INDEX:
     830                report_item->string_index =
     831                        usb_hid_report_tag_data_uint32(data,item_size);
     832                break;
     833
     834        case USB_HID_REPORT_TAG_STRING_MINIMUM:
     835                report_item->string_minimum =
     836                        usb_hid_report_tag_data_uint32(data,item_size);
     837                break;
     838
     839        case USB_HID_REPORT_TAG_STRING_MAXIMUM:
     840                report_item->string_maximum =
     841                        usb_hid_report_tag_data_uint32(data,item_size);
     842                break;                 
     843
     844        case USB_HID_REPORT_TAG_DELIMITER:
     845                report_item->in_delimiter =
     846                        usb_hid_report_tag_data_uint32(data,item_size);
     847                break;
     848
     849        default:
     850                return USB_HID_NO_ACTION;
    652851        }
    653852
    654853        return EOK;
    655854}
     855/*---------------------------------------------------------------------------*/
    656856
    657857/**
     
    674874        return result;
    675875}
     876/*---------------------------------------------------------------------------*/
    676877
    677878/**
     
    694895        for(item = head->next; item != head; item = item->next) {
    695896               
    696                 report_item = list_get_instance(item, usb_hid_report_field_t, link);
     897                report_item = list_get_instance(item, usb_hid_report_field_t,
     898                                link);
    697899
    698900                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    699                 usb_log_debug("\t\tSIZE: %zu\n", report_item->size);                           
    700                 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
    701                 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);               
    702                 usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum);               
    703                 usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum);                               
    704                 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
    705                 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
    706                 usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count);
     901                usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
     902                usb_log_debug("\t\tLOGMIN: %d\n",
     903                        report_item->logical_minimum);
     904                usb_log_debug("\t\tLOGMAX: %d\n",
     905                        report_item->logical_maximum);         
     906                usb_log_debug("\t\tPHYMIN: %d\n",
     907                        report_item->physical_minimum);         
     908                usb_log_debug("\t\tPHYMAX: %d\n",
     909                        report_item->physical_maximum);                         
     910                usb_log_debug("\t\ttUSAGEMIN: %X\n",
     911                        report_item->usage_minimum);
     912                usb_log_debug("\t\tUSAGEMAX: %X\n",
     913                               report_item->usage_maximum);
     914                usb_log_debug("\t\tUSAGES COUNT: %zu\n",
     915                        report_item->usages_count);
    707916
    708917                usb_log_debug("\t\tVALUE: %X\n", report_item->value);
     
    716925        }
    717926
    718 
    719 }
     927}
     928/*---------------------------------------------------------------------------*/
     929
    720930/**
    721931 * Prints content of given report descriptor in human readable format.
     
    734944
    735945        while(report_it != &report->reports) {
    736                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
     946                report_des = list_get_instance(report_it,
     947                        usb_hid_report_description_t, link);
    737948                usb_log_debug("Report ID: %d\n", report_des->report_id);
    738949                usb_log_debug("\tType: %d\n", report_des->type);
    739950                usb_log_debug("\tLength: %zu\n", report_des->bit_length);               
     951                usb_log_debug("\tB Size: %zu\n",
     952                        usb_hid_report_byte_size(report,
     953                                report_des->report_id,
     954                                report_des->type));
    740955                usb_log_debug("\tItems: %zu\n", report_des->item_length);               
    741956
    742957                usb_hid_descriptor_print_list(&report_des->report_items);
    743958
    744 /*
    745                 link_t *path_it = report->collection_paths.next;
    746                 while(path_it != &report->collection_paths) {
    747                         usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link));
    748                         path_it = path_it->next;
    749                 }
    750 */             
    751959                report_it = report_it->next;
    752960        }
    753961}
     962/*---------------------------------------------------------------------------*/
    754963
    755964/**
     
    776985
    777986                while(!list_empty(&report_item->usage_path->link)) {
    778                         usb_hid_report_remove_last_item(report_item->usage_path);
     987                    usb_hid_report_remove_last_item(report_item->usage_path);
    779988                }
    780989
     
    788997       
    789998}
     999/*---------------------------------------------------------------------------*/
    7901000
    7911001/** Frees the HID report descriptor parser structure
     
    8031013        usb_hid_report_path_t *path;
    8041014        while(!list_empty(&report->collection_paths)) {
    805                 path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link);
     1015                path = list_get_instance(report->collection_paths.next,
     1016                                usb_hid_report_path_t, link);
     1017
    8061018                usb_hid_report_path_free(path);         
    8071019        }
     
    8111023        usb_hid_report_field_t *field;
    8121024        while(!list_empty(&report->reports)) {
    813                 report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link);
     1025                report_des = list_get_instance(report->reports.next,
     1026                                usb_hid_report_description_t, link);
     1027
    8141028                list_remove(&report_des->link);
    8151029               
    8161030                while(!list_empty(&report_des->report_items)) {
    817                         field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link);
     1031                        field = list_get_instance(
     1032                                report_des->report_items.next,
     1033                                usb_hid_report_field_t, link);
     1034
    8181035                        list_remove(&field->link);
    8191036
     
    8261043        return;
    8271044}
     1045/*---------------------------------------------------------------------------*/
    8281046
    8291047/**
  • uspace/lib/usbhid/src/hidiface.c

    re8f826b r400735e  
    4646 * @return Number of usages returned or negative error code.
    4747 */
    48 int usbhid_dev_get_event_length(int dev_phone)
     48int usbhid_dev_get_event_length(int dev_phone, size_t *size)
    4949{
    5050        if (dev_phone < 0) {
     
    5656            IPC_M_USBHID_GET_EVENT_LENGTH, &len);
    5757        if (rc == EOK) {
    58                 return (int) len;
    59         } else {
    60                 return rc;
    61         }
     58                if (size != NULL) {
     59                        *size = (size_t) len;
     60                }
     61        }
     62       
     63        return rc;
    6264}
    6365
     
    7476 * @return Error code.
    7577 */
    76 int usbhid_dev_get_event(int dev_phone, uint16_t *usage_pages, uint16_t *usages,
    77     size_t usage_count, size_t *actual_usage_count, unsigned int flags)
    78 {
    79         if (dev_phone < 0) {
    80                 return EINVAL;
    81         }
    82         if ((usage_pages == NULL) || (usages == NULL)) {
    83                 return ENOMEM;
    84         }
    85         if (usage_count == 0) {
    86                 return EINVAL;
    87         }
    88 
    89         size_t buffer_size = sizeof(uint16_t) * usage_count * 2;
    90         uint16_t *buffer = malloc(buffer_size);
     78int usbhid_dev_get_event(int dev_phone, uint8_t *buf,
     79    size_t size, size_t *actual_size, int *event_nr, unsigned int flags)
     80{
     81        if (dev_phone < 0) {
     82                return EINVAL;
     83        }
     84        if ((buf == NULL)) {
     85                return ENOMEM;
     86        }
     87        if (size == 0) {
     88                return EINVAL;
     89        }
     90       
     91//      if (size == 0) {
     92//              return EOK;
     93//      }
     94
     95        size_t buffer_size =  size;
     96        uint8_t *buffer = malloc(buffer_size);
    9197        if (buffer == NULL) {
    9298                return ENOMEM;
    9399        }
    94100
     101        ipc_call_t opening_request_call;
    95102        aid_t opening_request = async_send_2(dev_phone,
    96103            DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT,
    97             flags, NULL);
     104            flags, &opening_request_call);
    98105        if (opening_request == 0) {
    99106                free(buffer);
     
    128135        }
    129136
    130         size_t actual_size = IPC_GET_ARG2(data_request_call);
    131         size_t items = actual_size / 2;
     137        size_t act_size = IPC_GET_ARG2(data_request_call);
    132138
    133139        /* Copy the individual items. */
    134         memcpy(usage_pages, buffer, items * sizeof(uint16_t));
    135         memcpy(usages, buffer + items, items * sizeof(uint16_t));
    136 
    137         if (actual_usage_count != NULL) {
    138                 *actual_usage_count = items;
     140        memcpy(buf, buffer, act_size);
     141//      memcpy(usages, buffer + items, items * sizeof(int32_t));
     142
     143        if (actual_size != NULL) {
     144                *actual_size = act_size;
     145        }
     146       
     147        if (event_nr != NULL) {
     148                *event_nr = IPC_GET_ARG1(opening_request_call);
     149        }
     150
     151        return EOK;
     152}
     153
     154
     155int usbhid_dev_get_report_descriptor_length(int dev_phone, size_t *size)
     156{
     157        if (dev_phone < 0) {
     158                return EINVAL;
     159        }
     160
     161        sysarg_t arg_size;
     162        int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE),
     163            IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size);
     164        if (rc == EOK) {
     165                if (size != NULL) {
     166                        *size = (size_t) arg_size;
     167                }
     168        }
     169        return rc;
     170}
     171
     172int usbhid_dev_get_report_descriptor(int dev_phone, uint8_t *buf, size_t size,
     173    size_t *actual_size)
     174{
     175        if (dev_phone < 0) {
     176                return EINVAL;
     177        }
     178        if ((buf == NULL)) {
     179                return ENOMEM;
     180        }
     181        if (size == 0) {
     182                return EINVAL;
     183        }
     184
     185        aid_t opening_request = async_send_1(dev_phone,
     186            DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR,
     187            NULL);
     188        if (opening_request == 0) {
     189                return ENOMEM;
     190        }
     191
     192        ipc_call_t data_request_call;
     193        aid_t data_request = async_data_read(dev_phone, buf, size,
     194            &data_request_call);
     195        if (data_request == 0) {
     196                async_wait_for(opening_request, NULL);
     197                return ENOMEM;
     198        }
     199
     200        sysarg_t data_request_rc;
     201        sysarg_t opening_request_rc;
     202        async_wait_for(data_request, &data_request_rc);
     203        async_wait_for(opening_request, &opening_request_rc);
     204
     205        if (data_request_rc != EOK) {
     206                /* Prefer return code of the opening request. */
     207                if (opening_request_rc != EOK) {
     208                        return (int) opening_request_rc;
     209                } else {
     210                        return (int) data_request_rc;
     211                }
     212        }
     213
     214        if (opening_request_rc != EOK) {
     215                return (int) opening_request_rc;
     216        }
     217
     218        size_t act_size = IPC_GET_ARG2(data_request_call);
     219
     220        if (actual_size != NULL) {
     221                *actual_size = act_size;
    139222        }
    140223
  • uspace/lib/usbhid/src/hidparser.c

    re8f826b r400735e  
    3131 */
    3232/** @file
    33  * HID report descriptor and report data parser implementation.
     33 * USB HID report data parser implementation.
    3434 */
    3535#include <usb/hid/hidparser.h>
     
    4141#include <assert.h>
    4242
    43 
     43/*---------------------------------------------------------------------------*/
    4444/*
    4545 * Data translation private functions
    4646 */
    4747uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
    48 //inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
     48
    4949int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
    50 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value);
     50
     51uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item,
     52        int32_t value);
     53
    5154int usb_pow(int a, int b);
    5255
     56/*---------------------------------------------------------------------------*/
    5357
    5458// TODO: tohle ma bejt asi jinde
     
    5660{
    5761        switch(b) {
    58                 case 0:
    59                         return 1;
    60                         break;
    61                 case 1:
    62                         return a;
    63                         break;
    64                 default:
    65                         return a * usb_pow(a, b-1);
    66                         break;
    67         }
    68 }
    69 
     62        case 0:
     63                return 1;
     64                break;
     65        case 1:
     66                return a;
     67                break;
     68        default:
     69                return a * usb_pow(a, b-1);
     70                break;
     71        }
     72}
     73/*---------------------------------------------------------------------------*/
    7074
    7175/** Returns size of report of specified report id and type in items
     
    9498}
    9599
     100/** Returns size of report of specified report id and type in bytes
     101 *
     102 * @param parser Opaque report parser structure
     103 * @param report_id
     104 * @param type
     105 * @return Number of items in specified report
     106 */
     107size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id,
     108                           usb_hid_report_type_t type)
     109{
     110        usb_hid_report_description_t *report_des;
     111
     112        if(report == NULL) {
     113                return 0;
     114        }
     115
     116        report_des = usb_hid_report_find_description (report, report_id, type);
     117        if(report_des == NULL){
     118                return 0;
     119        }
     120        else {
     121                return ((report_des->bit_length + 7) / 8) ;
     122        }
     123}
     124/*---------------------------------------------------------------------------*/
    96125
    97126/** Parse and act upon a HID report.
     
    103132 * @return Error code.
    104133 */
    105 int usb_hid_parse_report(const usb_hid_report_t *report,
    106     const uint8_t *data, size_t size, uint8_t *report_id)
     134int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
     135        size_t size, uint8_t *report_id)
    107136{
    108137        link_t *list_item;
     
    125154
    126155        report_des = usb_hid_report_find_description(report, *report_id, type);
     156        if(report_des == NULL) {
     157                return EINVAL;
     158        }
    127159
    128160        /* read data */
     
    130162        while(list_item != &(report_des->report_items)) {
    131163
    132                 item = list_get_instance(list_item, usb_hid_report_field_t, link);
     164                item = list_get_instance(list_item, usb_hid_report_field_t,
     165                                link);
    133166
    134167                if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
     
    137170
    138171                                // array
    139                                 item->value = usb_hid_translate_data(item, data);
     172                                item->value =
     173                                        usb_hid_translate_data(item, data);
    140174               
    141                                 item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]);
    142                                 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]);                             
     175                                item->usage = USB_HID_EXTENDED_USAGE(
     176                                    item->usages[item->value - item->physical_minimum]);
     177
     178                                item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(
     179                                    item->usages[item->value - item->physical_minimum]);
    143180
    144181                                usb_hid_report_set_last_item (item->collection_path,
    145                                                               USB_HID_TAG_CLASS_GLOBAL,
    146                                                               item->usage_page);
     182                                    USB_HID_TAG_CLASS_GLOBAL, item->usage_page);
     183
    147184                                usb_hid_report_set_last_item (item->collection_path,
    148                                                               USB_HID_TAG_CLASS_LOCAL,
    149                                                               item->usage);
     185                                    USB_HID_TAG_CLASS_LOCAL, item->usage);
    150186                               
    151187                        }
     
    162198}
    163199
     200/*---------------------------------------------------------------------------*/
    164201/**
    165202 * Translate data from the report as specified in report descriptor item
     
    167204 * @param item Report descriptor item with definition of translation
    168205 * @param data Data to translate
    169  * @param j Index of processed field in report descriptor item
    170206 * @return Translated data
    171207 */
     
    236272        }
    237273
    238         return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum);
    239        
    240 }
    241 
    242 /*** OUTPUT API **/
     274        return (int)(((value - item->logical_minimum) / resolution) +
     275                item->physical_minimum);
     276       
     277}
     278
     279/*---------------------------------------------------------------------------*/
     280/* OUTPUT API */
    243281
    244282/**
     
    250288 * @return Returns allocated output buffer for specified output
    251289 */
    252 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id)
     290uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
     291        uint8_t report_id)
    253292{
    254293        if(report == NULL) {
     
    260299        usb_hid_report_description_t *report_des = NULL;
    261300        while(report_it != &report->reports) {
    262                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
    263                 if((report_des->report_id == report_id) && (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
     301                report_des = list_get_instance(report_it,
     302                        usb_hid_report_description_t, link);
     303               
     304                if((report_des->report_id == report_id) &&
     305                        (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
    264306                        break;
    265307                }
     
    303345 * @return Error code
    304346 */
    305 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
    306                                     uint8_t *buffer, size_t size)
     347int usb_hid_report_output_translate(usb_hid_report_t *report,
     348        uint8_t report_id, uint8_t *buffer, size_t size)
    307349{
    308350        link_t *item;   
     
    320362        }
    321363
    322         usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    323        
    324364        usb_hid_report_description_t *report_des;
    325         report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT);
     365        report_des = usb_hid_report_find_description (report, report_id,
     366                USB_HID_REPORT_TYPE_OUTPUT);
     367       
    326368        if(report_des == NULL){
    327369                return EINVAL;
     
    333375                report_item = list_get_instance(item, usb_hid_report_field_t, link);
    334376
    335                 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value);
    336                
    337377                if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
    338378                                       
    339379                        // array
    340                         value = usb_hid_translate_data_reverse(report_item, report_item->value);
     380                        value = usb_hid_translate_data_reverse(report_item,
     381                                report_item->value);
     382
    341383                        offset = report_item->offset;
    342384                        length = report_item->size;
     
    344386                else {
    345387                        // variable item
    346                         value  = usb_hid_translate_data_reverse(report_item, report_item->value);
     388                        value  = usb_hid_translate_data_reverse(report_item,
     389                                report_item->value);
     390
    347391                        offset = report_item->offset;
    348392                        length = report_item->size;
     
    353397                if((offset/8) == ((offset+length-1)/8)) {
    354398                        // je to v jednom bytu
    355                         if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) {
     399                        if(((size_t)(offset/8) >= size) ||
     400                                ((size_t)(offset+length-1)/8) >= size) {
    356401                                break; // TODO ErrorCode
    357402                        }
     
    370415                                if(i == (offset/8)) {
    371416                                        tmp_value = value;
    372                                         tmp_value = tmp_value & ((1 << (8-(offset%8)))-1);                             
     417                                        tmp_value = tmp_value &
     418                                                ((1 << (8-(offset%8)))-1);
     419
    373420                                        tmp_value = tmp_value << (offset%8);
    374421       
    375                                         mask = ~(((1 << (8-(offset%8)))-1) << (offset%8));
    376                                         buffer[i] = (buffer[i] & mask) | tmp_value;                     
     422                                        mask = ~(((1 << (8-(offset%8)))-1) <<
     423                                                        (offset%8));
     424
     425                                        buffer[i] = (buffer[i] & mask) |
     426                                                tmp_value;
    377427                                }
    378428                                else if (i == ((offset + length -1)/8)) {
    379429                                       
    380                                         value = value >> (length - ((offset + length) % 8));
    381                                         value = value & ((1 << (length - ((offset + length) % 8))) - 1);
     430                                        value = value >> (length -
     431                                                ((offset + length) % 8));
     432
     433                                        value = value & ((1 << (length -
     434                                                ((offset + length) % 8))) - 1);
    382435                               
    383                                         mask = (1 << (length - ((offset + length) % 8))) - 1;
     436                                        mask = (1 << (length -
     437                                                ((offset + length) % 8))) - 1;
     438
    384439                                        buffer[i] = (buffer[i] & mask) | value;
    385440                                }
     
    396451        }
    397452       
    398         usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    399 
    400453        return EOK;
    401454}
    402455
     456/*---------------------------------------------------------------------------*/
    403457/**
    404458 * Translate given data for putting them into the outoput report
     
    407461 * @return ranslated value
    408462 */
    409 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int value)
     463uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item,
     464        int value)
    410465{
    411466        int ret=0;
     
    431486        }
    432487
    433         ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum;
    434         usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), ret(%x)\n", value, resolution, item->physical_minimum, item->logical_minimum, ret);
     488        ret = ((value - item->physical_minimum) * resolution) +
     489                item->logical_minimum;
     490
     491        usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), \
     492                ret(%x)\n", value, resolution, item->physical_minimum,
     493                item->logical_minimum, ret);
    435494       
    436495        if((item->logical_minimum < 0) || (item->logical_maximum < 0)){
     
    440499}
    441500
    442 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item)
     501/*---------------------------------------------------------------------------*/
     502/**
     503 * Clones given state table
     504 *
     505 * @param item State table to clone
     506 * @return Pointer to the cloned item
     507 */
     508usb_hid_report_item_t *usb_hid_report_item_clone(
     509        const usb_hid_report_item_t *item)
    443510{
    444511        usb_hid_report_item_t *new_report_item;
     
    453520}
    454521
    455 
     522/*---------------------------------------------------------------------------*/
     523/**
     524 * Function for sequence walking through the report. Returns next field in the
     525 * report or the first one when no field is given.
     526 *
     527 * @param report Searched report structure
     528 * @param field Current field. If NULL is given, the first one in the report
     529 * is returned. Otherwise the next one i nthe list is returned.
     530 * @param path Usage path specifying which fields wa are interested in.
     531 * @param flags Flags defining mode of usage paths comparison
     532 * @param type Type of report we search.
     533 * @retval NULL if no field is founded
     534 * @retval Pointer to the founded report structure when founded
     535 */
    456536usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
    457                                                         usb_hid_report_field_t *field,
    458                             usb_hid_report_path_t *path, int flags,
    459                             usb_hid_report_type_t type)
    460 {
    461         usb_hid_report_description_t *report_des = usb_hid_report_find_description (report, path->report_id, type);
     537        usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags,
     538        usb_hid_report_type_t type)
     539{
     540        usb_hid_report_description_t *report_des =
     541                usb_hid_report_find_description(report, path->report_id, type);
     542
    462543        link_t *field_it;
    463544       
     
    467548
    468549        if(field == NULL){
    469                 // vezmu prvni co mathuje podle path!!
    470550                field_it = report_des->report_items.next;
    471551        }
     
    475555
    476556        while(field_it != &report_des->report_items) {
    477                 field = list_get_instance(field_it, usb_hid_report_field_t, link);
     557                field = list_get_instance(field_it, usb_hid_report_field_t,
     558                        link);
    478559
    479560                if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
    480                         usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
    481                         if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){
    482                                 usb_hid_report_remove_last_item (field->collection_path);
     561                        usb_hid_report_path_append_item (
     562                                field->collection_path, field->usage_page,
     563                                field->usage);
     564
     565                        if(usb_hid_report_compare_usage_path(
     566                                field->collection_path, path, flags) == EOK){
     567
     568                                usb_hid_report_remove_last_item(
     569                                        field->collection_path);
     570
    483571                                return field;
    484572                        }
    485                         usb_hid_report_remove_last_item (field->collection_path);
     573                        usb_hid_report_remove_last_item (
     574                                field->collection_path);
    486575                }
    487576                field_it = field_it->next;
     
    491580}
    492581
    493 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
     582/*---------------------------------------------------------------------------*/
     583/**
     584 * Returns next report_id of report of specified type. If zero is given than
     585 * first report_id of specified type is returned (0 is not legal value for
     586 * repotr_id)
     587 *
     588 * @param report_id Current report_id, 0 if there is no current report_id
     589 * @param type Type of searched report
     590 * @param report Report structure inwhich we search
     591 * @retval 0 if report structure is null or there is no specified report
     592 * @retval report_id otherwise
     593 */
     594uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report,
     595        uint8_t report_id, usb_hid_report_type_t type)
    494596{
    495597        if(report == NULL){
     
    500602        link_t *report_it;
    501603       
    502         if(report_id == 0) {
    503                 report_it = usb_hid_report_find_description (report, report_id, type)->link.next;               
     604        if(report_id > 0) {
     605                report_it = usb_hid_report_find_description(report, report_id,
     606                        type)->link.next;               
    504607        }
    505608        else {
     
    508611
    509612        while(report_it != &report->reports) {
    510                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
     613                report_des = list_get_instance(report_it,
     614                        usb_hid_report_description_t, link);
     615
    511616                if(report_des->type == type){
    512617                        return report_des->report_id;
     
    517622}
    518623
     624/*---------------------------------------------------------------------------*/
     625/**
     626 * Reset all local items in given state table
     627 *
     628 * @param report_item State table containing current state of report
     629 * descriptor parsing
     630 *
     631 * @return void
     632 */
    519633void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item)
    520634{
  • uspace/lib/usbhid/src/hidpath.c

    re8f826b r400735e  
    4141#include <assert.h>
    4242
    43 
    44 #define USB_HID_SAME_USAGE(usage1, usage2)      ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0))
    45 #define USB_HID_SAME_USAGE_PAGE(page1, page2)   ((page1 == page2) || (page1 == 0) || (page2 == 0))
    46 
     43/*---------------------------------------------------------------------------*/
     44/**
     45 * Compares two usages if they are same or not or one of the usages is not
     46 * set.
     47 *
     48 * @param usage1
     49 * @param usage2
     50 * @return boolean
     51 */
     52#define USB_HID_SAME_USAGE(usage1, usage2)              \
     53        ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0))
     54
     55/**
     56 * Compares two usage pages if they are same or not or one of them is not set.
     57 *
     58 * @param page1
     59 * @param page2
     60 * @return boolean
     61 */
     62#define USB_HID_SAME_USAGE_PAGE(page1, page2)   \
     63        ((page1 == page2) || (page1 == 0) || (page2 == 0))
     64
     65/*---------------------------------------------------------------------------*/
    4766/**
    4867 * Appends one item (couple of usage_path and usage) into the usage path
     
    7392}
    7493
     94/*---------------------------------------------------------------------------*/
    7595/**
    7696 * Removes last item from the usage path structure
     
    91111}
    92112
     113/*---------------------------------------------------------------------------*/
    93114/**
    94115 * Nulls last item of the usage path structure.
     
    102123       
    103124        if(!list_empty(&usage_path->head)){     
    104                 item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
     125                item = list_get_instance(usage_path->head.prev,
     126                        usb_hid_report_usage_path_t, link);
     127
    105128                memset(item, 0, sizeof(usb_hid_report_usage_path_t));
    106129        }
    107130}
    108131
     132/*---------------------------------------------------------------------------*/
    109133/**
    110134 * Modifies last item of usage path structure by given usage page or usage
     
    137161}
    138162
    139 
     163/*---------------------------------------------------------------------------*/
     164/**
     165 *
     166 *
     167 *
     168 *
     169 */
    140170void usb_hid_print_usage_path(usb_hid_report_path_t *path)
    141171{
     
    147177        while(item != &path->head) {
    148178
    149                 path_item = list_get_instance(item, usb_hid_report_usage_path_t, link);
     179                path_item = list_get_instance(item, usb_hid_report_usage_path_t,
     180                        link);
     181
    150182                usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
    151183                usb_log_debug("\tUSAGE: %X\n", path_item->usage);
    152184                usb_log_debug("\tFLAGS: %d\n", path_item->flags);               
    153185               
    154                 item = item->next;
    155         }
    156 }
    157 
     186        item = item->next;
     187        }
     188}
     189
     190/*---------------------------------------------------------------------------*/
    158191/**
    159192 * Compares two usage paths structures
     
    192225       
    193226        switch(flags){
    194                 /* path is somewhere in report_path */
    195                 case USB_HID_PATH_COMPARE_ANYWHERE:
    196                         if(path->depth != 1){
    197                                 return 1;
    198                         }
    199 
    200                         // projit skrz cestu a kdyz nekde sedi tak vratim EOK
    201                         // dojduli az za konec tak nnesedi
    202                         report_link = report_path->head.next;
    203                         path_link = path->head.next;
    204                         path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
    205 
    206                         while(report_link != &report_path->head) {
    207                                 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
    208                                 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){
    209                                         if(only_page == 0){
    210                                                 if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) {
    211                                                         return EOK;
    212                                                 }
    213                                         }
    214                                         else {
     227        /* path is somewhere in report_path */
     228        case USB_HID_PATH_COMPARE_ANYWHERE:
     229                if(path->depth != 1){
     230                        return 1;
     231                }
     232
     233                report_link = report_path->head.next;
     234                path_link = path->head.next;
     235                path_item = list_get_instance(path_link,
     236                        usb_hid_report_usage_path_t, link);
     237
     238                while(report_link != &report_path->head) {
     239                        report_item = list_get_instance(report_link,
     240                                usb_hid_report_usage_path_t, link);
     241                               
     242                        if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     243                                path_item->usage_page)){
     244                                       
     245                                if(only_page == 0){
     246                                        if(USB_HID_SAME_USAGE(
     247                                                report_item->usage,
     248                                                path_item->usage)) {
     249                                                       
    215250                                                return EOK;
    216251                                        }
    217252                                }
    218 
     253                                else {
     254                                        return EOK;
     255                                }
     256                        }
     257
     258                        report_link = report_link->next;
     259                }
     260
     261                return 1;
     262                break;
     263
     264        /* the paths must be identical */
     265        case USB_HID_PATH_COMPARE_STRICT:
     266                if(report_path->depth != path->depth){
     267                        return 1;
     268                }
     269               
     270        /* path is prefix of the report_path */
     271        case USB_HID_PATH_COMPARE_BEGIN:
     272       
     273                report_link = report_path->head.next;
     274                path_link = path->head.next;
     275                       
     276                while((report_link != &report_path->head) &&
     277                      (path_link != &path->head)) {
     278                                         
     279                        report_item = list_get_instance(report_link,
     280                                usb_hid_report_usage_path_t, link);
     281                                         
     282                        path_item = list_get_instance(path_link,
     283                                usb_hid_report_usage_path_t, link);
     284
     285                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     286                                path_item->usage_page) || ((only_page == 0) &&
     287                            !USB_HID_SAME_USAGE(report_item->usage,
     288                                path_item->usage))) {
     289                       
     290                                return 1;
     291                        }
     292                        else {
    219293                                report_link = report_link->next;
     294                                path_link = path_link->next;                   
    220295                        }
    221 
    222                         return 1;
    223                         break;
    224                 /* the paths must be identical */
    225                 case USB_HID_PATH_COMPARE_STRICT:
    226                                 if(report_path->depth != path->depth){
    227                                         return 1;
    228                                 }
    229                
    230                 /* path is prefix of the report_path */
    231                 case USB_HID_PATH_COMPARE_BEGIN:
    232        
    233                                 report_link = report_path->head.next;
    234                                 path_link = path->head.next;
    235                        
    236                                 while((report_link != &report_path->head) &&
    237                                       (path_link != &path->head)) {
    238                                                  
    239                                         report_item = list_get_instance(report_link,
    240                                                                         usb_hid_report_usage_path_t,
    241                                                                         link);
    242                                                  
    243                                         path_item = list_get_instance(path_link,
    244                                                                       usb_hid_report_usage_path_t,
    245                                                                       link);           
    246 
    247                                         if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
    248                                            ((only_page == 0) &&
    249                                             !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
    250                                                        
    251                                                    return 1;
    252                                         } else {
    253                                                 report_link = report_link->next;
    254                                                 path_link = path_link->next;                   
    255                                         }
    256296                       
    257297                                }
    258298
    259                                 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) ||
    260                                    ((report_link == &report_path->head) && (path_link == &path->head))) {
    261                                         return EOK;
    262                                 }
    263                                 else {
     299                if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
     300                        (path_link == &path->head)) ||
     301                   ((report_link == &report_path->head) &&
     302                        (path_link == &path->head))) {
     303                               
     304                        return EOK;
     305                }
     306                else {
     307                        return 1;
     308                }                                               
     309                break;
     310
     311        /* path is suffix of report_path */
     312        case USB_HID_PATH_COMPARE_END:
     313
     314                report_link = report_path->head.prev;
     315                path_link = path->head.prev;
     316
     317                if(list_empty(&path->head)){
     318                        return EOK;
     319                }
     320                       
     321                while((report_link != &report_path->head) &&
     322                      (path_link != &path->head)) {
     323                                                 
     324                        report_item = list_get_instance(report_link,
     325                                usb_hid_report_usage_path_t, link);
     326
     327                        path_item = list_get_instance(path_link,
     328                                usb_hid_report_usage_path_t, link);             
     329                                                 
     330                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     331                                path_item->usage_page) || ((only_page == 0) &&
     332                            !USB_HID_SAME_USAGE(report_item->usage,
     333                                path_item->usage))) {
     334                                               
    264335                                        return 1;
    265                                 }                                               
    266                         break;
    267 
    268                 /* path is suffix of report_path */
    269                 case USB_HID_PATH_COMPARE_END:
    270 
    271                                 report_link = report_path->head.prev;
    272                                 path_link = path->head.prev;
    273 
    274                                 if(list_empty(&path->head)){
    275                                         return EOK;
    276                                 }
     336                        } else {
     337                                report_link = report_link->prev;
     338                                path_link = path_link->prev;                   
     339                        }
     340
     341                }
     342
     343                if(path_link == &path->head) {
     344                        return EOK;
     345                }
     346                else {
     347                        return 1;
     348                }                                               
    277349                       
    278                                 while((report_link != &report_path->head) &&
    279                                       (path_link != &path->head)) {
    280                                                  
    281                                         report_item = list_get_instance(report_link,
    282                                                                         usb_hid_report_usage_path_t,
    283                                                                         link);
    284                                         path_item = list_get_instance(path_link,
    285                                                                       usb_hid_report_usage_path_t,
    286                                                                       link);           
    287                                                  
    288                                         if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
    289                                            ((only_page == 0) &&
    290                                             !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
    291                                                         return 1;
    292                                         } else {
    293                                                 report_link = report_link->prev;
    294                                                 path_link = path_link->prev;                   
    295                                         }
    296                        
    297                                 }
    298 
    299                                 if(path_link == &path->head) {
    300                                         return EOK;
    301                                 }
    302                                 else {
    303                                         return 1;
    304                                 }                                               
    305                        
    306                         break;
    307 
    308                 default:
    309                         return EINVAL;
    310         }
    311 }
    312 
     350                break;
     351
     352        default:
     353                return EINVAL;
     354        }
     355}
     356
     357/*---------------------------------------------------------------------------*/
    313358/**
    314359 * Allocates and initializes new usage path structure.
     
    332377}
    333378
     379/*---------------------------------------------------------------------------*/
    334380/**
    335381 * Releases given usage path structure.
     
    348394}
    349395
    350 
     396/*---------------------------------------------------------------------------*/
    351397/**
    352398 * Clone content of given usage path to the new one
     
    355401 * @return New copy of given usage path structure
    356402 */
    357 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
     403usb_hid_report_path_t *usb_hid_report_path_clone(
     404        usb_hid_report_path_t *usage_path)
    358405{
    359406        link_t *path_link;
     
    374421        path_link = usage_path->head.next;
    375422        while(path_link != &usage_path->head) {
    376                 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t,
    377                                               link);
     423                path_item = list_get_instance(path_link,
     424                        usb_hid_report_usage_path_t, link);
     425
    378426                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
    379427                if(new_path_item == NULL) {
     
    395443}
    396444
    397 
     445/*---------------------------------------------------------------------------*/
    398446/**
    399447 * Sets report id in usage path structure
     
    403451 * @return Error code
    404452 */
    405 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id)
     453int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path,
     454        uint8_t report_id)
    406455{
    407456        if(path == NULL){
  • uspace/lib/usbhid/src/hidreport.c

    re8f826b r400735e  
    164164
    165165int usb_hid_process_report_descriptor(usb_device_t *dev,
    166     usb_hid_report_t *report)
     166    usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size)
    167167{
    168168        if (dev == NULL || report == NULL) {
     
    172172        }
    173173       
    174         uint8_t *report_desc = NULL;
    175         size_t report_size;
    176        
    177         int rc = usb_hid_get_report_descriptor(dev, &report_desc,
    178             &report_size);
     174//      uint8_t *report_desc = NULL;
     175//      size_t report_size;
     176       
     177        int rc = usb_hid_get_report_descriptor(dev, report_desc, report_size);
    179178       
    180179        if (rc != EOK) {
    181180                usb_log_error("Problem with getting Report descriptor: %s.\n",
    182181                    str_error(rc));
    183                 if (report_desc != NULL) {
    184                         free(report_desc);
     182                if (*report_desc != NULL) {
     183                        free(*report_desc);
     184                        *report_desc = NULL;
    185185                }
    186186                return rc;
    187187        }
    188188       
    189         assert(report_desc != NULL);
    190        
    191         rc = usb_hid_parse_report_descriptor(report, report_desc, report_size);
     189        assert(*report_desc != NULL);
     190       
     191        rc = usb_hid_parse_report_descriptor(report, *report_desc, *report_size);
    192192        if (rc != EOK) {
    193193                usb_log_error("Problem parsing Report descriptor: %s.\n",
    194194                    str_error(rc));
    195                 free(report_desc);
     195                free(*report_desc);
     196                *report_desc = NULL;
    196197                return rc;
    197198        }
    198199       
    199200        usb_hid_descriptor_print(report);
    200         free(report_desc);
    201201       
    202202        return EOK;
Note: See TracChangeset for help on using the changeset viewer.