1 /*
2  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef _USB_DEVICE_DESCRIPTOR_H_
9 #define _USB_DEVICE_DESCRIPTOR_H_ 1
10 
11 /*******************************************************************************
12  * Definitions
13  ******************************************************************************/
14 #define USB_DEVICE_SPECIFIC_BCD_VERSION (0x0200)
15 #define USB_DEVICE_DEMO_BCD_VERSION     (0x0101U)
16 
17 /* Communication  Class Codes */
18 #define CDC_COMM_CLASS (0x02)
19 /* Data  Class Codes */
20 #define CDC_DATA_CLASS (0x0A)
21 
22 /* Communication Class SubClass Codes */
23 #define USB_CDC_DIRECT_LINE_CONTROL_MODEL         (0x01)
24 #define USB_CDC_ABSTRACT_CONTROL_MODEL            (0x02)
25 #define USB_CDC_TELEPHONE_CONTROL_MODEL           (0x03)
26 #define USB_CDC_MULTI_CHANNEL_CONTROL_MODEL       (0x04)
27 #define USB_CDC_CAPI_CONTROL_MOPDEL               (0x05)
28 #define USB_CDC_ETHERNET_NETWORKING_CONTROL_MODEL (0x06)
29 #define USB_CDC_ATM_NETWORKING_CONTROL_MODEL      (0x07)
30 #define USB_CDC_WIRELESS_HANDSET_CONTROL_MODEL    (0x08)
31 #define USB_CDC_DEVICE_MANAGEMENT                 (0x09)
32 #define USB_CDC_MOBILE_DIRECT_LINE_MODEL          (0x0A)
33 #define USB_CDC_OBEX                              (0x0B)
34 #define USB_CDC_ETHERNET_EMULATION_MODEL          (0x0C)
35 
36 /* Communication Class Protocol Codes */
37 #define USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL  (0x00) /*also for Data Class Protocol Code */
38 #define USB_CDC_AT_250_PROTOCOL             (0x01)
39 #define USB_CDC_AT_PCCA_101_PROTOCOL        (0x02)
40 #define USB_CDC_AT_PCCA_101_ANNEX_O         (0x03)
41 #define USB_CDC_AT_GSM_7_07                 (0x04)
42 #define USB_CDC_AT_3GPP_27_007              (0x05)
43 #define USB_CDC_AT_TIA_CDMA                 (0x06)
44 #define USB_CDC_ETHERNET_EMULATION_PROTOCOL (0x07)
45 #define USB_CDC_EXTERNAL_PROTOCOL           (0xFE)
46 #define USB_CDC_VENDOR_SPECIFIC             (0xFF) /*also for Data Class Protocol Code */
47 
48 /* Data Class Protocol Codes */
49 #define USB_CDC_PYHSICAL_INTERFACE_PROTOCOL (0x30)
50 #define USB_CDC_HDLC_PROTOCOL               (0x31)
51 #define USB_CDC_TRANSPARENT_PROTOCOL        (0x32)
52 #define USB_CDC_MANAGEMENT_PROTOCOL         (0x50)
53 #define USB_CDC_DATA_LINK_Q931_PROTOCOL     (0x51)
54 #define USB_CDC_DATA_LINK_Q921_PROTOCOL     (0x52)
55 #define USB_CDC_DATA_COMPRESSION_V42BIS     (0x90)
56 #define USB_CDC_EURO_ISDN_PROTOCOL          (0x91)
57 #define USB_CDC_RATE_ADAPTION_ISDN_V24      (0x92)
58 #define USB_CDC_CAPI_COMMANDS               (0x93)
59 #define USB_CDC_HOST_BASED_DRIVER           (0xFD)
60 #define USB_CDC_UNIT_FUNCTIONAL             (0xFE)
61 
62 /* Descriptor SubType in Communications Class Functional Descriptors */
63 #define USB_CDC_HEADER_FUNC_DESC              (0x00)
64 #define USB_CDC_CALL_MANAGEMENT_FUNC_DESC     (0x01)
65 #define USB_CDC_ABSTRACT_CONTROL_FUNC_DESC    (0x02)
66 #define USB_CDC_DIRECT_LINE_FUNC_DESC         (0x03)
67 #define USB_CDC_TELEPHONE_RINGER_FUNC_DESC    (0x04)
68 #define USB_CDC_TELEPHONE_REPORT_FUNC_DESC    (0x05)
69 #define USB_CDC_UNION_FUNC_DESC               (0x06)
70 #define USB_CDC_COUNTRY_SELECT_FUNC_DESC      (0x07)
71 #define USB_CDC_TELEPHONE_MODES_FUNC_DESC     (0x08)
72 #define USB_CDC_TERMINAL_FUNC_DESC            (0x09)
73 #define USB_CDC_NETWORK_CHANNEL_FUNC_DESC     (0x0A)
74 #define USB_CDC_PROTOCOL_UNIT_FUNC_DESC       (0x0B)
75 #define USB_CDC_EXTENSION_UNIT_FUNC_DESC      (0x0C)
76 #define USB_CDC_MULTI_CHANNEL_FUNC_DESC       (0x0D)
77 #define USB_CDC_CAPI_CONTROL_FUNC_DESC        (0x0E)
78 #define USB_CDC_ETHERNET_NETWORKING_FUNC_DESC (0x0F)
79 #define USB_CDC_ATM_NETWORKING_FUNC_DESC      (0x10)
80 #define USB_CDC_WIRELESS_CONTROL_FUNC_DESC    (0x11)
81 #define USB_CDC_MOBILE_DIRECT_LINE_FUNC_DESC  (0x12)
82 #define USB_CDC_MDLM_DETAIL_FUNC_DESC         (0x13)
83 #define USB_CDC_DEVICE_MANAGEMENT_FUNC_DESC   (0x14)
84 #define USB_CDC_OBEX_FUNC_DESC                (0x15)
85 #define USB_CDC_COMMAND_SET_FUNC_DESC         (0x16)
86 #define USB_CDC_COMMAND_SET_DETAIL_FUNC_DESC  (0x17)
87 #define USB_CDC_TELEPHONE_CONTROL_FUNC_DESC   (0x18)
88 #define USB_CDC_OBEX_SERVICE_ID_FUNC_DESC     (0x19)
89 
90 /* usb descritpor length */
91 #define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL (sizeof(g_UsbDeviceConfigurationDescriptor))
92 #define USB_DESCRIPTOR_LENGTH_CDC_HEADER_FUNC   (5)
93 #define USB_DESCRIPTOR_LENGTH_CDC_CALL_MANAG    (5)
94 #define USB_DESCRIPTOR_LENGTH_CDC_ABSTRACT      (4)
95 #define USB_DESCRIPTOR_LENGTH_CDC_UNION_FUNC    (5)
96 
97 /* Configuration, interface and endpoint. */
98 #define USB_DEVICE_CONFIGURATION_COUNT (1)
99 #define USB_DEVICE_STRING_COUNT        (3)
100 #define USB_DEVICE_LANGUAGE_COUNT      (1)
101 
102 #define USB_CDC_VCOM_CONFIGURE_INDEX (1)
103 
104 #define USB_CDC_VCOM_ENDPOINT_CIC_COUNT    (1)
105 #define USB_CDC_VCOM_ENDPOINT_DIC_COUNT    (2)
106 #define USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT (1)
107 #define USB_CDC_VCOM_BULK_IN_ENDPOINT      (2)
108 #define USB_CDC_VCOM_BULK_OUT_ENDPOINT     (3)
109 #define USB_CDC_VCOM_INTERFACE_COUNT       (2)
110 #define USB_CDC_VCOM_COMM_INTERFACE_INDEX  (0)
111 #define USB_CDC_VCOM_DATA_INTERFACE_INDEX  (1)
112 
113 /* Packet size. */
114 #define HS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE (16)
115 #define FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE (16)
116 #define HS_CDC_VCOM_INTERRUPT_IN_INTERVAL    (0x07) /* 2^(7-1) = 8ms */
117 #define FS_CDC_VCOM_INTERRUPT_IN_INTERVAL    (0x08)
118 #define HS_CDC_VCOM_BULK_IN_PACKET_SIZE      (512)
119 #define FS_CDC_VCOM_BULK_IN_PACKET_SIZE      (64)
120 #define HS_CDC_VCOM_BULK_OUT_PACKET_SIZE     (512)
121 #define FS_CDC_VCOM_BULK_OUT_PACKET_SIZE     (64)
122 
123 /* String descriptor length. */
124 #define USB_DESCRIPTOR_LENGTH_STRING0 (sizeof(g_UsbDeviceString0))
125 #define USB_DESCRIPTOR_LENGTH_STRING1 (sizeof(g_UsbDeviceString1))
126 #define USB_DESCRIPTOR_LENGTH_STRING2 (sizeof(g_UsbDeviceString2))
127 
128 #define USB_DESCRIPTOR_TYPE_CDC_CS_INTERFACE (0x24)
129 #define USB_DESCRIPTOR_TYPE_CDC_CS_ENDPOINT  (0x25)
130 
131 /* Class code. */
132 #define USB_DEVICE_CLASS    (0x02)
133 #define USB_DEVICE_SUBCLASS (0x00)
134 #define USB_DEVICE_PROTOCOL (0x00)
135 
136 #define USB_DEVICE_MAX_POWER (0x32)
137 
138 #define USB_CDC_VCOM_CIC_CLASS    (CDC_COMM_CLASS)
139 #define USB_CDC_VCOM_CIC_SUBCLASS (USB_CDC_ABSTRACT_CONTROL_MODEL)
140 #define USB_CDC_VCOM_CIC_PROTOCOL (USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL)
141 
142 #define USB_CDC_VCOM_DIC_CLASS    (CDC_DATA_CLASS)
143 #define USB_CDC_VCOM_DIC_SUBCLASS (0x00)
144 #define USB_CDC_VCOM_DIC_PROTOCOL (USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL)
145 
146 /*******************************************************************************
147  * Variables
148  ******************************************************************************/
149 /* Define endpoint for communication class */
150 extern usb_device_endpoint_struct_t g_UsbDeviceCdcVcomCicEndpoints[USB_CDC_VCOM_ENDPOINT_CIC_COUNT];
151 
152 /* Define endpoint for data class */
153 extern usb_device_endpoint_struct_t g_UsbDeviceCdcVcomDicEndpoints[USB_CDC_VCOM_ENDPOINT_DIC_COUNT];
154 
155 /* Define interface for communication class */
156 extern usb_device_interface_struct_t g_UsbDeviceCdcVcomCommunicationInterface[];
157 
158 /* Define interface for data class */
159 extern usb_device_interface_struct_t g_UsbDeviceCdcVcomDataInterface[];
160 
161 /* Define interfaces for virtual com */
162 extern usb_device_interfaces_struct_t g_UsbDeviceCdcVcomInterfaces[USB_CDC_VCOM_INTERFACE_COUNT];
163 
164 /* Define configurations for virtual com */
165 extern usb_device_interface_list_t g_UsbDeviceCdcVcomInterfaceLIST_[USB_DEVICE_CONFIGURATION_COUNT];
166 
167 /* Define class information for virtual com */
168 extern usb_device_class_struct_t g_UsbDeviceCdcVcomConfig;
169 
170 /* Define device descriptor */
171 extern uint8_t g_UsbDeviceDescriptor[];
172 
173 /* Define configuration descriptor */
174 extern uint8_t g_UsbDeviceConfigurationDescriptor[];
175 
176 /* Define string descriptor */
177 extern uint8_t g_UsbDeviceString0[];
178 
179 extern uint8_t g_UsbDeviceString1[];
180 
181 extern uint8_t g_UsbDeviceString2[];
182 
183 extern uint8_t *g_UsbDeviceStringDescriptorArray[USB_DEVICE_STRING_COUNT];
184 
185 /* Define string descriptor size */
186 extern uint32_t g_UsbDeviceStringDescriptorLength[USB_DEVICE_STRING_COUNT];
187 extern usb_language_t g_UsbDeviceLanguage[USB_DEVICE_LANGUAGE_COUNT];
188 extern usb_language_list_t g_UsbDeviceLanguageList;
189 
190 /*******************************************************************************
191  * API
192  ******************************************************************************/
193 /*!
194  * @brief USB device set speed function.
195  *
196  * This function sets the speed of the USB device.
197  *
198  * Due to the difference of HS and FS descriptors, the device descriptors and configurations need to be updated to match
199  * current speed.
200  * As the default, the device descriptors and configurations are configured by using FS parameters for both EHCI and
201  * KHCI.
202  * When the EHCI is enabled, the application needs to call this function to update device by using current speed.
203  * The updated information includes endpoint max packet size, endpoint interval, etc.
204  *
205  * @param handle The USB device handle.
206  * @param speed Speed type. USB_SPEED_HIGH/USB_SPEED_FULL/USB_SPEED_LOW.
207  *
208  * @return A USB error code or kStatus_USB_Success.
209  */
210 extern usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed);
211 /*!
212  * @brief USB device get device descriptor function.
213  *
214  * This function gets the device descriptor of the USB device.
215  *
216  * @param handle The USB device handle.
217  * @param deviceDescriptor The pointer to the device descriptor structure.
218  *
219  * @return A USB error code or kStatus_USB_Success.
220  */
221 extern usb_status_t USB_DeviceGetDeviceDescriptor(usb_device_handle handle,
222                                                   usb_device_get_device_descriptor_struct_t *deviceDescriptor);
223 /*!
224  * @brief USB device get string descriptor function.
225  *
226  * This function gets the string descriptor of the USB device.
227  *
228  * @param handle The USB device handle.
229  * @param stringDescriptor Pointer to the string descriptor structure.
230  *
231  * @return A USB error code or kStatus_USB_Success.
232  */
233 usb_status_t USB_DeviceGetStringDescriptor(usb_device_handle handle,
234                                            usb_device_get_string_descriptor_struct_t *stringDescriptor);
235 /*!
236  * @brief USB device get configuration descriptor function.
237  *
238  * This function gets the configuration descriptor of the USB device.
239  *
240  * @param handle The USB device handle.
241  * @param configurationDescriptor The pointer to the configuration descriptor structure.
242  *
243  * @return A USB error code or kStatus_USB_Success.
244  */
245 extern usb_status_t USB_DeviceGetConfigurationDescriptor(
246     usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor);
247 #endif /* _USB_DEVICE_DESCRIPTOR_H_ */
248