Skip to content

Commit 392efa6

Browse files
net_if: begin fixing issues
- it may happen that net_if_up is never called on iface inside of the begin function, forcing it if the netif is not up - it may happen that the dhcpv4 address is already bound before the wait for the event is started, avoid that as it may be reported as an error - removed wait forever in dhcp wait event listener in favor of 10s which seems enough in order to report the error to the user and let him start the retrial procedure
1 parent 78a49f3 commit 392efa6

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

libraries/SocketWrapper/SocketHelpers.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,22 @@ void NetworkInterface::setMACAddress(const uint8_t *mac) {
100100
}
101101

102102
int NetworkInterface::begin(bool blocking, uint64_t additional_event_mask) {
103+
if (!net_if_is_up(netif)) {
104+
net_if_up(netif);
105+
}
106+
103107
dhcp();
104108

105109
// FIXME: additional_event_mask cannot be ORed here due to how Zephyr
106110
// events are handled internally. Must be reworked to wait on a sem
107111
// and register multiple event masks with event_handler instead.
108112
ARG_UNUSED(additional_event_mask);
109113

110-
int ret = net_mgmt_event_wait_on_iface(netif, NET_EVENT_IPV4_ADDR_ADD, NULL, NULL, NULL,
111-
blocking ? K_FOREVER : K_SECONDS(1));
114+
int ret = 0;
115+
if (blocking && netif->config.dhcpv4.state != NET_DHCPV4_BOUND) {
116+
ret = net_mgmt_event_wait_on_iface(netif, NET_EVENT_IPV4_DHCP_BOUND, NULL, NULL, NULL,
117+
K_SECONDS(10));
118+
}
112119
return (ret == 0) ? 1 : 0;
113120
}
114121

0 commit comments

Comments
 (0)