• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
3  * Description: LiteOS USB Driver Config Data Stream HeadFile
4  * Author: Yannik Li
5  * Create: 2021-02-21
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted provided that the following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  * conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14  * to endorse or promote products derived from this software without specific prior written
15  * permission.
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * --------------------------------------------------------------------------- */
28 /* ----------------------------------------------------------------------------
29  * Notice of Export Control Law
30  * ===============================================
31  * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
32  * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
33  * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
34  * applicable export control laws and regulations.
35  * --------------------------------------------------------------------------- */
36 
37 #ifndef LITEOS_USB_DEVICE_CONFIG_H
38 #define LITEOS_USB_DEVICE_CONFIG_H
39 
40 #include "usb_obj.h"
41 #include "gadget/composite.h"
42 
43 #ifdef __cplusplus
44 #if __cplusplus
45 //extern "C" {
46 #endif /* __cplusplus */
47 #endif /* __cplusplus */
48 
49 #define FCONFIG_IOC_MAGIC                'c'
50 #define FCONFIG_CMD_MAKE_GADGET          _IO(FCONFIG_IOC_MAGIC, 1)
51 #define FCONFIG_CMD_DROP_GADGET          _IO(FCONFIG_IOC_MAGIC, 2)
52 #define FCONFIG_CMD_WRITE_DEV_DESC       _IO(FCONFIG_IOC_MAGIC, 3)
53 #define FCONFIG_CMD_ADD_CONFIG           _IO(FCONFIG_IOC_MAGIC, 4)
54 #define FCONFIG_CMD_REMOVE_CONFIG        _IO(FCONFIG_IOC_MAGIC, 5)
55 #define FCONFIG_CMD_WRITE_STRINGS        _IO(FCONFIG_IOC_MAGIC, 6)
56 #define FCONFIG_CMD_MAKE_FUNCTION        _IO(FCONFIG_IOC_MAGIC, 7)
57 #define FCONFIG_CMD_DROP_FUNCTION        _IO(FCONFIG_IOC_MAGIC, 8)
58 #define FCONFIG_CMD_ENABLE_UDC           _IO(FCONFIG_IOC_MAGIC, 9)
59 #define FCONFIG_CMD_DISABLE_UDC          _IO(FCONFIG_IOC_MAGIC, 10)
60 #define FCONFIG_CMD_CHAGE_DEVINFO        _IO(FCONFIG_IOC_MAGIC, 11)
61 #define FCONFIG_CMD_CHAGE_DEVSTRING      _IO(FCONFIG_IOC_MAGIC, 12)
62 
63 /* USB_DT_DEVICE: Device descriptor */
64 #define USBDEV_CLASS "bDeviceClass"
65 #define USBDEV_SUBCLASS "bDeviceSubClass"
66 #define USBDEV_PROTOCOL "bDeviceProtocol"
67 #define USBDEV_MAXSIZE "bMaxPacketSize0"
68 #define USBDEV_MANUFACTURER "manufacturer"
69 #define USBDEV_PRODUCT "product"
70 #define USBDEV_SERIALNUM "serialnumber"
71 #define USBDEV_NUMCFG "numConfigurations"
72 #define USBDEV_BCD "bcdUSB"
73 #define USBDEV_VENDOR "idVendor"
74 #define USBDEV_IDPRODUCT "idProduct"
75 #define USBDEV_BCDDEVICE "bcdDevice"
76 
77 struct fconfig_string {
78   uint32_t                      len;
79   char                          *s;
80 };
81 
82 struct fconfig_usb_string {
83   uint8_t                       id;
84   struct fconfig_string         str;
85 };
86 
87 struct fconfig_dev_strings {
88   struct fconfig_string         gadget_name;
89   uint16_t                      language;
90   uint32_t                      str_count;
91   struct fconfig_usb_string     *strings;
92 } __attribute__((packed));
93 
94 struct fconfig_dev_desc {
95   struct fconfig_string         gadget_name;
96   struct usb_device_descriptor  dev_desc;
97 } __attribute__((packed));
98 
99 struct fconfig_cfg_desc {
100   struct fconfig_string         gadget_name;
101   struct fconfig_string         config_name;
102   struct usb_config_descriptor  cfg_desc;
103 } __attribute__((packed));
104 
105 struct fconfig_func_info {
106   struct fconfig_string         gadget_name;
107   struct fconfig_string         config_name;
108   struct fconfig_string         func_name;
109 };
110 
111 struct fconfig_udc_info {
112   struct fconfig_string         gadget_name;
113   struct fconfig_string         udc_name;
114 };
115 
116 struct usbdev_info {
117   const char                    *name;
118   device_type                   type;
119   int                           ifnum;
120   void (*initialize_sub)(struct composite_devdesc_s *dev, int ifnobase, int minor);
121 };
122 
123 struct function_instance {
124   struct usb_obj                obj;
125   struct function_info          *func_info;
126   struct usbdev_info            *dev_info;
127   struct gadget_config          *cfg;
128   char                          *name;
129   int                           minor;
130   int                           ifnobase;
131 };
132 
133 struct gadget_config {
134   struct usb_obj                obj;
135   struct gadget_info            *gi;
136   struct usb_config_descriptor  *cfg_desc;
137   uint8_t                       cfg_num;
138   char                          *name;
139 };
140 
141 struct gadget_strings {
142   struct usb_obj                obj;
143   uint16_t                      language;
144   struct usbd_string            *strings;
145 };
146 
147 struct gadget_info {
148   struct usb_obj                obj;
149   const char                    *name;
150   struct fconfig_softc          *cdev;
151   char                          *udc_name;
152   struct composite_softc        *com_s;
153   device_t                      dev;
154   struct usb_device_descriptor  *dev_desc;
155   struct usb_obj                strings;
156   uint32_t                      str_count;
157   uint32_t                      lang_count;
158 };
159 
160 struct fconfig_prop {
161   const char  *prop_name;
162   uint16_t    prop_value;
163 };
164 
165 struct fconfig_propSting {
166   uint16_t    lang;
167   const char  *prop_name;
168   const char  *prop_value;
169 };
170 
171 struct fconfig_dev_desc_info {
172   struct fconfig_string      gadget_name;
173   struct fconfig_prop        prop;
174 };
175 
176 struct fconfig_dev_desc_string {
177   struct fconfig_string      gadget_name;
178   struct fconfig_propSting   prop;
179 };
180 
181 extern int fconfig_fops_init(struct fconfig_softc *cdev);
182 extern int fconfig_fops_deinit(const struct fconfig_softc *cdev);
183 
184 #ifdef __cplusplus
185 #if __cplusplus
186 //}
187 #endif /* __cplusplus */
188 #endif /* __cplusplus */
189 
190 #endif /* LITEOS_USB_DEVICE_CONFIG_H */
191