blob: ab95d064e53e4ba6ac72f6d0b6adf162c09c5142 [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
Ruchi Kandoi461dedd2017-11-10 08:22:48 -080022struct Nfc : public INfc, public hidl_death_recipient {
23 Nfc(nfc_nci_device_t* device);
24 ::android::hardware::Return<NfcStatus> open(
25 const sp<INfcClientCallback>& clientCallback) override;
26 ::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
27 ::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
28 ::android::hardware::Return<NfcStatus> prediscover() override;
29 ::android::hardware::Return<NfcStatus> close() override;
30 ::android::hardware::Return<NfcStatus> controlGranted() override;
31 ::android::hardware::Return<NfcStatus> powerCycle() override;
32
33 static void eventCallback(uint8_t event, uint8_t status) {
34 if (mCallback != nullptr) {
35 auto ret = mCallback->sendEvent((::android::hardware::nfc::V1_0::NfcEvent)event,
36 (::android::hardware::nfc::V1_0::NfcStatus)status);
37 if (!ret.isOk()) {
38 ALOGW("Failed to call back into NFC process.");
39 }
40 }
41 }
42 static void dataCallback(uint16_t data_len, uint8_t* p_data) {
43 hidl_vec<uint8_t> data;
44 data.setToExternal(p_data, data_len);
45 if (mCallback != nullptr) {
46 auto ret = mCallback->sendData(data);
47 if (!ret.isOk()) {
48 ALOGW("Failed to call back into NFC process.");
49 }
50 }
Martijn Coenen85ca1302017-02-23 17:24:20 +010051 }
52
Ruchi Kandoi461dedd2017-11-10 08:22:48 -080053 virtual void serviceDied(uint64_t /*cookie*/,
54 const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
55 close();
Martijn Coenen85ca1302017-02-23 17:24:20 +010056 }
Martijn Coenen85ca1302017-02-23 17:24:20 +010057
Ruchi Kandoi461dedd2017-11-10 08:22:48 -080058 private:
Iliyan Malchev678fa1f2016-09-22 15:53:53 -070059 static sp<INfcClientCallback> mCallback;
60 const nfc_nci_device_t* mDevice;
61};
62
63extern "C" INfc* HIDL_FETCH_INfc(const char* name);
64
65} // namespace implementation
66} // namespace V1_0
67} // namespace nfc
68} // namespace hardware
69} // namespace android
70
Steven Moreland33e87b82016-11-22 15:34:39 -080071#endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H