Add -W option for enabling workaround for buggy AP that handle broadcast flag incorrectly 43/225943/4 accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix accepted/tizen_6.5_unified tizen_6.0 tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.104145 accepted/tizen/6.0/unified/hotfix/20201103.045349 accepted/tizen/6.5/unified/20211029.015201 accepted/tizen/unified/20200305.123244 submit/tizen/20200305.075617 submit/tizen_6.0/20201029.205504 submit/tizen_6.0_hotfix/20201102.192904 submit/tizen_6.0_hotfix/20201103.115104 submit/tizen_6.5/20211028.163901 tizen_6.0.m2_release tizen_6.5.m2_release
authorNishant Chaprana <n.chaprana@samsung.com>
Tue, 25 Feb 2020 14:41:51 +0000 (20:11 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Mon, 2 Mar 2020 09:53:34 +0000 (15:23 +0530)
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>
toys/pending/dhcp.c

index 3c70765..0451c81 100644 (file)
@@ -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);