From 2e679ed4912b6ff50f6594e5ccda7372325feb14 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Fri, 13 Feb 2015 18:35:44 -0500 Subject: [PATCH] Fix the dhcp state bootstrapping when rfkill is set #2. --- src/ndhc.c | 6 +++++- src/ndhc.h | 2 +- src/rfkill.c | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ndhc.c b/src/ndhc.c index 6fbbac4..9145d01 100644 --- a/src/ndhc.c +++ b/src/ndhc.c @@ -502,7 +502,11 @@ int main(int argc, char *argv[]) switch (perform_ifup()) { case 1: cs.ifsPrevState = IFS_UP; case 0: break; - case -3: cs.rfkill_set = 1; cs.ifsPrevState = IFS_DOWN; break; + case -3: + cs.rfkill_set = 1; + cs.rfkill_at_init = 1; + cs.ifsPrevState = IFS_DOWN; + break; default: suicide("failed to set the interface to up state"); } diff --git a/src/ndhc.h b/src/ndhc.h index bb20992..152362e 100644 --- a/src/ndhc.h +++ b/src/ndhc.h @@ -47,7 +47,7 @@ struct client_state_t { struct nk_random_state_u32 rnd32_state; uint8_t routerArp[6], serverArp[6]; uint8_t using_dhcp_bpf, init, got_router_arp, got_server_arp; - uint8_t rfkill_set; + uint8_t rfkill_set, rfkill_at_init; }; struct client_config_t { diff --git a/src/rfkill.c b/src/rfkill.c index 57d0eb2..1e2f155 100644 --- a/src/rfkill.c +++ b/src/rfkill.c @@ -36,6 +36,7 @@ #include "nk/io.h" #include "ndhc.h" #include "netlink.h" +#include "ifset.h" #include "rfkill.h" int rfkill_open(char enable_rfkill[static 1]) @@ -81,6 +82,18 @@ void handle_rfkill_notice(struct client_state_t cs[static 1], uint32_t rfkidx) cs->rfkill_set = 0; if (cs->ifsPrevState == IFS_DOWN) { log_line("rfkill: radio now unblocked; bringing interface up"); + if (cs->rfkill_at_init) { + cs->rfkill_at_init = 0; + switch (perform_ifup()) { + case 1: case 0: break; + case -3: + cs->rfkill_set = 1; + cs->rfkill_at_init = 1; + log_line("rfkill: radio immediately blocked again; spurious?"); + return; + default: suicide("failed to set the interface to up state"); + } + } cs->ifsPrevState = IFS_UP; ifup_action(cs); } else {