Skip to content

Commit f059e57

Browse files
committed
- Use the new Crypto, TypeConversion and random() functionality added to the Arduino core, instead of the versions local to the mesh library.
- Rearrange class variables to minimize storage padding. - Add protected getters for EspnowMeshBackend and MeshBackendBase components. - Partially update README.md
1 parent 595fb23 commit f059e57

34 files changed

+219
-1582
lines changed

libraries/ESP8266WiFiMesh/README.md

Lines changed: 71 additions & 61 deletions
Large diffs are not rendered by default.

libraries/ESP8266WiFiMesh/examples/HelloEspnow/HelloEspnow.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ void networkFilter(int numberOfNetworks, MeshBackendBase &meshInstance) {
138138

139139
if (targetNodeID < TypeCast::stringToUint64(meshInstance.getNodeID())) {
140140
if (EspnowMeshBackend *espnowInstance = TypeCast::meshBackendCast<EspnowMeshBackend *>(&meshInstance)) {
141-
espnowInstance->connectionQueue().push_back(networkIndex);
141+
espnowInstance->connectionQueue().emplace_back(networkIndex);
142142
} else if (TcpIpMeshBackend *tcpIpInstance = TypeCast::meshBackendCast<TcpIpMeshBackend *>(&meshInstance)) {
143-
tcpIpInstance->connectionQueue().push_back(networkIndex);
143+
tcpIpInstance->connectionQueue().emplace_back(networkIndex);
144144
} else {
145145
Serial.println(F("Invalid mesh backend!"));
146146
}

libraries/ESP8266WiFiMesh/examples/HelloTcpIp/HelloTcpIp.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ void networkFilter(int numberOfNetworks, MeshBackendBase &meshInstance) {
117117

118118
if (targetNodeID < TypeCast::stringToUint64(meshInstance.getNodeID())) {
119119
if (EspnowMeshBackend *espnowInstance = TypeCast::meshBackendCast<EspnowMeshBackend *>(&meshInstance)) {
120-
espnowInstance->connectionQueue().push_back(networkIndex);
120+
espnowInstance->connectionQueue().emplace_back(networkIndex);
121121
} else if (TcpIpMeshBackend *tcpIpInstance = TypeCast::meshBackendCast<TcpIpMeshBackend *>(&meshInstance)) {
122-
tcpIpInstance->connectionQueue().push_back(networkIndex);
122+
tcpIpInstance->connectionQueue().emplace_back(networkIndex);
123123
} else {
124124
Serial.println(F("Invalid mesh backend!"));
125125
}

libraries/ESP8266WiFiMesh/src/CryptoInterface.cpp

Lines changed: 0 additions & 563 deletions
This file was deleted.

libraries/ESP8266WiFiMesh/src/CryptoInterface.h

Lines changed: 0 additions & 803 deletions
This file was deleted.

libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], co
5050
}
5151

5252
EncryptedConnectionData::EncryptedConnectionData(const EncryptedConnectionData &other)
53-
: _peerSessionKey(other.getPeerSessionKey()), _ownSessionKey(other.getOwnSessionKey()), _desync(other.desync()),
54-
_timeTracker(other.temporary() ? new ExpiringTimeTracker(*other.temporary()) : nullptr)
53+
: _peerSessionKey(other.getPeerSessionKey()), _ownSessionKey(other.getOwnSessionKey()),
54+
_timeTracker(other.temporary() ? new ExpiringTimeTracker(*other.temporary()) : nullptr),
55+
_desync(other.desync())
5556
{
5657
other.getPeerStaMac(_peerStaMac);
5758
other.getPeerApMac(_peerApMac);
@@ -132,16 +133,16 @@ uint64_t EncryptedConnectionData::getOwnSessionKey() const { return _ownSessionK
132133
uint64_t EncryptedConnectionData::incrementSessionKey(const uint64_t sessionKey, const uint8_t *hashKey, const uint8_t hashKeyLength)
133134
{
134135
uint8_t inputArray[8] {0};
135-
uint8_t hmacArray[CryptoInterface::SHA256_NATURAL_LENGTH] {0};
136-
CryptoInterface::sha256Hmac(TypeCast::uint64ToUint8Array(sessionKey, inputArray), 8, hashKey, hashKeyLength, hmacArray, CryptoInterface::SHA256_NATURAL_LENGTH);
136+
uint8_t hmacArray[experimental::crypto::SHA256::NATURAL_LENGTH] {0};
137+
experimental::crypto::SHA256::hmac(TypeCast::uint64ToUint8Array(sessionKey, inputArray), 8, hashKey, hashKeyLength, hmacArray, experimental::crypto::SHA256::NATURAL_LENGTH);
137138

138139
/* HMAC truncation should be OK since hmac sha256 is a PRF and we are truncating to the leftmost (MSB) bits.
139140
PRF: https://crypto.stackexchange.com/questions/26410/whats-the-gcm-sha-256-of-a-tls-protocol/26434#26434
140141
Truncate to leftmost bits: https://tools.ietf.org/html/rfc2104#section-5 */
141142
uint64_t newLeftmostBits = TypeCast::uint8ArrayToUint64(hmacArray) & EspnowProtocolInterpreter::uint64LeftmostBits;
142143

143144
if(newLeftmostBits == 0)
144-
newLeftmostBits = ((uint64_t)RANDOM_REG32 | (1 << 31)) << 32; // We never want newLeftmostBits == 0 since that would indicate an unencrypted transmission.
145+
newLeftmostBits = ((uint64_t)ESP.random() | (1 << 31)) << 32; // We never want newLeftmostBits == 0 since that would indicate an unencrypted transmission.
145146

146147
uint64_t newRightmostBits = (uint32_t)(sessionKey + 1);
147148

libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ class EncryptedConnectionData {
9090
uint8_t _peerApMac[6] {0};
9191
uint64_t _peerSessionKey;
9292
uint64_t _ownSessionKey;
93+
std::unique_ptr<ExpiringTimeTracker> _timeTracker = nullptr;
9394
uint8_t _hashKey[EspnowProtocolInterpreter::hashKeyLength] {0};
9495
bool _desync = false;
95-
std::unique_ptr<ExpiringTimeTracker> _timeTracker = nullptr;
9696
};
9797

9898
#endif

libraries/ESP8266WiFiMesh/src/EspnowConnectionManager.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ class EspnowConnectionManager
140140

141141
ConditionalPrinter & _conditionalPrinter;
142142
EspnowDatabase & _database;
143-
144-
uint8_t _encryptedConnectionsSoftLimit = 6;
143+
144+
static ConnectionType getConnectionInfoHelper(const EncryptedConnectionLog *encryptedConnection, uint32_t *remainingDuration, uint8_t *peerMac = nullptr);
145145

146146
uint8_t _espnowEncryptedConnectionKey[EspnowProtocolInterpreter::encryptedConnectionKeyLength] {0};
147147
uint8_t _espnowHashKey[EspnowProtocolInterpreter::hashKeyLength] {0};
148-
149-
static ConnectionType getConnectionInfoHelper(const EncryptedConnectionLog *encryptedConnection, uint32_t *remainingDuration, uint8_t *peerMac = nullptr);
148+
149+
uint8_t _encryptedConnectionsSoftLimit = 6;
150150
};
151151

152152
#endif

libraries/ESP8266WiFiMesh/src/EspnowDatabase.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,6 @@ class EspnowDatabase
202202
ConditionalPrinter & _conditionalPrinter;
203203

204204
uint32_t _autoEncryptionDuration = 50;
205-
206-
uint8_t _senderMac[6] = {0};
207-
uint8_t _senderAPMac[6] = {0};
208-
209-
uint8 _espnowWiFiChannel;
210205

211206
template <typename T, typename U>
212207
static void deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, T> &logEntries, const uint32_t maxEntryLifetimeMs);
@@ -218,6 +213,11 @@ class EspnowDatabase
218213

219214
template <typename T>
220215
static void deleteExpiredLogEntries(std::list<T> &logEntries, const uint32_t maxEntryLifetimeMs);
216+
217+
uint8_t _senderMac[6] = {0};
218+
uint8_t _senderAPMac[6] = {0};
219+
220+
uint8 _espnowWiFiChannel;
221221
};
222222

223223
#endif

libraries/ESP8266WiFiMesh/src/EspnowEncryptionBroker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ namespace
3737
namespace TypeCast = MeshTypeConversionFunctions;
3838

3939
String _ongoingPeerRequestNonce;
40-
uint8_t _ongoingPeerRequestMac[6] = {0};
4140
EspnowMeshBackend *_ongoingPeerRequester = nullptr;
4241
EncryptedConnectionStatus _ongoingPeerRequestResult = EncryptedConnectionStatus::MAX_CONNECTIONS_REACHED_SELF;
4342
ExpiringTimeTracker _ongoingPeerRequestEncryptionTimeout([](){ return EspnowDatabase::getEncryptionRequestTimeout(); });
43+
uint8_t _ongoingPeerRequestMac[6] = {0};
4444
bool _reciprocalPeerRequestConfirmation = false;
4545
}
4646

@@ -465,7 +465,7 @@ bool EspnowEncryptionBroker::verifyEncryptionRequestHmac(const String &encryptio
465465
if(hmacStartIndex < 0)
466466
return false;
467467

468-
if(hmac.length() == 2*CryptoInterface::SHA256_NATURAL_LENGTH // We know that each HMAC byte should become 2 String characters due to uint8ArrayToHexString.
468+
if(hmac.length() == 2*experimental::crypto::SHA256::NATURAL_LENGTH // We know that each HMAC byte should become 2 String characters due to uint8ArrayToHexString.
469469
&& verifyMeshHmac(TypeCast::macToString(requesterStaMac) + TypeCast::macToString(requesterApMac) + encryptionRequestHmacMessage.substring(0, hmacStartIndex), hmac, hashKey, hashKeyLength))
470470
{
471471
return true;

libraries/ESP8266WiFiMesh/src/EspnowEncryptionBroker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ class EspnowEncryptionBroker
8181
EspnowConnectionManager & _connectionManager;
8282
EspnowTransmitter & _transmitter;
8383

84-
bool _receivedEncryptedTransmission = false;
85-
8684
using encryptionRequestBuilderType = std::function<String(const String &, const ExpiringTimeTracker &)>;
8785
static String defaultEncryptionRequestBuilder(const String &requestHeader, const uint32_t durationMs, const uint8_t *hashKey, const String &requestNonce, const ExpiringTimeTracker &existingTimeTracker);
8886
static String flexibleEncryptionRequestBuilder(const uint32_t minDurationMs, const uint8_t *hashKey, const String &requestNonce, const ExpiringTimeTracker &existingTimeTracker);
@@ -100,6 +98,8 @@ class EspnowEncryptionBroker
10098
EncryptedConnectionStatus requestEncryptedConnectionKernel(const uint8_t *peerMac, const encryptionRequestBuilderType &encryptionRequestBuilder, EspnowMeshBackend &espnowInstance);
10199

102100
static bool verifyEncryptionRequestHmac(const String &encryptionRequestHmacMessage, const uint8_t *requesterStaMac, const uint8_t *requesterApMac, const uint8_t *hashKey, const uint8_t hashKeyLength);
101+
102+
bool _receivedEncryptedTransmission = false;
103103
};
104104

105105
#endif

libraries/ESP8266WiFiMesh/src/EspnowMeshBackend.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ EspnowMeshBackend::EspnowMeshBackend(const requestHandlerType requestHandler, co
5757
const broadcastFilterType broadcastFilter, const String &meshPassword, const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode,
5858
const uint8 meshWiFiChannel)
5959
: MeshBackendBase(requestHandler, responseHandler, networkFilter, MeshBackendType::ESP_NOW),
60-
_database(_conditionalPrinter, meshWiFiChannel), _connectionManager(_conditionalPrinter, _database),
61-
_transmitter(_conditionalPrinter, _database, _connectionManager),
62-
_encryptionBroker(_conditionalPrinter, _database, _connectionManager, _transmitter)
60+
_database(*getConditionalPrinter(), meshWiFiChannel), _connectionManager(*getConditionalPrinter(), *getDatabase()),
61+
_transmitter(*getConditionalPrinter(), *getDatabase(), *getConnectionManager()),
62+
_encryptionBroker(*getConditionalPrinter(), *getDatabase(), *getConnectionManager(), *getTransmitter())
6363
{
6464
setBroadcastFilter(broadcastFilter);
6565
setSSID(ssidPrefix, emptyString, ssidSuffix);
@@ -241,7 +241,7 @@ void EspnowMeshBackend::espnowReceiveCallbackWrapper(uint8_t *macaddr, uint8_t *
241241
{
242242
// chacha20Poly1305Decrypt decrypts dataArray in place.
243243
// We are using the protocol bytes as a key salt.
244-
if(!CryptoInterface::chacha20Poly1305Decrypt(dataArray + metadataSize(), len - metadataSize(), getEspnowMessageEncryptionKey(), dataArray,
244+
if(!experimental::crypto::ChaCha20Poly1305::decrypt(dataArray + metadataSize(), len - metadataSize(), getEspnowMessageEncryptionKey(), dataArray,
245245
protocolBytesSize, dataArray + protocolBytesSize, dataArray + protocolBytesSize + 12))
246246
{
247247
return; // Decryption of message failed.
@@ -470,7 +470,7 @@ void EspnowMeshBackend::espnowReceiveCallback(const uint8_t *macaddr, uint8_t *d
470470

471471
if(response.length() > 0)
472472
{
473-
EspnowDatabase::responsesToSend().push_back(ResponseData(response, macaddr, messageID));
473+
EspnowDatabase::responsesToSend().emplace_back(response, macaddr, messageID);
474474

475475
//Serial.println("methodStart Q done " + String(millis() - methodStart));
476476
}
@@ -626,7 +626,7 @@ void EspnowMeshBackend::setUseEncryptedMessages(const bool useEncryptedMessages)
626626
}
627627
bool EspnowMeshBackend::useEncryptedMessages() { return EspnowTransmitter::useEncryptedMessages(); }
628628

629-
void EspnowMeshBackend::setEspnowMessageEncryptionKey(const uint8_t espnowMessageEncryptionKey[CryptoInterface::ENCRYPTION_KEY_LENGTH])
629+
void EspnowMeshBackend::setEspnowMessageEncryptionKey(const uint8_t espnowMessageEncryptionKey[experimental::crypto::ENCRYPTION_KEY_LENGTH])
630630
{
631631
EspnowTransmitter::setEspnowMessageEncryptionKey(espnowMessageEncryptionKey);
632632
}
@@ -762,10 +762,10 @@ TransmissionStatusType EspnowMeshBackend::initiateTransmission(const String &mes
762762
assert(recipientInfo.BSSID() != nullptr); // We need at least the BSSID to connect
763763
recipientInfo.getBSSID(targetBSSID);
764764

765-
if(_conditionalPrinter.verboseMode()) // Avoid string generation if not required
765+
if(verboseMode()) // Avoid string generation if not required
766766
{
767767
printAPInfo(recipientInfo);
768-
_conditionalPrinter.verboseModePrint(emptyString);
768+
verboseModePrint(emptyString);
769769
}
770770

771771
return initiateTransmissionKernel(message, targetBSSID);
@@ -778,7 +778,7 @@ TransmissionStatusType EspnowMeshBackend::initiateTransmissionKernel(const Strin
778778

779779
uint32_t transmissionDuration = millis() - transmissionStartTime;
780780

781-
if(_conditionalPrinter.verboseMode() && transmissionResult == TransmissionStatusType::TRANSMISSION_COMPLETE) // Avoid calculations if not required
781+
if(verboseMode() && transmissionResult == TransmissionStatusType::TRANSMISSION_COMPLETE) // Avoid calculations if not required
782782
{
783783
totalDurationWhenSuccessful_AT += transmissionDuration;
784784
++successfulTransmissions_AT;
@@ -793,14 +793,14 @@ TransmissionStatusType EspnowMeshBackend::initiateTransmissionKernel(const Strin
793793

794794
void EspnowMeshBackend::printTransmissionStatistics() const
795795
{
796-
if(_conditionalPrinter.verboseMode() && successfulTransmissions_AT > 0) // Avoid calculations if not required
796+
if(verboseMode() && successfulTransmissions_AT > 0) // Avoid calculations if not required
797797
{
798-
_conditionalPrinter.verboseModePrint(String(F("Average duration of successful transmissions: ")) + String(totalDurationWhenSuccessful_AT/successfulTransmissions_AT) + String(F(" ms.")));
799-
_conditionalPrinter.verboseModePrint(String(F("Maximum duration of successful transmissions: ")) + String(maxTransmissionDuration_AT) + String(F(" ms.")));
798+
verboseModePrint(String(F("Average duration of successful transmissions: ")) + String(totalDurationWhenSuccessful_AT/successfulTransmissions_AT) + String(F(" ms.")));
799+
verboseModePrint(String(F("Maximum duration of successful transmissions: ")) + String(maxTransmissionDuration_AT) + String(F(" ms.")));
800800
}
801801
else
802802
{
803-
_conditionalPrinter.verboseModePrint(String(F("No successful transmission.")));
803+
verboseModePrint(String(F("No successful transmission.")));
804804
}
805805
}
806806

@@ -947,6 +947,15 @@ uint8_t EspnowMeshBackend::getBroadcastTransmissionRedundancy() const { return _
947947
void EspnowMeshBackend::setResponseTransmittedHook(const EspnowTransmitter::responseTransmittedHookType responseTransmittedHook) { _transmitter.setResponseTransmittedHook(responseTransmittedHook); }
948948
EspnowTransmitter::responseTransmittedHookType EspnowMeshBackend::getResponseTransmittedHook() const { return _transmitter.getResponseTransmittedHook(); }
949949

950+
EspnowDatabase *EspnowMeshBackend::getDatabase() { return &_database; }
951+
const EspnowDatabase *EspnowMeshBackend::getDatabaseConst() const { return &_database; }
952+
EspnowConnectionManager *EspnowMeshBackend::getConnectionManager() { return &_connectionManager; }
953+
const EspnowConnectionManager *EspnowMeshBackend::getConnectionManagerConst() const { return &_connectionManager; }
954+
EspnowTransmitter *EspnowMeshBackend::getTransmitter() { return &_transmitter; }
955+
const EspnowTransmitter *EspnowMeshBackend::getTransmitterConst() const { return &_transmitter; }
956+
EspnowEncryptionBroker *EspnowMeshBackend::getEncryptionBroker() { return &_encryptionBroker; }
957+
const EspnowEncryptionBroker *EspnowMeshBackend::getEncryptionBrokerConst() const { return &_encryptionBroker; }
958+
950959
void EspnowMeshBackend::sendStoredEspnowMessages(const ExpiringTimeTracker *estimatedMaxDurationTracker)
951960
{
952961
EspnowEncryptionBroker::sendPeerRequestConfirmations(estimatedMaxDurationTracker);
@@ -974,12 +983,12 @@ uint32_t EspnowMeshBackend::getMaxMessageLength()
974983
return EspnowTransmitter::getMaxMessageLength();
975984
}
976985

977-
void EspnowMeshBackend::setVerboseModeState(const bool enabled) {_conditionalPrinter.setVerboseModeState(enabled); ConditionalPrinter::setStaticVerboseModeState(enabled);}
986+
void EspnowMeshBackend::setVerboseModeState(const bool enabled) {(*getConditionalPrinter()).setVerboseModeState(enabled); ConditionalPrinter::setStaticVerboseModeState(enabled);}
978987
bool EspnowMeshBackend::verboseMode() const {return ConditionalPrinter::staticVerboseMode();}
979988

980989
void EspnowMeshBackend::verboseModePrint(const String &stringToPrint, const bool newline) const
981990
{
982-
_conditionalPrinter.verboseModePrint(stringToPrint, newline);
991+
(*getConditionalPrinterConst()).verboseModePrint(stringToPrint, newline);
983992
}
984993

985994
bool EspnowMeshBackend::staticVerboseMode() {return ConditionalPrinter::staticVerboseMode();}

libraries/ESP8266WiFiMesh/src/EspnowMeshBackend.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
#include <map>
9393
#include <list>
9494
#include "EspnowNetworkInfo.h"
95-
#include "CryptoInterface.h"
9695

9796
/**
9897
* An alternative to standard delay(). Will continuously call performEspnowMaintenance() during the waiting time, so that the ESP-NOW node remains responsive.
@@ -483,9 +482,9 @@ class EspnowMeshBackend : public MeshBackendBase {
483482
*
484483
* This changes the message encryption key for all EspnowMeshBackend instances on this ESP8266.
485484
*
486-
* @param espnowMessageEncryptionKey An array containing the CryptoInterface::ENCRYPTION_KEY_LENGTH bytes that will be used as the message encryption key.
485+
* @param espnowMessageEncryptionKey An array containing the experimental::crypto::ENCRYPTION_KEY_LENGTH bytes that will be used as the message encryption key.
487486
*/
488-
static void setEspnowMessageEncryptionKey(const uint8_t espnowMessageEncryptionKey[CryptoInterface::ENCRYPTION_KEY_LENGTH]);
487+
static void setEspnowMessageEncryptionKey(const uint8_t espnowMessageEncryptionKey[experimental::crypto::ENCRYPTION_KEY_LENGTH]);
489488

490489
/**
491490
* Change the key used to encrypt/decrypt messages when using AEAD encryption.
@@ -501,7 +500,7 @@ class EspnowMeshBackend : public MeshBackendBase {
501500
/**
502501
* Get the key used to encrypt/decrypt messages when using AEAD encryption.
503502
*
504-
* @return An uint8_t array with size CryptoInterface::ENCRYPTION_KEY_LENGTH containing the currently used message encryption key.
503+
* @return An uint8_t array with size experimental::crypto::ENCRYPTION_KEY_LENGTH containing the currently used message encryption key.
505504
*/
506505
static const uint8_t *getEspnowMessageEncryptionKey();
507506

@@ -935,6 +934,15 @@ class EspnowMeshBackend : public MeshBackendBase {
935934

936935
protected:
937936

937+
EspnowDatabase *getDatabase();
938+
const EspnowDatabase *getDatabaseConst() const;
939+
EspnowConnectionManager *getConnectionManager();
940+
const EspnowConnectionManager *getConnectionManagerConst() const;
941+
EspnowTransmitter *getTransmitter();
942+
const EspnowTransmitter *getTransmitterConst() const;
943+
EspnowEncryptionBroker *getEncryptionBroker();
944+
const EspnowEncryptionBroker *getEncryptionBrokerConst() const;
945+
938946
bool activateEspnow();
939947

940948
/*

libraries/ESP8266WiFiMesh/src/EspnowProtocolInterpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace EspnowProtocolInterpreter
114114
uint64_t createSessionKey()
115115
{
116116
uint64_t newSessionKey = MeshUtilityFunctions::randomUint64();
117-
return usesEncryption(newSessionKey) ? newSessionKey : (newSessionKey | ((uint64_t)RANDOM_REG32) << 32 | uint64MSB); // TODO: Replace RANDOM_REG32 use with ESP.random().
117+
return usesEncryption(newSessionKey) ? newSessionKey : (newSessionKey | ((uint64_t)ESP.random()) << 32 | uint64MSB);
118118
}
119119

120120
macAndType_td createMacAndTypeValue(const uint64_t uint64Mac, const char messageType)

libraries/ESP8266WiFiMesh/src/EspnowProtocolInterpreter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ namespace EspnowProtocolInterpreter
5353
constexpr uint8_t transmissionsRemainingIndex = 1;
5454
constexpr uint8_t transmissionMacIndex = 2;
5555
constexpr uint8_t messageIDIndex = 8;
56+
57+
constexpr uint8_t maxEncryptedConnections = 6; // This is limited by the ESP-NOW API. Max 6 in AP or AP+STA mode. Max 10 in STA mode. See "ESP-NOW User Guide" for more info.
5658

5759
constexpr uint8_t protocolBytesSize = 16;
5860
constexpr uint8_t aeadMetadataSize = 28;
5961
uint8_t metadataSize();
6062
uint32_t getMaxBytesPerTransmission();
6163
uint32_t getMaxMessageBytesPerTransmission();
62-
63-
constexpr uint8_t broadcastMac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
64+
6465
constexpr uint64_t uint64BroadcastMac = 0xFFFFFFFFFFFF;
65-
66-
constexpr uint8_t maxEncryptedConnections = 6; // This is limited by the ESP-NOW API. Max 6 in AP or AP+STA mode. Max 10 in STA mode. See "ESP-NOW User Guide" for more info.
66+
constexpr uint8_t broadcastMac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
6767

6868
constexpr uint8_t encryptedConnectionKeyLength = 16; // This is restricted to exactly 16 bytes by the ESP-NOW API. It should not be changed unless the ESP-NOW API is changed.
6969
constexpr uint8_t hashKeyLength = 16; // This can be changed to any value up to 255. Common values are 16 and 32.
@@ -85,7 +85,7 @@ namespace EspnowProtocolInterpreter
8585
bool usesConstantSessionKey(const char messageType);
8686

8787
/**
88-
* Create a new session key for an encrypted connection using the built in RANDOM_REG32 of the ESP8266.
88+
* Create a new session key for an encrypted connection using the built in RANDOM_REG32/ESP.random() of the ESP8266.
8989
* Should only be used when initializing a new connection.
9090
* Use generateMessageID instead when the encrypted connection is already initialized to keep the connection synchronized.
9191
*

0 commit comments

Comments
 (0)