From c0ac457cadc895ea485c38893a4aaecbca54cdfa Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 13 Mar 2021 13:14:27 +0800 Subject: [PATCH] lockdown plugins that touch hardware --- docs/software/TODO.md | 4 ++++ src/mesh/Channels.cpp | 4 ++++ src/mesh/Channels.h | 4 ++++ src/plugins/AdminPlugin.cpp | 2 +- src/plugins/ExternalNotificationPlugin.cpp | 5 +++++ src/plugins/ExternalNotificationPlugin.h | 2 +- src/plugins/RemoteHardwarePlugin.cpp | 3 ++- src/plugins/SerialPlugin.cpp | 6 ++++++ src/plugins/SerialPlugin.h | 3 +-- 9 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 3a768e68f..c6625e8ef 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -4,9 +4,13 @@ You probably don't care about this section - skip to the next one. ## 1.2 cleanup & multichannel support: +* cleanup the external notification and serial plugins +* non ack version of stress test fails sometimes! * timestamps on oled screen are wrong - don't seem to be updating based on message rx * luxon bug report - seeing rx acks for nodes that are not on the network * channel hash suffixes are wrong on android +* tx fault test has a bug #734 + * cdcacm bug on nrf52: emittx thinks it emitted but client sees nothing. works again later * nrf52: segger logs have errors in formatting that should be impossible (because not going through serial, try stalling on segger) * DONE call RouterPlugin for *all* packets - not just Router packets diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 2a04c9a7b..135ff4329 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -10,6 +10,10 @@ static const uint8_t defaultpsk[] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0 Channels channels; +const char *Channels::adminChannel = "admin"; +const char *Channels::gpioChannel = "gpio"; +const char *Channels::serialChannel = "serial"; + uint8_t xorHash(const uint8_t *p, size_t len) { uint8_t code = 0; diff --git a/src/mesh/Channels.h b/src/mesh/Channels.h index 4fbafe42b..bbd767fa0 100644 --- a/src/mesh/Channels.h +++ b/src/mesh/Channels.h @@ -29,6 +29,10 @@ class Channels int16_t hashes[MAX_NUM_CHANNELS]; public: + + /// Well known channel names + static const char *adminChannel, *gpioChannel, *serialChannel; + const ChannelSettings &getPrimary() { return getByIndex(getPrimaryIndex()).settings; } /** Return the Channel for a specified index */ diff --git a/src/plugins/AdminPlugin.cpp b/src/plugins/AdminPlugin.cpp index 060b1e635..96b5c51a0 100644 --- a/src/plugins/AdminPlugin.cpp +++ b/src/plugins/AdminPlugin.cpp @@ -126,5 +126,5 @@ MeshPacket *AdminPlugin::allocReply() AdminPlugin::AdminPlugin() : ProtobufPlugin("Admin", PortNum_ADMIN_APP, AdminMessage_fields) { // restrict to the admin channel for rx - boundChannel = "admin"; + boundChannel = Channels::adminChannel; } diff --git a/src/plugins/ExternalNotificationPlugin.cpp b/src/plugins/ExternalNotificationPlugin.cpp index 0320c7b30..b69a13cf1 100644 --- a/src/plugins/ExternalNotificationPlugin.cpp +++ b/src/plugins/ExternalNotificationPlugin.cpp @@ -140,6 +140,11 @@ void ExternalNotificationPlugin::setExternalOff() // -------- +ExternalNotificationPluginRadio::ExternalNotificationPluginRadio() : SinglePortPlugin("ExternalNotificationPluginRadio", PortNum_TEXT_MESSAGE_APP) { + // restrict to the admin channel for rx + boundChannel = Channels::gpioChannel; +} + bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp) { #ifndef NO_ESP32 diff --git a/src/plugins/ExternalNotificationPlugin.h b/src/plugins/ExternalNotificationPlugin.h index a9ef58d04..cf4a4abb2 100644 --- a/src/plugins/ExternalNotificationPlugin.h +++ b/src/plugins/ExternalNotificationPlugin.h @@ -32,7 +32,7 @@ class ExternalNotificationPluginRadio : public SinglePortPlugin { public: - ExternalNotificationPluginRadio() : SinglePortPlugin("ExternalNotificationPluginRadio", PortNum_TEXT_MESSAGE_APP) {} + ExternalNotificationPluginRadio(); protected: //virtual MeshPacket *allocReply(); diff --git a/src/plugins/RemoteHardwarePlugin.cpp b/src/plugins/RemoteHardwarePlugin.cpp index 33130663f..ac7e70e58 100644 --- a/src/plugins/RemoteHardwarePlugin.cpp +++ b/src/plugins/RemoteHardwarePlugin.cpp @@ -69,7 +69,8 @@ bool RemoteHardwarePlugin::handleReceivedProtobuf(const MeshPacket &req, const H case HardwareMessage_Type_READ_GPIOS: { // Print notification to LCD screen - screen->print("Read GPIOs\n"); + if(screen) + screen->print("Read GPIOs\n"); uint64_t res = digitalReads(p.gpio_mask); diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index 9aab876f9..a2e2113b3 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -61,6 +61,12 @@ SerialPlugin::SerialPlugin() : concurrency::OSThread("SerialPlugin") {} char serialStringChar[Constants_DATA_PAYLOAD_LEN]; +SerialPluginRadio::SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_SERIAL_APP) +{ + // restrict to the admin channel for rx + boundChannel = Channels::serialChannel; +} + int32_t SerialPlugin::runOnce() { #ifndef NO_ESP32 diff --git a/src/plugins/SerialPlugin.h b/src/plugins/SerialPlugin.h index 4555c65b8..54776ec6a 100644 --- a/src/plugins/SerialPlugin.h +++ b/src/plugins/SerialPlugin.h @@ -33,8 +33,7 @@ class SerialPluginRadio : public SinglePortPlugin from the main code. */ - // SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_TEXT_MESSAGE_APP) {} - SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_SERIAL_APP) {} + SerialPluginRadio(); /** * Send our payload into the mesh