summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNishant Chaprana <n.chaprana@samsung.com>2020-02-25 20:11:51 +0530
committerNishant Chaprana <n.chaprana@samsung.com>2020-03-02 15:23:34 +0530
commit8b8bd9142f5e039347b5931c54c7e2a852351e04 (patch)
tree2573394801b2b159e0cebe3479b68584ba466c5f
parent3ded0d7ad87ce74e2a7944dde83222736e2bb39f (diff)
downloadtoybox-8b8bd9142f5e039347b5931c54c7e2a852351e04.tar.gz
toybox-8b8bd9142f5e039347b5931c54c7e2a852351e04.tar.bz2
toybox-8b8bd9142f5e039347b5931c54c7e2a852351e04.zip
Some routers/AP handle the DHCP broadcast flag incorrectly. This means that some AP discard the DHCP packet if broadcast flag is present and some discard it if broadcast flag is missing. The workaround is to first send DISCOVER packet in INIT state without broadcast flag. If there is a timeout we send the second packet with broadcast flag set. In a case of second timeout the next DISCOVER will not set broadcast flag etc. In REBOOTING state the REQUEST packet will not set the broadcast flag. If we do not get a reply, we switch to INIT state anyway which will set the broadcast flag. Change-Id: Ifd3adfe6693f51f0f331c6ebcdc7011e3be3a353 Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
-rw-r--r--toys/pending/dhcp.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/toys/pending/dhcp.c b/toys/pending/dhcp.c
index 3c70765..0451c81 100644
--- a/toys/pending/dhcp.c
+++ b/toys/pending/dhcp.c
@@ -4,7 +4,7 @@
* Copyright 2013 Kyungwan Han <asura321@gmail.com>
*
* Not in SUSv4.
-USE_DHCP(NEWTOY(dhcp, "V:H:F:x*r:O*A#<0T#<0t#<0s:p:i:SBRCaovqnbf", TOYFLAG_SBIN|TOYFLAG_ROOTONLY))
+USE_DHCP(NEWTOY(dhcp, "V:H:F:x*r:O*A#<0T#<0t#<0s:p:i:SBRCaovqnbfW", TOYFLAG_SBIN|TOYFLAG_ROOTONLY))
config DHCP
bool "dhcp"
@@ -38,6 +38,7 @@ config DHCP
-V VENDOR Vendor identifier (default 'toybox VERSION')
-C Don't send MAC as client identifier
-v Verbose
+ -W Workarround for buggy APs when DHCPDISCOVER/DHCPREQUEST set/unset BOOTP broadcast flag
Signals:
USR1 Renew current lease
@@ -199,6 +200,7 @@ struct fd_pair { int rd; int wr; };
static uint32_t xid;
static dhcpc_state_t *state;
static struct fd_pair sigfd;
+static int broadcast_flag;
uint8_t bmacaddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
int set = 1;
uint8_t infomode = LOG_CONSOLE;
@@ -1007,7 +1009,7 @@ static int dhcpc_sendmsg(int msgtype)
// Handle the message specific settings
switch (msgtype) {
case DHCPDISCOVER: // Broadcast DISCOVER message to all servers
- if (flag_chk(FLAG_B))
+ if (flag_chk(FLAG_B) || (flag_chk(FLAG_W) && broadcast_flag))
state->pdhcp.flags = htons(BOOTP_BROADCAST_ON); // Broadcast bit set.
else
state->pdhcp.flags = htons(BOOTP_BROADCAST_OFF); // Broadcast bit unset.
@@ -1024,7 +1026,7 @@ static int dhcpc_sendmsg(int msgtype)
if (flag_chk(FLAG_x)) pend = set_xopt(pend);
break;
case DHCPREQUEST: // Send REQUEST message to the server that sent the *first* OFFER
- if (flag_chk(FLAG_B))
+ if (flag_chk(FLAG_B) || (flag_chk(FLAG_W) && broadcast_flag) || (server == INADDR_BROADCAST))
state->pdhcp.flags = htons(BOOTP_BROADCAST_ON); // Broadcast bit set.
else
state->pdhcp.flags = htons(BOOTP_BROADCAST_OFF); // Broadcast bit unset.
@@ -1346,6 +1348,7 @@ void dhcp_main(void)
if (!packets) xid = getxid();
run_script(NULL, "deconfig");
infomsg(infomode, "Sending discover...");
+ broadcast_flag = (broadcast_flag + 1) % 2;
dhcpc_sendmsg(DHCPDISCOVER);
server = 0;
timeout = flag_get(FLAG_T, TT.timeout, 3);