summaryrefslogtreecommitdiff
path: root/snxxx/1.2/SecureElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'snxxx/1.2/SecureElement.cpp')
-rw-r--r--[-rwxr-xr-x]snxxx/1.2/SecureElement.cpp109
1 files changed, 61 insertions, 48 deletions
diff --git a/snxxx/1.2/SecureElement.cpp b/snxxx/1.2/SecureElement.cpp
index 35b84eb..8cdb5c4 100755..100644
--- a/snxxx/1.2/SecureElement.cpp
+++ b/snxxx/1.2/SecureElement.cpp
@@ -17,8 +17,8 @@
******************************************************************************/
#include "SecureElement.h"
-#include "NxpEse.h"
#ifdef NXP_BOOTTIME_UPDATE
+#include "NxpEse.h"
#include "eSEClient.h"
#endif
#include <android-base/logging.h>
@@ -55,7 +55,9 @@ static sTransceiveBuffer_t gsTxRxBuffer;
static hidl_vec<uint8_t> gsRspDataBuff(256);
sp<V1_0::ISecureElementHalCallback> SecureElement::mCallbackV1_0 = nullptr;
std::vector<bool> SecureElement::mOpenedChannels;
+#ifdef NXP_BOOTTIME_UPDATE
using vendor::nxp::nxpese::V1_0::implementation::NxpEse;
+#endif
SecureElement::SecureElement()
: mMaxChannelCount(0), mOpenedchannelCount(0), mIsEseInitialized(false) {}
@@ -109,8 +111,10 @@ Return<void> SecureElement::init(
if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0)) {
initStatus = phNxpEse_init(initParams);
if (ESESTATUS_SUCCESS == initStatus) {
- /*update OS mode during first init*/
- IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+ if (GET_CHIP_OS_VERSION() < OS_VERSION_8_9) {
+ /*update OS mode during first init*/
+ IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+ }
if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
LOG(INFO) << "ESE SPI init complete!!!";
@@ -125,7 +129,8 @@ Return<void> SecureElement::init(
if (status == ESESTATUS_SUCCESS &&
(initStatus == ESESTATUS_TRANSCEIVE_FAILED ||
initStatus == ESESTATUS_FAILED)) {
- IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+ if (GET_CHIP_OS_VERSION() < OS_VERSION_8_9)
+ IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
mIsInitDone = true;
}
}
@@ -220,7 +225,8 @@ Return<void> SecureElement::init_1_1(
initStatus = phNxpEse_init(initParams);
if (initStatus == ESESTATUS_SUCCESS) {
/*update OS mode during first init*/
- IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+ if (GET_CHIP_OS_VERSION() < OS_VERSION_8_9)
+ IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
LOG(INFO) << "ESE SPI init complete!!!";
@@ -235,7 +241,8 @@ Return<void> SecureElement::init_1_1(
if (status == ESESTATUS_SUCCESS &&
(initStatus == ESESTATUS_TRANSCEIVE_FAILED ||
initStatus == ESESTATUS_FAILED)) {
- IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+ if (GET_CHIP_OS_VERSION() < OS_VERSION_8_9)
+ IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
mIsInitDone = true;
}
}
@@ -264,7 +271,8 @@ Return<void> SecureElement::getAtr(getAtr_cb _hidl_cb) {
bool mIsSeHalInitDone = false;
// In dedicated mode getATR not allowed
- if (IS_OSU_MODE(OsuHalExtn::getInstance().GETATR)) {
+ if ((GET_CHIP_OS_VERSION() < OS_VERSION_8_9) &&
+ (IS_OSU_MODE(OsuHalExtn::getInstance().GETATR))) {
LOG(ERROR) << "%s: Not allowed in dedicated mode!!!" << __func__;
_hidl_cb(response);
return Void();
@@ -282,7 +290,7 @@ Return<void> SecureElement::getAtr(getAtr_cb _hidl_cb) {
}
status = phNxpEse_SetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "Endpoint set failed";
+ LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed";
}
status = phNxpEse_getAtr(&atrData);
if (status != ESESTATUS_SUCCESS) {
@@ -296,7 +304,7 @@ Return<void> SecureElement::getAtr(getAtr_cb _hidl_cb) {
status = phNxpEse_ResetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "Endpoint set failed";
+ LOG(ERROR) << "phNxpEse_ResetEndPoint_Cntxt failed";
}
if (status != ESESTATUS_SUCCESS) {
@@ -337,23 +345,24 @@ Return<void> SecureElement::transmit(const hidl_vec<uint8_t>& data,
_hidl_cb(result);
return Void();
}
- OsuHalExtn::OsuApduMode mode = IS_OSU_MODE(
- data, OsuHalExtn::getInstance().TRANSMIT, &gsTxRxBuffer.cmdData);
- if (mode == OsuHalExtn::getInstance().OSU_BLOCKED_MODE) {
- LOG(ERROR) << "Not allowed in dedicated mode!!!";
- /*Return empty hidl_vec*/
- _hidl_cb(result);
- return Void();
- } else if (mode == OsuHalExtn::getInstance().OSU_RST_MODE) {
- uint8_t sw[2] = {0x90, 0x00};
- result.resize(sizeof(sw));
- memcpy(&result[0], sw, sizeof(sw));
- _hidl_cb(result);
- return Void();
+ if (GET_CHIP_OS_VERSION() < OS_VERSION_8_9) {
+ OsuHalExtn::OsuApduMode mode = IS_OSU_MODE(
+ data, OsuHalExtn::getInstance().TRANSMIT, &gsTxRxBuffer.cmdData);
+ if (mode == OsuHalExtn::getInstance().OSU_BLOCKED_MODE) {
+ LOG(ERROR) << "Not allowed in dedicated mode!!!";
+ /*Return empty hidl_vec*/
+ _hidl_cb(result);
+ return Void();
+ } else if (mode == OsuHalExtn::getInstance().OSU_RST_MODE) {
+ uint8_t sw[2] = {0x90, 0x00};
+ result.resize(sizeof(sw));
+ memcpy(&result[0], sw, sizeof(sw));
+ _hidl_cb(result);
+ return Void();
+ }
} else {
- // continue with normal processing
+ memcpy(gsTxRxBuffer.cmdData.p_data, data.data(), gsTxRxBuffer.cmdData.len);
}
- // memcpy(gsTxRxBuffer.cmdData.p_data, data.data(), gsTxRxBuffer.cmdData.len);
LOG(INFO) << "Acquired lock for SPI";
status = phNxpEse_SetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
@@ -373,7 +382,7 @@ Return<void> SecureElement::transmit(const hidl_vec<uint8_t>& data,
}
status = phNxpEse_ResetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+ LOG(ERROR) << "phNxpEse_ResetEndPoint_Cntxt failed!!!";
}
_hidl_cb(result);
@@ -424,7 +433,8 @@ Return<void> SecureElement::openLogicalChannel(const hidl_vec<uint8_t>& aid,
LOG(INFO) << "Acquired the lock from SPI openLogicalChannel";
// In dedicated mode openLogical not allowed
- if (IS_OSU_MODE(OsuHalExtn::getInstance().OPENLOGICAL)) {
+ if ((GET_CHIP_OS_VERSION() < OS_VERSION_6_2) &&
+ (IS_OSU_MODE(OsuHalExtn::getInstance().OPENLOGICAL))) {
LOG(ERROR) << "%s: Not allowed in dedicated mode!!!" << __func__;
_hidl_cb(resApduBuff, SecureElementStatus::IOERROR);
return Void();
@@ -494,7 +504,7 @@ Return<void> SecureElement::openLogicalChannel(const hidl_vec<uint8_t>& aid,
send the callback and return*/
status = phNxpEse_ResetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+ LOG(ERROR) << "phNxpEse_ResetEndPoint_Cntxt failed!!!";
}
_hidl_cb(resApduBuff, sestatus);
return Void();
@@ -590,7 +600,7 @@ Return<void> SecureElement::openLogicalChannel(const hidl_vec<uint8_t>& aid,
}
status = phNxpEse_ResetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+ LOG(ERROR) << "phNxpEse_ResetEndPoint_Cntxt failed!!!";
}
_hidl_cb(resApduBuff, sestatus);
phNxpEse_free(cpdu.pdata);
@@ -616,9 +626,9 @@ Return<void> SecureElement::openBasicChannel(const hidl_vec<uint8_t>& aid,
0x41, 0x01, 0x43, 0x4F, 0x52, 0x01};
LOG(ERROR) << "Acquired the lock in SPI openBasicChannel";
- OsuHalExtn::OsuApduMode mode =
- IS_OSU_MODE(aid, OsuHalExtn::getInstance().OPENBASIC);
- if (mode == OsuHalExtn::OSU_PROP_MODE) {
+ if ((GET_CHIP_OS_VERSION() < OS_VERSION_8_9) &&
+ IS_OSU_MODE(aid, OsuHalExtn::getInstance().OPENBASIC) ==
+ OsuHalExtn::OSU_PROP_MODE) {
uint8_t sw[2] = {0x90, 0x00};
result.resize(sizeof(sw));
memcpy(&result[0], sw, 2);
@@ -662,22 +672,24 @@ Return<void> SecureElement::openBasicChannel(const hidl_vec<uint8_t>& aid,
}
}
- phNxpEse_data atrData;
- if (phNxpEse_getAtr(&atrData) != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "phNxpEse_getAtr failed";
- }
- if (atrData.p_data != NULL) {
- phNxpEse_free(atrData.p_data);
- }
+ if (GET_CHIP_OS_VERSION() < OS_VERSION_8_9) {
+ phNxpEse_data atrData;
+ if (phNxpEse_getAtr(&atrData) != ESESTATUS_SUCCESS) {
+ LOG(ERROR) << "phNxpEse_getAtr failed";
+ }
+ if (atrData.p_data != NULL) {
+ phNxpEse_free(atrData.p_data);
+ }
- if (phNxpEse_GetOsMode() == OSU_MODE) {
- if (mOpenedchannelCount == 0) {
- if (seHalDeInit() != SecureElementStatus::SUCCESS) {
- LOG(INFO) << "seDeInit Failed";
+ if (phNxpEse_GetOsMode() == OSU_MODE) {
+ if (mOpenedchannelCount == 0) {
+ if (seHalDeInit() != SecureElementStatus::SUCCESS) {
+ LOG(INFO) << "seDeInit Failed";
+ }
}
+ _hidl_cb(result, SecureElementStatus::IOERROR);
+ return Void();
}
- _hidl_cb(result, SecureElementStatus::IOERROR);
- return Void();
}
if (mOpenedChannels.size() == 0x00) {
@@ -755,7 +767,7 @@ Return<void> SecureElement::openBasicChannel(const hidl_vec<uint8_t>& aid,
}
status = phNxpEse_ResetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+ LOG(ERROR) << "phNxpEse_ResetEndPoint_Cntxt failed!!!";
}
if (sestatus != SecureElementStatus::SUCCESS) {
SecureElementStatus closeChannelStatus =
@@ -808,7 +820,7 @@ Return<SecureElementStatus> SecureElement::internalCloseChannel(
}
status = phNxpEse_ResetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+ LOG(ERROR) << "phNxpEse_ResetEndPoint_Cntxt failed!!!";
}
}
if (channelNumber < mMaxChannelCount) {
@@ -829,7 +841,8 @@ Return<SecureElementStatus> SecureElement::internalCloseChannel(
Return<SecureElementStatus> SecureElement::closeChannel(uint8_t channelNumber) {
AutoMutex guard(seHalLock);
// Close internal allowed when not in dedicated Mode
- if (!IS_OSU_MODE(OsuHalExtn::getInstance().CLOSE, channelNumber)) {
+ if ((GET_CHIP_OS_VERSION() >= OS_VERSION_8_9) ||
+ (!IS_OSU_MODE(OsuHalExtn::getInstance().CLOSE, channelNumber))) {
return internalCloseChannel(channelNumber);
} else {
/*Decrement channel count opened to
@@ -904,7 +917,7 @@ Return<SecureElementStatus> SecureElement::seHalDeInit() {
if (ESESTATUS_SUCCESS != deInitStatus) mIsDeInitDone = false;
status = phNxpEse_ResetEndPoint_Cntxt(0);
if (status != ESESTATUS_SUCCESS) {
- LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+ LOG(ERROR) << "phNxpEse_ResetEndPoint_Cntxt failed!!!";
mIsDeInitDone = false;
}
status = phNxpEse_close(deInitStatus);