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