Skip to content

Commit 98c9364

Browse files
authored
Merge pull request #2343 from geky/fix-lwip-reconnect
[nsapi] Fix issue with reconnecting the ethernet interface
2 parents c6c8d42 + 06826a9 commit 98c9364

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,33 @@ const char *lwip_get_ip_address(void)
144144
int lwip_bringup(void)
145145
{
146146
// Check if we've already connected
147-
if (lwip_get_mac_address()) {
148-
return 0;
149-
}
150-
151-
// Set up network
152-
lwip_set_mac_address();
147+
if (!lwip_get_mac_address()) {
148+
// Set up network
149+
lwip_set_mac_address();
153150

154-
sys_sem_new(&lwip_tcpip_inited, 0);
155-
sys_sem_new(&lwip_netif_linked, 0);
156-
sys_sem_new(&lwip_netif_up, 0);
151+
sys_sem_new(&lwip_tcpip_inited, 0);
152+
sys_sem_new(&lwip_netif_linked, 0);
153+
sys_sem_new(&lwip_netif_up, 0);
157154

158-
tcpip_init(lwip_tcpip_init_irq, NULL);
159-
sys_arch_sem_wait(&lwip_tcpip_inited, 0);
155+
tcpip_init(lwip_tcpip_init_irq, NULL);
156+
sys_arch_sem_wait(&lwip_tcpip_inited, 0);
160157

161-
memset(&lwip_netif, 0, sizeof lwip_netif);
162-
netif_add(&lwip_netif, 0, 0, 0, NULL, eth_arch_enetif_init, tcpip_input);
163-
netif_set_default(&lwip_netif);
158+
memset(&lwip_netif, 0, sizeof lwip_netif);
159+
netif_add(&lwip_netif, 0, 0, 0, NULL, eth_arch_enetif_init, tcpip_input);
160+
netif_set_default(&lwip_netif);
164161

165-
netif_set_link_callback (&lwip_netif, lwip_netif_link_irq);
166-
netif_set_status_callback(&lwip_netif, lwip_netif_status_irq);
162+
netif_set_link_callback (&lwip_netif, lwip_netif_link_irq);
163+
netif_set_status_callback(&lwip_netif, lwip_netif_status_irq);
167164

168-
// Connect to network
169-
eth_arch_enable_interrupts();
170-
dhcp_start(&lwip_netif);
165+
eth_arch_enable_interrupts();
166+
}
171167

172168
// Zero out socket set
173169
lwip_arena_init();
174170

171+
// Connect to the network
172+
dhcp_start(&lwip_netif);
173+
175174
// Wait for an IP Address
176175
u32_t ret = sys_arch_sem_wait(&lwip_netif_up, 15000);
177176
if (ret == SYS_ARCH_TIMEOUT) {
@@ -183,12 +182,10 @@ int lwip_bringup(void)
183182

184183
void lwip_bringdown(void)
185184
{
185+
// Disconnect from the network
186186
dhcp_release(&lwip_netif);
187187
dhcp_stop(&lwip_netif);
188-
189-
eth_arch_disable_interrupts();
190188
lwip_ip_addr[0] = '\0';
191-
lwip_mac_addr[0] = '\0';
192189
}
193190

194191

0 commit comments

Comments
 (0)