summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINSUN PYO <insun.pyo@samsung.com>2020-03-30 04:07:07 (GMT)
committerHyotaek Shim <hyotaek.shim@samsung.com>2020-04-07 01:17:40 (GMT)
commit65079e9b1722bbd03370e53f3e86469bd3eaf9dc (patch)
tree4c105ba7f33711dfb5496c2a9a06390775f4ab8b
parent8de14db8a87d17b6b43972ef13f5faebf6f1ba65 (diff)
downloadlibdevice-node-65079e9b1722bbd03370e53f3e86469bd3eaf9dc.zip
libdevice-node-65079e9b1722bbd03370e53f3e86469bd3eaf9dc.tar.gz
libdevice-node-65079e9b1722bbd03370e53f3e86469bd3eaf9dc.tar.bz2
Rework usb gadget validataionrefs/changes/54/229954/1
On SLP : check if /sys/class/usb_mode/usb0/f_[sdb|mtp|acm|rndis|diag|dm] exists On CFS : check if /usr/lib/systemd/system/[sdb|mpt].service exists or the result of usbg_lookup_function_type() Change-Id: I2cc8acc3553a8734484d50cfc0ede7a963a363b0 (cherry picked from commit 3bb736815986e6433b2a94555c4ceb64b2abea7a)
-rw-r--r--hw/usb_cfs_client_common.c36
-rw-r--r--hw/usb_client_common.c29
2 files changed, 35 insertions, 30 deletions
diff --git a/hw/usb_cfs_client_common.c b/hw/usb_cfs_client_common.c
index fb599df..1e30ab5 100644
--- a/hw/usb_cfs_client_common.c
+++ b/hw/usb_cfs_client_common.c
@@ -96,25 +96,33 @@ static struct usb_function *cfs_find_usb_function(usbg_function *function)
static bool cfs_is_function_supported(struct usb_function *func)
{
- bool res;
- int ret;
+ char buf[PATH_MAX];
+
+ if (func->is_functionfs) {
+ /* functionfs must have a service */
+ if (!func->service)
+ return false;
- if (!func->is_functionfs) {
- ret = usbg_lookup_function_type(func->name);
- res = ret >= 0;
+ snprintf(buf, sizeof(buf), "/usr/lib/systemd/system/%s.socket", func->service);
+ if (access(buf, F_OK))
+ return false;
} else {
- /* TODO: Check if socket is available */
- res = true;
+ if (usbg_lookup_function_type(func->name) < 0)
+ return false;
}
- return res;
+ return true;
}
static bool cfs_is_gadget_supported(struct usb_gadget *gadget)
{
int i, j;
+ struct usb_configuration *config;
+
+ if (!gadget || !gadget->configs || !gadget->configs[0] || !gadget->funcs)
+ return false;
- if (!gadget || !gadget->configs || !gadget->funcs)
+ if (!gadget->attrs.idVendor || !gadget->attrs.idProduct || !gadget->attrs.bcdDevice)
return false;
/* only strings in US_en are allowed */
@@ -124,8 +132,8 @@ static bool cfs_is_gadget_supported(struct usb_gadget *gadget)
if (!gadget->strs.manufacturer || !gadget->strs.product || !gadget->strs.serial)
return false;
- for (j = 0; gadget->configs && gadget->configs[j]; ++j) {
- struct usb_configuration *config = gadget->configs[j];
+ for (j = 0; gadget->configs[j]; ++j) {
+ config = gadget->configs[j];
if (!config->funcs)
return false;
@@ -135,9 +143,6 @@ static bool cfs_is_gadget_supported(struct usb_gadget *gadget)
return false;
}
- if (j == 0)
- return false;
-
return true;
}
@@ -458,6 +463,7 @@ static int cfs_reconfigure_gadget(struct usb_client *usb, struct usb_gadget *gad
if (!usb || !gadget)
return -EINVAL;
+ /* Verify the gadget and check if function is supported */
if (!cfs_is_gadget_supported(gadget))
return -ENOTSUP;
@@ -475,7 +481,7 @@ static int cfs_reconfigure_gadget(struct usb_client *usb, struct usb_gadget *gad
if (ret)
return ret;
- for (i = 0; gadget->configs && gadget->configs[i]; ++i) {
+ for (i = 0; gadget->configs[i]; ++i) {
ret = cfs_set_gadget_config(cfs_client, i + 1, gadget->configs[i]);
if (ret)
return ret;
diff --git a/hw/usb_client_common.c b/hw/usb_client_common.c
index 709d7c0..87a418d 100644
--- a/hw/usb_client_common.c
+++ b/hw/usb_client_common.c
@@ -61,25 +61,26 @@
static bool legacy_is_function_supported(struct usb_function *func)
{
- /*
- * TODO
- * Instead of only checking whether we know this function
- * we should also parse sysfs to check if it is build into
- * slp-gadget.
- */
- if (find_usb_function_by_name(func->name))
- return true;
- else
+ char buf[PATH_MAX];
+
+ snprintf (buf, sizeof(buf), "%s/f_%s", LEGACY_ROOTPATH, func->name);
+ if (access(buf, F_OK))
return false;
+
+ return true;
}
static bool legacy_is_gadget_supported(struct usb_gadget *gadget)
{
int i, j;
+ struct usb_configuration *config;
- if (!gadget || !gadget->configs || !gadget->funcs)
+ if (!gadget || !gadget->configs || !gadget->configs[0] || !gadget->funcs)
return false;
+ if (!gadget->attrs.idVendor || !gadget->attrs.idProduct || !gadget->attrs.bcdDevice)
+ return false;
+
/* only strings in US_en are allowed */
if (gadget->strs.lang_code != DEFAULT_LANG)
return false;
@@ -88,7 +89,7 @@ static bool legacy_is_gadget_supported(struct usb_gadget *gadget)
return false;
for (j = 0; gadget->configs[j]; ++j) {
- struct usb_configuration *config = gadget->configs[j];
+ config = gadget->configs[j];
if (!config->funcs)
return false;
@@ -98,17 +99,14 @@ static bool legacy_is_gadget_supported(struct usb_gadget *gadget)
return false;
}
- if (j == 0 || j > 2)
- return false;
-
return true;
}
/* TODO. Maybe move this to sys ? */
static int legacy_set_int_hex(char *path, int val)
{
- char buf[MAX_GADGET_STR_LEN];
int r;
+ char buf[MAX_GADGET_STR_LEN];
if (!path)
return -EINVAL;
@@ -211,6 +209,7 @@ static int legacy_reconfigure_gadget(struct usb_client *usb, struct usb_gadget *
if (!usb || !gadget)
return -EINVAL;
+ /* Verify the gadget and check if function is supported */
if (!legacy_is_gadget_supported(gadget))
return -ENOTSUP;