|
| 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 | +namespaceIntel |
| 17 | +{ |
| 18 | +namespaceMEI_Client |
| 19 | + { |
| 20 | +namespaceLME_Client |
| 21 | + { |
| 22 | +constuint32_tHECI_IO_TIMEOUT = 5000; |
| 23 | +voidLMEClient::Connect() |
| 24 | + { |
| 25 | + _heci.reset(newintel::security::metee(heciClientByGUID(LME_GUID))); |
| 26 | + } |
| 27 | + |
| 28 | +voidLMEClient::Disconnect() |
| 29 | + { |
| 30 | + _heci.reset(nullptr); |
| 31 | + } |
| 32 | + |
| 33 | + std::vector<uint8_t> LMEClient::Read() |
| 34 | + { |
| 35 | +if (_heci == nullptr) |
| 36 | +throwMEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 37 | +try |
| 38 | + { |
| 39 | +return _heci->read(0); |
| 40 | + } |
| 41 | +catch (const intel::security::metee_exception& e) |
| 42 | + { |
| 43 | +throwMEIClientException(e.what(), e.code().value()); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | +voidLMEClient::Cancel() |
| 48 | + { |
| 49 | +if (_heci == nullptr) |
| 50 | +throwMEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 51 | +try |
| 52 | + { |
| 53 | + _heci->cancel_io(); |
| 54 | + } |
| 55 | +catch (const intel::security::metee_exception& e) |
| 56 | + { |
| 57 | +throwMEIClientException(e.what(), e.code().value()); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | +size_tLMEClient::Write(const std::vector<uint8_t> &buffer) |
| 62 | + { |
| 63 | +if (_heci == nullptr) |
| 64 | +throwMEIClientException("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 | +throwMEIClientException(e.what(), e.code().value()); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | +size_tLMEClient::GetBufferSize() const |
| 79 | + { |
| 80 | +if (_heci == nullptr) |
| 81 | +throwMEIClientException("Not initialized", TEE_INTERNAL_ERROR); |
| 82 | +return _heci->max_msg_len(); |
| 83 | + } |
| 84 | + |
| 85 | +TEE_DEVICE_HANDLELMEClient::GetDeviceHandle() const |
| 86 | + { |
| 87 | +if (_heci == nullptr) |
| 88 | +throwMEIClientException("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