Dr Andrew Scott G7VAV

My photo
 
June 2025
Mo Tu We Th Fr Sa Su
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6


functionfs.h
001: #ifndef __LINUX_FUNCTIONFS_H__
002: #define __LINUX_FUNCTIONFS_H__ 1
003: 
004: 
005: #include <linux/types.h>
006: #include <linux/ioctl.h>
007: 
008: #include <linux/usb/ch9.h>
009: 
010: 
011: enum {
012:         FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
013:         FUNCTIONFS_STRINGS_MAGIC     = 2
014: };
015: 
016: 
017: 
018: /* Descriptor of an non-audio endpoint */
019: struct usb_endpoint_descriptor_no_audio {
020:         __u8  bLength;
021:         __u8  bDescriptorType;
022: 
023:         __u8  bEndpointAddress;
024:         __u8  bmAttributes;
025:         __le16 wMaxPacketSize;
026:         __u8  bInterval;
027: } __attribute__((packed));
028: 
029: 
030: /*
031:  * All numbers must be in little endian order.
032:  */
033: 
034: struct usb_functionfs_descs_head {
035:         __le32 magic;
036:         __le32 length;
037:         __le32 fs_count;
038:         __le32 hs_count;
039: } __attribute__((packed));
040: 
041: /*
042:  * Descriptors format:
043:  *
044:  * | off | name      | type         | description                          |
045:  * |-----+-----------+--------------+--------------------------------------|
046:  * |   0 | magic     | LE32         | FUNCTIONFS_{FS,HS}_DESCRIPTORS_MAGIC |
047:  * |   4 | length    | LE32         | length of the whole data chunk       |
048:  * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
049:  * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
050:  * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
051:  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
052:  *
053:  * descs are just valid USB descriptors and have the following format:
054:  *
055:  * | off | name            | type | description              |
056:  * |-----+-----------------+------+--------------------------|
057:  * |   0 | bLength         | U8   | length of the descriptor |
058:  * |   1 | bDescriptorType | U8   | descriptor type          |
059:  * |   2 | payload         |      | descriptor's payload     |
060:  */
061: 
062: struct usb_functionfs_strings_head {
063:         __le32 magic;
064:         __le32 length;
065:         __le32 str_count;
066:         __le32 lang_count;
067: } __attribute__((packed));
068: 
069: /*
070:  * Strings format:
071:  *
072:  * | off | name       | type                  | description                |
073:  * |-----+------------+-----------------------+----------------------------|
074:  * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
075:  * |   4 | length     | LE32                  | length of the data chunk   |
076:  * |   8 | str_count  | LE32                  | number of strings          |
077:  * |  12 | lang_count | LE32                  | number of languages        |
078:  * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
079:  *
080:  * For each language there is one stringtab entry (ie. there are lang_count
081:  * stringtab entires).  Each StringTab has following format:
082:  *
083:  * | off | name    | type              | description                        |
084:  * |-----+---------+-------------------+------------------------------------|
085:  * |   0 | lang    | LE16              | language code                      |
086:  * |   2 | strings | String[str_count] | array of strings in given language |
087:  *
088:  * For each string there is one strings entry (ie. there are str_count
089:  * string entries).  Each String is a NUL terminated string encoded in
090:  * UTF-8.
091:  */
092: 
093: 
094: 
095: /*
096:  * Events are delivered on the ep0 file descriptor, when the user mode driver
097:  * reads from this file descriptor after writing the descriptors.  Don't
098:  * stop polling this descriptor.
099:  */
100: 
101: enum usb_functionfs_event_type {
102:         FUNCTIONFS_BIND,
103:         FUNCTIONFS_UNBIND,
104: 
105:         FUNCTIONFS_ENABLE,
106:         FUNCTIONFS_DISABLE,
107: 
108:         FUNCTIONFS_SETUP,
109: 
110:         FUNCTIONFS_SUSPEND,
111:         FUNCTIONFS_RESUME
112: };
113: 
114: /* NOTE:  this structure must stay the same size and layout on
115:  * both 32-bit and 64-bit kernels.
116:  */
117: struct usb_functionfs_event {
118:         union {
119:                 /* SETUP: packet; DATA phase i/o precedes next event
120:                  *(setup.bmRequestType & USB_DIR_IN) flags direction */
121:                 struct usb_ctrlrequest  setup;
122:         } __attribute__((packed)) u;
123: 
124:         /* enum usb_functionfs_event_type */
125:         __u8                            type;
126:         __u8                            _pad[3];
127: } __attribute__((packed));
128: 
129: 
130: /* Endpoint ioctls */
131: /* The same as in gadgetfs */
132: 
133: /* IN transfers may be reported to the gadget driver as complete
134:  *      when the fifo is loaded, before the host reads the data;
135:  * OUT transfers may be reported to the host's "client" driver as
136:  *      complete when they're sitting in the FIFO unread.
137:  * THIS returns how many bytes are "unclaimed" in the endpoint fifo
138:  * (needed for precise fault handling, when the hardware allows it)
139:  */
140: #define FUNCTIONFS_FIFO_STATUS  _IO('g', 1)
141: 
142: /* discards any unclaimed data in the fifo. */
143: #define FUNCTIONFS_FIFO_FLUSH   _IO('g', 2)
144: 
145: /* resets endpoint halt+toggle; used to implement set_interface.
146:  * some hardware (like pxa2xx) can't support this.
147:  */
148: #define FUNCTIONFS_CLEAR_HALT   _IO('g', 3)
149: 
150: /* Specific for functionfs */
151: 
152: /*
153:  * Returns reverse mapping of an interface.  Called on EP0.  If there
154:  * is no such interface returns -EDOM.  If function is not active
155:  * returns -ENODEV.
156:  */
157: #define FUNCTIONFS_INTERFACE_REVMAP     _IO('g', 128)
158: 
159: /*
160:  * Returns real bEndpointAddress of an endpoint.  If function is not
161:  * active returns -ENODEV.
162:  */
163: #define FUNCTIONFS_ENDPOINT_REVMAP      _IO('g', 129)
164: 
165: 
166: 
167: #endif
168: 


for client (none)
© Andrew Scott 2006 - 2025,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/