• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2018-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 
63   // Methods from ::android::hardware::nfc::V1_2::INfc follow.
64   Return<void> getConfig_1_2(getConfig_1_2_cb config);
65 
66   // Methods from ::android::hidl::base::V1_0::IBase follow.
eventCallbackNfc67   static void eventCallback(uint8_t event, uint8_t status) {
68     if (mCallbackV1_1 != nullptr) {
69       auto ret = mCallbackV1_1->sendEvent_1_1((V1_1::NfcEvent)event,
70                                               (V1_0::NfcStatus)status);
71       if (!ret.isOk()) {
72         ALOGW("failed to send event!!!");
73       }
74     } else if (mCallbackV1_0 != nullptr) {
75       auto ret = mCallbackV1_0->sendEvent((V1_0::NfcEvent)event,
76                                           (V1_0::NfcStatus)status);
77       if (!ret.isOk()) {
78         ALOGE("failed to send event!!!");
79       }
80     }
81   }
82 
dataCallbackNfc83   static void dataCallback(uint16_t data_len, uint8_t* p_data) {
84     hidl_vec<uint8_t> data;
85     data.setToExternal(p_data, data_len);
86     if (mCallbackV1_1 != nullptr) {
87       auto ret = mCallbackV1_1->sendData(data);
88       if (!ret.isOk()) {
89         ALOGW("failed to send data!!!");
90       }
91     } else if (mCallbackV1_0 != nullptr) {
92       auto ret = mCallbackV1_0->sendData(data);
93       if (!ret.isOk()) {
94         ALOGE("failed to send data!!!");
95       }
96     }
97   }
98 
serviceDiedNfc99   virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) {
100     close();
101   }
102 
103  private:
104   static sp<V1_1::INfcClientCallback> mCallbackV1_1;
105   static sp<V1_0::INfcClientCallback> mCallbackV1_0;
106 };
107 
108 }  // namespace implementation
109 }  // namespace V1_2
110 }  // namespace nfc
111 }  // namespace hardware
112 }  // namespace android
113 
114 #endif  // ANDROID_HARDWARE_NFC_V1_2_NFC_H
115