![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
xDotBridge/inc/CommProtocolPeerBrute.h
- Committer:
- Matt Briggs
- Date:
- 2017-02-22
- Revision:
- 53:a1563574a980
- Parent:
- 47:a68747642a7a
- Child:
- 54:c04d7b6fa075
File content as of revision 53:a1563574a980:
/** * Library for LoRa Peer to Peer Brute Force Protocol */ #ifndef COMMPROTOCOLPEERBRUTE_H_ #define COMMPROTOCOLPEERBRUTE_H_ #include <inttypes.h> #include <vector> #include "../config.h" #include "mDot.h" // TODO make base class to allow different protocols to be used with easy // TODO wrap radio commands for error checking // TODO change to const static uint8_t pair_network_address[] = { 0x01, 0x02, 0x03, 0x04 }; static uint8_t pair_network_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; static uint8_t pair_data_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; /** * @class PeerBruteCommProtocol * @brief This class implements a peer-to-peer (P2P) brute force protocol. * * @details The protocol consists of at a minimum one transmitter (TX) and one * receiver (RX) which communicate via the 900MHz LoRa modulation. The concept * is that the RX is cycling on and off thus only listening for a small period * of time. Since we are not relying on a common time-base or other * synchronization mechanism the TX simply transmits for a duration long enough * guarantee that the RX will have at least one receive window during that time * period. Hence the name brute since the TX is just transmitting plenty for * the RX to hear it. * * The following should be implemented outside of the class: * - Power settings? * - What to do with the msgs which are received * - When to send messages * - When to sleep * */ class CommProtocolPeerBrute { public: /** * @brief CommProtocolPeerBrute constructor * * @details Just initialized internal variables does not configure devices. * Should call init before other functions are called. * * On Entry: * * On Exit: * Internal variables are set to a known state but further initialization is required * * @return */ CommProtocolPeerBrute(); /** * @brief Initialize radio with stored network network settings * * @return Returns the result of all the commands */ CmdResult init(); /** * @brief Sets weather this object is configured as a TX or RX * * @param isTx if true then configured as transmitter if false then configured as receiver. */ void setTx(bool isTx); /** * @brief Returns weather this object is configured as a TX or RX * @return Returns true if TX */ bool isTx(); /** * @brief Returns weather this object is configured as a TX or RX * @return Returns true if RX */ bool isRx() {return !isTx();} /** * @brief This will clear the security pairs and channel info for pair * * @details This will clear both the value in RAM as well as the value stored in EEPROM for security and * clarity purposes. If RX this command will automatically trigger the generation of new security keys and * pair specific parameters. * * @return Returns status of all commands completed */ CmdResult clearPair(); // TX focused /** * @brief Transmit the msg attached * * @details TODO figure out what information is wrapped by the LoRaWAN stuff implemented by * Multitech Systems * * @param msg A STL vector of uint8_t * @return Returns status of all commands completed */ CmdResult send (const std::vector<uint8_t> &msg); /** * @brief This function sends a request to pair with a RX. If successful a pair accept message is received. * * @return Returns status of all commands completed */ CmdResult sendPairReq(); // RX focused /** * @brief This function enables the RX hardware of a radio. Note the listen time is defined internally by the protocol * * @param msgPending This boolean is return by reference. If true then during the listen window a msg was received. * @return Returns status of all commands completed */ CmdResult listen (bool &msgPending); /** * @brief Returns the last message received via listening * * @param msg This STL vector of uint8_t is returned by reference with msg contents. * @return Returns status of all commands completed */ CmdResult recv (std::vector<uint8_t> &msg); /** * @brief This fucntion enables the radio to listen for pair requests. * @param waitTime The maximum time which radio waits for pair requests * * TODO determine if it is important to know who is paired * * @return If pair message received then cmdSucess is returned otherwise timeout is returned. */ CmdResult waitForPairing(float waitTime); /** * @brief Send a pair accept message. This message contains all the information for TX to properly send * msgs to RX in P2P mode. * @return Returns status of all commands completed */ CmdResult sendPairAccepted(); // xDot Peer to Peer Specific /** * Convenience function to get the internal downlink count from radio * @return Number of downlink msgs */ uint32_t getDLC(); /** * Convenience function to get the internal uplink count from radio * @return Number of uplink msgs */ uint32_t getULC(); private: uint8_t mNetworkAddr[4]; uint8_t mNetwork_session_key[16]; uint8_t mData_session_key[16]; bool mIsTx; /** * @brief Reads baseboard information from non-volatile memory (NVM) * * @details This data is read from the xDot's internal EEPROM. This * method is called from init(). The following * is stored: * 1. Peer Brute Storage code word * 2. 8-bit protocol version * 3. 16-bit Baseboard serial number * 4. 4 Byte network address * 5. 16 Byte network session key * 6. 16 Byte data session key * 7. 4 Byte DLC * 8. 4 Byte ULC * * TODO add memory map information * * @return CmdResult */ CmdResult readInfoFromNVM(); /** * @brief Stores baseboard information to non-volatile memory (NVM) * * @details This method is called during special configuration events like first time boot or factory reset. * * TODO add memory map information * * @return CmdResult */ CmdResult writeInfoToNVM(); /** * Resets both uplink and downlink counters to zero. Useful for when pairing. * @return */ CmdResult resetCounters(); /** * Generates new encryption keys for radio * @return */ CmdResult genEncypKeys(); }; #endif