2018-05-25 17:25:17 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-23 22:15:55 +08:00
|
|
|
#define LOG_LEVEL CONFIG_USB_DEVICE_LOG_LEVEL
|
|
|
|
#include <logging/log.h>
|
2018-11-02 22:17:09 +08:00
|
|
|
LOG_MODULE_REGISTER(usb_os_desc);
|
2018-05-25 17:25:17 +08:00
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
|
|
|
|
#include <usb/usb_device.h>
|
|
|
|
#include <os_desc.h>
|
|
|
|
|
|
|
|
static struct usb_os_descriptor *os_desc;
|
|
|
|
|
|
|
|
int usb_handle_os_desc(struct usb_setup_packet *setup,
|
|
|
|
s32_t *len, u8_t **data)
|
|
|
|
{
|
2018-11-05 18:46:06 +08:00
|
|
|
LOG_DBG("wValue 0x%x", setup->wValue);
|
2018-05-25 17:25:17 +08:00
|
|
|
|
|
|
|
if (!os_desc) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GET_DESC_TYPE(setup->wValue) == DESC_STRING &&
|
2018-07-10 19:39:34 +08:00
|
|
|
GET_DESC_INDEX(setup->wValue) == USB_OSDESC_STRING_DESC_INDEX) {
|
2018-11-05 18:46:06 +08:00
|
|
|
LOG_DBG("MS OS Descriptor string read");
|
2018-05-25 17:25:17 +08:00
|
|
|
*data = os_desc->string;
|
|
|
|
*len = os_desc->string_len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_handle_os_desc_feature(struct usb_setup_packet *setup,
|
|
|
|
s32_t *len, u8_t **data)
|
|
|
|
{
|
2018-11-05 18:46:06 +08:00
|
|
|
LOG_DBG("bRequest 0x%x", setup->bRequest);
|
2018-05-25 17:25:17 +08:00
|
|
|
|
|
|
|
if (!os_desc) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setup->bRequest == os_desc->vendor_code) {
|
|
|
|
switch (setup->wIndex) {
|
|
|
|
case USB_OSDESC_EXTENDED_COMPAT_ID:
|
2018-11-05 18:46:06 +08:00
|
|
|
LOG_DBG("Handle Compat ID");
|
2018-05-25 17:25:17 +08:00
|
|
|
*data = os_desc->compat_id;
|
|
|
|
*len = os_desc->compat_id_len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register MS OS Descriptors version 1 */
|
|
|
|
void usb_register_os_desc(struct usb_os_descriptor *desc)
|
|
|
|
{
|
|
|
|
os_desc = desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool usb_os_desc_enabled(void)
|
|
|
|
{
|
|
|
|
return !!os_desc;
|
|
|
|
}
|