1 /*
2  * Copyright (c) 2018 Intel Corporation
3  * Copyright (c) 2023 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef ZEPHYR_INCLUDE_USB_BOS_H_
9 #define ZEPHYR_INCLUDE_USB_BOS_H_
10 
11 #include <stdint.h>
12 
13 /**
14  * @brief USB Binary Device Object Store support
15  * @defgroup usb_bos USB BOS support
16  * @ingroup usb
17  * @{
18  */
19 
20 /**
21  * @brief Helper macro to place the BOS compatibility descriptor
22  *        in the right memory section.
23  */
24 #define USB_DEVICE_BOS_DESC_DEFINE_CAP \
25 	static __in_section(usb, bos_desc_area, 1) __aligned(1) __used
26 
27 /** Device capability type codes */
28 enum usb_bos_capability_types {
29 	USB_BOS_CAPABILITY_EXTENSION = 0x02,
30 	USB_BOS_CAPABILITY_PLATFORM = 0x05,
31 };
32 
33 /** BOS USB 2.0 extension capability descriptor */
34 struct usb_bos_capability_lpm {
35 	uint8_t bLength;
36 	uint8_t bDescriptorType;
37 	uint8_t bDevCapabilityType;
38 	uint32_t bmAttributes;
39 } __packed;
40 
41 /** BOS platform capability descriptor */
42 struct usb_bos_platform_descriptor {
43 	uint8_t bLength;
44 	uint8_t bDescriptorType;
45 	uint8_t bDevCapabilityType;
46 	uint8_t bReserved;
47 	uint8_t PlatformCapabilityUUID[16];
48 } __packed;
49 
50 /** WebUSB specific part of platform capability descriptor */
51 struct usb_bos_capability_webusb {
52 	uint16_t bcdVersion;
53 	uint8_t bVendorCode;
54 	uint8_t iLandingPage;
55 } __packed;
56 
57 /** Microsoft OS 2.0 descriptor specific part of platform capability descriptor */
58 struct usb_bos_capability_msos {
59 	uint32_t dwWindowsVersion;
60 	uint16_t wMSOSDescriptorSetTotalLength;
61 	uint8_t bMS_VendorCode;
62 	uint8_t bAltEnumCode;
63 } __packed;
64 
65 /**
66  * @brief Register BOS capability descriptor
67  *
68  * This function should be used by the application to register BOS capability
69  * descriptors before the USB device stack is enabled.
70  *
71  * @param[in] hdr Pointer to BOS capability descriptor
72  */
73 void usb_bos_register_cap(struct usb_bos_platform_descriptor *hdr);
74 
75 /**
76  * @cond INTERNAL_HIDDEN
77  * Internally used functions
78  */
79 
80 /* BOS Descriptor (root descriptor) */
81 struct usb_bos_descriptor {
82 	uint8_t bLength;
83 	uint8_t bDescriptorType;
84 	uint16_t wTotalLength;
85 	uint8_t bNumDeviceCaps;
86 } __packed;
87 
88 #define USB_DEVICE_BOS_DESC_DEFINE_HDR \
89 	static __in_section(usb, bos_desc_area, 0) __aligned(1) __used
90 
91 size_t usb_bos_get_length(void);
92 
93 void usb_bos_fix_total_length(void);
94 
95 const void *usb_bos_get_header(void);
96 
97 #if defined(CONFIG_USB_DEVICE_BOS)
98 int usb_handle_bos(struct usb_setup_packet *setup, int32_t *len, uint8_t **data);
99 #else
100 #define usb_handle_bos(x, y, z)		-ENOTSUP
101 #endif
102 /** @endcond */
103 
104 /**
105  * @}
106  */
107 
108 #endif	/* ZEPHYR_INCLUDE_USB_BOS_H_ */
109