blob: 9023eccdf215026b5f240ae721dec9176db1986a [file] [log] [blame]
Iliyan Malchev678fa1f2016-09-22 15:53:53 -07001#include <hardware/hardware.h>
2#include <hardware/nfc.h>
3#include "Nfc.h"
4
5namespace android {
6namespace hardware {
7namespace nfc {
8namespace V1_0 {
9namespace implementation {
10
11sp<INfcClientCallback> Nfc::mCallback = NULL;
12
13Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) {
14}
15
16// Methods from ::android::hardware::nfc::V1_0::INfc follow.
17::android::hardware::Return<int32_t> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
18 mCallback = clientCallback;
19 return mDevice->open(mDevice, event_callback, data_callback);
20}
21
22::android::hardware::Return<int32_t> Nfc::write(const nfc_data_t& data) {
23 return mDevice->write(mDevice, data.data.size(), &data.data[0]);
24}
25
26::android::hardware::Return<int32_t> Nfc::core_initialized(const hidl_vec<uint8_t>& data) {
27 hidl_vec<uint8_t> copy = data;
28 return mDevice->core_initialized(mDevice, &copy[0]);
29}
30
31::android::hardware::Return<int32_t> Nfc::pre_discover() {
32 return mDevice->pre_discover(mDevice);
33}
34
35::android::hardware::Return<int32_t> Nfc::close() {
36 return mDevice->close(mDevice);
37}
38
39::android::hardware::Return<int32_t> Nfc::control_granted() {
40 return mDevice->control_granted(mDevice);
41}
42
43::android::hardware::Return<int32_t> Nfc::power_cycle() {
44 return mDevice->power_cycle(mDevice);
45}
46
47
48INfc* HIDL_FETCH_INfc(const char *hal) {
49 nfc_nci_device_t* nfc_device;
50 int ret = 0;
51 const hw_module_t* hw_module = NULL;
52
53 ret = hw_get_module (hal, &hw_module);
54 if (ret == 0)
55 {
56 ret = nfc_nci_open (hw_module, &nfc_device);
57 if (ret != 0) {
58 ALOGE ("nfc_nci_open %s failed: %d", hal, ret);
59 }
60 }
61 else
62 ALOGE ("hw_get_module %s failed: %d", hal, ret);
63
64 if (ret == 0) {
65 return new Nfc(nfc_device);
66 } else {
67 ALOGE("Passthrough failed to load legacy HAL.");
68 return nullptr;
69 }
70}
71
72} // namespace implementation
73} // namespace V1_0
74} // namespace nfc
75} // namespace hardware
76} // namespace android