LoRaMAC
4.4.5
Documentation of the API
|
LoRa MAC layer cryptographic functionality implementation. More...
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "utilities.h"
#include "LoRaMacTypes.h"
#include "LoRaMacMessageTypes.h"
Go to the source code of this file.
LoRa MAC layer cryptographic functionality implementation.
addtogroup LORAMAC
#define USE_LRWAN_1_1_X_CRYPTO 0 |
Indicates if LoRaWAN 1.1.x crypto scheme is enabled
#define USE_RANDOM_DEV_NONCE 1 |
Indicates if a random devnonce must be used or not
#define USE_JOIN_NONCE_COUNTER_CHECK 0 |
Indicates if JoinNonce is counter based and requires to be checked
#define FCNT_DOWN_INITAL_VALUE 0xFFFFFFFF |
Initial value of the frame counters
typedef void( * LoRaMacCryptoNvmEvent) (void) |
Signature of callback function to be called by the LoRaMac Crypto module when the non-volatile context have to be stored. It is also possible to save the entire crypto module context.
LoRaMac Cryto Status
LoRaMacCryptoStatus_t LoRaMacCryptoInit | ( | LoRaMacCryptoNvmEvent | cryptoNvmCtxChanged | ) |
Initialization of LoRaMac Crypto module It sets initial values of volatile variables and assigns the non-volatile context.
[IN] | cryptoNvmCtxChanged - Callback function which will be called when the non-volatile context have to be stored. |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoSetLrWanVersion | ( | Version_t | version | ) |
Sets the LoRaWAN specification version to be used.
[IN] | version - LoRaWAN specification version to be used. |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoRestoreNvmCtx | ( | void * | cryptoNvmCtx | ) |
Restores the internal nvm context from passed pointer.
[IN] | cryptoNmvCtx - Pointer to non-volatile crypto module context to be restored. |
- | Status of the operation |
void* LoRaMacCryptoGetNvmCtx | ( | size_t * | cryptoNvmCtxSize | ) |
Returns a pointer to the internal non-volatile context.
[IN] | cryptoNvmCtxSize - Size of the module non-volatile context |
- | Points to a structure where the module store its non-volatile context |
LoRaMacCryptoStatus_t LoRaMacCryptoGetFCntDown | ( | FCntIdentifier_t | fCntID, |
uint16_t | maxFCntGap, | ||
uint32_t | frameFcnt, | ||
uint32_t * | currentDown | ||
) |
Returns updated fCntID downlink counter value.
[IN] | fCntID - Frame counter identifier |
[IN] | maxFcntGap - Maximum allowed frame counter difference (only necessary for L2 LW1.0.x) |
[IN] | frameFcnt - Received frame counter (used to update current counter value) |
[OUT] | currentDown - Current downlink counter value |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoGetFCntUp | ( | uint32_t * | currentUp | ) |
Returns updated fCntUp uplink counter value.
[IN] | currentUp - Uplink counter value |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoSetMulticastReference | ( | MulticastCtx_t * | multicastList | ) |
Provides multicast context.
[IN] | multicastList - Pointer to the multicast context list |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoSetKey | ( | KeyIdentifier_t | keyID, |
uint8_t * | key | ||
) |
Sets a key
[IN] | keyID - Key identifier |
[IN] | key - Key value (16 byte), if its a multicast key it must be encrypted with McKEKey |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoPrepareJoinRequest | ( | LoRaMacMessageJoinRequest_t * | macMsg | ) |
Prepares the join-request message. It computes the mic and add it to the message.
[IN/OUT] | macMsg - Join-request message object |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoPrepareReJoinType1 | ( | LoRaMacMessageReJoinType1_t * | macMsg | ) |
Prepares a rejoin-request type 1 message. It computes the mic and add it to the message.
[IN/OUT] | macMsg - Rejoin message object |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoPrepareReJoinType0or2 | ( | LoRaMacMessageReJoinType0or2_t * | macMsg | ) |
Prepares a rejoin-request type 0 or 2 message. It computes the mic and add it to the message.
[IN/OUT] | macMsg - Rejoin message object |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoHandleJoinAccept | ( | JoinReqIdentifier_t | joinReqType, |
uint8_t * | joinEUI, | ||
LoRaMacMessageJoinAccept_t * | macMsg | ||
) |
Handles the join-accept message. It decrypts the message, verifies the MIC and if successful derives the session keys.
[IN] | joinReqType - Type of last join-request or rejoin which triggered the join-accept response |
[IN] | joinEUI - Join server EUI (8 byte) |
[IN/OUT] | macMsg - Join-accept message object |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoSecureMessage | ( | uint32_t | fCntUp, |
uint8_t | txDr, | ||
uint8_t | txCh, | ||
LoRaMacMessageData_t * | macMsg | ||
) |
Secures a message (encryption + integrity).
[IN] | fCntUp - Uplink sequence counter |
[IN] | txDr - Data rate used for the transmission |
[IN] | txCh - Index of the channel used for the transmission |
[IN/OUT] | macMsg - Data message object |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoUnsecureMessage | ( | AddressIdentifier_t | addrID, |
uint32_t | address, | ||
FCntIdentifier_t | fCntID, | ||
uint32_t | fCntDown, | ||
LoRaMacMessageData_t * | macMsg | ||
) |
Unsecures a message (decryption + integrity verification).
[IN] | addrID - Address identifier |
[IN] | address - Address |
[IN] | fCntID - Frame counter identifier |
[IN] | fCntDown - Downlink sequence counter |
[IN/OUT] | macMsg - Data message object |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoDeriveMcRootKey | ( | uint8_t | versionMinor, |
KeyIdentifier_t | keyID | ||
) |
Derives the McRootKey from the AppKey.
1.0.x McRootKey = aes128_encrypt(AppKey, 0x00 | pad16)
1.1.x McRootKey = aes128_encrypt(AppKey, 0x20 | pad16)
[IN] | versionMinor - LoRaWAN specification minor version to be used. |
[IN] | keyID - Key identifier of the root key to use to perform the derivation ( AppKey ) |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoDeriveMcKEKey | ( | KeyIdentifier_t | keyID | ) |
Derives the McKEKey from the McRootKey.
McKEKey = aes128_encrypt(McRootKey , 0x00 | pad16)
[IN] | keyID - Key identifier of the root key to use to perform the derivation ( McRootKey ) |
- | Status of the operation |
LoRaMacCryptoStatus_t LoRaMacCryptoDeriveMcSessionKeyPair | ( | AddressIdentifier_t | addrID, |
uint32_t | mcAddr | ||
) |
Derives a Multicast group key pair ( McAppSKey, McNwkSKey ) from McKey
McAppSKey = aes128_encrypt(McKey, 0x01 | McAddr | pad16) McNwkSKey = aes128_encrypt(McKey, 0x02 | McAddr | pad16)
[IN] | addrID - Address identifier to select the multicast group |
[IN] | mcAddr - Multicast group address (4 bytes) |
- | Status of the operation |