blob: bee374d587975950dceb4d66496bf0abdb360a02 [file] [log] [blame]
Iliyan Malchev3db0f602016-09-26 09:57:20 -07001#define LOG_TAG "android.hardware.nfc@1.0-impl"
2#include <utils/Log.h>
3
Iliyan Malchev678fa1f2016-09-22 15:53:53 -07004#include <hardware/hardware.h>
5#include <hardware/nfc.h>
6#include "Nfc.h"
7
8namespace android {
9namespace hardware {
10namespace nfc {
11namespace V1_0 {
12namespace implementation {
13
14sp<INfcClientCallback> Nfc::mCallback = NULL;
15
16Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) {
17}
18
19// Methods from ::android::hardware::nfc::V1_0::INfc follow.
Ruchi Kandoi51068e02016-11-18 14:11:33 -080020::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070021 mCallback = clientCallback;
Ruchi Kandoi51068e02016-11-18 14:11:33 -080022 int ret = mDevice->open(mDevice, eventCallback, dataCallback);
23 return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070024}
25
Ruchi Kandoi51068e02016-11-18 14:11:33 -080026::android::hardware::Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data) {
Steven Morelanda74426d2016-09-26 12:41:23 -070027 return mDevice->write(mDevice, data.size(), &data[0]);
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070028}
29
Ruchi Kandoi51068e02016-11-18 14:11:33 -080030::android::hardware::Return<NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070031 hidl_vec<uint8_t> copy = data;
Ruchi Kandoi51068e02016-11-18 14:11:33 -080032 int ret = mDevice->core_initialized(mDevice, &copy[0]);
33 return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070034}
35
Ruchi Kandoi51068e02016-11-18 14:11:33 -080036::android::hardware::Return<NfcStatus> Nfc::prediscover() {
37 return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070038}
39
Ruchi Kandoi51068e02016-11-18 14:11:33 -080040::android::hardware::Return<NfcStatus> Nfc::close() {
41 return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070042}
43
Ruchi Kandoi51068e02016-11-18 14:11:33 -080044::android::hardware::Return<NfcStatus> Nfc::controlGranted() {
45 return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070046}
47
Ruchi Kandoi51068e02016-11-18 14:11:33 -080048::android::hardware::Return<NfcStatus> Nfc::powerCycle() {
49 return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070050}
51
52
53INfc* HIDL_FETCH_INfc(const char *hal) {
54 nfc_nci_device_t* nfc_device;
55 int ret = 0;
56 const hw_module_t* hw_module = NULL;
57
58 ret = hw_get_module (hal, &hw_module);
59 if (ret == 0)
60 {
61 ret = nfc_nci_open (hw_module, &nfc_device);
62 if (ret != 0) {
63 ALOGE ("nfc_nci_open %s failed: %d", hal, ret);
64 }
65 }
66 else
67 ALOGE ("hw_get_module %s failed: %d", hal, ret);
68
69 if (ret == 0) {
70 return new Nfc(nfc_device);
71 } else {
72 ALOGE("Passthrough failed to load legacy HAL.");
73 return nullptr;
74 }
75}
76
77} // namespace implementation
78} // namespace V1_0
79} // namespace nfc
80} // namespace hardware
81} // namespace android