Skip to content

Commit

Permalink
Store DevEUI and JoinEUI in the secure element.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Jaeckle authored and mluis1 committed Jul 8, 2019
1 parent ef9f88c commit 71740b8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/mac/LoRaMac.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,6 @@ typedef struct sLoRaMacNvmCtx

typedef struct sLoRaMacCtx
{
/*
* Device IEEE EUI
*/
uint8_t* DevEui;
/*
* Join IEEE EUI
*/
uint8_t* JoinEui;
/*
* Length of packet in PktBuffer
*/
Expand Down Expand Up @@ -1012,7 +1004,7 @@ static void ProcessRadioRxDone( void )
PrepareRxDoneAbort( );
return;
}
macCryptoStatus = LoRaMacCryptoHandleJoinAccept( JOIN_REQ, MacCtx.JoinEui, &macMsgJoinAccept );
macCryptoStatus = LoRaMacCryptoHandleJoinAccept( JOIN_REQ, SecureElementGetJoinEui( ), &macMsgJoinAccept );

if( LORAMAC_CRYPTO_SUCCESS == macCryptoStatus )
{
Expand Down Expand Up @@ -2350,8 +2342,8 @@ LoRaMacStatus_t SendReJoinReq( JoinReqIdentifier_t joinReqType )
macHdr.Bits.MType = FRAME_TYPE_JOIN_REQ;
MacCtx.TxMsg.Message.JoinReq.MHDR.Value = macHdr.Value;

memcpy1( MacCtx.TxMsg.Message.JoinReq.JoinEUI, MacCtx.JoinEui, LORAMAC_JOIN_EUI_FIELD_SIZE );
memcpy1( MacCtx.TxMsg.Message.JoinReq.DevEUI, MacCtx.DevEui, LORAMAC_DEV_EUI_FIELD_SIZE );
memcpy1( MacCtx.TxMsg.Message.JoinReq.JoinEUI, SecureElementGetJoinEui( ), LORAMAC_JOIN_EUI_FIELD_SIZE );
memcpy1( MacCtx.TxMsg.Message.JoinReq.DevEUI, SecureElementGetDevEui( ), LORAMAC_DEV_EUI_FIELD_SIZE );

allowDelayedTx = false;

Expand Down Expand Up @@ -4455,8 +4447,8 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest )

ResetMacParameters( );

MacCtx.DevEui = mlmeRequest->Req.Join.DevEui;
MacCtx.JoinEui = mlmeRequest->Req.Join.JoinEui;
SecureElementSetDevEui( mlmeRequest->Req.Join.DevEui );
SecureElementSetJoinEui( mlmeRequest->Req.Join.JoinEui );

MacCtx.NvmCtx->MacParams.ChannelsDatarate = RegionAlternateDr( MacCtx.NvmCtx->Region, mlmeRequest->Req.Join.Datarate, ALTERNATE_DR );

Expand Down
32 changes: 32 additions & 0 deletions src/mac/secure-element.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <stdint.h>
#include "LoRaMacCrypto.h"

#define SE_EUI_SIZE 16

/*!
* Return values.
*/
Expand Down Expand Up @@ -166,4 +168,34 @@ SecureElementStatus_t SecureElementDeriveAndStoreKey( Version_t version, uint8_t
*/
SecureElementStatus_t SecureElementRandomNumber( uint32_t* randomNum );

/*!
* Sets the DevEUI
*
* \param[IN] devEui - Pointer to the 16-byte devEUI
* \retval - Status of the operation
*/
SecureElementStatus_t SecureElementSetDevEui( uint8_t* devEui );

/*!
* Gets the DevEUI
*
* \retval - Pointer to the 16-byte devEUI
*/
uint8_t* SecureElementGetDevEui( void );

/*!
* Sets the JoinEUI
*
* \param[IN] joinEui - Pointer to the 16-byte joinEui
* \retval - Status of the operation
*/
SecureElementStatus_t SecureElementSetJoinEui( uint8_t* joinEui );

/*!
* Gets the DevEUI
*
* \retval - Pointer to the 16-byte joinEui
*/
uint8_t* SecureElementGetJoinEui( void );

#endif // __SECURE_ELEMENT_H__
43 changes: 43 additions & 0 deletions src/peripherals/soft-se/soft-se.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ typedef struct sKey
*/
typedef struct sSecureElementNvCtx
{
/*
* DevEUI storage
*/
uint8_t DevEui[SE_EUI_SIZE];
/*
* Join EUI storage
*/
uint8_t JoinEui[SE_EUI_SIZE];
/*
* AES computation context variable
*/
Expand Down Expand Up @@ -191,6 +199,9 @@ SecureElementStatus_t SecureElementInit( SecureElementNvmEvent seNvmCtxChanged )
// Set standard keys
memcpy1( SeNvmCtx.KeyList[itr].KeyValue, zeroKey, KEY_SIZE );

memset1( SeNvmCtx.DevEui, 0, SE_EUI_SIZE );
memset1( SeNvmCtx.JoinEui, 0, SE_EUI_SIZE );

// Assign callback
if( seNvmCtxChanged != 0 )
{
Expand Down Expand Up @@ -372,3 +383,35 @@ SecureElementStatus_t SecureElementRandomNumber( uint32_t* randomNum )
*randomNum = Radio.Random( );
return SECURE_ELEMENT_SUCCESS;
}

SecureElementStatus_t SecureElementSetDevEui( uint8_t* devEui )
{
if( devEui == NULL )
{
return SECURE_ELEMENT_ERROR_NPE;
}
memcpy1( SeNvmCtx.DevEui, devEui, SE_EUI_SIZE );
SeNvmCtxChanged( );
return SECURE_ELEMENT_SUCCESS;
}

uint8_t* SecureElementGetDevEui( void )
{
return SeNvmCtx.DevEui;
}

SecureElementStatus_t SecureElementSetJoinEui( uint8_t* joinEui )
{
if( joinEui == NULL )
{
return SECURE_ELEMENT_ERROR_NPE;
}
memcpy1( SeNvmCtx.JoinEui, joinEui, SE_EUI_SIZE );
SeNvmCtxChanged( );
return SECURE_ELEMENT_SUCCESS;
}

uint8_t* SecureElementGetJoinEui( void )
{
return SeNvmCtx.JoinEui;
}

0 comments on commit 71740b8

Please sign in to comment.