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()
|
int EthernetInterface::disconnect()
|
||||||
{
|
{
|
||||||
lwip_bringdown();
|
return lwip_bringdown();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *EthernetInterface::get_ip_address()
|
const char *EthernetInterface::get_ip_address()
|
||||||
|
|
|
@ -145,6 +145,11 @@ const char *lwip_get_ip_address(void)
|
||||||
int lwip_bringup(void)
|
int lwip_bringup(void)
|
||||||
{
|
{
|
||||||
// Check if we've already connected
|
// 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()) {
|
if (!lwip_get_mac_address()) {
|
||||||
// Set up network
|
// Set up network
|
||||||
lwip_set_mac_address();
|
lwip_set_mac_address();
|
||||||
|
@ -181,12 +186,19 @@ int lwip_bringup(void)
|
||||||
return 0;
|
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
|
// Disconnect from the network
|
||||||
dhcp_release(&lwip_netif);
|
dhcp_release(&lwip_netif);
|
||||||
dhcp_stop(&lwip_netif);
|
dhcp_stop(&lwip_netif);
|
||||||
lwip_ip_addr[0] = '\0';
|
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)
|
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();
|
struct lwip_socket *s = lwip_arena_alloc();
|
||||||
if (!s) {
|
if (!s) {
|
||||||
return NSAPI_ERROR_NO_SOCKET;
|
return NSAPI_ERROR_NO_SOCKET;
|
||||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
||||||
|
|
||||||
// Access to lwip through the nsapi
|
// Access to lwip through the nsapi
|
||||||
int lwip_bringup(void);
|
int lwip_bringup(void);
|
||||||
void lwip_bringdown(void);
|
int lwip_bringdown(void);
|
||||||
|
|
||||||
extern nsapi_stack_t lwip_stack;
|
extern nsapi_stack_t lwip_stack;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue