You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2017/04/19 18:18:16 UTC
[20/30] incubator-mynewt-core git commit: net/ip/lwip_base;
update to LwIP to tag STABLE-2_0_2_RELEASE
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/prot/tcp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/prot/tcp.h b/net/ip/lwip_base/include/lwip/prot/tcp.h
index 8ef0bf1..67fe7b9 100644
--- a/net/ip/lwip_base/include/lwip/prot/tcp.h
+++ b/net/ip/lwip_base/include/lwip/prot/tcp.h
@@ -80,15 +80,15 @@ PACK_STRUCT_END
/* Valid TCP header flags */
#define TCP_FLAGS 0x3fU
-#define TCPH_HDRLEN(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) >> 12))
-#define TCPH_FLAGS(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS))
+#define TCPH_HDRLEN(phdr) ((u16_t)(lwip_ntohs((phdr)->_hdrlen_rsvd_flags) >> 12))
+#define TCPH_FLAGS(phdr) ((u16_t)(lwip_ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS))
-#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
-#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | htons(flags))
-#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
+#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = lwip_htons(((len) << 12) | TCPH_FLAGS(phdr))
+#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | lwip_htons(flags))
+#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = (u16_t)(lwip_htons((u16_t)((len) << 12) | (flags)))
-#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
-#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~htons(flags))
+#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | lwip_htons(flags))
+#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~lwip_htons(flags))
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/raw.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/raw.h b/net/ip/lwip_base/include/lwip/raw.h
index f92c8ee..30aa147 100644
--- a/net/ip/lwip_base/include/lwip/raw.h
+++ b/net/ip/lwip_base/include/lwip/raw.h
@@ -104,6 +104,8 @@ void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *re
u8_t raw_input (struct pbuf *p, struct netif *inp);
#define raw_init() /* Compatibility define, no init needed. */
+void raw_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr);
+
/* for compatibility with older implementation */
#define raw_new_ip6(proto) raw_new_ip_type(IPADDR_TYPE_V6, proto)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/sockets.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/sockets.h b/net/ip/lwip_base/include/lwip/sockets.h
index 20ba629..2522056 100644
--- a/net/ip/lwip_base/include/lwip/sockets.h
+++ b/net/ip/lwip_base/include/lwip/sockets.h
@@ -43,11 +43,10 @@
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
-#include <stddef.h> /* for size_t */
-
#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/inet.h"
+#include "lwip/errno.h"
#ifdef __cplusplus
extern "C" {
@@ -427,6 +426,8 @@ typedef struct fd_set
#elif LWIP_SOCKET_OFFSET
#error LWIP_SOCKET_OFFSET does not work with external FD_SET!
+#elif FD_SETSIZE < MEMP_NUM_NETCONN
+#error "external FD_SETSIZE too small for number of sockets"
#endif /* FD_SET */
/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/stats.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/stats.h b/net/ip/lwip_base/include/lwip/stats.h
index 89f54f3..bcda2ac 100644
--- a/net/ip/lwip_base/include/lwip/stats.h
+++ b/net/ip/lwip_base/include/lwip/stats.h
@@ -304,7 +304,7 @@ struct stats_ {
extern struct stats_ lwip_stats;
/** Init statistics */
-void lwip_stats_init(void);
+void stats_init(void);
#define STATS_INC(x) ++lwip_stats.x
#define STATS_DEC(x) --lwip_stats.x
@@ -315,7 +315,7 @@ void lwip_stats_init(void);
} while(0)
#define STATS_GET(x) lwip_stats.x
#else /* LWIP_STATS */
-#define lwip_stats_init()
+#define stats_init()
#define STATS_INC(x)
#define STATS_DEC(x)
#define STATS_INC_USED(x)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/sys.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/sys.h b/net/ip/lwip_base/include/lwip/sys.h
index f8804df..d12bae0 100644
--- a/net/ip/lwip_base/include/lwip/sys.h
+++ b/net/ip/lwip_base/include/lwip/sys.h
@@ -34,44 +34,6 @@
* Author: Adam Dunkels <ad...@sics.se>
*/
-/**
- * @defgroup sys_layer System abstraction layer
- * @ingroup infrastructure
- * @verbinclude "sys_arch.txt"
- *
- * @defgroup sys_os OS abstraction layer
- * @ingroup sys_layer
- * No need to implement functions in this section in NO_SYS mode.
- *
- * @defgroup sys_sem Semaphores
- * @ingroup sys_os
- *
- * @defgroup sys_mutex Mutexes
- * @ingroup sys_os
- * Mutexes are recommended to correctly handle priority inversion,
- * especially if you use LWIP_CORE_LOCKING .
- *
- * @defgroup sys_mbox Mailboxes
- * @ingroup sys_os
- *
- * @defgroup sys_time Time
- * @ingroup sys_layer
- *
- * @defgroup sys_prot Critical sections
- * @ingroup sys_layer
- * Used to protect short regions of code against concurrent access.
- * - Your system is a bare-metal system (probably with an RTOS)
- * and interrupts are under your control:
- * Implement this as LockInterrupts() / UnlockInterrupts()
- * - Your system uses an RTOS with deferred interrupt handling from a
- * worker thread: Implement as a global mutex or lock/unlock scheduler
- * - Your system uses a high-level OS with e.g. POSIX signals:
- * Implement as a global mutex
- *
- * @defgroup sys_misc Misc
- * @ingroup sys_os
- */
-
#ifndef LWIP_HDR_SYS_H
#define LWIP_HDR_SYS_H
@@ -160,9 +122,11 @@ typedef void (*lwip_thread_fn)(void *arg);
/**
* @ingroup sys_mutex
- * Create a new mutex
+ * Create a new mutex.
+ * Note that mutexes are expected to not be taken recursively by the lwIP code,
+ * so both implementation types (recursive or non-recursive) should work.
* @param mutex pointer to the mutex to create
- * @return a new mutex
+ * @return ERR_OK if successful, another err_t otherwise
*/
err_t sys_mutex_new(sys_mutex_t *mutex);
/**
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/tcp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/tcp.h b/net/ip/lwip_base/include/lwip/tcp.h
index 35584b4..34d1c10 100644
--- a/net/ip/lwip_base/include/lwip/tcp.h
+++ b/net/ip/lwip_base/include/lwip/tcp.h
@@ -145,7 +145,7 @@ typedef u32_t tcpwnd_size_t;
typedef u16_t tcpwnd_size_t;
#endif
-#if LWIP_WND_SCALE || TCP_LISTEN_BACKLOG
+#if LWIP_WND_SCALE || TCP_LISTEN_BACKLOG || LWIP_TCP_TIMESTAMPS
typedef u16_t tcpflags_t;
#else
typedef u8_t tcpflags_t;
@@ -210,7 +210,7 @@ struct tcp_pcb {
#define TF_ACK_DELAY 0x01U /* Delayed ACK. */
#define TF_ACK_NOW 0x02U /* Immediate ACK. */
#define TF_INFR 0x04U /* In fast recovery. */
-#define TF_TIMESTAMP 0x08U /* Timestamp option enabled */
+#define TF_CLOSEPEND 0x08U /* If this is set, tcp_close failed to enqueue the FIN (retried in tcp_tmr) */
#define TF_RXCLOSED 0x10U /* rx closed by tcp_shutdown */
#define TF_FIN 0x20U /* Connection was closed locally (FIN segment enqueued). */
#define TF_NODELAY 0x40U /* Disable Nagle algorithm */
@@ -221,6 +221,9 @@ struct tcp_pcb {
#if TCP_LISTEN_BACKLOG
#define TF_BACKLOGPEND 0x0200U /* If this is set, a connection pcb has increased the backlog on its listener */
#endif
+#if LWIP_TCP_TIMESTAMPS
+#define TF_TIMESTAMP 0x0400U /* Timestamp option enabled */
+#endif
/* the rest of the fields are in host byte order
as we have to do some math with them */
@@ -358,7 +361,11 @@ void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept);
#endif /* LWIP_CALLBACK_API */
void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval);
+#if LWIP_TCP_TIMESTAMPS
#define tcp_mss(pcb) (((pcb)->flags & TF_TIMESTAMP) ? ((pcb)->mss - 12) : (pcb)->mss)
+#else /* LWIP_TCP_TIMESTAMPS */
+#define tcp_mss(pcb) ((pcb)->mss)
+#endif /* LWIP_TCP_TIMESTAMPS */
#define tcp_sndbuf(pcb) (TCPWND16((pcb)->snd_buf))
#define tcp_sndqueuelen(pcb) ((pcb)->snd_queuelen)
/** @ingroup tcp_raw */
@@ -387,6 +394,7 @@ err_t tcp_bind (struct tcp_pcb *pcb, const ip_addr_t *ipaddr,
err_t tcp_connect (struct tcp_pcb *pcb, const ip_addr_t *ipaddr,
u16_t port, tcp_connected_fn connected);
+struct tcp_pcb * tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err);
struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog);
/** @ingroup tcp_raw */
#define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/tcpip.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/tcpip.h b/net/ip/lwip_base/include/lwip/tcpip.h
index 404a4a2..f2f6b46 100644
--- a/net/ip/lwip_base/include/lwip/tcpip.h
+++ b/net/ip/lwip_base/include/lwip/tcpip.h
@@ -52,7 +52,9 @@ extern "C" {
#if LWIP_TCPIP_CORE_LOCKING
/** The global semaphore to lock the stack. */
extern sys_mutex_t lock_tcpip_core;
+/** Lock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */
#define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
+/** Unlock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */
#define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
#else /* LWIP_TCPIP_CORE_LOCKING */
#define LOCK_TCPIP_CORE()
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/lwip/timeouts.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/lwip/timeouts.h b/net/ip/lwip_base/include/lwip/timeouts.h
index 4988b15..c9b93aa 100644
--- a/net/ip/lwip_base/include/lwip/timeouts.h
+++ b/net/ip/lwip_base/include/lwip/timeouts.h
@@ -103,9 +103,9 @@ void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg);
#endif /* LWIP_DEBUG_TIMERNAMES */
void sys_untimeout(sys_timeout_handler handler, void *arg);
+void sys_restart_timeouts(void);
#if NO_SYS
void sys_check_timeouts(void);
-void sys_restart_timeouts(void);
u32_t sys_timeouts_sleeptime(void);
#else /* NO_SYS */
void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/lowpan6_opts.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/lowpan6_opts.h b/net/ip/lwip_base/include/netif/lowpan6_opts.h
index 140d0c3..fb93ea0 100644
--- a/net/ip/lwip_base/include/netif/lowpan6_opts.h
+++ b/net/ip/lwip_base/include/netif/lowpan6_opts.h
@@ -43,10 +43,6 @@
#include "lwip/opt.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#ifndef LWIP_6LOWPAN
#define LWIP_6LOWPAN 0
#endif
@@ -71,8 +67,4 @@ extern "C" {
#define LOWPAN6_DEBUG LWIP_DBG_OFF
#endif
-#ifdef __cplusplus
-}
-#endif
-
#endif /* LWIP_HDR_LOWPAN6_OPTS_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/ccp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/ccp.h b/net/ip/lwip_base/include/netif/ppp/ccp.h
index b5642db..14dd659 100644
--- a/net/ip/lwip_base/include/netif/ppp/ccp.h
+++ b/net/ip/lwip_base/include/netif/ppp/ccp.h
@@ -36,10 +36,6 @@
#ifndef CCP_H
#define CCP_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* CCP codes.
*/
@@ -157,8 +153,4 @@ extern const struct protent ccp_protent;
void ccp_resetrequest(ppp_pcb *pcb); /* Issue a reset-request. */
#endif /* CCP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && CCP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/chap-new.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/chap-new.h b/net/ip/lwip_base/include/netif/ppp/chap-new.h
index 872979d..64eae32 100644
--- a/net/ip/lwip_base/include/netif/ppp/chap-new.h
+++ b/net/ip/lwip_base/include/netif/ppp/chap-new.h
@@ -36,10 +36,6 @@
#include "ppp.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* CHAP packets begin with a standard header with code, id, len (2 bytes).
*/
@@ -193,8 +189,4 @@ extern void chap_auth_with_peer(ppp_pcb *pcb, const char *our_name, int digest_c
extern const struct protent chap_protent;
#endif /* CHAP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && CHAP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/chap_ms.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/chap_ms.h b/net/ip/lwip_base/include/netif/ppp/chap_ms.h
index 10898c6..0795291 100644
--- a/net/ip/lwip_base/include/netif/ppp/chap_ms.h
+++ b/net/ip/lwip_base/include/netif/ppp/chap_ms.h
@@ -36,17 +36,9 @@
#ifndef CHAPMS_INCLUDE
#define CHAPMS_INCLUDE
-#ifdef __cplusplus
-extern "C" {
-#endif
-
extern const struct chap_digest_type chapms_digest;
extern const struct chap_digest_type chapms2_digest;
#endif /* CHAPMS_INCLUDE */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && MSCHAP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/eui64.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/eui64.h b/net/ip/lwip_base/include/netif/ppp/eui64.h
index 758d8e6..20ac22e 100644
--- a/net/ip/lwip_base/include/netif/ppp/eui64.h
+++ b/net/ip/lwip_base/include/netif/ppp/eui64.h
@@ -41,10 +41,6 @@
#ifndef EUI64_H
#define EUI64_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* @todo:
*
@@ -88,15 +84,11 @@ typedef union
#define eui64_set32(e, l) do { \
(e).e32[0] = 0; \
- (e).e32[1] = htonl(l); \
+ (e).e32[1] = lwip_htonl(l); \
} while (0)
#define eui64_setlo32(e, l) eui64_set32(e, l)
char *eui64_ntoa(eui64_t); /* Returns ascii representation of id */
#endif /* EUI64_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/fsm.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/fsm.h b/net/ip/lwip_base/include/netif/ppp/fsm.h
index c5fcc5c..b6915d3 100644
--- a/net/ip/lwip_base/include/netif/ppp/fsm.h
+++ b/net/ip/lwip_base/include/netif/ppp/fsm.h
@@ -50,10 +50,6 @@
#include "ppp.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Packet header = Code, id, length.
*/
@@ -176,8 +172,4 @@ void fsm_sdata(fsm *f, u_char code, u_char id, const u_char *data, int datalen);
#endif /* FSM_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/ipcp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/ipcp.h b/net/ip/lwip_base/include/netif/ppp/ipcp.h
index b41bd96..45f46b3 100644
--- a/net/ip/lwip_base/include/netif/ppp/ipcp.h
+++ b/net/ip/lwip_base/include/netif/ppp/ipcp.h
@@ -48,10 +48,6 @@
#ifndef IPCP_H
#define IPCP_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Options.
*/
@@ -127,8 +123,4 @@ char *ip_ntoa (u32_t);
extern const struct protent ipcp_protent;
#endif /* IPCP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && PPP_IPV4_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/ipv6cp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/ipv6cp.h b/net/ip/lwip_base/include/netif/ppp/ipv6cp.h
index 64c30e3..07d1ae3 100644
--- a/net/ip/lwip_base/include/netif/ppp/ipv6cp.h
+++ b/net/ip/lwip_base/include/netif/ppp/ipv6cp.h
@@ -146,10 +146,6 @@
#include "eui64.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Options.
*/
@@ -184,8 +180,4 @@ typedef struct ipv6cp_options {
extern const struct protent ipv6cp_protent;
#endif /* IPV6CP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/lcp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/lcp.h b/net/ip/lwip_base/include/netif/ppp/lcp.h
index 65f7394..12e2a05 100644
--- a/net/ip/lwip_base/include/netif/ppp/lcp.h
+++ b/net/ip/lwip_base/include/netif/ppp/lcp.h
@@ -50,10 +50,6 @@
#include "ppp.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Options.
*/
@@ -172,8 +168,4 @@ extern const struct protent lcp_protent;
#endif /* moved to ppp_opts.h */
#endif /* LCP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/magic.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/magic.h b/net/ip/lwip_base/include/netif/ppp/magic.h
index eea645b..a2a9b53 100644
--- a/net/ip/lwip_base/include/netif/ppp/magic.h
+++ b/net/ip/lwip_base/include/netif/ppp/magic.h
@@ -80,10 +80,6 @@
#ifndef MAGIC_H
#define MAGIC_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/***********************
*** PUBLIC FUNCTIONS ***
***********************/
@@ -123,8 +119,4 @@ u32_t magic_pow(u8_t pow);
#endif /* MAGIC_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/mppe.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/mppe.h b/net/ip/lwip_base/include/netif/ppp/mppe.h
index d7383a9..1ae8a5d 100644
--- a/net/ip/lwip_base/include/netif/ppp/mppe.h
+++ b/net/ip/lwip_base/include/netif/ppp/mppe.h
@@ -41,10 +41,6 @@
#include "netif/ppp/pppcrypt.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#define MPPE_PAD 4 /* MPPE growth per frame */
#define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
@@ -63,7 +59,7 @@ extern "C" {
* This is not nice ... the alternative is a bitfield struct though.
* And unfortunately, we cannot share the same bits for the option
* names above since C and H are the same bit. We could do a u_int32
- * but then we have to do a htonl() all the time and/or we still need
+ * but then we have to do a lwip_htonl() all the time and/or we still need
* to know which octet is which.
*/
#define MPPE_C_BIT 0x01 /* MPPC */
@@ -174,8 +170,4 @@ void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state);
err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb);
#endif /* MPPE_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && MPPE_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/ppp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/ppp.h b/net/ip/lwip_base/include/netif/ppp/ppp.h
index 58c8e09..d9ea097 100644
--- a/net/ip/lwip_base/include/netif/ppp/ppp.h
+++ b/net/ip/lwip_base/include/netif/ppp/ppp.h
@@ -43,10 +43,6 @@
#include "lwip/netif.h"
#include "lwip/sys.h"
#include "lwip/timeouts.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#if PPP_IPV6_SUPPORT
#include "lwip/ip6_addr.h"
#endif /* PPP_IPV6_SUPPORT */
@@ -328,6 +324,7 @@ struct ppp_pcb_s {
/* flags */
#if PPP_IPV4_SUPPORT
+ unsigned int ask_for_local :1; /* request our address from peer */
unsigned int ipcp_is_open :1; /* haven't called np_finished() */
unsigned int ipcp_is_up :1; /* have called ipcp_up() */
unsigned int if4_up :1; /* True when the IPv4 interface is up. */
@@ -479,7 +476,8 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas
*
* Default is unset (0.0.0.0).
*/
-#define ppp_set_ipcp_ouraddr(ppp, addr) (ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr))
+#define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \
+ ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0)
#define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr))
#if LWIP_DNS
/*
@@ -689,8 +687,4 @@ err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg);
#endif /* PPP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/ppp_impl.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/ppp_impl.h b/net/ip/lwip_base/include/netif/ppp/ppp_impl.h
index 5fcc858..1d4c774 100644
--- a/net/ip/lwip_base/include/netif/ppp/ppp_impl.h
+++ b/net/ip/lwip_base/include/netif/ppp/ppp_impl.h
@@ -35,10 +35,6 @@
#include "netif/ppp/ppp_opts.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
#ifdef PPP_INCLUDE_SETTINGS_HEADER
@@ -142,10 +138,10 @@ extern "C" {
*/
struct link_callbacks {
/* Start a connection (e.g. Initiate discovery phase) */
- err_t (*connect) (ppp_pcb *pcb, void *ctx);
+ void (*connect) (ppp_pcb *pcb, void *ctx);
#if PPP_SERVER
/* Listen for an incoming connection (Passive mode) */
- err_t (*listen) (ppp_pcb *pcb, void *ctx);
+ void (*listen) (ppp_pcb *pcb, void *ctx);
#endif /* PPP_SERVER */
/* End a connection (i.e. initiate disconnect phase) */
void (*disconnect) (ppp_pcb *pcb, void *ctx);
@@ -630,8 +626,4 @@ void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len);
#endif /* PPP_SUPPORT */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* LWIP_HDR_PPP_IMPL_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/ppp_opts.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/ppp_opts.h b/net/ip/lwip_base/include/netif/ppp/ppp_opts.h
index dee5153..fa79c09 100644
--- a/net/ip/lwip_base/include/netif/ppp/ppp_opts.h
+++ b/net/ip/lwip_base/include/netif/ppp/ppp_opts.h
@@ -30,10 +30,6 @@
#include "lwip/opt.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* PPP_SUPPORT==1: Enable PPP.
*/
@@ -594,8 +590,4 @@ extern "C" {
#endif /* PPP_SUPPORT */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* LWIP_PPP_OPTS_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/pppcrypt.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/pppcrypt.h b/net/ip/lwip_base/include/netif/ppp/pppcrypt.h
index 3bc9d4b..a7b2099 100644
--- a/net/ip/lwip_base/include/netif/ppp/pppcrypt.h
+++ b/net/ip/lwip_base/include/netif/ppp/pppcrypt.h
@@ -38,10 +38,6 @@
#ifndef PPPCRYPT_H
#define PPPCRYPT_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* If included PolarSSL copy is not used, user is expected to include
* external libraries in arch/cc.h (which is included by lwip/arch.h).
@@ -137,8 +133,4 @@ void pppcrypt_56_to_64_bit_key(u_char *key, u_char *des_key);
#endif /* PPPCRYPT_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/pppdebug.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/pppdebug.h b/net/ip/lwip_base/include/netif/ppp/pppdebug.h
index 6b927bb..7ead045 100644
--- a/net/ip/lwip_base/include/netif/ppp/pppdebug.h
+++ b/net/ip/lwip_base/include/netif/ppp/pppdebug.h
@@ -40,10 +40,6 @@
#ifndef PPPDEBUG_H
#define PPPDEBUG_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/* Trace levels. */
#define LOG_CRITICAL (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE)
#define LOG_ERR (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE)
@@ -81,8 +77,4 @@ extern "C" {
#endif /* PPPDEBUG_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/pppoe.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/pppoe.h b/net/ip/lwip_base/include/netif/ppp/pppoe.h
index 10e402d..9f8f289 100644
--- a/net/ip/lwip_base/include/netif/ppp/pppoe.h
+++ b/net/ip/lwip_base/include/netif/ppp/pppoe.h
@@ -76,10 +76,6 @@
#include "ppp.h"
#include "lwip/etharp.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
@@ -180,8 +176,4 @@ void pppoe_data_input(struct netif *netif, struct pbuf *p);
#endif /* PPP_OE_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && PPPOE_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/pppol2tp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/pppol2tp.h b/net/ip/lwip_base/include/netif/ppp/pppol2tp.h
index 79406b0..f03950e 100644
--- a/net/ip/lwip_base/include/netif/ppp/pppol2tp.h
+++ b/net/ip/lwip_base/include/netif/ppp/pppol2tp.h
@@ -39,10 +39,6 @@
#include "ppp.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/* Timeout */
#define PPPOL2TP_CONTROL_TIMEOUT (5*1000) /* base for quick timeout calculation */
#define PPPOL2TP_SLOW_RETRY (60*1000) /* persistent retry interval */
@@ -202,8 +198,4 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
#endif /* PPPOL2TP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/pppos.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/pppos.h b/net/ip/lwip_base/include/netif/ppp/pppos.h
index 6b1c995..d924a9f 100644
--- a/net/ip/lwip_base/include/netif/ppp/pppos.h
+++ b/net/ip/lwip_base/include/netif/ppp/pppos.h
@@ -42,10 +42,6 @@
#include "ppp.h"
#include "vj.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/* PPP packet parser states. Current state indicates operation yet to be
* completed. */
enum {
@@ -119,8 +115,4 @@ err_t pppos_input_sys(struct pbuf *p, struct netif *inp);
#endif /* !NO_SYS && !PPP_INPROC_IRQ_SAFE */
#endif /* PPPOS_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/upap.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/upap.h b/net/ip/lwip_base/include/netif/ppp/upap.h
index 0d9dd1c..7da792e 100644
--- a/net/ip/lwip_base/include/netif/ppp/upap.h
+++ b/net/ip/lwip_base/include/netif/ppp/upap.h
@@ -50,10 +50,6 @@
#include "ppp.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Packet header = Code, id, length.
*/
@@ -124,8 +120,4 @@ void upap_authpeer(ppp_pcb *pcb);
extern const struct protent pap_protent;
#endif /* UPAP_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && PAP_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/netif/ppp/vj.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/netif/ppp/vj.h b/net/ip/lwip_base/include/netif/ppp/vj.h
index b386c01..7f389c8 100644
--- a/net/ip/lwip_base/include/netif/ppp/vj.h
+++ b/net/ip/lwip_base/include/netif/ppp/vj.h
@@ -31,10 +31,6 @@
#include "lwip/ip.h"
#include "lwip/priv/tcp_priv.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#define MAX_SLOTS 16 /* must be > 2 and < 256 */
#define MAX_HDR 128
@@ -162,8 +158,4 @@ extern int vj_uncompress_tcp (struct pbuf **nb, struct vjcompress *comp);
#endif /* VJ_H */
-#ifdef __cplusplus
-}
-#endif
-
#endif /* PPP_SUPPORT && VJ_SUPPORT */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/include/posix/errno.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/include/posix/errno.h b/net/ip/lwip_base/include/posix/errno.h
new file mode 100644
index 0000000..5917c75
--- /dev/null
+++ b/net/ip/lwip_base/include/posix/errno.h
@@ -0,0 +1,33 @@
+/**
+ * @file
+ * This file is a posix wrapper for lwip/errno.h.
+ */
+
+/*
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ *
+ */
+
+#include "lwip/errno.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/Filelists.mk
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/Filelists.mk b/net/ip/lwip_base/src/Filelists.mk
index 2dd0d36..7d30bb8 100644
--- a/net/ip/lwip_base/src/Filelists.mk
+++ b/net/ip/lwip_base/src/Filelists.mk
@@ -164,10 +164,18 @@ MDNSFILES=$(LWIPDIR)/apps/mdns/mdns.c
# NETBIOSNSFILES: NetBIOS name server
NETBIOSNSFILES=$(LWIPDIR)/apps/netbiosns/netbiosns.c
+# TFTPFILES: TFTP server files
+TFTPFILES=$(LWIPDIR)/apps/tftp/tftp_server.c
+
+# MQTTFILES: MQTT client files
+MQTTFILES=$(LWIPDIR)/apps/mqtt/mqtt.c
+
# LWIPAPPFILES: All LWIP APPs
LWIPAPPFILES=$(SNMPFILES) \
$(HTTPDFILES) \
$(LWIPERFFILES) \
$(SNTPFILES) \
$(MDNSFILES) \
- $(NETBIOSNSFILES)
+ $(NETBIOSNSFILES) \
+ $(TFTPFILES) \
+ $(MQTTFILES)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/api/api_lib.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/api/api_lib.c b/net/ip/lwip_base/src/api/api_lib.c
index 740fe39..3c1d6a6 100644
--- a/net/ip/lwip_base/src/api/api_lib.c
+++ b/net/ip/lwip_base/src/api/api_lib.c
@@ -3,7 +3,7 @@
* Sequential API External module
*
* @defgroup netconn Netconn API
- * @ingroup threadsafe_api
+ * @ingroup sequential_api
* Thread-safe, to be called from non-TCPIP threads only.
* TX/RX handling based on @ref netbuf (containing @ref pbuf)
* to avoid copying data around.
@@ -241,8 +241,8 @@ netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local)
* Binding one netconn twice might not always be checked correctly!
*
* @param conn the netconn to bind
- * @param addr the local IP address to bind the netconn to (use IP_ADDR_ANY
- * to bind to all addresses)
+ * @param addr the local IP address to bind the netconn to
+ * (use IP4_ADDR_ANY/IP6_ADDR_ANY to bind to all addresses)
* @param port the local port to bind the netconn to (not used for RAW)
* @return ERR_OK if bound, any other err_t on failure
*/
@@ -254,10 +254,22 @@ netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port)
LWIP_ERROR("netconn_bind: invalid conn", (conn != NULL), return ERR_ARG;);
+#if LWIP_IPV4
/* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent functions */
if (addr == NULL) {
- addr = IP_ADDR_ANY;
+ addr = IP4_ADDR_ANY;
}
+#endif /* LWIP_IPV4 */
+
+#if LWIP_IPV4 && LWIP_IPV6
+ /* "Socket API like" dual-stack support: If IP to bind to is IP6_ADDR_ANY,
+ * and NETCONN_FLAG_IPV6_V6ONLY is 0, use IP_ANY_TYPE to bind
+ */
+ if ((netconn_get_ipv6only(conn) == 0) &&
+ ip_addr_cmp(addr, IP6_ADDR_ANY)) {
+ addr = IP_ANY_TYPE;
+ }
+#endif /* LWIP_IPV4 && LWIP_IPV6 */
API_MSG_VAR_ALLOC(msg);
API_MSG_VAR_REF(msg).conn = conn;
@@ -286,10 +298,12 @@ netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port)
LWIP_ERROR("netconn_connect: invalid conn", (conn != NULL), return ERR_ARG;);
+#if LWIP_IPV4
/* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent functions */
if (addr == NULL) {
- addr = IP_ADDR_ANY;
+ addr = IP4_ADDR_ANY;
}
+#endif /* LWIP_IPV4 */
API_MSG_VAR_ALLOC(msg);
API_MSG_VAR_REF(msg).conn = conn;
@@ -306,7 +320,7 @@ netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port)
* Disconnect a netconn from its current peer (only valid for UDP netconns).
*
* @param conn the netconn to disconnect
- * @return @todo: return value is not set here...
+ * @return See @ref err_t
*/
err_t
netconn_disconnect(struct netconn *conn)
@@ -376,7 +390,6 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
#if LWIP_TCP
void *accept_ptr;
struct netconn *newconn;
- err_t err;
#if TCP_LISTEN_BACKLOG
API_MSG_VAR_DECLARE(msg);
#endif /* TCP_LISTEN_BACKLOG */
@@ -385,11 +398,10 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
*new_conn = NULL;
LWIP_ERROR("netconn_accept: invalid conn", (conn != NULL), return ERR_ARG;);
- err = conn->last_err;
- if (ERR_IS_FATAL(err)) {
+ if (ERR_IS_FATAL(conn->last_err)) {
/* don't recv on fatal errors: this might block the application task
waiting on acceptmbox forever! */
- return err;
+ return conn->last_err;
}
if (!sys_mbox_valid(&conn->acceptmbox)) {
return ERR_CLSD;
@@ -465,7 +477,6 @@ netconn_recv_data(struct netconn *conn, void **new_buf)
{
void *buf = NULL;
u16_t len;
- err_t err;
#if LWIP_TCP
API_MSG_VAR_DECLARE(msg);
#if LWIP_MPU_COMPATIBLE
@@ -489,13 +500,12 @@ netconn_recv_data(struct netconn *conn, void **new_buf)
#endif /* LWIP_TCP */
LWIP_ERROR("netconn_recv: invalid recvmbox", sys_mbox_valid(&conn->recvmbox), return ERR_CONN;);
- err = conn->last_err;
- if (ERR_IS_FATAL(err)) {
+ if (ERR_IS_FATAL(conn->last_err)) {
/* don't recv on fatal errors: this might block the application task
waiting on recvmbox forever! */
/* @todo: this does not allow us to fetch data that has been put into recvmbox
before the fatal error occurred - is that a problem? */
- return err;
+ return conn->last_err;
}
#if LWIP_TCP
#if (LWIP_UDP || LWIP_RAW)
@@ -544,6 +554,10 @@ netconn_recv_data(struct netconn *conn, void **new_buf)
/* If we are closed, we indicate that we no longer wish to use the socket */
if (buf == NULL) {
API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0);
+ if (conn->pcb.ip == NULL) {
+ /* race condition: RST during recv */
+ return conn->last_err == ERR_OK ? ERR_RST : conn->last_err;
+ }
/* RX side is closed, so deallocate the recvmbox */
netconn_close_shutdown(conn, NETCONN_SHUT_RD);
/* Don' store ERR_CLSD as conn->err since we are only half-closed */
@@ -558,7 +572,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf)
#if (LWIP_UDP || LWIP_RAW)
{
LWIP_ASSERT("buf != NULL", buf != NULL);
- len = netbuf_len((struct netbuf *)buf);
+ len = netbuf_len((struct netbuf*)buf);
}
#endif /* (LWIP_UDP || LWIP_RAW) */
@@ -693,6 +707,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
LWIP_ERROR("netconn_send: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %"U16_F" bytes\n", buf->p->tot_len));
+
API_MSG_VAR_ALLOC(msg);
API_MSG_VAR_REF(msg).conn = conn;
API_MSG_VAR_REF(msg).msg.b = buf;
@@ -730,6 +745,11 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
return ERR_OK;
}
dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK);
+#if LWIP_SO_SNDTIMEO
+ if (conn->send_timeout != 0) {
+ dontblock = 1;
+ }
+#endif /* LWIP_SO_SNDTIMEO */
if (dontblock && !bytes_written) {
/* This implies netconn_write() cannot be used for non-blocking send, since
it has no way to return the number of bytes written. */
@@ -757,11 +777,7 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
non-blocking version here. */
err = netconn_apimsg(lwip_netconn_do_write, &API_MSG_VAR_REF(msg));
if ((err == ERR_OK) && (bytes_written != NULL)) {
- if (dontblock
-#if LWIP_SO_SNDTIMEO
- || (conn->send_timeout != 0)
-#endif /* LWIP_SO_SNDTIMEO */
- ) {
+ if (dontblock) {
/* nonblocking write: maybe the data has been sent partly */
*bytes_written = API_MSG_VAR_REF(msg).msg.w.len;
} else {
@@ -865,13 +881,15 @@ netconn_join_leave_group(struct netconn *conn,
API_MSG_VAR_ALLOC(msg);
+#if LWIP_IPV4
/* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent functions */
if (multiaddr == NULL) {
- multiaddr = IP_ADDR_ANY;
+ multiaddr = IP4_ADDR_ANY;
}
if (netif_addr == NULL) {
- netif_addr = IP_ADDR_ANY;
+ netif_addr = IP4_ADDR_ANY;
}
+#endif /* LWIP_IPV4 */
API_MSG_VAR_REF(msg).conn = conn;
API_MSG_VAR_REF(msg).msg.jl.multiaddr = API_MSG_VAR_REF(multiaddr);
@@ -910,6 +928,7 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr)
sys_sem_t sem;
#endif /* LWIP_MPU_COMPATIBLE */
err_t err;
+ err_t cberr;
LWIP_ERROR("netconn_gethostbyname: invalid name", (name != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_gethostbyname: invalid addr", (addr != NULL), return ERR_ARG;);
@@ -942,13 +961,13 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr)
}
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
- err = tcpip_callback(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg));
- if (err != ERR_OK) {
+ cberr = tcpip_callback(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg));
+ if (cberr != ERR_OK) {
#if !LWIP_NETCONN_SEM_PER_THREAD
sys_sem_free(API_EXPR_REF(API_VAR_REF(msg).sem));
#endif /* !LWIP_NETCONN_SEM_PER_THREAD */
API_VAR_FREE(MEMP_DNS_API_MSG, msg);
- return err;
+ return cberr;
}
sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem));
#if !LWIP_NETCONN_SEM_PER_THREAD
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/api/api_msg.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/api/api_msg.c b/net/ip/lwip_base/src/api/api_msg.c
index 9dfea64..dd99c1e 100644
--- a/net/ip/lwip_base/src/api/api_msg.c
+++ b/net/ip/lwip_base/src/api/api_msg.c
@@ -43,6 +43,7 @@
#include "lwip/priv/api_msg.h"
#include "lwip/ip.h"
+#include "lwip/ip_addr.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/raw.h"
@@ -540,26 +541,41 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
* Called from lwip_netconn_do_newconn().
*
* @param msg the api_msg_msg describing the connection type
- * @return msg->conn->err, but the return value is currently ignored
*/
static void
pcb_new(struct api_msg *msg)
{
- LWIP_ASSERT("pcb_new: pcb already allocated", msg->conn->pcb.tcp == NULL);
+ enum lwip_ip_addr_type iptype = IPADDR_TYPE_V4;
+ LWIP_ASSERT("pcb_new: pcb already allocated", msg->conn->pcb.tcp == NULL);
+
+#if LWIP_IPV6 && LWIP_IPV4
+ /* IPv6: Dual-stack by default, unless netconn_set_ipv6only() is called */
+ if(NETCONNTYPE_ISIPV6(netconn_type(msg->conn))) {
+ iptype = IPADDR_TYPE_ANY;
+ }
+#endif
+
/* Allocate a PCB for this connection */
switch(NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
- msg->conn->pcb.raw = raw_new(msg->msg.n.proto);
+ msg->conn->pcb.raw = raw_new_ip_type(iptype, msg->msg.n.proto);
if (msg->conn->pcb.raw != NULL) {
+#if LWIP_IPV6
+ /* ICMPv6 packets should always have checksum calculated by the stack as per RFC 3542 chapter 3.1 */
+ if (NETCONNTYPE_ISIPV6(msg->conn->type) && msg->conn->pcb.raw->protocol == IP6_NEXTH_ICMP6) {
+ msg->conn->pcb.raw->chksum_reqd = 1;
+ msg->conn->pcb.raw->chksum_offset = 2;
+ }
+#endif /* LWIP_IPV6 */
raw_recv(msg->conn->pcb.raw, recv_raw, msg->conn);
}
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
- msg->conn->pcb.udp = udp_new();
+ msg->conn->pcb.udp = udp_new_ip_type(iptype);
if (msg->conn->pcb.udp != NULL) {
#if LWIP_UDPLITE
if (NETCONNTYPE_ISUDPLITE(msg->conn->type)) {
@@ -575,7 +591,7 @@ pcb_new(struct api_msg *msg)
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
- msg->conn->pcb.tcp = tcp_new();
+ msg->conn->pcb.tcp = tcp_new_ip_type(iptype);
if (msg->conn->pcb.tcp != NULL) {
setup_tcp(msg->conn);
}
@@ -589,15 +605,6 @@ pcb_new(struct api_msg *msg)
if (msg->conn->pcb.ip == NULL) {
msg->err = ERR_MEM;
}
-#if LWIP_IPV4 && LWIP_IPV6
- else {
- if (NETCONNTYPE_ISIPV6(msg->conn->type)) {
- /* Convert IPv4 PCB manually to an IPv6 PCB */
- IP_SET_TYPE_VAL(msg->conn->pcb.ip->local_ip, IPADDR_TYPE_V6);
- IP_SET_TYPE_VAL(msg->conn->pcb.ip->remote_ip, IPADDR_TYPE_V6);
- }
- }
-#endif /* LWIP_IPV4 && LWIP_IPV6 */
}
/**
@@ -781,16 +788,18 @@ netconn_drain(struct netconn *conn)
#if LWIP_TCP
if (sys_mbox_valid(&conn->acceptmbox)) {
while (sys_mbox_tryfetch(&conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) {
- struct netconn *newconn = (struct netconn *)mem;
- /* Only tcp pcbs have an acceptmbox, so no need to check conn->type */
- /* pcb might be set to NULL already by err_tcp() */
- /* drain recvmbox */
- netconn_drain(newconn);
- if (newconn->pcb.tcp != NULL) {
- tcp_abort(newconn->pcb.tcp);
- newconn->pcb.tcp = NULL;
+ if (mem != &netconn_aborted) {
+ struct netconn *newconn = (struct netconn *)mem;
+ /* Only tcp pcbs have an acceptmbox, so no need to check conn->type */
+ /* pcb might be set to NULL already by err_tcp() */
+ /* drain recvmbox */
+ netconn_drain(newconn);
+ if (newconn->pcb.tcp != NULL) {
+ tcp_abort(newconn->pcb.tcp);
+ newconn->pcb.tcp = NULL;
+ }
+ netconn_free(newconn);
}
- netconn_free(newconn);
}
sys_mbox_free(&conn->acceptmbox);
sys_mbox_set_invalid(&conn->acceptmbox);
@@ -805,7 +814,6 @@ netconn_drain(struct netconn *conn)
* places.
*
* @param conn the TCP netconn to close
- * [@param delay 1 if called from sent/poll (wake up calling thread on end)]
*/
static err_t
lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
@@ -1113,37 +1121,20 @@ lwip_netconn_do_bind(void *m)
} else {
msg->err = ERR_VAL;
if (msg->conn->pcb.tcp != NULL) {
- const ip_addr_t *ipaddr = API_EXPR_REF(msg->msg.bc.ipaddr);
-
-#if LWIP_IPV4 && LWIP_IPV6
- /* "Socket API like" dual-stack support: If IP to bind to is IP6_ADDR_ANY,
- * and NETCONN_FLAG_IPV6_V6ONLY is NOT set, use IP_ANY_TYPE to bind
- */
- if (ip_addr_cmp(ipaddr, IP6_ADDR_ANY) &&
- (netconn_get_ipv6only(msg->conn) == 0)) {
- /* change PCB type to IPADDR_TYPE_ANY */
- IP_SET_TYPE_VAL(msg->conn->pcb.ip->local_ip, IPADDR_TYPE_ANY);
- IP_SET_TYPE_VAL(msg->conn->pcb.ip->remote_ip, IPADDR_TYPE_ANY);
-
- /* bind to IPADDR_TYPE_ANY */
- ipaddr = IP_ANY_TYPE;
- }
-#endif /* LWIP_IPV4 && LWIP_IPV6 */
-
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
- msg->err = raw_bind(msg->conn->pcb.raw, ipaddr);
+ msg->err = raw_bind(msg->conn->pcb.raw, API_EXPR_REF(msg->msg.bc.ipaddr));
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
- msg->err = udp_bind(msg->conn->pcb.udp, ipaddr, msg->msg.bc.port);
+ msg->err = udp_bind(msg->conn->pcb.udp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
- msg->err = tcp_bind(msg->conn->pcb.tcp, ipaddr, msg->msg.bc.port);
+ msg->err = tcp_bind(msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
#endif /* LWIP_TCP */
default:
@@ -1323,6 +1314,13 @@ lwip_netconn_do_listen(void *m)
/* connection is not closed, cannot listen */
msg->err = ERR_VAL;
} else {
+ err_t err;
+ u8_t backlog;
+#if TCP_LISTEN_BACKLOG
+ backlog = msg->msg.lb.backlog;
+#else /* TCP_LISTEN_BACKLOG */
+ backlog = TCP_DEFAULT_LISTEN_BACKLOG;
+#endif /* TCP_LISTEN_BACKLOG */
#if LWIP_IPV4 && LWIP_IPV6
/* "Socket API like" dual-stack support: If IP to listen to is IP6_ADDR_ANY,
* and NETCONN_FLAG_IPV6_V6ONLY is NOT set, use IP_ANY_TYPE to listen
@@ -1335,15 +1333,11 @@ lwip_netconn_do_listen(void *m)
}
#endif /* LWIP_IPV4 && LWIP_IPV6 */
-#if TCP_LISTEN_BACKLOG
- lpcb = tcp_listen_with_backlog(msg->conn->pcb.tcp, msg->msg.lb.backlog);
-#else /* TCP_LISTEN_BACKLOG */
- lpcb = tcp_listen(msg->conn->pcb.tcp);
-#endif /* TCP_LISTEN_BACKLOG */
+ lpcb = tcp_listen_with_backlog_and_err(msg->conn->pcb.tcp, backlog, &err);
if (lpcb == NULL) {
/* in this case, the old pcb is still allocated */
- msg->err = ERR_MEM;
+ msg->err = err;
} else {
/* delete the recvmbox and allocate the acceptmbox */
if (sys_mbox_valid(&msg->conn->recvmbox)) {
@@ -1400,7 +1394,7 @@ lwip_netconn_do_send(void *m)
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
- if (ip_addr_isany(&msg->msg.b->addr)) {
+ if (ip_addr_isany(&msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
msg->err = raw_send(msg->conn->pcb.raw, msg->msg.b->p);
} else {
msg->err = raw_sendto(msg->conn->pcb.raw, msg->msg.b->p, &msg->msg.b->addr);
@@ -1490,7 +1484,6 @@ lwip_netconn_do_accepted(void *m)
* blocking application thread (waiting in netconn_write) is released.
*
* @param conn netconn (that is currently in state NETCONN_WRITE) to process
- * [@param delay 1 if called from sent/poll (wake up calling thread on end)]
* @return ERR_OK
* ERR_MEM if LWIP_TCPIP_CORE_LOCKING=1 and sending hasn't yet finished
*/
@@ -1512,9 +1505,8 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
LWIP_ASSERT("conn->write_offset < conn->current_msg->msg.w.len",
conn->write_offset < conn->current_msg->msg.w.len);
- dontblock = netconn_is_nonblocking(conn) ||
- (conn->current_msg->msg.w.apiflags & NETCONN_DONTBLOCK);
apiflags = conn->current_msg->msg.w.apiflags;
+ dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK);
#if LWIP_SO_SNDTIMEO
if ((conn->send_timeout != 0) &&
@@ -1590,10 +1582,11 @@ err_mem:
write_finished = 1;
conn->current_msg->msg.w.len = 0;
}
- } else if ((err == ERR_MEM) && !dontblock) {
- /* If ERR_MEM, we wait for sent_tcp or poll_tcp to be called
- we do NOT return to the application thread, since ERR_MEM is
- only a temporary error! */
+ } else if (err == ERR_MEM) {
+ /* If ERR_MEM, we wait for sent_tcp or poll_tcp to be called.
+ For blocking sockets, we do NOT return to the application
+ thread, since ERR_MEM is only a temporary error! Non-blocking
+ will remain non-writable until sent_tcp/poll_tcp is called */
/* tcp_write returned ERR_MEM, try tcp_output anyway */
err_t out_err = tcp_output(conn->pcb.tcp);
@@ -1604,7 +1597,11 @@ err_mem:
err = out_err;
write_finished = 1;
conn->current_msg->msg.w.len = 0;
- } else {
+ } else if (dontblock) {
+ /* non-blocking write is done on ERR_MEM */
+ err = ERR_WOULDBLOCK;
+ write_finished = 1;
+ conn->current_msg->msg.w.len = 0;
}
} else {
/* On errors != ERR_MEM, we don't try writing any more but return
@@ -1713,6 +1710,7 @@ lwip_netconn_do_getaddr(void *m)
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr),
msg->conn->pcb.ip->remote_ip);
}
+
msg->err = ERR_OK;
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
@@ -1786,25 +1784,28 @@ lwip_netconn_do_close(void *m)
#if LWIP_NETCONN_FULLDUPLEX
if (msg->msg.sd.shut & NETCONN_SHUT_WR) {
/* close requested, abort running write */
- sys_sem_t* op_completed_sem;
+ sys_sem_t* write_completed_sem;
LWIP_ASSERT("msg->conn->current_msg != NULL", msg->conn->current_msg != NULL);
- op_completed_sem = LWIP_API_MSG_SEM(msg->conn->current_msg);
+ write_completed_sem = LWIP_API_MSG_SEM(msg->conn->current_msg);
msg->conn->current_msg->err = ERR_CLSD;
msg->conn->current_msg = NULL;
msg->conn->write_offset = 0;
msg->conn->state = NETCONN_NONE;
+ state = NETCONN_NONE;
NETCONN_SET_SAFE_ERR(msg->conn, ERR_CLSD);
- sys_sem_signal(op_completed_sem);
+ sys_sem_signal(write_completed_sem);
} else {
LWIP_ASSERT("msg->msg.sd.shut == NETCONN_SHUT_RD", msg->msg.sd.shut == NETCONN_SHUT_RD);
/* In this case, let the write continue and do not interfere with
conn->current_msg or conn->state! */
msg->err = tcp_shutdown(msg->conn->pcb.tcp, 1, 0);
}
+ }
+ if (state == NETCONN_NONE) {
#else /* LWIP_NETCONN_FULLDUPLEX */
msg->err = ERR_INPROGRESS;
-#endif /* LWIP_NETCONN_FULLDUPLEX */
} else {
+#endif /* LWIP_NETCONN_FULLDUPLEX */
if (msg->msg.sd.shut & NETCONN_SHUT_RD) {
/* Drain and delete mboxes */
netconn_drain(msg->conn);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/api/err.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/api/err.c b/net/ip/lwip_base/src/api/err.c
index f3650f4..35e9c02 100644
--- a/net/ip/lwip_base/src/api/err.c
+++ b/net/ip/lwip_base/src/api/err.c
@@ -37,6 +37,43 @@
*/
#include "lwip/err.h"
+#include "lwip/def.h"
+#include "lwip/sys.h"
+
+#include "lwip/errno.h"
+
+#if !NO_SYS
+/** Table to quickly map an lwIP error (err_t) to a socket error
+ * by using -err as an index */
+static const int err_to_errno_table[] = {
+ 0, /* ERR_OK 0 No error, everything OK. */
+ ENOMEM, /* ERR_MEM -1 Out of memory error. */
+ ENOBUFS, /* ERR_BUF -2 Buffer error. */
+ EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
+ EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
+ EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
+ EINVAL, /* ERR_VAL -6 Illegal value. */
+ EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
+ EADDRINUSE, /* ERR_USE -8 Address in use. */
+ EALREADY, /* ERR_ALREADY -9 Already connecting. */
+ EISCONN, /* ERR_ISCONN -10 Conn already established.*/
+ ENOTCONN, /* ERR_CONN -11 Not connected. */
+ -1, /* ERR_IF -12 Low-level netif error */
+ ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */
+ ECONNRESET, /* ERR_RST -14 Connection reset. */
+ ENOTCONN, /* ERR_CLSD -15 Connection closed. */
+ EIO /* ERR_ARG -16 Illegal argument. */
+};
+
+int
+err_to_errno(err_t err)
+{
+ if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_to_errno_table))) {
+ return EIO;
+ }
+ return err_to_errno_table[-err];
+}
+#endif /* !NO_SYS */
#ifdef LWIP_DEBUG
@@ -69,6 +106,9 @@ static const char *err_strerr[] = {
const char *
lwip_strerr(err_t err)
{
+ if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) {
+ return "Unknown error.";
+ }
return err_strerr[-err];
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/api/netdb.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/api/netdb.c b/net/ip/lwip_base/src/api/netdb.c
index 670f6b9..ccd9586 100644
--- a/net/ip/lwip_base/src/api/netdb.c
+++ b/net/ip/lwip_base/src/api/netdb.c
@@ -46,8 +46,8 @@
#include "lwip/api.h"
#include "lwip/dns.h"
-#include <string.h>
-#include <stdlib.h>
+#include <string.h> /* memset */
+#include <stdlib.h> /* atoi */
/** helper struct for gethostbyname_r to access the char* buffer */
struct gethostbyname_r_helper {
@@ -375,17 +375,17 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
inet6_addr_from_ip6addr(&sa6->sin6_addr, ip_2_ip6(&addr));
sa6->sin6_family = AF_INET6;
sa6->sin6_len = sizeof(struct sockaddr_in6);
- sa6->sin6_port = htons((u16_t)port_nr);
+ sa6->sin6_port = lwip_htons((u16_t)port_nr);
ai->ai_family = AF_INET6;
#endif /* LWIP_IPV6 */
} else {
#if LWIP_IPV4
struct sockaddr_in *sa4 = (struct sockaddr_in*)sa;
/* set up sockaddr */
- inet_addr_from_ipaddr(&sa4->sin_addr, ip_2_ip4(&addr));
+ inet_addr_from_ip4addr(&sa4->sin_addr, ip_2_ip4(&addr));
sa4->sin_family = AF_INET;
sa4->sin_len = sizeof(struct sockaddr_in);
- sa4->sin_port = htons((u16_t)port_nr);
+ sa4->sin_port = lwip_htons((u16_t)port_nr);
ai->ai_family = AF_INET;
#endif /* LWIP_IPV4 */
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/api/netifapi.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/api/netifapi.c b/net/ip/lwip_base/src/api/netifapi.c
index 265b60c..fef05a3 100644
--- a/net/ip/lwip_base/src/api/netifapi.c
+++ b/net/ip/lwip_base/src/api/netifapi.c
@@ -3,7 +3,7 @@
* Network Interface Sequential API module
*
* @defgroup netifapi NETIF API
- * @ingroup threadsafe_api
+ * @ingroup sequential_api
* Thread-safe functions to be called from non-TCPIP threads
*
* @defgroup netifapi_netif NETIF related
@@ -134,13 +134,13 @@ netifapi_netif_add(struct netif *netif,
#if LWIP_IPV4
if (ipaddr == NULL) {
- ipaddr = IP4_ADDR_ANY;
+ ipaddr = IP4_ADDR_ANY4;
}
if (netmask == NULL) {
- netmask = IP4_ADDR_ANY;
+ netmask = IP4_ADDR_ANY4;
}
if (gw == NULL) {
- gw = IP4_ADDR_ANY;
+ gw = IP4_ADDR_ANY4;
}
#endif /* LWIP_IPV4 */
@@ -177,13 +177,13 @@ netifapi_netif_set_addr(struct netif *netif,
NETIFAPI_VAR_ALLOC(msg);
if (ipaddr == NULL) {
- ipaddr = IP4_ADDR_ANY;
+ ipaddr = IP4_ADDR_ANY4;
}
if (netmask == NULL) {
- netmask = IP4_ADDR_ANY;
+ netmask = IP4_ADDR_ANY4;
}
if (gw == NULL) {
- gw = IP4_ADDR_ANY;
+ gw = IP4_ADDR_ANY4;
}
NETIFAPI_VAR_REF(msg).netif = netif;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/api/sockets.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/api/sockets.c b/net/ip/lwip_base/src/api/sockets.c
index 72e777d..b763248 100644
--- a/net/ip/lwip_base/src/api/sockets.c
+++ b/net/ip/lwip_base/src/api/sockets.c
@@ -3,7 +3,7 @@
* Sockets BSD-Like API module
*
* @defgroup socket Socket API
- * @ingroup threadsafe_api
+ * @ingroup sequential_api
* BSD-style socket API.\n
* Thread-safe, to be called from non-TCPIP threads only.\n
* Can be activated by defining @ref LWIP_SOCKET to 1.\n
@@ -81,25 +81,25 @@
#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \
(sin)->sin_len = sizeof(struct sockaddr_in); \
(sin)->sin_family = AF_INET; \
- (sin)->sin_port = htons((port)); \
- inet_addr_from_ipaddr(&(sin)->sin_addr, ipaddr); \
+ (sin)->sin_port = lwip_htons((port)); \
+ inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \
memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0)
#define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipaddr, port) do { \
- inet_addr_to_ipaddr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \
- (port) = ntohs((sin)->sin_port); }while(0)
+ inet_addr_to_ip4addr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \
+ (port) = lwip_ntohs((sin)->sin_port); }while(0)
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \
(sin6)->sin6_len = sizeof(struct sockaddr_in6); \
(sin6)->sin6_family = AF_INET6; \
- (sin6)->sin6_port = htons((port)); \
+ (sin6)->sin6_port = lwip_htons((port)); \
(sin6)->sin6_flowinfo = 0; \
inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \
(sin6)->sin6_scope_id = 0; }while(0)
#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \
inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \
- (port) = ntohs((sin6)->sin6_port); }while(0)
+ (port) = lwip_ntohs((sin6)->sin6_port); }while(0)
#endif /* LWIP_IPV6 */
#if LWIP_IPV4 && LWIP_IPV6
@@ -266,8 +266,8 @@ union sockaddr_aligned {
/* This is to keep track of IP_ADD_MEMBERSHIP calls to drop the membership when
a socket is closed */
struct lwip_socket_multicast_pair {
- /** the socket (+1 to not require initialization) */
- int sa;
+ /** the socket */
+ struct lwip_sock* sock;
/** the interface address */
ip4_addr_t if_addr;
/** the group address */
@@ -289,34 +289,6 @@ static struct lwip_select_cb *select_cb_list;
and checked in event_callback to see if it has changed. */
static volatile int select_cb_ctr;
-/** Table to quickly map an lwIP error (err_t) to a socket error
- * by using -err as an index */
-static const int err_to_errno_table[] = {
- 0, /* ERR_OK 0 No error, everything OK. */
- ENOMEM, /* ERR_MEM -1 Out of memory error. */
- ENOBUFS, /* ERR_BUF -2 Buffer error. */
- EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
- EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
- EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
- EINVAL, /* ERR_VAL -6 Illegal value. */
- EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
- EADDRINUSE, /* ERR_USE -8 Address in use. */
- EALREADY, /* ERR_ALREADY -9 Already connecting. */
- EISCONN, /* ERR_ISCONN -10 Conn already established.*/
- ENOTCONN, /* ERR_CONN -11 Not connected. */
- -1, /* ERR_IF -12 Low-level netif error */
- ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */
- ECONNRESET, /* ERR_RST -14 Connection reset. */
- ENOTCONN, /* ERR_CLSD -15 Connection closed. */
- EIO /* ERR_ARG -16 Illegal argument. */
-};
-
-#define ERR_TO_ERRNO_TABLE_SIZE LWIP_ARRAYSIZE(err_to_errno_table)
-
-#define err_to_errno(err) \
- ((unsigned)(-(signed)(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \
- err_to_errno_table[-(signed)(err)] : EIO)
-
#if LWIP_SOCKET_SET_ERRNO
#ifndef set_errno
#define set_errno(err) do { if (err) { errno = (err); } } while(0)
@@ -435,7 +407,7 @@ alloc_socket(struct netconn *newconn, int accepted)
for (i = 0; i < NUM_SOCKETS; ++i) {
/* Protect socket array */
SYS_ARCH_PROTECT(lev);
- if (!sockets[i].conn) {
+ if (!sockets[i].conn && (sockets[i].select_waiting == 0)) {
sockets[i].conn = newconn;
/* The socket is not yet known to anyone, so no need to protect
after having marked it as used. */
@@ -448,7 +420,6 @@ alloc_socket(struct netconn *newconn, int accepted)
sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1);
sockets[i].errevent = 0;
sockets[i].err = 0;
- sockets[i].select_waiting = 0;
return i + LWIP_SOCKET_OFFSET;
}
SYS_ARCH_UNPROTECT(lev);
@@ -510,7 +481,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
if (netconn_is_nonblocking(sock->conn) && (sock->rcvevent <= 0)) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): returning EWOULDBLOCK\n", s));
- sock_set_errno(sock, EWOULDBLOCK);
+ set_errno(EWOULDBLOCK);
return -1;
}
@@ -612,6 +583,14 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
ip_addr_debug_print_val(SOCKETS_DEBUG, local_addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", local_port));
+#if LWIP_IPV4 && LWIP_IPV6
+ /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */
+ if (IP_IS_V6_VAL(local_addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&local_addr))) {
+ unmap_ipv4_mapped_ipv6(ip_2_ip4(&local_addr), ip_2_ip6(&local_addr));
+ IP_SET_TYPE_VAL(local_addr, IPADDR_TYPE_V4);
+ }
+#endif /* LWIP_IPV4 && LWIP_IPV6 */
+
err = netconn_bind(sock->conn, &local_addr, local_port);
if (err != ERR_OK) {
@@ -696,6 +675,14 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
ip_addr_debug_print_val(SOCKETS_DEBUG, remote_addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", remote_port));
+#if LWIP_IPV4 && LWIP_IPV6
+ /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */
+ if (IP_IS_V6_VAL(remote_addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&remote_addr))) {
+ unmap_ipv4_mapped_ipv6(ip_2_ip4(&remote_addr), ip_2_ip6(&remote_addr));
+ IP_SET_TYPE_VAL(remote_addr, IPADDR_TYPE_V4);
+ }
+#endif /* LWIP_IPV4 && LWIP_IPV6 */
+
err = netconn_connect(sock->conn, &remote_addr, remote_port);
}
@@ -783,7 +770,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
return off;
}
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): returning EWOULDBLOCK\n", s));
- sock_set_errno(sock, EWOULDBLOCK);
+ set_errno(EWOULDBLOCK);
return -1;
}
@@ -875,6 +862,15 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
port = netbuf_fromport((struct netbuf *)buf);
fromaddr = netbuf_fromaddr((struct netbuf *)buf);
}
+
+#if LWIP_IPV4 && LWIP_IPV6
+ /* Dual-stack: Map IPv4 addresses to IPv4 mapped IPv6 */
+ if (NETCONNTYPE_ISIPV6(netconn_type(sock->conn)) && IP_IS_V4(fromaddr)) {
+ ip4_2_ipv4_mapped_ipv6(ip_2_ip6(fromaddr), ip_2_ip4(fromaddr));
+ IP_SET_TYPE(fromaddr, IPADDR_TYPE_V6);
+ }
+#endif /* LWIP_IPV4 && LWIP_IPV6 */
+
IPADDR_PORT_TO_SOCKADDR(&saddr, fromaddr, port);
ip_addr_debug_print(SOCKETS_DEBUG, fromaddr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F" len=%d\n", port, off));
@@ -998,6 +994,10 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags)
((flags & MSG_DONTWAIT) ? NETCONN_DONTBLOCK : 0);
for (i = 0; i < msg->msg_iovlen; i++) {
+ u8_t apiflags = write_flags;
+ if (i + 1 < msg->msg_iovlen) {
+ apiflags |= NETCONN_MORE;
+ }
written = 0;
err = netconn_write_partly(sock->conn, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, write_flags, &written);
if (err == ERR_OK) {
@@ -1094,6 +1094,14 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags)
#endif /* LWIP_NETIF_TX_SINGLE_PBUF */
if (err == ERR_OK) {
+#if LWIP_IPV4 && LWIP_IPV6
+ /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */
+ if (IP_IS_V6_VAL(chain_buf->addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&chain_buf->addr))) {
+ unmap_ipv4_mapped_ipv6(ip_2_ip4(&chain_buf->addr), ip_2_ip6(&chain_buf->addr));
+ IP_SET_TYPE_VAL(chain_buf->addr, IPADDR_TYPE_V4);
+ }
+#endif /* LWIP_IPV4 && LWIP_IPV6 */
+
/* send the data */
err = netconn_send(sock->conn, chain_buf);
}
@@ -1135,12 +1143,6 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
#endif /* LWIP_TCP */
}
- if ((to != NULL) && !SOCK_ADDR_TYPE_MATCH(to, sock)) {
- /* sockaddr does not match socket type (IPv4/IPv6) */
- sock_set_errno(sock, err_to_errno(ERR_VAL));
- return -1;
- }
-
/* @todo: split into multiple sendto's? */
LWIP_ASSERT("lwip_sendto: size must fit in u16_t", size <= 0xffff);
short_size = (u16_t)size;
@@ -1190,6 +1192,14 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
err = netbuf_ref(&buf, data, short_size);
#endif /* LWIP_NETIF_TX_SINGLE_PBUF */
if (err == ERR_OK) {
+#if LWIP_IPV4 && LWIP_IPV6
+ /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */
+ if (IP_IS_V6_VAL(buf.addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&buf.addr))) {
+ unmap_ipv4_mapped_ipv6(ip_2_ip4(&buf.addr), ip_2_ip6(&buf.addr));
+ IP_SET_TYPE_VAL(buf.addr, IPADDR_TYPE_V4);
+ }
+#endif /* LWIP_IPV4 && LWIP_IPV6 */
+
/* send the data */
err = netconn_send(sock->conn, &buf);
}
@@ -1207,9 +1217,7 @@ lwip_socket(int domain, int type, int protocol)
struct netconn *conn;
int i;
-#if !LWIP_IPV6
LWIP_UNUSED_ARG(domain); /* @todo: check this */
-#endif /* LWIP_IPV6 */
/* create a netconn */
switch (type) {
@@ -1272,7 +1280,7 @@ lwip_writev(int s, const struct iovec *iov, int iovcnt)
msg.msg_namelen = 0;
/* Hack: we have to cast via number to cast from 'const' pointer to non-const.
Blame the opengroup standard for this inconsistency. */
- msg.msg_iov = (struct iovec *)(size_t)iov;
+ msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov);
msg.msg_iovlen = iovcnt;
msg.msg_control = NULL;
msg.msg_controllen = 0;
@@ -1286,12 +1294,12 @@ lwip_writev(int s, const struct iovec *iov, int iovcnt)
* the sockets enabled that had events.
*
* @param maxfdp1 the highest socket index in the sets
- * @param readset_in: set of sockets to check for read events
- * @param writeset_in: set of sockets to check for write events
- * @param exceptset_in: set of sockets to check for error events
- * @param readset_out: set of sockets that had read events
- * @param writeset_out: set of sockets that had write events
- * @param exceptset_out: set os sockets that had error events
+ * @param readset_in set of sockets to check for read events
+ * @param writeset_in set of sockets to check for write events
+ * @param exceptset_in set of sockets to check for error events
+ * @param readset_out set of sockets that had read events
+ * @param writeset_out set of sockets that had write events
+ * @param exceptset_out set os sockets that had error events
* @return number of sockets that had events (read/write/exception) (>= 0)
*/
static int
@@ -1485,9 +1493,7 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
SYS_ARCH_PROTECT(lev);
sock = tryget_socket(i);
if (sock != NULL) {
- /* @todo: what if this is a new socket (reallocated?) in this case,
- select_waiting-- would be wrong (a global 'sockalloc' counter,
- stored per socket could help) */
+ /* for now, handle select_waiting==0... */
LWIP_ASSERT("sock->select_waiting > 0", sock->select_waiting > 0);
if (sock->select_waiting > 0) {
sock->select_waiting--;
@@ -1679,8 +1685,7 @@ again:
}
/**
- * Unimplemented: Close one end of a full-duplex connection.
- * Currently, the full connection is closed.
+ * Close one end of a full-duplex connection.
*/
int
lwip_shutdown(int s, int how)
@@ -1738,12 +1743,21 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
}
/* get the IP address and port */
- /* @todo: this does not work for IPv6, yet */
err = netconn_getaddr(sock->conn, &naddr, &port, local);
if (err != ERR_OK) {
sock_set_errno(sock, err_to_errno(err));
return -1;
}
+
+#if LWIP_IPV4 && LWIP_IPV6
+ /* Dual-stack: Map IPv4 addresses to IPv4 mapped IPv6 */
+ if (NETCONNTYPE_ISIPV6(netconn_type(sock->conn)) &&
+ IP_IS_V4_VAL(naddr)) {
+ ip4_2_ipv4_mapped_ipv6(ip_2_ip6(&naddr), ip_2_ip4(&naddr));
+ IP_SET_TYPE_VAL(naddr, IPADDR_TYPE_V6);
+ }
+#endif /* LWIP_IPV4 && LWIP_IPV6 */
+
IPADDR_PORT_TO_SOCKADDR(&saddr, &naddr, port);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getaddrname(%d, addr=", s));
@@ -2029,7 +2043,7 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_UDP) {
return ENOPROTOOPT;
}
- inet_addr_from_ipaddr((struct in_addr*)optval, udp_get_multicast_netif_addr(sock->conn->pcb.udp));
+ inet_addr_from_ip4addr((struct in_addr*)optval, udp_get_multicast_netif_addr(sock->conn->pcb.udp));
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_IF) = 0x%"X32_F"\n",
s, *(u32_t *)optval));
break;
@@ -2057,6 +2071,9 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
case IPPROTO_TCP:
/* Special case: all IPPROTO_TCP option take an int */
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, int, NETCONN_TCP);
+ if (sock->conn->pcb.tcp->state == LISTEN) {
+ return EINVAL;
+ }
switch (optname) {
case TCP_NODELAY:
*(int*)optval = tcp_nagle_disabled(sock->conn->pcb.tcp);
@@ -2101,10 +2118,6 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
switch (optname) {
case IPV6_V6ONLY:
LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, int);
- /* @todo: this does not work for datagram sockets, yet */
- if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) {
- return ENOPROTOOPT;
- }
*(int*)optval = (netconn_get_ipv6only(sock->conn) ? 1 : 0);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IPV6, IPV6_V6ONLY) = %d\n",
s, *(int *)optval));
@@ -2393,7 +2406,7 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
{
ip4_addr_t if_addr;
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct in_addr, NETCONN_UDP);
- inet_addr_to_ipaddr(&if_addr, (const struct in_addr*)optval);
+ inet_addr_to_ip4addr(&if_addr, (const struct in_addr*)optval);
udp_set_multicast_netif_addr(sock->conn->pcb.udp, &if_addr);
}
break;
@@ -2417,8 +2430,8 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
ip4_addr_t if_addr;
ip4_addr_t multi_addr;
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct ip_mreq, NETCONN_UDP);
- inet_addr_to_ipaddr(&if_addr, &imr->imr_interface);
- inet_addr_to_ipaddr(&multi_addr, &imr->imr_multiaddr);
+ inet_addr_to_ip4addr(&if_addr, &imr->imr_interface);
+ inet_addr_to_ip4addr(&multi_addr, &imr->imr_multiaddr);
if (optname == IP_ADD_MEMBERSHIP) {
if (!lwip_socket_register_membership(s, &if_addr, &multi_addr)) {
/* cannot track membership (out of memory) */
@@ -2450,6 +2463,9 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
case IPPROTO_TCP:
/* Special case: all IPPROTO_TCP option take an int */
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_TCP);
+ if (sock->conn->pcb.tcp->state == LISTEN) {
+ return EINVAL;
+ }
switch (optname) {
case TCP_NODELAY:
if (*(const int*)optval) {
@@ -2497,7 +2513,6 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
case IPPROTO_IPV6:
switch (optname) {
case IPV6_V6ONLY:
- /* @todo: this does not work for datagram sockets, yet */
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_TCP);
if (*(const int*)optval) {
netconn_set_ipv6only(sock->conn, 1);
@@ -2559,6 +2574,12 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
switch (optname) {
#if LWIP_IPV6 && LWIP_RAW
case IPV6_CHECKSUM:
+ /* It should not be possible to disable the checksum generation with ICMPv6
+ * as per RFC 3542 chapter 3.1 */
+ if(sock->conn->pcb.raw->protocol == IPPROTO_ICMPV6) {
+ return EINVAL;
+ }
+
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_RAW);
if (*(const int *)optval < 0) {
sock->conn->pcb.raw->chksum_reqd = 0;
@@ -2730,14 +2751,16 @@ lwip_fcntl(int s, int cmd, int val)
static int
lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr)
{
- /* s+1 is stored in the array to prevent having to initialize the array
- (default initialization is to 0) */
- int sa = s + 1;
+ struct lwip_sock *sock = get_socket(s);
int i;
+ if (!sock) {
+ return 0;
+ }
+
for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
- if (socket_ipv4_multicast_memberships[i].sa == 0) {
- socket_ipv4_multicast_memberships[i].sa = sa;
+ if (socket_ipv4_multicast_memberships[i].sock == NULL) {
+ socket_ipv4_multicast_memberships[i].sock = sock;
ip4_addr_copy(socket_ipv4_multicast_memberships[i].if_addr, *if_addr);
ip4_addr_copy(socket_ipv4_multicast_memberships[i].multi_addr, *multi_addr);
return 1;
@@ -2754,16 +2777,18 @@ lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr
static void
lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr)
{
- /* s+1 is stored in the array to prevent having to initialize the array
- (default initialization is to 0) */
- int sa = s + 1;
+ struct lwip_sock *sock = get_socket(s);
int i;
+ if (!sock) {
+ return;
+ }
+
for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
- if ((socket_ipv4_multicast_memberships[i].sa == sa) &&
+ if ((socket_ipv4_multicast_memberships[i].sock == sock) &&
ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].if_addr, if_addr) &&
ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].multi_addr, multi_addr)) {
- socket_ipv4_multicast_memberships[i].sa = 0;
+ socket_ipv4_multicast_memberships[i].sock = NULL;
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr);
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr);
return;
@@ -2775,25 +2800,26 @@ lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_ad
*
* ATTENTION: this function is NOT called from tcpip_thread (or under CORE_LOCK).
*/
-static void lwip_socket_drop_registered_memberships(int s)
+static void
+lwip_socket_drop_registered_memberships(int s)
{
- /* s+1 is stored in the array to prevent having to initialize the array
- (default initialization is to 0) */
- int sa = s + 1;
+ struct lwip_sock *sock = get_socket(s);
int i;
- LWIP_ASSERT("socket has no netconn", sockets[s].conn != NULL);
+ if (!sock) {
+ return;
+ }
for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
- if (socket_ipv4_multicast_memberships[i].sa == sa) {
+ if (socket_ipv4_multicast_memberships[i].sock == sock) {
ip_addr_t multi_addr, if_addr;
ip_addr_copy_from_ip4(multi_addr, socket_ipv4_multicast_memberships[i].multi_addr);
ip_addr_copy_from_ip4(if_addr, socket_ipv4_multicast_memberships[i].if_addr);
- socket_ipv4_multicast_memberships[i].sa = 0;
+ socket_ipv4_multicast_memberships[i].sock = NULL;
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr);
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr);
- netconn_join_leave_group(sockets[s].conn, &multi_addr, &if_addr, NETCONN_LEAVE);
+ netconn_join_leave_group(sock->conn, &multi_addr, &if_addr, NETCONN_LEAVE);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/api/tcpip.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/api/tcpip.c b/net/ip/lwip_base/src/api/tcpip.c
index 4dfeabd..07b2f98 100644
--- a/net/ip/lwip_base/src/api/tcpip.c
+++ b/net/ip/lwip_base/src/api/tcpip.c
@@ -260,7 +260,7 @@ tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
/**
* call sys_timeout in tcpip_thread
*
- * @param msec time in milliseconds for timeout
+ * @param msecs time in milliseconds for timeout
* @param h function to be called on timeout
* @param arg argument to pass to timeout function h
* @return ERR_MEM on memory error, ERR_OK otherwise
@@ -288,7 +288,6 @@ tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
/**
* call sys_untimeout in tcpip_thread
*
- * @param msec time in milliseconds for timeout
* @param h function to be called on timeout
* @param arg argument to pass to timeout function h
* @return ERR_MEM on memory error, ERR_OK otherwise
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/apps/httpd/fsdata.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/apps/httpd/fsdata.h b/net/ip/lwip_base/src/apps/httpd/fsdata.h
index 0c54d39..ac4548c 100644
--- a/net/ip/lwip_base/src/apps/httpd/fsdata.h
+++ b/net/ip/lwip_base/src/apps/httpd/fsdata.h
@@ -35,10 +35,6 @@
#include "lwip/apps/httpd_opts.h"
#include "lwip/apps/fs.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
struct fsdata_file {
const struct fsdata_file *next;
const unsigned char *name;
@@ -51,8 +47,4 @@ struct fsdata_file {
#endif /* HTTPD_PRECALCULATED_CHECKSUM */
};
-#ifdef __cplusplus
-}
-#endif
-
#endif /* LWIP_FSDATA_H */