1 /****************************************************************************** 2 * 3 * Copyright 2018 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_1_NFC_H 20 #define ANDROID_HARDWARE_NFC_V1_1_NFC_H 21 22 #include <android/hardware/nfc/1.1/INfc.h> 23 #include <android/hardware/nfc/1.1/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_1 { 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_1::INfc; 42 using ::android::hidl::base::V1_0::IBase; 43 struct Nfc : public V1_1::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 63 // Methods from ::android::hidl::base::V1_0::IBase follow. 64 eventCallbackNfc65 static void eventCallback(uint8_t event, uint8_t status) { 66 if (mCallbackV1_1 != nullptr) { 67 auto ret = mCallbackV1_1->sendEvent_1_1((V1_1::NfcEvent)event, 68 (V1_0::NfcStatus)status); 69 if (!ret.isOk()) { 70 ALOGW("failed to send event!!!"); 71 } 72 } else if (mCallbackV1_0 != nullptr) { 73 auto ret = mCallbackV1_0->sendEvent((V1_0::NfcEvent)event, 74 (V1_0::NfcStatus)status); 75 if (!ret.isOk()) { 76 ALOGE("failed to send event!!!"); 77 } 78 } 79 } 80 dataCallbackNfc81 static void dataCallback(uint16_t data_len, uint8_t* p_data) { 82 hidl_vec<uint8_t> data; 83 data.setToExternal(p_data, data_len); 84 if (mCallbackV1_1 != nullptr) { 85 auto ret = mCallbackV1_1->sendData(data); 86 if (!ret.isOk()) { 87 ALOGW("failed to send data!!!"); 88 } 89 } else if (mCallbackV1_0 != nullptr) { 90 auto ret = mCallbackV1_0->sendData(data); 91 if (!ret.isOk()) { 92 ALOGE("failed to send data!!!"); 93 } 94 } 95 } 96 serviceDiedNfc97 virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) { 98 close(); 99 } 100 101 private: 102 static sp<V1_1::INfcClientCallback> mCallbackV1_1; 103 static sp<V1_0::INfcClientCallback> mCallbackV1_0; 104 }; 105 106 } // namespace implementation 107 } // namespace V1_1 108 } // namespace nfc 109 } // namespace hardware 110 } // namespace android 111 112 #endif // ANDROID_HARDWARE_NFC_V1_1_NFC_H 113