summaryrefslogtreecommitdiffstats
path: root/nfc/1.0/default/Nfc.cpp
blob: 44c8e423324d982c50725dd2cf7b233380caf628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define LOG_TAG "android.hardware.nfc@1.0-impl"
#include <android/log.h>

#include <hardware/hardware.h>
#include <hardware/nfc.h>
#include "Nfc.h"

namespace android {
namespace hardware {
namespace nfc {
namespace V1_0 {
namespace implementation {

sp<INfcClientCallback> Nfc::mCallback = NULL;

Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) {
}

// Methods from ::android::hardware::nfc::V1_0::INfc follow.
::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback)  {
    mCallback = clientCallback;
    int ret = mDevice->open(mDevice, eventCallback, dataCallback);
    return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
}

::android::hardware::Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data)  {
    return mDevice->write(mDevice, data.size(), &data[0]);
}

::android::hardware::Return<NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data)  {
    hidl_vec<uint8_t> copy = data;
    int ret = mDevice->core_initialized(mDevice, &copy[0]);
    return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
}

::android::hardware::Return<NfcStatus> Nfc::prediscover()  {
    return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}

::android::hardware::Return<NfcStatus> Nfc::close()  {
    return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}

::android::hardware::Return<NfcStatus> Nfc::controlGranted()  {
    return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}

::android::hardware::Return<NfcStatus> Nfc::powerCycle()  {
    return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}


INfc* HIDL_FETCH_INfc(const char *hal) {
    nfc_nci_device_t* nfc_device;
    int ret = 0;
    const hw_module_t* hw_module = NULL;

    ret = hw_get_module (hal, &hw_module);
    if (ret == 0)
    {
        ret = nfc_nci_open (hw_module, &nfc_device);
        if (ret != 0) {
            ALOGE ("nfc_nci_open %s failed: %d", hal, ret);
        }
    }
    else
        ALOGE ("hw_get_module %s failed: %d", hal, 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