[LoRaWAN] Expose clearSession, drop force
This commit is contained in:
parent
616fff15c3
commit
0458b6ecb4
2 changed files with 29 additions and 36 deletions
|
@ -57,6 +57,8 @@ void LoRaWANNode::clearSession() {
|
||||||
memset(this->bufferSession, 0, RADIOLIB_LW_SESSION_BUF_SIZE);
|
memset(this->bufferSession, 0, RADIOLIB_LW_SESSION_BUF_SIZE);
|
||||||
memset(&(this->commandsUp), 0, sizeof(LoRaWANMacCommandQueue_t));
|
memset(&(this->commandsUp), 0, sizeof(LoRaWANMacCommandQueue_t));
|
||||||
memset(&(this->commandsDown), 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() {
|
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;
|
this->lwClass = RADIOLIB_LW_CLASS_A;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaWANNode::activateOTAA(bool force, uint8_t joinDr, LoRaWANJoinEvent_t *joinEvent) {
|
int16_t LoRaWANNode::activateOTAA(uint8_t joinDr, LoRaWANJoinEvent_t *joinEvent) {
|
||||||
// if not forced by the user, check if there is an active session
|
// check if there is an active session
|
||||||
if(!force) {
|
if(this->isActivated()) {
|
||||||
if(this->isActivated()) {
|
// already activated, don't do anything
|
||||||
// already activated, don't do anything
|
return(RADIOLIB_ERR_NONE);
|
||||||
return(RADIOLIB_ERR_NONE);
|
}
|
||||||
}
|
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
|
||||||
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
|
// session restored but not yet activated - do so now
|
||||||
// session restored but not yet activated - do so now
|
this->isActive = true;
|
||||||
this->isActive = true;
|
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
|
||||||
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||||
|
|
||||||
// either no valid session was found or user forced a new session, so clear all activity
|
// either no valid session was found or user forced a new session, so clear all activity
|
||||||
this->clearSession();
|
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
|
// starting a new session, so make sure to update event fields already
|
||||||
if(joinEvent) {
|
if(joinEvent) {
|
||||||
|
@ -778,24 +776,20 @@ void LoRaWANNode::beginABP(uint32_t addr, uint8_t* fNwkSIntKey, uint8_t* sNwkSIn
|
||||||
this->lwClass = RADIOLIB_LW_CLASS_A;
|
this->lwClass = RADIOLIB_LW_CLASS_A;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaWANNode::activateABP(bool force, uint8_t initialDr) {
|
int16_t LoRaWANNode::activateABP(uint8_t initialDr) {
|
||||||
// if not forced by the user, check if there is an active session
|
// check if there is an active session
|
||||||
if(!force) {
|
if(this->isActivated()) {
|
||||||
if(this->isActivated()) {
|
// already activated, don't do anything
|
||||||
// already activated, don't do anything
|
return(RADIOLIB_ERR_NONE);
|
||||||
return(RADIOLIB_ERR_NONE);
|
}
|
||||||
}
|
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
|
||||||
if(this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE]) {
|
// session restored but not yet activated - do so now
|
||||||
// session restored but not yet activated - do so now
|
this->isActive = true;
|
||||||
this->isActive = true;
|
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
|
||||||
return(RADIOLIB_LORAWAN_SESSION_RESTORED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// either no valid session was found or user forced a new session, so clear all activity
|
// either no valid session was found or user forced a new session, so clear all activity
|
||||||
this->clearSession();
|
this->clearSession();
|
||||||
this->bufferNonces[RADIOLIB_LW_NONCES_ACTIVE] = (uint8_t)false;
|
|
||||||
this->isActive = false;
|
|
||||||
|
|
||||||
// setup the uplink/downlink channels and initial datarate
|
// setup the uplink/downlink channels and initial datarate
|
||||||
if(this->band->bandType == RADIOLIB_LW_BAND_DYNAMIC) {
|
if(this->band->bandType == RADIOLIB_LW_BAND_DYNAMIC) {
|
||||||
|
|
|
@ -527,6 +527,11 @@ class LoRaWANNode {
|
||||||
*/
|
*/
|
||||||
LoRaWANNode(PhysicalLayer* phy, const LoRaWANBand_t* band, uint8_t subBand = 0);
|
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
|
\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
|
\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,
|
\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.
|
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)
|
\param joinDr The datarate at which to send the join-request and any subsequent uplinks (unless ADR is enabled)
|
||||||
\returns \ref status_codes
|
\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
|
\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.
|
\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.
|
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)
|
\param initialDr The datarate at which to send the first uplink and any subsequent uplinks (unless ADR is enabled)
|
||||||
\returns \ref status_codes
|
\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 */
|
/*! \brief Whether there is an ongoing session active */
|
||||||
bool isActivated();
|
bool isActivated();
|
||||||
|
@ -978,9 +980,6 @@ class LoRaWANNode {
|
||||||
// this will reset the device credentials, so the device starts completely new
|
// this will reset the device credentials, so the device starts completely new
|
||||||
void clearNonces();
|
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
|
// wait for, open and listen during Rx1 and Rx2 windows; only performs listening
|
||||||
int16_t downlinkCommon();
|
int16_t downlinkCommon();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue