summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2015-09-21 20:58:18 +0200
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-09-21 20:58:18 +0200
commit8795c2d0ae1ba38b12eaeda56a2aae0c08ba2313 (patch)
treeb07becb7da9514b21a3d59b9fd59c63b7500578e
parent20d09b46a2fe476f861e780440f6e79241179511 (diff)
downloadlibusbg-8795c2d0ae1ba38b12eaeda56a2aae0c08ba2313.tar.gz
libusbg-8795c2d0ae1ba38b12eaeda56a2aae0c08ba2313.tar.bz2
libusbg-8795c2d0ae1ba38b12eaeda56a2aae0c08ba2313.zip
libusbg: Add support for importing/exporting loopback function
Now it is also possible to use loopback function in gadget schemes. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--src/usbg_schemes_libconfig.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/usbg_schemes_libconfig.c b/src/usbg_schemes_libconfig.c
index 0f6a99a..c8944ed 100644
--- a/src/usbg_schemes_libconfig.c
+++ b/src/usbg_schemes_libconfig.c
@@ -485,6 +485,39 @@ out:
return ret;
}
+static int usbg_export_f_loopback_attrs(usbg_f_loopback_attrs *attrs,
+ config_setting_t *root)
+{
+ config_setting_t *node;
+ int cfg_ret;
+ int ret = USBG_ERROR_NO_MEM;
+
+#define ADD_F_LOOPBACK_INT_ATTR(attr, minval) \
+ do { \
+ if ((int)attrs->attr < minval) { \
+ ret = USBG_ERROR_INVALID_VALUE; \
+ goto out; \
+ } \
+ node = config_setting_add(root, #attr, CONFIG_TYPE_INT);\
+ if (!node) \
+ goto out; \
+ cfg_ret = config_setting_set_int(node, attrs->attr); \
+ if (cfg_ret != CONFIG_TRUE) { \
+ ret = USBG_ERROR_OTHER_ERROR; \
+ goto out; \
+ } \
+ } while (0)
+
+ ADD_F_LOOPBACK_INT_ATTR(buflen, 0);
+ ADD_F_LOOPBACK_INT_ATTR(qlen, 0);
+
+#undef ADD_F_LOOPBACK_INT_ATTR
+
+ ret = USBG_SUCCESS;
+out:
+ return ret;
+}
+
static int usbg_export_function_attrs(usbg_function *f, config_setting_t *root)
{
config_setting_t *node;
@@ -520,6 +553,10 @@ static int usbg_export_function_attrs(usbg_function *f, config_setting_t *root)
ret = usbg_export_f_midi_attrs(&f_attrs.attrs.midi, root);
break;
+ case USBG_F_ATTRS_LOOPBACK:
+ ret = usbg_export_f_loopback_attrs(&f_attrs.attrs.loopback, root);
+ break;
+
case USBG_F_ATTRS_PHONET:
/* Don't export ifname because it is read only */
case USBG_F_ATTRS_FFS:
@@ -1191,6 +1228,45 @@ out:
return ret;
}
+static int usbg_import_f_loopback_attrs(config_setting_t *root, usbg_function *f)
+{
+ config_setting_t *node;
+ int ret = USBG_ERROR_NO_MEM;
+ int tmp;
+ usbg_function_attrs attrs;
+ usbg_f_loopback_attrs *loopback_attrs = &attrs.attrs.loopback;
+
+ attrs.header.attrs_type = USBG_F_ATTRS_LOOPBACK;
+
+#define ADD_F_LOOPBACK_INT_ATTR(attr, defval, minval) \
+ do { \
+ node = config_setting_get_member(root, #attr); \
+ if (node) { \
+ if (!usbg_config_is_int(node)) { \
+ ret = USBG_ERROR_INVALID_TYPE; \
+ goto out; \
+ } \
+ tmp = config_setting_get_int(node); \
+ if (tmp < minval) { \
+ ret = USBG_ERROR_INVALID_VALUE; \
+ goto out; \
+ } \
+ loopback_attrs->attr = tmp; \
+ } else { \
+ loopback_attrs->attr = defval; \
+ } \
+ } while (0)
+
+ ADD_F_LOOPBACK_INT_ATTR(buflen, 4096, 0);
+ ADD_F_LOOPBACK_INT_ATTR(qlen, 32, 0);
+
+#undef ADD_F_LOOPBACK_INT_ATTR
+
+ ret = usbg_set_function_attrs(f, &attrs);
+out:
+ return ret;
+}
+
static int usbg_import_function_attrs(config_setting_t *root, usbg_function *f)
{
int ret = USBG_SUCCESS;
@@ -1228,6 +1304,10 @@ static int usbg_import_function_attrs(config_setting_t *root, usbg_function *f)
ret = usbg_import_f_midi_attrs(root, f);
break;
+ case USBG_F_ATTRS_LOOPBACK:
+ ret = usbg_import_f_loopback_attrs(root, f);
+ break;
+
default:
ERROR("Unsupported function type\n");
ret = USBG_ERROR_NOT_SUPPORTED;