Added lwip status parameter

pull/2767/head
Mika Leppänen 2016-09-21 13:32:41 +03:00
parent 0a88251b6c
commit 283ee52228
1 changed files with 8 additions and 4 deletions

View File

@ -43,6 +43,8 @@ static struct lwip_socket {
void *data; void *data;
} lwip_arena[MEMP_NUM_NETCONN]; } lwip_arena[MEMP_NUM_NETCONN];
static bool lwip_connected = false;
static void lwip_arena_init(void) static void lwip_arena_init(void)
{ {
memset(lwip_arena, 0, sizeof lwip_arena); memset(lwip_arena, 0, sizeof lwip_arena);
@ -260,7 +262,6 @@ static void lwip_set_mac_address(void)
#endif #endif
} }
/* LWIP interface implementation */ /* LWIP interface implementation */
const char *lwip_get_mac_address(void) const char *lwip_get_mac_address(void)
{ {
@ -317,7 +318,7 @@ char *lwip_get_gateway(char *buf, int buflen)
int lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw) int lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw)
{ {
// Check if we've already connected // Check if we've already connected
if (lwip_get_ip_address()) { if (lwip_connected) {
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
@ -416,6 +417,7 @@ int lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw)
if (ret == SYS_ARCH_TIMEOUT) { if (ret == SYS_ARCH_TIMEOUT) {
return NSAPI_ERROR_DHCP_FAILURE; return NSAPI_ERROR_DHCP_FAILURE;
} }
lwip_connected = true;
} }
#if ADDR_TIMEOUT #if ADDR_TIMEOUT
@ -432,7 +434,7 @@ int lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw)
int lwip_bringdown(void) int lwip_bringdown(void)
{ {
// Check if we've connected // Check if we've connected
if (!lwip_get_ip_address()) { if (!lwip_connected) {
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
@ -447,6 +449,8 @@ int lwip_bringdown(void)
} }
#endif #endif
lwip_connected = false;
// TO DO - actually remove addresses from stack, and shut down properly
return 0; return 0;
} }
@ -492,7 +496,7 @@ static int lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi_addr
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 // check if network is connected
if (!lwip_get_ip_address()) { if (!lwip_connected) {
return NSAPI_ERROR_NO_CONNECTION; return NSAPI_ERROR_NO_CONNECTION;
} }