1 /****************************************************************************** 2 * 3 * Copyright 2018 NXP 4 * Copyright 2018 ST Microelectronics S.A. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ******************************************************************************/ 19 20 #ifndef ANDROID_HARDWARE_NFC_V1_1_NFC_H 21 #define ANDROID_HARDWARE_NFC_V1_1_NFC_H 22 23 #include <android/hardware/nfc/1.1/INfc.h> 24 #include <android/hardware/nfc/1.1/types.h> 25 #include <hidl/MQDescriptor.h> 26 #include <hidl/Status.h> 27 #include <log/log.h> 28 29 namespace android { 30 namespace hardware { 31 namespace nfc { 32 namespace V1_1 { 33 namespace implementation { 34 35 using ::android::sp; 36 using ::android::hardware::hidl_array; 37 using ::android::hardware::hidl_memory; 38 using ::android::hardware::hidl_string; 39 using ::android::hardware::hidl_vec; 40 using ::android::hardware::Return; 41 using ::android::hardware::Void; 42 using ::android::hardware::nfc::V1_1::INfc; 43 using ::android::hidl::base::V1_0::IBase; 44 struct Nfc : public V1_1::INfc, public hidl_death_recipient { 45 public: 46 // Methods from ::android::hardware::nfc::V1_0::INfc follow. 47 Return<V1_0::NfcStatus> open( 48 const sp<V1_0::INfcClientCallback>& clientCallback) override; 49 Return<V1_0::NfcStatus> open_1_1( 50 const sp<V1_1::INfcClientCallback>& clientCallback) override; 51 Return<uint32_t> write(const hidl_vec<uint8_t>& data) override; 52 Return<V1_0::NfcStatus> coreInitialized( 53 const hidl_vec<uint8_t>& data) override; 54 Return<V1_0::NfcStatus> prediscover() override; 55 Return<V1_0::NfcStatus> close() override; 56 Return<V1_0::NfcStatus> controlGranted() override; 57 Return<V1_0::NfcStatus> powerCycle() override; 58 59 // Methods from ::android::hardware::nfc::V1_1::INfc follow. 60 Return<void> factoryReset(); 61 Return<V1_0::NfcStatus> closeForPowerOffCase(); 62 Return<void> getConfig(getConfig_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_1 109 } // namespace nfc 110 } // namespace hardware 111 } // namespace android 112 113 #endif // ANDROID_HARDWARE_NFC_V1_1_NFC_H 114