summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohit Rangwani <rrangwan@codeaurora.org>2018-04-03 16:19:10 +0530
committerGerrit - the friendly Code Review server <code-review@localhost>2018-05-30 22:08:45 -0700
commit748bc6511fa2ad20488a1a9dd291ef8a27eef24d (patch)
tree79d693fff15adce9d982cf83bb23880860658e29
parentf857499763a2022963274b8686c558f230c6f0d1 (diff)
downloadandroid_vendor_nxp_opensource_hidlimpl-748bc6511fa2ad20488a1a9dd291ef8a27eef24d.tar.gz
android_vendor_nxp_opensource_hidlimpl-748bc6511fa2ad20488a1a9dd291ef8a27eef24d.tar.bz2
android_vendor_nxp_opensource_hidlimpl-748bc6511fa2ad20488a1a9dd291ef8a27eef24d.zip
NFC: Add implementaion for 1.1 HAL
Add implementation for required methods to support 1.1 vendor HAL. Change-Id: I4dca0b5515c9be0df2f43af21efb8d628dbd29f5
-rw-r--r--1.1/default/Nfc.cpp140
-rw-r--r--1.1/default/Nfc.h72
2 files changed, 162 insertions, 50 deletions
diff --git a/1.1/default/Nfc.cpp b/1.1/default/Nfc.cpp
index 6a16980..04c2ba2 100644
--- a/1.1/default/Nfc.cpp
+++ b/1.1/default/Nfc.cpp
@@ -1,3 +1,20 @@
+/******************************************************************************
+ *
+ * Copyright 2018 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.
+ *
+ ******************************************************************************/
/*
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
*
@@ -27,7 +44,19 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#define LOG_TAG "android.hardware.nfc@1.1-impl"
+
+#include <log/log.h>
#include "Nfc.h"
+extern "C" {
+#include "halimpl/inc/phNxpNciHal_Adaptation.h"
+}
+
+#define UNUSED(x) (void)(x)
+#define HALSTATUS_SUCCESS (0x0000)
+#define HALSTATUS_FAILED (0x00FF)
+
+typedef uint32_t HALSTATUS;
namespace android {
namespace hardware {
@@ -35,66 +64,103 @@ namespace nfc {
namespace V1_1 {
namespace implementation {
+sp<INfcClientCallback> Nfc::mCallback = nullptr;
+
// Methods from ::android::hardware::nfc::V1_0::INfc follow.
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::open(const sp<::android::hardware::nfc::V1_0::INfcClientCallback>& clientCallback) {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
+Return<V1_0::NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
+ ALOGD("Nfc::open Enter");
+ HALSTATUS status = HALSTATUS_FAILED;
+ if (clientCallback == nullptr) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ mCallback = clientCallback;
+ mCallback->linkToDeath(this, 0 /*cookie*/);
+ }
+
+ status = phNxpNciHal_open(eventCallback, dataCallback);
+ ALOGD("Nfc::open Exit");
+ if(status != HALSTATUS_SUCCESS) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ return V1_0::NfcStatus::OK;
+ }
}
Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data) {
- // TODO implement
- return uint32_t {};
+ hidl_vec<uint8_t> copy = data;
+ return phNxpNciHal_write(copy.size(), &copy[0]);
}
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
+Return<V1_0::NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
+ HALSTATUS status = HALSTATUS_FAILED;
+ hidl_vec<uint8_t> copy = data;
+ status = phNxpNciHal_core_initialized(&copy[0]);
+ if(status != HALSTATUS_SUCCESS) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ return V1_0::NfcStatus::OK;
+ }
}
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::prediscover() {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
+Return<V1_0::NfcStatus> Nfc::prediscover() {
+ HALSTATUS status = HALSTATUS_FAILED;
+ status = phNxpNciHal_pre_discover();
+ return V1_0::NfcStatus {};
}
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::close() {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
+Return<V1_0::NfcStatus> Nfc::close() {
+ HALSTATUS status = HALSTATUS_FAILED;
+
+ if (mCallback == nullptr) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ mCallback->unlinkToDeath(this);
+ }
+
+ status = phNxpNciHal_close();
+ if(status != HALSTATUS_SUCCESS) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ return V1_0::NfcStatus::OK;
+ }
}
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::controlGranted() {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
+Return<V1_0::NfcStatus> Nfc::controlGranted() {
+ HALSTATUS status = HALSTATUS_FAILED;
+ status = phNxpNciHal_control_granted();
+ if(status != HALSTATUS_SUCCESS) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ return V1_0::NfcStatus::OK;
+ }
}
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::powerCycle() {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
+Return<V1_0::NfcStatus> Nfc::powerCycle() {
+ HALSTATUS status = HALSTATUS_FAILED;
+ status = phNxpNciHal_power_cycle();
+ if(status != HALSTATUS_SUCCESS) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ return V1_0::NfcStatus::OK;
+ }
}
-
// Methods from ::android::hardware::nfc::V1_1::INfc follow.
Return<void> Nfc::factoryReset() {
- // TODO implement
+ phNxpNciHal_do_factory_reset();
return Void();
}
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::closeForPowerOffCase() {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
-}
-
-Return<::android::hardware::nfc::V1_0::NfcStatus> Nfc::open_1_1(const sp<::android::hardware::nfc::V1_1::INfcClientCallback>& clientCallback) {
- // TODO implement
- return ::android::hardware::nfc::V1_0::NfcStatus {};
+Return<V1_0::NfcStatus> Nfc::closeForPowerOffCase() {
+ HALSTATUS status = HALSTATUS_FAILED;
+ status = phNxpNciHal_shutdown();
+ if(status != HALSTATUS_SUCCESS) {
+ return V1_0::NfcStatus::FAILED;
+ } else {
+ return V1_0::NfcStatus::OK;
+ }
}
-
-// Methods from ::android::hidl::base::V1_0::IBase follow.
-
-//INfc* HIDL_FETCH_INfc(const char* /* name */) {
-// return new Nfc();
-//}
-
} // namespace implementation
} // namespace V1_1
} // namespace nfc
diff --git a/1.1/default/Nfc.h b/1.1/default/Nfc.h
index cc30d9a..c8f2b7d 100644
--- a/1.1/default/Nfc.h
+++ b/1.1/default/Nfc.h
@@ -1,3 +1,20 @@
+/******************************************************************************
+ *
+ * Copyright 2018 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.
+ *
+ ******************************************************************************/
/*
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
*
@@ -31,6 +48,7 @@
#define ANDROID_HARDWARE_NFC_V1_1_NFC_H
#include <android/hardware/nfc/1.1/INfc.h>
+#include <android/hardware/nfc/1.1/types.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
@@ -40,6 +58,9 @@ namespace nfc {
namespace V1_1 {
namespace implementation {
+using ::android::hidl::base::V1_0::IBase;
+using ::android::hardware::nfc::V1_0::INfc;
+using ::android::hardware::nfc::V1_0::INfcClientCallback;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
@@ -48,27 +69,52 @@ using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
-struct Nfc : public INfc {
+struct Nfc : public V1_1::INfc, public hidl_death_recipient {
+public:
// Methods from ::android::hardware::nfc::V1_0::INfc follow.
- Return<::android::hardware::nfc::V1_0::NfcStatus> open(const sp<::android::hardware::nfc::V1_0::INfcClientCallback>& clientCallback) override;
+ Return<V1_0::NfcStatus> open(const sp<INfcClientCallback>& clientCallback) override;
Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
- Return<::android::hardware::nfc::V1_0::NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
- Return<::android::hardware::nfc::V1_0::NfcStatus> prediscover() override;
- Return<::android::hardware::nfc::V1_0::NfcStatus> close() override;
- Return<::android::hardware::nfc::V1_0::NfcStatus> controlGranted() override;
- Return<::android::hardware::nfc::V1_0::NfcStatus> powerCycle() override;
+ Return<V1_0::NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
+ Return<V1_0::NfcStatus> prediscover() override;
+ Return<V1_0::NfcStatus> close() override;
+ Return<V1_0::NfcStatus> controlGranted() override;
+ Return<V1_0::NfcStatus> powerCycle() override;
// Methods from ::android::hardware::nfc::V1_1::INfc follow.
- Return<void> factoryReset() override;
- Return<::android::hardware::nfc::V1_0::NfcStatus> closeForPowerOffCase() override;
- Return<::android::hardware::nfc::V1_0::NfcStatus> open_1_1(const sp<::android::hardware::nfc::V1_1::INfcClientCallback>& clientCallback) override;
+ Return<void> factoryReset();
+ Return<V1_0::NfcStatus> closeForPowerOffCase();
// Methods from ::android::hidl::base::V1_0::IBase follow.
-};
-// FIXME: most likely delete, this is only for passthrough implementations
-// extern "C" INfc* HIDL_FETCH_INfc(const char* name);
+ static void eventCallback(uint8_t event, uint8_t status) {
+ if (mCallback != nullptr) {
+ auto ret = mCallback->sendEvent((V1_0::NfcEvent)event,
+ (V1_0::NfcStatus)status);
+ if (!ret.isOk()) {
+ ALOGW("failed to send event!!!");
+ }
+ }
+ }
+
+ static void dataCallback(uint16_t data_len, uint8_t* p_data) {
+ hidl_vec<uint8_t> data;
+ data.setToExternal(p_data, data_len);
+ if (mCallback != nullptr) {
+ auto ret = mCallback->sendData(data);
+ if (!ret.isOk()) {
+ ALOGW("failed to send data!!!");
+ }
+ }
+ }
+
+ virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) {
+ close();
+ }
+
+private:
+ static sp<INfcClientCallback> mCallback;
+};
} // namespace implementation
} // namespace V1_1