blob: d8787fd0435a04967f53cb1c8842d1a90359a920 [file] [log] [blame]
Steven Moreland33e87b82016-11-22 15:34:39 -08001#ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H
2#define ANDROID_HARDWARE_NFC_V1_0_NFC_H
Iliyan Malchev678fa1f2016-09-22 15:53:53 -07003
4#include <android/hardware/nfc/1.0/INfc.h>
5#include <hidl/Status.h>
6#include <hardware/hardware.h>
7#include <hardware/nfc.h>
8namespace android {
9namespace hardware {
10namespace nfc {
11namespace V1_0 {
12namespace implementation {
13
14using ::android::hardware::nfc::V1_0::INfc;
15using ::android::hardware::nfc::V1_0::INfcClientCallback;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070016using ::android::hardware::Return;
17using ::android::hardware::Void;
18using ::android::hardware::hidl_vec;
19using ::android::hardware::hidl_string;
20using ::android::sp;
21
Martijn Coenen85ca1302017-02-23 17:24:20 +010022struct NfcDeathRecipient : hidl_death_recipient {
23 NfcDeathRecipient(const sp<INfc> nfc) : mNfc(nfc) {
24 }
25
26 virtual void serviceDied(uint64_t /*cookie*/, const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
27 mNfc->close();
28 }
29 sp<INfc> mNfc;
30};
31
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070032struct Nfc : public INfc {
33 Nfc(nfc_nci_device_t* device);
Ruchi Kandoi51068e02016-11-18 14:11:33 -080034 ::android::hardware::Return<NfcStatus> open(const sp<INfcClientCallback>& clientCallback) override;
35 ::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
36 ::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
37 ::android::hardware::Return<NfcStatus> prediscover() override;
38 ::android::hardware::Return<NfcStatus> close() override;
39 ::android::hardware::Return<NfcStatus> controlGranted() override;
40 ::android::hardware::Return<NfcStatus> powerCycle() override;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070041
Steven Morelanda74426d2016-09-26 12:41:23 -070042 static void eventCallback(uint8_t event, uint8_t status) {
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070043 if (mCallback != nullptr) {
Martijn Coenen85ca1302017-02-23 17:24:20 +010044 auto ret = mCallback->sendEvent(
Steven Morelanda74426d2016-09-26 12:41:23 -070045 (::android::hardware::nfc::V1_0::NfcEvent) event,
46 (::android::hardware::nfc::V1_0::NfcStatus) status);
Martijn Coenen85ca1302017-02-23 17:24:20 +010047 if (!ret.isOk()) {
48 ALOGW("Failed to call back into NFC process.");
49 }
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070050 }
51 }
Steven Morelanda74426d2016-09-26 12:41:23 -070052 static void dataCallback(uint16_t data_len, uint8_t* p_data) {
53 hidl_vec<uint8_t> data;
54 data.setToExternal(p_data, data_len);
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070055 if (mCallback != nullptr) {
Martijn Coenen85ca1302017-02-23 17:24:20 +010056 auto ret = mCallback->sendData(data);
57 if (!ret.isOk()) {
58 ALOGW("Failed to call back into NFC process.");
59 }
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070060 }
61 }
62 private:
63 static sp<INfcClientCallback> mCallback;
64 const nfc_nci_device_t* mDevice;
Martijn Coenen85ca1302017-02-23 17:24:20 +010065 sp<NfcDeathRecipient> mDeathRecipient;
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070066};
67
68extern "C" INfc* HIDL_FETCH_INfc(const char* name);
69
70} // namespace implementation
71} // namespace V1_0
72} // namespace nfc
73} // namespace hardware
74} // namespace android
75
Steven Moreland33e87b82016-11-22 15:34:39 -080076#endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H