[PATCH 3/3] ANDROID: usb: f_accessory: send uevent for 51,52 requests
From: rickyniu
Date: Mon Oct 12 2020 - 07:10:59 EST
Add more log between accessory device and host to help debug.
Send the uevent when the host gets ctrl_request 51 and 52 to user space.
Let user space know the current connect status.
Signed-off-by: rickyniu <rickyniu@xxxxxxxxxx>
---
drivers/usb/gadget/function/f_accessory.c | 30 +++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/usb/gadget/function/f_accessory.c b/drivers/usb/gadget/function/f_accessory.c
index 5ed80940b9bf..e51cab9246f9 100644
--- a/drivers/usb/gadget/function/f_accessory.c
+++ b/drivers/usb/gadget/function/f_accessory.c
@@ -117,6 +117,12 @@ struct acc_dev {
/* delayed work for handling ACCESSORY_START */
struct delayed_work start_work;
+ /* work for handling ACCESSORY GET PROTOCOL */
+ struct work_struct getprotocol_work;
+
+ /* work for handling ACCESSORY SEND STRING */
+ struct work_struct sendstring_work;
+
/* worker for registering and unregistering hid devices */
struct work_struct hid_work;
@@ -849,11 +855,16 @@ int acc_ctrlrequest(struct usb_composite_dev *cdev,
if (b_requestType == (USB_DIR_OUT | USB_TYPE_VENDOR)) {
if (b_request == ACCESSORY_START) {
dev->start_requested = 1;
+ dev_info(&cdev->gadget->dev, "%s: got ACCESSORY_START(53) request\n",
+ __func__);
schedule_delayed_work(
&dev->start_work, msecs_to_jiffies(10));
value = 0;
cdev->req->complete = acc_complete_setup_noop;
} else if (b_request == ACCESSORY_SEND_STRING) {
+ dev_info(&cdev->gadget->dev, "%s: got ACCESSORY_SEND_STRING(52) request\n",
+ __func__);
+ schedule_work(&dev->sendstring_work);
dev->string_index = w_index;
cdev->gadget->ep0->driver_data = dev;
cdev->req->complete = acc_complete_set_string;
@@ -900,6 +911,9 @@ int acc_ctrlrequest(struct usb_composite_dev *cdev,
}
} else if (b_requestType == (USB_DIR_IN | USB_TYPE_VENDOR)) {
if (b_request == ACCESSORY_GET_PROTOCOL) {
+ dev_info(&cdev->gadget->dev, "%s: got ACCESSORY_GET_PROTOCOL(51) request\n",
+ __func__);
+ schedule_work(&dev->getprotocol_work);
*((u16 *)cdev->req->buf) = PROTOCOL_VERSION;
value = sizeof(u16);
cdev->req->complete = acc_complete_setup_noop;
@@ -1047,6 +1061,20 @@ acc_function_unbind(struct usb_configuration *c, struct usb_function *f)
acc_hid_unbind(dev);
}
+static void acc_getprotocol_work(struct work_struct *data)
+{
+ char *envp[2] = { "ACCESSORY=GETPROTOCOL", NULL };
+
+ kobject_uevent_env(&acc_device.this_device->kobj, KOBJ_CHANGE, envp);
+}
+
+static void acc_sendstring_work(struct work_struct *data)
+{
+ char *envp[2] = { "ACCESSORY=SENDSTRING", NULL };
+
+ kobject_uevent_env(&acc_device.this_device->kobj, KOBJ_CHANGE, envp);
+}
+
static void acc_start_work(struct work_struct *data)
{
char *envp[2] = { "ACCESSORY=START", NULL };
@@ -1213,6 +1241,8 @@ static int acc_setup(void)
INIT_LIST_HEAD(&dev->dead_hid_list);
INIT_DELAYED_WORK(&dev->start_work, acc_start_work);
INIT_WORK(&dev->hid_work, acc_hid_work);
+ INIT_WORK(&dev->getprotocol_work, acc_getprotocol_work);
+ INIT_WORK(&dev->sendstring_work, acc_sendstring_work);
/* _acc_dev must be set before calling usb_gadget_register_driver */
_acc_dev = dev;
--
2.28.0.1011.ga647a8990f-goog