Knight KE / Mbed OS Game_Master
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LWIPInterface.cpp Source File

LWIPInterface.cpp

00001 /* Copyright (c) 2017 ARM Limited
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *     http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00016 #define __STDC_LIMIT_MACROS
00017 
00018 #include "nsapi.h"
00019 #include "mbed_interface.h"
00020 #include "mbed_assert.h"
00021 #include <stdio.h>
00022 #include <stdbool.h>
00023 #include <string.h>
00024 #include <new>
00025 #include <stdint.h>
00026 
00027 #include "lwip/opt.h"
00028 #include "lwip/api.h"
00029 #include "lwip/inet.h"
00030 #include "lwip/netif.h"
00031 #include "lwip/dhcp.h"
00032 #include "lwip/tcpip.h"
00033 #include "lwip/tcp.h"
00034 #include "lwip/ip.h"
00035 #include "lwip/mld6.h"
00036 #include "lwip/dns.h"
00037 #include "lwip/udp.h"
00038 
00039 #include "ppp_lwip.h"
00040 
00041 #include "LWIPStack.h"
00042 
00043 LWIP::Interface *LWIP::Interface::list;
00044 
00045 LWIP::Interface *LWIP::Interface::our_if_from_netif(struct netif *netif)
00046 {
00047     for (Interface *interface = list; interface; interface = interface->next) {
00048         if (netif == &interface->netif) {
00049             return interface;
00050         }
00051     }
00052 
00053     return NULL;
00054 }
00055 
00056 static void add_dns_addr_to_dns_list_index(const u8_t addr_type, const u8_t index)
00057 {
00058 #if LWIP_IPV6
00059     if (addr_type == IPADDR_TYPE_V6) {
00060         /* 2001:4860:4860::8888 google */
00061         ip_addr_t ipv6_dns_addr = IPADDR6_INIT(
00062                 PP_HTONL(0x20014860UL),
00063                 PP_HTONL(0x48600000UL),
00064                 PP_HTONL(0x00000000UL),
00065                 PP_HTONL(0x00008888UL));
00066         dns_setserver(index, &ipv6_dns_addr);
00067     }
00068 #endif
00069 #if LWIP_IPV4
00070     if (addr_type == IPADDR_TYPE_V4) {
00071         /* 8.8.8.8 google */
00072         ip_addr_t ipv4_dns_addr = IPADDR4_INIT(0x08080808);
00073         dns_setserver(index, &ipv4_dns_addr);
00074     }
00075 #endif
00076 }
00077 
00078 static int get_ip_addr_type(const ip_addr_t *ip_addr)
00079 {
00080 #if LWIP_IPV6
00081     if (IP_IS_V6(ip_addr)) {
00082         return IPADDR_TYPE_V6;
00083     }
00084 #endif
00085 #if LWIP_IPV4
00086     if (IP_IS_V4(ip_addr)) {
00087         return IPADDR_TYPE_V4;
00088     }
00089 #endif
00090 #if LWIP_IPV6 && LWIP_IPV4
00091     return IPADDR_TYPE_ANY;
00092 #endif
00093 }
00094 
00095 void LWIP::add_dns_addr(struct netif *lwip_netif)
00096 {
00097     // Check for existing dns address
00098     for (char numdns = 0; numdns < DNS_MAX_SERVERS; numdns++) {
00099         const ip_addr_t *dns_ip_addr = dns_getserver(numdns);
00100         if (!ip_addr_isany(dns_ip_addr)) {
00101             return;
00102         }
00103     }
00104 
00105     // Get preferred ip version
00106     const ip_addr_t *ip_addr = get_ip_addr(false, lwip_netif);
00107     u8_t addr_type = IPADDR_TYPE_ANY;
00108 
00109     // Add preferred ip version dns address to index 0
00110     if (ip_addr) {
00111         addr_type = get_ip_addr_type(ip_addr);
00112         add_dns_addr_to_dns_list_index(addr_type, 0);
00113     }
00114 
00115 #if LWIP_IPV4 && LWIP_IPV6
00116     if (!ip_addr) {
00117         // Get address for any ip version
00118         ip_addr = get_ip_addr(true, lwip_netif);
00119         if (!ip_addr) {
00120             return;
00121         }
00122         addr_type = get_ip_addr_type(ip_addr);
00123         // Add the dns address to index 0
00124         add_dns_addr_to_dns_list_index(addr_type, 0);
00125     }
00126 
00127     if (addr_type == IPADDR_TYPE_V4) {
00128         // If ipv4 is preferred and ipv6 is available add ipv6 dns address to index 1
00129         ip_addr = get_ipv6_addr(lwip_netif);
00130     } else if (addr_type == IPADDR_TYPE_V6) {
00131         // If ipv6 is preferred and ipv4 is available add ipv4 dns address to index 1
00132         ip_addr = get_ipv4_addr(lwip_netif);
00133     } else {
00134         ip_addr = NULL;
00135     }
00136 
00137     if (ip_addr) {
00138         addr_type = get_ip_addr_type(ip_addr);
00139         add_dns_addr_to_dns_list_index(addr_type, 1);
00140     }
00141 #endif
00142 }
00143 
00144 nsapi_error_t LWIP::Interface::set_dhcp()
00145 {
00146     netif_set_up(&netif);
00147 
00148 #if LWIP_DHCP
00149     if (dhcp_has_to_be_set) {
00150         err_t err = dhcp_start(&netif);
00151         dhcp_has_to_be_set = false;
00152         if (err) {
00153             connected = NSAPI_STATUS_DISCONNECTED ;
00154             if (client_callback) {
00155                 client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE , NSAPI_STATUS_DISCONNECTED );
00156             }
00157             return NSAPI_ERROR_DHCP_FAILURE ;
00158         }
00159         dhcp_started = true;
00160     }
00161 #endif
00162 
00163     return NSAPI_ERROR_OK ;
00164 }
00165 
00166 void LWIP::Interface::netif_link_irq(struct netif *netif)
00167 {
00168     LWIP::Interface *interface = our_if_from_netif(netif);
00169 
00170     if (netif_is_link_up(&interface->netif)) {
00171         nsapi_error_t dhcp_status = interface->set_dhcp();
00172 
00173         if (interface->blocking && dhcp_status == NSAPI_ERROR_OK ) {
00174             osSemaphoreRelease(interface->linked);
00175         } else if (dhcp_status != NSAPI_ERROR_OK ) {
00176             netif_set_down(&interface->netif);
00177         }
00178     } else {
00179         osSemaphoreRelease(interface->unlinked);
00180         netif_set_down(&interface->netif);
00181     }
00182 }
00183 
00184 void LWIP::Interface::netif_status_irq(struct netif *netif)
00185 {
00186     LWIP::Interface *interface = our_if_from_netif(netif);
00187 
00188     if (netif_is_up(&interface->netif)) {
00189         bool dns_addr_has_to_be_added = false;
00190         if (!(interface->has_addr_state & HAS_ANY_ADDR) && LWIP::get_ip_addr(true, netif)) {
00191             if (interface->blocking) {
00192                 osSemaphoreRelease(interface->has_any_addr);
00193             }
00194             interface->has_addr_state |= HAS_ANY_ADDR;
00195             dns_addr_has_to_be_added = true;
00196         }
00197 #if PREF_ADDR_TIMEOUT
00198         if (!(interface->has_addr_state & HAS_PREF_ADDR) && LWIP::get_ip_addr(false, netif)) {
00199             if (interface->blocking) {
00200                 osSemaphoreRelease(interface->has_pref_addr);
00201             }
00202             interface->has_addr_state |= HAS_PREF_ADDR;
00203             dns_addr_has_to_be_added = true;
00204         }
00205 #endif
00206 #if BOTH_ADDR_TIMEOUT
00207         if (!(interface->has_addr_state & HAS_BOTH_ADDR) && LWIP::get_ipv4_addr(netif) && LWIP::get_ipv6_addr(netif)) {
00208             if (interface->blocking) {
00209                 osSemaphoreRelease(interface->has_both_addr);
00210             }
00211             interface->has_addr_state |= HAS_BOTH_ADDR;
00212             dns_addr_has_to_be_added = true;
00213         }
00214 #endif
00215        if (dns_addr_has_to_be_added && !interface->blocking) {
00216             add_dns_addr(&interface->netif);
00217         }
00218 
00219 
00220         if (interface->has_addr_state & HAS_ANY_ADDR) {
00221             interface->connected = NSAPI_STATUS_GLOBAL_UP ;
00222         }
00223     } else {
00224         interface->connected = NSAPI_STATUS_DISCONNECTED ;
00225     }
00226 
00227     if (interface->client_callback) {
00228         interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE , interface->connected);
00229     }
00230 }
00231 
00232 void LWIP::Interface::attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
00233 {
00234     client_callback = status_cb;
00235 }
00236 
00237 nsapi_connection_status_t LWIP::Interface::get_connection_status() const
00238 {
00239     return connected;
00240 }
00241 
00242 #if LWIP_IPV6
00243 static void mbed_lwip_clear_ipv6_addresses(struct netif *netif)
00244 {
00245     for (u8_t i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
00246         netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID);
00247     }
00248 }
00249 #endif
00250 
00251 char *LWIP::Interface::get_mac_address(char *buf, nsapi_size_t buflen)
00252 {
00253     (void) snprintf(buf, buflen, "%02x:%02x:%02x:%02x:%02x:%02x",
00254              netif.hwaddr[0], netif.hwaddr[1], netif.hwaddr[2],
00255              netif.hwaddr[3], netif.hwaddr[4], netif.hwaddr[5]);
00256     return buf;
00257 }
00258 
00259 char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
00260 {
00261     const ip_addr_t *addr = LWIP::get_ip_addr(true, &netif);
00262     if (!addr) {
00263         return NULL;
00264     }
00265 #if LWIP_IPV6
00266     if (IP_IS_V6(addr)) {
00267         return ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen);
00268     }
00269 #endif
00270 #if LWIP_IPV4
00271     if (IP_IS_V4(addr)) {
00272         return ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen);
00273     }
00274 #endif
00275 #if LWIP_IPV6 && LWIP_IPV4
00276     return NULL;
00277 #endif
00278 }
00279 
00280 char *LWIP::Interface::get_netmask(char *buf, nsapi_size_t buflen)
00281 {
00282 #if LWIP_IPV4
00283     const ip4_addr_t *addr = netif_ip4_netmask(&netif);
00284     if (!ip4_addr_isany(addr)) {
00285         return ip4addr_ntoa_r(addr, buf, buflen);
00286     } else {
00287         return NULL;
00288     }
00289 #else
00290     return NULL;
00291 #endif
00292 }
00293 
00294 char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
00295 {
00296 #if LWIP_IPV4
00297     const ip4_addr_t *addr = netif_ip4_gw(&netif);
00298     if (!ip4_addr_isany(addr)) {
00299         return ip4addr_ntoa_r(addr, buf, buflen);
00300     } else {
00301         return NULL;
00302     }
00303 #else
00304     return NULL;
00305 #endif
00306 }
00307 
00308 LWIP::Interface::Interface() :
00309         hw(NULL), has_addr_state(0),
00310         connected(NSAPI_STATUS_DISCONNECTED ),
00311         dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false)
00312 {
00313     memset(&netif, 0, sizeof netif);
00314 
00315     osSemaphoreAttr_t attr;
00316     attr.name = NULL;
00317     attr.attr_bits = 0;
00318 
00319     attr.cb_mem = &linked_sem;
00320     attr.cb_size = sizeof linked_sem;
00321     linked = osSemaphoreNew(UINT16_MAX, 0, &attr);
00322 
00323     attr.cb_mem = &unlinked_sem;
00324     attr.cb_size = sizeof unlinked_sem;
00325     unlinked = osSemaphoreNew(UINT16_MAX, 0, &attr);
00326 
00327     attr.cb_mem = &has_any_addr_sem;
00328     attr.cb_size = sizeof has_any_addr_sem;
00329     has_any_addr = osSemaphoreNew(UINT16_MAX, 0, &attr);
00330 #if PREF_ADDR_TIMEOUT
00331     attr.cb_mem = &has_pref_addr_sem;
00332     attr.cb_size = sizeof has_pref_addr_sem;
00333     has_pref_addr = osSemaphoreNew(UINT16_MAX, 0, &attr);
00334 #endif
00335 #if BOTH_ADDR_TIMEOUT
00336     attr.cb_mem = &has_both_addr_sem;
00337     attr.cb_size = sizeof has_both_addr_sem;
00338     has_both_addr = osSemaphoreNew(UINT16_MAX, 0, &attr);
00339 #endif
00340 
00341     next = list;
00342     list = this;
00343 }
00344 
00345 nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out)
00346 {
00347 #if LWIP_ETHERNET
00348     Interface *interface = new (std::nothrow) Interface();
00349     if (!interface) {
00350         return NSAPI_ERROR_NO_MEMORY ;
00351     }
00352     interface->emac = &emac;
00353     interface->memory_manager = &memory_manager;
00354     interface->ppp = false;
00355 
00356 #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
00357     netif->interface.hwaddr[0] = MBED_MAC_ADDR_0;
00358     netif->interface.hwaddr[1] = MBED_MAC_ADDR_1;
00359     netif->interface.hwaddr[2] = MBED_MAC_ADDR_2;
00360     netif->interface.hwaddr[3] = MBED_MAC_ADDR_3;
00361     netif->interface.hwaddr[4] = MBED_MAC_ADDR_4;
00362     netif->interface.hwaddr[5] = MBED_MAC_ADDR_5;
00363 #else
00364     mbed_mac_address((char *) interface->netif.hwaddr);
00365 #endif
00366 
00367     interface->netif.hwaddr_len = 6;
00368 
00369     if (!netif_add(&interface->netif,
00370 #if LWIP_IPV4
00371             0, 0, 0,
00372 #endif
00373             interface, &LWIP::Interface::emac_if_init, tcpip_input)) {
00374         return NSAPI_ERROR_DEVICE_ERROR ;
00375     }
00376 
00377     if (default_if) {
00378         netif_set_default(&interface->netif);
00379         default_interface = interface;
00380     }
00381 
00382     netif_set_link_callback(&interface->netif, &LWIP::Interface::netif_link_irq);
00383     netif_set_status_callback(&interface->netif, &LWIP::Interface::netif_status_irq);
00384 
00385     *interface_out = interface;
00386 
00387     /* Use mac address as additional seed to random number generator */
00388     uint64_t seed = interface->netif.hwaddr[0];
00389     for (uint8_t i = 1; i < 8; i++) {
00390         seed <<= 8;
00391         seed |= interface->netif.hwaddr[i % 6];
00392     }
00393     lwip_add_random_seed(seed);
00394 
00395     return NSAPI_ERROR_OK ;
00396 #else
00397     return NSAPI_ERROR_UNSUPPORTED ;
00398 #endif //LWIP_ETHERNET
00399 }
00400 
00401 /* Internal API to preserve existing PPP functionality - revise to better match mbed_ipstak_add_ethernet_interface later */
00402 nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out)
00403 {
00404 #if LWIP_PPP_API
00405     Interface *interface = new (std::nothrow) Interface();
00406     if (!interface) {
00407         return NSAPI_ERROR_NO_MEMORY ;
00408     }
00409     interface->hw = hw;
00410     interface->ppp = true;
00411 
00412     nsapi_error_t ret = ppp_lwip_if_init(hw, &interface->netif, stack);
00413     if (ret != NSAPI_ERROR_OK ) {
00414         free(interface);
00415         return ret;
00416     }
00417 
00418     if (default_if) {
00419         netif_set_default(&interface->netif);
00420         default_interface = interface;
00421     }
00422 
00423     netif_set_link_callback(&interface->netif, &LWIP::Interface::netif_link_irq);
00424     netif_set_status_callback(&interface->netif, &LWIP::Interface::netif_status_irq);
00425 
00426     *interface_out = interface;
00427 
00428     return NSAPI_ERROR_OK ;
00429 #else
00430     return NSAPI_ERROR_UNSUPPORTED ;
00431 #endif //LWIP_PPP_API
00432 }
00433 
00434 
00435 nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *netmask, const char *gw, const nsapi_ip_stack_t stack, bool block)
00436 {
00437     // Check if we've already connected
00438     if (connected == NSAPI_STATUS_GLOBAL_UP ) {
00439         return NSAPI_ERROR_IS_CONNECTED ;
00440     } else if (connected == NSAPI_STATUS_CONNECTING ) {
00441         return NSAPI_ERROR_ALREADY ;
00442     }
00443 
00444     connected = NSAPI_STATUS_CONNECTING ;
00445     blocking = block;
00446 
00447 #if LWIP_DHCP
00448     if (stack != IPV6_STACK && dhcp) {
00449         dhcp_has_to_be_set = true;
00450     }
00451 #endif
00452 
00453 #if LWIP_IPV6
00454     if (stack != IPV4_STACK) {
00455         if (netif.hwaddr_len == 6) {
00456             netif_create_ip6_linklocal_address(&netif, 1/*from MAC*/);
00457         }
00458 #if LWIP_IPV6_MLD
00459         /*
00460          * For hardware/netifs that implement MAC filtering.
00461          * All-nodes link-local is handled by default, so we must let the hardware know
00462          * to allow multicast packets in.
00463          * Should set mld_mac_filter previously. */
00464         if (netif.mld_mac_filter != NULL) {
00465             ip6_addr_t ip6_allnodes_ll;
00466             ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll);
00467             netif.mld_mac_filter(&netif, &ip6_allnodes_ll, NETIF_ADD_MAC_FILTER);
00468         }
00469 #endif /* LWIP_IPV6_MLD */
00470 
00471 #if LWIP_IPV6_AUTOCONFIG
00472         /* IPv6 address autoconfiguration not enabled by default */
00473         netif.ip6_autoconfig_enabled = 1;
00474 #endif /* LWIP_IPV6_AUTOCONFIG */
00475     } else {
00476         // Disable rourter solicitations
00477         netif.rs_count = 0;
00478     }
00479 #endif /* LWIP_IPV6 */
00480 
00481 #if LWIP_IPV4
00482     if (stack != IPV6_STACK) {
00483         if (!dhcp && !ppp) {
00484             ip4_addr_t ip_addr;
00485             ip4_addr_t netmask_addr;
00486             ip4_addr_t gw_addr;
00487 
00488             if (!inet_aton(ip, &ip_addr) ||
00489                 !inet_aton(netmask, &netmask_addr) ||
00490                 !inet_aton(gw, &gw_addr)) {
00491                 return NSAPI_ERROR_PARAMETER ;
00492             }
00493 
00494             netif_set_addr(&netif, &ip_addr, &netmask_addr, &gw_addr);
00495         }
00496     }
00497 #endif
00498 
00499     if (client_callback) {
00500         client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE , NSAPI_STATUS_CONNECTING );
00501     }
00502 
00503     if (ppp) {
00504        err_t err = ppp_lwip_connect(hw);
00505        if (err) {
00506            connected = NSAPI_STATUS_DISCONNECTED ;
00507            if (client_callback) {
00508                client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE , NSAPI_STATUS_DISCONNECTED );
00509            }
00510           return err_remap(err);
00511        }
00512     }
00513 
00514     if (!netif_is_link_up(&netif)) {
00515         if (blocking) {
00516             if (osSemaphoreAcquire(linked, 15000) != osOK) {
00517                 if (ppp) {
00518                     (void) ppp_lwip_disconnect(hw);
00519                 }
00520                 return NSAPI_ERROR_NO_CONNECTION ;
00521             }
00522         }
00523     } else {
00524         nsapi_error_t ret = set_dhcp();
00525         if (ret != NSAPI_ERROR_OK ) {
00526             return ret;
00527         }
00528     }
00529 
00530     if (!blocking) {
00531         // Done enough - as addresses are acquired, there will be
00532         // connected callbacks.
00533         // XXX shouldn't this be NSAPI_ERROR_IN_PROGRESS if in CONNECTING state?
00534         return NSAPI_ERROR_OK ;
00535     }
00536 
00537     // If doesn't have address
00538     if (!LWIP::get_ip_addr(true, &netif)) {
00539         if (osSemaphoreAcquire(has_any_addr, DHCP_TIMEOUT * 1000) != osOK) {
00540             if (ppp) {
00541                 (void) ppp_lwip_disconnect(hw);
00542             }
00543             return NSAPI_ERROR_DHCP_FAILURE ;
00544         }
00545     }
00546 
00547 #if PREF_ADDR_TIMEOUT
00548     if (stack != IPV4_STACK && stack != IPV6_STACK) {
00549         // If address is not for preferred stack waits a while to see
00550         // if preferred stack address is acquired
00551         if (!LWIP::get_ip_addr(false, &netif)) {
00552             osSemaphoreAcquire(has_pref_addr, PREF_ADDR_TIMEOUT * 1000);
00553         }
00554     }
00555 #endif
00556 #if BOTH_ADDR_TIMEOUT
00557     if (stack != IPV4_STACK && stack != IPV6_STACK) {
00558         // If addresses for both stacks are not available waits a while to
00559         // see if address for both stacks are acquired
00560         if (!(LWIP::get_ipv4_addr(&netif) && LWIP::get_ipv6_addr(&netif))) {
00561             osSemaphoreAcquire(has_both_addr, BOTH_ADDR_TIMEOUT * 1000);
00562         }
00563     }
00564 #endif
00565 
00566     add_dns_addr(&netif);
00567 
00568     return NSAPI_ERROR_OK ;
00569 }
00570 
00571 nsapi_error_t LWIP::Interface::bringdown()
00572 {
00573     // Check if we've connected
00574     if (connected == NSAPI_STATUS_DISCONNECTED ) {
00575         return NSAPI_ERROR_PARAMETER ;
00576     }
00577 
00578 #if LWIP_DHCP
00579     // Disconnect from the network
00580     if (dhcp_started) {
00581         dhcp_release(&netif);
00582         dhcp_stop(&netif);
00583         dhcp_started = false;
00584         dhcp_has_to_be_set = false;
00585     }
00586 #endif
00587 
00588     if (ppp) {
00589         /* this is a blocking call, returns when PPP is properly closed */
00590        err_t err = ppp_lwip_disconnect(hw);
00591        if (err) {
00592            return err_remap(err);
00593        }
00594        MBED_ASSERT(!netif_is_link_up(&netif));
00595        /*if (netif_is_link_up(&netif)) {
00596            if (sys_arch_sem_wait(&unlinked, 15000) == SYS_ARCH_TIMEOUT) {
00597                return NSAPI_ERROR_DEVICE_ERROR;
00598            }
00599        }*/
00600     } else {
00601         netif_set_down(&netif);
00602     }
00603 
00604 #if LWIP_IPV6
00605     mbed_lwip_clear_ipv6_addresses(&netif);
00606 #endif
00607 #if LWIP_IPV4
00608     ip_addr_set_zero(&(netif.ip_addr));
00609     ip_addr_set_zero(&(netif.netmask));
00610     ip_addr_set_zero(&(netif.gw));
00611 #endif
00612 
00613     osSemaphoreDelete(has_any_addr);
00614     osSemaphoreAttr_t attr;
00615     attr.name = NULL;
00616     attr.attr_bits = 0;
00617     attr.cb_mem = &has_any_addr_sem;
00618     attr.cb_size = sizeof has_any_addr_sem;
00619     has_any_addr = osSemaphoreNew(UINT16_MAX, 0, &attr);
00620 #if PREF_ADDR_TIMEOUT
00621     osSemaphoreDelete(has_pref_addr);
00622     attr.cb_mem = &has_pref_addr_sem;
00623     attr.cb_size = sizeof has_pref_addr_sem;
00624     has_pref_addr = osSemaphoreNew(UINT16_MAX, 0, &attr);
00625 #endif
00626 #if BOTH_ADDR_TIMEOUT
00627     osSemaphoreDelete(has_both_addr);
00628     attr.cb_mem = &has_both_addr_sem;
00629     attr.cb_size = sizeof has_both_addr_sem;
00630     has_both_addr = osSemaphoreNew(UINT16_MAX, 0, &attr);
00631 #endif
00632     has_addr_state = 0;
00633 
00634     connected = NSAPI_STATUS_DISCONNECTED ;
00635     return 0;
00636 }