2018-05-31 21:26:58 +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_bos);
|
2018-05-31 21:26:58 +08:00
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
|
|
|
|
#include <usb/usb_device.h>
|
|
|
|
#include <usb/usb_common.h>
|
|
|
|
|
|
|
|
#include <usb/bos.h>
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
extern const uint8_t __usb_bos_desc_start[];
|
|
|
|
extern const uint8_t __usb_bos_desc_end[];
|
2018-05-31 21:26:58 +08:00
|
|
|
|
2021-02-01 21:37:30 +08:00
|
|
|
USB_DEVICE_BOS_DESC_DEFINE_HDR struct usb_bos_descriptor bos_hdr = {
|
2018-05-31 21:26:58 +08:00
|
|
|
.bLength = sizeof(struct usb_bos_descriptor),
|
|
|
|
.bDescriptorType = USB_BINARY_OBJECT_STORE_DESC,
|
|
|
|
.wTotalLength = 0, /* should be corrected with register */
|
|
|
|
.bNumDeviceCaps = 0, /* should be set with register */
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t usb_bos_get_length(void)
|
|
|
|
{
|
|
|
|
return __usb_bos_desc_end - __usb_bos_desc_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
const void *usb_bos_get_header(void)
|
|
|
|
{
|
|
|
|
return __usb_bos_desc_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_bos_fix_total_length(void)
|
|
|
|
{
|
2021-02-01 21:37:30 +08:00
|
|
|
bos_hdr.wTotalLength = usb_bos_get_length();
|
2018-05-31 21:26:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_bos_register_cap(struct usb_bos_platform_descriptor *desc)
|
|
|
|
{
|
|
|
|
/* Has effect only on first register */
|
2021-02-01 21:37:30 +08:00
|
|
|
bos_hdr.wTotalLength = usb_bos_get_length();
|
2018-05-31 21:26:58 +08:00
|
|
|
|
2021-02-01 21:37:30 +08:00
|
|
|
bos_hdr.bNumDeviceCaps += 1U;
|
2018-05-31 21:26:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int usb_handle_bos(struct usb_setup_packet *setup,
|
2020-05-28 00:26:57 +08:00
|
|
|
int32_t *len, uint8_t **data)
|
2018-05-31 21:26:58 +08:00
|
|
|
{
|
|
|
|
if (GET_DESC_TYPE(setup->wValue) == DESCRIPTOR_TYPE_BOS) {
|
2019-10-01 16:29:02 +08:00
|
|
|
LOG_DBG("Read BOS descriptor");
|
2020-05-28 00:26:57 +08:00
|
|
|
*data = (uint8_t *)usb_bos_get_header();
|
2018-05-31 21:26:58 +08:00
|
|
|
*len = usb_bos_get_length();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|