1 /*! 2 * \file LoRaMacCryptoNvm.h 3 * 4 * \brief LoRa MAC layer cryptographic NVM data. 5 * 6 * \copyright Revised BSD License, see section \ref LICENSE. 7 * 8 * \code 9 * ______ _ 10 * / _____) _ | | 11 * ( (____ _____ ____ _| |_ _____ ____| |__ 12 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 13 * _____) ) ____| | | || |_| ____( (___| | | | 14 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 15 * (C)2013-2017 Semtech 16 * 17 * ___ _____ _ ___ _ _____ ___ ___ ___ ___ 18 * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| 19 * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| 20 * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| 21 * embedded.connectivity.solutions=============== 22 * 23 * \endcode 24 * 25 * \author Miguel Luis ( Semtech ) 26 * 27 * \author Daniel Jaeckle ( STACKFORCE ) 28 * 29 * addtogroup LORAMAC 30 * \{ 31 * 32 */ 33 #ifndef __LORAMAC_CRYPTO_NVM_H__ 34 #define __LORAMAC_CRYPTO_NVM_H__ 35 36 #ifdef __cplusplus 37 extern "C" 38 { 39 #endif 40 41 #include <stdint.h> 42 #include "utilities.h" 43 #include "LoRaMacTypes.h" 44 45 46 /*! 47 * LoRaWAN Frame counter list. 48 */ 49 typedef struct sFCntList 50 { 51 /*! 52 * Uplink frame counter which is incremented with each uplink. 53 */ 54 uint32_t FCntUp; 55 /*! 56 * Network downlink frame counter which is incremented with each downlink on FPort 0 57 * or when the FPort field is missing. 58 */ 59 uint32_t NFCntDown; 60 /*! 61 * Application downlink frame counter which is incremented with each downlink 62 * on a port different than 0. 63 */ 64 uint32_t AFCntDown; 65 /*! 66 * In case if the device is connected to a LoRaWAN 1.0 Server, 67 * this counter is used for every kind of downlink frame. 68 */ 69 uint32_t FCntDown; 70 /*! 71 * Multicast downlink counters 72 */ 73 uint32_t McFCntDown[LORAMAC_MAX_MC_CTX]; 74 #if( USE_LRWAN_1_1_X_CRYPTO == 1 ) 75 /*! 76 * RJcount1 is a counter incremented with every Rejoin request Type 1 frame transmitted. 77 */ 78 uint16_t RJcount1; 79 #endif 80 }FCntList_t; 81 82 /*! 83 * LoRaMac Crypto Non Volatile Context structure 84 */ 85 typedef struct sLoRaMacCryptoNvmData 86 { 87 /*! 88 * Stores the information if the device is connected to a LoRaWAN network 89 * server with prior to 1.1.0 implementation. 90 */ 91 Version_t LrWanVersion; 92 /*! 93 * Device nonce is a counter starting at 0 when the device is initially 94 * powered up and incremented with every JoinRequest. 95 */ 96 uint16_t DevNonce; 97 /*! 98 * JoinNonce is a device specific counter value (that never repeats itself) 99 * provided by the join server and incremented with every JoinAccept message. 100 */ 101 uint32_t JoinNonce; 102 /*! 103 * Frame counter list 104 */ 105 FCntList_t FCntList; 106 /*! 107 * LastDownFCnt stores the information which frame counter was used to 108 * decrypt the last frame. This information is needed to compute ConfFCnt in 109 * B1 block for the MIC. 110 */ 111 uint32_t LastDownFCnt; 112 /*! 113 * CRC32 value of the Crypto data structure. 114 */ 115 uint32_t Crc32; 116 }LoRaMacCryptoNvmData_t; 117 118 /*! \} addtogroup LORAMAC */ 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 #endif // __LORAMAC_CRYPTO_NVM_H__ 125