1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-13 02:22:55 +03:00

- Split most of the EspnowMeshBackend code into utility files and the new ConditionalPrinter, EspnowDatabase, EspnowConnectionManager, EspnowTransmitter and EspnowEncryptionBroker classes.

- Improve mutex handling.

- Move verifyEncryptionRequestHmac function from JsonTranslator to EspnowEncryptionBroker.

- Remove UtilityMethods.cpp.
This commit is contained in:
Anders
2020-05-15 20:33:08 +02:00
parent 3f5495bb3d
commit 40e1f02ffb
30 changed files with 3181 additions and 2263 deletions

View File

@ -25,7 +25,8 @@
#include "EspnowProtocolInterpreter.h"
#include "TypeConversionFunctions.h"
#include <algorithm>
#include "EspnowMeshBackend.h"
#include "EspnowTransmitter.h"
#include "UtilityFunctions.h"
namespace
{
@ -36,7 +37,17 @@ namespace EspnowProtocolInterpreter
{
uint8_t metadataSize()
{
return protocolBytesSize + (EspnowMeshBackend::useEncryptedMessages() ? aeadMetadataSize : 0);
return protocolBytesSize + (EspnowTransmitter::useEncryptedMessages() ? aeadMetadataSize : 0);
}
uint32_t getMaxBytesPerTransmission()
{
return 250;
}
uint32_t getMaxMessageBytesPerTransmission()
{
return getMaxBytesPerTransmission() - metadataSize();
}
String getHashKeyLength(uint8_t *transmissionDataArray, const uint8_t transmissionLength)
@ -94,4 +105,25 @@ namespace EspnowProtocolInterpreter
// At least one of the leftmost half of bits in messageID is 1 if the transmission is encrypted.
return messageID & uint64LeftmostBits;
}
bool usesConstantSessionKey(const char messageType)
{
return messageType == 'A' || messageType == 'C';
}
uint64_t createSessionKey()
{
uint64_t newSessionKey = MeshUtilityFunctions::randomUint64();
return usesEncryption(newSessionKey) ? newSessionKey : (newSessionKey | ((uint64_t)RANDOM_REG32) << 32 | uint64MSB); // TODO: Replace RANDOM_REG32 use with ESP.random().
}
macAndType_td createMacAndTypeValue(const uint64_t uint64Mac, const char messageType)
{
return static_cast<macAndType_td>(uint64Mac << 8 | (uint64_t)messageType);
}
uint64_t macAndTypeToUint64Mac(const macAndType_td &macAndTypeValue)
{
return static_cast<uint64_t>(macAndTypeValue) >> 8;
}
}