Skip to content

Stop beaconing if bcning null or absent#216

Open
emanuele-dedonatis wants to merge 1 commit intolorabasics:masterfrom
emanuele-dedonatis:master
Open

Stop beaconing if bcning null or absent#216
emanuele-dedonatis wants to merge 1 commit intolorabasics:masterfrom
emanuele-dedonatis:master

Conversation

@emanuele-dedonatis
Copy link

Fix: Beaconing not stopped on reconnection when bcning field is absent or null

Problem

Once beaconing was started via router_config, it could not be stopped on subsequent reconnections. Two cases were broken:

  1. "bcning": null — explicitly sending null had no effect; the gateway kept beaconing.
  2. bcning field absent — omitting the field on reconnection left s2ctx->bcn untouched and the beacon timer kept running.

This was a problem for network servers that send router_config on every reconnection and rely on the absence of bcning to mean "no beaconing required".

Root Cause

In handle_router_config() (s2e.c):

  • The J_bcning: null case just breaked without clearing any state.
  • The end-of-function check only handled the start beaconing case (bcn.ctrl&0xF0 != 0). There was no else branch to stop beaconing when the new config carried no beacon frequencies.

Since bcn is a local variable initialized to zero, a missing or empty bcning field would always result in bcn.ctrl == 0, silently skipping the if block and leaving s2ctx->bcn and the beacon timer from the previous session intact.

Fix

1. Handle "bcning": null explicitly:

case J_bcning: {
    if( uj_null(D) ) {
        rt_clrTimer(&s2ctx->bcntimer);
        memset(&s2ctx->bcn, 0, sizeof(s2ctx->bcn));
        LOG(MOD_S2E|INFO, "Beaconing disabled (bcning: null)");
        break;
    }
    // ...
}

2. Stop beaconing when bcning is absent or carries no frequencies:

if( (bcn.ctrl&0xF0) != 0 ) {
    // start beaconing (unchanged)
    ...
} else if( (s2ctx->bcn.ctrl&0xF0) != 0 ) {
    // bcning absent or no frequencies — stop ongoing beaconing
    rt_clrTimer(&s2ctx->bcntimer);
    memset(&s2ctx->bcn, 0, sizeof(s2ctx->bcn));
    LOG(MOD_S2E|INFO, "Beaconing disabled (bcning field absent or no frequencies)");
}

Behaviour After Fix

router_config sent Before After
"bcning": { "freqs": [...] } ✅ Starts beaconing ✅ Starts beaconing
"bcning": null ❌ No effect ✅ Stops beaconing
bcning field absent ❌ Kept beaconing ✅ Stops beaconing
"bcning": { "freqs": [] } ❌ Kept beaconing ✅ Stops beaconing

Files Changed

  • src/s2e.c

Signed-off-by: Emanuele De Donatis <ede@loriot.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant