libusbgx-0.2.0
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
Libusbgx

Data Structures

struct  usbg_gadget_attrs
 USB gadget device attributes. More...
 
struct  usbg_gadget_strs
 USB gadget device strings. More...
 
struct  usbg_gadget_os_descs
 USB gadget Microsoft OS Descriptors. More...
 
struct  usbg_config_attrs
 USB configuration attributes. More...
 
struct  usbg_config_strs
 USB configuration strings. More...
 
struct  usbg_function_os_desc
 USB OS Descriptor function attributes. More...
 

Macros

#define DEFAULT_UDC   NULL
 
#define LANG_US_ENG   0x0409
 
#define DEFAULT_CONFIG_LABEL   "config"
 
#define USBG_MAX_STR_LENGTH   256
 
#define USBG_MAX_NAME_LENGTH   40
 
#define USBG_MAX_DEV_LENGTH   (USBG_MAX_NAME_LENGTH - 4)
 
#define USBG_TO_UNION(UNAME, FIELD, WHAT)    ((union UNAME){ .FIELD = WHAT, })
 
#define USBG_RM_RECURSE   1
 Additional option for usbg_rm_* functions.
 
#define usbg_for_each_gadget(g, s)
 
#define usbg_for_each_function(f, g)
 
#define usbg_for_each_config(c, g)
 
#define usbg_for_each_binding(b, c)
 
#define usbg_for_each_udc(u, s)
 

Typedefs

typedef struct usbg_state usbg_state
 State of the gadget devices in the system.
 
typedef struct usbg_gadget usbg_gadget
 USB gadget device.
 
typedef struct usbg_config usbg_config
 USB configuration.
 
typedef struct usbg_function usbg_function
 USB function.
 
typedef struct usbg_binding usbg_binding
 USB function to config binding.
 
typedef struct usbg_udc usbg_udc
 USB device controller.
 

Enumerations

enum  usbg_gadget_attr {
  USBG_GADGET_ATTR_MIN = 0 , USBG_BCD_USB = USBG_GADGET_ATTR_MIN , USBG_B_DEVICE_CLASS , USBG_B_DEVICE_SUB_CLASS ,
  USBG_B_DEVICE_PROTOCOL , USBG_B_MAX_PACKET_SIZE_0 , USBG_ID_VENDOR , USBG_ID_PRODUCT ,
  USBG_BCD_DEVICE , USBG_GADGET_ATTR_MAX
}
 Gadget attributes which can be set using usbg_set_gadget_attr() function.
 
enum  usbg_gadget_str {
  USBG_GADGET_STR_MIN = 0 , USBG_STR_MANUFACTURER = USBG_GADGET_STR_MIN , USBG_STR_PRODUCT , USBG_STR_SERIAL_NUMBER ,
  USBG_GADGET_STR_MAX
}
 
enum  usbg_gadget_os_desc_strs {
  USBG_GADGET_OS_DESC_MIN = 0 , OS_DESC_USE = USBG_GADGET_OS_DESC_MIN , OS_DESC_B_VENDOR_CODE , OS_DESC_QW_SIGN ,
  USBG_GADGET_OS_DESC_MAX
}
 Microsoft OS Descriptors strings.
 
enum  usbg_function_type {
  USBG_FUNCTION_TYPE_MIN = 0 , USBG_F_SERIAL = USBG_FUNCTION_TYPE_MIN , USBG_F_ACM , USBG_F_OBEX ,
  USBG_F_ECM , USBG_F_SUBSET , USBG_F_NCM , USBG_F_EEM ,
  USBG_F_RNDIS , USBG_F_PHONET , USBG_F_FFS , USBG_F_MASS_STORAGE ,
  USBG_F_MIDI , USBG_F_LOOPBACK , USBG_F_HID , USBG_F_UAC2 ,
  USBG_FUNCTION_TYPE_MAX
}
 Supported USB function types.
 
enum  usbg_error {
  USBG_SUCCESS = 0 , USBG_ERROR_NO_MEM = -1 , USBG_ERROR_NO_ACCESS = -2 , USBG_ERROR_INVALID_PARAM = -3 ,
  USBG_ERROR_NOT_FOUND = -4 , USBG_ERROR_IO = -5 , USBG_ERROR_EXIST = -6 , USBG_ERROR_NO_DEV = -7 ,
  USBG_ERROR_BUSY = -8 , USBG_ERROR_NOT_SUPPORTED = -9 , USBG_ERROR_PATH_TOO_LONG = -10 , USBG_ERROR_INVALID_FORMAT = -11 ,
  USBG_ERROR_MISSING_TAG = -12 , USBG_ERROR_INVALID_TYPE = -13 , USBG_ERROR_INVALID_VALUE = -14 , USBG_ERROR_NOT_EMPTY = -15 ,
  USBG_ERROR_OTHER_ERROR = -99
}
 Errors which could be returned by library functions.
 

Functions

const char * usbg_error_name (usbg_error e)
 Get the error name as a constant string.
 
const char * usbg_strerror (usbg_error e)
 Get the short description of error.
 
int usbg_init (const char *configfs_path, usbg_state **state)
 Initialize the libusbgx library state.
 
void usbg_cleanup (usbg_state *s)
 Clean up the libusbgx library state.
 
const char * usbg_get_configfs_path (usbg_state *s)
 Get ConfigFS path.
 
int usbg_get_configfs_path_s (usbg_state *s, char *buf, int len)
 Get ConfigFS path into user buffer.
 
usbg_gadgetusbg_get_gadget (usbg_state *s, const char *name)
 Get a gadget device by name.
 
usbg_functionusbg_get_function (usbg_gadget *g, usbg_function_type type, const char *instance)
 Get a function by name.
 
usbg_configusbg_get_config (usbg_gadget *g, int id, const char *label)
 Get a configuration by name.
 
usbg_udcusbg_get_udc (usbg_state *s, const char *name)
 Get a udc by name.
 
int usbg_rm_binding (usbg_binding *b)
 Remove binding between configuration and function.
 
int usbg_rm_config (usbg_config *c, int opts)
 Remove configuration.
 
int usbg_rm_function (usbg_function *f, int opts)
 Remove existing USB function.
 
int usbg_rm_gadget (usbg_gadget *g, int opts)
 Remove existing USB gadget.
 
int usbg_rm_config_strs (usbg_config *c, int lang)
 Remove configuration strings for given language.
 
int usbg_rm_gadget_strs (usbg_gadget *g, int lang)
 Remove gadget strings for given language.
 
int usbg_create_gadget_vid_pid (usbg_state *s, const char *name, uint16_t idVendor, uint16_t idProduct, usbg_gadget **g)
 Create a new USB gadget device.
 
int usbg_create_gadget (usbg_state *s, const char *name, const struct usbg_gadget_attrs *g_attrs, const struct usbg_gadget_strs *g_strs, usbg_gadget **g)
 Create a new USB gadget device and set given attributes and strings.
 
const char * usbg_get_gadget_attr_str (usbg_gadget_attr attr)
 Get string representing selected gadget attribute.
 
int usbg_lookup_gadget_attr (const char *name)
 Lookup attr code based on its name.
 
int usbg_lookup_gadget_str (const char *name)
 Lookup str code based on its name.
 
const char * usbg_get_gadget_str_name (usbg_gadget_str str)
 Get name of selected gadget string.
 
const char * usbg_get_gadget_os_desc_name (usbg_gadget_os_desc_strs str)
 Get name of selected OS Descriptor string.
 
int usbg_set_gadget_attr (usbg_gadget *g, usbg_gadget_attr attr, int val)
 Set selected attribute to value.
 
int usbg_get_gadget_attr (usbg_gadget *g, usbg_gadget_attr attr)
 Get value of selected attribute.
 
int usbg_set_gadget_attrs (usbg_gadget *g, const struct usbg_gadget_attrs *g_attrs)
 Set the USB gadget attributes.
 
int usbg_get_gadget_attrs (usbg_gadget *g, struct usbg_gadget_attrs *g_attrs)
 Get the USB gadget strings.
 
const char * usbg_get_gadget_name (usbg_gadget *g)
 Get gadget name.
 
int usbg_get_gadget_name_s (usbg_gadget *g, char *buf, int len)
 Get gadget name into user buffer.
 
int usbg_set_gadget_vendor_id (usbg_gadget *g, uint16_t idVendor)
 Set the USB gadget vendor id.
 
int usbg_set_gadget_product_id (usbg_gadget *g, uint16_t idProduct)
 Set the USB gadget product id.
 
int usbg_set_gadget_device_class (usbg_gadget *g, uint8_t bDeviceClass)
 Set the USB gadget device class code.
 
int usbg_set_gadget_device_protocol (usbg_gadget *g, uint8_t bDeviceProtocol)
 Set the USB gadget protocol code.
 
int usbg_set_gadget_device_subclass (usbg_gadget *g, uint8_t bDeviceSubClass)
 Set the USB gadget device subclass code.
 
int usbg_set_gadget_device_max_packet (usbg_gadget *g, uint8_t bMaxPacketSize0)
 Set the maximum packet size for a gadget.
 
int usbg_set_gadget_device_bcd_device (usbg_gadget *g, uint16_t bcdDevice)
 Set the gadget device BCD release number.
 
int usbg_set_gadget_device_bcd_usb (usbg_gadget *g, uint16_t bcdUSB)
 Set the gadget device BCD USB version.
 
int usbg_get_gadget_strs (usbg_gadget *g, int lang, struct usbg_gadget_strs *g_strs)
 Get the USB gadget strings.
 
int usbg_get_gadget_strs_langs (usbg_gadget *g, int **langs)
 Get the array of languages available in this gadget.
 
int usbg_set_gadget_str (usbg_gadget *g, usbg_gadget_str str, int lang, const char *val)
 Set selected string.
 
int usbg_set_gadget_strs (usbg_gadget *g, int lang, const struct usbg_gadget_strs *g_strs)
 Set the USB gadget strings.
 
int usbg_set_gadget_serial_number (usbg_gadget *g, int lang, const char *ser)
 Set the serial number for a gadget.
 
int usbg_set_gadget_manufacturer (usbg_gadget *g, int lang, const char *mnf)
 Set the manufacturer name for a gadget.
 
int usbg_set_gadget_product (usbg_gadget *g, int lang, const char *prd)
 Set the product name for a gadget.
 
int usbg_get_gadget_os_descs (usbg_gadget *g, struct usbg_gadget_os_descs *g_os_descs)
 Get the USB gadget OS Descriptor.
 
int usbg_set_gadget_os_descs (usbg_gadget *g, const struct usbg_gadget_os_descs *g_os_descs)
 Set the USB gadget OS Descriptor.
 
int usbg_create_function (usbg_gadget *g, usbg_function_type type, const char *instance, void *f_attrs, usbg_function **f)
 Create a new USB gadget function and set its attributes.
 
const char * usbg_get_function_instance (usbg_function *f)
 Get function instance name.
 
int usbg_get_function_instance_s (usbg_function *f, char *buf, int len)
 Get function instance name into user buffer.
 
const char * usbg_get_function_type_str (usbg_function_type type)
 Get function type as a string.
 
int usbg_lookup_function_type (const char *name)
 Lookup function type suitable for given name.
 
void usbg_cleanup_function_attrs (usbg_function *f, void *f_attrs)
 Cleanup content of function attributes.
 
usbg_function_type usbg_get_function_type (usbg_function *f)
 Get type of given function.
 
int usbg_get_function_attrs (usbg_function *f, void *f_attrs)
 Get attributes of given function.
 
int usbg_set_function_attrs (usbg_function *f, void *f_attrs)
 Set attributes of given function.
 
int usbg_get_interf_os_desc (usbg_function *f, const char *iname, struct usbg_function_os_desc *f_os_desc)
 Get OS Descriptor compatibility of given function.
 
int usbg_set_interf_os_desc (usbg_function *f, const char *iname, const struct usbg_function_os_desc *f_os_desc)
 Set OS Descriptor compatibility of given function.
 
int usbg_create_config (usbg_gadget *g, int id, const char *label, const struct usbg_config_attrs *c_attrs, const struct usbg_config_strs *c_strs, usbg_config **c)
 Create a new USB gadget configuration.
 
const char * usbg_get_config_label (usbg_config *c)
 Get config label.
 
int usbg_get_config_label_s (usbg_config *c, char *buf, int len)
 Get config label into user buffer.
 
int usbg_get_config_id (usbg_config *c)
 Get config id.
 
int usbg_set_config_attrs (usbg_config *c, const struct usbg_config_attrs *c_attrs)
 Set the USB configuration attributes.
 
int usbg_get_config_attrs (usbg_config *c, struct usbg_config_attrs *c_attrs)
 Get the USB configuration strings.
 
int usbg_set_config_max_power (usbg_config *c, int bMaxPower)
 Set the configuration maximum power.
 
int usbg_set_config_bm_attrs (usbg_config *c, int bmAttributes)
 Set the configuration bitmap attributes.
 
int usbg_get_config_strs (usbg_config *c, int lang, struct usbg_config_strs *c_strs)
 Get the USB configuration strings.
 
int usbg_get_config_strs_langs (usbg_config *c, int **langs)
 Get the array of languages available in this config.
 
int usbg_set_config_strs (usbg_config *c, int lang, const struct usbg_config_strs *c_strs)
 Set the USB configuration strings.
 
int usbg_set_config_string (usbg_config *c, int lang, const char *string)
 Set the configuration string.
 
int usbg_add_config_function (usbg_config *c, const char *name, usbg_function *f)
 Add a function to a configuration.
 
usbg_functionusbg_get_binding_target (usbg_binding *b)
 Get target function of given binding.
 
const char * usbg_get_binding_name (usbg_binding *b)
 Get binding name.
 
int usbg_get_binding_name_s (usbg_binding *b, char *buf, int len)
 Get binding name into user buffer.
 
usbg_configusbg_get_os_desc_binding (usbg_gadget *g)
 Get configuration selected for OS Descriptors.
 
int usbg_set_os_desc_config (usbg_gadget *g, usbg_config *c)
 Set configuration for OS Descriptors.
 
int usbg_enable_gadget (usbg_gadget *g, usbg_udc *udc)
 Enable a USB gadget device.
 
int usbg_disable_gadget (usbg_gadget *g)
 Disable a USB gadget device.
 
const char * usbg_get_udc_name (usbg_udc *u)
 Get name of udc.
 
int usbg_get_udc_name_s (usbg_udc *u, char *buf, int len)
 Get udc name into user buffer.
 
usbg_udcusbg_get_gadget_udc (usbg_gadget *g)
 Get udc to which gadget is bound.
 
usbg_gadgetusbg_get_udc_gadget (usbg_udc *u)
 Get gadget which is attached to this UDC.
 
usbg_gadgetusbg_get_first_gadget (usbg_state *s)
 Get first gadget in gadget list.
 
usbg_functionusbg_get_first_function (usbg_gadget *g)
 Get first function in function list.
 
usbg_configusbg_get_first_config (usbg_gadget *g)
 Get first config in config list.
 
usbg_bindingusbg_get_first_binding (usbg_config *c)
 Get first binding in binding list.
 
usbg_udcusbg_get_first_udc (usbg_state *s)
 Get first udc in udc list.
 
usbg_gadgetusbg_get_next_gadget (usbg_gadget *g)
 Get the next gadget on a list.
 
usbg_functionusbg_get_next_function (usbg_function *f)
 Get the next function on a list.
 
usbg_configusbg_get_next_config (usbg_config *c)
 Get the next config on a list.
 
usbg_bindingusbg_get_next_binding (usbg_binding *b)
 Get the next binding on a list.
 
usbg_udcusbg_get_next_udc (usbg_udc *u)
 Get the next udc on a list.
 
int usbg_export_function (usbg_function *f, FILE *stream)
 Exports usb function to file.
 
int usbg_export_config (usbg_config *c, FILE *stream)
 Exports configuration to file.
 
int usbg_export_gadget (usbg_gadget *g, FILE *stream)
 Exports whole gadget to file.
 
int usbg_import_function (usbg_gadget *g, FILE *stream, const char *instance, usbg_function **f)
 Imports usb function from file and adds it to given gadget.
 
int usbg_import_config (usbg_gadget *g, FILE *stream, int id, usbg_config **c)
 Imports usb configuration from file and adds it to given gadget.
 
int usbg_import_gadget (usbg_state *s, FILE *stream, const char *name, usbg_gadget **g)
 Imports usb gadget from file.
 
const char * usbg_get_func_import_error_text (usbg_gadget *g)
 Get text of error which occurred during last function import.
 
int usbg_get_func_import_error_line (usbg_gadget *g)
 Get line number where function import error occurred.
 
const char * usbg_get_config_import_error_text (usbg_gadget *g)
 Get text of error which occurred during last config import.
 
int usbg_get_config_import_error_line (usbg_gadget *g)
 Get line number where config import error occurred.
 
const char * usbg_get_gadget_import_error_text (usbg_state *s)
 Get text of error which occurred during last gadget import.
 
int usbg_get_gadget_import_error_line (usbg_state *s)
 Get line number where gadget import error occurred.
 

Detailed Description

Public API for USB gadget-configfs library


Data Structure Documentation

◆ usbg_gadget_attrs

struct usbg_gadget_attrs
Data Fields
uint16_t bcdDevice
uint16_t bcdUSB
uint8_t bDeviceClass
uint8_t bDeviceProtocol
uint8_t bDeviceSubClass
uint8_t bMaxPacketSize0
uint16_t idProduct
uint16_t idVendor

◆ usbg_gadget_strs

struct usbg_gadget_strs
Data Fields
char * manufacturer
char * product
char * serial

◆ usbg_gadget_os_descs

struct usbg_gadget_os_descs

USB gadget Microsoft OS Descriptors.

Examples
gadget-rndis-os-desc.c.
Data Fields
uint8_t b_vendor_code
char * qw_sign
bool use

◆ usbg_config_attrs

struct usbg_config_attrs

USB configuration attributes.

Examples
show-gadgets.c.
Data Fields
uint8_t bmAttributes
uint8_t bMaxPower

◆ usbg_config_strs

struct usbg_config_strs
Data Fields
char * configuration

◆ usbg_function_os_desc

struct usbg_function_os_desc

USB OS Descriptor function attributes.

Examples
gadget-rndis-os-desc.c.
Data Fields
char * compatible_id
char * sub_compatible_id

Macro Definition Documentation

◆ usbg_for_each_binding

#define usbg_for_each_binding (   b,
 
)
Value:
for (b = usbg_get_first_binding(c); \
b != NULL; \
usbg_binding * usbg_get_first_binding(usbg_config *c)
Get first binding in binding list.
Definition usbg.c:2635
usbg_binding * usbg_get_next_binding(usbg_binding *b)
Get the next binding on a list.
Definition usbg.c:2660

Iterates over each binding

Examples
show-gadgets.c.

◆ usbg_for_each_config

#define usbg_for_each_config (   c,
 
)
Value:
for (c = usbg_get_first_config(g); \
c != NULL; \
usbg_config * usbg_get_first_config(usbg_gadget *g)
Get first config in config list.
Definition usbg.c:2630
usbg_config * usbg_get_next_config(usbg_config *c)
Get the next config on a list.
Definition usbg.c:2655

Iterates over each config

Examples
show-gadgets.c.

◆ usbg_for_each_function

#define usbg_for_each_function (   f,
 
)
Value:
for (f = usbg_get_first_function(g); \
f != NULL; \
usbg_function * usbg_get_first_function(usbg_gadget *g)
Get first function in function list.
Definition usbg.c:2625
usbg_function * usbg_get_next_function(usbg_function *f)
Get the next function on a list.
Definition usbg.c:2650

Iterates over each function

Examples
show-gadgets.c.

◆ usbg_for_each_gadget

#define usbg_for_each_gadget (   g,
 
)
Value:
for (g = usbg_get_first_gadget(s); \
g != NULL; \
usbg_gadget * usbg_get_next_gadget(usbg_gadget *g)
Get the next gadget on a list.
Definition usbg.c:2645
usbg_gadget * usbg_get_first_gadget(usbg_state *s)
Get first gadget in gadget list.
Definition usbg.c:2620

Iterates over each gadget

Examples
show-gadgets.c.

◆ usbg_for_each_udc

#define usbg_for_each_udc (   u,
 
)
Value:
for (u = usbg_get_first_udc(s); \
u != NULL; \
usbg_udc * usbg_get_next_udc(usbg_udc *u)
Get the next udc on a list.
Definition usbg.c:2665
usbg_udc * usbg_get_first_udc(usbg_state *s)
Get first udc in udc list.
Definition usbg.c:2640

Iterates over each udc

Examples
show-udcs.c.

◆ USBG_RM_RECURSE

#define USBG_RM_RECURSE   1

Additional option for usbg_rm_* functions.

This option allows to remove all content of gadget/config/function recursively.

Examples
gadget-vid-pid-remove.c.

Function Documentation

◆ usbg_add_config_function()

int usbg_add_config_function ( usbg_config c,
const char *  name,
usbg_function f 
)
extern

Add a function to a configuration.

Parameters
cPointer to config
nameName of configuration function binding
fPointer to function
Returns
0 on success, usbg_error on failure.
Examples
gadget-acm-ecm.c, gadget-ffs.c, gadget-ms.c, and gadget-rndis-os-desc.c.

◆ usbg_cleanup()

void usbg_cleanup ( usbg_state s)
extern

Clean up the libusbgx library state.

Parameters
sPointer to state
Examples
gadget-acm-ecm.c, gadget-export.c, gadget-ffs.c, gadget-import.c, gadget-ms.c, gadget-rndis-os-desc.c, gadget-vid-pid-remove.c, show-gadgets.c, and show-udcs.c.

◆ usbg_cleanup_function_attrs()

void usbg_cleanup_function_attrs ( usbg_function f,
void *  f_attrs 
)
extern

Cleanup content of function attributes.

Parameters
f_attrsfunction attributes which should be cleaned up.
Note
This function should be called to free additional memory allocated by usbg_get_function_attrs().
Warning
None of attributes in passed structure should be accessed after returning from this function.
Examples
show-gadgets.c.

◆ usbg_create_config()

int usbg_create_config ( usbg_gadget g,
int  id,
const char *  label,
const struct usbg_config_attrs c_attrs,
const struct usbg_config_strs c_strs,
usbg_config **  c 
)
extern

Create a new USB gadget configuration.

Parameters
gPointer to gadget
idIdentify of configuration
labelconfiguration label, if NULL, default is used
c_attrsConfiguration attributes to be set
c_strsConfiguration strings to be set
cPointer to be filled with pointer to configuration
Note
Given strings are assumed to be in US English
Returns
0 on success usbg_error if error occurred
Examples
gadget-acm-ecm.c, gadget-ffs.c, gadget-ms.c, and gadget-rndis-os-desc.c.

◆ usbg_create_function()

int usbg_create_function ( usbg_gadget g,
usbg_function_type  type,
const char *  instance,
void *  f_attrs,
usbg_function **  f 
)
extern

Create a new USB gadget function and set its attributes.

Parameters
gPointer to gadget
typeType of function
instanceFunction instance name
f_attrsFunction specific attributes to be set. If NULL setting is omitted.
fPointer to be filled with pointer to function
Note
Given strings are assumed to be in US English
Returns
0 on success usbg_error if error occurred
Examples
gadget-acm-ecm.c, gadget-ffs.c, gadget-ms.c, and gadget-rndis-os-desc.c.

◆ usbg_create_gadget()

int usbg_create_gadget ( usbg_state s,
const char *  name,
const struct usbg_gadget_attrs g_attrs,
const struct usbg_gadget_strs g_strs,
usbg_gadget **  g 
)
extern

Create a new USB gadget device and set given attributes and strings.

Parameters
sPointer to state
nameName of the gadget
g_attrsGadget attributes to be set. If NULL setting is omitted.
g_strsGadget strings to be set. If NULL setting is omitted.
gPointer to be filled with pointer to gadget
Note
Given strings are assumed to be in US English
Returns
0 on success usbg_error if error occurred
Examples
gadget-acm-ecm.c, gadget-ffs.c, gadget-ms.c, and gadget-rndis-os-desc.c.

◆ usbg_create_gadget_vid_pid()

int usbg_create_gadget_vid_pid ( usbg_state s,
const char *  name,
uint16_t  idVendor,
uint16_t  idProduct,
usbg_gadget **  g 
)
extern

Create a new USB gadget device.

Parameters
sPointer to state
nameName of the gadget
idVendorGadget vendor ID
idProductGadget product ID
gPointer to be filled with pointer to gadget
Returns
0 on success usbg_error if error occurred

◆ usbg_disable_gadget()

int usbg_disable_gadget ( usbg_gadget g)
extern

Disable a USB gadget device.

Parameters
gPointer to gadget
Returns
0 on success or usbg_error if error occurred.
Examples
gadget-vid-pid-remove.c.

◆ usbg_enable_gadget()

int usbg_enable_gadget ( usbg_gadget g,
usbg_udc udc 
)
extern

Enable a USB gadget device.

Parameters
gPointer to gadget
udcwhere gadget should be assigned. If NULL, default one (first) is used.
Returns
0 on success or usbg_error if error occurred.
Examples
gadget-acm-ecm.c, gadget-ms.c, and gadget-rndis-os-desc.c.

◆ usbg_error_name()

const char * usbg_error_name ( usbg_error  e)
extern

Get the error name as a constant string.

Parameters
eerror code
Returns
Constant string with error name
Examples
gadget-acm-ecm.c, gadget-export.c, gadget-ffs.c, gadget-import.c, gadget-ms.c, gadget-rndis-os-desc.c, gadget-vid-pid-remove.c, show-gadgets.c, and show-udcs.c.

◆ usbg_export_config()

int usbg_export_config ( usbg_config c,
FILE *  stream 
)
extern

Exports configuration to file.

Parameters
cPointer to configuration to be exported
streamwhere configuration should be saved
Returns
0 on success, usbg_error otherwise

◆ usbg_export_function()

int usbg_export_function ( usbg_function f,
FILE *  stream 
)
extern

Exports usb function to file.

Parameters
fPointer to function to be exported
streamwhere function should be saved
Returns
0 on success, usbg_error otherwise

◆ usbg_export_gadget()

int usbg_export_gadget ( usbg_gadget g,
FILE *  stream 
)
extern

Exports whole gadget to file.

Parameters
gPointer to gadget to be exported
streamwhere gadget should be saved
Returns
0 on success, usbg_error otherwise
Examples
gadget-export.c.

◆ usbg_get_binding_name()

const char * usbg_get_binding_name ( usbg_binding b)
extern

Get binding name.

Parameters
bPointer to binding
Returns
Binding name or NULL if error occurred.
Warning
Returned buffer should not be edited! Returned string is valid as long as passed usbg_binding is valid. For example binding name is valid until someone remove this binding.
Examples
show-gadgets.c.

◆ usbg_get_binding_name_s()

int usbg_get_binding_name_s ( usbg_binding b,
char *  buf,
int  len 
)
extern

Get binding name into user buffer.

Parameters
[in]bPointer to binding
[out]bufPlace where binding name should be stored
[in]lenSize of buffer
Returns
Number of bytes placed into buf (excluding '\0') or the number of characters which would have been written to the buffer if enough space had been available. (just like snprintf() family).

◆ usbg_get_binding_target()

usbg_function * usbg_get_binding_target ( usbg_binding b)
extern

Get target function of given binding.

Parameters
bBinding between configuration and function
Returns
Pointer to USB function which is target for this binding
Examples
show-gadgets.c.

◆ usbg_get_config()

usbg_config * usbg_get_config ( usbg_gadget g,
int  id,
const char *  label 
)
extern

Get a configuration by name.

Parameters
gPointer to gadget
idIdentify of configuration
labelConfiguration label. If not NULL this function will return valid value only if configuration with given id exist and has this label. If NULL this function will return config with given id (if such exist) and ignore this param.
Returns
Pointer to config or NULL if a matching config isn't found

◆ usbg_get_config_attrs()

int usbg_get_config_attrs ( usbg_config c,
struct usbg_config_attrs c_attrs 
)
extern

Get the USB configuration strings.

Parameters
cPointer to configuration
c_attrsStructure to be filled
Returns
0 on success or usbg_error if error occurred.
Examples
show-gadgets.c.

◆ usbg_get_config_id()

int usbg_get_config_id ( usbg_config c)
extern

Get config id.

Parameters
cPointer to config
Returns
Configuration id or usbg_error if error occurred.
Examples
show-gadgets.c.

◆ usbg_get_config_import_error_line()

int usbg_get_config_import_error_line ( usbg_gadget g)
extern

Get line number where config import error occurred.

Parameters
ggadget where config import error occurred
Returns
line number or value below 0 if no error data

◆ usbg_get_config_import_error_text()

const char * usbg_get_config_import_error_text ( usbg_gadget g)
extern

Get text of error which occurred during last config import.

Parameters
ggadget where config import error occurred
Returns
Text of error or NULL if no error data

◆ usbg_get_config_label()

const char * usbg_get_config_label ( usbg_config c)
extern

Get config label.

Parameters
cPointer to config
Returns
config label or NULL if error occurred.
Warning
Returned buffer should not be edited! Returned string is valid as long as passed usbg_config is valid. For example config label is valid until someone remove this function.
Examples
show-gadgets.c.

◆ usbg_get_config_label_s()

int usbg_get_config_label_s ( usbg_config c,
char *  buf,
int  len 
)
extern

Get config label into user buffer.

Parameters
[in]cPointer to config
[out]bufPlace where label should be stored
[in]lenSize of buffer
Returns
Number of bytes placed into buf (excluding '\0') or the number of characters which would have been written to the buffer if enough space had been available. (just like snprintf() family).

◆ usbg_get_config_strs()

int usbg_get_config_strs ( usbg_config c,
int  lang,
struct usbg_config_strs c_strs 
)
extern

Get the USB configuration strings.

Parameters
cPointer to configuration
langLanguage of strings
c_strsStructure to be filled
Returns
0 on success or usbg_error if error occurred.
Examples
show-gadgets.c.

◆ usbg_get_config_strs_langs()

int usbg_get_config_strs_langs ( usbg_config c,
int **  langs 
)
extern

Get the array of languages available in this config.

Parameters
cPointer to configuration
langsarray of available language codes
Returns
0 on success usbg_error if error occurred
Examples
show-gadgets.c.

◆ usbg_get_configfs_path()

const char * usbg_get_configfs_path ( usbg_state s)
extern

Get ConfigFS path.

Parameters
sPointer to state
Returns
Path to configfs or NULL if error occurred
Warning
Returned buffer should not be edited! Returned string is valid as long as passed usbg_state is valid. For example path is valid until usbg_cleanup() call.

◆ usbg_get_configfs_path_s()

int usbg_get_configfs_path_s ( usbg_state s,
char *  buf,
int  len 
)
extern

Get ConfigFS path into user buffer.

Parameters
[in]sPointer to state
[out]bufPlace where path should be stored
[in]lenSize of buffer
Returns
Number of bytes placed into buf (excluding '\0') or the number of characters which would have been written to the buffer if enough space had been available. (just like snprintf() family).

◆ usbg_get_first_binding()

usbg_binding * usbg_get_first_binding ( usbg_config c)
extern

Get first binding in binding list.

Parameters
cPointer to configuration
Returns
Pointer to binding or NULL if list is empty.
Note
Bindings are sorted in strings (name) order

◆ usbg_get_first_config()

usbg_config * usbg_get_first_config ( usbg_gadget g)
extern

Get first config in config list.

Parameters
gPointer of gadget
Returns
Pointer to configuration or NULL if list is empty.
Note
Configs are sorted in strings (name) order

◆ usbg_get_first_function()

usbg_function * usbg_get_first_function ( usbg_gadget g)
extern

Get first function in function list.

Parameters
gPointer of gadget
Returns
Pointer to function or NULL if list is empty.
Note
Functions are sorted in strings (name) order

◆ usbg_get_first_gadget()

usbg_gadget * usbg_get_first_gadget ( usbg_state s)
extern

Get first gadget in gadget list.

Parameters
sState of library
Returns
Pointer to gadget or NULL if list is empty.
Note
Gadgets are sorted in strings (name) order
Examples
gadget-vid-pid-remove.c.

◆ usbg_get_first_udc()

usbg_udc * usbg_get_first_udc ( usbg_state s)
extern

Get first udc in udc list.

Parameters
sState of library
Returns
Pointer to udc or NULL if list is empty.
Note
UDCs are sorted in strings (name) order

◆ usbg_get_func_import_error_line()

int usbg_get_func_import_error_line ( usbg_gadget g)
extern

Get line number where function import error occurred.

Parameters
ggadget where function import error occurred
Returns
line number or value below 0 if no error data

◆ usbg_get_func_import_error_text()

const char * usbg_get_func_import_error_text ( usbg_gadget g)
extern

Get text of error which occurred during last function import.

Parameters
ggadget where function import error occurred
Returns
Text of error or NULL if no error data

◆ usbg_get_function()

usbg_function * usbg_get_function ( usbg_gadget g,
usbg_function_type  type,
const char *  instance 
)
extern

Get a function by name.

Parameters
gPointer to gadget
typeFunction type
instanceInstance of function
Returns
Pointer to function or NULL if a matching function isn't found

◆ usbg_get_function_attrs()

int usbg_get_function_attrs ( usbg_function f,
void *  f_attrs 
)
extern

Get attributes of given function.

Parameters
fPointer to function
f_attrsUnion to be filled
Returns
0 on success usbg_error if error occurred.
Warning
memory pointed by f_attrs should be big enough to hold attributes specific for given function type. This function can by dangerous. That's why it is strongly recomended to use set/get function provided by each function type.
Examples
show-gadgets.c.

◆ usbg_get_function_instance()

const char * usbg_get_function_instance ( usbg_function f)
extern

Get function instance name.

Parameters
fPointer to function
Returns
instance name or NULL if error occurred.
Warning
Returned buffer should not be edited! Returned string is valid as long as passed usbg_function is valid. For example instance name is valid until someone remove this function.
Examples
show-gadgets.c.

◆ usbg_get_function_instance_s()

int usbg_get_function_instance_s ( usbg_function f,
char *  buf,
int  len 
)
extern

Get function instance name into user buffer.

Parameters
[in]fPointer to function
[out]bufPlace where instance name should be stored
[in]lenSize of buffer
Returns
Number of bytes placed into buf (excluding '\0') or the number of characters which would have been written to the buffer if enough space had been available. (just like snprintf() family).

◆ usbg_get_function_type()

usbg_function_type usbg_get_function_type ( usbg_function f)
extern

Get type of given function.

Parameters
fPointer to function
Returns
usbg_function_type (0 or above) or usbg_error (below 0) if error occurred
Examples
show-gadgets.c.

◆ usbg_get_function_type_str()

const char * usbg_get_function_type_str ( usbg_function_type  type)
extern

Get function type as a string.

Parameters
typeFunction type
Returns
String suitable for given function type
Examples
show-gadgets.c.

◆ usbg_get_gadget()

usbg_gadget * usbg_get_gadget ( usbg_state s,
const char *  name 
)
extern

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
Examples
gadget-export.c.

◆ usbg_get_gadget_attr()

int usbg_get_gadget_attr ( usbg_gadget g,
usbg_gadget_attr  attr 
)
extern

Get value of selected attribute.

Parameters
gPointer to gadget
attrCode of selected attribute
Returns
Value of selected attribute (always above zero) or usbg_error if error occurred.
Note
User should use only lowest one or two bytes as attribute value depending on attribute size (see usbg_gadget_attrs for details).

◆ usbg_get_gadget_attr_str()

const char * usbg_get_gadget_attr_str ( usbg_gadget_attr  attr)
extern

Get string representing selected gadget attribute.

Parameters
attrcode of selected attribute
Returns
String suitable for given attribute or NULL if such string has not been found

◆ usbg_get_gadget_attrs()

int usbg_get_gadget_attrs ( usbg_gadget g,
struct usbg_gadget_attrs g_attrs 
)
extern

Get the USB gadget strings.

Parameters
gPointer to gadget
g_attrsStructure to be filled
Returns
0 on success usbg_error if error occurred
Examples
gadget-vid-pid-remove.c, and show-gadgets.c.

◆ usbg_get_gadget_import_error_line()

int usbg_get_gadget_import_error_line ( usbg_state s)
extern

Get line number where gadget import error occurred.

Parameters
swhere gadget import error occurred
Returns
line number or value below 0 if no error data
Examples
gadget-import.c.

◆ usbg_get_gadget_import_error_text()

const char * usbg_get_gadget_import_error_text ( usbg_state s)
extern

Get text of error which occurred during last gadget import.

Parameters
swhere gadget import error occurred
Returns
Text of error or NULL if no error data
Examples
gadget-import.c.

◆ usbg_get_gadget_name()

const char * usbg_get_gadget_name ( usbg_gadget g)
extern

Get gadget name.

Parameters
gPointer to gadget
Returns
Gadget name or NULL if error occurred.
Warning
Returned buffer should not be edited! Returned string is valid as long as passed usbg_gadget is valid. For example gadget name is valid until someone remove gadget.
Examples
show-gadgets.c, and show-udcs.c.

◆ usbg_get_gadget_name_s()

int usbg_get_gadget_name_s ( usbg_gadget g,
char *  buf,
int  len 
)
extern

Get gadget name into user buffer.

Parameters
[in]gPointer to state
[out]bufPlace where name should be stored
[in]lenSize of buffer
Returns
Number of bytes placed into buf (excluding '\0') or the number of characters which would have been written to the buffer if enough space had been available. (just like snprintf() family).

◆ usbg_get_gadget_os_desc_name()

const char * usbg_get_gadget_os_desc_name ( usbg_gadget_os_desc_strs  str)
extern

Get name of selected OS Descriptor string.

Parameters
strOS Descriptor string code
Returns
Name of OS Descriptor associated with this code

◆ usbg_get_gadget_os_descs()

int usbg_get_gadget_os_descs ( usbg_gadget g,
struct usbg_gadget_os_descs g_os_descs 
)
extern

Get the USB gadget OS Descriptor.

Parameters
gPointer to gadget
g_os_descsStructure to be filled
Returns
0 on success usbg_error if error occurred

◆ usbg_get_gadget_str_name()

const char * usbg_get_gadget_str_name ( usbg_gadget_str  str)
extern

Get name of selected gadget string.

Parameters
strGadget string code
Returns
Name of string associated with this code

◆ usbg_get_gadget_strs()

int usbg_get_gadget_strs ( usbg_gadget g,
int  lang,
struct usbg_gadget_strs g_strs 
)
extern

Get the USB gadget strings.

Parameters
gPointer to gadget
langLanguage of strings
g_strsStructure to be filled
Returns
0 on success usbg_error if error occurred
Examples
show-gadgets.c.

◆ usbg_get_gadget_strs_langs()

int usbg_get_gadget_strs_langs ( usbg_gadget g,
int **  langs 
)
extern

Get the array of languages available in this gadget.

Parameters
gPointer to gadget
langsarray of available language codes
Returns
0 on success usbg_error if error occurred
Examples
show-gadgets.c.

◆ usbg_get_gadget_udc()

usbg_udc * usbg_get_gadget_udc ( usbg_gadget g)
extern

Get udc to which gadget is bound.

Parameters
gPointer to gadget
Returns
Pointer to UDC or NULL if gadget is not enabled
Examples
gadget-vid-pid-remove.c, and show-gadgets.c.

◆ usbg_get_interf_os_desc()

int usbg_get_interf_os_desc ( usbg_function f,
const char *  iname,
struct usbg_function_os_desc f_os_desc 
)
extern

Get OS Descriptor compatibility of given function.

Parameters
fPointer to function
inameInterface name
f_os_descOS Descriptor compatibility to be filled
Returns
0 on success, usbg_error if error occurred

◆ usbg_get_next_binding()

usbg_binding * usbg_get_next_binding ( usbg_binding b)
extern

Get the next binding on a list.

Parameters
bPointer to current binding
Returns
Next binding or NULL if end of list.

◆ usbg_get_next_config()

usbg_config * usbg_get_next_config ( usbg_config c)
extern

Get the next config on a list.

Parameters
cPointer to current config
Returns
Next config or NULL if end of list.

◆ usbg_get_next_function()

usbg_function * usbg_get_next_function ( usbg_function f)
extern

Get the next function on a list.

Parameters
fPointer to current function
Returns
Next function or NULL if end of list.

◆ usbg_get_next_gadget()

usbg_gadget * usbg_get_next_gadget ( usbg_gadget g)
extern

Get the next gadget on a list.

Parameters
gPointer to current gadget
Returns
Next gadget or NULL if end of list.
Examples
gadget-vid-pid-remove.c.

◆ usbg_get_next_udc()

usbg_udc * usbg_get_next_udc ( usbg_udc u)
extern

Get the next udc on a list.

Parameters
uPointer to current udc
Returns
Next udc or NULL if end of list.

◆ usbg_get_os_desc_binding()

usbg_config * usbg_get_os_desc_binding ( usbg_gadget g)

Get configuration selected for OS Descriptors.

Parameters
gPointer to gadget
Returns
usbg_config or NULL

◆ usbg_get_udc()

usbg_udc * usbg_get_udc ( usbg_state s,
const char *  name 
)
extern

Get a udc by name.

Parameters
sPointer to state
nameName of the udc
Returns
Pointer to udc or NULL if a matching udc isn't found

◆ usbg_get_udc_gadget()

usbg_gadget * usbg_get_udc_gadget ( usbg_udc u)
extern

Get gadget which is attached to this UDC.

Parameters
uPointer to udc
Returns
Pointer to gadget or NULL if UDC is free
Examples
show-udcs.c.

◆ usbg_get_udc_name()

const char * usbg_get_udc_name ( usbg_udc u)
extern

Get name of udc.

Parameters
uPointer to udc
Returns
UDC name or NULL if error occurred.
Warning
Returned buffer should not be edited! Returned string is valid as long as passed usbg_state is valid. For example UDC name is valid until usbg_cleanup().
Examples
show-gadgets.c, and show-udcs.c.

◆ usbg_get_udc_name_s()

int usbg_get_udc_name_s ( usbg_udc u,
char *  buf,
int  len 
)
extern

Get udc name into user buffer.

Parameters
[in]uPointer to udc
[out]bufPlace where udc name should be stored
[in]lenSize of buffer
Returns
Number of bytes placed into buf (excluding '\0') or the number of characters which would have been written to the buffer if enough space had been available. (just like snprintf() family).

◆ usbg_import_config()

int usbg_import_config ( usbg_gadget g,
FILE *  stream,
int  id,
usbg_config **  c 
)
extern

Imports usb configuration from file and adds it to given gadget.

Parameters
gGadget where configuration should be placed
streamfrom which configuration should be imported
idwhich should be used for new configuration
cplace for pointer to imported configuration if NULL this param will be ignored.
Returns
0 on success, usbg_error otherwise

◆ usbg_import_function()

int usbg_import_function ( usbg_gadget g,
FILE *  stream,
const char *  instance,
usbg_function **  f 
)
extern

Imports usb function from file and adds it to given gadget.

Parameters
gGadget where function should be placed
streamfrom which function should be imported
instancename which should be used for new function
fplace for pointer to imported function if NULL this param will be ignored.
Returns
0 on success, usbg_error otherwise

◆ usbg_import_gadget()

int usbg_import_gadget ( usbg_state s,
FILE *  stream,
const char *  name,
usbg_gadget **  g 
)
extern

Imports usb gadget from file.

Parameters
scurrent state of library
streamfrom which gadget should be imported
namewhich should be used for new gadget
gplace for pointer to imported gadget if NULL this param will be ignored.
Returns
0 on success, usbg_error otherwise
Examples
gadget-import.c.

◆ usbg_init()

int usbg_init ( const char *  configfs_path,
usbg_state **  state 
)
extern

Initialize the libusbgx library state.

Parameters
configfs_pathPath to the mounted configfs filesystem
statePointer to be filled with pointer to usbg_state
Returns
0 on success, usbg_error on error
Examples
gadget-acm-ecm.c, gadget-export.c, gadget-ffs.c, gadget-import.c, gadget-ms.c, gadget-rndis-os-desc.c, gadget-vid-pid-remove.c, show-gadgets.c, and show-udcs.c.

◆ usbg_lookup_function_type()

int usbg_lookup_function_type ( const char *  name)
extern

Lookup function type suitable for given name.

Parameters
nameName of function
Returns
Function type enum or negative error code

◆ usbg_lookup_gadget_attr()

int usbg_lookup_gadget_attr ( const char *  name)
extern

Lookup attr code based on its name.

Parameters
nameof attribute
Returns
code of suitable attribute or usbg_error

◆ usbg_lookup_gadget_str()

int usbg_lookup_gadget_str ( const char *  name)
extern

Lookup str code based on its name.

Parameters
nameof string
Returns
code of suitable string or usbg_error

◆ usbg_rm_binding()

int usbg_rm_binding ( usbg_binding b)
extern

Remove binding between configuration and function.

This function frees also the memory allocated for binding

Parameters
bBinding to be removed
Returns
0 on success, usbg_error if error occurred

◆ usbg_rm_config()

int usbg_rm_config ( usbg_config c,
int  opts 
)
extern

Remove configuration.

This function frees also the memory allocated for configuration

Parameters
cConfiguration to be removed
optsAdditional options for configuration removal.
Returns
0 on success, usbg_error if error occurred

◆ usbg_rm_config_strs()

int usbg_rm_config_strs ( usbg_config c,
int  lang 
)
extern

Remove configuration strings for given language.

Parameters
cPointer to configuration
langLanguage of strings which should be deleted
Returns
0 on success, usbg_error if error occurred

◆ usbg_rm_function()

int usbg_rm_function ( usbg_function f,
int  opts 
)
extern

Remove existing USB function.

This function frees also the memory allocated for function

Parameters
fFunction to be removed
optsAdditional options for configuration removal.
Returns
0 on success, usbg_error if error occurred

◆ usbg_rm_gadget()

int usbg_rm_gadget ( usbg_gadget g,
int  opts 
)
extern

Remove existing USB gadget.

This function frees also the memory allocated for gadget

Parameters
gGadget to be removed
optsAdditional options for configuration removal.
Returns
0 on success, usbg_error if error occurred
Examples
gadget-vid-pid-remove.c.

◆ usbg_rm_gadget_strs()

int usbg_rm_gadget_strs ( usbg_gadget g,
int  lang 
)
extern

Remove gadget strings for given language.

Parameters
gPointer to gadget
langLanguage of strings which should be deleted
Returns
0 on success, usbg_error if error occurred

◆ usbg_set_config_attrs()

int usbg_set_config_attrs ( usbg_config c,
const struct usbg_config_attrs c_attrs 
)
extern

Set the USB configuration attributes.

Parameters
cPointer to configuration
c_attrsConfiguration attributes
Returns
0 on success or usbg_error if error occurred.

◆ usbg_set_config_bm_attrs()

int usbg_set_config_bm_attrs ( usbg_config c,
int  bmAttributes 
)
extern

Set the configuration bitmap attributes.

Parameters
cPointer to config
bmAttributesConfiguration characteristics
Returns
0 on success or usbg_error if error occurred.

◆ usbg_set_config_max_power()

int usbg_set_config_max_power ( usbg_config c,
int  bMaxPower 
)
extern

Set the configuration maximum power.

Parameters
cPointer to config
bMaxPowerMaximum power (in 2 mA units)
Returns
0 on success or usbg_error if error occurred.

◆ usbg_set_config_string()

int usbg_set_config_string ( usbg_config c,
int  lang,
const char *  string 
)
extern

Set the configuration string.

Parameters
cPointer to config
langUSB language ID
stringConfiguration description
Returns
0 on success, usbg_error on failure.

◆ usbg_set_config_strs()

int usbg_set_config_strs ( usbg_config c,
int  lang,
const struct usbg_config_strs c_strs 
)
extern

Set the USB configuration strings.

Parameters
cPointer to configuration
langUSB language ID
c_strsConfiguration strings
Returns
0 on success, usbg_error on failure.

◆ usbg_set_function_attrs()

int usbg_set_function_attrs ( usbg_function f,
void *  f_attrs 
)
extern

Set attributes of given function.

Parameters
fPointer to function
f_attrsAttributes to be set
Returns
0 on success, usbg_error if error occurred

◆ usbg_set_gadget_attr()

int usbg_set_gadget_attr ( usbg_gadget g,
usbg_gadget_attr  attr,
int  val 
)
extern

Set selected attribute to value.

Parameters
gPointer to gadget
attrCode of selected attribute
valvalue to be set
Returns
0 on success, usbg_error otherwise
Note
val is of type int but value provided to this function should be suitable to place it in type dedicated for selected attr (uint16 or uint8)

◆ usbg_set_gadget_attrs()

int usbg_set_gadget_attrs ( usbg_gadget g,
const struct usbg_gadget_attrs g_attrs 
)
extern

Set the USB gadget attributes.

Parameters
gPointer to gadget
g_attrsGadget attributes
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_device_bcd_device()

int usbg_set_gadget_device_bcd_device ( usbg_gadget g,
uint16_t  bcdDevice 
)
extern

Set the gadget device BCD release number.

Parameters
gPointer to gadget
bcdDeviceBCD release number
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_device_bcd_usb()

int usbg_set_gadget_device_bcd_usb ( usbg_gadget g,
uint16_t  bcdUSB 
)
extern

Set the gadget device BCD USB version.

Parameters
gPointer to gadget
bcdUSBBCD USB version
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_device_class()

int usbg_set_gadget_device_class ( usbg_gadget g,
uint8_t  bDeviceClass 
)
extern

Set the USB gadget device class code.

Parameters
gPointer to gadget
bDeviceClassUSB device class code
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_device_max_packet()

int usbg_set_gadget_device_max_packet ( usbg_gadget g,
uint8_t  bMaxPacketSize0 
)
extern

Set the maximum packet size for a gadget.

Parameters
gPointer to gadget
bMaxPacketSize0Maximum packet size
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_device_protocol()

int usbg_set_gadget_device_protocol ( usbg_gadget g,
uint8_t  bDeviceProtocol 
)
extern

Set the USB gadget protocol code.

Parameters
gPointer to gadget
bDeviceProtocolUSB protocol code
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_device_subclass()

int usbg_set_gadget_device_subclass ( usbg_gadget g,
uint8_t  bDeviceSubClass 
)
extern

Set the USB gadget device subclass code.

Parameters
gPointer to gadget
bDeviceSubClassUSB device subclass code
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_manufacturer()

int usbg_set_gadget_manufacturer ( usbg_gadget g,
int  lang,
const char *  mnf 
)
extern

Set the manufacturer name for a gadget.

Parameters
gPointer to gadget
langUSB language ID
mnfManufacturer
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_os_descs()

int usbg_set_gadget_os_descs ( usbg_gadget g,
const struct usbg_gadget_os_descs g_os_descs 
)
extern

Set the USB gadget OS Descriptor.

Parameters
gPointer to gadget
g_os_descsStructure to be filled
Returns
0 on success usbg_error if error occurred
Examples
gadget-rndis-os-desc.c.

◆ usbg_set_gadget_product()

int usbg_set_gadget_product ( usbg_gadget g,
int  lang,
const char *  prd 
)
extern

Set the product name for a gadget.

Parameters
gPointer to gadget
langUSB language ID
prdProduct
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_product_id()

int usbg_set_gadget_product_id ( usbg_gadget g,
uint16_t  idProduct 
)
extern

Set the USB gadget product id.

Parameters
gPointer to gadget
idProductUSB device product id
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_serial_number()

int usbg_set_gadget_serial_number ( usbg_gadget g,
int  lang,
const char *  ser 
)
extern

Set the serial number for a gadget.

Parameters
gPointer to gadget
langUSB language ID
serSerial number
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_str()

int usbg_set_gadget_str ( usbg_gadget g,
usbg_gadget_str  str,
int  lang,
const char *  val 
)
extern

Set selected string.

Parameters
gPointer to gadget
strCode of selected string
valvalue to be set
Returns
0 on success, usbg_error otherwise

◆ usbg_set_gadget_strs()

int usbg_set_gadget_strs ( usbg_gadget g,
int  lang,
const struct usbg_gadget_strs g_strs 
)
extern

Set the USB gadget strings.

Parameters
gPointer to gadget
langUSB language ID
g_strsGadget attributes
Returns
0 on success usbg_error if error occurred

◆ usbg_set_gadget_vendor_id()

int usbg_set_gadget_vendor_id ( usbg_gadget g,
uint16_t  idVendor 
)
extern

Set the USB gadget vendor id.

Parameters
gPointer to gadget
idVendorUSB device vendor id
Returns
0 on success usbg_error if error occurred

◆ usbg_set_interf_os_desc()

int usbg_set_interf_os_desc ( usbg_function f,
const char *  iname,
const struct usbg_function_os_desc f_os_desc 
)
extern

Set OS Descriptor compatibility of given function.

Parameters
fPointer to function
inameInterface name
f_os_descOS Descriptor compatibility to be set
Returns
0 on success, usbg_error if error occurred
Examples
gadget-rndis-os-desc.c.

◆ usbg_set_os_desc_config()

int usbg_set_os_desc_config ( usbg_gadget g,
usbg_config c 
)
extern

Set configuration for OS Descriptors.

Parameters
gPointer to gadget
cPointer to config
Returns
0 on success, usbg_error on failure.
Examples
gadget-rndis-os-desc.c.

◆ usbg_strerror()

const char * usbg_strerror ( usbg_error  e)
extern

Get the short description of error.

Parameters
eerror code
Returns
Constant string with error description
Examples
gadget-acm-ecm.c, gadget-export.c, gadget-ffs.c, gadget-import.c, gadget-ms.c, gadget-rndis-os-desc.c, gadget-vid-pid-remove.c, show-gadgets.c, and show-udcs.c.