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