1
0
Fork 0
mirror of https://github.com/linux-usb-gadgets/libusbgx.git synced 2025-07-20 18:05:06 +03:00

libusbgx: Switch to a new function API

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
This commit is contained in:
Krzysztof Opasiak 2015-12-21 22:51:53 +01:00
parent 76214e391a
commit 5637edd558
10 changed files with 89 additions and 543 deletions

View file

@ -195,122 +195,6 @@ typedef enum
USBG_FUNCTION_TYPE_MAX,
} usbg_function_type;
/**
* @typedef usbg_f_serial_attrs
* @brief Attributes for Serial, ACM, and OBEX USB functions
*/
typedef struct {
int port_num;
} usbg_f_serial_attrs;
/**
* @typedef net_attrs
* @brief Attributes for ECM, ECM subset, NCM, EEM, and RNDIS USB functions
*/
typedef struct {
struct ether_addr dev_addr;
struct ether_addr host_addr;
const char *ifname;
int qmult;
} usbg_f_net_attrs;
/**
* @typedef usbg_f_phonet_attrs
* @brief Attributes for the phonet USB function
*/
typedef struct {
const char *ifname;
} usbg_f_phonet_attrs;
/**
* @typedef usbg_f_ffs_attrs
* @brief Attributes for function fs based functions
* @details This is read only and a virtual attribute, it is non present
* on config fs.
*/
typedef struct {
const char *dev_name;
} usbg_f_ffs_attrs;
/**
* @typedef usbg_f_ms_attrs
* @brief Attributes for mass storage functions
*/
typedef struct {
int id;
bool cdrom;
bool ro;
bool nofua;
bool removable;
const char *filename;
} usbg_f_ms_lun_attrs;
/**
* @typedef usbg_f_ms_attrs
* @brief Attributes for mass storage functions
*/
typedef struct {
bool stall;
int nluns;
usbg_f_ms_lun_attrs **luns;
} usbg_f_ms_attrs;
/**
* @typedef usbg_f_midi_attrs
* @brief Attributes for the MIDI function
*/
typedef struct {
int index;
const char *id;
unsigned int in_ports;
unsigned int out_ports;
unsigned int buflen;
unsigned int qlen;
} usbg_f_midi_attrs;
/**
* @typedef usbg_f_loopback_attrs
* @brief Attributes for Loopback function
*/
typedef struct {
unsigned int buflen;
unsigned int qlen;
} usbg_f_loopback_attrs;
/**
* @typedef attrs
* @brief Attributes for a given function type
*/
typedef union {
usbg_f_serial_attrs serial;
usbg_f_net_attrs net;
usbg_f_phonet_attrs phonet;
usbg_f_ffs_attrs ffs;
usbg_f_ms_attrs ms;
usbg_f_midi_attrs midi;
usbg_f_loopback_attrs loopback;
} usbg_f_attrs;
typedef enum {
USBG_F_ATTRS_SERIAL = 1,
USBG_F_ATTRS_NET,
USBG_F_ATTRS_PHONET,
USBG_F_ATTRS_FFS,
USBG_F_ATTRS_MS,
USBG_F_ATTRS_MIDI,
USBG_F_ATTRS_LOOPBACK,
} usbg_f_attrs_type;
typedef struct {
int attrs_type;
} usbg_f_attrs_header;
typedef struct {
usbg_f_attrs_header header;
usbg_f_attrs attrs;
} usbg_function_attrs;
/* Error codes */
/**
@ -745,14 +629,14 @@ extern int usbg_set_gadget_product(usbg_gadget *g, int lang,
* @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.
* @param f_attrs Function specific attributes to be set.
* If NULL setting is omitted.
* @param f Pointer to be filled with pointer to function
* @note Given strings are assumed to be in US English
* @return 0 on success usbg_error if error occurred
*/
extern int usbg_create_function(usbg_gadget *g, usbg_function_type type,
const char *instance, const usbg_function_attrs *f_attrs,
usbg_function **f);
const char *instance, void *f_attrs, usbg_function **f);
/**
* @brief Get function instance name
@ -794,13 +678,6 @@ extern const char *usbg_get_function_type_str(usbg_function_type type);
*/
extern int usbg_lookup_function_type(const char *name);
/**
* @brief Lookup attrs type for given type of function
* @param f_type type of functions
* @return Attributes type for this type of function
*/
extern int usbg_lookup_function_attrs_type(int f_type);
/**
* @brief Cleanup content of function attributes
* @param f_attrs function attributes which should be cleaned up.
@ -809,7 +686,35 @@ extern int usbg_lookup_function_attrs_type(int f_type);
* @warning None of attributes in passed structure should be
* accessed after returning from this function.
*/
extern void usbg_cleanup_function_attrs(usbg_function_attrs *f_attrs);
extern void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs);
/**
* @brief Get type of given function
* @param f Pointer to function
* @return usbg_function_type (0 or above) or
* usbg_error (below 0) if error occurred
*/
extern usbg_function_type usbg_get_function_type(usbg_function *f);
/**
* @brief Get attributes of given function
* @param f Pointer to function
* @param f_attrs Union to be filled
* @return 0 on success usbg_error if error occurred.
* @warning memory pointed by f_attrs should be big enough to hold attributes
* specific for given function type. This function can by dangerous.
* That's why it is strongly recomended to use set/get function provided
* by each function type.
*/
extern int usbg_get_function_attrs(usbg_function *f, void *f_attrs);
/**
* @brief Set attributes of given function
* @param f Pointer to function
* @param f_attrs Attributes to be set
* @return 0 on success, usbg_error if error occurred
*/
extern int usbg_set_function_attrs(usbg_function *f, void *f_attrs);
/* USB configurations allocation and configuration */
@ -1025,60 +930,6 @@ extern usbg_udc *usbg_get_gadget_udc(usbg_gadget *g);
*/
extern usbg_gadget *usbg_get_udc_gadget(usbg_udc *u);
/*
* USB function-specific attribute configuration
*/
/**
* @brief Get type of given function
* @param f Pointer to function
* @return usbg_function_type (0 or above) or
* usbg_error (below 0) if error occurred
*/
extern usbg_function_type usbg_get_function_type(usbg_function *f);
/**
* @brief Get attributes of given function
* @param f Pointer to function
* @param f_attrs Union to be filled
* @return 0 on success usbg_error if error occurred.
*/
extern int usbg_get_function_attrs(usbg_function *f,
usbg_function_attrs *f_attrs);
/**
* @brief Set attributes of given function
* @param f Pointer to function
* @param f_attrs Attributes to be set
* @return 0 on success, usbg_error if error occurred
*/
extern int usbg_set_function_attrs(usbg_function *f,
const usbg_function_attrs *f_attrs);
/**
* @brief Set USB function network device address
* @param f Pointer to function
* @param addr Pointer to Ethernet address
* @return 0 on success, usbg_error if error occurred
*/
extern int usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *addr);
/**
* @brief Set USB function network host address
* @param f Pointer to function
* @param addr Pointer to Ethernet address
* @return 0 on success, usbg_error if error occurred
*/
extern int usbg_set_net_host_addr(usbg_function *f, struct ether_addr *addr);
/**
* @brief Set USB function network qmult
* @param f Pointer to function
* @param qmult Queue length multiplier
* @return 0 on success, usbg_error if error occurred
*/
extern int usbg_set_net_qmult(usbg_function *f, int qmult);
/**
* @def usbg_for_each_gadget(g, s)
* Iterates over each gadget
@ -1248,6 +1099,7 @@ extern int usbg_import_function(usbg_gadget *g, FILE *stream,
*/
extern int usbg_import_config(usbg_gadget *g, FILE *stream, int id,
usbg_config **c);
/**
* @brief Imports usb gadget from file
* @param s current state of library

View file

@ -65,13 +65,13 @@ struct usbg_function_type
int (*remove)(struct usbg_function *, int);
/* Set the value of all given attributes */
int (*set_attrs)(struct usbg_function *, const usbg_function_attrs *);
int (*set_attrs)(struct usbg_function *, void *);
/* Get the value of all function attributes */
int (*get_attrs)(struct usbg_function *, usbg_function_attrs *);
int (*get_attrs)(struct usbg_function *, void *);
/* Free the additional memory allocated for function attributes */
void (*cleanup_attrs)(struct usbg_function *, usbg_function_attrs *);
void (*cleanup_attrs)(struct usbg_function *, void *);
/* Should import all function attributes from libconfig format */
int (*import)(struct usbg_function *, config_setting_t *);

View file

@ -76,45 +76,27 @@ GENERIC_ALLOC_INST(ether, struct usbg_f_net, func);
GENERIC_FREE_INST(ether, struct usbg_f_net, func);
static int ether_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
static int ether_set_attrs(struct usbg_function *f, void *f_attrs)
{
int ret = USBG_SUCCESS;
const usbg_f_net_attrs *attrs = &f_attrs->attrs.net;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_NET)
return USBG_ERROR_INVALID_PARAM;
const struct usbg_f_net_attrs *attrs = f_attrs;
/* ifname is read only so we accept only empty string for this param */
if (attrs->ifname && attrs->ifname[0])
return USBG_ERROR_INVALID_PARAM;
return usbg_f_net_set_attrs(usbg_to_net_function(f),
(struct usbg_f_net_attrs *)attrs);
return usbg_f_net_set_attrs(usbg_to_net_function(f), attrs);
}
static int ether_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static int ether_get_attrs(struct usbg_function *f, void *f_attrs)
{
int ret;
usbg_f_net_attrs *attrs = &f_attrs->attrs.net;
struct usbg_f_net_attrs *attrs = f_attrs;
ret = usbg_f_net_get_attrs(usbg_to_net_function(f),
(struct usbg_f_net_attrs *)attrs);
if (ret != USBG_SUCCESS)
goto out;
f_attrs->header.attrs_type = USBG_F_ATTRS_NET;
out:
return ret;
return usbg_f_net_get_attrs(usbg_to_net_function(f), attrs);
}
static void ether_cleanup_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static void ether_cleanup_attrs(struct usbg_function *f, void *f_attrs)
{
free((char*)f_attrs->attrs.net.ifname);
f_attrs->attrs.net.ifname = NULL;
usbg_f_net_cleanup_attrs(f_attrs);
}
#ifdef HAS_LIBCONFIG

View file

@ -27,44 +27,22 @@ GENERIC_ALLOC_INST(ffs, struct usbg_f_fs, func);
GENERIC_FREE_INST(ffs, struct usbg_f_fs, func);
static int ffs_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
static int ffs_set_attrs(struct usbg_function *f, void *f_attrs)
{
const usbg_f_ffs_attrs *ffs_attrs = &(f_attrs->attrs.ffs);
int ret = USBG_ERROR_INVALID_PARAM;
const char *dev_name = *(const char **)f_attrs;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_FFS)
goto out;
ret = ffs_attrs->dev_name && ffs_attrs->dev_name[0] ?
USBG_ERROR_INVALID_PARAM : USBG_SUCCESS;
out:
return ret;
return dev_name && dev_name[0] ? USBG_ERROR_INVALID_PARAM
: USBG_SUCCESS;
}
static int ffs_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static int ffs_get_attrs(struct usbg_function *f, void *f_attrs)
{
usbg_f_ffs_attrs *ffs_attrs = &(f_attrs->attrs.ffs);
int ret = USBG_SUCCESS;
ret = usbg_f_fs_get_dev_name(usbg_to_fs_function(f),
(char **)&ffs_attrs->dev_name);
if (ret)
goto out;
f_attrs->header.attrs_type = USBG_F_ATTRS_FFS;
out:
return ret;
return usbg_f_fs_get_dev_name(usbg_to_fs_function(f), f_attrs);
}
static void ffs_cleanup_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static void ffs_cleanup_attrs(struct usbg_function *f, void *f_attrs)
{
free((char*)f_attrs->attrs.ffs.dev_name);
f_attrs->attrs.ffs.dev_name = NULL;
free(*(char **)f_attrs);
}
static int ffs_libconfig_import(struct usbg_function *f,

View file

@ -37,33 +37,15 @@ GENERIC_ALLOC_INST(loopback, struct usbg_f_loopback, func);
GENERIC_FREE_INST(loopback, struct usbg_f_loopback, func);
static int loopback_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
static int loopback_set_attrs(struct usbg_function *f, void *f_attrs)
{
const usbg_f_loopback_attrs *attrs = &f_attrs->attrs.loopback;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_LOOPBACK)
return USBG_ERROR_INVALID_PARAM;
return usbg_f_loopback_set_attrs(usbg_to_loopback_function(f),
(const struct usbg_f_loopback_attrs *)attrs);
return usbg_f_loopback_set_attrs(usbg_to_loopback_function(f), f_attrs);
}
static int loopback_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static int loopback_get_attrs(struct usbg_function *f, void *f_attrs)
{
int ret;
usbg_f_loopback_attrs *attrs = &f_attrs->attrs.loopback;
ret = usbg_f_loopback_get_attrs(usbg_to_loopback_function(f),
(struct usbg_f_loopback_attrs *)attrs);
if (ret != USBG_SUCCESS)
goto out;
f_attrs->header.attrs_type = USBG_F_ATTRS_LOOPBACK;
out:
return ret;
return usbg_f_loopback_get_attrs(usbg_to_loopback_function(f), f_attrs);
}
#ifdef HAS_LIBCONFIG

View file

@ -66,40 +66,19 @@ GENERIC_ALLOC_INST(midi, struct usbg_f_midi, func);
GENERIC_FREE_INST(midi, struct usbg_f_midi, func);
static int midi_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
static int midi_set_attrs(struct usbg_function *f, void *f_attrs)
{
const usbg_f_midi_attrs *attrs = &f_attrs->attrs.midi;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_MIDI)
return USBG_ERROR_INVALID_PARAM;
return usbg_f_midi_set_attrs(usbg_to_midi_function(f),
(struct usbg_f_midi_attrs *)attrs);
return usbg_f_midi_set_attrs(usbg_to_midi_function(f), f_attrs);
}
static int midi_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static int midi_get_attrs(struct usbg_function *f, void *f_attrs)
{
int ret;
usbg_f_midi_attrs *attrs = &f_attrs->attrs.midi;
ret = usbg_f_midi_get_attrs(usbg_to_midi_function(f),
(struct usbg_f_midi_attrs *)attrs);
if (ret != USBG_SUCCESS)
goto out;
f_attrs->header.attrs_type = USBG_F_ATTRS_MIDI;
out:
return ret;
return usbg_f_midi_get_attrs(usbg_to_midi_function(f), f_attrs);
}
static void midi_cleanup_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static void midi_cleanup_attrs(struct usbg_function *f, void *f_attrs)
{
free((char*)f_attrs->attrs.midi.id);
f_attrs->attrs.midi.id = NULL;
usbg_f_midi_cleanup_attrs(f_attrs);
}
#ifdef HAS_LIBCONFIG

View file

@ -171,53 +171,21 @@ out:
GENERIC_FREE_INST(ms, struct usbg_f_ms, func);
static int ms_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
static int ms_set_attrs(struct usbg_function *f, void *f_attrs)
{
const usbg_f_ms_attrs *attrs = &f_attrs->attrs.ms;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_MS)
return USBG_ERROR_INVALID_PARAM;
return usbg_f_ms_set_attrs(usbg_to_ms_function(f),
(struct usbg_f_ms_attrs *)attrs);
(struct usbg_f_ms_attrs *)f_attrs);
}
static void ms_cleanup_lun_attrs(usbg_f_ms_lun_attrs *lun_attrs)
static void ms_cleanup_attrs(struct usbg_function *f, void *f_attrs)
{
if (!lun_attrs)
return;
usbg_f_ms_cleanup_lun_attrs((struct usbg_f_ms_lun_attrs *)lun_attrs);
usbg_f_ms_cleanup_attrs((struct usbg_f_ms_attrs *)f_attrs);
}
static void ms_cleanup_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static int ms_get_attrs(struct usbg_function *f, void *f_attrs)
{
int i;
usbg_f_ms_attrs *attrs = &f_attrs->attrs.ms;
usbg_f_ms_cleanup_attrs((struct usbg_f_ms_attrs *)attrs);
}
static int ms_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
{
usbg_f_ms_attrs *attrs = &f_attrs->attrs.ms;
int ret;
ret = usbg_f_ms_get_attrs(usbg_to_ms_function(f),
(struct usbg_f_ms_attrs *)attrs);
if (ret != USBG_SUCCESS)
goto out;
f_attrs->header.attrs_type = USBG_F_ATTRS_MS;
return USBG_SUCCESS;
out:
return ret;
return usbg_f_ms_get_attrs(usbg_to_ms_function(f),
(struct usbg_f_ms_attrs *)f_attrs);
}
#ifdef HAS_LIBCONFIG

View file

@ -27,43 +27,21 @@ GENERIC_ALLOC_INST(phonet, struct usbg_f_phonet, func);
GENERIC_FREE_INST(phonet, struct usbg_f_phonet, func);
static int phonet_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
static int phonet_set_attrs(struct usbg_function *f, void *f_attrs)
{
int ret = USBG_ERROR_INVALID_PARAM;
const usbg_f_phonet_attrs *attrs = &f_attrs->attrs.phonet;
const char *ifname = *(const char **)f_attrs;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_PHONET)
goto out;
ret = attrs->ifname && attrs->ifname[0] ?
USBG_ERROR_INVALID_PARAM : USBG_SUCCESS;
out:
return ret;
return ifname && ifname[0] ? USBG_ERROR_INVALID_PARAM : USBG_SUCCESS;
}
static int phonet_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static int phonet_get_attrs(struct usbg_function *f, void *f_attrs)
{
int ret;
ret = usbg_f_phonet_get_ifname(usbg_to_phonet_function(f),
(char **)&(f_attrs->attrs.phonet.ifname));
if (ret != USBG_SUCCESS)
goto out;
f_attrs->header.attrs_type = USBG_F_ATTRS_PHONET;
out:
return ret;
return usbg_f_phonet_get_ifname(usbg_to_phonet_function(f), f_attrs);
}
static void phonet_cleanup_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static void phonet_cleanup_attrs(struct usbg_function *f, void *f_attrs)
{
free((char*)f_attrs->attrs.phonet.ifname);
f_attrs->attrs.phonet.ifname = NULL;
free(*(char **)f_attrs);
}
static int phonet_libconfig_import(struct usbg_function *f,

View file

@ -26,34 +26,16 @@ GENERIC_ALLOC_INST(serial, struct usbg_f_serial, func);
GENERIC_FREE_INST(serial, struct usbg_f_serial, func);
static int serial_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
static int serial_set_attrs(struct usbg_function *f, void *f_attrs)
{
int ret = USBG_ERROR_INVALID_PARAM;
int port_num = *(int *)f_attrs;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_SERIAL)
goto out;
ret = f_attrs->attrs.serial.port_num ?
USBG_ERROR_INVALID_PARAM : USBG_SUCCESS;
out:
return ret;
return port_num ? USBG_ERROR_INVALID_PARAM : USBG_SUCCESS;
}
static int serial_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
static int serial_get_attrs(struct usbg_function *f, void *f_attrs)
{
int ret;
ret = usbg_f_serial_get_port_num(usbg_to_serial_function(f),
&(f_attrs->attrs.serial.port_num));
if (ret != USBG_SUCCESS)
goto out;
f_attrs->header.attrs_type = USBG_F_ATTRS_SERIAL;
out:
return ret;
return usbg_f_serial_get_port_num(usbg_to_serial_function(f), f_attrs);
}
static int serial_libconfig_import(struct usbg_function *f,

View file

@ -92,45 +92,6 @@ const char *gadget_str_names[] =
ARRAY_SIZE_SENTINEL(gadget_str_names, USBG_GADGET_STR_MAX);
int usbg_lookup_function_attrs_type(int f_type)
{
int ret;
switch (f_type) {
case F_SERIAL:
case F_ACM:
case F_OBEX:
ret = USBG_F_ATTRS_SERIAL;
break;
case F_ECM:
case F_SUBSET:
case F_NCM:
case F_EEM:
case F_RNDIS:
ret = USBG_F_ATTRS_NET;
break;
case F_PHONET:
ret = USBG_F_ATTRS_PHONET;
break;
case F_FFS:
ret = USBG_F_ATTRS_FFS;
break;
case F_MASS_STORAGE:
ret = USBG_F_ATTRS_MS;
break;
case F_MIDI:
ret = USBG_F_ATTRS_MIDI;
break;
case F_LOOPBACK:
ret = USBG_F_ATTRS_LOOPBACK;
break;
default:
ret = USBG_ERROR_NOT_SUPPORTED;
}
return ret;
}
int usbg_lookup_function_type(const char *name)
{
int i = USBG_FUNCTION_TYPE_MIN;
@ -1805,28 +1766,16 @@ int usbg_set_gadget_product(usbg_gadget *g, int lang, const char *prd)
}
int usbg_create_function(usbg_gadget *g, usbg_function_type type,
const char *instance, const usbg_function_attrs *f_attrs,
usbg_function **f)
const char *instance, void *f_attrs, usbg_function **f)
{
char fpath[USBG_MAX_PATH_LENGTH];
usbg_function *func;
int ret = USBG_ERROR_INVALID_PARAM;
int n, free_space;
if (!g || !f)
if (!g || !f || !instance)
return ret;
if (!instance) {
/* If someone creates ffs function and doesn't pass instance name
this means that device name from attrs should be used */
if (type == F_FFS && f_attrs && f_attrs->attrs.ffs.dev_name) {
instance = f_attrs->attrs.ffs.dev_name;
f_attrs = NULL;
} else {
return ret;
}
}
func = usbg_get_function(g, type, instance);
if (func) {
ERROR("duplicate function name\n");
@ -2208,7 +2157,7 @@ int usbg_disable_gadget(usbg_gadget *g)
}
/*
* USB function-specific attribute configuration
* USB function
*/
usbg_function_type usbg_get_function_type(usbg_function *f)
@ -2216,87 +2165,19 @@ usbg_function_type usbg_get_function_type(usbg_function *f)
return f ? f->type : USBG_ERROR_INVALID_PARAM;
}
int usbg_get_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
int usbg_get_function_attrs(usbg_function *f, void *f_attrs)
{
return f && f_attrs ? f->ops->get_attrs(f, f_attrs)
: USBG_ERROR_INVALID_PARAM;
}
static void usbg_cleanup_function_ms_lun_attrs(usbg_f_ms_lun_attrs *lun_attrs)
void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs)
{
if (!lun_attrs)
return;
free((char*)lun_attrs->filename);
lun_attrs->id = -1;
if (f->ops->cleanup_attrs)
f->ops->cleanup_attrs(f, f_attrs);
}
void usbg_cleanup_function_attrs(usbg_function_attrs *f_attrs)
{
usbg_f_attrs *attrs;
if (!f_attrs)
return;
attrs = &f_attrs->attrs;
switch (f_attrs->header.attrs_type) {
case USBG_F_ATTRS_SERIAL:
break;
case USBG_F_ATTRS_NET:
free((char*)attrs->net.ifname);
attrs->net.ifname = NULL;
break;
case USBG_F_ATTRS_PHONET:
free((char*)attrs->phonet.ifname);
attrs->phonet.ifname = NULL;
break;
case USBG_F_ATTRS_FFS:
free((char*)attrs->ffs.dev_name);
attrs->ffs.dev_name = NULL;
break;
case USBG_F_ATTRS_MS:
{
int i;
usbg_f_ms_attrs *ms_attrs = &attrs->ms;
if (!ms_attrs->luns)
goto ms_break;
for (i = 0; i < ms_attrs->nluns; ++i) {
if (!ms_attrs->luns[i])
continue;
usbg_cleanup_function_ms_lun_attrs(ms_attrs->luns[i]);
free(ms_attrs->luns[i]);
}
free(ms_attrs->luns);
ms_attrs->luns = NULL;
ms_attrs->nluns = -1;
ms_break:
break;
}
case USBG_F_ATTRS_MIDI:
free((char*)attrs->midi.id);
attrs->midi.id = NULL;
break;
case USBG_F_ATTRS_LOOPBACK:
break;
default:
ERROR("Unsupported attrs type\n");
break;
}
}
int usbg_set_function_attrs(usbg_function *f,
const usbg_function_attrs *f_attrs)
int usbg_set_function_attrs(usbg_function *f, void *f_attrs)
{
int ret = USBG_ERROR_INVALID_PARAM;
@ -2308,42 +2189,6 @@ out:
return ret;
}
int usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *dev_addr)
{
int ret = USBG_SUCCESS;
if (f && dev_addr) {
char str_buf[USBG_MAX_STR_LENGTH];
char *str_addr = usbg_ether_ntoa_r(dev_addr, str_buf);
ret = usbg_write_string(f->path, f->name, "dev_addr", str_addr);
} else {
ret = USBG_ERROR_INVALID_PARAM;
}
return ret;
}
int usbg_set_net_host_addr(usbg_function *f, struct ether_addr *host_addr)
{
int ret = USBG_SUCCESS;
if (f && host_addr) {
char str_buf[USBG_MAX_STR_LENGTH];
char *str_addr = usbg_ether_ntoa_r(host_addr, str_buf);
ret = usbg_write_string(f->path, f->name, "host_addr", str_addr);
} else {
ret = USBG_ERROR_INVALID_PARAM;
}
return ret;
}
int usbg_set_net_qmult(usbg_function *f, int qmult)
{
return f ? usbg_write_dec(f->path, f->name, "qmult", qmult)
: USBG_ERROR_INVALID_PARAM;
}
usbg_gadget *usbg_get_first_gadget(usbg_state *s)
{
return s ? TAILQ_FIRST(&s->gadgets) : NULL;