File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed
features/net/FEATURE_IPV4/lwip-interface Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,7 @@ int EthernetInterface::connect()
26
26
27
27
int EthernetInterface::disconnect ()
28
28
{
29
- lwip_bringdown ();
30
- return 0 ;
29
+ return lwip_bringdown ();
31
30
}
32
31
33
32
const char *EthernetInterface::get_ip_address ()
Original file line number Diff line number Diff line change @@ -145,6 +145,11 @@ const char *lwip_get_ip_address(void)
145
145
int lwip_bringup (void )
146
146
{
147
147
// Check if we've already connected
148
+ if (lwip_get_ip_address ()) {
149
+ return NSAPI_ERROR_PARAMETER ;
150
+ }
151
+
152
+ // Check if we've already brought up lwip
148
153
if (!lwip_get_mac_address ()) {
149
154
// Set up network
150
155
lwip_set_mac_address ();
@@ -181,12 +186,19 @@ int lwip_bringup(void)
181
186
return 0 ;
182
187
}
183
188
184
- void lwip_bringdown (void )
189
+ int lwip_bringdown (void )
185
190
{
191
+ // Check if we've connected
192
+ if (!lwip_get_ip_address ()) {
193
+ return NSAPI_ERROR_PARAMETER ;
194
+ }
195
+
186
196
// Disconnect from the network
187
197
dhcp_release (& lwip_netif );
188
198
dhcp_stop (& lwip_netif );
189
199
lwip_ip_addr [0 ] = '\0' ;
200
+
201
+ return 0 ;
190
202
}
191
203
192
204
@@ -231,6 +243,12 @@ static nsapi_addr_t lwip_get_addr(nsapi_stack_t *stack)
231
243
232
244
static int lwip_socket_open (nsapi_stack_t * stack , nsapi_socket_t * handle , nsapi_protocol_t proto )
233
245
{
246
+ // check if network is connected
247
+ if (!lwip_get_ip_address ()) {
248
+ return NSAPI_ERROR_NO_CONNECTION ;
249
+ }
250
+
251
+ // allocate a socket
234
252
struct lwip_socket * s = lwip_arena_alloc ();
235
253
if (!s ) {
236
254
return NSAPI_ERROR_NO_SOCKET ;
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ extern "C" {
26
26
27
27
// Access to lwip through the nsapi
28
28
int lwip_bringup (void );
29
- void lwip_bringdown (void );
29
+ int lwip_bringdown (void );
30
30
31
31
extern nsapi_stack_t lwip_stack ;
32
32
You can’t perform that action at this time.
0 commit comments