Home | History | Annotate | Download | only in ee
      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 
     32 extern 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
     39 tNFA_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 *****************************************************************************/
     50 static 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 
     62 const 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 *******************************************************************************/
    100 void 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 *******************************************************************************/
    130 void 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 *******************************************************************************/
    147 void 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 *******************************************************************************/
    208 void 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 *******************************************************************************/
    267 void nfa_ee_proc_hci_info_cback (void)
    268 {
    269     UINT32          xx;
    270     tNFA_EE_ECB     *p_cb;
    271     tNFA_EE_MSG     data;
    272 
    273     NFA_TRACE_DEBUG0 ("nfa_ee_proc_hci_info_cback ()");
    274     /* if NFCC power state is change to full power */
    275     nfa_ee_cb.ee_flags   &= ~NFA_EE_FLAG_WAIT_HCI;
    276 
    277     p_cb = nfa_ee_cb.ecb;
    278     for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
    279     {
    280         /* NCI spec says: An NFCEE_DISCOVER_NTF that contains a Protocol type of "HCI Access"
    281          * SHALL NOT contain any other additional Protocol
    282          * i.e. check only first supported NFCEE interface is HCI access */
    283         /* NFA_HCI module handles restoring configurations for HCI access */
    284         if (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS)
    285         {
    286             nfa_ee_restore_one_ecb (p_cb);
    287         }
    288     }
    289 
    290     if (nfa_ee_restore_ntf_done())
    291     {
    292         nfa_ee_check_restore_complete();
    293         if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT_DONE)
    294         {
    295             if (nfa_ee_cb.discv_timer.in_use)
    296             {
    297                 nfa_sys_stop_timer (&nfa_ee_cb.discv_timer);
    298                 data.hdr.event = NFA_EE_DISCV_TIMEOUT_EVT;
    299                 nfa_ee_evt_hdlr((BT_HDR *)&data);
    300             }
    301         }
    302     }
    303 }
    304 
    305 /*******************************************************************************
    306 **
    307 ** Function         nfa_ee_proc_evt
    308 **
    309 ** Description      Process NFCEE related events from NFC stack
    310 **
    311 **
    312 ** Returns          None
    313 **
    314 *******************************************************************************/
    315 void nfa_ee_proc_evt (tNFC_RESPONSE_EVT event, void *p_data)
    316 {
    317     tNFA_EE_INT_EVT         int_event=0;
    318     tNFA_EE_NCI_RESPONSE    cbk;
    319     BT_HDR                  *p_hdr;
    320 
    321     switch (event)
    322     {
    323     case NFC_NFCEE_DISCOVER_REVT:                /* 4  NFCEE Discover response */
    324         int_event   = NFA_EE_NCI_DISC_RSP_EVT;
    325         break;
    326 
    327     case NFC_NFCEE_INFO_REVT:                    /* 5  NFCEE Discover Notification */
    328         int_event    = NFA_EE_NCI_DISC_NTF_EVT;
    329         break;
    330 
    331     case NFC_NFCEE_MODE_SET_REVT:                /* 6  NFCEE Mode Set response */
    332         int_event   = NFA_EE_NCI_MODE_SET_RSP_EVT;
    333         break;
    334 
    335     case NFC_EE_ACTION_REVT:
    336         int_event   = NFA_EE_NCI_ACTION_NTF_EVT;
    337         break;
    338 
    339     case NFC_EE_DISCOVER_REQ_REVT:               /* 10 EE Discover Req notification */
    340         int_event   = NFA_EE_NCI_DISC_REQ_NTF_EVT;
    341         break;
    342 
    343     }
    344 
    345     NFA_TRACE_DEBUG2 ("nfa_ee_proc_evt: event=0x%02x int_event:0x%x", event, int_event);
    346     if (int_event)
    347     {
    348         p_hdr           = (BT_HDR *) &cbk;
    349         cbk.hdr.event   = int_event;
    350         cbk.p_data      = p_data;
    351 
    352         nfa_ee_evt_hdlr (p_hdr);
    353     }
    354 
    355 }
    356 
    357 /*******************************************************************************
    358 **
    359 ** Function         nfa_ee_ecb_to_mask
    360 **
    361 ** Description      Given a ecb, return the bit mask to be used in nfa_ee_cb.ee_cfged
    362 **
    363 ** Returns          the bitmask for the given ecb.
    364 **
    365 *******************************************************************************/
    366 UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb)
    367 {
    368     UINT8   mask;
    369     UINT8   index;
    370 
    371     index = (UINT8) (p_cb - nfa_ee_cb.ecb);
    372     mask  = 1 << index;
    373 
    374     return mask;
    375 }
    376 
    377 /*******************************************************************************
    378 **
    379 ** Function         nfa_ee_find_ecb
    380 **
    381 ** Description      Return the ecb associated with the given nfcee_id
    382 **
    383 ** Returns          tNFA_EE_ECB
    384 **
    385 *******************************************************************************/
    386 tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id)
    387 {
    388     UINT32  xx;
    389     tNFA_EE_ECB *p_ret = NULL, *p_cb;
    390     NFA_TRACE_DEBUG0 ("nfa_ee_find_ecb ()");
    391 
    392     if (nfcee_id == NFC_DH_ID)
    393     {
    394         p_ret = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
    395     }
    396     else
    397     {
    398         p_cb = nfa_ee_cb.ecb;
    399         for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
    400         {
    401             if (nfcee_id == p_cb->nfcee_id)
    402             {
    403                 p_ret = p_cb;
    404                 break;
    405             }
    406         }
    407     }
    408 
    409     return p_ret;
    410 }
    411 
    412 /*******************************************************************************
    413 **
    414 ** Function         nfa_ee_find_ecb_by_conn_id
    415 **
    416 ** Description      Return the ecb associated with the given connection id
    417 **
    418 ** Returns          tNFA_EE_ECB
    419 **
    420 *******************************************************************************/
    421 tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id)
    422 {
    423     UINT32  xx;
    424     tNFA_EE_ECB *p_ret = NULL, *p_cb;
    425     NFA_TRACE_DEBUG0 ("nfa_ee_find_ecb_by_conn_id ()");
    426 
    427     p_cb = nfa_ee_cb.ecb;
    428     for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
    429     {
    430         if (conn_id == p_cb->conn_id)
    431         {
    432             p_ret = p_cb;
    433             break;
    434         }
    435     }
    436 
    437     return p_ret;
    438 }
    439 
    440 /*******************************************************************************
    441 **
    442 ** Function         nfa_ee_sys_disable
    443 **
    444 ** Description      Deregister NFA EE from NFA SYS/DM
    445 **
    446 **
    447 ** Returns          None
    448 **
    449 *******************************************************************************/
    450 void nfa_ee_sys_disable (void)
    451 {
    452     UINT32  xx;
    453     tNFA_EE_ECB *p_cb;
    454     tNFA_EE_MSG     msg;
    455 
    456     NFA_TRACE_DEBUG0 ("nfa_ee_sys_disable ()");
    457 
    458     nfa_ee_cb.em_state = NFA_EE_EM_STATE_DISABLED;
    459     /* report NFA_EE_DEREGISTER_EVT to all registered to EE */
    460     for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++)
    461     {
    462         if (nfa_ee_cb.p_ee_cback[xx])
    463         {
    464             msg.deregister.index     = xx;
    465             nfa_ee_api_deregister (&msg);
    466         }
    467     }
    468 
    469     nfa_ee_cb.num_ee_expecting  = 0;
    470     p_cb = nfa_ee_cb.ecb;
    471     for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
    472     {
    473         if (p_cb->conn_st == NFA_EE_CONN_ST_CONN)
    474         {
    475             if (nfa_sys_is_graceful_disable ())
    476             {
    477                 /* Disconnect NCI connection on graceful shutdown */
    478                 msg.disconnect.p_cb = p_cb;
    479                 nfa_ee_api_disconnect (&msg);
    480                 nfa_ee_cb.num_ee_expecting++;
    481             }
    482             else
    483             {
    484                 /* fake NFA_EE_DISCONNECT_EVT on ungraceful shutdown */
    485                 msg.conn.conn_id    = p_cb->conn_id;
    486                 msg.conn.event      = NFC_CONN_CLOSE_CEVT;
    487                 nfa_ee_nci_conn (&msg);
    488             }
    489         }
    490     }
    491 
    492     if (nfa_ee_cb.num_ee_expecting)
    493     {
    494         nfa_ee_cb.ee_flags |= NFA_EE_FLAG_WAIT_DISCONN;
    495         nfa_ee_cb.em_state  = NFA_EE_EM_STATE_DISABLING;
    496     }
    497 
    498 
    499     nfa_sys_stop_timer (&nfa_ee_cb.timer);
    500     nfa_sys_stop_timer (&nfa_ee_cb.discv_timer);
    501 
    502     /* If Application initiated NFCEE discovery, fake/report the event */
    503     nfa_ee_report_disc_done (FALSE);
    504 
    505     /* deregister message handler on NFA SYS */
    506     if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_DISABLED)
    507         nfa_sys_deregister (NFA_ID_EE);
    508 
    509 }
    510 
    511 /*******************************************************************************
    512 **
    513 ** Function         nfa_ee_check_disable
    514 **
    515 ** Description      Check if it is safe to move to disabled state
    516 **
    517 ** Returns          None
    518 **
    519 *******************************************************************************/
    520 void nfa_ee_check_disable (void)
    521 {
    522     if (!(nfa_ee_cb.ee_flags & NFA_EE_FLAG_WAIT_DISCONN))
    523     {
    524         nfa_ee_cb.em_state = NFA_EE_EM_STATE_DISABLED;
    525         nfa_sys_deregister (NFA_ID_EE);
    526     }
    527 }
    528 /*******************************************************************************
    529 **
    530 ** Function         nfa_ee_reg_cback_enable_done
    531 **
    532 ** Description      Allow a module to register to EE to be notified when NFA-EE
    533 **                  finishes enable process
    534 **
    535 ** Returns          None
    536 **
    537 *******************************************************************************/
    538 void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback)
    539 {
    540     nfa_ee_cb.p_enable_cback = p_cback;
    541 }
    542 
    543 #if (BT_TRACE_VERBOSE == TRUE)
    544 /*******************************************************************************
    545 **
    546 ** Function         nfa_ee_sm_st_2_str
    547 **
    548 ** Description      convert nfa-ee state to string
    549 **
    550 *******************************************************************************/
    551 static char *nfa_ee_sm_st_2_str (UINT8 state)
    552 {
    553     switch (state)
    554     {
    555     case NFA_EE_EM_STATE_INIT:
    556         return "INIT";
    557 
    558     case NFA_EE_EM_STATE_INIT_DONE:
    559         return "INIT_DONE";
    560 
    561     case NFA_EE_EM_STATE_RESTORING:
    562         return "RESTORING";
    563 
    564     case NFA_EE_EM_STATE_DISABLING:
    565         return "DISABLING";
    566 
    567     case NFA_EE_EM_STATE_DISABLED:
    568         return "DISABLED";
    569 
    570     default:
    571         return "Unknown";
    572     }
    573 }
    574 
    575 /*******************************************************************************
    576 **
    577 ** Function         nfa_ee_sm_evt_2_str
    578 **
    579 ** Description      convert nfa-ee evt to string
    580 **
    581 *******************************************************************************/
    582 static char *nfa_ee_sm_evt_2_str (UINT16 event)
    583 {
    584     switch (event)
    585     {
    586     case NFA_EE_API_DISCOVER_EVT:
    587         return "API_DISCOVER";
    588     case NFA_EE_API_REGISTER_EVT:
    589         return "API_REGISTER";
    590     case NFA_EE_API_DEREGISTER_EVT:
    591         return "API_DEREGISTER";
    592     case NFA_EE_API_MODE_SET_EVT:
    593         return "API_MODE_SET";
    594     case NFA_EE_API_SET_TECH_CFG_EVT:
    595         return "API_SET_TECH_CFG";
    596     case NFA_EE_API_SET_PROTO_CFG_EVT:
    597         return "API_SET_PROTO_CFG";
    598     case NFA_EE_API_ADD_AID_EVT:
    599         return "API_ADD_AID";
    600     case NFA_EE_API_REMOVE_AID_EVT:
    601         return "API_REMOVE_AID";
    602     case NFA_EE_API_UPDATE_NOW_EVT:
    603         return "API_UPDATE_NOW";
    604     case NFA_EE_API_CONNECT_EVT:
    605         return "API_CONNECT";
    606     case NFA_EE_API_SEND_DATA_EVT:
    607         return "API_SEND_DATA";
    608     case NFA_EE_API_DISCONNECT_EVT:
    609         return "API_DISCONNECT";
    610     case NFA_EE_NCI_DISC_RSP_EVT:
    611         return "NCI_DISC_RSP";
    612     case NFA_EE_NCI_DISC_NTF_EVT:
    613         return "NCI_DISC_NTF";
    614     case NFA_EE_NCI_MODE_SET_RSP_EVT:
    615         return "NCI_MODE_SET";
    616     case NFA_EE_NCI_CONN_EVT:
    617         return "NCI_CONN";
    618     case NFA_EE_NCI_DATA_EVT:
    619         return "NCI_DATA";
    620     case NFA_EE_NCI_ACTION_NTF_EVT:
    621         return "NCI_ACTION";
    622     case NFA_EE_NCI_DISC_REQ_NTF_EVT:
    623         return "NCI_DISC_REQ";
    624     case NFA_EE_ROUT_TIMEOUT_EVT:
    625         return "ROUT_TIMEOUT";
    626     case NFA_EE_DISCV_TIMEOUT_EVT:
    627         return "NFA_EE_DISCV_TIMEOUT_EVT";
    628     case NFA_EE_CFG_TO_NFCC_EVT:
    629         return "CFG_TO_NFCC";
    630     default:
    631         return "Unknown";
    632     }
    633 }
    634 #endif /* BT_TRACE_VERBOSE */
    635 
    636 /*******************************************************************************
    637 **
    638 ** Function         nfa_ee_evt_hdlr
    639 **
    640 ** Description      Processing event for NFA EE
    641 **
    642 **
    643 ** Returns          TRUE if p_msg needs to be deallocated
    644 **
    645 *******************************************************************************/
    646 BOOLEAN nfa_ee_evt_hdlr (BT_HDR *p_msg)
    647 {
    648     tNFA_EE_MSG *p_evt_data = (tNFA_EE_MSG *) p_msg;
    649     UINT16  event = p_msg->event & 0x00ff;
    650     BOOLEAN act = FALSE;
    651 
    652 #if (BT_TRACE_VERBOSE == TRUE)
    653     NFA_TRACE_DEBUG4 ("nfa_ee_evt_hdlr (): Event %s(0x%02x), State: %s(%d)",
    654         nfa_ee_sm_evt_2_str (p_evt_data->hdr.event), p_evt_data->hdr.event,
    655         nfa_ee_sm_st_2_str (nfa_ee_cb.em_state), nfa_ee_cb.em_state);
    656 #else
    657     NFA_TRACE_DEBUG2 ("nfa_ee_evt_hdlr (): Event 0x%02x, State: %d", p_evt_data->hdr.event, nfa_ee_cb.em_state);
    658 #endif
    659 
    660     switch (nfa_ee_cb.em_state)
    661     {
    662     case NFA_EE_EM_STATE_INIT_DONE:
    663     case NFA_EE_EM_STATE_RESTORING:
    664         act = TRUE;
    665         break;
    666     case NFA_EE_EM_STATE_INIT:
    667         if ((p_msg->event == NFA_EE_NCI_DISC_NTF_EVT) || (p_msg->event == NFA_EE_NCI_DISC_RSP_EVT))
    668             act = TRUE;
    669         break;
    670     case NFA_EE_EM_STATE_DISABLING:
    671         if (p_msg->event == NFA_EE_NCI_CONN_EVT)
    672             act = TRUE;
    673         break;
    674     }
    675     if (act)
    676     {
    677         if (event < NFA_EE_NUM_ACTIONS)
    678         {
    679             (*nfa_ee_actions[event]) (p_evt_data);
    680         }
    681     }
    682     else
    683     {
    684         /* if the data event is not handled by action function, free the data packet */
    685         if (p_msg->event == NFA_EE_NCI_DATA_EVT)
    686             GKI_freebuf (p_evt_data->conn.p_data);
    687     }
    688 
    689     return TRUE;
    690 }
    691 
    692 
    693