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.opasiak@xxxxxxxxxxx> --- examples/gadget-acm-ecm.c | 2 +- include/usbg/usbg.h | 40 +++++++++++++++++++++++++++++++++- src/usbg.c | 53 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 90 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 847d536..458bb6d 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 87121d0..79e7df0 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -861,7 +861,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; @@ -898,14 +899,43 @@ struct config *usbg_create_config(struct gadget *g, char *name) return NULL; } - usbg_parse_config_attrs(c->path, c->name, &c->attrs); - usbg_parse_config_strs(c->path, c->name, &c->strs); + if (c_attrs) + usbg_set_config_attrs(c, c_attrs); + else + usbg_parse_config_attrs(c->path, c->name, &c->attrs); + + if (c_strs) + usbg_set_config_string(c, LANG_US_ENG, c_strs->configuration); + else + usbg_parse_config_strs(c->path, c->name, &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; @@ -918,6 +948,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 majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html