blob: 9d05fc27919a27f0e9862926bae7398fb687bebd [file] [log] [blame]
Iliyan Malchev3db0f602016-09-26 09:57:20 -07001#define LOG_TAG "android.hardware.nfc@1.0-impl"
Mark Salyzyna4842ac2017-01-10 10:16:48 -08002
3#include <log/log.h>
Iliyan Malchev3db0f602016-09-26 09:57:20 -07004
Iliyan Malchev678fa1f2016-09-22 15:53:53 -07005#include <hardware/hardware.h>
6#include <hardware/nfc.h>
7#include "Nfc.h"
8
9namespace android {
10namespace hardware {
11namespace nfc {
12namespace V1_0 {
13namespace implementation {
14
15sp<INfcClientCallback> Nfc::mCallback = NULL;
16
17Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) {
18}
19
20// Methods from ::android::hardware::nfc::V1_0::INfc follow.
Ruchi Kandoi51068e02016-11-18 14:11:33 -080021::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070022 mCallback = clientCallback;
Ruchi Kandoi51068e02016-11-18 14:11:33 -080023 int ret = mDevice->open(mDevice, eventCallback, dataCallback);
24 return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070025}
26
Ruchi Kandoi51068e02016-11-18 14:11:33 -080027::android::hardware::Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data) {
Steven Morelanda74426d2016-09-26 12:41:23 -070028 return mDevice->write(mDevice, data.size(), &data[0]);
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070029}
30
Ruchi Kandoi51068e02016-11-18 14:11:33 -080031::android::hardware::Return<NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070032 hidl_vec<uint8_t> copy = data;
Ruchi Kandoi51068e02016-11-18 14:11:33 -080033 int ret = mDevice->core_initialized(mDevice, &copy[0]);
34 return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070035}
36
Ruchi Kandoi51068e02016-11-18 14:11:33 -080037::android::hardware::Return<NfcStatus> Nfc::prediscover() {
38 return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070039}
40
Ruchi Kandoi51068e02016-11-18 14:11:33 -080041::android::hardware::Return<NfcStatus> Nfc::close() {
42 return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070043}
44
Ruchi Kandoi51068e02016-11-18 14:11:33 -080045::android::hardware::Return<NfcStatus> Nfc::controlGranted() {
46 return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070047}
48
Ruchi Kandoi51068e02016-11-18 14:11:33 -080049::android::hardware::Return<NfcStatus> Nfc::powerCycle() {
50 return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070051}
52
53
Martijn Coenence2e6562017-01-12 11:37:25 +010054INfc* HIDL_FETCH_INfc(const char * /*name*/) {
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070055 nfc_nci_device_t* nfc_device;
56 int ret = 0;
57 const hw_module_t* hw_module = NULL;
58
Martijn Coenence2e6562017-01-12 11:37:25 +010059 ret = hw_get_module (NFC_NCI_HARDWARE_MODULE_ID, &hw_module);
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070060 if (ret == 0)
61 {
62 ret = nfc_nci_open (hw_module, &nfc_device);
63 if (ret != 0) {
Martijn Coenence2e6562017-01-12 11:37:25 +010064 ALOGE ("nfc_nci_open failed: %d", ret);
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070065 }
66 }
67 else
Martijn Coenence2e6562017-01-12 11:37:25 +010068 ALOGE ("hw_get_module failed: %d", ret);
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070069
70 if (ret == 0) {
71 return new Nfc(nfc_device);
72 } else {
73 ALOGE("Passthrough failed to load legacy HAL.");
74 return nullptr;
75 }
76}
77
78} // namespace implementation
79} // namespace V1_0
80} // namespace nfc
81} // namespace hardware
82} // namespace android