summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Porter <mporter@linaro.org>2014-01-04 15:23:14 -0500
committerMatt Porter <mporter@linaro.org>2014-01-21 07:58:24 -0500
commita371518d64ba444d46e2b9d23a8d78f63aae3bbf (patch)
treef1edca88d0ea6f936d9d241dcc91933725c0dbca
parent8b074b73d1c31ae59b572bdf1c2cafce3a9c6f02 (diff)
downloadlibusbg-a371518d64ba444d46e2b9d23a8d78f63aae3bbf.tar.gz
libusbg-a371518d64ba444d46e2b9d23a8d78f63aae3bbf.tar.bz2
libusbg-a371518d64ba444d46e2b9d23a8d78f63aae3bbf.zip
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>
-rw-r--r--INSTALL2
-rw-r--r--Makefile.am6
-rw-r--r--README6
-rw-r--r--configure.ac4
-rw-r--r--doxygen.cfg2
-rw-r--r--examples/Makefile.am2
-rw-r--r--examples/gadget-acm-ecm.c32
-rw-r--r--examples/show-gadgets.c14
-rw-r--r--include/usbg/usbg.h (renamed from include/gadget/gadget.h)80
-rw-r--r--libusbg.pc.in (renamed from libgadget.pc.in)4
-rw-r--r--src/Makefile.am6
-rw-r--r--src/usbg.c (renamed from src/gadget.c)222
12 files changed, 190 insertions, 190 deletions
diff --git a/INSTALL b/INSTALL
index fef58f8..786ecee 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,4 +1,4 @@
-Installing libgadget:
+Installing libusbg:
$ autoreconf -i
$ ./configure
diff --git a/Makefile.am b/Makefile.am
index 7290d21..5fc3cd6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ include $(top_srcdir)/aminclude.am
SUBDIRS = src examples
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = doxygen.cfg
-library_includedir=$(includedir)/gadget
-library_include_HEADERS = include/gadget/gadget.h
+library_includedir=$(includedir)/usbg
+library_include_HEADERS = include/usbg/usbg.h
pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libgadget.pc
+pkgconfig_DATA = libusbg.pc
diff --git a/README b/README
index 353cd90..38e388d 100644
--- a/README
+++ b/README
@@ -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.
It provides routines for creating and parsing USB gadget devices using
diff --git a/configure.ac b/configure.ac
index bdff17a..7b2132a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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])
AC_PROG_CC
AM_PROG_AR
AC_CONFIG_MACRO_DIR([m4])
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])
AC_OUTPUT
diff --git a/doxygen.cfg b/doxygen.cfg
index c4fd608..4d7a5d8 100644
--- a/doxygen.cfg
+++ b/doxygen.cfg
@@ -648,7 +648,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# 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
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
diff --git a/examples/Makefile.am b/examples/Makefile.am
index eb98bdc..f9f9407 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -2,4 +2,4 @@ bin_PROGRAMS = show-gadgets gadget-acm-ecm
gadget_acm_ecm_SOURCES = gadget-acm-ecm.c
show_gadgets_SOURCES = show-gadgets.c
AM_CPPFLAGS=-I../include/
-AM_LDFLAGS=-L../src/ -lgadget
+AM_LDFLAGS=-L../src/ -lusbg
diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index e33ee06..ea11599 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -16,7 +16,7 @@
#include <errno.h>
#include <stdio.h>
-#include <gadget/gadget.h>
+#include <usbg/usbg.h>
/**
* @file gadget-acm-ecm.c
@@ -36,55 +36,55 @@ int main(void)
struct function *f_acm0, *f_acm1, *f_ecm;
int ret = -EINVAL;
- s = gadget_init("/config");
+ s = usbg_init("/config");
if (!s) {
fprintf(stderr, "Error on USB gadget init\n");
goto error1;
}
- g = gadget_create_gadget(s, "g1", VENDOR, PRODUCT);
+ g = usbg_create_gadget(s, "g1", VENDOR, PRODUCT);
if (!g) {
fprintf(stderr, "Error on create gadget\n");
goto error2;
}
- gadget_set_gadget_serial_number(g, LANG_US_ENG, "0123456789");
- gadget_set_gadget_manufacturer(g, LANG_US_ENG, "Foo Inc.");
- gadget_set_gadget_product(g, LANG_US_ENG, "Bar Gadget");
+ usbg_set_gadget_serial_number(g, LANG_US_ENG, "0123456789");
+ usbg_set_gadget_manufacturer(g, LANG_US_ENG, "Foo Inc.");
+ 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) {
fprintf(stderr, "Error creating acm0 function\n");
goto error2;
}
- f_acm1 = gadget_create_function(g, F_ACM, "usb1");
+ f_acm1 = usbg_create_function(g, F_ACM, "usb1");
if (!f_acm1) {
fprintf(stderr, "Error creating acm1 function\n");
goto error2;
}
- f_ecm = gadget_create_function(g, F_ECM, "usb0");
+ f_ecm = usbg_create_function(g, F_ECM, "usb0");
if (!f_ecm) {
fprintf(stderr, "Error creating ecm function\n");
goto error2;
}
- c = gadget_create_config(g, "c.1");
+ c = usbg_create_config(g, "c.1");
if (!c) {
fprintf(stderr, "Error creating config\n");
goto error2;
}
- gadget_set_config_string(c, LANG_US_ENG, "CDC 2xACM+ECM");
- gadget_add_config_function(c, "acm.GS0", f_acm0);
- gadget_add_config_function(c, "acm.GS1", f_acm1);
- gadget_add_config_function(c, "ecm.usb0", f_ecm);
+ usbg_set_config_string(c, LANG_US_ENG, "CDC 2xACM+ECM");
+ usbg_add_config_function(c, "acm.GS0", f_acm0);
+ usbg_add_config_function(c, "acm.GS1", f_acm1);
+ usbg_add_config_function(c, "ecm.usb0", f_ecm);
- gadget_enable_gadget(g, DEFAULT_UDC);
+ usbg_enable_gadget(g, DEFAULT_UDC);
return 0;
error2:
- gadget_cleanup(s);
+ usbg_cleanup(s);
error1:
return -EINVAL;
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index a7e20aa..a0fc1e3 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -17,8 +17,8 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <gadget/gadget.h>
#include <netinet/ether.h>
+#include <usbg/usbg.h>
/**
* @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, " bmAttributes\t0x%02x\n", c->bmattrs);
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);
}
@@ -96,21 +96,21 @@ int main(void)
struct binding *b;
struct function *f_acm0, *f_acm1, *f_ecm;
- s = gadget_init("/config");
+ s = usbg_init("/config");
if (!s) {
fprintf(stderr, "Error on USB gadget init\n");
return -EINVAL;
}
- gadget_for_each_gadget(g, s) {
+ usbg_for_each_gadget(g, s) {
show_gadget(g);
- gadget_for_each_function(f, g)
+ usbg_for_each_function(f, g)
show_function(f);
- gadget_for_each_config(c, g)
+ usbg_for_each_config(c, g)
show_config(c);
}
- gadget_cleanup(s);
+ usbg_cleanup(s);
return 0;
}
diff --git a/include/gadget/gadget.h b/include/usbg/usbg.h
index 6a32c39..641e520 100644
--- a/include/gadget/gadget.h
+++ b/include/usbg/usbg.h
@@ -19,13 +19,13 @@
#include <netinet/ether.h>
/**
- * @file include/gadget/gadget.h
- * @todo Add gadget_remove_[gadget|config|function|binding] APIs
+ * @file include/usbg/usbg.h
+ * @todo Add usbg_remove_[gadget|config|function|binding] APIs
* @todo Clean up static buffers in structures
*/
/**
- * @addtogroup libgadget
+ * @addtogroup libusbg
* Public API for USB gadget-configfs library
* @{
*/
@@ -193,17 +193,17 @@ struct binding
/* 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
* @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
*/
-extern void gadget_cleanup(struct state *s);
+extern void usbg_cleanup(struct state *s);
/* USB gadget queries */
@@ -213,7 +213,7 @@ extern void gadget_cleanup(struct state *s);
* @param name Name of the gadget device
* @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
@@ -221,7 +221,7 @@ extern struct gadget *gadget_get_gadget(struct state *s, const char *name);
* @param name Name of the function
* @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
@@ -229,7 +229,7 @@ extern struct function *gadget_get_function(struct gadget *g, const char *name);
* @param name Name of the configuration
* @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 */
@@ -241,49 +241,49 @@ extern struct config *gadget_get_config(struct gadget *g, const char *name);
* @param product Gadget product ID
* @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
* @param g Pointer to gadget
* @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
* @param g Pointer to gadget
* @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
* @param g Pointer to gadget
* @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
* @param g Pointer to gadget
* @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
* @param g Pointer to gadget
* @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
* @param g Pointer to gadget
* @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
@@ -291,7 +291,7 @@ extern void gadget_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb);
* @param lang USB language ID
* @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
@@ -299,7 +299,7 @@ extern void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *se
* @param lang USB language ID
* @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
@@ -307,7 +307,7 @@ extern void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf
* @param lang USB language ID
* @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 */
@@ -318,7 +318,7 @@ extern void gadget_set_gadget_product(struct gadget *g, int lang, char *prd);
* @param instance Function instance name
* @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 */
@@ -328,21 +328,21 @@ extern struct function *gadget_create_function(struct gadget *g, enum function_t
* @param name Name of configuration
* @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
* @param c Pointer to config
* @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
* @param c Pointer to config
* @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
@@ -350,7 +350,7 @@ extern void gadget_set_config_bm_attrs(struct config *c, int bmattrs);
* @param lang USB language ID
* @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
@@ -359,7 +359,7 @@ extern void gadget_set_config_string(struct config *c, int lang, char *string);
* @param f Pointer to function
* @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 */
@@ -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
* @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
* @param g Pointer to 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
* @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
@@ -392,45 +392,45 @@ extern void gadget_disable_gadget(struct gadget *g);
* @param f Pointer to function
* @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
* @param f Pointer to function
* @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
* @param f Pointer to function
* @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
*/
-#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
*/
-#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
*/
-#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
*/
-#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)
/**
* @}
diff --git a/libgadget.pc.in b/libusbg.pc.in
index 0c980ed..46eb245 100644
--- a/libgadget.pc.in
+++ b/libusbg.pc.in
@@ -3,9 +3,9 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
-Name: libgadget
+Name: libusbg
Description: USB gadget-configfs library
Requires:
Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -lgadget
+Libs: -L${libdir} -lusbg
Cflags: -I${includedir}
diff --git a/src/Makefile.am b/src/Makefile.am
index 2155360..d955a4c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-lib_LTLIBRARIES = libgadget.la
-libgadget_la_SOURCES = gadget.c
-libgadget_la_LDFLAGS = -version-info 0:1:0
+lib_LTLIBRARIES = libusbg.la
+libusbg_la_SOURCES = usbg.c
+libusbg_la_LDFLAGS = -version-info 0:1:0
AM_CPPFLAGS=-I../include/
diff --git a/src/gadget.c b/src/usbg.c
index 83b8b62..01af98f 100644
--- a/src/gadget.c
+++ b/src/usbg.c
@@ -16,7 +16,7 @@
#include <dirent.h>
#include <errno.h>
-#include <gadget/gadget.h>
+#include <usbg/usbg.h>
#include <netinet/ether.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,7 +27,7 @@
#include <unistd.h>
/**
- * @file gadget.c
+ * @file usbg.c
* @todo Handle buffer overflows
* @todo Error checking and return code propagation
*/
@@ -44,7 +44,7 @@
__func__, strerror(errno), ##__VA_ARGS__);\
} while (0)
-static int gadget_lookup_function_type(char *name)
+static int usbg_lookup_function_type(char *name)
{
int i = 0;
int max = sizeof(function_names)/sizeof(char *);
@@ -80,7 +80,7 @@ static int file_select(const struct dirent *dent)
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];
FILE *fp;
@@ -100,30 +100,30 @@ out:
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];
- if (gadget_read_buf(path, name, file, buf))
+ if (usbg_read_buf(path, name, file, buf))
return strtol(buf, NULL, base);
else
return 0;
}
-#define gadget_read_dec(p, n, f) gadget_read_int(p, n, f, 10)
-#define gadget_read_hex(p, n, f) gadget_read_int(p, n, f, 16)
+#define usbg_read_dec(p, n, f) usbg_read_int(p, n, f, 10)
+#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;
- gadget_read_buf(path, name, file, buf);
+ usbg_read_buf(path, name, file, buf);
if ((p = strchr(buf, '\n')) != NULL)
*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];
FILE *fp;
@@ -141,24 +141,24 @@ static void gadget_write_buf(char *path, char *name, char *file, char *buf)
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];
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 gadget_write_hex16(p, n, f, v) gadget_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_dec(p, n, f, v) usbg_write_int(p, n, f, v, "%d\n")
+#define usbg_write_hex16(p, n, f, v) usbg_write_int(p, n, f, v, "0x%04x\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;
char str_addr[40];
@@ -167,31 +167,31 @@ static void gadget_parse_function_attrs(struct function *f)
case F_SERIAL:
case F_ACM:
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;
case F_ECM:
case F_SUBSET:
case F_NCM:
case F_EEM:
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);
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);
memcpy(&f->attr.net.host_addr, addr, 6);
- gadget_read_string(f->path, f->name, "ifname", f->attr.net.ifname);
- f->attr.net.qmult = gadget_read_dec(f->path, f->name, "qmult");
+ usbg_read_string(f->path, f->name, "ifname", f->attr.net.ifname);
+ f->attr.net.qmult = usbg_read_dec(f->path, f->name, "qmult");
break;
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;
default:
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;
int i, n;
@@ -208,22 +208,22 @@ static int gadget_parse_functions(char *path, struct gadget *g)
f->parent = g;
strcpy(f->name, dent[i]->d_name);
strcpy(f->path, fpath);
- f->type = gadget_lookup_function_type(strtok(dent[i]->d_name, "."));
- gadget_parse_function_attrs(f);
+ f->type = usbg_lookup_function_type(strtok(dent[i]->d_name, "."));
+ usbg_parse_function_attrs(f);
TAILQ_INSERT_TAIL(&g->functions, f, fnode);
free(dent[i]);
}
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->bmattrs = gadget_read_hex(c->path, c->name, "bmAttributes");
- gadget_read_string(c->path, c->name, "strings/0x409/configuration", c->str_cfg);
+ c->maxpower = usbg_read_dec(c->path, c->name, "MaxPower");
+ c->bmattrs = usbg_read_hex(c->path, c->name, "bmAttributes");
+ 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;
struct dirent **dent;
@@ -263,7 +263,7 @@ static void gadget_parse_config_bindings(struct config *c)
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;
int i, n;
@@ -280,36 +280,36 @@ static int gadget_parse_configs(char *path, struct gadget *g)
c->parent = g;
strcpy(c->name, dent[i]->d_name);
strcpy(c->path, cpath);
- gadget_parse_config_attrs(c);
- gadget_parse_config_bindings(c);
+ usbg_parse_config_attrs(c);
+ usbg_parse_config_bindings(c);
TAILQ_INSERT_TAIL(&g->configs, c, cnode);
free(dent[i]);
}
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 */
- gadget_read_string(path, g->name, "UDC", g->udc);
+ usbg_read_string(path, g->name, "UDC", g->udc);
/* Actual attributes */
- g->dclass = gadget_read_hex(path, g->name, "bDeviceClass");
- g->dsubclass = gadget_read_hex(path, g->name, "bDeviceSubClass");
- g->dproto = gadget_read_hex(path, g->name, "bDeviceProtocol");
- g->maxpacket = gadget_read_hex(path, g->name, "bMaxPacketSize0");
- g->bcddevice = gadget_read_hex(path, g->name, "bcdDevice");
- g->bcdusb = gadget_read_hex(path, g->name, "bcdUSB");
- g->vendor = gadget_read_hex(path, g->name, "idVendor");
- g->product = gadget_read_hex(path, g->name, "idProduct");
+ g->dclass = usbg_read_hex(path, g->name, "bDeviceClass");
+ g->dsubclass = usbg_read_hex(path, g->name, "bDeviceSubClass");
+ g->dproto = usbg_read_hex(path, g->name, "bDeviceProtocol");
+ g->maxpacket = usbg_read_hex(path, g->name, "bMaxPacketSize0");
+ g->bcddevice = usbg_read_hex(path, g->name, "bcdDevice");
+ g->bcdusb = usbg_read_hex(path, g->name, "bcdUSB");
+ g->vendor = usbg_read_hex(path, g->name, "idVendor");
+ g->product = usbg_read_hex(path, g->name, "idProduct");
/* Strings - hardcoded to U.S. English only for now */
- gadget_read_string(path, g->name, "strings/0x409/serialnumber", g->str_ser);
- gadget_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/serialnumber", g->str_ser);
+ usbg_read_string(path, g->name, "strings/0x409/manufacturer", g->str_mnf);
+ 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;
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->path, s->path);
g->parent = s;
- gadget_parse_attrs(path, g);
- gadget_parse_functions(path, g);
- gadget_parse_configs(path, g);
+ usbg_parse_attrs(path, g);
+ usbg_parse_functions(path, g);
+ usbg_parse_configs(path, g);
TAILQ_INSERT_TAIL(&s->gadgets, g, gnode);
free(dent[i]);
}
@@ -334,11 +334,11 @@ static int gadget_parse_gadgets(char *path, struct state *s)
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);
- if (gadget_parse_gadgets(path, s) < 0) {
+ if (usbg_parse_gadgets(path, s) < 0) {
ERRORNO("unable to parse %s\n", path);
return -1;
}
@@ -350,7 +350,7 @@ static int gadget_init_state(char *path, struct state *s)
* User API
*/
-struct state *gadget_init(char *configfs_path)
+struct state *usbg_init(char *configfs_path)
{
int ret;
struct stat sts;
@@ -371,7 +371,7 @@ struct state *gadget_init(char *configfs_path)
s = malloc(sizeof(struct state));
if (s)
- gadget_init_state(path, s);
+ usbg_init_state(path, s);
else
ERRORNO("couldn't init gadget state\n");
@@ -379,7 +379,7 @@ out:
return s;
}
-void gadget_cleanup(struct state *s)
+void usbg_cleanup(struct state *s)
{
struct gadget *g;
struct config *c;
@@ -410,7 +410,7 @@ void gadget_cleanup(struct state *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;
@@ -421,7 +421,7 @@ struct gadget *gadget_get_gadget(struct state *s, const char *name)
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;
@@ -432,7 +432,7 @@ struct function *gadget_get_function(struct gadget *g, const char *name)
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;
@@ -443,7 +443,7 @@ struct config *gadget_get_config(struct gadget *g, const char *name)
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;
@@ -454,7 +454,7 @@ struct binding *gadget_get_binding(struct config *c, const char *name)
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;
@@ -465,7 +465,7 @@ struct binding *gadget_get_link_binding(struct config *c, struct function *f)
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)
{
char gpath[256];
@@ -475,7 +475,7 @@ struct gadget *gadget_create_gadget(struct state *s, char *name,
if (!s)
return NULL;
- g = gadget_get_gadget(s, name);
+ g = usbg_get_gadget(s, name);
if (g) {
ERROR("duplicate gadget name\n");
return NULL;
@@ -503,8 +503,8 @@ struct gadget *gadget_create_gadget(struct state *s, char *name,
g->vendor = vendor;
g->product = product;
- gadget_write_hex16(s->path, name, "idVendor", vendor);
- gadget_write_hex16(s->path, name, "idProduct", product);
+ usbg_write_hex16(s->path, name, "idVendor", vendor);
+ usbg_write_hex16(s->path, name, "idProduct", product);
/* Insert in string order */
if (TAILQ_EMPTY(&s->gadgets) ||
@@ -522,43 +522,43 @@ struct gadget *gadget_create_gadget(struct state *s, char *name,
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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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];
@@ -568,10 +568,10 @@ void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *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];
@@ -581,10 +581,10 @@ void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *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];
@@ -594,10 +594,10 @@ void gadget_set_gadget_product(struct gadget *g, int lang, char *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 name[256];
@@ -611,7 +611,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
* @todo Check for legal function type
*/
sprintf(name, "%s.%s", function_names[type], instance);
- f = gadget_get_function(g, name);
+ f = usbg_get_function(g, name);
if (f) {
ERROR("duplicate function name\n");
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");
f->type = type;
- gadget_parse_function_attrs(f);
+ usbg_parse_function_attrs(f);
/* Insert in string order */
if (TAILQ_EMPTY(&g->functions) ||
@@ -653,7 +653,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
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];
struct config *c, *cur;
@@ -665,7 +665,7 @@ struct config *gadget_create_config(struct gadget *g, char *name)
/**
* @todo Check for legal configuration name
*/
- c = gadget_get_config(g, name);
+ c = usbg_get_config(g, name);
if (c) {
ERROR("duplicate configuration name\n");
return NULL;
@@ -705,19 +705,19 @@ struct config *gadget_create_config(struct gadget *g, char *name)
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;
- 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;
- 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];
@@ -727,10 +727,10 @@ void gadget_set_config_string(struct config *c, int lang, char *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 fpath[256];
@@ -741,13 +741,13 @@ int gadget_add_config_function(struct config *c, char *name, struct function *f)
if (!c || !f)
return ret;
- b = gadget_get_binding(c, name);
+ b = usbg_get_binding(c, name);
if (b) {
ERROR("duplicate binding name\n");
return ret;
}
- b = gadget_get_link_binding(c, f);
+ b = usbg_get_link_binding(c, f);
if (b) {
ERROR("duplicate binding link\n");
return ret;
@@ -788,19 +788,19 @@ int gadget_add_config_function(struct config *c, char *name, struct function *f)
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);
}
-void gadget_enable_gadget(struct gadget *g, char *udc)
+void usbg_enable_gadget(struct gadget *g, char *udc)
{
char gudc[256];
struct dirent **udc_list;
int n;
if (!udc) {
- n = gadget_get_udcs(&udc_list);
+ n = usbg_get_udcs(&udc_list);
if (!n)
return;
strcpy(gudc, udc_list[0]->d_name);
@@ -811,41 +811,41 @@ void gadget_enable_gadget(struct gadget *g, char *udc)
strcpy (gudc, udc);
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, "");
- gadget_write_string(g->path, g->name, "UDC", "");
+ usbg_write_string(g->path, g->name, "UDC", "");
}
/*
* 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;
memcpy(&f->attr.net.dev_addr, dev_addr, 6);
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;
memcpy(&f->attr.net.host_addr, host_addr, 6);
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;
- gadget_write_dec(f->path, f->name, "qmult", qmult);
+ usbg_write_dec(f->path, f->name, "qmult", qmult);
}