Aidan Wynn / libmDot-mbed5

Dependents:   Cloudtracker

Committer:
Jenkins@KEILDM1.dc.multitech.prv
Date:
Mon Feb 17 14:43:04 2020 -0600
Revision:
72:b1e07ec1c30d
Parent:
70:0c5b5b02d17b
mdot-library revision 3.3.5 and mbed-os revision mbed-os-5.13.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 16:b630e18103e5 1 /** __ ___ ____ _ ______ __ ____ __ ____
Mike Fiore 16:b630e18103e5 2 * / |/ /_ __/ / /_(_)__/_ __/__ ____/ / / __/_ _____ / /____ __ _ ___ / _/__ ____
Mike Fiore 16:b630e18103e5 3 * / /|_/ / // / / __/ /___// / / -_) __/ _ \ _\ \/ // (_-</ __/ -_) ' \(_-< _/ // _ \/ __/ __
Mike Fiore 16:b630e18103e5 4 * /_/ /_/\_,_/_/\__/_/ /_/ \__/\__/_//_/ /___/\_, /___/\__/\__/_/_/_/___/ /___/_//_/\__/ /_/
Mike Fiore 16:b630e18103e5 5 * Copyright (C) 2015 by Multi-Tech Systems /___/
Mike Fiore 16:b630e18103e5 6 *
Mike Fiore 16:b630e18103e5 7 *
Mike Fiore 16:b630e18103e5 8 * @author Jason Reiss
Mike Fiore 16:b630e18103e5 9 * @date 10-31-2015
Mike Fiore 16:b630e18103e5 10 * @brief lora namespace defines global settings, structures and enums for the lora library
Mike Fiore 16:b630e18103e5 11 *
Mike Fiore 16:b630e18103e5 12 * @details
Mike Fiore 16:b630e18103e5 13 *
Mike Fiore 16:b630e18103e5 14 *
Mike Fiore 16:b630e18103e5 15 *
Mike Fiore 16:b630e18103e5 16 */
Mike Fiore 16:b630e18103e5 17
Mike Fiore 16:b630e18103e5 18 #ifndef __LORA_H__
Mike Fiore 16:b630e18103e5 19 #define __LORA_H__
Mike Fiore 16:b630e18103e5 20
Mike Fiore 16:b630e18103e5 21 #include "mbed.h"
Mike Fiore 16:b630e18103e5 22 #include <assert.h>
Mike Fiore 16:b630e18103e5 23 #include "MTSLog.h"
Mike Fiore 16:b630e18103e5 24 //#include <cstring>
Mike Fiore 16:b630e18103e5 25 #include <inttypes.h>
Mike Fiore 16:b630e18103e5 26
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 27
Mike Fiore 16:b630e18103e5 28 namespace lora {
Mike Fiore 16:b630e18103e5 29
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 30 #ifndef MAC_VERSION
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 31 const std::string MAC_VERSION = "1.0.4";
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 32 #endif
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 33
Mike Fiore 16:b630e18103e5 34 /**
Mike Fiore 16:b630e18103e5 35 * Frequency bandwidth of a Datarate, higher bandwidth gives higher datarate
Mike Fiore 16:b630e18103e5 36 */
Mike Fiore 16:b630e18103e5 37 enum Bandwidth {
Mike Fiore 16:b630e18103e5 38 BW_125,
Mike Fiore 16:b630e18103e5 39 BW_250,
Mike Fiore 16:b630e18103e5 40 BW_500,
Mike Fiore 16:b630e18103e5 41 BW_FSK = 50
Mike Fiore 16:b630e18103e5 42 };
Mike Fiore 16:b630e18103e5 43
Mike Fiore 16:b630e18103e5 44 /**
Mike Fiore 16:b630e18103e5 45 * Spreading factor of a Datarate, lower spreading factor gives higher datarate
Mike Fiore 16:b630e18103e5 46 */
Mike Fiore 16:b630e18103e5 47 enum SpreadingFactors {
Mike Fiore 16:b630e18103e5 48 SF_6 = 6,
Mike Fiore 16:b630e18103e5 49 SF_7,
Mike Fiore 16:b630e18103e5 50 SF_8,
Mike Fiore 16:b630e18103e5 51 SF_9,
Mike Fiore 16:b630e18103e5 52 SF_10,
Mike Fiore 16:b630e18103e5 53 SF_11,
Mike Fiore 16:b630e18103e5 54 SF_12,
Mike Fiore 16:b630e18103e5 55 SF_FSK,
Mike Fiore 16:b630e18103e5 56 SF_INVALID
Mike Fiore 16:b630e18103e5 57 };
Mike Fiore 16:b630e18103e5 58
Mike Fiore 16:b630e18103e5 59 /**
Mike Fiore 16:b630e18103e5 60 * Datarates for use with ChannelPlan
Mike Fiore 16:b630e18103e5 61 */
Mike Fiore 16:b630e18103e5 62 enum Datarates {
Mike Fiore 16:b630e18103e5 63 DR_0 = 0,
Mike Fiore 16:b630e18103e5 64 DR_1,
Mike Fiore 16:b630e18103e5 65 DR_2,
Mike Fiore 16:b630e18103e5 66 DR_3,
Mike Fiore 16:b630e18103e5 67 DR_4,
Mike Fiore 16:b630e18103e5 68 DR_5,
Mike Fiore 16:b630e18103e5 69 DR_6,
Mike Fiore 16:b630e18103e5 70 DR_7,
Mike Fiore 16:b630e18103e5 71 DR_8,
Mike Fiore 16:b630e18103e5 72 DR_9,
Mike Fiore 16:b630e18103e5 73 DR_10,
Mike Fiore 16:b630e18103e5 74 DR_11,
Mike Fiore 16:b630e18103e5 75 DR_12,
Mike Fiore 16:b630e18103e5 76 DR_13,
Mike Fiore 16:b630e18103e5 77 DR_14,
Mike Fiore 16:b630e18103e5 78 DR_15
Mike Fiore 16:b630e18103e5 79 };
Mike Fiore 16:b630e18103e5 80
Mike Fiore 16:b630e18103e5 81 const uint8_t MIN_DATARATE = (uint8_t) DR_0; //!< Minimum datarate
Mike Fiore 16:b630e18103e5 82
Mike Fiore 16:b630e18103e5 83
Mike Fiore 16:b630e18103e5 84 const uint8_t MAX_PHY_PACKET_SIZE = 255; //!< Maximum size for a packet
Mike Fiore 16:b630e18103e5 85 const uint8_t MAX_APPS = 8; //!< Maximum number of apps sessions to save
Mike Fiore 16:b630e18103e5 86 const uint8_t MAX_MULTICAST_SESSIONS = 8; //!< Maximum number of multicast sessions to save
Mike Fiore 16:b630e18103e5 87 const uint8_t EUI_SIZE = 8; //!< Number of bytes in an EUI
Mike Fiore 16:b630e18103e5 88 const uint8_t KEY_SIZE = 16; //!< Number of bytes in an AES key
Mike Fiore 16:b630e18103e5 89
Mike Fiore 16:b630e18103e5 90 const uint8_t DEFAULT_NUM_CHANNELS = 16; //!< Default number of channels in a plan
Mike Fiore 16:b630e18103e5 91 const uint8_t DEFAULT_RX1_DR_OFFSET = 0; //!< Default datarate offset for first rx window
Mike Fiore 16:b630e18103e5 92 const uint8_t DEFAULT_RX2_DATARATE = 0; //!< Default datarate for second rx window
Mike Fiore 16:b630e18103e5 93 const uint8_t DEFAULT_TX_POWER = 14; //!< Default transmit power
Mike Fiore 16:b630e18103e5 94 const uint8_t DEFAULT_CODE_RATE = 1; //!< Default coding rate 1:4/5, 2:4/6, 3:4/7, 4:4/8
Mike Fiore 16:b630e18103e5 95 const uint8_t DEFAULT_PREAMBLE_LEN = 8; //!< Default preamble length
Mike Fiore 16:b630e18103e5 96
Mike Fiore 16:b630e18103e5 97 const int32_t MAX_FCNT_GAP = 16384; //!< Maximum allowed gap in sequence numbers before roll-over
Mike Fiore 16:b630e18103e5 98
Mike Fiore 16:b630e18103e5 99 const uint16_t PRIVATE_JOIN_DELAY = 1000; //!< Default join delay used for private network
Mike Fiore 16:b630e18103e5 100 const uint16_t PUBLIC_JOIN_DELAY = 5000; //!< Default join delay used for public network
Mike Fiore 16:b630e18103e5 101 const uint16_t DEFAULT_JOIN_DELAY = PRIVATE_JOIN_DELAY; //!< Default join delay1
Mike Fiore 16:b630e18103e5 102 const uint16_t DEFAULT_RX_DELAY = 1000; //!< Default delay for first receive window
Mike Fiore 16:b630e18103e5 103 const uint16_t DEFAULT_RX_TIMEOUT = 3000; //!< Default timeout for receive windows
Mike Fiore 16:b630e18103e5 104
Mike Fiore 16:b630e18103e5 105 const uint8_t HI_DR_SYMBOL_TIMEOUT = 12; //!< Symbol timeout for receive at datarate with SF < 11
Mike Fiore 16:b630e18103e5 106 const uint8_t LO_DR_SYMBOL_TIMEOUT = 8; //!< Symbol timeout for receive at datarate with SF > 10
Mike Fiore 16:b630e18103e5 107
Mike Fiore 16:b630e18103e5 108 const uint16_t RX2_DELAY_OFFSET = 1000; //!< Delay between first and second window
Mike Fiore 16:b630e18103e5 109 const uint16_t RXC_OFFSET = 50; //!< Time between end of RXC after TX and RX1
Mike Fiore 16:b630e18103e5 110
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 111 const uint16_t BEACON_PREAMBLE_LENGTH = 10U; //!< Beacon preamble length
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 112 const uint16_t DEFAULT_BEACON_PERIOD = 128U; //!< Default period of the beacon (in seconds)
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 113 const uint16_t PING_SLOT_LENGTH = 30U; //!< Duration of each class B ping slot (in milliseconds)
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 114 const uint32_t BEACON_RESERVED_TIME = 2120U; //!< Time reserved for beacon broadcast (in milliseconds)
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 115 const uint16_t BEACON_GUARD_TIME = 3000U; //!< Guard time before beacon transmission where no ping slots can be scheduled (in milliseconds)
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 116 const uint32_t MAX_BEACONLESS_OP_TIME = 7200U; //!< Maximum time to operate in class B since last beacon received (in seconds)
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 117 const uint16_t MAX_CLASS_B_WINDOW_GROWTH = 3U; //!< Maximum window growth factor for beacons and ping slots in beacon-less operation
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 118 const uint16_t DEFAULT_PING_NB = 1U; //!< Default number of ping slots per beacon interval
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 119 const uint16_t CLS_B_PAD = 15U; //!< Pad added to the beginning of ping slot rx windows (in milliseconds)
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 120 const uint16_t BEACON_PAD = 100U; //!< Pad beacon window is expanded (in milliseconds)
Mike Fiore 16:b630e18103e5 121
Mike Fiore 16:b630e18103e5 122 const int16_t DEFAULT_FREE_CHAN_RSSI_THRESHOLD = -90; //!< Threshold for channel activity detection (CAD) dBm
Mike Fiore 16:b630e18103e5 123
Mike Fiore 16:b630e18103e5 124 const uint8_t CHAN_MASK_SIZE = 16; //!< Number of bits in a channel mask
Mike Fiore 16:b630e18103e5 125 const uint8_t COMMANDS_BUFFER_SIZE = 15; //!< Size of Mac Command buffer
Mike Fiore 16:b630e18103e5 126
Mike Fiore 16:b630e18103e5 127 const uint8_t PKT_HEADER = 0; //!< Index to packet mHdr field
Mike Fiore 16:b630e18103e5 128 const uint8_t PKT_ADDRESS = 1; //!< Index to first byte of packet address field
Mike Fiore 16:b630e18103e5 129 const uint8_t PKT_FRAME_CONTROL = PKT_ADDRESS + 4; //!< Index to packet fCtrl field @see UplinkControl
Mike Fiore 16:b630e18103e5 130 const uint8_t PKT_FRAME_COUNTER = PKT_FRAME_CONTROL + 1; //!< Index to packet frame counter field
Mike Fiore 16:b630e18103e5 131 const uint8_t PKT_OPTIONS_START = PKT_FRAME_COUNTER + 2; //!< Index to start of optional mac commands
Mike Fiore 16:b630e18103e5 132
Mike Fiore 16:b630e18103e5 133 const uint8_t PKT_JOIN_APP_NONCE = 1; //!< Index to application nonce in Join Accept message
Mike Fiore 16:b630e18103e5 134 const uint8_t PKT_JOIN_NETWORK_ID = 4; //!< Index to network id in Join Accept message
Mike Fiore 16:b630e18103e5 135 const uint8_t PKT_JOIN_NETWORK_ADDRESS = 7; //!< Index to network address in Join Accept message
Mike Fiore 16:b630e18103e5 136 const uint8_t PKT_JOIN_DL_SETTINGS = 11; //!< Index to downlink settings in Join Accept message
Mike Fiore 16:b630e18103e5 137 const uint8_t PKT_JOIN_RX_DELAY = 12; //!< Index to rx delay in Join Accept message
Mike Fiore 16:b630e18103e5 138
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 139 const uint8_t DEFAULT_ADR_ACK_LIMIT = 64; //!< Number of packets without ADR ACK Request
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 140 const uint8_t DEFAULT_ADR_ACK_DELAY = 32; //!< Number of packets to expect ADR ACK Response within
Mike Fiore 16:b630e18103e5 141
Mike Fiore 16:b630e18103e5 142 const uint16_t ACK_TIMEOUT = 2000; //!< Base millisecond timeout to resend after missed ACK
Mike Fiore 16:b630e18103e5 143 const uint16_t ACK_TIMEOUT_RND = 1000; //!< Random millisecond adjustment to resend after missed ACK
Mike Fiore 16:b630e18103e5 144
Mike Fiore 16:b630e18103e5 145 const uint8_t FRAME_OVERHEAD = 13; //!< Bytes of network info overhead in a frame
Mike Fiore 16:b630e18103e5 146
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 147 const uint16_t MAX_OFF_AIR_WAIT = 5000U; //!< Max time in ms to block for a duty cycle restriction to expire before erroring out
Mike Fiore 16:b630e18103e5 148 /**
Mike Fiore 16:b630e18103e5 149 * Settings for type of network
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 150 *
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 151 * PRIVATE_MTS - Sync Word 0x12, US/AU Downlink frequencies per Frequency Sub Band
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 152 * PUBLIC_LORAWAN - Sync Word 0x34
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 153 * PRIVATE_LORAWAN - Sync Word 0x12
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 154 * PEER_TO_PEER - Sync Word 0x56 used for Dot to Dot communication
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 155 *
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 156 * Join Delay window settings are independent of Network Type setting
Mike Fiore 16:b630e18103e5 157 */
Mike Fiore 16:b630e18103e5 158 enum NetworkType {
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 159 PRIVATE_MTS = 0,
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 160 PUBLIC_LORAWAN = 1,
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 161 PRIVATE_LORAWAN = 2,
Mike Fiore 16:b630e18103e5 162 PEER_TO_PEER = 4
Mike Fiore 16:b630e18103e5 163 };
Mike Fiore 16:b630e18103e5 164
Mike Fiore 16:b630e18103e5 165 /**
Mike Fiore 16:b630e18103e5 166 * Enum for on/off settings
Mike Fiore 16:b630e18103e5 167 */
Mike Fiore 16:b630e18103e5 168 enum Enabled {
Mike Fiore 16:b630e18103e5 169 OFF = 0,
Mike Fiore 16:b630e18103e5 170 ON = 1
Mike Fiore 16:b630e18103e5 171 };
Mike Fiore 16:b630e18103e5 172
Mike Fiore 16:b630e18103e5 173 /**
Mike Fiore 16:b630e18103e5 174 * Return status of mac functions
Mike Fiore 16:b630e18103e5 175 */
Mike Fiore 16:b630e18103e5 176 enum MacStatus {
Mike Fiore 16:b630e18103e5 177 LORA_OK = 0,
Mike Fiore 16:b630e18103e5 178 LORA_ERROR = 1,
Mike Fiore 16:b630e18103e5 179 LORA_JOIN_ERROR = 2,
Mike Fiore 16:b630e18103e5 180 LORA_SEND_ERROR = 3,
Mike Fiore 16:b630e18103e5 181 LORA_MIC_ERROR = 4,
Mike Fiore 16:b630e18103e5 182 LORA_ADDRESS_ERROR = 5,
Mike Fiore 16:b630e18103e5 183 LORA_NO_CHANS_ENABLED = 6,
Mike Fiore 16:b630e18103e5 184 LORA_COMMAND_BUFFER_FULL = 7,
Mike Fiore 16:b630e18103e5 185 LORA_UNKNOWN_MAC_COMMAND = 8,
Mike Fiore 16:b630e18103e5 186 LORA_ADR_OFF = 9,
Mike Fiore 16:b630e18103e5 187 LORA_BUSY = 10,
Mike Fiore 16:b630e18103e5 188 LORA_LINK_BUSY = 11,
Mike Fiore 16:b630e18103e5 189 LORA_RADIO_BUSY = 12,
Mike Fiore 16:b630e18103e5 190 LORA_BUFFER_FULL = 13,
Mike Fiore 16:b630e18103e5 191 LORA_JOIN_BACKOFF = 14,
Mike Fiore 16:b630e18103e5 192 LORA_NO_FREE_CHAN = 15,
Mike Fiore 16:b630e18103e5 193 LORA_AGGREGATED_DUTY_CYCLE = 16,
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 194 LORA_MAC_COMMAND_ERROR = 17,
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 195 LORA_MAX_PAYLOAD_EXCEEDED = 18,
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 196 LORA_LBT_CHANNEL_BUSY = 19,
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 197 LORA_BEACON_SIZE = 20,
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 198 LORA_BEACON_CRC = 21
Mike Fiore 16:b630e18103e5 199 };
Mike Fiore 16:b630e18103e5 200
Mike Fiore 16:b630e18103e5 201 /**
Mike Fiore 16:b630e18103e5 202 * State for Link
Mike Fiore 16:b630e18103e5 203 */
Mike Fiore 16:b630e18103e5 204 enum LinkState {
Mike Fiore 16:b630e18103e5 205 LINK_IDLE = 0, //!< Link ready to send or receive
Mike Fiore 16:b630e18103e5 206 LINK_TX, //!< Link is busy sending
Mike Fiore 16:b630e18103e5 207 LINK_ACK_TX, //!< Link is busy resending after missed ACK
Mike Fiore 16:b630e18103e5 208 LINK_REP_TX, //!< Link is busy repeating
Mike Fiore 16:b630e18103e5 209 LINK_RX, //!< Link has receive window open
Mike Fiore 16:b630e18103e5 210 LINK_RX1, //!< Link has first received window open
Mike Fiore 16:b630e18103e5 211 LINK_RX2, //!< Link has second received window open
Mike Fiore 16:b630e18103e5 212 LINK_RXC, //!< Link has class C received window open
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 213 LINK_RX_BEACON, //!< Link has a beacon receive window open
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 214 LINK_RX_PING, //!< Link has a ping slot receive window open
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 215 LINK_P2P //!< Link is busy sending
Mike Fiore 16:b630e18103e5 216 };
Mike Fiore 16:b630e18103e5 217
Mike Fiore 16:b630e18103e5 218 /**
Mike Fiore 16:b630e18103e5 219 * State for MAC
Mike Fiore 16:b630e18103e5 220 */
Mike Fiore 16:b630e18103e5 221 enum MacState {
Mike Fiore 16:b630e18103e5 222 MAC_IDLE,
Mike Fiore 16:b630e18103e5 223 MAC_RX1,
Mike Fiore 16:b630e18103e5 224 MAC_RX2,
Mike Fiore 16:b630e18103e5 225 MAC_RXC,
jreiss 17:306ffaa5d79b 226 MAC_TX,
jreiss 17:306ffaa5d79b 227 MAC_JOIN
Mike Fiore 16:b630e18103e5 228 };
Mike Fiore 16:b630e18103e5 229
Mike Fiore 16:b630e18103e5 230 /**
Mike Fiore 16:b630e18103e5 231 * Operation class for device
Mike Fiore 16:b630e18103e5 232 */
Mike Fiore 16:b630e18103e5 233 enum MoteClass {
Mike Fiore 16:b630e18103e5 234 CLASS_A = 0x00, //!< Device can only receive in windows opened after a transmit
Mike Fiore 16:b630e18103e5 235 CLASS_B = 0x01, //!< Device can receive in windows sychronized with gateway beacon
Mike Fiore 16:b630e18103e5 236 CLASS_C = 0x02 //!< Device can receive any time when not transmitting
Mike Fiore 16:b630e18103e5 237 };
Mike Fiore 16:b630e18103e5 238
Mike Fiore 16:b630e18103e5 239 /**
Mike Fiore 16:b630e18103e5 240 * Direction of a packet
Mike Fiore 16:b630e18103e5 241 */
Mike Fiore 16:b630e18103e5 242 enum Direction {
Mike Fiore 16:b630e18103e5 243 DIR_UP = 0, //!< Packet is sent from mote to gateway
Mike Fiore 16:b630e18103e5 244 DIR_DOWN = 1, //!< Packet was received from gateway
Mike Fiore 16:b630e18103e5 245 DIR_PEER = 2 //!< Packet was received from peer
Mike Fiore 16:b630e18103e5 246 };
Mike Fiore 16:b630e18103e5 247
Mike Fiore 16:b630e18103e5 248
Mike Fiore 16:b630e18103e5 249 /**
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 250 * Receive window used by Link
Mike Fiore 16:b630e18103e5 251 */
Mike Fiore 16:b630e18103e5 252 enum ReceiveWindows {
Mike Fiore 16:b630e18103e5 253 RX_1 = 1, //!< First receive window
Mike Fiore 16:b630e18103e5 254 RX_2, //!< Second receive window
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 255 RX_SLOT, //!< Ping slot receive window
Mike Fiore 16:b630e18103e5 256 RX_BEACON, //!< Beacon receive window
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 257 RXC, //!< Class C continuous window
Mike Fiore 16:b630e18103e5 258 RX_TEST
Mike Fiore 16:b630e18103e5 259 };
Mike Fiore 16:b630e18103e5 260
Mike Fiore 16:b630e18103e5 261 /**
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 262 * Beacon info descriptors for the GwSpecific Info field
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 263 */
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 264 enum BeaconInfoDesc {
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 265 GPS_FIRST_ANTENNA = 0, //!< GPS coordinates of the gateway's first antenna
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 266 GPS_SECOND_ANTENNA, //!< GPS coordinates of the gateway's second antenna
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 267 GPS_THIRD_ANTENNA, //!< GPS coordinates of the gateway's third antenna
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 268 };
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 269
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 270 /**
Mike Fiore 16:b630e18103e5 271 * Datarate range for a Channel
Mike Fiore 16:b630e18103e5 272 */
Mike Fiore 16:b630e18103e5 273 typedef union {
Mike Fiore 16:b630e18103e5 274 int8_t Value;
Mike Fiore 16:b630e18103e5 275 struct {
Mike Fiore 16:b630e18103e5 276 int8_t Min :4;
Mike Fiore 16:b630e18103e5 277 int8_t Max :4;
Mike Fiore 16:b630e18103e5 278 } Fields;
Mike Fiore 16:b630e18103e5 279 } DatarateRange;
Mike Fiore 16:b630e18103e5 280
Mike Fiore 16:b630e18103e5 281 /**
Mike Fiore 16:b630e18103e5 282 * Datarate used for transmitting and receiving
Mike Fiore 16:b630e18103e5 283 */
Mike Fiore 16:b630e18103e5 284 typedef struct Datarate {
Mike Fiore 16:b630e18103e5 285 uint8_t Index;
Mike Fiore 16:b630e18103e5 286 uint8_t Bandwidth;
Mike Fiore 16:b630e18103e5 287 uint8_t Coderate;
Mike Fiore 16:b630e18103e5 288 uint8_t PreambleLength;
Mike Fiore 16:b630e18103e5 289 uint8_t SpreadingFactor;
Mike Fiore 16:b630e18103e5 290 uint8_t Crc;
Mike Fiore 16:b630e18103e5 291 uint8_t TxIQ;
Mike Fiore 16:b630e18103e5 292 uint8_t RxIQ;
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 293 uint16_t SymbolTimeout(uint16_t pad_ms = 0);
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 294 float Timeout();
Mike Fiore 16:b630e18103e5 295 Datarate();
Mike Fiore 16:b630e18103e5 296 } Datarate;
Mike Fiore 16:b630e18103e5 297
Mike Fiore 16:b630e18103e5 298 /**
Mike Fiore 16:b630e18103e5 299 * Channel used for transmitting
Mike Fiore 16:b630e18103e5 300 */
Mike Fiore 16:b630e18103e5 301 typedef struct {
Mike Fiore 16:b630e18103e5 302 uint8_t Index;
Mike Fiore 16:b630e18103e5 303 uint32_t Frequency;
Mike Fiore 16:b630e18103e5 304 DatarateRange DrRange;
Mike Fiore 16:b630e18103e5 305 } Channel;
Mike Fiore 16:b630e18103e5 306
Mike Fiore 16:b630e18103e5 307 /**
Mike Fiore 16:b630e18103e5 308 * Receive window
Mike Fiore 16:b630e18103e5 309 */
Mike Fiore 16:b630e18103e5 310 typedef struct {
Mike Fiore 16:b630e18103e5 311 uint8_t Index;
Mike Fiore 16:b630e18103e5 312 uint32_t Frequency;
Mike Fiore 16:b630e18103e5 313 uint8_t DatarateIndex;
Mike Fiore 16:b630e18103e5 314 } RxWindow;
Mike Fiore 16:b630e18103e5 315
Mike Fiore 16:b630e18103e5 316 /**
Mike Fiore 16:b630e18103e5 317 * Duty band for limiting time-on-air for regional regulations
Mike Fiore 16:b630e18103e5 318 */
Mike Fiore 16:b630e18103e5 319 typedef struct {
Mike Fiore 16:b630e18103e5 320 uint8_t Index;
Mike Fiore 16:b630e18103e5 321 uint32_t FrequencyMin;
Mike Fiore 16:b630e18103e5 322 uint32_t FrequencyMax;
Mike Fiore 16:b630e18103e5 323 uint8_t PowerMax;
Mike Fiore 16:b630e18103e5 324 uint16_t DutyCycle; //!< Multiplier of time on air, 0:100%, 1:50%, 2:33%, 10:10%, 100:1%, 1000,0.1%
Mike Fiore 16:b630e18103e5 325 uint32_t TimeOffEnd; //!< Timestamp when this band will be available
Mike Fiore 16:b630e18103e5 326 } DutyBand;
Mike Fiore 16:b630e18103e5 327
Mike Fiore 16:b630e18103e5 328 /**
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 329 * Beacon data content (w/o CRCs and RFUs)
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 330 */
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 331 typedef struct {
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 332 uint32_t Time;
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 333 uint8_t InfoDesc;
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 334 uint32_t Latitude;
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 335 uint32_t Longitude;
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 336 } BeaconData_t;
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 337
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 338 /**
Mike Fiore 16:b630e18103e5 339 * Device configuration
Mike Fiore 16:b630e18103e5 340 */
Mike Fiore 16:b630e18103e5 341 typedef struct {
Mike Fiore 16:b630e18103e5 342 uint8_t FrequencyBand; //!< Used to choose ChannelPlan
Mike Fiore 16:b630e18103e5 343 uint8_t EUI[8]; //!< Unique identifier assigned to device
Mike Fiore 16:b630e18103e5 344 } DeviceConfig;
Mike Fiore 16:b630e18103e5 345
Mike Fiore 16:b630e18103e5 346 /**
Mike Fiore 16:b630e18103e5 347 * Network configuration
Mike Fiore 16:b630e18103e5 348 */
Mike Fiore 16:b630e18103e5 349 typedef struct {
Mike Fiore 16:b630e18103e5 350 uint8_t Mode; //!< PUBLIC, PRIVATE or PEER_TO_PEER network mode
Mike Fiore 16:b630e18103e5 351 uint8_t Class; //!< Operating class of device
Mike Fiore 16:b630e18103e5 352 uint8_t EUI[8]; //!< Network ID or AppEUI
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 353 uint16_t DevNonce; //!< Incrementing DevNonce Counter
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 354 uint32_t AppNonce; //!< Incrementing AppNonce Counter
Mike Fiore 16:b630e18103e5 355 uint8_t Key[16]; //!< Network Key or AppKey
Jenkins@KEILDM1.dc.multitech.prv 70:0c5b5b02d17b 356 uint8_t GenAppKey[16]; //!< Generic App Key, will be AppKey for LW 1.1.x
Jenkins@KEILDM1.dc.multitech.prv 70:0c5b5b02d17b 357 uint8_t McKEKey[16]; //!< Multicast Key Encryption Key
Mike Fiore 16:b630e18103e5 358 uint8_t JoinDelay; //!< Number of seconds to wait before 1st RX Window
Mike Fiore 16:b630e18103e5 359 uint8_t RxDelay; //!< Number of seconds to wait before 1st RX Window
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 360 uint8_t FrequencySubBand; //!< FrequencySubBand used for US915 hybrid operation 0:72 channels, 1:1-8 channels ...
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 361 uint8_t AckEnabled; //!< Enable confirmed messages to be sent with Retries
Mike Fiore 16:b630e18103e5 362 uint8_t Retries; //!< Number of times to resend a packet without receiving an ACK, redundancy
Mike Fiore 16:b630e18103e5 363 uint8_t ADREnabled; //!< Enable adaptive datarate
Jenkins@KEILDM1.dc.multitech.prv 70:0c5b5b02d17b 364 uint8_t AdrAckLimit; //!< Number of uplinks without a downlink to allow before setting ADRACKReq
Jenkins@KEILDM1.dc.multitech.prv 70:0c5b5b02d17b 365 uint8_t AdrAckDelay; //!< Number of downlinks to expect ADR ACK Response within
Mike Fiore 16:b630e18103e5 366 uint8_t CADEnabled; //!< Enable listen before talk/channel activity detection
Mike Fiore 16:b630e18103e5 367 uint8_t RepeaterMode; //!< Limit payloads to repeater compatible sizes
Mike Fiore 16:b630e18103e5 368 uint8_t TxPower; //!< Default radio output power in dBm
Mike Fiore 16:b630e18103e5 369 uint8_t TxPowerMax; //!< Max transmit power
Mike Fiore 16:b630e18103e5 370 uint8_t TxDatarate; //!< Datarate for P2P transmit
Mike Fiore 16:b630e18103e5 371 uint32_t TxFrequency; //!< Frequency for P2P transmit
Mike Fiore 16:b630e18103e5 372 int8_t AntennaGain; //!< Antenna Gain
Mike Fiore 16:b630e18103e5 373 uint8_t DisableEncryption; //!< Disable Encryption
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 374 uint8_t DisableCRC; //!< Disable CRC on uplink packets
Mike Fiore 16:b630e18103e5 375 uint16_t P2PACKTimeout;
Mike Fiore 16:b630e18103e5 376 uint16_t P2PACKBackoff;
Mike Fiore 16:b630e18103e5 377 uint8_t JoinRx1DatarateOffset; //!< Offset for datarate for first window
Mike Fiore 16:b630e18103e5 378 uint32_t JoinRx2Frequency; //!< Frequency used in second window
Mike Fiore 16:b630e18103e5 379 uint8_t JoinRx2DatarateIndex; //!< Datarate for second window
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 380 uint8_t PingPeriodicity; //!< Number of ping slots to open in a beacon interval (2^(7-PingPeriodicity))
Mike Fiore 16:b630e18103e5 381 } NetworkConfig;
Mike Fiore 16:b630e18103e5 382
Mike Fiore 16:b630e18103e5 383 /**
Mike Fiore 16:b630e18103e5 384 * Network session info
Mike Fiore 16:b630e18103e5 385 * Some settings are acquired in join message and others may be changed through Mac Commands from server
Mike Fiore 16:b630e18103e5 386 */
Mike Fiore 16:b630e18103e5 387 typedef struct {
Mike Fiore 16:b630e18103e5 388 uint8_t Joined; //!< State of session
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 389 uint8_t Class; //!< Operating class of device
Mike Fiore 16:b630e18103e5 390 uint8_t Rx1DatarateOffset; //!< Offset for datarate for first window
Mike Fiore 16:b630e18103e5 391 uint32_t Rx2Frequency; //!< Frequency used in second window
Mike Fiore 16:b630e18103e5 392 uint8_t Rx2DatarateIndex; //!< Datarate for second window
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 393 uint32_t BeaconFrequency; //!< Frequency used for the beacon window
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 394 bool BeaconFreqHop; //!< Beacon frequency hopping enable
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 395 uint32_t PingSlotFrequency; //!< Frequency used for ping slot windows
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 396 uint8_t PingSlotDatarateIndex; //!< Datarate for the ping slots
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 397 bool PingSlotFreqHop; //!< Ping slot frequency hopping enable
Mike Fiore 16:b630e18103e5 398 uint8_t TxPower; //!< Current total radiated output power in dBm
Mike Fiore 16:b630e18103e5 399 uint8_t TxDatarate; //!< Current datarate can be changed when ADR is enabled
Mike Fiore 16:b630e18103e5 400 uint32_t Address; //!< Network address
Mike Fiore 16:b630e18103e5 401 uint32_t NetworkID; //!< Network ID 24-bits
Mike Fiore 16:b630e18103e5 402 uint8_t NetworkSessionKey[16]; //!< Network session key
Mike Fiore 16:b630e18103e5 403 uint8_t ApplicationSessionKey[16]; //!< Data session key
Mike Fiore 16:b630e18103e5 404 uint16_t ChannelMask[4]; //!< Current channel mask
Mike Fiore 16:b630e18103e5 405 uint16_t ChannelMask500k; //!< Current channel mask for 500k channels
Mike Fiore 16:b630e18103e5 406 uint32_t DownlinkCounter; //!< Downlink counter of last packet received from server
Mike Fiore 16:b630e18103e5 407 uint32_t UplinkCounter; //!< Uplink counter of last packet received from server
Mike Fiore 16:b630e18103e5 408 uint8_t Redundancy; //!< Number of time to repeat an uplink
Mike Fiore 16:b630e18103e5 409 uint8_t MaxDutyCycle; //!< Current Max Duty Cycle value
Mike Fiore 16:b630e18103e5 410 uint32_t JoinTimeOnAir; //!< Balance of time on air used during join attempts
Mike Fiore 16:b630e18103e5 411 uint32_t JoinTimeOffEnd; //!< RTC time of next join attempt
Mike Fiore 16:b630e18103e5 412 uint32_t JoinFirstAttempt; //!< RTC time of first failed join attempt
Mike Fiore 16:b630e18103e5 413 uint32_t AggregatedTimeOffEnd; //!< Time off air expiration for aggregate duty cycle
Mike Fiore 16:b630e18103e5 414 uint16_t AggregateDutyCycle; //!< Used for enforcing time-on-air
Mike Fiore 16:b630e18103e5 415 uint8_t AdrCounter; //!< Current number of packets received without downlink from server
Mike Fiore 16:b630e18103e5 416 uint8_t RxDelay; //!< Number of seconds to wait before 1st RX Window
Mike Fiore 16:b630e18103e5 417 uint8_t CommandBuffer[COMMANDS_BUFFER_SIZE]; //!< Buffer to hold Mac Commands and parameters to be sent in next packet
Mike Fiore 16:b630e18103e5 418 uint8_t CommandBufferIndex; //!< Index to place next Mac Command, also current size of Command Buffer
Mike Fiore 16:b630e18103e5 419 bool SrvRequestedAck; //!< Indicator of ACK requested by server in last packet received
Mike Fiore 16:b630e18103e5 420 bool DataPending; //!< Indicator of data pending at server
Mike Fiore 16:b630e18103e5 421 uint8_t RxTimingSetupReqReceived; //!< Indicator that RxTimingSetupAns should be included in uplink
Mike Fiore 16:b630e18103e5 422 uint8_t RxParamSetupReqAnswer; //!< Indicator that RxParamSetupAns should be included in uplink
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 423 uint8_t DlChannelReqAnswer; //!< Indicator that DlChannelAns should be included in uplink
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 424 uint8_t DownlinkDwelltime; //!< On air dwell time for downlink packets 0:NONE,1:400ms
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 425 uint8_t UplinkDwelltime; //!< On air dwell time for uplink packets 0:NONE,1:400ms
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 426 uint8_t Max_EIRP; //!< Maximum allowed EIRP for uplink
Mike Fiore 16:b630e18103e5 427 } NetworkSession;
Mike Fiore 16:b630e18103e5 428
Mike Fiore 16:b630e18103e5 429 /**
Mike Fiore 16:b630e18103e5 430 * Multicast session info
Mike Fiore 16:b630e18103e5 431 */
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 432 typedef struct MulticastSession {
Mike Fiore 16:b630e18103e5 433 uint32_t Address; //!< Network address
Mike Fiore 16:b630e18103e5 434 uint8_t NetworkSessionKey[16]; //!< Network session key
Mike Fiore 16:b630e18103e5 435 uint8_t DataSessionKey[16]; //!< Data session key
Mike Fiore 16:b630e18103e5 436 uint32_t DownlinkCounter; //!< Downlink counter of last packet received from server
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 437 int8_t Periodicity; //!< Number of downlink windows to open per beacon period
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 438 uint32_t Frequency; //!< Frequency used for downlink windows
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 439 uint8_t DatarateIndex; //!< Datarate used for downlink windows
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 440 bool DataPending; //!< Indicates network has data pending for this address
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 441 uint16_t PingPeriod;
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 442 int32_t NextPingSlot;
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 443 MulticastSession() :
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 444 Periodicity(-1)
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 445 {
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 446
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 447 }
Mike Fiore 16:b630e18103e5 448 } MulticastSession;
Mike Fiore 16:b630e18103e5 449
Mike Fiore 16:b630e18103e5 450 /**
Mike Fiore 16:b630e18103e5 451 * Statistics of current network session
Mike Fiore 16:b630e18103e5 452 */
Mike Fiore 16:b630e18103e5 453 typedef struct Statistics {
Mike Fiore 16:b630e18103e5 454 uint32_t Up; //!< Number of uplink packets sent
Mike Fiore 16:b630e18103e5 455 uint32_t Down; //!< Number of downlink packets received
Mike Fiore 16:b630e18103e5 456 uint32_t Joins; //!< Number of join requests sent
Mike Fiore 16:b630e18103e5 457 uint32_t JoinFails; //!< Number of join requests without response or invalid response
Mike Fiore 16:b630e18103e5 458 uint32_t MissedAcks; //!< Number of missed acknowledgement attempts of confirmed packets
Mike Fiore 16:b630e18103e5 459 uint32_t CRCErrors; //!< Number of CRC errors in received packets
Mike Fiore 16:b630e18103e5 460 int32_t AvgCount; //!< Number of packets used to compute rolling average of RSSI and SNR
Mike Fiore 16:b630e18103e5 461 int16_t Rssi; //!< RSSI of last packet received
Mike Fiore 16:b630e18103e5 462 int16_t RssiMin; //!< Minimum RSSI of last AvgCount packets
Mike Fiore 16:b630e18103e5 463 int16_t RssiMax; //!< Maximum RSSI of last AvgCount packets
Mike Fiore 16:b630e18103e5 464 int16_t RssiAvg; //!< Rolling average RSSI of last AvgCount packets
Mike Fiore 16:b630e18103e5 465 int16_t Snr; //!< SNR of last packet received
Mike Fiore 16:b630e18103e5 466 int16_t SnrMin; //!< Minimum SNR of last AvgCount packets
Mike Fiore 16:b630e18103e5 467 int16_t SnrMax; //!< Maximum SNR of last AvgCount packets
Mike Fiore 16:b630e18103e5 468 int16_t SnrAvg; //!< Rolling average SNR of last AvgCount packets
Mike Fiore 16:b630e18103e5 469 } Statistics;
Mike Fiore 16:b630e18103e5 470
Mike Fiore 16:b630e18103e5 471 /**
Mike Fiore 16:b630e18103e5 472 * Testing settings
Mike Fiore 16:b630e18103e5 473 */
Mike Fiore 16:b630e18103e5 474 typedef struct {
Mike Fiore 16:b630e18103e5 475 uint8_t TestMode;
Mike Fiore 16:b630e18103e5 476 uint8_t SkipMICCheck;
Mike Fiore 16:b630e18103e5 477 uint8_t DisableDutyCycle;
Mike Fiore 16:b630e18103e5 478 uint8_t DisableRx1;
Mike Fiore 16:b630e18103e5 479 uint8_t DisableRx2;
Mike Fiore 16:b630e18103e5 480 uint8_t FixedUplinkCounter;
Mike Fiore 16:b630e18103e5 481 uint8_t DisableRandomJoinDatarate;
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 482 uint8_t DisableAppNonceValidation;
Mike Fiore 16:b630e18103e5 483 } Testing;
Mike Fiore 16:b630e18103e5 484
Mike Fiore 16:b630e18103e5 485 /**
Mike Fiore 16:b630e18103e5 486 * Combination of device, network, testing settings and statistics
Mike Fiore 16:b630e18103e5 487 */
Mike Fiore 16:b630e18103e5 488 typedef struct {
Mike Fiore 16:b630e18103e5 489 DeviceConfig Device;
Mike Fiore 16:b630e18103e5 490 NetworkConfig Network;
Mike Fiore 16:b630e18103e5 491 NetworkSession Session;
Mike Fiore 16:b630e18103e5 492 MulticastSession Multicast[MAX_MULTICAST_SESSIONS];
Mike Fiore 16:b630e18103e5 493 Statistics Stats;
Mike Fiore 16:b630e18103e5 494 Testing Test;
Mike Fiore 16:b630e18103e5 495 } Settings;
Mike Fiore 16:b630e18103e5 496
Mike Fiore 16:b630e18103e5 497 /**
Mike Fiore 16:b630e18103e5 498 * Downlink settings sent in Join Accept message
Mike Fiore 16:b630e18103e5 499 */
Mike Fiore 16:b630e18103e5 500 typedef union {
Mike Fiore 16:b630e18103e5 501 uint8_t Value;
Mike Fiore 16:b630e18103e5 502 struct {
Mike Fiore 16:b630e18103e5 503 uint8_t Rx2Datarate :4;
Mike Fiore 16:b630e18103e5 504 uint8_t Rx1Offset :3;
Mike Fiore 16:b630e18103e5 505 uint8_t RFU :1;
Mike Fiore 16:b630e18103e5 506 };
Mike Fiore 16:b630e18103e5 507 } DownlinkSettings;
Mike Fiore 16:b630e18103e5 508
Mike Fiore 16:b630e18103e5 509 /**
Mike Fiore 16:b630e18103e5 510 * Frame structure for Join Request
Mike Fiore 16:b630e18103e5 511 */
Mike Fiore 16:b630e18103e5 512 typedef struct {
Mike Fiore 16:b630e18103e5 513 uint8_t Type;
Mike Fiore 16:b630e18103e5 514 uint8_t AppEUI[8];
Mike Fiore 16:b630e18103e5 515 uint8_t DevEUI[8];
Mike Fiore 16:b630e18103e5 516 uint8_t Nonce[2];
Mike Fiore 16:b630e18103e5 517 uint8_t MIC[4];
Mike Fiore 16:b630e18103e5 518 } JoinRequestFrame;
Mike Fiore 16:b630e18103e5 519
Mike Fiore 16:b630e18103e5 520 /**
Mike Fiore 16:b630e18103e5 521 * Mac header of uplink and downlink packets
Mike Fiore 16:b630e18103e5 522 */
Mike Fiore 16:b630e18103e5 523 typedef union {
Mike Fiore 16:b630e18103e5 524 uint8_t Value;
Mike Fiore 16:b630e18103e5 525 struct {
Mike Fiore 16:b630e18103e5 526 uint8_t Major :2;
Mike Fiore 16:b630e18103e5 527 uint8_t RFU :3;
Mike Fiore 16:b630e18103e5 528 uint8_t MType :3;
Mike Fiore 16:b630e18103e5 529 } Bits;
Mike Fiore 16:b630e18103e5 530 } MacHeader;
Mike Fiore 16:b630e18103e5 531
Mike Fiore 16:b630e18103e5 532 /**
Mike Fiore 16:b630e18103e5 533 * Frame control field of uplink packets
Mike Fiore 16:b630e18103e5 534 */
Mike Fiore 16:b630e18103e5 535 typedef union {
Mike Fiore 16:b630e18103e5 536 uint8_t Value;
Mike Fiore 16:b630e18103e5 537 struct {
Mike Fiore 16:b630e18103e5 538 uint8_t OptionsLength :4;
Mike Fiore 16:b630e18103e5 539 uint8_t ClassB :1;
Mike Fiore 16:b630e18103e5 540 uint8_t Ack :1;
Mike Fiore 16:b630e18103e5 541 uint8_t AdrAckReq :1;
Mike Fiore 16:b630e18103e5 542 uint8_t Adr :1;
Mike Fiore 16:b630e18103e5 543 } Bits;
Mike Fiore 16:b630e18103e5 544 } UplinkControl;
Mike Fiore 16:b630e18103e5 545
Mike Fiore 16:b630e18103e5 546 /**
Mike Fiore 16:b630e18103e5 547 * Frame control field of downlink packets
Mike Fiore 16:b630e18103e5 548 */
Mike Fiore 16:b630e18103e5 549 typedef union {
Mike Fiore 16:b630e18103e5 550 uint8_t Value;
Mike Fiore 16:b630e18103e5 551 struct {
Mike Fiore 16:b630e18103e5 552 uint8_t OptionsLength :4;
Mike Fiore 16:b630e18103e5 553 uint8_t FPending :1;
Mike Fiore 16:b630e18103e5 554 uint8_t Ack :1;
Mike Fiore 16:b630e18103e5 555 uint8_t RFU :1;
Mike Fiore 16:b630e18103e5 556 uint8_t Adr :1;
Mike Fiore 16:b630e18103e5 557 } Bits;
Mike Fiore 16:b630e18103e5 558 } DownlinkControl;
Mike Fiore 16:b630e18103e5 559
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 560 typedef struct PingSlot {
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 561 uint32_t MSec;
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 562 int8_t Id;
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 563 PingSlot() : MSec(0), Id(-1) {}
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 564 PingSlot(uint32_t msec, int8_t id) : MSec(msec), Id(id) {}
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 565 } PingSlot;
Jenkins@KEILDM1.dc.multitech.prv 72:b1e07ec1c30d 566
Mike Fiore 16:b630e18103e5 567 /**
Mike Fiore 16:b630e18103e5 568 * Frame type of packet
Mike Fiore 16:b630e18103e5 569 */
Mike Fiore 16:b630e18103e5 570 typedef enum {
Mike Fiore 16:b630e18103e5 571 FRAME_TYPE_JOIN_REQ = 0x00,
Mike Fiore 16:b630e18103e5 572 FRAME_TYPE_JOIN_ACCEPT = 0x01,
Mike Fiore 16:b630e18103e5 573 FRAME_TYPE_DATA_UNCONFIRMED_UP = 0x02,
Mike Fiore 16:b630e18103e5 574 FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03,
Mike Fiore 16:b630e18103e5 575 FRAME_TYPE_DATA_CONFIRMED_UP = 0x04,
Mike Fiore 16:b630e18103e5 576 FRAME_TYPE_DATA_CONFIRMED_DOWN = 0x05,
Mike Fiore 16:b630e18103e5 577 FRAME_TYPE_RFU = 0x06,
Mike Fiore 16:b630e18103e5 578 FRAME_TYPE_PROPRIETARY = 0x07,
Mike Fiore 16:b630e18103e5 579 } FrameType;
Mike Fiore 16:b630e18103e5 580
Mike Fiore 16:b630e18103e5 581 /**
Mike Fiore 16:b630e18103e5 582 * LoRaWAN mote MAC commands
Mike Fiore 16:b630e18103e5 583 */
Mike Fiore 16:b630e18103e5 584 typedef enum {
Mike Fiore 16:b630e18103e5 585 /* Class A */
Mike Fiore 16:b630e18103e5 586 MOTE_MAC_LINK_CHECK_REQ = 0x02,
Mike Fiore 16:b630e18103e5 587 MOTE_MAC_LINK_ADR_ANS = 0x03,
Mike Fiore 16:b630e18103e5 588 MOTE_MAC_DUTY_CYCLE_ANS = 0x04,
Mike Fiore 16:b630e18103e5 589 MOTE_MAC_RX_PARAM_SETUP_ANS = 0x05,
Mike Fiore 16:b630e18103e5 590 MOTE_MAC_DEV_STATUS_ANS = 0x06,
Mike Fiore 16:b630e18103e5 591 MOTE_MAC_NEW_CHANNEL_ANS = 0x07,
Mike Fiore 16:b630e18103e5 592 MOTE_MAC_RX_TIMING_SETUP_ANS = 0x08,
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 593 MOTE_MAC_TX_PARAM_SETUP_ANS = 0x09,
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 594 MOTE_MAC_DL_CHANNEL_ANS = 0x0A,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 595 MOTE_MAC_REKEY_IND = 0x0B,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 596 MOTE_MAC_ADR_PARAM_SETUP_ANS = 0x0C,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 597 MOTE_MAC_DEVICE_TIME_REQ = 0x0D,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 598 MOTE_MAC_REJOIN_PARAM_SETUP_ANS = 0x0F,
Mike Fiore 16:b630e18103e5 599
Mike Fiore 16:b630e18103e5 600 /* Class B */
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 601 MOTE_MAC_PING_SLOT_INFO_REQ = 0x10,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 602 MOTE_MAC_PING_SLOT_CHANNEL_ANS = 0x11,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 603 MOTE_MAC_BEACON_TIMING_REQ = 0x12,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 604 MOTE_MAC_BEACON_FREQ_ANS = 0x13,
Mike Fiore 16:b630e18103e5 605
Mike Fiore 16:b630e18103e5 606 /* Multitech */
Mike Fiore 16:b630e18103e5 607 MOTE_MAC_PING_REQ = 0x80,
Mike Fiore 16:b630e18103e5 608 MOTE_MAC_CHANGE_CLASS = 0x81,
Mike Fiore 16:b630e18103e5 609 MOTE_MAC_MULTIPART_START_REQ = 0x82,
Mike Fiore 16:b630e18103e5 610 MOTE_MAC_MULTIPART_START_ANS = 0x83,
Mike Fiore 16:b630e18103e5 611 MOTE_MAC_MULTIPART_CHUNK = 0x84,
Mike Fiore 16:b630e18103e5 612 MOTE_MAC_MULTIPART_END_REQ = 0x85,
Mike Fiore 16:b630e18103e5 613 MOTE_MAC_MULTIPART_END_ANS = 0x86
Mike Fiore 16:b630e18103e5 614 } MoteCommand;
Mike Fiore 16:b630e18103e5 615
Mike Fiore 16:b630e18103e5 616 /*!
Mike Fiore 16:b630e18103e5 617 * LoRaWAN server MAC commands
Mike Fiore 16:b630e18103e5 618 */
Mike Fiore 16:b630e18103e5 619 typedef enum {
Mike Fiore 16:b630e18103e5 620 /* Class A */
Mike Fiore 16:b630e18103e5 621 SRV_MAC_LINK_CHECK_ANS = 0x02,
Mike Fiore 16:b630e18103e5 622 SRV_MAC_LINK_ADR_REQ = 0x03,
Mike Fiore 16:b630e18103e5 623 SRV_MAC_DUTY_CYCLE_REQ = 0x04,
Mike Fiore 16:b630e18103e5 624 SRV_MAC_RX_PARAM_SETUP_REQ = 0x05,
Mike Fiore 16:b630e18103e5 625 SRV_MAC_DEV_STATUS_REQ = 0x06,
Mike Fiore 16:b630e18103e5 626 SRV_MAC_NEW_CHANNEL_REQ = 0x07,
Mike Fiore 16:b630e18103e5 627 SRV_MAC_RX_TIMING_SETUP_REQ = 0x08,
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 628 SRV_MAC_TX_PARAM_SETUP_REQ = 0x09,
Jenkins@KEILDM1.dc.multitech.prv 60:7985b4783af9 629 SRV_MAC_DL_CHANNEL_REQ = 0x0A,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 630 SRV_MAC_REKEY_CONF = 0x0B,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 631 SRV_MAC_ADR_PARAM_SETUP_REQ = 0x0C,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 632 SRV_MAC_DEVICE_TIME_ANS = 0x0D,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 633 SRV_MAC_FORCE_REJOIN_REQ = 0x0E,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 634 SRV_MAC_REJOIN_PARAM_SETUP_REQ = 0x0F,
Mike Fiore 16:b630e18103e5 635
Mike Fiore 16:b630e18103e5 636 /* Class B */
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 637 SRV_MAC_PING_SLOT_INFO_ANS = 0x10,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 638 SRV_MAC_PING_SLOT_CHANNEL_REQ = 0x11,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 639 SRV_MAC_BEACON_TIMING_ANS = 0x12,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 640 SRV_MAC_BEACON_FREQ_REQ = 0x13,
Mike Fiore 16:b630e18103e5 641
Mike Fiore 16:b630e18103e5 642 /* Multitech */
Mike Fiore 16:b630e18103e5 643 SRV_MAC_PING_ANS = 0x80,
Mike Fiore 16:b630e18103e5 644 SRV_MAC_CHANGE_CLASS = 0x81,
Mike Fiore 16:b630e18103e5 645 SRV_MAC_MULTIPART_START_REQ = 0x82,
Mike Fiore 16:b630e18103e5 646 SRV_MAC_MULTIPART_START_ANS = 0x83,
Mike Fiore 16:b630e18103e5 647 SRV_MAC_MULTIPART_CHUNK = 0x84,
Mike Fiore 16:b630e18103e5 648 SRV_MAC_MULTIPART_END_REQ = 0x85,
Mike Fiore 16:b630e18103e5 649 SRV_MAC_MULTIPART_END_ANS = 0x86
Mike Fiore 16:b630e18103e5 650 } ServerCommand;
Mike Fiore 16:b630e18103e5 651
Mike Fiore 16:b630e18103e5 652 /**
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 653 * Radio configuration options
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 654 */
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 655 typedef enum RadioCfg {
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 656 NO_RADIO_CFG,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 657 TX_RADIO_CFG,
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 658 RX_RADIO_CFG
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 659 } RadioCfg_t;
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 660
Jenkins@KEILDM1.dc.multitech.prv 65:acc0468b9aec 661 /**
Mike Fiore 16:b630e18103e5 662 * Random seed for software RNG
Mike Fiore 16:b630e18103e5 663 */
Mike Fiore 16:b630e18103e5 664 void srand(uint32_t seed);
Mike Fiore 16:b630e18103e5 665
Mike Fiore 16:b630e18103e5 666 /**
Mike Fiore 16:b630e18103e5 667 * Software RNG for consistent results across differing hardware
Mike Fiore 16:b630e18103e5 668 */
Mike Fiore 16:b630e18103e5 669 int rand(void);
Mike Fiore 16:b630e18103e5 670
Mike Fiore 16:b630e18103e5 671 /**
Mike Fiore 16:b630e18103e5 672 * Generate random number bounded by min and max
Mike Fiore 16:b630e18103e5 673 */
Mike Fiore 16:b630e18103e5 674 int32_t rand_r(int32_t min, int32_t max);
Mike Fiore 16:b630e18103e5 675
Mike Fiore 16:b630e18103e5 676 uint8_t CountBits(uint16_t mask);
Mike Fiore 16:b630e18103e5 677
Mike Fiore 16:b630e18103e5 678 /**
Mike Fiore 16:b630e18103e5 679 * Copy 3-bytes network order from array into LSB of integer value
Mike Fiore 16:b630e18103e5 680 */
Mike Fiore 16:b630e18103e5 681 void CopyNetIDtoInt(const uint8_t* arr, uint32_t& val);
Mike Fiore 16:b630e18103e5 682
Mike Fiore 16:b630e18103e5 683 /**
Mike Fiore 16:b630e18103e5 684 * Copy LSB 3-bytes from integer value into array network order
Mike Fiore 16:b630e18103e5 685 */
Mike Fiore 16:b630e18103e5 686 void CopyNetIDtoArray(uint32_t val, uint8_t* arr);
Mike Fiore 16:b630e18103e5 687
Mike Fiore 16:b630e18103e5 688 /**
Mike Fiore 16:b630e18103e5 689 * Copy 4-bytes network order from array in to integer value
Mike Fiore 16:b630e18103e5 690 */
Mike Fiore 16:b630e18103e5 691 void CopyAddrtoInt(const uint8_t* arr, uint32_t& val);
Mike Fiore 16:b630e18103e5 692
Mike Fiore 16:b630e18103e5 693 /**
Mike Fiore 16:b630e18103e5 694 * Copy 4-bytes from integer in to array network order
Mike Fiore 16:b630e18103e5 695 */
Mike Fiore 16:b630e18103e5 696 void CopyAddrtoArray(uint32_t val, uint8_t* arr);
Mike Fiore 16:b630e18103e5 697
Mike Fiore 16:b630e18103e5 698 /**
Mike Fiore 16:b630e18103e5 699 * Copy 3-bytes network order from array into integer value and multiply by 100
Mike Fiore 16:b630e18103e5 700 */
Mike Fiore 16:b630e18103e5 701 void CopyFreqtoInt(const uint8_t* arr, uint32_t& freq);
Mike Fiore 16:b630e18103e5 702
Mike Fiore 16:b630e18103e5 703 /**
Mike Fiore 16:b630e18103e5 704 * Reverse memory copy
Mike Fiore 16:b630e18103e5 705 */
Mike Fiore 16:b630e18103e5 706 void memcpy_r(uint8_t *dst, const uint8_t *src, size_t n);
Mike Fiore 16:b630e18103e5 707
Mike Fiore 16:b630e18103e5 708 }
Mike Fiore 16:b630e18103e5 709
Mike Fiore 16:b630e18103e5 710 #endif
Mike Fiore 16:b630e18103e5 711