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 #include "translate.h" 16 #include "host_updater.h" 17 18 namespace Hdc { 19 namespace TranslateCommand { Usage()20 string Usage() 21 { 22 string ret = ""; 23 ret = "\n OpenHarmony device connector(hdc) ...\n\n" 24 "---------------------------------global commands:----------------------------------\n" 25 " -h/help [verbose] - Print hdc help, 'verbose' for more other cmds\n" 26 " -v/version - Print hdc version\n" 27 " -t connectkey - Use device with given connect key\n" 28 "\n" 29 "---------------------------------component commands:-------------------------------\n" 30 "session commands(on server):\n" 31 " list targets [-v] - List all devices status, -v for detail\n" 32 " start [-r] - Start server. If with '-r', will be restart server\n" 33 " kill [-r] - Kill server. If with '-r', will be restart server\n" 34 "\n" 35 "service commands(on daemon):\n" 36 " target mount - Set /system /vendor partition read-write\n" 37 " wait - Wait for the device to become available\n" 38 " target boot [-bootloader|-recovery] - Reboot the device or boot into bootloader\\recovery.\n" 39 " target boot [MODE] - Reboot the into MODE.\n" 40 " smode [-r] - Restart daemon with root permissions, '-r' to cancel root\n" 41 " permissions\n" 42 " tmode usb - Reboot the device, listening on USB\n" 43 " tmode port [port] - Reboot the device, listening on TCP port\n" 44 "\n" 45 "---------------------------------task commands:-------------------------------------\n" 46 "file commands:\n" 47 " file send [option] local remote - Send file to device\n" 48 " file recv [option] remote local - Recv file from device\n" 49 " option is -a|-s|-z\n" 50 " -a: hold target file timestamp\n" 51 " -sync: just update newer file\n" 52 " -z: compress transfer, not improve transmission efficiency\n" 53 " for compressed files\n" 54 " -m: mode sync\n" 55 " -b: send/receive file to debug application directory\n" 56 "\n" 57 "forward commands:\n" 58 " fport localnode remotenode - Forward local traffic to remote device\n" 59 " rport remotenode localnode - Reserve remote traffic to local host\n" 60 " node config name format 'schema:content'\n" 61 " examples are below:\n" 62 " tcp:<port>\n" 63 " localfilesystem:<unix domain socket name>\n" 64 " localreserved:<unix domain socket name>\n" 65 " localabstract:<unix domain socket name>\n" 66 " dev:<device name>\n" 67 " jdwp:<pid> (remote only)\n" 68 " ark:pid@tid@Debugger\n" 69 " fport ls - Display forward/reverse tasks\n" 70 " fport rm taskstr - Remove forward/reverse task by taskstring\n" 71 "\n" 72 "app commands:\n" 73 " install [-r|-s] src - Send package(s) to device and install them\n" 74 " src examples: single or multiple packages and directories\n" 75 " (.hap .hsp)\n" 76 " -r: replace existing application\n" 77 " -s: install shared bundle for multi-apps\n" 78 " uninstall [-k] [-s] package - Remove application package from device\n" 79 " -k: keep the data and cache directories\n" 80 " -s: remove shared bundle\n" 81 "\n" 82 "debug commands:\n" 83 " hilog [-h] - Show device log, -h for detail\n" 84 " shell [-b bundlename] [COMMAND...] - Run shell command (interactive shell if no command given)\n" 85 " -b: run command in specified debug application bundle path\n" 86 " bundle parameter only support non-interactive shell\n" 87 " bugreport [FILE] - Return all information from the device, stored in file if " 88 "FILE is specified\n" 89 " jpid - List PIDs of processes hosting a JDWP transport\n" 90 " track-jpid [-a|-p] - Track PIDs of debug processes hosting a JDWP transport\n" 91 " -a: include debug and release processes\n" 92 " -p: don't display debug and release tags\n" 93 #ifdef __OHOS__ 94 "\n"; 95 #else 96 "\n" 97 "security commands:\n" 98 " keygen FILE - Generate public/private key; key stored in FILE and FILE.pub\n" 99 "\n"; 100 #endif 101 return ret; 102 } 103 Verbose()104 string Verbose() 105 { 106 string ret = "\n OpenHarmony device connector(hdc) ...\n\n" 107 "---------------------------------global commands:----------------------------------\n" 108 " -h/help [verbose] - Print hdc help, 'verbose' for more other cmds\n" 109 " -v/version - Print hdc version\n" 110 " -l[0-5] - Set runtime loglevel\n" 111 " -t connectkey - Use device with given connect key\n" 112 " checkserver - check client-server version\n" 113 " checkdevice - check server-daemon version(only uart)\n" 114 "\n" 115 "---------------------------------component commands:-------------------------------\n" 116 "session commands(on server):\n" 117 " discover - Discover devices listening on TCP via LAN broadcast\n" 118 " list targets [-v] - List all devices status, -v for detail\n" 119 " tconn key - Connect device via key, TCP use ip:port\n" 120 " example:192.168.0.100:10178/192.168.0.100\n" 121 " USB connect automatic, TCP need to connect manually\n" 122 #ifdef HDC_SUPPORT_UART 123 "\n" 124 " UART connect need connect manually\n" 125 " Baud Rate can be specified with commas\n" 126 " key format: <Port Name>[,Baud Rate]\n" 127 " example: tconn COM5,921600\n" 128 " Default Baud Rate is 921600\n" 129 "\n" 130 #endif 131 " start [-r] - Start server. If with '-r', will be restart server\n" 132 " kill [-r] - Kill server. If with '-r', will be restart server\n" 133 #ifdef __OHOS__ 134 " -s [ip:]port | uds - Set hdc server listen config\n" 135 #else 136 " -s [ip:]port - Set hdc server listen config\n" 137 #endif 138 " -e ip - Set the IP address for which the host listens during TCP\n" 139 " port forwarding. The default value is 127.0.0.1,\n" 140 " cannot run in single client mode\n" 141 " -m - Start server at foreground\n" 142 " -p - Skip the server startup, run in single client mode\n" 143 "\n" 144 "service commands(on daemon):\n" 145 " target mount - Set /system /vendor partition read-write\n" 146 " target boot [-bootloader|-recovery] - Reboot the device or boot into bootloader\\recovery\n" 147 " target boot [MODE] - Reboot the into MODE\n" 148 " smode [-r] - Restart daemon with root permissions, '-r' to cancel root\n" 149 " permissions\n" 150 " tmode usb - Reboot the device, listening on USB\n" 151 " tmode port [port] - Reboot the device, listening on TCP port\n" 152 "\n" 153 "---------------------------------task commands:-------------------------------------\n" 154 "file commands:\n" 155 " file send [option] local remote - Send file to device\n" 156 " file recv [option] remote local - Recv file from device\n" 157 " option is -a|-s|-z\n" 158 " -a: hold target file timestamp\n" 159 " -sync: just update newer file\n" 160 " -z: compress transfer, not improve transmission efficiency\n" 161 " for compressed files\n" 162 " -m: mode sync\n" 163 " -b: send/receive file to debug application directory\n" 164 "\n" 165 "forward commands:\n" 166 " fport localnode remotenode - Forward local traffic to remote device\n" 167 " rport remotenode localnode - Reserve remote traffic to local host\n" 168 " node config name format 'schema:content'\n" 169 " examples are below:\n" 170 " tcp:<port>\n" 171 " localfilesystem:<unix domain socket name>\n" 172 " localreserved:<unix domain socket name>\n" 173 " localabstract:<unix domain socket name>\n" 174 " dev:<device name>\n" 175 " jdwp:<pid> (remote only)\n" 176 " ark:pid@tid@Debugger\n" 177 " fport ls - Display forward/reverse tasks\n" 178 " fport rm taskstr - Remove forward/reverse task by taskstring\n" 179 "\n" 180 "app commands:\n" 181 " install [-r|-s] src - Send package(s) to device and install them\n" 182 " src examples: single or multiple packages and directories\n" 183 " (.hap .hsp)\n" 184 " -r: replace existing application\n" 185 " -s: install shared bundle for multi-apps\n" 186 " uninstall [-k] [-s] package - Remove application package from device\n" 187 " -k: keep the data and cache directories\n" 188 " -s: remove shared bundle\n" 189 "\n" 190 "debug commands:\n" 191 " hilog [-h] - Show device log, -h for detail\n" 192 " shell [-b bundlename] [COMMAND...] - Run shell command (interactive shell if no command given)\n" 193 " -b: run command in specified debug application bundle path\n" 194 " bundle parameter only support non-interactive shell\n" 195 " bugreport [FILE] - Return all information from the device, stored in file if FILE " 196 "is specified\n" 197 " jpid - List PIDs of processes hosting a JDWP transport\n" 198 " sideload [PATH] - Sideload the given full OTA package\n" 199 "\n" 200 #ifndef __OHOS__ 201 "security commands:\n" 202 " keygen FILE - Generate public/private key; key stored in FILE and FILE.pub\n" 203 "\n" 204 #endif 205 "---------------------------------flash commands:------------------------------------\n" 206 "flash commands:\n" 207 " update packagename - Update system by package\n" 208 " flash [-f] partition imagename - Flash partition by image\n" 209 " erase [-f] partition - Erase partition\n" 210 " format [-f] partition - Format partition\n" 211 "---------------------------------external commands:------------------------------------\n" 212 "extconn key - Connect external device via key, TCP use ip:port(remian)\n" 213 "-S [ip:]port - Set hdc external server listen config\n" 214 "\n" 215 "---------------------------------environment variables:-----------------------------\n" 216 #ifdef _WIN32 217 "OHOS_HDC_SERVER_PORT - Set hdc server listen port(range 1~65535, default 8710)\n" 218 "OHOS_HDC_LOG_LEVEL - Set hdc server log level(range 0~5, default 5)\n" 219 "OHOS_HDC_HEARTBEAT - Set whether the hdc heartbeat function is disabled\n" 220 " (1: disabled, other: enabled, default: enabled)\n" 221 "OHOS_HDC_CMD_RECORD - Set whether the hdc command record function is enabled\n" 222 " (1: enabled, other: disabled, default: disabled)\n" 223 #ifdef HDC_SUPPORT_ENCRYPT_TCP 224 "OHOS_HDC_ENCRYPT_CHANNEL - Set whether to use an encrypted channel " 225 "when using a TCP connection\n" 226 " (1: enabled, other: disabled, default: disabled)\n" 227 #endif 228 #ifdef FEATURE_HOST_LOG_COMPRESS 229 "OHOS_HDC_LOG_LIMIT - Set the number of logs that trigger the total" 230 " log file size statistics (default 300 (files))\n" 231 #endif 232 #else 233 "$OHOS_HDC_SERVER_PORT - Set hdc server listen port(range 1~65535, default 8710)\n" 234 "$OHOS_HDC_LOG_LEVEL - Set hdc server log level(range 0~5, default 5)\n" 235 "$OHOS_HDC_HEARTBEAT - Set whether the hdc heartbeat function is disabled\n" 236 " (1: disabled, other: enabled, default: enabled)\n" 237 "$OHOS_HDC_CMD_RECORD - Set whether the hdc command record function is enabled\n" 238 " (1: enabled, other: disabled, default: disabled)\n" 239 #ifdef HDC_SUPPORT_ENCRYPT_TCP 240 "$OHOS_HDC_ENCRYPT_CHANNEL - Set whether to use an encrypted channel " 241 "when using a TCP connection\n" 242 " (1: enabled, other: disabled, default: disabled)\n" 243 #endif 244 #ifdef FEATURE_HOST_LOG_COMPRESS 245 "$OHOS_HDC_LOG_LIMIT - Set the number of logs that trigger the total" 246 " log file size statistics (default 300 (files))\n" 247 #endif 248 #endif 249 "\n"; 250 return ret; 251 } 252 TargetConnect(FormatCommand * outCmd)253 string TargetConnect(FormatCommand *outCmd) 254 { 255 string stringError; 256 if (Base::StringEndsWith(outCmd->parameters, " -remove")) { 257 outCmd->parameters = outCmd->parameters.substr(0, outCmd->parameters.size() - CMD_REMOTE_SIZE); 258 outCmd->cmdFlag = CMD_KERNEL_TARGET_DISCONNECT; 259 } else { 260 outCmd->cmdFlag = CMD_KERNEL_TARGET_CONNECT; 261 constexpr int maxKeyLength = 50; // 50: tcp max=21,USB max=8bytes, serial device name maybe long 262 if (outCmd->parameters.size() > maxKeyLength) { 263 stringError = "Error connect key's size"; 264 outCmd->bJumpDo = true; 265 } 266 } 267 size_t pos = outCmd->parameters.find(":"); 268 if (pos != std::string::npos) { 269 // tcp mode 270 string ip = outCmd->parameters.substr(0, pos); 271 if (!Base::IsValidIpv4(ip)) { 272 stringError = "[E001104]:IP address incorrect"; 273 outCmd->bJumpDo = true; 274 return stringError; 275 } 276 string sport = outCmd->parameters.substr(pos + 1); 277 WRITE_LOG(LOG_INFO, "TargetConnect ip:%s port:%s", ip.c_str(), sport.c_str()); 278 if (sport.empty() || !Base::IsDigitString(sport)) { 279 stringError = "Port incorrect"; 280 outCmd->bJumpDo = true; 281 return stringError; 282 } 283 if (ip == "localhost") { 284 ip = "127.0.0.1"; 285 outCmd->parameters.replace(0, pos, ip); 286 } 287 int port = static_cast<int>(strtol(sport.c_str(), nullptr, 10)); 288 sockaddr_in addr; 289 if ((port <= 0 || port > MAX_IP_PORT) || uv_ip4_addr(ip.c_str(), port, &addr) < 0) { 290 stringError = "IP:Port incorrect"; 291 outCmd->bJumpDo = true; 292 } 293 } 294 return stringError; 295 } 296 ForwardPort(const char * input,FormatCommand * outCmd)297 string ForwardPort(const char *input, FormatCommand *outCmd) 298 { 299 string stringError; 300 const char *pExtra = input + 6; // CMDSTR_FORWARD_FPORT CMDSTR_FORWARD_RPORT + " " size 301 if (!strncmp(input, CMDSTR_FORWARD_FPORT.c_str(), CMDSTR_FORWARD_FPORT.size()) && !strcmp(pExtra, "ls")) { 302 outCmd->cmdFlag = CMD_FORWARD_LIST; 303 } else if (!strncmp(input, CMDSTR_FORWARD_FPORT.c_str(), CMDSTR_FORWARD_FPORT.size()) && 304 !strncmp(pExtra, "rm", 2)) { // 2: "rm" size 305 outCmd->cmdFlag = CMD_FORWARD_REMOVE; 306 if (strcmp(pExtra, "rm")) { 307 outCmd->parameters = input + FORWORD_PORT_RM_BUF_SIZE; 308 } 309 } else { 310 const char *p = input + FORWORD_PORT_OTHER_BUF_SIZE; 311 // clang-format off 312 if (strncmp(p, "tcp:", 4) && // 4: "tcp:" size 313 strncmp(p, "localabstract:", 14) && // 14: "localabstract:" size 314 strncmp(p, "localreserved:", 14) && // 14: "localreserved:" size 315 strncmp(p, "localfilesystem:", 16) && // 16: "localfilesystem:" size 316 strncmp(p, "dev:", 4) && // 4: "dev:" size 317 strncmp(p, "jdwp:", 5) && // 5: "jdwp:" size 318 strncmp(p, "ark:", 4)) { // 4: "ark:" size 319 stringError = "Incorrect forward command"; 320 outCmd->bJumpDo = true; 321 } 322 // clang-format on 323 outCmd->cmdFlag = CMD_FORWARD_INIT; 324 outCmd->parameters = input; 325 } 326 return stringError; 327 } 328 RunMode(const char * input,FormatCommand * outCmd)329 string RunMode(const char *input, FormatCommand *outCmd) 330 { 331 string stringError; 332 outCmd->cmdFlag = CMD_UNITY_RUNMODE; 333 outCmd->parameters = input + CMDSTR_TARGET_MODE.size() + 1; // with ' ' 334 int portLength = 4; 335 int portSpaceLength = 5; 336 if (!strncmp(outCmd->parameters.c_str(), "port", portLength) && 337 !strcmp(outCmd->parameters.c_str(), CMDSTR_TMODE_USB.c_str())) { 338 stringError = "Error tmode command"; 339 outCmd->bJumpDo = true; 340 } else if (!strncmp(outCmd->parameters.c_str(), "port ", portSpaceLength)) { 341 const char *tmp = input + strlen("tmode port "); 342 // command is tmode port close 343 if (strcmp(tmp, "close") == 0) { 344 return stringError; 345 } 346 int port = atoi(tmp); 347 if (port > MAX_IP_PORT || port <= 0) { 348 stringError = "Incorrect port range"; 349 outCmd->bJumpDo = true; 350 } 351 } 352 return stringError; 353 } 354 TargetReboot(const char * input,FormatCommand * outCmd)355 void TargetReboot(const char *input, FormatCommand *outCmd) 356 { 357 outCmd->cmdFlag = CMD_UNITY_REBOOT; 358 if (strcmp(input, CMDSTR_TARGET_REBOOT.c_str())) { 359 outCmd->parameters = input + CMDSTR_TARGET_REBOOT.size() + 1; // with ' ' 360 if (outCmd->parameters == "-bootloader" || outCmd->parameters == "-recovery" || 361 outCmd->parameters == "-flashd") { 362 outCmd->parameters.erase(outCmd->parameters.begin()); 363 } 364 } 365 } 366 367 // command input 368 // client side:Enter string data formatting conversion to module see internal processing command String2FormatCommand(const char * inputRaw,int sizeInputRaw,FormatCommand * outCmd)369 string String2FormatCommand(const char *inputRaw, int sizeInputRaw, FormatCommand *outCmd) 370 { 371 string stringError; 372 string input = string(inputRaw, sizeInputRaw); 373 if (!strncmp(input.c_str(), CMDSTR_SOFTWARE_HELP.c_str(), CMDSTR_SOFTWARE_HELP.size())) { 374 outCmd->cmdFlag = CMD_KERNEL_HELP; 375 outCmd->bJumpDo = true; 376 if (strstr(input.c_str(), " verbose")) { 377 stringError = Verbose(); 378 } else { 379 stringError = Usage(); 380 } 381 } else if (!strcmp(input.c_str(), CMDSTR_SOFTWARE_VERSION.c_str())) { 382 outCmd->cmdFlag = CMD_KERNEL_HELP; 383 stringError = Base::GetVersion(); 384 outCmd->bJumpDo = true; 385 } else if (!strcmp(input.c_str(), CMDSTR_TARGET_DISCOVER.c_str())) { 386 outCmd->cmdFlag = CMD_KERNEL_TARGET_DISCOVER; 387 } else if (!strncmp(input.c_str(), CMDSTR_LIST_TARGETS.c_str(), CMDSTR_LIST_TARGETS.size())) { 388 outCmd->cmdFlag = CMD_KERNEL_TARGET_LIST; 389 if (strstr(input.c_str(), " -v")) { 390 outCmd->parameters = "v"; 391 } 392 } else if (!strncmp(input.c_str(), CMDSTR_SERVICE_START.c_str(), CMDSTR_SERVICE_START.size())) { 393 outCmd->cmdFlag = CMD_SERVICE_START; 394 } 395 #ifdef HOST_OHOS 396 else if (!strncmp(input.c_str(), CMDSTR_SERVICE_KILL.c_str(), CMDSTR_SERVICE_KILL.size())) { 397 outCmd->cmdFlag = CMD_SERVER_KILL; 398 } 399 #endif 400 else if (!strncmp(input.c_str(), CMDSTR_CHECK_SERVER.c_str(), CMDSTR_CHECK_SERVER.size())) { 401 outCmd->cmdFlag = CMD_CHECK_SERVER; 402 } else if (!strncmp(input.c_str(), CMDSTR_CHECK_DEVICE.c_str(), CMDSTR_CHECK_DEVICE.size())) { 403 outCmd->parameters = input.c_str() + CMDSTR_CHECK_DEVICE.size() + 1; // with ' ' 404 outCmd->cmdFlag = CMD_CHECK_DEVICE; 405 } else if (!strncmp(input.c_str(), CMDSTR_WAIT_FOR.c_str(), CMDSTR_WAIT_FOR.size())) { 406 outCmd->cmdFlag = CMD_WAIT_FOR; 407 } else if (!strcmp(input.c_str(), CMDSTR_CONNECT_ANY.c_str())) { 408 outCmd->cmdFlag = CMD_KERNEL_TARGET_ANY; 409 } else if (!strncmp(input.c_str(), CMDSTR_CONNECT_TARGET.c_str(), CMDSTR_CONNECT_TARGET.size())) { 410 outCmd->parameters = input.c_str() + CMDSTR_CONNECT_TARGET.size() + 1; // with ' ' 411 stringError = TargetConnect(outCmd); 412 } else if (!strncmp(input.c_str(), (CMDSTR_SHELL_EX).c_str(), (CMDSTR_SHELL_EX).size())) { 413 if (!HostShellOption::FormatParametersToTlv( 414 input, CMDSTR_SHELL_EX.size() - 1, outCmd->parameters, stringError)) { 415 outCmd->bJumpDo = true; 416 } 417 outCmd->cmdFlag = CMD_UNITY_EXECUTE_EX; 418 } else if (!strncmp(input.c_str(), (CMDSTR_SHELL + " ").c_str(), CMDSTR_SHELL.size() + 1)) { 419 outCmd->cmdFlag = CMD_UNITY_EXECUTE; 420 outCmd->parameters = input.c_str() + CMDSTR_SHELL.size() + 1; 421 } else if (!strcmp(input.c_str(), CMDSTR_SHELL.c_str())) { 422 outCmd->cmdFlag = CMD_SHELL_INIT; 423 } else if (!strncmp(input.c_str(), CMDSTR_FILE_SEND.c_str(), CMDSTR_FILE_SEND.size()) || 424 !strncmp(input.c_str(), CMDSTR_FILE_RECV.c_str(), CMDSTR_FILE_RECV.size())) { 425 outCmd->cmdFlag = CMD_FILE_INIT; 426 outCmd->parameters = input.c_str() + strlen("file "); 427 } else if (!strncmp(input.c_str(), string(CMDSTR_FORWARD_FPORT + " ").c_str(), CMDSTR_FORWARD_FPORT.size() + 1) 428 || !strncmp(input.c_str(), string(CMDSTR_FORWARD_RPORT + " ").c_str(), 429 CMDSTR_FORWARD_RPORT.size() + 1)) { 430 stringError = ForwardPort(input.c_str(), outCmd); 431 } else if (!strncmp(input.c_str(), CMDSTR_APP_INSTALL.c_str(), CMDSTR_APP_INSTALL.size())) { 432 outCmd->cmdFlag = CMD_APP_INIT; 433 outCmd->parameters = input; 434 } else if (!strncmp(input.c_str(), CMDSTR_APP_UNINSTALL.c_str(), CMDSTR_APP_UNINSTALL.size())) { 435 outCmd->cmdFlag = CMD_APP_UNINSTALL; 436 outCmd->parameters = input; 437 if (outCmd->parameters.size() > MAX_APP_PARAM_SIZE || outCmd->parameters.size() < MIN_APP_PARAM_SIZE) { 438 stringError = "Package's path incorrect"; 439 outCmd->bJumpDo = true; 440 } 441 } else if (!strcmp(input.c_str(), CMDSTR_TARGET_MOUNT.c_str())) { 442 outCmd->cmdFlag = CMD_UNITY_REMOUNT; 443 } else if (!strcmp(input.c_str(), CMDSTR_LIST_JDWP.c_str())) { 444 outCmd->cmdFlag = CMD_JDWP_LIST; 445 } else if (!strncmp(input.c_str(), CMDSTR_TRACK_JDWP.c_str(), CMDSTR_TRACK_JDWP.size())) { 446 outCmd->cmdFlag = CMD_JDWP_TRACK; 447 if (strstr(input.c_str(), " -p")) { 448 outCmd->parameters = "p"; 449 } else if (strstr(input.c_str(), " -a")) { 450 outCmd->parameters = "a"; 451 } 452 } else if (!strncmp(input.c_str(), CMDSTR_TARGET_REBOOT.c_str(), CMDSTR_TARGET_REBOOT.size())) { 453 TargetReboot(input.c_str(), outCmd); 454 } else if (!strncmp(input.c_str(), CMDSTR_TARGET_MODE.c_str(), CMDSTR_TARGET_MODE.size())) { 455 stringError = RunMode(input.c_str(), outCmd); 456 } else if (!strncmp(input.c_str(), CMDSTR_HILOG.c_str(), CMDSTR_HILOG.size())) { 457 outCmd->cmdFlag = CMD_UNITY_HILOG; 458 if (strstr(input.c_str(), " -h")) { 459 outCmd->parameters = "h"; 460 } 461 } else if (!strncmp(input.c_str(), CMDSTR_STARTUP_MODE.c_str(), CMDSTR_STARTUP_MODE.size())) { 462 outCmd->cmdFlag = CMD_UNITY_ROOTRUN; 463 if (strstr(input.c_str(), " -r")) { 464 outCmd->parameters = "r"; 465 } 466 } else if (!strncmp(input.c_str(), CMDSTR_APP_SIDELOAD.c_str(), CMDSTR_APP_SIDELOAD.size())) { 467 if (strlen(input.c_str()) == CMDSTR_APP_SIDELOAD.size()) { 468 stringError = "Incorrect command, please with local path"; 469 outCmd->bJumpDo = true; 470 } 471 outCmd->cmdFlag = CMD_APP_SIDELOAD; 472 outCmd->parameters = input; 473 } else if (!strncmp(input.c_str(), CMDSTR_BUGREPORT.c_str(), CMDSTR_BUGREPORT.size())) { 474 outCmd->cmdFlag = CMD_UNITY_BUGREPORT_INIT; 475 outCmd->parameters = input; 476 if (outCmd->parameters.size() == CMDSTR_BUGREPORT.size() + 1) { // 1 is sizeInputRaw = input.size() + 1 477 outCmd->parameters = CMDSTR_BUGREPORT + " "; 478 } 479 } 480 // Inner command, protocol uses only 481 else if (!strncmp(input.c_str(), CMDSTR_INNER_ENABLE_KEEPALIVE.c_str(), CMDSTR_INNER_ENABLE_KEEPALIVE.size())) { 482 outCmd->cmdFlag = CMD_KERNEL_ENABLE_KEEPALIVE; 483 } else if (HostUpdater::CheckMatchUpdate(input, *outCmd)) { 484 outCmd->parameters = input; 485 } else { 486 stringError = "Unknown command..."; 487 outCmd->bJumpDo = true; 488 } 489 #ifdef HDC_DEBUG 490 WRITE_LOG(LOG_DEBUG, "String2FormatCommand cmdFlag:%d", outCmd->cmdFlag); 491 #endif 492 // nl 493 if (stringError.size()) { 494 stringError += "\n"; 495 } 496 return stringError; 497 }; 498 } 499 } // namespace Hdc 500