1STRUCT USB_FUNCTION(9) Kernel Mode Gadget API STRUCT USB_FUNCTION(9)
2
3
4
6 struct_usb_function - describes one function of a configuration
7
9 struct usb_function {
10 const char * name;
11 struct usb_gadget_strings ** strings;
12 struct usb_descriptor_header ** descriptors;
13 struct usb_descriptor_header ** hs_descriptors;
14 struct usb_configuration * config;
15 int (* bind) (struct usb_configuration *,struct usb_function *);
16 void (* unbind) (struct usb_configuration *,struct usb_function *);
17 int (* set_alt) (struct usb_function *,unsigned interface, unsigned alt);
18 int (* get_alt) (struct usb_function *,unsigned interface);
19 void (* disable) (struct usb_function *);
20 int (* setup) (struct usb_function *,const struct usb_ctrlrequest *);
21 void (* suspend) (struct usb_function *);
22 void (* resume) (struct usb_function *);
23 };
24
26 name
27 For diagnostics, identifies the function.
28
29 strings
30 tables of strings, keyed by identifiers assigned during bind and by
31 language IDs provided in control requests
32
33 descriptors
34 Table of full (or low) speed descriptors, using interface and
35 string identifiers assigned during bind(). If this pointer is null,
36 the function will not be available at full speed (or at low speed).
37
38 hs_descriptors
39 Table of high speed descriptors, using interface and string
40 identifiers assigned during bind(). If this pointer is null, the
41 function will not be available at high speed.
42
43 config
44 assigned when usb_add_function() is called; this is the
45 configuration with which this function is associated.
46
47 bind
48 Before the gadget can register, all of its functions bind to the
49 available resources including string and interface identifiers used
50 in interface or class descriptors; endpoints; I/O buffers; and so
51 on.
52
53 unbind
54 Reverses bind; called as a side effect of unregistering the driver
55 which added this function.
56
57 set_alt
58 (REQUIRED) Reconfigures altsettings; function drivers may
59 initialize usb_ep.driver data at this time (when it is used). Note
60 that setting an interface to its current altsetting resets
61 interface state, and that all interfaces have a disabled state.
62
63 get_alt
64 Returns the active altsetting. If this is not provided, then only
65 altsetting zero is supported.
66
67 disable
68 (REQUIRED) Indicates the function should be disabled. Reasons
69 include host resetting or reconfiguring the gadget, and
70 disconnection.
71
72 setup
73 Used for interface-specific control requests.
74
75 suspend
76 Notifies functions when the host stops sending USB traffic.
77
78 resume
79 Notifies functions when the host restarts USB traffic.
80
82 A single USB function uses one or more interfaces, and should in most
83 cases support operation at both full and high speeds. Each function is
84 associated by usb_add_function() with a one configuration; that
85 function causes bind() to be called so resources can be allocated as
86 part of setting up a gadget driver. Those resources include endpoints,
87 which should be allocated using usb_ep_autoconfig().
88
89 To support dual speed operation, a function driver provides descriptors
90 for both high and full speed operation. Except in rare cases that don't
91 involve bulk endpoints, each speed needs different endpoint
92 descriptors.
93
94 Function drivers choose their own strategies for managing instance
95 data. The simplest strategy just declares it "static', which means the
96 function can only be activated once. If the function needs to be
97 exposed in more than one configuration at a given speed, it needs to
98 support multiple usb_function structures (one for each configuration).
99
100 A more complex strategy might encapsulate a usb_function structure
101 inside a driver-specific instance structure to allows multiple
102 activations. An example of multiple activations might be a CDC ACM
103 function that supports two or more distinct instances within the same
104 configuration, providing several independent logical data links to a
105 USB host.
106
108 David Brownell <dbrownell@users.sourceforge.net>
109 Author.
110
112Kernel Hackers Manual 2.6. November 2011 STRUCT USB_FUNCTION(9)