summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsuryaprakash.konduru <suryaprakash.konduru@nxp.com>2023-11-09 21:26:38 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-09 21:26:38 +0000
commitac6b68b8fd4fc51506dc4564ef79402aa5c42315 (patch)
tree459a8736658752634ee5ba26376ef6dc9e227d12
parent22db2f5bec4f31a9063aeec2a2222186248aefbd (diff)
parentf395b2d6c68d973cdcedee1ac85b8d3820adad59 (diff)
downloadweaver-ac6b68b8fd4fc51506dc4564ef79402aa5c42315.tar.gz
Weaver AIDL support added am: f395b2d6c6
Original change: https://android-review.googlesource.com/c/platform/hardware/nxp/weaver/+/2770202 Change-Id: I78111772cefa923c418644aaedaf7ddfdcc951e7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-xAndroid.bp27
-rw-r--r--NOTICE2
-rw-r--r--aidl_impl/Weaver.cpp148
-rw-r--r--aidl_impl/Weaver.h51
-rw-r--r--aidl_impl/android.hardware.weaver-service.nxp.rc4
-rw-r--r--aidl_impl/android.hardware.weaver-service.nxp.xml10
-rw-r--r--aidl_impl/service.cpp44
7 files changed, 285 insertions, 1 deletions
diff --git a/Android.bp b/Android.bp
index 6f06246..bb9b998 100755
--- a/Android.bp
+++ b/Android.bp
@@ -67,3 +67,30 @@ cc_binary {
"-fexceptions",
],
}
+
+cc_binary {
+ name: "android.hardware.weaver-service.nxp",
+ relative_install_path: "hw",
+ init_rc: ["aidl_impl/android.hardware.weaver-service.nxp.rc"],
+ vintf_fragments: ["aidl_impl/android.hardware.weaver-service.nxp.xml"],
+ vendor: true,
+ srcs: [
+ "aidl_impl/service.cpp",
+ "aidl_impl/Weaver.cpp",
+ ],
+
+ local_include_dirs: [
+ "libese_weaver/inc",
+ ],
+ cppflags: [
+ "-Wall",
+ "-fexceptions",
+ ],
+ shared_libs: [
+ "android.hardware.weaver-V2-ndk",
+ "libbase",
+ "libbinder_ndk",
+ "liblog",
+ "ese_weaver.nxp",
+ ],
+}
diff --git a/NOTICE b/NOTICE
index a0ac881..e14ff16 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,6 +1,6 @@
Copyright (C) 2017 The Android Open Source Project
-icensed under the Apache License, Version 2.0 (the "License");
+Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
diff --git a/aidl_impl/Weaver.cpp b/aidl_impl/Weaver.cpp
new file mode 100644
index 0000000..66f1313
--- /dev/null
+++ b/aidl_impl/Weaver.cpp
@@ -0,0 +1,148 @@
+/******************************************************************************
+ *
+ * Copyright 2023 NXP
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+#include "Weaver.h"
+#include <log/log.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace weaver {
+
+using ::ndk::ScopedAStatus;
+using std::vector;
+
+// Methods from ::android::hardware::weaver::IWeaver follow.
+
+Weaver::Weaver() {
+ ALOGD("Weaver Constructor");
+ pInterface = WeaverImpl::getInstance();
+ if (pInterface != NULL) {
+ pInterface->Init();
+ } else {
+ ALOGE("Failed to get Weaver Interface");
+ }
+}
+
+ScopedAStatus Weaver::getConfig(WeaverConfig *out_config) {
+ ALOGD("Weaver::getConfig");
+
+ if (out_config == NULL) {
+ ALOGE("Invalid param");
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Null pointer passed");
+ }
+ memset(out_config, 0, sizeof(WeaverConfig));
+
+ if (pInterface == NULL) {
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Weaver interface not defined");
+ }
+ SlotInfo slotInfo;
+ Status_Weaver status = pInterface->GetSlots(slotInfo);
+ if (status == WEAVER_STATUS_OK) {
+ out_config->slots = slotInfo.slots;
+ out_config->keySize = slotInfo.keySize;
+ out_config->valueSize = slotInfo.valueSize;
+ ALOGD("Weaver Success for getSlots Slots :(%d)", out_config->slots);
+ return ScopedAStatus::ok();
+ } else {
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Failed to retrieve slots info");
+ }
+}
+
+ScopedAStatus Weaver::read(int32_t in_slotId, const vector<uint8_t> &in_key,
+ WeaverReadResponse *out_response) {
+
+ ALOGD("Weaver::read slot %d", in_slotId);
+ if (out_response == NULL) {
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Null pointer passed");
+ }
+ if (in_key.empty()) {
+ out_response->status = WeaverReadStatus::FAILED;
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Empty key input passed");
+ }
+ if (pInterface == NULL) {
+ out_response->status = WeaverReadStatus::FAILED;
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Weaver interface not defined");
+ }
+ memset(out_response, 0, sizeof(WeaverReadResponse));
+
+ ReadRespInfo readInfo;
+ ScopedAStatus retStatus;
+ Status_Weaver status;
+
+ status = pInterface->Read(in_slotId, in_key, readInfo);
+ switch (status) {
+ case WEAVER_STATUS_OK:
+ ALOGD("Read slot %d OK", in_slotId);
+ out_response->value = readInfo.value;
+ out_response->status = WeaverReadStatus::OK;
+ retStatus = ScopedAStatus::ok();
+ break;
+ case WEAVER_STATUS_INCORRECT_KEY:
+ ALOGE("Read Incorrect Key");
+ out_response->value.resize(0);
+ out_response->timeout = readInfo.timeout;
+ out_response->status = WeaverReadStatus::INCORRECT_KEY;
+ retStatus = ScopedAStatus::ok();
+ break;
+ case WEAVER_STATUS_THROTTLE:
+ ALOGE("Read WEAVER_THROTTLE");
+ out_response->value.resize(0);
+ out_response->timeout = readInfo.timeout;
+ out_response->status = WeaverReadStatus::THROTTLE;
+ retStatus = ScopedAStatus::ok();
+ break;
+ default:
+ out_response->timeout = 0;
+ out_response->value.resize(0);
+ out_response->status = WeaverReadStatus::FAILED;
+ retStatus = ScopedAStatus::ok();
+ break;
+ }
+ return retStatus;
+}
+
+ScopedAStatus Weaver::write(int32_t in_slotId, const vector<uint8_t> &in_key,
+ const vector<uint8_t> &in_value) {
+ ALOGD("Weaver::write slot %d", in_slotId);
+ if (in_key.empty() || in_value.empty()) {
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Invalid parameters passed");
+ }
+ if (pInterface == NULL) {
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ STATUS_FAILED, "Weaver interface not defined");
+ }
+ if (pInterface->Write(in_slotId, in_key, in_value) == WEAVER_STATUS_OK) {
+ ALOGD("Write slot %d OK", in_slotId);
+ return ScopedAStatus::ok();
+ } else {
+ return ScopedAStatus::fromServiceSpecificErrorWithMessage(STATUS_FAILED,
+ "Unknown error");
+ }
+}
+
+} // namespace weaver
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/aidl_impl/Weaver.h b/aidl_impl/Weaver.h
new file mode 100644
index 0000000..1eaa5cc
--- /dev/null
+++ b/aidl_impl/Weaver.h
@@ -0,0 +1,51 @@
+/******************************************************************************
+ *
+ * Copyright 2023 NXP
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+#pragma once
+
+#include <aidl/android/hardware/weaver/BnWeaver.h>
+#include <weaver-impl.h>
+#include <weaver_interface.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace weaver {
+
+using ::aidl::android::hardware::weaver::WeaverConfig;
+using ::aidl::android::hardware::weaver::WeaverReadResponse;
+using ::ndk::ScopedAStatus;
+using std::vector;
+
+struct Weaver : public BnWeaver {
+public:
+ Weaver();
+ // Methods from ::android::hardware::weaver::IWeaver follow.
+ ScopedAStatus getConfig(WeaverConfig *_aidl_return) override;
+ ScopedAStatus read(int32_t in_slotId, const vector<uint8_t> &in_key,
+ WeaverReadResponse *_aidl_return) override;
+ ScopedAStatus write(int32_t in_slotId, const vector<uint8_t> &in_key,
+ const vector<uint8_t> &in_value) override;
+
+private:
+ WeaverInterface *pInterface = nullptr;
+};
+
+} // namespace weaver
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/aidl_impl/android.hardware.weaver-service.nxp.rc b/aidl_impl/android.hardware.weaver-service.nxp.rc
new file mode 100644
index 0000000..5516e65
--- /dev/null
+++ b/aidl_impl/android.hardware.weaver-service.nxp.rc
@@ -0,0 +1,4 @@
+service vendor.weaver_nxp /vendor/bin/hw/android.hardware.weaver-service.nxp
+ class hal
+ user vendor_nxp_weaver
+ group system drmrpc
diff --git a/aidl_impl/android.hardware.weaver-service.nxp.xml b/aidl_impl/android.hardware.weaver-service.nxp.xml
new file mode 100644
index 0000000..bfe4396
--- /dev/null
+++ b/aidl_impl/android.hardware.weaver-service.nxp.xml
@@ -0,0 +1,10 @@
+<manifest version="1.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.weaver</name>
+ <version>2</version>
+ <interface>
+ <name>IWeaver</name>
+ <instance>default</instance>
+ </interface>
+ </hal>
+</manifest>
diff --git a/aidl_impl/service.cpp b/aidl_impl/service.cpp
new file mode 100644
index 0000000..570f427
--- /dev/null
+++ b/aidl_impl/service.cpp
@@ -0,0 +1,44 @@
+/******************************************************************************
+ *
+ * Copyright 2023 NXP
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+#include "Weaver.h"
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <log/log.h>
+
+using ::aidl::android::hardware::weaver::Weaver;
+
+int main() {
+ try {
+ ABinderProcess_setThreadPoolMaxThreadCount(0);
+ std::shared_ptr<Weaver> weaver = ndk::SharedRefBase::make<Weaver>();
+
+ const std::string instance =
+ std::string() + Weaver::descriptor + "/default";
+ binder_status_t status =
+ AServiceManager_addService(weaver->asBinder().get(), instance.c_str());
+ CHECK(status == STATUS_OK);
+
+ ABinderProcess_joinThreadPool();
+ } catch (std::__1::ios_base::failure &e) {
+ ALOGE("ios failure Exception occurred = %s ", e.what());
+ } catch (std::__1::system_error &e) {
+ ALOGE("system error Exception occurred = %s ", e.what());
+ }
+ return -1; // Should never be reached
+}