Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LORA MAC] Prevent 32-bit data from overflowing and winding to cause RX receive window exception #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Middlewares/Third_Party/LoRaWAN/Mac/LoRaMac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,12 +1007,16 @@ static void ProcessRadioTxDone( void )
Radio.Sleep( );
}
#if ( !defined(DISABLE_LORAWAN_RX_WINDOW) || (DISABLE_LORAWAN_RX_WINDOW == 0) )
// Setup timers
// Setup timers
CRITICAL_SECTION_BEGIN( );
uint32_t offset = TimerGetCurrentTime( ) - TxDoneParams.CurTime;
TimerSetValue( &MacCtx.RxWindowTimer1, MacCtx.RxWindow1Delay - offset );
uint32_t cur_time = TimerGetCurrentTime( );
uint32_t offset = (cur_time >= TxDoneParams.CurTime) ? (cur_time - TxDoneParams.CurTime) : (cur_time+ (0XFFFFFFFF - TxDoneParams.CurTime + 1));
uint32_t value1 = (MacCtx.RxWindow1Delay > offset) ? (MacCtx.RxWindow1Delay - offset) : MacCtx.RxWindow1Delay;
TimerSetValue( &MacCtx.RxWindowTimer1, value1 );
TimerStart( &MacCtx.RxWindowTimer1 );
TimerSetValue( &MacCtx.RxWindowTimer2, MacCtx.RxWindow2Delay - offset );
uint32_t value2 = (MacCtx.RxWindow2Delay > offset) ? (MacCtx.RxWindow2Delay - offset) : MacCtx.RxWindow2Delay;
TimerSetValue( &MacCtx.RxWindowTimer2, value2 );
TimerStart( &MacCtx.RxWindowTimer2 );
CRITICAL_SECTION_END( );
#else
Expand Down