usb: f_mtp: Handle OS descriptors only when bound
Handle OS descriptors and other Vendor defined requests only when the MTP function is bound. Otherwise MTP responds for setup requests from Windows Hosts when other gadget drivers are active and the host ends up loading the wrong driver. Change-Id: I324d42bd0fab743c7b40d2b119225a6d66781a52 Signed-off-by: Ravi Vembu <raviv@motorola.com> Moto-CRs-fixed: (CR) Reviewed-on: https://gerrit.mot.com/946404 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver <sltawvr@motorola.com> Tested-by: Jira Key <jirakey@motorola.com> Submit-Approved: Jira Key <jirakey@motorola.com> Reviewed-on: https://gerrit.mot.com/1167321 SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Lu Chai <chailu1@motorola.com> Reviewed-by: Jianqi Yang <yangj@motorola.com> Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1262838 Reviewed-by: Huosheng Liao <liaohs@motorola.com> Reviewed-on: https://gerrit.mot.com/1338858 Reviewed-on: https://gerrit.mot.com/1448946 Reviewed-on: https://gerrit.mot.com/1511632 Reviewed-by: Zonghua Liu <a17671@motorola.com> Reviewed-by: Wang Wang <wangwang1@lenovo.com>
This commit is contained in:
1 parent
30b0c9d6fc
commit
e56df2d966
1 file changed
+17
-1
@@ -376,6 +376,7 @@ struct mtp_instance {
|
||||
struct mtp_dev *dev;
|
||||
char mtp_ext_compat_id[16];
|
||||
struct usb_os_desc mtp_os_desc;
|
||||
bool is_bound;
|
||||
};
|
||||
|
||||
/* temporary variable used between mtp_open() and mtp_gadget_bind() */
|
||||
@@ -1443,6 +1444,7 @@ mtp_function_bind(struct usb_configuration *c, struct usb_function *f)
|
||||
}
|
||||
|
||||
fi_mtp->func_inst.f = &dev->function;
|
||||
fi_mtp->is_bound = true;
|
||||
mtp_log("%s speed %s: IN/%s, OUT/%s\n",
|
||||
gadget_is_superspeed(c->cdev->gadget) ? "super" :
|
||||
(gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full"),
|
||||
@@ -1477,6 +1479,7 @@ mtp_function_unbind(struct usb_configuration *c, struct usb_function *f)
|
||||
kfree(f->os_desc_table);
|
||||
f->os_desc_n = 0;
|
||||
fi_mtp->func_inst.f = NULL;
|
||||
fi_mtp->is_bound = false;
|
||||
}
|
||||
|
||||
static int mtp_function_set_alt(struct usb_function *f,
|
||||
@@ -1832,7 +1835,20 @@ static struct usb_function_instance *mtp_alloc_inst(void)
|
||||
static int mtp_ctrlreq_configfs(struct usb_function *f,
|
||||
const struct usb_ctrlrequest *ctrl)
|
||||
{
|
||||
return mtp_ctrlrequest(f->config->cdev, ctrl);
|
||||
struct mtp_instance *fi_mtp =
|
||||
container_of(f->fi, struct mtp_instance, func_inst);
|
||||
|
||||
if (!f || !f->config) {
|
||||
pr_err("%s: Invalid input for %s function\n",
|
||||
__func__, (f && f->name)? f->name : "unknown");
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!fi_mtp || (fi_mtp->is_bound == false))
|
||||
return -EOPNOTSUPP;
|
||||
else
|
||||
return mtp_ctrlrequest(f->config->cdev, ctrl);
|
||||
}
|
||||
|
||||
static void mtp_free(struct usb_function *f)
|
||||
|
||||
Reference in new issue
Block a user