1 /* 2 * Copyright (C) 2021 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 #ifndef HDC_DEFINE_H 16 #define HDC_DEFINE_H 17 #include "define_plus.h" 18 19 namespace Hdc { 20 // ############################## config ####################################### 21 #ifndef USE_CONFIG_UV_THREADS 22 constexpr size_t SIZE_THREAD_POOL = 16; 23 #endif 24 constexpr size_t SIZE_THREAD_POOL_MIN = 16; 25 constexpr size_t SIZE_THREAD_POOL_MAX = 256; 26 constexpr uint8_t GLOBAL_TIMEOUT = 30; 27 constexpr uint16_t DEFAULT_PORT = 8710; 28 #ifdef FEATURE_HOST_LOG_COMPRESS 29 constexpr uint16_t MAX_LOG_FILE_COUNT = 300; 30 #else 31 constexpr uint16_t MAX_LOG_FILE_COUNT = 30; 32 #endif 33 constexpr uint64_t MAX_LOG_FILE_SIZE = static_cast<uint64_t>(100) * 1024 * 1024; // 100MB 34 constexpr uint64_t MAX_LOG_DIR_SIZE = static_cast<uint64_t>(3) * 1024 * 1024 * 1024; // 3GB 35 constexpr bool ENABLE_IO_CHECKSUM = false; 36 const string IPV4_MAPPING_PREFIX = "::ffff:"; 37 const string DEFAULT_SERVER_ADDR_IP = "::ffff:127.0.0.1"; 38 const string DEFAULT_SERVER_ADDR = "::ffff:127.0.0.1:8710"; 39 const string ENV_SERVER_PORT = "OHOS_HDC_SERVER_PORT"; 40 const string ENV_SERVER_LOG = "OHOS_HDC_LOG_LEVEL"; 41 const string ENV_SERVER_LOG_LIMIT = "OHOS_HDC_LOG_LIMIT"; 42 const string ENV_SERVER_HEARTBEAT = "OHOS_HDC_HEARTBEAT"; // 1: turn off heartbeat 43 44 // ################################ macro define ################################### 45 constexpr uint8_t MINOR_TIMEOUT = 5; 46 constexpr uint8_t MILL_SECONDS = 10; 47 constexpr uint8_t WAIT_SECONDS = 30; 48 constexpr uint8_t DWORD_SERIALIZE_SIZE = 4; 49 constexpr uint8_t OFFSET = 2; 50 constexpr uint8_t CMD_ARG1_COUNT = 2; 51 constexpr uint8_t COUNT = 10; 52 constexpr uint8_t STREAM_MAIN = 0; // work at main thread 53 constexpr uint8_t STREAM_WORK = 1; // work at work thread 54 constexpr uint8_t STREAM_SIZE = 2; 55 constexpr uint8_t FEATURE_FLAG_MAX_SIZE = 8; 56 constexpr uint16_t TIME_BUF_SIZE = 32; 57 constexpr uint16_t BUF_SIZE_MICRO = 16; 58 constexpr uint16_t BUF_SIZE_TINY = 64; 59 constexpr uint16_t BUF_SIZE_SMALL = 256; 60 constexpr uint16_t BUF_SIZE_MEDIUM = 512; 61 constexpr uint16_t BUF_SIZE_DEFAULT = 1024; 62 constexpr uint16_t BUF_SIZE_DEFAULT2 = BUF_SIZE_DEFAULT * 2; 63 constexpr uint16_t BUF_SIZE_DEFAULT4 = BUF_SIZE_DEFAULT * 4; 64 constexpr uint16_t MAX_IP_PORT = 65535; 65 constexpr uint16_t MAX_CONNECTKEY_SIZE = 32; // usb sn/tcp ipport 66 constexpr uint16_t TIME_BASE = 1000; // time unit conversion base value 67 constexpr uint16_t UV_DEFAULT_INTERVAL = 250; // ms 68 constexpr uint16_t VER_PROTOCOL = 0x01; 69 constexpr uint16_t MAX_PACKET_SIZE_HISPEED = 512; 70 constexpr uint16_t DEVICE_CHECK_INTERVAL = 3000; // ms 71 constexpr uint32_t MAX_SIZE_IOBUF = 511 * 1024; // 511KB, large file transfer speed up 72 constexpr uint32_t MAX_USBFFS_BULK = 512 * 1024; // 512KB, large file transfer speed up 73 constexpr uint32_t MAX_SIZE_IOBUF_STABLE = 60 * 1024; // 60KB, compatible with previous version 74 constexpr uint32_t MAX_USBFFS_BULK_STABLE = 61 * 1024; // 61KB, compatible with provious version 75 constexpr uint16_t MAX_LOG_TIMER = 20; 76 constexpr uint16_t MAX_LOG_REPRINT_COUNT = 5; 77 constexpr double DECODE_SCALE = 0.75; 78 constexpr uint16_t LAST_EQUAL_NUM = 2; 79 constexpr uint16_t UV_START_TIMEOUT = 10; 80 constexpr uint16_t UV_START_REPEAT = 10; 81 constexpr uint16_t UV_LISTEN_LBACKOG = 4; 82 constexpr uint16_t BUF_EXTEND_SIZE = 4; 83 constexpr uint16_t BUF_MULTIPLE = 2; 84 constexpr uint16_t EXPECTED_LEN = 9; 85 constexpr uint16_t MAX_APP_PARAM_SIZE = 512; 86 constexpr uint16_t MIN_APP_PARAM_SIZE = 4; 87 constexpr uint16_t FORWORD_PORT_RM_BUF_SIZE = 9; 88 constexpr uint16_t FORWORD_PORT_OTHER_BUF_SIZE = 6; 89 constexpr uint16_t CMD_REMOTE_SIZE = 8; 90 constexpr uint16_t PORT_MAX_LEN = 5; 91 constexpr uint16_t START_SERVER_FOR_CLIENT_TIME = 300; 92 constexpr uint16_t START_CMD_WAIT_TIME = 3000; // 3 seconds, for client wait for server start 93 constexpr uint16_t CMD_FILE_PENULT_PARAM = 2; 94 constexpr uint16_t BUNDLE_MIN_SIZE = 7; 95 constexpr uint16_t BUNDLE_MAX_SIZE = 128; 96 constexpr uint16_t HEARTBEAT_INTERVAL = 5000; // 5 seconds 97 #ifdef HDC_HOST 98 constexpr uint16_t MAX_DELETED_SESSION_ID_RECORD_COUNT = 32; 99 #else 100 constexpr uint16_t MAX_DELETED_SESSION_ID_RECORD_COUNT = 10; 101 #endif 102 constexpr uint16_t TCP_CONNECT_MAX_RETRY_COUNT = 6; 103 constexpr uint16_t TCP_CONNECT_RETRY_TIME_MS = 500; 104 105 // the maximum time (in milliseconds) to drop USB channel data for new session 106 constexpr uint16_t NEW_SESSION_DROP_USB_DATA_TIME_MAX_MS = 1000; 107 108 // double-word(hex)=[0]major[1][2]minor[3][4]version[5]fix(a-p)[6][7]reserve 109 // |----------------------------------------------------------------| 110 // | 31-28 | 27-24 | 23-20 | 19-16 | 15-12 | 11-08 | 07-00 | 111 // |----------------------------------------------------------------| 112 // | major |reserve| minor |reserve|version| fix | reserve | 113 // |----------------------------------------------------------------| 114 // 0x30100400 is 3.1.0e 115 constexpr uint32_t HDC_VERSION_NUMBER = 0x30100400; 116 constexpr uint32_t HDC_BUF_MAX_BYTES = INT_MAX; 117 #ifdef HDC_HOST 118 constexpr uint32_t HOST_SOCKETPAIR_SIZE = 1024 * 1024; 119 #endif 120 constexpr uint32_t HDC_SOCKETPAIR_SIZE = MAX_SIZE_IOBUF * 2; 121 // "\f" asicc is 12 122 const string HDC_HOST_DAEMON_BUF_SEPARATOR = "\f"; 123 constexpr int32_t RSA_KEY_BITS = 3072; 124 125 const string WHITE_SPACES = " \t\n\r"; 126 const string UT_TMP_PATH = "/tmp/hdc-ut"; 127 const string DEBUG_BUNDLE_PATH = "/mnt/debug/100/debug_hap/"; 128 const string LOG_FILE_NAME = "hdc.log"; 129 const string LOG_FILE_NAME_PREFIX = "hdc-"; 130 const string LOG_FILE_SUFFIX = ".log"; 131 const string LOG_FILE_COMPRESS_SUFFIX = ".tgz"; 132 const string LOG_COMPRESS_TOOL_NAME = "tar"; 133 const string LOG_CACHE_NAME = ".hdc.cache.log"; 134 const string LOG_DIR_NAME = "hdc_logs"; 135 const string LOG_COMPRESS_TOOL_PARAMS = "czfp"; 136 const string SERVER_NAME = "HDCServer"; 137 const string STRING_EMPTY = ""; 138 const string HANDSHAKE_MESSAGE = "OHOS HDC"; // sep not char '-', not more than 11 bytes 139 const string HANDSHAKE_FAILED = "HS FAILED"; 140 const string PACKET_FLAG = "HW"; // must 2bytes 141 const string EMPTY_ECHO = "[Empty]"; 142 const string MESSAGE_INFO = "[Info]"; 143 const string MESSAGE_FAIL = "[Fail]"; 144 const string MESSAGE_SUCCESS = "[Success]"; 145 const char HUGE_BUF_TAG = 'H'; // support huge buffer 146 const size_t BANNER_FEATURE_TAG_OFFSET = 11; 147 const char WAIT_DEVICE_TAG = 'W'; 148 const size_t WAIT_TAG_OFFSET = 11; 149 // input command 150 const string CMDSTR_SOFTWARE_VERSION = "version"; 151 const string CMDSTR_SOFTWARE_HELP = "help"; 152 const string CMDSTR_TARGET_DISCOVER = "discover"; 153 const string CMDSTR_SERVICE_START = "start"; 154 const string CMDSTR_SERVICE_KILL = "kill"; 155 const string CMDSTR_GENERATE_KEY = "keygen"; 156 const string CMDSTR_LIST_TARGETS = "list targets"; 157 const string CMDSTR_CHECK_SERVER = "checkserver"; 158 const string CMDSTR_CHECK_DEVICE = "checkdevice"; 159 const string CMDSTR_WAIT_FOR = "wait"; 160 const string CMDSTR_CONNECT_TARGET = "tconn"; 161 const string CMDSTR_CONNECT_ANY = "any"; 162 const string CMDSTR_SHELL = "shell"; 163 const string CMDSTR_SHELL_EX = "shell -"; 164 const string CMDSTR_TARGET_REBOOT = "target boot"; 165 const string CMDSTR_TARGET_MOUNT = "target mount"; 166 const string CMDSTR_STARTUP_MODE = "smode"; 167 const string CMDSTR_TARGET_MODE = "tmode"; 168 const string CMDSTR_BUGREPORT = "bugreport"; 169 const string CMDSTR_HILOG = "hilog"; 170 const string CMDSTR_TMODE_USB = "usb"; 171 #ifdef _WIN32 172 const string HILOG_NAME = "hilog.exe"; 173 const string SPLIT = "\\"; 174 const string LOG_COMPRESS_TOOL_BIN_WIN32 = "C:\\Windows\\System32\\tar.exe"; 175 #else 176 const string LOG_COMPRESS_TOOL_BIN_UNIX = "tar"; 177 #endif 178 #ifdef HDC_SUPPORT_UART 179 const string CMDSTR_TMODE_UART = "uart"; 180 const string UART_HDC_NODE = "/dev/ttyS4"; 181 const string CONSOLE_ACTIVE_NODE = "/sys/class/tty/console/active"; 182 constexpr int UART_IO_WAIT_TIME_100 = 100; 183 constexpr int UART_IO_WAIT_TIME = 1000; 184 constexpr uint16_t MAX_UART_SIZE_IOBUF = 4096; // MAX_SIZE_IOBUF; 185 #endif 186 const string CMDSTR_TMODE_TCP = "tcp"; 187 #ifdef HDC_EMULATOR 188 const string CMDSTR_TMODE_BRIDGE = "bridge"; 189 #endif 190 const string CMDSTR_FILE_SEND = "file send"; 191 const string CMDSTR_FILE_RECV = "file recv"; 192 const string CMDSTR_REMOTE_PARAMETER = "remote"; 193 const string CMDSTR_FORWARD_FPORT = "fport"; 194 const string CMDSTR_FORWARD_RPORT = "rport"; 195 const string CMDSTR_APP_INSTALL = "install"; 196 const string CMDSTR_APP_UNINSTALL = "uninstall"; 197 const string CMDSTR_APP_SIDELOAD = "sideload"; 198 const string CMDSTR_LIST_JDWP = "jpid"; 199 const string CMDSTR_TRACK_JDWP = "track-jpid"; 200 const string CMDSTR_INNER_ENABLE_KEEPALIVE = "alive"; 201 const string CMDSTR_FLASHD_UPDATE = "update"; 202 const string CMDSTR_FLASHD_FLASH = "flash"; 203 const string CMDSTR_FLASHD_ERASE = "erase"; 204 const string CMDSTR_FLASHD_FORMAT = "format"; 205 const string STR_FEATURE_ENABLE = "enable"; 206 const string STR_FEATURE_DISABLE = "disable"; 207 // ################################ Error Message ################################### 208 const string TERMINAL_HDC_PROCESS_FAILED = "[E002101]:Terminal hdc process failed, "\ 209 "please terminal the hdc process in the task manager first."; 210 211 // ################################ Macro define ################################### 212 #ifdef IS_RELEASE_VERSION 213 #define WRITE_LOG(level, fmt, ...) Base::PrintLogEx(__FUNCTION__, __LINE__, level, fmt, ##__VA_ARGS__) 214 #else 215 #define WRITE_LOG(level, fmt, ...) Base::PrintLogEx(__FILE_NAME__, __LINE__, level, fmt, ##__VA_ARGS__) 216 #endif 217 #ifdef HDC_DEBUG 218 #define DEBUG_LOG(fmt, ...) WRITE_LOG(LOG_DEBUG, fmt, ##__VA_ARGS__) 219 #else 220 #define DEBUG_LOG(fmt, ...) 221 #endif 222 223 #ifdef _WIN32 224 #define hdc_strerrno(buf) \ 225 char buf[1024] = { 0 }; \ 226 strerror_s(buf, 1024, errno) 227 #else 228 #define hdc_strerrno(buf) \ 229 char buf[1024] = { 0 }; \ 230 strerror_r(errno, buf, 1024) 231 #endif 232 } // namespace Hdc 233 #endif // HDC_DEFINE_H 234