From d0fd17134e9fdc51d838694a9a51e9143ae628a3 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 26 Aug 2024 07:48:07 -0500 Subject: [PATCH 1/4] Protos --- protobufs | 2 +- src/mesh/generated/meshtastic/config.pb.h | 11 ++++++----- src/mesh/generated/meshtastic/deviceonly.pb.h | 2 +- src/mesh/generated/meshtastic/localonly.pb.h | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/protobufs b/protobufs index 52cfa2c1c..431291e67 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 52cfa2c1c2cd5a1a714e1338d551d967f674fca8 +Subproject commit 431291e673c1c7592ee64cb972d7845589f60138 diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index d79654856..eb03ddc58 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -532,7 +532,8 @@ typedef struct _meshtastic_Config_SecurityConfig { Used to create a shared key with a remote device. */ meshtastic_Config_SecurityConfig_private_key_t private_key; /* The public key authorized to send admin messages to this node. */ - meshtastic_Config_SecurityConfig_admin_key_t admin_key; + pb_size_t admin_key_count; + meshtastic_Config_SecurityConfig_admin_key_t admin_key[1]; /* If true, device is considered to be "managed" by a mesh administrator via admin messages Device is managed by a mesh administrator. */ bool is_managed; @@ -657,7 +658,7 @@ extern "C" { #define meshtastic_Config_DisplayConfig_init_default {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0, _meshtastic_Config_DisplayConfig_CompassOrientation_MIN} #define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} #define meshtastic_Config_BluetoothConfig_init_default {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} -#define meshtastic_Config_SecurityConfig_init_default {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0} +#define meshtastic_Config_SecurityConfig_init_default {{0, {0}}, {0, {0}}, 0, {{0, {0}}}, 0, 0, 0, 0} #define meshtastic_Config_SessionkeyConfig_init_default {0} #define meshtastic_Config_init_zero {0, {meshtastic_Config_DeviceConfig_init_zero}} #define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0, "", 0} @@ -668,7 +669,7 @@ extern "C" { #define meshtastic_Config_DisplayConfig_init_zero {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0, _meshtastic_Config_DisplayConfig_CompassOrientation_MIN} #define meshtastic_Config_LoRaConfig_init_zero {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} #define meshtastic_Config_BluetoothConfig_init_zero {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} -#define meshtastic_Config_SecurityConfig_init_zero {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0} +#define meshtastic_Config_SecurityConfig_init_zero {{0, {0}}, {0, {0}}, 0, {{0, {0}}}, 0, 0, 0, 0} #define meshtastic_Config_SessionkeyConfig_init_zero {0} /* Field tags (for use in manual encoding/decoding) */ @@ -900,7 +901,7 @@ X(a, STATIC, SINGULAR, UINT32, fixed_pin, 3) #define meshtastic_Config_SecurityConfig_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, BYTES, public_key, 1) \ X(a, STATIC, SINGULAR, BYTES, private_key, 2) \ -X(a, STATIC, SINGULAR, BYTES, admin_key, 3) \ +X(a, STATIC, REPEATED, BYTES, admin_key, 3) \ X(a, STATIC, SINGULAR, BOOL, is_managed, 4) \ X(a, STATIC, SINGULAR, BOOL, serial_enabled, 5) \ X(a, STATIC, SINGULAR, BOOL, debug_log_api_enabled, 6) \ @@ -948,7 +949,7 @@ extern const pb_msgdesc_t meshtastic_Config_SessionkeyConfig_msg; #define meshtastic_Config_NetworkConfig_size 196 #define meshtastic_Config_PositionConfig_size 62 #define meshtastic_Config_PowerConfig_size 52 -#define meshtastic_Config_SecurityConfig_size 110 +#define meshtastic_Config_SecurityConfig_size 111 #define meshtastic_Config_SessionkeyConfig_size 0 #define meshtastic_Config_size 199 diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 976e0e135..692402210 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -358,7 +358,7 @@ extern const pb_msgdesc_t meshtastic_OEMStore_msg; #define MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_MAX_SIZE meshtastic_OEMStore_size #define meshtastic_ChannelFile_size 718 #define meshtastic_NodeInfoLite_size 183 -#define meshtastic_OEMStore_size 3496 +#define meshtastic_OEMStore_size 3497 #define meshtastic_PositionLite_size 28 #define meshtastic_UserLite_size 96 diff --git a/src/mesh/generated/meshtastic/localonly.pb.h b/src/mesh/generated/meshtastic/localonly.pb.h index 38529fc14..91a23dc4f 100644 --- a/src/mesh/generated/meshtastic/localonly.pb.h +++ b/src/mesh/generated/meshtastic/localonly.pb.h @@ -187,7 +187,7 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg; /* Maximum encoded size of messages (where known) */ #define MESHTASTIC_MESHTASTIC_LOCALONLY_PB_H_MAX_SIZE meshtastic_LocalModuleConfig_size -#define meshtastic_LocalConfig_size 663 +#define meshtastic_LocalConfig_size 664 #define meshtastic_LocalModuleConfig_size 687 #ifdef __cplusplus From 777ae2b99c13bbe59f94fd23f9fcdcbab9674419 Mon Sep 17 00:00:00 2001 From: John Milton Date: Mon, 26 Aug 2024 11:28:08 -0400 Subject: [PATCH 2/4] Add support for Adafruit Feather RP2040 with RFM95. (#4451) * Add support for Adafruit Feather RP2040 with RFM95. * Update mesh.pb.h dropping this change from the file generated by the protobuf * Update mesh.pb.h remove these reverting changes * Update mesh.pb.h oops, missed a comma --- src/platform/rp2040/architecture.h | 2 + variants/feather_rp2040_rfm95/platformio.ini | 16 +++++ variants/feather_rp2040_rfm95/variant.h | 61 ++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 variants/feather_rp2040_rfm95/platformio.ini create mode 100644 variants/feather_rp2040_rfm95/variant.h diff --git a/src/platform/rp2040/architecture.h b/src/platform/rp2040/architecture.h index d7d7214c0..3f75735d3 100644 --- a/src/platform/rp2040/architecture.h +++ b/src/platform/rp2040/architecture.h @@ -29,4 +29,6 @@ #define HW_VENDOR meshtastic_HardwareModel_SENSELORA_RP2040 #elif defined(RP2040_LORA) #define HW_VENDOR meshtastic_HardwareModel_RP2040_LORA +#elif defined(RP2040_FEATHER_RFM95) +#define HW_VENDOR meshtastic_HardwareModel_RP2040_FEATHER_RFM95 #endif \ No newline at end of file diff --git a/variants/feather_rp2040_rfm95/platformio.ini b/variants/feather_rp2040_rfm95/platformio.ini new file mode 100644 index 000000000..a28ad7655 --- /dev/null +++ b/variants/feather_rp2040_rfm95/platformio.ini @@ -0,0 +1,16 @@ +[env:feather_rp2040_rfm95] +extends = rp2040_base +board = adafruit_feather +upload_protocol = picotool + +# add our variants files to the include and src paths +build_flags = ${rp2040_base.build_flags} + -DRP2040_FEATHER_RFM95 + -Ivariants/feather_rp2040_rfm95 + -DDEBUG_RP2040_PORT=Serial + -DHW_SPI1_DEVICE + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m0plus" +lib_deps = + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/feather_rp2040_rfm95/variant.h b/variants/feather_rp2040_rfm95/variant.h new file mode 100644 index 000000000..e9e178202 --- /dev/null +++ b/variants/feather_rp2040_rfm95/variant.h @@ -0,0 +1,61 @@ +// #define RADIOLIB_CUSTOM_ARDUINO 1 +// #define RADIOLIB_TONE_UNSUPPORTED 1 +// #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED 1 + +#define ARDUINO_ARCH_AVR + +// #define USE_SSD1306 + +// #define USE_SH1106 1 + +// default I2C pins: +// SDA = 4 +// SCL = 5 + +// Recommended pins for SerialModule: +// txd = 8 +// rxd = 9 + +#define EXT_NOTIFY_OUT 22 +#define BUTTON_PIN 7 +// #define BUTTON_NEED_PULLUP + +#define LED_PIN PIN_LED + +// #define BATTERY_PIN 26 +// ratio of voltage divider = 3.0 (R17=200k, R18=100k) +// #define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic + +#define USE_RF95 // RFM95/SX127x + +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS + +// https://www.adafruit.com/product/5714 +// https://learn.adafruit.com/feather-rp2040-rfm95 +// https://learn.adafruit.com/assets/120283 +// https://learn.adafruit.com/assets/120813 +#define LORA_SCK 14 // 10 12P +#define LORA_MISO 8 // 12 10P +#define LORA_MOSI 15 // 11 11P +#define LORA_CS 16 // 3 13P + +#define LORA_RESET 17 // 15 14P + +#define LORA_DIO0 21 // ?? 6P +#define LORA_DIO1 22 // 20 7P +#define LORA_DIO2 23 // 2 8P +#define LORA_DIO3 19 // ?? 3P +#define LORA_DIO4 20 // ?? 4P +#define LORA_DIO5 18 // ?? 15P + +#ifdef USE_SX1262 +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_DIO2_AS_RF_SWITCH +// #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#endif \ No newline at end of file From 5824a8f4c1eaae2c6b9b62bb227387b32d488d3a Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 26 Aug 2024 12:29:44 -0500 Subject: [PATCH 3/4] Deal with admin_key being repeated (#4558) --- src/mesh/NodeDB.cpp | 6 +++--- src/modules/AdminModule.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 3af6c6a45..fa736e08a 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -292,10 +292,10 @@ void NodeDB::installDefaultConfig() config.lora.ignore_mqtt = false; #endif #ifdef ADMIN_KEY_USERPREFS - memcpy(config.security.admin_key.bytes, admin_key_userprefs, 32); - config.security.admin_key.size = 32; + memcpy(config.security.admin_key[0].bytes, admin_key_userprefs, 32); + config.security.admin_key[0].size = 32; #else - config.security.admin_key.size = 0; + config.security.admin_key[0].size = 0; #endif config.security.public_key.size = 0; config.security.private_key.size = 0; diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index ef60a4bf2..b63eca396 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -75,7 +75,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta // and only allowing responses from that remote. if (!((mp.from == 0 && !config.security.is_managed) || messageIsResponse(r) || (strcasecmp(ch->settings.name, Channels::adminChannel) == 0 && config.security.admin_channel_enabled) || - (mp.pki_encrypted && memcmp(mp.public_key.bytes, config.security.admin_key.bytes, 32) == 0))) { + (mp.pki_encrypted && memcmp(mp.public_key.bytes, config.security.admin_key[0].bytes, 32) == 0))) { LOG_INFO("Ignoring admin payload %i\n", r->which_payload_variant); return handled; } From b9a8683a4bfe9c453313554f8de1e85acb789383 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 26 Aug 2024 15:48:47 -0500 Subject: [PATCH 4/4] Mask out random bits when doing queue ordering (#4561) * Mask out random bits when doing queue ordering * Parenthesis --- src/mesh/MeshPacketQueue.cpp | 7 ++++--- src/mesh/MeshTypes.h | 5 +++-- src/mesh/Router.cpp | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mesh/MeshPacketQueue.cpp b/src/mesh/MeshPacketQueue.cpp index 24756fd2a..f1c6c4ff3 100644 --- a/src/mesh/MeshPacketQueue.cpp +++ b/src/mesh/MeshPacketQueue.cpp @@ -20,8 +20,9 @@ bool CompareMeshPacketFunc(const meshtastic_MeshPacket *p1, const meshtastic_Mes // If priorities differ, use that // for equal priorities, order by id (older packets have higher priority - this will briefly be wrong when IDs roll over but // no big deal) - return (p1p != p2p) ? (p1p < p2p) // prefer bigger priorities - : (p1->id >= p2->id); // prefer smaller packet ids + return (p1p != p2p) + ? (p1p < p2p) // prefer bigger priorities + : ((p1->id & ID_COUNTER_MASK) >= (p2->id & ID_COUNTER_MASK)); // Mask to counter portion, prefer smaller packet ids } MeshPacketQueue::MeshPacketQueue(size_t _maxLen) : maxLen(_maxLen) {} @@ -127,4 +128,4 @@ bool MeshPacketQueue::replaceLowerPriorityPacket(meshtastic_MeshPacket *p) std::make_heap(queue.begin(), queue.end(), &CompareMeshPacketFunc); return true; -} +} \ No newline at end of file diff --git a/src/mesh/MeshTypes.h b/src/mesh/MeshTypes.h index c0919bf5d..1c9099c39 100644 --- a/src/mesh/MeshTypes.h +++ b/src/mesh/MeshTypes.h @@ -14,8 +14,9 @@ typedef uint32_t PacketId; // A packet sequence number 1 // Reserved to only deliver packets over high speed (non-lora) transports, such as MQTT or BLE mesh (not yet implemented) #define ERRNO_OK 0 #define ERRNO_NO_INTERFACES 33 -#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER -#define ERRNO_DISABLED 34 // the interface is disabled +#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER +#define ERRNO_DISABLED 34 // the interface is disabled +#define ID_COUNTER_MASK (UINT32_MAX >> 22) // mask to select the counter portion of the ID /* * Source of a received message diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index bdd8c4e6c..61b1bbfb6 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -109,7 +109,7 @@ PacketId generatePacketId() rollingPacketId++; - rollingPacketId &= UINT32_MAX >> 22; // Mask out the top 22 bits + rollingPacketId &= ID_COUNTER_MASK; // Mask out the top 22 bits PacketId id = rollingPacketId | random(UINT32_MAX & 0x7fffffff) << 10; // top 22 bits LOG_DEBUG("Partially randomized packet id %u\n", id); return id;