Add usbg_set_config_attrs() function to allow setting
all attributes with one call. Add also getter for attrs
to avoid direct accessing of configuration fields.

Add usbg_set_config_strs() to be consistent with gadget
API.

Change usbg_create_config() to allow configuration creation
and attribute setting with one call.

Signed-off-by: Krzysztof Opasiak <k.opas...@samsung.com>
---
 examples/gadget-acm-ecm.c |    2 +-
 include/usbg/usbg.h       |   40 ++++++++++++++++++++++++++++++-
 src/usbg.c                |   57 ++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 94 insertions(+), 5 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 503a64f..a50bf1c 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -69,7 +69,7 @@ int main(void)
                goto out2;
        }
 
-       c = usbg_create_config(g, "c.1");
+       c = usbg_create_config(g, "c.1", NULL, NULL);
        if (!c) {
                fprintf(stderr, "Error creating config\n");
                goto out2;
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index d7933a0..0f3fe4c 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -472,9 +472,29 @@ extern struct function *usbg_create_function(struct gadget 
*g, enum function_typ
  * @brief Create a new USB gadget configuration
  * @param g Pointer to gadget
  * @param name Name of configuration
+ * @param c_attrs Configuration attributes to be set
+ * @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(struct gadget *g, char *name,
+               struct config_attrs *c_attrs, struct config_strs *c_strs);
+
+/**
+ * @brief Set the USB configuration attributes
+ * @param c Pointer to configuration
+ * @param c_attrs Configuration attributes
+ */
+extern void usbg_set_config_attrs(struct config *c,
+               struct config_attrs *c_attrs);
+
+/**
+ * @brief Get the USB configuration strings
+ * @param c Pointer to configuration
+ * @param c_attrs Structure to be filled
+ * @retur Pointer to filled structure or NULL if error occurred.
+ */
+extern struct config_attrs *usbg_get_config_attrs(struct config *c,
+               struct config_attrs *c_attrs);
 
 /**
  * @brief Set the configuration maximum power
@@ -491,6 +511,24 @@ extern void usbg_set_config_max_power(struct config *c, 
int bMaxPower);
 extern void usbg_set_config_bm_attrs(struct config *c, int bmAttributes);
 
 /**
+ * @brief Get the USB configuration strings
+ * @param c Pointer to configuration
+ * @param c_sttrs Structure to be filled
+ * @retur Pointer to filled structure or NULL if error occurred.
+ */
+extern struct config_strs *usbg_get_config_strs(struct config *c,
+               struct config_strs *c_strs);
+
+/**
+ * @brief Set the USB configuration strings
+ * @param c Pointer to configuration
+ * @param lang USB language ID
+ * @param c_sttrs Configuration strings
+ */
+extern void usbg_set_config_strs(struct config *c, int lang,
+               struct config_strs *c_strs);
+
+/**
  * @brief Set the configuration string
  * @param c Pointer to config
  * @param lang USB language ID
diff --git a/src/usbg.c b/src/usbg.c
index d5b57c6..073efd6 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -870,7 +870,8 @@ 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(struct gadget *g, char *name,
+               struct config_attrs *c_attrs, struct config_strs *c_strs)
 {
        char cpath[USBG_MAX_PATH_LENGTH];
        struct config *c;
@@ -907,14 +908,47 @@ struct config *usbg_create_config(struct gadget *g, char 
*name)
                return NULL;
        }
 
-       usbg_parse_config_attrs(cpath, &c->attrs);
-       usbg_parse_config_strs(cpath, &c->strs);
+       if(c_attrs) {
+               usbg_set_config_attrs(c, c_attrs);
+       } else {
+               usbg_parse_config_attrs(cpath, &c->attrs);
+       }
+
+       if(c_strs) {
+               usbg_set_config_string(c, LANG_US_ENG, c_strs->configuration);
+       } else {
+               usbg_parse_config_strs(cpath, &c->strs);
+       }
 
        INSERT_TAILQ_STRING_ORDER(&g->configs, chead, name, c, cnode);
 
        return c;
 }
 
+void usbg_set_config_attrs(struct config *c, struct config_attrs *c_attrs)
+{
+       if(!c || !c_attrs) {
+               return;
+       }
+
+       c->attrs = *c_attrs;
+
+       usbg_write_dec(c->path, c->name, "MaxPower", c_attrs->bMaxPower);
+       usbg_write_hex8(c->path, c->name, "bmAttributes", 
c_attrs->bmAttributes);
+}
+
+struct config_attrs *usbg_get_config_attrs(struct config *c,
+               struct config_attrs *c_attrs)
+{
+       if (c && c_attrs) {
+               *c_attrs = c->attrs;
+       } else {
+               c_attrs = NULL;
+       }
+
+       return c_attrs;
+}
+
 void usbg_set_config_max_power(struct config *c, int bMaxPower)
 {
        c->attrs.bMaxPower = bMaxPower;
@@ -927,6 +961,23 @@ void usbg_set_config_bm_attrs(struct config *c, int 
bmAttributes)
        usbg_write_hex8(c->path, c->name, "bmAttributes", bmAttributes);
 }
 
+struct config_strs *usbg_get_config_strs(struct config *c,
+               struct config_strs *c_strs)
+{
+       if (c && c_strs) {
+               *c_strs = c->strs;
+       } else {
+               c_strs = NULL;
+       }
+       return c_strs;
+}
+
+void usbg_set_config_strs(struct config *c, int lang,
+               struct config_strs *c_strs)
+{
+       usbg_set_config_string(c, lang, c_strs->configuration);
+}
+
 void usbg_set_config_string(struct config *c, int lang, char *str)
 {
        char path[USBG_MAX_PATH_LENGTH];
-- 
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