From 6efa74efa32db5f539cd98275a6db64ebab16851 Mon Sep 17 00:00:00 2001 From: jrior001 Date: Fri, 22 Sep 2017 19:22:25 -0400 Subject: lineage/interfaces: Add bcm2709x changes to Nfc impl Convert to android.hardware.nfc@1.0-impl-bcm and change to checking the BCM2079X HAL ID Change-Id: I4dfe232363ae6141020715ba98918b99c556f8ff --- nfc/1.0-bcm/Android.bp | 18 +++++++++ nfc/1.0-bcm/Nfc.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ nfc/1.0-bcm/Nfc.h | 76 +++++++++++++++++++++++++++++++++++ nfc/1.0/Android.bp | 18 --------- nfc/1.0/Nfc.cpp | 107 ------------------------------------------------- nfc/1.0/Nfc.h | 76 ----------------------------------- nfc/Android.bp | 2 +- 7 files changed, 202 insertions(+), 202 deletions(-) create mode 100644 nfc/1.0-bcm/Android.bp create mode 100644 nfc/1.0-bcm/Nfc.cpp create mode 100644 nfc/1.0-bcm/Nfc.h delete mode 100644 nfc/1.0/Android.bp delete mode 100644 nfc/1.0/Nfc.cpp delete mode 100644 nfc/1.0/Nfc.h diff --git a/nfc/1.0-bcm/Android.bp b/nfc/1.0-bcm/Android.bp new file mode 100644 index 0000000..f533a1d --- /dev/null +++ b/nfc/1.0-bcm/Android.bp @@ -0,0 +1,18 @@ +cc_library_shared { + name: "android.hardware.nfc@1.0-impl-bcm", + defaults: ["hidl_defaults"], + relative_install_path: "hw", + proprietary: true, + srcs: ["Nfc.cpp"], + shared_libs: [ + "liblog", + "libcutils", + "libhardware", + "libbase", + "libcutils", + "libutils", + "libhidlbase", + "libhidltransport", + "android.hardware.nfc@1.0", + ], +} diff --git a/nfc/1.0-bcm/Nfc.cpp b/nfc/1.0-bcm/Nfc.cpp new file mode 100644 index 0000000..1b5637a --- /dev/null +++ b/nfc/1.0-bcm/Nfc.cpp @@ -0,0 +1,107 @@ +#define LOG_TAG "android.hardware.nfc@1.0-impl" + +#include + +#include +#include +#include "Nfc.h" + +namespace android { +namespace hardware { +namespace nfc { +namespace V1_0 { +namespace implementation { + +sp Nfc::mCallback = nullptr; + +Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device), + mDeathRecipient(new NfcDeathRecipient(this)) { +} + +// Methods from ::android::hardware::nfc::V1_0::INfc follow. +::android::hardware::Return Nfc::open(const sp& clientCallback) { + mCallback = clientCallback; + + if (mDevice == nullptr || mCallback == nullptr) { + return NfcStatus::FAILED; + } + mCallback->linkToDeath(mDeathRecipient, 0 /*cookie*/); + int ret = mDevice->open(mDevice, eventCallback, dataCallback); + return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; +} + +::android::hardware::Return Nfc::write(const hidl_vec& data) { + if (mDevice == nullptr) { + return -1; + } + return mDevice->write(mDevice, data.size(), &data[0]); +} + +::android::hardware::Return Nfc::coreInitialized(const hidl_vec& data) { + hidl_vec copy = data; + + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + int ret = mDevice->core_initialized(mDevice, ©[0]); + return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; +} + +::android::hardware::Return Nfc::prediscover() { + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + +::android::hardware::Return Nfc::close() { + if (mDevice == nullptr || mCallback == nullptr) { + return NfcStatus::FAILED; + } + mCallback->unlinkToDeath(mDeathRecipient); + return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + +::android::hardware::Return Nfc::controlGranted() { + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + +::android::hardware::Return Nfc::powerCycle() { + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + + +INfc* HIDL_FETCH_INfc(const char * /*name*/) { + nfc_nci_device_t* nfc_device; + int ret = 0; + const hw_module_t* hw_module = nullptr; + + ret = hw_get_module (NFC_NCI_BCM2079X_HARDWARE_MODULE_ID, &hw_module); + if (ret == 0) { + ret = nfc_nci_open (hw_module, &nfc_device); + if (ret != 0) { + ALOGE ("nfc_nci_open failed: %d", ret); + } + } + else + ALOGE ("hw_get_module %s failed: %d", NFC_NCI_BCM2079X_HARDWARE_MODULE_ID, ret); + + if (ret == 0) { + return new Nfc(nfc_device); + } else { + ALOGE("Passthrough failed to load legacy HAL."); + return nullptr; + } +} + +} // namespace implementation +} // namespace V1_0 +} // namespace nfc +} // namespace hardware +} // namespace android diff --git a/nfc/1.0-bcm/Nfc.h b/nfc/1.0-bcm/Nfc.h new file mode 100644 index 0000000..d8787fd --- /dev/null +++ b/nfc/1.0-bcm/Nfc.h @@ -0,0 +1,76 @@ +#ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H +#define ANDROID_HARDWARE_NFC_V1_0_NFC_H + +#include +#include +#include +#include +namespace android { +namespace hardware { +namespace nfc { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::nfc::V1_0::INfc; +using ::android::hardware::nfc::V1_0::INfcClientCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct NfcDeathRecipient : hidl_death_recipient { + NfcDeathRecipient(const sp nfc) : mNfc(nfc) { + } + + virtual void serviceDied(uint64_t /*cookie*/, const wp<::android::hidl::base::V1_0::IBase>& /*who*/) { + mNfc->close(); + } + sp mNfc; +}; + +struct Nfc : public INfc { + Nfc(nfc_nci_device_t* device); + ::android::hardware::Return open(const sp& clientCallback) override; + ::android::hardware::Return write(const hidl_vec& data) override; + ::android::hardware::Return coreInitialized(const hidl_vec& data) override; + ::android::hardware::Return prediscover() override; + ::android::hardware::Return close() override; + ::android::hardware::Return controlGranted() override; + ::android::hardware::Return powerCycle() override; + + static void eventCallback(uint8_t event, uint8_t status) { + if (mCallback != nullptr) { + auto ret = mCallback->sendEvent( + (::android::hardware::nfc::V1_0::NfcEvent) event, + (::android::hardware::nfc::V1_0::NfcStatus) status); + if (!ret.isOk()) { + ALOGW("Failed to call back into NFC process."); + } + } + } + static void dataCallback(uint16_t data_len, uint8_t* p_data) { + hidl_vec data; + data.setToExternal(p_data, data_len); + if (mCallback != nullptr) { + auto ret = mCallback->sendData(data); + if (!ret.isOk()) { + ALOGW("Failed to call back into NFC process."); + } + } + } + private: + static sp mCallback; + const nfc_nci_device_t* mDevice; + sp mDeathRecipient; +}; + +extern "C" INfc* HIDL_FETCH_INfc(const char* name); + +} // namespace implementation +} // namespace V1_0 +} // namespace nfc +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H diff --git a/nfc/1.0/Android.bp b/nfc/1.0/Android.bp deleted file mode 100644 index a157f86..0000000 --- a/nfc/1.0/Android.bp +++ /dev/null @@ -1,18 +0,0 @@ -cc_library_shared { - name: "android.hardware.nfc@1.0-impl", - defaults: ["hidl_defaults"], - relative_install_path: "hw", - proprietary: true, - srcs: ["Nfc.cpp"], - shared_libs: [ - "liblog", - "libcutils", - "libhardware", - "libbase", - "libcutils", - "libutils", - "libhidlbase", - "libhidltransport", - "android.hardware.nfc@1.0", - ], -} diff --git a/nfc/1.0/Nfc.cpp b/nfc/1.0/Nfc.cpp deleted file mode 100644 index d337a36..0000000 --- a/nfc/1.0/Nfc.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#define LOG_TAG "android.hardware.nfc@1.0-impl" - -#include - -#include -#include -#include "Nfc.h" - -namespace android { -namespace hardware { -namespace nfc { -namespace V1_0 { -namespace implementation { - -sp Nfc::mCallback = nullptr; - -Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device), - mDeathRecipient(new NfcDeathRecipient(this)) { -} - -// Methods from ::android::hardware::nfc::V1_0::INfc follow. -::android::hardware::Return Nfc::open(const sp& clientCallback) { - mCallback = clientCallback; - - if (mDevice == nullptr || mCallback == nullptr) { - return NfcStatus::FAILED; - } - mCallback->linkToDeath(mDeathRecipient, 0 /*cookie*/); - int ret = mDevice->open(mDevice, eventCallback, dataCallback); - return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; -} - -::android::hardware::Return Nfc::write(const hidl_vec& data) { - if (mDevice == nullptr) { - return -1; - } - return mDevice->write(mDevice, data.size(), &data[0]); -} - -::android::hardware::Return Nfc::coreInitialized(const hidl_vec& data) { - hidl_vec copy = data; - - if (mDevice == nullptr) { - return NfcStatus::FAILED; - } - int ret = mDevice->core_initialized(mDevice, ©[0]); - return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; -} - -::android::hardware::Return Nfc::prediscover() { - if (mDevice == nullptr) { - return NfcStatus::FAILED; - } - return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; -} - -::android::hardware::Return Nfc::close() { - if (mDevice == nullptr || mCallback == nullptr) { - return NfcStatus::FAILED; - } - mCallback->unlinkToDeath(mDeathRecipient); - return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; -} - -::android::hardware::Return Nfc::controlGranted() { - if (mDevice == nullptr) { - return NfcStatus::FAILED; - } - return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; -} - -::android::hardware::Return Nfc::powerCycle() { - if (mDevice == nullptr) { - return NfcStatus::FAILED; - } - return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; -} - - -INfc* HIDL_FETCH_INfc(const char * /*name*/) { - nfc_nci_device_t* nfc_device; - int ret = 0; - const hw_module_t* hw_module = nullptr; - - ret = hw_get_module (NFC_NCI_HARDWARE_MODULE_ID, &hw_module); - if (ret == 0) { - ret = nfc_nci_open (hw_module, &nfc_device); - if (ret != 0) { - ALOGE ("nfc_nci_open failed: %d", ret); - } - } - else - ALOGE ("hw_get_module %s failed: %d", NFC_NCI_HARDWARE_MODULE_ID, ret); - - if (ret == 0) { - return new Nfc(nfc_device); - } else { - ALOGE("Passthrough failed to load legacy HAL."); - return nullptr; - } -} - -} // namespace implementation -} // namespace V1_0 -} // namespace nfc -} // namespace hardware -} // namespace android diff --git a/nfc/1.0/Nfc.h b/nfc/1.0/Nfc.h deleted file mode 100644 index d8787fd..0000000 --- a/nfc/1.0/Nfc.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H -#define ANDROID_HARDWARE_NFC_V1_0_NFC_H - -#include -#include -#include -#include -namespace android { -namespace hardware { -namespace nfc { -namespace V1_0 { -namespace implementation { - -using ::android::hardware::nfc::V1_0::INfc; -using ::android::hardware::nfc::V1_0::INfcClientCallback; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::hidl_vec; -using ::android::hardware::hidl_string; -using ::android::sp; - -struct NfcDeathRecipient : hidl_death_recipient { - NfcDeathRecipient(const sp nfc) : mNfc(nfc) { - } - - virtual void serviceDied(uint64_t /*cookie*/, const wp<::android::hidl::base::V1_0::IBase>& /*who*/) { - mNfc->close(); - } - sp mNfc; -}; - -struct Nfc : public INfc { - Nfc(nfc_nci_device_t* device); - ::android::hardware::Return open(const sp& clientCallback) override; - ::android::hardware::Return write(const hidl_vec& data) override; - ::android::hardware::Return coreInitialized(const hidl_vec& data) override; - ::android::hardware::Return prediscover() override; - ::android::hardware::Return close() override; - ::android::hardware::Return controlGranted() override; - ::android::hardware::Return powerCycle() override; - - static void eventCallback(uint8_t event, uint8_t status) { - if (mCallback != nullptr) { - auto ret = mCallback->sendEvent( - (::android::hardware::nfc::V1_0::NfcEvent) event, - (::android::hardware::nfc::V1_0::NfcStatus) status); - if (!ret.isOk()) { - ALOGW("Failed to call back into NFC process."); - } - } - } - static void dataCallback(uint16_t data_len, uint8_t* p_data) { - hidl_vec data; - data.setToExternal(p_data, data_len); - if (mCallback != nullptr) { - auto ret = mCallback->sendData(data); - if (!ret.isOk()) { - ALOGW("Failed to call back into NFC process."); - } - } - } - private: - static sp mCallback; - const nfc_nci_device_t* mDevice; - sp mDeathRecipient; -}; - -extern "C" INfc* HIDL_FETCH_INfc(const char* name); - -} // namespace implementation -} // namespace V1_0 -} // namespace nfc -} // namespace hardware -} // namespace android - -#endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H diff --git a/nfc/Android.bp b/nfc/Android.bp index 58a4473..bb37fae 100644 --- a/nfc/Android.bp +++ b/nfc/Android.bp @@ -1,3 +1,3 @@ subdirs = [ - "1.0", + "1.0-bcm", ] -- cgit v1.2.3