![](/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@100:0882cf295f8e, 2017-11-29 (annotated)
- Committer:
- mbriggs_vortex
- Date:
- Wed Nov 29 13:54:36 2017 -0700
- Revision:
- 100:0882cf295f8e
- Parent:
- 70:6b3ca63792c2
Adding relaese bin to repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Matt Briggs | 40:2ec4be320961 | 1 | /** |
Matt Briggs | 40:2ec4be320961 | 2 | * Library for LoRa Peer to Peer Brute Force Protocol |
Matt Briggs | 40:2ec4be320961 | 3 | */ |
Matt Briggs | 40:2ec4be320961 | 4 | |
Matt Briggs | 41:9ef4c4d77711 | 5 | #ifndef COMMPROTOCOLPEERBRUTE_H_ |
Matt Briggs | 41:9ef4c4d77711 | 6 | #define COMMPROTOCOLPEERBRUTE_H_ |
Matt Briggs | 40:2ec4be320961 | 7 | |
Matt Briggs | 41:9ef4c4d77711 | 8 | #include <inttypes.h> |
Matt Briggs | 41:9ef4c4d77711 | 9 | #include <vector> |
Matt Briggs | 40:2ec4be320961 | 10 | #include "../config.h" |
Matt Briggs | 41:9ef4c4d77711 | 11 | #include "mDot.h" |
Matt Briggs | 40:2ec4be320961 | 12 | |
Matt Briggs | 40:2ec4be320961 | 13 | // TODO make base class to allow different protocols to be used with easy |
Matt Briggs | 41:9ef4c4d77711 | 14 | // TODO wrap radio commands for error checking |
Matt Briggs | 41:9ef4c4d77711 | 15 | |
Matt Briggs | 41:9ef4c4d77711 | 16 | // TODO change to const |
Matt Briggs | 62:9751a8504c82 | 17 | static uint8_t pair_network_address[] = { 0x01, 0x00, 0x00, 0x00 }; // 0x00000000 reserved for multicast so use 1 |
Matt Briggs | 40:2ec4be320961 | 18 | static uint8_t pair_network_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; |
Matt Briggs | 40:2ec4be320961 | 19 | static uint8_t pair_data_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; |
Matt Briggs | 40:2ec4be320961 | 20 | |
Matt Briggs | 55:79ab0bbc5008 | 21 | const uint16_t PROTOCOL_NVM_START_ADDR = 0x1000; |
Matt Briggs | 62:9751a8504c82 | 22 | const uint16_t PROTOCOL_NVM_SIZE = 54; // Bytes |
Matt Briggs | 55:79ab0bbc5008 | 23 | const uint16_t PROTOCOL_FLAG = 0x5A00; |
Matt Briggs | 62:9751a8504c82 | 24 | const uint16_t PROTOCOL_REV = 0x0002; |
Matt Briggs | 70:6b3ca63792c2 | 25 | |
Matt Briggs | 70:6b3ca63792c2 | 26 | /** |
Matt Briggs | 70:6b3ca63792c2 | 27 | * @class NvmProtocolObj |
Matt Briggs | 70:6b3ca63792c2 | 28 | * @brief This convenience class implements helps storing protocol settings to non-volatile memory |
Matt Briggs | 70:6b3ca63792c2 | 29 | * |
Matt Briggs | 70:6b3ca63792c2 | 30 | * @details This class can translate to and from a byte array which can be stored then be easily stored |
Matt Briggs | 70:6b3ca63792c2 | 31 | * using any number of APIs. |
Matt Briggs | 70:6b3ca63792c2 | 32 | */ |
Matt Briggs | 55:79ab0bbc5008 | 33 | class NvmProtocolObj { |
Matt Briggs | 55:79ab0bbc5008 | 34 | public: |
Matt Briggs | 70:6b3ca63792c2 | 35 | /** |
Matt Briggs | 70:6b3ca63792c2 | 36 | * @brief NvmProtocolObj constructor |
Matt Briggs | 70:6b3ca63792c2 | 37 | * @details Initializes internal values with defaults |
Matt Briggs | 70:6b3ca63792c2 | 38 | */ |
Matt Briggs | 55:79ab0bbc5008 | 39 | NvmProtocolObj(); |
Matt Briggs | 70:6b3ca63792c2 | 40 | |
Matt Briggs | 70:6b3ca63792c2 | 41 | /** |
Matt Briggs | 70:6b3ca63792c2 | 42 | * @brief Set all internal variables to defaults. This is automatically called from constructor. |
Matt Briggs | 70:6b3ca63792c2 | 43 | */ |
Matt Briggs | 55:79ab0bbc5008 | 44 | void setDefaults(); |
Matt Briggs | 70:6b3ca63792c2 | 45 | |
Matt Briggs | 70:6b3ca63792c2 | 46 | /** |
Matt Briggs | 70:6b3ca63792c2 | 47 | * @brief Saves internal state from a byte array |
Matt Briggs | 70:6b3ca63792c2 | 48 | */ |
Matt Briggs | 55:79ab0bbc5008 | 49 | CmdResult toBytes(uint8_t *data, uint8_t &size); |
Matt Briggs | 55:79ab0bbc5008 | 50 | |
Matt Briggs | 70:6b3ca63792c2 | 51 | /** |
Matt Briggs | 70:6b3ca63792c2 | 52 | * @brief Loads internal state from a byte array. This byte array should typically have |
Matt Briggs | 70:6b3ca63792c2 | 53 | * previously generated by the toBytes function. |
Matt Briggs | 70:6b3ca63792c2 | 54 | */ |
Matt Briggs | 70:6b3ca63792c2 | 55 | CmdResult fromBytes(uint8_t *data, uint8_t size); |
Matt Briggs | 70:6b3ca63792c2 | 56 | |
Matt Briggs | 70:6b3ca63792c2 | 57 | /** |
Matt Briggs | 70:6b3ca63792c2 | 58 | * @brief Accessor for protocol flag |
Matt Briggs | 70:6b3ca63792c2 | 59 | */ |
Matt Briggs | 55:79ab0bbc5008 | 60 | uint16_t getProtocolFlag(); |
Matt Briggs | 70:6b3ca63792c2 | 61 | |
Matt Briggs | 70:6b3ca63792c2 | 62 | /** |
Matt Briggs | 70:6b3ca63792c2 | 63 | * @brief Checks if protocol flag is valid |
Matt Briggs | 70:6b3ca63792c2 | 64 | */ |
Matt Briggs | 55:79ab0bbc5008 | 65 | bool validProtocolFlag(); |
Matt Briggs | 70:6b3ca63792c2 | 66 | |
Matt Briggs | 70:6b3ca63792c2 | 67 | /** |
Matt Briggs | 70:6b3ca63792c2 | 68 | * @brief Accessor for protocol rev |
Matt Briggs | 70:6b3ca63792c2 | 69 | */ |
Matt Briggs | 55:79ab0bbc5008 | 70 | uint16_t getProtocolRev(); |
Matt Briggs | 70:6b3ca63792c2 | 71 | |
Matt Briggs | 70:6b3ca63792c2 | 72 | /** |
Matt Briggs | 70:6b3ca63792c2 | 73 | * @brief Checks if the revision of the protocol matches |
Matt Briggs | 70:6b3ca63792c2 | 74 | */ |
Matt Briggs | 55:79ab0bbc5008 | 75 | bool validProtocolRev(); |
Matt Briggs | 55:79ab0bbc5008 | 76 | |
Matt Briggs | 70:6b3ca63792c2 | 77 | /** |
Matt Briggs | 70:6b3ca63792c2 | 78 | * @brief Accessor for network address. Note value is returned via parameter. |
Matt Briggs | 70:6b3ca63792c2 | 79 | * @param addr A STL vector which will be set to 4 byte address |
Matt Briggs | 70:6b3ca63792c2 | 80 | */ |
Matt Briggs | 62:9751a8504c82 | 81 | void getNetworkAddr(std::vector<uint8_t> &addr); |
Matt Briggs | 70:6b3ca63792c2 | 82 | |
Matt Briggs | 70:6b3ca63792c2 | 83 | /** |
Matt Briggs | 70:6b3ca63792c2 | 84 | * @brief A setter for network address |
Matt Briggs | 70:6b3ca63792c2 | 85 | * @param addr The network address to be stored. This value should be 4 bytes. |
Matt Briggs | 70:6b3ca63792c2 | 86 | */ |
Matt Briggs | 62:9751a8504c82 | 87 | void setNetworkAddr(const std::vector<uint8_t> &addr); |
Matt Briggs | 70:6b3ca63792c2 | 88 | |
Matt Briggs | 70:6b3ca63792c2 | 89 | /** |
Matt Briggs | 70:6b3ca63792c2 | 90 | * @brief Accessor for network session key. Value return via parameter |
Matt Briggs | 70:6b3ca63792c2 | 91 | * @param key A STL Vector which will be set with 16 byte key |
Matt Briggs | 70:6b3ca63792c2 | 92 | */ |
Matt Briggs | 62:9751a8504c82 | 93 | void getNetworkSessionKey(std::vector<uint8_t> &key); |
Matt Briggs | 70:6b3ca63792c2 | 94 | |
Matt Briggs | 70:6b3ca63792c2 | 95 | /** |
Matt Briggs | 70:6b3ca63792c2 | 96 | * @brief A setter for network session key |
Matt Briggs | 70:6b3ca63792c2 | 97 | * |
Matt Briggs | 70:6b3ca63792c2 | 98 | * @param key The network session key to be stored. This value should be 16 bytes. |
Matt Briggs | 70:6b3ca63792c2 | 99 | */ |
Matt Briggs | 62:9751a8504c82 | 100 | void setNetworkSessionKey(const std::vector<uint8_t> &key); |
Matt Briggs | 70:6b3ca63792c2 | 101 | |
Matt Briggs | 70:6b3ca63792c2 | 102 | /** |
Matt Briggs | 70:6b3ca63792c2 | 103 | * @brief Accessor for data session key. Value return via parameter |
Matt Briggs | 70:6b3ca63792c2 | 104 | * @param key A STL Vector which will be set with 16 byte key |
Matt Briggs | 70:6b3ca63792c2 | 105 | */ |
Matt Briggs | 62:9751a8504c82 | 106 | void getDataSessionKey(std::vector<uint8_t> &key); |
Matt Briggs | 70:6b3ca63792c2 | 107 | |
Matt Briggs | 70:6b3ca63792c2 | 108 | /** |
Matt Briggs | 70:6b3ca63792c2 | 109 | * @brief A setter for data session key |
Matt Briggs | 70:6b3ca63792c2 | 110 | * @param key The network session key to be stored. This value should be 16 bytes. |
Matt Briggs | 70:6b3ca63792c2 | 111 | */ |
Matt Briggs | 62:9751a8504c82 | 112 | void setDataSessionKey(const std::vector<uint8_t> &key); |
Matt Briggs | 62:9751a8504c82 | 113 | |
Matt Briggs | 70:6b3ca63792c2 | 114 | /** |
Matt Briggs | 70:6b3ca63792c2 | 115 | * @brief A accessor for logical address |
Matt Briggs | 70:6b3ca63792c2 | 116 | */ |
Matt Briggs | 55:79ab0bbc5008 | 117 | uint16_t getLogicalAddr(); |
Matt Briggs | 70:6b3ca63792c2 | 118 | |
Matt Briggs | 70:6b3ca63792c2 | 119 | /** |
Matt Briggs | 70:6b3ca63792c2 | 120 | * @brief A setter for logical address |
Matt Briggs | 70:6b3ca63792c2 | 121 | * @param in Value for logical address |
Matt Briggs | 70:6b3ca63792c2 | 122 | */ |
Matt Briggs | 55:79ab0bbc5008 | 123 | void setLogicalAddr(uint16_t in); |
Matt Briggs | 70:6b3ca63792c2 | 124 | |
Matt Briggs | 70:6b3ca63792c2 | 125 | /** |
Matt Briggs | 70:6b3ca63792c2 | 126 | * @brief A accessor for LastMsgSeq |
Matt Briggs | 70:6b3ca63792c2 | 127 | */ |
Matt Briggs | 55:79ab0bbc5008 | 128 | uint32_t getLastMsgSeq(); |
Matt Briggs | 70:6b3ca63792c2 | 129 | |
Matt Briggs | 70:6b3ca63792c2 | 130 | /** |
Matt Briggs | 70:6b3ca63792c2 | 131 | * @brief A setter for LastMsgSeq |
Matt Briggs | 70:6b3ca63792c2 | 132 | * @param in Value for ter for LastMsgSeq |
Matt Briggs | 70:6b3ca63792c2 | 133 | */ |
Matt Briggs | 55:79ab0bbc5008 | 134 | void setLastMsgSeq(uint32_t in); |
Matt Briggs | 70:6b3ca63792c2 | 135 | |
Matt Briggs | 70:6b3ca63792c2 | 136 | /** |
Matt Briggs | 70:6b3ca63792c2 | 137 | * @brief A convenience method which increments LastMsgSeq |
Matt Briggs | 70:6b3ca63792c2 | 138 | */ |
Matt Briggs | 65:d546060aa03d | 139 | void incLastMsgSeq(); |
Matt Briggs | 62:9751a8504c82 | 140 | |
Matt Briggs | 62:9751a8504c82 | 141 | // TODO some day make these private with setters and getters |
Matt Briggs | 62:9751a8504c82 | 142 | uint8_t mNetworkAddr[4]; |
Matt Briggs | 62:9751a8504c82 | 143 | uint8_t mNetworkSessionKey[16]; |
Matt Briggs | 62:9751a8504c82 | 144 | uint8_t mDataSessionKey[16]; |
Matt Briggs | 55:79ab0bbc5008 | 145 | private: |
Matt Briggs | 55:79ab0bbc5008 | 146 | uint16_t mProtocolFlag; |
Matt Briggs | 55:79ab0bbc5008 | 147 | uint16_t mProtocolRev; |
Matt Briggs | 62:9751a8504c82 | 148 | uint32_t mFreq; |
Matt Briggs | 55:79ab0bbc5008 | 149 | uint16_t mLogicalAddr; |
Matt Briggs | 55:79ab0bbc5008 | 150 | uint32_t mSeqNum; |
Matt Briggs | 55:79ab0bbc5008 | 151 | }; |
Matt Briggs | 55:79ab0bbc5008 | 152 | |
Matt Briggs | 40:2ec4be320961 | 153 | /** |
Matt Briggs | 70:6b3ca63792c2 | 154 | * @class CommProtocolPeerBrute |
Matt Briggs | 41:9ef4c4d77711 | 155 | * @brief This class implements a peer-to-peer (P2P) brute force protocol. |
Matt Briggs | 41:9ef4c4d77711 | 156 | * |
Matt Briggs | 41:9ef4c4d77711 | 157 | * @details The protocol consists of at a minimum one transmitter (TX) and one |
Matt Briggs | 41:9ef4c4d77711 | 158 | * receiver (RX) which communicate via the 900MHz LoRa modulation. The concept |
Matt Briggs | 41:9ef4c4d77711 | 159 | * is that the RX is cycling on and off thus only listening for a small period |
Matt Briggs | 41:9ef4c4d77711 | 160 | * of time. Since we are not relying on a common time-base or other |
Matt Briggs | 41:9ef4c4d77711 | 161 | * synchronization mechanism the TX simply transmits for a duration long enough |
Matt Briggs | 41:9ef4c4d77711 | 162 | * guarantee that the RX will have at least one receive window during that time |
Matt Briggs | 41:9ef4c4d77711 | 163 | * period. Hence the name brute since the TX is just transmitting plenty for |
Matt Briggs | 41:9ef4c4d77711 | 164 | * the RX to hear it. |
Matt Briggs | 41:9ef4c4d77711 | 165 | * |
Matt Briggs | 41:9ef4c4d77711 | 166 | * The following should be implemented outside of the class: |
Matt Briggs | 41:9ef4c4d77711 | 167 | * - Power settings? |
Matt Briggs | 41:9ef4c4d77711 | 168 | * - What to do with the msgs which are received |
Matt Briggs | 41:9ef4c4d77711 | 169 | * - When to send messages |
Matt Briggs | 41:9ef4c4d77711 | 170 | * - When to sleep |
Matt Briggs | 41:9ef4c4d77711 | 171 | * |
Matt Briggs | 40:2ec4be320961 | 172 | */ |
Matt Briggs | 41:9ef4c4d77711 | 173 | class CommProtocolPeerBrute |
Matt Briggs | 40:2ec4be320961 | 174 | { |
Matt Briggs | 40:2ec4be320961 | 175 | public: |
Matt Briggs | 41:9ef4c4d77711 | 176 | /** |
Matt Briggs | 41:9ef4c4d77711 | 177 | * @brief CommProtocolPeerBrute constructor |
Matt Briggs | 41:9ef4c4d77711 | 178 | * |
Matt Briggs | 41:9ef4c4d77711 | 179 | * @details Just initialized internal variables does not configure devices. |
Matt Briggs | 41:9ef4c4d77711 | 180 | * Should call init before other functions are called. |
Matt Briggs | 41:9ef4c4d77711 | 181 | * |
Matt Briggs | 41:9ef4c4d77711 | 182 | * On Entry: |
Matt Briggs | 41:9ef4c4d77711 | 183 | * |
Matt Briggs | 41:9ef4c4d77711 | 184 | * On Exit: |
Matt Briggs | 44:ece6330e9b57 | 185 | * Internal variables are set to a known state but further initialization is required |
Matt Briggs | 41:9ef4c4d77711 | 186 | * |
Matt Briggs | 41:9ef4c4d77711 | 187 | * @return |
Matt Briggs | 41:9ef4c4d77711 | 188 | */ |
Matt Briggs | 44:ece6330e9b57 | 189 | CommProtocolPeerBrute(); |
Matt Briggs | 40:2ec4be320961 | 190 | |
Matt Briggs | 41:9ef4c4d77711 | 191 | /** |
Matt Briggs | 70:6b3ca63792c2 | 192 | * Attempts to read values from NVM (xDot's eeprom) if failure saves defaults. Then |
Matt Briggs | 70:6b3ca63792c2 | 193 | * configures radio with settings. |
Matt Briggs | 70:6b3ca63792c2 | 194 | * @return Success unless radio configuration error |
Matt Briggs | 70:6b3ca63792c2 | 195 | */ |
Matt Briggs | 70:6b3ca63792c2 | 196 | CmdResult init(); |
Matt Briggs | 70:6b3ca63792c2 | 197 | |
Matt Briggs | 70:6b3ca63792c2 | 198 | /** |
Matt Briggs | 47:a68747642a7a | 199 | * @brief Initialize radio with stored network network settings |
Matt Briggs | 41:9ef4c4d77711 | 200 | * |
Matt Briggs | 70:6b3ca63792c2 | 201 | * @return Returns the result of all the radio commands |
Matt Briggs | 41:9ef4c4d77711 | 202 | */ |
Matt Briggs | 62:9751a8504c82 | 203 | CmdResult configForSavedNetwork(); |
Matt Briggs | 41:9ef4c4d77711 | 204 | |
Matt Briggs | 41:9ef4c4d77711 | 205 | /** |
Matt Briggs | 44:ece6330e9b57 | 206 | * @brief Sets weather this object is configured as a TX or RX |
Matt Briggs | 44:ece6330e9b57 | 207 | * |
Matt Briggs | 44:ece6330e9b57 | 208 | * @param isTx if true then configured as transmitter if false then configured as receiver. |
Matt Briggs | 44:ece6330e9b57 | 209 | */ |
Matt Briggs | 44:ece6330e9b57 | 210 | void setTx(bool isTx); |
Matt Briggs | 44:ece6330e9b57 | 211 | |
Matt Briggs | 44:ece6330e9b57 | 212 | /** |
Matt Briggs | 41:9ef4c4d77711 | 213 | * @brief Returns weather this object is configured as a TX or RX |
Matt Briggs | 41:9ef4c4d77711 | 214 | * @return Returns true if TX |
Matt Briggs | 41:9ef4c4d77711 | 215 | */ |
Matt Briggs | 40:2ec4be320961 | 216 | bool isTx(); |
Matt Briggs | 41:9ef4c4d77711 | 217 | |
Matt Briggs | 41:9ef4c4d77711 | 218 | /** |
Matt Briggs | 41:9ef4c4d77711 | 219 | * @brief Returns weather this object is configured as a TX or RX |
Matt Briggs | 41:9ef4c4d77711 | 220 | * @return Returns true if RX |
Matt Briggs | 41:9ef4c4d77711 | 221 | */ |
Matt Briggs | 40:2ec4be320961 | 222 | bool isRx() {return !isTx();} |
Matt Briggs | 40:2ec4be320961 | 223 | |
Matt Briggs | 41:9ef4c4d77711 | 224 | /** |
Matt Briggs | 41:9ef4c4d77711 | 225 | * @brief This will clear the security pairs and channel info for pair |
Matt Briggs | 41:9ef4c4d77711 | 226 | * |
Matt Briggs | 41:9ef4c4d77711 | 227 | * @details This will clear both the value in RAM as well as the value stored in EEPROM for security and |
Matt Briggs | 41:9ef4c4d77711 | 228 | * clarity purposes. If RX this command will automatically trigger the generation of new security keys and |
Matt Briggs | 41:9ef4c4d77711 | 229 | * pair specific parameters. |
Matt Briggs | 41:9ef4c4d77711 | 230 | * |
Matt Briggs | 41:9ef4c4d77711 | 231 | * @return Returns status of all commands completed |
Matt Briggs | 41:9ef4c4d77711 | 232 | */ |
Matt Briggs | 40:2ec4be320961 | 233 | CmdResult clearPair(); |
Matt Briggs | 40:2ec4be320961 | 234 | |
Matt Briggs | 40:2ec4be320961 | 235 | // TX focused |
Matt Briggs | 70:6b3ca63792c2 | 236 | /** |
Matt Briggs | 70:6b3ca63792c2 | 237 | * @brief Accessor sequence number |
Matt Briggs | 70:6b3ca63792c2 | 238 | * @return Integer value |
Matt Briggs | 70:6b3ca63792c2 | 239 | */ |
Matt Briggs | 65:d546060aa03d | 240 | uint32_t getSeqNum(); |
Matt Briggs | 41:9ef4c4d77711 | 241 | /** |
Matt Briggs | 41:9ef4c4d77711 | 242 | * @brief Transmit the msg attached |
Matt Briggs | 41:9ef4c4d77711 | 243 | * |
Matt Briggs | 41:9ef4c4d77711 | 244 | * @details TODO figure out what information is wrapped by the LoRaWAN stuff implemented by |
Matt Briggs | 41:9ef4c4d77711 | 245 | * Multitech Systems |
Matt Briggs | 41:9ef4c4d77711 | 246 | * |
Matt Briggs | 41:9ef4c4d77711 | 247 | * @param msg A STL vector of uint8_t |
Matt Briggs | 41:9ef4c4d77711 | 248 | * @return Returns status of all commands completed |
Matt Briggs | 41:9ef4c4d77711 | 249 | */ |
Matt Briggs | 40:2ec4be320961 | 250 | CmdResult send (const std::vector<uint8_t> &msg); |
Matt Briggs | 41:9ef4c4d77711 | 251 | |
Matt Briggs | 41:9ef4c4d77711 | 252 | /** |
Matt Briggs | 65:d546060aa03d | 253 | * @brief Transmit an alert per documentation |
Matt Briggs | 65:d546060aa03d | 254 | * |
Matt Briggs | 65:d546060aa03d | 255 | * @details Sends EUI, uint16 data, alert seqNum |
Matt Briggs | 65:d546060aa03d | 256 | * |
Matt Briggs | 65:d546060aa03d | 257 | * @param data Input data to send |
Matt Briggs | 65:d546060aa03d | 258 | * @return if transmission is successful (note no ACK checked) |
Matt Briggs | 65:d546060aa03d | 259 | */ |
Matt Briggs | 65:d546060aa03d | 260 | CmdResult sendAlert (uint16_t data); |
Matt Briggs | 65:d546060aa03d | 261 | |
Matt Briggs | 65:d546060aa03d | 262 | /** |
Matt Briggs | 41:9ef4c4d77711 | 263 | * @brief This function sends a request to pair with a RX. If successful a pair accept message is received. |
Matt Briggs | 41:9ef4c4d77711 | 264 | * |
Matt Briggs | 41:9ef4c4d77711 | 265 | * @return Returns status of all commands completed |
Matt Briggs | 41:9ef4c4d77711 | 266 | */ |
Matt Briggs | 40:2ec4be320961 | 267 | CmdResult sendPairReq(); |
Matt Briggs | 40:2ec4be320961 | 268 | |
Matt Briggs | 40:2ec4be320961 | 269 | // RX focused |
Matt Briggs | 41:9ef4c4d77711 | 270 | /** |
Matt Briggs | 41:9ef4c4d77711 | 271 | * @brief This function enables the RX hardware of a radio. Note the listen time is defined internally by the protocol |
Matt Briggs | 41:9ef4c4d77711 | 272 | * |
Matt Briggs | 41:9ef4c4d77711 | 273 | * @param msgPending This boolean is return by reference. If true then during the listen window a msg was received. |
Matt Briggs | 41:9ef4c4d77711 | 274 | * @return Returns status of all commands completed |
Matt Briggs | 41:9ef4c4d77711 | 275 | */ |
Matt Briggs | 40:2ec4be320961 | 276 | CmdResult listen (bool &msgPending); |
Matt Briggs | 41:9ef4c4d77711 | 277 | |
Matt Briggs | 41:9ef4c4d77711 | 278 | /** |
Matt Briggs | 41:9ef4c4d77711 | 279 | * @brief Returns the last message received via listening |
Matt Briggs | 41:9ef4c4d77711 | 280 | * |
Matt Briggs | 41:9ef4c4d77711 | 281 | * @param msg This STL vector of uint8_t is returned by reference with msg contents. |
Matt Briggs | 41:9ef4c4d77711 | 282 | * @return Returns status of all commands completed |
Matt Briggs | 41:9ef4c4d77711 | 283 | */ |
Matt Briggs | 40:2ec4be320961 | 284 | CmdResult recv (std::vector<uint8_t> &msg); |
Matt Briggs | 70:6b3ca63792c2 | 285 | |
Matt Briggs | 70:6b3ca63792c2 | 286 | /** |
Matt Briggs | 70:6b3ca63792c2 | 287 | * @brief Attempts to parse and return the last message received |
Matt Briggs | 70:6b3ca63792c2 | 288 | * |
Matt Briggs | 70:6b3ca63792c2 | 289 | * @details If the message is too short or if the flag is not correct will return an error. |
Matt Briggs | 70:6b3ca63792c2 | 290 | * |
Matt Briggs | 70:6b3ca63792c2 | 291 | * @param eui 4 byte value returned |
Matt Briggs | 70:6b3ca63792c2 | 292 | * @param data Data field from alert message |
Matt Briggs | 70:6b3ca63792c2 | 293 | * @param seqNum Transmitter's sequence number |
Matt Briggs | 70:6b3ca63792c2 | 294 | * @return Returns status of all commands completed |
Matt Briggs | 70:6b3ca63792c2 | 295 | */ |
Matt Briggs | 65:d546060aa03d | 296 | CmdResult recvAlert (std::vector<uint8_t> &eui, uint16_t &data, uint32_t &seqNum); |
Matt Briggs | 41:9ef4c4d77711 | 297 | |
Matt Briggs | 41:9ef4c4d77711 | 298 | /** |
Matt Briggs | 70:6b3ca63792c2 | 299 | * @brief This function enables the radio to listen for pair requests. |
Matt Briggs | 41:9ef4c4d77711 | 300 | * @param waitTime The maximum time which radio waits for pair requests |
Matt Briggs | 41:9ef4c4d77711 | 301 | * |
Matt Briggs | 41:9ef4c4d77711 | 302 | * TODO determine if it is important to know who is paired |
Matt Briggs | 41:9ef4c4d77711 | 303 | * |
Matt Briggs | 70:6b3ca63792c2 | 304 | * @return If pair message received then cmdSucess is returned otherwise |
Matt Briggs | 70:6b3ca63792c2 | 305 | * timeout is returned. |
Matt Briggs | 41:9ef4c4d77711 | 306 | */ |
Matt Briggs | 40:2ec4be320961 | 307 | CmdResult waitForPairing(float waitTime); |
Matt Briggs | 40:2ec4be320961 | 308 | |
Matt Briggs | 41:9ef4c4d77711 | 309 | /** |
Matt Briggs | 41:9ef4c4d77711 | 310 | * @brief Send a pair accept message. This message contains all the information for TX to properly send |
Matt Briggs | 41:9ef4c4d77711 | 311 | * msgs to RX in P2P mode. |
Matt Briggs | 41:9ef4c4d77711 | 312 | * @return Returns status of all commands completed |
Matt Briggs | 41:9ef4c4d77711 | 313 | */ |
Matt Briggs | 41:9ef4c4d77711 | 314 | CmdResult sendPairAccepted(); |
Matt Briggs | 41:9ef4c4d77711 | 315 | |
Matt Briggs | 70:6b3ca63792c2 | 316 | /** |
Matt Briggs | 70:6b3ca63792c2 | 317 | * |
Matt Briggs | 70:6b3ca63792c2 | 318 | * @param waitTime |
Matt Briggs | 70:6b3ca63792c2 | 319 | * @return |
Matt Briggs | 70:6b3ca63792c2 | 320 | */ |
Matt Briggs | 61:8d9efd33cac9 | 321 | CmdResult waitForAccept(float waitTime); |
Matt Briggs | 61:8d9efd33cac9 | 322 | |
Matt Briggs | 41:9ef4c4d77711 | 323 | // xDot Peer to Peer Specific |
Matt Briggs | 41:9ef4c4d77711 | 324 | /** |
Matt Briggs | 41:9ef4c4d77711 | 325 | * Convenience function to get the internal downlink count from radio |
Matt Briggs | 41:9ef4c4d77711 | 326 | * @return Number of downlink msgs |
Matt Briggs | 41:9ef4c4d77711 | 327 | */ |
Matt Briggs | 41:9ef4c4d77711 | 328 | uint32_t getDLC(); |
Matt Briggs | 41:9ef4c4d77711 | 329 | |
Matt Briggs | 41:9ef4c4d77711 | 330 | /** |
Matt Briggs | 41:9ef4c4d77711 | 331 | * Convenience function to get the internal uplink count from radio |
Matt Briggs | 41:9ef4c4d77711 | 332 | * @return Number of uplink msgs |
Matt Briggs | 41:9ef4c4d77711 | 333 | */ |
Matt Briggs | 41:9ef4c4d77711 | 334 | uint32_t getULC(); |
Matt Briggs | 41:9ef4c4d77711 | 335 | |
Matt Briggs | 64:46c8819c07cc | 336 | /** |
Matt Briggs | 64:46c8819c07cc | 337 | * Resets both uplink and downlink counters (1 and 0 respectively). |
Matt Briggs | 64:46c8819c07cc | 338 | * @return |
Matt Briggs | 64:46c8819c07cc | 339 | */ |
Matt Briggs | 64:46c8819c07cc | 340 | CmdResult resetCounters(); |
Matt Briggs | 64:46c8819c07cc | 341 | |
Matt Briggs | 62:9751a8504c82 | 342 | // TODO maybe this should be private |
Matt Briggs | 62:9751a8504c82 | 343 | CmdResult configForPairingNetwork(); |
Matt Briggs | 63:e1efbe3402d9 | 344 | void printDotConfig(); |
Matt Briggs | 62:9751a8504c82 | 345 | |
Matt Briggs | 40:2ec4be320961 | 346 | private: |
Matt Briggs | 55:79ab0bbc5008 | 347 | NvmProtocolObj mMemObj; |
Matt Briggs | 40:2ec4be320961 | 348 | bool mIsTx; |
Matt Briggs | 54:c04d7b6fa075 | 349 | uint32_t mPrevDownLinkCnt; |
Matt Briggs | 40:2ec4be320961 | 350 | |
Matt Briggs | 40:2ec4be320961 | 351 | /** |
Matt Briggs | 40:2ec4be320961 | 352 | * @brief Reads baseboard information from non-volatile memory (NVM) |
Matt Briggs | 40:2ec4be320961 | 353 | * |
Matt Briggs | 40:2ec4be320961 | 354 | * @details This data is read from the xDot's internal EEPROM. This |
Matt Briggs | 40:2ec4be320961 | 355 | * method is called from init(). The following |
Matt Briggs | 40:2ec4be320961 | 356 | * is stored: |
Matt Briggs | 40:2ec4be320961 | 357 | * 1. Peer Brute Storage code word |
Matt Briggs | 40:2ec4be320961 | 358 | * 2. 8-bit protocol version |
Matt Briggs | 40:2ec4be320961 | 359 | * 3. 16-bit Baseboard serial number |
Matt Briggs | 40:2ec4be320961 | 360 | * 4. 4 Byte network address |
Matt Briggs | 40:2ec4be320961 | 361 | * 5. 16 Byte network session key |
Matt Briggs | 40:2ec4be320961 | 362 | * 6. 16 Byte data session key |
Matt Briggs | 40:2ec4be320961 | 363 | * 7. 4 Byte DLC |
Matt Briggs | 40:2ec4be320961 | 364 | * 8. 4 Byte ULC |
Matt Briggs | 40:2ec4be320961 | 365 | * |
Matt Briggs | 40:2ec4be320961 | 366 | * TODO add memory map information |
Matt Briggs | 40:2ec4be320961 | 367 | * |
Matt Briggs | 40:2ec4be320961 | 368 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 369 | */ |
Matt Briggs | 40:2ec4be320961 | 370 | CmdResult readInfoFromNVM(); |
Matt Briggs | 40:2ec4be320961 | 371 | |
Matt Briggs | 40:2ec4be320961 | 372 | /** |
Matt Briggs | 40:2ec4be320961 | 373 | * @brief Stores baseboard information to non-volatile memory (NVM) |
Matt Briggs | 40:2ec4be320961 | 374 | * |
Matt Briggs | 40:2ec4be320961 | 375 | * @details This method is called during special configuration events like first time boot or factory reset. |
Matt Briggs | 40:2ec4be320961 | 376 | * |
Matt Briggs | 40:2ec4be320961 | 377 | * TODO add memory map information |
Matt Briggs | 40:2ec4be320961 | 378 | * |
Matt Briggs | 40:2ec4be320961 | 379 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 380 | */ |
Matt Briggs | 40:2ec4be320961 | 381 | CmdResult writeInfoToNVM(); |
Matt Briggs | 40:2ec4be320961 | 382 | |
Matt Briggs | 41:9ef4c4d77711 | 383 | /** |
Matt Briggs | 41:9ef4c4d77711 | 384 | * Generates new encryption keys for radio |
Matt Briggs | 41:9ef4c4d77711 | 385 | * @return |
Matt Briggs | 41:9ef4c4d77711 | 386 | */ |
Matt Briggs | 62:9751a8504c82 | 387 | CmdResult genEncypKey(std::vector<uint8_t> &newKey, uint8_t keySize, bool allowZero); |
Matt Briggs | 61:8d9efd33cac9 | 388 | CmdResult genEncypKey(std::vector<uint8_t> &newKey, uint8_t keySize); |
Matt Briggs | 61:8d9efd33cac9 | 389 | |
Matt Briggs | 40:2ec4be320961 | 390 | }; |
Matt Briggs | 40:2ec4be320961 | 391 | |
Matt Briggs | 55:79ab0bbc5008 | 392 | |
Matt Briggs | 40:2ec4be320961 | 393 | #endif |