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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion samples/net/mqtt_sn_publisher/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_MQTT_SN_LIB=y
CONFIG_MQTT_SN_TRANSPORT_UDP=y
CONFIG_MQTT_SN_LIB_BROADCAST_RADIUS=1
CONFIG_MQTT_SN_LIB_MAX_ADDR_SIZE=24
CONFIG_NET_SAMPLE_MQTT_SN_STATIC_GATEWAY=y
CONFIG_NET_SAMPLE_MQTT_SN_GATEWAY_ADDRESS="192.0.2.2:10000"
CONFIG_NET_SAMPLE_MQTT_SN_BROADCAST_ADDRESS="225.1.1.1:1883"
Expand Down
7 changes: 7 additions & 0 deletions subsys/net/lib/mqtt_sn/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ config MQTT_SN_LIB_MAX_GATEWAYS

config MQTT_SN_LIB_MAX_ADDR_SIZE
int "Maximum address size for the transport"
default 24 if NET_IPV6
default 8 if NET_IPV4
default 21
range 1 $(UINT8_MAX)
help
The MQTT_SN library stores addresses internally and thus
needs to know how long your addresses are. Set this to the maximum
length in bytes of the address data structure for your implemented transport.

A UDP transport requires at least 8 bytes on IPv4 and 24 bytes on
IPv6, corresponding to the sizes of the sockaddr_in and sockaddr_in6
structs. For an out-of-tree transport, you may need to adjust this
value.

config MQTT_SN_LIB_BROADCAST_RADIUS
int "Radius for broadcast messages"
default 1
Expand Down
6 changes: 6 additions & 0 deletions subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(net_mqtt_sn, CONFIG_MQTT_SN_LOG_LEVEL);

BUILD_ASSERT(CONFIG_MQTT_SN_LIB_MAX_ADDR_SIZE >= sizeof(struct net_sockaddr_in) ||
!IS_ENABLED(CONFIG_NET_IPV4));

BUILD_ASSERT(CONFIG_MQTT_SN_LIB_MAX_ADDR_SIZE >= sizeof(struct net_sockaddr_in6) ||
!IS_ENABLED(CONFIG_NET_IPV6));

static char *get_ip_str(const struct net_sockaddr *sa, char *s, size_t maxlen)
{
switch (sa->sa_family) {
Expand Down