1 /****************************************************************************** 2 * 3 * Copyright (C) 2010-2013 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 20 /****************************************************************************** 21 * 22 * This is the 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 */ 45 enum 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 76 typedef 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 */ 82 enum 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 }; 92 typedef UINT8 tNFA_EE_EM_STATE; 93 94 /* NFA EE connection status */ 95 enum 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 }; 103 typedef 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 */ 119 typedef 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) */ 126 typedef 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 } tNFA_EE_ECB; 162 163 /* data type for NFA_EE_API_DISCOVER_EVT */ 164 typedef struct 165 { 166 BT_HDR hdr; 167 tNFA_EE_CBACK *p_cback; 168 } tNFA_EE_API_DISCOVER; 169 170 /* data type for NFA_EE_API_REGISTER_EVT */ 171 typedef struct 172 { 173 BT_HDR hdr; 174 tNFA_EE_CBACK *p_cback; 175 } tNFA_EE_API_REGISTER; 176 177 /* data type for NFA_EE_API_DEREGISTER_EVT */ 178 typedef struct 179 { 180 BT_HDR hdr; 181 int index; 182 } tNFA_EE_API_DEREGISTER; 183 184 /* data type for NFA_EE_API_MODE_SET_EVT */ 185 typedef struct 186 { 187 BT_HDR hdr; 188 tNFA_EE_ECB *p_cb; 189 UINT8 nfcee_id; 190 UINT8 mode; 191 } tNFA_EE_API_MODE_SET; 192 193 /* data type for NFA_EE_API_SET_TECH_CFG_EVT */ 194 typedef struct 195 { 196 BT_HDR hdr; 197 tNFA_EE_ECB *p_cb; 198 UINT8 nfcee_id; 199 tNFA_TECHNOLOGY_MASK technologies_switch_on; 200 tNFA_TECHNOLOGY_MASK technologies_switch_off; 201 tNFA_TECHNOLOGY_MASK technologies_battery_off; 202 } tNFA_EE_API_SET_TECH_CFG; 203 204 /* data type for NFA_EE_API_SET_PROTO_CFG_EVT */ 205 typedef struct 206 { 207 BT_HDR hdr; 208 tNFA_EE_ECB *p_cb; 209 UINT8 nfcee_id; 210 tNFA_PROTOCOL_MASK protocols_switch_on; 211 tNFA_PROTOCOL_MASK protocols_switch_off; 212 tNFA_PROTOCOL_MASK protocols_battery_off; 213 } tNFA_EE_API_SET_PROTO_CFG; 214 215 /* data type for NFA_EE_API_ADD_AID_EVT */ 216 typedef struct 217 { 218 BT_HDR hdr; 219 tNFA_EE_ECB *p_cb; 220 UINT8 nfcee_id; 221 UINT8 aid_len; 222 UINT8 *p_aid; 223 tNFA_EE_PWR_STATE power_state; 224 } tNFA_EE_API_ADD_AID; 225 226 /* data type for NFA_EE_API_REMOVE_AID_EVT */ 227 typedef struct 228 { 229 BT_HDR hdr; 230 UINT8 aid_len; 231 UINT8 *p_aid; 232 } tNFA_EE_API_REMOVE_AID; 233 234 /* data type for NFA_EE_API_CONNECT_EVT */ 235 typedef struct 236 { 237 BT_HDR hdr; 238 tNFA_EE_ECB *p_cb; 239 UINT8 nfcee_id; 240 UINT8 ee_interface; 241 tNFA_EE_CBACK *p_cback; 242 } tNFA_EE_API_CONNECT; 243 244 /* data type for NFA_EE_API_SEND_DATA_EVT */ 245 typedef struct 246 { 247 BT_HDR hdr; 248 tNFA_EE_ECB *p_cb; 249 UINT8 nfcee_id; 250 UINT16 data_len; 251 UINT8 *p_data; 252 } tNFA_EE_API_SEND_DATA; 253 254 /* data type for NFA_EE_API_DISCONNECT_EVT */ 255 typedef struct 256 { 257 BT_HDR hdr; 258 tNFA_EE_ECB *p_cb; 259 UINT8 nfcee_id; 260 } tNFA_EE_API_DISCONNECT; 261 262 263 typedef struct 264 { 265 BT_HDR hdr; 266 tNFC_STATUS status; /* The event status. */ 267 } tNFA_EE_MSG_STATUS; 268 269 /* common data type for internal events with nfa_ee_use_cfg_cb[] as TRUE */ 270 typedef struct 271 { 272 BT_HDR hdr; 273 tNFA_EE_ECB *p_cb; 274 UINT8 nfcee_id; 275 } tNFA_EE_CFG_HDR; 276 277 /* data type for tNFC_RESPONSE_EVT */ 278 typedef struct 279 { 280 BT_HDR hdr; 281 void *p_data; 282 } tNFA_EE_NCI_RESPONSE; 283 284 /* data type for NFA_EE_NCI_DISC_RSP_EVT */ 285 typedef struct 286 { 287 BT_HDR hdr; 288 tNFC_NFCEE_DISCOVER_REVT *p_data; 289 } tNFA_EE_NCI_DISC_RSP; 290 291 /* data type for NFA_EE_NCI_DISC_NTF_EVT */ 292 typedef struct 293 { 294 BT_HDR hdr; 295 tNFC_NFCEE_INFO_REVT *p_data; 296 } tNFA_EE_NCI_DISC_NTF; 297 298 /* data type for NFA_EE_NCI_MODE_SET_RSP_EVT */ 299 typedef struct 300 { 301 BT_HDR hdr; 302 tNFC_NFCEE_MODE_SET_REVT *p_data; 303 } tNFA_EE_NCI_MODE_SET; 304 305 /* data type for NFA_EE_NCI_CONN_EVT and NFA_EE_NCI_DATA_EVT */ 306 typedef struct 307 { 308 BT_HDR hdr; 309 UINT8 conn_id; 310 tNFC_CONN_EVT event; 311 tNFC_CONN *p_data; 312 } tNFA_EE_NCI_CONN; 313 314 /* data type for NFA_EE_NCI_ACTION_NTF_EVT */ 315 typedef struct 316 { 317 BT_HDR hdr; 318 tNFC_EE_ACTION_REVT *p_data; 319 } tNFA_EE_NCI_ACTION; 320 321 /* data type for NFA_EE_NCI_DISC_REQ_NTF_EVT */ 322 typedef struct 323 { 324 BT_HDR hdr; 325 tNFC_EE_DISCOVER_REQ_REVT *p_data; 326 } tNFA_EE_NCI_DISC_REQ; 327 328 /* union of all event data types */ 329 typedef union 330 { 331 BT_HDR hdr; 332 tNFA_EE_CFG_HDR cfg_hdr; 333 tNFA_EE_API_DISCOVER ee_discover; 334 tNFA_EE_API_REGISTER ee_register; 335 tNFA_EE_API_DEREGISTER deregister; 336 tNFA_EE_API_MODE_SET mode_set; 337 tNFA_EE_API_SET_TECH_CFG set_tech; 338 tNFA_EE_API_SET_PROTO_CFG set_proto; 339 tNFA_EE_API_ADD_AID add_aid; 340 tNFA_EE_API_REMOVE_AID rm_aid; 341 tNFA_EE_API_CONNECT connect; 342 tNFA_EE_API_SEND_DATA send_data; 343 tNFA_EE_API_DISCONNECT disconnect; 344 tNFA_EE_NCI_DISC_RSP disc_rsp; 345 tNFA_EE_NCI_DISC_NTF disc_ntf; 346 tNFA_EE_NCI_MODE_SET mode_set_rsp; 347 tNFA_EE_NCI_CONN conn; 348 tNFA_EE_NCI_ACTION act; 349 tNFA_EE_NCI_DISC_REQ disc_req; 350 } tNFA_EE_MSG; 351 352 /* type for State Machine (SM) action functions */ 353 typedef void (*tNFA_EE_SM_ACT)(tNFA_EE_MSG *p_data); 354 355 /***************************************************************************** 356 ** control block 357 *****************************************************************************/ 358 #define NFA_EE_CFGED_UPDATE_NOW 0x80 359 #define NFA_EE_CFGED_OFF_ROUTING 0x40 /* either switch off or battery off is configured */ 360 361 /* the following status are the definition used in ee_cfg_sts */ 362 #define NFA_EE_STS_CHANGED_ROUTING 0x01 363 #define NFA_EE_STS_CHANGED_VS 0x02 364 #define NFA_EE_STS_CHANGED 0x0f 365 #define NFA_EE_STS_PREV 0xf0 366 #define NFA_EE_STS_PREV_ROUTING 0x10 367 368 #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 */ 369 #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 */ 370 #define NFA_EE_FLAG_WAIT_DISCONN 0x04 /* set this bit when gracefully disable with outstanding NCI connections */ 371 typedef UINT8 tNFA_EE_FLAGS; 372 373 374 #define NFA_EE_DISC_STS_ON 0x00 /* NFCEE DISCOVER in progress */ 375 #define NFA_EE_DISC_STS_OFF 0x01 /* disable NFCEE DISCOVER */ 376 #define NFA_EE_DISC_STS_REQ 0x02 /* received NFCEE DISCOVER REQ NTF */ 377 typedef UINT8 tNFA_EE_DISC_STS; 378 379 typedef void (tNFA_EE_ENABLE_DONE_CBACK)(tNFA_EE_DISC_STS status); 380 381 /* NFA EE Management control block */ 382 typedef struct 383 { 384 tNFA_EE_ECB ecb[NFA_EE_NUM_ECBS]; /* control block for DH and NFCEEs */ 385 TIMER_LIST_ENT timer; /* timer to send info to NFCC */ 386 TIMER_LIST_ENT discv_timer; /* timer to end NFCEE discovery */ 387 tNFA_EE_CBACK *p_ee_cback[NFA_EE_MAX_CBACKS];/* to report EE events */ 388 tNFA_EE_CBACK *p_ee_disc_cback; /* to report EE discovery result */ 389 tNFA_EE_ENABLE_DONE_CBACK *p_enable_cback; /* callback to notify on enable done*/ 390 tNFA_EE_EM_STATE em_state; /* NFA-EE state initialized or not */ 391 UINT8 num_ee_expecting; /* number of ee_info still expecting*/ 392 UINT8 cur_ee; /* the number of ee_info in cb */ 393 UINT8 ee_cfged; /* the bit mask of configured ECBs */ 394 UINT8 ee_cfg_sts; /* configuration status */ 395 tNFA_EE_FLAGS ee_flags; /* flags */ 396 } tNFA_EE_CB; 397 398 /***************************************************************************** 399 ** External variables 400 *****************************************************************************/ 401 402 /* NFA EE control block */ 403 #if NFA_DYNAMIC_MEMORY == FALSE 404 extern tNFA_EE_CB nfa_ee_cb; 405 #else 406 extern tNFA_EE_CB *nfa_ee_cb_ptr; 407 #define nfa_ee_cb (*nfa_ee_cb_ptr) 408 #endif 409 410 /***************************************************************************** 411 ** External functions 412 *****************************************************************************/ 413 /* function prototypes - exported from nfa_ee_main.c */ 414 void nfa_ee_sys_enable (void); 415 void nfa_ee_sys_disable (void); 416 417 /* event handler function type */ 418 BOOLEAN nfa_ee_evt_hdlr (BT_HDR *p_msg); 419 void nfa_ee_proc_nfcc_power_mode (UINT8 nfcc_power_mode); 420 #if (NFC_NFCEE_INCLUDED == TRUE) 421 void nfa_ee_get_tech_route (UINT8 power_state, UINT8 *p_handles); 422 #endif 423 void nfa_ee_proc_evt(tNFC_RESPONSE_EVT event, void *p_data); 424 tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id); 425 tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id); 426 UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb); 427 void nfa_ee_restore_one_ecb (tNFA_EE_ECB *p_cb); 428 BOOLEAN nfa_ee_is_active (tNFA_HANDLE nfcee_id); 429 430 /* Action function prototypes - nfa_ee_act.c */ 431 void nfa_ee_api_discover(tNFA_EE_MSG *p_data); 432 void nfa_ee_api_register(tNFA_EE_MSG *p_data); 433 void nfa_ee_api_deregister(tNFA_EE_MSG *p_data); 434 void nfa_ee_api_mode_set(tNFA_EE_MSG *p_data); 435 void nfa_ee_api_set_tech_cfg(tNFA_EE_MSG *p_data); 436 void nfa_ee_api_set_proto_cfg(tNFA_EE_MSG *p_data); 437 void nfa_ee_api_add_aid(tNFA_EE_MSG *p_data); 438 void nfa_ee_api_remove_aid(tNFA_EE_MSG *p_data); 439 void nfa_ee_api_update_now(tNFA_EE_MSG *p_data); 440 void nfa_ee_api_connect(tNFA_EE_MSG *p_data); 441 void nfa_ee_api_send_data(tNFA_EE_MSG *p_data); 442 void nfa_ee_api_disconnect(tNFA_EE_MSG *p_data); 443 void nfa_ee_report_disc_done(BOOLEAN notify_sys); 444 void nfa_ee_nci_disc_rsp(tNFA_EE_MSG *p_data); 445 void nfa_ee_nci_disc_ntf(tNFA_EE_MSG *p_data); 446 void nfa_ee_nci_mode_set_rsp(tNFA_EE_MSG *p_data); 447 void nfa_ee_nci_conn(tNFA_EE_MSG *p_data); 448 void nfa_ee_nci_action_ntf(tNFA_EE_MSG *p_data); 449 void nfa_ee_nci_disc_req_ntf(tNFA_EE_MSG *p_data); 450 void nfa_ee_rout_timeout(tNFA_EE_MSG *p_data); 451 void nfa_ee_discv_timeout(tNFA_EE_MSG *p_data); 452 void nfa_ee_lmrt_to_nfcc(tNFA_EE_MSG *p_data); 453 void nfa_ee_update_rout(void); 454 void nfa_ee_report_event(tNFA_EE_CBACK *p_cback, tNFA_EE_EVT event, tNFA_EE_CBACK_DATA *p_data); 455 tNFA_EE_ECB * nfa_ee_find_aid_offset(UINT8 aid_len, UINT8 *p_aid, int *p_offset, int *p_entry); 456 void nfa_ee_remove_labels(void); 457 int nfa_ee_find_total_aid_len(tNFA_EE_ECB *p_cb, int start_entry); 458 void nfa_ee_start_timer(void); 459 void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback); 460 461 extern void nfa_ee_proc_hci_info_cback (void); 462 void nfa_ee_check_disable (void); 463 BOOLEAN nfa_ee_restore_ntf_done(void); 464 void nfa_ee_check_restore_complete(void); 465 466 467 #endif /* NFA_P2P_INT_H */ 468