Changeset a6afb4c in mainline for uspace/lib/usb/include


Ignore:
Timestamp:
2018-01-23T14:02:35Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4db49344
Parents:
e7e1fd3
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-23 13:35:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-23 14:02:35)
Message:

usbhost: check validity of arguments, cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/usb.h

    re7e1fd3 ra6afb4c  
    6363}
    6464
     65static inline bool usb_speed_is_valid(const usb_speed_t s)
     66{
     67        return (s >= USB_SPEED_LOW) && (s < USB_SPEED_MAX);
     68}
     69
    6570const char *usb_str_speed(usb_speed_t);
    6671
     
    97102static inline bool usb_address_is_valid(usb_address_t a)
    98103{
    99         return (a >= USB_ADDRESS_DEFAULT) && (a <= USB11_ADDRESS_MAX);
     104        return a <= USB11_ADDRESS_MAX;
    100105}
    101106
     
    105110/** Maximum endpoint number in USB */
    106111#define USB_ENDPOINT_MAX 16
     112
     113/** There might be two directions for every endpoint number (except 0) */
     114#define USB_ENDPOINT_COUNT (2 * USB_ENDPOINT_MAX)
    107115
    108116/** Check USB endpoint for allowed values.
     
    115123static inline bool usb_endpoint_is_valid(usb_endpoint_t ep)
    116124{
    117         return (ep >= USB_ENDPOINT_DEFAULT_CONTROL) &&
    118             (ep < USB_ENDPOINT_MAX);
     125        return ep < USB_ENDPOINT_MAX;
    119126}
    120127
    121 /** Check USB target for allowed values (address and endpoint).
     128/**
     129 * Check USB target for allowed values (address, endpoint, stream).
    122130 *
    123131 * @param target.
    124132 * @return True, if values are wihtin limits, false otherwise.
    125133 */
    126 static inline bool usb_target_is_valid(usb_target_t target)
     134static inline bool usb_target_is_valid(usb_target_t *target)
    127135{
    128         return usb_address_is_valid(target.address) &&
    129             usb_endpoint_is_valid(target.endpoint);
     136        return usb_address_is_valid(target->address) &&
     137            usb_endpoint_is_valid(target->endpoint);
     138
     139        // A 16-bit Stream ID is always valid.
    130140}
    131141
     
    136146 * @return Whether @p a and @p b points to the same pipe on the same device.
    137147 */
    138 static inline int usb_target_same(usb_target_t a, usb_target_t b)
     148static inline bool usb_target_same(usb_target_t a, usb_target_t b)
    139149{
    140150        return (a.address == b.address)
     
    142152}
    143153
    144 /** General handle type.
    145  * Used by various USB functions as opaque handle.
    146  */
    147 typedef sysarg_t usb_handle_t;
     154static inline bool usb_transfer_type_is_valid(usb_transfer_type_t type)
     155{
     156        return (type >= 0) && (type < USB_TRANSFER_COUNT);
     157}
     158
     159static inline bool usb_direction_is_valid(usb_direction_t dir)
     160{
     161        return (dir >= 0) && (dir < USB_DIRECTION_COUNT);
     162}
    148163
    149164/** USB packet identifier. */
Note: See TracChangeset for help on using the changeset viewer.