libusbg-0.1.0
Data Structures | Defines | Enumerations | Functions | Variables
Libusbg

Data Structures

struct  state
 State of the gadget devices in the system. More...
struct  gadget
 USB gadget device attributes. More...
struct  config
 USB gadget configuration attributes. More...
struct  serial_attrs
 Attributes for Serial, ACM, and OBEX USB functions. More...
struct  net_attrs
 Attributes for ECM, ECM subset, NCM, EEM, and RNDIS USB functions. More...
struct  phonet_attrs
 Attributes for the phonet USB function. More...
union  attrs
 Attributes for a given function type. More...
struct  function
 USB gadget function attributes. More...
struct  binding
 Describes a binding between a USB gadget configuration and a USB gadget function. More...

Defines

#define DEFAULT_UDC   NULL
#define LANG_US_ENG   0x0409
#define usbg_for_each_gadget(g, s)   TAILQ_FOREACH(g, &s->gadgets, gnode)
#define usbg_for_each_function(f, g)   TAILQ_FOREACH(f, &g->functions, fnode)
#define usbg_for_each_config(c, g)   TAILQ_FOREACH(c, &g->configs, cnode)
#define usbg_for_each_binding(b, c)   TAILQ_FOREACH(b, &c->bindings, bnode)

Enumerations

enum  function_type {
  F_SERIAL, F_ACM, F_OBEX, F_ECM,
  F_SUBSET, F_NCM, F_EEM, F_RNDIS,
  F_PHONET
}
 Supported USB function types.

Functions

struct stateusbg_init (char *configfs_path)
 Initialize the libusbg library state.
void usbg_cleanup (struct state *s)
 Clean up the libusbg library state.
struct gadgetusbg_get_gadget (struct state *s, const char *name)
 Get a gadget device by name.
struct functionusbg_get_function (struct gadget *g, const char *name)
 Get a function by name.
struct configusbg_get_config (struct gadget *g, const char *name)
 Get a configuration by name.
struct gadgetusbg_create_gadget (struct state *s, char *name, int vendor, int product)
 Create a new USB gadget device.
void usbg_set_gadget_device_class (struct gadget *g, int dclass)
 Set the USB gadget device class code.
void usbg_set_gadget_device_protocol (struct gadget *g, int dproto)
 Set the USB gadget protocol code.
void usbg_set_gadget_device_subclass (struct gadget *g, int dsubclass)
 Set the USB gadget device subclass code.
void usbg_set_gadget_device_max_packet (struct gadget *g, int maxpacket)
 Set the maximum packet size for a gadget.
void usbg_set_gadget_device_bcd_device (struct gadget *g, int bcddevice)
 Set the gadget device BCD release number.
void usbg_set_gadget_device_bcd_usb (struct gadget *g, int bcdusb)
 Set the gadget device BCD USB version.
void usbg_set_gadget_serial_number (struct gadget *g, int lang, char *ser)
 Set the serial number for a gadget.
void usbg_set_gadget_manufacturer (struct gadget *g, int lang, char *mnf)
 Set the manufacturer name for a gadget.
void usbg_set_gadget_product (struct gadget *g, int lang, char *prd)
 Set the product name for a gadget.
struct functionusbg_create_function (struct gadget *g, enum function_type type, char *instance)
 Create a new USB gadget function.
struct configusbg_create_config (struct gadget *g, char *name)
 Create a new USB gadget configuration.
void usbg_set_config_max_power (struct config *c, int maxpower)
 Set the configuration maximum power.
void usbg_set_config_bm_attrs (struct config *c, int bmattrs)
 Set the configuration bitmap attributes.
void usbg_set_config_string (struct config *c, int lang, char *string)
 Set the configuration string.
int usbg_add_config_function (struct config *c, char *name, struct function *f)
 Add a function to a configuration.
int usbg_get_udcs (struct dirent ***udc_list)
 Get a list of UDC devices on the system.
void usbg_enable_gadget (struct gadget *g, char *udc)
 Enable a USB gadget device.
void usbg_disable_gadget (struct gadget *g)
 Disable a USB gadget device.
void usbg_set_net_dev_addr (struct function *f, struct ether_addr *addr)
 Set USB function network device address.
void usbg_set_net_host_addr (struct function *f, struct ether_addr *addr)
 Set USB function network host address.
void usbg_set_net_qmult (struct function *f, int qmult)
 Set USB function network qmult.

Variables

const char * function_names []
 Name strings for supported USB function types.

Detailed Description

Public API for USB gadget-configfs library


Data Structure Documentation

struct state

State of the gadget devices in the system.

Examples:
gadget-acm-ecm.c, and show-gadgets.c.

Public Member Functions

 TAILQ_HEAD (ghead, gadget) gadgets

Data Fields

char path [256]
struct gadget

USB gadget device attributes.

Examples:
gadget-acm-ecm.c, and show-gadgets.c.

Public Member Functions

 TAILQ_ENTRY (gadget) gnode
 TAILQ_HEAD (chead, config) configs
 TAILQ_HEAD (fhead, function) functions

Data Fields

char name [40]
char path [256]
char udc [256]
int dclass
int dsubclass
int dproto
int maxpacket
int bcddevice
int bcdusb
int product
int vendor
char str_ser [256]
char str_mnf [256]
char str_prd [256]
struct stateparent
struct config

USB gadget configuration attributes.

Examples:
gadget-acm-ecm.c, and show-gadgets.c.

Public Member Functions

 TAILQ_ENTRY (config) cnode
 TAILQ_HEAD (bhead, binding) bindings

Data Fields

struct gadgetparent
char name [40]
char path [256]
int maxpower
int bmattrs
char str_cfg [256]
struct serial_attrs

Attributes for Serial, ACM, and OBEX USB functions.

Data Fields
int port_num
struct net_attrs

Attributes for ECM, ECM subset, NCM, EEM, and RNDIS USB functions.

Data Fields
struct ether_addr dev_addr
struct ether_addr host_addr
char ifname
int qmult
struct phonet_attrs

Attributes for the phonet USB function.

Data Fields
char ifname
union attrs

Attributes for a given function type.

Data Fields
struct net_attrs net
struct phonet_attrs phonet
struct serial_attrs serial
struct function

USB gadget function attributes.

Examples:
gadget-acm-ecm.c, and show-gadgets.c.

Public Member Functions

 TAILQ_ENTRY (function) fnode

Data Fields

struct gadgetparent
char name [40]
char path [256]
enum function_type type
union attrs attr
struct binding

Describes a binding between a USB gadget configuration and a USB gadget function.

Examples:
show-gadgets.c.

Public Member Functions

 TAILQ_ENTRY (binding) bnode

Data Fields

struct configparent
struct functiontarget
char name [40]
char path [256]

Define Documentation

#define usbg_for_each_binding (   b,
 
)    TAILQ_FOREACH(b, &c->bindings, bnode)

Iterates over each binding

Examples:
show-gadgets.c.
#define usbg_for_each_config (   c,
 
)    TAILQ_FOREACH(c, &g->configs, cnode)

Iterates over each config

Examples:
show-gadgets.c.
#define usbg_for_each_function (   f,
 
)    TAILQ_FOREACH(f, &g->functions, fnode)

Iterates over each function

Examples:
show-gadgets.c.
#define usbg_for_each_gadget (   g,
 
)    TAILQ_FOREACH(g, &s->gadgets, gnode)

Iterates over each gadget

Examples:
show-gadgets.c.

Function Documentation

int usbg_add_config_function ( struct config c,
char *  name,
struct function f 
)

Add a function to a configuration.

Parameters:
cPointer to config
nameName of configuration function binding
fPointer to function
Returns:
0 on success, -1 on failure.
Examples:
gadget-acm-ecm.c.
void usbg_cleanup ( struct state s)

Clean up the libusbg library state.

Parameters:
sPointer to state
Examples:
gadget-acm-ecm.c, and show-gadgets.c.
struct config* usbg_create_config ( struct gadget g,
char *  name 
) [read]

Create a new USB gadget configuration.

Parameters:
gPointer to gadget
nameName of configuration
Returns:
Pointer to configuration or NULL if it cannot be created
Todo:
Check for legal configuration name
Examples:
gadget-acm-ecm.c.
struct function* usbg_create_function ( struct gadget g,
enum function_type  type,
char *  instance 
) [read]

Create a new USB gadget function.

Parameters:
gPointer to gadget
typeType of function
instanceFunction instance name
Returns:
Pointer to function or NULL if it cannot be created
Todo:
Check for legal function type
Examples:
gadget-acm-ecm.c.
struct gadget* usbg_create_gadget ( struct state s,
char *  name,
int  vendor,
int  product 
) [read]

Create a new USB gadget device.

Parameters:
sPointer to state
nameName of the gadget
vendorGadget vendor ID
productGadget product ID
Returns:
Pointer to gadget or NULL if the gadget cannot be created
Examples:
gadget-acm-ecm.c.
void usbg_disable_gadget ( struct gadget g)

Disable a USB gadget device.

Parameters:
gPointer to gadget
void usbg_enable_gadget ( struct gadget g,
char *  udc 
)

Enable a USB gadget device.

Parameters:
gPointer to gadget
udcName of UDC to enable gadget
Examples:
gadget-acm-ecm.c.
struct config* usbg_get_config ( struct gadget g,
const char *  name 
) [read]

Get a configuration by name.

Parameters:
gPointer to gadget
nameName of the configuration
Returns:
Pointer to config or NULL if a matching config isn't found
struct function* usbg_get_function ( struct gadget g,
const char *  name 
) [read]

Get a function by name.

Parameters:
gPointer to gadget
nameName of the function
Returns:
Pointer to function or NULL if a matching function isn't found
struct gadget* usbg_get_gadget ( struct state s,
const char *  name 
) [read]

Get a gadget device by name.

Parameters:
sPointer to state
nameName of the gadget device
Returns:
Pointer to gadget or NULL if a matching gadget isn't found
int usbg_get_udcs ( struct dirent ***  udc_list)

Get a list of UDC devices on the system.

Parameters:
udc_listPointer to pointer to dirent pointer
Returns:
Number of UDC devices on success, -1 on failure
struct state* usbg_init ( char *  configfs_path) [read]

Initialize the libusbg library state.

Parameters:
configfs_pathPath to the mounted configfs filesystem
Returns:
Pointer to a state structure
Examples:
gadget-acm-ecm.c, and show-gadgets.c.
void usbg_set_config_bm_attrs ( struct config c,
int  bmattrs 
)

Set the configuration bitmap attributes.

Parameters:
cPointer to config
bmattrsConfiguration characteristics
void usbg_set_config_max_power ( struct config c,
int  maxpower 
)

Set the configuration maximum power.

Parameters:
cPointer to config
maxpowerMaximum power (in 2 mA units)
void usbg_set_config_string ( struct config c,
int  lang,
char *  string 
)

Set the configuration string.

Parameters:
cPointer to config
langUSB language ID
stringConfiguration description
Examples:
gadget-acm-ecm.c.
void usbg_set_gadget_device_bcd_device ( struct gadget g,
int  bcddevice 
)

Set the gadget device BCD release number.

Parameters:
gPointer to gadget
bcddeviceBCD release number
void usbg_set_gadget_device_bcd_usb ( struct gadget g,
int  bcdusb 
)

Set the gadget device BCD USB version.

Parameters:
gPointer to gadget
bcdusbBCD USB version
void usbg_set_gadget_device_class ( struct gadget g,
int  dclass 
)

Set the USB gadget device class code.

Parameters:
gPointer to gadget
dclassUSB device class code
void usbg_set_gadget_device_max_packet ( struct gadget g,
int  maxpacket 
)

Set the maximum packet size for a gadget.

Parameters:
gPointer to gadget
maxpacketMaximum packet size
void usbg_set_gadget_device_protocol ( struct gadget g,
int  dproto 
)

Set the USB gadget protocol code.

Parameters:
gPointer to gadget
dprotocolUSB protocol code
void usbg_set_gadget_device_subclass ( struct gadget g,
int  dsubclass 
)

Set the USB gadget device subclass code.

Parameters:
gPointer to gadget
dsubclassUSB device subclass code
void usbg_set_gadget_manufacturer ( struct gadget g,
int  lang,
char *  mnf 
)

Set the manufacturer name for a gadget.

Parameters:
gPointer to gadget
langUSB language ID
mnfManufacturer
Examples:
gadget-acm-ecm.c.
void usbg_set_gadget_product ( struct gadget g,
int  lang,
char *  prd 
)

Set the product name for a gadget.

Parameters:
gPointer to gadget
langUSB language ID
prdProduct
Examples:
gadget-acm-ecm.c.
void usbg_set_gadget_serial_number ( struct gadget g,
int  lang,
char *  ser 
)

Set the serial number for a gadget.

Parameters:
gPointer to gadget
langUSB language ID
serSerial number
Examples:
gadget-acm-ecm.c.
void usbg_set_net_dev_addr ( struct function f,
struct ether_addr *  addr 
)

Set USB function network device address.

Parameters:
fPointer to function
addrPointer to Ethernet address
void usbg_set_net_host_addr ( struct function f,
struct ether_addr *  addr 
)

Set USB function network host address.

Parameters:
fPointer to function
addrPointer to Ethernet address
void usbg_set_net_qmult ( struct function f,
int  qmult 
)

Set USB function network qmult.

Parameters:
fPointer to function
qmultQueue length multiplier

Variable Documentation

Initial value:
{
        "gser",
        "acm",
        "obex",
        "ecm",
        "geth",
        "ncm",
        "eem",
        "rndis",
        "phonet",
}

Name strings for supported USB function types.

 All Data Structures Files Functions Variables Enumerations Defines