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