diff --git a/src/apps/altcp_tls/altcp_tls_mbedtls.c b/src/apps/altcp_tls/altcp_tls_mbedtls.c index 35b18155..bf3883a8 100644 --- a/src/apps/altcp_tls/altcp_tls_mbedtls.c +++ b/src/apps/altcp_tls/altcp_tls_mbedtls.c @@ -1256,6 +1256,10 @@ const struct altcp_functions altcp_mbedtls_functions = { altcp_default_get_tcp_addrinfo, altcp_default_get_ip, altcp_default_get_port +#if LWIP_TCP_KEEPALIVE + , altcp_default_keepalive_disable + , altcp_default_keepalive_enable +#endif #ifdef LWIP_DEBUG , altcp_default_dbg_get_tcp_state #endif diff --git a/src/core/altcp.c b/src/core/altcp.c index 1156307a..028fcbc8 100644 --- a/src/core/altcp.c +++ b/src/core/altcp.c @@ -501,6 +501,24 @@ altcp_get_port(struct altcp_pcb *conn, int local) return 0; } +#if LWIP_TCP_KEEPALIVE +void +altcp_keepalive_disable(struct altcp_pcb *conn) +{ + if (conn && conn->fns && conn->fns->keepalive_disable) { + conn->fns->keepalive_disable(conn); + } +} + +void +altcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count) +{ + if (conn && conn->fns && conn->fns->keepalive_enable) { + conn->fns->keepalive_enable(conn, idle, intvl, count); + } +} +#endif + #ifdef LWIP_DEBUG enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn) @@ -666,6 +684,24 @@ altcp_default_get_port(struct altcp_pcb *conn, int local) return 0; } +#if LWIP_TCP_KEEPALIVE +void +altcp_default_keepalive_disable(struct altcp_pcb *conn) +{ + if (conn && conn->inner_conn) { + altcp_keepalive_disable(conn->inner_conn); + } +} + +void +altcp_default_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count) +{ + if (conn && conn->inner_conn) { + altcp_keepalive_enable(conn->inner_conn, idle, intvl, count); + } +} +#endif + #ifdef LWIP_DEBUG enum tcp_state altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn) diff --git a/src/core/altcp_tcp.c b/src/core/altcp_tcp.c index b715f045..867d2b44 100644 --- a/src/core/altcp_tcp.c +++ b/src/core/altcp_tcp.c @@ -49,6 +49,7 @@ #include "lwip/altcp_tcp.h" #include "lwip/priv/altcp_priv.h" #include "lwip/tcp.h" +#include "lwip/priv/tcp_priv.h" #include "lwip/mem.h" #include @@ -446,6 +447,31 @@ altcp_tcp_setprio(struct altcp_pcb *conn, u8_t prio) } } +#if LWIP_TCP_KEEPALIVE +static void +altcp_tcp_keepalive_disable(struct altcp_pcb *conn) +{ + if (conn && conn->state) { + struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state; + ALTCP_TCP_ASSERT_CONN(conn); + ip_reset_option(pcb, SOF_KEEPALIVE); + } +} + +static void +altcp_tcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t cnt) +{ + if (conn && conn->state) { + struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state; + ALTCP_TCP_ASSERT_CONN(conn); + ip_set_option(pcb, SOF_KEEPALIVE); + pcb->keep_idle = idle ? idle : TCP_KEEPIDLE_DEFAULT; + pcb->keep_intvl = intvl ? intvl : TCP_KEEPINTVL_DEFAULT; + pcb->keep_cnt = cnt ? cnt : TCP_KEEPCNT_DEFAULT; + } +} +#endif + static void altcp_tcp_dealloc(struct altcp_pcb *conn) { @@ -535,6 +561,10 @@ const struct altcp_functions altcp_tcp_functions = { altcp_tcp_get_tcp_addrinfo, altcp_tcp_get_ip, altcp_tcp_get_port +#if LWIP_TCP_KEEPALIVE + , altcp_tcp_keepalive_disable + , altcp_tcp_keepalive_enable +#endif #ifdef LWIP_DEBUG , altcp_tcp_dbg_get_tcp_state #endif diff --git a/src/include/lwip/altcp.h b/src/include/lwip/altcp.h index 97abc54d..1b245449 100644 --- a/src/include/lwip/altcp.h +++ b/src/include/lwip/altcp.h @@ -129,6 +129,11 @@ err_t altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local); u16_t altcp_get_port(struct altcp_pcb *conn, int local); +#if LWIP_TCP_KEEPALIVE +void altcp_keepalive_disable(struct altcp_pcb *conn); +void altcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count); +#endif + #ifdef LWIP_DEBUG enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn); #endif diff --git a/src/include/lwip/priv/altcp_priv.h b/src/include/lwip/priv/altcp_priv.h index 2d3b2fdb..d1de9b11 100644 --- a/src/include/lwip/priv/altcp_priv.h +++ b/src/include/lwip/priv/altcp_priv.h @@ -85,6 +85,11 @@ typedef err_t (*altcp_get_tcp_addrinfo_fn)(struct altcp_pcb *conn, int local, ip typedef ip_addr_t *(*altcp_get_ip_fn)(struct altcp_pcb *conn, int local); typedef u16_t (*altcp_get_port_fn)(struct altcp_pcb *conn, int local); +#if LWIP_TCP_KEEPALIVE +typedef void (*altcp_keepalive_disable_fn)(struct altcp_pcb *conn); +typedef void (*altcp_keepalive_enable_fn)(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count); +#endif + #ifdef LWIP_DEBUG typedef enum tcp_state (*altcp_dbg_get_tcp_state_fn)(struct altcp_pcb *conn); #endif @@ -111,6 +116,10 @@ struct altcp_functions { altcp_get_tcp_addrinfo_fn addrinfo; altcp_get_ip_fn getip; altcp_get_port_fn getport; +#if LWIP_TCP_KEEPALIVE + altcp_keepalive_disable_fn keepalive_disable; + altcp_keepalive_enable_fn keepalive_enable; +#endif #ifdef LWIP_DEBUG altcp_dbg_get_tcp_state_fn dbg_get_tcp_state; #endif @@ -133,6 +142,10 @@ void altcp_default_dealloc(struct altcp_pcb *conn); err_t altcp_default_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port); ip_addr_t *altcp_default_get_ip(struct altcp_pcb *conn, int local); u16_t altcp_default_get_port(struct altcp_pcb *conn, int local); +#if LWIP_TCP_KEEPALIVE +void altcp_default_keepalive_disable(struct altcp_pcb *conn); +void altcp_default_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count); +#endif #ifdef LWIP_DEBUG enum tcp_state altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn); #endif