Mistake on this page?
Report an issue in GitHub or email us
LWIPStack.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2017 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LWIPSTACK_H_
18 #define LWIPSTACK_H_
19 
20 #include "lwip/tcpip.h"
21 #include "lwip/tcp.h"
22 #include "lwip/ip.h"
23 #include "lwip/api.h"
24 #include "netif/etharp.h"
25 #include "lwip/ethip6.h"
26 #include "netsocket/nsapi_types.h"
27 #include "netsocket/EMAC.h"
28 #include "netsocket/L3IP.h"
29 #include "netsocket/PPP.h"
30 #include "netsocket/OnboardNetworkStack.h"
31 #include "LWIPMemoryManager.h"
32 
33 #if LWIP_IPV6
34 #include "lwip/ip6_addr.h"
35 #define IP_ADDR_VALID IP6_ADDR_VALID
36 #else
37 #define IP_ADDR_VALID 0
38 #endif
39 
40 class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
41 public:
43  static LWIP &get_instance();
44 
46  public:
47  /** Set IP address to LWIP stack
48  *
49  * This function can set both IPv4 or IPv6 address to LWIP stack.
50  *
51  * bringup() can only take one IP address and in dual stack case
52  * another IP address can be set using this function.
53  *
54  * IPv4 or IPv6 address should be in format of https://tools.ietf.org/html/draft-main-ipaddr-text-rep-00.
55  *
56  * @param ip IP address to be used for the interface as IPv4 or IPv6 address string.
57  * This parameter should not be NULL.
58  * @param netmask Net mask to be used for the interface as IPv4 address string or NULL.
59  * NULL value will set this value to 255.255.255.255.
60  * This parameter will be ignored for IPv6 ip argument.
61  * @param gw Gateway address to be used for the interface as IPv4 address string or NULL
62  * NULL value will set this value to 0.0.0.0
63  * This parameter will be ignored for IPv6 ip argument.
64  * @param ipv6_flag Provide this flag for IPv6 state flag override. For example, you can set IP6_ADDR_PREFERRED.
65  * Default value is IP6_ADDR_VALID. For IPv4, this value will be ignored.
66  * @return NSAPI_ERROR_OK on success, or error code
67  */
68  nsapi_error_t set_ip_address(const char *ip,
69  const char *netmask,
70  const char *gw,
71  uint8_t ipv6_flag = IP_ADDR_VALID
72  ) override;
73 
74  /** Connect the interface to the network
75  *
76  * Sets up a connection on specified network interface, using DHCP or provided network details. If the @a dhcp is set to
77  * true all the remaining parameters are ignored.
78  *
79  * @param dhcp true if the network details should be acquired using DHCP
80  * @param ip IP address to be used for the interface as "W:X:Y:Z" or NULL
81  * @param netmask Net mask to be used for the interface as "W:X:Y:Z" or NULL
82  * @param gw Gateway address to be used for the interface as "W:X:Y:Z" or NULL
83  * @param stack Allow manual selection of IPv4 and/or IPv6.
84  * @param blocking Specify whether bringup blocks for connection completion.
85  * @return NSAPI_ERROR_OK on success, or error code
86  */
87  nsapi_error_t bringup(bool dhcp, const char *ip,
88  const char *netmask, const char *gw,
89  nsapi_ip_stack_t stack = DEFAULT_STACK,
90  bool blocking = true
91  ) override;
92 
93  /** Disconnect interface from the network
94  *
95  * After this call the network interface is inactive, to use it again user needs to call @a mbed_ipstack_bringup again.
96  *
97  * @return NSAPI_ERROR_OK on success, or error code
98  */
99  nsapi_error_t bringdown() override;
100 
101  /** Register callback for status reporting
102  *
103  * The specified status callback function will be called on status changes
104  * on the network. The parameters on the callback are the event type and
105  * event-type dependent reason parameter.
106  *
107  * @param status_cb The callback for status changes
108  */
109  void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
110 
111  /** Get the connection status
112  *
113  * @return The connection status according to ConnectionStatusType
114  */
115  nsapi_connection_status_t get_connection_status() const override;
116 
117  /** Return netif interface name
118  *
119  * @return netif name eg "en0"
120  */
121  char *get_interface_name(char *buf) override;
122 
123  /** Return MAC address of the network interface
124  *
125  * @return MAC address as "V:W:X:Y:Z"
126  */
127  char *get_mac_address(char *buf, nsapi_size_t buflen) override;
128 
129  /** @copydoc OnboardNetworkStack::Interface::get_ip_address */
130  nsapi_error_t get_ip_address(SocketAddress *address) override;
131 
132  /** Get the IPv6 link local address in SocketAddress representation
133  *
134  * @address SocketAddress representation of the link local IPv6 address
135  * @return NSAPI_ERROR_OK on success, or error code
136  */
138 
139  /** Copies netmask of the network interface to user supplied buffer
140  *
141  * @param buf buffer to which netmask will be copied as "W:X:Y:Z"
142  * @param buflen size of supplied buffer
143  * @return Pointer to a buffer, or NULL if the buffer is too small
144  */
145  nsapi_error_t get_netmask(SocketAddress *address) override;
146 
147  /** Copies gateway address of the network interface to user supplied buffer
148  *
149  * @param buf buffer to which gateway address will be copied as "W:X:Y:Z"
150  * @param buflen size of supplied buffer
151  * @return Pointer to a buffer, or NULL if the buffer is too small
152  */
153  nsapi_error_t get_gateway(SocketAddress *address) override;
154 
155  private:
156  friend class LWIP;
157 
158  Interface();
159 
160  nsapi_error_t set_dhcp();
161  static void netif_link_irq(struct netif *netif);
162  static void netif_status_irq(struct netif *netif);
163  static Interface *our_if_from_netif(struct netif *netif);
164  static void delete_interface(OnboardNetworkStack::Interface **interface_out);
165 
166 #if LWIP_ETHERNET
167  static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
168  void emac_input(net_stack_mem_buf_t *buf);
169  void emac_state_change(bool up);
170 #if LWIP_IGMP
171  static err_t emac_igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action);
172 #endif
173 #if LWIP_IPV6_MLD
174  static err_t emac_mld_mac_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action);
175 #endif
176 
177  static err_t emac_if_init(struct netif *netif);
178 #endif
179 
180 #if LWIP_L3IP
181 #if LWIP_IPV4
182  static err_t l3ip4_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr);
183 #endif
184 #if LWIP_IPV6
185  static err_t l3ip6_output(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
186 #endif
187  void l3ip_input(net_stack_mem_buf_t *buf);
188  void l3ip_state_change(bool up);
189 #if LWIP_IGMP
190  static err_t l3ip_multicast_ipv4_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action);
191 #endif
192 #if LWIP_IPV6_MLD
193  static err_t l3ip_multicast_ipv6_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action);
194 #endif
195 
196  static err_t l3ip_if_init(struct netif *netif);
197 #endif
198 
199 #if PPP_SUPPORT
200 #if PPP_IPV4_SUPPORT && LWIP_IPV4
201  static err_t ppp4_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr);
202 #endif
203 #if PPP_IPV6_SUPPORT && LWIP_IPV6
204  static err_t ppp6_output(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
205 #endif
206  void ppp_input(net_stack_mem_buf_t *buf);
207  void ppp_state_change(bool up);
208  static err_t ppp_if_init(struct netif *netif);
209 #endif
210 
211  union {
212 #if LWIP_ETHERNET
213  EMAC *emac; /**< HW specific emac implementation */
214 #endif
215 #if LWIP_L3IP
216  L3IP *l3ip; /**< L3IP implementation */
217 #endif
218 #if PPP_SUPPORT
219  PPP *ppp; /**< PPP implementation */
220 #endif
221  void *hw; /**< alternative implementation pointer - used for PPP */
222  };
223 
224  mbed_rtos_storage_semaphore_t remove_interface_sem;
225  osSemaphoreId_t remove_interface;
226  mbed_rtos_storage_semaphore_t linked_sem;
227  osSemaphoreId_t linked;
228  mbed_rtos_storage_semaphore_t unlinked_sem;
229  osSemaphoreId_t unlinked;
230  mbed_rtos_storage_semaphore_t has_any_addr_sem;
231  osSemaphoreId_t has_any_addr;
232 #define HAS_ANY_ADDR 1
233 #if PREF_ADDR_TIMEOUT
234  mbed_rtos_storage_semaphore_t has_pref_addr_sem;
235  osSemaphoreId_t has_pref_addr;
236 #define HAS_PREF_ADDR 2
237 #endif
238 #if BOTH_ADDR_TIMEOUT
239  mbed_rtos_storage_semaphore_t has_both_addr_sem;
240  osSemaphoreId_t has_both_addr;
241 #define HAS_BOTH_ADDR 4
242 #endif
243  char _interface_name[NSAPI_INTERFACE_NAME_MAX_SIZE];
244  char has_addr_state;
245  nsapi_connection_status_t connected;
246  bool dhcp_started;
247  bool dhcp_has_to_be_set;
248  bool blocking;
249  bool ppp_enabled;
251  struct netif netif;
252  static Interface *list;
253  Interface *next;
255  };
256 
257  /** Register a network interface with the IP stack
258  *
259  * Connects EMAC layer with the IP stack and initializes all the required infrastructure.
260  * This function should be called only once for each available interface.
261  *
262  * @param emac EMAC HAL implementation for this network interface
263  * @param default_if true if the interface should be treated as the default one
264  * @param[out] interface_out pointer to stack interface object controlling the EMAC
265  * @return NSAPI_ERROR_OK on success, or error code
266  */
267  nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out) override;
268 
269  /** Register a network interface with the IP stack
270  *
271  * Connects L3IP layer with the IP stack and initializes all the required infrastructure.
272  * This function should be called only once for each available interface.
273  *
274  * @param l3ip L3IP HAL implementation for this network interface
275  * @param default_if true if the interface should be treated as the default one
276  * @param[out] interface_out pointer to stack interface object controlling the L3IP
277  * @return NSAPI_ERROR_OK on success, or error code
278  */
279  nsapi_error_t add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetworkStack::Interface **interface_out) override;
280 
281  /** Register a PPP interface with the IP stack
282  *
283  * Connects PPP layer with the IP stack and initializes all the required infrastructure.
284  * This function should be called only once for each available interface.
285  *
286  * This is an internal function that links ppp_lwip.cpp to mbed_ipstack_lwip.cpp,
287  * once a driver starts it via the nsapi_ppp.h API.
288  *
289  * Ultimately the nsapi_ppp.h API will be deprecated, and there will be a
290  * mbed_ipstack_add_ppp_interface() replacing nsapi_ppp_connect().
291  *
292  * @param pcb PPP implementation specific user data; will be passed to PPP callbacks
293  * @param default_if true if the interface should be treated as the default one
294  * @param stack Allow manual selection of IPv4 and/or IPv6
295  * @param[out] interface_out set to interface handle that must be passed to subsequent mbed_stack calls
296  * @return NSAPI_ERROR_OK on success, or error code
297  */
298  nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out) override;
299 
300  /** Remove a network interface from IP stack
301  *
302  * Removes layer 3 IP objects,network interface from stack list .
303  * @param[out] interface_out pointer to stack interface object controlling the EMAC
304  * @return NSAPI_ERROR_OK on success, or error code
305  */
307 
308  /** Remove a network interface from IP stack
309  *
310  * Removes PPP objects,network interface from stack list, and shutdown device driver.
311  * @param[out] interface_out pointer to stack interface object controlling the PPP
312  * @return NSAPI_ERROR_OK on success, or error code
313  */
315 
316  /** Remove a network interface from IP stack
317  *
318  * Removes PPP objects,network interface from stack list, and shutdown device driver.
319  * @param[out] interface_out pointer to stack interface object controlling the PPP
320  * @return NSAPI_ERROR_OK on success, or error code
321  */
323 
324  /** Get a domain name server from a list of servers to query
325  *
326  * Returns a DNS server address for a index. If returns error no more
327  * DNS servers to read.
328  *
329  * @param index Index of the DNS server, starts from zero
330  * @param address Destination for the host address
331  * @return 0 on success, negative error code on failure
332  */
333  nsapi_error_t get_dns_server(int index, SocketAddress *address, const char *interface_name) override;
334 
335  /** Add a domain name server to list of servers to query
336  *
337  * @param address Destination for the host address
338  * @param interface_name Network interface name
339  * @return NSAPI_ERROR_OK on success, negative error code on failure
340  */
341  nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name) override;
342 
343  /** @copydoc NetworkStack::get_ip_address */
344  nsapi_error_t get_ip_address(SocketAddress *address) override;
345 
346  /** @copydoc NetworkStack::get_ip_address_if */
347  nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name) override;
348 
349  /** Set the network interface as default one
350  */
351  void set_default_interface(OnboardNetworkStack::Interface *interface) override;
352 
353 protected:
354  LWIP();
355 
356  /** Opens a socket
357  *
358  * Creates a network socket and stores it in the specified handle.
359  * The handle must be passed to following calls on the socket.
360  *
361  * A stack may have a finite number of sockets, in this case
362  * NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
363  *
364  * @param handle Destination for the handle to a newly created socket
365  * @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
366  * @return 0 on success, negative error code on failure
367  */
368  nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) override;
369 
370  /** Close the socket
371  *
372  * Closes any open connection and deallocates any memory associated
373  * with the socket.
374  *
375  * @param handle Socket handle
376  * @return 0 on success, negative error code on failure
377  */
378  nsapi_error_t socket_close(nsapi_socket_t handle) override;
379 
380  /** Bind a specific address to a socket
381  *
382  * Binding a socket specifies the address and port on which to recieve
383  * data. If the IP address is zeroed, only the port is bound.
384  *
385  * @param handle Socket handle
386  * @param address Local address to bind
387  * @return 0 on success, negative error code on failure.
388  */
389  nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) override;
390 
391  /** Listen for connections on a TCP socket
392  *
393  * Marks the socket as a passive socket that can be used to accept
394  * incoming connections.
395  *
396  * @param handle Socket handle
397  * @param backlog Number of pending connections that can be queued
398  * simultaneously
399  * @return 0 on success, negative error code on failure
400  */
401  nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) override;
402 
403  /** Connects TCP socket to a remote host
404  *
405  * Initiates a connection to a remote server specified by the
406  * indicated address.
407  *
408  * @param handle Socket handle
409  * @param address The SocketAddress of the remote host
410  * @return 0 on success, negative error code on failure
411  */
412  nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) override;
413 
414  /** Accepts a connection on a TCP socket
415  *
416  * The server socket must be bound and set to listen for connections.
417  * On a new connection, creates a network socket and stores it in the
418  * specified handle. The handle must be passed to following calls on
419  * the socket.
420  *
421  * A stack may have a finite number of sockets, in this case
422  * NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
423  *
424  * This call is non-blocking. If accept would block,
425  * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
426  *
427  * @param server Socket handle to server to accept from
428  * @param handle Destination for a handle to the newly created socket
429  * @param address Destination for the remote address or NULL
430  * @return 0 on success, negative error code on failure
431  */
433  nsapi_socket_t *handle, SocketAddress *address = 0) override;
434 
435  /** Send data over a TCP socket
436  *
437  * The socket must be connected to a remote host. Returns the number of
438  * bytes sent from the buffer.
439  *
440  * This call is non-blocking. If send would block,
441  * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
442  *
443  * @param handle Socket handle
444  * @param data Buffer of data to send to the host
445  * @param size Size of the buffer in bytes
446  * @return Number of sent bytes on success, negative error
447  * code on failure
448  */
450  const void *data, nsapi_size_t size) override;
451 
452  /** Receive data over a TCP socket
453  *
454  * The socket must be connected to a remote host. Returns the number of
455  * bytes received into the buffer.
456  *
457  * This call is non-blocking. If recv would block,
458  * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
459  *
460  * @param handle Socket handle
461  * @param data Destination buffer for data received from the host
462  * @param size Size of the buffer in bytes
463  * @return Number of received bytes on success, negative error
464  * code on failure
465  */
467  void *data, nsapi_size_t size) override;
468 
469  /** Send a packet over a UDP socket
470  *
471  * Sends data to the specified address. Returns the number of bytes
472  * sent from the buffer.
473  *
474  * This call is non-blocking. If sendto would block,
475  * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
476  *
477  * @param handle Socket handle
478  * @param address The SocketAddress of the remote host
479  * @param data Buffer of data to send to the host
480  * @param size Size of the buffer in bytes
481  * @return Number of sent bytes on success, negative error
482  * code on failure
483  */
485  const void *data, nsapi_size_t size) override;
486 
487  /** Receive a packet over a UDP socket
488  *
489  * Receives data and stores the source address in address if address
490  * is not NULL. Returns the number of bytes received into the buffer.
491  *
492  * This call is non-blocking. If recvfrom would block,
493  * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
494  *
495  * @param handle Socket handle
496  * @param address Destination for the source address or NULL
497  * @param buffer Destination buffer for data received from the host
498  * @param size Size of the buffer in bytes
499  * @return Number of received bytes on success, negative error
500  * code on failure
501  */
503  void *buffer, nsapi_size_t size) override;
504 
505  /** Register a callback on state change of the socket
506  *
507  * The specified callback will be called on state changes such as when
508  * the socket can recv/send/accept successfully and on when an error
509  * occurs. The callback may also be called spuriously without reason.
510  *
511  * The callback may be called in an interrupt context and should not
512  * perform expensive operations such as recv/send calls.
513  *
514  * @param handle Socket handle
515  * @param callback Function to call on state change
516  * @param data Argument to pass to callback
517  */
518  void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) override;
519 
520  /* Set stack-specific socket options
521  *
522  * The setsockopt allow an application to pass stack-specific hints
523  * to the underlying stack. For unsupported options,
524  * NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
525  *
526  * @param handle Socket handle
527  * @param level Stack-specific protocol level
528  * @param optname Stack-specific option identifier
529  * @param optval Option value
530  * @param optlen Length of the option value
531  * @return 0 on success, negative error code on failure
532  */
533  nsapi_error_t setsockopt(nsapi_socket_t handle, int level,
534  int optname, const void *optval, unsigned optlen) override;
535 
536  /* Get stack-specific socket options
537  *
538  * The getstackopt allow an application to retrieve stack-specific hints
539  * from the underlying stack. For unsupported options,
540  * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
541  *
542  * @param handle Socket handle
543  * @param level Stack-specific protocol level
544  * @param optname Stack-specific option identifier
545  * @param optval Destination for option value
546  * @param optlen Length of the option value
547  * @return 0 on success, negative error code on failure
548  */
549  nsapi_error_t getsockopt(nsapi_socket_t handle, int level,
550  int optname, void *optval, unsigned *optlen) override;
551 private:
552 
553  /** Call in callback
554  *
555  * Callback is used to call the call in method of the network stack.
556  */
558 
559  /** Get a call in callback
560  *
561  * Get a call in callback from the network stack context.
562  *
563  * Callback should not take more than 10ms to execute, otherwise it might
564  * prevent underlying thread processing. A portable user of the callback
565  * should not make calls to network operations due to stack size limitations.
566  * The callback should not perform expensive operations such as socket recv/send
567  * calls or blocking operations.
568  *
569  * @return Call in callback
570  */
571  call_in_callback_cb_t get_call_in_callback() override;
572 
573  /** Call a callback after a delay
574  *
575  * Call a callback from the network stack context after a delay. If function
576  * returns error callback will not be called.
577  *
578  * @param delay Delay in milliseconds
579  * @param func Callback to be called
580  * @return 0 on success, negative error code on failure
581  */
582  nsapi_error_t call_in(int delay, mbed::Callback<void()> func) override;
583 
584  struct mbed_lwip_socket {
585  bool in_use;
586 
587  struct netconn *conn;
588  struct pbuf *buf;
589  u16_t offset;
590 
591  void (*cb)(void *);
592  void *data;
593 
594  // Track multicast addresses subscribed to by this socket
595  nsapi_ip_mreq_t *multicast_memberships;
596  uint32_t multicast_memberships_count;
597  uint32_t multicast_memberships_registry;
598  };
599 
600  struct lwip_callback {
601  unsigned int delay;
603  };
604 
605  static nsapi_error_t err_remap(err_t err);
606  static bool is_local_addr(const ip_addr_t *ip_addr);
607  static const ip_addr_t *get_ip_addr(bool any_addr, const struct netif *netif);
608  static const ip_addr_t *get_ipv4_addr(const struct netif *netif);
609  static const ip_addr_t *get_ipv6_addr(const struct netif *netif);
610  static const ip_addr_t *get_ipv6_link_local_addr(const struct netif *netif);
611 
612  static void add_dns_addr(struct netif *lwip_netif, const char *interface_name);
613 
614  /* Static arena of sockets */
615  struct mbed_lwip_socket arena[MEMP_NUM_NETCONN];
616  void arena_init(void);
617  struct mbed_lwip_socket *arena_alloc();
618  void arena_dealloc(struct mbed_lwip_socket *s);
619 
620  static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
621  {
622  while (!(s->multicast_memberships_registry & (0x0001 << index))) {
623  index++;
624  }
625  return index;
626  }
627 
628  static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
629  {
630  while ((s->multicast_memberships_registry & (0x0001 << index))) {
631  index++;
632  }
633  return index;
634  }
635 
636  static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
637  {
638  s->multicast_memberships_registry |= (0x0001 << index);
639  }
640 
641  static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
642  {
643  s->multicast_memberships_registry &= ~(0x0001 << index);
644  }
645  static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr);
646 
647  static void socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len);
648 
649  static void tcpip_init_irq(void *handle);
650  static void tcpip_thread_callback(void *ptr);
651 
652  char ip_address[40];
653  Interface *default_interface;
654  LWIPMemoryManager memory_manager;
655  osThreadId tcpip_thread_id;
656  rtos::Mutex adaptation;
657  rtos::EventFlags _event_flag;
658  static const int TCP_CLOSED_FLAG = 0x4u;
659 };
660 
661 #endif /* LWIPSTACK_H_ */
char * get_interface_name(char *buf) override
Return netif interface name.
Functions to sync with TCPIP thread.
void socket_attach(nsapi_socket_t handle, void(*callback)(void *), void *data) override
Register a callback on state change of the socket.
netconn API (to be used from non-TCPIP threads)
nsapi_error_t get_dns_server(int index, SocketAddress *address, const char *interface_name) override
Get a domain name server from a list of servers to query.
nsapi_error_t getsockopt(nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen) override
Get stack-specific socket options.
The EventFlags class is used to control event flags or wait for event flags other threads control...
Definition: EventFlags.h:53
void * memory_manager
Pointer to memory manager.
Representation of a stack&#39;s view of an interface.
void * nsapi_socket_t
Opaque handle for network sockets.
Definition: nsapi_types.h:207
void set_default_interface(OnboardNetworkStack::Interface *interface) override
Set the network interface as default one.
struct netif * next
pointer to next in linked list
Definition: netif.h:264
nsapi_error_t get_gateway(SocketAddress *address) override
Copies gateway address of the network interface to user supplied buffer.
IP API.
nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out) override
Register a PPP interface with the IP stack.
nsapi_error_t get_ipv6_link_local_address(SocketAddress *address) override
Get the IPv6 link local address in SocketAddress representation.
nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name) override
Get the local IP address on interface name.
virtual nsapi_error_t get_ip_address(SocketAddress *address)
Get the local IP address.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
IPv6 addresses.
#define NSAPI_INTERFACE_NAME_MAX_SIZE
Maximum size of network interface name.
Definition: nsapi_types.h:142
nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name) override
Add a domain name server to list of servers to query.
nsapi_error_t bringup(bool dhcp, const char *ip, const char *netmask, const char *gw, nsapi_ip_stack_t stack=DEFAULT_STACK, bool blocking=true) override
Connect the interface to the network.
nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) override
Opens a socket.
Ethernet output for IPv6.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:162
void * hw
alternative implementation pointer - used for PPP
Definition: LWIPStack.h:221
nsapi_error_t socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0) override
Accepts a connection on a TCP socket.
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
Definition: nsapi_types.h:106
nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, void *buffer, nsapi_size_t size) override
Receive a packet over a UDP socket.
mbed OS API for onboard IP stack abstraction
void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) override
Register callback for status reporting.
nsapi_error_t bringdown() override
Disconnect interface from the network.
Definition: PPP.h:26
Main packet buffer struct.
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: L3IP.h:31
Generic data structure used for all lwIP network interfaces.
SocketAddress class.
Definition: SocketAddress.h:36
The Mutex class is used to synchronize the execution of threads.
Definition: Mutex.h:70
nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, void *data, nsapi_size_t size) override
Receive data over a TCP socket.
#define MEMP_NUM_NETCONN
MEMP_NUM_NETCONN: the number of struct netconns.
Definition: opt.h:532
nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) override
Listen for connections on a TCP socket.
nsapi_error_t remove_ppp_interface(OnboardNetworkStack::Interface **interface_out) override
Remove a network interface from IP stack.
nsapi_connection_status_t get_connection_status() const override
Get the connection status.
nsapi_error_t get_netmask(SocketAddress *address) override
Copies netmask of the network interface to user supplied buffer.
nsapi_error_t remove_l3ip_interface(OnboardNetworkStack::Interface **interface_out) override
Remove a network interface from IP stack.
nsapi_error_t get_ip_address(SocketAddress *address) override
Get the local IP address.
char * get_mac_address(char *buf, nsapi_size_t buflen) override
Return MAC address of the network interface.
Definition: LWIPStack.h:40
Connected isochronous stream linked list.
Definition: lctr_int_cis.h:306
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
Definition: nsapi_types.h:99
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: EMAC.h:32
nsapi_error_t setsockopt(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen) override
Set stack-specific socket options.
IP address structure for passing IP addresses by value.
Definition: nsapi_types.h:190
netif_mac_filter_action
MAC Filter Actions, these are passed to a netif&#39;s igmp_mac_filter or mld_mac_filter callback function...
Definition: netif.h:157
nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) override
Connects TCP socket to a remote host.
nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size) override
Send a packet over a UDP socket.
nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out) override
Register a network interface with the IP stack.
Callback class based on template specialization.
Definition: Callback.h:53
TCP API (to be used from TCPIP thread) See also tcp_raw.
nsapi_error_t socket_close(nsapi_socket_t handle) override
Close the socket.
nsapi_ip_mreq structure
Definition: nsapi_types.h:340
nsapi_error_t add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetworkStack::Interface **interface_out) override
Register a network interface with the IP stack.
nsapi_error_t remove_ethernet_interface(OnboardNetworkStack::Interface **interface_out) override
Remove a network interface from IP stack.
nsapi_error_t set_ip_address(const char *ip, const char *netmask, const char *gw, uint8_t ipv6_flag=0) override
Set IP address to LWIP stack.
nsapi_size_or_error_t socket_send(nsapi_socket_t handle, const void *data, nsapi_size_t size) override
Send data over a TCP socket.
nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) override
Bind a specific address to a socket.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.