Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.4
1.7.0
33 changes: 32 additions & 1 deletion libmei.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
76 changes: 62 additions & 14 deletions mei.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdarg.h>

#include "libmei.h"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
10 changes: 8 additions & 2 deletions version.cmake
Original file line number Diff line number Diff line change
@@ -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})