NfcAdaptation.cpp revision b20cbf35a541d380f32d1f43a78feb44e9e0dc1b
1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/******************************************************************************
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  Copyright (C) 1999-2012 Broadcom Corporation
4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  Licensed under the Apache License, Version 2.0 (the "License");
6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  you may not use this file except in compliance with the License.
7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  You may obtain a copy of the License at:
8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  http://www.apache.org/licenses/LICENSE-2.0
10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  Unless required by applicable law or agreed to in writing, software
12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  distributed under the License is distributed on an "AS IS" BASIS,
13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  See the License for the specific language governing permissions and
15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *  limitations under the License.
16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson ******************************************************************************/
18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson#include "OverrideLog.h"
19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson#include "NfcAdaptation.h"
201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertextern "C"
21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
22090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    #include "gki.h"
231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    #include "nfa_api.h"
24090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    #include "nfc_int.h"
25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
26090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson#include "config.h"
27090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
28090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson#define LOG_TAG "NfcAdaptation"
29090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
30090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern "C" void GKI_shutdown();
31090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern void resetConfig();
32090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern "C" void verify_stack_non_volatile_store ();
33090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern "C" void delete_stack_non_volatile_store (BOOLEAN forceDelete);
34090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
35090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonNfcAdaptation* NfcAdaptation::mpInstance = NULL;
36090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonThreadMutex NfcAdaptation::sLock;
37090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonnfc_nci_device_t* NfcAdaptation::mHalDeviceContext = NULL;
38090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsontHAL_NFC_CBACK* NfcAdaptation::mHalCallback = NULL;
39090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsontHAL_NFC_DATA_CBACK* NfcAdaptation::mHalDataCallback = NULL;
40090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonThreadCondVar NfcAdaptation::mHalOpenCompletedEvent;
41090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonThreadCondVar NfcAdaptation::mHalCloseCompletedEvent;
42090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
43090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonUINT32 ScrProtocolTraceFlag = SCR_PROTO_TRACE_ALL; //0x017F00;
44090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonUINT8 appl_trace_level = 0xff;
45090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonchar bcm_nfc_location[120];
46090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
47090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonstatic UINT8 nfa_dm_cfg[sizeof ( tNFA_DM_CFG ) ];
48090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern tNFA_DM_CFG *p_nfa_dm_cfg;
49090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern UINT8 nfa_ee_max_ee_cfg;
50090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern const UINT8  nfca_version_string [];
51090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonextern const UINT8  nfa_version_string [];
52090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
53090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
54090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
55090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::NfcAdaptation()
56090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
57090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: class constructor
58090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
59090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     none
60090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
61090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
62090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonNfcAdaptation::NfcAdaptation()
63090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
64090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
65090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
66090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
67090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
68090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::~NfcAdaptation()
691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert**
70090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: class destructor
711d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert**
72090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     none
73090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
74090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
75090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonNfcAdaptation::~NfcAdaptation()
76090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
77090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mpInstance = NULL;
78090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
79090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
80090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
81090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
82090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::GetInstance()
83090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
84090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: access class singleton
85090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
86090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     pointer to the singleton object
87090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
88090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
89090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonNfcAdaptation& NfcAdaptation::GetInstance()
90090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
91090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    AutoThreadMutex  a(sLock);
92090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
93090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if (!mpInstance)
94090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        mpInstance = new NfcAdaptation;
95090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return *mpInstance;
96090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
97090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
98090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
99090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
100090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::Initialize()
101090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
102090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: class initializer
103090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
104090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     none
105090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
106090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
107090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::Initialize ()
108090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
109090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::Initialize";
110090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD("%s: enter", func);
111090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGE("%s: ver=%s nfa=%s", func, nfca_version_string, nfa_version_string);
112090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    unsigned long num;
113090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
114090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if ( !GetStrValue ( NAME_NFA_STORAGE, bcm_nfc_location, sizeof ( bcm_nfc_location ) ) )
115090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
116090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        memset (bcm_nfc_location, 0, sizeof(bcm_nfc_location));
117090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        strncpy (bcm_nfc_location, "/data/nfc", 9);
118090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
119090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if ( GetNumValue ( NAME_PROTOCOL_TRACE_LEVEL, &num, sizeof ( num ) ) )
120090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        ScrProtocolTraceFlag = num;
121090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
122090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if ( GetStrValue ( NAME_NFA_DM_CFG, (char*)nfa_dm_cfg, sizeof ( nfa_dm_cfg ) ) )
123090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        p_nfa_dm_cfg = ( tNFA_DM_CFG * ) &nfa_dm_cfg[0];
124090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
125090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if ( GetNumValue ( NAME_NFA_MAX_EE_SUPPORTED, &num, sizeof ( num ) ) )
126090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
127090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        nfa_ee_max_ee_cfg = num;
128090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        ALOGD("%s: Overriding NFA_EE_MAX_EE_SUPPORTED to use %d", func, nfa_ee_max_ee_cfg);
129090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
130090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
1311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    initializeGlobalAppLogLevel ();
1321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
133090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    verify_stack_non_volatile_store ();
134090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if ( GetNumValue ( NAME_PRESERVE_STORAGE, (char*)&num, sizeof ( num ) ) &&
135090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson            (num == 1) )
136090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        ALOGD ("%s: preserve stack NV store", __FUNCTION__);
137090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    else
138090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
139090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        delete_stack_non_volatile_store (FALSE);
140090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
141090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
142090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    GKI_init ();
143090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    GKI_enable ();
144090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    GKI_create_task ((TASKPTR)NFCA_TASK, BTU_TASK, (INT8*)"NFCA_TASK", 0, 0, (pthread_cond_t*)NULL, NULL);
145090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
146090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        AutoThreadMutex guard(mCondVar);
147090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        GKI_create_task ((TASKPTR)Thread, MMI_TASK, (INT8*)"NFCA_THREAD", 0, 0, (pthread_cond_t*)NULL, NULL);
148090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        mCondVar.wait();
149090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
150090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
151090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalDeviceContext = NULL;
152090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalCallback =  NULL;
153090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
154090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    InitializeHalDeviceContext ();
155090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: exit", func);
156090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
157090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
158090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
159090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
160090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::Finalize()
161090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
162090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: class finalizer
163090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
164090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     none
165090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
166090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
167090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::Finalize()
168090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
169090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::Finalize";
170090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    AutoThreadMutex  a(sLock);
171090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
172090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: enter", func);
173090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    GKI_shutdown ();
174090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
175090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    resetConfig();
176090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
177090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    nfc_nci_close(mHalDeviceContext); //close the HAL's device context
178090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalDeviceContext = NULL;
179090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalCallback = NULL;
180090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    memset (&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
181090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
182090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: exit", func);
183090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    delete this;
184090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
185090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
186090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
187090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
188090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::signal()
189090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
190090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: signal the CondVar to release the thread that is waiting
191090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
192090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     none
193090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
194090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
195090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::signal ()
196090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
197090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mCondVar.signal();
198090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
199090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
200090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
201090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
202090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::NFCA_TASK()
203090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
204090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: NFCA_TASK runs the GKI main task
205090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
206090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     none
207090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
208090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
209090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonUINT32 NfcAdaptation::NFCA_TASK (UINT32 arg)
210090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
211090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::NFCA_TASK";
212090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: enter", func);
213090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    GKI_run (0);
2141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    ALOGD ("%s: exit", func);
2151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    return NULL;
2161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert}
217090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
218090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
219090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
220090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::Thread()
221090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
222090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Creates work threads
223090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
224090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     none
2251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert**
226090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
227090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsonUINT32 NfcAdaptation::Thread (UINT32 arg)
228090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
2291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    const char* func = "NfcAdaptation::Thread";
230090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: enter", func);
231090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
232090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
233090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        ThreadCondVar    CondVar;
2341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert        AutoThreadMutex  guard(CondVar);
235090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        GKI_create_task ((TASKPTR)nfc_task, NFC_TASK, (INT8*)"NFC_TASK", 0, 0, (pthread_cond_t*)CondVar, (pthread_mutex_t*)CondVar);
236090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        CondVar.wait();
237090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
238090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
239090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    NfcAdaptation::GetInstance().signal();
240090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
241090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    GKI_exit_task (GKI_get_taskid ());
242090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: exit", func);
243090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return NULL;
244090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
245090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
246090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
247090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
248090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::GetHalEntryFuncs()
249090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
250090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Get the set of HAL entry points.
251090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
252090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     Functions pointers for HAL entry points.
253090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
254090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
255090f9b4c879985bc747c214f82c62471e60c7742Jesse WilsontHAL_NFC_ENTRY* NfcAdaptation::GetHalEntryFuncs ()
256090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
257090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return &mHalEntryFuncs;
258090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
259090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
260090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
261090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
262090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::InitializeHalDeviceContext
263090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
264090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Ask the generic Android HAL to find the Broadcom-specific HAL.
265090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
266090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     None.
267090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
268090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
269090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::InitializeHalDeviceContext ()
270090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
271090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::InitializeHalDeviceContext";
272090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: enter", func);
273090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    int ret = 0; //0 means success
274090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const hw_module_t* hw_module = NULL;
275090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
276090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.initialize = HalInitialize;
277090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.terminate = HalTerminate;
278090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.open = HalOpen;
279090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.close = HalClose;
280090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.core_initialized = HalCoreInitialized;
281090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.write = HalWrite;
282090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.prediscover = HalPrediscover;
283090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.control_granted = HalControlGranted;
284090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.power_cycle = HalPowerCycle;
285090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    mHalEntryFuncs.get_max_ee = HalGetMaxNfcee;
286090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
287090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ret = hw_get_module (NFC_NCI_HARDWARE_MODULE_ID, &hw_module);
288090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if (ret == 0)
289090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
290090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        ret = nfc_nci_open (hw_module, &mHalDeviceContext);
291090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        if (ret != 0)
292090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson            ALOGE ("%s: nfc_nci_open fail", func);
293090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
294090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    else
2951d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert        ALOGE ("%s: fail hw_get_module", func);
296090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: exit", func);
297090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
298090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
299090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
3001d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert**
301090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::HalInitialize
302090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
303090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Not implemented because this function is only needed
304090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**              within the HAL.
305090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
3061d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert** Returns:     None.
307090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
308090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
309090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::HalInitialize ()
310090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
311090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::HalInitialize";
312090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s", func);
313090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
314090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
315090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
316090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
317090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::HalTerminate
318090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
319090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Not implemented because this function is only needed
320090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**              within the HAL.
321090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
322090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     None.
323090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
324090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
325090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::HalTerminate ()
326090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
327090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::HalTerminate";
328090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s", func);
329090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
330090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
331090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
332090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
333090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::HalOpen
334090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
335090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Turn on controller, download firmware.
336090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
337090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     None.
338090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
339090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
340090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::HalOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK* p_data_cback)
341090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
342090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::HalOpen";
343090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s", func);
344090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if (mHalDeviceContext)
345090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
346090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        mHalCallback = p_hal_cback;
347090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        mHalDataCallback = p_data_cback;
348090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        mHalDeviceContext->open (mHalDeviceContext, HalDeviceContextCallback, HalDeviceContextDataCallback);
349090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
350090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
351090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
352090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
353090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
354090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::HalClose
355090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
356090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Turn off controller.
357090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
358090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     None.
359090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
360090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
361090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::HalClose ()
362090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
3631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    const char* func = "NfcAdaptation::HalClose";
364090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s", func);
365090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if (mHalDeviceContext)
366090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    {
367090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        mHalDeviceContext->close (mHalDeviceContext);
368090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
369090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
370090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
371090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
372090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
373090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::HalDeviceContextCallback
3741d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert**
375090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Translate generic Android HAL's callback into Broadcom-specific
376090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**              callback function.
377090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
378090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     None.
379090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
380090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson*******************************************************************************/
381090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonvoid NfcAdaptation::HalDeviceContextCallback (nfc_event_t event, nfc_status_t event_status)
382090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson{
383090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    const char* func = "NfcAdaptation::HalDeviceContextCallback";
384090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    ALOGD ("%s: event=%u", func, event);
385090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if (mHalCallback)
386090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson        mHalCallback (event, (tHAL_NFC_STATUS) event_status);
387090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
388090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
389090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*******************************************************************************
390090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
391090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Function:    NfcAdaptation::HalDeviceContextDataCallback
392090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
393090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Description: Translate generic Android HAL's callback into Broadcom-specific
3941d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert**              callback function.
395090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson**
396090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson** Returns:     None.
397**
398*******************************************************************************/
399void NfcAdaptation::HalDeviceContextDataCallback (uint16_t data_len, uint8_t* p_data)
400{
401    const char* func = "NfcAdaptation::HalDeviceContextDataCallback";
402    ALOGD ("%s: len=%u", func, data_len);
403    if (mHalDataCallback)
404        mHalDataCallback (data_len, p_data);
405}
406
407/*******************************************************************************
408**
409** Function:    NfcAdaptation::HalWrite
410**
411** Description: Write NCI message to the controller.
412**
413** Returns:     None.
414**
415*******************************************************************************/
416void NfcAdaptation::HalWrite (UINT16 data_len, UINT8* p_data)
417{
418    const char* func = "NfcAdaptation::HalWrite";
419    ALOGD ("%s", func);
420    if (mHalDeviceContext)
421    {
422        mHalDeviceContext->write (mHalDeviceContext, data_len, p_data);
423    }
424}
425
426/*******************************************************************************
427**
428** Function:    NfcAdaptation::HalCoreInitialized
429**
430** Description: Adjust the configurable parameters in the controller.
431**
432** Returns:     None.
433**
434*******************************************************************************/
435void NfcAdaptation::HalCoreInitialized (UINT8* p_core_init_rsp_params)
436{
437    const char* func = "NfcAdaptation::HalCoreInitialized";
438    ALOGD ("%s", func);
439    if (mHalDeviceContext)
440    {
441        mHalDeviceContext->core_initialized (mHalDeviceContext, p_core_init_rsp_params);
442    }
443}
444
445/*******************************************************************************
446**
447** Function:    NfcAdaptation::HalPrediscover
448**
449** Description:     Perform any vendor-specific pre-discovery actions (if needed)
450**                  If any actions were performed TRUE will be returned, and
451**                  HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are
452**                  completed.
453**
454** Returns:          TRUE if vendor-specific pre-discovery actions initialized
455**                  FALSE if no vendor-specific pre-discovery actions are needed.
456**
457*******************************************************************************/
458BOOLEAN NfcAdaptation::HalPrediscover ()
459{
460    const char* func = "NfcAdaptation::HalPrediscover";
461    ALOGD ("%s", func);
462    BOOLEAN retval = FALSE;
463
464    if (mHalDeviceContext)
465    {
466        retval = mHalDeviceContext->pre_discover (mHalDeviceContext);
467    }
468    return retval;
469}
470
471/*******************************************************************************
472**
473** Function:        HAL_NfcControlGranted
474**
475** Description:     Grant control to HAL control for sending NCI commands.
476**                  Call in response to HAL_REQUEST_CONTROL_EVT.
477**                  Must only be called when there are no NCI commands pending.
478**                  HAL_RELEASE_CONTROL_EVT will notify when HAL no longer
479**                  needs control of NCI.
480**
481** Returns:         void
482**
483*******************************************************************************/
484void NfcAdaptation::HalControlGranted ()
485{
486    const char* func = "NfcAdaptation::HalControlGranted";
487    ALOGD ("%s", func);
488    if (mHalDeviceContext)
489    {
490        mHalDeviceContext->control_granted (mHalDeviceContext);
491    }
492}
493
494/*******************************************************************************
495**
496** Function:    NfcAdaptation::HalPowerCycle
497**
498** Description: Turn off and turn on the controller.
499**
500** Returns:     None.
501**
502*******************************************************************************/
503void NfcAdaptation::HalPowerCycle ()
504{
505    const char* func = "NfcAdaptation::HalPowerCycle";
506    ALOGD ("%s", func);
507    if (mHalDeviceContext)
508    {
509        mHalDeviceContext->power_cycle (mHalDeviceContext);
510    }
511}
512
513/*******************************************************************************
514**
515** Function:    NfcAdaptation::HalGetMaxNfcee
516**
517** Description: Turn off and turn on the controller.
518**
519** Returns:     None.
520**
521*******************************************************************************/
522UINT8 NfcAdaptation::HalGetMaxNfcee()
523{
524    const char* func = "NfcAdaptation::HalPowerCycle";
525    UINT8 maxNfcee = 0;
526    ALOGD ("%s", func);
527    if (mHalDeviceContext)
528    {
529        mHalDeviceContext->get_max_ee (mHalDeviceContext, &maxNfcee);
530    }
531
532    return maxNfcee;
533}
534
535/*******************************************************************************
536**
537** Function:    NfcAdaptation::DownloadFirmware
538**
539** Description: Download firmware patch files.
540**
541** Returns:     None.
542**
543*******************************************************************************/
544void NfcAdaptation::DownloadFirmware ()
545{
546    const char* func = "NfcAdaptation::DownloadFirmware";
547    ALOGD ("%s: enter", func);
548    HalInitialize ();
549
550    mHalOpenCompletedEvent.lock ();
551    ALOGD ("%s: try open HAL", func);
552    HalOpen (HalDownloadFirmwareCallback, HalDownloadFirmwareDataCallback);
553    mHalOpenCompletedEvent.wait ();
554
555    mHalCloseCompletedEvent.lock ();
556    ALOGD ("%s: try close HAL", func);
557    HalClose ();
558    mHalCloseCompletedEvent.wait ();
559
560    HalTerminate ();
561    ALOGD ("%s: exit", func);
562}
563
564/*******************************************************************************
565**
566** Function:    NfcAdaptation::HalDownloadFirmwareCallback
567**
568** Description: Receive events from the HAL.
569**
570** Returns:     None.
571**
572*******************************************************************************/
573void NfcAdaptation::HalDownloadFirmwareCallback (nfc_event_t event, nfc_status_t event_status)
574{
575    const char* func = "NfcAdaptation::HalDownloadFirmwareCallback";
576    ALOGD ("%s: event=0x%X", func, event);
577    switch (event)
578    {
579    case HAL_NFC_OPEN_CPLT_EVT:
580        {
581            ALOGD ("%s: HAL_NFC_OPEN_CPLT_EVT", func);
582            mHalOpenCompletedEvent.signal ();
583            break;
584        }
585    case HAL_NFC_CLOSE_CPLT_EVT:
586        {
587            ALOGD ("%s: HAL_NFC_CLOSE_CPLT_EVT", func);
588            mHalCloseCompletedEvent.signal ();
589            break;
590        }
591    }
592}
593
594/*******************************************************************************
595**
596** Function:    NfcAdaptation::HalDownloadFirmwareDataCallback
597**
598** Description: Receive data events from the HAL.
599**
600** Returns:     None.
601**
602*******************************************************************************/
603void NfcAdaptation::HalDownloadFirmwareDataCallback (uint16_t data_len, uint8_t* p_data)
604{
605}
606
607
608/*******************************************************************************
609**
610** Function:    ThreadMutex::ThreadMutex()
611**
612** Description: class constructor
613**
614** Returns:     none
615**
616*******************************************************************************/
617ThreadMutex::ThreadMutex()
618{
619    pthread_mutexattr_t mutexAttr;
620
621    pthread_mutexattr_init(&mutexAttr);
622    pthread_mutex_init(&mMutex, &mutexAttr);
623    pthread_mutexattr_destroy(&mutexAttr);
624}
625
626/*******************************************************************************
627**
628** Function:    ThreadMutex::~ThreadMutex()
629**
630** Description: class destructor
631**
632** Returns:     none
633**
634*******************************************************************************/
635ThreadMutex::~ThreadMutex()
636{
637    pthread_mutex_destroy(&mMutex);
638}
639
640/*******************************************************************************
641**
642** Function:    ThreadMutex::lock()
643**
644** Description: lock kthe mutex
645**
646** Returns:     none
647**
648*******************************************************************************/
649void ThreadMutex::lock()
650{
651    pthread_mutex_lock(&mMutex);
652}
653
654/*******************************************************************************
655**
656** Function:    ThreadMutex::unblock()
657**
658** Description: unlock the mutex
659**
660** Returns:     none
661**
662*******************************************************************************/
663void ThreadMutex::unlock()
664{
665    pthread_mutex_unlock(&mMutex);
666}
667
668/*******************************************************************************
669**
670** Function:    ThreadCondVar::ThreadCondVar()
671**
672** Description: class constructor
673**
674** Returns:     none
675**
676*******************************************************************************/
677ThreadCondVar::ThreadCondVar()
678{
679    pthread_condattr_t CondAttr;
680
681    pthread_condattr_init(&CondAttr);
682    pthread_cond_init(&mCondVar, &CondAttr);
683
684    pthread_condattr_destroy(&CondAttr);
685}
686
687/*******************************************************************************
688**
689** Function:    ThreadCondVar::~ThreadCondVar()
690**
691** Description: class destructor
692**
693** Returns:     none
694**
695*******************************************************************************/
696ThreadCondVar::~ThreadCondVar()
697{
698    pthread_cond_destroy(&mCondVar);
699}
700
701/*******************************************************************************
702**
703** Function:    ThreadCondVar::wait()
704**
705** Description: wait on the mCondVar
706**
707** Returns:     none
708**
709*******************************************************************************/
710void ThreadCondVar::wait()
711{
712    pthread_cond_wait(&mCondVar, *this);
713    pthread_mutex_unlock(*this);
714}
715
716/*******************************************************************************
717**
718** Function:    ThreadCondVar::signal()
719**
720** Description: signal the mCondVar
721**
722** Returns:     none
723**
724*******************************************************************************/
725void ThreadCondVar::signal()
726{
727    AutoThreadMutex  a(*this);
728    pthread_cond_signal(&mCondVar);
729}
730
731/*******************************************************************************
732**
733** Function:    AutoThreadMutex::AutoThreadMutex()
734**
735** Description: class constructor, automatically lock the mutex
736**
737** Returns:     none
738**
739*******************************************************************************/
740AutoThreadMutex::AutoThreadMutex(ThreadMutex &m)
741    : mm(m)
742{
743    mm.lock();
744}
745
746/*******************************************************************************
747**
748** Function:    AutoThreadMutex::~AutoThreadMutex()
749**
750** Description: class destructor, automatically unlock the mutex
751**
752** Returns:     none
753**
754*******************************************************************************/
755AutoThreadMutex::~AutoThreadMutex()
756{
757    mm.unlock();
758}
759