nfa_ee_main.c revision df5080d7feca9827fd0306471c54f52ecf185c22
1/******************************************************************************
2 *
3 *  Copyright (C) 2010-2013 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
19
20/******************************************************************************
21 *
22 *  This is the main implementation file for the NFA EE.
23 *
24 ******************************************************************************/
25#include <string.h>
26#include "nfc_api.h"
27#include "nfa_sys.h"
28#include "nfa_sys_int.h"
29#include "nfa_dm_int.h"
30#include "nfa_ee_int.h"
31
32extern void nfa_ee_vs_cback (tNFC_VS_EVT event, BT_HDR *p_data);
33/*****************************************************************************
34**  Global Variables
35*****************************************************************************/
36
37/* system manager control block definition */
38#if NFA_DYNAMIC_MEMORY == FALSE
39tNFA_EE_CB nfa_ee_cb;
40#endif
41
42/*****************************************************************************
43**  Constants
44*****************************************************************************/
45static const tNFA_SYS_REG nfa_ee_sys_reg =
46{
47    nfa_ee_sys_enable,
48    nfa_ee_evt_hdlr,
49    nfa_ee_sys_disable,
50    nfa_ee_proc_nfcc_power_mode
51};
52
53
54#define NFA_EE_NUM_ACTIONS  (NFA_EE_MAX_EVT & 0x00ff)
55
56
57const tNFA_EE_SM_ACT nfa_ee_actions[] =
58{
59    /* NFA-EE action function/ internal events */
60    nfa_ee_api_discover     ,   /* NFA_EE_API_DISCOVER_EVT      */
61    nfa_ee_api_register     ,   /* NFA_EE_API_REGISTER_EVT      */
62    nfa_ee_api_deregister   ,   /* NFA_EE_API_DEREGISTER_EVT    */
63    nfa_ee_api_mode_set     ,   /* NFA_EE_API_MODE_SET_EVT      */
64    nfa_ee_api_set_tech_cfg ,   /* NFA_EE_API_SET_TECH_CFG_EVT  */
65    nfa_ee_api_set_proto_cfg,   /* NFA_EE_API_SET_PROTO_CFG_EVT */
66    nfa_ee_api_add_aid      ,   /* NFA_EE_API_ADD_AID_EVT       */
67    nfa_ee_api_remove_aid   ,   /* NFA_EE_API_REMOVE_AID_EVT    */
68    nfa_ee_api_update_now   ,   /* NFA_EE_API_UPDATE_NOW_EVT    */
69    nfa_ee_api_connect      ,   /* NFA_EE_API_CONNECT_EVT       */
70    nfa_ee_api_send_data    ,   /* NFA_EE_API_SEND_DATA_EVT     */
71    nfa_ee_api_disconnect   ,   /* NFA_EE_API_DISCONNECT_EVT    */
72    nfa_ee_nci_disc_rsp     ,   /* NFA_EE_NCI_DISC_RSP_EVT      */
73    nfa_ee_nci_disc_ntf     ,   /* NFA_EE_NCI_DISC_NTF_EVT      */
74    nfa_ee_nci_mode_set_rsp ,   /* NFA_EE_NCI_MODE_SET_RSP_EVT  */
75    nfa_ee_nci_conn         ,   /* NFA_EE_NCI_CONN_EVT          */
76    nfa_ee_nci_conn         ,   /* NFA_EE_NCI_DATA_EVT          */
77    nfa_ee_nci_action_ntf   ,   /* NFA_EE_NCI_ACTION_NTF_EVT    */
78    nfa_ee_nci_disc_req_ntf ,   /* NFA_EE_NCI_DISC_REQ_NTF_EVT  */
79    nfa_ee_rout_timeout     ,   /* NFA_EE_ROUT_TIMEOUT_EVT      */
80    nfa_ee_discv_timeout    ,   /* NFA_EE_DISCV_TIMEOUT_EVT     */
81    nfa_ee_lmrt_to_nfcc         /* NFA_EE_CFG_TO_NFCC_EVT       */
82};
83
84
85/*******************************************************************************
86**
87** Function         nfa_ee_init
88**
89** Description      Initialize NFA EE control block
90**                  register to NFA SYS
91**
92** Returns          None
93**
94*******************************************************************************/
95void nfa_ee_init (void)
96{
97    int xx;
98
99    NFA_TRACE_DEBUG0 ("nfa_ee_init ()");
100
101    /* initialize control block */
102    memset (&nfa_ee_cb, 0, sizeof (tNFA_EE_CB));
103    for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++)
104    {
105        nfa_ee_cb.ecb[xx].nfcee_id       = NFA_EE_INVALID;
106        nfa_ee_cb.ecb[xx].ee_status      = NFC_NFCEE_STATUS_INACTIVE;
107    }
108
109    nfa_ee_cb.ecb[NFA_EE_CB_4_DH].ee_status       = NFC_NFCEE_STATUS_ACTIVE;
110    nfa_ee_cb.ecb[NFA_EE_CB_4_DH].nfcee_id        = NFC_DH_ID;
111
112    /* register message handler on NFA SYS */
113    nfa_sys_register (NFA_ID_EE,  &nfa_ee_sys_reg);
114}
115
116/*******************************************************************************
117**
118** Function         nfa_ee_sys_enable
119**
120** Description      Enable NFA EE
121**
122** Returns          None
123**
124*******************************************************************************/
125void nfa_ee_sys_enable (void)
126{
127    /* collect NFCEE information */
128    NFC_NfceeDiscover (TRUE);
129    nfa_sys_start_timer (&nfa_ee_cb.discv_timer, NFA_EE_DISCV_TIMEOUT_EVT, NFA_EE_DISCV_TIMEOUT_VAL);
130}
131
132/*******************************************************************************
133**
134** Function         nfa_ee_restore_one_ecb
135**
136** Description      activate the NFCEE and restore the routing when
137**                  changing power state from low power mode to full power mode
138**
139** Returns          None
140**
141*******************************************************************************/
142void nfa_ee_restore_one_ecb (tNFA_EE_ECB *p_cb)
143{
144    UINT8   mask;
145    tNFC_NFCEE_MODE_SET_REVT    rsp;
146    tNFA_EE_NCI_MODE_SET        ee_msg;
147
148    NFA_TRACE_DEBUG4 ("nfa_ee_restore_one_ecb () nfcee_id:0x%x, ecb_flags:0x%x ee_status:0x%x ee_old_status: 0x%x", p_cb->nfcee_id, p_cb->ecb_flags, p_cb->ee_status, p_cb->ee_old_status);
149    if ((p_cb->nfcee_id != NFA_EE_INVALID) && (p_cb->ee_status & NFA_EE_STATUS_RESTORING) == 0 && (p_cb->ee_old_status & NFA_EE_STATUS_RESTORING) != 0)
150    {
151        p_cb->ee_old_status &= ~NFA_EE_STATUS_RESTORING;
152        mask = nfa_ee_ecb_to_mask(p_cb);
153        if (p_cb->ee_status != p_cb->ee_old_status)
154        {
155            p_cb->ecb_flags   |= NFA_EE_ECB_FLAGS_RESTORE;
156            if (p_cb->ee_old_status == NFC_NFCEE_STATUS_ACTIVE)
157            {
158                NFC_NfceeModeSet (p_cb->nfcee_id, NFC_MODE_ACTIVATE);
159
160                if (nfa_ee_cb.ee_cfged & mask)
161                {
162                    /* if any routing is configured on this NFCEE. need to mark this NFCEE as changed
163                     * to cause the configuration to be sent to NFCC again */
164                    p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_ROUTING;
165                    p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_VS;
166                }
167            }
168            else
169            {
170                NFC_NfceeModeSet (p_cb->nfcee_id, NFC_MODE_DEACTIVATE);
171            }
172        }
173        else if (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE)
174        {
175            /* the initial NFCEE status after start up is the same as the current status and it's active:
176             * process the same as the host gets activate rsp */
177            p_cb->ecb_flags   |= NFA_EE_ECB_FLAGS_RESTORE;
178            if (nfa_ee_cb.ee_cfged & mask)
179            {
180                /* if any routing is configured on this NFCEE. need to mark this NFCEE as changed
181                 * to cause the configuration to be sent to NFCC again */
182                p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_ROUTING;
183                p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_VS;
184            }
185            rsp.mode        = NFA_EE_MD_ACTIVATE;
186            rsp.nfcee_id    = p_cb->nfcee_id;
187            rsp.status      = NFA_STATUS_OK;
188            ee_msg.p_data   = &rsp;
189            nfa_ee_nci_mode_set_rsp ((tNFA_EE_MSG *) &ee_msg);
190        }
191    }
192}
193
194/*******************************************************************************
195**
196** Function         nfa_ee_proc_nfcc_power_mode
197**
198** Description      Restore NFA EE sub-module
199**
200** Returns          None
201**
202*******************************************************************************/
203void nfa_ee_proc_nfcc_power_mode (UINT8 nfcc_power_mode)
204{
205    UINT32          xx;
206    tNFA_EE_ECB     *p_cb;
207    BOOLEAN         proc_complete = TRUE;
208
209    NFA_TRACE_DEBUG1 ("nfa_ee_proc_nfcc_power_mode (): nfcc_power_mode=%d", nfcc_power_mode);
210    /* if NFCC power state is change to full power */
211    if (nfcc_power_mode == NFA_DM_PWR_MODE_FULL)
212    {
213        p_cb = nfa_ee_cb.ecb;
214        for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
215        {
216            p_cb->ee_old_status = 0;
217            if (xx >= nfa_ee_cb.cur_ee)
218                p_cb->nfcee_id = NFA_EE_INVALID;
219
220            if ((p_cb->nfcee_id != NFA_EE_INVALID) && (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS) && (p_cb->ee_status  != NFA_EE_STATUS_REMOVED))
221            {
222                proc_complete       = FALSE;
223                /* NFA_EE_STATUS_RESTORING bit makes sure the ee_status restore to ee_old_status
224                 * NFA_EE_STATUS_RESTORING bit is cleared in ee_status at NFCEE_DISCOVER NTF.
225                 * NFA_EE_STATUS_RESTORING bit is cleared in ee_old_status at restoring the activate/inactive status after NFCEE_DISCOVER NTF */
226                p_cb->ee_status    |= NFA_EE_STATUS_RESTORING;
227                p_cb->ee_old_status = p_cb->ee_status;
228                /* NFA_EE_FLAGS_RESTORE bit makes sure the routing/nci logical connection is restore to prior to entering low power mode */
229                p_cb->ecb_flags    |= NFA_EE_ECB_FLAGS_RESTORE;
230            }
231        }
232        nfa_ee_cb.em_state          = NFA_EE_EM_STATE_RESTORING;
233        nfa_ee_cb.num_ee_expecting  = 0;
234        if (nfa_sys_is_register (NFA_ID_HCI))
235        {
236            nfa_ee_cb.ee_flags   |= NFA_EE_FLAG_WAIT_HCI;
237            nfa_ee_cb.ee_flags   |= NFA_EE_FLAG_NOTIFY_HCI;
238        }
239        NFC_NfceeDiscover (TRUE);
240        nfa_sys_start_timer (&nfa_ee_cb.discv_timer, NFA_EE_DISCV_TIMEOUT_EVT, NFA_EE_DISCV_TIMEOUT_VAL);
241    }
242    else
243    {
244        nfa_sys_stop_timer (&nfa_ee_cb.timer);
245        nfa_sys_stop_timer (&nfa_ee_cb.discv_timer);
246        nfa_ee_cb.num_ee_expecting = 0;
247    }
248
249    if (proc_complete)
250        nfa_sys_cback_notify_nfcc_power_mode_proc_complete (NFA_ID_EE);
251}
252
253/*******************************************************************************
254**
255** Function         nfa_ee_proc_hci_info_cback
256**
257** Description      HCI initialization complete from power off sleep mode
258**
259** Returns          None
260**
261*******************************************************************************/
262void nfa_ee_proc_hci_info_cback (void)
263{
264    UINT32          xx;
265    tNFA_EE_ECB     *p_cb;
266    tNFA_EE_MSG     data;
267
268    NFA_TRACE_DEBUG0 ("nfa_ee_proc_hci_info_cback ()");
269    /* if NFCC power state is change to full power */
270    nfa_ee_cb.ee_flags   &= ~NFA_EE_FLAG_WAIT_HCI;
271
272    p_cb = nfa_ee_cb.ecb;
273    for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
274    {
275        /* NCI spec says: An NFCEE_DISCOVER_NTF that contains a Protocol type of "HCI Access"
276         * SHALL NOT contain any other additional Protocol
277         * i.e. check only first supported NFCEE interface is HCI access */
278        /* NFA_HCI module handles restoring configurations for HCI access */
279        if (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS)
280        {
281            nfa_ee_restore_one_ecb (p_cb);
282        }
283    }
284
285    if (nfa_ee_restore_ntf_done())
286    {
287        nfa_ee_check_restore_complete();
288        if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT_DONE)
289        {
290            if (nfa_ee_cb.discv_timer.in_use)
291            {
292                nfa_sys_stop_timer (&nfa_ee_cb.discv_timer);
293                data.hdr.event = NFA_EE_DISCV_TIMEOUT_EVT;
294                nfa_ee_evt_hdlr((BT_HDR *)&data);
295            }
296        }
297    }
298}
299
300/*******************************************************************************
301**
302** Function         nfa_ee_proc_evt
303**
304** Description      Process NFCEE related events from NFC stack
305**
306**
307** Returns          None
308**
309*******************************************************************************/
310void nfa_ee_proc_evt (tNFC_RESPONSE_EVT event, void *p_data)
311{
312    tNFA_EE_INT_EVT         int_event=0;
313    tNFA_EE_NCI_RESPONSE    cbk;
314    BT_HDR                  *p_hdr;
315
316    switch (event)
317    {
318    case NFC_NFCEE_DISCOVER_REVT:                /* 4  NFCEE Discover response */
319        int_event   = NFA_EE_NCI_DISC_RSP_EVT;
320        break;
321
322    case NFC_NFCEE_INFO_REVT:                    /* 5  NFCEE Discover Notification */
323        int_event    = NFA_EE_NCI_DISC_NTF_EVT;
324        break;
325
326    case NFC_NFCEE_MODE_SET_REVT:                /* 6  NFCEE Mode Set response */
327        int_event   = NFA_EE_NCI_MODE_SET_RSP_EVT;
328        break;
329
330    case NFC_EE_ACTION_REVT:
331        int_event   = NFA_EE_NCI_ACTION_NTF_EVT;
332        break;
333
334    case NFC_EE_DISCOVER_REQ_REVT:               /* 10 EE Discover Req notification */
335        int_event   = NFA_EE_NCI_DISC_REQ_NTF_EVT;
336        break;
337
338    }
339
340    NFA_TRACE_DEBUG2 ("nfa_ee_proc_evt: event=0x%02x int_event:0x%x", event, int_event);
341    if (int_event)
342    {
343        p_hdr           = (BT_HDR *) &cbk;
344        cbk.hdr.event   = int_event;
345        cbk.p_data      = p_data;
346
347        nfa_ee_evt_hdlr (p_hdr);
348    }
349
350}
351
352/*******************************************************************************
353**
354** Function         nfa_ee_ecb_to_mask
355**
356** Description      Given a ecb, return the bit mask to be used in nfa_ee_cb.ee_cfged
357**
358** Returns          the bitmask for the given ecb.
359**
360*******************************************************************************/
361UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb)
362{
363    UINT8   mask;
364    UINT8   index;
365
366    index = (UINT8) (p_cb - nfa_ee_cb.ecb);
367    mask  = 1 << index;
368
369    return mask;
370}
371
372/*******************************************************************************
373**
374** Function         nfa_ee_find_ecb
375**
376** Description      Return the ecb associated with the given nfcee_id
377**
378** Returns          tNFA_EE_ECB
379**
380*******************************************************************************/
381tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id)
382{
383    UINT32  xx;
384    tNFA_EE_ECB *p_ret = NULL, *p_cb;
385    NFA_TRACE_DEBUG0 ("nfa_ee_find_ecb ()");
386
387    if (nfcee_id == NFC_DH_ID)
388    {
389        p_ret = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
390    }
391    else
392    {
393        p_cb = nfa_ee_cb.ecb;
394        for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
395        {
396            if (nfcee_id == p_cb->nfcee_id)
397            {
398                p_ret = p_cb;
399                break;
400            }
401        }
402    }
403
404    return p_ret;
405}
406
407/*******************************************************************************
408**
409** Function         nfa_ee_find_ecb_by_conn_id
410**
411** Description      Return the ecb associated with the given connection id
412**
413** Returns          tNFA_EE_ECB
414**
415*******************************************************************************/
416tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id)
417{
418    UINT32  xx;
419    tNFA_EE_ECB *p_ret = NULL, *p_cb;
420    NFA_TRACE_DEBUG0 ("nfa_ee_find_ecb_by_conn_id ()");
421
422    p_cb = nfa_ee_cb.ecb;
423    for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
424    {
425        if (conn_id == p_cb->conn_id)
426        {
427            p_ret = p_cb;
428            break;
429        }
430    }
431
432    return p_ret;
433}
434
435/*******************************************************************************
436**
437** Function         nfa_ee_sys_disable
438**
439** Description      Deregister NFA EE from NFA SYS/DM
440**
441**
442** Returns          None
443**
444*******************************************************************************/
445void nfa_ee_sys_disable (void)
446{
447    UINT32  xx;
448    tNFA_EE_ECB *p_cb;
449    tNFA_EE_MSG     msg;
450
451    NFA_TRACE_DEBUG0 ("nfa_ee_sys_disable ()");
452
453    nfa_ee_cb.em_state = NFA_EE_EM_STATE_DISABLED;
454    /* report NFA_EE_DEREGISTER_EVT to all registered to EE */
455    for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++)
456    {
457        if (nfa_ee_cb.p_ee_cback[xx])
458        {
459            msg.deregister.index     = xx;
460            nfa_ee_api_deregister (&msg);
461        }
462    }
463
464    nfa_ee_cb.num_ee_expecting  = 0;
465    p_cb = nfa_ee_cb.ecb;
466    for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
467    {
468        if (p_cb->conn_st == NFA_EE_CONN_ST_CONN)
469        {
470            if (nfa_sys_is_graceful_disable ())
471            {
472                /* Disconnect NCI connection on graceful shutdown */
473                msg.disconnect.p_cb = p_cb;
474                nfa_ee_api_disconnect (&msg);
475                nfa_ee_cb.num_ee_expecting++;
476            }
477            else
478            {
479                /* fake NFA_EE_DISCONNECT_EVT on ungraceful shutdown */
480                msg.conn.conn_id    = p_cb->conn_id;
481                msg.conn.event      = NFC_CONN_CLOSE_CEVT;
482                nfa_ee_nci_conn (&msg);
483            }
484        }
485    }
486
487    if (nfa_ee_cb.num_ee_expecting)
488    {
489        nfa_ee_cb.ee_flags |= NFA_EE_FLAG_WAIT_DISCONN;
490        nfa_ee_cb.em_state  = NFA_EE_EM_STATE_DISABLING;
491    }
492
493
494    nfa_sys_stop_timer (&nfa_ee_cb.timer);
495    nfa_sys_stop_timer (&nfa_ee_cb.discv_timer);
496
497    /* If Application initiated NFCEE discovery, fake/report the event */
498    nfa_ee_report_disc_done (FALSE);
499
500    /* deregister message handler on NFA SYS */
501    if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_DISABLED)
502        nfa_sys_deregister (NFA_ID_EE);
503
504}
505
506/*******************************************************************************
507**
508** Function         nfa_ee_check_disable
509**
510** Description      Check if it is safe to move to disabled state
511**
512** Returns          None
513**
514*******************************************************************************/
515void nfa_ee_check_disable (void)
516{
517    if (!(nfa_ee_cb.ee_flags & NFA_EE_FLAG_WAIT_DISCONN))
518    {
519        nfa_ee_cb.em_state = NFA_EE_EM_STATE_DISABLED;
520        nfa_sys_deregister (NFA_ID_EE);
521    }
522}
523/*******************************************************************************
524**
525** Function         nfa_ee_reg_cback_enable_done
526**
527** Description      Allow a module to register to EE to be notified when NFA-EE
528**                  finishes enable process
529**
530** Returns          None
531**
532*******************************************************************************/
533void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback)
534{
535    nfa_ee_cb.p_enable_cback = p_cback;
536}
537
538#if (BT_TRACE_VERBOSE == TRUE)
539/*******************************************************************************
540**
541** Function         nfa_ee_sm_st_2_str
542**
543** Description      convert nfa-ee state to string
544**
545*******************************************************************************/
546static char *nfa_ee_sm_st_2_str (UINT8 state)
547{
548    switch (state)
549    {
550    case NFA_EE_EM_STATE_INIT:
551        return "INIT";
552
553    case NFA_EE_EM_STATE_INIT_DONE:
554        return "INIT_DONE";
555
556    case NFA_EE_EM_STATE_RESTORING:
557        return "RESTORING";
558
559    case NFA_EE_EM_STATE_DISABLING:
560        return "DISABLING";
561
562    case NFA_EE_EM_STATE_DISABLED:
563        return "DISABLED";
564
565    default:
566        return "Unknown";
567    }
568}
569
570/*******************************************************************************
571**
572** Function         nfa_ee_sm_evt_2_str
573**
574** Description      convert nfa-ee evt to string
575**
576*******************************************************************************/
577static char *nfa_ee_sm_evt_2_str (UINT16 event)
578{
579    switch (event)
580    {
581    case NFA_EE_API_DISCOVER_EVT:
582        return "API_DISCOVER";
583    case NFA_EE_API_REGISTER_EVT:
584        return "API_REGISTER";
585    case NFA_EE_API_DEREGISTER_EVT:
586        return "API_DEREGISTER";
587    case NFA_EE_API_MODE_SET_EVT:
588        return "API_MODE_SET";
589    case NFA_EE_API_SET_TECH_CFG_EVT:
590        return "API_SET_TECH_CFG";
591    case NFA_EE_API_SET_PROTO_CFG_EVT:
592        return "API_SET_PROTO_CFG";
593    case NFA_EE_API_ADD_AID_EVT:
594        return "API_ADD_AID";
595    case NFA_EE_API_REMOVE_AID_EVT:
596        return "API_REMOVE_AID";
597    case NFA_EE_API_UPDATE_NOW_EVT:
598        return "API_UPDATE_NOW";
599    case NFA_EE_API_CONNECT_EVT:
600        return "API_CONNECT";
601    case NFA_EE_API_SEND_DATA_EVT:
602        return "API_SEND_DATA";
603    case NFA_EE_API_DISCONNECT_EVT:
604        return "API_DISCONNECT";
605    case NFA_EE_NCI_DISC_RSP_EVT:
606        return "NCI_DISC_RSP";
607    case NFA_EE_NCI_DISC_NTF_EVT:
608        return "NCI_DISC_NTF";
609    case NFA_EE_NCI_MODE_SET_RSP_EVT:
610        return "NCI_MODE_SET";
611    case NFA_EE_NCI_CONN_EVT:
612        return "NCI_CONN";
613    case NFA_EE_NCI_DATA_EVT:
614        return "NCI_DATA";
615    case NFA_EE_NCI_ACTION_NTF_EVT:
616        return "NCI_ACTION";
617    case NFA_EE_NCI_DISC_REQ_NTF_EVT:
618        return "NCI_DISC_REQ";
619    case NFA_EE_ROUT_TIMEOUT_EVT:
620        return "ROUT_TIMEOUT";
621    case NFA_EE_DISCV_TIMEOUT_EVT:
622        return "NFA_EE_DISCV_TIMEOUT_EVT";
623    case NFA_EE_CFG_TO_NFCC_EVT:
624        return "CFG_TO_NFCC";
625    default:
626        return "Unknown";
627    }
628}
629#endif /* BT_TRACE_VERBOSE */
630
631/*******************************************************************************
632**
633** Function         nfa_ee_evt_hdlr
634**
635** Description      Processing event for NFA EE
636**
637**
638** Returns          TRUE if p_msg needs to be deallocated
639**
640*******************************************************************************/
641BOOLEAN nfa_ee_evt_hdlr (BT_HDR *p_msg)
642{
643    tNFA_EE_MSG *p_evt_data = (tNFA_EE_MSG *) p_msg;
644    UINT16  event = p_msg->event & 0x00ff;
645    BOOLEAN act = FALSE;
646
647#if (BT_TRACE_VERBOSE == TRUE)
648    NFA_TRACE_DEBUG4 ("nfa_ee_evt_hdlr (): Event %s(0x%02x), State: %s(%d)",
649        nfa_ee_sm_evt_2_str (p_evt_data->hdr.event), p_evt_data->hdr.event,
650        nfa_ee_sm_st_2_str (nfa_ee_cb.em_state), nfa_ee_cb.em_state);
651#else
652    NFA_TRACE_DEBUG2 ("nfa_ee_evt_hdlr (): Event 0x%02x, State: %d", p_evt_data->hdr.event, nfa_ee_cb.em_state);
653#endif
654
655    switch (nfa_ee_cb.em_state)
656    {
657    case NFA_EE_EM_STATE_INIT_DONE:
658    case NFA_EE_EM_STATE_RESTORING:
659        act = TRUE;
660        break;
661    case NFA_EE_EM_STATE_INIT:
662        if ((p_msg->event == NFA_EE_NCI_DISC_NTF_EVT) || (p_msg->event == NFA_EE_NCI_DISC_RSP_EVT))
663            act = TRUE;
664        break;
665    case NFA_EE_EM_STATE_DISABLING:
666        if (p_msg->event == NFA_EE_NCI_CONN_EVT)
667            act = TRUE;
668        break;
669    }
670    if (act)
671    {
672        if (event < NFA_EE_NUM_ACTIONS)
673        {
674            (*nfa_ee_actions[event]) (p_evt_data);
675        }
676    }
677    else
678    {
679        /* if the data event is not handled by action function, free the data packet */
680        if (p_msg->event == NFA_EE_NCI_DATA_EVT)
681            GKI_freebuf (p_evt_data->conn.p_data);
682    }
683
684    return TRUE;
685}
686
687
688