summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);