1 /****************************************************************************** 2 * 3 * Copyright 2019-2023 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::hidl::base::V1_0::IBase follow. 46 Return<void> debug(const hidl_handle& handle, 47 const hidl_vec<hidl_string>& options) override; 48 // Methods from ::android::hardware::nfc::V1_0::INfc follow. 49 Return<V1_0::NfcStatus> open( 50 const sp<V1_0::INfcClientCallback>& clientCallback) override; 51 Return<V1_0::NfcStatus> open_1_1( 52 const sp<V1_1::INfcClientCallback>& clientCallback) override; 53 Return<uint32_t> write(const hidl_vec<uint8_t>& data) override; 54 Return<V1_0::NfcStatus> coreInitialized( 55 const hidl_vec<uint8_t>& data) override; 56 Return<V1_0::NfcStatus> prediscover() override; 57 Return<V1_0::NfcStatus> close() override; 58 Return<V1_0::NfcStatus> controlGranted() override; 59 Return<V1_0::NfcStatus> powerCycle() override; 60 61 // Methods from ::android::hardware::nfc::V1_1::INfc follow. 62 Return<void> factoryReset(); 63 Return<V1_0::NfcStatus> closeForPowerOffCase(); 64 Return<void> getConfig(getConfig_cb config); 65 Return<void> getConfig_1_2(getConfig_1_2_cb config); 66 67 // Methods from ::android::hidl::base::V1_0::IBase follow. 68 eventCallbackNfc69 static void eventCallback(uint8_t event, uint8_t status) { 70 if (mCallbackV1_1 != nullptr) { 71 auto ret = mCallbackV1_1->sendEvent_1_1((V1_1::NfcEvent)event, 72 (V1_0::NfcStatus)status); 73 if (!ret.isOk()) { 74 ALOGW("failed to send event!!!"); 75 } 76 } else if (mCallbackV1_0 != nullptr) { 77 auto ret = mCallbackV1_0->sendEvent((V1_0::NfcEvent)event, 78 (V1_0::NfcStatus)status); 79 if (!ret.isOk()) { 80 ALOGE("failed to send event!!!"); 81 } 82 } 83 } 84 dataCallbackNfc85 static void dataCallback(uint16_t data_len, uint8_t* p_data) { 86 hidl_vec<uint8_t> data; 87 data.setToExternal(p_data, data_len); 88 if (mCallbackV1_1 != nullptr) { 89 auto ret = mCallbackV1_1->sendData(data); 90 if (!ret.isOk()) { 91 ALOGW("failed to send data!!!"); 92 } 93 } else if (mCallbackV1_0 != nullptr) { 94 auto ret = mCallbackV1_0->sendData(data); 95 if (!ret.isOk()) { 96 ALOGE("failed to send data!!!"); 97 } 98 } 99 } 100 101 virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/); 102 103 private: 104 bool mIsServiceStarted; 105 static sp<V1_1::INfcClientCallback> mCallbackV1_1; 106 static sp<V1_0::INfcClientCallback> mCallbackV1_0; 107 }; 108 109 } // namespace implementation 110 } // namespace V1_2 111 } // namespace nfc 112 } // namespace hardware 113 } // namespace android 114 115 #endif // ANDROID_HARDWARE_NFC_V1_2_NFC_H 116