mctpd: Ignore IIDs mismatch for the MCTP control responses
If there is a mismatch between the instance ID we will just
log the error but still accept the response. Also, deleting the
unused patches leftover from MCTPd bump to v2.1.
http://fusion2.corp.google.com/dacc4564-8a65-4188-8f45-a25a45586fae
Tested: Manually
Google-Bug-Id: 437126395
Change-Id: I0b9feac6df936ae4b02ebfaa21c7aca4061b9b71
Signed-off-by: Muhammad Usama <muhammadusama@google.com>
diff --git a/recipes-connectivity/mctp/mctp/0001-mctpd-Set-initial-route-MTU-to-minimum.patch b/recipes-connectivity/mctp/mctp/0001-mctpd-Set-initial-route-MTU-to-minimum.patch
deleted file mode 100644
index e940c35..0000000
--- a/recipes-connectivity/mctp/mctp/0001-mctpd-Set-initial-route-MTU-to-minimum.patch
+++ /dev/null
@@ -1,60 +0,0 @@
-From b1537cd5eb20c49bc0dc708f3e8d848e848db6cf Mon Sep 17 00:00:00 2001
-From: Matt Johnston <matt@codeconstruct.com.au>
-Date: Thu, 2 Mar 2023 14:26:12 +0800
-Subject: [PATCH] mctpd: Set initial route MTU to minimum
-
-Endpoint routes are now created with a MTU of 68 (the MCTP specified
-minimum).
-This allows better compatibility with devices that have a low
-initial MTU. Clients can increase the MTU with .SetMTU method if
-the device is known/configured to support a larger size.
-
-Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
-
-Patch Tracking Bug: b/294943849
-Upstream info / review: https://github.com/CodeConstruct/mctp/commit/b1537cd5eb20c49bc0dc708f3e8d848e848db6cf
-Upstream-Status: Submitted
-Justification: Improves compabtibility with devices that have small
-initial MTU
----
- src/mctpd.c | 10 +++++++++-
- 1 file changed, 9 insertions(+), 1 deletion(-)
-
-diff --git a/src/mctpd.c b/src/mctpd.c
-index b89b01b..b8b007e 100644
---- a/src/mctpd.c
-+++ b/src/mctpd.c
-@@ -51,6 +51,9 @@ static size_t MAX_PEER_SIZE = 1000000;
- static const uint8_t RQDI_REQ = 1<<7;
- static const uint8_t RQDI_RESP = 0x0;
-
-+// 64 byte Baseline transmission unit plus 4 byte MCTP header
-+static const uint32_t MCTP_MIN_MTU = 68;
-+
- struct dest_phys {
- int ifindex;
- uint8_t hwaddr[MAX_ADDR_LEN];
-@@ -96,7 +99,8 @@ struct peer {
- bool have_neigh;
- bool have_route;
-
-- // set by SetMTU method, 0 otherwise
-+ // Route MTU. Will be set to MCTP_MIN_MTU for newly created
-+ // peers. Can be modified with .SetMTU method
- uint32_t mtu;
-
- // malloc()ed list of supported message types, from Get Message Type
-@@ -1909,6 +1913,10 @@ static int setup_added_peer(peer *peer)
- {
- int rc;
-
-+ // Set minimum MTU by default for compatibility. Clients can increase
-+ // this with .SetMTU as needed
-+ peer->mtu = MCTP_MIN_MTU;
-+
- // add route before querying
- add_peer_route(peer);
-
---
-2.41.0.640.ga95def55d0-goog
-
diff --git a/recipes-connectivity/mctp/mctp/0001-mctpd-ignore-IIDs-validation-for-control-responses.patch b/recipes-connectivity/mctp/mctp/0001-mctpd-ignore-IIDs-validation-for-control-responses.patch
new file mode 100644
index 0000000..4505019
--- /dev/null
+++ b/recipes-connectivity/mctp/mctp/0001-mctpd-ignore-IIDs-validation-for-control-responses.patch
@@ -0,0 +1,30 @@
+From f98d14a81ce3ba3184f5e269f07e813f7677fdd7 Mon Sep 17 00:00:00 2001
+From: Muhammad Usama <muhammadusama@google.com>
+Date: Wed, 3 Sep 2025 21:26:35 +0000
+Subject: [PATCH] mctpd: ignore IIDs validation for control responses
+
+While validating the MCTP control responses, If IIDs does
+not match the IID of the request just log the error but
+still accept the response.
+
+Google-Bug-Id: 437126395
+Signed-off-by: Muhammad Usama <muhammadusama@google.com>
+---
+ src/mctpd.c | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/src/mctpd.c b/src/mctpd.c
+index 89991a4..a739b62 100644
+--- a/src/mctpd.c
++++ b/src/mctpd.c
+@@ -1180,7 +1180,6 @@ static int mctp_ctrl_validate_response(uint8_t *buf, size_t rsp_size,
+ warnx("%s: Wrong IID (0x%02x, expected 0x%02x)",
+ peer_cmd_prefix(peer, cmd),
+ rsp->ctrl_hdr.rq_dgram_inst & RQDI_IID_MASK, iid);
+- return -ENOMSG;
+ }
+
+ if (rsp->ctrl_hdr.command_code != cmd) {
+--
+2.51.0.355.g5224444f11-goog
+
diff --git a/recipes-connectivity/mctp/mctp/0002-mctpd-improve-handling-for-out-of-spec-Set-Endpoint.patch b/recipes-connectivity/mctp/mctp/0002-mctpd-improve-handling-for-out-of-spec-Set-Endpoint.patch
deleted file mode 100644
index 96f4fb8..0000000
--- a/recipes-connectivity/mctp/mctp/0002-mctpd-improve-handling-for-out-of-spec-Set-Endpoint.patch
+++ /dev/null
@@ -1,148 +0,0 @@
-From b81c31dc1c3f137c1c8c27deba5ecf11dfddde6b Mon Sep 17 00:00:00 2001
-From: Muhammad Usama <muhammadusama@google.com>
-Date: Thu, 26 Jun 2025 18:18:21 +0000
-Subject: [PATCH] mctpd: improve handling for out-of-spec Set Endpoint ID
- responses
-
-We may have endpoints reporting strange EID values in their set endpoint
-ID response, even when reporting that the assignement was accepted.
-Particularly, if the EID is in the invalid range, we will still attempt
-to add neighour and route entries for this invalid EID.
-
-We still want to accommodate valid IDs that were not the same as the one
-assigned, but ensure the EID is valid before processing.
-
-Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
-
-Patch Tracking Bug: b/294943849
-Upstream info / review: https://github.com/CodeConstruct/mctp/commit/2948041a02776e93b84510ed6d310bcce2f2c28e
-Upstream-Status: Submitted
-Justification: Improves stack
----
- CHANGELOG.md | 3 +++
- src/mctp-util.c | 5 +++++
- src/mctp-util.h | 4 ++++
- src/mctpd.c | 32 +++++++++++++++++++++++++++-----
- 4 files changed, 39 insertions(+), 5 deletions(-)
-
-diff --git a/CHANGELOG.md b/CHANGELOG.md
-index ac03224..b9a4de3 100644
---- a/CHANGELOG.md
-+++ b/CHANGELOG.md
-@@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 2. mctpd: Allow recovery of devices reporting a nil UUID for development
- 3. mctpd: Allow configuring .Connectivity as writable for development
- 4. mctpd: Add AssignEndpointStatic for static EID allocations
-+5. mctpd: Better handling of strange cases of Set Endpoint ID responses,Add commentMore actions
-+ where the reported endpoint EID may either be different from expected,
-+ or invalid
-
- ### Changed
-
-diff --git a/src/mctp-util.c b/src/mctp-util.c
-index 5226718..4964a7c 100644
---- a/src/mctp-util.c
-+++ b/src/mctp-util.c
-@@ -156,3 +156,8 @@ char* bytes_to_uuid(const uint8_t u[16])
- u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15]);
- return buf;
- }
-+
-+bool mctp_eid_is_valid_unicast(mctp_eid_t eid)
-+{
-+ return eid >= 8 && eid < 0xff;
-+}
-\ No newline at end of file
-diff --git a/src/mctp-util.h b/src/mctp-util.h
-index 3089299..7423965 100644
---- a/src/mctp-util.h
-+++ b/src/mctp-util.h
-@@ -1,5 +1,8 @@
-+#include <stdbool.h>
- #include <stdint.h>
-
-+#include "mctp.h"
-+
- void mctp_hexdump(const void *b, int len, const char *indent);
- void print_hex_addr(const uint8_t *data, size_t len);
- int write_hex_addr(const uint8_t *data, size_t len, char* dest, size_t dest_len);
-@@ -8,3 +11,4 @@ int parse_uint32(const char *str, uint32_t *out);
- int parse_int32(const char *str, int32_t *out);
- /* Returns a malloced pointer */
- char* bytes_to_uuid(const uint8_t u[16]);
-+bool mctp_eid_is_valid_unicast(mctp_eid_t eid);
-diff --git a/src/mctpd.c b/src/mctpd.c
-index 978f2b8..3cee0a3 100644
---- a/src/mctpd.c
-+++ b/src/mctpd.c
-@@ -1090,7 +1090,7 @@ static int endpoint_query_phys(ctx *ctx, const dest_phys *dest,
- }
-
- /* returns -ECONNREFUSED if the endpoint returns failure. */
--static int endpoint_send_set_endpoint_id(const peer *peer, mctp_eid_t *new_eid)
-+static int endpoint_send_set_endpoint_id(const peer *peer, mctp_eid_t *new_eidp)
- {
- struct sockaddr_mctp_ext addr;
- struct mctp_ctrl_cmd_set_eid req = {0};
-@@ -1100,6 +1100,7 @@ static int endpoint_send_set_endpoint_id(const peer *peer, mctp_eid_t *new_eid)
- size_t buf_size;
- uint8_t stat, alloc;
- const dest_phys *dest = &peer->phys;
-+ mctp_eid_t new_eid;
-
- rc = -1;
-
-@@ -1129,18 +1130,36 @@ static int endpoint_send_set_endpoint_id(const peer *peer, mctp_eid_t *new_eid)
- }
-
- stat = resp->status >> 4 & 0x3;
-+ new_eid = resp->eid_set;
-+
-+ // For both accepted and rejected cases, we learn the new EID of the
-+ // endpoint. If this is a valid ID, we are likely to be able to handle
-+ // this, as the caller may be able to change_peer_eid() to the
-+ // newly-reported eid
-+
- if (stat == 0x01) {
- // changed eid
-+ if (!mctp_eid_is_valid_unicast(new_eid)) {
-+ warnx("%s rejected assignment eid %d, and reported invalid eid %d",
-+ dest_phys_tostr(dest), peer->eid, new_eid);
-+ rc = -ECONNREFUSED;
-+ goto out;
-+ }
- } else if (stat == 0x00) {
-- if (resp->eid_set != peer->eid) {
-+ if (!mctp_eid_is_valid_unicast(new_eid)) {
-+ warnx("%s eid %d replied with invalid eid %d, but 'accepted'",
-+ dest_phys_tostr(dest), peer->eid, new_eid);
-+ rc = -ECONNREFUSED;
-+ goto out;
-+ } else if (new_eid != peer->eid) {
- warnx("%s eid %d replied with different eid %d, but 'accepted'",
-- dest_phys_tostr(dest), peer->eid, resp->eid_set);
-- }
-+ dest_phys_tostr(dest), peer->eid, new_eid);
-+ }
- } else {
- warnx("%s unexpected status 0x%02x",
- dest_phys_tostr(dest), resp->status);
- }
-- *new_eid = resp->eid_set;
-+ *new_eidp = new_eid;
-
- alloc = resp->status & 0x3;
- if (alloc != 0) {
-@@ -1300,6 +1319,9 @@ static int remove_peer(peer *peer)
- static int change_peer_eid(peer *peer, mctp_eid_t new_eid) {
- net_det *n = NULL;
-
-+ if (!mctp_eid_is_valid_unicast(new_eid))
-+ return -EINVAL;
-+
- n = lookup_net(peer->ctx, peer->net);
- if (!n) {
- warnx("BUG: %s: Bad net %d", __func__, peer->net);
---
-2.50.0.727.gbf7dc18ff4-goog
-
diff --git a/recipes-connectivity/mctp/mctp_%.bbappend b/recipes-connectivity/mctp/mctp_%.bbappend
index be69489..40ebe51 100644
--- a/recipes-connectivity/mctp/mctp_%.bbappend
+++ b/recipes-connectivity/mctp/mctp_%.bbappend
@@ -5,6 +5,7 @@
file://mctp-i2c.service \
file://init-mctp-i2c-endpoint.sh \
file://service-override.conf \
+ file://0001-mctpd-ignore-IIDs-validation-for-control-responses.patch \
"
RDEPENDS:${PN} += " \