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);
}
};
/**
+ * @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
*/
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;
};
/**
/**
* @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
return 0;
}
-static void usbg_parse_config_attrs(struct config *c)
+static void usbg_parse_config_attrs(char *path, char *name,
+ 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(path, name, "MaxPower");
+ c_attrs->bmAttributes = usbg_read_hex(path, name, "bmAttributes");
+}
+
+static void usbg_parse_config_strs(char *path, char *name,
+ 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/%s/0x%x", path, name, STRINGS_DIR, lang);
+ usbg_read_string(spath, "", "configuration", c_attrs->configuration);
}
static void usbg_parse_config_bindings(struct config *c)
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->name, &c->attrs);
+ usbg_parse_config_strs(cpath, c->name, &c->strs);
usbg_parse_config_bindings(c);
TAILQ_INSERT_TAIL(&g->configs, c, cnode);
free(dent[i]);
return NULL;
}
- usbg_parse_config_attrs(c);
+ usbg_parse_config_attrs(c->path, c->name, &c->attrs);
+ 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_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)
/* 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);
}