linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: uvc: default the ctrl request interface offsets
@ 2022-10-10 18:20 Michael Grzeschik
  2022-10-10 20:21 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Grzeschik @ 2022-10-10 18:20 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-media, balbi, laurent.pinchart, kernel

For the userspace it is needed to distinguish between requests for the
control or streaming interface. The userspace would have to parse the
configfs to know which interface index it has to compare the ctrl
requests against. Since the interface numbers are not fixed, e.g. for
composite gadgets, the interface offset depends on the setup.

The kernel has this information when handing over the ctrl request to
the userspace. This patch removes the offset from the interface numbers
and expose the default interface defines in the uapi g_uvc.h.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
 drivers/usb/gadget/function/f_uvc.c | 16 +++++++++++++---
 include/uapi/linux/usb/g_uvc.h      |  3 +++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 6e196e06181ecf..d6e7821c9f3121 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -39,9 +39,6 @@ MODULE_PARM_DESC(trace, "Trace level bitmask");
 
 /* string IDs are assigned dynamically */
 
-#define UVC_STRING_CONTROL_IDX			0
-#define UVC_STRING_STREAMING_IDX		1
-
 static struct usb_string uvc_en_us_strings[] = {
 	/* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */
 	[UVC_STRING_STREAMING_IDX].s = "Video Streaming",
@@ -228,6 +225,8 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
 	struct uvc_device *uvc = to_uvc(f);
 	struct v4l2_event v4l2_event;
 	struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
+	unsigned int interface = le16_to_cpu(ctrl->wIndex) & 0xff;
+	struct usb_ctrlrequest *mctrl;
 
 	if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) {
 		uvcg_info(f, "invalid request type\n");
@@ -248,6 +247,17 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
 	memset(&v4l2_event, 0, sizeof(v4l2_event));
 	v4l2_event.type = UVC_EVENT_SETUP;
 	memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req));
+
+
+	/* check for the interface number, fixup the interface number in
+	 * the ctrl request so the userspace doesn't have to bother with
+	 * offset and configfs parsing
+	 */
+	mctrl = &uvc_event->req;
+	mctrl->wIndex &= ~cpu_to_le16(0xff);
+	if (interface == uvc->streaming_intf)
+		mctrl->wIndex = cpu_to_le16(UVC_STRING_STREAMING_IDX);
+
 	v4l2_event_queue(&uvc->vdev, &v4l2_event);
 
 	return 0;
diff --git a/include/uapi/linux/usb/g_uvc.h b/include/uapi/linux/usb/g_uvc.h
index 652f169a019e7d..8d7824dde1b2f9 100644
--- a/include/uapi/linux/usb/g_uvc.h
+++ b/include/uapi/linux/usb/g_uvc.h
@@ -21,6 +21,9 @@
 #define UVC_EVENT_DATA			(V4L2_EVENT_PRIVATE_START + 5)
 #define UVC_EVENT_LAST			(V4L2_EVENT_PRIVATE_START + 5)
 
+#define UVC_STRING_CONTROL_IDX			0
+#define UVC_STRING_STREAMING_IDX		1
+
 struct uvc_request_data {
 	__s32 length;
 	__u8 data[60];
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: uvc: default the ctrl request interface offsets
  2022-10-10 18:20 [PATCH] usb: gadget: uvc: default the ctrl request interface offsets Michael Grzeschik
@ 2022-10-10 20:21 ` Greg KH
  2022-10-10 21:03   ` Michael Grzeschik
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2022-10-10 20:21 UTC (permalink / raw)
  To: Michael Grzeschik; +Cc: linux-usb, linux-media, balbi, laurent.pinchart, kernel

On Mon, Oct 10, 2022 at 08:20:28PM +0200, Michael Grzeschik wrote:
> For the userspace it is needed to distinguish between requests for the
> control or streaming interface. The userspace would have to parse the
> configfs to know which interface index it has to compare the ctrl
> requests against. Since the interface numbers are not fixed, e.g. for
> composite gadgets, the interface offset depends on the setup.
> 
> The kernel has this information when handing over the ctrl request to
> the userspace. This patch removes the offset from the interface numbers
> and expose the default interface defines in the uapi g_uvc.h.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> ---
>  drivers/usb/gadget/function/f_uvc.c | 16 +++++++++++++---
>  include/uapi/linux/usb/g_uvc.h      |  3 +++
>  2 files changed, 16 insertions(+), 3 deletions(-)

This is a v2, what changed from v1?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: uvc: default the ctrl request interface offsets
  2022-10-10 20:21 ` Greg KH
@ 2022-10-10 21:03   ` Michael Grzeschik
  2022-10-11  6:08     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Grzeschik @ 2022-10-10 21:03 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb, linux-media, balbi, laurent.pinchart, kernel

[-- Attachment #1: Type: text/plain, Size: 1505 bytes --]

On Mon, Oct 10, 2022 at 10:21:35PM +0200, Greg KH wrote:
>On Mon, Oct 10, 2022 at 08:20:28PM +0200, Michael Grzeschik wrote:
>> For the userspace it is needed to distinguish between requests for the
>> control or streaming interface. The userspace would have to parse the
>> configfs to know which interface index it has to compare the ctrl
>> requests against. Since the interface numbers are not fixed, e.g. for
>> composite gadgets, the interface offset depends on the setup.
>>
>> The kernel has this information when handing over the ctrl request to
>> the userspace. This patch removes the offset from the interface numbers
>> and expose the default interface defines in the uapi g_uvc.h.
>>
>> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>> ---
>>  drivers/usb/gadget/function/f_uvc.c | 16 +++++++++++++---
>>  include/uapi/linux/usb/g_uvc.h      |  3 +++
>>  2 files changed, 16 insertions(+), 3 deletions(-)
>
>This is a v2, what changed from v1?

v1 - v2: - removed the extra variable in struct uvc_event
         - replacing the ctrl request bits in place
	 - included the move of the defualt interface defines to g_uvc.h

Thanks,
Michael

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: uvc: default the ctrl request interface offsets
  2022-10-10 21:03   ` Michael Grzeschik
@ 2022-10-11  6:08     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2022-10-11  6:08 UTC (permalink / raw)
  To: Michael Grzeschik; +Cc: linux-usb, linux-media, balbi, laurent.pinchart, kernel

On Mon, Oct 10, 2022 at 11:03:59PM +0200, Michael Grzeschik wrote:
> On Mon, Oct 10, 2022 at 10:21:35PM +0200, Greg KH wrote:
> > On Mon, Oct 10, 2022 at 08:20:28PM +0200, Michael Grzeschik wrote:
> > > For the userspace it is needed to distinguish between requests for the
> > > control or streaming interface. The userspace would have to parse the
> > > configfs to know which interface index it has to compare the ctrl
> > > requests against. Since the interface numbers are not fixed, e.g. for
> > > composite gadgets, the interface offset depends on the setup.
> > > 
> > > The kernel has this information when handing over the ctrl request to
> > > the userspace. This patch removes the offset from the interface numbers
> > > and expose the default interface defines in the uapi g_uvc.h.
> > > 
> > > Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> > > ---
> > >  drivers/usb/gadget/function/f_uvc.c | 16 +++++++++++++---
> > >  include/uapi/linux/usb/g_uvc.h      |  3 +++
> > >  2 files changed, 16 insertions(+), 3 deletions(-)
> > 
> > This is a v2, what changed from v1?
> 
> v1 - v2: - removed the extra variable in struct uvc_event
>         - replacing the ctrl request bits in place
> 	 - included the move of the defualt interface defines to g_uvc.h

Great, please submit a v3 with that info.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-11  6:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 18:20 [PATCH] usb: gadget: uvc: default the ctrl request interface offsets Michael Grzeschik
2022-10-10 20:21 ` Greg KH
2022-10-10 21:03   ` Michael Grzeschik
2022-10-11  6:08     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).