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