Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LWIPStack.h Source File

LWIPStack.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef LWIPSTACK_H_
00018 #define LWIPSTACK_H_
00019 
00020 #include "lwip/tcpip.h"
00021 #include "lwip/tcp.h"
00022 #include "lwip/ip.h"
00023 #include "lwip/api.h"
00024 #include "netif/etharp.h"
00025 #include "lwip/ethip6.h"
00026 #include "netsocket/nsapi_types.h"
00027 #include "netsocket/EMAC.h"
00028 #include "netsocket/L3IP.h"
00029 #include "netsocket/PPP.h"
00030 #include "netsocket/OnboardNetworkStack.h"
00031 #include "LWIPMemoryManager.h"
00032 
00033 
00034 class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
00035 public:
00036     using NetworkStack::get_ip_address;
00037     static LWIP &get_instance();
00038 
00039     class Interface : public OnboardNetworkStack::Interface {
00040     public:
00041         /** Connect the interface to the network
00042          *
00043          * Sets up a connection on specified network interface, using DHCP or provided network details. If the @a dhcp is set to
00044          * true all the remaining parameters are ignored.
00045          *
00046          * @param    dhcp       true if the network details should be acquired using DHCP
00047          * @param    ip         IP address to be used for the interface as "W:X:Y:Z" or NULL
00048          * @param    netmask    Net mask to be used for the interface as "W:X:Y:Z" or NULL
00049          * @param    gw         Gateway address to be used for the interface as "W:X:Y:Z" or NULL
00050          * @param    stack      Allow manual selection of IPv4 and/or IPv6.
00051          * @param    blocking   Specify whether bringup blocks for connection completion.
00052          * @return              NSAPI_ERROR_OK on success, or error code
00053          */
00054         virtual nsapi_error_t bringup(bool dhcp, const char *ip,
00055                                       const char *netmask, const char *gw,
00056                                       nsapi_ip_stack_t stack = DEFAULT_STACK,
00057                                       bool blocking = true
00058                                      );
00059 
00060         /** Disconnect interface from the network
00061          *
00062          * After this call the network interface is inactive, to use it again user needs to call @a mbed_ipstack_bringup again.
00063          *
00064          * @return    NSAPI_ERROR_OK on success, or error code
00065          */
00066         virtual nsapi_error_t bringdown();
00067 
00068         /** Register callback for status reporting
00069          *
00070          *  The specified status callback function will be called on status changes
00071          *  on the network. The parameters on the callback are the event type and
00072          *  event-type dependent reason parameter.
00073          *
00074          *  @param status_cb The callback for status changes
00075          */
00076         virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
00077 
00078         /** Get the connection status
00079          *
00080          *  @return         The connection status according to ConnectionStatusType
00081          */
00082         virtual nsapi_connection_status_t get_connection_status() const;
00083 
00084         /** Return netif interface name
00085          *
00086          * @return       netif name  eg "en0"
00087         */
00088         virtual char *get_interface_name(char *buf);
00089 
00090         /** Return MAC address of the network interface
00091          *
00092          * @return              MAC address as "V:W:X:Y:Z"
00093          */
00094         virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
00095 
00096         /** @copydoc NetworkStack::get_ip_address */
00097         virtual nsapi_error_t get_ip_address(SocketAddress *address);
00098 
00099         MBED_DEPRECATED_SINCE ("mbed-os-5.15", "String-based APIs are deprecated")
00100         virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
00101 
00102         /** Get the IPv6 link local address in SocketAddress representation
00103          *
00104          *  @address        SocketAddress representation of the link local IPv6 address
00105          *  @return         NSAPI_ERROR_OK on success, or error code
00106          */
00107         virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
00108 
00109         /** Copies netmask of the network interface to user supplied buffer
00110          *
00111          * @param    buf        buffer to which netmask will be copied as "W:X:Y:Z"
00112          * @param    buflen     size of supplied buffer
00113          * @return              Pointer to a buffer, or NULL if the buffer is too small
00114          */
00115         virtual nsapi_error_t get_netmask(SocketAddress *address);
00116 
00117         MBED_DEPRECATED_SINCE ("mbed-os-5.15", "String-based APIs are deprecated")
00118         virtual char *get_netmask(char *buf, nsapi_size_t buflen);
00119 
00120         /** Copies gateway address of the network interface to user supplied buffer
00121          *
00122          * @param    buf        buffer to which gateway address will be copied as "W:X:Y:Z"
00123          * @param    buflen     size of supplied buffer
00124          * @return              Pointer to a buffer, or NULL if the buffer is too small
00125          */
00126         virtual nsapi_error_t get_gateway(SocketAddress *address);
00127 
00128         MBED_DEPRECATED_SINCE ("mbed-os-5.15", "String-based APIs are deprecated")
00129         virtual char *get_gateway(char *buf, nsapi_size_t buflen);
00130 
00131     private:
00132         friend class LWIP;
00133 
00134         Interface();
00135 
00136         nsapi_error_t set_dhcp();
00137         static void netif_link_irq(struct netif *netif);
00138         static void netif_status_irq(struct netif *netif);
00139         static Interface *our_if_from_netif(struct netif *netif);
00140 
00141 #if LWIP_ETHERNET
00142         static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
00143         void emac_input(net_stack_mem_buf_t *buf);
00144         void emac_state_change(bool up);
00145 #if LWIP_IGMP
00146         static err_t emac_igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action);
00147 #endif
00148 #if LWIP_IPV6_MLD
00149         static err_t emac_mld_mac_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action);
00150 #endif
00151 
00152         static err_t emac_if_init(struct netif *netif);
00153 #endif
00154 
00155 #if LWIP_L3IP
00156 #if LWIP_IPV4
00157         static err_t l3ip4_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr);
00158 #endif
00159 #if LWIP_IPV6
00160         static err_t l3ip6_output(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
00161 #endif
00162         void l3ip_input(net_stack_mem_buf_t *buf);
00163         void l3ip_state_change(bool up);
00164 #if LWIP_IGMP
00165         static err_t l3ip_multicast_ipv4_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action);
00166 #endif
00167 #if LWIP_IPV6_MLD
00168         static err_t l3ip_multicast_ipv6_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action);
00169 #endif
00170 
00171         static err_t l3ip_if_init(struct netif *netif);
00172 #endif
00173 
00174 #if PPP_SUPPORT
00175 #if PPP_IPV4_SUPPORT && LWIP_IPV4
00176         static err_t ppp4_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr);
00177 #endif
00178 #if PPP_IPV6_SUPPORT && LWIP_IPV6
00179         static err_t ppp6_output(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
00180 #endif
00181         void ppp_input(net_stack_mem_buf_t *buf);
00182         void ppp_state_change(bool up);
00183         static err_t ppp_if_init(struct netif *netif);
00184 #endif
00185 
00186         union {
00187 #if LWIP_ETHERNET
00188             EMAC *emac; /**< HW specific emac implementation */
00189 #endif
00190 #if LWIP_L3IP
00191             L3IP *l3ip; /**<  L3IP implementation */
00192 #endif
00193 #if PPP_SUPPORT
00194             PPP *ppp; /**< PPP implementation */
00195 #endif
00196             void *hw; /**< alternative implementation pointer - used for PPP */
00197         };
00198 
00199         mbed_rtos_storage_semaphore_t linked_sem;
00200         osSemaphoreId_t linked;
00201         mbed_rtos_storage_semaphore_t unlinked_sem;
00202         osSemaphoreId_t unlinked;
00203         mbed_rtos_storage_semaphore_t has_any_addr_sem;
00204         osSemaphoreId_t has_any_addr;
00205 #define HAS_ANY_ADDR 1
00206 #if PREF_ADDR_TIMEOUT
00207         mbed_rtos_storage_semaphore_t has_pref_addr_sem;
00208         osSemaphoreId_t has_pref_addr;
00209 #define HAS_PREF_ADDR 2
00210 #endif
00211 #if BOTH_ADDR_TIMEOUT
00212         mbed_rtos_storage_semaphore_t has_both_addr_sem;
00213         osSemaphoreId_t has_both_addr;
00214 #define HAS_BOTH_ADDR 4
00215 #endif
00216         char _interface_name[NSAPI_INTERFACE_NAME_MAX_SIZE];
00217         char has_addr_state;
00218         nsapi_connection_status_t connected;
00219         bool dhcp_started;
00220         bool dhcp_has_to_be_set;
00221         bool blocking;
00222         bool ppp_enabled;
00223         mbed::Callback<void(nsapi_event_t, intptr_t)> client_callback;
00224         struct netif netif;
00225         static Interface *list;
00226         Interface *next;
00227         LWIPMemoryManager *memory_manager;
00228     };
00229 
00230     /** Register a network interface with the IP stack
00231      *
00232      * Connects EMAC layer with the IP stack and initializes all the required infrastructure.
00233      * This function should be called only once for each available interface.
00234      *
00235      * @param      emac             EMAC HAL implementation for this network interface
00236      * @param      default_if       true if the interface should be treated as the default one
00237      * @param[out] interface_out    pointer to stack interface object controlling the EMAC
00238      * @return                      NSAPI_ERROR_OK on success, or error code
00239      */
00240     virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out);
00241 
00242     /** Register a network interface with the IP stack
00243      *
00244      * Connects L3IP layer with the IP stack and initializes all the required infrastructure.
00245      * This function should be called only once for each available interface.
00246      *
00247      * @param      l3ip             L3IP HAL implementation for this network interface
00248      * @param      default_if       true if the interface should be treated as the default one
00249      * @param[out] interface_out    pointer to stack interface object controlling the L3IP
00250      * @return                      NSAPI_ERROR_OK on success, or error code
00251      */
00252     virtual nsapi_error_t add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetworkStack::Interface **interface_out);
00253 
00254     /** Register a PPP interface with the IP stack
00255      *
00256      * Connects PPP layer with the IP stack and initializes all the required infrastructure.
00257      * This function should be called only once for each available interface.
00258      *
00259      * This is an internal function that links ppp_lwip.cpp to mbed_ipstack_lwip.cpp,
00260      * once a driver starts it via the nsapi_ppp.h API.
00261      *
00262      * Ultimately the nsapi_ppp.h API will be deprecated, and there will be a
00263      * mbed_ipstack_add_ppp_interface() replacing nsapi_ppp_connect().
00264      *
00265      * @param      pcb              PPP implementation specific user data; will be passed to PPP callbacks
00266      * @param      default_if       true if the interface should be treated as the default one
00267      * @param      stack            Allow manual selection of IPv4 and/or IPv6
00268      * @param[out] interface_out    set to interface handle that must be passed to subsequent mbed_stack calls
00269      * @return                      NSAPI_ERROR_OK on success, or error code
00270      */
00271     virtual nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out);
00272 
00273     /** Remove a network interface from IP stack
00274      *
00275      * Removes layer 3 IP objects,network interface from stack list, and shutdown device driver .
00276      * @param[out] interface_out    pointer to stack interface object controlling the L3IP
00277      * @return                      NSAPI_ERROR_OK on success, or error code
00278      */
00279     virtual nsapi_error_t remove_l3ip_interface(OnboardNetworkStack::Interface **interface_out);
00280 
00281     /** Remove a network interface from IP stack
00282      *
00283      * Removes PPP objects,network interface from stack list, and shutdown device driver.
00284      * @param[out] interface_out    pointer to stack interface object controlling the PPP
00285      * @return                      NSAPI_ERROR_OK on success, or error code
00286      */
00287     virtual nsapi_error_t remove_ppp_interface(OnboardNetworkStack::Interface **interface_out);
00288 
00289     /** Get a domain name server from a list of servers to query
00290      *
00291      *  Returns a DNS server address for a index. If returns error no more
00292      *  DNS servers to read.
00293      *
00294      *  @param index    Index of the DNS server, starts from zero
00295      *  @param address  Destination for the host address
00296      *  @return         0 on success, negative error code on failure
00297      */
00298     virtual nsapi_error_t get_dns_server(int index, SocketAddress *address, const char *interface_name);
00299 
00300     /** Add a domain name server to list of servers to query
00301      *
00302      *  @param address  Destination for the host address
00303      *  @param interface_name  Network interface name
00304      *  @return         NSAPI_ERROR_OK on success, negative error code on failure
00305      */
00306     virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name);
00307 
00308     /** Get the local IP address
00309      *
00310      *  @return         Null-terminated representation of the local IP address
00311      *                  or null if not yet connected
00312      */
00313     virtual const char *get_ip_address();
00314 
00315     /** Copies IP address of the name based network interface to user supplied buffer
00316      *
00317      * @param    address        SocketAddress object pointer to store the address
00318      * @param    interface_name name of the interface
00319      * @return                  Pointer to a buffer, or NULL if the buffer is too small
00320      */
00321     virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name);
00322 
00323     /** Set the network interface as default one
00324       */
00325     virtual void set_default_interface(OnboardNetworkStack::Interface *interface);
00326 
00327 protected:
00328     LWIP();
00329     virtual ~LWIP() {}
00330 
00331     /** Opens a socket
00332      *
00333      *  Creates a network socket and stores it in the specified handle.
00334      *  The handle must be passed to following calls on the socket.
00335      *
00336      *  A stack may have a finite number of sockets, in this case
00337      *  NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
00338      *
00339      *  @param handle   Destination for the handle to a newly created socket
00340      *  @param proto    Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
00341      *  @return         0 on success, negative error code on failure
00342      */
00343     virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto);
00344 
00345     /** Close the socket
00346      *
00347      *  Closes any open connection and deallocates any memory associated
00348      *  with the socket.
00349      *
00350      *  @param handle   Socket handle
00351      *  @return         0 on success, negative error code on failure
00352      */
00353     virtual nsapi_error_t socket_close(nsapi_socket_t handle);
00354 
00355     /** Bind a specific address to a socket
00356      *
00357      *  Binding a socket specifies the address and port on which to recieve
00358      *  data. If the IP address is zeroed, only the port is bound.
00359      *
00360      *  @param handle   Socket handle
00361      *  @param address  Local address to bind
00362      *  @return         0 on success, negative error code on failure.
00363      */
00364     virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address);
00365 
00366     /** Listen for connections on a TCP socket
00367      *
00368      *  Marks the socket as a passive socket that can be used to accept
00369      *  incoming connections.
00370      *
00371      *  @param handle   Socket handle
00372      *  @param backlog  Number of pending connections that can be queued
00373      *                  simultaneously
00374      *  @return         0 on success, negative error code on failure
00375      */
00376     virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
00377 
00378     /** Connects TCP socket to a remote host
00379      *
00380      *  Initiates a connection to a remote server specified by the
00381      *  indicated address.
00382      *
00383      *  @param handle   Socket handle
00384      *  @param address  The SocketAddress of the remote host
00385      *  @return         0 on success, negative error code on failure
00386      */
00387     virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
00388 
00389     /** Accepts a connection on a TCP socket
00390      *
00391      *  The server socket must be bound and set to listen for connections.
00392      *  On a new connection, creates a network socket and stores it in the
00393      *  specified handle. The handle must be passed to following calls on
00394      *  the socket.
00395      *
00396      *  A stack may have a finite number of sockets, in this case
00397      *  NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
00398      *
00399      *  This call is non-blocking. If accept would block,
00400      *  NSAPI_ERROR_WOULD_BLOCK is returned immediately.
00401      *
00402      *  @param server   Socket handle to server to accept from
00403      *  @param handle   Destination for a handle to the newly created socket
00404      *  @param address  Destination for the remote address or NULL
00405      *  @return         0 on success, negative error code on failure
00406      */
00407     virtual nsapi_error_t socket_accept(nsapi_socket_t server,
00408                                         nsapi_socket_t *handle, SocketAddress *address = 0);
00409 
00410     /** Send data over a TCP socket
00411      *
00412      *  The socket must be connected to a remote host. Returns the number of
00413      *  bytes sent from the buffer.
00414      *
00415      *  This call is non-blocking. If send would block,
00416      *  NSAPI_ERROR_WOULD_BLOCK is returned immediately.
00417      *
00418      *  @param handle   Socket handle
00419      *  @param data     Buffer of data to send to the host
00420      *  @param size     Size of the buffer in bytes
00421      *  @return         Number of sent bytes on success, negative error
00422      *                  code on failure
00423      */
00424     virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle,
00425                                               const void *data, nsapi_size_t size);
00426 
00427     /** Receive data over a TCP socket
00428      *
00429      *  The socket must be connected to a remote host. Returns the number of
00430      *  bytes received into the buffer.
00431      *
00432      *  This call is non-blocking. If recv would block,
00433      *  NSAPI_ERROR_WOULD_BLOCK is returned immediately.
00434      *
00435      *  @param handle   Socket handle
00436      *  @param data     Destination buffer for data received from the host
00437      *  @param size     Size of the buffer in bytes
00438      *  @return         Number of received bytes on success, negative error
00439      *                  code on failure
00440      */
00441     virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle,
00442                                               void *data, nsapi_size_t size);
00443 
00444     /** Send a packet over a UDP socket
00445      *
00446      *  Sends data to the specified address. Returns the number of bytes
00447      *  sent from the buffer.
00448      *
00449      *  This call is non-blocking. If sendto would block,
00450      *  NSAPI_ERROR_WOULD_BLOCK is returned immediately.
00451      *
00452      *  @param handle   Socket handle
00453      *  @param address  The SocketAddress of the remote host
00454      *  @param data     Buffer of data to send to the host
00455      *  @param size     Size of the buffer in bytes
00456      *  @return         Number of sent bytes on success, negative error
00457      *                  code on failure
00458      */
00459     virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address,
00460                                                 const void *data, nsapi_size_t size);
00461 
00462     /** Receive a packet over a UDP socket
00463      *
00464      *  Receives data and stores the source address in address if address
00465      *  is not NULL. Returns the number of bytes received into the buffer.
00466      *
00467      *  This call is non-blocking. If recvfrom would block,
00468      *  NSAPI_ERROR_WOULD_BLOCK is returned immediately.
00469      *
00470      *  @param handle   Socket handle
00471      *  @param address  Destination for the source address or NULL
00472      *  @param buffer   Destination buffer for data received from the host
00473      *  @param size     Size of the buffer in bytes
00474      *  @return         Number of received bytes on success, negative error
00475      *                  code on failure
00476      */
00477     virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address,
00478                                                   void *buffer, nsapi_size_t size);
00479 
00480     /** Register a callback on state change of the socket
00481      *
00482      *  The specified callback will be called on state changes such as when
00483      *  the socket can recv/send/accept successfully and on when an error
00484      *  occurs. The callback may also be called spuriously without reason.
00485      *
00486      *  The callback may be called in an interrupt context and should not
00487      *  perform expensive operations such as recv/send calls.
00488      *
00489      *  @param handle   Socket handle
00490      *  @param callback Function to call on state change
00491      *  @param data     Argument to pass to callback
00492      */
00493     virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data);
00494 
00495     /*  Set stack-specific socket options
00496      *
00497      *  The setsockopt allow an application to pass stack-specific hints
00498      *  to the underlying stack. For unsupported options,
00499      *  NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
00500      *
00501      *  @param handle   Socket handle
00502      *  @param level    Stack-specific protocol level
00503      *  @param optname  Stack-specific option identifier
00504      *  @param optval   Option value
00505      *  @param optlen   Length of the option value
00506      *  @return         0 on success, negative error code on failure
00507      */
00508     virtual nsapi_error_t setsockopt(nsapi_socket_t handle, int level,
00509                                      int optname, const void *optval, unsigned optlen);
00510 
00511     /*  Get stack-specific socket options
00512      *
00513      *  The getstackopt allow an application to retrieve stack-specific hints
00514      *  from the underlying stack. For unsupported options,
00515      *  NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
00516      *
00517      *  @param handle   Socket handle
00518      *  @param level    Stack-specific protocol level
00519      *  @param optname  Stack-specific option identifier
00520      *  @param optval   Destination for option value
00521      *  @param optlen   Length of the option value
00522      *  @return         0 on success, negative error code on failure
00523      */
00524     virtual nsapi_error_t getsockopt(nsapi_socket_t handle, int level,
00525                                      int optname, void *optval, unsigned *optlen);
00526 private:
00527 
00528     /** Call in callback
00529       *
00530       *  Callback is used to call the call in method of the network stack.
00531       */
00532     typedef mbed::Callback<nsapi_error_t (int delay_ms, mbed::Callback<void()> user_cb)> call_in_callback_cb_t;
00533 
00534     /** Get a call in callback
00535      *
00536      *  Get a call in callback from the network stack context.
00537      *
00538      *  Callback should not take more than 10ms to execute, otherwise it might
00539      *  prevent underlying thread processing. A portable user of the callback
00540      *  should not make calls to network operations due to stack size limitations.
00541      *  The callback should not perform expensive operations such as socket recv/send
00542      *  calls or blocking operations.
00543      *
00544      *  @return         Call in callback
00545      */
00546     virtual call_in_callback_cb_t get_call_in_callback();
00547 
00548     /** Call a callback after a delay
00549      *
00550      *  Call a callback from the network stack context after a delay. If function
00551      *  returns error callback will not be called.
00552      *
00553      *  @param delay    Delay in milliseconds
00554      *  @param func     Callback to be called
00555      *  @return         0 on success, negative error code on failure
00556      */
00557     virtual nsapi_error_t call_in(int delay, mbed::Callback<void()> func);
00558 
00559     struct mbed_lwip_socket {
00560         bool in_use;
00561 
00562         struct netconn *conn;
00563         struct pbuf *buf;
00564         u16_t offset;
00565 
00566         void (*cb)(void *);
00567         void *data;
00568 
00569         // Track multicast addresses subscribed to by this socket
00570         nsapi_ip_mreq_t *multicast_memberships;
00571         uint32_t         multicast_memberships_count;
00572         uint32_t         multicast_memberships_registry;
00573     };
00574 
00575     struct lwip_callback {
00576         unsigned int delay;
00577         mbed::Callback<void()> callback;
00578     };
00579 
00580     static nsapi_error_t err_remap(err_t err);
00581     static bool is_local_addr(const ip_addr_t *ip_addr);
00582     static const ip_addr_t *get_ip_addr(bool any_addr, const struct netif *netif);
00583     static const ip_addr_t *get_ipv4_addr(const struct netif *netif);
00584     static const ip_addr_t *get_ipv6_addr(const struct netif *netif);
00585     static const ip_addr_t *get_ipv6_link_local_addr(const struct netif *netif);
00586 
00587     static void add_dns_addr(struct netif *lwip_netif, const char *interface_name);
00588 
00589     /* Static arena of sockets */
00590     struct mbed_lwip_socket arena[MEMP_NUM_NETCONN];
00591     void arena_init(void);
00592     struct mbed_lwip_socket *arena_alloc();
00593     void arena_dealloc(struct mbed_lwip_socket *s);
00594 
00595     static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
00596     {
00597         while (!(s->multicast_memberships_registry & (0x0001 << index))) {
00598             index++;
00599         }
00600         return index;
00601     }
00602 
00603     static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
00604     {
00605         while ((s->multicast_memberships_registry & (0x0001 << index))) {
00606             index++;
00607         }
00608         return index;
00609     }
00610 
00611     static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
00612     {
00613         s->multicast_memberships_registry |= (0x0001 << index);
00614     }
00615 
00616     static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
00617     {
00618         s->multicast_memberships_registry &= ~(0x0001 << index);
00619     }
00620     static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr);
00621 
00622     static void socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len);
00623 
00624     static void tcpip_init_irq(void *handle);
00625     static void tcpip_thread_callback(void *ptr);
00626 
00627     char ip_address[40];
00628     Interface *default_interface;
00629     LWIPMemoryManager memory_manager;
00630     osThreadId tcpip_thread_id;
00631     rtos::Mutex adaptation;
00632     rtos::EventFlags _event_flag;
00633     static const int TCP_CLOSED_FLAG = 0x4u;
00634 };
00635 
00636 #endif /* LWIPSTACK_H_ */