Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/coding_guidelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
sudo apt-get install coccinelle

- name: Run Coding Guidelines Checks
continue-on-error: true
id: coding_guidelines
env:
BASE_REF: ${{ github.base_ref }}
Expand Down
2 changes: 1 addition & 1 deletion Kconfig.infuse
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ config INFUSE_APPLICATION_NAME
Typically set by the `release-build` scripts.

rsource "kconfig/Kconfig.defaults.core"
rsource "kconfig/Kconfig.defaults.net"
rsource "kconfig/Kconfig.defaults.nrf"
rsource "kconfig/Kconfig.defaults.stm32"
rsource "kconfig/Kconfig.defaults.sensor"
Expand All @@ -40,6 +39,7 @@ endif # INFUSE_SDK

rsource "kconfig/Kconfig.defaults.802154"
rsource "kconfig/Kconfig.defaults.bluetooth"
rsource "kconfig/Kconfig.defaults.net"

if ZTEST
rsource "kconfig/Kconfig.defaults.ztest"
Expand Down
41 changes: 41 additions & 0 deletions include/infuse/net/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,47 @@ extern "C" {
int infuse_sync_dns(const char *host, uint16_t port, int family, int socktype,
struct sockaddr *addr, socklen_t *addrlen);

/* One result for the DNS query (multiple results are possible) */
#define INFUSE_ASYNC_DNS_RESULT 0
/* DNS query has completed successfully */
#define INFUSE_ASYNC_DNS_COMPLETE 1

struct infuse_async_dns_context;

/**
* @brief Callback when DNS results are received
*
* @param result @ref INFUSE_ASYNC_DNS_RESULT, @ref INFUSE_ASYNC_DNS_COMPLETE, or negative errno
* @param addr For @ref INFUSE_ASYNC_DNS_RESULT, the address associated with the query
* @param addrlen For @ref INFUSE_ASYNC_DNS_RESULT, the length of the address
* @param cb_ctx @ref infuse_async_dns_context provided to @ref infuse_async_dns
*/
typedef void (*infuse_async_dns_cb)(int result, struct sockaddr *addr, socklen_t addrlen,
struct infuse_async_dns_context *cb_ctx);

/** Async query context for @ref infuse_async_dns */
struct infuse_async_dns_context {
/* Callback to run on events */
infuse_async_dns_cb cb;
/* Arbitarary user context */
void *user_data;
};

/**
* @brief Perform an asynchronous DNS query for a host
*
* @param host Host to lookup
* @param family Protocol family hint
* @param context Context package for callbacks. Must remain valid until either
* @ref INFUSE_ASYNC_DNS_COMPLETE or error callback.
* @param timeout_ms Timeout for query in milliseconds
*
* @retval 0 if query successfully started
* @retval -errno other return value from dns_get_addr_info
*/
int infuse_async_dns(const char *host, int family, struct infuse_async_dns_context *context,
int32_t timeout_ms);

/**
* @}
*/
Expand Down
15 changes: 12 additions & 3 deletions kconfig/Kconfig.defaults.net
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

DT_CHOSEN_Z_WIFI := zephyr,wifi

if NETWORKING
config INFUSE_SDK_NETWORKING
bool "Infuse-IoT SDK Networking defaults"
depends on NETWORKING
default y if INFUSE_SDK

if INFUSE_SDK_NETWORKING

configdefault WIFI
default y if $(dt_chosen_enabled,$(DT_CHOSEN_Z_WIFI))
Expand Down Expand Up @@ -56,7 +61,9 @@ configdefault DNS_RESOLVER
configdefault DNS_SERVER_IP_ADDRESSES
default y
configdefault DNS_SERVER1
default "8.8.8.8"
default "1.1.1.1"
configdefault DNS_SERVER2
default "1.0.0.1"
configdefault DNS_NUM_CONCUR_QUERIES
# Both libraries do DNS queries immediately upon connection
default 2 if SNTP_AUTO && EPACKET_INTERFACE_UDP
Expand Down Expand Up @@ -90,6 +97,8 @@ configdefault NET_SOCKETS_ENABLE_DTLS
default y
configdefault MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
default y
configdefault PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
default y if !BUILD_WITH_TFM
configdefault PSA_WANT_ALG_TLS12_PSK_TO_MS
default y
configdefault PSA_WANT_ALG_TLS12_PRF
Expand All @@ -111,7 +120,7 @@ configdefault CONN_MGR_WIFI_KV_STORE
configdefault NET_IF_MAX_IPV4_COUNT
default 2 if NRF_MODEM_LIB_NET_IF && WIFI

endif # NETWORKING
endif # INFUSE_SDK_NETWORKING

if SHIELD_NRF7002EB || SHIELD_NRF7002EK

Expand Down
5 changes: 5 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ config INFUSE_EPOCH_TIME_PRINT_ON_SYNC
depends on INFUSE_EPOCH_TIME
default y

config INFUSE_EPOCH_TIME_PRINT_REF_ON_SYNC
bool "Print the current reference local time on sync"
depends on ARCH_POSIX
default y

config INFUSE_CUSTOM_IDENTIFIERS
bool "Rely on some other source to supply an implementation of infuse_device_id"
help
Expand Down
15 changes: 15 additions & 0 deletions lib/time/epoch.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include <infuse/time/epoch.h>
#include <infuse/states.h>

#ifdef CONFIG_INFUSE_EPOCH_TIME_PRINT_REF_ON_SYNC
#include <time.h>
#include <sys/time.h>
#endif /* CONFIG_INFUSE_EPOCH_TIME_PRINT_REF_ON_SYNC */

#define JAN_01_01_2020 (1261872018ULL * INFUSE_EPOCH_TIME_TICKS_PER_SEC)

static const struct timeutil_sync_config infuse_civil_config = {
Expand Down Expand Up @@ -139,6 +144,16 @@ int epoch_time_set_reference(enum epoch_time_source source, struct timeutil_sync
LOG_INF("Now: %d-%02d-%02dT%02d:%02d:%02d.%03d UTC", 1900 + c.tm_year, 1 + c.tm_mon,
c.tm_mday, c.tm_hour, c.tm_min, c.tm_sec, epoch_time_milliseconds(now));
#endif /* CONFIG_INFUSE_EPOCH_TIME_PRINT_ON_SYNC */
#ifdef CONFIG_INFUSE_EPOCH_TIME_PRINT_REF_ON_SYNC
struct timeval tv_now;
struct tm *t;

(void)gettimeofday(&tv_now, NULL);
t = gmtime(&tv_now.tv_sec);
LOG_INF("Ref: %d-%02d-%02dT%02d:%02d:%02d.%03d UTC", 1900 + t->tm_year, 1 + t->tm_mon,
t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv_now.tv_usec / USEC_PER_MSEC);
#endif /* INFUSE_EPOCH_TIME_PRINT_REF_ON_SYNC */

return rc;
}

Expand Down
7 changes: 4 additions & 3 deletions scripts/west_commands/release-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import pykwalify.core
import yaml

from typing_extensions import Tuple

from west.commands import WestCommand
from west.manifest import Project, ManifestProject

Expand Down Expand Up @@ -216,7 +214,7 @@ def validate_manifest_repos_state(self) -> None:
else:
sys.exit(msg)

def expected_version(self, repo: Repo) -> Tuple[str, str]:
def expected_version(self, repo: Repo) -> tuple[str, str]:
version_file = self.application / "VERSION"
if not version_file.exists():
sys.exit(f"{version_file} does not exist")
Expand Down Expand Up @@ -351,6 +349,9 @@ def validate_build(self, expected_version: str) -> dict:
if "CONFIG_EPACKET_INTERFACE_UDP_DOWNLINK_WATCHDOG" not in configs:
warnings.append("UDP interface enabled without downlink watchdog")

if "CONFIG_DNS_RESOLVER_CACHE" in configs:
warnings.append("Application cannot handle changing IP addresses")

if self.tfm_build:
key_file_0 = configs["CONFIG_TFM_KEY_FILE_S"]
key_file_1 = configs["CONFIG_TFM_KEY_FILE_NS"]
Expand Down
6 changes: 6 additions & 0 deletions subsys/net/dns/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ config INFUSE_DNS
queries at once, returning errors otherwise. This library
mediates access to the shared resource, blocking until a
query slot is available before running.

config INFUSE_DNS_ASYNC
bool "Asynchronous variant of INFUSE_DNS"
depends on INFUSE_DNS
depends on DNS_RESOLVER
default y
104 changes: 90 additions & 14 deletions subsys/net/dns/infuse_dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ LOG_MODULE_REGISTER(infuse_dns, LOG_LEVEL_INF);
K_SEM_DEFINE(dns_ctx, CONFIG_DNS_NUM_CONCUR_QUERIES, CONFIG_DNS_NUM_CONCUR_QUERIES);
#endif /* CONFIG_DNS_RESOLVER */

static void dns_result_display(struct sockaddr *addr, const char *host, uint16_t port)
{
#ifdef CONFIG_NET_IPV4
if (addr->sa_family == AF_INET) {
struct sockaddr_in *ipv4 = (struct sockaddr_in *)addr;
uint8_t *b = ipv4->sin_addr.s4_addr;

ipv4->sin_port = htons(port);
LOG_INF("%s -> %d.%d.%d.%d:%d", host, b[0], b[1], b[2], b[3], port);
}
#endif /* CONFIG_NET_IPV4 */
#ifdef CONFIG_NET_IPV6
if (addr->sa_family == AF_INET6) {
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)addr;

ipv6->sin6_port = htons(port);
LOG_INF("%s -> IPv6:%d", host, port);
}
#endif /* CONFIG_NET_IPV6 */
}

int infuse_sync_dns(const char *host, uint16_t port, int family, int socktype,
struct sockaddr *addr, socklen_t *addrlen)
{
Expand Down Expand Up @@ -59,22 +80,77 @@ int infuse_sync_dns(const char *host, uint16_t port, int family, int socktype,
k_sem_give(&dns_ctx);
#endif /* CONFIG_DNS_RESOLVER */

#ifdef CONFIG_NET_IPV4
if (addr->sa_family == AF_INET) {
struct sockaddr_in *ipv4 = (struct sockaddr_in *)addr;
uint8_t *b = ipv4->sin_addr.s4_addr;
/* Display DNS result */
dns_result_display(addr, host, port);
return 0;
}

ipv4->sin_port = htons(port);
LOG_INF("%s -> %d.%d.%d.%d:%d", host, b[0], b[1], b[2], b[3], port);
#ifdef CONFIG_INFUSE_DNS_ASYNC

static void dns_result_cb(enum dns_resolve_status status, struct dns_addrinfo *info,
void *user_data)
{
struct infuse_async_dns_context *context = user_data;
int rc;

switch (status) {
case DNS_EAI_NODATA:
LOG_WRN("%s -> Lookup failed (%d, %d)", "???", DNS_EAI_NODATA, DNS_EAI_NODATA);
rc = -EINVAL;
goto done;
case DNS_EAI_ALLDONE:
LOG_DBG("DNS resolving finished");
rc = INFUSE_ASYNC_DNS_COMPLETE;
goto done;
case DNS_EAI_INPROGRESS:
LOG_DBG("DNS resolving in progress");
rc = INFUSE_ASYNC_DNS_RESULT;
break;
default:
LOG_DBG("DNS resolving error (%d)", status);
rc = -EIO;
goto done;
}
#endif /* CONFIG_NET_IPV4 */
#ifdef CONFIG_NET_IPV6
if (addr->sa_family == AF_INET6) {
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)addr;

ipv6->sin6_port = htons(port);
LOG_INF("%s -> IPv6:%d", host, port);
if (!info) {
return;
}
#endif /* CONFIG_NET_IPV6 */
return 0;

/* Display DNS result (Host and port not cached for async) */
dns_result_display(&info->ai_addr, "???", 0);

context->cb(INFUSE_ASYNC_DNS_RESULT, &info->ai_addr, info->ai_addrlen, context);
return;
done:
context->cb(rc, NULL, 0, context);
/* Querying complete, release the context */
k_sem_give(&dns_ctx);
}

int infuse_async_dns(const char *host, int family, struct infuse_async_dns_context *context,
int32_t timeout)
{
enum dns_query_type query_type;
int rc;

if (family == AF_INET) {
query_type = DNS_QUERY_TYPE_A;
} else if (family == AF_INET6) {
query_type = DNS_QUERY_TYPE_AAAA;
} else {
return -EINVAL;
}

/* Take a context */
(void)k_sem_take(&dns_ctx, K_FOREVER);

/* Start the DNS query process */
rc = dns_get_addr_info(host, query_type, NULL, dns_result_cb, context, timeout);
if (rc < 0) {
/* Release the context on error */
k_sem_give(&dns_ctx);
}
return rc;
}

#endif /* CONFIG_INFUSE_DNS_ASYNC */
Loading
Loading