Skip to content

Commit

Permalink
add ipv6 gateway support,change the dtls shakehand timeout by interva…
Browse files Browse the repository at this point in the history
…l time for too long waiting when reconnecting and fixed a bug when connection changed.
  • Loading branch information
jimscen committed Jan 14, 2019
1 parent 2402fcc commit 9f9162b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 10 deletions.
29 changes: 26 additions & 3 deletions components/connectivity/agent_tiny/atiny_lwm2m/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ int connection_connect_dtls(connection_t *connP, security_instance_t *targetP, c
{
info.u.c.host = host;
info.u.c.port = port;
info.timeout = DTLS_UDP_CLIENT_SHAKEHAND_TIMEOUT;
}
else
{
#ifdef LWM2M_BOOTSTRAP
info.u.s.timeout = targetP->clientHoldOffTime;
info.timeout = targetP->clientHoldOffTime;
info.u.s.local_port = port;
timer_init(&connP->server_triger_timer, LWM2M_TRIGER_SERVER_MODE_INITIATED_TIME, (void(*)(void*))connection_striger_server_initiated_bs, connP);
timer_start(&connP->server_triger_timer);
Expand Down Expand Up @@ -456,15 +457,37 @@ int lwm2m_buffer_recv(void *sessionH, uint8_t *buffer, size_t length, uint32_t t
return ret;
}

static bool connection_is_valid(void *user_data, void *session)
{
client_data_t *data = (client_data_t *)user_data;
connection_t *conn;
if (data == NULL || data->connList == NULL)
{
return false;
}

conn = data->connList;
while(conn != NULL)
{
if (conn == session)
{
return true;
}
conn = conn->next;
}

return false;
}

uint8_t lwm2m_buffer_send(void *sessionH,
uint8_t *buffer,
size_t length,
void *userdata)
{
connection_t *connP = (connection_t *) sessionH;
int ret;

if (connP == NULL)
/* should check the valid of the connection,because coap tranctions does not update the session */
if (connP == NULL || (!connection_is_valid(userdata, sessionH)))
{
ATINY_LOG(LOG_INFO, "#> failed sending %lu bytes, missing connection\r\n", (unsigned long)length);
return COAP_500_INTERNAL_SERVER_ERROR ;
Expand Down
5 changes: 5 additions & 0 deletions components/connectivity/agent_tiny/atiny_lwm2m/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
#define LWM2M_IS_CLIENT 0
#define LWM2M_IS_SERVER 1

/* timeout for udp client shakehand,the unit is second */
#ifndef DTLS_UDP_CLIENT_SHAKEHAND_TIMEOUT
#define DTLS_UDP_CLIENT_SHAKEHAND_TIMEOUT 60
#endif

typedef enum
{
CONNECTION_SEND_ERR,
Expand Down
1 change: 1 addition & 0 deletions components/net/lwip/lwip-2.0.3/src/core/ipv6/nd6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,7 @@ nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif)
{
#ifdef LWIP_HOOK_ND6_GET_GW
const ip6_addr_t *next_hop_addr;
ip6_addr_t *LWIP_HOOK_ND6_GET_GW(const struct netif *netif, const ip6_addr_t *ip6addr);
#endif /* LWIP_HOOK_ND6_GET_GW */
s8_t i;

Expand Down
20 changes: 20 additions & 0 deletions components/net/lwip/lwip_port/OS/ethernetif.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,23 @@ static void arp_timer(void *arg)
}
#endif

#if LWIP_IPV6
static ip6_addr_t g_lwip_ipv6_gw;
ip6_addr_t *get_lwip_ipv6_default_gw(const struct netif *netif, const ip6_addr_t *ip6addr)
{
(void)ip6addr;
(void)netif;
return &g_lwip_ipv6_gw;
}

void set_lwip_ipv6_default_gw(struct netif *netif, const ip6_addr_t *gw)
{
(void)netif;
if (gw == NULL)
{
return;
}
memcpy( &g_lwip_ipv6_gw, gw, sizeof(g_lwip_ipv6_gw));
}
#endif

5 changes: 5 additions & 0 deletions components/net/lwip/lwip_port/OS/ethernetif.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ int8_t ethernetif_api_register(struct ethernet_api *api);
err_t ethernetif_init(struct netif *netif);
void ethernetif_input( void * pvParameters );

#if LWIP_IPV6
ip6_addr_t *get_lwip_ipv6_default_gw(const struct netif *netif, const ip6_addr_t *ip6addr);
void set_lwip_ipv6_default_gw(struct netif *netif, const ip6_addr_t *gw);
#endif

#endif /* __ETHERNETIF_H__ */


4 changes: 3 additions & 1 deletion components/net/lwip/lwip_port/OS/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
*/
//#define LWIP_DEBUG 1

#define TCPIP_THREAD_STACKSIZE 1000
#define TCPIP_THREAD_STACKSIZE 0x1000
#define TCPIP_MBOX_SIZE 12
#define DEFAULT_UDP_RECVMBOX_SIZE 12
#define DEFAULT_TCP_RECVMBOX_SIZE 6
Expand All @@ -255,6 +255,8 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
//for dtls server
#define SO_REUSE 1

#define LWIP_HOOK_ND6_GET_GW get_lwip_ipv6_default_gw

#endif /* __LWIPOPTS_H__ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
6 changes: 3 additions & 3 deletions components/security/mbedtls/mbedtls_port/dtls_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ int dtls_shakehand(mbedtls_ssl_context *ssl, const dtls_shakehand_info_s *info)

MBEDTLS_LOG("performing the SSL/TLS handshake");

max_value = ((MBEDTLS_SSL_IS_SERVER == info->client_or_server) ?
(dtls_gettime() + info->u.s.timeout) : (info->udp_or_tcp == MBEDTLS_NET_PROTO_TCP ? 50 : 10));
max_value = ((MBEDTLS_SSL_IS_SERVER == info->client_or_server || info->udp_or_tcp == MBEDTLS_NET_PROTO_UDP) ?
(dtls_gettime() + info->timeout) : 50);

do
{
ret = mbedtls_ssl_handshake(ssl);
//MBEDTLS_LOG("mbedtls_ssl_handshake %d %d", change_value, max_value);
//LOS_TaskDelay(1);
if (MBEDTLS_SSL_IS_CLIENT == info->client_or_server)
if (MBEDTLS_SSL_IS_CLIENT == info->client_or_server && info->udp_or_tcp == MBEDTLS_NET_PROTO_TCP)
{
change_value++;
}
Expand Down
2 changes: 1 addition & 1 deletion components/security/mbedtls/mbedtls_port/dtls_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ typedef struct
}c;
struct
{
uint32_t timeout;
const char *local_port;
}s;
}u;
uint32_t timeout;
int client_or_server;
int udp_or_tcp;
verify_type_e psk_or_cert;
Expand Down
13 changes: 11 additions & 2 deletions targets/Cloud_STM32F429IGTx_FIRE/Src/sys_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,26 @@ void net_init(void)
ip6_addr_t ip6;
err_t ret;
s8_t idx;

ip6_addr_t ipv6_gw;

if (inet_pton(AF_INET6, "2000::2", &ip6) <= 0)
{
printf("set source ip6 failed \n");
return;
}
printf("after set source ip6\n");
ret = netif_add_ip6_address(&gnetif, &ip6, &idx);
if (ret != 0)
{
printf("netif_add_ip6_address failed,ret %d\n", ret);
return;
}

if (inet_pton(AF_INET6, "2000::1", &ipv6_gw) <= 0)
{
printf("inet_pton failed\n");
return;
}
set_lwip_ipv6_default_gw(&gnetif, &ipv6_gw);
}
#else
(void)netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);//lint !e546
Expand Down

0 comments on commit 9f9162b

Please sign in to comment.