Skip to content

Commit b9fa4dd

Browse files
author
Josuah Demangeon
committed
usb: host: uvc: loop through every descriptor
Loop through each of the VideoStreaming and VideoControl descriptor to parse them. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent c872246 commit b9fa4dd

File tree

1 file changed

+87
-11
lines changed

1 file changed

+87
-11
lines changed

subsys/usb/host/class/usbh_uvc.c

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
LOG_MODULE_REGISTER(usbh_uvc, CONFIG_USBH_VIDEO_LOG_LEVEL);
3535

36-
struct usbh_uvc_config {
37-
struct usbh_contex *uhs_ctx;
36+
struct usbh_uvc_data {
37+
int todo;
3838
};
3939

4040
static int usbh_uvc_request(struct usbh_contex *const uhs_ctx, struct uhc_transfer *const xfer,
@@ -45,28 +45,104 @@ static int usbh_uvc_request(struct usbh_contex *const uhs_ctx, struct uhc_transf
4545
return 0;
4646
}
4747

48+
static int usbh_uvc_parse_control_desc(struct usbh_contex *const uhs_ctx,
49+
struct usbh_uvc_data *const uvc,
50+
struct usb_if_descriptor *const if_control)
51+
{
52+
struct uvc_if_descriptor *desc = (void *)if_control;
53+
54+
LOG_INF("%s", __func__);
55+
56+
while (desc->bLength != 0) {
57+
/* Skip the interface descriptor or switch to the next descriptor */
58+
desc = (void *)((uint8_t *)desc + desc->bLength);
59+
60+
if (desc->bDescriptorType == USB_DESC_INTERFACE ||
61+
desc->bDescriptorType == USB_DESC_INTERFACE_ASSOC ||
62+
desc->bDescriptorType == 0) {
63+
break;
64+
} else if (desc->bDescriptorType == USB_DESC_CS_INTERFACE) {
65+
;
66+
} else if (desc->bDescriptorType == USB_DESC_CS_ENDPOINT) {
67+
;
68+
}
69+
70+
LOG_INF("bLength %u, bDescriptorType %u, bDescriptorSubtype %u",
71+
desc->bDescriptorType, desc->bDescriptorSubtype, desc->bLength);
72+
}
73+
74+
return 0;
75+
}
76+
77+
static int usbh_uvc_parse_streaming_desc(struct usbh_contex *const uhs_ctx,
78+
struct usbh_uvc_data *const uvc,
79+
struct usb_if_descriptor *const if_streaming)
80+
{
81+
struct uvc_if_descriptor *desc = (void *)if_streaming;
82+
83+
LOG_INF("%s", __func__);
84+
85+
while (desc->bLength != 0) {
86+
/* Skip the interface descriptor or switch to the next descriptor */
87+
desc = (void *)((uint8_t *)desc + desc->bLength);
88+
89+
if (desc->bDescriptorType == USB_DESC_INTERFACE ||
90+
desc->bDescriptorType == USB_DESC_INTERFACE_ASSOC ||
91+
desc->bDescriptorType == 0) {
92+
break;
93+
} else if (desc->bDescriptorType == USB_DESC_CS_INTERFACE) {
94+
;
95+
} else if (desc->bDescriptorType == USB_DESC_CS_ENDPOINT) {
96+
;
97+
}
98+
99+
LOG_INF("bLength %u, bDescriptorType %u, bDescriptorSubtype %u",
100+
desc->bDescriptorType, desc->bDescriptorSubtype, desc->bLength);
101+
}
102+
103+
return 0;
104+
}
105+
48106
static int usbh_uvc_connected(struct usbh_contex *const uhs_ctx)
49107
{
50108
struct usb_device *const udev = uhs_ctx->root;
51-
const size_t len = 512;
52-
struct net_buf *buf;
109+
struct usbh_uvc_data *const uvc = NULL;
110+
struct usb_if_descriptor *if_control;
111+
struct usb_if_descriptor *if_streaming;
53112
int ret;
54113

55114
LOG_INF("%p", uhs_ctx);
56115

57-
buf = usbh_xfer_buf_alloc(udev, len);
58-
if (buf == NULL) {
59-
LOG_ERR("Failed to allocate a host transfer buffer");
60-
return -ENOMEM;
116+
/* TODO only scan through the interfaces assigned to this class by usbh_class.c */
117+
for (unsigned int i = 0; udev->ifaces[i].dhp != NULL; i++) {
118+
struct usb_if_descriptor *if_desc = (void *)udev->ifaces[i].dhp;
119+
120+
if (if_desc->bInterfaceClass == USB_BCC_VIDEO &&
121+
if_desc->bInterfaceSubClass == UVC_SC_VIDEOCONTROL) {
122+
if_control = if_desc;
123+
}
124+
125+
if (if_desc->bInterfaceClass == USB_BCC_VIDEO &&
126+
if_desc->bInterfaceSubClass == UVC_SC_VIDEOSTREAMING) {
127+
if_streaming = if_desc;
128+
}
61129
}
62130

63-
ret = usbh_req_desc(udev, USB_DESC_DEVICE, 0, 0, len, buf);
131+
if (if_streaming == NULL || if_control == NULL) {
132+
LOG_ERR("Video Streaming %p or Control %p interface missing",
133+
if_streaming, if_control);
134+
return -EINVAL;
135+
}
136+
137+
ret = usbh_uvc_parse_control_desc(uhs_ctx, uvc, if_control);
64138
if (ret != 0) {
65-
LOG_ERR("Failed to request descriptor");
66139
return ret;
67140
}
68141

69-
LOG_HEXDUMP_INF(buf->data, buf->len, "buf");
142+
ret = usbh_uvc_parse_streaming_desc(uhs_ctx, uvc, if_streaming);
143+
if (ret != 0) {
144+
return ret;
145+
}
70146

71147
return 0;
72148
}

0 commit comments

Comments
 (0)