• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_HDI_USB_V1_0_USBD_FUNCTION_H
17 #define OHOS_HDI_USB_V1_0_USBD_FUNCTION_H
18 
19 #include <stdint.h>
20 
21 #define USB_FUNCTION_NONE    0
22 #define USB_FUNCTION_ACM     (1 << 0)
23 #define USB_FUNCTION_ECM     (1 << 1)
24 #define USB_FUNCTION_HDC     (1 << 2)
25 #define USB_FUNCTION_RNDIS   (1 << 5)
26 #define USB_FUNCTION_STORAGE (1 << 9)
27 #define USB_FUNCTION_SUPPORT \
28     (USB_FUNCTION_ACM | USB_FUNCTION_ECM | USB_FUNCTION_HDC | USB_FUNCTION_RNDIS | USB_FUNCTION_STORAGE)
29 
30 #define DEV_SERVICE_NAME "usbfn_master"
31 #define ACM_SERVICE_NAME "usbfn_cdcacm"
32 #define ECM_SERVICE_NAME "usbfn_cdcecm"
33 
34 #define SYS_USB_CONFIGFS       "sys.usb.configfs"
35 #define SYS_USB_CONFIG         "sys.usb.config"
36 #define HDC_CONFIG_OFF         "none"
37 #define HDC_CONFIG_ON          "hdc"
38 #define HDC_CONFIG_RNDIS       "rndis"
39 #define HDC_CONFIG_STORAGE     "storage"
40 #define HDC_CONFIG_RNDIS_HDC   "rndis_hdc"
41 #define HDC_CONFIG_STORAGE_HDC "storage_hdc"
42 #define HDC_CONFIGFS_OFF       "0"
43 #define HDC_CONFIGFS_ON        "1"
44 
45 #define FUNCTION_ADD 1
46 #define FUNCTION_DEL 2
47 
48 #define ACM_INIT    100
49 #define ACM_RELEASE 101
50 #define ECM_INIT    100
51 #define ECM_RELEASE 101
52 
53 #define USB_DDK_FUNCTION_SUPPORT (USB_FUNCTION_ACM | USB_FUNCTION_ECM)
54 namespace OHOS {
55 namespace HDI {
56 namespace Usb {
57 namespace V1_0 {
58 class UsbdFunction {
59 public:
60     UsbdFunction() = default;
61     ~UsbdFunction() = default;
62     static int32_t UsbdSetFunction(uint32_t funcs);
63     static int32_t UsbdGetFunction();
64 
65 private:
66     static int32_t SendCmdToService(const char *name, int32_t cmd, unsigned char funcMask);
67     static int32_t RemoveHdc();
68     static int32_t AddHdc();
69     static int32_t SetFunctionToNone();
70     static int32_t SetFunctionToRndis();
71     static int32_t SetFunctionToStorage();
72     static int32_t SetFunctionToRndisHdc();
73     static int32_t SetFunctionToStorageHdc();
74     static int32_t SetDDKFunction(uint32_t funcs);
75     static int32_t UsbdEnableDevice();
76     static int32_t UsbdWaitUdc();
77     static int32_t UsbdInitDDKFunction(uint32_t funcs);
78     static int32_t UsbdSetKernelFunction(int32_t kfuns);
79     static uint32_t currentFuncs_;
80 };
81 } // namespace V1_0
82 } // namespace Usb
83 } // namespace HDI
84 } // namespace OHOS
85 #endif // OHOS_HDI_USB_V1_0_USBD_FUNCTION_H
86