1
0
Fork 0
mirror of https://github.com/linux-usb-gadgets/libusbgx.git synced 2025-07-26 02:05:06 +03:00

libusbg: rename gadget_*() -> usbg_*(), libusbg, and usbg.h

Rename library to libusbg. Moves the API include to usbg.h and
accordingly changes all API prefixes to usbg_*().

Signed-off-by: Matt Porter <mporter@linaro.org>
This commit is contained in:
Matt Porter 2014-01-04 15:23:14 -05:00
parent 8b074b73d1
commit a371518d64
12 changed files with 190 additions and 190 deletions

View file

@ -1,4 +1,4 @@
Installing libgadget: Installing libusbg:
$ autoreconf -i $ autoreconf -i
$ ./configure $ ./configure

View file

@ -2,7 +2,7 @@ include $(top_srcdir)/aminclude.am
SUBDIRS = src examples SUBDIRS = src examples
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = doxygen.cfg EXTRA_DIST = doxygen.cfg
library_includedir=$(includedir)/gadget library_includedir=$(includedir)/usbg
library_include_HEADERS = include/gadget/gadget.h library_include_HEADERS = include/usbg/usbg.h
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libgadget.pc pkgconfig_DATA = libusbg.pc

6
README
View file

@ -1,7 +1,7 @@
libgadget libusbg
--------- -------
libgadget is a C library encapsulating the kernel USB gadget-configfs libusbg is a C library encapsulating the kernel USB gadget-configfs
userspace API functionality. userspace API functionality.
It provides routines for creating and parsing USB gadget devices using It provides routines for creating and parsing USB gadget devices using

View file

@ -1,9 +1,9 @@
AC_INIT([libgadget], [0.0.1], [matt.porter@linaro.org]) AC_INIT([libusbg], [0.0.1], [matt.porter@linaro.org])
AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC AC_PROG_CC
AM_PROG_AR AM_PROG_AR
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
LT_INIT LT_INIT
AC_CONFIG_FILES([Makefile src/Makefile examples/Makefile libgadget.pc]) AC_CONFIG_FILES([Makefile src/Makefile examples/Makefile libusbg.pc])
DX_INIT_DOXYGEN([$PACKAGE_NAME],[doxygen.cfg]) DX_INIT_DOXYGEN([$PACKAGE_NAME],[doxygen.cfg])
AC_OUTPUT AC_OUTPUT

View file

@ -648,7 +648,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories # directories like "/usr/src/myproject". Separate the files or directories
# with spaces. # with spaces.
INPUT = $(SRCDIR)/include/gadget/ $(SRCDIR)/src $(SRCDIR)/examples/ INPUT = $(SRCDIR)/include/usbg/ $(SRCDIR)/src $(SRCDIR)/examples/
# This tag can be used to specify the character encoding of the source files # This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is

View file

@ -2,4 +2,4 @@ bin_PROGRAMS = show-gadgets gadget-acm-ecm
gadget_acm_ecm_SOURCES = gadget-acm-ecm.c gadget_acm_ecm_SOURCES = gadget-acm-ecm.c
show_gadgets_SOURCES = show-gadgets.c show_gadgets_SOURCES = show-gadgets.c
AM_CPPFLAGS=-I../include/ AM_CPPFLAGS=-I../include/
AM_LDFLAGS=-L../src/ -lgadget AM_LDFLAGS=-L../src/ -lusbg

View file

@ -16,7 +16,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <gadget/gadget.h> #include <usbg/usbg.h>
/** /**
* @file gadget-acm-ecm.c * @file gadget-acm-ecm.c
@ -36,55 +36,55 @@ int main(void)
struct function *f_acm0, *f_acm1, *f_ecm; struct function *f_acm0, *f_acm1, *f_ecm;
int ret = -EINVAL; int ret = -EINVAL;
s = gadget_init("/config"); s = usbg_init("/config");
if (!s) { if (!s) {
fprintf(stderr, "Error on USB gadget init\n"); fprintf(stderr, "Error on USB gadget init\n");
goto error1; goto error1;
} }
g = gadget_create_gadget(s, "g1", VENDOR, PRODUCT); g = usbg_create_gadget(s, "g1", VENDOR, PRODUCT);
if (!g) { if (!g) {
fprintf(stderr, "Error on create gadget\n"); fprintf(stderr, "Error on create gadget\n");
goto error2; goto error2;
} }
gadget_set_gadget_serial_number(g, LANG_US_ENG, "0123456789"); usbg_set_gadget_serial_number(g, LANG_US_ENG, "0123456789");
gadget_set_gadget_manufacturer(g, LANG_US_ENG, "Foo Inc."); usbg_set_gadget_manufacturer(g, LANG_US_ENG, "Foo Inc.");
gadget_set_gadget_product(g, LANG_US_ENG, "Bar Gadget"); usbg_set_gadget_product(g, LANG_US_ENG, "Bar Gadget");
f_acm0 = gadget_create_function(g, F_ACM, "usb0"); f_acm0 = usbg_create_function(g, F_ACM, "usb0");
if (!f_acm0) { if (!f_acm0) {
fprintf(stderr, "Error creating acm0 function\n"); fprintf(stderr, "Error creating acm0 function\n");
goto error2; goto error2;
} }
f_acm1 = gadget_create_function(g, F_ACM, "usb1"); f_acm1 = usbg_create_function(g, F_ACM, "usb1");
if (!f_acm1) { if (!f_acm1) {
fprintf(stderr, "Error creating acm1 function\n"); fprintf(stderr, "Error creating acm1 function\n");
goto error2; goto error2;
} }
f_ecm = gadget_create_function(g, F_ECM, "usb0"); f_ecm = usbg_create_function(g, F_ECM, "usb0");
if (!f_ecm) { if (!f_ecm) {
fprintf(stderr, "Error creating ecm function\n"); fprintf(stderr, "Error creating ecm function\n");
goto error2; goto error2;
} }
c = gadget_create_config(g, "c.1"); c = usbg_create_config(g, "c.1");
if (!c) { if (!c) {
fprintf(stderr, "Error creating config\n"); fprintf(stderr, "Error creating config\n");
goto error2; goto error2;
} }
gadget_set_config_string(c, LANG_US_ENG, "CDC 2xACM+ECM"); usbg_set_config_string(c, LANG_US_ENG, "CDC 2xACM+ECM");
gadget_add_config_function(c, "acm.GS0", f_acm0); usbg_add_config_function(c, "acm.GS0", f_acm0);
gadget_add_config_function(c, "acm.GS1", f_acm1); usbg_add_config_function(c, "acm.GS1", f_acm1);
gadget_add_config_function(c, "ecm.usb0", f_ecm); usbg_add_config_function(c, "ecm.usb0", f_ecm);
gadget_enable_gadget(g, DEFAULT_UDC); usbg_enable_gadget(g, DEFAULT_UDC);
return 0; return 0;
error2: error2:
gadget_cleanup(s); usbg_cleanup(s);
error1: error1:
return -EINVAL; return -EINVAL;

View file

@ -17,8 +17,8 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <gadget/gadget.h>
#include <netinet/ether.h> #include <netinet/ether.h>
#include <usbg/usbg.h>
/** /**
* @file show-gadgets.c * @file show-gadgets.c
@ -83,7 +83,7 @@ void show_config(struct config *c)
fprintf(stdout, " MaxPower\t\t%d\n", c->maxpower); fprintf(stdout, " MaxPower\t\t%d\n", c->maxpower);
fprintf(stdout, " bmAttributes\t0x%02x\n", c->bmattrs); fprintf(stdout, " bmAttributes\t0x%02x\n", c->bmattrs);
fprintf(stdout, " configuration\t%s\n", c->str_cfg); fprintf(stdout, " configuration\t%s\n", c->str_cfg);
gadget_for_each_binding(b, c) usbg_for_each_binding(b, c)
fprintf(stdout, " %s -> %s\n", b->name,b->target->name); fprintf(stdout, " %s -> %s\n", b->name,b->target->name);
} }
@ -96,21 +96,21 @@ int main(void)
struct binding *b; struct binding *b;
struct function *f_acm0, *f_acm1, *f_ecm; struct function *f_acm0, *f_acm1, *f_ecm;
s = gadget_init("/config"); s = usbg_init("/config");
if (!s) { if (!s) {
fprintf(stderr, "Error on USB gadget init\n"); fprintf(stderr, "Error on USB gadget init\n");
return -EINVAL; return -EINVAL;
} }
gadget_for_each_gadget(g, s) { usbg_for_each_gadget(g, s) {
show_gadget(g); show_gadget(g);
gadget_for_each_function(f, g) usbg_for_each_function(f, g)
show_function(f); show_function(f);
gadget_for_each_config(c, g) usbg_for_each_config(c, g)
show_config(c); show_config(c);
} }
gadget_cleanup(s); usbg_cleanup(s);
return 0; return 0;
} }

View file

@ -19,13 +19,13 @@
#include <netinet/ether.h> #include <netinet/ether.h>
/** /**
* @file include/gadget/gadget.h * @file include/usbg/usbg.h
* @todo Add gadget_remove_[gadget|config|function|binding] APIs * @todo Add usbg_remove_[gadget|config|function|binding] APIs
* @todo Clean up static buffers in structures * @todo Clean up static buffers in structures
*/ */
/** /**
* @addtogroup libgadget * @addtogroup libusbg
* Public API for USB gadget-configfs library * Public API for USB gadget-configfs library
* @{ * @{
*/ */
@ -193,17 +193,17 @@ struct binding
/* Library init and cleanup */ /* Library init and cleanup */
/** /**
* @brief Initialize the libgadget library state * @brief Initialize the libusbg library state
* @param configfs_path Path to the mounted configfs filesystem * @param configfs_path Path to the mounted configfs filesystem
* @return Pointer to a state structure * @return Pointer to a state structure
*/ */
extern struct state *gadget_init(char *configfs_path); extern struct state *usbg_init(char *configfs_path);
/** /**
* @brief Clean up the libgadget library state * @brief Clean up the libusbg library state
* @param s Pointer to state * @param s Pointer to state
*/ */
extern void gadget_cleanup(struct state *s); extern void usbg_cleanup(struct state *s);
/* USB gadget queries */ /* USB gadget queries */
@ -213,7 +213,7 @@ extern void gadget_cleanup(struct state *s);
* @param name Name of the gadget device * @param name Name of the gadget device
* @return Pointer to gadget or NULL if a matching gadget isn't found * @return Pointer to gadget or NULL if a matching gadget isn't found
*/ */
extern struct gadget *gadget_get_gadget(struct state *s, const char *name); extern struct gadget *usbg_get_gadget(struct state *s, const char *name);
/** /**
* @brief Get a function by name * @brief Get a function by name
@ -221,7 +221,7 @@ extern struct gadget *gadget_get_gadget(struct state *s, const char *name);
* @param name Name of the function * @param name Name of the function
* @return Pointer to function or NULL if a matching function isn't found * @return Pointer to function or NULL if a matching function isn't found
*/ */
extern struct function *gadget_get_function(struct gadget *g, const char *name); extern struct function *usbg_get_function(struct gadget *g, const char *name);
/** /**
* @brief Get a configuration by name * @brief Get a configuration by name
@ -229,7 +229,7 @@ extern struct function *gadget_get_function(struct gadget *g, const char *name);
* @param name Name of the configuration * @param name Name of the configuration
* @return Pointer to config or NULL if a matching config isn't found * @return Pointer to config or NULL if a matching config isn't found
*/ */
extern struct config *gadget_get_config(struct gadget *g, const char *name); extern struct config *usbg_get_config(struct gadget *g, const char *name);
/* USB gadget allocation and configuration */ /* USB gadget allocation and configuration */
@ -241,49 +241,49 @@ extern struct config *gadget_get_config(struct gadget *g, const char *name);
* @param product Gadget product ID * @param product Gadget product ID
* @return Pointer to gadget or NULL if the gadget cannot be created * @return Pointer to gadget or NULL if the gadget cannot be created
*/ */
extern struct gadget *gadget_create_gadget(struct state *s, char *name, int vendor, int product); extern struct gadget *usbg_create_gadget(struct state *s, char *name, int vendor, int product);
/** /**
* @brief Set the USB gadget device class code * @brief Set the USB gadget device class code
* @param g Pointer to gadget * @param g Pointer to gadget
* @param dclass USB device class code * @param dclass USB device class code
*/ */
extern void gadget_set_gadget_device_class(struct gadget *g, int dclass); extern void usbg_set_gadget_device_class(struct gadget *g, int dclass);
/** /**
* @brief Set the USB gadget protocol code * @brief Set the USB gadget protocol code
* @param g Pointer to gadget * @param g Pointer to gadget
* @param dprotocol USB protocol code * @param dprotocol USB protocol code
*/ */
extern void gadget_set_gadget_device_protocol(struct gadget *g, int dproto); extern void usbg_set_gadget_device_protocol(struct gadget *g, int dproto);
/** /**
* @brief Set the USB gadget device subclass code * @brief Set the USB gadget device subclass code
* @param g Pointer to gadget * @param g Pointer to gadget
* @param dsubclass USB device subclass code * @param dsubclass USB device subclass code
*/ */
extern void gadget_set_gadget_device_subclass(struct gadget *g, int dsubclass); extern void usbg_set_gadget_device_subclass(struct gadget *g, int dsubclass);
/** /**
* @brief Set the maximum packet size for a gadget * @brief Set the maximum packet size for a gadget
* @param g Pointer to gadget * @param g Pointer to gadget
* @param maxpacket Maximum packet size * @param maxpacket Maximum packet size
*/ */
extern void gadget_set_gadget_device_max_packet(struct gadget *g, int maxpacket); extern void usbg_set_gadget_device_max_packet(struct gadget *g, int maxpacket);
/** /**
* @brief Set the gadget device BCD release number * @brief Set the gadget device BCD release number
* @param g Pointer to gadget * @param g Pointer to gadget
* @param bcddevice BCD release number * @param bcddevice BCD release number
*/ */
extern void gadget_set_gadget_device_bcd_device(struct gadget *g, int bcddevice); extern void usbg_set_gadget_device_bcd_device(struct gadget *g, int bcddevice);
/** /**
* @brief Set the gadget device BCD USB version * @brief Set the gadget device BCD USB version
* @param g Pointer to gadget * @param g Pointer to gadget
* @param bcdusb BCD USB version * @param bcdusb BCD USB version
*/ */
extern void gadget_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb); extern void usbg_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb);
/** /**
* @brief Set the serial number for a gadget * @brief Set the serial number for a gadget
@ -291,7 +291,7 @@ extern void gadget_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb);
* @param lang USB language ID * @param lang USB language ID
* @param ser Serial number * @param ser Serial number
*/ */
extern void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *ser); extern void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *ser);
/** /**
* @brief Set the manufacturer name for a gadget * @brief Set the manufacturer name for a gadget
@ -299,7 +299,7 @@ extern void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *se
* @param lang USB language ID * @param lang USB language ID
* @param mnf Manufacturer * @param mnf Manufacturer
*/ */
extern void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf); extern void usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf);
/** /**
* @brief Set the product name for a gadget * @brief Set the product name for a gadget
@ -307,7 +307,7 @@ extern void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf
* @param lang USB language ID * @param lang USB language ID
* @param prd Product * @param prd Product
*/ */
extern void gadget_set_gadget_product(struct gadget *g, int lang, char *prd); extern void usbg_set_gadget_product(struct gadget *g, int lang, char *prd);
/* USB function allocation and configuration */ /* USB function allocation and configuration */
@ -318,7 +318,7 @@ extern void gadget_set_gadget_product(struct gadget *g, int lang, char *prd);
* @param instance Function instance name * @param instance Function instance name
* @return Pointer to function or NULL if it cannot be created * @return Pointer to function or NULL if it cannot be created
*/ */
extern struct function *gadget_create_function(struct gadget *g, enum function_type type, char *instance); extern struct function *usbg_create_function(struct gadget *g, enum function_type type, char *instance);
/* USB configurations allocation and configuration */ /* USB configurations allocation and configuration */
@ -328,21 +328,21 @@ extern struct function *gadget_create_function(struct gadget *g, enum function_t
* @param name Name of configuration * @param name Name of configuration
* @return Pointer to configuration or NULL if it cannot be created * @return Pointer to configuration or NULL if it cannot be created
*/ */
extern struct config *gadget_create_config(struct gadget *g, char *name); extern struct config *usbg_create_config(struct gadget *g, char *name);
/** /**
* @brief Set the configuration maximum power * @brief Set the configuration maximum power
* @param c Pointer to config * @param c Pointer to config
* @param maxpower Maximum power (in 2 mA units) * @param maxpower Maximum power (in 2 mA units)
*/ */
extern void gadget_set_config_max_power(struct config *c, int maxpower); extern void usbg_set_config_max_power(struct config *c, int maxpower);
/** /**
* @brief Set the configuration bitmap attributes * @brief Set the configuration bitmap attributes
* @param c Pointer to config * @param c Pointer to config
* @param bmattrs Configuration characteristics * @param bmattrs Configuration characteristics
*/ */
extern void gadget_set_config_bm_attrs(struct config *c, int bmattrs); extern void usbg_set_config_bm_attrs(struct config *c, int bmattrs);
/** /**
* @brief Set the configuration string * @brief Set the configuration string
@ -350,7 +350,7 @@ extern void gadget_set_config_bm_attrs(struct config *c, int bmattrs);
* @param lang USB language ID * @param lang USB language ID
* @param string Configuration description * @param string Configuration description
*/ */
extern void gadget_set_config_string(struct config *c, int lang, char *string); extern void usbg_set_config_string(struct config *c, int lang, char *string);
/** /**
* @brief Add a function to a configuration * @brief Add a function to a configuration
@ -359,7 +359,7 @@ extern void gadget_set_config_string(struct config *c, int lang, char *string);
* @param f Pointer to function * @param f Pointer to function
* @return 0 on success, -1 on failure. * @return 0 on success, -1 on failure.
*/ */
extern int gadget_add_config_function(struct config *c, char *name, struct function *f); extern int usbg_add_config_function(struct config *c, char *name, struct function *f);
/* USB gadget setup and teardown */ /* USB gadget setup and teardown */
@ -368,20 +368,20 @@ extern int gadget_add_config_function(struct config *c, char *name, struct funct
* @param udc_list Pointer to pointer to dirent pointer * @param udc_list Pointer to pointer to dirent pointer
* @return Number of UDC devices on success, -1 on failure * @return Number of UDC devices on success, -1 on failure
*/ */
extern int gadget_get_udcs(struct dirent ***udc_list); extern int usbg_get_udcs(struct dirent ***udc_list);
/** /**
* @brief Enable a USB gadget device * @brief Enable a USB gadget device
* @param g Pointer to gadget * @param g Pointer to gadget
* @param udc Name of UDC to enable gadget * @param udc Name of UDC to enable gadget
*/ */
extern void gadget_enable_gadget(struct gadget *g, char *udc); extern void usbg_enable_gadget(struct gadget *g, char *udc);
/** /**
* @brief Disable a USB gadget device * @brief Disable a USB gadget device
* @param g Pointer to gadget * @param g Pointer to gadget
*/ */
extern void gadget_disable_gadget(struct gadget *g); extern void usbg_disable_gadget(struct gadget *g);
/* /*
* USB function-specific attribute configuration * USB function-specific attribute configuration
@ -392,45 +392,45 @@ extern void gadget_disable_gadget(struct gadget *g);
* @param f Pointer to function * @param f Pointer to function
* @param addr Pointer to Ethernet address * @param addr Pointer to Ethernet address
*/ */
extern void gadget_set_net_dev_addr(struct function *f, struct ether_addr *addr); extern void usbg_set_net_dev_addr(struct function *f, struct ether_addr *addr);
/** /**
* @brief Set USB function network host address * @brief Set USB function network host address
* @param f Pointer to function * @param f Pointer to function
* @param addr Pointer to Ethernet address * @param addr Pointer to Ethernet address
*/ */
extern void gadget_set_net_host_addr(struct function *f, struct ether_addr *addr); extern void usbg_set_net_host_addr(struct function *f, struct ether_addr *addr);
/** /**
* @brief Set USB function network qmult * @brief Set USB function network qmult
* @param f Pointer to function * @param f Pointer to function
* @param qmult Queue length multiplier * @param qmult Queue length multiplier
*/ */
extern void gadget_set_net_qmult(struct function *f, int qmult); extern void usbg_set_net_qmult(struct function *f, int qmult);
/** /**
* @def gadget_for_each_gadget(g, s) * @def usbg_for_each_gadget(g, s)
* Iterates over each gadget * Iterates over each gadget
*/ */
#define gadget_for_each_gadget(g, s) TAILQ_FOREACH(g, &s->gadgets, gnode) #define usbg_for_each_gadget(g, s) TAILQ_FOREACH(g, &s->gadgets, gnode)
/** /**
* @def gadget_for_each_function(f, g) * @def usbg_for_each_function(f, g)
* Iterates over each function * Iterates over each function
*/ */
#define gadget_for_each_function(f, g) TAILQ_FOREACH(f, &g->functions, fnode) #define usbg_for_each_function(f, g) TAILQ_FOREACH(f, &g->functions, fnode)
/** /**
* @def gadget_for_each_config(c, g) * @def usbg_for_each_config(c, g)
* Iterates over each config * Iterates over each config
*/ */
#define gadget_for_each_config(c, g) TAILQ_FOREACH(c, &g->configs, cnode) #define usbg_for_each_config(c, g) TAILQ_FOREACH(c, &g->configs, cnode)
/** /**
* @def gadget_for_each_binding(b, c) * @def usbg_for_each_binding(b, c)
* Iterates over each binding * Iterates over each binding
*/ */
#define gadget_for_each_binding(b, c) TAILQ_FOREACH(b, &c->bindings, bnode) #define usbg_for_each_binding(b, c) TAILQ_FOREACH(b, &c->bindings, bnode)
/** /**
* @} * @}

View file

@ -3,9 +3,9 @@ exec_prefix=@exec_prefix@
libdir=@libdir@ libdir=@libdir@
includedir=@includedir@ includedir=@includedir@
Name: libgadget Name: libusbg
Description: USB gadget-configfs library Description: USB gadget-configfs library
Requires: Requires:
Version: @PACKAGE_VERSION@ Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lgadget Libs: -L${libdir} -lusbg
Cflags: -I${includedir} Cflags: -I${includedir}

View file

@ -1,4 +1,4 @@
lib_LTLIBRARIES = libgadget.la lib_LTLIBRARIES = libusbg.la
libgadget_la_SOURCES = gadget.c libusbg_la_SOURCES = usbg.c
libgadget_la_LDFLAGS = -version-info 0:1:0 libusbg_la_LDFLAGS = -version-info 0:1:0
AM_CPPFLAGS=-I../include/ AM_CPPFLAGS=-I../include/

View file

@ -16,7 +16,7 @@
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <gadget/gadget.h> #include <usbg/usbg.h>
#include <netinet/ether.h> #include <netinet/ether.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -27,7 +27,7 @@
#include <unistd.h> #include <unistd.h>
/** /**
* @file gadget.c * @file usbg.c
* @todo Handle buffer overflows * @todo Handle buffer overflows
* @todo Error checking and return code propagation * @todo Error checking and return code propagation
*/ */
@ -44,7 +44,7 @@
__func__, strerror(errno), ##__VA_ARGS__);\ __func__, strerror(errno), ##__VA_ARGS__);\
} while (0) } while (0)
static int gadget_lookup_function_type(char *name) static int usbg_lookup_function_type(char *name)
{ {
int i = 0; int i = 0;
int max = sizeof(function_names)/sizeof(char *); int max = sizeof(function_names)/sizeof(char *);
@ -80,7 +80,7 @@ static int file_select(const struct dirent *dent)
return 1; return 1;
} }
static char *gadget_read_buf(char *path, char *name, char *file, char *buf) static char *usbg_read_buf(char *path, char *name, char *file, char *buf)
{ {
char p[256]; char p[256];
FILE *fp; FILE *fp;
@ -100,30 +100,30 @@ out:
return ret; return ret;
} }
static int gadget_read_int(char *path, char *name, char *file, int base) static int usbg_read_int(char *path, char *name, char *file, int base)
{ {
char buf[256]; char buf[256];
if (gadget_read_buf(path, name, file, buf)) if (usbg_read_buf(path, name, file, buf))
return strtol(buf, NULL, base); return strtol(buf, NULL, base);
else else
return 0; return 0;
} }
#define gadget_read_dec(p, n, f) gadget_read_int(p, n, f, 10) #define usbg_read_dec(p, n, f) usbg_read_int(p, n, f, 10)
#define gadget_read_hex(p, n, f) gadget_read_int(p, n, f, 16) #define usbg_read_hex(p, n, f) usbg_read_int(p, n, f, 16)
static void gadget_read_string(char *path, char *name, char *file, char *buf) static void usbg_read_string(char *path, char *name, char *file, char *buf)
{ {
char *p; char *p;
gadget_read_buf(path, name, file, buf); usbg_read_buf(path, name, file, buf);
if ((p = strchr(buf, '\n')) != NULL) if ((p = strchr(buf, '\n')) != NULL)
*p = '\0'; *p = '\0';
} }
static void gadget_write_buf(char *path, char *name, char *file, char *buf) static void usbg_write_buf(char *path, char *name, char *file, char *buf)
{ {
char p[256]; char p[256];
FILE *fp; FILE *fp;
@ -141,24 +141,24 @@ static void gadget_write_buf(char *path, char *name, char *file, char *buf)
fclose(fp); fclose(fp);
} }
static void gadget_write_int(char *path, char *name, char *file, int value, char *str) static void usbg_write_int(char *path, char *name, char *file, int value, char *str)
{ {
char buf[256]; char buf[256];
sprintf(buf, str, value); sprintf(buf, str, value);
gadget_write_buf(path, name, file, buf); usbg_write_buf(path, name, file, buf);
} }
#define gadget_write_dec(p, n, f, v) gadget_write_int(p, n, f, v, "%d\n") #define usbg_write_dec(p, n, f, v) usbg_write_int(p, n, f, v, "%d\n")
#define gadget_write_hex16(p, n, f, v) gadget_write_int(p, n, f, v, "0x%04x\n") #define usbg_write_hex16(p, n, f, v) usbg_write_int(p, n, f, v, "0x%04x\n")
#define gadget_write_hex8(p, n, f, v) gadget_write_int(p, n, f, v, "0x%02x\n") #define usbg_write_hex8(p, n, f, v) usbg_write_int(p, n, f, v, "0x%02x\n")
static void gadget_write_string(char *path, char *name, char *file, char *buf) static void usbg_write_string(char *path, char *name, char *file, char *buf)
{ {
gadget_write_buf(path, name, file, buf); usbg_write_buf(path, name, file, buf);
} }
static void gadget_parse_function_attrs(struct function *f) static void usbg_parse_function_attrs(struct function *f)
{ {
struct ether_addr *addr; struct ether_addr *addr;
char str_addr[40]; char str_addr[40];
@ -167,31 +167,31 @@ static void gadget_parse_function_attrs(struct function *f)
case F_SERIAL: case F_SERIAL:
case F_ACM: case F_ACM:
case F_OBEX: case F_OBEX:
f->attr.serial.port_num = gadget_read_dec(f->path, f->name, "port_num"); f->attr.serial.port_num = usbg_read_dec(f->path, f->name, "port_num");
break; break;
case F_ECM: case F_ECM:
case F_SUBSET: case F_SUBSET:
case F_NCM: case F_NCM:
case F_EEM: case F_EEM:
case F_RNDIS: case F_RNDIS:
gadget_read_string(f->path, f->name, "dev_addr", str_addr); usbg_read_string(f->path, f->name, "dev_addr", str_addr);
addr = ether_aton(str_addr); addr = ether_aton(str_addr);
memcpy(&f->attr.net.dev_addr, addr, 6); memcpy(&f->attr.net.dev_addr, addr, 6);
gadget_read_string(f->path, f->name, "host_addr", str_addr); usbg_read_string(f->path, f->name, "host_addr", str_addr);
addr = ether_aton(str_addr); addr = ether_aton(str_addr);
memcpy(&f->attr.net.host_addr, addr, 6); memcpy(&f->attr.net.host_addr, addr, 6);
gadget_read_string(f->path, f->name, "ifname", f->attr.net.ifname); usbg_read_string(f->path, f->name, "ifname", f->attr.net.ifname);
f->attr.net.qmult = gadget_read_dec(f->path, f->name, "qmult"); f->attr.net.qmult = usbg_read_dec(f->path, f->name, "qmult");
break; break;
case F_PHONET: case F_PHONET:
gadget_read_string(f->path, f->name, "ifname", f->attr.phonet.ifname); usbg_read_string(f->path, f->name, "ifname", f->attr.phonet.ifname);
break; break;
default: default:
ERROR("Unsupported function type\n"); ERROR("Unsupported function type\n");
} }
} }
static int gadget_parse_functions(char *path, struct gadget *g) static int usbg_parse_functions(char *path, struct gadget *g)
{ {
struct function *f; struct function *f;
int i, n; int i, n;
@ -208,22 +208,22 @@ static int gadget_parse_functions(char *path, struct gadget *g)
f->parent = g; f->parent = g;
strcpy(f->name, dent[i]->d_name); strcpy(f->name, dent[i]->d_name);
strcpy(f->path, fpath); strcpy(f->path, fpath);
f->type = gadget_lookup_function_type(strtok(dent[i]->d_name, ".")); f->type = usbg_lookup_function_type(strtok(dent[i]->d_name, "."));
gadget_parse_function_attrs(f); usbg_parse_function_attrs(f);
TAILQ_INSERT_TAIL(&g->functions, f, fnode); TAILQ_INSERT_TAIL(&g->functions, f, fnode);
free(dent[i]); free(dent[i]);
} }
free(dent); free(dent);
} }
static void gadget_parse_config_attrs(struct config *c) static void usbg_parse_config_attrs(struct config *c)
{ {
c->maxpower = gadget_read_dec(c->path, c->name, "MaxPower"); c->maxpower = usbg_read_dec(c->path, c->name, "MaxPower");
c->bmattrs = gadget_read_hex(c->path, c->name, "bmAttributes"); c->bmattrs = usbg_read_hex(c->path, c->name, "bmAttributes");
gadget_read_string(c->path, c->name, "strings/0x409/configuration", c->str_cfg); usbg_read_string(c->path, c->name, "strings/0x409/configuration", c->str_cfg);
} }
static void gadget_parse_config_bindings(struct config *c) static void usbg_parse_config_bindings(struct config *c)
{ {
int i, n; int i, n;
struct dirent **dent; struct dirent **dent;
@ -263,7 +263,7 @@ static void gadget_parse_config_bindings(struct config *c)
free(dent); free(dent);
} }
static int gadget_parse_configs(char *path, struct gadget *g) static int usbg_parse_configs(char *path, struct gadget *g)
{ {
struct config *c; struct config *c;
int i, n; int i, n;
@ -280,36 +280,36 @@ static int gadget_parse_configs(char *path, struct gadget *g)
c->parent = g; c->parent = g;
strcpy(c->name, dent[i]->d_name); strcpy(c->name, dent[i]->d_name);
strcpy(c->path, cpath); strcpy(c->path, cpath);
gadget_parse_config_attrs(c); usbg_parse_config_attrs(c);
gadget_parse_config_bindings(c); usbg_parse_config_bindings(c);
TAILQ_INSERT_TAIL(&g->configs, c, cnode); TAILQ_INSERT_TAIL(&g->configs, c, cnode);
free(dent[i]); free(dent[i]);
} }
free(dent); free(dent);
} }
static void gadget_parse_attrs(char *path, struct gadget *g) static void usbg_parse_attrs(char *path, struct gadget *g)
{ {
/* UDC bound to, if any */ /* UDC bound to, if any */
gadget_read_string(path, g->name, "UDC", g->udc); usbg_read_string(path, g->name, "UDC", g->udc);
/* Actual attributes */ /* Actual attributes */
g->dclass = gadget_read_hex(path, g->name, "bDeviceClass"); g->dclass = usbg_read_hex(path, g->name, "bDeviceClass");
g->dsubclass = gadget_read_hex(path, g->name, "bDeviceSubClass"); g->dsubclass = usbg_read_hex(path, g->name, "bDeviceSubClass");
g->dproto = gadget_read_hex(path, g->name, "bDeviceProtocol"); g->dproto = usbg_read_hex(path, g->name, "bDeviceProtocol");
g->maxpacket = gadget_read_hex(path, g->name, "bMaxPacketSize0"); g->maxpacket = usbg_read_hex(path, g->name, "bMaxPacketSize0");
g->bcddevice = gadget_read_hex(path, g->name, "bcdDevice"); g->bcddevice = usbg_read_hex(path, g->name, "bcdDevice");
g->bcdusb = gadget_read_hex(path, g->name, "bcdUSB"); g->bcdusb = usbg_read_hex(path, g->name, "bcdUSB");
g->vendor = gadget_read_hex(path, g->name, "idVendor"); g->vendor = usbg_read_hex(path, g->name, "idVendor");
g->product = gadget_read_hex(path, g->name, "idProduct"); g->product = usbg_read_hex(path, g->name, "idProduct");
/* Strings - hardcoded to U.S. English only for now */ /* Strings - hardcoded to U.S. English only for now */
gadget_read_string(path, g->name, "strings/0x409/serialnumber", g->str_ser); usbg_read_string(path, g->name, "strings/0x409/serialnumber", g->str_ser);
gadget_read_string(path, g->name, "strings/0x409/manufacturer", g->str_mnf); usbg_read_string(path, g->name, "strings/0x409/manufacturer", g->str_mnf);
gadget_read_string(path, g->name, "strings/0x409/product", g->str_prd); usbg_read_string(path, g->name, "strings/0x409/product", g->str_prd);
} }
static int gadget_parse_gadgets(char *path, struct state *s) static int usbg_parse_gadgets(char *path, struct state *s)
{ {
struct gadget *g; struct gadget *g;
int i, n; int i, n;
@ -323,9 +323,9 @@ static int gadget_parse_gadgets(char *path, struct state *s)
strcpy(g->name, dent[i]->d_name); strcpy(g->name, dent[i]->d_name);
strcpy(g->path, s->path); strcpy(g->path, s->path);
g->parent = s; g->parent = s;
gadget_parse_attrs(path, g); usbg_parse_attrs(path, g);
gadget_parse_functions(path, g); usbg_parse_functions(path, g);
gadget_parse_configs(path, g); usbg_parse_configs(path, g);
TAILQ_INSERT_TAIL(&s->gadgets, g, gnode); TAILQ_INSERT_TAIL(&s->gadgets, g, gnode);
free(dent[i]); free(dent[i]);
} }
@ -334,11 +334,11 @@ static int gadget_parse_gadgets(char *path, struct state *s)
return 0; return 0;
} }
static int gadget_init_state(char *path, struct state *s) static int usbg_init_state(char *path, struct state *s)
{ {
strcpy(s->path, path); strcpy(s->path, path);
if (gadget_parse_gadgets(path, s) < 0) { if (usbg_parse_gadgets(path, s) < 0) {
ERRORNO("unable to parse %s\n", path); ERRORNO("unable to parse %s\n", path);
return -1; return -1;
} }
@ -350,7 +350,7 @@ static int gadget_init_state(char *path, struct state *s)
* User API * User API
*/ */
struct state *gadget_init(char *configfs_path) struct state *usbg_init(char *configfs_path)
{ {
int ret; int ret;
struct stat sts; struct stat sts;
@ -371,7 +371,7 @@ struct state *gadget_init(char *configfs_path)
s = malloc(sizeof(struct state)); s = malloc(sizeof(struct state));
if (s) if (s)
gadget_init_state(path, s); usbg_init_state(path, s);
else else
ERRORNO("couldn't init gadget state\n"); ERRORNO("couldn't init gadget state\n");
@ -379,7 +379,7 @@ out:
return s; return s;
} }
void gadget_cleanup(struct state *s) void usbg_cleanup(struct state *s)
{ {
struct gadget *g; struct gadget *g;
struct config *c; struct config *c;
@ -410,7 +410,7 @@ void gadget_cleanup(struct state *s)
free(s); free(s);
} }
struct gadget *gadget_get_gadget(struct state *s, const char *name) struct gadget *usbg_get_gadget(struct state *s, const char *name)
{ {
struct gadget *g; struct gadget *g;
@ -421,7 +421,7 @@ struct gadget *gadget_get_gadget(struct state *s, const char *name)
return NULL; return NULL;
} }
struct function *gadget_get_function(struct gadget *g, const char *name) struct function *usbg_get_function(struct gadget *g, const char *name)
{ {
struct function *f; struct function *f;
@ -432,7 +432,7 @@ struct function *gadget_get_function(struct gadget *g, const char *name)
return NULL; return NULL;
} }
struct config *gadget_get_config(struct gadget *g, const char *name) struct config *usbg_get_config(struct gadget *g, const char *name)
{ {
struct config *c; struct config *c;
@ -443,7 +443,7 @@ struct config *gadget_get_config(struct gadget *g, const char *name)
return NULL; return NULL;
} }
struct binding *gadget_get_binding(struct config *c, const char *name) struct binding *usbg_get_binding(struct config *c, const char *name)
{ {
struct binding *b; struct binding *b;
@ -454,7 +454,7 @@ struct binding *gadget_get_binding(struct config *c, const char *name)
return NULL; return NULL;
} }
struct binding *gadget_get_link_binding(struct config *c, struct function *f) struct binding *usbg_get_link_binding(struct config *c, struct function *f)
{ {
struct binding *b; struct binding *b;
@ -465,7 +465,7 @@ struct binding *gadget_get_link_binding(struct config *c, struct function *f)
return NULL; return NULL;
} }
struct gadget *gadget_create_gadget(struct state *s, char *name, struct gadget *usbg_create_gadget(struct state *s, char *name,
int vendor, int product) int vendor, int product)
{ {
char gpath[256]; char gpath[256];
@ -475,7 +475,7 @@ struct gadget *gadget_create_gadget(struct state *s, char *name,
if (!s) if (!s)
return NULL; return NULL;
g = gadget_get_gadget(s, name); g = usbg_get_gadget(s, name);
if (g) { if (g) {
ERROR("duplicate gadget name\n"); ERROR("duplicate gadget name\n");
return NULL; return NULL;
@ -503,8 +503,8 @@ struct gadget *gadget_create_gadget(struct state *s, char *name,
g->vendor = vendor; g->vendor = vendor;
g->product = product; g->product = product;
gadget_write_hex16(s->path, name, "idVendor", vendor); usbg_write_hex16(s->path, name, "idVendor", vendor);
gadget_write_hex16(s->path, name, "idProduct", product); usbg_write_hex16(s->path, name, "idProduct", product);
/* Insert in string order */ /* Insert in string order */
if (TAILQ_EMPTY(&s->gadgets) || if (TAILQ_EMPTY(&s->gadgets) ||
@ -522,43 +522,43 @@ struct gadget *gadget_create_gadget(struct state *s, char *name,
return g; return g;
} }
void gadget_set_gadget_device_class(struct gadget *g, int dclass) void usbg_set_gadget_device_class(struct gadget *g, int dclass)
{ {
g->dclass = dclass; g->dclass = dclass;
gadget_write_hex8(g->path, "", "bDeviceClass", dclass); usbg_write_hex8(g->path, "", "bDeviceClass", dclass);
} }
void gadget_set_gadget_device_protocol(struct gadget *g, int dproto) void usbg_set_gadget_device_protocol(struct gadget *g, int dproto)
{ {
g->dproto = dproto; g->dproto = dproto;
gadget_write_hex8(g->path, "", "bDeviceProtocol", dproto); usbg_write_hex8(g->path, "", "bDeviceProtocol", dproto);
} }
void gadget_set_gadget_device_subclass(struct gadget *g, int dsubclass) void usbg_set_gadget_device_subclass(struct gadget *g, int dsubclass)
{ {
g->dsubclass = dsubclass; g->dsubclass = dsubclass;
gadget_write_hex8(g->path, "", "bDeviceSubClass", dsubclass); usbg_write_hex8(g->path, "", "bDeviceSubClass", dsubclass);
} }
void gadget_set_gadget_device_max_packet(struct gadget *g, int maxpacket) void usbg_set_gadget_device_max_packet(struct gadget *g, int maxpacket)
{ {
g->maxpacket = maxpacket; g->maxpacket = maxpacket;
gadget_write_hex8(g->path, "", "bMaxPacketSize0", maxpacket); usbg_write_hex8(g->path, "", "bMaxPacketSize0", maxpacket);
} }
void gadget_set_gadget_device_bcd_device(struct gadget *g, int bcddevice) void usbg_set_gadget_device_bcd_device(struct gadget *g, int bcddevice)
{ {
g->bcddevice = bcddevice; g->bcddevice = bcddevice;
gadget_write_hex16(g->path, "", "bcdDevice", bcddevice); usbg_write_hex16(g->path, "", "bcdDevice", bcddevice);
} }
void gadget_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb) void usbg_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb)
{ {
g->bcdusb = bcdusb; g->bcdusb = bcdusb;
gadget_write_hex16(g->path, "", "bcdUSB", bcdusb); usbg_write_hex16(g->path, "", "bcdUSB", bcdusb);
} }
void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *serno) void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno)
{ {
char path[256]; char path[256];
@ -568,10 +568,10 @@ void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *serno)
strcpy(g->str_ser, serno); strcpy(g->str_ser, serno);
gadget_write_string(path, "", "serialnumber", serno); usbg_write_string(path, "", "serialnumber", serno);
} }
void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf) void usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf)
{ {
char path[256]; char path[256];
@ -581,10 +581,10 @@ void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf)
strcpy(g->str_mnf, mnf); strcpy(g->str_mnf, mnf);
gadget_write_string(path, "", "manufacturer", mnf); usbg_write_string(path, "", "manufacturer", mnf);
} }
void gadget_set_gadget_product(struct gadget *g, int lang, char *prd) void usbg_set_gadget_product(struct gadget *g, int lang, char *prd)
{ {
char path[256]; char path[256];
@ -594,10 +594,10 @@ void gadget_set_gadget_product(struct gadget *g, int lang, char *prd)
strcpy(g->str_prd, prd); strcpy(g->str_prd, prd);
gadget_write_string(path, "", "product", prd); usbg_write_string(path, "", "product", prd);
} }
struct function *gadget_create_function(struct gadget *g, enum function_type type, char *instance) struct function *usbg_create_function(struct gadget *g, enum function_type type, char *instance)
{ {
char fpath[256]; char fpath[256];
char name[256]; char name[256];
@ -611,7 +611,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
* @todo Check for legal function type * @todo Check for legal function type
*/ */
sprintf(name, "%s.%s", function_names[type], instance); sprintf(name, "%s.%s", function_names[type], instance);
f = gadget_get_function(g, name); f = usbg_get_function(g, name);
if (f) { if (f) {
ERROR("duplicate function name\n"); ERROR("duplicate function name\n");
return NULL; return NULL;
@ -635,7 +635,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
sprintf(f->path, "%s/%s/%s", g->path, g->name, "functions"); sprintf(f->path, "%s/%s/%s", g->path, g->name, "functions");
f->type = type; f->type = type;
gadget_parse_function_attrs(f); usbg_parse_function_attrs(f);
/* Insert in string order */ /* Insert in string order */
if (TAILQ_EMPTY(&g->functions) || if (TAILQ_EMPTY(&g->functions) ||
@ -653,7 +653,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
return f; return f;
} }
struct config *gadget_create_config(struct gadget *g, char *name) struct config *usbg_create_config(struct gadget *g, char *name)
{ {
char cpath[256]; char cpath[256];
struct config *c, *cur; struct config *c, *cur;
@ -665,7 +665,7 @@ struct config *gadget_create_config(struct gadget *g, char *name)
/** /**
* @todo Check for legal configuration name * @todo Check for legal configuration name
*/ */
c = gadget_get_config(g, name); c = usbg_get_config(g, name);
if (c) { if (c) {
ERROR("duplicate configuration name\n"); ERROR("duplicate configuration name\n");
return NULL; return NULL;
@ -705,19 +705,19 @@ struct config *gadget_create_config(struct gadget *g, char *name)
return c; return c;
} }
void gadget_set_config_max_power(struct config *c, int maxpower) void usbg_set_config_max_power(struct config *c, int maxpower)
{ {
c->maxpower = maxpower; c->maxpower = maxpower;
gadget_write_dec(c->path, c->name, "MaxPower", maxpower); usbg_write_dec(c->path, c->name, "MaxPower", maxpower);
} }
void gadget_set_config_bm_attrs(struct config *c, int bmattrs) void usbg_set_config_bm_attrs(struct config *c, int bmattrs)
{ {
c->bmattrs = bmattrs; c->bmattrs = bmattrs;
gadget_write_hex8(c->path, c->name, "bmAttributes", bmattrs); usbg_write_hex8(c->path, c->name, "bmAttributes", bmattrs);
} }
void gadget_set_config_string(struct config *c, int lang, char *str) void usbg_set_config_string(struct config *c, int lang, char *str)
{ {
char path[256]; char path[256];
@ -727,10 +727,10 @@ void gadget_set_config_string(struct config *c, int lang, char *str)
strcpy(c->str_cfg, str); strcpy(c->str_cfg, str);
gadget_write_string(path, "", "configuration", str); usbg_write_string(path, "", "configuration", str);
} }
int gadget_add_config_function(struct config *c, char *name, struct function *f) int usbg_add_config_function(struct config *c, char *name, struct function *f)
{ {
char bpath[256]; char bpath[256];
char fpath[256]; char fpath[256];
@ -741,13 +741,13 @@ int gadget_add_config_function(struct config *c, char *name, struct function *f)
if (!c || !f) if (!c || !f)
return ret; return ret;
b = gadget_get_binding(c, name); b = usbg_get_binding(c, name);
if (b) { if (b) {
ERROR("duplicate binding name\n"); ERROR("duplicate binding name\n");
return ret; return ret;
} }
b = gadget_get_link_binding(c, f); b = usbg_get_link_binding(c, f);
if (b) { if (b) {
ERROR("duplicate binding link\n"); ERROR("duplicate binding link\n");
return ret; return ret;
@ -788,19 +788,19 @@ int gadget_add_config_function(struct config *c, char *name, struct function *f)
return 0; return 0;
} }
int gadget_get_udcs(struct dirent ***udc_list) int usbg_get_udcs(struct dirent ***udc_list)
{ {
return scandir("/sys/class/udc", udc_list, file_select, alphasort); return scandir("/sys/class/udc", udc_list, file_select, alphasort);
} }
void gadget_enable_gadget(struct gadget *g, char *udc) void usbg_enable_gadget(struct gadget *g, char *udc)
{ {
char gudc[256]; char gudc[256];
struct dirent **udc_list; struct dirent **udc_list;
int n; int n;
if (!udc) { if (!udc) {
n = gadget_get_udcs(&udc_list); n = usbg_get_udcs(&udc_list);
if (!n) if (!n)
return; return;
strcpy(gudc, udc_list[0]->d_name); strcpy(gudc, udc_list[0]->d_name);
@ -811,41 +811,41 @@ void gadget_enable_gadget(struct gadget *g, char *udc)
strcpy (gudc, udc); strcpy (gudc, udc);
strcpy(g->udc, gudc); strcpy(g->udc, gudc);
gadget_write_string(g->path, g->name, "UDC", gudc); usbg_write_string(g->path, g->name, "UDC", gudc);
} }
void gadget_disable_gadget(struct gadget *g) void usbg_disable_gadget(struct gadget *g)
{ {
strcpy(g->udc, ""); strcpy(g->udc, "");
gadget_write_string(g->path, g->name, "UDC", ""); usbg_write_string(g->path, g->name, "UDC", "");
} }
/* /*
* USB function-specific attribute configuration * USB function-specific attribute configuration
*/ */
void gadget_set_net_dev_addr(struct function *f, struct ether_addr *dev_addr) void usbg_set_net_dev_addr(struct function *f, struct ether_addr *dev_addr)
{ {
char *str_addr; char *str_addr;
memcpy(&f->attr.net.dev_addr, dev_addr, 6); memcpy(&f->attr.net.dev_addr, dev_addr, 6);
str_addr = ether_ntoa(dev_addr); str_addr = ether_ntoa(dev_addr);
gadget_write_string(f->path, f->name, "dev_addr", str_addr); usbg_write_string(f->path, f->name, "dev_addr", str_addr);
} }
void gadget_set_net_host_addr(struct function *f, struct ether_addr *host_addr) void usbg_set_net_host_addr(struct function *f, struct ether_addr *host_addr)
{ {
char *str_addr; char *str_addr;
memcpy(&f->attr.net.host_addr, host_addr, 6); memcpy(&f->attr.net.host_addr, host_addr, 6);
str_addr = ether_ntoa(host_addr); str_addr = ether_ntoa(host_addr);
gadget_write_string(f->path, f->name, "host_addr", str_addr); usbg_write_string(f->path, f->name, "host_addr", str_addr);
} }
void gadget_set_net_qmult(struct function *f, int qmult) void usbg_set_net_qmult(struct function *f, int qmult)
{ {
f->attr.net.qmult = qmult; f->attr.net.qmult = qmult;
gadget_write_dec(f->path, f->name, "qmult", qmult); usbg_write_dec(f->path, f->name, "qmult", qmult);
} }