Fix status sequence and reporting for LWIP stack

pull/8381/head
Michal Paszta 2018-10-09 08:25:17 +02:00
parent 6d7b655b87
commit bc2a1c1a71
1 changed files with 20 additions and 6 deletions

View File

@ -166,8 +166,9 @@ nsapi_error_t LWIP::Interface::set_dhcp()
void LWIP::Interface::netif_link_irq(struct netif *netif) void LWIP::Interface::netif_link_irq(struct netif *netif)
{ {
LWIP::Interface *interface = our_if_from_netif(netif); LWIP::Interface *interface = our_if_from_netif(netif);
nsapi_connection_status_t connectedStatusPrev = interface->connected;
if (netif_is_link_up(&interface->netif)) { if (netif_is_link_up(&interface->netif) && interface->connected == NSAPI_STATUS_CONNECTING) {
nsapi_error_t dhcp_status = interface->set_dhcp(); nsapi_error_t dhcp_status = interface->set_dhcp();
if (interface->blocking && dhcp_status == NSAPI_ERROR_OK) { if (interface->blocking && dhcp_status == NSAPI_ERROR_OK) {
@ -177,15 +178,25 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
} }
} else { } else {
osSemaphoreRelease(interface->unlinked); osSemaphoreRelease(interface->unlinked);
if (netif_is_up(&interface->netif)) {
interface->connected = NSAPI_STATUS_CONNECTING;
}
netif_set_down(&interface->netif); netif_set_down(&interface->netif);
} }
if (interface->client_callback && connectedStatusPrev != interface->connected
&& interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ {
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
}
} }
void LWIP::Interface::netif_status_irq(struct netif *netif) void LWIP::Interface::netif_status_irq(struct netif *netif)
{ {
LWIP::Interface *interface = our_if_from_netif(netif); LWIP::Interface *interface = our_if_from_netif(netif);
nsapi_connection_status_t connectedStatusPrev = interface->connected;
if (netif_is_up(&interface->netif)) { if (netif_is_up(&interface->netif) && netif_is_link_up(&interface->netif)) {
bool dns_addr_has_to_be_added = false; bool dns_addr_has_to_be_added = false;
if (!(interface->has_addr_state & HAS_ANY_ADDR) && LWIP::get_ip_addr(true, netif)) { if (!(interface->has_addr_state & HAS_ANY_ADDR) && LWIP::get_ip_addr(true, netif)) {
if (interface->blocking) { if (interface->blocking) {
@ -216,15 +227,15 @@ void LWIP::Interface::netif_status_irq(struct netif *netif)
add_dns_addr(&interface->netif); add_dns_addr(&interface->netif);
} }
if (interface->has_addr_state & HAS_ANY_ADDR) { if (interface->has_addr_state & HAS_ANY_ADDR) {
interface->connected = NSAPI_STATUS_GLOBAL_UP; interface->connected = NSAPI_STATUS_GLOBAL_UP;
} }
} else { } else if (!netif_is_up(&interface->netif) && netif_is_link_up(&interface->netif)) {
interface->connected = NSAPI_STATUS_DISCONNECTED; interface->connected = NSAPI_STATUS_DISCONNECTED;
} }
if (interface->client_callback) { if (interface->client_callback && (connectedStatusPrev != interface->connected)
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ {
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected); interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
} }
} }
@ -632,5 +643,8 @@ nsapi_error_t LWIP::Interface::bringdown()
has_addr_state = 0; has_addr_state = 0;
connected = NSAPI_STATUS_DISCONNECTED; connected = NSAPI_STATUS_DISCONNECTED;
if (client_callback) {
client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, connected);
}
return 0; return 0;
} }