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