nfa_ee_int.h revision 43ef645f118877526ae57eebe35229eb52492211
1/****************************************************************************** 2 * 3 * Copyright (C) 2010-2014 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 20/****************************************************************************** 21 * 22 * This is the private interface file for the NFA EE. 23 * 24 ******************************************************************************/ 25#ifndef NFA_EE_INT_H 26#define NFA_EE_INT_H 27#include "nfc_api.h" 28#include "nfa_ee_api.h" 29#include "nfa_sys.h" 30 31/***************************************************************************** 32** Constants and data types 33*****************************************************************************/ 34#define NFA_EE_DEBUG BT_TRACE_VERBOSE 35#define NFA_EE_NUM_ECBS (NFA_EE_MAX_EE_SUPPORTED+1) /* the number of tNFA_EE_ECBs (for NFCEEs and DH) */ 36#define NFA_EE_CB_4_DH NFA_EE_MAX_EE_SUPPORTED /* The index for DH in nfa_ee_cb.ee_cb[] */ 37#define NFA_EE_INVALID 0xFF 38#define NFA_EE_MAX_TECH_ROUTE 4 /* only A, B, F, Bprime are supported by UICC now */ 39 40#ifndef NFA_EE_AID_CFG_TAG_NAME 41#define NFA_EE_AID_CFG_TAG_NAME 0x4F /* AID */ 42#endif 43 44/* NFA EE events */ 45enum 46{ 47 NFA_EE_API_DISCOVER_EVT = NFA_SYS_EVT_START(NFA_ID_EE), 48 NFA_EE_API_REGISTER_EVT, 49 NFA_EE_API_DEREGISTER_EVT, 50 NFA_EE_API_MODE_SET_EVT, 51 NFA_EE_API_SET_TECH_CFG_EVT, 52 NFA_EE_API_SET_PROTO_CFG_EVT, 53 NFA_EE_API_ADD_AID_EVT, 54 NFA_EE_API_REMOVE_AID_EVT, 55 NFA_EE_API_UPDATE_NOW_EVT, 56 NFA_EE_API_CONNECT_EVT, 57 NFA_EE_API_SEND_DATA_EVT, 58 NFA_EE_API_DISCONNECT_EVT, 59 60 NFA_EE_NCI_DISC_RSP_EVT, 61 NFA_EE_NCI_DISC_NTF_EVT, 62 NFA_EE_NCI_MODE_SET_RSP_EVT, 63 NFA_EE_NCI_CONN_EVT, 64 NFA_EE_NCI_DATA_EVT, 65 NFA_EE_NCI_ACTION_NTF_EVT, 66 NFA_EE_NCI_DISC_REQ_NTF_EVT, 67 68 NFA_EE_ROUT_TIMEOUT_EVT, 69 NFA_EE_DISCV_TIMEOUT_EVT, 70 NFA_EE_CFG_TO_NFCC_EVT, 71 NFA_EE_MAX_EVT 72 73}; 74 75 76typedef UINT16 tNFA_EE_INT_EVT; 77#define NFA_EE_AE_ROUTE 0x80 /* for listen mode routing table*/ 78#define NFA_EE_AE_VS 0x40 79 80 81/* NFA EE Management state */ 82enum 83{ 84 NFA_EE_EM_STATE_INIT = 0, 85 NFA_EE_EM_STATE_INIT_DONE, 86 NFA_EE_EM_STATE_RESTORING, 87 NFA_EE_EM_STATE_DISABLING, 88 NFA_EE_EM_STATE_DISABLED, 89 90 NFA_EE_EM_STATE_MAX 91}; 92typedef UINT8 tNFA_EE_EM_STATE; 93 94/* NFA EE connection status */ 95enum 96{ 97 NFA_EE_CONN_ST_NONE, /* not connected */ 98 NFA_EE_CONN_ST_WAIT, /* connection is initiated; waiting for ack */ 99 NFA_EE_CONN_ST_CONN, /* connected; can send/receive data */ 100 NFA_EE_CONN_ST_DISC, /* disconnecting; waiting for ack */ 101 NFA_EE_CONN_ST_MAX 102}; 103typedef UINT8 tNFA_EE_CONN_ST; 104 105#define NFA_EE_MAX_AID_CFG_LEN (510) 106#define NFA_EE_7816_STATUS_LEN (2) 107 108/* NFA EE control block flags: 109 * use to indicate an API function has changed the configuration of the associated NFCEE 110 * The flags are cleared when the routing table/VS is updated */ 111#define NFA_EE_ECB_FLAGS_TECH 0x02 /* technology routing changed */ 112#define NFA_EE_ECB_FLAGS_PROTO 0x04 /* protocol routing changed */ 113#define NFA_EE_ECB_FLAGS_AID 0x08 /* AID routing changed */ 114#define NFA_EE_ECB_FLAGS_VS 0x10 /* VS changed */ 115#define NFA_EE_ECB_FLAGS_RESTORE 0x20 /* Restore related */ 116#define NFA_EE_ECB_FLAGS_ROUTING 0x0E /* routing flags changed */ 117#define NFA_EE_ECB_FLAGS_DISC_REQ 0x40 /* NFCEE Discover Request NTF is set */ 118#define NFA_EE_ECB_FLAGS_ORDER 0x80 /* DISC_REQ N reported before DISC N */ 119typedef UINT8 tNFA_EE_ECB_FLAGS; 120 121/* part of tNFA_EE_STATUS; for internal use only */ 122#define NFA_EE_STATUS_RESTORING 0x20 /* waiting for restore to full power mode to complete */ 123#define NFA_EE_STATUS_INT_MASK 0x20 /* this bit is in ee_status for internal use only */ 124 125/* NFA-EE information for a particular NFCEE Entity (including DH) */ 126typedef struct 127{ 128 tNFA_TECHNOLOGY_MASK tech_switch_on; /* default routing - technologies switch_on */ 129 tNFA_TECHNOLOGY_MASK tech_switch_off; /* default routing - technologies switch_off */ 130 tNFA_TECHNOLOGY_MASK tech_battery_off; /* default routing - technologies battery_off*/ 131 tNFA_PROTOCOL_MASK proto_switch_on; /* default routing - protocols switch_on */ 132 tNFA_PROTOCOL_MASK proto_switch_off; /* default routing - protocols switch_off */ 133 tNFA_PROTOCOL_MASK proto_battery_off; /* default routing - protocols battery_off */ 134 tNFA_EE_CONN_ST conn_st; /* connection status */ 135 UINT8 conn_id; /* connection id */ 136 tNFA_EE_CBACK *p_ee_cback; /* the callback function */ 137 138 /* Each AID entry has an ssociated aid_len, aid_pwr_cfg, aid_rt_info. 139 * aid_cfg[] contains AID and maybe some other VS information in TLV format 140 * The first T is always NFA_EE_AID_CFG_TAG_NAME, the L is the actual AID length 141 * the aid_len is the total length of all the TLVs associated with this AID entry 142 */ 143 UINT8 aid_len[NFA_EE_MAX_AID_ENTRIES];/* the actual lengths in aid_cfg */ 144 UINT8 aid_pwr_cfg[NFA_EE_MAX_AID_ENTRIES];/* power configuration of this AID entry */ 145 UINT8 aid_rt_info[NFA_EE_MAX_AID_ENTRIES];/* route/vs info for this AID entry */ 146 UINT8 aid_cfg[NFA_EE_MAX_AID_CFG_LEN];/* routing entries based on AID */ 147 UINT8 aid_entries; /* The number of AID entries in aid_cfg */ 148 UINT8 nfcee_id; /* ID for this NFCEE */ 149 UINT8 ee_status; /* The NFCEE status */ 150 UINT8 ee_old_status; /* The NFCEE status before going to low power mode */ 151 tNFA_EE_INTERFACE ee_interface[NFC_MAX_EE_INTERFACE];/* NFCEE supported interface */ 152 tNFA_EE_TLV ee_tlv[NFC_MAX_EE_TLVS];/* the TLV */ 153 UINT8 num_interface; /* number of Target interface */ 154 UINT8 num_tlvs; /* number of TLVs */ 155 tNFA_EE_ECB_FLAGS ecb_flags; /* the flags of this control block */ 156 tNFA_EE_INTERFACE use_interface; /* NFCEE interface used for the connection */ 157 tNFA_NFC_PROTOCOL la_protocol; /* Listen A protocol */ 158 tNFA_NFC_PROTOCOL lb_protocol; /* Listen B protocol */ 159 tNFA_NFC_PROTOCOL lf_protocol; /* Listen F protocol */ 160 tNFA_NFC_PROTOCOL lbp_protocol; /* Listen B' protocol */ 161 UINT8 size_mask; /* the size for technology and protocol routing */ 162 UINT8 size_aid; /* the size for aid routing */ 163} tNFA_EE_ECB; 164 165/* data type for NFA_EE_API_DISCOVER_EVT */ 166typedef struct 167{ 168 BT_HDR hdr; 169 tNFA_EE_CBACK *p_cback; 170} tNFA_EE_API_DISCOVER; 171 172/* data type for NFA_EE_API_REGISTER_EVT */ 173typedef struct 174{ 175 BT_HDR hdr; 176 tNFA_EE_CBACK *p_cback; 177} tNFA_EE_API_REGISTER; 178 179/* data type for NFA_EE_API_DEREGISTER_EVT */ 180typedef struct 181{ 182 BT_HDR hdr; 183 int index; 184} tNFA_EE_API_DEREGISTER; 185 186/* data type for NFA_EE_API_MODE_SET_EVT */ 187typedef struct 188{ 189 BT_HDR hdr; 190 tNFA_EE_ECB *p_cb; 191 UINT8 nfcee_id; 192 UINT8 mode; 193} tNFA_EE_API_MODE_SET; 194 195/* data type for NFA_EE_API_SET_TECH_CFG_EVT */ 196typedef struct 197{ 198 BT_HDR hdr; 199 tNFA_EE_ECB *p_cb; 200 UINT8 nfcee_id; 201 tNFA_TECHNOLOGY_MASK technologies_switch_on; 202 tNFA_TECHNOLOGY_MASK technologies_switch_off; 203 tNFA_TECHNOLOGY_MASK technologies_battery_off; 204} tNFA_EE_API_SET_TECH_CFG; 205 206/* data type for NFA_EE_API_SET_PROTO_CFG_EVT */ 207typedef struct 208{ 209 BT_HDR hdr; 210 tNFA_EE_ECB *p_cb; 211 UINT8 nfcee_id; 212 tNFA_PROTOCOL_MASK protocols_switch_on; 213 tNFA_PROTOCOL_MASK protocols_switch_off; 214 tNFA_PROTOCOL_MASK protocols_battery_off; 215} tNFA_EE_API_SET_PROTO_CFG; 216 217/* data type for NFA_EE_API_ADD_AID_EVT */ 218typedef struct 219{ 220 BT_HDR hdr; 221 tNFA_EE_ECB *p_cb; 222 UINT8 nfcee_id; 223 UINT8 aid_len; 224 UINT8 *p_aid; 225 tNFA_EE_PWR_STATE power_state; 226} tNFA_EE_API_ADD_AID; 227 228/* data type for NFA_EE_API_REMOVE_AID_EVT */ 229typedef struct 230{ 231 BT_HDR hdr; 232 UINT8 aid_len; 233 UINT8 *p_aid; 234} tNFA_EE_API_REMOVE_AID; 235 236/* data type for NFA_EE_API_CONNECT_EVT */ 237typedef struct 238{ 239 BT_HDR hdr; 240 tNFA_EE_ECB *p_cb; 241 UINT8 nfcee_id; 242 UINT8 ee_interface; 243 tNFA_EE_CBACK *p_cback; 244} tNFA_EE_API_CONNECT; 245 246/* data type for NFA_EE_API_SEND_DATA_EVT */ 247typedef struct 248{ 249 BT_HDR hdr; 250 tNFA_EE_ECB *p_cb; 251 UINT8 nfcee_id; 252 UINT16 data_len; 253 UINT8 *p_data; 254} tNFA_EE_API_SEND_DATA; 255 256/* data type for NFA_EE_API_DISCONNECT_EVT */ 257typedef struct 258{ 259 BT_HDR hdr; 260 tNFA_EE_ECB *p_cb; 261 UINT8 nfcee_id; 262} tNFA_EE_API_DISCONNECT; 263 264 265typedef struct 266{ 267 BT_HDR hdr; 268 tNFC_STATUS status; /* The event status. */ 269} tNFA_EE_MSG_STATUS; 270 271/* common data type for internal events with nfa_ee_use_cfg_cb[] as TRUE */ 272typedef struct 273{ 274 BT_HDR hdr; 275 tNFA_EE_ECB *p_cb; 276 UINT8 nfcee_id; 277} tNFA_EE_CFG_HDR; 278 279/* data type for tNFC_RESPONSE_EVT */ 280typedef struct 281{ 282 BT_HDR hdr; 283 void *p_data; 284} tNFA_EE_NCI_RESPONSE; 285 286/* data type for NFA_EE_NCI_DISC_RSP_EVT */ 287typedef struct 288{ 289 BT_HDR hdr; 290 tNFC_NFCEE_DISCOVER_REVT *p_data; 291} tNFA_EE_NCI_DISC_RSP; 292 293/* data type for NFA_EE_NCI_DISC_NTF_EVT */ 294typedef struct 295{ 296 BT_HDR hdr; 297 tNFC_NFCEE_INFO_REVT *p_data; 298} tNFA_EE_NCI_DISC_NTF; 299 300/* data type for NFA_EE_NCI_MODE_SET_RSP_EVT */ 301typedef struct 302{ 303 BT_HDR hdr; 304 tNFC_NFCEE_MODE_SET_REVT *p_data; 305} tNFA_EE_NCI_MODE_SET; 306 307/* data type for NFA_EE_NCI_CONN_EVT and NFA_EE_NCI_DATA_EVT */ 308typedef struct 309{ 310 BT_HDR hdr; 311 UINT8 conn_id; 312 tNFC_CONN_EVT event; 313 tNFC_CONN *p_data; 314} tNFA_EE_NCI_CONN; 315 316/* data type for NFA_EE_NCI_ACTION_NTF_EVT */ 317typedef struct 318{ 319 BT_HDR hdr; 320 tNFC_EE_ACTION_REVT *p_data; 321} tNFA_EE_NCI_ACTION; 322 323/* data type for NFA_EE_NCI_DISC_REQ_NTF_EVT */ 324typedef struct 325{ 326 BT_HDR hdr; 327 tNFC_EE_DISCOVER_REQ_REVT *p_data; 328} tNFA_EE_NCI_DISC_REQ; 329 330/* union of all event data types */ 331typedef union 332{ 333 BT_HDR hdr; 334 tNFA_EE_CFG_HDR cfg_hdr; 335 tNFA_EE_API_DISCOVER ee_discover; 336 tNFA_EE_API_REGISTER ee_register; 337 tNFA_EE_API_DEREGISTER deregister; 338 tNFA_EE_API_MODE_SET mode_set; 339 tNFA_EE_API_SET_TECH_CFG set_tech; 340 tNFA_EE_API_SET_PROTO_CFG set_proto; 341 tNFA_EE_API_ADD_AID add_aid; 342 tNFA_EE_API_REMOVE_AID rm_aid; 343 tNFA_EE_API_CONNECT connect; 344 tNFA_EE_API_SEND_DATA send_data; 345 tNFA_EE_API_DISCONNECT disconnect; 346 tNFA_EE_NCI_DISC_RSP disc_rsp; 347 tNFA_EE_NCI_DISC_NTF disc_ntf; 348 tNFA_EE_NCI_MODE_SET mode_set_rsp; 349 tNFA_EE_NCI_CONN conn; 350 tNFA_EE_NCI_ACTION act; 351 tNFA_EE_NCI_DISC_REQ disc_req; 352} tNFA_EE_MSG; 353 354/* type for State Machine (SM) action functions */ 355typedef void (*tNFA_EE_SM_ACT)(tNFA_EE_MSG *p_data); 356 357/***************************************************************************** 358** control block 359*****************************************************************************/ 360#define NFA_EE_CFGED_UPDATE_NOW 0x80 361#define NFA_EE_CFGED_OFF_ROUTING 0x40 /* either switch off or battery off is configured */ 362 363/* the following status are the definition used in ee_cfg_sts */ 364#define NFA_EE_STS_CHANGED_ROUTING 0x01 365#define NFA_EE_STS_CHANGED_VS 0x02 366#define NFA_EE_STS_CHANGED 0x0f 367#define NFA_EE_STS_PREV 0xf0 368#define NFA_EE_STS_PREV_ROUTING 0x10 369 370#define NFA_EE_FLAG_WAIT_HCI 0x01 /* set this bit when waiting for HCI to finish the initialization process in NFA_EE_EM_STATE_RESTORING */ 371#define NFA_EE_FLAG_NOTIFY_HCI 0x02 /* set this bit when EE needs to notify the p_enable_cback at the end of NFCEE discover process in NFA_EE_EM_STATE_RESTORING */ 372#define NFA_EE_FLAG_WAIT_DISCONN 0x04 /* set this bit when gracefully disable with outstanding NCI connections */ 373typedef UINT8 tNFA_EE_FLAGS; 374 375 376#define NFA_EE_DISC_STS_ON 0x00 /* NFCEE DISCOVER in progress */ 377#define NFA_EE_DISC_STS_OFF 0x01 /* disable NFCEE DISCOVER */ 378#define NFA_EE_DISC_STS_REQ 0x02 /* received NFCEE DISCOVER REQ NTF */ 379typedef UINT8 tNFA_EE_DISC_STS; 380 381typedef void (tNFA_EE_ENABLE_DONE_CBACK)(tNFA_EE_DISC_STS status); 382 383/* NFA EE Management control block */ 384typedef struct 385{ 386 tNFA_EE_ECB ecb[NFA_EE_NUM_ECBS]; /* control block for DH and NFCEEs */ 387 TIMER_LIST_ENT timer; /* timer to send info to NFCC */ 388 TIMER_LIST_ENT discv_timer; /* timer to end NFCEE discovery */ 389 tNFA_EE_CBACK *p_ee_cback[NFA_EE_MAX_CBACKS];/* to report EE events */ 390 tNFA_EE_CBACK *p_ee_disc_cback; /* to report EE discovery result */ 391 tNFA_EE_ENABLE_DONE_CBACK *p_enable_cback; /* callback to notify on enable done*/ 392 tNFA_EE_EM_STATE em_state; /* NFA-EE state initialized or not */ 393 UINT8 num_ee_expecting; /* number of ee_info still expecting*/ 394 UINT8 cur_ee; /* the number of ee_info in cb */ 395 UINT8 ee_cfged; /* the bit mask of configured ECBs */ 396 UINT8 ee_cfg_sts; /* configuration status */ 397 tNFA_EE_FLAGS ee_flags; /* flags */ 398} tNFA_EE_CB; 399 400/***************************************************************************** 401** External variables 402*****************************************************************************/ 403 404/* NFA EE control block */ 405#if NFA_DYNAMIC_MEMORY == FALSE 406extern tNFA_EE_CB nfa_ee_cb; 407#else 408extern tNFA_EE_CB *nfa_ee_cb_ptr; 409#define nfa_ee_cb (*nfa_ee_cb_ptr) 410#endif 411 412/***************************************************************************** 413** External functions 414*****************************************************************************/ 415/* function prototypes - exported from nfa_ee_main.c */ 416void nfa_ee_sys_enable (void); 417void nfa_ee_sys_disable (void); 418 419/* event handler function type */ 420BOOLEAN nfa_ee_evt_hdlr (BT_HDR *p_msg); 421void nfa_ee_proc_nfcc_power_mode (UINT8 nfcc_power_mode); 422#if (NFC_NFCEE_INCLUDED == TRUE) 423void nfa_ee_get_tech_route (UINT8 power_state, UINT8 *p_handles); 424#endif 425void nfa_ee_proc_evt(tNFC_RESPONSE_EVT event, void *p_data); 426tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id); 427tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id); 428UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb); 429void nfa_ee_restore_one_ecb (tNFA_EE_ECB *p_cb); 430BOOLEAN nfa_ee_is_active (tNFA_HANDLE nfcee_id); 431 432/* Action function prototypes - nfa_ee_act.c */ 433void nfa_ee_api_discover(tNFA_EE_MSG *p_data); 434void nfa_ee_api_register(tNFA_EE_MSG *p_data); 435void nfa_ee_api_deregister(tNFA_EE_MSG *p_data); 436void nfa_ee_api_mode_set(tNFA_EE_MSG *p_data); 437void nfa_ee_api_set_tech_cfg(tNFA_EE_MSG *p_data); 438void nfa_ee_api_set_proto_cfg(tNFA_EE_MSG *p_data); 439void nfa_ee_api_add_aid(tNFA_EE_MSG *p_data); 440void nfa_ee_api_remove_aid(tNFA_EE_MSG *p_data); 441void nfa_ee_api_update_now(tNFA_EE_MSG *p_data); 442void nfa_ee_api_connect(tNFA_EE_MSG *p_data); 443void nfa_ee_api_send_data(tNFA_EE_MSG *p_data); 444void nfa_ee_api_disconnect(tNFA_EE_MSG *p_data); 445void nfa_ee_report_disc_done(BOOLEAN notify_sys); 446void nfa_ee_nci_disc_rsp(tNFA_EE_MSG *p_data); 447void nfa_ee_nci_disc_ntf(tNFA_EE_MSG *p_data); 448void nfa_ee_nci_mode_set_rsp(tNFA_EE_MSG *p_data); 449void nfa_ee_nci_conn(tNFA_EE_MSG *p_data); 450void nfa_ee_nci_action_ntf(tNFA_EE_MSG *p_data); 451void nfa_ee_nci_disc_req_ntf(tNFA_EE_MSG *p_data); 452void nfa_ee_rout_timeout(tNFA_EE_MSG *p_data); 453void nfa_ee_discv_timeout(tNFA_EE_MSG *p_data); 454void nfa_ee_lmrt_to_nfcc(tNFA_EE_MSG *p_data); 455void nfa_ee_update_rout(void); 456void nfa_ee_report_event(tNFA_EE_CBACK *p_cback, tNFA_EE_EVT event, tNFA_EE_CBACK_DATA *p_data); 457tNFA_EE_ECB * nfa_ee_find_aid_offset(UINT8 aid_len, UINT8 *p_aid, int *p_offset, int *p_entry); 458void nfa_ee_remove_labels(void); 459int nfa_ee_find_total_aid_len(tNFA_EE_ECB *p_cb, int start_entry); 460void nfa_ee_start_timer(void); 461void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback); 462 463extern void nfa_ee_proc_hci_info_cback (void); 464void nfa_ee_check_disable (void); 465BOOLEAN nfa_ee_restore_ntf_done(void); 466void nfa_ee_check_restore_complete(void); 467 468 469#endif /* NFA_P2P_INT_H */ 470