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_1_USBD_FUNCTION_H 17 #define OHOS_HDI_USB_V1_1_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_MANUFACTURE (1 << 10) 31 #define USB_FUNCTION_SUPPORT \ 32 (USB_FUNCTION_ACM | USB_FUNCTION_ECM | USB_FUNCTION_HDC | USB_FUNCTION_MTP | USB_FUNCTION_PTP | \ 33 USB_FUNCTION_RNDIS | USB_FUNCTION_STORAGE | USB_FUNCTION_MANUFACTURE) 34 35 #define DEV_SERVICE_NAME "usbfn" 36 #define ACM_SERVICE_NAME "usbfn_cdcacm" 37 #define ECM_SERVICE_NAME "usbfn_cdcecm" 38 39 #define SYS_USB_CONFIGFS "sys.usb.configfs" 40 #define SYS_USB_CONFIG "sys.usb.config" 41 #define SYS_USB_STATE "sys.usb.state" 42 #define PERSIST_SYS_USB_CONFIG "persist.sys.usb.config" 43 #define HDC_CONFIG_OFF "none" 44 #define HDC_CONFIG_HDC "hdc" 45 #define HDC_CONFIG_ON "hdc_debug" 46 #define HDC_CONFIG_RNDIS "rndis" 47 48 #ifdef USB_EVENT_NOTIFY_LINUX_NATIVE_MODE 49 #define HDC_CONFIG_STORAGE "hisuite_mass_storage" 50 #else 51 #define HDC_CONFIG_STORAGE "storage" 52 #endif 53 54 #define HDC_CONFIG_RNDIS_HDC "rndis_hdc" 55 #define HDC_CONFIG_STORAGE_HDC "storage_hdc" 56 #define HDC_CONFIG_MANUFACTURE_HDC "manufacture_hdc" 57 #define HDC_CONFIGFS_OFF "0" 58 #define HDC_CONFIGFS_ON "1" 59 60 #define FUNCTION_ADD 1 61 #define FUNCTION_DEL 2 62 63 #define ACM_INIT 100 64 #define ACM_RELEASE 101 65 #define ECM_INIT 100 66 #define ECM_RELEASE 101 67 #define MTP_PTP_INIT 100 68 #define MTP_PTP_RELEASE 101 69 70 #define USB_DDK_FUNCTION_SUPPORT (USB_FUNCTION_ACM | USB_FUNCTION_ECM | USB_FUNCTION_MTP | USB_FUNCTION_PTP) 71 #define HDC_READY_TIME 2000 72 73 namespace OHOS { 74 namespace HDI { 75 namespace Usb { 76 namespace V1_1 { 77 class UsbdFunction { 78 public: 79 UsbdFunction() = default; 80 ~UsbdFunction() = default; 81 static int32_t UsbdSetFunction(uint32_t funcs); 82 static int32_t UsbdGetFunction(); 83 static int32_t UsbdUpdateFunction(uint32_t funcs); 84 85 private: 86 static int32_t SendCmdToService(const char *name, int32_t cmd, unsigned char funcMask); 87 static int32_t RemoveHdc(); 88 static int32_t AddHdc(); 89 static int32_t SetFunctionToNone(); 90 static int32_t SetFunctionToRndis(); 91 static int32_t SetFunctionToStorage(); 92 static int32_t SetFunctionToRndisHdc(); 93 static int32_t SetFunctionToStorageHdc(); 94 static int32_t SetFunctionToManufactureHdc(); 95 static int32_t SetDDKFunction(uint32_t funcs); 96 static int32_t UsbdEnableDevice(int32_t funcs); 97 static int32_t UsbdWaitUdc(); 98 static int32_t UsbdWaitToNone(); 99 static int32_t UsbdInitDDKFunction(uint32_t funcs); 100 static int32_t UsbdSetKernelFunction(int32_t kfuns, int32_t funcs); 101 static int32_t UsbdReadUdc(char* udcName, size_t len); 102 static int32_t UsbdWriteUdc(char* udcName, size_t len); 103 static void UsbdUnregisterDevice(const std::string &serviceName); 104 static int32_t UsbdRegisterDevice(const std::string &serviceName); 105 static int32_t InitMtp(); 106 static int32_t ReleaseMtp(); 107 108 static uint32_t currentFuncs_; 109 }; 110 } // namespace V1_1 111 } // namespace Usb 112 } // namespace HDI 113 } // namespace OHOS 114 #endif // OHOS_HDI_USB_V1_1_USBD_FUNCTION_H 115