blob: 371e31b397b3d58e0e52a3e60dd765cbd909f17a [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 ******************************************************************************/
18#include "OverrideLog.h"
19#include "NfcAdaptation.h"
20extern "C"
21{
22 #include "gki.h"
23 #include "nfa_api.h"
24 #include "nfc_int.h"
Jizhou Liaoacf1ec02015-06-30 10:25:41 -070025 #include "vendor_cfg.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080026}
27#include "config.h"
Evan Chua24be4f2013-11-13 15:30:16 -050028#include "android_logmsg.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080029
Jizhou Liao65ebec52016-04-05 17:09:24 -070030#undef LOG_TAG
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080031#define LOG_TAG "NfcAdaptation"
32
33extern "C" void GKI_shutdown();
34extern void resetConfig();
Evan Chuedbfba92013-04-10 13:57:34 -040035extern "C" void verify_stack_non_volatile_store ();
36extern "C" void delete_stack_non_volatile_store (BOOLEAN forceDelete);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080037
38NfcAdaptation* NfcAdaptation::mpInstance = NULL;
39ThreadMutex NfcAdaptation::sLock;
40nfc_nci_device_t* NfcAdaptation::mHalDeviceContext = NULL;
41tHAL_NFC_CBACK* NfcAdaptation::mHalCallback = NULL;
42tHAL_NFC_DATA_CBACK* NfcAdaptation::mHalDataCallback = NULL;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070043ThreadCondVar NfcAdaptation::mHalOpenCompletedEvent;
44ThreadCondVar NfcAdaptation::mHalCloseCompletedEvent;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080045
46UINT32 ScrProtocolTraceFlag = SCR_PROTO_TRACE_ALL; //0x017F00;
47UINT8 appl_trace_level = 0xff;
48char bcm_nfc_location[120];
Martijn Coenen077f48f2014-07-24 17:32:51 -070049char nci_hal_module[64];
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080050
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070051static UINT8 nfa_dm_cfg[sizeof ( tNFA_DM_CFG ) ];
Jizhou Liaoacf1ec02015-06-30 10:25:41 -070052static UINT8 nfa_proprietary_cfg[sizeof ( tNFA_PROPRIETARY_CFG )];
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070053extern tNFA_DM_CFG *p_nfa_dm_cfg;
Jizhou Liaoacf1ec02015-06-30 10:25:41 -070054extern tNFA_PROPRIETARY_CFG *p_nfa_proprietary_cfg;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070055extern UINT8 nfa_ee_max_ee_cfg;
Evan Chu0976d372013-04-30 14:49:29 -040056extern const UINT8 nfca_version_string [];
57extern const UINT8 nfa_version_string [];
Evan Chub7cb5672014-02-07 15:01:21 -050058static UINT8 deviceHostWhiteList [NFA_HCI_MAX_HOST_IN_NETWORK];
59static tNFA_HCI_CFG jni_nfa_hci_cfg;
60extern tNFA_HCI_CFG *p_nfa_hci_cfg;
Jizhou Liao2ef08962015-06-08 16:11:04 -070061extern BOOLEAN nfa_poll_bail_out_mode;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070062
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080063/*******************************************************************************
64**
65** Function: NfcAdaptation::NfcAdaptation()
66**
67** Description: class constructor
68**
69** Returns: none
70**
71*******************************************************************************/
72NfcAdaptation::NfcAdaptation()
73{
Evan Chu15696412014-07-16 16:40:22 -040074 memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080075}
76
77/*******************************************************************************
78**
79** Function: NfcAdaptation::~NfcAdaptation()
80**
81** Description: class destructor
82**
83** Returns: none
84**
85*******************************************************************************/
86NfcAdaptation::~NfcAdaptation()
87{
88 mpInstance = NULL;
89}
90
91/*******************************************************************************
92**
93** Function: NfcAdaptation::GetInstance()
94**
95** Description: access class singleton
96**
97** Returns: pointer to the singleton object
98**
99*******************************************************************************/
100NfcAdaptation& NfcAdaptation::GetInstance()
101{
102 AutoThreadMutex a(sLock);
103
104 if (!mpInstance)
105 mpInstance = new NfcAdaptation;
106 return *mpInstance;
107}
108
109/*******************************************************************************
110**
111** Function: NfcAdaptation::Initialize()
112**
113** Description: class initializer
114**
115** Returns: none
116**
117*******************************************************************************/
118void NfcAdaptation::Initialize ()
119{
120 const char* func = "NfcAdaptation::Initialize";
Evan Chu0976d372013-04-30 14:49:29 -0400121 ALOGD("%s: enter", func);
122 ALOGE("%s: ver=%s nfa=%s", func, nfca_version_string, nfa_version_string);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800123 unsigned long num;
124
Evan Chua24be4f2013-11-13 15:30:16 -0500125 if ( GetNumValue ( NAME_USE_RAW_NCI_TRACE, &num, sizeof ( num ) ) )
126 {
127 if (num == 1)
128 {
129 // display protocol traces in raw format
130 ProtoDispAdapterUseRawOutput (TRUE);
131 ALOGD("%s: logging protocol in raw format", func);
132 }
133 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800134 if ( !GetStrValue ( NAME_NFA_STORAGE, bcm_nfc_location, sizeof ( bcm_nfc_location ) ) )
Evan Chud8f93322013-05-10 09:59:20 -0400135 {
Martijn Coenen077f48f2014-07-24 17:32:51 -0700136 strlcpy (bcm_nfc_location, "/data/nfc", sizeof(bcm_nfc_location));
Evan Chud8f93322013-05-10 09:59:20 -0400137 }
Andres Moralese4ecc7d2014-10-01 17:46:04 -0700138
139 initializeProtocolLogLevel ();
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700140
141 if ( GetStrValue ( NAME_NFA_DM_CFG, (char*)nfa_dm_cfg, sizeof ( nfa_dm_cfg ) ) )
142 p_nfa_dm_cfg = ( tNFA_DM_CFG * ) &nfa_dm_cfg[0];
143
144 if ( GetNumValue ( NAME_NFA_MAX_EE_SUPPORTED, &num, sizeof ( num ) ) )
145 {
146 nfa_ee_max_ee_cfg = num;
147 ALOGD("%s: Overriding NFA_EE_MAX_EE_SUPPORTED to use %d", func, nfa_ee_max_ee_cfg);
148 }
Jizhou Liao2ef08962015-06-08 16:11:04 -0700149 if ( GetNumValue ( NAME_NFA_POLL_BAIL_OUT_MODE, &num, sizeof ( num ) ) )
150 {
151 nfa_poll_bail_out_mode = num;
152 ALOGD("%s: Overriding NFA_POLL_BAIL_OUT_MODE to use %d", func, nfa_poll_bail_out_mode);
153 }
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700154
Jizhou Liaoacf1ec02015-06-30 10:25:41 -0700155 if ( GetStrValue ( NAME_NFA_PROPRIETARY_CFG, (char*)nfa_proprietary_cfg, sizeof ( tNFA_PROPRIETARY_CFG ) ) )
156 {
157 p_nfa_proprietary_cfg = (tNFA_PROPRIETARY_CFG*) &nfa_proprietary_cfg[0];
158 }
159
Evan Chub7cb5672014-02-07 15:01:21 -0500160 //configure device host whitelist of HCI host ID's; see specification ETSI TS 102 622 V11.1.10
161 //(2012-10), section 6.1.3.1
162 num = GetStrValue ( NAME_DEVICE_HOST_WHITE_LIST, (char*) deviceHostWhiteList, sizeof ( deviceHostWhiteList ) );
163 if (num)
164 {
165 memmove (&jni_nfa_hci_cfg, p_nfa_hci_cfg, sizeof(jni_nfa_hci_cfg));
166 jni_nfa_hci_cfg.num_whitelist_host = (UINT8) num; //number of HCI host ID's in the whitelist
167 jni_nfa_hci_cfg.p_whitelist = deviceHostWhiteList; //array of HCI host ID's
168 p_nfa_hci_cfg = &jni_nfa_hci_cfg;
169 }
170
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800171 initializeGlobalAppLogLevel ();
172
Evan Chu5a7e8572013-05-01 10:10:31 -0400173 verify_stack_non_volatile_store ();
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700174 if ( GetNumValue ( NAME_PRESERVE_STORAGE, (char*)&num, sizeof ( num ) ) &&
175 (num == 1) )
176 ALOGD ("%s: preserve stack NV store", __FUNCTION__);
177 else
Evan Chuedbfba92013-04-10 13:57:34 -0400178 {
Evan Chuedbfba92013-04-10 13:57:34 -0400179 delete_stack_non_volatile_store (FALSE);
180 }
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700181
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800182 GKI_init ();
183 GKI_enable ();
184 GKI_create_task ((TASKPTR)NFCA_TASK, BTU_TASK, (INT8*)"NFCA_TASK", 0, 0, (pthread_cond_t*)NULL, NULL);
185 {
186 AutoThreadMutex guard(mCondVar);
187 GKI_create_task ((TASKPTR)Thread, MMI_TASK, (INT8*)"NFCA_THREAD", 0, 0, (pthread_cond_t*)NULL, NULL);
188 mCondVar.wait();
189 }
190
191 mHalDeviceContext = NULL;
192 mHalCallback = NULL;
193 memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
194 InitializeHalDeviceContext ();
195 ALOGD ("%s: exit", func);
196}
197
198/*******************************************************************************
199**
200** Function: NfcAdaptation::Finalize()
201**
202** Description: class finalizer
203**
204** Returns: none
205**
206*******************************************************************************/
207void NfcAdaptation::Finalize()
208{
209 const char* func = "NfcAdaptation::Finalize";
210 AutoThreadMutex a(sLock);
211
212 ALOGD ("%s: enter", func);
213 GKI_shutdown ();
214
215 resetConfig();
216
217 nfc_nci_close(mHalDeviceContext); //close the HAL's device context
218 mHalDeviceContext = NULL;
219 mHalCallback = NULL;
220 memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
221
222 ALOGD ("%s: exit", func);
223 delete this;
224}
225
226/*******************************************************************************
227**
228** Function: NfcAdaptation::signal()
229**
230** Description: signal the CondVar to release the thread that is waiting
231**
232** Returns: none
233**
234*******************************************************************************/
235void NfcAdaptation::signal ()
236{
237 mCondVar.signal();
238}
239
240/*******************************************************************************
241**
242** Function: NfcAdaptation::NFCA_TASK()
243**
244** Description: NFCA_TASK runs the GKI main task
245**
246** Returns: none
247**
248*******************************************************************************/
249UINT32 NfcAdaptation::NFCA_TASK (UINT32 arg)
250{
251 const char* func = "NfcAdaptation::NFCA_TASK";
252 ALOGD ("%s: enter", func);
253 GKI_run (0);
254 ALOGD ("%s: exit", func);
Martijn Coenen0a85f652014-02-27 18:15:21 -0800255 return 0;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800256}
257
258/*******************************************************************************
259**
260** Function: NfcAdaptation::Thread()
261**
262** Description: Creates work threads
263**
264** Returns: none
265**
266*******************************************************************************/
267UINT32 NfcAdaptation::Thread (UINT32 arg)
268{
269 const char* func = "NfcAdaptation::Thread";
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800270 ALOGD ("%s: enter", func);
271
272 {
273 ThreadCondVar CondVar;
274 AutoThreadMutex guard(CondVar);
275 GKI_create_task ((TASKPTR)nfc_task, NFC_TASK, (INT8*)"NFC_TASK", 0, 0, (pthread_cond_t*)CondVar, (pthread_mutex_t*)CondVar);
276 CondVar.wait();
277 }
278
279 NfcAdaptation::GetInstance().signal();
280
281 GKI_exit_task (GKI_get_taskid ());
282 ALOGD ("%s: exit", func);
Martijn Coenen0a85f652014-02-27 18:15:21 -0800283 return 0;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800284}
285
286/*******************************************************************************
287**
288** Function: NfcAdaptation::GetHalEntryFuncs()
289**
290** Description: Get the set of HAL entry points.
291**
292** Returns: Functions pointers for HAL entry points.
293**
294*******************************************************************************/
295tHAL_NFC_ENTRY* NfcAdaptation::GetHalEntryFuncs ()
296{
297 return &mHalEntryFuncs;
298}
299
300/*******************************************************************************
301**
302** Function: NfcAdaptation::InitializeHalDeviceContext
303**
304** Description: Ask the generic Android HAL to find the Broadcom-specific HAL.
305**
306** Returns: None.
307**
308*******************************************************************************/
309void NfcAdaptation::InitializeHalDeviceContext ()
310{
311 const char* func = "NfcAdaptation::InitializeHalDeviceContext";
312 ALOGD ("%s: enter", func);
313 int ret = 0; //0 means success
Martijn Coenen077f48f2014-07-24 17:32:51 -0700314 if ( !GetStrValue ( NAME_NCI_HAL_MODULE, nci_hal_module, sizeof ( nci_hal_module) ) )
315 {
316 ALOGE("No HAL module specified in config, falling back to BCM2079x");
317 strlcpy (nci_hal_module, "nfc_nci.bcm2079x", sizeof(nci_hal_module));
318 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800319 const hw_module_t* hw_module = NULL;
320
321 mHalEntryFuncs.initialize = HalInitialize;
322 mHalEntryFuncs.terminate = HalTerminate;
323 mHalEntryFuncs.open = HalOpen;
324 mHalEntryFuncs.close = HalClose;
325 mHalEntryFuncs.core_initialized = HalCoreInitialized;
326 mHalEntryFuncs.write = HalWrite;
327 mHalEntryFuncs.prediscover = HalPrediscover;
328 mHalEntryFuncs.control_granted = HalControlGranted;
329 mHalEntryFuncs.power_cycle = HalPowerCycle;
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400330 mHalEntryFuncs.get_max_ee = HalGetMaxNfcee;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800331
Martijn Coenen077f48f2014-07-24 17:32:51 -0700332 ret = hw_get_module (nci_hal_module, &hw_module);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800333 if (ret == 0)
334 {
335 ret = nfc_nci_open (hw_module, &mHalDeviceContext);
336 if (ret != 0)
337 ALOGE ("%s: nfc_nci_open fail", func);
338 }
339 else
Martijn Coenen077f48f2014-07-24 17:32:51 -0700340 ALOGE ("%s: fail hw_get_module %s", func, nci_hal_module);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800341 ALOGD ("%s: exit", func);
342}
343
344/*******************************************************************************
345**
346** Function: NfcAdaptation::HalInitialize
347**
348** Description: Not implemented because this function is only needed
349** within the HAL.
350**
351** Returns: None.
352**
353*******************************************************************************/
354void NfcAdaptation::HalInitialize ()
355{
356 const char* func = "NfcAdaptation::HalInitialize";
357 ALOGD ("%s", func);
358}
359
360/*******************************************************************************
361**
362** Function: NfcAdaptation::HalTerminate
363**
364** Description: Not implemented because this function is only needed
365** within the HAL.
366**
367** Returns: None.
368**
369*******************************************************************************/
370void NfcAdaptation::HalTerminate ()
371{
372 const char* func = "NfcAdaptation::HalTerminate";
373 ALOGD ("%s", func);
374}
375
376/*******************************************************************************
377**
378** Function: NfcAdaptation::HalOpen
379**
380** Description: Turn on controller, download firmware.
381**
382** Returns: None.
383**
384*******************************************************************************/
385void NfcAdaptation::HalOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK* p_data_cback)
386{
387 const char* func = "NfcAdaptation::HalOpen";
388 ALOGD ("%s", func);
389 if (mHalDeviceContext)
390 {
391 mHalCallback = p_hal_cback;
392 mHalDataCallback = p_data_cback;
393 mHalDeviceContext->open (mHalDeviceContext, HalDeviceContextCallback, HalDeviceContextDataCallback);
394 }
395}
396
397/*******************************************************************************
398**
399** Function: NfcAdaptation::HalClose
400**
401** Description: Turn off controller.
402**
403** Returns: None.
404**
405*******************************************************************************/
406void NfcAdaptation::HalClose ()
407{
408 const char* func = "NfcAdaptation::HalClose";
409 ALOGD ("%s", func);
410 if (mHalDeviceContext)
411 {
412 mHalDeviceContext->close (mHalDeviceContext);
413 }
414}
415
416/*******************************************************************************
417**
418** Function: NfcAdaptation::HalDeviceContextCallback
419**
420** Description: Translate generic Android HAL's callback into Broadcom-specific
421** callback function.
422**
423** Returns: None.
424**
425*******************************************************************************/
426void NfcAdaptation::HalDeviceContextCallback (nfc_event_t event, nfc_status_t event_status)
427{
428 const char* func = "NfcAdaptation::HalDeviceContextCallback";
429 ALOGD ("%s: event=%u", func, event);
430 if (mHalCallback)
431 mHalCallback (event, (tHAL_NFC_STATUS) event_status);
432}
433
434/*******************************************************************************
435**
436** Function: NfcAdaptation::HalDeviceContextDataCallback
437**
438** Description: Translate generic Android HAL's callback into Broadcom-specific
439** callback function.
440**
441** Returns: None.
442**
443*******************************************************************************/
444void NfcAdaptation::HalDeviceContextDataCallback (uint16_t data_len, uint8_t* p_data)
445{
446 const char* func = "NfcAdaptation::HalDeviceContextDataCallback";
447 ALOGD ("%s: len=%u", func, data_len);
448 if (mHalDataCallback)
449 mHalDataCallback (data_len, p_data);
450}
451
452/*******************************************************************************
453**
454** Function: NfcAdaptation::HalWrite
455**
456** Description: Write NCI message to the controller.
457**
458** Returns: None.
459**
460*******************************************************************************/
461void NfcAdaptation::HalWrite (UINT16 data_len, UINT8* p_data)
462{
463 const char* func = "NfcAdaptation::HalWrite";
464 ALOGD ("%s", func);
465 if (mHalDeviceContext)
466 {
467 mHalDeviceContext->write (mHalDeviceContext, data_len, p_data);
468 }
469}
470
471/*******************************************************************************
472**
473** Function: NfcAdaptation::HalCoreInitialized
474**
475** Description: Adjust the configurable parameters in the controller.
476**
477** Returns: None.
478**
479*******************************************************************************/
480void NfcAdaptation::HalCoreInitialized (UINT8* p_core_init_rsp_params)
481{
482 const char* func = "NfcAdaptation::HalCoreInitialized";
483 ALOGD ("%s", func);
484 if (mHalDeviceContext)
485 {
486 mHalDeviceContext->core_initialized (mHalDeviceContext, p_core_init_rsp_params);
487 }
488}
489
490/*******************************************************************************
491**
492** Function: NfcAdaptation::HalPrediscover
493**
494** Description: Perform any vendor-specific pre-discovery actions (if needed)
495** If any actions were performed TRUE will be returned, and
496** HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are
497** completed.
498**
499** Returns: TRUE if vendor-specific pre-discovery actions initialized
500** FALSE if no vendor-specific pre-discovery actions are needed.
501**
502*******************************************************************************/
503BOOLEAN NfcAdaptation::HalPrediscover ()
504{
505 const char* func = "NfcAdaptation::HalPrediscover";
506 ALOGD ("%s", func);
507 BOOLEAN retval = FALSE;
508
509 if (mHalDeviceContext)
510 {
Evan Chu45e68232013-05-01 11:29:02 -0700511 retval = mHalDeviceContext->pre_discover (mHalDeviceContext);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800512 }
513 return retval;
514}
515
516/*******************************************************************************
517**
518** Function: HAL_NfcControlGranted
519**
520** Description: Grant control to HAL control for sending NCI commands.
521** Call in response to HAL_REQUEST_CONTROL_EVT.
522** Must only be called when there are no NCI commands pending.
523** HAL_RELEASE_CONTROL_EVT will notify when HAL no longer
524** needs control of NCI.
525**
526** Returns: void
527**
528*******************************************************************************/
529void NfcAdaptation::HalControlGranted ()
530{
531 const char* func = "NfcAdaptation::HalControlGranted";
532 ALOGD ("%s", func);
533 if (mHalDeviceContext)
534 {
535 mHalDeviceContext->control_granted (mHalDeviceContext);
536 }
537}
538
539/*******************************************************************************
540**
541** Function: NfcAdaptation::HalPowerCycle
542**
543** Description: Turn off and turn on the controller.
544**
545** Returns: None.
546**
547*******************************************************************************/
548void NfcAdaptation::HalPowerCycle ()
549{
550 const char* func = "NfcAdaptation::HalPowerCycle";
551 ALOGD ("%s", func);
552 if (mHalDeviceContext)
553 {
554 mHalDeviceContext->power_cycle (mHalDeviceContext);
555 }
556}
557
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400558/*******************************************************************************
559**
560** Function: NfcAdaptation::HalGetMaxNfcee
561**
562** Description: Turn off and turn on the controller.
563**
564** Returns: None.
565**
566*******************************************************************************/
567UINT8 NfcAdaptation::HalGetMaxNfcee()
568{
569 const char* func = "NfcAdaptation::HalPowerCycle";
570 UINT8 maxNfcee = 0;
Evan Chua24be4f2013-11-13 15:30:16 -0500571 ALOGD ("%s", func);
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400572 if (mHalDeviceContext)
573 {
Martijn Coenenb4b1c462013-08-05 13:14:20 -0700574 // TODO maco call into HAL when we figure out binary compatibility.
575 return nfa_ee_max_ee_cfg;
Evan Chua24be4f2013-11-13 15:30:16 -0500576
577 //mHalDeviceContext->get_max_ee (mHalDeviceContext, &maxNfcee);
Paul Chaissonb20cbf32013-07-12 13:25:09 -0400578 }
579
580 return maxNfcee;
581}
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}