nfa_ce_main.c revision e09fd9c5ce2c1eaef0831d8699a01404bea14894
1/****************************************************************************** 2 * 3 * Copyright (C) 2011-2014 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 20/****************************************************************************** 21 * 22 * This is the main implementation file for the NFA_CE 23 * 24 ******************************************************************************/ 25#include <string.h> 26#include "nfa_ce_api.h" 27#include "nfa_sys.h" 28#include "nfa_ce_int.h" 29#include "nfa_dm_int.h" 30#include "nfa_sys_int.h" 31 32/* NFA_CE control block */ 33tNFA_CE_CB nfa_ce_cb; 34 35/***************************************************************************** 36** Constants and types 37*****************************************************************************/ 38#define NFA_CE_DEFAULT_ISODEP_DISC_MASK (NFA_DM_DISC_MASK_LA_ISO_DEP | NFA_DM_DISC_MASK_LB_ISO_DEP) 39static void nfa_ce_proc_nfcc_power_mode (UINT8 nfcc_power_mode); 40 41static const tNFA_SYS_REG nfa_ce_sys_reg = 42{ 43 NULL, 44 nfa_ce_hdl_event, 45 nfa_ce_sys_disable, 46 nfa_ce_proc_nfcc_power_mode 47}; 48 49/* NFA_CE actions */ 50const tNFA_CE_ACTION nfa_ce_action_tbl[] = 51{ 52 nfa_ce_api_cfg_local_tag, /* NFA_CE_API_CFG_LOCAL_TAG_EVT */ 53 nfa_ce_api_reg_listen, /* NFA_CE_API_REG_LISTEN_EVT */ 54 nfa_ce_api_dereg_listen, /* NFA_CE_API_DEREG_LISTEN_EVT */ 55 nfa_ce_api_cfg_isodep_tech, /* NFA_CE_API_CFG_ISODEP_TECH_EVT*/ 56 nfa_ce_activate_ntf, /* NFA_CE_ACTIVATE_NTF_EVT */ 57 nfa_ce_deactivate_ntf, /* NFA_CE_DEACTIVATE_NTF_EVT */ 58}; 59#define NFA_CE_ACTION_TBL_SIZE (sizeof (nfa_ce_action_tbl) / sizeof (tNFA_CE_ACTION)) 60 61/***************************************************************************** 62** Local function prototypes 63*****************************************************************************/ 64#if (BT_TRACE_VERBOSE == TRUE) 65static char *nfa_ce_evt_2_str (UINT16 event); 66#endif 67 68 69/******************************************************************************* 70** 71** Function nfa_ce_init 72** 73** Description Initialize NFA CE 74** 75** Returns None 76** 77*******************************************************************************/ 78void nfa_ce_init (void) 79{ 80 NFA_TRACE_DEBUG0 ("nfa_ce_init ()"); 81 82 /* initialize control block */ 83 memset (&nfa_ce_cb, 0, sizeof (tNFA_CE_CB)); 84 85 /* Generate a random NFCID for Type-3 NDEF emulation (Type-3 tag NFCID2 must start with 02:FE) */ 86 nfa_ce_t3t_generate_rand_nfcid (nfa_ce_cb.listen_info[NFA_CE_LISTEN_INFO_IDX_NDEF].t3t_nfcid2); 87 nfa_ce_cb.listen_info[NFA_CE_LISTEN_INFO_IDX_NDEF].rf_disc_handle = NFA_HANDLE_INVALID; 88 nfa_ce_cb.isodep_disc_mask = NFA_CE_DEFAULT_ISODEP_DISC_MASK; 89 90 /* register message handler on NFA SYS */ 91 nfa_sys_register ( NFA_ID_CE, &nfa_ce_sys_reg); 92} 93 94/******************************************************************************* 95** 96** Function nfa_ce_sys_disable 97** 98** Description Clean up ce sub-system 99** 100** 101** Returns void 102** 103*******************************************************************************/ 104void nfa_ce_sys_disable (void) 105{ 106 tNFA_CE_LISTEN_INFO *p_info; 107 UINT8 xx; 108 109 NFC_SetStaticRfCback (NULL); 110 111 /* Free scratch buf if any */ 112 nfa_ce_free_scratch_buf (); 113 114 /* Delete discovery handles */ 115 for (xx = 0, p_info = nfa_ce_cb.listen_info; xx < NFA_CE_LISTEN_INFO_MAX; xx++, p_info++) 116 { 117 if ((p_info->flags & NFA_CE_LISTEN_INFO_IN_USE) && (p_info->rf_disc_handle != NFA_HANDLE_INVALID)) 118 { 119 nfa_dm_delete_rf_discover (p_info->rf_disc_handle); 120 p_info->rf_disc_handle = NFA_HANDLE_INVALID; 121 } 122 } 123 124 nfa_sys_deregister (NFA_ID_CE); 125} 126 127/******************************************************************************* 128** 129** Function nfa_ce_proc_nfcc_power_mode 130** 131** Description Processing NFCC power mode changes 132** 133** Returns None 134** 135*******************************************************************************/ 136static void nfa_ce_proc_nfcc_power_mode (UINT8 nfcc_power_mode) 137{ 138 tNFA_CE_CB *p_cb = &nfa_ce_cb; 139 UINT8 listen_info_idx; 140 141 NFA_TRACE_DEBUG1 ("nfa_ce_proc_nfcc_power_mode (): nfcc_power_mode=%d", 142 nfcc_power_mode); 143 144 /* if NFCC power mode is change to full power */ 145 if (nfcc_power_mode == NFA_DM_PWR_MODE_FULL) 146 { 147 nfa_ce_restart_listen_check (); 148 } 149 else 150 { 151 for (listen_info_idx=0; listen_info_idx<NFA_CE_LISTEN_INFO_IDX_INVALID; listen_info_idx++) 152 { 153 /* add RF discovery to DM only if it is not added yet */ 154 if ( (p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_IN_USE) 155 &&(p_cb->listen_info[listen_info_idx].rf_disc_handle != NFA_HANDLE_INVALID)) 156 { 157 nfa_dm_delete_rf_discover (p_cb->listen_info[listen_info_idx].rf_disc_handle); 158 p_cb->listen_info[listen_info_idx].rf_disc_handle = NFA_HANDLE_INVALID; 159 } 160 } 161 } 162 163 nfa_sys_cback_notify_nfcc_power_mode_proc_complete (NFA_ID_CE); 164} 165 166/******************************************************************************* 167** 168** Function nfa_ce_hdl_event 169** 170** Description nfa rw main event handling function. 171** 172** Returns BOOLEAN 173** 174*******************************************************************************/ 175BOOLEAN nfa_ce_hdl_event (BT_HDR *p_msg) 176{ 177 UINT16 act_idx; 178 BOOLEAN freebuf = TRUE; 179 180#if (BT_TRACE_VERBOSE == TRUE) 181 NFA_TRACE_EVENT3 ("nfa_ce_handle_event event: %s (0x%02x), flags: %08x", nfa_ce_evt_2_str (p_msg->event), p_msg->event, nfa_ce_cb.flags); 182#else 183 NFA_TRACE_EVENT2 ("nfa_ce_handle_event event: 0x%x, flags: %08x",p_msg->event, nfa_ce_cb.flags); 184#endif 185 186 /* Get NFA_RW sub-event */ 187 if ((act_idx = (p_msg->event & 0x00FF)) < NFA_CE_ACTION_TBL_SIZE) 188 { 189 freebuf = (*nfa_ce_action_tbl[act_idx]) ((tNFA_CE_MSG*) p_msg); 190 } 191 192 /* if vendor specific event handler is registered */ 193 if (nfa_ce_cb.p_vs_evt_hdlr) 194 { 195 (*nfa_ce_cb.p_vs_evt_hdlr) (p_msg); 196 } 197 198 return freebuf; 199} 200 201#if (BT_TRACE_VERBOSE == TRUE) 202/******************************************************************************* 203** 204** Function nfa_ce_evt_2_str 205** 206** Description convert nfc evt to string 207** 208*******************************************************************************/ 209static char *nfa_ce_evt_2_str (UINT16 event) 210{ 211 switch (event) 212 { 213 case NFA_CE_API_CFG_LOCAL_TAG_EVT: 214 return "NFA_CE_API_CFG_LOCAL_TAG_EVT"; 215 216 case NFA_CE_API_REG_LISTEN_EVT: 217 return "NFA_CE_API_REG_LISTEN_EVT"; 218 219 case NFA_CE_API_DEREG_LISTEN_EVT: 220 return "NFA_CE_API_DEREG_LISTEN_EVT"; 221 222 case NFA_CE_API_CFG_ISODEP_TECH_EVT: 223 return "NFA_CE_API_CFG_ISODEP_TECH_EVT"; 224 225 case NFA_CE_ACTIVATE_NTF_EVT: 226 return "NFA_CE_ACTIVATE_NTF_EVT"; 227 228 case NFA_CE_DEACTIVATE_NTF_EVT: 229 return "NFA_CE_DEACTIVATE_NTF_EVT"; 230 231 default: 232 return "Unknown"; 233 } 234} 235#endif /* BT_TRACE_VERBOSE */ 236