summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJyoti Wadhwani <jyotiw@codeaurora.org>2015-01-14 15:59:33 -0800
committerSteve Kondik <steve@cyngn.com>2015-10-30 15:34:06 -0700
commit9093ff000a224fec6258013d1a6de4a1816d1b33 (patch)
treed155f1bf1146355059ab0d8b01c67bde0e9fc0fe
parent7ad7aed998676bff53c570b1a697a33ebae66a78 (diff)
downloadandroid_hardware_qcom_keymaster-9093ff000a224fec6258013d1a6de4a1816d1b33.tar.gz
android_hardware_qcom_keymaster-9093ff000a224fec6258013d1a6de4a1816d1b33.tar.bz2
android_hardware_qcom_keymaster-9093ff000a224fec6258013d1a6de4a1816d1b33.zip
Keymaster: Check if keymaster TZ app is loaded
qseecomd sets a property to indicate that it has successfully loaded keymaster TZ app. This change checks waits until that property is set Change-Id: I3533ba7489ab2d7d85473821557e4ddf0119cf6f
-rw-r--r--Android.mk3
-rw-r--r--keymaster_qcom.cpp25
2 files changed, 27 insertions, 1 deletions
diff --git a/Android.mk b/Android.mk
index 219aa32..8f474c2 100644
--- a/Android.mk
+++ b/Android.mk
@@ -30,7 +30,8 @@ LOCAL_SHARED_LIBRARIES := \
libcrypto \
liblog \
libc \
- libdl
+ libdl \
+ libcutils
LOCAL_ADDITIONAL_DEPENDENCIES := \
$(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr \
diff --git a/keymaster_qcom.cpp b/keymaster_qcom.cpp
index d133401..98ca034 100644
--- a/keymaster_qcom.cpp
+++ b/keymaster_qcom.cpp
@@ -43,6 +43,7 @@
#include <dlfcn.h>
#include <UniquePtr.h>
+#include <cutils/properties.h>
#include "QSEEComAPI.h"
#include "keymaster_qcom.h"
@@ -53,6 +54,8 @@
#define LOG_TAG "QCOMKeyMaster"
#define UNUSED(x) (void)(x)
#define KM_SB_LENGTH (4096 * 2)
+#define MAX_PROPERTY_GET_ATTEMPTS 60
+#define PROPERTY_GET_SLEEP_INTERVAL 1
#include <cutils/log.h>
struct qcom_km_ion_info_t {
@@ -738,6 +741,8 @@ static int qcom_km_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
int ret = 0;
+ unsigned int attempt_num = 0;
+ char property_val[PROPERTY_VALUE_MAX] = {0};
qcom_keymaster_handle_t* km_handle;
if (strcmp(name, KEYSTORE_KEYMASTER) != 0)
return -EINVAL;
@@ -760,6 +765,26 @@ static int qcom_km_open(const hw_module_t* module, const char* name,
return -ENOMEM;
}
dev->context = (void *)km_handle;
+ while (attempt_num < MAX_PROPERTY_GET_ATTEMPTS)
+ {
+ property_get("sys.keymaster.loaded", property_val, "");
+ if (strncmp(property_val, "true", sizeof(property_val)) == 0)
+ {
+ ALOGD("keymaster app is loaded");
+ break;
+ }
+ if (attempt_num == 0)
+ ALOGE("keymaster app is not loaded, attempt number %d", attempt_num);
+ attempt_num++;
+ sleep(PROPERTY_GET_SLEEP_INTERVAL);
+ }
+ if (attempt_num == MAX_PROPERTY_GET_ATTEMPTS)
+ {
+ ALOGE("Keymaster app not loaded: Max attempts reached");
+ free(km_handle);
+ return -1;
+ }
+ ALOGD("keymaster app got loaded at attempt number %d", attempt_num);
ret = (*km_handle->QSEECom_start_app)((struct QSEECom_handle **)&km_handle->qseecom,
"/vendor/firmware/keymaster", "keymaster", KM_SB_LENGTH);
if(ret)