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