blob: 4636c73a1012f4856b167c3ea875bc8fb1c0ecd5 [file] [log] [blame]
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001/******************************************************************************
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 ******************************************************************************/
Ruchi Kandoid03c06e2017-01-26 15:32:03 -080018#include "_OverrideLog.h"
19
Martijn Coenene9e48e52016-09-06 16:05:25 +020020#include <android/hardware/nfc/1.0/INfc.h>
21#include <android/hardware/nfc/1.0/INfcClientCallback.h>
22#include <hwbinder/ProcessState.h>
23#include <pthread.h>
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080024#include "NfcAdaptation.h"
25extern "C"
26{
27 #include "gki.h"
28 #include "nfa_api.h"
29 #include "nfc_int.h"
Jizhou Liaoacf1ec02015-06-30 10:25:41 -070030 #include "vendor_cfg.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080031}
32#include "config.h"
Evan Chua24be4f2013-11-13 15:30:16 -050033#include "android_logmsg.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080034
Jizhou Liao65ebec52016-04-05 17:09:24 -070035#undef LOG_TAG
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080036#define LOG_TAG "NfcAdaptation"
37
Martijn Coenene9e48e52016-09-06 16:05:25 +020038using android::OK;
39using android::sp;
40using android::status_t;
41
42using android::hardware::ProcessState;
43using android::hardware::Return;
44using android::hardware::Void;
45using android::hardware::nfc::V1_0::INfc;
46using android::hardware::nfc::V1_0::INfcClientCallback;
47using android::hardware::hidl_vec;
48
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080049extern "C" void GKI_shutdown();
50extern void resetConfig();
Evan Chuedbfba92013-04-10 13:57:34 -040051extern "C" void verify_stack_non_volatile_store ();
Ruchi Kandoi512ee632017-01-03 13:59:10 -080052extern "C" void delete_stack_non_volatile_store (bool forceDelete);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080053
54NfcAdaptation* NfcAdaptation::mpInstance = NULL;
55ThreadMutex NfcAdaptation::sLock;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080056tHAL_NFC_CBACK* NfcAdaptation::mHalCallback = NULL;
57tHAL_NFC_DATA_CBACK* NfcAdaptation::mHalDataCallback = NULL;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070058ThreadCondVar NfcAdaptation::mHalOpenCompletedEvent;
59ThreadCondVar NfcAdaptation::mHalCloseCompletedEvent;
Martijn Coenene9e48e52016-09-06 16:05:25 +020060sp<INfc> NfcAdaptation::mHal;
61INfcClientCallback* NfcAdaptation::mCallback;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080062
Ruchi Kandoi512ee632017-01-03 13:59:10 -080063uint32_t ScrProtocolTraceFlag = SCR_PROTO_TRACE_ALL; //0x017F00;
64uint8_t appl_trace_level = 0xff;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080065char bcm_nfc_location[120];
66
Ruchi Kandoi512ee632017-01-03 13:59:10 -080067static uint8_t nfa_dm_cfg[sizeof ( tNFA_DM_CFG ) ];
68static uint8_t nfa_proprietary_cfg[sizeof ( tNFA_PROPRIETARY_CFG )];
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070069extern tNFA_DM_CFG *p_nfa_dm_cfg;
Jizhou Liaoacf1ec02015-06-30 10:25:41 -070070extern tNFA_PROPRIETARY_CFG *p_nfa_proprietary_cfg;
Ruchi Kandoi512ee632017-01-03 13:59:10 -080071extern uint8_t nfa_ee_max_ee_cfg;
72extern const uint8_t nfca_version_string [];
73extern const uint8_t nfa_version_string [];
74static uint8_t deviceHostWhiteList [NFA_HCI_MAX_HOST_IN_NETWORK];
Evan Chub7cb5672014-02-07 15:01:21 -050075static tNFA_HCI_CFG jni_nfa_hci_cfg;
76extern tNFA_HCI_CFG *p_nfa_hci_cfg;
Ruchi Kandoi512ee632017-01-03 13:59:10 -080077extern bool nfa_poll_bail_out_mode;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070078
Martijn Coenene9e48e52016-09-06 16:05:25 +020079class NfcClientCallback : public INfcClientCallback {
80 public:
81 NfcClientCallback(tHAL_NFC_CBACK* eventCallback, tHAL_NFC_DATA_CBACK dataCallback) {
82 mEventCallback = eventCallback;
83 mDataCallback = dataCallback;
84 };
85 virtual ~NfcClientCallback() = default;
86 Return<void> sendEvent(
Steven Moreland98cd45d2016-09-29 11:18:21 -070087 ::android::hardware::nfc::V1_0::NfcEvent event,
88 ::android::hardware::nfc::V1_0::NfcStatus event_status) override {
Ruchi Kandoi512ee632017-01-03 13:59:10 -080089 mEventCallback ((uint8_t)event, (tHAL_NFC_STATUS) event_status);
Martijn Coenene9e48e52016-09-06 16:05:25 +020090 return Void();
91 };
Steven Moreland98cd45d2016-09-29 11:18:21 -070092 Return<void> sendData(const ::android::hardware::nfc::V1_0::NfcData &data ) override {
93 ::android::hardware::nfc::V1_0::NfcData copy = data;
94 mDataCallback(copy.size(), &copy[0]);
Martijn Coenene9e48e52016-09-06 16:05:25 +020095 return Void();
96 };
97 private:
98 tHAL_NFC_CBACK* mEventCallback;
99 tHAL_NFC_DATA_CBACK* mDataCallback;
100};
101
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800102/*******************************************************************************
103**
104** Function: NfcAdaptation::NfcAdaptation()
105**
106** Description: class constructor
107**
108** Returns: none
109**
110*******************************************************************************/
111NfcAdaptation::NfcAdaptation()
112{
Evan Chu15696412014-07-16 16:40:22 -0400113 memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800114}
115
116/*******************************************************************************
117**
118** Function: NfcAdaptation::~NfcAdaptation()
119**
120** Description: class destructor
121**
122** Returns: none
123**
124*******************************************************************************/
125NfcAdaptation::~NfcAdaptation()
126{
127 mpInstance = NULL;
128}
129
130/*******************************************************************************
131**
132** Function: NfcAdaptation::GetInstance()
133**
134** Description: access class singleton
135**
136** Returns: pointer to the singleton object
137**
138*******************************************************************************/
139NfcAdaptation& NfcAdaptation::GetInstance()
140{
141 AutoThreadMutex a(sLock);
142
143 if (!mpInstance)
144 mpInstance = new NfcAdaptation;
145 return *mpInstance;
146}
147
148/*******************************************************************************
149**
150** Function: NfcAdaptation::Initialize()
151**
152** Description: class initializer
153**
154** Returns: none
155**
156*******************************************************************************/
157void NfcAdaptation::Initialize ()
158{
159 const char* func = "NfcAdaptation::Initialize";
Evan Chu0976d372013-04-30 14:49:29 -0400160 ALOGD("%s: enter", func);
161 ALOGE("%s: ver=%s nfa=%s", func, nfca_version_string, nfa_version_string);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800162 unsigned long num;
163
Evan Chua24be4f2013-11-13 15:30:16 -0500164 if ( GetNumValue ( NAME_USE_RAW_NCI_TRACE, &num, sizeof ( num ) ) )
165 {
166 if (num == 1)
167 {
168 // display protocol traces in raw format
169 ProtoDispAdapterUseRawOutput (TRUE);
170 ALOGD("%s: logging protocol in raw format", func);
171 }
172 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800173 if ( !GetStrValue ( NAME_NFA_STORAGE, bcm_nfc_location, sizeof ( bcm_nfc_location ) ) )
Evan Chud8f93322013-05-10 09:59:20 -0400174 {
Martijn Coenen077f48f2014-07-24 17:32:51 -0700175 strlcpy (bcm_nfc_location, "/data/nfc", sizeof(bcm_nfc_location));
Evan Chud8f93322013-05-10 09:59:20 -0400176 }
Andres Moralese4ecc7d2014-10-01 17:46:04 -0700177
178 initializeProtocolLogLevel ();
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700179
180 if ( GetStrValue ( NAME_NFA_DM_CFG, (char*)nfa_dm_cfg, sizeof ( nfa_dm_cfg ) ) )
181 p_nfa_dm_cfg = ( tNFA_DM_CFG * ) &nfa_dm_cfg[0];
182
183 if ( GetNumValue ( NAME_NFA_MAX_EE_SUPPORTED, &num, sizeof ( num ) ) )
184 {
185 nfa_ee_max_ee_cfg = num;
186 ALOGD("%s: Overriding NFA_EE_MAX_EE_SUPPORTED to use %d", func, nfa_ee_max_ee_cfg);
187 }
Jizhou Liao2ef08962015-06-08 16:11:04 -0700188 if ( GetNumValue ( NAME_NFA_POLL_BAIL_OUT_MODE, &num, sizeof ( num ) ) )
189 {
190 nfa_poll_bail_out_mode = num;
191 ALOGD("%s: Overriding NFA_POLL_BAIL_OUT_MODE to use %d", func, nfa_poll_bail_out_mode);
192 }
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700193
Jizhou Liaoacf1ec02015-06-30 10:25:41 -0700194 if ( GetStrValue ( NAME_NFA_PROPRIETARY_CFG, (char*)nfa_proprietary_cfg, sizeof ( tNFA_PROPRIETARY_CFG ) ) )
195 {
196 p_nfa_proprietary_cfg = (tNFA_PROPRIETARY_CFG*) &nfa_proprietary_cfg[0];
197 }
198
Evan Chub7cb5672014-02-07 15:01:21 -0500199 //configure device host whitelist of HCI host ID's; see specification ETSI TS 102 622 V11.1.10
200 //(2012-10), section 6.1.3.1
201 num = GetStrValue ( NAME_DEVICE_HOST_WHITE_LIST, (char*) deviceHostWhiteList, sizeof ( deviceHostWhiteList ) );
202 if (num)
203 {
204 memmove (&jni_nfa_hci_cfg, p_nfa_hci_cfg, sizeof(jni_nfa_hci_cfg));
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800205 jni_nfa_hci_cfg.num_whitelist_host = (uint8_t) num; //number of HCI host ID's in the whitelist
Evan Chub7cb5672014-02-07 15:01:21 -0500206 jni_nfa_hci_cfg.p_whitelist = deviceHostWhiteList; //array of HCI host ID's
207 p_nfa_hci_cfg = &jni_nfa_hci_cfg;
208 }
209
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800210 initializeGlobalAppLogLevel ();
211
Evan Chu5a7e8572013-05-01 10:10:31 -0400212 verify_stack_non_volatile_store ();
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700213 if ( GetNumValue ( NAME_PRESERVE_STORAGE, (char*)&num, sizeof ( num ) ) &&
214 (num == 1) )
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800215 ALOGD ("%s: preserve stack NV store", __func__);
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700216 else
Evan Chuedbfba92013-04-10 13:57:34 -0400217 {
Evan Chuedbfba92013-04-10 13:57:34 -0400218 delete_stack_non_volatile_store (FALSE);
219 }
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700220
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800221 GKI_init ();
222 GKI_enable ();
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800223 GKI_create_task ((TASKPTR)NFCA_TASK, BTU_TASK, (int8_t*)"NFCA_TASK", 0, 0, (pthread_cond_t*)NULL, NULL);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800224 {
225 AutoThreadMutex guard(mCondVar);
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800226 GKI_create_task ((TASKPTR)Thread, MMI_TASK, (int8_t*)"NFCA_THREAD", 0, 0, (pthread_cond_t*)NULL, NULL);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800227 mCondVar.wait();
228 }
229
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800230 mHalCallback = NULL;
231 memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
232 InitializeHalDeviceContext ();
233 ALOGD ("%s: exit", func);
234}
235
236/*******************************************************************************
237**
238** Function: NfcAdaptation::Finalize()
239**
240** Description: class finalizer
241**
242** Returns: none
243**
244*******************************************************************************/
245void NfcAdaptation::Finalize()
246{
247 const char* func = "NfcAdaptation::Finalize";
248 AutoThreadMutex a(sLock);
249
250 ALOGD ("%s: enter", func);
251 GKI_shutdown ();
252
253 resetConfig();
254
Martijn Coenene9e48e52016-09-06 16:05:25 +0200255 mCallback = NULL;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800256 memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
257
258 ALOGD ("%s: exit", func);
259 delete this;
260}
261
262/*******************************************************************************
263**
264** Function: NfcAdaptation::signal()
265**
266** Description: signal the CondVar to release the thread that is waiting
267**
268** Returns: none
269**
270*******************************************************************************/
271void NfcAdaptation::signal ()
272{
273 mCondVar.signal();
274}
275
276/*******************************************************************************
277**
278** Function: NfcAdaptation::NFCA_TASK()
279**
280** Description: NFCA_TASK runs the GKI main task
281**
282** Returns: none
283**
284*******************************************************************************/
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800285uint32_t NfcAdaptation::NFCA_TASK (uint32_t arg)
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800286{
287 const char* func = "NfcAdaptation::NFCA_TASK";
288 ALOGD ("%s: enter", func);
289 GKI_run (0);
290 ALOGD ("%s: exit", func);
Martijn Coenen0a85f652014-02-27 18:15:21 -0800291 return 0;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800292}
293
294/*******************************************************************************
295**
296** Function: NfcAdaptation::Thread()
297**
298** Description: Creates work threads
299**
300** Returns: none
301**
302*******************************************************************************/
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800303uint32_t NfcAdaptation::Thread (uint32_t arg)
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800304{
305 const char* func = "NfcAdaptation::Thread";
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800306 ALOGD ("%s: enter", func);
307
308 {
309 ThreadCondVar CondVar;
310 AutoThreadMutex guard(CondVar);
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800311 GKI_create_task ((TASKPTR)nfc_task, NFC_TASK, (int8_t*)"NFC_TASK", 0, 0, (pthread_cond_t*)CondVar, (pthread_mutex_t*)CondVar);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800312 CondVar.wait();
313 }
314
315 NfcAdaptation::GetInstance().signal();
316
317 GKI_exit_task (GKI_get_taskid ());
318 ALOGD ("%s: exit", func);
Martijn Coenen0a85f652014-02-27 18:15:21 -0800319 return 0;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800320}
321
322/*******************************************************************************
323**
324** Function: NfcAdaptation::GetHalEntryFuncs()
325**
326** Description: Get the set of HAL entry points.
327**
328** Returns: Functions pointers for HAL entry points.
329**
330*******************************************************************************/
331tHAL_NFC_ENTRY* NfcAdaptation::GetHalEntryFuncs ()
332{
333 return &mHalEntryFuncs;
334}
335
336/*******************************************************************************
337**
338** Function: NfcAdaptation::InitializeHalDeviceContext
339**
340** Description: Ask the generic Android HAL to find the Broadcom-specific HAL.
341**
342** Returns: None.
343**
344*******************************************************************************/
345void NfcAdaptation::InitializeHalDeviceContext ()
346{
347 const char* func = "NfcAdaptation::InitializeHalDeviceContext";
348 ALOGD ("%s: enter", func);
349 int ret = 0; //0 means success
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800350
351 mHalEntryFuncs.initialize = HalInitialize;
352 mHalEntryFuncs.terminate = HalTerminate;
353 mHalEntryFuncs.open = HalOpen;
354 mHalEntryFuncs.close = HalClose;
355 mHalEntryFuncs.core_initialized = HalCoreInitialized;
356 mHalEntryFuncs.write = HalWrite;
357 mHalEntryFuncs.prediscover = HalPrediscover;
358 mHalEntryFuncs.control_granted = HalControlGranted;
359 mHalEntryFuncs.power_cycle = HalPowerCycle;
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400360 mHalEntryFuncs.get_max_ee = HalGetMaxNfcee;
Chris Phoenix950638a2017-01-14 10:29:11 -0800361 ALOGI("%s: INfc::getService()", func);
362 mHal = INfc::getService();
Martijn Coenene9e48e52016-09-06 16:05:25 +0200363 LOG_FATAL_IF(mHal == nullptr, "Failed to retrieve the NFC HAL!");
Chris Phoenix950638a2017-01-14 10:29:11 -0800364 ALOGI("%s: INfc::getService() returned %p (%s)", func,
Martijn Coenene9e48e52016-09-06 16:05:25 +0200365 mHal.get(), (mHal->isRemote() ? "remote" : "local"));
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800366 ALOGD ("%s: exit", func);
367}
368
369/*******************************************************************************
370**
371** Function: NfcAdaptation::HalInitialize
372**
373** Description: Not implemented because this function is only needed
374** within the HAL.
375**
376** Returns: None.
377**
378*******************************************************************************/
379void NfcAdaptation::HalInitialize ()
380{
381 const char* func = "NfcAdaptation::HalInitialize";
382 ALOGD ("%s", func);
383}
384
385/*******************************************************************************
386**
387** Function: NfcAdaptation::HalTerminate
388**
389** Description: Not implemented because this function is only needed
390** within the HAL.
391**
392** Returns: None.
393**
394*******************************************************************************/
395void NfcAdaptation::HalTerminate ()
396{
397 const char* func = "NfcAdaptation::HalTerminate";
398 ALOGD ("%s", func);
399}
400
401/*******************************************************************************
402**
403** Function: NfcAdaptation::HalOpen
404**
405** Description: Turn on controller, download firmware.
406**
407** Returns: None.
408**
409*******************************************************************************/
410void NfcAdaptation::HalOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK* p_data_cback)
411{
412 const char* func = "NfcAdaptation::HalOpen";
413 ALOGD ("%s", func);
Martijn Coenene9e48e52016-09-06 16:05:25 +0200414 mCallback = new NfcClientCallback(p_hal_cback, p_data_cback);
415 mHal->open(mCallback);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800416}
417
418/*******************************************************************************
419**
420** Function: NfcAdaptation::HalClose
421**
422** Description: Turn off controller.
423**
424** Returns: None.
425**
426*******************************************************************************/
427void NfcAdaptation::HalClose ()
428{
429 const char* func = "NfcAdaptation::HalClose";
430 ALOGD ("%s", func);
Martijn Coenene9e48e52016-09-06 16:05:25 +0200431 mHal->close();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800432}
433
434/*******************************************************************************
435**
436** Function: NfcAdaptation::HalDeviceContextCallback
437**
438** Description: Translate generic Android HAL's callback into Broadcom-specific
439** callback function.
440**
441** Returns: None.
442**
443*******************************************************************************/
444void NfcAdaptation::HalDeviceContextCallback (nfc_event_t event, nfc_status_t event_status)
445{
446 const char* func = "NfcAdaptation::HalDeviceContextCallback";
447 ALOGD ("%s: event=%u", func, event);
448 if (mHalCallback)
449 mHalCallback (event, (tHAL_NFC_STATUS) event_status);
450}
451
452/*******************************************************************************
453**
454** Function: NfcAdaptation::HalDeviceContextDataCallback
455**
456** Description: Translate generic Android HAL's callback into Broadcom-specific
457** callback function.
458**
459** Returns: None.
460**
461*******************************************************************************/
462void NfcAdaptation::HalDeviceContextDataCallback (uint16_t data_len, uint8_t* p_data)
463{
464 const char* func = "NfcAdaptation::HalDeviceContextDataCallback";
465 ALOGD ("%s: len=%u", func, data_len);
466 if (mHalDataCallback)
467 mHalDataCallback (data_len, p_data);
468}
469
470/*******************************************************************************
471**
472** Function: NfcAdaptation::HalWrite
473**
474** Description: Write NCI message to the controller.
475**
476** Returns: None.
477**
478*******************************************************************************/
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800479void NfcAdaptation::HalWrite (uint16_t data_len, uint8_t* p_data)
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800480{
481 const char* func = "NfcAdaptation::HalWrite";
482 ALOGD ("%s", func);
Steven Moreland98cd45d2016-09-29 11:18:21 -0700483 ::android::hardware::nfc::V1_0::NfcData data;
484 data.setToExternal(p_data, data_len);
Martijn Coenene9e48e52016-09-06 16:05:25 +0200485 mHal->write(data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800486}
487
488/*******************************************************************************
489**
490** Function: NfcAdaptation::HalCoreInitialized
491**
492** Description: Adjust the configurable parameters in the controller.
493**
494** Returns: None.
495**
496*******************************************************************************/
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800497void NfcAdaptation::HalCoreInitialized (uint16_t data_len, uint8_t* p_core_init_rsp_params)
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800498{
499 const char* func = "NfcAdaptation::HalCoreInitialized";
500 ALOGD ("%s", func);
Martijn Coenene9e48e52016-09-06 16:05:25 +0200501 hidl_vec<uint8_t> data;
502 data.setToExternal(p_core_init_rsp_params, data_len);
503
Steven Moreland98cd45d2016-09-29 11:18:21 -0700504 mHal->coreInitialized(data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800505}
506
507/*******************************************************************************
508**
509** Function: NfcAdaptation::HalPrediscover
510**
511** Description: Perform any vendor-specific pre-discovery actions (if needed)
512** If any actions were performed TRUE will be returned, and
513** HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are
514** completed.
515**
516** Returns: TRUE if vendor-specific pre-discovery actions initialized
517** FALSE if no vendor-specific pre-discovery actions are needed.
518**
519*******************************************************************************/
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800520bool NfcAdaptation::HalPrediscover ()
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800521{
522 const char* func = "NfcAdaptation::HalPrediscover";
523 ALOGD ("%s", func);
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800524 bool retval = FALSE;
Steven Moreland98cd45d2016-09-29 11:18:21 -0700525 mHal->prediscover();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800526 return retval;
527}
528
529/*******************************************************************************
530**
531** Function: HAL_NfcControlGranted
532**
533** Description: Grant control to HAL control for sending NCI commands.
534** Call in response to HAL_REQUEST_CONTROL_EVT.
535** Must only be called when there are no NCI commands pending.
536** HAL_RELEASE_CONTROL_EVT will notify when HAL no longer
537** needs control of NCI.
538**
539** Returns: void
540**
541*******************************************************************************/
542void NfcAdaptation::HalControlGranted ()
543{
544 const char* func = "NfcAdaptation::HalControlGranted";
545 ALOGD ("%s", func);
Steven Moreland98cd45d2016-09-29 11:18:21 -0700546 mHal->controlGranted();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800547}
548
549/*******************************************************************************
550**
551** Function: NfcAdaptation::HalPowerCycle
552**
553** Description: Turn off and turn on the controller.
554**
555** Returns: None.
556**
557*******************************************************************************/
558void NfcAdaptation::HalPowerCycle ()
559{
560 const char* func = "NfcAdaptation::HalPowerCycle";
561 ALOGD ("%s", func);
Steven Moreland98cd45d2016-09-29 11:18:21 -0700562 mHal->powerCycle();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800563}
564
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400565/*******************************************************************************
566**
567** Function: NfcAdaptation::HalGetMaxNfcee
568**
569** Description: Turn off and turn on the controller.
570**
571** Returns: None.
572**
573*******************************************************************************/
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800574uint8_t NfcAdaptation::HalGetMaxNfcee()
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400575{
576 const char* func = "NfcAdaptation::HalPowerCycle";
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800577 uint8_t maxNfcee = 0;
Evan Chua24be4f2013-11-13 15:30:16 -0500578 ALOGD ("%s", func);
Evan Chua24be4f2013-11-13 15:30:16 -0500579
Martijn Coenene9e48e52016-09-06 16:05:25 +0200580 return nfa_ee_max_ee_cfg;
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400581}
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700582
Evan Chua24be4f2013-11-13 15:30:16 -0500583
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700584/*******************************************************************************
585**
586** Function: NfcAdaptation::DownloadFirmware
587**
588** Description: Download firmware patch files.
589**
590** Returns: None.
591**
592*******************************************************************************/
593void NfcAdaptation::DownloadFirmware ()
594{
595 const char* func = "NfcAdaptation::DownloadFirmware";
596 ALOGD ("%s: enter", func);
597 HalInitialize ();
598
599 mHalOpenCompletedEvent.lock ();
600 ALOGD ("%s: try open HAL", func);
601 HalOpen (HalDownloadFirmwareCallback, HalDownloadFirmwareDataCallback);
602 mHalOpenCompletedEvent.wait ();
603
604 mHalCloseCompletedEvent.lock ();
605 ALOGD ("%s: try close HAL", func);
606 HalClose ();
607 mHalCloseCompletedEvent.wait ();
608
609 HalTerminate ();
610 ALOGD ("%s: exit", func);
611}
612
613/*******************************************************************************
614**
615** Function: NfcAdaptation::HalDownloadFirmwareCallback
616**
617** Description: Receive events from the HAL.
618**
619** Returns: None.
620**
621*******************************************************************************/
622void NfcAdaptation::HalDownloadFirmwareCallback (nfc_event_t event, nfc_status_t event_status)
623{
624 const char* func = "NfcAdaptation::HalDownloadFirmwareCallback";
625 ALOGD ("%s: event=0x%X", func, event);
626 switch (event)
627 {
628 case HAL_NFC_OPEN_CPLT_EVT:
629 {
630 ALOGD ("%s: HAL_NFC_OPEN_CPLT_EVT", func);
631 mHalOpenCompletedEvent.signal ();
632 break;
633 }
634 case HAL_NFC_CLOSE_CPLT_EVT:
635 {
636 ALOGD ("%s: HAL_NFC_CLOSE_CPLT_EVT", func);
637 mHalCloseCompletedEvent.signal ();
638 break;
639 }
640 }
641}
642
643/*******************************************************************************
644**
645** Function: NfcAdaptation::HalDownloadFirmwareDataCallback
646**
647** Description: Receive data events from the HAL.
648**
649** Returns: None.
650**
651*******************************************************************************/
652void NfcAdaptation::HalDownloadFirmwareDataCallback (uint16_t data_len, uint8_t* p_data)
653{
654}
655
656
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800657/*******************************************************************************
658**
659** Function: ThreadMutex::ThreadMutex()
660**
661** Description: class constructor
662**
663** Returns: none
664**
665*******************************************************************************/
666ThreadMutex::ThreadMutex()
667{
668 pthread_mutexattr_t mutexAttr;
669
670 pthread_mutexattr_init(&mutexAttr);
671 pthread_mutex_init(&mMutex, &mutexAttr);
672 pthread_mutexattr_destroy(&mutexAttr);
673}
674
675/*******************************************************************************
676**
677** Function: ThreadMutex::~ThreadMutex()
678**
679** Description: class destructor
680**
681** Returns: none
682**
683*******************************************************************************/
684ThreadMutex::~ThreadMutex()
685{
686 pthread_mutex_destroy(&mMutex);
687}
688
689/*******************************************************************************
690**
691** Function: ThreadMutex::lock()
692**
693** Description: lock kthe mutex
694**
695** Returns: none
696**
697*******************************************************************************/
698void ThreadMutex::lock()
699{
700 pthread_mutex_lock(&mMutex);
701}
702
703/*******************************************************************************
704**
705** Function: ThreadMutex::unblock()
706**
707** Description: unlock the mutex
708**
709** Returns: none
710**
711*******************************************************************************/
712void ThreadMutex::unlock()
713{
714 pthread_mutex_unlock(&mMutex);
715}
716
717/*******************************************************************************
718**
719** Function: ThreadCondVar::ThreadCondVar()
720**
721** Description: class constructor
722**
723** Returns: none
724**
725*******************************************************************************/
726ThreadCondVar::ThreadCondVar()
727{
728 pthread_condattr_t CondAttr;
729
730 pthread_condattr_init(&CondAttr);
731 pthread_cond_init(&mCondVar, &CondAttr);
732
733 pthread_condattr_destroy(&CondAttr);
734}
735
736/*******************************************************************************
737**
738** Function: ThreadCondVar::~ThreadCondVar()
739**
740** Description: class destructor
741**
742** Returns: none
743**
744*******************************************************************************/
745ThreadCondVar::~ThreadCondVar()
746{
747 pthread_cond_destroy(&mCondVar);
748}
749
750/*******************************************************************************
751**
752** Function: ThreadCondVar::wait()
753**
754** Description: wait on the mCondVar
755**
756** Returns: none
757**
758*******************************************************************************/
759void ThreadCondVar::wait()
760{
761 pthread_cond_wait(&mCondVar, *this);
762 pthread_mutex_unlock(*this);
763}
764
765/*******************************************************************************
766**
767** Function: ThreadCondVar::signal()
768**
769** Description: signal the mCondVar
770**
771** Returns: none
772**
773*******************************************************************************/
774void ThreadCondVar::signal()
775{
776 AutoThreadMutex a(*this);
777 pthread_cond_signal(&mCondVar);
778}
779
780/*******************************************************************************
781**
782** Function: AutoThreadMutex::AutoThreadMutex()
783**
784** Description: class constructor, automatically lock the mutex
785**
786** Returns: none
787**
788*******************************************************************************/
789AutoThreadMutex::AutoThreadMutex(ThreadMutex &m)
790 : mm(m)
791{
792 mm.lock();
793}
794
795/*******************************************************************************
796**
797** Function: AutoThreadMutex::~AutoThreadMutex()
798**
799** Description: class destructor, automatically unlock the mutex
800**
801** Returns: none
802**
803*******************************************************************************/
804AutoThreadMutex::~AutoThreadMutex()
805{
806 mm.unlock();
807}