Skip to content

Commit 116a743

Browse files
author
Cruz Monrreal
authored
Merge pull request #8381 from michalpasztamobica/master
Fix status sequence and reporting for LWIP stack
2 parents a0a3dd6 + bc2a1c1 commit 116a743

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

features/lwipstack/LWIPInterface.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ nsapi_error_t LWIP::Interface::set_dhcp()
166166
void LWIP::Interface::netif_link_irq(struct netif *netif)
167167
{
168168
LWIP::Interface *interface = our_if_from_netif(netif);
169+
nsapi_connection_status_t connectedStatusPrev = interface->connected;
169170

170-
if (netif_is_link_up(&interface->netif)) {
171+
if (netif_is_link_up(&interface->netif) && interface->connected == NSAPI_STATUS_CONNECTING) {
171172
nsapi_error_t dhcp_status = interface->set_dhcp();
172173

173174
if (interface->blocking && dhcp_status == NSAPI_ERROR_OK) {
@@ -177,15 +178,25 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
177178
}
178179
} else {
179180
osSemaphoreRelease(interface->unlinked);
181+
if (netif_is_up(&interface->netif)) {
182+
interface->connected = NSAPI_STATUS_CONNECTING;
183+
}
180184
netif_set_down(&interface->netif);
181185
}
186+
187+
if (interface->client_callback && connectedStatusPrev != interface->connected
188+
&& interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */
189+
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ {
190+
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
191+
}
182192
}
183193

184194
void LWIP::Interface::netif_status_irq(struct netif *netif)
185195
{
186196
LWIP::Interface *interface = our_if_from_netif(netif);
197+
nsapi_connection_status_t connectedStatusPrev = interface->connected;
187198

188-
if (netif_is_up(&interface->netif)) {
199+
if (netif_is_up(&interface->netif) && netif_is_link_up(&interface->netif)) {
189200
bool dns_addr_has_to_be_added = false;
190201
if (!(interface->has_addr_state & HAS_ANY_ADDR) && LWIP::get_ip_addr(true, netif)) {
191202
if (interface->blocking) {
@@ -212,19 +223,19 @@ void LWIP::Interface::netif_status_irq(struct netif *netif)
212223
dns_addr_has_to_be_added = true;
213224
}
214225
#endif
215-
if (dns_addr_has_to_be_added && !interface->blocking) {
226+
if (dns_addr_has_to_be_added && !interface->blocking) {
216227
add_dns_addr(&interface->netif);
217228
}
218229

219-
220230
if (interface->has_addr_state & HAS_ANY_ADDR) {
221231
interface->connected = NSAPI_STATUS_GLOBAL_UP;
222232
}
223-
} else {
233+
} else if (!netif_is_up(&interface->netif) && netif_is_link_up(&interface->netif)) {
224234
interface->connected = NSAPI_STATUS_DISCONNECTED;
225235
}
226236

227-
if (interface->client_callback) {
237+
if (interface->client_callback && (connectedStatusPrev != interface->connected)
238+
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ {
228239
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
229240
}
230241
}
@@ -632,5 +643,8 @@ nsapi_error_t LWIP::Interface::bringdown()
632643
has_addr_state = 0;
633644

634645
connected = NSAPI_STATUS_DISCONNECTED;
646+
if (client_callback) {
647+
client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, connected);
648+
}
635649
return 0;
636650
}

0 commit comments

Comments
 (0)