The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 1999-2012 Broadcom Corporation |
| 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 | ******************************************************************************/ |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 18 | #include <android-base/stringprintf.h> |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame] | 19 | #include <android/hardware/nfc/1.1/INfc.h> |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 20 | #include <base/command_line.h> |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 21 | #include <base/logging.h> |
| 22 | #include <cutils/properties.h> |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 23 | #include <hwbinder/ProcessState.h> |
Ruchi Kandoi | c0cd1ab | 2017-04-17 17:23:56 -0700 | [diff] [blame] | 24 | |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 25 | #include "NfcAdaptation.h" |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 26 | #include "android_logmsg.h" |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 27 | #include "debug_nfcsnoop.h" |
| 28 | #include "nfa_api.h" |
Ruchi Kandoi | f406415 | 2018-02-28 16:27:41 -0800 | [diff] [blame] | 29 | #include "nfa_rw_api.h" |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 30 | #include "nfc_config.h" |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 31 | #include "nfc_int.h" |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 32 | |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 33 | using android::OK; |
| 34 | using android::sp; |
| 35 | using android::status_t; |
| 36 | |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 37 | using android::base::StringPrintf; |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 38 | using android::hardware::ProcessState; |
| 39 | using android::hardware::Return; |
| 40 | using android::hardware::Void; |
| 41 | using android::hardware::nfc::V1_0::INfc; |
Ruchi Kandoi | f406415 | 2018-02-28 16:27:41 -0800 | [diff] [blame] | 42 | using android::hardware::nfc::V1_1::PresenceCheckAlgorithm; |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame] | 43 | using INfcV1_1 = android::hardware::nfc::V1_1::INfc; |
Ruchi Kandoi | f406415 | 2018-02-28 16:27:41 -0800 | [diff] [blame] | 44 | using NfcVendorConfig = android::hardware::nfc::V1_1::NfcConfig; |
Ruchi Kandoi | 267fdf5 | 2018-02-02 15:31:55 -0800 | [diff] [blame] | 45 | using android::hardware::nfc::V1_1::INfcClientCallback; |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 46 | using android::hardware::hidl_vec; |
| 47 | |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 48 | extern bool nfc_debug_enabled; |
| 49 | |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 50 | extern void GKI_shutdown(); |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 51 | extern void verify_stack_non_volatile_store(); |
| 52 | extern void delete_stack_non_volatile_store(bool forceDelete); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 53 | |
| 54 | NfcAdaptation* NfcAdaptation::mpInstance = NULL; |
| 55 | ThreadMutex NfcAdaptation::sLock; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 56 | tHAL_NFC_CBACK* NfcAdaptation::mHalCallback = NULL; |
| 57 | tHAL_NFC_DATA_CBACK* NfcAdaptation::mHalDataCallback = NULL; |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 58 | ThreadCondVar NfcAdaptation::mHalOpenCompletedEvent; |
| 59 | ThreadCondVar NfcAdaptation::mHalCloseCompletedEvent; |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 60 | sp<INfc> NfcAdaptation::mHal; |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame] | 61 | sp<INfcV1_1> NfcAdaptation::mHal_1_1; |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 62 | INfcClientCallback* NfcAdaptation::mCallback; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 63 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 64 | bool nfc_debug_enabled = false; |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 65 | std::string nfc_storage_path; |
Love Khanna | d7852c9 | 2017-06-02 19:55:05 +0530 | [diff] [blame] | 66 | uint8_t appl_dta_mode_flag = 0x00; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 67 | |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 68 | extern tNFA_DM_CFG nfa_dm_cfg; |
| 69 | extern tNFA_PROPRIETARY_CFG nfa_proprietary_cfg; |
| 70 | extern tNFA_HCI_CFG nfa_hci_cfg; |
Ruchi Kandoi | 512ee63 | 2017-01-03 13:59:10 -0800 | [diff] [blame] | 71 | extern uint8_t nfa_ee_max_ee_cfg; |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 72 | extern bool nfa_poll_bail_out_mode; |
| 73 | |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 74 | // Whitelist for hosts allowed to create a pipe |
| 75 | // See ADM_CREATE_PIPE command in the ETSI test specification |
| 76 | // ETSI TS 102 622, section 6.1.3.1 |
| 77 | static std::vector<uint8_t> host_whitelist; |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 78 | |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 79 | namespace { |
| 80 | void initializeGlobalDebugEnabledFlag() { |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 81 | nfc_debug_enabled = |
| 82 | (NfcConfig::getUnsigned(NAME_NFC_DEBUG_ENABLED, 0) != 0) ? true : false; |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 83 | |
| 84 | char valueStr[PROPERTY_VALUE_MAX] = {0}; |
Andre Eisenbach | 6261a47 | 2017-12-05 16:56:25 -0800 | [diff] [blame] | 85 | int len = property_get("nfc.debug_enabled", valueStr, ""); |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 86 | if (len > 0) { |
| 87 | // let Android property override .conf variable |
Andre Eisenbach | 6261a47 | 2017-12-05 16:56:25 -0800 | [diff] [blame] | 88 | unsigned debug_enabled = 0; |
| 89 | sscanf(valueStr, "%u", &debug_enabled); |
| 90 | nfc_debug_enabled = (debug_enabled == 0) ? false : true; |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | DLOG_IF(INFO, nfc_debug_enabled) |
| 94 | << StringPrintf("%s: level=%u", __func__, nfc_debug_enabled); |
| 95 | } |
| 96 | } // namespace |
| 97 | |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 98 | class NfcClientCallback : public INfcClientCallback { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 99 | public: |
| 100 | NfcClientCallback(tHAL_NFC_CBACK* eventCallback, |
| 101 | tHAL_NFC_DATA_CBACK dataCallback) { |
| 102 | mEventCallback = eventCallback; |
| 103 | mDataCallback = dataCallback; |
| 104 | }; |
| 105 | virtual ~NfcClientCallback() = default; |
Ruchi Kandoi | 267fdf5 | 2018-02-02 15:31:55 -0800 | [diff] [blame] | 106 | Return<void> sendEvent_1_1( |
| 107 | ::android::hardware::nfc::V1_1::NfcEvent event, |
| 108 | ::android::hardware::nfc::V1_0::NfcStatus event_status) override { |
| 109 | mEventCallback((uint8_t)event, (tHAL_NFC_STATUS)event_status); |
| 110 | return Void(); |
| 111 | }; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 112 | Return<void> sendEvent( |
| 113 | ::android::hardware::nfc::V1_0::NfcEvent event, |
| 114 | ::android::hardware::nfc::V1_0::NfcStatus event_status) override { |
| 115 | mEventCallback((uint8_t)event, (tHAL_NFC_STATUS)event_status); |
| 116 | return Void(); |
| 117 | }; |
| 118 | Return<void> sendData( |
| 119 | const ::android::hardware::nfc::V1_0::NfcData& data) override { |
| 120 | ::android::hardware::nfc::V1_0::NfcData copy = data; |
| 121 | mDataCallback(copy.size(), ©[0]); |
| 122 | return Void(); |
| 123 | }; |
| 124 | |
| 125 | private: |
| 126 | tHAL_NFC_CBACK* mEventCallback; |
| 127 | tHAL_NFC_DATA_CBACK* mDataCallback; |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 128 | }; |
| 129 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 130 | /******************************************************************************* |
| 131 | ** |
| 132 | ** Function: NfcAdaptation::NfcAdaptation() |
| 133 | ** |
| 134 | ** Description: class constructor |
| 135 | ** |
| 136 | ** Returns: none |
| 137 | ** |
| 138 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 139 | NfcAdaptation::NfcAdaptation() { |
| 140 | memset(&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /******************************************************************************* |
| 144 | ** |
| 145 | ** Function: NfcAdaptation::~NfcAdaptation() |
| 146 | ** |
| 147 | ** Description: class destructor |
| 148 | ** |
| 149 | ** Returns: none |
| 150 | ** |
| 151 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 152 | NfcAdaptation::~NfcAdaptation() { mpInstance = NULL; } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 153 | |
| 154 | /******************************************************************************* |
| 155 | ** |
| 156 | ** Function: NfcAdaptation::GetInstance() |
| 157 | ** |
| 158 | ** Description: access class singleton |
| 159 | ** |
| 160 | ** Returns: pointer to the singleton object |
| 161 | ** |
| 162 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 163 | NfcAdaptation& NfcAdaptation::GetInstance() { |
| 164 | AutoThreadMutex a(sLock); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 165 | |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame] | 166 | if (!mpInstance) { |
| 167 | mpInstance = new NfcAdaptation; |
| 168 | mpInstance->InitializeHalDeviceContext(); |
| 169 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 170 | return *mpInstance; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Ruchi Kandoi | f406415 | 2018-02-28 16:27:41 -0800 | [diff] [blame] | 173 | void NfcAdaptation::GetVendorConfigs( |
| 174 | std::map<std::string, ConfigValue>& configMap) { |
| 175 | if (mHal_1_1) { |
| 176 | mHal_1_1->getConfig([&configMap](NfcVendorConfig config) { |
| 177 | std::vector<uint8_t> nfaPropCfg = { |
| 178 | config.nfaProprietaryCfg.protocol18092Active, |
| 179 | config.nfaProprietaryCfg.protocolBPrime, |
| 180 | config.nfaProprietaryCfg.protocolDual, |
| 181 | config.nfaProprietaryCfg.protocol15693, |
| 182 | config.nfaProprietaryCfg.protocolKovio, |
| 183 | config.nfaProprietaryCfg.protocolMifare, |
| 184 | config.nfaProprietaryCfg.discoveryPollKovio, |
| 185 | config.nfaProprietaryCfg.discoveryPollBPrime, |
| 186 | config.nfaProprietaryCfg.discoveryListenBPrime}; |
| 187 | configMap.emplace(NAME_NFA_PROPRIETARY_CFG, ConfigValue(nfaPropCfg)); |
| 188 | configMap.emplace(NAME_NFA_POLL_BAIL_OUT_MODE, |
| 189 | ConfigValue(config.nfaPollBailOutMode ? 1 : 0)); |
| 190 | configMap.emplace(NAME_DEFAULT_OFFHOST_ROUTE, |
| 191 | ConfigValue(config.defaultOffHostRoute)); |
| 192 | configMap.emplace(NAME_DEFAULT_NFCF_ROUTE, |
| 193 | ConfigValue(config.defaultOffHostRouteFelica)); |
| 194 | configMap.emplace(NAME_DEFAULT_SYS_CODE_ROUTE, |
| 195 | ConfigValue(config.defaultSystemCodeRoute)); |
Ruchi Kandoi | ce47812 | 2018-04-02 17:37:57 -0700 | [diff] [blame^] | 196 | configMap.emplace(NAME_DEFAULT_SYS_CODE_PWR_STATE, |
| 197 | ConfigValue(config.defaultSystemCodePowerState)); |
Ruchi Kandoi | f406415 | 2018-02-28 16:27:41 -0800 | [diff] [blame] | 198 | configMap.emplace(NAME_OFF_HOST_SIM_PIPE_ID, |
| 199 | ConfigValue(config.offHostSIMPipeId)); |
| 200 | configMap.emplace(NAME_OFF_HOST_ESE_PIPE_ID, |
| 201 | ConfigValue(config.offHostESEPipeId)); |
| 202 | configMap.emplace(NAME_ISO_DEP_MAX_TRANSCEIVE, |
| 203 | ConfigValue(config.maxIsoDepTransceiveLength)); |
| 204 | /* For Backwards compatibility */ |
| 205 | if (config.presenceCheckAlgorithm == |
| 206 | PresenceCheckAlgorithm::ISO_DEP_NAK) { |
| 207 | configMap.emplace(NAME_PRESENCE_CHECK_ALGORITHM, |
| 208 | ConfigValue((uint32_t)NFA_RW_PRES_CHK_ISO_DEP_NAK)); |
| 209 | } else { |
| 210 | configMap.emplace(NAME_PRESENCE_CHECK_ALGORITHM, |
| 211 | ConfigValue((uint32_t)config.presenceCheckAlgorithm)); |
| 212 | } |
| 213 | }); |
| 214 | } |
| 215 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 216 | /******************************************************************************* |
| 217 | ** |
| 218 | ** Function: NfcAdaptation::Initialize() |
| 219 | ** |
| 220 | ** Description: class initializer |
| 221 | ** |
| 222 | ** Returns: none |
| 223 | ** |
| 224 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 225 | void NfcAdaptation::Initialize() { |
| 226 | const char* func = "NfcAdaptation::Initialize"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 227 | const char* argv[] = {"libnfc_nci"}; |
| 228 | // Init log tag |
| 229 | base::CommandLine::Init(1, argv); |
| 230 | |
| 231 | // Android already logs thread_id, proc_id, timestamp, so disable those. |
| 232 | logging::SetLogItems(false, false, false, false); |
| 233 | |
| 234 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: enter", func); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 235 | |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 236 | nfc_storage_path = NfcConfig::getString(NAME_NFA_STORAGE, "/data/nfc"); |
| 237 | |
| 238 | if (NfcConfig::hasKey(NAME_NFA_DM_CFG)) { |
| 239 | std::vector<uint8_t> dm_config = NfcConfig::getBytes(NAME_NFA_DM_CFG); |
| 240 | if (dm_config.size() > 0) nfa_dm_cfg.auto_detect_ndef = dm_config[0]; |
| 241 | if (dm_config.size() > 1) nfa_dm_cfg.auto_read_ndef = dm_config[1]; |
| 242 | if (dm_config.size() > 2) nfa_dm_cfg.auto_presence_check = dm_config[2]; |
| 243 | if (dm_config.size() > 3) nfa_dm_cfg.presence_check_option = dm_config[3]; |
| 244 | // NOTE: The timeout value is not configurable here because the endianess |
| 245 | // of a byte array is ambiguous and needlessly difficult to configure. |
| 246 | // If this value needs to be configgurable, a numeric config option should |
| 247 | // be used. |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 248 | } |
Andres Morales | e4ecc7d | 2014-10-01 17:46:04 -0700 | [diff] [blame] | 249 | |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 250 | if (NfcConfig::hasKey(NAME_NFA_MAX_EE_SUPPORTED)) { |
| 251 | nfa_ee_max_ee_cfg = NfcConfig::getUnsigned(NAME_NFA_MAX_EE_SUPPORTED); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 252 | DLOG_IF(INFO, nfc_debug_enabled) |
| 253 | << StringPrintf("%s: Overriding NFA_EE_MAX_EE_SUPPORTED to use %d", |
| 254 | func, nfa_ee_max_ee_cfg); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 255 | } |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 256 | |
| 257 | if (NfcConfig::hasKey(NAME_NFA_POLL_BAIL_OUT_MODE)) { |
| 258 | nfa_poll_bail_out_mode = |
| 259 | NfcConfig::getUnsigned(NAME_NFA_POLL_BAIL_OUT_MODE); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 260 | DLOG_IF(INFO, nfc_debug_enabled) |
| 261 | << StringPrintf("%s: Overriding NFA_POLL_BAIL_OUT_MODE to use %d", func, |
| 262 | nfa_poll_bail_out_mode); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 263 | } |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 264 | |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 265 | if (NfcConfig::hasKey(NAME_NFA_PROPRIETARY_CFG)) { |
| 266 | std::vector<uint8_t> p_config = |
| 267 | NfcConfig::getBytes(NAME_NFA_PROPRIETARY_CFG); |
| 268 | if (p_config.size() > 0) |
| 269 | nfa_proprietary_cfg.pro_protocol_18092_active = p_config[0]; |
| 270 | if (p_config.size() > 1) |
| 271 | nfa_proprietary_cfg.pro_protocol_b_prime = p_config[1]; |
| 272 | if (p_config.size() > 2) |
| 273 | nfa_proprietary_cfg.pro_protocol_dual = p_config[2]; |
| 274 | if (p_config.size() > 3) |
| 275 | nfa_proprietary_cfg.pro_protocol_15693 = p_config[3]; |
| 276 | if (p_config.size() > 4) |
| 277 | nfa_proprietary_cfg.pro_protocol_kovio = p_config[4]; |
| 278 | if (p_config.size() > 5) nfa_proprietary_cfg.pro_protocol_mfc = p_config[5]; |
| 279 | if (p_config.size() > 6) |
| 280 | nfa_proprietary_cfg.pro_discovery_kovio_poll = p_config[6]; |
| 281 | if (p_config.size() > 7) |
| 282 | nfa_proprietary_cfg.pro_discovery_b_prime_poll = p_config[7]; |
| 283 | if (p_config.size() > 8) |
| 284 | nfa_proprietary_cfg.pro_discovery_b_prime_listen = p_config[8]; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 285 | } |
Jizhou Liao | acf1ec0 | 2015-06-30 10:25:41 -0700 | [diff] [blame] | 286 | |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 287 | // Configure whitelist of HCI host ID's |
| 288 | // See specification: ETSI TS 102 622, section 6.1.3.1 |
| 289 | if (NfcConfig::hasKey(NAME_DEVICE_HOST_WHITE_LIST)) { |
| 290 | host_whitelist = NfcConfig::getBytes(NAME_DEVICE_HOST_WHITE_LIST); |
| 291 | nfa_hci_cfg.num_whitelist_host = host_whitelist.size(); |
| 292 | nfa_hci_cfg.p_whitelist = &host_whitelist[0]; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 293 | } |
Evan Chu | b7cb567 | 2014-02-07 15:01:21 -0500 | [diff] [blame] | 294 | |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 295 | initializeGlobalDebugEnabledFlag(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 296 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 297 | verify_stack_non_volatile_store(); |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 298 | if (NfcConfig::hasKey(NAME_PRESERVE_STORAGE) && |
| 299 | NfcConfig::getUnsigned(NAME_PRESERVE_STORAGE) == 1) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 300 | DLOG_IF(INFO, nfc_debug_enabled) |
| 301 | << StringPrintf("%s: preserve stack NV store", __func__); |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 302 | } else { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 303 | delete_stack_non_volatile_store(FALSE); |
| 304 | } |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 305 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 306 | GKI_init(); |
| 307 | GKI_enable(); |
| 308 | GKI_create_task((TASKPTR)NFCA_TASK, BTU_TASK, (int8_t*)"NFCA_TASK", 0, 0, |
| 309 | (pthread_cond_t*)NULL, NULL); |
| 310 | { |
| 311 | AutoThreadMutex guard(mCondVar); |
| 312 | GKI_create_task((TASKPTR)Thread, MMI_TASK, (int8_t*)"NFCA_THREAD", 0, 0, |
| 313 | (pthread_cond_t*)NULL, NULL); |
| 314 | mCondVar.wait(); |
| 315 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 316 | |
Ruchi Kandoi | c0cd1ab | 2017-04-17 17:23:56 -0700 | [diff] [blame] | 317 | debug_nfcsnoop_init(); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 318 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: exit", func); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /******************************************************************************* |
| 322 | ** |
| 323 | ** Function: NfcAdaptation::Finalize() |
| 324 | ** |
| 325 | ** Description: class finalizer |
| 326 | ** |
| 327 | ** Returns: none |
| 328 | ** |
| 329 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 330 | void NfcAdaptation::Finalize() { |
| 331 | const char* func = "NfcAdaptation::Finalize"; |
| 332 | AutoThreadMutex a(sLock); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 333 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 334 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: enter", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 335 | GKI_shutdown(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 336 | |
Andre Eisenbach | a34d7d1 | 2017-11-27 13:16:18 -0800 | [diff] [blame] | 337 | NfcConfig::clear(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 338 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 339 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: exit", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 340 | delete this; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame] | 343 | void NfcAdaptation::FactoryReset() { |
| 344 | if (mHal_1_1 != nullptr) { |
| 345 | mHal_1_1->factoryReset(); |
| 346 | } |
| 347 | } |
| 348 | |
Ruchi Kandoi | 40da437 | 2017-12-07 15:19:30 -0800 | [diff] [blame] | 349 | void NfcAdaptation::DeviceShutdown() { |
| 350 | if (mHal_1_1 != nullptr) { |
| 351 | mHal_1_1->closeForPowerOffCase(); |
| 352 | } |
| 353 | } |
| 354 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 355 | /******************************************************************************* |
| 356 | ** |
Ruchi Kandoi | c0cd1ab | 2017-04-17 17:23:56 -0700 | [diff] [blame] | 357 | ** Function: NfcAdaptation::Dump |
| 358 | ** |
| 359 | ** Description: Native support for dumpsys function. |
| 360 | ** |
| 361 | ** Returns: None. |
| 362 | ** |
| 363 | *******************************************************************************/ |
| 364 | void NfcAdaptation::Dump(int fd) { debug_nfcsnoop_dump(fd); } |
| 365 | |
| 366 | /******************************************************************************* |
| 367 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 368 | ** Function: NfcAdaptation::signal() |
| 369 | ** |
| 370 | ** Description: signal the CondVar to release the thread that is waiting |
| 371 | ** |
| 372 | ** Returns: none |
| 373 | ** |
| 374 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 375 | void NfcAdaptation::signal() { mCondVar.signal(); } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 376 | |
| 377 | /******************************************************************************* |
| 378 | ** |
| 379 | ** Function: NfcAdaptation::NFCA_TASK() |
| 380 | ** |
| 381 | ** Description: NFCA_TASK runs the GKI main task |
| 382 | ** |
| 383 | ** Returns: none |
| 384 | ** |
| 385 | *******************************************************************************/ |
Ruchi Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 386 | uint32_t NfcAdaptation::NFCA_TASK(__attribute__((unused)) uint32_t arg) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 387 | const char* func = "NfcAdaptation::NFCA_TASK"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 388 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: enter", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 389 | GKI_run(0); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 390 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: exit", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 391 | return 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /******************************************************************************* |
| 395 | ** |
| 396 | ** Function: NfcAdaptation::Thread() |
| 397 | ** |
| 398 | ** Description: Creates work threads |
| 399 | ** |
| 400 | ** Returns: none |
| 401 | ** |
| 402 | *******************************************************************************/ |
Ruchi Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 403 | uint32_t NfcAdaptation::Thread(__attribute__((unused)) uint32_t arg) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 404 | const char* func = "NfcAdaptation::Thread"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 405 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: enter", func); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 406 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 407 | { |
| 408 | ThreadCondVar CondVar; |
| 409 | AutoThreadMutex guard(CondVar); |
| 410 | GKI_create_task((TASKPTR)nfc_task, NFC_TASK, (int8_t*)"NFC_TASK", 0, 0, |
| 411 | (pthread_cond_t*)CondVar, (pthread_mutex_t*)CondVar); |
| 412 | CondVar.wait(); |
| 413 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 414 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 415 | NfcAdaptation::GetInstance().signal(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 416 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 417 | GKI_exit_task(GKI_get_taskid()); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 418 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: exit", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 419 | return 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /******************************************************************************* |
| 423 | ** |
| 424 | ** Function: NfcAdaptation::GetHalEntryFuncs() |
| 425 | ** |
| 426 | ** Description: Get the set of HAL entry points. |
| 427 | ** |
| 428 | ** Returns: Functions pointers for HAL entry points. |
| 429 | ** |
| 430 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 431 | tHAL_NFC_ENTRY* NfcAdaptation::GetHalEntryFuncs() { return &mHalEntryFuncs; } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 432 | |
| 433 | /******************************************************************************* |
| 434 | ** |
| 435 | ** Function: NfcAdaptation::InitializeHalDeviceContext |
| 436 | ** |
| 437 | ** Description: Ask the generic Android HAL to find the Broadcom-specific HAL. |
| 438 | ** |
| 439 | ** Returns: None. |
| 440 | ** |
| 441 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 442 | void NfcAdaptation::InitializeHalDeviceContext() { |
| 443 | const char* func = "NfcAdaptation::InitializeHalDeviceContext"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 444 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 445 | mHalEntryFuncs.initialize = HalInitialize; |
| 446 | mHalEntryFuncs.terminate = HalTerminate; |
| 447 | mHalEntryFuncs.open = HalOpen; |
| 448 | mHalEntryFuncs.close = HalClose; |
| 449 | mHalEntryFuncs.core_initialized = HalCoreInitialized; |
| 450 | mHalEntryFuncs.write = HalWrite; |
| 451 | mHalEntryFuncs.prediscover = HalPrediscover; |
| 452 | mHalEntryFuncs.control_granted = HalControlGranted; |
| 453 | mHalEntryFuncs.power_cycle = HalPowerCycle; |
| 454 | mHalEntryFuncs.get_max_ee = HalGetMaxNfcee; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 455 | LOG(INFO) << StringPrintf("%s: INfc::getService()", func); |
Ruchi Kandoi | 5815b5c | 2017-12-07 09:30:01 -0800 | [diff] [blame] | 456 | mHal = mHal_1_1 = INfcV1_1::getService(); |
| 457 | if (mHal_1_1 == nullptr) { |
| 458 | mHal = INfc::getService(); |
| 459 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 460 | LOG_FATAL_IF(mHal == nullptr, "Failed to retrieve the NFC HAL!"); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 461 | LOG(INFO) << StringPrintf("%s: INfc::getService() returned %p (%s)", func, |
| 462 | mHal.get(), |
| 463 | (mHal->isRemote() ? "remote" : "local")); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /******************************************************************************* |
| 467 | ** |
| 468 | ** Function: NfcAdaptation::HalInitialize |
| 469 | ** |
| 470 | ** Description: Not implemented because this function is only needed |
| 471 | ** within the HAL. |
| 472 | ** |
| 473 | ** Returns: None. |
| 474 | ** |
| 475 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 476 | void NfcAdaptation::HalInitialize() { |
| 477 | const char* func = "NfcAdaptation::HalInitialize"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 478 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /******************************************************************************* |
| 482 | ** |
| 483 | ** Function: NfcAdaptation::HalTerminate |
| 484 | ** |
| 485 | ** Description: Not implemented because this function is only needed |
| 486 | ** within the HAL. |
| 487 | ** |
| 488 | ** Returns: None. |
| 489 | ** |
| 490 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 491 | void NfcAdaptation::HalTerminate() { |
| 492 | const char* func = "NfcAdaptation::HalTerminate"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 493 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /******************************************************************************* |
| 497 | ** |
| 498 | ** Function: NfcAdaptation::HalOpen |
| 499 | ** |
| 500 | ** Description: Turn on controller, download firmware. |
| 501 | ** |
| 502 | ** Returns: None. |
| 503 | ** |
| 504 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 505 | void NfcAdaptation::HalOpen(tHAL_NFC_CBACK* p_hal_cback, |
| 506 | tHAL_NFC_DATA_CBACK* p_data_cback) { |
| 507 | const char* func = "NfcAdaptation::HalOpen"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 508 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 509 | mCallback = new NfcClientCallback(p_hal_cback, p_data_cback); |
Ruchi Kandoi | 267fdf5 | 2018-02-02 15:31:55 -0800 | [diff] [blame] | 510 | if (mHal_1_1 != nullptr) { |
| 511 | mHal_1_1->open_1_1(mCallback); |
| 512 | } else { |
| 513 | mHal->open(mCallback); |
| 514 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /******************************************************************************* |
| 518 | ** |
| 519 | ** Function: NfcAdaptation::HalClose |
| 520 | ** |
| 521 | ** Description: Turn off controller. |
| 522 | ** |
| 523 | ** Returns: None. |
| 524 | ** |
| 525 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 526 | void NfcAdaptation::HalClose() { |
| 527 | const char* func = "NfcAdaptation::HalClose"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 528 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 529 | mHal->close(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /******************************************************************************* |
| 533 | ** |
| 534 | ** Function: NfcAdaptation::HalDeviceContextCallback |
| 535 | ** |
| 536 | ** Description: Translate generic Android HAL's callback into Broadcom-specific |
| 537 | ** callback function. |
| 538 | ** |
| 539 | ** Returns: None. |
| 540 | ** |
| 541 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 542 | void NfcAdaptation::HalDeviceContextCallback(nfc_event_t event, |
| 543 | nfc_status_t event_status) { |
| 544 | const char* func = "NfcAdaptation::HalDeviceContextCallback"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 545 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: event=%u", func, event); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 546 | if (mHalCallback) mHalCallback(event, (tHAL_NFC_STATUS)event_status); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /******************************************************************************* |
| 550 | ** |
| 551 | ** Function: NfcAdaptation::HalDeviceContextDataCallback |
| 552 | ** |
| 553 | ** Description: Translate generic Android HAL's callback into Broadcom-specific |
| 554 | ** callback function. |
| 555 | ** |
| 556 | ** Returns: None. |
| 557 | ** |
| 558 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 559 | void NfcAdaptation::HalDeviceContextDataCallback(uint16_t data_len, |
| 560 | uint8_t* p_data) { |
| 561 | const char* func = "NfcAdaptation::HalDeviceContextDataCallback"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 562 | DLOG_IF(INFO, nfc_debug_enabled) |
| 563 | << StringPrintf("%s: len=%u", func, data_len); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 564 | if (mHalDataCallback) mHalDataCallback(data_len, p_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /******************************************************************************* |
| 568 | ** |
| 569 | ** Function: NfcAdaptation::HalWrite |
| 570 | ** |
| 571 | ** Description: Write NCI message to the controller. |
| 572 | ** |
| 573 | ** Returns: None. |
| 574 | ** |
| 575 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 576 | void NfcAdaptation::HalWrite(uint16_t data_len, uint8_t* p_data) { |
| 577 | const char* func = "NfcAdaptation::HalWrite"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 578 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 579 | ::android::hardware::nfc::V1_0::NfcData data; |
| 580 | data.setToExternal(p_data, data_len); |
| 581 | mHal->write(data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /******************************************************************************* |
| 585 | ** |
| 586 | ** Function: NfcAdaptation::HalCoreInitialized |
| 587 | ** |
| 588 | ** Description: Adjust the configurable parameters in the controller. |
| 589 | ** |
| 590 | ** Returns: None. |
| 591 | ** |
| 592 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 593 | void NfcAdaptation::HalCoreInitialized(uint16_t data_len, |
| 594 | uint8_t* p_core_init_rsp_params) { |
| 595 | const char* func = "NfcAdaptation::HalCoreInitialized"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 596 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 597 | hidl_vec<uint8_t> data; |
| 598 | data.setToExternal(p_core_init_rsp_params, data_len); |
Martijn Coenen | e9e48e5 | 2016-09-06 16:05:25 +0200 | [diff] [blame] | 599 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 600 | mHal->coreInitialized(data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /******************************************************************************* |
| 604 | ** |
| 605 | ** Function: NfcAdaptation::HalPrediscover |
| 606 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 607 | ** Description: Perform any vendor-specific pre-discovery actions (if |
| 608 | ** needed) If any actions were performed TRUE will be returned, |
| 609 | ** and HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 610 | ** completed. |
| 611 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 612 | ** Returns: TRUE if vendor-specific pre-discovery actions initialized |
| 613 | ** FALSE if no vendor-specific pre-discovery actions are |
| 614 | ** needed. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 615 | ** |
| 616 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 617 | bool NfcAdaptation::HalPrediscover() { |
| 618 | const char* func = "NfcAdaptation::HalPrediscover"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 619 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 620 | bool retval = FALSE; |
| 621 | mHal->prediscover(); |
| 622 | return retval; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /******************************************************************************* |
| 626 | ** |
| 627 | ** Function: HAL_NfcControlGranted |
| 628 | ** |
| 629 | ** Description: Grant control to HAL control for sending NCI commands. |
| 630 | ** Call in response to HAL_REQUEST_CONTROL_EVT. |
| 631 | ** Must only be called when there are no NCI commands pending. |
| 632 | ** HAL_RELEASE_CONTROL_EVT will notify when HAL no longer |
| 633 | ** needs control of NCI. |
| 634 | ** |
| 635 | ** Returns: void |
| 636 | ** |
| 637 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 638 | void NfcAdaptation::HalControlGranted() { |
| 639 | const char* func = "NfcAdaptation::HalControlGranted"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 640 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 641 | mHal->controlGranted(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /******************************************************************************* |
| 645 | ** |
| 646 | ** Function: NfcAdaptation::HalPowerCycle |
| 647 | ** |
| 648 | ** Description: Turn off and turn on the controller. |
| 649 | ** |
| 650 | ** Returns: None. |
| 651 | ** |
| 652 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 653 | void NfcAdaptation::HalPowerCycle() { |
| 654 | const char* func = "NfcAdaptation::HalPowerCycle"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 655 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 656 | mHal->powerCycle(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Paul Chaisson | b20cbf3 | 2013-07-12 13:25:09 -0400 | [diff] [blame] | 659 | /******************************************************************************* |
| 660 | ** |
| 661 | ** Function: NfcAdaptation::HalGetMaxNfcee |
| 662 | ** |
| 663 | ** Description: Turn off and turn on the controller. |
| 664 | ** |
| 665 | ** Returns: None. |
| 666 | ** |
| 667 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 668 | uint8_t NfcAdaptation::HalGetMaxNfcee() { |
| 669 | const char* func = "NfcAdaptation::HalPowerCycle"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 670 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s", func); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 671 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 672 | return nfa_ee_max_ee_cfg; |
Paul Chaisson | b20cbf3 | 2013-07-12 13:25:09 -0400 | [diff] [blame] | 673 | } |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 674 | |
| 675 | /******************************************************************************* |
| 676 | ** |
| 677 | ** Function: NfcAdaptation::DownloadFirmware |
| 678 | ** |
| 679 | ** Description: Download firmware patch files. |
| 680 | ** |
| 681 | ** Returns: None. |
| 682 | ** |
| 683 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 684 | void NfcAdaptation::DownloadFirmware() { |
| 685 | const char* func = "NfcAdaptation::DownloadFirmware"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 686 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: enter", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 687 | HalInitialize(); |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 688 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 689 | mHalOpenCompletedEvent.lock(); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 690 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: try open HAL", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 691 | HalOpen(HalDownloadFirmwareCallback, HalDownloadFirmwareDataCallback); |
| 692 | mHalOpenCompletedEvent.wait(); |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 693 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 694 | mHalCloseCompletedEvent.lock(); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 695 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: try close HAL", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 696 | HalClose(); |
| 697 | mHalCloseCompletedEvent.wait(); |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 698 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 699 | HalTerminate(); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 700 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: exit", func); |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /******************************************************************************* |
| 704 | ** |
| 705 | ** Function: NfcAdaptation::HalDownloadFirmwareCallback |
| 706 | ** |
| 707 | ** Description: Receive events from the HAL. |
| 708 | ** |
| 709 | ** Returns: None. |
| 710 | ** |
| 711 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 712 | void NfcAdaptation::HalDownloadFirmwareCallback(nfc_event_t event, |
Ruchi Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 713 | __attribute__((unused)) |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 714 | nfc_status_t event_status) { |
| 715 | const char* func = "NfcAdaptation::HalDownloadFirmwareCallback"; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 716 | DLOG_IF(INFO, nfc_debug_enabled) |
| 717 | << StringPrintf("%s: event=0x%X", func, event); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 718 | switch (event) { |
| 719 | case HAL_NFC_OPEN_CPLT_EVT: { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 720 | DLOG_IF(INFO, nfc_debug_enabled) |
| 721 | << StringPrintf("%s: HAL_NFC_OPEN_CPLT_EVT", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 722 | mHalOpenCompletedEvent.signal(); |
| 723 | break; |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 724 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 725 | case HAL_NFC_CLOSE_CPLT_EVT: { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 726 | DLOG_IF(INFO, nfc_debug_enabled) |
| 727 | << StringPrintf("%s: HAL_NFC_CLOSE_CPLT_EVT", func); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 728 | mHalCloseCompletedEvent.signal(); |
| 729 | break; |
| 730 | } |
| 731 | } |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /******************************************************************************* |
| 735 | ** |
| 736 | ** Function: NfcAdaptation::HalDownloadFirmwareDataCallback |
| 737 | ** |
| 738 | ** Description: Receive data events from the HAL. |
| 739 | ** |
| 740 | ** Returns: None. |
| 741 | ** |
| 742 | *******************************************************************************/ |
Ruchi Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 743 | void NfcAdaptation::HalDownloadFirmwareDataCallback(__attribute__((unused)) |
| 744 | uint16_t data_len, |
| 745 | __attribute__((unused)) |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 746 | uint8_t* p_data) {} |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 747 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 748 | /******************************************************************************* |
| 749 | ** |
| 750 | ** Function: ThreadMutex::ThreadMutex() |
| 751 | ** |
| 752 | ** Description: class constructor |
| 753 | ** |
| 754 | ** Returns: none |
| 755 | ** |
| 756 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 757 | ThreadMutex::ThreadMutex() { |
| 758 | pthread_mutexattr_t mutexAttr; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 759 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 760 | pthread_mutexattr_init(&mutexAttr); |
| 761 | pthread_mutex_init(&mMutex, &mutexAttr); |
| 762 | pthread_mutexattr_destroy(&mutexAttr); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | /******************************************************************************* |
| 766 | ** |
| 767 | ** Function: ThreadMutex::~ThreadMutex() |
| 768 | ** |
| 769 | ** Description: class destructor |
| 770 | ** |
| 771 | ** Returns: none |
| 772 | ** |
| 773 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 774 | ThreadMutex::~ThreadMutex() { pthread_mutex_destroy(&mMutex); } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 775 | |
| 776 | /******************************************************************************* |
| 777 | ** |
| 778 | ** Function: ThreadMutex::lock() |
| 779 | ** |
| 780 | ** Description: lock kthe mutex |
| 781 | ** |
| 782 | ** Returns: none |
| 783 | ** |
| 784 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 785 | void ThreadMutex::lock() { pthread_mutex_lock(&mMutex); } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 786 | |
| 787 | /******************************************************************************* |
| 788 | ** |
| 789 | ** Function: ThreadMutex::unblock() |
| 790 | ** |
| 791 | ** Description: unlock the mutex |
| 792 | ** |
| 793 | ** Returns: none |
| 794 | ** |
| 795 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 796 | void ThreadMutex::unlock() { pthread_mutex_unlock(&mMutex); } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 797 | |
| 798 | /******************************************************************************* |
| 799 | ** |
| 800 | ** Function: ThreadCondVar::ThreadCondVar() |
| 801 | ** |
| 802 | ** Description: class constructor |
| 803 | ** |
| 804 | ** Returns: none |
| 805 | ** |
| 806 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 807 | ThreadCondVar::ThreadCondVar() { |
| 808 | pthread_condattr_t CondAttr; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 809 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 810 | pthread_condattr_init(&CondAttr); |
| 811 | pthread_cond_init(&mCondVar, &CondAttr); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 812 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 813 | pthread_condattr_destroy(&CondAttr); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /******************************************************************************* |
| 817 | ** |
| 818 | ** Function: ThreadCondVar::~ThreadCondVar() |
| 819 | ** |
| 820 | ** Description: class destructor |
| 821 | ** |
| 822 | ** Returns: none |
| 823 | ** |
| 824 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 825 | ThreadCondVar::~ThreadCondVar() { pthread_cond_destroy(&mCondVar); } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 826 | |
| 827 | /******************************************************************************* |
| 828 | ** |
| 829 | ** Function: ThreadCondVar::wait() |
| 830 | ** |
| 831 | ** Description: wait on the mCondVar |
| 832 | ** |
| 833 | ** Returns: none |
| 834 | ** |
| 835 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 836 | void ThreadCondVar::wait() { |
| 837 | pthread_cond_wait(&mCondVar, *this); |
| 838 | pthread_mutex_unlock(*this); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | /******************************************************************************* |
| 842 | ** |
| 843 | ** Function: ThreadCondVar::signal() |
| 844 | ** |
| 845 | ** Description: signal the mCondVar |
| 846 | ** |
| 847 | ** Returns: none |
| 848 | ** |
| 849 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 850 | void ThreadCondVar::signal() { |
| 851 | AutoThreadMutex a(*this); |
| 852 | pthread_cond_signal(&mCondVar); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /******************************************************************************* |
| 856 | ** |
| 857 | ** Function: AutoThreadMutex::AutoThreadMutex() |
| 858 | ** |
| 859 | ** Description: class constructor, automatically lock the mutex |
| 860 | ** |
| 861 | ** Returns: none |
| 862 | ** |
| 863 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 864 | AutoThreadMutex::AutoThreadMutex(ThreadMutex& m) : mm(m) { mm.lock(); } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 865 | |
| 866 | /******************************************************************************* |
| 867 | ** |
| 868 | ** Function: AutoThreadMutex::~AutoThreadMutex() |
| 869 | ** |
| 870 | ** Description: class destructor, automatically unlock the mutex |
| 871 | ** |
| 872 | ** Returns: none |
| 873 | ** |
| 874 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 875 | AutoThreadMutex::~AutoThreadMutex() { mm.unlock(); } |