Skip to content

Commit

Permalink
Subsys: mgmt: mcumgr: Fix mcumgr assertion error
Browse files Browse the repository at this point in the history
In the case of IPV6 not enabled, when NET_SOCKETS_PACKET is enabled,
the sizeof(struct sockarr) will change to 20, the value of
MCUMGR_TRANSPORT_NETBUF_MIN_USER_DATA_SIZE is 8, which is not able
to pass the compilation, so I change its default value to 20.

Fixes #82757

Signed-off-by: Hongquan Li <[email protected]>
  • Loading branch information
hongquan-prog authored and kartben committed Dec 16, 2024
1 parent cc620a3 commit bda1e76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions subsys/mgmt/mcumgr/transport/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ config MCUMGR_TRANSPORT_NETBUF_SIZE
config MCUMGR_TRANSPORT_NETBUF_MIN_USER_DATA_SIZE
int
default 24 if MCUMGR_TRANSPORT_UDP && NET_IPV6
default 20 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4 && NET_SOCKETS_PACKET
default 8 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4
default 8 if MCUMGR_TRANSPORT_BT
default 4
Expand Down
5 changes: 4 additions & 1 deletion subsys/mgmt/mcumgr/transport/src/smp_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ static int create_socket(enum proto_type proto, int *sock)
int tmp_sock;
int err;
struct sockaddr *addr;
socklen_t addr_len = 0;

#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4
struct sockaddr_in addr4;
Expand All @@ -175,6 +176,7 @@ static int create_socket(enum proto_type proto, int *sock)

#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4
if (proto == PROTOCOL_IPV4) {
addr_len = sizeof(struct sockaddr_in);
memset(&addr4, 0, sizeof(addr4));
addr4.sin_family = AF_INET;
addr4.sin_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT);
Expand All @@ -185,6 +187,7 @@ static int create_socket(enum proto_type proto, int *sock)

#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6
if (proto == PROTOCOL_IPV6) {
addr_len = sizeof(struct sockaddr_in6);
memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6;
addr6.sin6_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT);
Expand All @@ -203,7 +206,7 @@ static int create_socket(enum proto_type proto, int *sock)
return -err;
}

if (zsock_bind(tmp_sock, addr, sizeof(*addr)) < 0) {
if (zsock_bind(tmp_sock, addr, addr_len) < 0) {
err = errno;
LOG_ERR("Could not bind to receive socket (%s), err: %i",
smp_udp_proto_to_name(proto), err);
Expand Down

0 comments on commit bda1e76

Please sign in to comment.