#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) {} // 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(this, 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(this); 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