mirror of
https://github.com/linux-usb-gadgets/libusbgx.git
synced 2025-07-24 04:05:05 +03:00
libusbgx: Add functions for get/set function attributes.
Add usbg_get_function_attrs() and usbg_get_function_type() to aviod direct access to function structure members. Add usbg_set_function_attrs() to allow set all function\ attributes with one call. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com> [Port from libusbg and update description] Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
This commit is contained in:
parent
894741889e
commit
42c6bc3e56
3 changed files with 90 additions and 7 deletions
|
@ -51,19 +51,19 @@ int main(void)
|
||||||
usbg_set_gadget_manufacturer(g, LANG_US_ENG, "Foo Inc.");
|
usbg_set_gadget_manufacturer(g, LANG_US_ENG, "Foo Inc.");
|
||||||
usbg_set_gadget_product(g, LANG_US_ENG, "Bar Gadget");
|
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) {
|
if (!f_acm0) {
|
||||||
fprintf(stderr, "Error creating acm0 function\n");
|
fprintf(stderr, "Error creating acm0 function\n");
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
f_acm1 = usbg_create_function(g, F_ACM, "usb1");
|
f_acm1 = usbg_create_function(g, F_ACM, "usb1", NULL);
|
||||||
if (!f_acm1) {
|
if (!f_acm1) {
|
||||||
fprintf(stderr, "Error creating acm1 function\n");
|
fprintf(stderr, "Error creating acm1 function\n");
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
f_ecm = usbg_create_function(g, F_ECM, "usb0");
|
f_ecm = usbg_create_function(g, F_ECM, "usb0", NULL);
|
||||||
if (!f_ecm) {
|
if (!f_ecm) {
|
||||||
fprintf(stderr, "Error creating ecm function\n");
|
fprintf(stderr, "Error creating ecm function\n");
|
||||||
goto out2;
|
goto out2;
|
||||||
|
|
|
@ -441,13 +441,15 @@ extern void usbg_set_gadget_product(struct gadget *g, int lang, char *prd);
|
||||||
/* USB function allocation and configuration */
|
/* 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 g Pointer to gadget
|
||||||
* @param type Type of function
|
* @param type Type of function
|
||||||
* @param instance Function instance name
|
* @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
|
* @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 */
|
/* USB configurations allocation and configuration */
|
||||||
|
|
||||||
|
@ -588,6 +590,30 @@ extern char *usbg_get_gadget_udc(struct gadget *g, char *buf, size_t len);
|
||||||
* USB function-specific attribute configuration
|
* USB function-specific attribute 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
|
* @brief Set USB function network device address
|
||||||
* @param f Pointer to function
|
* @param f Pointer to function
|
||||||
|
|
61
src/usbg.c
61
src/usbg.c
|
@ -832,7 +832,8 @@ void usbg_set_gadget_product(struct gadget *g, int lang, char *prd)
|
||||||
usbg_write_string(path, "", "product", prd);
|
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 fpath[USBG_MAX_PATH_LENGTH];
|
||||||
char name[USBG_MAX_STR_LENGTH];
|
char name[USBG_MAX_STR_LENGTH];
|
||||||
|
@ -871,7 +872,10 @@ struct function *usbg_create_function(struct gadget *g, enum function_type type,
|
||||||
return NULL;
|
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);
|
INSERT_TAILQ_STRING_ORDER(&g->functions, fhead, name, f, fnode);
|
||||||
|
|
||||||
|
@ -1090,6 +1094,59 @@ void usbg_disable_gadget(struct gadget *g)
|
||||||
* USB function-specific attribute configuration
|
* 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)
|
void usbg_set_net_dev_addr(struct function *f, struct ether_addr *dev_addr)
|
||||||
{
|
{
|
||||||
char *str_addr;
|
char *str_addr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue