mirror of https://github.com/ARMmbed/mbed-os.git
lwip - Added checks for invalid state of network
- Check if disconnected in socket open - Check if connected in interface connect - Check if disconnected in interface disconnectpull/2561/head
parent
39127f856a
commit
98ec80c484
|
@ -26,8 +26,7 @@ int EthernetInterface::connect()
|
|||
|
||||
int EthernetInterface::disconnect()
|
||||
{
|
||||
lwip_bringdown();
|
||||
return 0;
|
||||
return lwip_bringdown();
|
||||
}
|
||||
|
||||
const char *EthernetInterface::get_ip_address()
|
||||
|
|
|
@ -145,6 +145,11 @@ const char *lwip_get_ip_address(void)
|
|||
int lwip_bringup(void)
|
||||
{
|
||||
// Check if we've already connected
|
||||
if (lwip_get_ip_address()) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
|
||||
// Check if we've already brought up lwip
|
||||
if (!lwip_get_mac_address()) {
|
||||
// Set up network
|
||||
lwip_set_mac_address();
|
||||
|
@ -181,12 +186,19 @@ int lwip_bringup(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void lwip_bringdown(void)
|
||||
int lwip_bringdown(void)
|
||||
{
|
||||
// Check if we've connected
|
||||
if (!lwip_get_ip_address()) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
|
||||
// Disconnect from the network
|
||||
dhcp_release(&lwip_netif);
|
||||
dhcp_stop(&lwip_netif);
|
||||
lwip_ip_addr[0] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -231,6 +243,12 @@ static nsapi_addr_t lwip_get_addr(nsapi_stack_t *stack)
|
|||
|
||||
static int lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
|
||||
{
|
||||
// check if network is connected
|
||||
if (!lwip_get_ip_address()) {
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
// allocate a socket
|
||||
struct lwip_socket *s = lwip_arena_alloc();
|
||||
if (!s) {
|
||||
return NSAPI_ERROR_NO_SOCKET;
|
||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
|
||||
// Access to lwip through the nsapi
|
||||
int lwip_bringup(void);
|
||||
void lwip_bringdown(void);
|
||||
int lwip_bringdown(void);
|
||||
|
||||
extern nsapi_stack_t lwip_stack;
|
||||
|
||||
|
|
Loading…
Reference in New Issue