summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Agner <stefan.agner@toradex.com>2017-01-24 14:22:08 -0800
committerKrzysztof Opasiak <k.opasiak@samsung.com>2017-12-12 14:06:36 +0100
commit996c322af13f9b3f8e34b17323cdd5120473b13d (patch)
tree78efbab4bfb5bcfa239268150c1093eab52c406f /src
parentad44340734fa3bb97c4472c6b004fa4ebdab335b (diff)
downloadlibusbg-996c322af13f9b3f8e34b17323cdd5120473b13d.tar.gz
libusbg-996c322af13f9b3f8e34b17323cdd5120473b13d.tar.bz2
libusbg-996c322af13f9b3f8e34b17323cdd5120473b13d.zip
libusbgx: Add OS Descriptors support
This adds OS Descriptors support on Gadget level. It allows to enable OS Descriptors support as well as to define the OS String proper. Signed-off-by: Stefan Agner <stefan.agner@toradex.com> [Remove unused variable] Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/usbg.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/usbg.c b/src/usbg.c
index 3a2c674..1c93f7b 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -98,6 +98,15 @@ const char *gadget_str_names[] =
ARRAY_SIZE_SENTINEL(gadget_str_names, USBG_GADGET_STR_MAX);
+const char *gadget_os_desc_names[] =
+{
+ "use",
+ "b_vendor_code",
+ "qw_sign",
+};
+
+ARRAY_SIZE_SENTINEL(gadget_os_desc_names, USBG_GADGET_OS_DESC_MAX);
+
int usbg_lookup_function_type(const char *name)
{
int i = USBG_FUNCTION_TYPE_MIN;
@@ -167,6 +176,13 @@ const char *usbg_get_gadget_str_name(usbg_gadget_str str)
gadget_str_names[str] : NULL;
}
+const char *usbg_get_gadget_os_desc_name(usbg_gadget_os_desc_strs str)
+{
+ return str >= USBG_GADGET_OS_DESC_MIN &&
+ str < USBG_GADGET_OS_DESC_MAX ?
+ gadget_os_desc_names[str] : NULL;
+}
+
static int usbg_split_function_instance_type(const char *full_name,
usbg_function_type *f_type, const char **instance)
{
@@ -802,6 +818,40 @@ out:
return ret;
}
+static int usbg_parse_gadget_os_descs(const char *path, const char *name,
+ struct usbg_gadget_os_descs *g_os_descs)
+{
+ int ret;
+ int nmb;
+ char spath[USBG_MAX_PATH_LENGTH];
+ int val;
+
+ nmb = snprintf(spath, sizeof(spath), "%s/%s/%s", path, name,
+ OS_DESC_DIR);
+ if (nmb >= sizeof(spath)) {
+ ret = USBG_ERROR_PATH_TOO_LONG;
+ goto out;
+ }
+
+ ret = usbg_read_string_alloc(spath, "", "qw_sign", &g_os_descs->qw_sign);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_read_hex(spath, "", "b_vendor_code", &val);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ g_os_descs->b_vendor_code = (unsigned char)val;
+
+ ret = usbg_read_int(spath, "", "use", 10, &val);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ g_os_descs->use = val ? true : false;
+out:
+ return ret;
+}
+
static inline int usbg_parse_gadget(usbg_gadget *g)
{
int ret;
@@ -1853,6 +1903,48 @@ out:
return ret;
}
+int usbg_get_gadget_os_descs(usbg_gadget *g, struct usbg_gadget_os_descs *g_os_descs)
+{
+ return g && g_os_descs ?
+ usbg_parse_gadget_os_descs(g->path, g->name, g_os_descs)
+ : USBG_ERROR_INVALID_PARAM;
+}
+
+int usbg_set_gadget_os_descs(usbg_gadget *g,
+ const struct usbg_gadget_os_descs *g_os_descs)
+{
+ int ret;
+ int nmb;
+ char spath[USBG_MAX_PATH_LENGTH];
+
+ nmb = snprintf(spath, sizeof(spath), "%s/%s/%s", g->path, g->name,
+ OS_DESC_DIR);
+ if (nmb >= sizeof(spath)) {
+ ret = USBG_ERROR_PATH_TOO_LONG;
+ goto out;
+ }
+
+ ret = usbg_check_dir(spath);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_string(spath, "", "qw_sign", g_os_descs->qw_sign);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_hex8(spath, "", "b_vendor_code",
+ g_os_descs->b_vendor_code);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_dec(spath, "", "use", g_os_descs->use);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+out:
+ return ret;
+}
+
int usbg_create_function(usbg_gadget *g, usbg_function_type type,
const char *instance, void *f_attrs, usbg_function **f)
{