summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsuryaprakash.konduru <suryaprakash.konduru@nxp.com>2023-11-01 20:54:18 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-01 20:54:18 +0000
commit22db2f5bec4f31a9063aeec2a2222186248aefbd (patch)
treecf75f22b8d3f9a9545d3506ddd00d219eca35445
parent4d7dcc951c51fdf5d1dd2be078c5b9d6feb36a15 (diff)
parent8c8efba908dc93325b6084fd5f22ee9af35da91f (diff)
downloadweaver-22db2f5bec4f31a9063aeec2a2222186248aefbd.tar.gz
Weaver libese module update am: 8c8efba908
Original change: https://android-review.googlesource.com/c/platform/hardware/nxp/weaver/+/2812613 Change-Id: Ie50604d11e74d74d1ce91e7c3b2d4b18b24f43e2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--libese_weaver/inc/TransportFactory.h9
-rw-r--r--libese_weaver/inc/weaver_parser-impl.h8
-rw-r--r--libese_weaver/inc/weaver_parser.h6
-rw-r--r--libese_weaver/inc/weaver_transport-impl.h8
-rw-r--r--libese_weaver/inc/weaver_transport.h6
-rw-r--r--libese_weaver/src/weaver-impl.cpp14
-rw-r--r--libese_weaver/src/weaver-parser-impl.cpp15
-rw-r--r--libese_weaver/src/weaver-transport-impl.cpp50
8 files changed, 83 insertions, 33 deletions
diff --git a/libese_weaver/inc/TransportFactory.h b/libese_weaver/inc/TransportFactory.h
index 9b68ffc..416f6d5 100644
--- a/libese_weaver/inc/TransportFactory.h
+++ b/libese_weaver/inc/TransportFactory.h
@@ -30,7 +30,7 @@
** See the License for the specific language governing permissions and
** limitations under the License.
**
- ** Copyright 2020-2022 NXP
+ ** Copyright 2020-2023 NXP
**
*********************************************************************************/
@@ -73,6 +73,13 @@ class TransportFactory {
~TransportFactory() {}
/**
+ * Sets Applet AID.
+ */
+ inline bool setAppletAid(const std::vector<uint8_t> &aid) {
+ return mTransport->setAppletAid(aid);
+ }
+
+ /**
* Establishes a communication channel with the secure element.
*/
inline bool openConnection() {
diff --git a/libese_weaver/inc/weaver_parser-impl.h b/libese_weaver/inc/weaver_parser-impl.h
index 7ca0267..14c7ef8 100644
--- a/libese_weaver/inc/weaver_parser-impl.h
+++ b/libese_weaver/inc/weaver_parser-impl.h
@@ -1,6 +1,6 @@
/******************************************************************************
*
- * Copyright 2020, 2022 NXP
+ * Copyright 2020, 2022-2023 NXP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -139,12 +139,12 @@ public:
/**
* \brief Function to get Weaver Applet ID
*
- * \param[out] aid - applet id of the weaver applet.
+ * \param[out] aid - applet ids of the weaver applet.
*
* \retval This function return true in case of success
* In case of failure returns false.
*/
- bool getAppletId(std::vector<uint8_t> &aid);
+ bool getAppletId(std::vector<std::vector<uint8_t>> &aid);
/**
* \brief static function to get the singleton instance of WeaverParserImpl
@@ -162,7 +162,7 @@ private:
APP_INVALID_LEN,
APP_INVALID_SLOT,
APP_INVALID_P1_P2,
- APP_UNKONWN_ERR,
+ APP_UNKNOWN_ERR,
};
/**
diff --git a/libese_weaver/inc/weaver_parser.h b/libese_weaver/inc/weaver_parser.h
index 5c505a2..71c1dce 100644
--- a/libese_weaver/inc/weaver_parser.h
+++ b/libese_weaver/inc/weaver_parser.h
@@ -1,6 +1,6 @@
/******************************************************************************
*
- * Copyright 2020, 2022 NXP
+ * Copyright 2020, 2023 NXP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,12 +136,12 @@ public:
/**
* \brief virtual Function to get Weaver Applet ID
*
- * \param[out] aid - applet id of the weaver applet.
+ * \param[out] aid - applet ids of the weaver applet.
*
* \retval This function return true in case of success
* In case of failure returns false.
*/
- virtual bool getAppletId(std::vector<uint8_t> &aid) = 0;
+ virtual bool getAppletId(std::vector<std::vector<uint8_t>> &aid) = 0;
/**
* \brief virtual destructor for weaver parser
diff --git a/libese_weaver/inc/weaver_transport-impl.h b/libese_weaver/inc/weaver_transport-impl.h
index c34a9e3..5fa4075 100644
--- a/libese_weaver/inc/weaver_transport-impl.h
+++ b/libese_weaver/inc/weaver_transport-impl.h
@@ -1,6 +1,6 @@
/******************************************************************************
*
- * Copyright 2020, 2022 NXP
+ * Copyright 2020, 2022-2023 NXP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ public:
* \retval This function return true in case of success
* In case of failure returns false.
*/
- bool Init(std::vector<uint8_t> aid) override;
+ bool Init(std::vector<std::vector<uint8_t>> aid) override;
/**
* \brief Function to open applet connection
@@ -105,6 +105,10 @@ private:
* Same will be used for std::call_once
*/
static void createInstance();
+ /* Private wrapper function to send apdu.
+ * It will try with alternate aids if sending is failed.
+ */
+ bool sendInternal(std::vector<uint8_t> data, std::vector<uint8_t> &resp);
};
#endif /* _WEAVER_TRANSPORT_IMPL_H_ */
diff --git a/libese_weaver/inc/weaver_transport.h b/libese_weaver/inc/weaver_transport.h
index 17b83e8..f8a76b6 100644
--- a/libese_weaver/inc/weaver_transport.h
+++ b/libese_weaver/inc/weaver_transport.h
@@ -1,6 +1,6 @@
/******************************************************************************
*
- * Copyright 2020 NXP
+ * Copyright 2020, 2023 NXP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,12 +26,12 @@ public:
/**
* \brief virtual Function to initialize Weaver Transport Interface
*
- * \param[in] aid - applet id to be set to transport interface
+ * \param[in] aid - applet ids to be set to transport interface
*
* \retval This function return true in case of success
* In case of failure returns false.
*/
- virtual bool Init(std::vector<uint8_t> aid) = 0;
+ virtual bool Init(std::vector<std::vector<uint8_t>> aid) = 0;
/**
* \brief virtual Function to open applet connection
diff --git a/libese_weaver/src/weaver-impl.cpp b/libese_weaver/src/weaver-impl.cpp
index d682b68..85f950b 100644
--- a/libese_weaver/src/weaver-impl.cpp
+++ b/libese_weaver/src/weaver-impl.cpp
@@ -58,10 +58,10 @@ Status_Weaver WeaverImpl::Init() {
mParser = WeaverParserImpl::getInstance();
RETURN_IF_NULL(mTransport, WEAVER_STATUS_FAILED, "Transport is NULL");
RETURN_IF_NULL(mParser, WEAVER_STATUS_FAILED, "Parser is NULL");
- std::vector<uint8_t> aid;
+ std::vector<std::vector<uint8_t>> aid;
mParser->getAppletId(aid);
- if (!mTransport->Init(aid)) {
- LOG_E(TAG, "Not able to Initilaize Transport Interface");
+ if (!mTransport->Init(std::move(aid))) {
+ LOG_E(TAG, "Not able to Initialize Transport Interface");
LOG_D(TAG, "Exit : FAILED");
return WEAVER_STATUS_FAILED;
}
@@ -98,7 +98,7 @@ Status_Weaver WeaverImpl::GetSlots(SlotInfo &slotInfo) {
}
#endif
if (status == WEAVER_STATUS_OK) {
- status = mParser->ParseSlotInfo(resp, slotInfo);
+ status = mParser->ParseSlotInfo(std::move(resp), slotInfo);
LOG_D(TAG, "Total Slots (%u) ", slotInfo.slots);
} else {
LOG_E(TAG, "Failed Parsing getSlot Response");
@@ -153,8 +153,8 @@ Status_Weaver WeaverImpl::Read(uint32_t slotId, const std::vector<uint8_t> &key,
if (mParser->FrameGetDataCmd(WeaverParserImpl::sThrottleGetDataP1, (uint8_t)slotId, cmd) &&
(mTransport->Send(cmd, resp))) {
GetDataRespInfo getDataInfo;
- if (mParser->ParseGetDataInfo(resp, getDataInfo) == WEAVER_STATUS_OK) {
- /* convert timeout from getDataInfo sec to millisec assign same to read response */
+ if (mParser->ParseGetDataInfo(std::move(resp), getDataInfo) == WEAVER_STATUS_OK) {
+ /* convert timeout from getDataInfo sec to millisecond assign same to read response */
readRespInfo.timeout = (getDataInfo.timeout * 1000);
}
}
@@ -204,7 +204,7 @@ Status_Weaver WeaverImpl::Write(uint32_t slotId,
// Channel Close Failed
}
#endif
- if (status != WEAVER_STATUS_OK || (!mParser->isSuccess(resp))) {
+ if (status != WEAVER_STATUS_OK || (!mParser->isSuccess(std::move(resp)))) {
status = WEAVER_STATUS_FAILED;
}
LOG_D(TAG, "Exit");
diff --git a/libese_weaver/src/weaver-parser-impl.cpp b/libese_weaver/src/weaver-parser-impl.cpp
index 229a349..0804281 100644
--- a/libese_weaver/src/weaver-parser-impl.cpp
+++ b/libese_weaver/src/weaver-parser-impl.cpp
@@ -66,8 +66,11 @@ std::once_flag WeaverParserImpl::s_instanceFlag;
#define INS_GET_DATA 0xCA
/* Applet ID to be used for Weaver */
-const std::vector<uint8_t> kWeaverAID = {0xA0, 0x00, 0x00, 0x03,
- 0x96, 0x10, 0x10};
+const std::vector<std::vector<uint8_t>> kWeaverAIDs = {
+ {0xA0, 0x00, 0x00, 0x03, 0x96, 0x10, 0x10}, // Primary AID
+ {0xA0, 0x00, 0x00, 0x03, 0x96, 0x54, 0x53, 0x00, 0x00, 0x00, 0x01, 0x00,
+ 0x23, 0x00, 0x00, 0x00}, // Alternate AID
+};
/**
* \brief static function to get the singleton instance of WeaverParserImpl
@@ -370,7 +373,7 @@ Status_Weaver WeaverParserImpl::ParseGetDataInfo(std::vector<uint8_t> response,
* and false in other cases.
*/
bool WeaverParserImpl::isSuccess(std::vector<uint8_t> response) {
- return (checkStatus(response) == APP_SUCCESS) ? true : false;
+ return (checkStatus(std::move(response)) == APP_SUCCESS) ? true : false;
}
/**
@@ -419,11 +422,11 @@ WeaverParserImpl::checkStatus(std::vector<uint8_t> response) {
* \retval This function return true in case of success
* In case of failure returns false.
*/
-bool WeaverParserImpl::getAppletId(std::vector<uint8_t> &aid) {
+bool WeaverParserImpl::getAppletId(std::vector<std::vector<uint8_t>> &aid) {
LOG_D(TAG, "Entry");
bool status = false;
- if (kWeaverAID.size() > 0) {
- aid = kWeaverAID;
+ if (kWeaverAIDs.size() > 0) {
+ aid = kWeaverAIDs;
status = true;
}
LOG_D(TAG, "Exit");
diff --git a/libese_weaver/src/weaver-transport-impl.cpp b/libese_weaver/src/weaver-transport-impl.cpp
index c1d59ef..08f4fd0 100644
--- a/libese_weaver/src/weaver-transport-impl.cpp
+++ b/libese_weaver/src/weaver-transport-impl.cpp
@@ -1,6 +1,6 @@
/******************************************************************************
*
- * Copyright 2020-2022 NXP
+ * Copyright 2020-2023 NXP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,12 +27,15 @@
#define RETRY_DELAY_INTERVAL_SEC 1
#define PROP_SYSBOOT_COMPLETED "sys.boot_completed"
#define SYSBOOT_COMPLETED_VALUE 1
+#define IS_APPLET_SELECTION_FAILED(resp) \
+ (!resp.empty() && resp[0] == APP_NOT_FOUND_SW1 && \
+ resp[1] == APP_NOT_FOUND_SW2)
WeaverTransportImpl *WeaverTransportImpl::s_instance = NULL;
std::once_flag WeaverTransportImpl::s_instanceFlag;
/* Applet ID to be use for communication */
-std::vector<uint8_t> kAppletId;
+std::vector<std::vector<uint8_t>> kAppletId;
/* Interface instance of libese-transport library */
static std::unique_ptr<se_transport::TransportFactory> pTransportFactory =
@@ -45,7 +48,7 @@ static inline std::unique_ptr<se_transport::TransportFactory> &
getTransportFactoryInstance() {
if (pTransportFactory == nullptr) {
pTransportFactory = std::unique_ptr<se_transport::TransportFactory>(
- new se_transport::TransportFactory(false, kAppletId));
+ new se_transport::TransportFactory(false, kAppletId[0]));
pTransportFactory->openConnection();
}
return pTransportFactory;
@@ -82,9 +85,9 @@ void WeaverTransportImpl::createInstance() {
* \retval This function return true in case of success
* In case of failure returns false.
*/
-bool WeaverTransportImpl::Init(std::vector<uint8_t> aid) {
+bool WeaverTransportImpl::Init(std::vector<std::vector<uint8_t>> aid) {
LOG_D(TAG, "Entry");
- kAppletId = aid;
+ kAppletId = std::move(aid);
LOG_D(TAG, "Exit");
return true;
}
@@ -125,6 +128,40 @@ bool WeaverTransportImpl::CloseApplet() {
}
/**
+ * \brief Private wrapper function to send apdu.
+ * It will try with alternate aids if sending is failed.
+ *
+ * \param[in] data - command to be send to applet
+ * \param[out] resp - response from applet
+ *
+ * \retval This function return true in case of success
+ * In case of failure returns false.
+ */
+bool WeaverTransportImpl::sendInternal(std::vector<uint8_t> data,
+ std::vector<uint8_t> &resp) {
+ bool status = false;
+ status =
+ getTransportFactoryInstance()->sendData(data.data(), data.size(), resp);
+ if (!status && IS_APPLET_SELECTION_FAILED(resp)) {
+ LOG_E(TAG, ": send Failed, trying with alternateAids");
+ // If Applet selection failed, try with alternate Aids
+ for (int i = 1; i < kAppletId.size(); i++) {
+ getTransportFactoryInstance()->setAppletAid(kAppletId[i]);
+ status = getTransportFactoryInstance()->sendData(data.data(), data.size(),
+ resp);
+ if (status) {
+ return status;
+ }
+ }
+ if (!status) {
+ // None of alternate Aids success, Revert back to primary AID
+ getTransportFactoryInstance()->setAppletAid(kAppletId[0]);
+ }
+ }
+ return status;
+}
+
+/**
* \brief Function to send commands to applet
*
* \param[in] data - command to be send to applet
@@ -140,8 +177,7 @@ bool WeaverTransportImpl::Send(std::vector<uint8_t> data,
bool status = false;
// Opens the channel with aid and transmit the data
do {
- status =
- getTransportFactoryInstance()->sendData(data.data(), data.size(), resp);
+ status = sendInternal(data, resp);
if (!status) {
if (!isDeviceBootCompleted()) {
LOG_D(TAG, ": Device boot not completed, no retry required");