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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [6.2.0]

### Changed
- Linux: build for Android using Android NDK
- Linux: import libmei 1.8.1

### Added
- add TeeCancelIO API

## [6.1.0]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.0
6.2.0
7 changes: 3 additions & 4 deletions include/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ extern "C" {
// For debugging
//#define LOG_NDEBUG 0
#define LOG_TAG "metee"
#include <cutils/log.h>
#define DebugPrintMe(fmt, ...) ALOGV_IF(true, fmt, ##__VA_ARGS__)
#define ErrorPrintMe(fmt, ...) ALOGE_IF(true, fmt, ##__VA_ARGS__)

#include <android/log_macros.h>
#define DebugPrintMe(fmt, ...) ALOGV(fmt, ##__VA_ARGS__)
#define ErrorPrintMe(fmt, ...) ALOGE(fmt, ##__VA_ARGS__)
#ifdef LOG_NDEBUG
#define TEE_DEFAULT_LOG_LEVEL TEE_LOG_LEVEL_VERBOSE
#else
Expand Down
5 changes: 5 additions & 0 deletions include/metee.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val);
*/
void TEEAPI TeeDisconnect(IN PTEEHANDLE handle);

/*! Try to stop all in-process reads and writes
* \param handle The handle of the session
*/
void TEEAPI TeeCancelIO(IN PTEEHANDLE handle);

/*! Returns handle of TEE device
* Obtains HECI device handle on Windows and mei device file descriptor on Linux
* \param handle The handle of the session.
Expand Down
6 changes: 6 additions & 0 deletions include/meteepp.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ namespace intel {
TeeDisconnect(&_handle);
}

/*! Try to stop all in-process reads and writes */
void cancel_io()
{
TeeCancelIO(&_handle);
}

/*! Connects to the TEE driver and starts a session */
void connect()
{
Expand Down
3 changes: 3 additions & 0 deletions linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ if(NOT CONSOLE_OUTPUT)
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE -D_GNU_SOURCE)
if(ANDROID)
target_link_libraries(${PROJECT_NAME} PRIVATE log)
endif()
40 changes: 29 additions & 11 deletions src/Windows/metee_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,20 +531,11 @@ TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val)
return status;
}

VOID TEEAPI TeeDisconnect(IN PTEEHANDLE handle)
static void __TeeCancelIO(PTEEHANDLE handle)
{
struct METEE_WIN_IMPL *impl_handle = to_int(handle);
DWORD ret;

if (NULL == handle) {
return;
}

FUNC_ENTRY(handle);
if (NULL == impl_handle) {
goto Cleanup;
}

if (CancelIoEx(impl_handle->handle, NULL)) {
HANDLE handles[MAX_EVT];
for (size_t i = 0; i < MAX_EVT; i++) {
Expand All @@ -556,6 +547,33 @@ VOID TEEAPI TeeDisconnect(IN PTEEHANDLE handle)
ret, GetLastError());
}
}
}

void TEEAPI TeeCancelIO(IN PTEEHANDLE handle)
{
struct METEE_WIN_IMPL *impl_handle = to_int(handle);

FUNC_ENTRY(handle);
if (NULL != impl_handle) {
__TeeCancelIO(handle);
}
FUNC_EXIT(handle, TEE_SUCCESS);
}

VOID TEEAPI TeeDisconnect(IN PTEEHANDLE handle)
{
struct METEE_WIN_IMPL *impl_handle = to_int(handle);

if (NULL == handle) {
return;
}

FUNC_ENTRY(handle);
if (NULL == impl_handle) {
goto Cleanup;
}

__TeeCancelIO(handle);
for (size_t i = 0; i < MAX_EVT; i++) {
if (impl_handle->evt[i]) {
if (impl_handle->evt[i]->hEvent)
Expand All @@ -570,7 +588,7 @@ VOID TEEAPI TeeDisconnect(IN PTEEHANDLE handle)
handle->handle = NULL;

Cleanup:
FUNC_EXIT(handle, 0);
FUNC_EXIT(handle, TEE_SUCCESS);
}

TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle)
Expand Down
8 changes: 6 additions & 2 deletions src/linux/mei.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
*****************************************************************************/
#ifdef ANDROID
#define LOG_TAG "libmei"
#include <cutils/log.h>
#define mei_msg(_me, fmt, ARGS...) ALOGV_IF((_me->log_level >= MEI_LOG_LEVEL_VERBOSE), fmt, ##ARGS)
#include <android/log_macros.h>
#define mei_msg(_me, fmt, ARGS...) \
((_me->log_level >= MEI_LOG_LEVEL_VERBOSE) \
? (void)ALOGV(fmt, ##ARGS) \
: (void)0)

#define mei_err(_me, fmt, ARGS...) ALOGE(fmt, ##ARGS)
#ifdef DEBUG
static inline void __dump_buffer(const char *buf)
Expand Down
26 changes: 22 additions & 4 deletions src/linux/metee_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,20 +488,38 @@ TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val)
return status;
}

static void __TeeCancelIO(PTEEHANDLE handle)
{
struct metee_linux_intl* intl = to_intl(handle);
const char buf[] = "X";

if (write(intl->cancel_pipe[1], buf, sizeof(buf)) < 0) {
ERRPRINT(handle, "Pipe write failed\n");
}
}

void TEEAPI TeeCancelIO(IN PTEEHANDLE handle)
{
struct metee_linux_intl* intl = to_intl(handle);

FUNC_ENTRY(handle);
if (intl) {
__TeeCancelIO(handle);
}
FUNC_EXIT(handle, TEE_SUCCESS);
}

void TEEAPI TeeDisconnect(PTEEHANDLE handle)
{
struct metee_linux_intl *intl = to_intl(handle);
const char buf[] = "X";

if (!handle) {
return;
}

FUNC_ENTRY(handle);
if (intl) {
if (write(intl->cancel_pipe[1], buf, sizeof(buf)) < 0) {
ERRPRINT(handle, "Pipe write failed\n");
}
__TeeCancelIO(handle);
mei_deinit(&intl->me);
close(intl->cancel_pipe[0]);
close(intl->cancel_pipe[1]);
Expand Down
4 changes: 4 additions & 0 deletions src/uefi/metee_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,4 +851,8 @@ TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size
End:
FUNC_EXIT(handle, status);
return status;
}

void TEEAPI TeeCancelIO(IN PTEEHANDLE handle)
{
}
Loading