linux/include/uapi/linux/usb/functionfs.h
<<
>>
Prefs
   1#ifndef _UAPI__LINUX_FUNCTIONFS_H__
   2#define _UAPI__LINUX_FUNCTIONFS_H__
   3
   4
   5#include <linux/types.h>
   6#include <linux/ioctl.h>
   7
   8#include <linux/usb/ch9.h>
   9
  10
  11enum {
  12        FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
  13        FUNCTIONFS_STRINGS_MAGIC = 2,
  14        FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
  15};
  16
  17enum functionfs_flags {
  18        FUNCTIONFS_HAS_FS_DESC = 1,
  19        FUNCTIONFS_HAS_HS_DESC = 2,
  20        FUNCTIONFS_HAS_SS_DESC = 4,
  21        FUNCTIONFS_HAS_MS_OS_DESC = 8,
  22        FUNCTIONFS_VIRTUAL_ADDR = 16,
  23        FUNCTIONFS_EVENTFD = 32,
  24};
  25
  26/* Descriptor of an non-audio endpoint */
  27struct usb_endpoint_descriptor_no_audio {
  28        __u8  bLength;
  29        __u8  bDescriptorType;
  30
  31        __u8  bEndpointAddress;
  32        __u8  bmAttributes;
  33        __le16 wMaxPacketSize;
  34        __u8  bInterval;
  35} __attribute__((packed));
  36
  37struct usb_functionfs_descs_head_v2 {
  38        __le32 magic;
  39        __le32 length;
  40        __le32 flags;
  41        /*
  42         * __le32 fs_count, hs_count, fs_count; must be included manually in
  43         * the structure taking flags into consideration.
  44         */
  45} __attribute__((packed));
  46
  47/* Legacy format, deprecated as of 3.14. */
  48struct usb_functionfs_descs_head {
  49        __le32 magic;
  50        __le32 length;
  51        __le32 fs_count;
  52        __le32 hs_count;
  53} __attribute__((packed, deprecated));
  54
  55/* MS OS Descriptor header */
  56struct usb_os_desc_header {
  57        __u8    interface;
  58        __le32  dwLength;
  59        __le16  bcdVersion;
  60        __le16  wIndex;
  61        union {
  62                struct {
  63                        __u8    bCount;
  64                        __u8    Reserved;
  65                };
  66                __le16  wCount;
  67        };
  68} __attribute__((packed));
  69
  70struct usb_ext_compat_desc {
  71        __u8    bFirstInterfaceNumber;
  72        __u8    Reserved1;
  73        __u8    CompatibleID[8];
  74        __u8    SubCompatibleID[8];
  75        __u8    Reserved2[6];
  76};
  77
  78struct usb_ext_prop_desc {
  79        __le32  dwSize;
  80        __le32  dwPropertyDataType;
  81        __le16  wPropertyNameLength;
  82} __attribute__((packed));
  83
  84#ifndef __KERNEL__
  85
  86/*
  87 * Descriptors format:
  88 *
  89 * | off | name      | type         | description                          |
  90 * |-----+-----------+--------------+--------------------------------------|
  91 * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC_V2      |
  92 * |   4 | length    | LE32         | length of the whole data chunk       |
  93 * |   8 | flags     | LE32         | combination of functionfs_flags      |
  94 * |     | fs_count  | LE32         | number of full-speed descriptors     |
  95 * |     | hs_count  | LE32         | number of high-speed descriptors     |
  96 * |     | ss_count  | LE32         | number of super-speed descriptors    |
  97 * |     | os_count  | LE32         | number of MS OS descriptors          |
  98 * |     | fs_descrs | Descriptor[] | list of full-speed descriptors       |
  99 * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
 100 * |     | ss_descrs | Descriptor[] | list of super-speed descriptors      |
 101 * |     | os_descrs | OSDesc[]     | list of MS OS descriptors            |
 102 *
 103 * Depending on which flags are set, various fields may be missing in the
 104 * structure.  Any flags that are not recognised cause the whole block to be
 105 * rejected with -ENOSYS.
 106 *
 107 * Legacy descriptors format (deprecated as of 3.14):
 108 *
 109 * | off | name      | type         | description                          |
 110 * |-----+-----------+--------------+--------------------------------------|
 111 * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC         |
 112 * |   4 | length    | LE32         | length of the whole data chunk       |
 113 * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
 114 * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
 115 * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
 116 * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
 117 *
 118 * All numbers must be in little endian order.
 119 *
 120 * Descriptor[] is an array of valid USB descriptors which have the following
 121 * format:
 122 *
 123 * | off | name            | type | description              |
 124 * |-----+-----------------+------+--------------------------|
 125 * |   0 | bLength         | U8   | length of the descriptor |
 126 * |   1 | bDescriptorType | U8   | descriptor type          |
 127 * |   2 | payload         |      | descriptor's payload     |
 128 *
 129 * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
 130 * the following formats:
 131 *
 132 * | off | name            | type | description              |
 133 * |-----+-----------------+------+--------------------------|
 134 * |   0 | inteface        | U8   | related interface number |
 135 * |   1 | dwLength        | U32  | length of the descriptor |
 136 * |   5 | bcdVersion      | U16  | currently supported: 1   |
 137 * |   7 | wIndex          | U16  | currently supported: 4   |
 138 * |   9 | bCount          | U8   | number of ext. compat.   |
 139 * |  10 | Reserved        | U8   | 0                        |
 140 * |  11 | ExtCompat[]     |      | list of ext. compat. d.  |
 141 *
 142 * | off | name            | type | description              |
 143 * |-----+-----------------+------+--------------------------|
 144 * |   0 | inteface        | U8   | related interface number |
 145 * |   1 | dwLength        | U32  | length of the descriptor |
 146 * |   5 | bcdVersion      | U16  | currently supported: 1   |
 147 * |   7 | wIndex          | U16  | currently supported: 5   |
 148 * |   9 | wCount          | U16  | number of ext. compat.   |
 149 * |  11 | ExtProp[]       |      | list of ext. prop. d.    |
 150 *
 151 * ExtCompat[] is an array of valid Extended Compatiblity descriptors
 152 * which have the following format:
 153 *
 154 * | off | name                  | type | description                         |
 155 * |-----+-----------------------+------+-------------------------------------|
 156 * |   0 | bFirstInterfaceNumber | U8   | index of the interface or of the 1st|
 157 * |     |                       |      | interface in an IAD group           |
 158 * |   1 | Reserved              | U8   | 0                                   |
 159 * |   2 | CompatibleID          | U8[8]| compatible ID string                |
 160 * |  10 | SubCompatibleID       | U8[8]| subcompatible ID string             |
 161 * |  18 | Reserved              | U8[6]| 0                                   |
 162 *
 163 * ExtProp[] is an array of valid Extended Properties descriptors
 164 * which have the following format:
 165 *
 166 * | off | name                  | type | description                         |
 167 * |-----+-----------------------+------+-------------------------------------|
 168 * |   0 | dwSize                | U32  | length of the descriptor            |
 169 * |   4 | dwPropertyDataType    | U32  | 1..7                                |
 170 * |   8 | wPropertyNameLength   | U16  | bPropertyName length (NL)           |
 171 * |  10 | bPropertyName         |U8[NL]| name of this property               |
 172 * |10+NL| dwPropertyDataLength  | U32  | bPropertyData length (DL)           |
 173 * |14+NL| bProperty             |U8[DL]| payload of this property            |
 174 */
 175
 176struct usb_functionfs_strings_head {
 177        __le32 magic;
 178        __le32 length;
 179        __le32 str_count;
 180        __le32 lang_count;
 181} __attribute__((packed));
 182
 183/*
 184 * Strings format:
 185 *
 186 * | off | name       | type                  | description                |
 187 * |-----+------------+-----------------------+----------------------------|
 188 * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
 189 * |   4 | length     | LE32                  | length of the data chunk   |
 190 * |   8 | str_count  | LE32                  | number of strings          |
 191 * |  12 | lang_count | LE32                  | number of languages        |
 192 * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
 193 *
 194 * For each language there is one stringtab entry (ie. there are lang_count
 195 * stringtab entires).  Each StringTab has following format:
 196 *
 197 * | off | name    | type              | description                        |
 198 * |-----+---------+-------------------+------------------------------------|
 199 * |   0 | lang    | LE16              | language code                      |
 200 * |   2 | strings | String[str_count] | array of strings in given language |
 201 *
 202 * For each string there is one strings entry (ie. there are str_count
 203 * string entries).  Each String is a NUL terminated string encoded in
 204 * UTF-8.
 205 */
 206
 207#endif
 208
 209
 210/*
 211 * Events are delivered on the ep0 file descriptor, when the user mode driver
 212 * reads from this file descriptor after writing the descriptors.  Don't
 213 * stop polling this descriptor.
 214 */
 215
 216enum usb_functionfs_event_type {
 217        FUNCTIONFS_BIND,
 218        FUNCTIONFS_UNBIND,
 219
 220        FUNCTIONFS_ENABLE,
 221        FUNCTIONFS_DISABLE,
 222
 223        FUNCTIONFS_SETUP,
 224
 225        FUNCTIONFS_SUSPEND,
 226        FUNCTIONFS_RESUME
 227};
 228
 229/* NOTE:  this structure must stay the same size and layout on
 230 * both 32-bit and 64-bit kernels.
 231 */
 232struct usb_functionfs_event {
 233        union {
 234                /* SETUP: packet; DATA phase i/o precedes next event
 235                 *(setup.bmRequestType & USB_DIR_IN) flags direction */
 236                struct usb_ctrlrequest  setup;
 237        } __attribute__((packed)) u;
 238
 239        /* enum usb_functionfs_event_type */
 240        __u8                            type;
 241        __u8                            _pad[3];
 242} __attribute__((packed));
 243
 244
 245/* Endpoint ioctls */
 246/* The same as in gadgetfs */
 247
 248/* IN transfers may be reported to the gadget driver as complete
 249 *      when the fifo is loaded, before the host reads the data;
 250 * OUT transfers may be reported to the host's "client" driver as
 251 *      complete when they're sitting in the FIFO unread.
 252 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
 253 * (needed for precise fault handling, when the hardware allows it)
 254 */
 255#define FUNCTIONFS_FIFO_STATUS  _IO('g', 1)
 256
 257/* discards any unclaimed data in the fifo. */
 258#define FUNCTIONFS_FIFO_FLUSH   _IO('g', 2)
 259
 260/* resets endpoint halt+toggle; used to implement set_interface.
 261 * some hardware (like pxa2xx) can't support this.
 262 */
 263#define FUNCTIONFS_CLEAR_HALT   _IO('g', 3)
 264
 265/* Specific for functionfs */
 266
 267/*
 268 * Returns reverse mapping of an interface.  Called on EP0.  If there
 269 * is no such interface returns -EDOM.  If function is not active
 270 * returns -ENODEV.
 271 */
 272#define FUNCTIONFS_INTERFACE_REVMAP     _IO('g', 128)
 273
 274/*
 275 * Returns real bEndpointAddress of an endpoint.  If function is not
 276 * active returns -ENODEV.
 277 */
 278#define FUNCTIONFS_ENDPOINT_REVMAP      _IO('g', 129)
 279
 280/*
 281 * Returns endpoint descriptor. If function is not active returns -ENODEV.
 282 */
 283#define FUNCTIONFS_ENDPOINT_DESC        _IOR('g', 130, \
 284                                             struct usb_endpoint_descriptor)
 285
 286
 287
 288#endif /* _UAPI__LINUX_FUNCTIONFS_H__ */
 289