diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index b49b942c..24343c24 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1146,11 +1146,7 @@ void MyMesh::handleCmdFrame(size_t len) { text[tlen] = 0; // ensure null reply_buf[0] = 0; - if (memcmp(text, "set pin ", 8) == 0 && !_serial->isConnectionSecure()) { - // CUSTOM (TeTeHacko): the same gate as CMD_SET_DEVICE_PIN -- through the - // CLI, USB set the PIN it may not set directly, then paired over BLE - strcpy(reply_buf, "Error: set pin only over paired BLE"); - } else if (!handleCommand(text, 0, reply_buf)) { + if (!handleCommand(text, 0, reply_buf)) { strcat(reply_buf, "Unknown command"); // reply_buf may have cmd prefix from 'text' } out_frame[0] = RESP_CODE_CLI_REPLY; @@ -2211,6 +2207,20 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* #endif if (memcmp(command, "set pin ", 8) == 0) { +#ifdef LOCKED_NODE + if (_cli_rescue) { + // CUSTOM (TeTeHacko): a known PIN = pair and read it all (checked after + // leading-space and XX| stripping so " set pin ..." cannot bypass it) + strcpy(reply, "Error: locked build"); + return true; + } +#endif + if (sender_timestamp == 0 && !_cli_rescue && (!_serial || !_serial->isConnectionSecure())) { + // CUSTOM (TeTeHacko): the same gate as CMD_SET_DEVICE_PIN -- through the + // CLI, USB set the PIN it may not set directly, then paired over BLE + strcpy(reply, "Error: set pin only over paired BLE"); + return true; + } long pin; // atoi(): "abc" was PIN 0, i.e. a random one if (!cli_args::parseInt(&command[8], 0, 999999, &pin)) { strcpy(reply, "Error, PIN must be 0-999999"); @@ -2495,11 +2505,6 @@ void MyMesh::checkCLIRescueCmd() { cli_command[len - 1] = 0; // replace newline with C string null terminator reply_buf[0] = 0; -#ifdef LOCKED_NODE - if (memcmp(cli_command, "set pin ", 8) == 0) { // CUSTOM (TeTeHacko): a known PIN = pair and read it all - Serial.println(" Error: locked build"); - } else -#endif if (handleCommand(cli_command, 0, reply_buf)) { // command was handled, print reply output Serial.print(" "); Serial.print(reply_buf); Serial.println();