25 #include "netif/etharp.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" 36 #define IP_ADDR_VALID IP6_ADDR_VALID 38 #define IP_ADDR_VALID 0 44 static LWIP &get_instance();
72 uint8_t ipv6_flag = IP_ADDR_VALID
89 const char *netmask,
const char *gw,
90 nsapi_ip_stack_t stack = DEFAULT_STACK,
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);
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);
178 static err_t emac_if_init(
struct netif *netif);
183 static err_t l3ip4_output(
struct netif *netif,
struct pbuf *p,
const ip4_addr_t *ipaddr);
186 static err_t l3ip6_output(
struct netif *netif,
struct pbuf *p,
const ip6_addr_t *ipaddr);
188 void l3ip_input(net_stack_mem_buf_t *buf);
189 void l3ip_state_change(
bool up);
197 static err_t l3ip_if_init(
struct netif *netif);
201 #if PPP_IPV4_SUPPORT && LWIP_IPV4 202 static err_t ppp4_output(
struct netif *netif,
struct pbuf *p,
const ip4_addr_t *ipaddr);
204 #if PPP_IPV6_SUPPORT && LWIP_IPV6 205 static err_t ppp6_output(
struct netif *netif,
struct pbuf *p,
const ip6_addr_t *ipaddr);
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);
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 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 246 nsapi_connection_status_t connected;
248 bool dhcp_has_to_be_set;
535 int optname,
const void *optval,
unsigned optlen)
override;
551 int optname,
void *optval,
unsigned *optlen)
override;
585 struct mbed_lwip_socket {
588 struct netconn *conn;
597 uint32_t multicast_memberships_count;
598 uint32_t multicast_memberships_registry;
601 struct lwip_callback {
607 static bool is_local_addr(
const ip_addr_t *ip_addr);
613 static void add_dns_addr(
struct netif *lwip_netif,
const char *interface_name);
617 void arena_init(
void);
618 struct mbed_lwip_socket *arena_alloc();
619 void arena_dealloc(
struct mbed_lwip_socket *s);
621 static uint32_t next_registered_multicast_member(
const struct mbed_lwip_socket *s, uint32_t index)
623 while (!(s->multicast_memberships_registry & (0x0001 << index))) {
629 static uint32_t next_free_multicast_member(
const struct mbed_lwip_socket *s, uint32_t index)
631 while ((s->multicast_memberships_registry & (0x0001 << index))) {
637 static void set_multicast_member_registry_bit(
struct mbed_lwip_socket *s, uint32_t index)
639 s->multicast_memberships_registry |= (0x0001 << index);
642 static void clear_multicast_member_registry_bit(
struct mbed_lwip_socket *s, uint32_t index)
644 s->multicast_memberships_registry &= ~(0x0001 << index);
646 static int32_t find_multicast_member(
const struct mbed_lwip_socket *s,
const nsapi_ip_mreq_t *imr);
648 static void socket_callback(
struct netconn *nc,
enum netconn_evt eh, u16_t len);
650 static void tcpip_init_irq(
void *handle);
651 static void tcpip_thread_callback(
void *ptr);
656 osThreadId tcpip_thread_id;
659 static const int TCP_CLOSED_FLAG = 0x4u;
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...
void * memory_manager
Pointer to memory manager.
Representation of a stack's view of an interface.
void * nsapi_socket_t
Opaque handle for network sockets.
void set_default_interface(OnboardNetworkStack::Interface *interface) override
Set the network interface as default one.
struct netif * next
pointer to next in linked list
nsapi_error_t get_gateway(SocketAddress *address) override
Copies gateway address of the network interface to user supplied buffer.
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.
#define NSAPI_INTERFACE_NAME_MAX_SIZE
Maximum size of network interface name.
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.
void * hw
alternative implementation pointer - used for PPP
nsapi_error_t socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0) override
Accepts a connection on a TCP socket.
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
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.
Main packet buffer struct.
This interface should be used to abstract low level access to networking hardware All operations rece...
Generic data structure used for all lwIP network interfaces.
The Mutex class is used to synchronize the execution of threads.
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.
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.
Connected isochronous stream linked list.
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
This interface should be used to abstract low level access to networking hardware All operations rece...
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.
netif_mac_filter_action
MAC Filter Actions, these are passed to a netif's igmp_mac_filter or mld_mac_filter callback function...
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.
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_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.