usbg_set_gadget_manufacturer(g, LANG_US_ENG, "Foo Inc.");
usbg_set_gadget_product(g, LANG_US_ENG, "Bar Gadget");
- f_acm0 = usbg_create_function(g, F_ACM, "usb0");
+ f_acm0 = usbg_create_function(g, F_ACM, "usb0", NULL);
if (!f_acm0) {
fprintf(stderr, "Error creating acm0 function\n");
goto out2;
}
- f_acm1 = usbg_create_function(g, F_ACM, "usb1");
+ f_acm1 = usbg_create_function(g, F_ACM, "usb1", NULL);
if (!f_acm1) {
fprintf(stderr, "Error creating acm1 function\n");
goto out2;
}
- f_ecm = usbg_create_function(g, F_ECM, "usb0");
+ f_ecm = usbg_create_function(g, F_ECM, "usb0", NULL);
if (!f_ecm) {
fprintf(stderr, "Error creating ecm function\n");
goto out2;
/* USB function allocation and configuration */
/**
- * @brief Create a new USB gadget function
+ * @brief Create a new USB gadget function and set its attributes
* @param g Pointer to gadget
* @param type Type of function
* @param instance Function instance name
+ * @param f_attrs Function attributes to be set. If NULL setting is omitted.
* @return Pointer to function or NULL if it cannot be created
*/
-extern struct function *usbg_create_function(struct gadget *g, enum function_type type, char *instance);
+extern struct function *usbg_create_function(struct gadget *g, enum function_type type,
+ char *instance, union attrs *f_attrs);
/* USB configurations allocation and configuration */
*/
/**
+ * @brief Get type of given function
+ * @param f Pointer to function
+ * @return Type of function
+ * @warning Pointer to function has to be valid.
+ */
+extern enum function_type usbg_get_function_type(struct function *f);
+
+/**
+ * @brief Get attributes of given function
+ * @param f Pointer to function
+ * @param f_attrs Union to be filled
+ * @return Pointer to filled structure or NULL if error occurred.
+ */
+extern union attrs *usbg_get_function_attrs(struct function *f,
+ union attrs *f_attrs);
+
+/**
+ * @brief Set attributes of given function
+ * @param f Pointer to function
+ * @param f_attrs Attributes to be set
+ */
+extern void usbg_set_function_attrs(struct function *f, union attrs *f_attrs);
+
+/**
* @brief Set USB function network device address
* @param f Pointer to function
* @param addr Pointer to Ethernet address
usbg_write_string(path, "", "product", prd);
}
-struct function *usbg_create_function(struct gadget *g, enum function_type type, char *instance)
+struct function *usbg_create_function(struct gadget *g, enum function_type type,
+ char *instance, union attrs *f_attrs)
{
char fpath[USBG_MAX_PATH_LENGTH];
char name[USBG_MAX_STR_LENGTH];
return NULL;
}
- usbg_parse_function_attrs(f);
+ if (f_attrs)
+ usbg_set_function_attrs(f, f_attrs);
+ else
+ usbg_parse_function_attrs(f);
INSERT_TAILQ_STRING_ORDER(&g->functions, fhead, name, f, fnode);
* USB function-specific attribute configuration
*/
+enum function_type usbg_get_function_type(struct function *f)
+{
+ return f->type;
+}
+
+union attrs *usbg_get_function_attrs(struct function *f, union attrs *f_attrs)
+{
+ if (f && f_attrs)
+ *f_attrs = f->attr;
+ else
+ f_attrs = NULL;
+
+ return f_attrs;
+}
+
+void usbg_set_function_attrs(struct function *f, union attrs *f_attrs)
+{
+ char *addr;
+
+ if (!f || !f_attrs)
+ return;
+
+ f->attr = *f_attrs;
+
+ switch (f->type) {
+ case F_SERIAL:
+ case F_ACM:
+ case F_OBEX:
+ usbg_write_dec(f->path, f->name, "port_num", f_attrs->serial.port_num);
+ break;
+ case F_ECM:
+ case F_SUBSET:
+ case F_NCM:
+ case F_EEM:
+ case F_RNDIS:
+ addr = ether_ntoa(&f_attrs->net.dev_addr);
+ usbg_write_string(f->path, f->name, "dev_addr", addr);
+
+ addr = ether_ntoa(&f_attrs->net.host_addr);
+ usbg_write_string(f->path, f->name, "host_addr", addr);
+
+ usbg_write_string(f->path, f->name, "ifname", f_attrs->net.ifname);
+
+ usbg_write_dec(f->path, f->name, "qmult", f_attrs->net.qmult);
+ break;
+ case F_PHONET:
+ usbg_write_string(f->path, f->name, "ifname", f_attrs->phonet.ifname);
+ break;
+ default:
+ ERROR("Unsupported function type\n");
+ }
+}
+
void usbg_set_net_dev_addr(struct function *f, struct ether_addr *dev_addr)
{
char *str_addr;