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