1 /****************************************************************************** 2 * 3 * Copyright (C) 2003-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 is the private interface file for the NFA DTA 22 * 23 ******************************************************************************/ 24 #ifndef NFA_DTA_INT_H 25 #define NFA_DTA_INT_H 26 27 #include "nfa_dta_api.h" 28 #include "nfa_sys.h" 29 #include "nfa_sys_int.h" 30 #include "nfc_api.h" 31 #include "rw_api.h" 32 #include "ce_api.h" 33 34 #if (NFA_DTA_INCLUDED == TRUE) 35 36 /***************************************************************************** 37 ** DTA definitions 38 *****************************************************************************/ 39 #define NFA_DTA_PATTERN_NUMBER_INVALID 0xFFFF 40 41 #define NFA_DTA_DISCOVER_PARAMS_MAX 6 42 43 #define NDEF_WKT_TEXT_HDR_LEN 7 /* Header length for long NDEF text message */ 44 #define NFA_DTA_T3T_WRITE_NDEF_SIZE 192 /* Size of NDEF message for T3T write-tests ([DTA] $5.5.6) */ 45 #define NFA_DTA_T3T_LISTEN_SYSTEMCODE 0xBABE /* System code to use for T3T Listen mode tests */ 46 47 #define NFA_PROTOCOL_RANK_INVALID 0xFF /* Maximum protocol preference rank */ 48 49 #define NFA_DTA_SCRATCH_BUF_SIZE T3T_MSG_BLOCKSIZE 50 51 #ifndef NFA_DTA_DEFAULT_CO_OUT_DSAP 52 #define NFA_DTA_DEFAULT_CO_OUT_DSAP 0x10 /* Default SAP[LT,CO-OUT-DEST] if SDP was not performed to get SAP from the LT */ 53 #endif 54 55 /***************************************************************************** 56 * DTA state machine definitions 57 *****************************************************************************/ 58 59 typedef struct { 60 BOOLEAN tp_continue; /* NFA_DTA_CFG_TP_CONTINUE */ 61 tNFA_DTA_FL_POLL_LISTEN poll_listen; /* NFA_DTA_CFG_POLL_LISTEN */ 62 BOOLEAN t4at_nfcdep_priority; /* NFA_DTA_CFG_T4AT_NFCDEP_PRIORITY */ 63 BOOLEAN reactivation; /* NFA_DTA_CFG_REACTIVATION */ 64 UINT16 total_duration; /* NFA_DTA_CFG_TOTAL_DURATION */ 65 BOOLEAN enable_dta_llcp; /* NFA_DTA_CFG_LLCP */ 66 tNFA_DTA_SNEP_MODE dta_snep_mode; /* NFA_DTA_CFG_SNEP */ 67 tNFA_DTA_EMVCO_PCD_MODE emvco_pcd_mode; /* NFA_DTA_CFG_EMVCO_PCD */ 68 } tNFA_DTA_CONFIG; 69 70 /***************************************************************************** 71 * DTA state machine definitions 72 *****************************************************************************/ 73 /* DTA events */ 74 enum 75 { 76 /* device manager local device API events */ 77 NFA_DTA_API_ENABLE_EVT = NFA_SYS_EVT_START (NFA_ID_DTA), 78 NFA_DTA_API_DISABLE_EVT, 79 NFA_DTA_API_CONFIG_EVT, 80 NFA_DTA_API_START_EVT, 81 NFA_DTA_API_STOP_EVT, 82 NFA_DTA_ACTIVATE_EVT, 83 NFA_DTA_DEACTIVATE_EVT, 84 NFA_DTA_DATA_CBACK_EVT, 85 86 NFA_DTA_MAX_EVT 87 }; 88 89 90 /* data type for NFA_DTA_API_ENABLE_EVT */ 91 typedef struct 92 { 93 BT_HDR hdr; 94 BOOLEAN auto_start; 95 tNFA_DTA_CBACK *p_cback; 96 } tNFA_DTA_API_ENABLE; 97 98 /* data type for NFA_DTA_API_START_EVT */ 99 typedef struct 100 { 101 BT_HDR hdr; 102 UINT8 pattern_number; 103 UINT8 tlv_len; 104 UINT8 *p_tlv_params; 105 } tNFA_DTA_API_START; 106 107 /* data type for NFA_DTA_API_CONFIG */ 108 typedef struct 109 { 110 BT_HDR hdr; 111 tNFA_DTA_CFG_ITEM item; 112 tNFA_DTA_CFG cfg_data; 113 } tNFA_DTA_API_CONFIG; 114 115 /* data type for NFA_DTA_DATA_CBACK_EVT */ 116 typedef struct 117 { 118 UINT8 event; 119 tRW_DATA data; 120 } tNFA_DTA_RW_DATA; 121 122 typedef struct 123 { 124 UINT8 event; 125 tCE_DATA data; 126 } tNFA_DTA_CE_DATA; 127 128 typedef struct 129 { 130 tNFC_CONN_EVT event; 131 tNFC_CONN data; 132 } tNFA_DTA_NFCDEP_DATA; 133 134 135 enum 136 { 137 NFA_DTA_LLCP_CONNECT_CO_ECHO_OUT, 138 NFA_DTA_LLCP_DISCONNECT_CO_ECHO_OUT 139 }; 140 typedef UINT8 tNFA_DTA_LLCP_EVT; 141 142 enum 143 { 144 NFA_DTA_RW_DATA, 145 NFA_DTA_CE_DATA, 146 NFA_DTA_NFCDEP_DATA, 147 NFA_DTA_LLCP_DATA 148 }; 149 150 typedef UINT8 tNFA_DTA_DATA_TYPE; 151 152 typedef struct 153 { 154 BT_HDR hdr; 155 tNFA_DTA_DATA_TYPE type; 156 union 157 { 158 tNFA_DTA_RW_DATA rw; 159 tNFA_DTA_CE_DATA ce; 160 tNFA_DTA_NFCDEP_DATA nfcdep; 161 tNFA_DTA_LLCP_EVT llcp_evt; 162 } data; 163 } tNFA_DTA_DATA_CBACK; 164 165 /* All API message type */ 166 typedef union 167 { 168 BT_HDR hdr; 169 tNFA_DTA_API_ENABLE enable; 170 tNFA_DTA_API_CONFIG cfg; 171 tNFA_DTA_API_START start; 172 tNFA_DTA_DATA_CBACK data_cback; 173 }tNFA_DTA_MSG; 174 175 176 177 /* DTA states */ 178 enum 179 { 180 NFA_DTA_ST_IDLE, 181 NFA_DTA_ST_DISCOVER, /* Polling/Listening */ 182 NFA_DTA_ST_ACTIVATED /* Activated, listen mode */ 183 }; 184 typedef UINT8 tNFA_DTA_STATE; 185 186 /* DTA Substates (while in ACTIVATED state) - substate enumerations are found in protocol-specific files (nfa_dta_XXX.c) */ 187 #define NFA_DTA_SST_IDLE 0 188 typedef UINT8 tNFA_DTA_SUBSTATE; 189 190 /* DTA discovery states */ 191 enum 192 { 193 NFA_DTA_DISC_STATE_IDLE, 194 NFA_DTA_DISC_STATE_DISCOVERY, 195 NFA_DTA_DISC_STATE_POLL_ACTIVE, 196 NFA_DTA_DISC_STATE_W4_ALL_DISCOVERIES, 197 NFA_DTA_DISC_STATE_W4_HOST_SELECT, 198 NFA_DTA_DISC_STATE_LISTEN_ACTIVE, 199 NFA_DTA_DISC_STATE_LISTEN_SLEEP, 200 NFA_DTA_DISC_STATE_MAX 201 }; 202 203 /***************************************************************************** 204 * DTA control block definitions 205 *****************************************************************************/ 206 207 /* NDEF buffer definitions */ 208 enum { 209 NFA_DTA_BUF_READ, /* Buffer for RW Read requests */ 210 NFA_DTA_BUF_WRITE, /* Buffer for RW Write requests */ 211 NFA_DTA_BUF_MAX 212 }; 213 214 typedef struct { 215 UINT8 *p_data; 216 UINT32 max_size; 217 UINT32 cur_size; 218 UINT32 offset; /* current read/write offset */ 219 } tNFA_DTA_BUF_CB; 220 221 222 /* T4T listen mode test application */ 223 enum { 224 NFA_DTA_T4T_CE_APP_NONE, /* Not selected */ 225 NFA_DTA_T4T_CE_APP_LOOPBACK, /* loopback test applicaiton */ 226 NFA_DTA_T4T_CE_APP_PROP /* propretary test application */ 227 }; 228 229 /* DTA test step command */ 230 typedef tNFC_STATUS (*tNFA_DTA_CMD_FCN) (void *); 231 232 /* dta control block flags */ 233 #define NFA_DTA_FL_ENABLED 0x00000001 /* DTA is enabled */ 234 #define NFA_DTA_FL_AUTOSTART 0x00000002 /* Automatically start discovery when NFC is enabled */ 235 #define NFA_DTA_FL_STOPPING 0x00000004 /* DTA is stopping (NFA_DtaStop called) */ 236 #define NFA_DTA_FL_DISABLING 0x00000008 /* DTA is being disabled (NFA_DtaDisable called) */ 237 #define NFA_DTA_FL_T4T_DESELECT_DEACT 0x00000010 /* T4T/NFCDEP is deactivating to IDLE (need to DESELECT first) */ 238 239 /* DTA control block */ 240 typedef struct { 241 UINT32 dta_flags; /* dta_flags must be first item in structure (statically intialized to 0 on startup) */ 242 243 /* Configuration */ 244 tNFA_DTA_CONFIG cfg; 245 246 /* DTA State Machine */ 247 tNFA_DTA_STATE state; 248 tNFA_DTA_SUBSTATE substate; /* Current protocol-specific sub-state */ 249 tNFA_DTA_CBACK *p_cback; /* Applicatation for DTA event notification */ 250 251 /* DTA test parameters */ 252 UINT32 pattern_number; 253 UINT32 pattern_number_old; 254 255 /* Discovery Parameters */ 256 UINT8 disc_state; 257 UINT8 disc_params_num; 258 tNFC_DISCOVER_PARAMS disc_params[NFA_DTA_DISCOVER_PARAMS_MAX]; 259 260 /* Activation parameters */ 261 tNFC_ACTIVATE_DEVT activate_params; 262 UINT8 cur_protocol_rank; /* perference ranking of currently discovered protocol */ 263 264 tRW_CBACK *p_rw_cback; 265 tCE_CBACK *p_ce_cback; 266 267 TIMER_LIST_ENT protocol_timer; /* timer for the activated protocol if needed */ 268 269 UINT8 t4t_ce_app; /* T4T listen mode test application */ 270 tCE_T4T_AID_HANDLE t4t_dta_aid_hdl; /* T4T registration handle for proprietary dta aid */ 271 tCE_T4T_AID_HANDLE t4t_prop_aid_hdl; /* T4T registration handle for proprietary aid */ 272 UINT8 nfc_dep_wt; 273 274 BOOLEAN llcp_cl_more_to_read; /* TRUE if there is more to read in llcp cl link*/ 275 BOOLEAN llcp_co_more_to_read; /* TRUE if there is more to read in llcp recieve window*/ 276 BOOLEAN llcp_is_initiator; /* TURE if IUT is LLCP initiator */ 277 UINT16 llcp_local_link_miu; /* link MIU of IUT */ 278 UINT16 llcp_remote_link_miu; /* link MIU of LT */ 279 280 UINT8 llcp_cl_in_local_sap; /* SAP of IUT-CL-IN-DEST */ 281 UINT8 llcp_cl_out_local_sap; /* SAP of IUT-CL-OUT-SRC */ 282 UINT8 llcp_cl_out_remote_sap; /* SAP of LT-CL-OUT-DEST */ 283 284 UINT8 llcp_co_in_local_sap; /* SAP of IUT-CO-IN-DEST */ 285 UINT8 llcp_co_in_remote_sap; /* SAP of LT-CO-IN-SRC */ 286 UINT8 llcp_co_out_local_sap; /* SAP of IUT-CO-OUT-SRC */ 287 UINT8 llcp_co_out_remote_sap; /* SAP of LT-CO-OUT-DEST */ 288 289 UINT16 llcp_co_out_remote_miu; /* MIU of LT-CO-OUT-DEST */ 290 UINT8 llcp_co_out_remote_rw; /* RW of LT-CO-OUT-DEST */ 291 292 #define NFA_DTA_LLCP_FLAGS_CO_OUT_CONNECTING 0x01 /* establishing outbound on connection-oriented */ 293 #define NFA_DTA_LLCP_FLAGS_CO_OUT_CONNECTED 0x02 /* established outbound on connection-oriented */ 294 295 UINT8 llcp_flags; /* internal flags for LLCP echo test */ 296 UINT8 llcp_sdp_tid; /* transaction ID for SDP */ 297 298 TIMER_LIST_ENT llcp_cl_echo_timer; /* timer for the connectionless echo test application */ 299 TIMER_LIST_ENT llcp_co_echo_timer; /* timer for the connection-oriented echo test application */ 300 BUFFER_Q llcp_cl_buffer; /* buffer for the connectionless echo test application */ 301 BUFFER_Q llcp_co_buffer; /* buffer for the connection-oriented echo test application*/ 302 303 tNFA_HANDLE snep_server_handle; 304 tNFA_HANDLE snep_server_conn_handle; 305 tNFA_HANDLE snep_client_handle; 306 307 #define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_DEFAULT_SERVER 0x01 308 #define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_EXTENDED_SERVER 0x02 309 #define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_PUT_SHORT_NDEF 0x04 310 #define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_PUT_LONG_NDEF 0x08 311 #define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_GET 0x10 312 313 UINT8 snep_client_test_flags; 314 315 UINT8 *p_snep_short_ndef; 316 UINT32 snep_short_ndef_size; 317 UINT8 *p_snep_long_ndef; 318 UINT32 snep_long_ndef_size; 319 320 /* DTA buffer for NDEF read/write */ 321 tNFA_DTA_BUF_CB buf_cb[NFA_DTA_BUF_MAX]; 322 UINT32 ndef_size; /* Size of NDEF message from NDEF detection */ 323 324 /* Scratch buffer for miscelaneous use */ 325 UINT8 scratch_buf[NFA_DTA_SCRATCH_BUF_SIZE]; 326 327 /* DTA Test command table */ 328 tNFA_DTA_CMD_FCN *p_cur_cmd_tbl; /* Current table of commands for current test */ 329 UINT8 cur_cmd_idx; 330 } tNFA_DTA_CB; 331 extern tNFA_DTA_CB nfa_dta_cb; 332 333 /* NFA_SYS info for DTA */ 334 extern const tNFA_SYS_REG nfa_dta_sys_reg; 335 336 /* DTA startup setconfig parameters */ 337 extern UINT8 *p_nfa_dta_start_up_cfg; 338 extern UINT8 nfa_dta_start_up_cfg_len; 339 340 /***************************************************************************** 341 * DTA internal funciton protoytpes 342 *****************************************************************************/ 343 /* Internal function prototypes */ 344 void nfa_dta_deactivate (UINT8 deactivate_type); 345 void nfa_dta_shutdown (void); 346 void nfa_dta_discover_start (void); 347 348 /* nfa_sys handler for DTA */ 349 BOOLEAN nfa_dta_evt_hdlr (BT_HDR *p_msg); 350 void nfa_dta_sys_disable (void); 351 352 /* State machine action functions */ 353 BOOLEAN nfa_dta_enable (tNFA_DTA_MSG *p_data); 354 BOOLEAN nfa_dta_disable (tNFA_DTA_MSG *p_data); 355 BOOLEAN nfa_dta_config (tNFA_DTA_MSG *p_data); 356 BOOLEAN nfa_dta_start (tNFA_DTA_MSG *p_data); 357 BOOLEAN nfa_dta_handle_deact (tNFA_DTA_MSG *p_data); 358 BOOLEAN nfa_dta_stop (tNFA_DTA_MSG *p_data); 359 BOOLEAN nfa_dta_run_test (tNFA_DTA_MSG *p_data); 360 BOOLEAN nfa_dta_proc_data (tNFA_DTA_MSG *p_msg_data); 361 362 /* Utility functions */ 363 void nfa_dta_test_set_state (tNFA_DTA_STATE state); 364 void nfa_dta_test_set_substate (tNFA_DTA_SUBSTATE substate); 365 void nfa_dta_free_ndef_buf (UINT8 ndef_idx); 366 UINT8 *nfa_dta_realloc_buf (UINT8 ndef_idx, UINT32 size); 367 void nfa_dta_t3t_nfcid_rand (UINT8 nfcid2[NCI_RF_F_UID_LEN]); 368 369 /* Test function entry points (in nfa_dta_XXX.c) */ 370 void nfa_dta_nfcdep_poll_test_start (void); 371 void nfa_dta_nfcdep_proc_data (tNFC_CONN_EVT event, tNFC_CONN *p_data); 372 void nfa_dta_t1t_poll_test_start (void); 373 void nfa_dta_t2t_poll_test_start (void); 374 void nfa_dta_t3t_poll_test_start (void); 375 void nfa_dta_t4t_poll_test_start (void); 376 377 void nfa_dta_nfcdep_listen_test_start (void); 378 void nfa_dta_t3t_listen_test_start (void); 379 void nfa_dta_t4t_listen_test_start (void); 380 381 void nfa_dta_t1t_rw_cback (UINT8 event, tRW_DATA *p_data); 382 void nfa_dta_t2t_rw_cback (UINT8 event, tRW_DATA *p_data); 383 void nfa_dta_t3t_rw_cback (UINT8 event, tRW_DATA *p_data); 384 void nfa_dta_t4t_rw_cback (UINT8 event, tRW_DATA *p_data); 385 386 void nfa_dta_t3t_ce_cback (UINT8 event, tCE_DATA *p_data); 387 void nfa_dta_t4t_ce_cback (UINT8 event, tCE_DATA *p_data); 388 389 void nfa_dta_ce_cback (UINT8 event, tCE_DATA *p_ce_data); 390 391 void nfa_dta_t4t_register_apps (void); 392 void nfa_dta_t4t_deregister_apps (void); 393 394 void nfa_dta_llcp_register_echo (void); 395 void nfa_dta_llcp_deregister_echo (void); 396 void nfa_dta_llcp_activate_link (void); 397 void nfa_dta_llcp_connect_co_echo_out (void); 398 void nfa_dta_llcp_disconnect_co_echo_out (void); 399 400 void nfa_dta_snep_register (void); 401 void nfa_dta_snep_deregister (void); 402 void nfa_dta_snep_mode (tNFA_DTA_SNEP_MODE mode); 403 404 void nfa_dta_emvco_pcd_config_nfcc (BOOLEAN enable); 405 void nfa_dta_emvco_pcd_start (void); 406 void nfa_dta_emvco_pcd_cback (UINT8 event, tRW_DATA *p_data); 407 408 extern UINT8 *p_nfa_dta_brcm_start_up_cfg; 409 extern UINT8 nfa_dta_brcm_start_up_cfg_len; 410 extern UINT8 *p_nfa_dta_start_up_vsc_cfg; 411 412 #endif /* (NFA_DTA_INCLUDED == TRUE) */ 413 #endif /* NFA_DTA_INT_H */ 414 415