Configuration, its attributes and strings are all logically
independent so should be placed in separate structures.

Signed-off-by: Krzysztof Opasiak <k.opas...@samsung.com>
---
 examples/show-gadgets.c |    6 +++---
 include/usbg/usbg.h     |   32 +++++++++++++++++++++++++-------
 src/usbg.c              |   37 ++++++++++++++++++++++++-------------
 3 files changed, 52 insertions(+), 23 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 5b6cb61..b9c5948 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -80,9 +80,9 @@ void show_config(struct config *c)
        struct binding *b;
 
        fprintf(stdout, "  Configuration '%s'\n", c->name);
-       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);
+       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);
 }
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 23aecfe..d7933a0 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -99,6 +99,25 @@ struct gadget
 };
 
 /**
+ * @struct config_attrs
+ * @brief USB configuration attributes
+ */
+struct config_attrs
+{
+       uint8_t bmAttributes;
+       uint8_t bMaxPower;
+};
+
+/**
+ * @struct config_strs
+ * @brief USB configuration strings
+ */
+struct config_strs
+{
+       char configuration[USBG_MAX_STR_LENGTH];
+};
+
+/**
  * @struct config
  * @brief USB gadget configuration attributes
  */
@@ -110,9 +129,8 @@ struct config
 
        char name[USBG_MAX_NAME_LENGTH];
        char path[USBG_MAX_PATH_LENGTH];
-       int maxpower;
-       int bmattrs;
-       char str_cfg[USBG_MAX_STR_LENGTH];
+       struct config_attrs attrs;
+       struct config_strs strs;
 };
 
 /**
@@ -461,16 +479,16 @@ 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)
+ * @param bMaxPower Maximum power (in 2 mA units)
  */
-extern void usbg_set_config_max_power(struct config *c, int maxpower);
+extern void usbg_set_config_max_power(struct config *c, int bMaxPower);
 
 /**
  * @brief Set the configuration bitmap attributes
  * @param c Pointer to config
- * @param bmattrs Configuration characteristics
+ * @param bmAttributes Configuration characteristics
  */
-extern void usbg_set_config_bm_attrs(struct config *c, int bmattrs);
+extern void usbg_set_config_bm_attrs(struct config *c, int bmAttributes);
 
 /**
  * @brief Set the configuration string
diff --git a/src/usbg.c b/src/usbg.c
index 316c515..d5b57c6 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -265,11 +265,20 @@ static int usbg_parse_functions(char *path, struct gadget 
*g)
        return 0;
 }
 
-static void usbg_parse_config_attrs(struct config *c)
+static void usbg_parse_config_attrs(char *cpath, struct config_attrs *c_attrs)
 {
-       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);
+       c_attrs->bMaxPower = usbg_read_dec(cpath, "", "MaxPower");
+       c_attrs->bmAttributes = usbg_read_hex(cpath, "", "bmAttributes");
+}
+
+static void usbg_parse_config_strs(char *cpath, struct config_strs *c_attrs)
+{
+       /* Hardcoded to US English right now*/
+       int lang = LANG_US_ENG;
+       char spath[USBG_MAX_PATH_LENGTH];
+
+       sprintf(spath, "%s/%s/0x%x", cpath, STRINGS_DIR, lang);
+       usbg_read_string(spath, "", "configuration", c_attrs->configuration);
 }
 
 static void usbg_parse_config_bindings(struct config *c)
@@ -329,7 +338,8 @@ static int usbg_parse_configs(char *path, struct gadget *g)
                c->parent = g;
                strcpy(c->name, dent[i]->d_name);
                strcpy(c->path, cpath);
-               usbg_parse_config_attrs(c);
+               usbg_parse_config_attrs(cpath, &c->attrs);
+               usbg_parse_config_strs(cpath, &c->strs);
                usbg_parse_config_bindings(c);
                TAILQ_INSERT_TAIL(&g->configs, c, cnode);
                free(dent[i]);
@@ -897,23 +907,24 @@ struct config *usbg_create_config(struct gadget *g, char 
*name)
                return NULL;
        }
 
-       usbg_parse_config_attrs(c);
+       usbg_parse_config_attrs(cpath, &c->attrs);
+       usbg_parse_config_strs(cpath, &c->strs);
 
        INSERT_TAILQ_STRING_ORDER(&g->configs, chead, name, c, cnode);
 
        return c;
 }
 
-void usbg_set_config_max_power(struct config *c, int maxpower)
+void usbg_set_config_max_power(struct config *c, int bMaxPower)
 {
-       c->maxpower = maxpower;
-       usbg_write_dec(c->path, c->name, "MaxPower", maxpower);
+       c->attrs.bMaxPower = bMaxPower;
+       usbg_write_dec(c->path, c->name, "MaxPower", bMaxPower);
 }
 
-void usbg_set_config_bm_attrs(struct config *c, int bmattrs)
+void usbg_set_config_bm_attrs(struct config *c, int bmAttributes)
 {
-       c->bmattrs = bmattrs;
-       usbg_write_hex8(c->path, c->name, "bmAttributes", bmattrs);
+       c->attrs.bmAttributes = bmAttributes;
+       usbg_write_hex8(c->path, c->name, "bmAttributes", bmAttributes);
 }
 
 void usbg_set_config_string(struct config *c, int lang, char *str)
@@ -926,7 +937,7 @@ void usbg_set_config_string(struct config *c, int lang, 
char *str)
 
        /* strings in library are hardcoded to US English for now */
        if (lang == LANG_US_ENG) {
-               strcpy(c->str_cfg, str);
+               strcpy(c->strs.configuration, str);
        }
 
        usbg_write_string(path, "", "configuration", str);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to