Gadget strings are not logically part of gadget, so should be separated. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- examples/show-gadgets.c | 6 +++--- include/usbg/usbg.h | 14 +++++++++++--- src/usbg.c | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index 29a30d3..5b6cb61 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -40,9 +40,9 @@ void show_gadget(struct gadget *g) 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->str_ser); - fprintf(stdout, " Manufacturer\t\t%s\n", g->str_mnf); - fprintf(stdout, " Product\t\t%s\n", g->str_prd); + 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) diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 840c047..5b2213d 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -68,6 +68,16 @@ struct gadget_attrs uint16_t bcdDevice; }; +/** + * @struct gadget_strs + * @brief USB gadget device strings + */ +struct gadget_strs +{ + char str_ser[USBG_MAX_STR_LENGTH]; + char str_mnf[USBG_MAX_STR_LENGTH]; + char str_prd[USBG_MAX_STR_LENGTH]; +}; /** * @struct gadget @@ -80,10 +90,8 @@ struct gadget char udc[USBG_MAX_STR_LENGTH]; struct gadget_attrs attrs; + struct gadget_strs strs; - char str_ser[USBG_MAX_STR_LENGTH]; - char str_mnf[USBG_MAX_STR_LENGTH]; - char str_prd[USBG_MAX_STR_LENGTH]; TAILQ_ENTRY(gadget) gnode; TAILQ_HEAD(chead, config) configs; TAILQ_HEAD(fhead, function) functions; diff --git a/src/usbg.c b/src/usbg.c index f5e06ba..b908a98 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -335,17 +335,17 @@ static void usbg_parse_gadget_attrs(char *path, char *name, g_attrs->bcdDevice = (uint16_t)usbg_read_hex(path, name, "bcdDevice"); } -static void usbg_parse_strings(char *path, struct gadget *g) +static void usbg_parse_strings(char *path, char *name, struct gadget_strs *g_strs) { /* Strings - hardcoded to U.S. English only for now */ int lang = LANG_US_ENG; char spath[USBG_MAX_PATH_LENGTH]; - sprintf(spath, "%s/%s/%s/0x%x", path, g->name, STRINGS_DIR, lang); + sprintf(spath, "%s/%s/%s/0x%x", path, name, STRINGS_DIR, lang); - usbg_read_string(spath, "", "serialnumber", g->str_ser); - usbg_read_string(spath, "", "manufacturer", g->str_mnf); - usbg_read_string(spath, "", "product", g->str_prd); + usbg_read_string(spath, "", "serialnumber", g_strs->str_ser); + usbg_read_string(spath, "", "manufacturer", g_strs->str_mnf); + usbg_read_string(spath, "", "product", g_strs->str_prd); } static int usbg_parse_gadgets(char *path, struct state *s) @@ -365,7 +365,7 @@ static int usbg_parse_gadgets(char *path, struct state *s) /* UDC bound to, if any */ usbg_read_string(path, g->name, "UDC", g->udc); usbg_parse_gadget_attrs(path, g->name, &g->attrs); - usbg_parse_strings(path, g); + usbg_parse_strings(path, g->name, &g->strs); usbg_parse_functions(path, g); usbg_parse_configs(path, g); TAILQ_INSERT_TAIL(&s->gadgets, g, gnode); @@ -548,7 +548,7 @@ struct gadget *usbg_create_gadget(struct state *s, char *name, usbg_write_hex16(s->path, name, "idProduct", idProduct); usbg_parse_gadget_attrs(s->path, name, &g->attrs); - usbg_parse_strings(s->path, g); + usbg_parse_strings(s->path, name, &g->strs); /* Insert in string order */ if (TAILQ_EMPTY(&s->gadgets) || @@ -610,7 +610,7 @@ void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno) mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO); - strcpy(g->str_ser, serno); + strcpy(g->strs.str_ser, serno); usbg_write_string(path, "", "serialnumber", serno); } @@ -623,7 +623,7 @@ void usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf) mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO); - strcpy(g->str_mnf, mnf); + strcpy(g->strs.str_mnf, mnf); usbg_write_string(path, "", "manufacturer", mnf); } @@ -636,7 +636,7 @@ void usbg_set_gadget_product(struct gadget *g, int lang, char *prd) mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO); - strcpy(g->str_prd, prd); + strcpy(g->strs.str_prd, prd); usbg_write_string(path, "", "product", prd); } -- 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