1 /****************************************************************************** 2 * 3 * Copyright 2019 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #ifndef ANDROID_HARDWARE_NFC_V1_2_NFC_H 20 #define ANDROID_HARDWARE_NFC_V1_2_NFC_H 21 22 #include <android/hardware/nfc/1.2/INfc.h> 23 #include <android/hardware/nfc/1.2/types.h> 24 #include <hidl/MQDescriptor.h> 25 #include <hidl/Status.h> 26 #include <log/log.h> 27 28 namespace android { 29 namespace hardware { 30 namespace nfc { 31 namespace V1_2 { 32 namespace implementation { 33 34 using ::android::sp; 35 using ::android::hardware::hidl_array; 36 using ::android::hardware::hidl_memory; 37 using ::android::hardware::hidl_string; 38 using ::android::hardware::hidl_vec; 39 using ::android::hardware::Return; 40 using ::android::hardware::Void; 41 using ::android::hardware::nfc::V1_2::INfc; 42 using ::android::hidl::base::V1_0::IBase; 43 struct Nfc : public V1_2::INfc, public hidl_death_recipient { 44 public: 45 // Methods from ::android::hardware::nfc::V1_0::INfc follow. 46 Return<V1_0::NfcStatus> open( 47 const sp<V1_0::INfcClientCallback>& clientCallback) override; 48 Return<V1_0::NfcStatus> open_1_1( 49 const sp<V1_1::INfcClientCallback>& clientCallback) override; 50 Return<uint32_t> write(const hidl_vec<uint8_t>& data) override; 51 Return<V1_0::NfcStatus> coreInitialized( 52 const hidl_vec<uint8_t>& data) override; 53 Return<V1_0::NfcStatus> prediscover() override; 54 Return<V1_0::NfcStatus> close() override; 55 Return<V1_0::NfcStatus> controlGranted() override; 56 Return<V1_0::NfcStatus> powerCycle() override; 57 58 // Methods from ::android::hardware::nfc::V1_1::INfc follow. 59 Return<void> factoryReset(); 60 Return<V1_0::NfcStatus> closeForPowerOffCase(); 61 Return<void> getConfig(getConfig_cb config); 62 Return<void> getConfig_1_2(getConfig_1_2_cb config); 63 64 // Methods from ::android::hidl::base::V1_0::IBase follow. 65 eventCallbackNfc66 static void eventCallback(uint8_t event, uint8_t status) { 67 if (mCallbackV1_1 != nullptr) { 68 auto ret = mCallbackV1_1->sendEvent_1_1((V1_1::NfcEvent)event, 69 (V1_0::NfcStatus)status); 70 if (!ret.isOk()) { 71 ALOGW("failed to send event!!!"); 72 } 73 } else if (mCallbackV1_0 != nullptr) { 74 auto ret = mCallbackV1_0->sendEvent((V1_0::NfcEvent)event, 75 (V1_0::NfcStatus)status); 76 if (!ret.isOk()) { 77 ALOGE("failed to send event!!!"); 78 } 79 } 80 } 81 dataCallbackNfc82 static void dataCallback(uint16_t data_len, uint8_t* p_data) { 83 hidl_vec<uint8_t> data; 84 data.setToExternal(p_data, data_len); 85 if (mCallbackV1_1 != nullptr) { 86 auto ret = mCallbackV1_1->sendData(data); 87 if (!ret.isOk()) { 88 ALOGW("failed to send data!!!"); 89 } 90 } else if (mCallbackV1_0 != nullptr) { 91 auto ret = mCallbackV1_0->sendData(data); 92 if (!ret.isOk()) { 93 ALOGE("failed to send data!!!"); 94 } 95 } 96 } 97 serviceDiedNfc98 virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) { 99 close(); 100 } 101 102 private: 103 static sp<V1_1::INfcClientCallback> mCallbackV1_1; 104 static sp<V1_0::INfcClientCallback> mCallbackV1_0; 105 }; 106 107 } // namespace implementation 108 } // namespace V1_2 109 } // namespace nfc 110 } // namespace hardware 111 } // namespace android 112 113 #endif // ANDROID_HARDWARE_NFC_V1_2_NFC_H 114