diff --git a/examples/wolfmqtt_aws/Makefile b/examples/wolfmqtt_aws/Makefile new file mode 100644 index 000000000000..be7f9c5c8d4d --- /dev/null +++ b/examples/wolfmqtt_aws/Makefile @@ -0,0 +1,67 @@ +# name of your application +APPLICATION = wolfmqtt_aws + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +WIFI_SSID ?= "WIFI_SSID" +WIFI_PASS ?= "WIFI_PASS" + +USEPKG += wolfmqtt + +USEPKG += wolfssl +USEMODULE += wolfssl_socket +USEMODULE += wolfcrypt wolfcrypt_rsa wolfcrypt_dh + +# This firmware is implemented inside the package examples +USEMODULE += wolfmqtt_examples_aws + +# rsa needs a larger stack +CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(5*THREAD_STACKSIZE_DEFAULT\) + +CFLAGS += -DWOLFMQTT_DEBUG_SOCKET + +LWIP_IPV4 ?= 0 + +USEMODULE += lwip +USEMODULE += lwip_netdev +USEMODULE += lwip_netdb + +ifneq (0,$(LWIP_IPV4)) + USEMODULE += ipv4_addr + USEMODULE += lwip_arp + USEMODULE += lwip_ipv4 + USEMODULE += lwip_dhcp_auto + CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 + LWIP_IPV6 ?= 0 +else + LWIP_IPV6 ?= 1 +endif + +ifneq (0,$(LWIP_IPV6)) + USEMODULE += ipv6_addr + USEMODULE += lwip_ipv6 + USEMODULE += lwip_ipv6_autoconfig +endif + +USEMODULE += sock_udp +USEMODULE += sock_tcp + +include $(RIOTBASE)/Makefile.include + +# needs to be put after "include $(RIOTBASE)/Makefile.include" +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + CFLAGS += -DESP_WIFI_SSID=\"$(WIFI_SSID)\" + CFLAGS += -DESP_WIFI_PASS=\"$(WIFI_PASS)\" +endif diff --git a/examples/wolfmqtt_aws/Makefile.board.dep b/examples/wolfmqtt_aws/Makefile.board.dep new file mode 100644 index 000000000000..4000952c2801 --- /dev/null +++ b/examples/wolfmqtt_aws/Makefile.board.dep @@ -0,0 +1,9 @@ +# Put board specific dependencies here + +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + USEMODULE += esp_wifi +endif + +ifeq ($(BOARD),native) + USEMODULE += netdev_default +endif diff --git a/examples/wolfmqtt_aws/user_settings.h b/examples/wolfmqtt_aws/user_settings.h new file mode 100644 index 000000000000..fc4d3d805317 --- /dev/null +++ b/examples/wolfmqtt_aws/user_settings.h @@ -0,0 +1,54 @@ +/* user_settings.h : custom configuration for wolfmqtt */ + +#ifndef WOLFMQTT_USER_SETTINGS_H +#define WOLFMQTT_USER_SETTINGS_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/* MANDATORY */ +#undef RIOT_OS +#define RIOT_OS + +#undef ENABLE_AWSIOT_EXAMPLE +#define ENABLE_AWSIOT_EXAMPLE + +#define WOLFMQTT_USE_HOSTNAME 1 + +#if WOLFMQTT_USE_HOSTNAME + #undef AWSIOT_HOST + #define AWSIOT_HOST "a2dujmi05ideo2.iot.us-west-2.amazonaws.com" + + #if defined(MODULE_IPV6_ADDR) + #undef WOLFMQTT_DNS_SERVER_IPV6 + #define WOLFMQTT_DNS_SERVER_IPV6 "2001:4860:4860::8888" + #else + #undef WOLFMQTT_DNS_SERVER_IPV4 + #define WOLFMQTT_DNS_SERVER_IPV4 "8.8.8.8" + #endif +#else + #if defined(MODULE_IPV6_ADDR) + #undef AWSIOT_HOST + #define AWSIOT_HOST "2620:108:700f::2351:30f8" + #else + #undef AWSIOT_HOST + #define AWSIOT_HOST "34.209.16.27" + #endif +#endif + +#undef ENABLE_MQTT_TLS +#define ENABLE_MQTT_TLS + +/* OPTIONAL */ +#undef TEST_MESSAGE +#define TEST_MESSAGE "wolfmqtt aws on RIOT OS" + +#ifdef __cplusplus +} +#endif + + +#endif /* WOLFMQTT_USER_SETTINGS_H */ + diff --git a/examples/wolfmqtt_azure/Makefile b/examples/wolfmqtt_azure/Makefile new file mode 100644 index 000000000000..82ee5b4750f3 --- /dev/null +++ b/examples/wolfmqtt_azure/Makefile @@ -0,0 +1,58 @@ +# name of your application +APPLICATION = wolfmqtt_mqttclient + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +WIFI_SSID ?= "WIFI_SSID" +WIFI_PASS ?= "WIFI_PASS" + +USEPKG += wolfmqtt + +# This firmware is implemented inside the package examples +USEMODULE += wolfmqtt_examples_azure + +LWIP_IPV4 ?= 0 + +USEMODULE += lwip +USEMODULE += lwip_netdev +USEMODULE += lwip_netdb + +ifneq (0,$(LWIP_IPV4)) + USEMODULE += ipv4_addr + USEMODULE += lwip_arp + USEMODULE += lwip_ipv4 + USEMODULE += lwip_dhcp_auto + CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 + LWIP_IPV6 ?= 0 +else + LWIP_IPV6 ?= 1 +endif + +ifneq (0,$(LWIP_IPV6)) + USEMODULE += ipv6_addr + USEMODULE += lwip_ipv6 + USEMODULE += lwip_ipv6_autoconfig +endif + +USEMODULE += sock_udp +USEMODULE += sock_tcp + +include $(RIOTBASE)/Makefile.include + +# needs to be put after "include $(RIOTBASE)/Makefile.include" +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + CFLAGS += -DESP_WIFI_SSID=\"$(WIFI_SSID)\" + CFLAGS += -DESP_WIFI_PASS=\"$(WIFI_PASS)\" +endif diff --git a/examples/wolfmqtt_azure/Makefile.board.dep b/examples/wolfmqtt_azure/Makefile.board.dep new file mode 100644 index 000000000000..4000952c2801 --- /dev/null +++ b/examples/wolfmqtt_azure/Makefile.board.dep @@ -0,0 +1,9 @@ +# Put board specific dependencies here + +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + USEMODULE += esp_wifi +endif + +ifeq ($(BOARD),native) + USEMODULE += netdev_default +endif diff --git a/examples/wolfmqtt_azure/user_settings.h b/examples/wolfmqtt_azure/user_settings.h new file mode 100644 index 000000000000..ffa5b32aa13b --- /dev/null +++ b/examples/wolfmqtt_azure/user_settings.h @@ -0,0 +1,51 @@ +/* user_settings.h : custom configuration for wolfmqtt */ + +#ifndef WOLFMQTT_USER_SETTINGS_H +#define WOLFMQTT_USER_SETTINGS_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/* MANDATORY */ +#undef RIOT_OS +#define RIOT_OS + +#define WOLFMQTT_USE_HOSTNAME 1 + +#if WOLFMQTT_USE_HOSTNAME + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "test.mosquitto.org" + + #if defined(MODULE_IPV6_ADDR) + #undef WOLFMQTT_DNS_SERVER_IPV6 + #define WOLFMQTT_DNS_SERVER_IPV6 "2001:4860:4860::8888" + #else + #undef WOLFMQTT_DNS_SERVER_IPV4 + #define WOLFMQTT_DNS_SERVER_IPV4 "8.8.8.8" + #endif +#else + #if defined(MODULE_IPV6_ADDR) + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "2001:41d0:a:fed0::1" + #else + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "5.196.95.208" + #endif +#endif + +/* OPTIONAL */ +#undef TEST_MESSAGE +#define TEST_MESSAGE "wolfmqtt azure on RIOT OS" + +#undef WOLFMQTT_DISCONNECT_CB +#define WOLFMQTT_DISCONNECT_CB + +#ifdef __cplusplus +} +#endif + + +#endif /* WOLFMQTT_USER_SETTINGS_H */ + diff --git a/examples/wolfmqtt_mqttclient/Makefile b/examples/wolfmqtt_mqttclient/Makefile new file mode 100644 index 000000000000..078f21ce6658 --- /dev/null +++ b/examples/wolfmqtt_mqttclient/Makefile @@ -0,0 +1,58 @@ +# name of your application +APPLICATION = wolfmqtt_mqttclient + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +WIFI_SSID ?= "WIFI_SSID" +WIFI_PASS ?= "WIFI_PASS" + +USEPKG += wolfmqtt + +# This firmware is implemented inside the package examples +USEMODULE += wolfmqtt_examples_mqttclient + +LWIP_IPV4 ?= 0 + +USEMODULE += lwip +USEMODULE += lwip_netdev +USEMODULE += lwip_netdb + +ifneq (0,$(LWIP_IPV4)) + USEMODULE += ipv4_addr + USEMODULE += lwip_arp + USEMODULE += lwip_ipv4 + USEMODULE += lwip_dhcp_auto + CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 + LWIP_IPV6 ?= 0 +else + LWIP_IPV6 ?= 1 +endif + +ifneq (0,$(LWIP_IPV6)) + USEMODULE += ipv6_addr + USEMODULE += lwip_ipv6 + USEMODULE += lwip_ipv6_autoconfig +endif + +USEMODULE += sock_udp +USEMODULE += sock_tcp + +include $(RIOTBASE)/Makefile.include + +# needs to be put after "include $(RIOTBASE)/Makefile.include" +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + CFLAGS += -DESP_WIFI_SSID=\"$(WIFI_SSID)\" + CFLAGS += -DESP_WIFI_PASS=\"$(WIFI_PASS)\" +endif diff --git a/examples/wolfmqtt_mqttclient/Makefile.board.dep b/examples/wolfmqtt_mqttclient/Makefile.board.dep new file mode 100644 index 000000000000..4000952c2801 --- /dev/null +++ b/examples/wolfmqtt_mqttclient/Makefile.board.dep @@ -0,0 +1,9 @@ +# Put board specific dependencies here + +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + USEMODULE += esp_wifi +endif + +ifeq ($(BOARD),native) + USEMODULE += netdev_default +endif diff --git a/examples/wolfmqtt_mqttclient/user_settings.h b/examples/wolfmqtt_mqttclient/user_settings.h new file mode 100644 index 000000000000..28b0aabbec16 --- /dev/null +++ b/examples/wolfmqtt_mqttclient/user_settings.h @@ -0,0 +1,51 @@ +/* user_settings.h : custom configuration for wolfmqtt */ + +#ifndef WOLFMQTT_USER_SETTINGS_H +#define WOLFMQTT_USER_SETTINGS_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/* MANDATORY */ +#undef RIOT_OS +#define RIOT_OS + +#define WOLFMQTT_USE_HOSTNAME 1 + +#if WOLFMQTT_USE_HOSTNAME + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "test.mosquitto.org" + + #if defined(MODULE_IPV6_ADDR) + #undef WOLFMQTT_DNS_SERVER_IPV6 + #define WOLFMQTT_DNS_SERVER_IPV6 "2001:4860:4860::8888" + #else + #undef WOLFMQTT_DNS_SERVER_IPV4 + #define WOLFMQTT_DNS_SERVER_IPV4 "8.8.8.8" + #endif +#else + #if defined(MODULE_IPV6_ADDR) + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "2001:41d0:a:fed0::1" + #else + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "5.196.95.208" + #endif +#endif + +/* OPTIONAL */ +#undef TEST_MESSAGE +#define TEST_MESSAGE "wolfmqtt mqttclient on RIOT OS" + +#undef WOLFMQTT_DISCONNECT_CB +#define WOLFMQTT_DISCONNECT_CB + +#ifdef __cplusplus +} +#endif + + +#endif /* WOLFMQTT_USER_SETTINGS_H */ + diff --git a/examples/wolfmqtt_multithread/Makefile b/examples/wolfmqtt_multithread/Makefile new file mode 100644 index 000000000000..817d655389ae --- /dev/null +++ b/examples/wolfmqtt_multithread/Makefile @@ -0,0 +1,58 @@ +# name of your application +APPLICATION = wolfmqtt_mqttclient + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +WIFI_SSID ?= "WIFI_SSID" +WIFI_PASS ?= "WIFI_PASS" + +USEPKG += wolfmqtt + +# This firmware is implemented inside the package examples +USEMODULE += wolfmqtt_examples_multithread + +LWIP_IPV4 ?= 0 + +USEMODULE += lwip +USEMODULE += lwip_netdev +USEMODULE += lwip_netdb + +ifneq (0,$(LWIP_IPV4)) + USEMODULE += ipv4_addr + USEMODULE += lwip_arp + USEMODULE += lwip_ipv4 + USEMODULE += lwip_dhcp_auto + CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 + LWIP_IPV6 ?= 0 +else + LWIP_IPV6 ?= 1 +endif + +ifneq (0,$(LWIP_IPV6)) + USEMODULE += ipv6_addr + USEMODULE += lwip_ipv6 + USEMODULE += lwip_ipv6_autoconfig +endif + +USEMODULE += sock_udp +USEMODULE += sock_tcp + +include $(RIOTBASE)/Makefile.include + +# needs to be put after "include $(RIOTBASE)/Makefile.include" +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + CFLAGS += -DESP_WIFI_SSID=\"$(WIFI_SSID)\" + CFLAGS += -DESP_WIFI_PASS=\"$(WIFI_PASS)\" +endif diff --git a/examples/wolfmqtt_multithread/Makefile.board.dep b/examples/wolfmqtt_multithread/Makefile.board.dep new file mode 100644 index 000000000000..4000952c2801 --- /dev/null +++ b/examples/wolfmqtt_multithread/Makefile.board.dep @@ -0,0 +1,9 @@ +# Put board specific dependencies here + +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + USEMODULE += esp_wifi +endif + +ifeq ($(BOARD),native) + USEMODULE += netdev_default +endif diff --git a/examples/wolfmqtt_multithread/user_settings.h b/examples/wolfmqtt_multithread/user_settings.h new file mode 100644 index 000000000000..757e2f1b432a --- /dev/null +++ b/examples/wolfmqtt_multithread/user_settings.h @@ -0,0 +1,54 @@ +/* user_settings.h : custom configuration for wolfmqtt */ + +#ifndef WOLFMQTT_USER_SETTINGS_H +#define WOLFMQTT_USER_SETTINGS_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/* MANDATORY */ +#undef RIOT_OS +#define RIOT_OS + +#undef WOLFMQTT_MULTITHREAD +#define WOLFMQTT_MULTITHREAD + +#define WOLFMQTT_USE_HOSTNAME 1 + +#if WOLFMQTT_USE_HOSTNAME + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "test.mosquitto.org" + + #if defined(MODULE_IPV6_ADDR) + #undef WOLFMQTT_DNS_SERVER_IPV6 + #define WOLFMQTT_DNS_SERVER_IPV6 "2001:4860:4860::8888" + #else + #undef WOLFMQTT_DNS_SERVER_IPV4 + #define WOLFMQTT_DNS_SERVER_IPV4 "8.8.8.8" + #endif +#else + #if defined(MODULE_IPV6_ADDR) + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "2001:41d0:a:fed0::1" + #else + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "5.196.95.208" + #endif +#endif + +/* OPTIONAL */ +#undef TEST_MESSAGE +#define TEST_MESSAGE "wolfmqtt multithread on RIOT OS" + +#undef WOLFMQTT_DISCONNECT_CB +#define WOLFMQTT_DISCONNECT_CB + +#ifdef __cplusplus +} +#endif + + +#endif /* WOLFMQTT_USER_SETTINGS_H */ + diff --git a/examples/wolfmqtt_nbclient/Makefile b/examples/wolfmqtt_nbclient/Makefile new file mode 100644 index 000000000000..b187d91f73ac --- /dev/null +++ b/examples/wolfmqtt_nbclient/Makefile @@ -0,0 +1,58 @@ +# name of your application +APPLICATION = wolfmqtt_mqttclient + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +WIFI_SSID ?= "WIFI_SSID" +WIFI_PASS ?= "WIFI_PASS" + +USEPKG += wolfmqtt + +# This firmware is implemented inside the package examples +USEMODULE += wolfmqtt_examples_nbclient + +LWIP_IPV4 ?= 0 + +USEMODULE += lwip +USEMODULE += lwip_netdev +USEMODULE += lwip_netdb + +ifneq (0,$(LWIP_IPV4)) + USEMODULE += ipv4_addr + USEMODULE += lwip_arp + USEMODULE += lwip_ipv4 + USEMODULE += lwip_dhcp_auto + CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 + LWIP_IPV6 ?= 0 +else + LWIP_IPV6 ?= 1 +endif + +ifneq (0,$(LWIP_IPV6)) + USEMODULE += ipv6_addr + USEMODULE += lwip_ipv6 + USEMODULE += lwip_ipv6_autoconfig +endif + +USEMODULE += sock_udp +USEMODULE += sock_tcp + +include $(RIOTBASE)/Makefile.include + +# needs to be put after "include $(RIOTBASE)/Makefile.include" +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + CFLAGS += -DESP_WIFI_SSID=\"$(WIFI_SSID)\" + CFLAGS += -DESP_WIFI_PASS=\"$(WIFI_PASS)\" +endif diff --git a/examples/wolfmqtt_nbclient/Makefile.board.dep b/examples/wolfmqtt_nbclient/Makefile.board.dep new file mode 100644 index 000000000000..4000952c2801 --- /dev/null +++ b/examples/wolfmqtt_nbclient/Makefile.board.dep @@ -0,0 +1,9 @@ +# Put board specific dependencies here + +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + USEMODULE += esp_wifi +endif + +ifeq ($(BOARD),native) + USEMODULE += netdev_default +endif diff --git a/examples/wolfmqtt_nbclient/user_settings.h b/examples/wolfmqtt_nbclient/user_settings.h new file mode 100644 index 000000000000..c90b333284ec --- /dev/null +++ b/examples/wolfmqtt_nbclient/user_settings.h @@ -0,0 +1,58 @@ +/* user_settings.h : custom configuration for wolfmqtt */ + +#ifndef WOLFMQTT_USER_SETTINGS_H +#define WOLFMQTT_USER_SETTINGS_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/* MANDATORY */ +#undef RIOT_OS +#define RIOT_OS + +#undef WOLFMQTT_NONBLOCK +#define WOLFMQTT_NONBLOCK + +#define WOLFMQTT_USE_HOSTNAME 1 + +#if WOLFMQTT_USE_HOSTNAME + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "test.mosquitto.org" + + #if defined(MODULE_IPV6_ADDR) + #undef WOLFMQTT_DNS_SERVER_IPV6 + #define WOLFMQTT_DNS_SERVER_IPV6 "2001:4860:4860::8888" + #else + #undef WOLFMQTT_DNS_SERVER_IPV4 + #define WOLFMQTT_DNS_SERVER_IPV4 "8.8.8.8" + #endif +#else + #if defined(MODULE_IPV6_ADDR) + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "2001:41d0:a:fed0::1" + #else + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "5.196.95.208" + #endif +#endif + +/* OPTIONAL */ +#undef TEST_MESSAGE +#define TEST_MESSAGE "wolfmqtt nbclient on RIOT OS" + +#undef WOLFMQTT_DISCONNECT_CB +#define WOLFMQTT_DISCONNECT_CB + +/* these are missing even though including "errno.h" */ +#define EAGAIN 6 +#define EWOULDBLOCK 80 + +#ifdef __cplusplus +} +#endif + + +#endif /* WOLFMQTT_USER_SETTINGS_H */ + diff --git a/examples/wolfmqtt_snclient/Makefile b/examples/wolfmqtt_snclient/Makefile new file mode 100644 index 000000000000..468dd6bfea82 --- /dev/null +++ b/examples/wolfmqtt_snclient/Makefile @@ -0,0 +1,58 @@ +# name of your application +APPLICATION = wolfmqtt_snclient + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +WIFI_SSID ?= "WIFI_SSID" +WIFI_PASS ?= "WIFI_PASS" + +USEPKG += wolfmqtt + +# This firmware is implemented inside the package examples +USEMODULE += wolfmqtt_examples_snclient + +LWIP_IPV4 ?= 0 + +USEMODULE += lwip +USEMODULE += lwip_netdev +USEMODULE += lwip_netdb + +ifneq (0,$(LWIP_IPV4)) + USEMODULE += ipv4_addr + USEMODULE += lwip_arp + USEMODULE += lwip_ipv4 + USEMODULE += lwip_dhcp_auto + CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 + LWIP_IPV6 ?= 0 +else + LWIP_IPV6 ?= 1 +endif + +ifneq (0,$(LWIP_IPV6)) + USEMODULE += ipv6_addr + USEMODULE += lwip_ipv6 + USEMODULE += lwip_ipv6_autoconfig +endif + +USEMODULE += sock_udp +USEMODULE += sock_tcp + +include $(RIOTBASE)/Makefile.include + +# needs to be put after "include $(RIOTBASE)/Makefile.include" +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + CFLAGS += -DESP_WIFI_SSID=\"$(WIFI_SSID)\" + CFLAGS += -DESP_WIFI_PASS=\"$(WIFI_PASS)\" +endif diff --git a/examples/wolfmqtt_snclient/Makefile.board.dep b/examples/wolfmqtt_snclient/Makefile.board.dep new file mode 100644 index 000000000000..4000952c2801 --- /dev/null +++ b/examples/wolfmqtt_snclient/Makefile.board.dep @@ -0,0 +1,9 @@ +# Put board specific dependencies here + +ifneq (,$(filter arch_esp,$(FEATURES_USED))) + USEMODULE += esp_wifi +endif + +ifeq ($(BOARD),native) + USEMODULE += netdev_default +endif diff --git a/examples/wolfmqtt_snclient/user_settings.h b/examples/wolfmqtt_snclient/user_settings.h new file mode 100644 index 000000000000..2fa2e0732046 --- /dev/null +++ b/examples/wolfmqtt_snclient/user_settings.h @@ -0,0 +1,54 @@ +/* user_settings.h : custom configuration for wolfmqtt */ + +#ifndef WOLFMQTT_USER_SETTINGS_H +#define WOLFMQTT_USER_SETTINGS_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/* MANDATORY */ +#undef RIOT_OS +#define RIOT_OS + +#undef WOLFMQTT_SN +#define WOLFMQTT_SN + +#define WOLFMQTT_USE_HOSTNAME 0 + +#if WOLFMQTT_USE_HOSTNAME + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "TODO" /* if you know a public mqttsn service put it here */ + + #if defined(MODULE_IPV6_ADDR) + #undef WOLFMQTT_DNS_SERVER_IPV6 + #define WOLFMQTT_DNS_SERVER_IPV6 "2001:4860:4860::8888" + #else + #undef WOLFMQTT_DNS_SERVER_IPV4 + #define WOLFMQTT_DNS_SERVER_IPV4 "8.8.8.8" + #endif +#else + #if defined(MODULE_IPV6_ADDR) + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "2003:e9:f44:2f25:95dc:c243:6b3b:a257" /* local */ + #else + #undef DEFAULT_MQTT_HOST + #define DEFAULT_MQTT_HOST "192.168.2.110" /* local */ + #endif +#endif + +#undef DEFAULT_MQTT_PORT +#define DEFAULT_MQTT_PORT 10000 + +/* OPTIONAL */ +#undef TEST_MESSAGE +#define TEST_MESSAGE "wolfmqtt snclient on RIOT OS" + +#ifdef __cplusplus +} +#endif + + +#endif /* WOLFMQTT_USER_SETTINGS_H */ + diff --git a/pkg/lwip/Makefile.include b/pkg/lwip/Makefile.include index caf6629cb924..07413dc191c4 100644 --- a/pkg/lwip/Makefile.include +++ b/pkg/lwip/Makefile.include @@ -9,6 +9,7 @@ PSEUDOMODULES += lwip_ethernet PSEUDOMODULES += lwip_igmp PSEUDOMODULES += lwip_ipv6_autoconfig PSEUDOMODULES += lwip_ipv6_mld +PSEUDOMODULES += lwip_netdb PSEUDOMODULES += lwip_raw PSEUDOMODULES += lwip_sixlowpan PSEUDOMODULES += lwip_stats @@ -29,6 +30,9 @@ endif ifneq (,$(filter lwip_netdev,$(USEMODULE))) DIRS += $(RIOTBASE)/pkg/lwip/contrib/netdev endif +ifneq (,$(filter lwip_netdb,$(USEMODULE))) + CFLAGS += -DLWIP_NETDB +endif ifneq (,$(filter lwip_sock,$(USEMODULE))) ifneq (,$(filter lwip_ipv6,$(USEMODULE))) CFLAGS += -DSOCK_HAS_IPV6 diff --git a/pkg/lwip/contrib/sock/udp/lwip_sock_udp.c b/pkg/lwip/contrib/sock/udp/lwip_sock_udp.c index 0e126f0ee68c..da5966c685b8 100644 --- a/pkg/lwip/contrib/sock/udp/lwip_sock_udp.c +++ b/pkg/lwip/contrib/sock/udp/lwip_sock_udp.c @@ -27,6 +27,10 @@ #include "lwip/sys.h" #include "lwip/udp.h" +#include "ringbuffer.h" + +#define RECV_BUF_SIZE 32 + int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local, const sock_udp_ep_t *remote, uint16_t flags) { @@ -43,6 +47,15 @@ int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local, #if IS_ACTIVE(SOCK_HAS_ASYNC) netconn_set_callback_arg(sock->base.conn, &sock->base); #endif + + char *buf_ptr = malloc(RECV_BUF_SIZE * sizeof(char)); + if(buf_ptr == NULL) { + errno = ENOMEM; + res = -1; + } + else { + ringbuffer_init(&(sock->recv_rb), buf_ptr, RECV_BUF_SIZE); + } } return res; } @@ -53,6 +66,8 @@ void sock_udp_close(sock_udp_t *sock) if (sock->base.conn != NULL) { netconn_delete(sock->base.conn); sock->base.conn = NULL; + + free(sock->recv_rb.buf); } } @@ -80,19 +95,50 @@ ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len, ssize_t res, ret = 0; bool nobufs = false; + size_t to_read = max_len; + uint8_t *buf_index = ptr; + + while (to_read != 0 && !ringbuffer_empty(&(sock->recv_rb))) { + *buf_index++ = ringbuffer_get_one(&(sock->recv_rb)); + to_read--; + } + + if (to_read == 0) { + /* read all bytes from ringbuffer */ + return max_len; + } + else { + /* only a part of the bytes was read from peek buffer, need to get + * the rest via socket calls + */ + ptr += max_len - to_read; + max_len = to_read; + } + assert((sock != NULL) && (data != NULL) && (max_len > 0)); while ((res = sock_udp_recv_buf_aux(sock, &pkt, &ctx, timeout, remote, aux)) > 0) { struct netbuf *buf = ctx; + if (buf->p->tot_len > (ssize_t)max_len) { - nobufs = true; + + size_t leftover_count = res - max_len; + ringbuffer_add(&(sock->recv_rb), (((char*) pkt) + max_len), leftover_count); + + memcpy(ptr, pkt, max_len); + ptr += max_len; + ret += max_len; + + //nobufs = true; /* progress context to last element */ - while (netbuf_next(ctx) == 0) {} - continue; + // while (netbuf_next(ctx) == 0) {} + // continue; + } + else { + memcpy(ptr, pkt, res); + ptr += res; + ret += res; } - memcpy(ptr, pkt, res); - ptr += res; - ret += res; } return (nobufs) ? -ENOBUFS : ((res < 0) ? res : ret); } diff --git a/pkg/lwip/include/lwipopts.h b/pkg/lwip/include/lwipopts.h index 9573866ae260..084fd8647957 100644 --- a/pkg/lwip/include/lwipopts.h +++ b/pkg/lwip/include/lwipopts.h @@ -148,6 +148,13 @@ extern "C" { #define LWIP_SOCKET 0 +#ifdef MODULE_LWIP_NETDB +#define LWIP_NETDB 1 +#define LWIP_DNS_API_DEFINE_ERRORS 1 +#define LWIP_DNS_API_DECLARE_H_ERRNO 1 +#define LWIP_DNS_API_DECLARE_STRUCTS 1 +#endif /* MODULE_LWIP_NETDB */ + #define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS #define MEMP_MEM_MALLOC 1 #define NETIF_MAX_HWADDR_LEN (GNRC_NETIF_HDR_L2ADDR_MAX_LEN) diff --git a/pkg/lwip/include/sock_types.h b/pkg/lwip/include/sock_types.h index 33e4686cba53..9a8ab12bd646 100644 --- a/pkg/lwip/include/sock_types.h +++ b/pkg/lwip/include/sock_types.h @@ -24,6 +24,8 @@ #include "net/sock/async/types.h" #endif +#include "ringbuffer.h" + #ifdef __cplusplus extern "C" { #endif @@ -127,6 +129,7 @@ struct sock_tcp_queue { */ struct sock_udp { lwip_sock_base_t base; /**< parent class */ + ringbuffer_t recv_rb; }; #ifdef __cplusplus diff --git a/pkg/lwip/patches/0002-adapt-netdb-functions-for-RIOT.patch b/pkg/lwip/patches/0002-adapt-netdb-functions-for-RIOT.patch new file mode 100644 index 000000000000..19e4715f9423 --- /dev/null +++ b/pkg/lwip/patches/0002-adapt-netdb-functions-for-RIOT.patch @@ -0,0 +1,249 @@ +From 51eb852671389157892781db7f80c39894d39996 Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Tue, 15 Jun 2021 22:05:13 +0200 +Subject: [PATCH] adapt netdb functions for RIOT + +--- + src/api/netdb.c | 23 ++++++++++------------- + src/include/lwip/inet.h | 28 ++++++++++++++++++++++++++++ + src/include/lwip/netdb.h | 19 ++++--------------- + src/include/lwip/priv/memp_std.h | 4 ++-- + 4 files changed, 44 insertions(+), 30 deletions(-) + +diff --git a/src/api/netdb.c b/src/api/netdb.c +index 87714259..4abd26e8 100644 +--- a/src/api/netdb.c ++++ b/src/api/netdb.c +@@ -37,7 +37,7 @@ + + #include "lwip/netdb.h" + +-#if LWIP_DNS && LWIP_SOCKET ++#if LWIP_NETDB + + #include "lwip/err.h" + #include "lwip/mem.h" +@@ -49,6 +49,8 @@ + #include /* memset */ + #include /* atoi */ + ++#include "net/sock/dns.h" ++ + /** helper struct for gethostbyname_r to access the char* buffer */ + struct gethostbyname_r_helper { + ip_addr_t *addr_list[2]; +@@ -86,7 +88,6 @@ int h_errno; + struct hostent * + lwip_gethostbyname(const char *name) + { +- err_t err; + ip_addr_t addr; + + /* buffer variables for lwip_gethostbyname() */ +@@ -97,8 +98,8 @@ lwip_gethostbyname(const char *name) + HOSTENT_STORAGE char s_hostname[DNS_MAX_NAME_LENGTH + 1]; + + /* query host IP address */ +- err = netconn_gethostbyname(name, &addr); +- if (err != ERR_OK) { ++ int res = sock_dns_query(name, &addr, AF_INET); ++ if (res < 0) { + LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err)); + h_errno = HOST_NOT_FOUND; + return NULL; +@@ -162,7 +163,6 @@ int + lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf, + size_t buflen, struct hostent **result, int *h_errnop) + { +- err_t err; + struct gethostbyname_r_helper *h; + char *hostname; + size_t namelen; +@@ -197,8 +197,8 @@ lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf, + hostname = ((char *)h) + sizeof(struct gethostbyname_r_helper); + + /* query host IP address */ +- err = netconn_gethostbyname(name, &h->addr); +- if (err != ERR_OK) { ++ int res = sock_dns_query(name, &h->addr, AF_INET); ++ if (res < 0) { + LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err)); + *h_errnop = HOST_NOT_FOUND; + return -1; +@@ -269,7 +269,6 @@ int + lwip_getaddrinfo(const char *nodename, const char *servname, + const struct addrinfo *hints, struct addrinfo **res) + { +- err_t err; + ip_addr_t addr; + struct addrinfo *ai; + struct sockaddr_storage *sa = NULL; +@@ -334,8 +333,8 @@ lwip_getaddrinfo(const char *nodename, const char *servname, + type = NETCONN_DNS_IPV6; + } + #endif /* LWIP_IPV4 && LWIP_IPV6 */ +- err = netconn_gethostbyname_addrtype(nodename, &addr, type); +- if (err != ERR_OK) { ++ int res = sock_dns_query(nodename, &addr, ai_family); ++ if (res < 0) { + return EAI_FAIL; + } + } +@@ -374,7 +373,6 @@ lwip_getaddrinfo(const char *nodename, const char *servname, + /* set up sockaddr */ + 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 = lwip_htons((u16_t)port_nr); + sa6->sin6_scope_id = ip6_addr_zone(ip_2_ip6(&addr)); + ai->ai_family = AF_INET6; +@@ -385,7 +383,6 @@ lwip_getaddrinfo(const char *nodename, const char *servname, + /* set up sockaddr */ + 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 = lwip_htons((u16_t)port_nr); + ai->ai_family = AF_INET; + #endif /* LWIP_IPV4 */ +@@ -411,4 +408,4 @@ lwip_getaddrinfo(const char *nodename, const char *servname, + return 0; + } + +-#endif /* LWIP_DNS && LWIP_SOCKET */ ++#endif /* LWIP_NETDB */ +diff --git a/src/include/lwip/inet.h b/src/include/lwip/inet.h +index 2982a0f4..7fd2d0cc 100644 +--- a/src/include/lwip/inet.h ++++ b/src/include/lwip/inet.h +@@ -55,6 +55,7 @@ extern "C" { + typedef u32_t in_addr_t; + #endif + ++#ifndef MODULE_POSIX_INET + struct in_addr { + in_addr_t s_addr; + }; +@@ -66,16 +67,21 @@ struct in6_addr { + } un; + #define s6_addr un.u8_addr + }; ++#endif /* MODULE_POSIX_INET */ + + /** 255.255.255.255 */ + #define INADDR_NONE IPADDR_NONE + /** 127.0.0.1 */ + #define INADDR_LOOPBACK IPADDR_LOOPBACK + /** 0.0.0.0 */ ++ ++#ifndef MODULE_POSIX_INET + #define INADDR_ANY IPADDR_ANY + /** 255.255.255.255 */ + #define INADDR_BROADCAST IPADDR_BROADCAST ++#endif /* MODULE_POSIX_INET */ + ++#ifndef MODULE_POSIX_INET + /** This macro can be used to initialize a variable of type struct in6_addr + to the IPv6 wildcard address. */ + #define IN6ADDR_ANY_INIT {{{0,0,0,0}}} +@@ -83,6 +89,8 @@ struct in6_addr { + to the IPv6 loopback address. */ + #define IN6ADDR_LOOPBACK_INIT {{{0,0,0,PP_HTONL(1)}}} + /** This variable is initialized by the system to contain the wildcard IPv6 address. */ ++#endif /* MODULE_POSIX_INET */ ++ + extern const struct in6_addr in6addr_any; + + /* Definitions of the bits in an (IPv4) Internet address integer. +@@ -144,6 +152,25 @@ extern const struct in6_addr in6addr_any; + #endif /* LWIP_IPV4 */ + + #if LWIP_IPV6 ++ ++#ifdef MODULE_POSIX_INET ++#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->s6_addr[0] = ((source_ip6addr)->addr[0] & 0x000000ff) >> 0; \ ++ (target_in6addr)->s6_addr[1] = ((source_ip6addr)->addr[0] & 0x0000ff00) >> 8; \ ++ (target_in6addr)->s6_addr[2] = ((source_ip6addr)->addr[0] & 0x00ff0000) >> 16; \ ++ (target_in6addr)->s6_addr[3] = ((source_ip6addr)->addr[0] & 0xff000000) >> 24; \ ++ (target_in6addr)->s6_addr[4] = ((source_ip6addr)->addr[1] & 0x000000ff) >> 0; \ ++ (target_in6addr)->s6_addr[5] = ((source_ip6addr)->addr[1] & 0x0000ff00) >> 8; \ ++ (target_in6addr)->s6_addr[6] = ((source_ip6addr)->addr[1] & 0x00ff0000) >> 16; \ ++ (target_in6addr)->s6_addr[7] = ((source_ip6addr)->addr[1] & 0xff000000) >> 24; \ ++ (target_in6addr)->s6_addr[8] = ((source_ip6addr)->addr[2] & 0x000000ff) >> 0; \ ++ (target_in6addr)->s6_addr[9] = ((source_ip6addr)->addr[2] & 0x0000ff00) >> 8; \ ++ (target_in6addr)->s6_addr[10] = ((source_ip6addr)->addr[2] & 0x00ff0000) >> 16; \ ++ (target_in6addr)->s6_addr[11] = ((source_ip6addr)->addr[2] & 0xff000000) >> 24; \ ++ (target_in6addr)->s6_addr[12] = ((source_ip6addr)->addr[3] & 0x000000ff) >> 0; \ ++ (target_in6addr)->s6_addr[13] = ((source_ip6addr)->addr[3] & 0x0000ff00) >> 8; \ ++ (target_in6addr)->s6_addr[14] = ((source_ip6addr)->addr[3] & 0x00ff0000) >> 16; \ ++ (target_in6addr)->s6_addr[15] = ((source_ip6addr)->addr[3] & 0xff000000) >> 24; } ++#else + #define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \ + (target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \ + (target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \ +@@ -153,6 +180,7 @@ extern const struct in6_addr in6addr_any; + (target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \ + (target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3]; \ + ip6_addr_clear_zone(target_ip6addr);} ++#endif /* MODULE_POSIX_INET */ + + /* directly map this to the lwip internal functions */ + #define inet6_aton(cp, addr) ip6addr_aton(cp, (ip6_addr_t*)addr) +diff --git a/src/include/lwip/netdb.h b/src/include/lwip/netdb.h +index d3d15dfa..03a4d663 100644 +--- a/src/include/lwip/netdb.h ++++ b/src/include/lwip/netdb.h +@@ -36,7 +36,9 @@ + + #include "lwip/opt.h" + +-#if LWIP_DNS && LWIP_SOCKET ++#if LWIP_NETDB ++ ++#include + + #include "lwip/arch.h" + #include "lwip/inet.h" +@@ -128,23 +130,10 @@ int lwip_getaddrinfo(const char *nodename, + const struct addrinfo *hints, + struct addrinfo **res); + +-#if LWIP_COMPAT_SOCKETS +-/** @ingroup netdbapi */ +-#define gethostbyname(name) lwip_gethostbyname(name) +-/** @ingroup netdbapi */ +-#define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \ +- lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop) +-/** @ingroup netdbapi */ +-#define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo) +-/** @ingroup netdbapi */ +-#define getaddrinfo(nodname, servname, hints, res) \ +- lwip_getaddrinfo(nodname, servname, hints, res) +-#endif /* LWIP_COMPAT_SOCKETS */ +- + #ifdef __cplusplus + } + #endif + +-#endif /* LWIP_DNS && LWIP_SOCKET */ ++#endif /* LWIP_NETDB */ + + #endif /* LWIP_HDR_NETDB_H */ +diff --git a/src/include/lwip/priv/memp_std.h b/src/include/lwip/priv/memp_std.h +index 669ad4d7..a03e55b6 100644 +--- a/src/include/lwip/priv/memp_std.h ++++ b/src/include/lwip/priv/memp_std.h +@@ -102,9 +102,9 @@ LWIP_MEMPOOL(IGMP_GROUP, MEMP_NUM_IGMP_GROUP, sizeof(struct igmp_group) + LWIP_MEMPOOL(SYS_TIMEOUT, MEMP_NUM_SYS_TIMEOUT, sizeof(struct sys_timeo), "SYS_TIMEOUT") + #endif /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */ + +-#if LWIP_DNS && LWIP_SOCKET ++#if LWIP_NETDB + LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE, "NETDB") +-#endif /* LWIP_DNS && LWIP_SOCKET */ ++#endif /* LWIP_NETDB */ + #if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC + LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST") + #endif /* LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ +-- +2.25.1 + diff --git a/pkg/wolfmqtt/Makefile b/pkg/wolfmqtt/Makefile new file mode 100644 index 000000000000..ac1f560c4372 --- /dev/null +++ b/pkg/wolfmqtt/Makefile @@ -0,0 +1,43 @@ +PKG_NAME = wolfmqtt +PKG_URL = https://github.com/wolfssl/wolfmqtt.git +PKG_VERSION = 238a70ec96a7501853b81241352c5091a86e9251 # v1.7 +PKG_LICENSE = GPLv2 + +include $(RIOTBASE)/pkg/pkg.mk + +CFLAGS += -Wno-unused-parameter + +all: $(filter \ + wolfmqtt \ + wolfmqtt_examples \ + wolfmqtt_examples_mqttclient \ + wolfmqtt_examples_snclient \ + wolfmqtt_examples_nbclient \ + wolfmqtt_examples_multithread \ + wolfmqtt_examples_aws \ + wolfmqtt_examples_azure \ + ,$(USEMODULE)) + +wolfmqtt: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/src -f $(CURDIR)/Makefile.$(PKG_NAME) + +wolfmqtt_examples: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/wolfmqtt_examples -f $(CURDIR)/Makefile.$(PKG_NAME).examples + +wolfmqtt_examples_mqttclient: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/wolfmqtt_examples/mqttclient -f $(CURDIR)/Makefile.$(PKG_NAME).examples.mqttclient + +wolfmqtt_examples_snclient: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/wolfmqtt_examples/sn-client -f $(CURDIR)/Makefile.$(PKG_NAME).examples.snclient + +wolfmqtt_examples_nbclient: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/wolfmqtt_examples/nbclient -f $(CURDIR)/Makefile.$(PKG_NAME).examples.nbclient + +wolfmqtt_examples_multithread: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/wolfmqtt_examples/multithread -f $(CURDIR)/Makefile.$(PKG_NAME).examples.multithread + +wolfmqtt_examples_aws: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/wolfmqtt_examples/aws -f $(CURDIR)/Makefile.$(PKG_NAME).examples.aws + +wolfmqtt_examples_azure: + "$(MAKE)" -C $(PKG_SOURCE_DIR)/wolfmqtt_examples/azure -f $(CURDIR)/Makefile.$(PKG_NAME).examples.azure diff --git a/pkg/wolfmqtt/Makefile.dep b/pkg/wolfmqtt/Makefile.dep new file mode 100644 index 000000000000..a43360d6b50a --- /dev/null +++ b/pkg/wolfmqtt/Makefile.dep @@ -0,0 +1,11 @@ +USEMODULE += wolfmqtt +USEMODULE += wolfmqtt_examples + +USEMODULE += posix_inet +USEMODULE += posix_netdb +USEMODULE += posix_sockets +USEMODULE += posix_select +USEMODULE += posix_semaphore +USEMODULE += pthread + +USEMODULE += xtimer diff --git a/pkg/wolfmqtt/Makefile.include b/pkg/wolfmqtt/Makefile.include new file mode 100644 index 000000000000..30d69fe01c19 --- /dev/null +++ b/pkg/wolfmqtt/Makefile.include @@ -0,0 +1,4 @@ +CFLAGS += -DWOLFMQTT_USER_SETTINGS=1 + +INCLUDES += -I$(APPDIR) +INCLUDES += -I$(PKGDIRBASE)/wolfmqtt diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt b/pkg/wolfmqtt/Makefile.wolfmqtt new file mode 100644 index 000000000000..c1eceba5594a --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt @@ -0,0 +1,3 @@ +MODULE = wolfmqtt + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt.examples b/pkg/wolfmqtt/Makefile.wolfmqtt.examples new file mode 100644 index 000000000000..7e20dd6ed545 --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt.examples @@ -0,0 +1,3 @@ +MODULE = wolfmqtt_examples + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt.examples.aws b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.aws new file mode 100644 index 000000000000..25b9b551210b --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.aws @@ -0,0 +1,3 @@ +MODULE = wolfmqtt_examples_aws + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt.examples.azure b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.azure new file mode 100644 index 000000000000..e95561c07e11 --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.azure @@ -0,0 +1,3 @@ +MODULE = wolfmqtt_examples_azure + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt.examples.mqttclient b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.mqttclient new file mode 100644 index 000000000000..9eb4b906a301 --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.mqttclient @@ -0,0 +1,3 @@ +MODULE = wolfmqtt_examples_mqttclient + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt.examples.multithread b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.multithread new file mode 100644 index 000000000000..7b3ab43dd4ba --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.multithread @@ -0,0 +1,3 @@ +MODULE = wolfmqtt_examples_multithread + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt.examples.nbclient b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.nbclient new file mode 100644 index 000000000000..6167bcce8a14 --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.nbclient @@ -0,0 +1,3 @@ +MODULE = wolfmqtt_examples_nbclient + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/Makefile.wolfmqtt.examples.snclient b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.snclient new file mode 100644 index 000000000000..6e4290fd00ea --- /dev/null +++ b/pkg/wolfmqtt/Makefile.wolfmqtt.examples.snclient @@ -0,0 +1,3 @@ +MODULE = wolfmqtt_examples_snclient + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/wolfmqtt/doc.txt b/pkg/wolfmqtt/doc.txt new file mode 100644 index 000000000000..dbf6f4be85e3 --- /dev/null +++ b/pkg/wolfmqtt/doc.txt @@ -0,0 +1,70 @@ +/** + * @defgroup pkg_wolfmqtt WolfMQTT embedded MQTT library + * @ingroup pkg + * @brief Provides the WolfMQTT client and example applications + * + * # Introduction + * + * The wolfMQTT library is a client implementation of the MQTT written in C for + * embedded use. It supports SSL/TLS via the wolfSSL library. From this, it can + * provide the security that the MQTT protocol lacks. wolfMQTT was built from + * the ground up to be multi-platform, space conscience and extensible. It + * supports all Packet Types, all Quality of Service (QoS) levels 0-2 and + * supports SSL/TLS using the wolfSSL library. This implementation provides + * support for MQTT v5.0 and is based on MQTT v3.1.1. Additionally, there is + * also client support for MQTT-SN (Sensor Network). + * + * Feature of wolfMQTT library supported by RIOT port at the moment + * Disconnect Callback yes + * Error Strings yes + * MQTT-SN yes + * MQTT v5.0 yes + * Property Callback yes + * Examples yes (partly) + * Non-Blocking yes + * STDIN Capture yes + * TLS no + * Multi-thread yes + * + * # License + * + * wolfSSL’s software is available under two distinct licensing models: + * Open Source (GPLv2) or proprietary. + * + * Open Source + * + * wolfSSL (formerly CyaSSL) offers multiple products including, but not limited + * to: + * + * wolfSSL + * wolfCrypt + * wolfMQTT + * wolfSSH + * + * These software products are free software and may be modified to + * the needs of the user as long as the user adheres to version two of the GPL + * License. The GPLv2 license can be found on the gnu.org website + * (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html). + * + * + * Commercial Licensing + * + * Businesses and enterprises who wish to incorporate wolfSSL products into + * proprietary appliances or other commercial software products for + * re-distribution must license commercial versions. Commercial licenses for + * wolfSSL, yaSSL, and wolfCrypt are available. Licenses are generally issued + * for one product and include unlimited royalty-free distribution. Custom + * licensing terms are also available. + * + * Commercial licenses are also available for wolfMQTT and wolfSSH. + * Please contact licensing@wolfssl.com with inquiries. + * + * @see https://github.com/wolfssl/wolfssl.git + * + * + * QUESTIONS / CONCERNS / FEEDBACK: + * + * For any questions, concerns, or other feedback please contact + * support@wolfssl.com anytime, we are always happy to help in any way we can!! + * + */ diff --git a/pkg/wolfmqtt/patches/0001-examples-prepend-examples-directory-by-wolfmqtt_.patch b/pkg/wolfmqtt/patches/0001-examples-prepend-examples-directory-by-wolfmqtt_.patch new file mode 100644 index 000000000000..cdef8c8503a9 --- /dev/null +++ b/pkg/wolfmqtt/patches/0001-examples-prepend-examples-directory-by-wolfmqtt_.patch @@ -0,0 +1,526 @@ +From d7bc5981c3b2b1e2d5b5bdbc0e2b43ff02d65e8b Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Thu, 21 Jan 2021 14:44:00 +0100 +Subject: [PATCH] examples: prepend examples directory by wolfmqtt_ + +--- + {examples => wolfmqtt_examples}/aws/awsiot.c | 4 ++-- + {examples => wolfmqtt_examples}/aws/awsiot.h | 2 +- + {examples => wolfmqtt_examples}/aws/awsiot.vcxproj | 0 + {examples => wolfmqtt_examples}/azure/azureiothub.c | 4 ++-- + {examples => wolfmqtt_examples}/azure/azureiothub.h | 2 +- + {examples => wolfmqtt_examples}/azure/azureiothub.vcxproj | 0 + {examples => wolfmqtt_examples}/firmware/firmware.h | 0 + .../firmware/firmware/firmware.X/nbproject/configurations.xml | 0 + .../firmware/firmware/firmware.X/nbproject/project.xml | 0 + {examples => wolfmqtt_examples}/firmware/fwclient.c | 4 ++-- + {examples => wolfmqtt_examples}/firmware/fwclient.h | 2 +- + {examples => wolfmqtt_examples}/firmware/fwclient.vcxproj | 0 + {examples => wolfmqtt_examples}/firmware/fwpush.c | 4 ++-- + {examples => wolfmqtt_examples}/firmware/fwpush.h | 2 +- + {examples => wolfmqtt_examples}/firmware/fwpush.vcxproj | 0 + {examples => wolfmqtt_examples}/include.am | 0 + {examples => wolfmqtt_examples}/mqttclient/mqttclient.c | 2 +- + {examples => wolfmqtt_examples}/mqttclient/mqttclient.h | 2 +- + {examples => wolfmqtt_examples}/mqttclient/mqttclient.vcxproj | 0 + {examples => wolfmqtt_examples}/mqttexample.c | 4 ++-- + {examples => wolfmqtt_examples}/mqttexample.h | 0 + {examples => wolfmqtt_examples}/mqttnet.c | 4 ++-- + {examples => wolfmqtt_examples}/mqttnet.h | 2 +- + {examples => wolfmqtt_examples}/mqttsimple/mqttsimple.c | 0 + {examples => wolfmqtt_examples}/mqttsimple/mqttsimple.h | 0 + {examples => wolfmqtt_examples}/mqttuart.c | 4 ++-- + {examples => wolfmqtt_examples}/multithread/multithread.c | 4 ++-- + {examples => wolfmqtt_examples}/multithread/multithread.h | 2 +- + .../multithread/multithread.vcxproj | 0 + {examples => wolfmqtt_examples}/nbclient/nbclient.c | 2 +- + {examples => wolfmqtt_examples}/nbclient/nbclient.h | 2 +- + {examples => wolfmqtt_examples}/nbclient/nbclient.vcxproj | 0 + {examples => wolfmqtt_examples}/sn-client/sn-client.c | 2 +- + {examples => wolfmqtt_examples}/sn-client/sn-client.h | 2 +- + {examples => wolfmqtt_examples}/sn-client/sn-client.vcxproj | 0 + {examples => wolfmqtt_examples}/wiot/wiot.c | 4 ++-- + {examples => wolfmqtt_examples}/wiot/wiot.h | 2 +- + {examples => wolfmqtt_examples}/wiot/wiot.vcxproj | 0 + 38 files changed, 31 insertions(+), 31 deletions(-) + rename {examples => wolfmqtt_examples}/aws/awsiot.c (99%) + rename {examples => wolfmqtt_examples}/aws/awsiot.h (95%) + rename {examples => wolfmqtt_examples}/aws/awsiot.vcxproj (100%) + rename {examples => wolfmqtt_examples}/azure/azureiothub.c (99%) + rename {examples => wolfmqtt_examples}/azure/azureiothub.h (95%) + rename {examples => wolfmqtt_examples}/azure/azureiothub.vcxproj (100%) + rename {examples => wolfmqtt_examples}/firmware/firmware.h (100%) + rename {examples => wolfmqtt_examples}/firmware/firmware/firmware/firmware.X/nbproject/configurations.xml (100%) + rename {examples => wolfmqtt_examples}/firmware/firmware/firmware/firmware.X/nbproject/project.xml (100%) + rename {examples => wolfmqtt_examples}/firmware/fwclient.c (99%) + rename {examples => wolfmqtt_examples}/firmware/fwclient.h (96%) + rename {examples => wolfmqtt_examples}/firmware/fwclient.vcxproj (100%) + rename {examples => wolfmqtt_examples}/firmware/fwpush.c (99%) + rename {examples => wolfmqtt_examples}/firmware/fwpush.h (96%) + rename {examples => wolfmqtt_examples}/firmware/fwpush.vcxproj (100%) + rename {examples => wolfmqtt_examples}/include.am (100%) + rename {examples => wolfmqtt_examples}/mqttclient/mqttclient.c (99%) + rename {examples => wolfmqtt_examples}/mqttclient/mqttclient.h (95%) + rename {examples => wolfmqtt_examples}/mqttclient/mqttclient.vcxproj (100%) + rename {examples => wolfmqtt_examples}/mqttexample.c (99%) + rename {examples => wolfmqtt_examples}/mqttexample.h (100%) + rename {examples => wolfmqtt_examples}/mqttnet.c (99%) + rename {examples => wolfmqtt_examples}/mqttnet.h (97%) + rename {examples => wolfmqtt_examples}/mqttsimple/mqttsimple.c (100%) + rename {examples => wolfmqtt_examples}/mqttsimple/mqttsimple.h (100%) + rename {examples => wolfmqtt_examples}/mqttuart.c (96%) + rename {examples => wolfmqtt_examples}/multithread/multithread.c (99%) + rename {examples => wolfmqtt_examples}/multithread/multithread.h (95%) + rename {examples => wolfmqtt_examples}/multithread/multithread.vcxproj (100%) + rename {examples => wolfmqtt_examples}/nbclient/nbclient.c (99%) + rename {examples => wolfmqtt_examples}/nbclient/nbclient.h (95%) + rename {examples => wolfmqtt_examples}/nbclient/nbclient.vcxproj (100%) + rename {examples => wolfmqtt_examples}/sn-client/sn-client.c (99%) + rename {examples => wolfmqtt_examples}/sn-client/sn-client.h (95%) + rename {examples => wolfmqtt_examples}/sn-client/sn-client.vcxproj (100%) + rename {examples => wolfmqtt_examples}/wiot/wiot.c (99%) + rename {examples => wolfmqtt_examples}/wiot/wiot.h (95%) + rename {examples => wolfmqtt_examples}/wiot/wiot.vcxproj (100%) + +diff --git a/examples/aws/awsiot.c b/wolfmqtt_examples/aws/awsiot.c +similarity index 99% +rename from examples/aws/awsiot.c +rename to wolfmqtt_examples/aws/awsiot.c +index d71e116..8e2f1bb 100644 +--- a/examples/aws/awsiot.c ++++ b/wolfmqtt_examples/aws/awsiot.c +@@ -58,8 +58,8 @@ + #include + + #include "awsiot.h" +-#include "examples/mqttexample.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" + #include + + /* Locals */ +diff --git a/examples/aws/awsiot.h b/wolfmqtt_examples/aws/awsiot.h +similarity index 95% +rename from examples/aws/awsiot.h +rename to wolfmqtt_examples/aws/awsiot.h +index 3dc21fe..5c66d15 100644 +--- a/examples/aws/awsiot.h ++++ b/wolfmqtt_examples/aws/awsiot.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_AWSIOT_H + #define WOLFMQTT_AWSIOT_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* Exposed functions */ +diff --git a/examples/aws/awsiot.vcxproj b/wolfmqtt_examples/aws/awsiot.vcxproj +similarity index 100% +rename from examples/aws/awsiot.vcxproj +rename to wolfmqtt_examples/aws/awsiot.vcxproj +diff --git a/examples/azure/azureiothub.c b/wolfmqtt_examples/azure/azureiothub.c +similarity index 99% +rename from examples/azure/azureiothub.c +rename to wolfmqtt_examples/azure/azureiothub.c +index e8bb54d..ff7d38a 100644 +--- a/examples/azure/azureiothub.c ++++ b/wolfmqtt_examples/azure/azureiothub.c +@@ -62,8 +62,8 @@ + #include + + #include "azureiothub.h" +-#include "examples/mqttexample.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" + + /* Locals */ + static int mStopRead = 0; +diff --git a/examples/azure/azureiothub.h b/wolfmqtt_examples/azure/azureiothub.h +similarity index 95% +rename from examples/azure/azureiothub.h +rename to wolfmqtt_examples/azure/azureiothub.h +index f0db48e..3186513 100644 +--- a/examples/azure/azureiothub.h ++++ b/wolfmqtt_examples/azure/azureiothub.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_AZUREIOTHUB_H + #define WOLFMQTT_AZUREIOTHUB_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* Exposed functions */ +diff --git a/examples/azure/azureiothub.vcxproj b/wolfmqtt_examples/azure/azureiothub.vcxproj +similarity index 100% +rename from examples/azure/azureiothub.vcxproj +rename to wolfmqtt_examples/azure/azureiothub.vcxproj +diff --git a/examples/firmware/firmware.h b/wolfmqtt_examples/firmware/firmware.h +similarity index 100% +rename from examples/firmware/firmware.h +rename to wolfmqtt_examples/firmware/firmware.h +diff --git a/examples/firmware/firmware/firmware/firmware.X/nbproject/configurations.xml b/wolfmqtt_examples/firmware/firmware/firmware/firmware.X/nbproject/configurations.xml +similarity index 100% +rename from examples/firmware/firmware/firmware/firmware.X/nbproject/configurations.xml +rename to wolfmqtt_examples/firmware/firmware/firmware/firmware.X/nbproject/configurations.xml +diff --git a/examples/firmware/firmware/firmware/firmware.X/nbproject/project.xml b/wolfmqtt_examples/firmware/firmware/firmware/firmware.X/nbproject/project.xml +similarity index 100% +rename from examples/firmware/firmware/firmware/firmware.X/nbproject/project.xml +rename to wolfmqtt_examples/firmware/firmware/firmware/firmware.X/nbproject/project.xml +diff --git a/examples/firmware/fwclient.c b/wolfmqtt_examples/firmware/fwclient.c +similarity index 99% +rename from examples/firmware/fwclient.c +rename to wolfmqtt_examples/firmware/fwclient.c +index 22435c4..194361e 100644 +--- a/examples/firmware/fwclient.c ++++ b/wolfmqtt_examples/firmware/fwclient.c +@@ -51,8 +51,8 @@ + + #include "fwclient.h" + #include "firmware.h" +-#include "examples/mqttexample.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" + + /* Configuration */ + #define MAX_BUFFER_SIZE FIRMWARE_MAX_PACKET +diff --git a/examples/firmware/fwclient.h b/wolfmqtt_examples/firmware/fwclient.h +similarity index 96% +rename from examples/firmware/fwclient.h +rename to wolfmqtt_examples/firmware/fwclient.h +index 3fdf7ba..496c400 100644 +--- a/examples/firmware/fwclient.h ++++ b/wolfmqtt_examples/firmware/fwclient.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_FWCLIENT_H + #define WOLFMQTT_FWCLIENT_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + #define FIRMWARE_CLIIENT_ID "WolfMQTTFWClient" + #define FIRMWARE_DEF_SAVE_AS "firmware.bin" +diff --git a/examples/firmware/fwclient.vcxproj b/wolfmqtt_examples/firmware/fwclient.vcxproj +similarity index 100% +rename from examples/firmware/fwclient.vcxproj +rename to wolfmqtt_examples/firmware/fwclient.vcxproj +diff --git a/examples/firmware/fwpush.c b/wolfmqtt_examples/firmware/fwpush.c +similarity index 99% +rename from examples/firmware/fwpush.c +rename to wolfmqtt_examples/firmware/fwpush.c +index 0653594..49c5307 100644 +--- a/examples/firmware/fwpush.c ++++ b/wolfmqtt_examples/firmware/fwpush.c +@@ -51,8 +51,8 @@ + + #include "fwpush.h" + #include "firmware.h" +-#include "examples/mqttexample.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" + + /* Configuration */ + #define MAX_BUFFER_SIZE FIRMWARE_MAX_PACKET +diff --git a/examples/firmware/fwpush.h b/wolfmqtt_examples/firmware/fwpush.h +similarity index 96% +rename from examples/firmware/fwpush.h +rename to wolfmqtt_examples/firmware/fwpush.h +index 39fa48f..2fe4fcd 100644 +--- a/examples/firmware/fwpush.h ++++ b/wolfmqtt_examples/firmware/fwpush.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_FWPUSH_H + #define WOLFMQTT_FWPUSH_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + #define FIRMWARE_PUSH_CLIENT_ID "WolfMQTTFwPush" + #define FIRMWARE_PUSH_DEF_FILE "README.md" +diff --git a/examples/firmware/fwpush.vcxproj b/wolfmqtt_examples/firmware/fwpush.vcxproj +similarity index 100% +rename from examples/firmware/fwpush.vcxproj +rename to wolfmqtt_examples/firmware/fwpush.vcxproj +diff --git a/examples/include.am b/wolfmqtt_examples/include.am +similarity index 100% +rename from examples/include.am +rename to wolfmqtt_examples/include.am +diff --git a/examples/mqttclient/mqttclient.c b/wolfmqtt_examples/mqttclient/mqttclient.c +similarity index 99% +rename from examples/mqttclient/mqttclient.c +rename to wolfmqtt_examples/mqttclient/mqttclient.c +index f0a7356..9f50e22 100644 +--- a/examples/mqttclient/mqttclient.c ++++ b/wolfmqtt_examples/mqttclient/mqttclient.c +@@ -27,7 +27,7 @@ + #include "wolfmqtt/mqtt_client.h" + + #include "mqttclient.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttnet.h" + + /* Locals */ + static int mStopRead = 0; +diff --git a/examples/mqttclient/mqttclient.h b/wolfmqtt_examples/mqttclient/mqttclient.h +similarity index 95% +rename from examples/mqttclient/mqttclient.h +rename to wolfmqtt_examples/mqttclient/mqttclient.h +index 0bdf289..e224af9 100644 +--- a/examples/mqttclient/mqttclient.h ++++ b/wolfmqtt_examples/mqttclient/mqttclient.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_MQTTCLIENT_H + #define WOLFMQTT_MQTTCLIENT_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* Exposed functions */ +diff --git a/examples/mqttclient/mqttclient.vcxproj b/wolfmqtt_examples/mqttclient/mqttclient.vcxproj +similarity index 100% +rename from examples/mqttclient/mqttclient.vcxproj +rename to wolfmqtt_examples/mqttclient/mqttclient.vcxproj +diff --git a/examples/mqttexample.c b/wolfmqtt_examples/mqttexample.c +similarity index 99% +rename from examples/mqttexample.c +rename to wolfmqtt_examples/mqttexample.c +index c39d000..42e8035 100644 +--- a/examples/mqttexample.c ++++ b/wolfmqtt_examples/mqttexample.c +@@ -25,8 +25,8 @@ + #endif + + #include "wolfmqtt/mqtt_client.h" +-#include "examples/mqttexample.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" + + + /* locals */ +diff --git a/examples/mqttexample.h b/wolfmqtt_examples/mqttexample.h +similarity index 100% +rename from examples/mqttexample.h +rename to wolfmqtt_examples/mqttexample.h +diff --git a/examples/mqttnet.c b/wolfmqtt_examples/mqttnet.c +similarity index 99% +rename from examples/mqttnet.c +rename to wolfmqtt_examples/mqttnet.c +index 98476a4..f53a8ea 100644 +--- a/examples/mqttnet.c ++++ b/wolfmqtt_examples/mqttnet.c +@@ -25,8 +25,8 @@ + #endif + + #include "wolfmqtt/mqtt_client.h" +-#include "examples/mqttnet.h" +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" + + /* FreeRTOS TCP */ + #ifdef FREERTOS_TCP +diff --git a/examples/mqttnet.h b/wolfmqtt_examples/mqttnet.h +similarity index 97% +rename from examples/mqttnet.h +rename to wolfmqtt_examples/mqttnet.h +index 2657052..690ddd3 100644 +--- a/examples/mqttnet.h ++++ b/wolfmqtt_examples/mqttnet.h +@@ -26,7 +26,7 @@ + extern "C" { + #endif + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + /* Default MQTT host broker to use, when none is specified in the examples */ + #ifndef DEFAULT_MQTT_HOST +diff --git a/examples/mqttsimple/mqttsimple.c b/wolfmqtt_examples/mqttsimple/mqttsimple.c +similarity index 100% +rename from examples/mqttsimple/mqttsimple.c +rename to wolfmqtt_examples/mqttsimple/mqttsimple.c +diff --git a/examples/mqttsimple/mqttsimple.h b/wolfmqtt_examples/mqttsimple/mqttsimple.h +similarity index 100% +rename from examples/mqttsimple/mqttsimple.h +rename to wolfmqtt_examples/mqttsimple/mqttsimple.h +diff --git a/examples/mqttuart.c b/wolfmqtt_examples/mqttuart.c +similarity index 96% +rename from examples/mqttuart.c +rename to wolfmqtt_examples/mqttuart.c +index bec2f27..303c022 100644 +--- a/examples/mqttuart.c ++++ b/wolfmqtt_examples/mqttuart.c +@@ -25,13 +25,13 @@ + #endif + + #include "wolfmqtt/mqtt_client.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttnet.h" + + + /* TODO: Add includes for UART HW */ + + /* Include the example code */ +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* this code is a template for using UART for communication */ +diff --git a/examples/multithread/multithread.c b/wolfmqtt_examples/multithread/multithread.c +similarity index 99% +rename from examples/multithread/multithread.c +rename to wolfmqtt_examples/multithread/multithread.c +index f2bb6d0..df84df4 100755 +--- a/examples/multithread/multithread.c ++++ b/wolfmqtt_examples/multithread/multithread.c +@@ -27,8 +27,8 @@ + #include "wolfmqtt/mqtt_client.h" + + #include "multithread.h" +-#include "examples/mqttnet.h" +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" + + #include + +diff --git a/examples/multithread/multithread.h b/wolfmqtt_examples/multithread/multithread.h +similarity index 95% +rename from examples/multithread/multithread.h +rename to wolfmqtt_examples/multithread/multithread.h +index 4da2d65..16b8138 100644 +--- a/examples/multithread/multithread.h ++++ b/wolfmqtt_examples/multithread/multithread.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_MULTITHREAD_H + #define WOLFMQTT_MULTITHREAD_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* Exposed functions */ +diff --git a/examples/multithread/multithread.vcxproj b/wolfmqtt_examples/multithread/multithread.vcxproj +similarity index 100% +rename from examples/multithread/multithread.vcxproj +rename to wolfmqtt_examples/multithread/multithread.vcxproj +diff --git a/examples/nbclient/nbclient.c b/wolfmqtt_examples/nbclient/nbclient.c +similarity index 99% +rename from examples/nbclient/nbclient.c +rename to wolfmqtt_examples/nbclient/nbclient.c +index 5558e8b..b3fff62 100644 +--- a/examples/nbclient/nbclient.c ++++ b/wolfmqtt_examples/nbclient/nbclient.c +@@ -29,7 +29,7 @@ + + #ifdef WOLFMQTT_NONBLOCK + #include "nbclient.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttnet.h" + + /* Locals */ + static int mStopRead = 0; +diff --git a/examples/nbclient/nbclient.h b/wolfmqtt_examples/nbclient/nbclient.h +similarity index 95% +rename from examples/nbclient/nbclient.h +rename to wolfmqtt_examples/nbclient/nbclient.h +index df4dd96..9cb0384 100644 +--- a/examples/nbclient/nbclient.h ++++ b/wolfmqtt_examples/nbclient/nbclient.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_NBCLIENT_H + #define WOLFMQTT_NBCLIENT_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* Exposed functions */ +diff --git a/examples/nbclient/nbclient.vcxproj b/wolfmqtt_examples/nbclient/nbclient.vcxproj +similarity index 100% +rename from examples/nbclient/nbclient.vcxproj +rename to wolfmqtt_examples/nbclient/nbclient.vcxproj +diff --git a/examples/sn-client/sn-client.c b/wolfmqtt_examples/sn-client/sn-client.c +similarity index 99% +rename from examples/sn-client/sn-client.c +rename to wolfmqtt_examples/sn-client/sn-client.c +index cbc7438..8dffc14 100644 +--- a/examples/sn-client/sn-client.c ++++ b/wolfmqtt_examples/sn-client/sn-client.c +@@ -27,7 +27,7 @@ + #include "wolfmqtt/mqtt_client.h" + + #include "sn-client.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttnet.h" + + /* Locals */ + static int mStopRead = 0; +diff --git a/examples/sn-client/sn-client.h b/wolfmqtt_examples/sn-client/sn-client.h +similarity index 95% +rename from examples/sn-client/sn-client.h +rename to wolfmqtt_examples/sn-client/sn-client.h +index 351c17e..5bd0665 100644 +--- a/examples/sn-client/sn-client.h ++++ b/wolfmqtt_examples/sn-client/sn-client.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_SNCLIENT_H + #define WOLFMQTT_SNCLIENT_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* Exposed functions */ +diff --git a/examples/sn-client/sn-client.vcxproj b/wolfmqtt_examples/sn-client/sn-client.vcxproj +similarity index 100% +rename from examples/sn-client/sn-client.vcxproj +rename to wolfmqtt_examples/sn-client/sn-client.vcxproj +diff --git a/examples/wiot/wiot.c b/wolfmqtt_examples/wiot/wiot.c +similarity index 99% +rename from examples/wiot/wiot.c +rename to wolfmqtt_examples/wiot/wiot.c +index 864b35d..5ee9c8e 100644 +--- a/examples/wiot/wiot.c ++++ b/wolfmqtt_examples/wiot/wiot.c +@@ -33,8 +33,8 @@ + #include "wolfmqtt/mqtt_client.h" + + #include "wiot.h" +-#include "examples/mqttexample.h" +-#include "examples/mqttnet.h" ++#include "wolfmqtt_examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttnet.h" + + /* Locals */ + static int mStopRead = 0; +diff --git a/examples/wiot/wiot.h b/wolfmqtt_examples/wiot/wiot.h +similarity index 95% +rename from examples/wiot/wiot.h +rename to wolfmqtt_examples/wiot/wiot.h +index fc3933f..41aeea0 100755 +--- a/examples/wiot/wiot.h ++++ b/wolfmqtt_examples/wiot/wiot.h +@@ -22,7 +22,7 @@ + #ifndef WOLFMQTT_WIOT_H + #define WOLFMQTT_WIOT_H + +-#include "examples/mqttexample.h" ++#include "wolfmqtt_examples/mqttexample.h" + + + /* Exposed functions */ +diff --git a/examples/wiot/wiot.vcxproj b/wolfmqtt_examples/wiot/wiot.vcxproj +similarity index 100% +rename from examples/wiot/wiot.vcxproj +rename to wolfmqtt_examples/wiot/wiot.vcxproj +-- +2.25.1 + diff --git a/pkg/wolfmqtt/patches/0002-adapt-network-code-to-RIOT.patch b/pkg/wolfmqtt/patches/0002-adapt-network-code-to-RIOT.patch new file mode 100644 index 000000000000..d641bf479177 --- /dev/null +++ b/pkg/wolfmqtt/patches/0002-adapt-network-code-to-RIOT.patch @@ -0,0 +1,492 @@ +From 7a30c998761a4d8ad42ddac3aeed7352c1ff6674 Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Fri, 29 Jan 2021 02:19:42 +0100 +Subject: [PATCH] adapt network code to RIOT + +--- + wolfmqtt/mqtt_types.h | 2 +- + wolfmqtt_examples/mqttnet.c | 343 +++++++++++++++++++++++++++--------- + 2 files changed, 262 insertions(+), 83 deletions(-) + +diff --git a/wolfmqtt/mqtt_types.h b/wolfmqtt/mqtt_types.h +index 8d70c2b..d822aca 100644 +--- a/wolfmqtt/mqtt_types.h ++++ b/wolfmqtt/mqtt_types.h +@@ -91,7 +91,7 @@ + #include + typedef dispatch_semaphore_t wm_Sem; + +- #elif defined(__FreeBSD__) || defined(__linux__) ++ #elif defined(__FreeBSD__) || defined(__linux__) || defined(RIOT_OS) + /* Posix Style Semaphore */ + #define WOLFMQTT_POSIX_SEMAPHORES + #include +diff --git a/wolfmqtt_examples/mqttnet.c b/wolfmqtt_examples/mqttnet.c +index f53a8ea..dbbbf93 100644 +--- a/wolfmqtt_examples/mqttnet.c ++++ b/wolfmqtt_examples/mqttnet.c +@@ -96,6 +96,32 @@ + #error wolfMQTT must be built with WOLFMQTT_NONBLOCK defined for Harmony + #endif + ++/* RIOT OS */ ++#elif defined(RIOT_OS) ++ #include "xtimer.h" ++ ++ #include ++ #include ++ ++ #include ++ #include ++ #include ++ ++ #include "net/ipv4/addr.h" ++ #include "net/ipv6/addr.h" ++ #include "net/sock/dns.h" ++ #include "net/sock/ip.h" ++ #include "net/sock/tcp.h" ++ #include "net/sock/udp.h" ++ ++ #if WOLFMQTT_USE_HOSTNAME ++ #include ++ #endif ++ ++ #include ++ #include ++ #include ++ + /* Linux */ + #else + #include +@@ -141,8 +167,15 @@ + #ifndef SOCK_CLOSE + #define SOCK_CLOSE close + #endif +-#ifndef SOCK_ADDR_IN +- #define SOCK_ADDR_IN struct sockaddr_in ++#ifdef MODULE_IPV4_ADDR ++ #ifndef SOCK_ADDR_IN ++ #define SOCK_ADDR_IN struct sockaddr_in ++ #endif ++#endif ++#ifdef MODULE_IPV6_ADDR ++ #ifndef SOCK_ADDR_IN6 ++ #define SOCK_ADDR_IN6 struct sockaddr_in6 ++ #endif + #endif + #ifdef SOCK_ADDRINFO + #define SOCK_ADDRINFO struct addrinfo +@@ -166,7 +199,12 @@ typedef struct MulticastContext { + typedef struct _SocketContext { + SOCKET_T fd; + NB_Stat stat; ++#ifdef MODULE_IPV4_ADDR + SOCK_ADDR_IN addr; ++#endif ++#ifdef MODULE_IPV6_ADDR ++ SOCK_ADDR_IN6 addr6; ++#endif + #ifdef MICROCHIP_MPLAB_HARMONY + word32 bytes; + #endif +@@ -560,8 +598,10 @@ static int NetConnect(void *context, const char* host, word16 port, + int type = SOCK_STREAM; + int rc = -1; + SOERROR_T so_error = 0; +- struct addrinfo *result = NULL; +- struct addrinfo hints; ++ #if WOLFMQTT_USE_HOSTNAME ++ struct addrinfo *result = NULL; ++ struct addrinfo hints; ++ #endif + MQTTCtx* mqttCtx = sock->mqttCtx; + + /* Get address information for host and locate IPv4 */ +@@ -571,50 +611,92 @@ static int NetConnect(void *context, const char* host, word16 port, + PRINTF("NetConnect: Host %s, Port %u, Timeout %d ms, Use TLS %d", + host, port, timeout_ms, mqttCtx->use_tls); + +- XMEMSET(&hints, 0, sizeof(hints)); +- hints.ai_family = AF_INET; +- hints.ai_socktype = SOCK_STREAM; +- hints.ai_protocol = IPPROTO_TCP; ++ #if WOLFMQTT_USE_HOSTNAME ++ XMEMSET(&hints, 0, sizeof(hints)); ++ hints.ai_socktype = SOCK_STREAM; ++ hints.ai_protocol = IPPROTO_TCP; + +- XMEMSET(&sock->addr, 0, sizeof(sock->addr)); +- sock->addr.sin_family = AF_INET; ++ #ifdef MODULE_IPV6_ADDR ++ hints.ai_family = AF_INET6; ++ #else ++ hints.ai_family = AF_INET; ++ #endif ++ #endif + +- rc = getaddrinfo(host, NULL, &hints, &result); +- if (rc == 0) { +- struct addrinfo* result_i = result; ++ #ifdef MODULE_IPV6_ADDR ++ XMEMSET(&sock->addr6, 0, sizeof(sock->addr6)); ++ #endif ++ #ifdef MODULE_IPV4_ADDR ++ XMEMSET(&sock->addr, 0, sizeof(sock->addr)); ++ #endif + +- if (! result) { +- rc = -1; +- goto exit; +- } ++ #ifdef MODULE_IPV6_ADDR ++ sock->addr6.sin6_port = htons(port); ++ sock->addr6.sin6_family = AF_INET6; ++ #else ++ sock->addr.sin_port = htons(port); ++ sock->addr.sin_family = AF_INET; ++ #endif + +- /* prefer ip4 addresses */ +- while (result_i) { +- if (result_i->ai_family == AF_INET) +- break; +- result_i = result_i->ai_next; +- } ++ #if WOLFMQTT_USE_HOSTNAME ++ rc = getaddrinfo(host, NULL, &hints, &result); ++ if (rc == 0) { ++ struct addrinfo* result_i = result; + +- if (result_i) { +- sock->addr.sin_port = htons(port); +- sock->addr.sin_family = AF_INET; +- sock->addr.sin_addr = +- ((SOCK_ADDR_IN*)(result_i->ai_addr))->sin_addr; +- } +- else { +- rc = -1; +- } ++ if (! result) { ++ rc = -1; ++ goto exit; ++ } + +- freeaddrinfo(result); +- } +- if (rc != 0) +- goto exit; ++ while (result_i) { ++ if (result_i->ai_family == hints.ai_family) ++ break; ++ result_i = result_i->ai_next; ++ } ++ ++ if (result_i) { ++ #ifdef MODULE_IPV6_ADDR ++ sock->addr6.sin6_addr = ++ ((SOCK_ADDR_IN6*)(result_i->ai_addr))->sin6_addr; ++ #else ++ sock->addr.sin_addr = ++ ((SOCK_ADDR_IN*)(result_i->ai_addr))->sin_addr; ++ #endif ++ } ++ else { ++ rc = -1; ++ } ++ ++ freeaddrinfo(result); ++ } ++ if (rc != 0) ++ goto exit; ++ #else ++ #if MODULE_IPV6_ADDR ++ if (inet_pton(AF_INET6, host, &sock->addr6.sin6_addr) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", host); ++ rc = -1; ++ goto exit; ++ } ++ #else ++ if (inet_pton(AF_INET, host, &sock->addr.sin_addr) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", host); ++ rc = -1; ++ goto exit; ++ } ++ #endif ++ #endif /* WOLFMQTT_USE_HOSTNAME */ + + /* Default to error */ + rc = -1; + + /* Create socket */ +- sock->fd = SOCK_OPEN(sock->addr.sin_family, type, 0); ++ #ifdef MODULE_IPV6_ADDR ++ sock->fd = SOCK_OPEN(sock->addr6.sin6_family, type, 0); ++ #else ++ sock->fd = SOCK_OPEN(sock->addr.sin_family, type, 0); ++ #endif ++ + if (sock->fd == SOCKET_INVALID) + goto exit; + +@@ -643,7 +725,11 @@ static int NetConnect(void *context, const char* host, word16 port, + #endif + + /* Start connect */ +- rc = SOCK_CONNECT(sock->fd, (struct sockaddr*)&sock->addr, sizeof(sock->addr)); ++ #ifdef MODULE_IPV6_ADDR ++ rc = SOCK_CONNECT(sock->fd, (struct sockaddr*)&sock->addr6, sizeof(sock->addr6)); ++ #else ++ rc = SOCK_CONNECT(sock->fd, (struct sockaddr*)&sock->addr, sizeof(sock->addr)); ++ #endif + if (rc < 0) { + /* Check for error */ + socklen_t len = sizeof(so_error); +@@ -688,60 +774,103 @@ static int SN_NetConnect(void *context, const char* host, word16 port, + { + SocketContext *sock = (SocketContext*)context; + int type = SOCK_DGRAM; +- int rc; ++ int rc = 0; + SOERROR_T so_error = 0; +- struct addrinfo *result = NULL; +- struct addrinfo hints; ++ #if WOLFMQTT_USE_HOSTNAME ++ struct addrinfo *result = NULL; ++ struct addrinfo hints; ++ #endif + MQTTCtx* mqttCtx = sock->mqttCtx; + + PRINTF("NetConnect: Host %s, Port %u, Timeout %d ms, Use TLS %d\n", + host, port, timeout_ms, mqttCtx->use_tls); + +- /* Get address information for host and locate IPv4 */ +- XMEMSET(&hints, 0, sizeof(struct addrinfo)); +- hints.ai_family = AF_INET; +- hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */ ++ #if WOLFMQTT_USE_HOSTNAME ++ XMEMSET(&hints, 0, sizeof(hints)); ++ hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */ ++ #ifdef MODULE_IPV6_ADDR ++ hints.ai_family = AF_INET6; ++ #else ++ hints.ai_family = AF_INET; ++ #endif ++ #endif + +- XMEMSET(&sock->addr, 0, sizeof(sock->addr)); +- sock->addr.sin_family = AF_INET; ++ #ifdef MODULE_IPV6_ADDR ++ XMEMSET(&sock->addr6, 0, sizeof(sock->addr6)); ++ #endif ++ #ifdef MODULE_IPV4_ADDR ++ XMEMSET(&sock->addr, 0, sizeof(sock->addr)); ++ #endif + +- rc = getaddrinfo(host, NULL, &hints, &result); +- if (rc == 0) { +- struct addrinfo* result_i = result; ++ #ifdef MODULE_IPV6_ADDR ++ sock->addr6.sin6_port = htons(port); ++ sock->addr6.sin6_family = AF_INET6; ++ #else ++ sock->addr.sin_port = htons(port); ++ sock->addr.sin_family = AF_INET; ++ #endif + +- if (! result) { +- rc = -1; +- goto exit; +- } ++ #if WOLFMQTT_USE_HOSTNAME ++ rc = getaddrinfo(host, NULL, &hints, &result); ++ if (rc == 0) { ++ struct addrinfo* result_i = result; + +- /* prefer ip4 addresses */ +- while (result_i) { +- if (result_i->ai_family == AF_INET) +- break; +- result_i = result_i->ai_next; +- } ++ if (! result) { ++ rc = -1; ++ goto exit; ++ } + +- if (result_i) { +- sock->addr.sin_port = htons(port); +- sock->addr.sin_family = AF_INET; +- sock->addr.sin_addr = +- ((SOCK_ADDR_IN*)(result_i->ai_addr))->sin_addr; +- } +- else { +- rc = -1; ++ while (result_i) { ++ if (result_i->ai_family == hints.ai_family) ++ break; ++ result_i = result_i->ai_next; ++ } ++ ++ if (result_i) { ++ #ifdef MODULE_IPV6_ADDR ++ sock->addr6.sin6_addr = ++ ((SOCK_ADDR_IN6*)(result_i->ai_addr))->sin6_addr; ++ #else ++ sock->addr.sin_addr = ++ ((SOCK_ADDR_IN*)(result_i->ai_addr))->sin_addr; ++ #endif ++ } ++ else { ++ rc = -1; ++ } ++ ++ freeaddrinfo(result); + } ++ if (rc != 0) ++ goto exit; ++ #else ++ #if MODULE_IPV6_ADDR ++ if (inet_pton(AF_INET6, host, &sock->addr6.sin6_addr) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", host); ++ rc = -1; ++ goto exit; ++ } ++ #else ++ if (inet_pton(AF_INET, host, &sock->addr.sin_addr) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", host); ++ rc = -1; ++ goto exit; ++ } ++ #endif ++ #endif /* WOLFMQTT_USE_HOSTNAME */ + +- freeaddrinfo(result); +- } +- if (rc != 0) +- goto exit; ++ /* Default to success */ ++ rc = 0; + +- if (rc == 0) { +- /* Create the socket */ ++ /* Create socket */ ++ #ifdef MODULE_IPV6_ADDR ++ sock->fd = SOCK_OPEN(sock->addr6.sin6_family, type, 0); ++ #else + sock->fd = SOCK_OPEN(sock->addr.sin_family, type, 0); +- if (sock->fd == SOCKET_INVALID) { +- rc = -1; +- } ++ #endif ++ ++ if (sock->fd == SOCKET_INVALID) { ++ rc = -1; + } + + if (rc == 0) +@@ -759,7 +888,11 @@ static int SN_NetConnect(void *context, const char* host, word16 port, + #endif /* !WOLFMQTT_NO_TIMEOUT */ + + /* Start connect */ +- rc = SOCK_CONNECT(sock->fd, (struct sockaddr*)&sock->addr, sizeof(sock->addr)); ++ #ifdef MODULE_IPV6_ADDR ++ rc = SOCK_CONNECT(sock->fd, (struct sockaddr*)&sock->addr6, sizeof(sock->addr6)); ++ #else ++ rc = SOCK_CONNECT(sock->fd, (struct sockaddr*)&sock->addr, sizeof(sock->addr)); ++ #endif + } + + exit: +@@ -895,7 +1028,7 @@ static int NetRead_ex(void *context, byte* buf, int buf_len, + } + /* Check if rx or error */ + #ifdef WOLFMQTT_ENABLE_STDIN_CAP +- else if ((!mqttCtx->test_mode && FD_ISSET(STDIN, &recvfds)) ++ else if ((!mqttCtx->test_mode && FD_ISSET(STDIN, &recvfds)) + #ifdef WOLFMQTT_MULTITHREAD + || FD_ISSET(sock->pfd[0], &recvfds) + #endif +@@ -903,9 +1036,11 @@ static int NetRead_ex(void *context, byte* buf, int buf_len, + return MQTT_CODE_STDIN_WAKE; + } + #endif ++ + if (FD_ISSET(sock->fd, &errfds)) { +- rc = -1; +- break; ++ // Todo: find out reason why we can ignore this case ++ //rc = -1; ++ //break; + } + } + else { +@@ -1041,6 +1176,28 @@ int MqttClientNet_Init(MqttNet* net, MQTTCtx* mqttCtx) + } + #endif /* MICROCHIP_MPLAB_HARMONY */ + ++ /* wait until connection has been established */ ++ xtimer_sleep(10); ++ ++ #if WOLFMQTT_USE_HOSTNAME ++ /* setup dns server */ ++ #ifdef MODULE_IPV6_ADDR ++ if (inet_pton(AF_INET6, WOLFMQTT_DNS_SERVER_IPV6, sock_dns_server.addr.ipv6) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", WOLFMQTT_DNS_SERVER_IPV6); ++ return -1; ++ } ++ sock_dns_server.family = AF_INET6; ++ #else ++ if (inet_pton(AF_INET, WOLFMQTT_DNS_SERVER_IPV4, sock_dns_server.addr.ipv4) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", WOLFMQTT_DNS_SERVER_IPV4); ++ return -1; ++ } ++ sock_dns_server.family = AF_INET; ++ #endif ++ ++ sock_dns_server.port = SOCK_DNS_PORT; ++ #endif ++ + if (net) { + SocketContext* sockCtx; + +@@ -1059,7 +1216,7 @@ int MqttClientNet_Init(MqttNet* net, MQTTCtx* mqttCtx) + sockCtx->fd = SOCKET_INVALID; + sockCtx->stat = SOCK_BEGIN; + sockCtx->mqttCtx = mqttCtx; +- ++ + #if defined(WOLFMQTT_MULTITHREAD) && defined(WOLFMQTT_ENABLE_STDIN_CAP) + /* setup the pipe for waking select() */ + if (pipe(sockCtx->pfd) != 0) { +@@ -1075,6 +1232,28 @@ int MqttClientNet_Init(MqttNet* net, MQTTCtx* mqttCtx) + #ifdef WOLFMQTT_SN + int SN_ClientNet_Init(MqttNet* net, MQTTCtx* mqttCtx) + { ++ /* wait until connection has been established */ ++ xtimer_sleep(10); ++ ++ #if WOLFMQTT_USE_HOSTNAME ++ /* setup dns server */ ++ #ifdef MODULE_IPV6_ADDR ++ if (inet_pton(AF_INET6, WOLFMQTT_DNS_SERVER_IPV6, sock_dns_server.addr.ipv6) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", WOLFMQTT_DNS_SERVER_IPV6); ++ return -1; ++ } ++ sock_dns_server.family = AF_INET6; ++ #else ++ if (inet_pton(AF_INET, WOLFMQTT_DNS_SERVER_IPV4, sock_dns_server.addr.ipv4) != 1) { ++ PRINTF("Error: unable to parse destination address '%s'\n", WOLFMQTT_DNS_SERVER_IPV4); ++ return -1; ++ } ++ sock_dns_server.family = AF_INET; ++ #endif ++ ++ sock_dns_server.port = SOCK_DNS_PORT; ++ #endif ++ + if (net) { + SocketContext* sockCtx; + +-- +2.25.1 + diff --git a/pkg/wolfmqtt/patches/0003-fix-linking-error.patch b/pkg/wolfmqtt/patches/0003-fix-linking-error.patch new file mode 100644 index 000000000000..8cbb61a31663 --- /dev/null +++ b/pkg/wolfmqtt/patches/0003-fix-linking-error.patch @@ -0,0 +1,32 @@ +From a1bd0146deffaefad6f6d7de7aab0be51bfb6787 Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Sat, 6 Feb 2021 00:35:04 +0100 +Subject: [PATCH] fix linking error + +The example 'multithread' can't be linked because the function 'pipe' +was declared, but never defined. +--- + wolfmqtt_examples/mqttnet.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/wolfmqtt_examples/mqttnet.c b/wolfmqtt_examples/mqttnet.c +index dbbbf93..c6a5686 100644 +--- a/wolfmqtt_examples/mqttnet.c ++++ b/wolfmqtt_examples/mqttnet.c +@@ -558,6 +558,13 @@ static int NetDisconnect(void *context) + /* -------------------------------------------------------------------------- */ + #else + ++int pipe(SOCKET_T *sock) ++{ ++ // empty implementation to fix linking error ++ return 0; ++} ++ ++ + #ifndef WOLFMQTT_NO_TIMEOUT + static void setup_timeout(struct timeval* tv, int timeout_ms) + { +-- +2.25.1 + diff --git a/pkg/wolfmqtt/patches/0004-mqttclient-enable-overriding-of-TEST_MESSAGE.patch b/pkg/wolfmqtt/patches/0004-mqttclient-enable-overriding-of-TEST_MESSAGE.patch new file mode 100644 index 000000000000..026efa0d2084 --- /dev/null +++ b/pkg/wolfmqtt/patches/0004-mqttclient-enable-overriding-of-TEST_MESSAGE.patch @@ -0,0 +1,27 @@ +From acaf67f199df15a381755c38975e5c0bff6819f9 Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Thu, 21 Jan 2021 20:32:55 +0100 +Subject: [PATCH] mqttclient: enable overriding of TEST_MESSAGE + +--- + wolfmqtt_examples/mqttclient/mqttclient.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/wolfmqtt_examples/mqttclient/mqttclient.c b/wolfmqtt_examples/mqttclient/mqttclient.c +index 9f50e22..71b1a77 100644 +--- a/wolfmqtt_examples/mqttclient/mqttclient.c ++++ b/wolfmqtt_examples/mqttclient/mqttclient.c +@@ -37,7 +37,10 @@ static int mStopRead = 0; + /* Maximum size for network read/write callbacks. There is also a v5 define that + describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */ + #define MAX_BUFFER_SIZE 1024 ++ ++#ifndef TEST_MESSAGE + #define TEST_MESSAGE "test" ++#endif + + #ifdef WOLFMQTT_PROPERTY_CB + #define MAX_CLIENT_ID_LEN 64 +-- +2.25.1 + diff --git a/pkg/wolfmqtt/patches/0005-sn-client-enable-overriding-of-TEST_MESSAGE.patch b/pkg/wolfmqtt/patches/0005-sn-client-enable-overriding-of-TEST_MESSAGE.patch new file mode 100644 index 000000000000..415ef62e4424 --- /dev/null +++ b/pkg/wolfmqtt/patches/0005-sn-client-enable-overriding-of-TEST_MESSAGE.patch @@ -0,0 +1,46 @@ +From 9544a5912ec87d1d1909a9e2aac24a878088c0ef Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Wed, 27 Jan 2021 19:04:04 +0100 +Subject: [PATCH] sn-client: enable overriding of TEST_MESSAGE + +--- + wolfmqtt_examples/sn-client/sn-client.c | 16 +++++++++++----- + 1 file changed, 11 insertions(+), 5 deletions(-) + +diff --git a/wolfmqtt_examples/sn-client/sn-client.c b/wolfmqtt_examples/sn-client/sn-client.c +index 8dffc14..3076d3a 100644 +--- a/wolfmqtt_examples/sn-client/sn-client.c ++++ b/wolfmqtt_examples/sn-client/sn-client.c +@@ -36,9 +36,15 @@ static int mStopRead = 0; + + /* Configuration */ + /* Maximum size for network read/write callbacks. */ +-#define MAX_BUFFER_SIZE 1024 +-#define TEST_MESSAGE "test" +-#define SHORT_TOPIC_NAME "s1" ++#define MAX_BUFFER_SIZE 1024 ++ ++#ifndef SHORT_TOPIC_NAME ++#define SHORT_TOPIC_NAME "s1" ++#endif ++ ++#ifndef TEST_MESSAGE ++#define TEST_MESSAGE "test" ++#endif + + static int sn_message_cb(MqttClient *client, MqttMessage *msg, + byte msg_new, byte msg_done) +@@ -460,8 +466,8 @@ int main(int argc, char** argv) + mqttCtx.app_name = "sn-client"; + + /* Settings for MQTT-SN gateway */ +- mqttCtx.host = "localhost"; +- mqttCtx.port = 10000; ++ mqttCtx.host = DEFAULT_MQTT_HOST; ++ mqttCtx.port = DEFAULT_MQTT_PORT; + + /* parse arguments */ + rc = mqtt_parse_args(&mqttCtx, argc, argv); +-- +2.25.1 + diff --git a/pkg/wolfmqtt/patches/0006-nbclient-enable-overriding-of-TEST_MESSAGE.patch b/pkg/wolfmqtt/patches/0006-nbclient-enable-overriding-of-TEST_MESSAGE.patch new file mode 100644 index 000000000000..304e759e4212 --- /dev/null +++ b/pkg/wolfmqtt/patches/0006-nbclient-enable-overriding-of-TEST_MESSAGE.patch @@ -0,0 +1,27 @@ +From 4dc01ba70e5775b2f86faab07f2e07eccc9f897a Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Fri, 5 Feb 2021 17:13:38 +0100 +Subject: [PATCH] nbclient: enable overriding of TEST_MESSAGE + +--- + wolfmqtt_examples/nbclient/nbclient.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/wolfmqtt_examples/nbclient/nbclient.c b/wolfmqtt_examples/nbclient/nbclient.c +index b3fff62..d9f2875 100644 +--- a/wolfmqtt_examples/nbclient/nbclient.c ++++ b/wolfmqtt_examples/nbclient/nbclient.c +@@ -38,7 +38,10 @@ static int mStopRead = 0; + + /* Maximum size for network read/write callbacks. */ + #define MAX_BUFFER_SIZE 1024 ++ ++#ifndef TEST_MESSAGE + #define TEST_MESSAGE "test" ++#endif + + #ifdef WOLFMQTT_DISCONNECT_CB + /* callback indicates a network error occurred */ +-- +2.25.1 + diff --git a/pkg/wolfmqtt/patches/0007-multithread-enable-overriding-of-TEST_MESSAGE.patch b/pkg/wolfmqtt/patches/0007-multithread-enable-overriding-of-TEST_MESSAGE.patch new file mode 100644 index 000000000000..ad2cb0d915c0 --- /dev/null +++ b/pkg/wolfmqtt/patches/0007-multithread-enable-overriding-of-TEST_MESSAGE.patch @@ -0,0 +1,28 @@ +From a8c71af8064cec84d5ba11ed652371080c08bd41 Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Sat, 6 Feb 2021 00:01:55 +0100 +Subject: [PATCH] multithread: enable overriding of TEST_MESSAGE + +--- + wolfmqtt_examples/multithread/multithread.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/wolfmqtt_examples/multithread/multithread.c b/wolfmqtt_examples/multithread/multithread.c +index df84df4..02ee48c 100755 +--- a/wolfmqtt_examples/multithread/multithread.c ++++ b/wolfmqtt_examples/multithread/multithread.c +@@ -38,7 +38,11 @@ + /* Maximum size for network read/write callbacks. There is also a v5 define that + describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */ + #define MAX_BUFFER_SIZE 1024 ++ ++#ifndef TEST_MESSAGE + #define TEST_MESSAGE "test00" ++#endif ++ + /* Number of publish tasks. Each will send a unique message to the broker. */ + #define NUM_PUB_TASKS 10 + +-- +2.25.1 + diff --git a/pkg/wolfmqtt/patches/0008-aws-enable-overriding-of-AWSIOT_HOST.patch b/pkg/wolfmqtt/patches/0008-aws-enable-overriding-of-AWSIOT_HOST.patch new file mode 100644 index 000000000000..e3b46bdd32ba --- /dev/null +++ b/pkg/wolfmqtt/patches/0008-aws-enable-overriding-of-AWSIOT_HOST.patch @@ -0,0 +1,27 @@ +From b1daf9955d5c07c2232efb1a657230b2dbeb1133 Mon Sep 17 00:00:00 2001 +From: Hendrik van Essen +Date: Wed, 3 Mar 2021 21:21:21 +0100 +Subject: [PATCH] aws: enable overriding of AWSIOT_HOST + +--- + wolfmqtt_examples/aws/awsiot.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/wolfmqtt_examples/aws/awsiot.c b/wolfmqtt_examples/aws/awsiot.c +index 8e2f1bb..b532f27 100644 +--- a/wolfmqtt_examples/aws/awsiot.c ++++ b/wolfmqtt_examples/aws/awsiot.c +@@ -70,7 +70,9 @@ static int mStopRead = 0; + #define APP_FIRMWARE_VERSION LIBWOLFMQTT_VERSION_STRING + + #define MAX_BUFFER_SIZE 512 /* Maximum size for network read/write callbacks */ +-#define AWSIOT_HOST "a2dujmi05ideo2.iot.us-west-2.amazonaws.com" ++#ifndef AWSIOT_HOST ++ #define AWSIOT_HOST "a2dujmi05ideo2.iot.us-west-2.amazonaws.com" ++#endif + #define AWSIOT_DEVICE_ID "demoDevice" + #define AWSIOT_QOS MQTT_QOS_1 + #define AWSIOT_KEEP_ALIVE_SEC DEFAULT_KEEP_ALIVE_SEC +-- +2.25.1 + diff --git a/pkg/wolfssl/include/user_settings.h b/pkg/wolfssl/include/wolfssl/user_settings.h similarity index 97% rename from pkg/wolfssl/include/user_settings.h rename to pkg/wolfssl/include/wolfssl/user_settings.h index 88ffad1ad45f..b182dbb1b4e7 100644 --- a/pkg/wolfssl/include/user_settings.h +++ b/pkg/wolfssl/include/wolfssl/user_settings.h @@ -18,10 +18,14 @@ extern "C" { #define NO_DEV_RANDOM #define NO_FILESYSTEM #define NO_WOLFSSL_MEMORY -#define NO_MAIN_DRIVER #define NO_SIG_WRAPPER #define NO_OLD_RNGNAME +/* we need the main driver for applications from the wolfmqtt pkg */ +#ifndef MODULE_WOLFMQTT +#define NO_MAIN_DRIVER +#endif + /* Uncomment the next two lines to enable wolfSSL debug */ // #define DEBUG_WOLFSSL // #define WOLFSSL_LOG_PRINTF @@ -147,6 +151,9 @@ int strncasecmp(const char *s1, const char * s2, unsigned int sz); #define NO_ASN #endif +/* date check does not work on RIOT */ +#define NO_ASN_TIME + #ifndef MODULE_WOLFCRYPT_HMAC #define NO_HMAC #endif diff --git a/pkg/wolfssl/patches/0001-prefix-include-of-user_settings.h.patch b/pkg/wolfssl/patches/0001-prefix-include-of-user_settings.h.patch new file mode 100644 index 000000000000..f68d6d6ca0f4 --- /dev/null +++ b/pkg/wolfssl/patches/0001-prefix-include-of-user_settings.h.patch @@ -0,0 +1,25 @@ +From 3ff8ea604a21d306b38f38e74ed42e457b1d09d5 Mon Sep 17 00:00:00 2001 +From: HendrikVE +Date: Wed, 3 Mar 2021 22:13:26 +0100 +Subject: [PATCH] prefix include of user_settings.h + +--- + wolfssl/wolfcrypt/settings.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h +index 917a391bc..be94381a0 100644 +--- a/wolfssl/wolfcrypt/settings.h ++++ b/wolfssl/wolfcrypt/settings.h +@@ -218,7 +218,7 @@ + #include + + #ifdef WOLFSSL_USER_SETTINGS +- #include "user_settings.h" ++ #include "wolfssl/user_settings.h" + #elif defined(USE_HAL_DRIVER) && !defined(HAVE_CONFIG_H) + /* STM Configuration File (generated by CubeMX) */ + #include "wolfSSL.wolfSSL_conf.h" +-- +2.25.1 + diff --git a/sys/Makefile b/sys/Makefile index aaa35287477d..cf129b17b761 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -137,6 +137,9 @@ endif ifneq (,$(filter posix_inet,$(USEMODULE))) DIRS += posix/inet endif +ifneq (,$(filter posix_netdb,$(USEMODULE))) + DIRS += posix/netdb +endif ifneq (,$(filter posix_select,$(USEMODULE))) DIRS += posix/select endif diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 1af282755219..003dbcdee6f0 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -1118,4 +1118,8 @@ ifneq (,$(filter ecc_%,$(USEMODULE))) USEMODULE += ecc endif +ifneq (,$(filter posix_netdb,$(USEMODULE))) + USEMODULE += sock_dns +endif + include $(RIOTBASE)/sys/test_utils/Makefile.dep diff --git a/sys/include/net/sock/dns.h b/sys/include/net/sock/dns.h index f7d4d82261df..066f5acd5972 100644 --- a/sys/include/net/sock/dns.h +++ b/sys/include/net/sock/dns.h @@ -55,7 +55,7 @@ typedef struct { #define DNS_CLASS_IN (1) #define SOCK_DNS_PORT (53) -#define SOCK_DNS_RETRIES (2) +#define SOCK_DNS_RETRIES (5) #define SOCK_DNS_BUF_LEN (128) /* we're in embedded context. */ #define SOCK_DNS_MAX_NAME_LEN (SOCK_DNS_BUF_LEN - sizeof(sock_dns_hdr_t) - 4) diff --git a/sys/net/application_layer/dns/dns.c b/sys/net/application_layer/dns/dns.c index b9e80029c469..ecaa7d27507f 100644 --- a/sys/net/application_layer/dns/dns.c +++ b/sys/net/application_layer/dns/dns.c @@ -181,12 +181,25 @@ int sock_dns_query(const char *domain_name, void *addr_out, int family) return -ENOSPC; } - sock_udp_t sock_dns; + ssize_t res = 0; - ssize_t res = sock_udp_create(&sock_dns, NULL, &sock_dns_server, 0); - if (res) { - goto out; - } + #ifdef MODULE_POSIX_SOCKETS + #if defined(MODULE_IPV6_ADDR) + ssize_t fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + #elif defined(MODULE_IPV4_ADDR) + ssize_t fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + #endif + + if (fd < 0) { + goto out; + } + #else + sock_udp_t sock_dns; + res = sock_udp_create(&sock_dns, NULL, &sock_dns_server, 0); + if (res) { + goto out; + } + #endif /* MODULE_POSIX_SOCKETS */ uint16_t id = 0; /* random? */ for (int i = 0; i < SOCK_DNS_RETRIES; i++) { @@ -219,11 +232,38 @@ int sock_dns_query(const char *domain_name, void *addr_out, int family) bufpos += _put_short(bufpos, htons(DNS_CLASS_IN)); } - res = sock_udp_send(&sock_dns, buf, (bufpos-buf), NULL); + #ifdef MODULE_POSIX_SOCKETS + #if defined(MODULE_IPV6_ADDR) + struct sockaddr_in6 dst_addr = {0}; + dst_addr.sin6_family = AF_INET6; + dst_addr.sin6_port = htons(sock_dns_server.port); + memcpy(&dst_addr.sin6_addr, sock_dns_server.addr.ipv6, sizeof(struct in6_addr)); + + socklen_t src_len = sizeof(struct sockaddr_in6); + #elif defined(MODULE_IPV4_ADDR) + struct sockaddr_in dst_addr = {0}; + dst_addr.sin_family = AF_INET; + dst_addr.sin_port = htons(sock_dns_server.port); + memcpy(&dst_addr.sin_addr, sock_dns_server.addr.ipv4, sizeof(struct in_addr)); + + socklen_t src_len = sizeof(struct sockaddr_in); + #endif + + res = sendto(fd, buf, (bufpos-buf), 0, (struct sockaddr *)&dst_addr, sizeof(dst_addr)); + #else + res = sock_udp_send(&sock_dns, buf, (bufpos-buf), NULL); + #endif /* MODULE_POSIX_SOCKETS */ + if (res <= 0) { continue; } - res = sock_udp_recv(&sock_dns, dns_buf, sizeof(dns_buf), 1000000LU, NULL); + + #ifdef MODULE_POSIX_SOCKETS + res = recvfrom(fd, dns_buf, sizeof(dns_buf), 0, (struct sockaddr *)&dst_addr, &src_len); + #else + res = sock_udp_recv(&sock_dns, dns_buf, sizeof(dns_buf), 1000000LU, NULL); + #endif /* MODULE_POSIX_SOCKETS */ + if (res > 0) { if (res > (int)DNS_MIN_REPLY_LEN) { if ((res = _parse_dns_reply(dns_buf, res, addr_out, @@ -238,6 +278,11 @@ int sock_dns_query(const char *domain_name, void *addr_out, int family) } out: - sock_udp_close(&sock_dns); + #ifdef MODULE_POSIX_SOCKETS + close(fd); + #else + sock_udp_close(&sock_dns); + #endif /* MODULE_POSIX_SOCKETS */ + return res; } diff --git a/sys/posix/include/netdb.h b/sys/posix/include/netdb.h new file mode 100644 index 000000000000..144559d18c47 --- /dev/null +++ b/sys/posix/include/netdb.h @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2021 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup posix + * + * @{ + * @file + * @brief posix netdb implementation + * @author Simon Goldschmidt + * @author Hendrik van Essen + * @} + */ + +#ifndef NETDB_H +#define NETDB_H + +#ifdef LWIP_NETDB +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef LWIP_DNS_API_DECLARE_STRUCTS +struct hostent { + char *h_name; /* Official name of the host. */ + char **h_aliases; /* A pointer to an array of pointers to alternative host names, + terminated by a null pointer. */ + int h_addrtype; /* Address type. */ + int h_length; /* The length, in bytes, of the address. */ + char **h_addr_list; /* A pointer to an array of pointers to network addresses (in + network byte order) for the host, terminated by a null pointer. */ +#define h_addr h_addr_list[0] /* for backward compatibility */ +}; + +struct addrinfo { + int ai_flags; /* Input flags. */ + int ai_family; /* Address family of socket. */ + int ai_socktype; /* Socket type. */ + int ai_protocol; /* Protocol of socket. */ + socklen_t ai_addrlen; /* Length of socket address. */ + struct sockaddr *ai_addr; /* Socket address of socket. */ + char *ai_canonname; /* Canonical name of service location. */ + struct addrinfo *ai_next; /* Pointer to next in list. */ +}; +#endif /* LWIP_DNS_API_DECLARE_STRUCTS */ + +/** +* Returns an entry containing addresses of address family AF_INET +* for the host with name name. +* +* @param name the hostname to resolve +* @return an entry containing addresses of address family AF_INET +* for the host with name name +*/ +struct hostent* gethostbyname(const char *name); + +/** +* Thread-safe variant of gethostbyname: instead of using a static +* buffer, this function takes buffer and errno pointers as arguments +* and uses these for the result. +* +* @param name the hostname to resolve +* @param ret pre-allocated struct where to store the result +* @param buf pre-allocated buffer where to store additional data +* @param buflen the size of buf +* @param result pointer to a hostent pointer that is set to ret on success +* and set to zero on error +* @param h_errnop pointer to an int where to store errors (instead of modifying +* the global h_errno) +* @return 0 on success, non-zero on error, additional error information +* is stored in *h_errnop instead of h_errno to be thread-safe +*/ +int gethostbyname_r(const char *name, struct hostent *ret, char *buf, + size_t buflen, struct hostent **result, int *h_errnop); + +/** + * Frees one or more addrinfo structures returned by getaddrinfo(), along with + * any additional storage associated with those structures. If the ai_next field + * of the structure is not null, the entire list of structures is freed. + * + * @param ai struct addrinfo to free + */ +void freeaddrinfo(struct addrinfo *ai); + +/** + * Translates the name of a service location (for example, a host name) and/or + * a service name and returns a set of socket addresses and associated + * information to be used in creating a socket with which to address the + * specified service. + * Memory for the result is allocated internally and must be freed by calling + * freeaddrinfo()! + * + * @param nodename descriptive name or address string of the host + * (may be NULL -> local address) + * @param servname port number as string of NULL + * @param hints structure containing input values that set socktype and protocol + * @param res pointer to a pointer where to store the result (set to NULL on failure) + * @return 0 on success, non-zero on failure + */ +int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ +#endif /* NETDB_H */ diff --git a/sys/posix/include/sys/socket.h b/sys/posix/include/sys/socket.h index a95b59130590..8d41c03088f7 100644 --- a/sys/posix/include/sys/socket.h +++ b/sys/posix/include/sys/socket.h @@ -116,6 +116,20 @@ extern "C" { #define SO_TYPE (15) /**< Socket type. */ /** @} */ +/** + * @name Flag names + * @brief Flag parameter for recvfrom(), recvmsg(), sendmsg(), or sendto() + * @{ + */ +#define MSG_CTRUNC (0x01) /**< Control data truncated. */ +#define MSG_DONTROUTE (0x02) /**< Send without using routing tables. */ +#define MSG_EOR (0x04) /**< Terminates a record (if supported by the protocol). */ +#define MSG_OOB (0x08) /**< Out-of-band data. */ +#define MSG_PEEK (0x10) /**< Leave received data in queue. */ +#define MSG_TRUNC (0x20) /**< Normal data truncated. */ +#define MSG_WAITALL (0x40) /**< Attempt to fill the read buffer. */ +/** @} */ + typedef unsigned short sa_family_t; /**< address family type */ /** @@ -135,7 +149,6 @@ struct sockaddr_storage { uint8_t ss_data[SOCKADDR_MAX_DATA_LEN]; /**< Socket address */ }; - /** * @brief Accept a new connection on a socket * @details The accept() function shall extract the first connection on the @@ -332,7 +345,8 @@ int listen(int socket, int backlog); * @param[in] length Specifies the length in bytes of the buffer pointed * to by the buffer argument. * @param[in] flags Specifies the type of message reception. Support - * for values other than 0 is not implemented yet. + * for values other than 0 or MSG_PEEK is not + * implemented yet. * @param[out] address A null pointer, or points to a sockaddr structure * in which the sending address is to be stored. The * length and format of the address depend on the @@ -369,7 +383,7 @@ ssize_t recvfrom(int socket, void *__restrict buffer, size_t length, int flags, * @param[in] length Specifies the length in bytes of the buffer pointed to * by the buffer argument. * @param[in] flags Specifies the type of message reception. Support for - * values other than 0 is not implemented yet. + * values other than 0 or MSG_PEEK is not implemented yet. * * @return Upon successful completion, recv() shall return the length of the * message in bytes. If no messages are available to be received and diff --git a/sys/posix/netdb/Makefile b/sys/posix/netdb/Makefile new file mode 100644 index 000000000000..793c8b6919ae --- /dev/null +++ b/sys/posix/netdb/Makefile @@ -0,0 +1,3 @@ +MODULE = posix_netdb + +include $(RIOTBASE)/Makefile.base diff --git a/sys/posix/netdb/netdb.c b/sys/posix/netdb/netdb.c new file mode 100644 index 000000000000..1c62b5d5d7ad --- /dev/null +++ b/sys/posix/netdb/netdb.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2021 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup posix + * + * @{ + * @file + * @brief posix netdb implementation + * @author Hendrik van Essen + * @} + */ + +#include "netdb.h" + +struct hostent* gethostbyname(const char *name) { +#if LWIP_NETDB + return lwip_gethostbyname(name); +#else + #error "There is not implementation of gethostbyname available" +#endif +} + +int gethostbyname_r(const char *name, struct hostent *ret, char *buf, + size_t buflen, struct hostent **result, int *h_errnop) { +#if LWIP_NETDB + return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); +#else + #error "There is not implementation of gethostbyname_r available" +#endif +} + +void freeaddrinfo(struct addrinfo *ai) +{ +#if LWIP_NETDB + lwip_freeaddrinfo(ai); +#else + #error "There is not implementation of freeaddrinfo available" +#endif +} + +int getaddrinfo(const char *nodename, const char *servname, + const struct addrinfo *hints, struct addrinfo **res) +{ +#if LWIP_NETDB + return lwip_getaddrinfo(nodename, servname, hints, res); +#else + #error "There is not implementation of getaddrinfo available" +#endif +} diff --git a/sys/posix/select/posix_select.c b/sys/posix/select/posix_select.c index b8d56fa8dc9b..cd80c76c8702 100644 --- a/sys/posix/select/posix_select.c +++ b/sys/posix/select/posix_select.c @@ -84,11 +84,20 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, errno = EINVAL; return -1; } + for (int i = 0; i < nfds; i++) { + if ((readfds != NULL) && FD_ISSET(i, readfds)) { if (!posix_socket_is(i)) { - errno = EBADF; - return -1; + /* errno = EBADF; */ + /* return -1; */ + /* Todo: I get two fd here. The socket wanted is 3 in my case, + * but there is also a fd for 0. posix_socket_is(0) would + * return false and return -1, before checking fd 3 which + * can be used. Therefore continue for now so we can reach + * the correct fd. + */ + continue; } if (posix_socket_avail(i) > 0) { FD_SET(i, &ret_readfds); diff --git a/sys/posix/sockets/posix_sockets.c b/sys/posix/sockets/posix_sockets.c index 5901a7559ff7..b2432286b9e4 100644 --- a/sys/posix/sockets/posix_sockets.c +++ b/sys/posix/sockets/posix_sockets.c @@ -48,11 +48,15 @@ #include "thread_flags.h" #endif +#include "ringbuffer.h" + /* enough to create sockets both with socket() and accept() */ #define _ACTUAL_SOCKET_POOL_SIZE (SOCKET_POOL_SIZE + \ (SOCKET_POOL_SIZE * SOCKET_TCP_QUEUE_SIZE)) #define SOCKET_BLKSIZE (512) +#define PEEK_BUF_SIZE (32) + /** * @brief Unitfied connection type. */ @@ -82,6 +86,7 @@ typedef struct { int type; int protocol; bool bound; + ringbuffer_t peek_rb; #ifdef POSIX_SETSOCKOPT uint32_t recv_timeout; #endif @@ -319,6 +324,9 @@ static int socket_close(vfs_file_t *filp) bf_unset(_sock_pool_used, idx); } } + + free(s->peek_rb.buf); + mutex_unlock(&_socket_pool_mutex); s->sock = NULL; s->domain = AF_UNSPEC; @@ -405,11 +413,11 @@ static void _sock_set_cb(socket_t *socket) case SOCK_STREAM: /* is a TCP client socket */ if (socket->queue_array == NULL) { - sock_tcp_set_cb(&socket->sock.tcp.sock, callback.tcp, socket); + sock_tcp_set_cb(&socket->sock->tcp.sock, callback.tcp, socket); } /* is a TCP listening socket */ else { - sock_tcp_queue_set_cb(&socket->sock.tcp.queue, + sock_tcp_queue_set_cb(&socket->sock->tcp.queue, callback.tcp_queue, socket); } break; @@ -479,6 +487,16 @@ int socket(int domain, int type, int protocol) errno = EAFNOSUPPORT; res = -1; } + + char *buf_ptr = malloc(PEEK_BUF_SIZE * sizeof(char)); + if(buf_ptr == NULL) { + errno = ENOMEM; + res = -1; + } + else { + ringbuffer_init(&(s->peek_rb), buf_ptr, PEEK_BUF_SIZE); + } + mutex_unlock(&_socket_pool_mutex); return res; } @@ -926,7 +944,6 @@ static ssize_t socket_recvfrom(socket_t *s, void *restrict buffer, int res = 0; struct _sock_tl_ep ep = { .port = 0 }; - (void)flags; if (s == NULL) { return -ENOTSOCK; } @@ -941,6 +958,32 @@ static ssize_t socket_recvfrom(socket_t *s, void *restrict buffer, return res; } } +#ifdef MODULE_SOCK_UDP + bool peek_mode = (flags & MSG_PEEK) != 0; +#else + (void) flags; +#endif + + size_t to_read = length; + uint8_t *buf_index = buffer; + + while (to_read != 0 && !ringbuffer_empty(&(s->peek_rb))) { + *buf_index++ = ringbuffer_get_one(&(s->peek_rb)); + to_read--; + } + + if (to_read == 0) { + /* read all bytes from peek buffer */ + return length; + } + else { + /* only a part of the bytes was read from peek buffer, need to get + * the rest via socket calls + */ + res = length - to_read; + buffer = buf_index; + length = to_read; + } #ifdef POSIX_SETSOCKOPT const uint32_t recv_timeout = s->recv_timeout; @@ -963,8 +1006,11 @@ static ssize_t socket_recvfrom(socket_t *s, void *restrict buffer, #endif #ifdef MODULE_SOCK_UDP case SOCK_DGRAM: - res = sock_udp_recv(&s->sock->udp, buffer, length, recv_timeout, + res += sock_udp_recv(&s->sock->udp, buffer, length, recv_timeout, &ep); + if (peek_mode) { + ringbuffer_add(&(s->peek_rb), buffer, length); + } break; #endif default: @@ -1037,8 +1083,7 @@ static ssize_t socket_sendto(socket_t *s, const void *buffer, size_t length, return -1; } #endif - /* bind implicitly */ - if ((res = _bind_connect(s, NULL, 0)) < 0) { + if ((res = _bind_connect(s, address, address_len)) < 0) { return res; } }