Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2011-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 NFA_CE
     22  *
     23  ******************************************************************************/
     24 #ifndef NFA_CE_INT_H
     25 #define NFA_CE_INT_H
     26 
     27 #include "nfa_api.h"
     28 #include "nfa_ce_api.h"
     29 #include "nfa_dm_int.h"
     30 #include "nfa_sys.h"
     31 #include "nfc_api.h"
     32 
     33 /*****************************************************************************
     34 **  Constants and data types
     35 *****************************************************************************/
     36 
     37 /* CE events */
     38 enum {
     39   /* device manager local device API events */
     40   NFA_CE_API_CFG_LOCAL_TAG_EVT = NFA_SYS_EVT_START(NFA_ID_CE),
     41   NFA_CE_API_REG_LISTEN_EVT,
     42   NFA_CE_API_DEREG_LISTEN_EVT,
     43   NFA_CE_API_CFG_ISODEP_TECH_EVT,
     44   NFA_CE_ACTIVATE_NTF_EVT,
     45   NFA_CE_DEACTIVATE_NTF_EVT
     46 
     47 };
     48 
     49 /* Listen registration types */
     50 enum { NFA_CE_REG_TYPE_ISO_DEP, NFA_CE_REG_TYPE_FELICA, NFA_CE_REG_TYPE_UICC };
     51 typedef uint8_t tNFA_CE_REG_TYPE;
     52 
     53 /* data type for NFA_CE_API_CFG_LOCAL_TAG_EVT */
     54 typedef struct {
     55   NFC_HDR hdr;
     56   tNFA_PROTOCOL_MASK protocol_mask;
     57   uint8_t* p_ndef_data;
     58   uint16_t ndef_cur_size;
     59   uint16_t ndef_max_size;
     60   bool read_only;
     61   uint8_t uid_len;
     62   uint8_t uid[NFA_MAX_UID_LEN];
     63 } tNFA_CE_API_CFG_LOCAL_TAG;
     64 
     65 /* data type for NFA_CE_ACTIVATE_NTF_EVT */
     66 typedef struct {
     67   NFC_HDR hdr;
     68   tNFC_ACTIVATE_DEVT* p_activation_params;
     69 } tNFA_CE_ACTIVATE_NTF;
     70 
     71 /* data type for NFA_CE_API_REG_LISTEN_EVT */
     72 typedef struct {
     73   NFC_HDR hdr;
     74   tNFA_CONN_CBACK* p_conn_cback;
     75 
     76   tNFA_CE_REG_TYPE listen_type;
     77 
     78   /* For registering Felica */
     79   uint16_t system_code;
     80   uint8_t nfcid2[NCI_RF_F_UID_LEN];
     81   uint8_t t3tPmm[NCI_T3T_PMM_LEN];
     82 
     83   /* For registering Type-4 */
     84   uint8_t aid[NFC_MAX_AID_LEN]; /* AID to listen for (For type-4 only)  */
     85   uint8_t aid_len;              /* AID length                           */
     86 
     87   /* For registering UICC */
     88   tNFA_HANDLE ee_handle;
     89   tNFA_TECHNOLOGY_MASK tech_mask;
     90 } tNFA_CE_API_REG_LISTEN;
     91 
     92 /* data type for NFA_CE_API_DEREG_LISTEN_EVT */
     93 typedef struct {
     94   NFC_HDR hdr;
     95   tNFA_HANDLE handle;
     96   uint32_t listen_info;
     97 } tNFA_CE_API_DEREG_LISTEN;
     98 
     99 /* union of all data types */
    100 typedef union {
    101   /* GKI event buffer header */
    102   NFC_HDR hdr;
    103   tNFA_CE_API_CFG_LOCAL_TAG local_tag;
    104   tNFA_CE_API_REG_LISTEN reg_listen;
    105   tNFA_CE_API_DEREG_LISTEN dereg_listen;
    106   tNFA_CE_ACTIVATE_NTF activate_ntf;
    107 } tNFA_CE_MSG;
    108 
    109 /****************************************************************************
    110 ** LISTEN_INFO definitions
    111 *****************************************************************************/
    112 /* Entry 0 is reserved for local NDEF tag */
    113 #define NFA_CE_LISTEN_INFO_IDX_NDEF 0
    114 #define NFA_CE_LISTEN_INFO_IDX_INVALID (NFA_CE_LISTEN_INFO_MAX)
    115 
    116 /* Flags for listen request */
    117 /* LISTEN_INFO entry is in use                                      */
    118 #define NFA_CE_LISTEN_INFO_IN_USE 0x00000001
    119 /* NDEF is read-only                                                */
    120 #define NFC_CE_LISTEN_INFO_READONLY_NDEF 0x00000010
    121 /* App has not been notified of ACTIVATE_EVT yet for this T4T AID   */
    122 #define NFA_CE_LISTEN_INFO_T4T_ACTIVATE_PND 0x00000040
    123 /* This is a listen_info for T4T AID                                */
    124 #define NFA_CE_LISTEN_INFO_T4T_AID 0x00000080
    125 /* App has not been notified of LISTEN_START yet                    */
    126 #define NFA_CE_LISTEN_INFO_START_NTF_PND 0x00000100
    127 /* This is a listen_info for non-NDEF Felica                        */
    128 #define NFA_CE_LISTEN_INFO_FELICA 0x00000200
    129 /* This is a listen_info for UICC                                   */
    130 #define NFA_CE_LISTEN_INFO_UICC 0x00000400
    131 /* App has not been notified of ACTIVATE_EVT yet for this HCEF NFCID2 */
    132 #define NFA_CE_LISTEN_INFO_T3T_ACTIVATE_PND 0x00010000
    133 
    134 /* Structure for listen look up table */
    135 typedef struct {
    136   uint32_t flags;
    137   tNFA_CONN_CBACK* p_conn_cback; /* Callback for this listen request */
    138   tNFA_PROTOCOL_MASK
    139       protocol_mask;          /* Mask of protocols for this listen request    */
    140   tNFA_HANDLE rf_disc_handle; /* RF Discover handle */
    141 
    142   /* For host tag emulation (NFA_CeRegisterVirtualT4tSE and
    143    * NFA_CeRegisterT4tAidOnDH) */
    144   uint8_t t3t_pmm[NCI_T3T_PMM_LEN];
    145   uint8_t t3t_nfcid2[NCI_RF_F_UID_LEN];
    146   uint16_t t3t_system_code; /* Type-3 system code */
    147   uint8_t
    148       t4t_aid_handle; /* Type-4 aid callback handle (from CE_T4tRegisterAID) */
    149 
    150   /* For UICC */
    151   tNFA_HANDLE ee_handle;
    152   tNFA_TECHNOLOGY_MASK tech_mask; /* listening technologies               */
    153   tNFA_DM_DISC_TECH_PROTO_MASK
    154       tech_proto_mask; /* listening technologies and protocols */
    155 } tNFA_CE_LISTEN_INFO;
    156 
    157 /****************************************************************************/
    158 
    159 /* Internal flags for nfa_ce */
    160 /* Deactivation locally initiated by application */
    161 #define NFA_CE_FLAGS_APP_INIT_DEACTIVATION 0x00000001
    162 /* Tag is in listen active or sleep state        */
    163 #define NFA_CE_FLAGS_LISTEN_ACTIVE_SLEEP 0x00000002
    164 typedef uint32_t tNFA_CE_FLAGS;
    165 
    166 /* NFA_CE control block */
    167 typedef struct {
    168   uint8_t* p_scratch_buf; /* Scratch buffer for write requests    */
    169   uint32_t scratch_buf_size;
    170 
    171   tNFC_ACTIVATE_DEVT activation_params; /* Activation params        */
    172   tNFA_CE_FLAGS flags;                  /* internal flags           */
    173   tNFA_CONN_CBACK* p_active_conn_cback; /* Callback of activated CE */
    174 
    175   /* listen_info table (table of listen paramters and app callbacks) */
    176   tNFA_CE_LISTEN_INFO
    177       listen_info[NFA_CE_LISTEN_INFO_MAX]; /* listen info table */
    178   uint8_t idx_cur_active; /* listen_info index for currently activated CE */
    179   uint8_t idx_wild_card;  /* listen_info index for T4T wild card CE */
    180 
    181   tNFA_DM_DISC_TECH_PROTO_MASK
    182       isodep_disc_mask; /* the technology/protocol mask for ISO-DEP */
    183 
    184   /* Local ndef tag info */
    185   uint8_t* p_ndef_data;
    186   uint16_t ndef_cur_size;
    187   uint16_t ndef_max_size;
    188 
    189   tNFA_SYS_EVT_HDLR* p_vs_evt_hdlr; /* VS event handler */
    190 } tNFA_CE_CB;
    191 extern tNFA_CE_CB nfa_ce_cb;
    192 
    193 /* type definition for action functions */
    194 typedef bool (*tNFA_CE_ACTION)(tNFA_CE_MSG* p_data);
    195 
    196 extern uint8_t NFC_GetNCIVersion();
    197 
    198 /* Action function prototypes */
    199 bool nfa_ce_api_cfg_local_tag(tNFA_CE_MSG* p_ce_msg);
    200 bool nfa_ce_api_reg_listen(tNFA_CE_MSG* p_ce_msg);
    201 bool nfa_ce_api_dereg_listen(tNFA_CE_MSG* p_ce_msg);
    202 bool nfa_ce_api_cfg_isodep_tech(tNFA_CE_MSG* p_ce_msg);
    203 bool nfa_ce_activate_ntf(tNFA_CE_MSG* p_ce_msg);
    204 bool nfa_ce_deactivate_ntf(tNFA_CE_MSG* p_ce_msg);
    205 
    206 /* Internal function prototypes */
    207 void nfa_ce_t3t_generate_rand_nfcid(uint8_t nfcid2[NCI_RF_F_UID_LEN]);
    208 bool nfa_ce_hdl_event(NFC_HDR* p_msg);
    209 tNFC_STATUS nfa_ce_set_content(void);
    210 tNFA_STATUS nfa_ce_start_listening(void);
    211 void nfa_ce_remove_listen_info_entry(uint8_t listen_info_idx, bool notify_app);
    212 void nfa_ce_sys_disable(void);
    213 void nfa_ce_free_scratch_buf(void);
    214 bool nfa_ce_restart_listen_check(void);
    215 #endif /* NFA_DM_INT_H */
    216