Skip to content
Permalink
Browse files

lib: updatehub: add support ipv6

This extends the UpdateHub library code to allow the
use of IPV6 for communication.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
  • Loading branch information...
chtavares592 authored and carlescufi committed Mar 20, 2019
1 parent c5d74ec commit 543de0935736ba5229d58dc570819285f2b39ca1
Showing with 23 additions and 8 deletions.
  1. +0 −1 lib/updatehub/Kconfig
  2. +17 −7 lib/updatehub/updatehub.c
  3. +2 −0 samples/net/updatehub/README.rst
  4. +4 −0 samples/net/updatehub/prj.conf
@@ -17,7 +17,6 @@ menuconfig UPDATEHUB
select NET_SOCKETS
select NET_SOCKETS_POSIX_NAMES
select COAP
select NET_CONFIG_NEED_IPV4
select NET_CONFIG_SETTINGS
select DNS_RESOLVER
select JSON_LIBRARY
@@ -127,10 +127,18 @@ is_compatible_hardware(struct resp_probe_some_boards *metadata_some_boards)

static bool start_coap_client(void)
{
static struct addrinfo hints = { .ai_family = AF_INET,
.ai_socktype = SOCK_STREAM };
struct addrinfo *addr;
struct addrinfo hints;
int resolve_attempts = 10;
int ret = -1;

if (IS_ENABLED(CONFIG_NET_IPV6)) {
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_STREAM;
} else if (IS_ENABLED(CONFIG_NET_IPV4)) {
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
}

#if defined(CONFIG_UPDATEHUB_DTLS)
int verify = 0;
@@ -143,13 +151,15 @@ static bool start_coap_client(void)
#endif

while (resolve_attempts--) {
if (getaddrinfo(UPDATEHUB_SERVER, port, &hints, &addr) == 0) {
ret = getaddrinfo(UPDATEHUB_SERVER, port, &hints, &addr);
if (ret == 0) {
break;
}
if (resolve_attempts-- == 0) {
LOG_ERR("Could not resolve dns");
return false;
}
k_sleep(K_SECONDS(1));
}
if (ret < 0) {
LOG_ERR("Could not resolve dns");
return false;
}

ctx.sock = socket(addr->ai_family, SOCK_DGRAM, protocol);
@@ -101,6 +101,8 @@ Using this server the user need create own ``overaly-prj.conf`` setting the opti
UpdateHub need too set the option :option:`CONFIG_UPDATEHUB_POLL_INTERVAL` with the period of
your preference, remembering that the limit is between 0 minute until 43200 minutes(30 days).
This server does not use DTLS, so you must not add ``overlay-dtls.config``.
This sample uses IPv4 by default, but if you would like use IPv6 is possible too, need just
enable IPv6 and configure your IP address.

Step 4: Build UpdateHub
=======================
@@ -5,6 +5,10 @@ CONFIG_UPDATEHUB=y
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_NET_IPV4=y
CONFIG_NET_CONFIG_NEED_IPV4=y

CONFIG_NET_IPV6=n
CONFIG_NET_DHCPV4=y

#Optional if you would like test on the your server

0 comments on commit 543de09

Please sign in to comment.
You can’t perform that action at this time.