mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-27 12:12:07 +00:00
Merge branch 'master' into BMP388
This commit is contained in:
@@ -157,7 +157,7 @@ bool EInkDisplay::connect()
|
||||
}
|
||||
|
||||
#elif defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_VISION_MASTER_E213) || \
|
||||
defined(HELTEC_VISION_MASTER_E290)
|
||||
defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER)
|
||||
{
|
||||
// Start HSPI
|
||||
hspi = new SPIClass(HSPI);
|
||||
|
||||
@@ -68,7 +68,7 @@ class EInkDisplay : public OLEDDisplay
|
||||
|
||||
// If display uses HSPI
|
||||
#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_VISION_MASTER_E213) || \
|
||||
defined(HELTEC_VISION_MASTER_E290)
|
||||
defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER)
|
||||
SPIClass *hspi = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Curve25519.h>
|
||||
#include <SHA256.h>
|
||||
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN)
|
||||
|
||||
/**
|
||||
* Create a public/private key pair with Curve25519.
|
||||
*
|
||||
@@ -24,6 +25,30 @@ void CryptoEngine::generateKeyPair(uint8_t *pubKey, uint8_t *privKey)
|
||||
memcpy(pubKey, public_key, sizeof(public_key));
|
||||
memcpy(privKey, private_key, sizeof(private_key));
|
||||
}
|
||||
|
||||
/**
|
||||
* regenerate a public key with Curve25519.
|
||||
*
|
||||
* @param pubKey The destination for the public key.
|
||||
* @param privKey The source for the private key.
|
||||
*/
|
||||
bool CryptoEngine::regeneratePublicKey(uint8_t *pubKey, uint8_t *privKey)
|
||||
{
|
||||
if (!memfll(privKey, 0, sizeof(private_key))) {
|
||||
Curve25519::eval(pubKey, privKey, 0);
|
||||
if (Curve25519::isWeakPoint(pubKey)) {
|
||||
LOG_ERROR("PKI key generation failed. Specified private key results in a weak\n");
|
||||
memset(pubKey, 0, 32);
|
||||
return false;
|
||||
}
|
||||
memcpy(private_key, privKey, sizeof(private_key));
|
||||
memcpy(public_key, pubKey, sizeof(public_key));
|
||||
} else {
|
||||
LOG_WARN("X25519 key generation failed due to blank private key\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
void CryptoEngine::clearKeys()
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ struct CryptoKey {
|
||||
*/
|
||||
|
||||
#define MAX_BLOCKSIZE 256
|
||||
#define TEST_CURVE25519_FIELD_OPS // Exposes Curve25519::isWeakPoint() for testing keys
|
||||
|
||||
class CryptoEngine
|
||||
{
|
||||
@@ -33,6 +34,8 @@ class CryptoEngine
|
||||
#if !(MESHTASTIC_EXCLUDE_PKI)
|
||||
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN)
|
||||
virtual void generateKeyPair(uint8_t *pubKey, uint8_t *privKey);
|
||||
virtual bool regeneratePublicKey(uint8_t *pubKey, uint8_t *privKey);
|
||||
|
||||
#endif
|
||||
void clearKeys();
|
||||
void setDHPrivateKey(uint8_t *_private_key);
|
||||
|
||||
@@ -40,19 +40,22 @@ void fixPriority(meshtastic_MeshPacket *p)
|
||||
// We might receive acks from other nodes (and since generated remotely, they won't have priority assigned. Check for that
|
||||
// and fix it
|
||||
if (p->priority == meshtastic_MeshPacket_Priority_UNSET) {
|
||||
// if acks give high priority
|
||||
// if a reliable message give a bit higher default priority
|
||||
p->priority = (p->decoded.portnum == meshtastic_PortNum_ROUTING_APP)
|
||||
? meshtastic_MeshPacket_Priority_ACK
|
||||
: (p->want_ack ? meshtastic_MeshPacket_Priority_RELIABLE : meshtastic_MeshPacket_Priority_DEFAULT);
|
||||
p->priority = (p->want_ack ? meshtastic_MeshPacket_Priority_RELIABLE : meshtastic_MeshPacket_Priority_DEFAULT);
|
||||
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
||||
// if acks/naks give very high priority
|
||||
if (p->decoded.portnum == meshtastic_PortNum_ROUTING_APP)
|
||||
p->priority = meshtastic_MeshPacket_Priority_ACK;
|
||||
// if text give high priority
|
||||
else if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP)
|
||||
p->priority = meshtastic_MeshPacket_Priority_HIGH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** enqueue a packet, return false if full */
|
||||
bool MeshPacketQueue::enqueue(meshtastic_MeshPacket *p)
|
||||
{
|
||||
fixPriority(p);
|
||||
|
||||
// no space - try to replace a lower priority packet in the queue
|
||||
if (queue.size() >= maxLen) {
|
||||
return replaceLowerPriorityPacket(p);
|
||||
|
||||
@@ -48,4 +48,7 @@ extern Allocator<meshtastic_MeshPacket> &packetPool;
|
||||
* Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on
|
||||
* the local node. If from is zero this function returns our node number instead
|
||||
*/
|
||||
NodeNum getFrom(const meshtastic_MeshPacket *p);
|
||||
NodeNum getFrom(const meshtastic_MeshPacket *p);
|
||||
|
||||
/* Some clients might not properly set priority, therefore we fix it here. */
|
||||
void fixPriority(meshtastic_MeshPacket *p);
|
||||
@@ -139,14 +139,24 @@ NodeDB::NodeDB()
|
||||
crypto->setDHPrivateKey(config.security.private_key.bytes);
|
||||
} else {
|
||||
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN)
|
||||
LOG_INFO("Generating new PKI keys\n");
|
||||
crypto->generateKeyPair(config.security.public_key.bytes, config.security.private_key.bytes);
|
||||
config.security.public_key.size = 32;
|
||||
config.security.private_key.size = 32;
|
||||
|
||||
printBytes("New Pubkey", config.security.public_key.bytes, 32);
|
||||
owner.public_key.size = 32;
|
||||
memcpy(owner.public_key.bytes, config.security.public_key.bytes, 32);
|
||||
bool keygenSuccess = false;
|
||||
if (config.security.private_key.size == 32) {
|
||||
LOG_INFO("Calculating PKI Public Key\n");
|
||||
if (crypto->regeneratePublicKey(config.security.public_key.bytes, config.security.private_key.bytes)) {
|
||||
keygenSuccess = true;
|
||||
}
|
||||
} else {
|
||||
LOG_INFO("Generating new PKI keys\n");
|
||||
crypto->generateKeyPair(config.security.public_key.bytes, config.security.private_key.bytes);
|
||||
keygenSuccess = true;
|
||||
}
|
||||
if (keygenSuccess) {
|
||||
config.security.public_key.size = 32;
|
||||
config.security.private_key.size = 32;
|
||||
printBytes("New Pubkey", config.security.public_key.bytes, 32);
|
||||
owner.public_key.size = 32;
|
||||
memcpy(owner.public_key.bytes, config.security.public_key.bytes, 32);
|
||||
}
|
||||
#else
|
||||
LOG_INFO("No PKI keys set, and generation disabled!\n");
|
||||
#endif
|
||||
@@ -307,7 +317,7 @@ void NodeDB::installDefaultConfig()
|
||||
#else
|
||||
config.device.disable_triple_click = true;
|
||||
#endif
|
||||
#if !HAS_GPS || defined(T_DECK)
|
||||
#if !HAS_GPS || defined(T_DECK) || defined(TLORA_T3S3_EPAPER)
|
||||
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT;
|
||||
#elif !defined(GPS_RX_PIN)
|
||||
if (config.position.rx_gpio == 0)
|
||||
|
||||
@@ -112,7 +112,7 @@ void ReliableRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas
|
||||
sendAckNak(meshtastic_Routing_Error_NONE, getFrom(p), p->id, p->channel, p->hop_start, p->hop_limit);
|
||||
} else if (p->which_payload_variant == meshtastic_MeshPacket_encrypted_tag && p->channel == 0 &&
|
||||
(nodeDB->getMeshNode(p->from) == nullptr || nodeDB->getMeshNode(p->from)->user.public_key.size == 0)) {
|
||||
// This looks like it might be a PKI packet from an unknown node, so send PKI_UNKNOWN_PUBKEY
|
||||
LOG_INFO("This looks like it might be a PKI packet from an unknown node, so send PKI_UNKNOWN_PUBKEY\n");
|
||||
sendAckNak(meshtastic_Routing_Error_PKI_UNKNOWN_PUBKEY, getFrom(p), p->id, channels.getPrimaryIndex(),
|
||||
p->hop_start, p->hop_limit);
|
||||
} else {
|
||||
|
||||
@@ -252,6 +252,8 @@ ErrorCode Router::send(meshtastic_MeshPacket *p)
|
||||
return meshtastic_Routing_Error_BAD_REQUEST;
|
||||
}
|
||||
|
||||
fixPriority(p); // Before encryption, fix the priority if it's unset
|
||||
|
||||
// If the packet is not yet encrypted, do so now
|
||||
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
||||
ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it
|
||||
|
||||
@@ -196,6 +196,9 @@ typedef enum _meshtastic_HardwareModel {
|
||||
https://www.adafruit.com/product/938
|
||||
^^^ short A0 to switch to I2C address 0x3C */
|
||||
meshtastic_HardwareModel_RP2040_FEATHER_RFM95 = 76,
|
||||
/* M5 esp32 based MCU modules with enclosure, TFT and LORA Shields. All Variants (Basic, Core, Fire, Core2, Paper) https://m5stack.com/ */
|
||||
meshtastic_HardwareModel_M5STACK_COREBASIC = 77,
|
||||
meshtastic_HardwareModel_M5STACK_CORE2 = 78,
|
||||
/* ------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits.
|
||||
------------------------------------------------------------------------------------------------------------------------------------------ */
|
||||
@@ -347,6 +350,8 @@ typedef enum _meshtastic_MeshPacket_Priority {
|
||||
/* If priority is unset but the message is marked as want_ack,
|
||||
assume it is important and use a slightly higher priority */
|
||||
meshtastic_MeshPacket_Priority_RELIABLE = 70,
|
||||
/* Higher priority for specific message types (portnums) to distinguish between other reliable packets. */
|
||||
meshtastic_MeshPacket_Priority_HIGH = 100,
|
||||
/* Ack/naks are sent with very high priority to ensure that retransmission
|
||||
stops as soon as possible */
|
||||
meshtastic_MeshPacket_Priority_ACK = 120,
|
||||
|
||||
@@ -69,7 +69,9 @@ typedef enum _meshtastic_TelemetrySensorType {
|
||||
/* ICM-20948 9-Axis digital motion processor */
|
||||
meshtastic_TelemetrySensorType_ICM20948 = 27,
|
||||
/* MAX17048 1S lipo battery sensor (voltage, state of charge, time to go) */
|
||||
meshtastic_TelemetrySensorType_MAX17048 = 28
|
||||
meshtastic_TelemetrySensorType_MAX17048 = 28,
|
||||
/* Custom I2C sensor implementation based on https://github.com/meshtastic/i2c-sensor */
|
||||
meshtastic_TelemetrySensorType_CUSTOM_SENSOR = 29
|
||||
} meshtastic_TelemetrySensorType;
|
||||
|
||||
/* Struct definitions */
|
||||
@@ -265,8 +267,8 @@ extern "C" {
|
||||
|
||||
/* Helper constants for enums */
|
||||
#define _meshtastic_TelemetrySensorType_MIN meshtastic_TelemetrySensorType_SENSOR_UNSET
|
||||
#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_MAX17048
|
||||
#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_MAX17048+1))
|
||||
#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_CUSTOM_SENSOR
|
||||
#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_CUSTOM_SENSOR+1))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
|
||||
tv.tv_sec = r->set_time_only;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
perhapsSetRTC(RTCQualityFromNet, &tv, false);
|
||||
perhapsSetRTC(RTCQualityNTP, &tv, false);
|
||||
break;
|
||||
}
|
||||
case meshtastic_AdminMessage_enter_dfu_mode_request_tag: {
|
||||
@@ -537,6 +537,15 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
|
||||
case meshtastic_Config_security_tag:
|
||||
LOG_INFO("Setting config: Security\n");
|
||||
config.security = c.payload_variant.security;
|
||||
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN) && !(MESHTASTIC_EXCLUDE_PKI)
|
||||
// We check for a potentially valid private key, and a blank public key, and regen the public key if needed.
|
||||
if (config.security.private_key.size == 32 && !memfll(config.security.private_key.bytes, 0, 32) &&
|
||||
(config.security.public_key.size == 0 || memfll(config.security.public_key.bytes, 0, 32))) {
|
||||
if (crypto->regeneratePublicKey(config.security.public_key.bytes, config.security.private_key.bytes)) {
|
||||
config.security.public_key.size = 32;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
owner.public_key.size = config.security.public_key.size;
|
||||
memcpy(owner.public_key.bytes, config.security.public_key.bytes, config.security.public_key.size);
|
||||
#if !MESHTASTIC_EXCLUDE_PKI
|
||||
@@ -1019,4 +1028,4 @@ bool AdminModule::messageIsRequest(meshtastic_AdminMessage *r)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,10 @@ void PositionModule::trySetRtc(meshtastic_Position p, bool isLocal, bool forceUp
|
||||
LOG_DEBUG("Ignoring time from mesh because we have a GPS, RTC, or Phone/NTP time source in the past day\n");
|
||||
return;
|
||||
}
|
||||
if (!isLocal && p.location_source < meshtastic_Position_LocSource_LOC_INTERNAL) {
|
||||
LOG_DEBUG("Ignoring time from mesh because it has a unknown or manual source\n");
|
||||
return;
|
||||
}
|
||||
struct timeval tv;
|
||||
uint32_t secs = p.time;
|
||||
|
||||
@@ -191,6 +195,10 @@ meshtastic_MeshPacket *PositionModule::allocReply()
|
||||
p.has_longitude_i = true;
|
||||
p.time = getValidTime(RTCQualityNTP) > 0 ? getValidTime(RTCQualityNTP) : localPosition.time;
|
||||
|
||||
if (config.position.fixed_position) {
|
||||
p.location_source = meshtastic_Position_LocSource_LOC_MANUAL;
|
||||
}
|
||||
|
||||
if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE) {
|
||||
if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL) {
|
||||
p.altitude = localPosition.altitude;
|
||||
|
||||
@@ -167,9 +167,9 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
|
||||
strcmp(e.channel_id, "PKI") == 0) {
|
||||
meshtastic_NodeInfoLite *tx = nodeDB->getMeshNode(getFrom(p));
|
||||
meshtastic_NodeInfoLite *rx = nodeDB->getMeshNode(p->to);
|
||||
// Only accept PKI messages if we have both the sender and receiver in our nodeDB, as then it's likely
|
||||
// they discovered each other via a channel we have downlink enabled for
|
||||
if (tx && tx->has_user && rx && rx->has_user)
|
||||
// Only accept PKI messages to us, or if we have both the sender and receiver in our nodeDB, as then it's
|
||||
// likely they discovered each other via a channel we have downlink enabled for
|
||||
if (p->to == nodeDB->getNodeNum() || (tx && tx->has_user && rx && rx->has_user))
|
||||
router->enqueueReceivedMessage(p);
|
||||
} else if (router && perhapsDecode(p)) // ignore messages if we don't have the channel key
|
||||
router->enqueueReceivedMessage(p);
|
||||
@@ -527,7 +527,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, const meshtastic_MeshPacket &
|
||||
}
|
||||
|
||||
if (ch.settings.uplink_enabled || mp.pki_encrypted) {
|
||||
const char *channelId = channels.getGlobalId(chIndex); // FIXME, for now we just use the human name for the channel
|
||||
const char *channelId = mp.pki_encrypted ? "PKI" : channels.getGlobalId(chIndex);
|
||||
|
||||
meshtastic_ServiceEnvelope *env = mqttPool.allocZeroed();
|
||||
env->channel_id = (char *)channelId;
|
||||
@@ -546,12 +546,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, const meshtastic_MeshPacket &
|
||||
// FIXME - this size calculation is super sloppy, but it will go away once we dynamically alloc meshpackets
|
||||
static uint8_t bytes[meshtastic_MeshPacket_size + 64];
|
||||
size_t numBytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_ServiceEnvelope_msg, env);
|
||||
std::string topic;
|
||||
if (mp.pki_encrypted) {
|
||||
topic = cryptTopic + "PKI/" + owner.id;
|
||||
} else {
|
||||
topic = cryptTopic + channelId + "/" + owner.id;
|
||||
}
|
||||
std::string topic = cryptTopic + channelId + "/" + owner.id;
|
||||
LOG_DEBUG("MQTT Publish %s, %u bytes\n", topic.c_str(), numBytes);
|
||||
|
||||
publish(topic.c_str(), bytes, numBytes, false);
|
||||
@@ -561,12 +556,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, const meshtastic_MeshPacket &
|
||||
// handle json topic
|
||||
auto jsonString = MeshPacketSerializer::JsonSerialize((meshtastic_MeshPacket *)&mp_decoded);
|
||||
if (jsonString.length() != 0) {
|
||||
std::string topicJson;
|
||||
if (mp.pki_encrypted) {
|
||||
topicJson = jsonTopic + "PKI/" + owner.id;
|
||||
} else {
|
||||
topicJson = jsonTopic + channelId + "/" + owner.id;
|
||||
}
|
||||
std::string topicJson = jsonTopic + channelId + "/" + owner.id;
|
||||
LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(),
|
||||
jsonString.c_str());
|
||||
publish(topicJson.c_str(), jsonString.c_str(), false);
|
||||
|
||||
@@ -122,6 +122,8 @@
|
||||
#define HW_VENDOR meshtastic_HardwareModel_HELTEC_WIRELESS_PAPER
|
||||
#elif defined(TLORA_T3S3_V1)
|
||||
#define HW_VENDOR meshtastic_HardwareModel_TLORA_T3_S3
|
||||
#elif defined(TLORA_T3S3_EPAPER)
|
||||
#define HW_VENDOR meshtastic_HardwareModel_TLORA_T3_S3
|
||||
#elif defined(CDEBYTE_EORA_S3)
|
||||
#define HW_VENDOR meshtastic_HardwareModel_CDEBYTE_EORA_S3
|
||||
#elif defined(BETAFPV_2400_TX)
|
||||
|
||||
Reference in New Issue
Block a user