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

Changeset 711f5fb8 in mainline


Ignore:
Timestamp:
2013-02-08T15:48:41Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
81da273b
Parents:
af4e464e
Message:

libusb: Add address and endpoint sanity helpers.

File:
1 edited

Legend:

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

    raf4e464e r711f5fb8  
    112112#define USB11_ADDRESS_MAX 128
    113113
     114/** Check USB address for allowed values.
     115 *
     116 * @param ep USB address.
     117 * @return True, if value is wihtin limits, false otherwise.
     118 */
     119static inline bool usb_address_is_valid(usb_address_t a)
     120{
     121        return (a >= USB_ADDRESS_DEFAULT) && (a < USB11_ADDRESS_MAX);
     122}
     123
    114124/** USB endpoint number type.
    115125 * Negative values could be used to indicate error.
     
    117127typedef int16_t usb_endpoint_t;
    118128
    119 /** Maximum endpoint number in USB 1.1.
    120  */
     129/** Default control endpoint */
     130#define USB_ENDPOINT_DEFAULT_CONTROL 0
     131/** Maximum endpoint number in USB 1.1. */
    121132#define USB11_ENDPOINT_MAX 16
     133
     134/** Check USB endpoint for allowed values.
     135 *
     136 * @param ep USB endpoint number.
     137 * @return True, if value is wihtin limits, false otherwise.
     138 */
     139static inline bool usb_endpoint_is_valid(usb_endpoint_t ep)
     140{
     141        return (ep >= USB_ENDPOINT_DEFAULT_CONTROL) &&
     142            (ep < USB11_ENDPOINT_MAX);
     143}
    122144
    123145
     
    133155} usb_target_t;
    134156
     157
    135158/** Check USB target for allowed values (address and endpoint).
    136159 *
     
    140163static inline bool usb_target_is_valid(usb_target_t target)
    141164{
    142         return !(target.endpoint > 15 || target.endpoint < 0
    143             || target.address >= USB11_ADDRESS_MAX || target.address < 0);
     165        return usb_address_is_valid(target.address) &&
     166            usb_endpoint_is_valid(target.endpoint);
    144167}
    145168
Note: See TracChangeset for help on using the changeset viewer.