1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>struct usb_function</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="USB Gadget API for Linux"><link rel="up" href="composite.html" title="Composite Device Framework"><link rel="prev" href="API-struct-usb-os-desc-table.html" title="struct usb_os_desc_table"><link rel="next" href="API-struct-usb-configuration.html" title="struct usb_configuration"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">struct usb_function</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-struct-usb-os-desc-table.html">Prev</a> </td><th width="60%" align="center">Composite Device Framework</th><td width="20%" align="right"> <a accesskey="n" href="API-struct-usb-configuration.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-struct-usb-function"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>struct usb_function — 2 describes one function of a configuration 3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="programlisting"> 4struct usb_function { 5 const char * name; 6 struct usb_gadget_strings ** strings; 7 struct usb_descriptor_header ** fs_descriptors; 8 struct usb_descriptor_header ** hs_descriptors; 9 struct usb_descriptor_header ** ss_descriptors; 10 struct usb_configuration * config; 11 struct usb_os_desc_table * os_desc_table; 12 unsigned os_desc_n; 13 int (* bind) (struct usb_configuration *,struct usb_function *); 14 void (* unbind) (struct usb_configuration *,struct usb_function *); 15 void (* free_func) (struct usb_function *f); 16 struct module * mod; 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 bool (* req_match) (struct usb_function *,const struct usb_ctrlrequest *); 22 void (* suspend) (struct usb_function *); 23 void (* resume) (struct usb_function *); 24 int (* get_status) (struct usb_function *); 25 int (* func_suspend) (struct usb_function *,u8 suspend_opt); 26}; </pre></div><div class="refsect1"><a name="idp1124312948"></a><h2>Members</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term">name</span></dt><dd><p> 27 For diagnostics, identifies the function. 28 </p></dd><dt><span class="term">strings</span></dt><dd><p> 29 tables of strings, keyed by identifiers assigned during <code class="function">bind</code> 30 and by language IDs provided in control requests 31 </p></dd><dt><span class="term">fs_descriptors</span></dt><dd><p> 32 Table of full (or low) speed descriptors, using interface and 33 string identifiers assigned during @<code class="function">bind</code>. If this pointer is null, 34 the function will not be available at full speed (or at low speed). 35 </p></dd><dt><span class="term">hs_descriptors</span></dt><dd><p> 36 Table of high speed descriptors, using interface and 37 string identifiers assigned during @<code class="function">bind</code>. If this pointer is null, 38 the function will not be available at high speed. 39 </p></dd><dt><span class="term">ss_descriptors</span></dt><dd><p> 40 Table of super speed descriptors, using interface and 41 string identifiers assigned during @<code class="function">bind</code>. If this 42 pointer is null after initiation, the function will not 43 be available at super speed. 44 </p></dd><dt><span class="term">config</span></dt><dd><p> 45 assigned when @<code class="function">usb_add_function</code> is called; this is the 46 configuration with which this function is associated. 47 </p></dd><dt><span class="term">os_desc_table</span></dt><dd><p> 48 Table of (interface id, os descriptors) pairs. The function 49 can expose more than one interface. If an interface is a member of 50 an IAD, only the first interface of IAD has its entry in the table. 51 </p></dd><dt><span class="term">os_desc_n</span></dt><dd><p> 52 Number of entries in os_desc_table 53 </p></dd><dt><span class="term">bind</span></dt><dd><p> 54 Before the gadget can register, all of its functions <code class="function">bind</code> to the 55 available resources including string and interface identifiers used 56 in interface or class descriptors; endpoints; I/O buffers; and so on. 57 </p></dd><dt><span class="term">unbind</span></dt><dd><p> 58 Reverses <em class="parameter"><code>bind</code></em>; called as a side effect of unregistering the 59 driver which added this function. 60 </p></dd><dt><span class="term">free_func</span></dt><dd><p> 61 free the struct usb_function. 62 </p></dd><dt><span class="term">mod</span></dt><dd><p> 63 (internal) points to the module that created this structure. 64 </p></dd><dt><span class="term">set_alt</span></dt><dd><p> 65 (REQUIRED) Reconfigures altsettings; function drivers may 66 initialize usb_ep.driver data at this time (when it is used). 67 Note that setting an interface to its current altsetting resets 68 interface state, and that all interfaces have a disabled state. 69 </p></dd><dt><span class="term">get_alt</span></dt><dd><p> 70 Returns the active altsetting. If this is not provided, 71 then only altsetting zero is supported. 72 </p></dd><dt><span class="term">disable</span></dt><dd><p> 73 (REQUIRED) Indicates the function should be disabled. Reasons 74 include host resetting or reconfiguring the gadget, and disconnection. 75 </p></dd><dt><span class="term">setup</span></dt><dd><p> 76 Used for interface-specific control requests. 77 </p></dd><dt><span class="term">req_match</span></dt><dd><p> 78 Tests if a given class request can be handled by this function. 79 </p></dd><dt><span class="term">suspend</span></dt><dd><p> 80 Notifies functions when the host stops sending USB traffic. 81 </p></dd><dt><span class="term">resume</span></dt><dd><p> 82 Notifies functions when the host restarts USB traffic. 83 </p></dd><dt><span class="term">get_status</span></dt><dd><p> 84 Returns function status as a reply to 85 <code class="function">GetStatus</code> request when the recipient is Interface. 86 </p></dd><dt><span class="term">func_suspend</span></dt><dd><p> 87 callback to be called when 88 SetFeature(FUNCTION_SUSPEND) is reseived 89 </p></dd></dl></div></div><div class="refsect1"><a name="idp1124332164"></a><h2>Description</h2><p> 90 A single USB function uses one or more interfaces, and should in most 91 cases support operation at both full and high speeds. Each function is 92 associated by @<code class="function">usb_add_function</code> with a one configuration; that function 93 causes @<code class="function">bind</code> to be called so resources can be allocated as part of 94 setting up a gadget driver. Those resources include endpoints, which 95 should be allocated using @<code class="function">usb_ep_autoconfig</code>. 96 </p><p> 97 98 To support dual speed operation, a function driver provides descriptors 99 for both high and full speed operation. Except in rare cases that don't 100 involve bulk endpoints, each speed needs different endpoint descriptors. 101 </p><p> 102 103 Function drivers choose their own strategies for managing instance data. 104 The simplest strategy just declares it "static', which means the function 105 can only be activated once. If the function needs to be exposed in more 106 than one configuration at a given speed, it needs to support multiple 107 usb_function structures (one for each configuration). 108 </p><p> 109 110 A more complex strategy might encapsulate a <em class="parameter"><code>usb_function</code></em> structure inside 111 a driver-specific instance structure to allows multiple activations. An 112 example of multiple activations might be a CDC ACM function that supports 113 two or more distinct instances within the same configuration, providing 114 several independent logical data links to a USB host. 115</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-struct-usb-os-desc-table.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="composite.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-struct-usb-configuration.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">struct usb_os_desc_table</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">struct usb_configuration</span></td></tr></table></div></body></html> 116