From 565fba360354e2e3c544606fb1c4ade4e0306305 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Tue, 11 Nov 2025 15:35:46 +0200 Subject: [PATCH 1/3] libmei: account for driver disabled state Mei driver can be in the disabled state but auxiliary operations like FW status should work. Process with init flow if -ENODEV received on file open attempt and set status to DISABLED to prevent fd-related operations. Signed-off-by: Alexander Usyskin --- libmei.h | 1 + mei.c | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/libmei.h b/libmei.h index c81f8d3..c4e10ff 100644 --- a/libmei.h +++ b/libmei.h @@ -46,6 +46,7 @@ enum mei_cl_state { MEI_CL_STATE_NOT_PRESENT, /**< client with GUID is not present in the system */ MEI_CL_STATE_VERSION_MISMATCH, /**< client version not supported */ MEI_CL_STATE_ERROR, /**< client is in error state */ + MEI_CL_STATE_DISABLED, /**< client is in disabled state */ }; /*! log level diff --git a/mei.c b/mei.c index 3a500ce..39dca75 100644 --- a/mei.c +++ b/mei.c @@ -400,7 +400,7 @@ static inline int __mei_getkind(struct mei *me, const char *device, char *kind, #undef KIND_LEN } -static int mei_init_with_log_int(struct mei *me, const char *device, const uuid_le *guid, +static int __mei_init_with_log_int(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback log_callback, mei_log_callback2 log_callback2) { @@ -425,13 +425,18 @@ static int mei_init_with_log_int(struct mei *me, const char *device, const uuid_ rc = __mei_open(me, device); if (rc < 0) { - mei_err(me, "Cannot establish a handle to the Intel MEI driver %.20s [%d]:%s\n", + if (rc != -ENODEV) { + mei_err(me, "Cannot establish a handle to the Intel MEI driver %.20s [%d]:%s\n", + device, rc, strerror(-rc)); + return rc; + } + mei_msg(me, "Intel MEI driver %.20s returned [%d]:%s\n", device, rc, strerror(-rc)); - return rc; + me->state = MEI_CL_STATE_DISABLED; + } else { + mei_msg(me, "Opened %.20s: fd = %d\n", device, me->fd); + me->state = MEI_CL_STATE_INITIALIZED; } - - mei_msg(me, "Opened %.20s: fd = %d\n", device, me->fd); - memcpy(&me->guid, guid, sizeof(*guid)); me->prot_ver = req_protocol_version; me->device = strdup(device); @@ -440,8 +445,6 @@ static int mei_init_with_log_int(struct mei *me, const char *device, const uuid_ return -ENOMEM; } - me->state = MEI_CL_STATE_INITIALIZED; - return 0; } @@ -449,7 +452,7 @@ int mei_init_with_log(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback log_callback) { - return mei_init_with_log_int(me, device, guid, + return __mei_init_with_log_int(me, device, guid, req_protocol_version, verbose, log_callback, NULL); } @@ -457,7 +460,7 @@ int mei_init_with_log2(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback2 log_callback) { - return mei_init_with_log_int(me, device, guid, + return __mei_init_with_log_int(me, device, guid, req_protocol_version, verbose, NULL, log_callback); } @@ -610,6 +613,11 @@ static int __int_mei_connect(struct mei *me, uint8_t vtag) return -EINVAL; } + if (me->state == MEI_CL_STATE_DISABLED) { + mei_err(me, "client is disabled\n"); + return -EINVAL; + } + me->vtag = vtag; if (me->vtag) { memset(&data_v, 0, sizeof(data_v)); @@ -665,6 +673,11 @@ ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer, size_t len) if (!me || !buffer) return -EINVAL; + if (me->state != MEI_CL_STATE_CONNECTED) { + mei_err(me, "client is not connected [%d]\n", me->state); + return -EINVAL; + } + mei_msg(me, "call read length = %zu\n", len); rc = __mei_read(me, buffer, len); @@ -686,6 +699,11 @@ ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, size_t len) if (!me || !buffer) return -EINVAL; + if (me->state != MEI_CL_STATE_CONNECTED) { + mei_err(me, "client is not connected [%d]\n", me->state); + return -EINVAL; + } + mei_msg(me, "call write length = %zu\n", len); mei_dump_hex_buffer(me, buffer, len); From bd6e0605b7acdafda33327c82bdbd804bfd86f2a Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Wed, 12 Nov 2025 15:03:55 +0200 Subject: [PATCH 2/3] libmei: make kind null-terminated Replace newline added by kernel by null-terminator. Signed-off-by: Alexander Usyskin --- mei.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mei.c b/mei.c index 39dca75..d48245f 100644 --- a/mei.c +++ b/mei.c @@ -394,6 +394,7 @@ static inline int __mei_getkind(struct mei *me, const char *device, char *kind, } *kind_size = (size_t)len; memcpy(kind, buf, (size_t)len); + kind[len - 1] = '\0'; return 0; #undef KIND_FILENAME_LEN From f326266397d8d76882c718dfcaf750574ed79f03 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Tue, 11 Nov 2025 15:43:53 +0200 Subject: [PATCH 3/3] libmei: bump version to 1.8.0 Update CHANGELOG.md Signed-off-by: Alexander Usyskin --- CHANGELOG.md | 8 ++++++++ VERSION | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f01ee..acf40d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [1.8.0] + +### Changed + - account for driver disabled state + +### Fixed + - make kind null-terminated + ## [1.7.0] Note: ABI only binary incompatibility diff --git a/VERSION b/VERSION index bd8bf88..27f9cd3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.0 +1.8.0