mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
- Add new ESP-NOW mesh backend.
- Add HelloEspnow.ino example to demonstrate the ESP-NOW mesh backend features. - Deprecate the ESP8266WiFiMesh class in favour of the new ESP-NOW and TCP/IP backends. - Update the TCP/IP mesh backend to use the new lwIP version preprocessor flag and remove obsolete preprocessor flags.
This commit is contained in:
96
libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.h
Normal file
96
libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.h
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Anders Löfgren
|
||||
*
|
||||
* License (MIT license):
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __ESPNOWENCRYPTEDCONNECTIONDATA_H__
|
||||
#define __ESPNOWENCRYPTEDCONNECTIONDATA_H__
|
||||
|
||||
#include "ExpiringTimeTracker.h"
|
||||
#include "EspnowProtocolInterpreter.h"
|
||||
#include <WString.h>
|
||||
#include <memory>
|
||||
|
||||
class EncryptedConnectionData {
|
||||
|
||||
public:
|
||||
|
||||
virtual ~EncryptedConnectionData() = default;
|
||||
|
||||
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
|
||||
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
|
||||
uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||
|
||||
EncryptedConnectionData(const EncryptedConnectionData &other);
|
||||
|
||||
EncryptedConnectionData & operator=(const EncryptedConnectionData &other);
|
||||
|
||||
/**
|
||||
* @param resultArray An uint8_t array with at least size 6.
|
||||
*
|
||||
* @returns The interface MAC used for communicating with the peer.
|
||||
*/
|
||||
uint8_t *getEncryptedPeerMac(uint8_t *resultArray) const;
|
||||
uint8_t *getUnencryptedPeerMac(uint8_t *resultArray) const;
|
||||
|
||||
// @param resultArray At least size 6.
|
||||
uint8_t *getPeerStaMac(uint8_t *resultArray) const;
|
||||
uint8_t *getPeerApMac(uint8_t *resultArray) const;
|
||||
|
||||
bool connectedTo(const uint8_t *peerMac) const;
|
||||
|
||||
void setHashKey(const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||
// @param resultArray At least size espnowHashKeyLength.
|
||||
uint8_t *getHashKey(uint8_t *resultArray) const;
|
||||
|
||||
void setPeerSessionKey(uint64_t sessionKey);
|
||||
uint64_t getPeerSessionKey() const;
|
||||
void setOwnSessionKey(uint64_t sessionKey);
|
||||
uint64_t getOwnSessionKey() const;
|
||||
|
||||
static uint64_t incrementSessionKey(uint64_t sessionKey, const uint8_t *hashKey, uint8_t hashKeyLength);
|
||||
void incrementOwnSessionKey();
|
||||
|
||||
void setDesync(bool desync);
|
||||
bool desync() const;
|
||||
|
||||
// Note that the espnowEncryptionKey, espnowEncryptionKok and espnowHashKey are not serialized.
|
||||
// These will be set to the values of the EspnowMeshBackend instance that is adding the serialized encrypted connection.
|
||||
String serialize() const;
|
||||
|
||||
const ExpiringTimeTracker *temporary() const;
|
||||
virtual void setRemainingDuration(uint32_t remainingDuration);
|
||||
virtual void removeDuration();
|
||||
|
||||
private:
|
||||
|
||||
uint8_t _peerStaMac[6] {0};
|
||||
uint8_t _peerApMac[6] {0};
|
||||
uint64_t _peerSessionKey;
|
||||
uint64_t _ownSessionKey;
|
||||
uint8_t _hashKey[EspnowProtocolInterpreter::espnowHashKeyLength] {0};
|
||||
bool _desync = false;
|
||||
std::unique_ptr<ExpiringTimeTracker> _timeTracker = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user