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