Skip to contentSkip to conversation

f_accessory upstream

PATCH In review rickyniu 4 participants 12 messages Oct 12, 2020 – Oct 21, 2020 USB

lore
Share & tools
lore

rickyniu

author
#0 lore raw

cover f_accessory upstream

Below commit is to add log and send uevent:
0003-ANDROID-usb-f_accessory-send-uevent-for-51-52-reques.patch

Benoit Goby (1):
ANDROID: usb: gadget: f_accessory: Add Android Accessory function

Vijayavardhan Vennapusa (1):
ANDROID: USB: f_accessory: Check dev pointer before decoding ctrl
request

rickyniu (1):
ANDROID: usb: f_accessory: send uevent for 51,52 requests

 drivers/usb/gadget/Kconfig                |   10 +
 drivers/usb/gadget/function/Makefile      |    2 +
 drivers/usb/gadget/function/f_accessory.c | 1388 +++++++++++++++++++++
 include/linux/usb/f_accessory.h           |   23 +
 include/uapi/linux/usb/f_accessory.h      |  146 +++
 5 files changed, 1569 insertions(+)
 create mode 100644 drivers/usb/gadget/function/f_accessory.c
 create mode 100644 include/linux/usb/f_accessory.h
 create mode 100644 include/uapi/linux/usb/f_accessory.h
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
author
#1 lore raw

PATCH 1/3 ANDROID: usb: gadget: f_accessory: Add Android Accessory function

From: Benoit Goby <[email protected]>

USB accessory mode allows users to connect USB host hardware specifically designed for Android-powered devices. The accessories must adhere to the Android accessory protocol outlined in the
http://accessories.android.com documentation. This allows Android devices that cannot act as a USB host to still interact with USB hardware. When an Android device is in USB accessory mode, the attached Android USB accessory acts as the host, provides power to the USB bus, and enumerates connected devices.

[AmitP: Folded following android-4.9 commit changes into this patch
ceb2f0aac624 ("ANDROID: usb: gadget: accessory: Fix section mismatch")
Parts of e27543931009 ("ANDROID: usb: gadget: Fixes and hacks to make android usb gadget compile on 3.8") 1b07ec751563 ("ANDROID: drivers: usb: gadget: 64-bit related type fixes")]

[astrachan: Folded the following changes into this patch:
9d5891d516e2 ("ANDROID: usb: gadget: f_accessory: Add ACCESSORY_SET_AUDIO_MODE control request and ioctl") dc66cfce9622 ("ANDROID: usb: gadget: f_accessory: Add support for HID input devices") 5f1ac9c2871b ("ANDROID: usb: gadget: f_accessory: move userspace interface to uapi") 9a6241722cd8 ("ANDROID: usb: gadget: f_accessory: Enabled Zero Length Packet (ZLP) for acc_write") 31a0ecd5a825 ("ANDROID: usb: gadget: f_accessory: check for accessory device before disconnecting HIDs") 580721fa6cbc ("ANDROID: usb: gadget: f_accessory: Migrate to USB_FUNCTION API")
7f407172fb28 ("ANDROID: usb: gadget: f_accessory: Fix for UsbAccessory clean unbind.") ebc98ac5a22f ("ANDROID: usb: gadget: f_accessory: fix false disconnect due to a signal sent to the reading process") 71c6dc5ffdab ("ANDROID: usb: gadget: f_accessory: assign no-op request complete callbacks") 675047ee68e9 ("ANDROID: usb: gadget: f_accessory: Move gadget functions code")
b2bedaa5c7df ("CHROMIUM: usb: gadget: f_accessory: add .raw_request callback")]

---
 drivers/usb/gadget/Kconfig                |   10 +
 drivers/usb/gadget/function/Makefile      |    2 +
 drivers/usb/gadget/function/f_accessory.c | 1352 +++++++++++++++++++++
 include/linux/usb/f_accessory.h           |   23 +
 include/uapi/linux/usb/f_accessory.h      |  146 +++
 5 files changed, 1533 insertions(+)
 create mode 100644 drivers/usb/gadget/function/f_accessory.c
 create mode 100644 include/linux/usb/f_accessory.h
 create mode 100644 include/uapi/linux/usb/f_accessory.h
drivers/usb/gadget/Kconfig +10 -0
index 02ff850278b1..ef8114720c73 100644
@@ -216,6 +216,9 @@ config USB_F_PRINTER
 config USB_F_TCM
 	tristate
 
+config USB_F_ACC
+	tristate
+
 # this first set of drivers all depend on bulk-capable hardware.
 
 config USB_CONFIGFS
@@ -369,6 +372,13 @@ config USB_CONFIGFS_F_FS
 	  implemented in kernel space (for instance Ethernet, serial or
 	  mass storage) and other are implemented in user space.
 
+config USB_CONFIGFS_F_ACC
+	bool "Accessory gadget"
+	depends on USB_CONFIGFS
+	select USB_F_ACC
+	help
+	  USB gadget Accessory support
+
 config USB_CONFIGFS_F_UAC1
 	bool "Audio Class 1.0"
 	depends on USB_CONFIGFS
drivers/usb/gadget/function/Makefile +2 -0
index 5d3a6cf02218..2305360e5f22 100644
@@ -50,3 +50,5 @@ usb_f_printer-y			:= f_printer.o
 obj-$(CONFIG_USB_F_PRINTER)	+= usb_f_printer.o
 usb_f_tcm-y			:= f_tcm.o
 obj-$(CONFIG_USB_F_TCM)		+= usb_f_tcm.o
+usb_f_accessory-y		:= f_accessory.o
+obj-$(CONFIG_USB_F_ACC)		+= usb_f_accessory.o
drivers/usb/gadget/function/f_accessory.c new file +1352 -0

1,352 lines not on this page · raw message

include/linux/usb/f_accessory.h new file +23 -0
new file mode 100644
index 000000000000..ebe3c4d59309
@@ -0,0 +1,23 @@
+/*
+ * Gadget Function Driver for Android USB accessories
+ *
+ * Copyright (C) 2011 Google, Inc.
+ * Author: Mike Lockwood <[email protected]>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __LINUX_USB_F_ACCESSORY_H
+#define __LINUX_USB_F_ACCESSORY_H
+
+#include <uapi/linux/usb/f_accessory.h>
+
+#endif /* __LINUX_USB_F_ACCESSORY_H */
include/uapi/linux/usb/f_accessory.h new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
2.28.0.1011.ga647a8990f-goog
maintainer
#2 lore raw

Re: [PATCH 1/3] ANDROID: usb: gadget: f_accessory: Add Android Accessory function

Quoted 17 lines · rickyniu

From: Benoit Goby <[email protected]>

USB accessory mode allows users to connect USB host hardware specifically designed for Android-powered devices. The accessories must adhere to the Android accessory protocol outlined in the
http://accessories.android.com documentation. This allows Android devices that cannot act as a USB host to still interact with USB hardware. When an Android device is in USB accessory mode, the attached Android USB accessory acts as the host, provides power to the USB bus, and enumerates connected devices.

[AmitP: Folded following android-4.9 commit changes into this patch
ceb2f0aac624 ("ANDROID: usb: gadget: accessory: Fix section mismatch")
Parts of e27543931009 ("ANDROID: usb: gadget: Fixes and hacks to make android usb gadget compile on 3.8") 1b07ec751563 ("ANDROID: drivers: usb: gadget: 64-bit related type fixes")]

Quoted 12 lines

[astrachan: Folded the following changes into this patch:
9d5891d516e2 ("ANDROID: usb: gadget: f_accessory: Add ACCESSORY_SET_AUDIO_MODE control request and ioctl") dc66cfce9622 ("ANDROID: usb: gadget: f_accessory: Add support for HID input devices") 5f1ac9c2871b ("ANDROID: usb: gadget: f_accessory: move userspace interface to uapi") 9a6241722cd8 ("ANDROID: usb: gadget: f_accessory: Enabled Zero Length Packet (ZLP) for acc_write") 31a0ecd5a825 ("ANDROID: usb: gadget: f_accessory: check for accessory device before disconnecting HIDs") 580721fa6cbc ("ANDROID: usb: gadget: f_accessory: Migrate to USB_FUNCTION API")
7f407172fb28 ("ANDROID: usb: gadget: f_accessory: Fix for UsbAccessory clean unbind.") ebc98ac5a22f ("ANDROID: usb: gadget: f_accessory: fix false disconnect due to a signal sent to the reading process") 71c6dc5ffdab ("ANDROID: usb: gadget: f_accessory: assign no-op request complete callbacks") 675047ee68e9 ("ANDROID: usb: gadget: f_accessory: Move gadget functions code")
b2bedaa5c7df ("CHROMIUM: usb: gadget: f_accessory: add .raw_request callback")]

Those commit ids mean nothing to the linux kernel tree, right?

Please fix up.

greg k-h

maintainer
#3 lore raw

Re: [PATCH 1/3] ANDROID: usb: gadget: f_accessory: Add Android Accessory function

In reply to rickyniu

drivers/usb/gadget/Kconfig config USB_CONFIGFS_F_FS · line 381

Quoted 11 lines · rickyniu
drivers/usb/gadget/Kconfig +7 -0
@@ -369,6 +372,13 @@ config USB_CONFIGFS_F_FS
 	  implemented in kernel space (for instance Ethernet, serial or
 	  mass storage) and other are implemented in user space.
 
+config USB_CONFIGFS_F_ACC
+	bool "Accessory gadget"
+	depends on USB_CONFIGFS
+	select USB_F_ACC
+	help
+	  USB gadget Accessory support
+

We need a real help text here please.

Quoted 19 lines
drivers/usb/gadget/Kconfig +0 -0
 config USB_CONFIGFS_F_UAC1
 	bool "Audio Class 1.0"
 	depends on USB_CONFIGFS
drivers/usb/gadget/function/Makefile +2 -0
index 5d3a6cf02218..2305360e5f22 100644
@@ -50,3 +50,5 @@ usb_f_printer-y			:= f_printer.o
 obj-$(CONFIG_USB_F_PRINTER)	+= usb_f_printer.o
 usb_f_tcm-y			:= f_tcm.o
 obj-$(CONFIG_USB_F_TCM)		+= usb_f_tcm.o
+usb_f_accessory-y		:= f_accessory.o
+obj-$(CONFIG_USB_F_ACC)		+= usb_f_accessory.o
drivers/usb/gadget/function/f_accessory.c new file +0 -0
new file mode 100644
index 000000000000..514eadee1793

drivers/usb/gadget/function/f_accessory.c line 2

Quoted 2 lines
drivers/usb/gadget/function/f_accessory.c new file +2 -0
@@ -0,0 +1,1352 @@
+/*
+ * Gadget Function Driver for Android USB accessories

You didn't run this through checkpatch, did you :(

You need a spdx line here.

drivers/usb/gadget/function/f_accessory.c line 4

Quoted 2 lines
drivers/usb/gadget/function/f_accessory.c new file +2 -0
+ *
+ * Copyright (C) 2011 Google, Inc.

No one has touched this since 2011?

drivers/usb/gadget/function/f_accessory.c line 14

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+ * Author: Mike Lockwood <[email protected]>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.

license boiler-plate text can be removed once you add the correct spdx line.

drivers/usb/gadget/function/f_accessory.c line 19

Quoted 5 lines
drivers/usb/gadget/function/f_accessory.c new file +5 -0
+ *
+ */
+
+/* #define DEBUG */
+/* #define VERBOSE_DEBUG */

Why are these here?

drivers/usb/gadget/function/f_accessory.c line 518

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+static int create_bulk_endpoints(struct acc_dev *dev,
+				struct usb_endpoint_descriptor *in_desc,
+				struct usb_endpoint_descriptor *out_desc)
+{
+	struct usb_composite_dev *cdev = dev->cdev;
+	struct usb_request *req;
+	struct usb_ep *ep;
+	int i;
+
+	DBG(cdev, "create_bulk_endpoints dev: %p\n", dev);

ftrace is your friend, this is not needed.

drivers/usb/gadget/function/f_accessory.c line 522

Quoted 4 lines
drivers/usb/gadget/function/f_accessory.c new file +4 -0
+
+	ep = usb_ep_autoconfig(cdev->gadget, in_desc);
+	if (!ep) {
+		DBG(cdev, "usb_ep_autoconfig for ep_in failed\n");

dev_err()?

drivers/usb/gadget/function/f_accessory.c line 525

Quoted 3 lines
drivers/usb/gadget/function/f_accessory.c new file +3 -0
+		return -ENODEV;
+	}
+	DBG(cdev, "usb_ep_autoconfig for ep_in got %s\n", ep->name);

dev_dbg()?

Quoted 22 lines
drivers/usb/gadget/function/f_accessory.c new file +22 -0
+	ep->driver_data = dev;		/* claim the endpoint */
+	dev->ep_in = ep;
+
+	ep = usb_ep_autoconfig(cdev->gadget, out_desc);
+	if (!ep) {
+		DBG(cdev, "usb_ep_autoconfig for ep_out failed\n");
+		return -ENODEV;
+	}
+	DBG(cdev, "usb_ep_autoconfig for ep_out got %s\n", ep->name);
+	ep->driver_data = dev;		/* claim the endpoint */
+	dev->ep_out = ep;
+
+	/* now allocate requests for our endpoints */
+	for (i = 0; i < TX_REQ_MAX; i++) {
+		req = acc_request_new(dev->ep_in, BULK_BUFFER_SIZE);
+		if (!req)
+			goto fail;
+		req->complete = acc_complete_in;
+		req_put(dev, &dev->tx_idle, req);
+	}
+	for (i = 0; i < RX_REQ_MAX; i++) {
+		req = acc_request_new(dev->ep_out, BULK_BUFFER_SIZE);

drivers/usb/gadget/function/f_accessory.c line 557

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+		if (!req)
+			goto fail;
+		req->complete = acc_complete_out;
+		dev->rx_req[i] = req;
+	}
+
+	return 0;
+
+fail:
+	pr_err("acc_bind() could not allocate requests\n");

dev_err()?

Same goes for all other pr_* calls in this driver.

Quoted 7 lines
drivers/usb/gadget/function/f_accessory.c new file +7 -0
+	while ((req = req_get(dev, &dev->tx_idle)))
+		acc_request_free(req, dev->ep_in);
+	for (i = 0; i < RX_REQ_MAX; i++)
+		acc_request_free(dev->rx_req[i], dev->ep_out);
+	return -1;
+}
+

drivers/usb/gadget/function/f_accessory.c line 574

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+static ssize_t acc_read(struct file *fp, char __user *buf,
+	size_t count, loff_t *pos)
+{
+	struct acc_dev *dev = fp->private_data;
+	struct usb_request *req;
+	ssize_t r = count;
+	unsigned xfer;
+	int ret = 0;
+
+	pr_debug("acc_read(%zu)\n", count);

Again, ftrace is there, please use it and remove all of this type of debugging lines.

Quoted 171 lines
drivers/usb/gadget/function/f_accessory.c new file +171 -0
+
+	if (dev->disconnected) {
+		pr_debug("acc_read disconnected");
+		return -ENODEV;
+	}
+
+	if (count > BULK_BUFFER_SIZE)
+		count = BULK_BUFFER_SIZE;
+
+	/* we will block until we're online */
+	pr_debug("acc_read: waiting for online\n");
+	ret = wait_event_interruptible(dev->read_wq, dev->online);
+	if (ret < 0) {
+		r = ret;
+		goto done;
+	}
+
+	if (dev->rx_done) {
+		// last req cancelled. try to get it.
+		req = dev->rx_req[0];
+		goto copy_data;
+	}
+
+requeue_req:
+	/* queue a request */
+	req = dev->rx_req[0];
+	req->length = count;
+	dev->rx_done = 0;
+	ret = usb_ep_queue(dev->ep_out, req, GFP_KERNEL);
+	if (ret < 0) {
+		r = -EIO;
+		goto done;
+	} else {
+		pr_debug("rx %p queue\n", req);
+	}
+
+	/* wait for a request to complete */
+	ret = wait_event_interruptible(dev->read_wq, dev->rx_done);
+	if (ret < 0) {
+		r = ret;
+		ret = usb_ep_dequeue(dev->ep_out, req);
+		if (ret != 0) {
+			// cancel failed. There can be a data already received.
+			// it will be retrieved in the next read.
+			pr_debug("acc_read: cancelling failed %d", ret);
+		}
+		goto done;
+	}
+
+copy_data:
+	dev->rx_done = 0;
+	if (dev->online) {
+		/* If we got a 0-len packet, throw it back and try again. */
+		if (req->actual == 0)
+			goto requeue_req;
+
+		pr_debug("rx %p %u\n", req, req->actual);
+		xfer = (req->actual < count) ? req->actual : count;
+		r = xfer;
+		if (copy_to_user(buf, req->buf, xfer))
+			r = -EFAULT;
+	} else
+		r = -EIO;
+
+done:
+	pr_debug("acc_read returning %zd\n", r);
+	return r;
+}
+
+static ssize_t acc_write(struct file *fp, const char __user *buf,
+	size_t count, loff_t *pos)
+{
+	struct acc_dev *dev = fp->private_data;
+	struct usb_request *req = 0;
+	ssize_t r = count;
+	unsigned xfer;
+	int ret;
+
+	pr_debug("acc_write(%zu)\n", count);
+
+	if (!dev->online || dev->disconnected) {
+		pr_debug("acc_write disconnected or not online");
+		return -ENODEV;
+	}
+
+	while (count > 0) {
+		if (!dev->online) {
+			pr_debug("acc_write dev->error\n");
+			r = -EIO;
+			break;
+		}
+
+		/* get an idle tx request to use */
+		req = 0;
+		ret = wait_event_interruptible(dev->write_wq,
+			((req = req_get(dev, &dev->tx_idle)) || !dev->online));
+		if (!req) {
+			r = ret;
+			break;
+		}
+
+		if (count > BULK_BUFFER_SIZE) {
+			xfer = BULK_BUFFER_SIZE;
+			/* ZLP, They will be more TX requests so not yet. */
+			req->zero = 0;
+		} else {
+			xfer = count;
+			/* If the data length is a multple of the
+			 * maxpacket size then send a zero length packet(ZLP).
+			*/
+			req->zero = ((xfer % dev->ep_in->maxpacket) == 0);
+		}
+		if (copy_from_user(req->buf, buf, xfer)) {
+			r = -EFAULT;
+			break;
+		}
+
+		req->length = xfer;
+		ret = usb_ep_queue(dev->ep_in, req, GFP_KERNEL);
+		if (ret < 0) {
+			pr_debug("acc_write: xfer error %d\n", ret);
+			r = -EIO;
+			break;
+		}
+
+		buf += xfer;
+		count -= xfer;
+
+		/* zero this so we don't try to free it on error exit */
+		req = 0;
+	}
+
+	if (req)
+		req_put(dev, &dev->tx_idle, req);
+
+	pr_debug("acc_write returning %zd\n", r);
+	return r;
+}
+
+static long acc_ioctl(struct file *fp, unsigned code, unsigned long value)
+{
+	struct acc_dev *dev = fp->private_data;
+	char *src = NULL;
+	int ret;
+
+	switch (code) {
+	case ACCESSORY_GET_STRING_MANUFACTURER:
+		src = dev->manufacturer;
+		break;
+	case ACCESSORY_GET_STRING_MODEL:
+		src = dev->model;
+		break;
+	case ACCESSORY_GET_STRING_DESCRIPTION:
+		src = dev->description;
+		break;
+	case ACCESSORY_GET_STRING_VERSION:
+		src = dev->version;
+		break;
+	case ACCESSORY_GET_STRING_URI:
+		src = dev->uri;
+		break;
+	case ACCESSORY_GET_STRING_SERIAL:
+		src = dev->serial;
+		break;
+	case ACCESSORY_IS_START_REQUESTED:
+		return dev->start_requested;
+	case ACCESSORY_GET_AUDIO_MODE:
+		return dev->audio_mode;
+	}
+	if (!src)
+		return -EINVAL;

drivers/usb/gadget/function/f_accessory.c line 755

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+
+	ret = strlen(src) + 1;
+	if (copy_to_user((void __user *)value, src, ret))
+		ret = -EFAULT;
+	return ret;
+}
+
+static int acc_open(struct inode *ip, struct file *fp)
+{
+	printk(KERN_INFO "acc_open\n");

That's just noisy, did you test this???

drivers/usb/gadget/function/f_accessory.c line 766

Quoted 11 lines
drivers/usb/gadget/function/f_accessory.c new file +11 -0
+	if (atomic_xchg(&_acc_dev->open_excl, 1))
+		return -EBUSY;
+
+	_acc_dev->disconnected = 0;
+	fp->private_data = _acc_dev;
+	return 0;
+}
+
+static int acc_release(struct inode *ip, struct file *fp)
+{
+	printk(KERN_INFO "acc_release\n");

Again, this is wrong.

Quoted 58 lines
drivers/usb/gadget/function/f_accessory.c new file +58 -0
+
+	WARN_ON(!atomic_xchg(&_acc_dev->open_excl, 0));
+	/* indicate that we are disconnected
+	 * still could be online so don't touch online flag
+	 */
+	_acc_dev->disconnected = 1;
+	return 0;
+}
+
+/* file operations for /dev/usb_accessory */
+static const struct file_operations acc_fops = {
+	.owner = THIS_MODULE,
+	.read = acc_read,
+	.write = acc_write,
+	.unlocked_ioctl = acc_ioctl,
+	.open = acc_open,
+	.release = acc_release,
+};
+
+static int acc_hid_probe(struct hid_device *hdev,
+		const struct hid_device_id *id)
+{
+	int ret;
+
+	ret = hid_parse(hdev);
+	if (ret)
+		return ret;
+	return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+}
+
+static struct miscdevice acc_device = {
+	.minor = MISC_DYNAMIC_MINOR,
+	.name = "usb_accessory",
+	.fops = &acc_fops,
+};
+
+static const struct hid_device_id acc_hid_table[] = {
+	{ HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) },
+	{ }
+};
+
+static struct hid_driver acc_hid_driver = {
+	.name = "USB accessory",
+	.id_table = acc_hid_table,
+	.probe = acc_hid_probe,
+};
+
+static void acc_complete_setup_noop(struct usb_ep *ep, struct usb_request *req)
+{
+	/*
+	 * Default no-op function when nothing needs to be done for the
+	 * setup request
+	 */
+}
+
+int acc_ctrlrequest(struct usb_composite_dev *cdev,
+				const struct usb_ctrlrequest *ctrl)
+{

drivers/usb/gadget/function/f_accessory.c line 834

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+	struct acc_dev	*dev = _acc_dev;
+	int	value = -EOPNOTSUPP;
+	struct acc_hid_dev *hid;
+	int offset;
+	u8 b_requestType = ctrl->bRequestType;
+	u8 b_request = ctrl->bRequest;
+	u16	w_index = le16_to_cpu(ctrl->wIndex);
+	u16	w_value = le16_to_cpu(ctrl->wValue);
+	u16	w_length = le16_to_cpu(ctrl->wLength);
+	unsigned long flags;

Odd alignment issues :(

drivers/usb/gadget/function/f_accessory.c line 841

Quoted 7 lines
drivers/usb/gadget/function/f_accessory.c new file +7 -0
+
+/*
+	printk(KERN_INFO "acc_ctrlrequest "
+			"%02x.%02x v%04x i%04x l%u\n",
+			b_requestType, b_request,
+			w_value, w_index, w_length);
+*/

Please remove all debugging code from the driver when you resend this.

thanks,

greg k-h

#4 lore raw

Re: [PATCH 1/3] ANDROID: usb: gadget: f_accessory: Add Android Accessory function

In reply to rickyniu

Hi,

Quoted 1 line · rickyniu

From: Benoit Goby <[email protected]>

missing Signed-off-by for author

Quoted 8 lines

USB accessory mode allows users to connect USB host hardware specifically designed for Android-powered devices. The accessories must adhere to the Android accessory protocol outlined in the
http://accessories.android.com documentation. This allows Android devices that cannot act as a USB host to still interact with USB hardware. When an Android device is in USB accessory mode, the attached Android USB accessory acts as the host, provides power to the USB bus, and enumerates connected devices.

The protocol is still a HID protocol, is it? Why couldn't you use f_hid.c?

Quoted 18 lines

[AmitP: Folded following android-4.9 commit changes into this patch
ceb2f0aac624 ("ANDROID: usb: gadget: accessory: Fix section mismatch")
Parts of e27543931009 ("ANDROID: usb: gadget: Fixes and hacks to make android usb gadget compile on 3.8") 1b07ec751563 ("ANDROID: drivers: usb: gadget: 64-bit related type fixes")]

[astrachan: Folded the following changes into this patch:
9d5891d516e2 ("ANDROID: usb: gadget: f_accessory: Add ACCESSORY_SET_AUDIO_MODE control request and ioctl") dc66cfce9622 ("ANDROID: usb: gadget: f_accessory: Add support for HID input devices") 5f1ac9c2871b ("ANDROID: usb: gadget: f_accessory: move userspace interface to uapi") 9a6241722cd8 ("ANDROID: usb: gadget: f_accessory: Enabled Zero Length Packet (ZLP) for acc_write") 31a0ecd5a825 ("ANDROID: usb: gadget: f_accessory: check for accessory device before disconnecting HIDs") 580721fa6cbc ("ANDROID: usb: gadget: f_accessory: Migrate to USB_FUNCTION API")
7f407172fb28 ("ANDROID: usb: gadget: f_accessory: Fix for UsbAccessory clean unbind.") ebc98ac5a22f ("ANDROID: usb: gadget: f_accessory: fix false disconnect due to a signal sent to the reading process") 71c6dc5ffdab ("ANDROID: usb: gadget: f_accessory: assign no-op request complete callbacks") 675047ee68e9 ("ANDROID: usb: gadget: f_accessory: Move gadget functions code")
b2bedaa5c7df ("CHROMIUM: usb: gadget: f_accessory: add .raw_request callback")]

Quoted 2 lines

We need an actual name here, IIRC.

drivers/usb/gadget/function/f_accessory.c

Quoted 6 lines
drivers/usb/gadget/function/f_accessory.c new file +0 -0
new file mode 100644
index 000000000000..514eadee1793
@@ -0,0 +1,1352 @@

missing SPDX license identifier comment

Quoted 9 lines
drivers/usb/gadget/function/f_accessory.c new file +9 -0
+/*
+ * Gadget Function Driver for Android USB accessories
+ *
+ * Copyright (C) 2011 Google, Inc.
+ * Author: Mike Lockwood <[email protected]>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.

drivers/usb/gadget/function/f_accessory.c line 19

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* #define DEBUG */
+/* #define VERBOSE_DEBUG */

these shouldn't be necessary

Quoted 53 lines
drivers/usb/gadget/function/f_accessory.c new file +52 -0
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/poll.h>
+#include <linux/delay.h>
+#include <linux/wait.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/kthread.h>
+#include <linux/freezer.h>
+
+#include <linux/types.h>
+#include <linux/file.h>
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+
+#include <linux/hid.h>
+#include <linux/hiddev.h>
 
+#include <linux/usb.h>
+#include <linux/usb/ch9.h>
+#include <linux/usb/f_accessory.h>
+
+#include <linux/configfs.h>
+#include <linux/usb/composite.h>
+
+#define MAX_INST_NAME_LEN        40
+#define BULK_BUFFER_SIZE    16384
+#define ACC_STRING_SIZE     256
+
+#define PROTOCOL_VERSION    2
+
+/* String IDs */
+#define INTERFACE_STRING_INDEX	0
+
+/* number of tx and rx requests to allocate */
+#define TX_REQ_MAX 4
+#define RX_REQ_MAX 2
+
+struct acc_hid_dev {
+	struct list_head	list;
+	struct hid_device *hid;
+	struct acc_dev *dev;
+	/* accessory defined ID */
+	int id;
+	/* HID report descriptor */
+	u8 *report_desc;
+	/* length of HID report descriptor */
+	int report_desc_len;
+	/* number of bytes of report_desc we have received so far */
+	int report_desc_offset;
+};
+
+struct acc_dev {

drivers/usb/gadget/function/f_accessory.c line 82

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+	struct usb_function function;
+	struct usb_composite_dev *cdev;
+	spinlock_t lock;
+
+	struct usb_ep *ep_in;
+	struct usb_ep *ep_out;
+
+	/* online indicates state of function_set_alt & function_unbind
+	 * set to 1 when we connect
+	 */

wrong multi-line comment style

Quoted 29 lines
drivers/usb/gadget/function/f_accessory.c new file +29 -0
+	int online:1;
+
+	/* disconnected indicates state of open & release
+	 * Set to 1 when we disconnect.
+	 * Not cleared until our file is closed.
+	 */
+	int disconnected:1;
+
+	/* strings sent by the host */
+	char manufacturer[ACC_STRING_SIZE];
+	char model[ACC_STRING_SIZE];
+	char description[ACC_STRING_SIZE];
+	char version[ACC_STRING_SIZE];
+	char uri[ACC_STRING_SIZE];
+	char serial[ACC_STRING_SIZE];
+
+	/* for acc_complete_set_string */
+	int string_index;
+
+	/* set to 1 if we have a pending start request */
+	int start_requested;
+
+	int audio_mode;
+
+	/* synchronize access to our device file */
+	atomic_t open_excl;
+
+	struct list_head tx_idle;
+

drivers/usb/gadget/function/f_accessory.c line 121

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+	wait_queue_head_t read_wq;
+	wait_queue_head_t write_wq;
+	struct usb_request *rx_req[RX_REQ_MAX];
+	int rx_done;
+
+	/* delayed work for handling ACCESSORY_START */
+	struct delayed_work start_work;
+
+	/* worker for registering and unregistering hid devices */
+	struct work_struct hid_work;

why are these workers needed?

drivers/usb/gadget/function/f_accessory.c line 141

Quoted 9 lines
drivers/usb/gadget/function/f_accessory.c new file +9 -0
+static struct usb_interface_descriptor acc_interface_desc = {
+	.bLength                = USB_DT_INTERFACE_SIZE,
+	.bDescriptorType        = USB_DT_INTERFACE,
+	.bInterfaceNumber       = 0,
+	.bNumEndpoints          = 2,
+	.bInterfaceClass        = USB_CLASS_VENDOR_SPEC,
+	.bInterfaceSubClass     = USB_SUBCLASS_VENDOR_SPEC,
+	.bInterfaceProtocol     = 0,
+};

const?

drivers/usb/gadget/function/f_accessory.c line 149

Quoted 7 lines
drivers/usb/gadget/function/f_accessory.c new file +7 -0
+static struct usb_endpoint_descriptor acc_highspeed_in_desc = {
+	.bLength                = USB_DT_ENDPOINT_SIZE,
+	.bDescriptorType        = USB_DT_ENDPOINT,
+	.bEndpointAddress       = USB_DIR_IN,
+	.bmAttributes           = USB_ENDPOINT_XFER_BULK,
+	.wMaxPacketSize         = __constant_cpu_to_le16(512),
+};

const?

drivers/usb/gadget/function/f_accessory.c line 157

Quoted 7 lines
drivers/usb/gadget/function/f_accessory.c new file +7 -0
+static struct usb_endpoint_descriptor acc_highspeed_out_desc = {
+	.bLength                = USB_DT_ENDPOINT_SIZE,
+	.bDescriptorType        = USB_DT_ENDPOINT,
+	.bEndpointAddress       = USB_DIR_OUT,
+	.bmAttributes           = USB_ENDPOINT_XFER_BULK,
+	.wMaxPacketSize         = __constant_cpu_to_le16(512),
+};

const?

drivers/usb/gadget/function/f_accessory.c line 164

Quoted 6 lines
drivers/usb/gadget/function/f_accessory.c new file +6 -0
+static struct usb_endpoint_descriptor acc_fullspeed_in_desc = {
+	.bLength                = USB_DT_ENDPOINT_SIZE,
+	.bDescriptorType        = USB_DT_ENDPOINT,
+	.bEndpointAddress       = USB_DIR_IN,
+	.bmAttributes           = USB_ENDPOINT_XFER_BULK,
+};

const?

drivers/usb/gadget/function/f_accessory.c line 171

Quoted 6 lines
drivers/usb/gadget/function/f_accessory.c new file +6 -0
+static struct usb_endpoint_descriptor acc_fullspeed_out_desc = {
+	.bLength                = USB_DT_ENDPOINT_SIZE,
+	.bDescriptorType        = USB_DT_ENDPOINT,
+	.bEndpointAddress       = USB_DIR_OUT,
+	.bmAttributes           = USB_ENDPOINT_XFER_BULK,
+};

const?

drivers/usb/gadget/function/f_accessory.c line 178

Quoted 6 lines
drivers/usb/gadget/function/f_accessory.c new file +6 -0
+static struct usb_descriptor_header *fs_acc_descs[] = {
+	(struct usb_descriptor_header *) &acc_interface_desc,
+	(struct usb_descriptor_header *) &acc_fullspeed_in_desc,
+	(struct usb_descriptor_header *) &acc_fullspeed_out_desc,
+	NULL,
+};

const?

drivers/usb/gadget/function/f_accessory.c line 185

Quoted 6 lines
drivers/usb/gadget/function/f_accessory.c new file +6 -0
+static struct usb_descriptor_header *hs_acc_descs[] = {
+	(struct usb_descriptor_header *) &acc_interface_desc,
+	(struct usb_descriptor_header *) &acc_highspeed_in_desc,
+	(struct usb_descriptor_header *) &acc_highspeed_out_desc,
+	NULL,
+};

const?

drivers/usb/gadget/function/f_accessory.c line 203

Quoted 2 lines
drivers/usb/gadget/function/f_accessory.c new file +2 -0
+/* temporary variable used between acc_open() and acc_gadget_bind() */
+static struct acc_dev *_acc_dev;

why?

drivers/usb/gadget/function/f_accessory.c line 213

Quoted 9 lines
drivers/usb/gadget/function/f_accessory.c new file +9 -0
+struct acc_instance {
+	struct usb_function_instance func_inst;
+	const char *name;
+};
+
+static inline struct acc_dev *func_to_dev(struct usb_function *f)
+{
+	return container_of(f, struct acc_dev, function);
+}

this can be a define, but fine :-)

drivers/usb/gadget/function/f_accessory.c line 234

Quoted 3 lines
drivers/usb/gadget/function/f_accessory.c new file +3 -0
+static void acc_request_free(struct usb_request *req, struct usb_ep *ep)
+{
+	if (req) {

why would req ever be NULL here?

Quoted 1 line

+static void req_put(struct acc_dev *dev, struct list_head *head,

how about we use a more descriptive name? Usually this would be called $prefix_enqueue().

Quoted 12 lines
drivers/usb/gadget/function/f_accessory.c new file +12 -0
+		struct usb_request *req)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&dev->lock, flags);
+	list_add_tail(&req->list, head);
+	spin_unlock_irqrestore(&dev->lock, flags);
+}
+
+/* remove a request from the head of a list */
+static struct usb_request *req_get(struct acc_dev *dev, struct list_head *head)
+{

drivers/usb/gadget/function/f_accessory.c line 263

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+	unsigned long flags;
+	struct usb_request *req;
+
+	spin_lock_irqsave(&dev->lock, flags);
+	if (list_empty(head)) {
+		req = 0;
+	} else {
+		req = list_first_entry(head, struct usb_request, list);
+		list_del(&req->list);
+	}

list_first_entry_or_null()?

drivers/usb/gadget/function/f_accessory.c line 278

Quoted 6 lines
drivers/usb/gadget/function/f_accessory.c new file +6 -0
+static void acc_complete_in(struct usb_ep *ep, struct usb_request *req)
+{
+	struct acc_dev *dev = _acc_dev;
+
+	if (req->status == -ESHUTDOWN) {
+		pr_debug("acc_complete_in set disconnected");

yeah, we need something with a dev* for these prints.

Quoted 13 lines
drivers/usb/gadget/function/f_accessory.c new file +13 -0
+static int acc_hid_start(struct hid_device *hid)
+{
+	return 0;
+}
+
+static void acc_hid_stop(struct hid_device *hid)
+{
+}
+
+static int acc_hid_open(struct hid_device *hid)
+{
+	return 0;
+}

drivers/usb/gadget/function/f_accessory.c line 415

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+
+static void acc_hid_close(struct hid_device *hid)
+{
+}
+
+static int acc_hid_raw_request(struct hid_device *hid, unsigned char reportnum,
+	__u8 *buf, size_t len, unsigned char rtype, int reqtype)
+{
+	return 0;
+}

what's with all the unimplemented methods?

Quoted 22 lines
drivers/usb/gadget/function/f_accessory.c new file +22 -0
+static long acc_ioctl(struct file *fp, unsigned code, unsigned long value)
+{
+	struct acc_dev *dev = fp->private_data;
+	char *src = NULL;
+	int ret;
+
+	switch (code) {
+	case ACCESSORY_GET_STRING_MANUFACTURER:
+		src = dev->manufacturer;
+		break;
+	case ACCESSORY_GET_STRING_MODEL:
+		src = dev->model;
+		break;
+	case ACCESSORY_GET_STRING_DESCRIPTION:
+		src = dev->description;
+		break;
+	case ACCESSORY_GET_STRING_VERSION:
+		src = dev->version;
+		break;
+	case ACCESSORY_GET_STRING_URI:
+		src = dev->uri;
+		break;

drivers/usb/gadget/function/f_accessory.c line 745

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+	case ACCESSORY_GET_STRING_SERIAL:
+		src = dev->serial;
+		break;
+	case ACCESSORY_IS_START_REQUESTED:
+		return dev->start_requested;
+	case ACCESSORY_GET_AUDIO_MODE:
+		return dev->audio_mode;
+	}
+	if (!src)
+		return -EINVAL;

add this part as a default on the switch above?

drivers/usb/gadget/function/f_accessory.c line 755

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+
+	ret = strlen(src) + 1;
+	if (copy_to_user((void __user *)value, src, ret))
+		ret = -EFAULT;
+	return ret;
+}
+
+static int acc_open(struct inode *ip, struct file *fp)
+{
+	printk(KERN_INFO "acc_open\n");

no printk() calls!

why couldn't you get your acc_dev from fp->private_data?

drivers/usb/gadget/function/f_accessory.c line 756

Quoted 1 line
drivers/usb/gadget/function/f_accessory.c new file +1 -0
+	if (atomic_xchg(&_acc_dev->open_excl, 1))

do you really need this to be an atomic_t?

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+int acc_ctrlrequest(struct usb_composite_dev *cdev,
+				const struct usb_ctrlrequest *ctrl)
+{
+	struct acc_dev	*dev = _acc_dev;
+	int	value = -EOPNOTSUPP;
+	struct acc_hid_dev *hid;
+	int offset;
+	u8 b_requestType = ctrl->bRequestType;
+	u8 b_request = ctrl->bRequest;
+	u16	w_index = le16_to_cpu(ctrl->wIndex);

drivers/usb/gadget/function/f_accessory.c line 841

Quoted 10 lines
drivers/usb/gadget/function/f_accessory.c new file +10 -0
+	u16	w_value = le16_to_cpu(ctrl->wValue);
+	u16	w_length = le16_to_cpu(ctrl->wLength);
+	unsigned long flags;
+
+/*
+	printk(KERN_INFO "acc_ctrlrequest "
+			"%02x.%02x v%04x i%04x l%u\n",
+			b_requestType, b_request,
+			w_value, w_index, w_length);
+*/

commented out code? Please remove.

drivers/usb/gadget/function/f_accessory.c line 844

Quoted 2 lines
drivers/usb/gadget/function/f_accessory.c new file +2 -0
+	if (b_requestType == (USB_DIR_OUT | USB_TYPE_VENDOR)) {
+		if (b_request == ACCESSORY_START) {

looks like a switch statement is fitting here?

Quoted 1 line

+EXPORT_SYMBOL_GPL(acc_ctrlrequest);

why do you export this for any caller? Who is going to call this?

drivers/usb/gadget/function/f_accessory.c line 1231

Quoted 6 lines
drivers/usb/gadget/function/f_accessory.c new file +6 -0
+void acc_disconnect(void)
+{
+	/* unregister all HID devices if USB is disconnected */
+	kill_all_hid_devices(_acc_dev);
+}
+EXPORT_SYMBOL_GPL(acc_disconnect);

why exported?

Signature · 1 line
balbi
#5 lore raw

Re: [PATCH 1/3] ANDROID: usb: gadget: f_accessory: Add Android Accessory function

In reply to rickyniu
Thank you for the patch! Perhaps something to improve:

Hi rickyniu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on balbi-usb/testing/next]
[also build test WARNING on usb/usb-testing staging/staging-testing linus/master v5.9 next-20201021] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/rickyniu/f_accessory-upstream/20201012-191125
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git testing/next
config: microblaze-randconfig-r021-20201021 (attached as .config)
compiler: microblaze-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/5ede414150565f8adfad89be50312681f7490ff9
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review rickyniu/f_accessory-upstream/20201012-191125 git checkout 5ede414150565f8adfad89be50312681f7490ff9
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=microblaze

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/usb/gadget/function/f_accessory.c:822:5: warning: no previous prototype for 'acc_ctrlrequest' [-Wmissing-prototypes]
     822 | int acc_ctrlrequest(struct usb_composite_dev *cdev,
         |     ^~~~~~~~~~~~~~~
>> drivers/usb/gadget/function/f_accessory.c:1226:6: warning: no previous prototype for 'acc_disconnect' [-Wmissing-prototypes]
    1226 | void acc_disconnect(void)
         |      ^~~~~~~~~~~~~~
   drivers/usb/gadget/function/f_accessory.c: In function 'acc_alloc_inst':
   drivers/usb/gadget/function/f_accessory.c:1297:18: warning: variable 'dev' set but not used [-Wunused-but-set-variable]
    1297 |  struct acc_dev *dev;
         |                  ^~~
   drivers/usb/gadget/function/f_accessory.c: At top level:
>> drivers/usb/gadget/function/f_accessory.c:1324:5: warning: no previous prototype for 'acc_ctrlrequest_configfs' [-Wmissing-prototypes]

1324 | int acc_ctrlrequest_configfs(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
| ^~~~~~~~~~~~~~~~~~~~~~~~

vim +/acc_ctrlrequest +822 drivers/usb/gadget/function/f_accessory.c

821

 > 822	int acc_ctrlrequest(struct usb_composite_dev *cdev,

823 const struct usb_ctrlrequest *ctrl)
824 {
825 struct acc_dev *dev = _acc_dev;
826 int value = -EOPNOTSUPP;
827 struct acc_hid_dev *hid;
828 int offset;
829 u8 b_requestType = ctrl->bRequestType;
830 u8 b_request = ctrl->bRequest;
831 u16 w_index = le16_to_cpu(ctrl->wIndex);
832 u16 w_value = le16_to_cpu(ctrl->wValue);
833 u16 w_length = le16_to_cpu(ctrl->wLength);
834 unsigned long flags;
835

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author
#6 lore raw

PATCH 2/3 ANDROID: USB: f_accessory: Check dev pointer before decoding ctrl request

In reply to rickyniu

From: Vijayavardhan Vennapusa <[email protected]>

In case of poweroff charging mode, accessory function instance is not created and due to this, _acc_dev will be NULL. If target is connected to Accessory dock in poweroff charging mode, there is a chance dev pointer is accessed, which is NULL. Hence add a check before processing control request and return error if it is NULL.

---
 drivers/usb/gadget/function/f_accessory.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/usb/gadget/function/f_accessory.c +6 -0
index 514eadee1793..5ed80940b9bf 100644
@@ -833,6 +833,12 @@ int acc_ctrlrequest(struct usb_composite_dev *cdev,
 	u16	w_length = le16_to_cpu(ctrl->wLength);
 	unsigned long flags;
 
+	/*
+	 * If instance is not created which is the case in power off charging
+	 * mode, dev will be NULL. Hence return error if it is the case.
+	 */
+	if (!dev)
+		return -ENODEV;
 /*
 	printk(KERN_INFO "acc_ctrlrequest "
 			"%02x.%02x v%04x i%04x l%u\n",
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
author
#7 lore raw

PATCH 3/3 ANDROID: usb: f_accessory: send uevent for 51,52 requests

In reply to rickyniu

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.

---
 drivers/usb/gadget/function/f_accessory.c | 30 +++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/usb/gadget/function/f_accessory.c +30 -0
index 5ed80940b9bf..e51cab9246f9 100644
@@ -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;
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
maintainer
#8 lore raw

Re: [PATCH 3/3] ANDROID: usb: f_accessory: send uevent for 51,52 requests

Quoted 5 lines · rickyniu

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.

Is this how you sign legal documents? If so, fine, but no upper case? If not, please fix this series up and resend.

thanks,

greg k-h

maintainer
#9 lore raw

Re: [PATCH 3/3] ANDROID: usb: f_accessory: send uevent for 51,52 requests

In reply to rickyniu
Quoted 27 lines · rickyniu

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.

---
 drivers/usb/gadget/function/f_accessory.c | 30 +++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/usb/gadget/function/f_accessory.c +6 -0
index 5ed80940b9bf..e51cab9246f9 100644
@@ -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;
 

drivers/usb/gadget/function/f_accessory.c int acc_ctrlrequest(struct usb_composite_dev *cdev, · line 859

Quoted 5 lines
drivers/usb/gadget/function/f_accessory.c +2 -0
@@ -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__);

Why is this here?

:(

maintainer
#10 lore raw
In reply to rickyniu
Quoted 2 lines · rickyniu

Below commit is to add log and send uevent:
0003-ANDROID-usb-f_accessory-send-uevent-for-51-52-reques.patch

I don't understand the text in this changelog, what does it mean?

confused,

greg k-h

#11 lore raw
In reply to rickyniu

Hi,

Quoted 2 lines · rickyniu

Below commit is to add log and send uevent:
0003-ANDROID-usb-f_accessory-send-uevent-for-51-52-reques.patch

if you're sending something new...

Quoted 9 lines

Benoit Goby (1):
ANDROID: usb: gadget: f_accessory: Add Android Accessory function

Vijayavardhan Vennapusa (1):
ANDROID: USB: f_accessory: Check dev pointer before decoding ctrl
request

rickyniu (1):
ANDROID: usb: f_accessory: send uevent for 51,52 requests

why do you send me a broken version with two fixes? Send me a single patch. Also, please correct the subject line for the patch to match what's used in the framework. Something like:

usb: gadget: function: add Android Accessory function

should do the trick

Signature · 1 line
balbi