1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef OHOS_HDI_USB_V1_1_USBD_FUNCTION_H 17094332d3Sopenharmony_ci#define OHOS_HDI_USB_V1_1_USBD_FUNCTION_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include <stdint.h> 20094332d3Sopenharmony_ci#include <string> 21094332d3Sopenharmony_ci 22094332d3Sopenharmony_ci#define USB_FUNCTION_NONE 0 23094332d3Sopenharmony_ci#define USB_FUNCTION_ACM (1 << 0) 24094332d3Sopenharmony_ci#define USB_FUNCTION_ECM (1 << 1) 25094332d3Sopenharmony_ci#define USB_FUNCTION_HDC (1 << 2) 26094332d3Sopenharmony_ci#define USB_FUNCTION_MTP (1 << 3) 27094332d3Sopenharmony_ci#define USB_FUNCTION_PTP (1 << 4) 28094332d3Sopenharmony_ci#define USB_FUNCTION_RNDIS (1 << 5) 29094332d3Sopenharmony_ci#define USB_FUNCTION_STORAGE (1 << 9) 30094332d3Sopenharmony_ci#define USB_FUNCTION_MANUFACTURE (1 << 10) 31094332d3Sopenharmony_ci#define USB_FUNCTION_SUPPORT \ 32094332d3Sopenharmony_ci (USB_FUNCTION_ACM | USB_FUNCTION_ECM | USB_FUNCTION_HDC | USB_FUNCTION_MTP | USB_FUNCTION_PTP | \ 33094332d3Sopenharmony_ci USB_FUNCTION_RNDIS | USB_FUNCTION_STORAGE | USB_FUNCTION_MANUFACTURE) 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_ci#define DEV_SERVICE_NAME "usbfn" 36094332d3Sopenharmony_ci#define ACM_SERVICE_NAME "usbfn_cdcacm" 37094332d3Sopenharmony_ci#define ECM_SERVICE_NAME "usbfn_cdcecm" 38094332d3Sopenharmony_ci 39094332d3Sopenharmony_ci#define SYS_USB_CONFIGFS "sys.usb.configfs" 40094332d3Sopenharmony_ci#define SYS_USB_CONFIG "sys.usb.config" 41094332d3Sopenharmony_ci#define SYS_USB_STATE "sys.usb.state" 42094332d3Sopenharmony_ci#define PERSIST_SYS_USB_CONFIG "persist.sys.usb.config" 43094332d3Sopenharmony_ci#define HDC_CONFIG_OFF "none" 44094332d3Sopenharmony_ci#define HDC_CONFIG_HDC "hdc" 45094332d3Sopenharmony_ci#define HDC_CONFIG_ON "hdc_debug" 46094332d3Sopenharmony_ci#define HDC_CONFIG_RNDIS "rndis" 47094332d3Sopenharmony_ci 48094332d3Sopenharmony_ci#ifdef USB_EVENT_NOTIFY_LINUX_NATIVE_MODE 49094332d3Sopenharmony_ci#define HDC_CONFIG_STORAGE "hisuite_mass_storage" 50094332d3Sopenharmony_ci#else 51094332d3Sopenharmony_ci#define HDC_CONFIG_STORAGE "storage" 52094332d3Sopenharmony_ci#endif 53094332d3Sopenharmony_ci 54094332d3Sopenharmony_ci#define HDC_CONFIG_RNDIS_HDC "rndis_hdc" 55094332d3Sopenharmony_ci#define HDC_CONFIG_STORAGE_HDC "storage_hdc" 56094332d3Sopenharmony_ci#define HDC_CONFIG_MANUFACTURE_HDC "manufacture_hdc" 57094332d3Sopenharmony_ci#define HDC_CONFIGFS_OFF "0" 58094332d3Sopenharmony_ci#define HDC_CONFIGFS_ON "1" 59094332d3Sopenharmony_ci 60094332d3Sopenharmony_ci#define FUNCTION_ADD 1 61094332d3Sopenharmony_ci#define FUNCTION_DEL 2 62094332d3Sopenharmony_ci 63094332d3Sopenharmony_ci#define ACM_INIT 100 64094332d3Sopenharmony_ci#define ACM_RELEASE 101 65094332d3Sopenharmony_ci#define ECM_INIT 100 66094332d3Sopenharmony_ci#define ECM_RELEASE 101 67094332d3Sopenharmony_ci#define MTP_PTP_INIT 100 68094332d3Sopenharmony_ci#define MTP_PTP_RELEASE 101 69094332d3Sopenharmony_ci 70094332d3Sopenharmony_ci#define USB_DDK_FUNCTION_SUPPORT (USB_FUNCTION_ACM | USB_FUNCTION_ECM | USB_FUNCTION_MTP | USB_FUNCTION_PTP) 71094332d3Sopenharmony_ci#define HDC_READY_TIME 2000 72094332d3Sopenharmony_ci 73094332d3Sopenharmony_cinamespace OHOS { 74094332d3Sopenharmony_cinamespace HDI { 75094332d3Sopenharmony_cinamespace Usb { 76094332d3Sopenharmony_cinamespace V1_1 { 77094332d3Sopenharmony_ciclass UsbdFunction { 78094332d3Sopenharmony_cipublic: 79094332d3Sopenharmony_ci UsbdFunction() = default; 80094332d3Sopenharmony_ci ~UsbdFunction() = default; 81094332d3Sopenharmony_ci static int32_t UsbdSetFunction(uint32_t funcs); 82094332d3Sopenharmony_ci static int32_t UsbdGetFunction(); 83094332d3Sopenharmony_ci static int32_t UsbdUpdateFunction(uint32_t funcs); 84094332d3Sopenharmony_ci 85094332d3Sopenharmony_ciprivate: 86094332d3Sopenharmony_ci static int32_t SendCmdToService(const char *name, int32_t cmd, unsigned char funcMask); 87094332d3Sopenharmony_ci static int32_t RemoveHdc(); 88094332d3Sopenharmony_ci static int32_t AddHdc(); 89094332d3Sopenharmony_ci static int32_t SetFunctionToNone(); 90094332d3Sopenharmony_ci static int32_t SetFunctionToRndis(); 91094332d3Sopenharmony_ci static int32_t SetFunctionToStorage(); 92094332d3Sopenharmony_ci static int32_t SetFunctionToRndisHdc(); 93094332d3Sopenharmony_ci static int32_t SetFunctionToStorageHdc(); 94094332d3Sopenharmony_ci static int32_t SetFunctionToManufactureHdc(); 95094332d3Sopenharmony_ci static int32_t SetDDKFunction(uint32_t funcs); 96094332d3Sopenharmony_ci static int32_t UsbdEnableDevice(int32_t funcs); 97094332d3Sopenharmony_ci static int32_t UsbdWaitUdc(); 98094332d3Sopenharmony_ci static int32_t UsbdWaitToNone(); 99094332d3Sopenharmony_ci static int32_t UsbdInitDDKFunction(uint32_t funcs); 100094332d3Sopenharmony_ci static int32_t UsbdSetKernelFunction(int32_t kfuns, int32_t funcs); 101094332d3Sopenharmony_ci static int32_t UsbdReadUdc(char* udcName, size_t len); 102094332d3Sopenharmony_ci static int32_t UsbdWriteUdc(char* udcName, size_t len); 103094332d3Sopenharmony_ci static void UsbdUnregisterDevice(const std::string &serviceName); 104094332d3Sopenharmony_ci static int32_t UsbdRegisterDevice(const std::string &serviceName); 105094332d3Sopenharmony_ci static int32_t InitMtp(); 106094332d3Sopenharmony_ci static int32_t ReleaseMtp(); 107094332d3Sopenharmony_ci 108094332d3Sopenharmony_ci static uint32_t currentFuncs_; 109094332d3Sopenharmony_ci}; 110094332d3Sopenharmony_ci} // namespace V1_1 111094332d3Sopenharmony_ci} // namespace Usb 112094332d3Sopenharmony_ci} // namespace HDI 113094332d3Sopenharmony_ci} // namespace OHOS 114094332d3Sopenharmony_ci#endif // OHOS_HDI_USB_V1_1_USBD_FUNCTION_H 115