summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usbg/usbg.h5
-rw-r--r--src/usbg.c77
2 files changed, 56 insertions, 26 deletions
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 1bb652e..ae53d22 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -189,6 +189,7 @@ typedef enum {
USBG_ERROR_EXIST = -6,
USBG_ERROR_NO_DEV = -7,
USBG_ERROR_BUSY = -8,
+ USBG_ERROR_NOT_SUPPORTED = -9,
USBG_ERROR_OTHER_ERROR = -99
} usbg_error;
@@ -641,9 +642,9 @@ 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 Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success usbg_error if error occurred.
*/
-extern usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
+extern int usbg_get_function_attrs(usbg_function *f,
usbg_function_attrs *f_attrs);
/**
diff --git a/src/usbg.c b/src/usbg.c
index f97ad1d..3589dd0 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -365,43 +365,76 @@ static void usbg_free_state(usbg_state *s)
free(s);
}
-
-static void usbg_parse_function_attrs(usbg_function *f,
+static int usbg_parse_function_net_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
{
struct ether_addr *addr;
char str_addr[40];
+ int ret;
+
+ ret = usbg_read_string(f->path, f->name, "dev_addr", str_addr);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ addr = ether_aton(str_addr);
+ if (addr) {
+ f_attrs->net.dev_addr = *addr;
+ } else {
+ ret = USBG_ERROR_IO;
+ goto out;
+ }
+
+ ret = usbg_read_string(f->path, f->name, "host_addr", str_addr);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ addr = ether_aton(str_addr);
+ if (addr) {
+ f_attrs->net.host_addr = *addr;
+ } else {
+ ret = USBG_ERROR_IO;
+ goto out;
+ }
+
+ ret = usbg_read_string(f->path, f->name, "ifname", f_attrs->net.ifname);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_read_dec(f->path, f->name, "qmult", &(f_attrs->net.qmult));
+
+out:
+ return ret;
+}
+
+static int usbg_parse_function_attrs(usbg_function *f,
+ usbg_function_attrs *f_attrs)
+{
+ int ret;
switch (f->type) {
case F_SERIAL:
case F_ACM:
case F_OBEX:
- usbg_read_dec(f->path, f->name, "port_num", &(f_attrs->serial.port_num));
+ ret = usbg_read_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:
- usbg_read_string(f->path, f->name, "dev_addr", str_addr);
- addr = ether_aton(str_addr);
- if (addr)
- f_attrs->net.dev_addr = *addr;
-
- usbg_read_string(f->path, f->name, "host_addr", str_addr);
- addr = ether_aton(str_addr);
- if(addr)
- f_attrs->net.host_addr = *addr;
-
- usbg_read_string(f->path, f->name, "ifname", f_attrs->net.ifname);
- usbg_read_dec(f->path, f->name, "qmult", &(f_attrs->net.qmult));
+ ret = usbg_parse_function_net_attrs(f, f_attrs);
break;
case F_PHONET:
- usbg_read_string(f->path, f->name, "ifname", f_attrs->phonet.ifname);
+ ret = usbg_read_string(f->path, f->name, "ifname",
+ f_attrs->phonet.ifname);
break;
default:
ERROR("Unsupported function type\n");
+ ret = USBG_ERROR_NOT_SUPPORTED;
}
+
+ return ret;
}
static int usbg_parse_functions(char *path, usbg_gadget *g)
@@ -1516,15 +1549,10 @@ usbg_function_type usbg_get_function_type(usbg_function *f)
return f->type;
}
-usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
- usbg_function_attrs *f_attrs)
+int usbg_get_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
{
- if (f && f_attrs)
- usbg_parse_function_attrs(f, f_attrs);
- else
- f_attrs = NULL;
-
- return f_attrs;
+ return f && f_attrs ? usbg_parse_function_attrs(f, f_attrs)
+ : USBG_ERROR_INVALID_PARAM;
}
int usbg_set_function_net_attrs(usbg_function *f, usbg_f_net_attrs *attrs)
@@ -1577,6 +1605,7 @@ int usbg_set_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
break;
default:
ERROR("Unsupported function type\n");
+ ret = USBG_ERROR_NOT_SUPPORTED;
}
return ret;