|
| 1 | +/* SPDX-License-Identifier: Apache-2.0 */ |
| 2 | +/* |
| 3 | + * Copyright (C) 2021-2026 Intel Corporation |
| 4 | + */ |
| 5 | + /*++ |
| 6 | +
|
| 7 | + @file: LMEClient.cpp |
| 8 | +
|
| 9 | + --*/ |
| 10 | + |
| 11 | +#include "LMEClient.h" |
| 12 | +#include "MEICommand.h" |
| 13 | +#include <meteepp.h> |
| 14 | +#include "HECI_if.h" |
| 15 | + |
| 16 | +namespace Intel |
| 17 | +{ |
| 18 | + namespace MEI_Client |
| 19 | + { |
| 20 | + namespace LME_Client |
| 21 | + { |
| 22 | + const uint32_t HECI_IO_TIMEOUT = 5000; |
| 23 | + void LMEClient::Connect() |
| 24 | + { |
| 25 | + _heci.reset(new intel::security::metee(heciClientByGUID(LME_GUID))); |
| 26 | + } |
| 27 | + |
| 28 | + void LMEClient::Disconnect() |
| 29 | + { |
| 30 | + _heci.reset(nullptr); |
| 31 | + } |
| 32 | + |
| 33 | + std::vector<uint8_t> LMEClient::Read() |
| 34 | + { |
| 35 | + if (_heci == nullptr) |
| 36 | + throw MEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 37 | + try |
| 38 | + { |
| 39 | + return _heci->read(0); |
| 40 | + } |
| 41 | + catch (const intel::security::metee_exception& e) |
| 42 | + { |
| 43 | + throw MEIClientException(e.what(), e.code().value()); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + void LMEClient::Cancel() |
| 48 | + { |
| 49 | + if (_heci == nullptr) |
| 50 | + throw MEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 51 | + try |
| 52 | + { |
| 53 | + _heci->cancel_io(); |
| 54 | + } |
| 55 | + catch (const intel::security::metee_exception& e) |
| 56 | + { |
| 57 | + throw MEIClientException(e.what(), e.code().value()); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + size_t LMEClient::Write(const std::vector<uint8_t> &buffer) |
| 62 | + { |
| 63 | + if (_heci == nullptr) |
| 64 | + throw MEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 65 | + |
| 66 | + std::lock_guard<std::mutex> lock(_sendMessageLock); |
| 67 | + |
| 68 | + try |
| 69 | + { |
| 70 | + return _heci->write(buffer, HECI_IO_TIMEOUT); |
| 71 | + } |
| 72 | + catch (const intel::security::metee_exception& e) |
| 73 | + { |
| 74 | + throw MEIClientException(e.what(), e.code().value()); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + size_t LMEClient::GetBufferSize() const |
| 79 | + { |
| 80 | + if (_heci == nullptr) |
| 81 | + throw MEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 82 | + return _heci->max_msg_len(); |
| 83 | + } |
| 84 | + |
| 85 | + TEE_DEVICE_HANDLE LMEClient::GetDeviceHandle() const |
| 86 | + { |
| 87 | + if (_heci == nullptr) |
| 88 | + throw MEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 89 | + return _heci->device_handle(); |
| 90 | + } |
| 91 | + } // namespace LME_Client |
| 92 | + } // namespace MEI_Client |
| 93 | +} // namespace Intel |
0 commit comments