diff --git a/CHANGELOG.md b/CHANGELOG.md index d549f4a..77f01ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [1.7.0] + +Note: ABI only binary incompatibility + struct mei size increased. + +### Added + - add initialization api with new logger callback + ## [1.6.4] ### Added diff --git a/VERSION b/VERSION index 9edc58b..bd8bf88 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.4 +1.7.0 diff --git a/libmei.h b/libmei.h index de9f3a7..c81f8d3 100644 --- a/libmei.h +++ b/libmei.h @@ -57,9 +57,14 @@ enum mei_log_level { }; /*! log callback function format + * @deprecated Since version 1.7.0 */ typedef void(*mei_log_callback)(bool is_error, const char* fmt, ...); +/*! log callback function format + */ +typedef void(*mei_log_callback2)(bool is_error, const char* msg); + /*! Structure to store connection data */ struct mei { @@ -74,7 +79,8 @@ struct mei { bool close_on_exit; /**< close handle on deinit */ char *device; /**< device name */ uint8_t vtag; /**< vtag used in communication */ - mei_log_callback log_callback; /**< Log callback */ + mei_log_callback log_callback; /**< Deprecated Log callback */ + mei_log_callback2 log_callback2; /**< Log callback */ }; /*! Default name of mei device @@ -131,6 +137,7 @@ int mei_init(struct mei *me, const char *device, const uuid_le *guid, /*! Initializes a mei connection with log callback * + * @deprecated Since version 1.7.0 * \param me A handle to the mei device. All subsequent calls to the lib's functions * must be with this handle * \param device device path, set MEI_DEFAULT_DEVICE to use default @@ -144,6 +151,21 @@ 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); +/*! Initializes a mei connection with log callback + * + * \param me A handle to the mei device. All subsequent calls to the lib's functions + * must be with this handle + * \param device device path, set MEI_DEFAULT_DEVICE to use default + * \param guid GUID of associated mei client + * \param req_protocol_version minimal required protocol version, 0 for any + * \param verbose print verbose output to a console + * \param log_callback pointer to function to run for log write, set NULL to use built-in function + * \return 0 if successful, otherwise error code + */ +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); + /*! Initializes a mei connection * * \param me A handle to the mei device. All subsequent calls to the lib's functions @@ -283,12 +305,21 @@ uint32_t mei_get_log_level(const struct mei *me); /*! Set log callback * + * @deprecated Since version 1.7.0 * \param me The mei handle * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code. */ int mei_set_log_callback(struct mei *me, mei_log_callback log_callback); +/*! Set log callback + * + * \param me The mei handle + * \param log_callback pointer to function to run for log write, set NULL to use built-in function + * \return 0 if successful, otherwise error code. + */ +int mei_set_log_callback2(struct mei *me, mei_log_callback2 log_callback); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/mei.c b/mei.c index 70192af..3a500ce 100644 --- a/mei.c +++ b/mei.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "libmei.h" @@ -45,22 +46,29 @@ static inline void __dump_buffer(const char *buf) #define __mei_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) #endif /* SYSLOG */ -#define mei_msg(_me, fmt, ARGS...) do { \ - if ((_me)->log_level >= MEI_LOG_LEVEL_VERBOSE) { \ - if ((_me)->log_callback) \ +#define LEGACY_CALLBACK_SET(h) ((h)->log_callback ? 1 : 0) +#define STANDARD_CALLBACK_SET(h) ((h)->log_callback2 ? 1 : 0) + +#define mei_msg(_me, fmt, ARGS...) do { \ + if ((_me)->log_level >= MEI_LOG_LEVEL_VERBOSE) { \ + if (LEGACY_CALLBACK_SET(_me)) \ (_me)->log_callback(false, fmt, ##ARGS); \ - else \ - __mei_msg(fmt, ##ARGS); \ - } \ + else if (STANDARD_CALLBACK_SET(_me)) \ + callback_print_helper((_me), false, fmt, ##ARGS); \ + else \ + __mei_msg(fmt, ##ARGS); \ + } \ } while (0) -#define mei_err(_me, fmt, ARGS...) do { \ - if ((_me)->log_level > MEI_LOG_LEVEL_QUIET) { \ - if ((_me)->log_callback) \ +#define mei_err(_me, fmt, ARGS...) do { \ + if ((_me)->log_level > MEI_LOG_LEVEL_QUIET) { \ + if (LEGACY_CALLBACK_SET(_me)) \ (_me)->log_callback(true, "me: error: " fmt, ##ARGS); \ - else \ - __mei_err("me: error: " fmt, ##ARGS); \ - } \ + else if (STANDARD_CALLBACK_SET(_me)) \ + callback_print_helper((_me), true, fmt, ##ARGS); \ + else \ + __mei_err("me: error: " fmt, ##ARGS); \ + } \ } while (0) #ifdef DEBUG @@ -106,6 +114,17 @@ static void mei_dump_hex_buffer(struct mei *me, } #endif /* DEBUG */ +static void callback_print_helper(struct mei *me, bool is_error, const char* args, ...) +{ +#define DEBUG_MSG_LEN 1024 + char msg[DEBUG_MSG_LEN + 1]; + va_list varl; + va_start(varl, args); + vsnprintf(msg, DEBUG_MSG_LEN, args, varl); + va_end(varl); + me->log_callback2(is_error, msg); +} + void mei_deinit(struct mei *me) { if (!me) @@ -381,9 +400,9 @@ static inline int __mei_getkind(struct mei *me, const char *device, char *kind, #undef KIND_LEN } -int mei_init_with_log(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_callback log_callback, mei_log_callback2 log_callback2) { int rc; @@ -395,6 +414,7 @@ int mei_init_with_log(struct mei *me, const char *device, const uuid_le *guid, me->close_on_exit = true; me->device = NULL; me->log_callback = log_callback; + me->log_callback2 = log_callback2; mei_deinit(me); me->log_level = verbose ? MEI_LOG_LEVEL_VERBOSE : MEI_LOG_LEVEL_ERROR; @@ -425,6 +445,22 @@ int mei_init_with_log(struct mei *me, const char *device, const uuid_le *guid, return 0; } +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, + req_protocol_version, verbose, log_callback, NULL); +} + +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, + req_protocol_version, verbose, NULL, log_callback); +} + int mei_init(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose) { @@ -485,6 +521,7 @@ int mei_init_fd(struct mei *me, int fd, const uuid_le *guid, mei_deinit(me); me->fd = fd; me->log_callback = NULL; + me->log_callback2 = NULL; me->log_level = verbose ? MEI_LOG_LEVEL_VERBOSE : MEI_LOG_LEVEL_ERROR; @@ -845,3 +882,14 @@ int mei_set_log_callback(struct mei *me, mei_log_callback log_callback) return 0; } + +int mei_set_log_callback2(struct mei *me, mei_log_callback2 log_callback) +{ + if (!me) + return -EINVAL; + + me->log_callback2 = log_callback; + mei_msg(me, "New log callback set\n"); + + return 0; +} diff --git a/version.cmake b/version.cmake index a9a6bb9..540411b 100644 --- a/version.cmake +++ b/version.cmake @@ -1,11 +1,17 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright (C) 2020 Intel Corporation +# Copyright (C) 2020-2025 Intel Corporation file(READ VERSION VER_FILE) string(STRIP "${VER_FILE}" VER_FILE) string(REPLACE "." ";" VER_LIST ${VER_FILE}) list(GET VER_LIST 0 MEI_VERSION_MAJOR) list(GET VER_LIST 1 MEI_VERSION_MINOR) list(GET VER_LIST 2 MEI_VERSION_PATCH) +list(LENGTH VER_LIST VER_LIST_LEN) +if(VER_LIST_LEN EQUAL 4) + list(GET VER_LIST 3 MEI_VERSION_BUILD) +else() + set(MEI_VERSION_BUILD 0) +endif() set(MEI_VERSION_STRING - ${MEI_VERSION_MAJOR}.${MEI_VERSION_MINOR}.${MEI_VERSION_PATCH}) + ${MEI_VERSION_MAJOR}.${MEI_VERSION_MINOR}.${MEI_VERSION_PATCH}.${MEI_VERSION_BUILD})