Skip to content

Commit 71740b8

Browse files
Daniel Jaecklemluis1
authored andcommitted
Store DevEUI and JoinEUI in the secure element.
1 parent ef9f88c commit 71740b8

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

src/mac/LoRaMac.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,6 @@ typedef struct sLoRaMacNvmCtx
201201

202202
typedef struct sLoRaMacCtx
203203
{
204-
/*
205-
* Device IEEE EUI
206-
*/
207-
uint8_t* DevEui;
208-
/*
209-
* Join IEEE EUI
210-
*/
211-
uint8_t* JoinEui;
212204
/*
213205
* Length of packet in PktBuffer
214206
*/
@@ -1012,7 +1004,7 @@ static void ProcessRadioRxDone( void )
10121004
PrepareRxDoneAbort( );
10131005
return;
10141006
}
1015-
macCryptoStatus = LoRaMacCryptoHandleJoinAccept( JOIN_REQ, MacCtx.JoinEui, &macMsgJoinAccept );
1007+
macCryptoStatus = LoRaMacCryptoHandleJoinAccept( JOIN_REQ, SecureElementGetJoinEui( ), &macMsgJoinAccept );
10161008

10171009
if( LORAMAC_CRYPTO_SUCCESS == macCryptoStatus )
10181010
{
@@ -2350,8 +2342,8 @@ LoRaMacStatus_t SendReJoinReq( JoinReqIdentifier_t joinReqType )
23502342
macHdr.Bits.MType = FRAME_TYPE_JOIN_REQ;
23512343
MacCtx.TxMsg.Message.JoinReq.MHDR.Value = macHdr.Value;
23522344

2353-
memcpy1( MacCtx.TxMsg.Message.JoinReq.JoinEUI, MacCtx.JoinEui, LORAMAC_JOIN_EUI_FIELD_SIZE );
2354-
memcpy1( MacCtx.TxMsg.Message.JoinReq.DevEUI, MacCtx.DevEui, LORAMAC_DEV_EUI_FIELD_SIZE );
2345+
memcpy1( MacCtx.TxMsg.Message.JoinReq.JoinEUI, SecureElementGetJoinEui( ), LORAMAC_JOIN_EUI_FIELD_SIZE );
2346+
memcpy1( MacCtx.TxMsg.Message.JoinReq.DevEUI, SecureElementGetDevEui( ), LORAMAC_DEV_EUI_FIELD_SIZE );
23552347

23562348
allowDelayedTx = false;
23572349

@@ -4455,8 +4447,8 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest )
44554447

44564448
ResetMacParameters( );
44574449

4458-
MacCtx.DevEui = mlmeRequest->Req.Join.DevEui;
4459-
MacCtx.JoinEui = mlmeRequest->Req.Join.JoinEui;
4450+
SecureElementSetDevEui( mlmeRequest->Req.Join.DevEui );
4451+
SecureElementSetJoinEui( mlmeRequest->Req.Join.JoinEui );
44604452

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

src/mac/secure-element.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include <stdint.h>
3838
#include "LoRaMacCrypto.h"
3939

40+
#define SE_EUI_SIZE 16
41+
4042
/*!
4143
* Return values.
4244
*/
@@ -166,4 +168,34 @@ SecureElementStatus_t SecureElementDeriveAndStoreKey( Version_t version, uint8_t
166168
*/
167169
SecureElementStatus_t SecureElementRandomNumber( uint32_t* randomNum );
168170

171+
/*!
172+
* Sets the DevEUI
173+
*
174+
* \param[IN] devEui - Pointer to the 16-byte devEUI
175+
* \retval - Status of the operation
176+
*/
177+
SecureElementStatus_t SecureElementSetDevEui( uint8_t* devEui );
178+
179+
/*!
180+
* Gets the DevEUI
181+
*
182+
* \retval - Pointer to the 16-byte devEUI
183+
*/
184+
uint8_t* SecureElementGetDevEui( void );
185+
186+
/*!
187+
* Sets the JoinEUI
188+
*
189+
* \param[IN] joinEui - Pointer to the 16-byte joinEui
190+
* \retval - Status of the operation
191+
*/
192+
SecureElementStatus_t SecureElementSetJoinEui( uint8_t* joinEui );
193+
194+
/*!
195+
* Gets the DevEUI
196+
*
197+
* \retval - Pointer to the 16-byte joinEui
198+
*/
199+
uint8_t* SecureElementGetJoinEui( void );
200+
169201
#endif // __SECURE_ELEMENT_H__

src/peripherals/soft-se/soft-se.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ typedef struct sKey
5252
*/
5353
typedef struct sSecureElementNvCtx
5454
{
55+
/*
56+
* DevEUI storage
57+
*/
58+
uint8_t DevEui[SE_EUI_SIZE];
59+
/*
60+
* Join EUI storage
61+
*/
62+
uint8_t JoinEui[SE_EUI_SIZE];
5563
/*
5664
* AES computation context variable
5765
*/
@@ -191,6 +199,9 @@ SecureElementStatus_t SecureElementInit( SecureElementNvmEvent seNvmCtxChanged )
191199
// Set standard keys
192200
memcpy1( SeNvmCtx.KeyList[itr].KeyValue, zeroKey, KEY_SIZE );
193201

202+
memset1( SeNvmCtx.DevEui, 0, SE_EUI_SIZE );
203+
memset1( SeNvmCtx.JoinEui, 0, SE_EUI_SIZE );
204+
194205
// Assign callback
195206
if( seNvmCtxChanged != 0 )
196207
{
@@ -372,3 +383,35 @@ SecureElementStatus_t SecureElementRandomNumber( uint32_t* randomNum )
372383
*randomNum = Radio.Random( );
373384
return SECURE_ELEMENT_SUCCESS;
374385
}
386+
387+
SecureElementStatus_t SecureElementSetDevEui( uint8_t* devEui )
388+
{
389+
if( devEui == NULL )
390+
{
391+
return SECURE_ELEMENT_ERROR_NPE;
392+
}
393+
memcpy1( SeNvmCtx.DevEui, devEui, SE_EUI_SIZE );
394+
SeNvmCtxChanged( );
395+
return SECURE_ELEMENT_SUCCESS;
396+
}
397+
398+
uint8_t* SecureElementGetDevEui( void )
399+
{
400+
return SeNvmCtx.DevEui;
401+
}
402+
403+
SecureElementStatus_t SecureElementSetJoinEui( uint8_t* joinEui )
404+
{
405+
if( joinEui == NULL )
406+
{
407+
return SECURE_ELEMENT_ERROR_NPE;
408+
}
409+
memcpy1( SeNvmCtx.JoinEui, joinEui, SE_EUI_SIZE );
410+
SeNvmCtxChanged( );
411+
return SECURE_ELEMENT_SUCCESS;
412+
}
413+
414+
uint8_t* SecureElementGetJoinEui( void )
415+
{
416+
return SeNvmCtx.JoinEui;
417+
}

0 commit comments

Comments
 (0)