1 /*
2  * Copyright (c) 2018 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_USB_BOS_H_
8 #define ZEPHYR_INCLUDE_USB_BOS_H_
9 
10 #if defined(CONFIG_USB_DEVICE_BOS)
11 #define USB_DEVICE_BOS_DESC_DEFINE_HDR \
12 	static __in_section(usb, bos_desc_area, 0) __aligned(1) __used
13 #define USB_DEVICE_BOS_DESC_DEFINE_CAP \
14 	static __in_section(usb, bos_desc_area, 1) __aligned(1) __used
15 
16 /*
17  * DESCRIPTOR_TYPE_BOS macro is deprecated in 2.7 release.
18  * Please replace with macros from Chapter 9 header, include/usb/usb_ch9.h
19  */
20 #define DESCRIPTOR_TYPE_BOS		__DEPRECATED_MACRO 0x0F
21 
22 #define USB_BOS_CAPABILITY_EXTENSION	0x02
23 #define USB_BOS_CAPABILITY_PLATFORM	0x05
24 
25 /* BOS Capability Descriptor */
26 struct usb_bos_platform_descriptor {
27 	uint8_t bLength;
28 	uint8_t bDescriptorType;
29 	uint8_t bDevCapabilityType;
30 	uint8_t bReserved;
31 	uint8_t PlatformCapabilityUUID[16];
32 } __packed;
33 
34 /* BOS Descriptor */
35 struct usb_bos_descriptor {
36 	uint8_t bLength;
37 	uint8_t bDescriptorType;
38 	uint16_t wTotalLength;
39 	uint8_t bNumDeviceCaps;
40 } __packed;
41 
42 /* BOS Capability webusb */
43 struct usb_bos_capability_webusb {
44 	uint16_t bcdVersion;
45 	uint8_t bVendorCode;
46 	uint8_t iLandingPage;
47 } __packed;
48 
49 /* BOS Capability MS OS Descriptors version 2 */
50 struct usb_bos_capability_msos {
51 	uint32_t dwWindowsVersion;
52 	uint16_t wMSOSDescriptorSetTotalLength;
53 	uint8_t bMS_VendorCode;
54 	uint8_t bAltEnumCode;
55 } __packed;
56 
57 struct usb_bos_capability_lpm {
58 	uint8_t bLength;
59 	uint8_t bDescriptorType;
60 	uint8_t bDevCapabilityType;
61 	uint32_t bmAttributes;
62 } __packed;
63 
64 size_t usb_bos_get_length(void);
65 void usb_bos_fix_total_length(void);
66 void usb_bos_register_cap(struct usb_bos_platform_descriptor *hdr);
67 const void *usb_bos_get_header(void);
68 int usb_handle_bos(struct usb_setup_packet *setup, int32_t *len, uint8_t **data);
69 #else
70 #define usb_handle_bos(x, y, z)		-ENOTSUP
71 #endif
72 
73 #endif	/* ZEPHYR_INCLUDE_USB_BOS_H_ */
74