This is an example of how to find and remove an gadget device with given Vendor ID and product ID.
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define VENDOR 0x1d6b
#define PRODUCT 0x0104
{
int usbg_ret;
if (u) {
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB disable gadget udc\n");
goto out;
}
}
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB gadget remove\n");
}
out:
return usbg_ret;
}
int main(int argc, char **argv)
{
int usbg_ret;
int ret = -EINVAL;
char *cp;
int vendor = VENDOR, product = PRODUCT;
if (argc >= 2) {
cp = strchr(argv[1], ':');
if (!cp) {
ret = -EINVAL;
fprintf(stderr, "Usage: gadget-vid-pid-remove vid:pid\n");
goto out1;
}
*cp++ = 0;
if (*argv[1])
vendor = strtoul(argv[1], NULL, 16);
if (*cp)
product = strtoul(cp, NULL, 16);
}
usbg_ret =
usbg_init(
"/sys/kernel/config", &s);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB state init\n");
goto out1;
}
while (g != NULL) {
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB get gadget attrs\n");
goto out2;
}
if (g_attrs.idVendor == vendor && g_attrs.idProduct == product) {
usbg_ret = remove_gadget(g);
if (usbg_ret != USBG_SUCCESS)
goto out2;
g = g_next;
} else {
}
}
ret = 0;
out2:
out1:
return ret;
}
const char * usbg_strerror(usbg_error e)
Get the short description of error.
Definition usbg_error.c:123
int usbg_rm_gadget(usbg_gadget *g, int opts)
Remove existing USB gadget.
Definition usbg.c:1350
int usbg_get_gadget_attrs(usbg_gadget *g, struct usbg_gadget_attrs *g_attrs)
Get the USB gadget strings.
Definition usbg.c:1578
usbg_gadget * usbg_get_next_gadget(usbg_gadget *g)
Get the next gadget on a list.
Definition usbg.c:2650
usbg_gadget * usbg_get_first_gadget(usbg_state *s)
Get first gadget in gadget list.
Definition usbg.c:2625
#define USBG_RM_RECURSE
Additional option for usbg_rm_* functions.
Definition usbg.h:71
int usbg_init(const char *configfs_path, usbg_state **state)
Initialize the libusbgx library state.
Definition usbg.c:1091
usbg_udc * usbg_get_gadget_udc(usbg_gadget *g)
Get udc to which gadget is bound.
Definition usbg.c:1648
void usbg_cleanup(usbg_state *s)
Clean up the libusbgx library state.
Definition usbg.c:1136
int usbg_disable_gadget(usbg_gadget *g)
Disable a USB gadget device.
Definition usbg.c:2576
const char * usbg_error_name(usbg_error e)
Get the error name as a constant string.
Definition usbg_error.c:62
USB gadget device attributes.
Definition usbg.h:135
Definition usbg_internal.h:103
Definition usbg_internal.h:93
Definition usbg_internal.h:153