Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsys:mgmt:mcumgr: Fix mcumgr assertion error #82786

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 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
Loading