[LoRaMac] The use of the adrBlockFound variable in ProcessMacCommands is unknown
Opened this issue · 1 comments
wdfk-prog commented
Additional context
-
I don't understand what
adrBlockFound
does here, because every time it comes in it's afalse
assignment; A value oftrue
below does nothing. -
I think this variable needs to be set to
static
to make sense.
STM32CubeWL/Middlewares/Third_Party/LoRaWAN/Mac/LoRaMac.c
Lines 2676 to 2774 in eec7ff9
static void ProcessMacCommands( uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, int8_t snr, LoRaMacRxSlot_t rxSlot ) | |
{ | |
uint8_t status = 0; | |
bool adrBlockFound = false; | |
uint8_t macCmdPayload[2] = { 0x00, 0x00 }; | |
#if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01010100 )) | |
MacCommand_t* macCmd; | |
#endif /* LORAMAC_VERSION */ | |
#if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 ))) | |
if( ( rxSlot != RX_SLOT_WIN_1 ) && ( rxSlot != RX_SLOT_WIN_2 ) ) | |
{ | |
// Do only parse MAC commands for Class A RX windows | |
return; | |
} | |
#endif /* LORAMAC_VERSION */ | |
while( macIndex < commandsSize ) | |
{ | |
// Make sure to parse only complete MAC commands | |
if( ( LoRaMacCommandsGetCmdSize( payload[macIndex] ) + macIndex ) > commandsSize ) | |
{ | |
return; | |
} | |
// Decode Frame MAC commands | |
switch( payload[macIndex++] ) | |
{ | |
#if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01010100 )) | |
case SRV_MAC_RESET_CONF: | |
{ | |
uint8_t serverMinorVersion = payload[macIndex++]; | |
// Compare own LoRaWAN Version with server's | |
if( Nvm.MacGroup2.Version.Fields.Minor >= serverMinorVersion ) | |
{ | |
// If they equal remove the sticky ResetInd MAC-Command. | |
if( LoRaMacCommandsGetCmd( MOTE_MAC_RESET_IND, &macCmd) == LORAMAC_COMMANDS_SUCCESS ) | |
{ | |
LoRaMacCommandsRemoveCmd( macCmd ); | |
} | |
} | |
break; | |
} | |
#endif /* LORAMAC_VERSION */ | |
case SRV_MAC_LINK_CHECK_ANS: | |
{ | |
if( LoRaMacConfirmQueueIsCmdActive( MLME_LINK_CHECK ) == true ) | |
{ | |
LoRaMacConfirmQueueSetStatus( LORAMAC_EVENT_INFO_STATUS_OK, MLME_LINK_CHECK ); | |
MacCtx.MlmeConfirm.DemodMargin = payload[macIndex++]; | |
MacCtx.MlmeConfirm.NbGateways = payload[macIndex++]; | |
} | |
break; | |
} | |
case SRV_MAC_LINK_ADR_REQ: | |
{ | |
LinkAdrReqParams_t linkAdrReq; | |
int8_t linkAdrDatarate = DR_0; | |
int8_t linkAdrTxPower = TX_POWER_0; | |
uint8_t linkAdrNbRep = 0; | |
uint8_t linkAdrNbBytesParsed = 0; | |
// The end node is allowed to process one block of LinkAdrRequests. | |
// It must ignore subsequent blocks | |
#if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01000300 )) | |
if( adrBlockFound == false ) | |
{ | |
adrBlockFound = true; | |
// Fill parameter structure | |
linkAdrReq.Payload = &payload[macIndex - 1]; | |
linkAdrReq.PayloadSize = commandsSize - ( macIndex - 1 ); | |
linkAdrReq.AdrEnabled = Nvm.MacGroup2.AdrCtrlOn; | |
linkAdrReq.UplinkDwellTime = Nvm.MacGroup2.MacParams.UplinkDwellTime; | |
linkAdrReq.CurrentDatarate = Nvm.MacGroup1.ChannelsDatarate; | |
linkAdrReq.CurrentTxPower = Nvm.MacGroup1.ChannelsTxPower; | |
linkAdrReq.CurrentNbRep = Nvm.MacGroup2.MacParams.ChannelsNbTrans; | |
linkAdrReq.Version = Nvm.MacGroup2.Version; | |
// Process the ADR requests | |
status = RegionLinkAdrReq( Nvm.MacGroup2.Region, &linkAdrReq, &linkAdrDatarate, | |
&linkAdrTxPower, &linkAdrNbRep, &linkAdrNbBytesParsed ); | |
if( ( status & 0x07 ) == 0x07 ) | |
{ | |
Nvm.MacGroup1.ChannelsDatarate = linkAdrDatarate; | |
Nvm.MacGroup1.ChannelsTxPower = linkAdrTxPower; | |
Nvm.MacGroup2.MacParams.ChannelsNbTrans = linkAdrNbRep; | |
} | |
// Add the answers to the buffer | |
for( uint8_t i = 0; i < ( linkAdrNbBytesParsed / 5 ); i++ ) | |
{ | |
LoRaMacCommandsAddCmd( MOTE_MAC_LINK_ADR_ANS, &status, 1 ); | |
} | |
// Update MAC index | |
macIndex += linkAdrNbBytesParsed - 1; | |
} |
RJMSTM commented
ST Internal Reference: 181246