Remove definition of gadget structure to avoid direct access to its fields. Rename that structure to usbg_gadget. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- examples/gadget-acm-ecm.c | 2 +- examples/show-gadgets.c | 60 ++++++++++++++++++-------- include/usbg/usbg.h | 93 +++++++++++++++++---------------------- src/usbg.c | 105 ++++++++++++++++++++++++++------------------- 4 files changed, 142 insertions(+), 118 deletions(-) diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c index 672d4b5..633f482 100644 --- a/examples/gadget-acm-ecm.c +++ b/examples/gadget-acm-ecm.c @@ -30,7 +30,7 @@ int main(void) { usbg_state *s; - struct gadget *g; + usbg_gadget *g; struct function *f; struct config *c; struct function *f_acm0, *f_acm1, *f_ecm; diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index a53c355..bea3e08 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -27,22 +27,34 @@ * in the system */ -void show_gadget(struct gadget *g) +void show_gadget(usbg_gadget *g) { + char buf[USBG_MAX_STR_LENGTH]; + struct gadget_attrs g_attrs; + struct gadget_strs g_strs; + + usbg_get_gadget_name(g, buf, USBG_MAX_STR_LENGTH); + usbg_get_gadget_attrs(g, &g_attrs); + fprintf(stdout, "ID %04x:%04x '%s'\n", - g->attrs.idVendor, g->attrs.idProduct, g->name); - fprintf(stdout, " UDC\t\t\t%s\n", g->udc); - fprintf(stdout, " bDeviceClass\t\t0x%02x\n", g->attrs.bDeviceClass); - fprintf(stdout, " bDeviceSubClass\t0x%02x\n", g->attrs.bDeviceSubClass); - fprintf(stdout, " bDeviceProtocol\t0x%02x\n", g->attrs.bDeviceProtocol); - fprintf(stdout, " bMaxPacketSize0\t0x%02x\n", g->attrs.bMaxPacketSize0); - fprintf(stdout, " bcdDevice\t\t0x%04x\n", g->attrs.bcdDevice); - fprintf(stdout, " bcdUSB\t\t0x%04x\n", g->attrs.bcdUSB); - fprintf(stdout, " idVendor\t\t0x%04x\n", g->attrs.idVendor); - fprintf(stdout, " idProduct\t\t0x%04x\n", g->attrs.idProduct); - fprintf(stdout, " Serial Number\t\t%s\n", g->strs.str_ser); - fprintf(stdout, " Manufacturer\t\t%s\n", g->strs.str_mnf); - fprintf(stdout, " Product\t\t%s\n", g->strs.str_prd); + g_attrs.idVendor, g_attrs.idProduct, buf); + + usbg_get_gadget_udc(g, buf, USBG_MAX_STR_LENGTH); + fprintf(stdout, " UDC\t\t\t%s\n", buf); + + fprintf(stdout, " bDeviceClass\t\t0x%02x\n", g_attrs.bDeviceClass); + fprintf(stdout, " bDeviceSubClass\t0x%02x\n", g_attrs.bDeviceSubClass); + fprintf(stdout, " bDeviceProtocol\t0x%02x\n", g_attrs.bDeviceProtocol); + fprintf(stdout, " bMaxPacketSize0\t0x%02x\n", g_attrs.bMaxPacketSize0); + fprintf(stdout, " bcdDevice\t\t0x%04x\n", g_attrs.bcdDevice); + fprintf(stdout, " bcdUSB\t\t0x%04x\n", g_attrs.bcdUSB); + fprintf(stdout, " idVendor\t\t0x%04x\n", g_attrs.idVendor); + fprintf(stdout, " idProduct\t\t0x%04x\n", g_attrs.idProduct); + + usbg_get_gadget_strs(g, &g_strs); + fprintf(stdout, " Serial Number\t\t%s\n", g_strs.str_ser); + fprintf(stdout, " Manufacturer\t\t%s\n", g_strs.str_mnf); + fprintf(stdout, " Product\t\t%s\n", g_strs.str_prd); } void show_function(struct function *f) @@ -78,11 +90,21 @@ void show_function(struct function *f) void show_config(struct config *c) { struct binding *b; + struct function *f; + char buf[USBG_MAX_STR_LENGTH], buf2[USBG_MAX_STR_LENGTH]; + struct config_attrs c_attrs; + struct config_strs c_strs; + + usbg_get_config_name(c, buf, USBG_MAX_STR_LENGTH); + fprintf(stdout, " Configuration '%s'\n", buf); + + usbg_get_config_attrs(c, &c_attrs); + fprintf(stdout, " MaxPower\t\t%d\n", c_attrs.bMaxPower); + fprintf(stdout, " bmAttributes\t0x%02x\n", c_attrs.bmAttributes); + + usbg_get_config_strs(c, &c_strs); + fprintf(stdout, " configuration\t%s\n", c_strs.configuration); - fprintf(stdout, " Configuration '%s'\n", c->name); - fprintf(stdout, " MaxPower\t\t%d\n", c->attrs.bMaxPower); - fprintf(stdout, " bmAttributes\t0x%02x\n", c->attrs.bmAttributes); - fprintf(stdout, " configuration\t%s\n", c->strs.configuration); usbg_for_each_binding(b, c) fprintf(stdout, " %s -> %s\n", b->name,b->target->name); } @@ -90,7 +112,7 @@ void show_config(struct config *c) int main(void) { usbg_state *s; - struct gadget *g; + usbg_gadget *g; struct function *f; struct config *c; struct binding *b; diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 5cad066..ad67876 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -45,6 +45,7 @@ * Internal structures */ struct usbg_state; +struct usbg_gadget; /** * @brief State of the gadget devices in the system @@ -52,6 +53,11 @@ struct usbg_state; typedef struct usbg_state usbg_state; /** + * @brief USB gadget device + */ +typedef struct usbg_gadget usbg_gadget; + +/** * @struct gadget_attrs * @brief USB gadget device attributes */ @@ -79,25 +85,6 @@ struct gadget_strs }; /** - * @struct gadget - * @brief USB gadget device - */ -struct gadget -{ - char name[USBG_MAX_NAME_LENGTH]; - char path[USBG_MAX_PATH_LENGTH]; - char udc[USBG_MAX_STR_LENGTH]; - - struct gadget_attrs attrs; - struct gadget_strs strs; - - TAILQ_ENTRY(gadget) gnode; - TAILQ_HEAD(chead, config) configs; - TAILQ_HEAD(fhead, function) functions; - usbg_state *parent; -}; - -/** * @struct config_attrs * @brief USB configuration attributes */ @@ -124,7 +111,7 @@ struct config { TAILQ_ENTRY(config) cnode; TAILQ_HEAD(bhead, binding) bindings; - struct gadget *parent; + usbg_gadget *parent; char name[USBG_MAX_NAME_LENGTH]; char path[USBG_MAX_PATH_LENGTH]; @@ -193,7 +180,7 @@ union attrs { struct function { TAILQ_ENTRY(function) fnode; - struct gadget *parent; + usbg_gadget *parent; char name[USBG_MAX_NAME_LENGTH]; char path[USBG_MAX_PATH_LENGTH]; @@ -257,7 +244,7 @@ extern char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len); * @param name Name of the gadget device * @return Pointer to gadget or NULL if a matching gadget isn't found */ -extern struct gadget *usbg_get_gadget(usbg_state *s, const char *name); +extern usbg_gadget *usbg_get_gadget(usbg_state *s, const char *name); /** * @brief Get a function by name @@ -265,7 +252,7 @@ extern struct gadget *usbg_get_gadget(usbg_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 *usbg_get_function(struct gadget *g, const char *name); +extern struct function *usbg_get_function(usbg_gadget *g, const char *name); /** * @brief Get a configuration by name @@ -273,7 +260,7 @@ extern struct function *usbg_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 *usbg_get_config(struct gadget *g, const char *name); +extern struct config *usbg_get_config(usbg_gadget *g, const char *name); /* USB gadget allocation and configuration */ @@ -285,7 +272,7 @@ extern struct config *usbg_get_config(struct gadget *g, const char *name); * @param idProduct Gadget product ID * @return Pointer to gadget or NULL if the gadget cannot be created */ -extern struct gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, +extern usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, uint16_t idVendor, uint16_t idProduct); /** @@ -298,7 +285,7 @@ extern struct gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, * @note Given strings are assumed to be in US English * @return Pointer to gadget or NULL if the gadget cannot be created */ -extern struct gadget *usbg_create_gadget(usbg_state *s, char *name, +extern usbg_gadget *usbg_create_gadget(usbg_state *s, char *name, struct gadget_attrs *g_attrs, struct gadget_strs *g_strs); /** @@ -306,7 +293,7 @@ extern struct gadget *usbg_create_gadget(usbg_state *s, char *name, * @param g Pointer to gadget * @param g_attrs Gadget attributes */ -extern void usbg_set_gadget_attrs(struct gadget *g, +extern void usbg_set_gadget_attrs(usbg_gadget *g, struct gadget_attrs *g_attrs); /** @@ -315,7 +302,7 @@ extern void usbg_set_gadget_attrs(struct gadget *g, * @param g_attrs Structure to be filled * @retur Pointer to filled structure or NULL if error occurred. */ -extern struct gadget_attrs *usbg_get_gadget_attrs(struct gadget *g, +extern struct gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g, struct gadget_attrs *g_attrs); /** @@ -323,7 +310,7 @@ extern struct gadget_attrs *usbg_get_gadget_attrs(struct gadget *g, * @param g Gadget which name length should be returned * @return Length of name string or -1 if error occurred. */ -extern size_t usbg_get_gadget_name_len(struct gadget *g); +extern size_t usbg_get_gadget_name_len(usbg_gadget *g); /** * @brieg Get gadget name @@ -332,28 +319,28 @@ extern size_t usbg_get_gadget_name_len(struct gadget *g); * @param len Length of given buffer * @return Pointer to destination or NULL if error occurred. */ -extern char *usbg_get_gadget_name(struct gadget *g, char *buf, size_t len); +extern char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len); /** * @brief Set the USB gadget vendor id * @param g Pointer to gadget * @param idVendor USB device vendor id */ -extern void usbg_set_gadget_vendor_id(struct gadget *g, uint16_t idVendor); +extern void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor); /** * @brief Set the USB gadget product id * @param g Pointer to gadget * @param idProduct USB device product id */ -extern void usbg_set_gadget_product_id(struct gadget *g, uint16_t idProduct); +extern void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct); /** * @brief Set the USB gadget device class code * @param g Pointer to gadget * @param bDeviceClass USB device class code */ -extern void usbg_set_gadget_device_class(struct gadget *g, +extern void usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass); /** @@ -361,7 +348,7 @@ extern void usbg_set_gadget_device_class(struct gadget *g, * @param g Pointer to gadget * @param bDeviceProtocol USB protocol code */ -extern void usbg_set_gadget_device_protocol(struct gadget *g, +extern void usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol); /** @@ -369,7 +356,7 @@ extern void usbg_set_gadget_device_protocol(struct gadget *g, * @param g Pointer to gadget * @param bDeviceSubClass USB device subclass code */ -extern void usbg_set_gadget_device_subclass(struct gadget *g, +extern void usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass); /** @@ -377,7 +364,7 @@ extern void usbg_set_gadget_device_subclass(struct gadget *g, * @param g Pointer to gadget * @param bMaxPacketSize0 Maximum packet size */ -extern void usbg_set_gadget_device_max_packet(struct gadget *g, +extern void usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0); /** @@ -385,7 +372,7 @@ extern void usbg_set_gadget_device_max_packet(struct gadget *g, * @param g Pointer to gadget * @param bcdDevice BCD release number */ -extern void usbg_set_gadget_device_bcd_device(struct gadget *g, +extern void usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice); /** @@ -393,7 +380,7 @@ extern void usbg_set_gadget_device_bcd_device(struct gadget *g, * @param g Pointer to gadget * @param bcdUSB BCD USB version */ -extern void usbg_set_gadget_device_bcd_usb(struct gadget *g, uint16_t bcdUSB); +extern void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB); /** * @brief Get the USB gadget strings @@ -401,7 +388,7 @@ extern void usbg_set_gadget_device_bcd_usb(struct gadget *g, uint16_t bcdUSB); * @param g_sttrs Structure to be filled * @retur Pointer to filled structure or NULL if error occurred. */ -extern struct gadget_strs *usbg_get_gadget_strs(struct gadget *g, +extern struct gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, struct gadget_strs *g_strs); /** @@ -410,7 +397,7 @@ extern struct gadget_strs *usbg_get_gadget_strs(struct gadget *g, * @param lang USB language ID * @param g_sttrs Gadget attributes */ -extern void usbg_set_gadget_strs(struct gadget *g, int lang, +extern void usbg_set_gadget_strs(usbg_gadget *g, int lang, struct gadget_strs *g_strs); /** @@ -419,7 +406,7 @@ extern void usbg_set_gadget_strs(struct gadget *g, int lang, * @param lang USB language ID * @param ser Serial number */ -extern void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *ser); +extern void usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *ser); /** * @brief Set the manufacturer name for a gadget @@ -427,7 +414,7 @@ extern void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *ser) * @param lang USB language ID * @param mnf Manufacturer */ -extern void usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf); +extern void usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf); /** * @brief Set the product name for a gadget @@ -435,7 +422,7 @@ extern void usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf); * @param lang USB language ID * @param prd Product */ -extern void usbg_set_gadget_product(struct gadget *g, int lang, char *prd); +extern void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd); /* USB function allocation and configuration */ @@ -447,7 +434,7 @@ extern void usbg_set_gadget_product(struct gadget *g, int lang, char *prd); * @param f_attrs Function attributes to be set. If NULL setting is omitted. * @return Pointer to function or NULL if it cannot be created */ -extern struct function *usbg_create_function(struct gadget *g, enum function_type type, +extern struct function *usbg_create_function(usbg_gadget *g, enum function_type type, char *instance, union attrs *f_attrs); /** @@ -476,7 +463,7 @@ extern char *usbg_get_function_name(struct function *f, char *buf, size_t len); * @param c_strs Configuration strings to be set * @return Pointer to configuration or NULL if it cannot be created */ -extern struct config *usbg_create_config(struct gadget *g, char *name, +extern struct config *usbg_create_config(usbg_gadget *g, char *name, struct config_attrs *c_attrs, struct config_strs *c_strs); /** @@ -598,13 +585,13 @@ extern int usbg_get_udcs(struct dirent ***udc_list); * @param g Pointer to gadget * @param udc Name of UDC to enable gadget */ -extern void usbg_enable_gadget(struct gadget *g, char *udc); +extern void usbg_enable_gadget(usbg_gadget *g, char *udc); /** * @brief Disable a USB gadget device * @param g Pointer to gadget */ -extern void usbg_disable_gadget(struct gadget *g); +extern void usbg_disable_gadget(usbg_gadget *g); /** * @brief Get gadget name length @@ -612,7 +599,7 @@ extern void usbg_disable_gadget(struct gadget *g); * @return Length of name string or -1 if error occurred. * @note If gadget isn't enabled on any udc returned size is 0. */ -extern size_t usbg_get_gadget_udc_len(struct gadget *g); +extern size_t usbg_get_gadget_udc_len(usbg_gadget *g); /** * @brieg Get name of udc to which gadget is binded @@ -622,7 +609,7 @@ extern size_t usbg_get_gadget_udc_len(struct gadget *g); * @return Pointer to destination or NULL if error occurred. * @note If gadget isn't enabled on any udc returned string is empty. */ -extern char *usbg_get_gadget_udc(struct gadget *g, char *buf, size_t len); +extern char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len); /* * USB function-specific attribute configuration @@ -715,7 +702,7 @@ extern void usbg_set_net_qmult(struct function *f, int qmult); * @return Pointer to gadget or NULL if list is empty. * @note Gadgets are sorted in strings (name) order */ -extern struct gadget *usbg_get_first_gadget(usbg_state *s); +extern usbg_gadget *usbg_get_first_gadget(usbg_state *s); /** * @brief Get first function in function list @@ -723,7 +710,7 @@ extern struct gadget *usbg_get_first_gadget(usbg_state *s); * @return Pointer to function or NULL if list is empty. * @note Functions are sorted in strings (name) order */ -extern struct function *usbg_get_first_function(struct gadget *g); +extern struct function *usbg_get_first_function(usbg_gadget *g); /** * @brief Get first config in config list @@ -731,7 +718,7 @@ extern struct function *usbg_get_first_function(struct gadget *g); * @return Pointer to configuration or NULL if list is empty. * @note Configs are sorted in strings (name) order */ -extern struct config *usbg_get_first_config(struct gadget *g); +extern struct config *usbg_get_first_config(usbg_gadget *g); /** * @brief Get first binding in binding list @@ -746,7 +733,7 @@ extern struct binding *usbg_get_first_binding(struct config *c); * @pram g Pointer to current gadget * @return Next gadget or NULL if end of list. */ -extern struct gadget *usbg_get_next_gadget(struct gadget *g); +extern usbg_gadget *usbg_get_next_gadget(usbg_gadget *g); /** * @brief Get the next function on a list. diff --git a/src/usbg.c b/src/usbg.c index 5649621..a05d5ac 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -40,7 +40,22 @@ struct usbg_state { char path[USBG_MAX_PATH_LENGTH]; - TAILQ_HEAD(ghead, gadget) gadgets; + TAILQ_HEAD(ghead, usbg_gadget) gadgets; +}; + +struct usbg_gadget +{ + char name[USBG_MAX_NAME_LENGTH]; + char path[USBG_MAX_PATH_LENGTH]; + char udc[USBG_MAX_STR_LENGTH]; + + struct gadget_attrs attrs; + struct gadget_strs strs; + + TAILQ_ENTRY(usbg_gadget) gnode; + TAILQ_HEAD(chead, config) configs; + TAILQ_HEAD(fhead, function) functions; + usbg_state *parent; }; /** @@ -262,7 +277,7 @@ static void usbg_parse_function_attrs(struct function *f) } } -static int usbg_parse_functions(char *path, struct gadget *g) +static int usbg_parse_functions(char *path, usbg_gadget *g) { struct function *f; int i, n; @@ -312,7 +327,7 @@ static void usbg_parse_config_bindings(struct config *c) int i, n; struct dirent **dent; char bpath[USBG_MAX_PATH_LENGTH]; - struct gadget *g = c->parent; + usbg_gadget *g = c->parent; struct binding *b; struct function *f; @@ -347,7 +362,7 @@ static void usbg_parse_config_bindings(struct config *c) free(dent); } -static int usbg_parse_configs(char *path, struct gadget *g) +static int usbg_parse_configs(char *path, usbg_gadget *g) { struct config *c; int i, n; @@ -404,7 +419,7 @@ static void usbg_parse_strings(char *path, char *name, struct gadget_strs *g_str static int usbg_parse_gadgets(char *path, usbg_state *s) { - struct gadget *g; + usbg_gadget *g; int i, n; struct dirent **dent; @@ -412,7 +427,7 @@ static int usbg_parse_gadgets(char *path, usbg_state *s) n = scandir(path, &dent, file_select, alphasort); for (i=0; i < n; i++) { - g = malloc(sizeof(struct gadget)); + g = malloc(sizeof(usbg_gadget)); strcpy(g->name, dent[i]->d_name); strcpy(g->path, s->path); g->parent = s; @@ -477,7 +492,7 @@ out: void usbg_cleanup(usbg_state *s) { - struct gadget *g; + usbg_gadget *g; struct config *c; struct binding *b; struct function *f; @@ -516,9 +531,9 @@ char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len) return s ? strncpy(buf, s->path, len) : NULL; } -struct gadget *usbg_get_gadget(usbg_state *s, const char *name) +usbg_gadget *usbg_get_gadget(usbg_state *s, const char *name) { - struct gadget *g; + usbg_gadget *g; TAILQ_FOREACH(g, &s->gadgets, gnode) if (!strcmp(g->name, name)) @@ -527,7 +542,7 @@ struct gadget *usbg_get_gadget(usbg_state *s, const char *name) return NULL; } -struct function *usbg_get_function(struct gadget *g, const char *name) +struct function *usbg_get_function(usbg_gadget *g, const char *name) { struct function *f; @@ -538,7 +553,7 @@ struct function *usbg_get_function(struct gadget *g, const char *name) return NULL; } -struct config *usbg_get_config(struct gadget *g, const char *name) +struct config *usbg_get_config(usbg_gadget *g, const char *name) { struct config *c; @@ -571,15 +586,15 @@ struct binding *usbg_get_link_binding(struct config *c, struct function *f) return NULL; } -static struct gadget *usbg_create_empty_gadget(usbg_state *s, char *name) +static usbg_gadget *usbg_create_empty_gadget(usbg_state *s, char *name) { char gpath[USBG_MAX_PATH_LENGTH]; - struct gadget *g; + usbg_gadget *g; int ret; sprintf(gpath, "%s/%s", s->path, name); - g = malloc(sizeof(struct gadget)); + g = malloc(sizeof(usbg_gadget)); if (!g) { ERRORNO("allocating gadget\n"); return NULL; @@ -606,10 +621,10 @@ static struct gadget *usbg_create_empty_gadget(usbg_state *s, char *name) -struct gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, +usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, uint16_t idVendor, uint16_t idProduct) { - struct gadget *g; + usbg_gadget *g; if (!s) return NULL; @@ -636,10 +651,10 @@ struct gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, return g; } -struct gadget *usbg_create_gadget(usbg_state *s, char *name, +usbg_gadget *usbg_create_gadget(usbg_state *s, char *name, struct gadget_attrs *g_attrs, struct gadget_strs *g_strs) { - struct gadget *g; + usbg_gadget *g; if (!s) return NULL; @@ -670,7 +685,7 @@ struct gadget *usbg_create_gadget(usbg_state *s, char *name, return g; } -struct gadget_attrs *usbg_get_gadget_attrs(struct gadget *g, +struct gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g, struct gadget_attrs *g_attrs) { if (g && g_attrs) @@ -681,27 +696,27 @@ struct gadget_attrs *usbg_get_gadget_attrs(struct gadget *g, return g_attrs; } -size_t usbg_get_gadget_name_len(struct gadget *g) +size_t usbg_get_gadget_name_len(usbg_gadget *g) { return g ? strlen(g->name) : -1; } -char *usbg_get_gadget_name(struct gadget *g, char *buf, size_t len) +char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len) { return g ? strncpy(buf, g->name, len) : NULL; } -size_t usbg_get_gadget_udc_len(struct gadget *g) +size_t usbg_get_gadget_udc_len(usbg_gadget *g) { return g ? strlen(g->udc) : -1; } -char *usbg_get_gadget_udc(struct gadget *g, char *buf, size_t len) +char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len) { return g ? strncpy(buf, g->udc, len) : NULL; } -void usbg_set_gadget_attrs(struct gadget *g, struct gadget_attrs *g_attrs) +void usbg_set_gadget_attrs(usbg_gadget *g, struct gadget_attrs *g_attrs) { if (!g || !g_attrs) return; @@ -717,55 +732,55 @@ void usbg_set_gadget_attrs(struct gadget *g, struct gadget_attrs *g_attrs) usbg_write_hex16(g->path, g->name, "bcdDevice", g_attrs->bcdDevice); } -void usbg_set_gadget_vendor_id(struct gadget *g, uint16_t idVendor) +void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor) { g->attrs.idVendor = idVendor; usbg_write_hex16(g->path, g->name, "idVendor", idVendor); } -void usbg_set_gadget_product_id(struct gadget *g, uint16_t idProduct) +void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct) { g->attrs.idProduct = idProduct; usbg_write_hex16(g->path, g->name, "idProduct", idProduct); } -void usbg_set_gadget_device_class(struct gadget *g, uint8_t bDeviceClass) +void usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass) { g->attrs.bDeviceClass = bDeviceClass; usbg_write_hex8(g->path, g->name, "bDeviceClass", bDeviceClass); } -void usbg_set_gadget_device_protocol(struct gadget *g, uint8_t bDeviceProtocol) +void usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol) { g->attrs.bDeviceProtocol = bDeviceProtocol; usbg_write_hex8(g->path, g->name, "bDeviceProtocol", bDeviceProtocol); } -void usbg_set_gadget_device_subclass(struct gadget *g, uint8_t bDeviceSubClass) +void usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass) { g->attrs.bDeviceSubClass = bDeviceSubClass; usbg_write_hex8(g->path, g->name, "bDeviceSubClass", bDeviceSubClass); } -void usbg_set_gadget_device_max_packet(struct gadget *g, uint8_t bMaxPacketSize0) +void usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0) { g->attrs.bMaxPacketSize0 = bMaxPacketSize0; usbg_write_hex8(g->path, g->name, "bMaxPacketSize0", bMaxPacketSize0); } -void usbg_set_gadget_device_bcd_device(struct gadget *g, uint16_t bcdDevice) +void usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice) { g->attrs.bcdDevice = bcdDevice; usbg_write_hex16(g->path, g->name, "bcdDevice", bcdDevice); } -void usbg_set_gadget_device_bcd_usb(struct gadget *g, uint16_t bcdUSB) +void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB) { g->attrs.bcdUSB = bcdUSB; usbg_write_hex16(g->path, g->name, "bcdUSB", bcdUSB); } -struct gadget_strs *usbg_get_gadget_strs(struct gadget *g, +struct gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, struct gadget_strs *g_strs) { if (g && g_strs) @@ -776,7 +791,7 @@ struct gadget_strs *usbg_get_gadget_strs(struct gadget *g, return g_strs; } -void usbg_set_gadget_strs(struct gadget *g, int lang, +void usbg_set_gadget_strs(usbg_gadget *g, int lang, struct gadget_strs *g_strs) { char path[USBG_MAX_PATH_LENGTH]; @@ -794,7 +809,7 @@ void usbg_set_gadget_strs(struct gadget *g, int lang, usbg_write_string(path, "", "product", g_strs->str_prd); } -void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno) +void usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *serno) { char path[USBG_MAX_PATH_LENGTH]; @@ -809,7 +824,7 @@ void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno) usbg_write_string(path, "", "serialnumber", serno); } -void usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf) +void usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf) { char path[USBG_MAX_PATH_LENGTH]; @@ -824,7 +839,7 @@ void usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf) usbg_write_string(path, "", "manufacturer", mnf); } -void usbg_set_gadget_product(struct gadget *g, int lang, char *prd) +void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd) { char path[USBG_MAX_PATH_LENGTH]; @@ -839,7 +854,7 @@ void usbg_set_gadget_product(struct gadget *g, int lang, char *prd) usbg_write_string(path, "", "product", prd); } -struct function *usbg_create_function(struct gadget *g, enum function_type type, +struct function *usbg_create_function(usbg_gadget *g, enum function_type type, char *instance, union attrs *f_attrs) { char fpath[USBG_MAX_PATH_LENGTH]; @@ -889,7 +904,7 @@ struct function *usbg_create_function(struct gadget *g, enum function_type type, return f; } -struct config *usbg_create_config(struct gadget *g, char *name, +struct config *usbg_create_config(usbg_gadget *g, char *name, struct config_attrs *c_attrs, struct config_strs *c_strs) { char cpath[USBG_MAX_PATH_LENGTH]; @@ -1095,7 +1110,7 @@ int usbg_get_udcs(struct dirent ***udc_list) return scandir("/sys/class/udc", udc_list, file_select, alphasort); } -void usbg_enable_gadget(struct gadget *g, char *udc) +void usbg_enable_gadget(usbg_gadget *g, char *udc) { char gudc[USBG_MAX_STR_LENGTH]; struct dirent **udc_list; @@ -1116,7 +1131,7 @@ void usbg_enable_gadget(struct gadget *g, char *udc) usbg_write_string(g->path, g->name, "UDC", gudc); } -void usbg_disable_gadget(struct gadget *g) +void usbg_disable_gadget(usbg_gadget *g) { strcpy(g->udc, ""); usbg_write_string(g->path, g->name, "UDC", ""); @@ -1205,17 +1220,17 @@ void usbg_set_net_qmult(struct function *f, int qmult) usbg_write_dec(f->path, f->name, "qmult", qmult); } -struct gadget *usbg_get_first_gadget(usbg_state *s) +usbg_gadget *usbg_get_first_gadget(usbg_state *s) { return s ? TAILQ_FIRST(&s->gadgets) : NULL; } -struct function *usbg_get_first_function(struct gadget *g) +struct function *usbg_get_first_function(usbg_gadget *g) { return g ? TAILQ_FIRST(&g->functions) : NULL; } -struct config *usbg_get_first_config(struct gadget *g) +struct config *usbg_get_first_config(usbg_gadget *g) { return g ? TAILQ_FIRST(&g->configs) : NULL; } @@ -1225,7 +1240,7 @@ struct binding *usbg_get_first_binding(struct config *c) return c ? TAILQ_FIRST(&c->bindings) : NULL; } -struct gadget *usbg_get_next_gadget(struct gadget *g) +usbg_gadget *usbg_get_next_gadget(usbg_gadget *g) { return g ? TAILQ_NEXT(g, gnode) : NULL; } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html