[LoRaWAN] Expose clearSession, drop force

This commit is contained in:
StevenCellist 2024-05-18 13:31:31 +02:00
parent 616fff15c3
commit 0458b6ecb4
2 changed files with 29 additions and 36 deletions

View file

@ -57,6 +57,8 @@ void LoRaWANNode::clearSession() {
memset(this->bufferSession, 0, RADIOLIB_LW_SESSION_BUF_SIZE);
memset(&(this->commandsUp), 0, sizeof(LoRaWANMacCommandQueue_t));
memset(&(this->commandsDown), 0, sizeof(LoRaWANMacCommandQueue_t));
this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE] = (uint8_t)false;
this->isActive = false;
}
uint8_t* LoRaWANNode::getBufferNonces() {
@ -456,26 +458,22 @@ void LoRaWANNode::beginOTAA(uint64_t joinEUI, uint64_t devEUI, uint8_t* nwkKey,
this->lwClass = RADIOLIB_LW_CLASS_A;
}
int16_t LoRaWANNode::activateOTAA(bool force, uint8_t joinDr, LoRaWANJoinEvent_t *joinEvent) {
// if not forced by the user, check if there is an active session
if(!force) {
if(this->isActivated()) {
// already activated, don't do anything
return(RADIOLIB_ERR_NONE);
}
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
// session restored but not yet activated - do so now
this->isActive = true;
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
}
int16_t LoRaWANNode::activateOTAA(uint8_t joinDr, LoRaWANJoinEvent_t *joinEvent) {
// check if there is an active session
if(this->isActivated()) {
// already activated, don't do anything
return(RADIOLIB_ERR_NONE);
}
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
// session restored but not yet activated - do so now
this->isActive = true;
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
}
int16_t state = RADIOLIB_ERR_UNKNOWN;
// either no valid session was found or user forced a new session, so clear all activity
this->clearSession();
this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE] = (uint8_t)false;
this->isActive = false;
// starting a new session, so make sure to update event fields already
if(joinEvent) {
@ -778,24 +776,20 @@ void LoRaWANNode::beginABP(uint32_t addr, uint8_t* fNwkSIntKey, uint8_t* sNwkSIn
this->lwClass = RADIOLIB_LW_CLASS_A;
}
int16_t LoRaWANNode::activateABP(bool force, uint8_t initialDr) {
// if not forced by the user, check if there is an active session
if(!force) {
if(this->isActivated()) {
// already activated, don't do anything
return(RADIOLIB_ERR_NONE);
}
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
// session restored but not yet activated - do so now
this->isActive = true;
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
}
int16_t LoRaWANNode::activateABP(uint8_t initialDr) {
// check if there is an active session
if(this->isActivated()) {
// already activated, don't do anything
return(RADIOLIB_ERR_NONE);
}
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
// session restored but not yet activated - do so now
this->isActive = true;
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
}
// either no valid session was found or user forced a new session, so clear all activity
this->clearSession();
this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE] = (uint8_t)false;
this->isActive = false;
// setup the uplink/downlink channels and initial datarate
if(this->band->bandType == RADIOLIB_LW_BAND_DYNAMIC) {

View file

@ -527,6 +527,11 @@ class LoRaWANNode {
*/
LoRaWANNode(PhysicalLayer* phy, const LoRaWANBand_t* band, uint8_t subBand = 0);
/*!
\brief Clear an active session, so that the device will have to rejoin the network.
*/
void clearSession();
/*!
\brief Returns the pointer to the internal buffer that holds the LW base parameters
\returns Pointer to uint8_t array of size RADIOLIB_LW_NONCES_BUF_SIZE
@ -565,11 +570,10 @@ class LoRaWANNode {
/*!
\brief Join network by restoring OTAA session or performing over-the-air activation. By this procedure,
the device will perform an exchange with the network server and set all necessary configuration.
\param force Set to true to force joining even if previously joined.
\param joinDr The datarate at which to send the join-request and any subsequent uplinks (unless ADR is enabled)
\returns \ref status_codes
*/
int16_t activateOTAA(bool force = false, uint8_t initialDr = RADIOLIB_LW_DATA_RATE_UNUSED, LoRaWANJoinEvent_t *joinEvent = NULL);
int16_t activateOTAA(uint8_t initialDr = RADIOLIB_LW_DATA_RATE_UNUSED, LoRaWANJoinEvent_t *joinEvent = NULL);
/*!
\brief Set the device credentials and activation configuration
@ -585,12 +589,10 @@ class LoRaWANNode {
/*!
\brief Join network by restoring ABP session or performing over-the-air activation.
In this procedure, all necessary configuration must be provided by the user.
\param force Set to true to force joining even if previously joined.
\param initialDr The datarate at which to send the first uplink and any subsequent uplinks (unless ADR is enabled)
\returns \ref status_codes
*/
int16_t activateABP(bool force = false, uint8_t initialDr = RADIOLIB_LW_DATA_RATE_UNUSED);
int16_t activateABP(uint8_t initialDr = RADIOLIB_LW_DATA_RATE_UNUSED);
/*! \brief Whether there is an ongoing session active */
bool isActivated();
@ -978,9 +980,6 @@ class LoRaWANNode {
// this will reset the device credentials, so the device starts completely new
void clearNonces();
// this will reset all counters and saved variables, so the device will have to rejoin the network.
void clearSession();
// wait for, open and listen during Rx1 and Rx2 windows; only performs listening
int16_t downlinkCommon();