Change global variable _available_funcs to const
[platform/core/system/libdevice-node.git] / hw / usb_gadget.h
1 /*
2  * libdevice-node
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef __HW_USB_GADGET_H__
20 #define __HW_USB_GADGET_H__
21
22 #include <stdint.h>
23
24 #include <hw/common.h>
25
26 /**
27  * The id of this device
28  */
29 #define USB_GADGET_DEVICE_ID    "usb_gadget"
30
31 /**
32  * The version of this device
33  */
34 #define USB_GADGET_DEVICE_VERSION       MAKE_VERSION(0,1)
35
36 typedef enum {
37         USB_FUNCTION_IDX_MTP         = 0,
38         USB_FUNCTION_IDX_ACM         = 1,
39         USB_FUNCTION_IDX_SDB         = 2,
40         USB_FUNCTION_IDX_RNDIS       = 3,
41         USB_FUNCTION_IDX_DIAG        = 4,
42         USB_FUNCTION_IDX_CONN_GADGET = 5,
43         USB_FUNCTION_IDX_DM          = 6,
44         USB_FUNCTION_IDX_RMNET       = 7,
45         USB_FUNCTION_IDX_MAX         = USB_FUNCTION_IDX_RMNET + 1
46 } usb_function_idx_e;
47
48 typedef enum {
49         USB_FUNCTION_NONE        = 0,
50         USB_FUNCTION_MTP         = 1 << USB_FUNCTION_IDX_MTP,
51         USB_FUNCTION_ACM         = 1 << USB_FUNCTION_IDX_ACM,
52         USB_FUNCTION_SDB         = 1 << USB_FUNCTION_IDX_SDB,
53         USB_FUNCTION_RNDIS       = 1 << USB_FUNCTION_IDX_RNDIS,
54         USB_FUNCTION_DIAG        = 1 << USB_FUNCTION_IDX_DIAG,
55         USB_FUNCTION_CONN_GADGET = 1 << USB_FUNCTION_IDX_CONN_GADGET,
56         USB_FUNCTION_DM          = 1 << USB_FUNCTION_IDX_DM,
57         USB_FUNCTION_RMNET       = 1 << USB_FUNCTION_IDX_RMNET
58 } usb_function_e;
59
60
61 /*
62  * legacy enable(usb plug)    : enable gadget -> handler(1) -> service start
63  * legacy disable(usb unplug) : service stop ->  handler(0) -> disable gadget
64  *
65  * configfs init(booting)       : service.socket start
66  * configfs enable(usb plug)*   : enable gadget -> handler(1)
67  * configfs disable(usb unplug) : handler(0) -> disable gadget -> service.service stop
68  * configfs deinit              : service.socket stop
69  *
70  * Since functionfs of configfs works by socket activation,
71  * it will be started automatically when data is enqueued to the usb socket.
72  * So when enabling configfs gadget, it doesn't start the service for functionfs.
73  */
74 struct usb_function {
75         int id;
76         const char *name;
77         const char *instance;
78
79         int is_functionfs;
80         const char *service;
81
82         void (*handler)(int enable);
83 };
84
85 struct usb_configuration_attributes {
86         uint8_t bmAttributs;
87         int MaxPower;
88 };
89
90 struct usb_configuration_strings {
91         uint16_t lang_code;
92         char *config_str;
93 };
94
95 struct usb_configuration {
96         struct usb_configuration_attributes attrs;
97         struct usb_configuration_strings *strs;
98         const struct usb_function **funcs;
99 };
100
101 struct usb_gadget_attrs {
102         uint8_t bDeviceClass;
103         uint8_t bDeviceSubClass;
104         uint8_t bDeviceProtocol;
105         uint16_t idVendor;
106         uint16_t idProduct;
107         uint16_t bcdDevice;
108 };
109
110 struct usb_gadget_strings {
111         uint16_t lang_code;
112         char *manufacturer;
113         char *product;
114         char *serial;
115 };
116
117 struct usb_gadget {
118         struct usb_gadget_attrs attrs;
119         struct usb_gadget_strings *strs;
120         const struct usb_function **funcs;
121         struct usb_configuration **configs;
122 };
123
124 struct usb_gadget_id {
125         unsigned int function_mask;
126 };
127
128 struct usb_gadget_translator {
129         struct hw_common common;
130
131         int (*id_to_gadget)(struct usb_gadget_id *gadget_id,  struct usb_gadget **gadget);
132         void (*cleanup_gadget)(struct usb_gadget *gadget);
133 };
134
135 int simple_translator_open(struct hw_info *info, const char *id, struct hw_common **common);
136 int simple_translator_close(struct hw_common *common);
137
138 const struct usb_function *find_usb_function_by_name(const char *name);
139 const struct usb_function *find_usb_function_by_name_instance(const char *name, const char *instance);
140
141 #endif