1/******************************************************************************
2 *
3 *  Copyright (C) 2010-2012 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 *  This file contains the action functions for device manager state
22 *  machine.
23 *
24 ******************************************************************************/
25#include <string.h>
26#include "nfa_sys.h"
27#include "nfa_api.h"
28#include "nfa_dm_int.h"
29#include "nfa_sys_int.h"
30#include "nfa_ce_int.h"
31#include "nfc_api.h"
32#include "nfa_rw_int.h"
33#include "nfa_rw_api.h"
34#include "nfa_p2p_int.h"
35#include "nfa_cho_int.h"
36#include "nci_hmsgs.h"
37
38#if (NFC_NFCEE_INCLUDED == TRUE)
39#include "nfa_ee_int.h"
40#include "nfa_hci_int.h"
41#endif
42
43#if (defined (NFA_SNEP_INCLUDED) && (NFA_SNEP_INCLUDED==TRUE))
44#include "nfa_snep_int.h"
45#else
46#define nfa_snep_init ()
47#endif
48
49/* This is the timeout value to guarantee disable is performed within reasonable amount of time */
50#ifndef NFA_DM_DISABLE_TIMEOUT_VAL
51#define NFA_DM_DISABLE_TIMEOUT_VAL         1000
52#endif
53
54static void nfa_dm_set_init_nci_params (void);
55static tNFA_STATUS nfa_dm_start_polling (void);
56static BOOLEAN nfa_dm_deactivate_polling (void);
57static void nfa_dm_excl_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
58static void nfa_dm_poll_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
59
60
61/*******************************************************************************
62**
63** Function         nfa_dm_module_init_cback
64**
65** Description      Processing initialization complete event from sub-modules
66**
67** Returns          None
68**
69*******************************************************************************/
70static void nfa_dm_module_init_cback (void)
71{
72    tNFA_DM_CBACK_DATA dm_cback_data;
73
74    nfa_dm_cb.flags &= ~NFA_DM_FLAGS_ENABLE_EVT_PEND;
75
76    /* All subsystem are initialized */
77    dm_cback_data.status = NFA_STATUS_OK;
78    (*nfa_dm_cb.p_dm_cback) (NFA_DM_ENABLE_EVT, &dm_cback_data);
79}
80
81/*******************************************************************************
82**
83** Function         nfa_dm_nfcc_power_mode_proc_complete_cback
84**
85** Description      Processing complete of processing NFCC power state change
86**                  from all sub-modules
87**
88** Returns          None
89**
90*******************************************************************************/
91static void nfa_dm_nfcc_power_mode_proc_complete_cback (void)
92{
93    tNFA_DM_PWR_MODE_CHANGE power_mode_change;
94
95    NFA_TRACE_DEBUG1 ("nfa_dm_nfcc_power_mode_proc_complete_cback () nfcc_pwr_mode = 0x%x",
96                      nfa_dm_cb.nfcc_pwr_mode);
97
98    /* if NFCC power state is change to full power */
99    if (nfa_dm_cb.nfcc_pwr_mode != NFA_DM_PWR_MODE_OFF_SLEEP)
100    {
101        nfa_dm_cb.flags &= ~NFA_DM_FLAGS_NFCC_IS_RESTORING;
102
103        /* reconfigure BRCM NFCC */
104        nfa_dm_disc_sm_execute (NFA_DM_RF_DISCOVER_CMD, NULL);
105    }
106
107    nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SETTING_PWR_MODE;
108
109    power_mode_change.status     = NFA_STATUS_OK;
110    power_mode_change.power_mode = nfa_dm_cb.nfcc_pwr_mode;
111    (*nfa_dm_cb.p_dm_cback) (NFA_DM_PWR_MODE_CHANGE_EVT, (tNFA_DM_CBACK_DATA*) &power_mode_change);
112}
113/*******************************************************************************
114**
115** Function         nfa_dm_sys_enable
116**
117** Description      This function on enable
118**
119** Returns          void
120**
121*******************************************************************************/
122void nfa_dm_sys_enable (void)
123{
124    nfa_dm_set_init_nci_params ();
125}
126
127/*******************************************************************************
128**
129** Function         nfa_dm_set_init_nci_params
130**
131** Description      Set initial NCI configuration parameters
132**
133** Returns          void
134**
135*******************************************************************************/
136static void nfa_dm_set_init_nci_params (void)
137{
138    UINT8   xx;
139
140    /* set NCI default value if other than zero */
141
142    /* LF_T3T_IDENTIFIERS_1/2/.../16 */
143    for (xx = 0; xx < NFA_CE_LISTEN_INFO_MAX; xx++)
144    {
145        nfa_dm_cb.params.lf_t3t_id[xx][0] = 0xFF;
146        nfa_dm_cb.params.lf_t3t_id[xx][1] = 0xFF;
147        nfa_dm_cb.params.lf_t3t_id[xx][2] = 0x02;
148        nfa_dm_cb.params.lf_t3t_id[xx][2] = 0xFE;
149    }
150
151    /* LF_T3T_PMM */
152    for (xx = 0; xx < NCI_PARAM_LEN_LF_T3T_PMM; xx++)
153    {
154        nfa_dm_cb.params.lf_t3t_pmm[xx] = 0xFF;
155    }
156
157    /* LF_T3T_FLAGS:
158    ** DH needs to set this configuration, even if default value (not listening) is used,
159    ** to let NFCC know of intention (not listening) of DH.
160    */
161
162    /* FWI */
163    nfa_dm_cb.params.fwi[0] = 0x04;
164
165    /* WT */
166    nfa_dm_cb.params.wt[0] = 14;
167
168    /* Set CE default configuration */
169    if (p_nfa_dm_ce_cfg[0])
170    {
171        nfa_dm_check_set_config (p_nfa_dm_ce_cfg[0], &p_nfa_dm_ce_cfg[1], FALSE);
172    }
173
174    /* Set optional general default configuration */
175    if (p_nfa_dm_gen_cfg && p_nfa_dm_gen_cfg[0])
176    {
177        nfa_dm_check_set_config (p_nfa_dm_gen_cfg[0], &p_nfa_dm_gen_cfg[1], FALSE);
178    }
179
180    if (p_nfa_dm_interface_mapping && nfa_dm_num_dm_interface_mapping)
181    {
182        NFC_DiscoveryMap (nfa_dm_num_dm_interface_mapping, p_nfa_dm_interface_mapping, NULL);
183    }
184}
185
186/*******************************************************************************
187**
188** Function         nfa_dm_proc_nfcc_power_mode
189**
190** Description      Processing NFCC power mode changes
191**
192** Returns          None
193**
194*******************************************************************************/
195void nfa_dm_proc_nfcc_power_mode (UINT8 nfcc_power_mode)
196{
197    NFA_TRACE_DEBUG1 ("nfa_dm_proc_nfcc_power_mode (): nfcc_power_mode=%d",
198                       nfcc_power_mode);
199
200    /* if NFCC power mode is change to full power */
201    if (nfcc_power_mode == NFA_DM_PWR_MODE_FULL)
202    {
203        memset (&nfa_dm_cb.params, 0x00, sizeof (tNFA_DM_PARAMS));
204
205        nfa_dm_cb.setcfg_pending_mask = 0;
206        nfa_dm_cb.setcfg_pending_num  = 0;
207        nfa_dm_set_init_nci_params ();
208    }
209
210    nfa_sys_cback_notify_nfcc_power_mode_proc_complete (NFA_ID_DM);
211}
212
213/*******************************************************************************
214**
215** Function         nfa_dm_disable_event
216**
217** Description      report disable event
218**
219** Returns          void
220**
221*******************************************************************************/
222static void nfa_dm_disable_event (void)
223{
224    /* Deregister DM from sys */
225    nfa_sys_deregister (NFA_ID_DM);
226
227    /* Notify app */
228    nfa_dm_cb.flags &= ~(NFA_DM_FLAGS_DM_IS_ACTIVE
229                        |NFA_DM_FLAGS_DM_DISABLING_NFC
230                        |NFA_DM_FLAGS_ENABLE_EVT_PEND);
231    (*nfa_dm_cb.p_dm_cback) (NFA_DM_DISABLE_EVT, NULL);
232}
233
234/*******************************************************************************
235**
236** Function         nfa_dm_nfc_response_cback
237**
238** Description      Call DM event hanlder with NFC response callback data
239**
240** Returns          void
241**
242*******************************************************************************/
243static void nfa_dm_nfc_response_cback (tNFC_RESPONSE_EVT event, tNFC_RESPONSE *p_data)
244{
245    tNFA_DM_CBACK_DATA dm_cback_data;
246    tNFA_GET_CONFIG   *p_nfa_get_confg;
247    tNFA_CONN_EVT_DATA conn_evt;
248    UINT8 dm_cback_evt;
249
250#if (BT_TRACE_VERBOSE == TRUE)
251    NFA_TRACE_DEBUG2 ("nfa_dm_nfc_response_cback () %s(0x%x)", nfa_dm_nfc_revt_2_str (event), event);
252#else
253    NFA_TRACE_DEBUG1 ("nfa_dm_nfc_response_cback () event=0x%x", event);
254#endif
255
256    switch (event)
257    {
258    case NFC_ENABLE_REVT:                        /* 0  Enable event */
259
260        /* NFC stack enabled. Enable nfa sub-systems */
261        if (p_data->enable.status == NFC_STATUS_OK)
262        {
263            nfa_dm_set_init_nci_params ();
264
265            /* Initialize NFA subsystems */
266            nfa_sys_enable_subsystems ();
267        }
268        else if (nfa_dm_cb.flags & NFA_DM_FLAGS_ENABLE_EVT_PEND)
269        {
270            /* Notify app */
271            nfa_dm_cb.flags &= ~(NFA_DM_FLAGS_ENABLE_EVT_PEND | NFA_DM_FLAGS_DM_IS_ACTIVE);
272            dm_cback_data.status = p_data->enable.status;
273            (*nfa_dm_cb.p_dm_cback) (NFA_DM_ENABLE_EVT, &dm_cback_data);
274        }
275        break;
276
277    case NFC_DISABLE_REVT:                       /* 1  Disable event */
278        nfa_dm_disable_event ();
279        break;
280
281    case NFC_SET_CONFIG_REVT:                    /* 2  Set Config Response */
282        /* If this setconfig was due to NFA_SetConfig, then notify the app */
283        if (nfa_dm_cb.setcfg_pending_mask & 1)      /* lsb=whether last NCI_SET_CONFIG was due to NFA_SetConfig */
284        {
285            dm_cback_data.set_config.status         = p_data->set_config.status;
286            dm_cback_data.set_config.num_param_id   = p_data->set_config.num_param_id;
287            memcpy (dm_cback_data.set_config.param_ids, p_data->set_config.param_ids, p_data->set_config.num_param_id);
288            (*nfa_dm_cb.p_dm_cback) (NFA_DM_SET_CONFIG_EVT, &dm_cback_data);
289        }
290
291        /* Update the pending mask */
292        if (nfa_dm_cb.setcfg_pending_num>0)
293        {
294            nfa_dm_cb.setcfg_pending_mask >>= 1;
295            nfa_dm_cb.setcfg_pending_num--;
296        }
297        else
298        {
299            /* This should not occur (means we got a SET_CONFIG_NTF that's unaccounted for */
300            NFA_TRACE_ERROR0 ("NFA received unexpected NFC_SET_CONFIG_REVT");
301        }
302        break;
303
304    case NFC_GET_CONFIG_REVT:                    /* 3  Get Config Response */
305        if (p_data->get_config.status == NFC_STATUS_OK)
306        {
307            if ((p_nfa_get_confg = (tNFA_GET_CONFIG *) GKI_getbuf ((UINT16) (sizeof (tNFA_GET_CONFIG) + p_data->get_config.tlv_size))) != NULL)
308            {
309                p_nfa_get_confg->status = NFA_STATUS_OK;
310                p_nfa_get_confg->tlv_size = p_data->get_config.tlv_size;
311                memcpy (p_nfa_get_confg->param_tlvs, p_data->get_config.p_param_tlvs, p_data->get_config.tlv_size);
312                (*nfa_dm_cb.p_dm_cback) (NFA_DM_GET_CONFIG_EVT, (tNFA_DM_CBACK_DATA *) p_nfa_get_confg);
313
314                GKI_freebuf (p_nfa_get_confg);
315                return;
316            }
317            else
318            {
319                NFA_TRACE_DEBUG0 ("nfa_dm_nfc_response_cback unable to allocate buffer");
320            }
321        }
322
323        /* Return result of getconfig to the app */
324        dm_cback_data.get_config.status = NFA_STATUS_FAILED;
325        (*nfa_dm_cb.p_dm_cback) (NFA_DM_GET_CONFIG_EVT, &dm_cback_data);
326        break;
327
328#if (NFC_NFCEE_INCLUDED == TRUE)
329    case NFC_NFCEE_DISCOVER_REVT:                /* NFCEE Discover response */
330    case NFC_NFCEE_INFO_REVT:                    /* NFCEE Discover Notification */
331    case NFC_EE_ACTION_REVT:                     /* EE Action notification */
332    case NFC_NFCEE_MODE_SET_REVT:                /* NFCEE Mode Set response */
333    case NFC_EE_DISCOVER_REQ_REVT:               /* EE Discover Req notification */
334        nfa_ee_proc_evt (event, p_data);
335        break;
336#endif
337
338    case NFC_RF_FIELD_REVT:                      /* RF Field information            */
339        dm_cback_data.rf_field.status          = NFA_STATUS_OK;
340        dm_cback_data.rf_field.rf_field_status = p_data->rf_field.rf_field;
341        (*nfa_dm_cb.p_dm_cback) (NFA_DM_RF_FIELD_EVT, &dm_cback_data);
342        break;
343
344    case NFC_SET_ROUTING_REVT:                   /* Configure Routing response */
345        break;
346
347    case NFC_GET_ROUTING_REVT:                   /* Retrieve Routing response */
348        break;
349
350    case NFC_GEN_ERROR_REVT:                     /* generic error command or notification */
351        break;
352
353    case NFC_NFCC_RESTART_REVT:                  /* NFCC has been re-initialized */
354
355        if (p_data->status == NFC_STATUS_OK)
356        {
357            nfa_dm_cb.nfcc_pwr_mode = NFA_DM_PWR_MODE_FULL;
358            nfa_dm_cb.flags |= NFA_DM_FLAGS_NFCC_IS_RESTORING;
359
360            /* NFCC will start from IDLE when turned on again */
361            nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_W4_RSP;
362            nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_W4_NTF;
363            nfa_dm_cb.disc_cb.disc_state = NFA_DM_RFST_IDLE;
364        }
365        else
366        {
367            nfa_dm_cb.nfcc_pwr_mode = NFA_DM_PWR_MODE_OFF_SLEEP;
368        }
369        /* Notify NFA submodules change of NFCC power mode */
370        nfa_sys_cback_reg_nfcc_power_mode_proc_complete (nfa_dm_nfcc_power_mode_proc_complete_cback);
371        nfa_sys_notify_nfcc_power_mode (nfa_dm_cb.nfcc_pwr_mode);
372        break;
373
374    case NFC_NFCC_TIMEOUT_REVT:
375    case NFC_NFCC_TRANSPORT_ERR_REVT:
376        NFA_TRACE_DEBUG1 ("flags:0x%08x", nfa_dm_cb.flags);
377        dm_cback_evt = (event == NFC_NFCC_TIMEOUT_REVT) ? NFA_DM_NFCC_TIMEOUT_EVT : NFA_DM_NFCC_TRANSPORT_ERR_EVT;
378        (*nfa_dm_cb.p_dm_cback) (dm_cback_evt, NULL);
379        break;
380
381    case NFC_NFCC_POWER_OFF_REVT:
382        nfa_dm_cb.nfcc_pwr_mode = NFA_DM_PWR_MODE_OFF_SLEEP;
383
384        /* Notify NFA submodules change of NFCC power mode */
385        nfa_sys_cback_reg_nfcc_power_mode_proc_complete (nfa_dm_nfcc_power_mode_proc_complete_cback);
386        nfa_sys_notify_nfcc_power_mode (NFA_DM_PWR_MODE_OFF_SLEEP);
387        break;
388
389    case NFC_RF_COMM_PARAMS_UPDATE_REVT:
390        conn_evt.status = p_data->status;
391        nfa_dm_conn_cback_event_notify (NFA_UPDATE_RF_PARAM_RESULT_EVT, &conn_evt);
392        break;
393
394    default:
395        break;
396    }
397}
398
399
400/*******************************************************************************
401**
402** Function         nfa_dm_enable
403**
404** Description      Initialises the NFC device manager
405**
406** Returns          TRUE (message buffer to be freed by caller)
407**
408*******************************************************************************/
409BOOLEAN nfa_dm_enable (tNFA_DM_MSG *p_data)
410{
411    tNFA_DM_CBACK_DATA dm_cback_data;
412    NFA_TRACE_DEBUG0 ("nfa_dm_enable ()");
413
414    /* Check if NFA is already enabled */
415    if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_DM_IS_ACTIVE))
416    {
417        /* Initialize BRCM control block, it musb be called before setting any flags */
418        nfa_dm_cb.flags |= (NFA_DM_FLAGS_DM_IS_ACTIVE | NFA_DM_FLAGS_ENABLE_EVT_PEND);
419        nfa_sys_cback_reg_enable_complete (nfa_dm_module_init_cback);
420
421
422        /* Store Enable parameters */
423        nfa_dm_cb.p_dm_cback    = p_data->enable.p_dm_cback;
424        nfa_dm_cb.p_conn_cback  = p_data->enable.p_conn_cback;
425
426        /* Enable NFC stack */
427        NFC_Enable (nfa_dm_nfc_response_cback);
428    }
429    else
430    {
431        NFA_TRACE_ERROR0 ("nfa_dm_enable: ERROR ALREADY ENABLED.");
432        dm_cback_data.status = NFA_STATUS_ALREADY_STARTED;
433        (*(p_data->enable.p_dm_cback)) (NFA_DM_ENABLE_EVT, &dm_cback_data);
434    }
435
436    return (TRUE);
437}
438
439/*******************************************************************************
440**
441** Function         nfa_dm_disable
442**
443** Description      Disables the NFC device manager
444**
445** Returns          TRUE (message buffer to be freed by caller)
446**
447*******************************************************************************/
448BOOLEAN nfa_dm_disable (tNFA_DM_MSG *p_data)
449{
450    tNFC_DEACT_TYPE deactivate_type = NFA_DEACTIVATE_TYPE_IDLE;
451
452    NFA_TRACE_DEBUG1 ("nfa_dm_disable (): graceful:%d", p_data->disable.graceful);
453
454    if (p_data->disable.graceful)
455    {
456        /* if RF discovery is enabled */
457        if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED)
458        {
459            nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
460
461            if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_IDLE)
462            {
463                /* if waiting RSP in idle state */
464                if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP)
465                {
466                    nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_DISABLING;
467                }
468            }
469            else
470            {
471                nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_DISABLING;
472                nfa_dm_disc_sm_execute (NFA_DM_RF_DEACTIVATE_CMD, (tNFA_DM_RF_DISC_DATA *) &deactivate_type);
473                if ((nfa_dm_cb.disc_cb.disc_flags & (NFA_DM_DISC_FLAGS_W4_RSP|NFA_DM_DISC_FLAGS_W4_NTF)) == 0)
474                {
475                    /* not waiting to deactivate, clear the flag now */
476                    nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_DISABLING;
477                }
478            }
479        }
480        /* Start timeout for graceful shutdown. If timer expires, then force an ungraceful shutdown */
481        nfa_sys_start_timer (&nfa_dm_cb.tle, NFA_DM_TIMEOUT_DISABLE_EVT, NFA_DM_DISABLE_TIMEOUT_VAL);
482    }
483
484    /* Disable all subsystems other than DM (DM will be disabled after all  */
485    /* the other subsystem have been disabled)                              */
486    nfa_sys_disable_subsystems (p_data->disable.graceful);
487    return (TRUE);
488}
489
490
491/*******************************************************************************
492**
493** Function         nfa_dm_disable_complete
494**
495** Description      Called when all NFA subsytems are disabled.
496**
497**                  NFC core stack can now be disabled.
498**
499** Returns          void
500**
501*******************************************************************************/
502void nfa_dm_disable_complete (void)
503{
504    NFA_TRACE_DEBUG0 ("nfa_dm_disable_complete ()");
505
506    if ((nfa_dm_cb.flags & NFA_DM_FLAGS_DM_DISABLING_NFC) == 0)
507    {
508        NFA_TRACE_DEBUG0 ("nfa_dm_disable_complete (): proceeding with nfc core shutdown.");
509
510        nfa_dm_cb.flags |= NFA_DM_FLAGS_DM_DISABLING_NFC;
511
512        nfa_sys_stop_timer (&nfa_dm_cb.tle);
513
514        /* Free all buffers for NDEF handlers */
515        nfa_dm_ndef_dereg_all();
516
517        /* Disable nfc core stack */
518        NFC_Disable ();
519    }
520}
521
522/*******************************************************************************
523**
524** Function         nfa_dm_set_config
525**
526** Description      Process set config command
527**
528** Returns          TRUE (message buffer to be freed by caller)
529**
530*******************************************************************************/
531BOOLEAN nfa_dm_set_config (tNFA_DM_MSG *p_data)
532{
533    tNFC_STATUS status;
534    UINT8       buff[255];
535    UINT8      *p = buff;
536
537    tNFA_DM_CBACK_DATA dm_cback_data;
538
539    if (p_data->setconfig.length + 2 > 255)
540    {
541        /* Total length of TLV must be less than 256 (1 byte) */
542        status = NFC_STATUS_FAILED;
543    }
544    else
545    {
546        UINT8_TO_STREAM (p, p_data->setconfig.param_id);
547        UINT8_TO_STREAM (p, p_data->setconfig.length);
548        ARRAY_TO_STREAM (p, p_data->setconfig.p_data, p_data->setconfig.length)
549        status = nfa_dm_check_set_config ((UINT8) (p_data->setconfig.length + 2), buff, TRUE);
550    }
551
552    if (status != NFC_STATUS_OK)
553    {
554        dm_cback_data.set_config.status = NFA_STATUS_INVALID_PARAM;
555        (*nfa_dm_cb.p_dm_cback) (NFA_DM_SET_CONFIG_EVT, &dm_cback_data);
556    }
557
558    return (TRUE);
559}
560
561/*******************************************************************************
562**
563** Function         nfa_dm_get_config
564**
565** Description      Process get config command
566**
567** Returns          TRUE (message buffer to be freed by caller)
568**
569*******************************************************************************/
570BOOLEAN nfa_dm_get_config (tNFA_DM_MSG *p_data)
571{
572    NFC_GetConfig (p_data->getconfig.num_ids, p_data->getconfig.p_pmids);
573
574    return (TRUE);
575}
576
577/*******************************************************************************
578**
579** Function         nfa_dm_conn_cback_event_notify
580**
581** Description      Notify application of CONN_CBACK event, using appropriate
582**                  callback
583**
584** Returns          nothing
585**
586*******************************************************************************/
587void nfa_dm_conn_cback_event_notify (UINT8 event, tNFA_CONN_EVT_DATA *p_data)
588{
589    if (nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)
590    {
591        /* Use exclusive RF mode callback */
592        if (nfa_dm_cb.p_excl_conn_cback)
593            (*nfa_dm_cb.p_excl_conn_cback) (event, p_data);
594    }
595    else
596    {
597        (*nfa_dm_cb.p_conn_cback) (event, p_data);
598    }
599}
600
601/*******************************************************************************
602**
603** Function         nfa_dm_rel_excl_rf_control_and_notify
604**
605** Description      Stop exclusive RF control and notify app of
606**                  NFA_EXCLUSIVE_RF_CONTROL_STOPPED_EVT
607**
608** Returns          void
609**
610*******************************************************************************/
611void nfa_dm_rel_excl_rf_control_and_notify (void)
612{
613    tNFA_CONN_EVT_DATA conn_evt;
614
615    NFA_TRACE_DEBUG0 ("nfa_dm_rel_excl_rf_control_and_notify ()");
616
617    /* Exclusive RF control stopped. Notify app */
618    nfa_dm_cb.flags &= ~NFA_DM_FLAGS_EXCL_RF_ACTIVE;
619
620    /* Stop exclusive RF discovery for exclusive RF mode */
621    nfa_dm_stop_excl_discovery ();
622
623    /* Notify app that exclusive RF control has stopped */
624    conn_evt.status = NFA_STATUS_OK;
625    (*nfa_dm_cb.p_excl_conn_cback) (NFA_EXCLUSIVE_RF_CONTROL_STOPPED_EVT, &conn_evt);
626    nfa_dm_cb.p_excl_conn_cback = NULL;
627    nfa_dm_cb.p_excl_ndef_cback = NULL;
628}
629
630/*******************************************************************************
631**
632** Function         nfa_dm_act_request_excl_rf_ctrl
633**
634** Description      Request exclusive RF control
635**
636** Returns          TRUE (message buffer to be freed by caller)
637**
638*******************************************************************************/
639BOOLEAN nfa_dm_act_request_excl_rf_ctrl (tNFA_DM_MSG *p_data)
640{
641    tNFA_CONN_EVT_DATA conn_evt;
642
643    NFA_TRACE_DEBUG0 ("nfa_dm_act_request_excl_rf_ctrl ()");
644
645    if (!nfa_dm_cb.p_excl_conn_cback)
646    {
647        if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_IDLE)
648        {
649            conn_evt.status = NFA_STATUS_FAILED;
650            (*p_data->req_excl_rf_ctrl.p_conn_cback) (NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT, &conn_evt);
651            return TRUE;
652        }
653
654        /* Store callbacks */
655        nfa_dm_cb.p_excl_conn_cback = p_data->req_excl_rf_ctrl.p_conn_cback;
656        nfa_dm_cb.p_excl_ndef_cback = p_data->req_excl_rf_ctrl.p_ndef_cback;
657
658        nfa_dm_cb.flags |= NFA_DM_FLAGS_EXCL_RF_ACTIVE;
659
660        /* start exclusive RF discovery */
661        nfa_dm_start_excl_discovery (p_data->req_excl_rf_ctrl.poll_mask,
662                                     &p_data->req_excl_rf_ctrl.listen_cfg,
663                                     nfa_dm_excl_disc_cback);
664    }
665    else
666    {
667        NFA_TRACE_ERROR0 ("Exclusive rf control already requested");
668
669        conn_evt.status = NFA_STATUS_FAILED;
670        (*p_data->req_excl_rf_ctrl.p_conn_cback) (NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT, &conn_evt);
671    }
672
673    return TRUE;
674}
675
676
677/*******************************************************************************
678**
679** Function         nfa_dm_act_release_excl_rf_ctrl
680**
681** Description      Release exclusive RF control
682**
683** Returns          TRUE (message buffer to be freed by caller)
684**
685*******************************************************************************/
686BOOLEAN nfa_dm_act_release_excl_rf_ctrl (tNFA_DM_MSG *p_data)
687{
688    NFA_TRACE_DEBUG0 ("nfa_dm_act_release_excl_rf_ctrl ()");
689
690    /* nfa_dm_rel_excl_rf_control_and_notify() is called when discovery state goes IDLE */
691    nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
692
693    /* if discover command has been sent in IDLE state and waiting for response
694    ** then just wait for responose. Otherwise initiate deactivating.
695    */
696    if (!(  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_IDLE)
697          &&(nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP)  ))
698    {
699        nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
700    }
701
702    return TRUE;
703}
704
705/*******************************************************************************
706**
707** Function         nfa_dm_act_deactivate
708**
709** Description      Process deactivate command
710**
711** Returns          TRUE (message buffer to be freed by caller)
712**
713*******************************************************************************/
714BOOLEAN nfa_dm_act_deactivate (tNFA_DM_MSG *p_data)
715{
716    tNFA_CONN_EVT_DATA conn_evt;
717    tNFA_DEACTIVATE_TYPE deact_type;
718
719    NFA_TRACE_DEBUG0 ("nfa_dm_act_deactivate ()");
720
721    if (  (p_data->deactivate.sleep_mode == FALSE)                 /* Always allow deactivate to IDLE */
722        ||(  (nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_T1T)      /* Do not allow deactivate to SLEEP for T1T,NFCDEP, ISO15693 */
723           &&(nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_NFC_DEP)
724           &&(nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_ISO15693)  )  )
725    {
726        if (  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_NFC_DEP)
727            &&((nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE) == 0x00)  )
728        {
729            /* Exclusive RF control doesn't use NFA P2P */
730            /* NFA P2P will deactivate NFC link after deactivating LLCP link */
731            nfa_p2p_deactivate_llcp ();
732            return (TRUE);
733        }
734        else
735        {
736            deact_type  = NFA_DEACTIVATE_TYPE_DISCOVERY;
737            if (p_data->deactivate.sleep_mode)
738            {
739                if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_HOST_SELECT)
740                {
741                    /* Deactivate to sleep mode not allowed in this state. */
742                    deact_type = NFA_DEACTIVATE_TYPE_IDLE;
743                }
744                else if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_LISTEN_SLEEP)
745                {
746                    deact_type = NFA_DEACTIVATE_TYPE_SLEEP;
747                }
748            }
749            if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
750            {
751                /* Only deactivate to IDLE is allowed in this state. */
752                deact_type = NFA_DEACTIVATE_TYPE_IDLE;
753            }
754            if (nfa_dm_rf_deactivate (deact_type) == NFA_STATUS_OK)
755            {
756                nfa_rw_stop_presence_check_timer ();
757                return (TRUE);
758            }
759        }
760    }
761
762    NFA_TRACE_ERROR0 ("nfa_dm_act_deactivate (): invalid protocol or mode");
763
764    /* Notify error to application */
765    conn_evt.status = NFA_STATUS_FAILED;
766    nfa_dm_conn_cback_event_notify (NFA_DEACTIVATE_FAIL_EVT, &conn_evt);
767
768    return (TRUE);
769}
770
771/*******************************************************************************
772**
773** Function         nfa_dm_act_power_off_sleep
774**
775** Description      Process power off sleep mode request
776**
777** Returns          TRUE (message buffer to be freed by caller)
778**
779*******************************************************************************/
780BOOLEAN nfa_dm_act_power_off_sleep (tNFA_DM_MSG *p_data)
781{
782    NFA_TRACE_DEBUG0 ("nfa_dm_act_power_off_sleep ()");
783
784    NFC_SetPowerOffSleep ((BOOLEAN) (p_data->hdr.layer_specific));
785
786    return (TRUE);
787}
788
789/*******************************************************************************
790**
791** Function         nfa_dm_act_reg_vsc
792**
793** Description      Process registers VSC callback
794**
795** Returns          TRUE (message buffer to be freed by caller)
796**
797*******************************************************************************/
798BOOLEAN nfa_dm_act_reg_vsc(tNFA_DM_MSG *p_data)
799{
800    if (NFC_RegVSCback(p_data->reg_vsc.is_register, p_data->reg_vsc.p_cback) != NFC_STATUS_OK)
801    {
802        NFA_TRACE_ERROR0 ("NFC_RegVSCback failed");
803    }
804    return (TRUE);
805}
806
807/*******************************************************************************
808**
809** Function         nfa_dm_act_send_vsc
810**
811** Description      Send the NCI Vendor Specific command to the NCI command queue
812**
813** Returns          FALSE (message buffer is NOT freed by caller)
814**
815*******************************************************************************/
816BOOLEAN nfa_dm_act_send_vsc(tNFA_DM_MSG *p_data)
817{
818    BT_HDR  *p_cmd = (BT_HDR *)p_data;
819
820    p_cmd->offset   = sizeof (tNFA_DM_API_SEND_VSC) - BT_HDR_SIZE;
821    p_cmd->len      = p_data->send_vsc.cmd_params_len;
822    NFC_SendVsCommand (p_data->send_vsc.oid, p_cmd, p_data->send_vsc.p_cback);
823
824    /* Most dm action functions return TRUE, so nfa-sys frees the GKI buffer carrying the message,
825     * This action function re-use the GKI buffer to send the VSC, so the GKI buffer can not be freed by nfa-sys */
826    return (FALSE);
827}
828
829/*******************************************************************************
830**
831** Function         nfa_dm_start_polling
832**
833** Description      Start polling
834**
835** Returns          tNFA_STATUS
836**
837*******************************************************************************/
838tNFA_STATUS nfa_dm_start_polling (void)
839{
840    tNFA_STATUS             status;
841    tNFA_TECHNOLOGY_MASK    poll_tech_mask;
842    tNFA_DM_DISC_TECH_PROTO_MASK poll_disc_mask = 0;
843
844    NFA_TRACE_DEBUG0 ("nfa_dm_start_polling ()");
845
846    poll_tech_mask = nfa_dm_cb.poll_mask;
847
848    /* start RF discovery with discovery callback */
849    if (nfa_dm_cb.poll_disc_handle == NFA_HANDLE_INVALID)
850    {
851        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_A)
852        {
853            poll_disc_mask |= NFA_DM_DISC_MASK_PA_T1T;
854            poll_disc_mask |= NFA_DM_DISC_MASK_PA_T2T;
855            poll_disc_mask |= NFA_DM_DISC_MASK_PA_ISO_DEP;
856            poll_disc_mask |= NFA_DM_DISC_MASK_PA_NFC_DEP;
857            poll_disc_mask |= NFA_DM_DISC_MASK_P_LEGACY;
858        }
859        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_A_ACTIVE)
860        {
861            poll_disc_mask |= NFA_DM_DISC_MASK_PAA_NFC_DEP;
862        }
863        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_B)
864        {
865            poll_disc_mask |= NFA_DM_DISC_MASK_PB_ISO_DEP;
866        }
867        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_F)
868        {
869            poll_disc_mask |= NFA_DM_DISC_MASK_PF_T3T;
870            poll_disc_mask |= NFA_DM_DISC_MASK_PF_NFC_DEP;
871        }
872        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_F_ACTIVE)
873        {
874            poll_disc_mask |= NFA_DM_DISC_MASK_PFA_NFC_DEP;
875        }
876        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_ISO15693)
877        {
878            poll_disc_mask |= NFA_DM_DISC_MASK_P_ISO15693;
879        }
880        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_B_PRIME)
881        {
882            poll_disc_mask |= NFA_DM_DISC_MASK_P_B_PRIME;
883        }
884        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_KOVIO)
885        {
886            poll_disc_mask |= NFA_DM_DISC_MASK_P_KOVIO;
887        }
888
889        nfa_dm_cb.poll_disc_handle = nfa_dm_add_rf_discover (poll_disc_mask,
890                                                             NFA_DM_DISC_HOST_ID_DH,
891                                                             nfa_dm_poll_disc_cback);
892
893        if (nfa_dm_cb.poll_disc_handle != NFA_HANDLE_INVALID)
894            status = NFA_STATUS_OK;
895        else
896            status = NFA_STATUS_FAILED;
897    }
898    else
899    {
900        status = NFA_STATUS_OK;
901    }
902
903    return (status);
904}
905
906/*******************************************************************************
907**
908** Function         nfa_dm_act_enable_polling
909**
910** Description      Process enable polling command
911**
912** Returns          TRUE (message buffer to be freed by caller)
913**
914*******************************************************************************/
915BOOLEAN nfa_dm_act_enable_polling (tNFA_DM_MSG *p_data)
916{
917    tNFA_CONN_EVT_DATA evt_data;
918
919    NFA_TRACE_DEBUG0 ("nfa_dm_act_enable_polling ()");
920
921    if (  (!(nfa_dm_cb.flags & NFA_DM_FLAGS_POLLING_ENABLED))
922        &&(!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)  )  )
923    {
924        nfa_dm_cb.poll_mask = p_data->enable_poll.poll_mask;
925
926        if (nfa_dm_start_polling () == NFA_STATUS_OK)
927        {
928            nfa_dm_cb.flags |= NFA_DM_FLAGS_POLLING_ENABLED;
929
930            evt_data.status = NFA_STATUS_OK;
931            nfa_dm_conn_cback_event_notify (NFA_POLL_ENABLED_EVT, &evt_data);
932            return (TRUE);
933        }
934    }
935    else
936    {
937        NFA_TRACE_ERROR0 ("nfa_dm_act_enable_polling (): already started");
938    }
939
940    /* send NFA_POLL_ENABLED_EVT with NFA_STATUS_FAILED */
941    evt_data.status = NFA_STATUS_FAILED;
942    nfa_dm_conn_cback_event_notify (NFA_POLL_ENABLED_EVT, &evt_data);
943
944    return (TRUE);
945}
946
947/*******************************************************************************
948**
949** Function         nfa_dm_deactivate_polling
950**
951** Description      Deactivate any polling state
952**
953** Returns          TRUE if need to wait for deactivation
954**
955*******************************************************************************/
956static BOOLEAN nfa_dm_deactivate_polling (void)
957{
958    NFA_TRACE_DEBUG0 ("nfa_dm_deactivate_polling ()");
959
960    if (  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
961        ||(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_HOST_SELECT)  )
962    {
963        nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
964        return FALSE;
965    }
966    else if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_POLL_ACTIVE)
967    {
968        if (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_NFC_DEP)
969        {
970            /* NFA P2P will deactivate NFC link after deactivating LLCP link */
971            nfa_p2p_deactivate_llcp ();
972        }
973        else
974        {
975            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
976        }
977        return TRUE;
978    }
979    else
980    {
981        return FALSE;
982    }
983}
984
985/*******************************************************************************
986**
987** Function         nfa_dm_act_disable_polling
988**
989** Description      Process disable polling command
990**
991** Returns          TRUE (message buffer to be freed by caller)
992**
993*******************************************************************************/
994BOOLEAN nfa_dm_act_disable_polling (tNFA_DM_MSG *p_data)
995{
996    tNFA_CONN_EVT_DATA evt_data;
997
998    NFA_TRACE_DEBUG0 ("nfa_dm_act_disable_polling ()");
999
1000    if (nfa_dm_cb.poll_disc_handle != NFA_HANDLE_INVALID)
1001    {
1002        nfa_dm_cb.flags &= ~NFA_DM_FLAGS_POLLING_ENABLED;
1003
1004        if (nfa_dm_deactivate_polling () == FALSE)
1005        {
1006            nfa_dm_delete_rf_discover (nfa_dm_cb.poll_disc_handle);
1007            nfa_dm_cb.poll_disc_handle = NFA_HANDLE_INVALID;
1008
1009            evt_data.status = NFA_STATUS_OK;
1010            nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
1011        }
1012        else
1013        {
1014            nfa_dm_cb.flags |= NFA_DM_FLAGS_SEND_POLL_STOP_EVT;
1015        }
1016    }
1017    else
1018    {
1019        evt_data.status = NFA_STATUS_FAILED;
1020        nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
1021    }
1022
1023    return (TRUE);
1024}
1025
1026/*******************************************************************************
1027**
1028** Function         nfa_dm_act_send_raw_frame
1029**
1030** Description      Send an raw frame on RF link
1031**
1032** Returns          TRUE (message buffer to be freed by caller)
1033**
1034*******************************************************************************/
1035BOOLEAN nfa_dm_act_send_raw_frame (tNFA_DM_MSG *p_data)
1036{
1037    tNFC_STATUS status = NFC_STATUS_FAILED;
1038
1039    NFA_TRACE_DEBUG0 ("nfa_dm_act_send_raw_frame ()");
1040
1041    /* If NFC link is activated */
1042    if (  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_POLL_ACTIVE)
1043        ||(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)  )
1044    {
1045        /* If not in exclusive mode, and not activated for LISTEN, then forward raw data to NFA_RW to send */
1046        if (  !(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)
1047            &&!(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)
1048            &&(  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T1T)
1049               ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T2T)
1050               ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T3T)
1051               ||(  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_ISO_DEP)
1052                  &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_ISO_DEP)  )
1053               ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_ISO15693)  )  )
1054        {
1055            /* if RW is checking presence then it will put into pending queue */
1056            status = nfa_rw_send_raw_frame ((BT_HDR*)p_data);
1057        }
1058        else
1059        {
1060            status = NFC_SendData (NFC_RF_CONN_ID, (BT_HDR*) p_data);
1061        }
1062    }
1063
1064    if (status == NFC_STATUS_FAILED)
1065    {
1066        /* free the buffer */
1067        return TRUE;
1068    }
1069    else
1070    {
1071        /* NCI layer will free buffer */
1072        return FALSE;
1073    }
1074}
1075
1076/*******************************************************************************
1077**
1078** Function         nfa_dm_set_p2p_listen_tech
1079**
1080** Description      Notify change of P2P listen technologies to NFA P2P
1081**
1082** Returns          TRUE (message buffer to be freed by caller)
1083**
1084*******************************************************************************/
1085BOOLEAN nfa_dm_set_p2p_listen_tech (tNFA_DM_MSG *p_data)
1086{
1087    NFA_TRACE_DEBUG1 ("nfa_dm_set_p2p_listen_tech ()  tech_mask = %d",
1088                      p_data->set_p2p_listen_tech.tech_mask);
1089
1090    nfa_p2p_update_listen_tech (p_data->set_p2p_listen_tech.tech_mask);
1091    nfa_dm_conn_cback_event_notify (NFA_SET_P2P_LISTEN_TECH_EVT, NULL);
1092
1093    return (TRUE);
1094}
1095
1096/*******************************************************************************
1097**
1098** Function         nfa_dm_act_start_rf_discovery
1099**
1100** Description      Process start RF discovery command
1101**
1102** Returns          TRUE (message buffer to be freed by caller)
1103**
1104*******************************************************************************/
1105BOOLEAN nfa_dm_act_start_rf_discovery (tNFA_DM_MSG *p_data)
1106{
1107    tNFA_CONN_EVT_DATA evt_data;
1108
1109    NFA_TRACE_DEBUG0 ("nfa_dm_act_start_rf_discovery ()");
1110
1111    if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED)
1112    {
1113        evt_data.status = NFA_STATUS_OK;
1114        nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STARTED_EVT, &evt_data);
1115    }
1116    else if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_IDLE)
1117    {
1118        evt_data.status = NFA_STATUS_SEMANTIC_ERROR;
1119        nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STARTED_EVT, &evt_data);
1120    }
1121    else
1122    {
1123        nfa_dm_cb.disc_cb.disc_flags |= (NFA_DM_DISC_FLAGS_ENABLED|NFA_DM_DISC_FLAGS_NOTIFY);
1124        nfa_dm_start_rf_discover ();
1125    }
1126
1127    return (TRUE);
1128}
1129
1130/*******************************************************************************
1131**
1132** Function         nfa_dm_act_stop_rf_discovery
1133**
1134** Description      Process stop RF discovery command
1135**
1136** Returns          TRUE (message buffer to be freed by caller)
1137**
1138*******************************************************************************/
1139BOOLEAN nfa_dm_act_stop_rf_discovery (tNFA_DM_MSG *p_data)
1140{
1141    tNFA_CONN_EVT_DATA evt_data;
1142
1143    NFA_TRACE_DEBUG0 ("nfa_dm_act_stop_rf_discovery ()");
1144
1145    if (!(nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED) ||
1146        (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_IDLE) )
1147    {
1148        nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
1149
1150        /* if discover command has been sent in IDLE state and waiting for response */
1151        if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP)
1152        {
1153            nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
1154        }
1155        else
1156        {
1157            evt_data.status = NFA_STATUS_OK;
1158            nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STOPPED_EVT, &evt_data);
1159        }
1160    }
1161    else
1162    {
1163        nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
1164        nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
1165        nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
1166    }
1167    return (TRUE);
1168}
1169
1170/*******************************************************************************
1171**
1172** Function         nfa_dm_act_set_rf_disc_duration
1173**
1174** Description      Set duration for RF discovery
1175**
1176** Returns          TRUE (message buffer to be freed by caller)
1177**
1178*******************************************************************************/
1179BOOLEAN nfa_dm_act_set_rf_disc_duration (tNFA_DM_MSG *p_data)
1180{
1181    nfa_dm_cb.disc_cb.disc_duration = p_data->disc_duration.rf_disc_dur_ms;
1182    return (TRUE);
1183}
1184
1185/*******************************************************************************
1186**
1187** Function         nfa_dm_act_select
1188**
1189** Description      Process RF select command
1190**
1191** Returns          TRUE (message buffer to be freed by caller)
1192**
1193*******************************************************************************/
1194BOOLEAN nfa_dm_act_select (tNFA_DM_MSG *p_data)
1195{
1196    NFA_TRACE_DEBUG0 ("nfa_dm_act_select ()");
1197
1198    nfa_dm_rf_discover_select (p_data->select.rf_disc_id,
1199                               p_data->select.protocol,
1200                               p_data->select.rf_interface);
1201    return (TRUE);
1202}
1203
1204/*******************************************************************************
1205**
1206** Function         nfa_dm_act_update_rf_params
1207**
1208** Description      Process update RF communication parameters command
1209**
1210** Returns          TRUE (message buffer to be freed by caller)
1211**
1212*******************************************************************************/
1213BOOLEAN nfa_dm_act_update_rf_params (tNFA_DM_MSG *p_data)
1214{
1215    tNFA_CONN_EVT_DATA conn_evt;
1216
1217    NFA_TRACE_DEBUG0 ("nfa_dm_act_update_rf_params ()");
1218
1219    if (NFC_UpdateRFCommParams (&p_data->update_rf_params.params) != NFC_STATUS_OK)
1220    {
1221        conn_evt.status = NFA_STATUS_FAILED;
1222        nfa_dm_conn_cback_event_notify (NFA_UPDATE_RF_PARAM_RESULT_EVT, &conn_evt);
1223    }
1224
1225    return (TRUE);
1226}
1227
1228/*******************************************************************************
1229**
1230** Function         nfa_dm_act_disable_timeout
1231**
1232** Description      timeout on disable process. Shutdown immediately
1233**
1234** Returns          TRUE (message buffer to be freed by caller)
1235**
1236*******************************************************************************/
1237BOOLEAN nfa_dm_act_disable_timeout (tNFA_DM_MSG *p_data)
1238{
1239    tNFA_DM_API_DISABLE disable;
1240
1241    disable.graceful = FALSE;
1242    nfa_dm_disable ((tNFA_DM_MSG *) &disable);
1243    return (TRUE);
1244}
1245
1246/*******************************************************************************
1247**
1248** Function         nfa_dm_act_conn_cback_notify
1249**
1250** Description      Notify app of reader/writer/ndef events
1251**
1252** Returns          nothing
1253**
1254*******************************************************************************/
1255void nfa_dm_act_conn_cback_notify (UINT8 event, tNFA_CONN_EVT_DATA *p_data)
1256{
1257    NFA_TRACE_DEBUG1 ("nfa_dm_act_conn_cback_notify (): event:0x%X", event);
1258
1259    /* Notify event using appropriate CONN_CBACK */
1260    nfa_dm_conn_cback_event_notify (event, p_data);
1261
1262    /* If not in exclusive RF mode, then read NDEF message from tag (if automatic reading is enabled) */
1263    if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE))
1264    {
1265        if (  (event == NFA_NDEF_DETECT_EVT)
1266            &&(nfa_dm_cb.flags & NFA_DM_FLAGS_AUTO_READING_NDEF)  )
1267        {
1268            /* read NDEF message from tag */
1269            if (p_data->ndef_detect.status == NFA_STATUS_OK)
1270            {
1271                NFA_RwReadNDef ();
1272            }
1273            else if (p_data->ndef_detect.status == NFA_STATUS_FAILED)
1274            {
1275                nfa_dm_cb.flags &= ~NFA_DM_FLAGS_AUTO_READING_NDEF;
1276            }
1277            /* ignore NFA_STATUS_BUSY */
1278        }
1279        else if (  (event == NFA_READ_CPLT_EVT)
1280                 &&(nfa_dm_cb.flags & NFA_DM_FLAGS_AUTO_READING_NDEF))
1281        {
1282            /* reading NDEF message is done */
1283            nfa_dm_cb.flags &= ~NFA_DM_FLAGS_AUTO_READING_NDEF;
1284        }
1285    }
1286}
1287
1288/*******************************************************************************
1289**
1290** Function         nfa_dm_act_data_cback
1291**
1292** Description      Processing data from RF link
1293**
1294** Returns          None
1295**
1296*******************************************************************************/
1297static void nfa_dm_act_data_cback (UINT8 conn_id, tNFC_CONN_EVT event, tNFC_CONN *p_data)
1298{
1299    BT_HDR             *p_msg = (BT_HDR *) p_data->data.p_data;
1300    tNFA_CONN_EVT_DATA evt_data;
1301
1302    NFA_TRACE_DEBUG1 ("nfa_dm_act_data_cback (): event = 0x%X", event);
1303
1304    if (event == NFC_DATA_CEVT)
1305    {
1306        if (p_msg)
1307        {
1308            evt_data.data.p_data = (UINT8 *) (p_msg + 1) + p_msg->offset;
1309            evt_data.data.len    = p_msg->len;
1310
1311            nfa_dm_conn_cback_event_notify (NFA_DATA_EVT, &evt_data);
1312
1313            GKI_freebuf (p_msg);
1314        }
1315        else
1316        {
1317            NFA_TRACE_ERROR0 ("nfa_dm_act_data_cback (): received NFC_DATA_CEVT with NULL data pointer");
1318        }
1319    }
1320    else if (event == NFC_DEACTIVATE_CEVT)
1321    {
1322        NFC_SetStaticRfCback (NULL);
1323    }
1324}
1325
1326/*******************************************************************************
1327**
1328** Function         nfa_dm_excl_disc_cback
1329**
1330** Description      Processing event from discovery callback
1331**
1332** Returns          None
1333**
1334*******************************************************************************/
1335static void nfa_dm_excl_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data)
1336{
1337    tNFA_CONN_EVT_DATA evt_data;
1338
1339    NFA_TRACE_DEBUG1 ("nfa_dm_excl_disc_cback (): event:0x%02X", event);
1340
1341    switch (event)
1342    {
1343    case NFA_DM_RF_DISC_START_EVT:
1344        evt_data.status = NFA_STATUS_OK;
1345        nfa_dm_conn_cback_event_notify (NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT, &evt_data);
1346        break;
1347
1348    case NFA_DM_RF_DISC_ACTIVATED_EVT:
1349        if (nfa_dm_cb.disc_cb.activated_tech_mode == NFC_DISCOVERY_TYPE_POLL_A)
1350        {
1351            /* store SEL_RES response */
1352            nfa_dm_cb.disc_cb.activated_sel_res = p_data->activate.rf_tech_param.param.pa.sel_rsp;
1353        }
1354
1355        if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)
1356        {
1357            /* Set data callback to receive raw frame */
1358            NFC_SetStaticRfCback (nfa_dm_act_data_cback);
1359
1360            memset (&(evt_data.activated.params), 0x00, sizeof (tNFA_TAG_PARAMS));
1361            memcpy (&(evt_data.activated.activate_ntf), &(p_data->activate), sizeof (tNFC_ACTIVATE_DEVT));
1362
1363            nfa_dm_conn_cback_event_notify (NFA_ACTIVATED_EVT, &evt_data);
1364        }
1365        else
1366        {
1367            /* holding activation notification until sub-module is ready */
1368            nfa_dm_cb.p_activate_ntf = (UINT8*) GKI_getbuf (sizeof (tNFC_ACTIVATE_DEVT));
1369
1370            if (nfa_dm_cb.p_activate_ntf)
1371            {
1372                memcpy (nfa_dm_cb.p_activate_ntf,
1373                        &(p_data->activate),
1374                        sizeof (tNFC_ACTIVATE_DEVT));
1375
1376                if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
1377                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
1378                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
1379                    ||(  (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_ISO_DEP)
1380                       &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_ISO_DEP) )
1381                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFA_PROTOCOL_ISO15693) )
1382                {
1383                    /* Notify NFA tag sub-system */
1384                    nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data, FALSE);
1385                }
1386                else /* if NFC-DEP, ISO-DEP with frame interface or others */
1387                {
1388                    /* Set data callback to receive raw frame */
1389                    NFC_SetStaticRfCback (nfa_dm_act_data_cback);
1390                    nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
1391                }
1392            }
1393            else
1394            {
1395                /* deactivate and restart RF discovery */
1396                nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
1397            }
1398        }
1399        break;
1400
1401    case NFA_DM_RF_DISC_DEACTIVATED_EVT:
1402
1403        /* clear stored NFCID/UID */
1404        nfa_dm_cb.activated_nfcid_len = 0;
1405
1406        if (nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_NFC_DEP)
1407        {
1408            /* Notify NFA RW sub-systems */
1409            nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_DEACTIVATED_EVT, NULL, FALSE);
1410        }
1411
1412        /* if deactivated as sleep mode */
1413        if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP)
1414            ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP_AF)  )
1415        {
1416            evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_SLEEP;
1417        }
1418        else
1419        {
1420            evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
1421        }
1422
1423        /* notify deactivation to upper layer */
1424        nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
1425
1426        /* clean up SEL_RES response */
1427        nfa_dm_cb.disc_cb.activated_sel_res = 0;
1428        break;
1429
1430    case NFA_DM_RF_DISC_CMD_IDLE_CMPL_EVT:
1431        /* DH initiated deactivation in NFA_DM_RFST_W4_HOST_SELECT */
1432        /* No need to notify NFA RW sub-systems                    */
1433
1434        evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
1435        /* notify deactivation to application */
1436        nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
1437        break;
1438
1439    default:
1440        NFA_TRACE_ERROR0 ("Unexpected event");
1441        break;
1442    }
1443}
1444
1445/*******************************************************************************
1446**
1447** Function         nfa_dm_poll_disc_cback
1448**
1449** Description      Processing event from discovery callback
1450**
1451** Returns          None
1452**
1453*******************************************************************************/
1454static void nfa_dm_poll_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data)
1455{
1456    tNFA_CONN_EVT_DATA evt_data;
1457
1458    NFA_TRACE_DEBUG1 ("nfa_dm_poll_disc_cback (): event:0x%02X", event);
1459
1460    switch (event)
1461    {
1462    case NFA_DM_RF_DISC_START_EVT:
1463        break;
1464
1465    case NFA_DM_RF_DISC_ACTIVATED_EVT:
1466
1467        if (nfa_dm_cb.disc_cb.activated_tech_mode == NFC_DISCOVERY_TYPE_POLL_A)
1468        {
1469            /* store SEL_RES response */
1470            nfa_dm_cb.disc_cb.activated_sel_res = p_data->activate.rf_tech_param.param.pa.sel_rsp;
1471        }
1472
1473        /* holding activation notification until sub-module is ready */
1474        nfa_dm_cb.p_activate_ntf = (UINT8*) GKI_getbuf (sizeof (tNFC_ACTIVATE_DEVT));
1475
1476        if (nfa_dm_cb.p_activate_ntf)
1477        {
1478            memcpy (nfa_dm_cb.p_activate_ntf,
1479                    &(p_data->activate),
1480                    sizeof (tNFC_ACTIVATE_DEVT));
1481
1482            if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
1483                &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
1484            {
1485                /* activate LLCP */
1486                nfa_p2p_activate_llcp (p_data);
1487            }
1488            else if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
1489                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
1490                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
1491                     ||(  (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_ISO_DEP)
1492                        &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_ISO_DEP)  )
1493                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFA_PROTOCOL_ISO15693)  )
1494            {
1495                /* Notify NFA tag sub-system */
1496                nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data, TRUE);
1497            }
1498            else /* if NFC-DEP/ISO-DEP with frame interface */
1499            {
1500                /* Set data callback to receive raw frame */
1501                NFC_SetStaticRfCback (nfa_dm_act_data_cback);
1502                nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
1503            }
1504        }
1505        else
1506        {
1507            /* deactivate and restart RF discovery */
1508            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
1509        }
1510        break;
1511
1512    case NFA_DM_RF_DISC_DEACTIVATED_EVT:
1513
1514        /* clear stored NFCID/UID */
1515        nfa_dm_cb.activated_nfcid_len = 0;
1516
1517        if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
1518            &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
1519        {
1520            /*
1521            ** If LLCP link is not deactivated yet,
1522            ** LLCP will receive deactivation ntf through data callback.
1523            ** NFA P2P will receive callback event from LLCP.
1524            */
1525        }
1526        else
1527        {
1528            /* Notify NFA RW sub-systems */
1529            nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_DEACTIVATED_EVT, NULL, TRUE);
1530        }
1531
1532        /* if NFA sent NFA_ACTIVATED_EVT earlier */
1533        if (nfa_dm_cb.flags & NFA_DM_FLAGS_SEND_DEACTIVATED_EVT)
1534        {
1535            nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SEND_DEACTIVATED_EVT;
1536
1537            /* if deactivated as sleep mode */
1538            if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP)
1539                ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP_AF)  )
1540            {
1541                evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_SLEEP;
1542            }
1543            else
1544            {
1545                evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
1546            }
1547            /* notify deactivation to application */
1548            nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
1549        }
1550
1551        /* clean up SEL_RES response */
1552        nfa_dm_cb.disc_cb.activated_sel_res = 0;
1553
1554        if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_POLLING_ENABLED))
1555        {
1556            /* deregister discovery callback from NFA DM Discovery */
1557            nfa_dm_delete_rf_discover (nfa_dm_cb.poll_disc_handle);
1558            nfa_dm_cb.poll_disc_handle = NFA_HANDLE_INVALID;
1559
1560            /* this is for disable polling */
1561            if (nfa_dm_cb.flags & NFA_DM_FLAGS_SEND_POLL_STOP_EVT)
1562            {
1563                nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SEND_POLL_STOP_EVT;
1564
1565                evt_data.status = NFA_STATUS_OK;
1566                nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
1567            }
1568        }
1569
1570        break;
1571
1572    case NFA_DM_RF_DISC_CMD_IDLE_CMPL_EVT:
1573        /* DH initiated deactivation in NFA_DM_RFST_W4_HOST_SELECT */
1574        /* No need to notify NFA RW sub-systems                    */
1575
1576        /* clear stored NFCID/UID */
1577        nfa_dm_cb.activated_nfcid_len = 0;
1578        /* clean up SEL_RES response */
1579        nfa_dm_cb.disc_cb.activated_sel_res = 0;
1580
1581        evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
1582        /* notify deactivation to application */
1583        nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
1584
1585        if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_POLLING_ENABLED))
1586        {
1587            /* deregister discovery callback from NFA DM Discovery */
1588            nfa_dm_delete_rf_discover (nfa_dm_cb.poll_disc_handle);
1589            nfa_dm_cb.poll_disc_handle = NFA_HANDLE_INVALID;
1590
1591            /* this is for disable polling */
1592            if (nfa_dm_cb.flags & NFA_DM_FLAGS_SEND_POLL_STOP_EVT)
1593            {
1594                nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SEND_POLL_STOP_EVT;
1595
1596                evt_data.status = NFA_STATUS_OK;
1597                nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
1598            }
1599        }
1600        break;
1601    }
1602}
1603
1604/*******************************************************************************
1605**
1606** Function         nfa_dm_notify_activation_status
1607**
1608** Description      Processing activation status from sub-modules
1609**
1610** Returns          None
1611**
1612*******************************************************************************/
1613void nfa_dm_notify_activation_status (tNFA_STATUS status, tNFA_TAG_PARAMS *p_params)
1614{
1615    tNFA_CONN_EVT_DATA  evt_data;
1616    tNFC_RF_TECH_PARAMS *p_tech_params;
1617    UINT8               *p_nfcid = NULL, nfcid_len;
1618
1619    NFA_TRACE_DEBUG1 ("nfa_dm_notify_activation_status (): status:0x%X", status);
1620
1621    if (!nfa_dm_cb.p_activate_ntf)
1622    {
1623        /* this is for NFA P2P listen */
1624        return;
1625    }
1626
1627    if (status == NFA_STATUS_OK)
1628    {
1629        /* notify NFC link activation */
1630        memcpy ( &(evt_data.activated.activate_ntf),
1631                 nfa_dm_cb.p_activate_ntf,
1632                 sizeof (tNFC_ACTIVATE_DEVT));
1633
1634        p_tech_params = &evt_data.activated.activate_ntf.rf_tech_param;
1635
1636        if (p_params)
1637        {
1638            memcpy (&(evt_data.activated.params),
1639                    p_params,
1640                    sizeof (tNFA_TAG_PARAMS));
1641        }
1642
1643        /* get length of NFCID and location */
1644        if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_A)
1645        {
1646            nfcid_len = p_tech_params->param.pa.nfcid1_len;
1647            p_nfcid   = p_tech_params->param.pa.nfcid1;
1648        }
1649        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_B)
1650        {
1651            nfcid_len = NFC_NFCID0_MAX_LEN;
1652            p_nfcid   = p_tech_params->param.pb.nfcid0;
1653        }
1654        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_F)
1655        {
1656            nfcid_len = NFC_NFCID2_LEN;
1657            p_nfcid   = p_tech_params->param.pf.nfcid2;
1658        }
1659        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_ISO15693)
1660        {
1661            nfcid_len = NFC_ISO15693_UID_LEN;
1662            p_nfcid   = p_tech_params->param.pi93.uid;
1663        }
1664        else
1665        {
1666            nfcid_len = 0;
1667        }
1668
1669        /*
1670        ** If not in exlusive RF mode, and
1671        **      P2P activation, then push default NDEF message through SNEP
1672        **      TAG activation, then read NDEF message
1673        */
1674        if (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_NFC_DEP)
1675        {
1676            /*
1677            ** Default NDEF message will be put to NFC Forum defualt SNEP server
1678            ** after receiving NFA_LLCP_ACTIVATED_EVT.
1679            */
1680        }
1681        /* Do not perform NDEF operations on KOVIO */
1682        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_KOVIO)
1683        {
1684            NFA_TRACE_DEBUG1 ("Not an NFC-Forum tag, bypassing NDEF detection", nfa_dm_cb.disc_cb.activated_protocol);
1685        }
1686        else if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE))
1687        {
1688            /*
1689            ** if the same tag is activated then do not perform auto NDEF detection.
1690            ** Application may put a tag into sleep mode and reactivate the same tag.
1691            */
1692
1693            if (  (p_tech_params->mode != nfa_dm_cb.disc_cb.activated_tech_mode)
1694                ||(nfcid_len != nfa_dm_cb.activated_nfcid_len)
1695                ||(memcmp (p_nfcid, nfa_dm_cb.activated_nfcid, nfcid_len)))
1696            {
1697                if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
1698                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
1699                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
1700                    ||(  (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_ISO_DEP)
1701                       &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_ISO_DEP)  )
1702                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFA_PROTOCOL_ISO15693)  )
1703                {
1704                    if (p_nfa_dm_cfg->auto_detect_ndef)
1705                    {
1706                        if (p_nfa_dm_cfg->auto_read_ndef)
1707                        {
1708                            nfa_dm_cb.flags |= NFA_DM_FLAGS_AUTO_READING_NDEF;
1709                        }
1710                        NFA_RwDetectNDef ();
1711                    }
1712                    else if (p_nfa_dm_cfg->auto_read_ndef)
1713                    {
1714                        NFA_RwReadNDef ();
1715                    }
1716                }
1717            }
1718        }
1719
1720        /* store activated tag information */
1721        nfa_dm_cb.activated_nfcid_len = nfcid_len;
1722        if (nfcid_len)
1723            memcpy (nfa_dm_cb.activated_nfcid, p_nfcid, nfcid_len);
1724
1725        nfa_dm_cb.flags |= NFA_DM_FLAGS_SEND_DEACTIVATED_EVT;
1726        nfa_dm_conn_cback_event_notify (NFA_ACTIVATED_EVT, &evt_data);
1727    }
1728    else
1729    {
1730        /* if NFC_DEP, NFA P2P will deactivate */
1731        if (nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_NFC_DEP)
1732        {
1733            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
1734        }
1735    }
1736
1737    GKI_freebuf (nfa_dm_cb.p_activate_ntf);
1738    nfa_dm_cb.p_activate_ntf = NULL;
1739}
1740
1741#if (BT_TRACE_VERBOSE == TRUE)
1742/*******************************************************************************
1743**
1744** Function         nfa_dm_nfc_revt_2_str
1745**
1746** Description      convert nfc revt to string
1747**
1748*******************************************************************************/
1749char *nfa_dm_nfc_revt_2_str (tNFC_RESPONSE_EVT event)
1750{
1751    switch (event) {
1752    case NFC_ENABLE_REVT:
1753        return "NFC_ENABLE_REVT";
1754
1755    case NFC_DISABLE_REVT:
1756        return "NFC_DISABLE_REVT";
1757
1758    case NFC_SET_CONFIG_REVT:
1759        return "NFC_SET_CONFIG_REVT";
1760
1761    case NFC_GET_CONFIG_REVT:
1762        return "NFC_GET_CONFIG_REVT";
1763
1764    case NFC_NFCEE_DISCOVER_REVT:
1765        return "NFC_NFCEE_DISCOVER_REVT";
1766
1767    case NFC_NFCEE_INFO_REVT:
1768        return "NFC_NFCEE_INFO_REVT";
1769
1770    case NFC_NFCEE_MODE_SET_REVT:
1771        return "NFC_NFCEE_MODE_SET_REVT";
1772
1773    case NFC_RF_FIELD_REVT:
1774        return "NFC_RF_FIELD_REVT";
1775
1776    case NFC_EE_ACTION_REVT:
1777        return "NFC_EE_ACTION_REVT";
1778
1779    case NFC_EE_DISCOVER_REQ_REVT:
1780        return "NFC_EE_DISCOVER_REQ_REVT";
1781
1782    case NFC_SET_ROUTING_REVT:
1783        return "NFC_SET_ROUTING_REVT";
1784
1785    case NFC_GET_ROUTING_REVT:
1786        return "NFC_GET_ROUTING_REVT";
1787
1788    case NFC_GEN_ERROR_REVT:
1789        return "NFC_GEN_ERROR_REVT";
1790
1791    case NFC_NFCC_RESTART_REVT:
1792        return "NFC_NFCC_RESTART_REVT";
1793
1794    case NFC_NFCC_TIMEOUT_REVT:
1795        return "NFC_NFCC_TIMEOUT_REVT";
1796
1797    case NFC_NFCC_TRANSPORT_ERR_REVT:
1798        return "NFC_NFCC_TRANSPORT_ERR_REVT";
1799
1800    case NFC_NFCC_POWER_OFF_REVT:
1801        return "NFC_NFCC_POWER_OFF_REVT";
1802
1803    default:
1804        return "unknown revt";
1805        break;
1806    }
1807}
1808#endif /* BT_VERBOSE */
1809