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);
171 static err_t emac_low_level_output(
struct netif *netif,
struct pbuf *p);
172 void emac_input(net_stack_mem_buf_t *buf);
173 void emac_state_change(
bool up);
181 static err_t emac_if_init(
struct netif *netif);
186 static err_t l3ip4_output(
struct netif *netif,
struct pbuf *p,
const ip4_addr_t *ipaddr);
189 static err_t l3ip6_output(
struct netif *netif,
struct pbuf *p,
const ip6_addr_t *ipaddr);
191 void l3ip_input(net_stack_mem_buf_t *buf);
192 void l3ip_state_change(
bool up);
200 static err_t l3ip_if_init(
struct netif *netif);
204 #if PPP_IPV4_SUPPORT && LWIP_IPV4 205 static err_t ppp4_output(
struct netif *netif,
struct pbuf *p,
const ip4_addr_t *ipaddr);
207 #if PPP_IPV6_SUPPORT && LWIP_IPV6 208 static err_t ppp6_output(
struct netif *netif,
struct pbuf *p,
const ip6_addr_t *ipaddr);
210 void ppp_input(net_stack_mem_buf_t *buf);
211 void ppp_state_change(
bool up);
212 static err_t ppp_if_init(
struct netif *netif);
230 mbed_rtos_storage_semaphore_t remove_interface_sem;
231 osSemaphoreId_t remove_interface;
232 mbed_rtos_storage_semaphore_t linked_sem;
233 osSemaphoreId_t linked;
234 mbed_rtos_storage_semaphore_t unlinked_sem;
235 osSemaphoreId_t unlinked;
236 mbed_rtos_storage_semaphore_t has_any_addr_sem;
237 osSemaphoreId_t has_any_addr;
238 #define HAS_ANY_ADDR 1 239 #if PREF_ADDR_TIMEOUT 240 mbed_rtos_storage_semaphore_t has_pref_addr_sem;
241 osSemaphoreId_t has_pref_addr;
242 #define HAS_PREF_ADDR 2 244 #if BOTH_ADDR_TIMEOUT 245 mbed_rtos_storage_semaphore_t has_both_addr_sem;
246 osSemaphoreId_t has_both_addr;
247 #define HAS_BOTH_ADDR 4 251 nsapi_connection_status_t connected;
253 bool dhcp_has_to_be_set;
583 int optname,
const void *optval,
unsigned optlen)
override;
599 int optname,
void *optval,
unsigned *optlen)
override;
633 struct mbed_lwip_socket {
636 struct netconn *conn;
645 uint32_t multicast_memberships_count;
646 uint32_t multicast_memberships_registry;
649 struct lwip_callback {
655 static bool is_local_addr(
const ip_addr_t *ip_addr);
661 static void add_dns_addr(
struct netif *lwip_netif,
const char *interface_name);
665 void arena_init(
void);
666 struct mbed_lwip_socket *arena_alloc();
667 void arena_dealloc(
struct mbed_lwip_socket *s);
669 static uint32_t next_registered_multicast_member(
const struct mbed_lwip_socket *s, uint32_t index)
671 while (!(s->multicast_memberships_registry & (0x0001 << index))) {
677 static uint32_t next_free_multicast_member(
const struct mbed_lwip_socket *s, uint32_t index)
679 while ((s->multicast_memberships_registry & (0x0001 << index))) {
685 static void set_multicast_member_registry_bit(
struct mbed_lwip_socket *s, uint32_t index)
687 s->multicast_memberships_registry |= (0x0001 << index);
690 static void clear_multicast_member_registry_bit(
struct mbed_lwip_socket *s, uint32_t index)
692 s->multicast_memberships_registry &= ~(0x0001 << index);
694 static int32_t find_multicast_member(
const struct mbed_lwip_socket *s,
const nsapi_ip_mreq_t *imr);
696 static void socket_callback(
struct netconn *nc,
enum netconn_evt eh, u16_t len);
698 static void tcpip_init_irq(
void *handle);
699 static void tcpip_thread_callback(
void *ptr);
704 osThreadId tcpip_thread_id;
707 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_size_or_error_t socket_sendto_control(nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size, nsapi_msghdr_t *control, nsapi_size_t control_size) override
Send a packet with ancillary data over a UDP socket.
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.
Common interface that is shared between network devices.
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.
nsapi_size_or_error_t socket_recvfrom_control(nsapi_socket_t handle, SocketAddress *address, void *data, nsapi_size_t size, nsapi_msghdr_t *control, nsapi_size_t control_size) override
Receive a packet with ancillary data over a UDP socket.
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.
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 add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out, NetworkInterface *user_network_interface=NULL) 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.