1beacf11bSopenharmony_ci/* ----------------------------------------------------------------------------
2beacf11bSopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2016-2019. All rights reserved.
3beacf11bSopenharmony_ci * Description: LiteOS USB Driver Virtual Serial Port Descriptor
4beacf11bSopenharmony_ci * Author: huangjieliang
5beacf11bSopenharmony_ci * Create: 2016-07-06
6beacf11bSopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
7beacf11bSopenharmony_ci * are permitted provided that the following conditions are met:
8beacf11bSopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
9beacf11bSopenharmony_ci * conditions and the following disclaimer.
10beacf11bSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11beacf11bSopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials
12beacf11bSopenharmony_ci * provided with the distribution.
13beacf11bSopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14beacf11bSopenharmony_ci * to endorse or promote products derived from this software without specific prior written
15beacf11bSopenharmony_ci * permission.
16beacf11bSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17beacf11bSopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18beacf11bSopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19beacf11bSopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20beacf11bSopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21beacf11bSopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22beacf11bSopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23beacf11bSopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24beacf11bSopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25beacf11bSopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26beacf11bSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27beacf11bSopenharmony_ci * --------------------------------------------------------------------------- */
28beacf11bSopenharmony_ci/* ----------------------------------------------------------------------------
29beacf11bSopenharmony_ci * Notice of Export Control Law
30beacf11bSopenharmony_ci * ===============================================
31beacf11bSopenharmony_ci * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
32beacf11bSopenharmony_ci * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
33beacf11bSopenharmony_ci * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
34beacf11bSopenharmony_ci * applicable export control laws and regulations.
35beacf11bSopenharmony_ci * --------------------------------------------------------------------------- */
36beacf11bSopenharmony_ci
37beacf11bSopenharmony_ci#include "gadget/cdcacm.h"
38beacf11bSopenharmony_ci
39beacf11bSopenharmony_ci#ifdef __cplusplus
40beacf11bSopenharmony_ci#if __cplusplus
41beacf11bSopenharmony_ciextern "C" {
42beacf11bSopenharmony_ci#endif /* __cplusplus */
43beacf11bSopenharmony_ci#endif /* __cplusplus */
44beacf11bSopenharmony_ci
45beacf11bSopenharmony_cistatic const struct usb_device_descriptor g_cdcacm_device_desc =
46beacf11bSopenharmony_ci{
47beacf11bSopenharmony_ci  .bLength            = sizeof(struct usb_device_descriptor),
48beacf11bSopenharmony_ci  .bDescriptorType    = UDESC_DEVICE,
49beacf11bSopenharmony_ci  HSETW(.bcdUSB,      UD_BCD_USB),    /* usb version */
50beacf11bSopenharmony_ci  .bDeviceClass       = UDCLASS_COMM, /* 0x02 */
51beacf11bSopenharmony_ci  .bDeviceSubClass    = 0,
52beacf11bSopenharmony_ci  .bDeviceProtocol    = 0,
53beacf11bSopenharmony_ci  .bMaxPacketSize     = UD_USB_MPS,
54beacf11bSopenharmony_ci  HSETW(.idVendor, DEVICE_VENDOR_ID),   /* vendor 0x0525 */
55beacf11bSopenharmony_ci  HSETW(.idProduct, DEVICE_PRODUCT_ID), /* product 0xa4a7 */
56beacf11bSopenharmony_ci  HSETW(.bcdDevice, DEVICE_VERSION),    /* device version */
57beacf11bSopenharmony_ci  .iManufacturer      = 1,
58beacf11bSopenharmony_ci  .iProduct           = 2,
59beacf11bSopenharmony_ci  .iSerialNumber      = 0,
60beacf11bSopenharmony_ci  .bNumConfigurations = 1,
61beacf11bSopenharmony_ci};
62beacf11bSopenharmony_ci
63beacf11bSopenharmony_cistruct cdcacm_hs_function_descriptor g_cdcacm_hs_func_desc =
64beacf11bSopenharmony_ci{
65beacf11bSopenharmony_ci  {
66beacf11bSopenharmony_ci    .bLength            = sizeof(struct usb_interface_assoc_descriptor),
67beacf11bSopenharmony_ci    .bDescriptorType    = UDESC_IFACE_ASSOC,
68beacf11bSopenharmony_ci    .bInterfaceCount    = 2,
69beacf11bSopenharmony_ci    .bFunctionClass     = 2, /* UFCLASS_CDC */
70beacf11bSopenharmony_ci    .bFunctionSubClass  = 2,
71beacf11bSopenharmony_ci    .bFunctionProtocol  = 1,
72beacf11bSopenharmony_ci
73beacf11bSopenharmony_ci    /* Dynamic configuration when composite driver. 0x0c */
74beacf11bSopenharmony_ci
75beacf11bSopenharmony_ci    .iFunction = 7,
76beacf11bSopenharmony_ci  },
77beacf11bSopenharmony_ci  {
78beacf11bSopenharmony_ci    .bLength            = sizeof(struct usb_interface_descriptor),
79beacf11bSopenharmony_ci    .bDescriptorType    = UDESC_INTERFACE,
80beacf11bSopenharmony_ci    .bAlternateSetting  = 0,
81beacf11bSopenharmony_ci    .bNumEndpoints      = 0x1,
82beacf11bSopenharmony_ci    .bInterfaceClass    = UICLASS_CDC,
83beacf11bSopenharmony_ci    .bInterfaceSubClass = UISUBCLASS_ABSTRACT_CONTROL_MODEL,
84beacf11bSopenharmony_ci    .bInterfaceProtocol = UIPROTO_CDC_AT,
85beacf11bSopenharmony_ci
86beacf11bSopenharmony_ci    /* Dynamic configuration when composite driver. 0x0a */
87beacf11bSopenharmony_ci
88beacf11bSopenharmony_ci    .iInterface             = 5
89beacf11bSopenharmony_ci  },
90beacf11bSopenharmony_ci  {
91beacf11bSopenharmony_ci    .bLength            = sizeof(struct usb_cdc_header_descriptor),
92beacf11bSopenharmony_ci    .bDescriptorType    = UDESC_CS_INTERFACE,
93beacf11bSopenharmony_ci    .bDescriptorSubtype = UDESCSUB_CDC_HEADER,
94beacf11bSopenharmony_ci    HSETW(.bcdCDC, 0x0110)
95beacf11bSopenharmony_ci  },
96beacf11bSopenharmony_ci  {
97beacf11bSopenharmony_ci    .bLength            = sizeof(struct usb_cdc_cm_descriptor),
98beacf11bSopenharmony_ci    .bDescriptorType    = UDESC_CS_INTERFACE,
99beacf11bSopenharmony_ci    .bDescriptorSubtype = UDESCSUB_CDC_CM, /* call Management */
100beacf11bSopenharmony_ci    .bmCapabilities     = 0x0,
101beacf11bSopenharmony_ci  },
102beacf11bSopenharmony_ci  {
103beacf11bSopenharmony_ci    .bLength            = sizeof(struct usb_cdc_acm_descriptor),
104beacf11bSopenharmony_ci    .bDescriptorType    = UDESC_CS_INTERFACE,
105beacf11bSopenharmony_ci    .bDescriptorSubType = UDESCSUB_CDC_ACM, /* Abstract Control Model */
106beacf11bSopenharmony_ci    .bmCapabilities     = USB_CDC_ACM_HAS_LINE
107beacf11bSopenharmony_ci  },
108beacf11bSopenharmony_ci  {
109beacf11bSopenharmony_ci    .bLength            = sizeof(struct usb_cdc_union_desc),
110beacf11bSopenharmony_ci    .bDescriptorType    = UDESC_CS_INTERFACE,
111beacf11bSopenharmony_ci    .bDescriptorSubType = UDESCSUB_CDC_UNION,
112beacf11bSopenharmony_ci  },
113beacf11bSopenharmony_ci  {
114beacf11bSopenharmony_ci    .bLength          = sizeof(struct usb_endpoint_descriptor),
115beacf11bSopenharmony_ci    .bDescriptorType  = UDESC_ENDPOINT,
116beacf11bSopenharmony_ci    .bEndpointAddress = UE_DIR_IN,
117beacf11bSopenharmony_ci    .bmAttributes     = UE_INTERRUPT,
118beacf11bSopenharmony_ci    HSETW(.wMaxPacketSize, 0x000a),
119beacf11bSopenharmony_ci    .bInterval        = 9
120beacf11bSopenharmony_ci  },
121beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
122beacf11bSopenharmony_ci  {
123beacf11bSopenharmony_ci    .bLength           = 6,
124beacf11bSopenharmony_ci    .bDescriptorType   = 0x30,
125beacf11bSopenharmony_ci    .bMaxBurst         = 0,
126beacf11bSopenharmony_ci    .bmAttributes      = 0,
127beacf11bSopenharmony_ci    .wBytesPerInterval = {0}
128beacf11bSopenharmony_ci  },
129beacf11bSopenharmony_ci#endif
130beacf11bSopenharmony_ci  {
131beacf11bSopenharmony_ci    .bLength            = sizeof(struct usb_interface_descriptor),
132beacf11bSopenharmony_ci    .bDescriptorType    = UDESC_INTERFACE,
133beacf11bSopenharmony_ci    .bAlternateSetting  = 0,
134beacf11bSopenharmony_ci    .bNumEndpoints      = 0x2,
135beacf11bSopenharmony_ci    .bInterfaceClass    = UICLASS_CDC_DATA,
136beacf11bSopenharmony_ci    .bInterfaceSubClass = UISUBCLASS_DATA,
137beacf11bSopenharmony_ci    .bInterfaceProtocol = 0x0,
138beacf11bSopenharmony_ci
139beacf11bSopenharmony_ci    /* Dynamic configuration when composite driver. 0x0b */
140beacf11bSopenharmony_ci
141beacf11bSopenharmony_ci    .iInterface = 6
142beacf11bSopenharmony_ci  },
143beacf11bSopenharmony_ci  {
144beacf11bSopenharmony_ci    .bLength          = sizeof(struct usb_endpoint_descriptor),
145beacf11bSopenharmony_ci    .bDescriptorType  = UDESC_ENDPOINT,
146beacf11bSopenharmony_ci    .bEndpointAddress = UE_DIR_IN,
147beacf11bSopenharmony_ci    .bmAttributes     = UE_BULK,
148beacf11bSopenharmony_ci    HSETW(.wMaxPacketSize, MAX_PACKET_SIZE),
149beacf11bSopenharmony_ci    .bInterval        = 0
150beacf11bSopenharmony_ci  },
151beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
152beacf11bSopenharmony_ci  {
153beacf11bSopenharmony_ci    .bLength           = 6,
154beacf11bSopenharmony_ci    .bDescriptorType   = 0x30,
155beacf11bSopenharmony_ci    .bMaxBurst         = 0,
156beacf11bSopenharmony_ci    .bmAttributes      = 0,
157beacf11bSopenharmony_ci    .wBytesPerInterval = {0}
158beacf11bSopenharmony_ci  },
159beacf11bSopenharmony_ci#endif
160beacf11bSopenharmony_ci  {
161beacf11bSopenharmony_ci    .bLength          = sizeof(struct usb_endpoint_descriptor),
162beacf11bSopenharmony_ci    .bDescriptorType  = UDESC_ENDPOINT,
163beacf11bSopenharmony_ci    .bEndpointAddress = UE_DIR_OUT,
164beacf11bSopenharmony_ci    .bmAttributes     = UE_BULK,
165beacf11bSopenharmony_ci    HSETW(.wMaxPacketSize, MAX_PACKET_SIZE),
166beacf11bSopenharmony_ci    .bInterval        = 0
167beacf11bSopenharmony_ci  },
168beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
169beacf11bSopenharmony_ci  {
170beacf11bSopenharmony_ci    .bLength           = 6,
171beacf11bSopenharmony_ci    .bDescriptorType   = 0x30,
172beacf11bSopenharmony_ci    .bMaxBurst         = 0,
173beacf11bSopenharmony_ci    .bmAttributes      = 0,
174beacf11bSopenharmony_ci    .wBytesPerInterval = {0}
175beacf11bSopenharmony_ci  },
176beacf11bSopenharmony_ci#endif
177beacf11bSopenharmony_ci};
178beacf11bSopenharmony_ci
179beacf11bSopenharmony_ci/* config contain func */
180beacf11bSopenharmony_ci
181beacf11bSopenharmony_cistatic const struct usb_config_descriptor g_cdcacm_hs_config_desc =
182beacf11bSopenharmony_ci{
183beacf11bSopenharmony_ci  .bLength             = USB_CONFIG_DESC_SIZE,
184beacf11bSopenharmony_ci  .bDescriptorType     = UDESC_CONFIG,
185beacf11bSopenharmony_ci  HSETW(.wTotalLength, USB_CONFIG_DESC_SIZE + sizeof(g_cdcacm_hs_func_desc)),
186beacf11bSopenharmony_ci  .bNumInterface       = 2,
187beacf11bSopenharmony_ci  .bConfigurationValue = 2,
188beacf11bSopenharmony_ci  .iConfiguration      = 4,
189beacf11bSopenharmony_ci  .bmAttributes        = UC_SELF_POWERED | UC_BUS_POWERED, /* 0xc0 */
190beacf11bSopenharmony_ci  .bMaxPower           = 1                                 /* max power */
191beacf11bSopenharmony_ci};
192beacf11bSopenharmony_ci
193beacf11bSopenharmony_ci#define DT_STRING_ID_LEN 4
194beacf11bSopenharmony_cistatic const char g_dt_string_id[DT_STRING_ID_LEN] =
195beacf11bSopenharmony_ci{
196beacf11bSopenharmony_ci  DT_STRING_ID_LEN,
197beacf11bSopenharmony_ci  UDESC_STRING,
198beacf11bSopenharmony_ci  0x09, 0x04
199beacf11bSopenharmony_ci};
200beacf11bSopenharmony_ci
201beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
202beacf11bSopenharmony_ci#define DT_STRING_VID_LEN 94
203beacf11bSopenharmony_ci#else
204beacf11bSopenharmony_ci#define DT_STRING_VID_LEN 16
205beacf11bSopenharmony_ci#endif
206beacf11bSopenharmony_cistatic const char g_dt_string_vid[DT_STRING_VID_LEN] =
207beacf11bSopenharmony_ci{
208beacf11bSopenharmony_ci  DT_STRING_VID_LEN,
209beacf11bSopenharmony_ci  UDESC_STRING,
210beacf11bSopenharmony_ci#ifndef DWC3_USB_SERIAL
211beacf11bSopenharmony_ci  'D',0,'W',0,'C',0,'-',0,'O',0,'T',0,'G',0
212beacf11bSopenharmony_ci#else
213beacf11bSopenharmony_ci  0x4c, 0, 0x69, 0, 0x6e, 0, 0x75, 0, 0x78, 0, 0x20, 0, 0x33, 0, 0x2e, 0, 0x31, 0, 0x38, 0,
214beacf11bSopenharmony_ci  0x2e, 0, 0x31, 0, 0x33, 0, 0x2d, 0, 0x67, 0, 0x64, 0, 0x37, 0, 0x32, 0, 0x32, 0, 0x36, 0,
215beacf11bSopenharmony_ci  0x65, 0, 0x37, 0, 0x2d, 0, 0x64, 0, 0x69, 0, 0x72, 0, 0x74, 0, 0x79, 0, 0x20, 0, 0x77, 0,
216beacf11bSopenharmony_ci  0x69, 0, 0x74, 0, 0x68, 0, 0x20, 0, 0x64, 0, 0x77, 0, 0x63, 0, 0x5f, 0, 0x75, 0, 0x73, 0,
217beacf11bSopenharmony_ci  0x62, 0, 0x33, 0, 0x5f, 0, 0x70, 0, 0x63, 0, 0x64, 0
218beacf11bSopenharmony_ci#endif
219beacf11bSopenharmony_ci};
220beacf11bSopenharmony_ci
221beacf11bSopenharmony_ci#define DT_STRING_PID_LEN 38
222beacf11bSopenharmony_cistatic const char g_dt_string_pid[DT_STRING_PID_LEN] =
223beacf11bSopenharmony_ci{
224beacf11bSopenharmony_ci  DT_STRING_PID_LEN,
225beacf11bSopenharmony_ci  UDESC_STRING,
226beacf11bSopenharmony_ci  'G',0,'a',0,'d',0,'g',0,'e',0,'t',0,' ',0,
227beacf11bSopenharmony_ci  'S',0,'e',0,'r',0,'i',0,'a',0,'l',0,' ',0,
228beacf11bSopenharmony_ci  'v',0,'2',0,'.',0,'4',0
229beacf11bSopenharmony_ci};
230beacf11bSopenharmony_ci
231beacf11bSopenharmony_ci#define DT_STRING_SERIAL_LEN    18
232beacf11bSopenharmony_cistatic const char g_dt_string_serial[DT_STRING_SERIAL_LEN] =
233beacf11bSopenharmony_ci{
234beacf11bSopenharmony_ci  DT_STRING_SERIAL_LEN,
235beacf11bSopenharmony_ci  UDESC_STRING,
236beacf11bSopenharmony_ci  '2',0,'0',0,'1',0,'5',0,'0',0,'7',0,'3',0,'0',0
237beacf11bSopenharmony_ci};
238beacf11bSopenharmony_ci
239beacf11bSopenharmony_ci#define DT_STRING_4_LEN 30
240beacf11bSopenharmony_cistatic const char g_dt_string_4[DT_STRING_4_LEN] =
241beacf11bSopenharmony_ci{
242beacf11bSopenharmony_ci  DT_STRING_4_LEN,
243beacf11bSopenharmony_ci  UDESC_STRING,
244beacf11bSopenharmony_ci  0x43, 0, 0x44, 0, 0x43, 0, 0x20, 0, 0x41, 0, 0x43, 0, 0x4d, 0,
245beacf11bSopenharmony_ci  0x20, 0, 0x63, 0, 0x6f, 0, 0x6e, 0, 0x66, 0, 0x69, 0, 0x67, 0
246beacf11bSopenharmony_ci};
247beacf11bSopenharmony_ci
248beacf11bSopenharmony_ci#define DT_STRING_5_LEN 66
249beacf11bSopenharmony_cistatic const char g_dt_string_5[DT_STRING_5_LEN] =
250beacf11bSopenharmony_ci{
251beacf11bSopenharmony_ci  DT_STRING_5_LEN,
252beacf11bSopenharmony_ci  UDESC_STRING,
253beacf11bSopenharmony_ci  0x43, 0, 0x44, 0, 0x43, 0, 0x20, 0, 0x41, 0, 0x62, 0, 0x73, 0, 0x74, 0, 0x72, 0, 0x61, 0,
254beacf11bSopenharmony_ci  0x63, 0, 0x74, 0, 0x20, 0, 0x43, 0, 0x6f, 0, 0x6e, 0, 0x74, 0, 0x72, 0, 0x6f, 0, 0x6c, 0,
255beacf11bSopenharmony_ci  0x20, 0, 0x4d, 0, 0x6f, 0, 0x64, 0, 0x65, 0, 0x6c, 0, 0x20, 0, 0x28, 0, 0x41, 0, 0x43, 0,
256beacf11bSopenharmony_ci  0x4d, 0, 0x29, 0
257beacf11bSopenharmony_ci};
258beacf11bSopenharmony_ci
259beacf11bSopenharmony_ci#define DT_STRING_6_LEN 26
260beacf11bSopenharmony_cistatic const char g_dt_string_6[DT_STRING_6_LEN] =
261beacf11bSopenharmony_ci{
262beacf11bSopenharmony_ci  DT_STRING_6_LEN,
263beacf11bSopenharmony_ci  UDESC_STRING,
264beacf11bSopenharmony_ci  0x43, 0, 0x44, 0, 0x43, 0, 0x20, 0, 0x41, 0,
265beacf11bSopenharmony_ci  0x43, 0, 0x4d, 0, 0x20, 0, 0x44, 0, 0x61, 0, 0x74, 0, 0x61, 0
266beacf11bSopenharmony_ci};
267beacf11bSopenharmony_ci
268beacf11bSopenharmony_ci#define DT_STRING_7_LEN 22
269beacf11bSopenharmony_cistatic const char g_dt_string_7[DT_STRING_7_LEN] =
270beacf11bSopenharmony_ci{
271beacf11bSopenharmony_ci  DT_STRING_7_LEN,
272beacf11bSopenharmony_ci  UDESC_STRING,
273beacf11bSopenharmony_ci  0x43, 0, 0x44, 0, 0x43, 0, 0x20, 0, 0x53, 0, 0x65, 0,
274beacf11bSopenharmony_ci  0x72, 0, 0x69, 0, 0x61, 0, 0x6c, 0
275beacf11bSopenharmony_ci};
276beacf11bSopenharmony_ci
277beacf11bSopenharmony_ci#define FSERIAL_DSTR_IDX 9
278beacf11bSopenharmony_cistatic struct usbd_string g_cdcacm_device_strings[FSERIAL_DSTR_IDX] =
279beacf11bSopenharmony_ci{
280beacf11bSopenharmony_ci  { 0, g_dt_string_id },
281beacf11bSopenharmony_ci  { 1, g_dt_string_vid },
282beacf11bSopenharmony_ci  { 2, g_dt_string_pid },
283beacf11bSopenharmony_ci  { 3, g_dt_string_serial },
284beacf11bSopenharmony_ci  { 4, g_dt_string_4 },
285beacf11bSopenharmony_ci  { 5, g_dt_string_5 },
286beacf11bSopenharmony_ci  { 6, g_dt_string_6 },
287beacf11bSopenharmony_ci  { 7, g_dt_string_7 },
288beacf11bSopenharmony_ci  USBD_DEVICE_STRINGS_END
289beacf11bSopenharmony_ci};
290beacf11bSopenharmony_ci
291beacf11bSopenharmony_ci/* ***************************************************************************
292beacf11bSopenharmony_ci * Name: cdcacm_mkdevdesc
293beacf11bSopenharmony_ci *
294beacf11bSopenharmony_ci * Description:
295beacf11bSopenharmony_ci *   Construct the device descriptor
296beacf11bSopenharmony_ci *
297beacf11bSopenharmony_ci * ***************************************************************************
298beacf11bSopenharmony_ci */
299beacf11bSopenharmony_ci
300beacf11bSopenharmony_civoid cdcacm_mkdevdesc(uint8_t *buf)
301beacf11bSopenharmony_ci{
302beacf11bSopenharmony_ci  errno_t ret;
303beacf11bSopenharmony_ci
304beacf11bSopenharmony_ci  ret = memcpy_s(buf, USB_COMP_EP0_BUFSIZ, &g_cdcacm_device_desc, sizeof(g_cdcacm_device_desc));
305beacf11bSopenharmony_ci  if (ret != EOK)
306beacf11bSopenharmony_ci    {
307beacf11bSopenharmony_ci      usb_err("memcpy_s fail!, ret:%d\n", ret);
308beacf11bSopenharmony_ci      return;
309beacf11bSopenharmony_ci    }
310beacf11bSopenharmony_ci}
311beacf11bSopenharmony_ci
312beacf11bSopenharmony_ci/* ***************************************************************************
313beacf11bSopenharmony_ci * Name: cdcacm_mkcfgdesc
314beacf11bSopenharmony_ci *
315beacf11bSopenharmony_ci * Description:
316beacf11bSopenharmony_ci *   Construct the configuration descriptor
317beacf11bSopenharmony_ci *
318beacf11bSopenharmony_ci * ***************************************************************************
319beacf11bSopenharmony_ci */
320beacf11bSopenharmony_ci
321beacf11bSopenharmony_ciint16_t cdcacm_mkcfgdesc(uint8_t *buf, struct usbdev_devinfo_s *devinfo)
322beacf11bSopenharmony_ci{
323beacf11bSopenharmony_ci  int16_t total_len = 0;
324beacf11bSopenharmony_ci  int16_t len = USB_CONFIG_DESC_SIZE;
325beacf11bSopenharmony_ci  errno_t ret;
326beacf11bSopenharmony_ci
327beacf11bSopenharmony_ci  g_cdcacm_hs_func_desc.ifcad.bFirstInterface = (uint8_t)devinfo->ifnobase;
328beacf11bSopenharmony_ci  g_cdcacm_hs_func_desc.ifcd.bInterfaceNumber = (uint8_t)devinfo->ifnobase;
329beacf11bSopenharmony_ci  g_cdcacm_hs_func_desc.cdc_union_desc.bMasterInterface0 = (uint8_t)devinfo->ifnobase;
330beacf11bSopenharmony_ci  g_cdcacm_hs_func_desc.ifdd.bInterfaceNumber = (uint8_t)devinfo->ifnobase + 1;
331beacf11bSopenharmony_ci  g_cdcacm_hs_func_desc.cdc_union_desc.bSlaveInterface0 = (uint8_t)devinfo->ifnobase + 1;
332beacf11bSopenharmony_ci  g_cdcacm_hs_func_desc.cdc_call_desc.bDataInterface = (uint8_t)devinfo->ifnobase + 1;
333beacf11bSopenharmony_ci
334beacf11bSopenharmony_ci  /* Copy Serial device configure descriptor. */
335beacf11bSopenharmony_ci
336beacf11bSopenharmony_ci  ret = memcpy_s(buf, USB_COMP_EP0_BUFSIZ, (const void *)&g_cdcacm_hs_config_desc, (uint32_t)len);
337beacf11bSopenharmony_ci  if (ret != EOK)
338beacf11bSopenharmony_ci    {
339beacf11bSopenharmony_ci      usb_err("memcpy_s fail, ret:%d\n", ret);
340beacf11bSopenharmony_ci      return -1;
341beacf11bSopenharmony_ci    }
342beacf11bSopenharmony_ci  total_len += len;
343beacf11bSopenharmony_ci
344beacf11bSopenharmony_ci  /* Copy Serial device function descriptor. */
345beacf11bSopenharmony_ci
346beacf11bSopenharmony_ci  buf += USB_CONFIG_DESC_SIZE;
347beacf11bSopenharmony_ci  len = sizeof(g_cdcacm_hs_func_desc);
348beacf11bSopenharmony_ci  ret = memcpy_s(buf, (USB_COMP_EP0_BUFSIZ - total_len), (const void *)&g_cdcacm_hs_func_desc, (uint32_t)len);
349beacf11bSopenharmony_ci  if (ret != EOK)
350beacf11bSopenharmony_ci    {
351beacf11bSopenharmony_ci      usb_err("memcpy_s fail, ret:%d\n", ret);
352beacf11bSopenharmony_ci      return -1;
353beacf11bSopenharmony_ci    }
354beacf11bSopenharmony_ci  total_len += len;
355beacf11bSopenharmony_ci
356beacf11bSopenharmony_ci  return total_len;
357beacf11bSopenharmony_ci}
358beacf11bSopenharmony_ci
359beacf11bSopenharmony_ci/****************************************************************************
360beacf11bSopenharmony_ci * Name: cdcacm_mkstrdesc
361beacf11bSopenharmony_ci *
362beacf11bSopenharmony_ci * Description:
363beacf11bSopenharmony_ci *   Construct a string descriptor
364beacf11bSopenharmony_ci *
365beacf11bSopenharmony_ci ****************************************************************************/
366beacf11bSopenharmony_ci
367beacf11bSopenharmony_ciint cdcacm_mkstrdesc(uint8_t id, uint8_t *buf)
368beacf11bSopenharmony_ci{
369beacf11bSopenharmony_ci  errno_t ret;
370beacf11bSopenharmony_ci  const char *str;
371beacf11bSopenharmony_ci  int i;
372beacf11bSopenharmony_ci
373beacf11bSopenharmony_ci  for (i = 0; g_cdcacm_device_strings[i].s != NULL; i++)
374beacf11bSopenharmony_ci    {
375beacf11bSopenharmony_ci      str = g_cdcacm_device_strings[i].s;
376beacf11bSopenharmony_ci      if (g_cdcacm_device_strings[i].id == id)
377beacf11bSopenharmony_ci        {
378beacf11bSopenharmony_ci          ret = memcpy_s(buf, USB_COMP_EP0_BUFSIZ, (const void *)str, (uint32_t)str[0]);
379beacf11bSopenharmony_ci          if (ret != EOK)
380beacf11bSopenharmony_ci            {
381beacf11bSopenharmony_ci              usb_err("memcpy_s failed, ret = %d\n", ret);
382beacf11bSopenharmony_ci              return -1;
383beacf11bSopenharmony_ci            }
384beacf11bSopenharmony_ci          return str[0];
385beacf11bSopenharmony_ci        }
386beacf11bSopenharmony_ci    }
387beacf11bSopenharmony_ci
388beacf11bSopenharmony_ci  usb_err("Can not find the id = %u of string\n", id);
389beacf11bSopenharmony_ci  return -1;
390beacf11bSopenharmony_ci}
391beacf11bSopenharmony_ci
392beacf11bSopenharmony_ci#ifdef __cplusplus
393beacf11bSopenharmony_ci#if __cplusplus
394beacf11bSopenharmony_ci}
395beacf11bSopenharmony_ci#endif /* __cplusplus */
396beacf11bSopenharmony_ci#endif /* __cplusplus */