lwipstack: fix astyle coding style

pull/8591/head
Martin Kojtal 2018-10-30 15:02:01 +00:00
parent e54ce88bca
commit 41c1901318
7 changed files with 119 additions and 108 deletions

View File

@ -59,10 +59,10 @@ static void add_dns_addr_to_dns_list_index(const u8_t addr_type, const u8_t inde
if (addr_type == IPADDR_TYPE_V6) { if (addr_type == IPADDR_TYPE_V6) {
/* 2001:4860:4860::8888 google */ /* 2001:4860:4860::8888 google */
ip_addr_t ipv6_dns_addr = IPADDR6_INIT( ip_addr_t ipv6_dns_addr = IPADDR6_INIT(
PP_HTONL(0x20014860UL), PP_HTONL(0x20014860UL),
PP_HTONL(0x48600000UL), PP_HTONL(0x48600000UL),
PP_HTONL(0x00000000UL), PP_HTONL(0x00000000UL),
PP_HTONL(0x00008888UL)); PP_HTONL(0x00008888UL));
dns_setserver(index, &ipv6_dns_addr); dns_setserver(index, &ipv6_dns_addr);
} }
#endif #endif
@ -186,7 +186,7 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
if (interface->client_callback && connectedStatusPrev != interface->connected if (interface->client_callback && connectedStatusPrev != interface->connected
&& interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */ && interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ { && interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected); interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
} }
} }
@ -235,7 +235,7 @@ void LWIP::Interface::netif_status_irq(struct netif *netif)
} }
if (interface->client_callback && (connectedStatusPrev != interface->connected) if (interface->client_callback && (connectedStatusPrev != interface->connected)
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ { && interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected); interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
} }
} }
@ -262,8 +262,8 @@ static void mbed_lwip_clear_ipv6_addresses(struct netif *netif)
char *LWIP::Interface::get_mac_address(char *buf, nsapi_size_t buflen) char *LWIP::Interface::get_mac_address(char *buf, nsapi_size_t buflen)
{ {
(void) snprintf(buf, buflen, "%02x:%02x:%02x:%02x:%02x:%02x", (void) snprintf(buf, buflen, "%02x:%02x:%02x:%02x:%02x:%02x",
netif.hwaddr[0], netif.hwaddr[1], netif.hwaddr[2], netif.hwaddr[0], netif.hwaddr[1], netif.hwaddr[2],
netif.hwaddr[3], netif.hwaddr[4], netif.hwaddr[5]); netif.hwaddr[3], netif.hwaddr[4], netif.hwaddr[5]);
return buf; return buf;
} }
@ -317,9 +317,9 @@ char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
} }
LWIP::Interface::Interface() : LWIP::Interface::Interface() :
hw(NULL), has_addr_state(0), hw(NULL), has_addr_state(0),
connected(NSAPI_STATUS_DISCONNECTED), connected(NSAPI_STATUS_DISCONNECTED),
dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false) dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false)
{ {
memset(&netif, 0, sizeof netif); memset(&netif, 0, sizeof netif);
@ -379,9 +379,9 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN
if (!netif_add(&interface->netif, if (!netif_add(&interface->netif,
#if LWIP_IPV4 #if LWIP_IPV4
0, 0, 0, 0, 0, 0,
#endif #endif
interface, &LWIP::Interface::emac_if_init, tcpip_input)) { interface, &LWIP::Interface::emac_if_init, tcpip_input)) {
return NSAPI_ERROR_DEVICE_ERROR; return NSAPI_ERROR_DEVICE_ERROR;
} }
@ -497,8 +497,8 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
ip4_addr_t gw_addr; ip4_addr_t gw_addr;
if (!inet_aton(ip, &ip_addr) || if (!inet_aton(ip, &ip_addr) ||
!inet_aton(netmask, &netmask_addr) || !inet_aton(netmask, &netmask_addr) ||
!inet_aton(gw, &gw_addr)) { !inet_aton(gw, &gw_addr)) {
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
@ -512,14 +512,14 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
} }
if (ppp) { if (ppp) {
err_t err = ppp_lwip_connect(hw); err_t err = ppp_lwip_connect(hw);
if (err) { if (err) {
connected = NSAPI_STATUS_DISCONNECTED; connected = NSAPI_STATUS_DISCONNECTED;
if (client_callback) { if (client_callback) {
client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED); client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
} }
return err_remap(err); return err_remap(err);
} }
} }
if (!netif_is_link_up(&netif)) { if (!netif_is_link_up(&netif)) {
@ -598,16 +598,16 @@ nsapi_error_t LWIP::Interface::bringdown()
if (ppp) { if (ppp) {
/* this is a blocking call, returns when PPP is properly closed */ /* this is a blocking call, returns when PPP is properly closed */
err_t err = ppp_lwip_disconnect(hw); err_t err = ppp_lwip_disconnect(hw);
if (err) { if (err) {
return err_remap(err); return err_remap(err);
} }
MBED_ASSERT(!netif_is_link_up(&netif)); MBED_ASSERT(!netif_is_link_up(&netif));
/*if (netif_is_link_up(&netif)) { /*if (netif_is_link_up(&netif)) {
if (sys_arch_sem_wait(&unlinked, 15000) == SYS_ARCH_TIMEOUT) { if (sys_arch_sem_wait(&unlinked, 15000) == SYS_ARCH_TIMEOUT) {
return NSAPI_ERROR_DEVICE_ERROR; return NSAPI_ERROR_DEVICE_ERROR;
} }
}*/ }*/
} else { } else {
netif_set_down(&netif); netif_set_down(&netif);
} }

View File

@ -74,8 +74,7 @@ err_t LWIP::Interface::emac_igmp_mac_filter(struct netif *netif, const ip4_addr_
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state); LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
switch (action) { switch (action) {
case NETIF_ADD_MAC_FILTER: case NETIF_ADD_MAC_FILTER: {
{
uint32_t group23 = ntohl(group->addr) & 0x007FFFFF; uint32_t group23 = ntohl(group->addr) & 0x007FFFFF;
uint8_t addr[6]; uint8_t addr[6];
addr[0] = LL_IP4_MULTICAST_ADDR_0; addr[0] = LL_IP4_MULTICAST_ADDR_0;
@ -112,8 +111,7 @@ err_t LWIP::Interface::emac_mld_mac_filter(struct netif *netif, const ip6_addr_t
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state); LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
switch (action) { switch (action) {
case NETIF_ADD_MAC_FILTER: case NETIF_ADD_MAC_FILTER: {
{
uint32_t group32 = ntohl(group->addr[3]); uint32_t group32 = ntohl(group->addr[3]);
uint8_t addr[6]; uint8_t addr[6];
addr[0] = LL_IP6_MULTICAST_ADDR_0; addr[0] = LL_IP6_MULTICAST_ADDR_0;

View File

@ -38,7 +38,7 @@
#include "LWIPStack.h" #include "LWIPStack.h"
#ifndef LWIP_SOCKET_MAX_MEMBERSHIPS #ifndef LWIP_SOCKET_MAX_MEMBERSHIPS
#define LWIP_SOCKET_MAX_MEMBERSHIPS 4 #define LWIP_SOCKET_MAX_MEMBERSHIPS 4
#endif #endif
void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len) void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len)
@ -54,8 +54,8 @@ void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len)
for (int i = 0; i < MEMP_NUM_NETCONN; i++) { for (int i = 0; i < MEMP_NUM_NETCONN; i++) {
if (lwip.arena[i].in_use if (lwip.arena[i].in_use
&& lwip.arena[i].conn == nc && lwip.arena[i].conn == nc
&& lwip.arena[i].cb) { && lwip.arena[i].cb) {
lwip.arena[i].cb(lwip.arena[i].data); lwip.arena[i].cb(lwip.arena[i].data);
} }
} }
@ -101,15 +101,15 @@ static bool convert_mbed_addr_to_lwip(ip_addr_t *out, const nsapi_addr_t *in)
{ {
#if LWIP_IPV6 #if LWIP_IPV6
if (in->version == NSAPI_IPv6) { if (in->version == NSAPI_IPv6) {
IP_SET_TYPE(out, IPADDR_TYPE_V6); IP_SET_TYPE(out, IPADDR_TYPE_V6);
SMEMCPY(ip_2_ip6(out), in->bytes, sizeof(ip6_addr_t)); SMEMCPY(ip_2_ip6(out), in->bytes, sizeof(ip6_addr_t));
return true; return true;
} }
#if !LWIP_IPV4 #if !LWIP_IPV4
/* For bind() and other purposes, need to accept "null" of other type */ /* For bind() and other purposes, need to accept "null" of other type */
/* (People use IPv4 0.0.0.0 as a general null) */ /* (People use IPv4 0.0.0.0 as a general null) */
if (in->version == NSAPI_UNSPEC || if (in->version == NSAPI_UNSPEC ||
(in->version == NSAPI_IPv4 && all_zeros(in->bytes, 4))) { (in->version == NSAPI_IPv4 && all_zeros(in->bytes, 4))) {
ip_addr_set_zero_ip6(out); ip_addr_set_zero_ip6(out);
return true; return true;
} }
@ -118,14 +118,14 @@ static bool convert_mbed_addr_to_lwip(ip_addr_t *out, const nsapi_addr_t *in)
#if LWIP_IPV4 #if LWIP_IPV4
if (in->version == NSAPI_IPv4) { if (in->version == NSAPI_IPv4) {
IP_SET_TYPE(out, IPADDR_TYPE_V4); IP_SET_TYPE(out, IPADDR_TYPE_V4);
SMEMCPY(ip_2_ip4(out), in->bytes, sizeof(ip4_addr_t)); SMEMCPY(ip_2_ip4(out), in->bytes, sizeof(ip4_addr_t));
return true; return true;
} }
#if !LWIP_IPV6 #if !LWIP_IPV6
/* For symmetry with above, accept IPv6 :: as a general null */ /* For symmetry with above, accept IPv6 :: as a general null */
if (in->version == NSAPI_UNSPEC || if (in->version == NSAPI_UNSPEC ||
(in->version == NSAPI_IPv6 && all_zeros(in->bytes, 16))) { (in->version == NSAPI_IPv6 && all_zeros(in->bytes, 16))) {
ip_addr_set_zero_ip4(out); ip_addr_set_zero_ip4(out);
return true; return true;
} }
@ -273,7 +273,7 @@ nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
#if LWIP_IPV6 #if LWIP_IPV6
// Enable IPv6 (or dual-stack) // Enable IPv6 (or dual-stack)
lwip_proto = (enum netconn_type) (lwip_proto | NETCONN_TYPE_IPV6); lwip_proto = (enum netconn_type)(lwip_proto | NETCONN_TYPE_IPV6);
#endif #endif
s->conn = netconn_new_with_callback(lwip_proto, &LWIP::socket_callback); s->conn = netconn_new_with_callback(lwip_proto, &LWIP::socket_callback);
@ -485,7 +485,8 @@ nsapi_size_or_error_t LWIP::socket_recvfrom(nsapi_socket_t handle, SocketAddress
return recv; return recv;
} }
int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr) { int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr)
{
uint32_t count = 0; uint32_t count = 0;
uint32_t index = 0; uint32_t index = 0;
// Set upper limit on while loop, should break out when the membership pair is found // Set upper limit on while loop, should break out when the membership pair is found
@ -493,7 +494,7 @@ int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsap
index = next_registered_multicast_member(s, index); index = next_registered_multicast_member(s, index);
if (memcmp(&s->multicast_memberships[index].imr_multiaddr, &imr->imr_multiaddr, sizeof(nsapi_addr_t)) == 0 && if (memcmp(&s->multicast_memberships[index].imr_multiaddr, &imr->imr_multiaddr, sizeof(nsapi_addr_t)) == 0 &&
memcmp(&s->multicast_memberships[index].imr_interface, &imr->imr_interface, sizeof(nsapi_addr_t)) == 0) { memcmp(&s->multicast_memberships[index].imr_interface, &imr->imr_interface, sizeof(nsapi_addr_t)) == 0) {
return index; return index;
} }
count++; count++;
@ -522,7 +523,7 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
} }
s->conn->pcb.tcp->keep_idle = *(int*)optval; s->conn->pcb.tcp->keep_idle = *(int *)optval;
return 0; return 0;
case NSAPI_KEEPINTVL: case NSAPI_KEEPINTVL:
@ -530,7 +531,7 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
} }
s->conn->pcb.tcp->keep_intvl = *(int*)optval; s->conn->pcb.tcp->keep_intvl = *(int *)optval;
return 0; return 0;
#endif #endif
@ -582,11 +583,11 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
if (optname == NSAPI_ADD_MEMBERSHIP) { if (optname == NSAPI_ADD_MEMBERSHIP) {
if (!s->multicast_memberships) { if (!s->multicast_memberships) {
// First multicast join on this socket, allocate space for membership tracking // First multicast join on this socket, allocate space for membership tracking
s->multicast_memberships = (nsapi_ip_mreq_t*)malloc(sizeof(nsapi_ip_mreq_t) * LWIP_SOCKET_MAX_MEMBERSHIPS); s->multicast_memberships = (nsapi_ip_mreq_t *)malloc(sizeof(nsapi_ip_mreq_t) * LWIP_SOCKET_MAX_MEMBERSHIPS);
if (!s->multicast_memberships) { if (!s->multicast_memberships) {
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;
} }
} else if(s->multicast_memberships_count == LWIP_SOCKET_MAX_MEMBERSHIPS) { } else if (s->multicast_memberships_count == LWIP_SOCKET_MAX_MEMBERSHIPS) {
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;
} }
@ -598,16 +599,16 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
adaptation.lock(); adaptation.lock();
#if LWIP_IPV4 #if LWIP_IPV4
if (IP_IS_V4(&if_addr)) { if (IP_IS_V4(&if_addr)) {
igmp_err = igmp_joingroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr)); igmp_err = igmp_joingroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
} }
#endif #endif
#if LWIP_IPV6 #if LWIP_IPV6
if (IP_IS_V6(&if_addr)) { if (IP_IS_V6(&if_addr)) {
igmp_err = mld6_joingroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr)); igmp_err = mld6_joingroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
} }
#endif #endif
adaptation.unlock(); adaptation.unlock();
@ -626,22 +627,22 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
adaptation.lock(); adaptation.lock();
#if LWIP_IPV4 #if LWIP_IPV4
if (IP_IS_V4(&if_addr)) { if (IP_IS_V4(&if_addr)) {
igmp_err = igmp_leavegroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr)); igmp_err = igmp_leavegroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
} }
#endif #endif
#if LWIP_IPV6 #if LWIP_IPV6
if (IP_IS_V6(&if_addr)) { if (IP_IS_V6(&if_addr)) {
igmp_err = mld6_leavegroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr)); igmp_err = mld6_leavegroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
} }
#endif #endif
adaptation.unlock(); adaptation.unlock();
} }
return err_remap(igmp_err); return err_remap(igmp_err);
} }
default: default:
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -662,7 +663,8 @@ void LWIP::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *
s->data = data; s->data = data;
} }
LWIP &LWIP::get_instance() { LWIP &LWIP::get_instance()
{
static LWIP lwip; static LWIP lwip;
return lwip; return lwip;
} }
@ -672,7 +674,8 @@ LWIP &LWIP::get_instance() {
#define LWIP 0x11991199 #define LWIP 0x11991199
#if MBED_CONF_NSAPI_DEFAULT_STACK == LWIP #if MBED_CONF_NSAPI_DEFAULT_STACK == LWIP
#undef LWIP #undef LWIP
OnboardNetworkStack &OnboardNetworkStack::get_default_instance() { OnboardNetworkStack &OnboardNetworkStack::get_default_instance()
{
return LWIP::get_instance(); return LWIP::get_instance();
} }
#endif #endif

View File

@ -53,7 +53,7 @@ public:
const char *netmask, const char *gw, const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK, nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true bool blocking = true
); );
/** Disconnect interface from the network /** Disconnect interface from the network
* *
@ -120,24 +120,24 @@ public:
static void netif_status_irq(struct netif *netif); static void netif_status_irq(struct netif *netif);
static Interface *our_if_from_netif(struct netif *netif); static Interface *our_if_from_netif(struct netif *netif);
#if LWIP_ETHERNET #if LWIP_ETHERNET
static err_t emac_low_level_output(struct netif *netif, struct pbuf *p); static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
void emac_input(emac_mem_buf_t *buf); void emac_input(emac_mem_buf_t *buf);
void emac_state_change(bool up); void emac_state_change(bool up);
#if LWIP_IGMP #if LWIP_IGMP
static err_t emac_igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action); static err_t emac_igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action);
#endif #endif
#if LWIP_IPV6_MLD #if LWIP_IPV6_MLD
static err_t emac_mld_mac_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action); static err_t emac_mld_mac_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action);
#endif #endif
static err_t emac_if_init(struct netif *netif); static err_t emac_if_init(struct netif *netif);
#endif #endif
union { union {
#if LWIP_ETHERNET #if LWIP_ETHERNET
EMAC *emac; /**< HW specific emac implementation */ EMAC *emac; /**< HW specific emac implementation */
#endif #endif
void *hw; /**< alternative implementation pointer - used for PPP */ void *hw; /**< alternative implementation pointer - used for PPP */
}; };
@ -147,17 +147,17 @@ public:
osSemaphoreId_t unlinked; osSemaphoreId_t unlinked;
mbed_rtos_storage_semaphore_t has_any_addr_sem; mbed_rtos_storage_semaphore_t has_any_addr_sem;
osSemaphoreId_t has_any_addr; osSemaphoreId_t has_any_addr;
#define HAS_ANY_ADDR 1 #define HAS_ANY_ADDR 1
#if PREF_ADDR_TIMEOUT #if PREF_ADDR_TIMEOUT
mbed_rtos_storage_semaphore_t has_pref_addr_sem; mbed_rtos_storage_semaphore_t has_pref_addr_sem;
osSemaphoreId_t has_pref_addr; osSemaphoreId_t has_pref_addr;
#define HAS_PREF_ADDR 2 #define HAS_PREF_ADDR 2
#endif #endif
#if BOTH_ADDR_TIMEOUT #if BOTH_ADDR_TIMEOUT
mbed_rtos_storage_semaphore_t has_both_addr_sem; mbed_rtos_storage_semaphore_t has_both_addr_sem;
osSemaphoreId_t has_both_addr; osSemaphoreId_t has_both_addr;
#define HAS_BOTH_ADDR 4 #define HAS_BOTH_ADDR 4
#endif #endif
char has_addr_state; char has_addr_state;
nsapi_connection_status_t connected; nsapi_connection_status_t connected;
bool dhcp_started; bool dhcp_started;
@ -301,7 +301,7 @@ protected:
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t socket_accept(nsapi_socket_t server, virtual nsapi_error_t socket_accept(nsapi_socket_t server,
nsapi_socket_t *handle, SocketAddress *address=0); nsapi_socket_t *handle, SocketAddress *address = 0);
/** Send data over a TCP socket /** Send data over a TCP socket
* *
@ -487,21 +487,29 @@ private:
struct mbed_lwip_socket *arena_alloc(); struct mbed_lwip_socket *arena_alloc();
void arena_dealloc(struct mbed_lwip_socket *s); void arena_dealloc(struct mbed_lwip_socket *s);
static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index) { static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
while (!(s->multicast_memberships_registry & (0x0001 << index))) { index++; } {
while (!(s->multicast_memberships_registry & (0x0001 << index))) {
index++;
}
return index; return index;
} }
static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index) { static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
while ((s->multicast_memberships_registry & (0x0001 << index))) { index++; } {
while ((s->multicast_memberships_registry & (0x0001 << index))) {
index++;
}
return index; return index;
} }
static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index) { static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
{
s->multicast_memberships_registry |= (0x0001 << index); s->multicast_memberships_registry |= (0x0001 << index);
} }
static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index) { static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
{
s->multicast_memberships_registry &= ~(0x0001 << index); s->multicast_memberships_registry &= ~(0x0001 << index);
} }
static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr); static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr);

View File

@ -27,7 +27,8 @@
#include "netsocket/nsapi_types.h" #include "netsocket/nsapi_types.h"
/* LWIP error remapping */ /* LWIP error remapping */
nsapi_error_t LWIP::err_remap(err_t err) { nsapi_error_t LWIP::err_remap(err_t err)
{
switch (err) { switch (err) {
case ERR_OK: case ERR_OK:
case ERR_CLSD: case ERR_CLSD:
@ -103,7 +104,7 @@ bool LWIP::is_local_addr(const ip_addr_t *ip_addr)
if (IP_IS_V6(ip_addr)) { if (IP_IS_V6(ip_addr)) {
for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
ip6_addr_cmp(netif_ip6_addr(netif, i), ip_2_ip6(ip_addr))) { ip6_addr_cmp(netif_ip6_addr(netif, i), ip_2_ip6(ip_addr))) {
return true; return true;
} }
} }
@ -113,7 +114,7 @@ bool LWIP::is_local_addr(const ip_addr_t *ip_addr)
#if LWIP_IPV4 #if LWIP_IPV4
if (IP_IS_V4(ip_addr)) { if (IP_IS_V4(ip_addr)) {
if (!ip4_addr_isany(netif_ip4_addr(netif)) && if (!ip4_addr_isany(netif_ip4_addr(netif)) &&
ip4_addr_cmp(netif_ip4_addr(netif), ip_2_ip4(ip_addr))) { ip4_addr_cmp(netif_ip4_addr(netif), ip_2_ip4(ip_addr))) {
return true; return true;
} }
} }
@ -185,7 +186,7 @@ void LWIP::arena_dealloc(struct mbed_lwip_socket *s)
index = next_registered_multicast_member(s, index); index = next_registered_multicast_member(s, index);
setsockopt(s, NSAPI_SOCKET, NSAPI_DROP_MEMBERSHIP, &s->multicast_memberships[index], setsockopt(s, NSAPI_SOCKET, NSAPI_DROP_MEMBERSHIP, &s->multicast_memberships[index],
sizeof(s->multicast_memberships[index])); sizeof(s->multicast_memberships[index]));
index++; index++;
} }

View File

@ -25,7 +25,7 @@
#include <sys/time.h> #include <sys/time.h>
#endif #endif
// Operating System // Operating System
#define NO_SYS 0 #define NO_SYS 0
#if MBED_CONF_LWIP_IPV4_ENABLED #if MBED_CONF_LWIP_IPV4_ENABLED

View File

@ -120,7 +120,7 @@ static void ppp_link_status(ppp_pcb *pcb, int err_code, void *ctx)
{ {
nsapi_error_t mapped_err_code = NSAPI_ERROR_NO_CONNECTION; nsapi_error_t mapped_err_code = NSAPI_ERROR_NO_CONNECTION;
switch(err_code) { switch (err_code) {
case PPPERR_NONE: case PPPERR_NONE:
mapped_err_code = NSAPI_ERROR_OK; mapped_err_code = NSAPI_ERROR_OK;
tr_info("status_cb: Connected"); tr_info("status_cb: Connected");
@ -247,7 +247,7 @@ static void ppp_input()
fhs.fh = my_stream; fhs.fh = my_stream;
fhs.events = POLLIN; fhs.events = POLLIN;
poll(&fhs, 1, 0); poll(&fhs, 1, 0);
if (fhs.revents & (POLLHUP|POLLERR|POLLNVAL)) { if (fhs.revents & (POLLHUP | POLLERR | POLLNVAL)) {
handle_modem_hangup(); handle_modem_hangup();
return; return;
} }
@ -268,7 +268,8 @@ static void ppp_input()
return; return;
} }
static void stream_cb() { static void stream_cb()
{
if (my_stream && !event_queued) { if (my_stream && !event_queued) {
event_queued = true; event_queued = true;
if (event_queue->call(callback(ppp_input)) == 0) { if (event_queue->call(callback(ppp_input)) == 0) {
@ -280,17 +281,17 @@ static void stream_cb() {
extern "C" err_t ppp_lwip_connect(void *pcb) extern "C" err_t ppp_lwip_connect(void *pcb)
{ {
#if PPP_AUTH_SUPPORT #if PPP_AUTH_SUPPORT
ppp_set_auth(my_ppp_pcb, PPPAUTHTYPE_ANY, login, pwd); ppp_set_auth(my_ppp_pcb, PPPAUTHTYPE_ANY, login, pwd);
#endif //PPP_AUTH_SUPPORT #endif //PPP_AUTH_SUPPORT
ppp_active = true; ppp_active = true;
err_t ret = ppp_connect(my_ppp_pcb, 0); err_t ret = ppp_connect(my_ppp_pcb, 0);
// lwIP's ppp.txt says input must not be called until after connect // lwIP's ppp.txt says input must not be called until after connect
if (ret == ERR_OK) { if (ret == ERR_OK) {
my_stream->sigio(callback(stream_cb)); my_stream->sigio(callback(stream_cb));
} else { } else {
ppp_active = false; ppp_active = false;
} }
return ret; return ret;
} }
extern "C" err_t ppp_lwip_disconnect(void *pcb) extern "C" err_t ppp_lwip_disconnect(void *pcb)
@ -315,7 +316,7 @@ extern "C" nsapi_error_t ppp_lwip_if_init(void *pcb, struct netif *netif, const
if (!my_ppp_pcb) { if (!my_ppp_pcb) {
my_ppp_pcb = pppos_create(netif, my_ppp_pcb = pppos_create(netif,
ppp_output, ppp_link_status, NULL); ppp_output, ppp_link_status, NULL);
if (!my_ppp_pcb) { if (!my_ppp_pcb) {
return NSAPI_ERROR_DEVICE_ERROR; return NSAPI_ERROR_DEVICE_ERROR;
} }