1 #ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H 2 #define ANDROID_HARDWARE_NFC_V1_0_NFC_H 3 4 #include <android/hardware/nfc/1.0/INfc.h> 5 #include <hidl/Status.h> 6 #include <hardware/hardware.h> 7 #include <hardware/nfc.h> 8 namespace android { 9 namespace hardware { 10 namespace nfc { 11 namespace V1_0 { 12 namespace implementation { 13 14 using ::android::hardware::nfc::V1_0::INfc; 15 using ::android::hardware::nfc::V1_0::INfcClientCallback; 16 using ::android::hardware::Return; 17 using ::android::hardware::Void; 18 using ::android::hardware::hidl_vec; 19 using ::android::hardware::hidl_string; 20 using ::android::sp; 21 22 struct NfcDeathRecipient : hidl_death_recipient { NfcDeathRecipientNfcDeathRecipient23 NfcDeathRecipient(const sp<INfc> nfc) : mNfc(nfc) { 24 } 25 serviceDiedNfcDeathRecipient26 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 32 struct Nfc : public INfc { 33 Nfc(nfc_nci_device_t* device); 34 ::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; 41 eventCallbackNfc42 static void eventCallback(uint8_t event, uint8_t status) { 43 if (mCallback != nullptr) { 44 auto ret = mCallback->sendEvent( 45 (::android::hardware::nfc::V1_0::NfcEvent) event, 46 (::android::hardware::nfc::V1_0::NfcStatus) status); 47 if (!ret.isOk()) { 48 ALOGW("Failed to call back into NFC process."); 49 } 50 } 51 } dataCallbackNfc52 static void dataCallback(uint16_t data_len, uint8_t* p_data) { 53 hidl_vec<uint8_t> data; 54 data.setToExternal(p_data, data_len); 55 if (mCallback != nullptr) { 56 auto ret = mCallback->sendData(data); 57 if (!ret.isOk()) { 58 ALOGW("Failed to call back into NFC process."); 59 } 60 } 61 } 62 private: 63 static sp<INfcClientCallback> mCallback; 64 const nfc_nci_device_t* mDevice; 65 sp<NfcDeathRecipient> mDeathRecipient; 66 }; 67 68 extern "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 76 #endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H 77