• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 #include <string>
21 
22 #define USB_FUNCTION_NONE    0
23 #define USB_FUNCTION_ACM     (1 << 0)
24 #define USB_FUNCTION_ECM     (1 << 1)
25 #define USB_FUNCTION_HDC     (1 << 2)
26 #define USB_FUNCTION_MTP     (1 << 3)
27 #define USB_FUNCTION_PTP     (1 << 4)
28 #define USB_FUNCTION_RNDIS   (1 << 5)
29 #define USB_FUNCTION_STORAGE (1 << 9)
30 #define USB_FUNCTION_SUPPORT                                                                        \
31     (USB_FUNCTION_ACM | USB_FUNCTION_ECM | USB_FUNCTION_HDC | USB_FUNCTION_MTP | USB_FUNCTION_PTP | \
32         USB_FUNCTION_RNDIS | USB_FUNCTION_STORAGE)
33 
34 #define DEV_SERVICE_NAME "usbfn"
35 #define ACM_SERVICE_NAME "usbfn_cdcacm"
36 #define ECM_SERVICE_NAME "usbfn_cdcecm"
37 
38 #define SYS_USB_CONFIGFS       "sys.usb.configfs"
39 #define SYS_USB_CONFIG         "sys.usb.config"
40 #define HDC_CONFIG_OFF         "none"
41 #define HDC_CONFIG_ON          "hdc"
42 #define HDC_CONFIG_RNDIS       "rndis"
43 #define HDC_CONFIG_STORAGE     "storage"
44 #define HDC_CONFIG_RNDIS_HDC   "rndis_hdc"
45 #define HDC_CONFIG_STORAGE_HDC "storage_hdc"
46 #define HDC_CONFIGFS_OFF       "0"
47 #define HDC_CONFIGFS_ON        "1"
48 
49 #define FUNCTION_ADD 1
50 #define FUNCTION_DEL 2
51 
52 #define ACM_INIT        100
53 #define ACM_RELEASE     101
54 #define ECM_INIT        100
55 #define ECM_RELEASE     101
56 #define MTP_PTP_INIT    100
57 #define MTP_PTP_RELEASE 101
58 
59 #define USB_DDK_FUNCTION_SUPPORT (USB_FUNCTION_ACM | USB_FUNCTION_ECM | USB_FUNCTION_MTP | USB_FUNCTION_PTP)
60 #define HDC_READY_TIME           2000
61 
62 namespace OHOS {
63 namespace HDI {
64 namespace Usb {
65 namespace V1_0 {
66 class UsbdFunction {
67 public:
68     UsbdFunction() = default;
69     ~UsbdFunction() = default;
70     static int32_t UsbdSetFunction(uint32_t funcs);
71     static int32_t UsbdGetFunction();
72 
73 private:
74     static int32_t SendCmdToService(const char *name, int32_t cmd, unsigned char funcMask);
75     static int32_t RemoveHdc();
76     static int32_t AddHdc();
77     static int32_t SetFunctionToNone();
78     static int32_t SetFunctionToRndis();
79     static int32_t SetFunctionToStorage();
80     static int32_t SetFunctionToRndisHdc();
81     static int32_t SetFunctionToStorageHdc();
82     static int32_t SetDDKFunction(uint32_t funcs);
83     static int32_t UsbdEnableDevice();
84     static int32_t UsbdWaitUdc();
85     static int32_t UsbdInitDDKFunction(uint32_t funcs);
86     static int32_t UsbdSetKernelFunction(int32_t kfuns);
87     static void UsbdUnregisterDevice(const std::string &serviceName);
88     static int32_t UsbdRegisterDevice(const std::string &serviceName);
89     static int32_t InitMtp();
90     static int32_t ReleaseMtp();
91 
92     static uint32_t currentFuncs_;
93 };
94 } // namespace V1_0
95 } // namespace Usb
96 } // namespace HDI
97 } // namespace OHOS
98 #endif // OHOS_HDI_USB_V1_0_USBD_FUNCTION_H
99