Skip to content

Commit

Permalink
Added esp_fill_random to DevNonce (ESP32) - TODO: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
REGIOIGER committed Jan 12, 2024
1 parent e53d8ed commit a2bde65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/arduino-rfm/LoRaMAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,15 @@ void LORA_Receive_Data(sBuffer *Data_Rx, sLoRa_Session *Session_Data, sLoRa_OTAA
*/
static void Generate_DevNonce(unsigned char *DevNonce)
{
#ifdef ESP32
// Use the built-in random number generator of ESP32 to obtain a random value
esp_fill_random(DevNonce, 2); // Fill the first 2 bytes of DevNonce with random values
#else
unsigned int RandNumber;

RandNumber = random(0xFFFF);

DevNonce[0] = RandNumber & 0x00FF;
DevNonce[1] = (RandNumber >> 8) & 0x00FF;
#endif
}
/*
*****************************************************************************************
Expand Down
7 changes: 5 additions & 2 deletions src/arduino-rfm/lorawan-arduino-rfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ void LoRaWANClass::setAppSKey(const char *ApskKey_in)

void LoRaWANClass::setDevAddr(const char *devAddr_in)
{
memset(Session_Data.DevAddr, 0x30, sizeof(Session_Data.DevAddr));
size_t devAddrSize = sizeof(Session_Data.DevAddr);
memset(Session_Data.DevAddr, 0x30, devAddrSize);

//Check if it is a set command and there is enough data sent
Address_Tx[0] = ASCII2Hex(devAddr_in[0], devAddr_in[1]);
Expand Down Expand Up @@ -329,7 +330,9 @@ void LoRaWANClass::sendACK()
//Set new command for RFM
RFM_Command_Status = NEW_RFM_COMMAND;
upMsg_Type = MSG_ACK;
sprintf(Str, "");

Str[0] = '\0';

memcpy(Buffer_Tx.Data, Str, sizeof(Str));

}
Expand Down

0 comments on commit a2bde65

Please sign in to comment.