• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 device manager.
22  *
23  ******************************************************************************/
24 #ifndef NFA_DM_INT_H
25 #define NFA_DM_INT_H
26 
27 #include <string>
28 #include "nfa_api.h"
29 #include "nfa_sys.h"
30 #include "nfc_api.h"
31 
32 /*****************************************************************************
33 **  Constants and data types
34 *****************************************************************************/
35 
36 /* DM events */
37 enum {
38   /* device manager local device API events */
39   NFA_DM_API_ENABLE_EVT = NFA_SYS_EVT_START(NFA_ID_DM),
40   NFA_DM_API_DISABLE_EVT,
41   NFA_DM_API_SET_CONFIG_EVT,
42   NFA_DM_API_GET_CONFIG_EVT,
43   NFA_DM_API_REQUEST_EXCL_RF_CTRL_EVT,
44   NFA_DM_API_RELEASE_EXCL_RF_CTRL_EVT,
45   NFA_DM_API_ENABLE_POLLING_EVT,
46   NFA_DM_API_DISABLE_POLLING_EVT,
47   NFA_DM_API_ENABLE_LISTENING_EVT,
48   NFA_DM_API_DISABLE_LISTENING_EVT,
49   NFA_DM_API_RAW_FRAME_EVT,
50   NFA_DM_API_START_RF_DISCOVERY_EVT,
51   NFA_DM_API_STOP_RF_DISCOVERY_EVT,
52   NFA_DM_API_SET_RF_DISC_DURATION_EVT,
53   NFA_DM_API_SELECT_EVT,
54   NFA_DM_API_UPDATE_RF_PARAMS_EVT,
55   NFA_DM_API_DEACTIVATE_EVT,
56   NFA_DM_API_POWER_OFF_SLEEP_EVT,
57   NFA_DM_API_REG_NDEF_HDLR_EVT,
58   NFA_DM_API_DEREG_NDEF_HDLR_EVT,
59   NFA_DM_API_REG_VSC_EVT,
60   NFA_DM_API_SEND_VSC_EVT,
61   NFA_DM_TIMEOUT_DISABLE_EVT,
62   NFA_DM_API_SET_POWER_SUB_STATE_EVT,
63   NFA_DM_API_SEND_RAW_VS_EVT,
64   NFA_DM_API_CHANGE_DISCOVERY_TECH_EVT,
65   NFA_DM_MAX_EVT
66 };
67 
68 /* data type for NFA_DM_API_ENABLE_EVT */
69 typedef struct {
70   NFC_HDR hdr;
71   tNFA_DM_CBACK* p_dm_cback;
72   tNFA_CONN_CBACK* p_conn_cback;
73 } tNFA_DM_API_ENABLE;
74 
75 /* data type for NFA_DM_API_DISABLE_EVT */
76 typedef struct {
77   NFC_HDR hdr;
78   bool graceful;
79 } tNFA_DM_API_DISABLE;
80 
81 /* data type for NFA_DM_API_SET_CONFIG_EVT */
82 typedef struct {
83   NFC_HDR hdr;
84   tNFA_PMID param_id;
85   uint8_t length;
86   uint8_t* p_data;
87 } tNFA_DM_API_SET_CONFIG;
88 
89 /* data type for NFA_DM_API_GET_CONFIG_EVT */
90 typedef struct {
91   NFC_HDR hdr;
92   uint8_t num_ids;
93   tNFA_PMID* p_pmids;
94 } tNFA_DM_API_GET_CONFIG;
95 
96 /* data type for NFA_DM_API_REQ_EXCL_RF_CTRL_EVT */
97 typedef struct {
98   NFC_HDR hdr;
99   tNFA_TECHNOLOGY_MASK poll_mask;
100   tNFA_LISTEN_CFG listen_cfg;
101   tNFA_CONN_CBACK* p_conn_cback;
102   tNFA_NDEF_CBACK* p_ndef_cback;
103 } tNFA_DM_API_REQ_EXCL_RF_CTRL;
104 
105 /* data type for NFA_DM_API_ENABLE_POLLING_EVT */
106 typedef struct {
107   NFC_HDR hdr;
108   tNFA_TECHNOLOGY_MASK poll_mask;
109 } tNFA_DM_API_ENABLE_POLL;
110 
111 /* data type for NFA_DM_API_CHANGE_DISCOVERY_TECH_EVT*/
112 typedef struct {
113   NFC_HDR hdr;
114   bool is_revert_poll;
115   bool is_revert_listen;
116   bool change_default_tech;
117   tNFA_TECHNOLOGY_MASK change_listen_mask;
118   tNFA_TECHNOLOGY_MASK change_poll_mask;
119 } tNFA_DM_API_CHANGE_DISCOVERY_TECH;
120 
121 /* data type for NFA_DM_API_SELECT_EVT */
122 typedef struct {
123   NFC_HDR hdr;
124   uint8_t rf_disc_id;
125   tNFA_NFC_PROTOCOL protocol;
126   tNFA_INTF_TYPE rf_interface;
127 } tNFA_DM_API_SELECT;
128 
129 /* data type for NFA_DM_API_UPDATE_RF_PARAMS_EVT */
130 typedef struct {
131   NFC_HDR hdr;
132   tNFA_RF_COMM_PARAMS params;
133 } tNFA_DM_API_UPDATE_RF_PARAMS;
134 
135 /* data type for NFA_DM_API_DEACTIVATE_EVT */
136 typedef struct {
137   NFC_HDR hdr;
138   bool sleep_mode;
139 } tNFA_DM_API_DEACTIVATE;
140 
141 /* data type for NFA_DM_API_SET_RF_DISC_DURATION_EVT */
142 typedef struct {
143   NFC_HDR hdr;
144   uint16_t rf_disc_dur_ms;
145 } tNFA_DM_API_SET_RF_DISC_DUR;
146 
147 /* data type for NFA_DM_API_REG_NDEF_HDLR_EVT */
148 #define NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE 0x01
149 #define NFA_NDEF_FLAGS_WKT_URI 0x02
150 #define NFA_NDEF_FLAGS_WHOLE_MESSAGE_NOTIFIED 0x04
151 
152 typedef struct {
153   NFC_HDR hdr;
154   tNFA_HANDLE ndef_type_handle;
155   uint8_t flags;
156   tNFA_NDEF_CBACK* p_ndef_cback;
157   tNFA_TNF tnf; /* Type-name field of record-type that was registered. */
158   tNFA_NDEF_URI_ID
159       uri_id; /* URI prefix abrieviation (for NFA_RegisterNDefUriHandler) */
160   uint8_t name_len; /* Length of type name or absolute URI */
161   uint8_t name[1];  /* Type name or absolute URI of record-type that got was
162                        registered.    */
163 } tNFA_DM_API_REG_NDEF_HDLR;
164 
165 /* data type for NFA_DM_API_DEREG_NDEF_HDLR_EVT */
166 typedef struct {
167   NFC_HDR hdr;
168   tNFA_HANDLE ndef_type_handle;
169 } tNFA_DM_API_DEREG_NDEF_HDLR;
170 
171 /* data type for NFA_DM_API_REG_VSC_EVT */
172 typedef struct {
173   NFC_HDR hdr;
174   tNFA_VSC_CBACK* p_cback;
175   bool is_register;
176 } tNFA_DM_API_REG_VSC;
177 
178 /* data type for NFA_DM_API_SEND_VSC_EVT */
179 typedef struct {
180   NFC_HDR hdr;
181   tNFA_VSC_CBACK* p_cback;
182   uint8_t oid;
183   uint8_t cmd_params_len;
184   uint16_t pad; /* add padding to ensure the size is big enough for
185                    offset=NCI_VSC_MSG_HDR_SIZE */
186   uint8_t* p_cmd_params;
187 } tNFA_DM_API_SEND_VSC;
188 
189 /* data type for NFA_DM_API_SET_POWER_SUB_STATE_EVT */
190 typedef struct {
191   NFC_HDR hdr;
192   uint8_t screen_state;
193 } tNFA_DM_API_SET_POWER_SUB_STATE;
194 
195 /* union of all data types */
196 typedef union {
197   /* GKI event buffer header */
198   NFC_HDR hdr;                      /* NFA_DM_API_RAW_FRAME_EVT             */
199                                     /* NFA_DM_API_MULTI_TECH_RSP_EVT        */
200                                     /* NFA_DM_API_RELEASE_EXCL_RF_CTRL      */
201                                     /* NFA_DM_API_DISABLE_POLLING_EVT       */
202                                     /* NFA_DM_API_START_RF_DISCOVERY_EVT    */
203                                     /* NFA_DM_API_STOP_RF_DISCOVERY_EVT     */
204   tNFA_DM_API_ENABLE enable;        /* NFA_DM_API_ENABLE_EVT                */
205   tNFA_DM_API_DISABLE disable;      /* NFA_DM_API_DISABLE_EVT               */
206   tNFA_DM_API_SET_CONFIG setconfig; /* NFA_DM_API_SET_CONFIG_EVT            */
207   tNFA_DM_API_GET_CONFIG getconfig; /* NFA_DM_API_GET_CONFIG_EVT            */
208   tNFA_DM_API_SET_RF_DISC_DUR
209       disc_duration; /* NFA_DM_API_SET_RF_DISC_DURATION_EVT  */
210   tNFA_DM_API_REG_NDEF_HDLR reg_ndef_hdlr; /* NFA_DM_API_REG_NDEF_HDLR_EVT */
211   tNFA_DM_API_DEREG_NDEF_HDLR
212       dereg_ndef_hdlr; /* NFA_DM_API_DEREG_NDEF_HDLR_EVT       */
213   tNFA_DM_API_REQ_EXCL_RF_CTRL
214       req_excl_rf_ctrl; /* NFA_DM_API_REQUEST_EXCL_RF_CTRL      */
215   tNFA_DM_API_ENABLE_POLL enable_poll; /* NFA_DM_API_ENABLE_POLLING_EVT */
216   tNFA_DM_API_SELECT select; /* NFA_DM_API_SELECT_EVT                */
217   tNFA_DM_API_UPDATE_RF_PARAMS
218       update_rf_params;              /* NFA_DM_API_UPDATE_RF_PARAMS_EVT      */
219   tNFA_DM_API_DEACTIVATE deactivate; /* NFA_DM_API_DEACTIVATE_EVT            */
220   tNFA_DM_API_SEND_VSC send_vsc;     /* NFA_DM_API_SEND_VSC_EVT              */
221   tNFA_DM_API_REG_VSC reg_vsc;       /* NFA_DM_API_REG_VSC_EVT               */
222   /* NFA_DM_API_SET_POWER_SUB_STATE_EVT */
223   tNFA_DM_API_SET_POWER_SUB_STATE set_power_state;
224   /* NFA_DM_API_CHANGE_DISCOVERY_TECH_EVT */
225   tNFA_DM_API_CHANGE_DISCOVERY_TECH change_discovery_tech;
226 } tNFA_DM_MSG;
227 
228 /* DM RF discovery state */
229 enum {
230   NFA_DM_RFST_IDLE,               /* idle state                     */
231   NFA_DM_RFST_DISCOVERY,          /* discovery state                */
232   NFA_DM_RFST_W4_ALL_DISCOVERIES, /* wait for all discoveries state */
233   NFA_DM_RFST_W4_HOST_SELECT,     /* wait for host selection state  */
234   NFA_DM_RFST_POLL_ACTIVE,        /* poll mode activated state      */
235   NFA_DM_RFST_LISTEN_ACTIVE,      /* listen mode activated state    */
236   NFA_DM_RFST_LISTEN_SLEEP,       /* listen mode sleep state        */
237   NFA_DM_RFST_LP_LISTEN,          /* Listening in Low Power mode    */
238   NFA_DM_RFST_LP_ACTIVE           /* Activated in Low Power mode    */
239 };
240 typedef uint8_t tNFA_DM_RF_DISC_STATE;
241 
242 /* DM RF discovery state machine event */
243 enum {
244   NFA_DM_RF_DISCOVER_CMD,        /* start RF discovery                    */
245   NFA_DM_RF_DISCOVER_RSP,        /* discover response from NFCC           */
246   NFA_DM_RF_DISCOVER_NTF,        /* RF discovery NTF from NFCC            */
247   NFA_DM_RF_DISCOVER_SELECT_CMD, /* select discovered target              */
248   NFA_DM_RF_DISCOVER_SELECT_RSP, /* select response from NFCC             */
249   NFA_DM_RF_INTF_ACTIVATED_NTF,  /* RF interface activation NTF from NFCC */
250   NFA_DM_RF_DEACTIVATE_CMD,      /* deactivate RF interface               */
251   NFA_DM_RF_DEACTIVATE_RSP,      /* deactivate response from NFCC         */
252   NFA_DM_RF_DEACTIVATE_NTF,      /* deactivate RF interface NTF from NFCC */
253   NFA_DM_WPT_START_CMD,          /* start WPT phase                       */
254   NFA_DM_WPT_START_RSP,          /* start WPT response from NFCC          */
255   NFA_DM_LP_LISTEN_CMD,          /* NFCC is listening in low power mode   */
256   NFA_DM_CORE_INTF_ERROR_NTF,    /* RF interface error NTF from NFCC      */
257   NFA_DM_DISC_SM_MAX_EVENT
258 };
259 typedef uint8_t tNFA_DM_RF_DISC_SM_EVENT;
260 
261 /* DM RF discovery state machine data */
262 typedef struct {
263   uint8_t rf_disc_id;
264   tNFA_NFC_PROTOCOL protocol;
265   tNFA_INTF_TYPE rf_interface;
266 } tNFA_DM_DISC_SELECT_PARAMS;
267 
268 /* DM WPT data */
269 typedef struct {
270   uint8_t power_adj_req;
271   uint8_t wpt_time_int;
272 } tNFA_DM_DISC_WPT_START_PARAMS;
273 
274 typedef union {
275   tNFC_DISCOVER nfc_discover;        /* discovery data from NFCC    */
276   tNFC_DEACT_TYPE deactivate_type;   /* deactivation type           */
277   tNFA_DM_DISC_SELECT_PARAMS select; /* selected target information */
278   tNFA_DM_DISC_WPT_START_PARAMS start_wpt; /*  start power transfer */
279 } tNFA_DM_RF_DISC_DATA;
280 
281 /* Callback event from NFA DM RF Discovery to other NFA sub-modules */
282 enum {
283   NFA_DM_RF_DISC_START_EVT, /* discovery started with protocol, technology and
284                                mode       */
285   NFA_DM_RF_DISC_ACTIVATED_EVT,  /* activated with configured protocol,
286                                     technology and mode    */
287   NFA_DM_RF_DISC_DEACTIVATED_EVT /* deactivated sleep or idle */
288 };
289 typedef uint8_t tNFA_DM_RF_DISC_EVT;
290 
291 /* Combined NFC Technology and protocol bit mask */
292 #define NFA_DM_DISC_MASK_PA_T1T 0x00000001
293 #define NFA_DM_DISC_MASK_PA_T2T 0x00000002
294 #define NFA_DM_DISC_MASK_PA_ISO_DEP 0x00000004
295 #define NFA_DM_DISC_MASK_PA_NFC_DEP 0x00000008
296 #define NFA_DM_DISC_MASK_PB_ISO_DEP 0x00000010
297 #define NFA_DM_DISC_MASK_PF_T3T 0x00000020
298 #define NFA_DM_DISC_MASK_PF_NFC_DEP 0x00000040
299 #define NFA_DM_DISC_MASK_P_T5T 0x00000100
300 #define NFA_DM_DISC_MASK_P_B_PRIME 0x00000200
301 #define NFA_DM_DISC_MASK_P_KOVIO 0x00000400
302 #define NFA_DM_DISC_MASK_PAA_NFC_DEP 0x00000800
303 #define NFA_DM_DISC_MASK_PACM_NFC_DEP 0x00000800
304 #define NFA_DM_DISC_MASK_PFA_NFC_DEP 0x00001000
305 /* Legacy/proprietary/non-NFC Forum protocol (e.g Shanghai transit card) */
306 #define NFA_DM_DISC_MASK_P_LEGACY 0x00002000
307 #define NFA_DM_DISC_MASK_PA_MIFARE 0x00004000
308 #define NFA_DM_DISC_MASK_POLL 0x0000FFFF
309 
310 #define NFA_DM_DISC_MASK_LA_T1T 0x00010000
311 #define NFA_DM_DISC_MASK_LA_T2T 0x00020000
312 #define NFA_DM_DISC_MASK_LA_ISO_DEP 0x00040000
313 #define NFA_DM_DISC_MASK_LA_NFC_DEP 0x00080000
314 #define NFA_DM_DISC_MASK_LB_ISO_DEP 0x00100000
315 #define NFA_DM_DISC_MASK_LF_T3T 0x00200000
316 #define NFA_DM_DISC_MASK_LF_NFC_DEP 0x00400000
317 #define NFA_DM_DISC_MASK_L_ISO15693 0x01000000
318 #define NFA_DM_DISC_MASK_L_B_PRIME 0x02000000
319 #define NFA_DM_DISC_MASK_LACM_NFC_DEP 0x04000000
320 #define NFA_DM_DISC_MASK_LAA_NFC_DEP 0x04000000
321 #define NFA_DM_DISC_MASK_LFA_NFC_DEP 0x08000000
322 #define NFA_DM_DISC_MASK_L_LEGACY 0x10000000
323 #define NFA_DM_DISC_MASK_LISTEN 0xFFFF0000
324 
325 #define NFA_DM_DISC_MASK_NFC_DEP 0x0C481848
326 
327 typedef uint32_t tNFA_DM_DISC_TECH_PROTO_MASK;
328 
329 /* DM RF discovery host ID */
330 #define NFA_DM_DISC_HOST_ID_DH NFC_DH_ID
331 typedef uint8_t tNFA_DM_DISC_HOST_ID;
332 
333 /* DM deactivation callback type */
334 typedef void(tNFA_DISCOVER_CBACK)(tNFA_DM_RF_DISC_EVT event,
335                                   tNFC_DISCOVER* p_data);
336 
337 /* DM RF discovery action flags */
338 /* RF discovery process has been started        */
339 #define NFA_DM_DISC_FLAGS_ENABLED 0x0001
340 /* Stop RF discovery is pending                 */
341 #define NFA_DM_DISC_FLAGS_STOPPING 0x0002
342 /* Disable NFA is pending                       */
343 #define NFA_DM_DISC_FLAGS_DISABLING 0x0004
344 /* Sleep wakeup in progress                     */
345 #define NFA_DM_DISC_FLAGS_CHECKING 0x0008
346 /* Notify sub-module that discovery is starting */
347 #define NFA_DM_DISC_FLAGS_NOTIFY 0x0010
348 /* command has been sent to NFCC in the state   */
349 #define NFA_DM_DISC_FLAGS_W4_RSP 0x0020
350 /* wait for NTF before changing discovery state */
351 #define NFA_DM_DISC_FLAGS_W4_NTF 0x0040
352 
353 typedef uint16_t tNFA_DM_DISC_FLAGS;
354 
355 /* DM Discovery control block */
356 typedef struct {
357   bool in_use;                       /* TRUE if used          */
358   tNFA_DISCOVER_CBACK* p_disc_cback; /* discovery callback    */
359 
360   tNFA_DM_DISC_FLAGS disc_flags; /* specific action flags */
361   tNFA_DM_DISC_HOST_ID host_id;  /* DH or UICC1/UICC2     */
362   tNFA_DM_DISC_TECH_PROTO_MASK
363       requested_disc_mask; /* technology and protocol requested              */
364   tNFA_DM_DISC_TECH_PROTO_MASK
365       selected_disc_mask; /* technology and protocol waiting for activation */
366 } tNFA_DM_DISC_ENTRY;
367 
368 /* polling, raw listen, P2P listen, NDEF CE, 2xVSE, 2xUICC */
369 #define NFA_DM_DISC_NUM_ENTRIES 8
370 
371 /* max discovery technology parameters */
372 #define NFA_DM_MAX_DISC_PARAMS 16
373 
374 /* index of listen mode routing table for technologies */
375 enum {
376   NFA_DM_DISC_LRT_NFC_A,
377   NFA_DM_DISC_LRT_NFC_B,
378   NFA_DM_DISC_LRT_NFC_F,
379   NFA_DM_DISC_LRT_NFC_BP
380 };
381 
382 /* NFA_EE_MAX_TECH_ROUTE. only A, B, F, Bprime are supported by UICC now */
383 #define NFA_DM_MAX_TECH_ROUTE 4
384 
385 /* timeout for waiting deactivation NTF,
386 ** possible delay to send deactivate CMD if all credit wasn't returned
387 ** transport delay (1sec) and max RWT (5sec)
388 */
389 #define NFA_DM_DISC_TIMEOUT_W4_DEACT_NTF (NFC_DEACTIVATE_TIMEOUT * 1000 + 6000)
390 
391 typedef struct {
392   uint16_t disc_duration; /* Disc duration                                    */
393   tNFA_DM_DISC_FLAGS disc_flags;    /* specific action flags */
394   tNFA_DM_RF_DISC_STATE disc_state; /* RF discovery state */
395 
396   tNFC_RF_TECH_N_MODE activated_tech_mode; /* activated technology and mode */
397   uint8_t activated_rf_disc_id;            /* activated RF discovery ID */
398   tNFA_INTF_TYPE activated_rf_interface;   /* activated RF interface */
399   tNFA_NFC_PROTOCOL activated_protocol;    /* activated protocol */
400   tNFA_HANDLE activated_handle;            /* handle of activated sub-module */
401   uint8_t activated_sel_res; /* activated tag's SEL_RES response */
402 
403   tNFA_DM_DISC_ENTRY entry[NFA_DM_DISC_NUM_ENTRIES];
404 
405   tNFA_DM_DISC_ENTRY excl_disc_entry; /* exclusive RF discovery */
406   tNFA_LISTEN_CFG excl_listen_config; /* listen cfg for exclusive-rf mode */
407 
408   uint8_t listen_RT[NFA_DM_MAX_TECH_ROUTE]; /* Host ID for A, B, F, B'
409                                                technology routing*/
410   tNFA_DM_DISC_TECH_PROTO_MASK
411       dm_disc_mask; /* technology and protocol waiting for activation   */
412 
413   TIMER_LIST_ENT tle; /* timer for waiting deactivation NTF               */
414   TIMER_LIST_ENT kovio_tle; /* timer for Kovio bar code tag presence check */
415 
416   bool deact_pending; /* TRUE if deactivate while checking presence       */
417   bool deact_notify_pending; /* TRUE if notify DEACTIVATED EVT while Stop rf
418                                 discovery*/
419   tNFA_DEACTIVATE_TYPE pending_deact_type; /* pending deactivate type */
420 
421 } tNFA_DM_DISC_CB;
422 
423 /* NDEF Type Handler Definitions */
424 /* Default handler entry in ndef_handler table      */
425 #define NFA_NDEF_DEFAULT_HANDLER_IDX 0
426 
427 /* Maximum number of pending SetConfigs */
428 #define NFA_DM_SETCONFIG_PENDING_MAX 32
429 
430 /* NFA_DM flags */
431 /* DM is enabled                                                        */
432 #define NFA_DM_FLAGS_DM_IS_ACTIVE 0x00000001
433 /* Exclusive RF mode is active                                          */
434 #define NFA_DM_FLAGS_EXCL_RF_ACTIVE 0x00000002
435 /* Polling is enabled (while not in exclusive RF mode                   */
436 #define NFA_DM_FLAGS_POLLING_ENABLED 0x00000004
437 /* send poll stop event                                                 */
438 #define NFA_DM_FLAGS_SEND_POLL_STOP_EVT 0x00000008
439 /* auto reading of NDEF in progress                                     */
440 #define NFA_DM_FLAGS_AUTO_READING_NDEF 0x00000010
441 /* NFA_DM_ENABLE_EVT is not reported yet                                */
442 #define NFA_DM_FLAGS_ENABLE_EVT_PEND 0x00000020
443 /* Send NFA_DEACTIVATED_EVT when deactivated                            */
444 #define NFA_DM_FLAGS_SEND_DEACTIVATED_EVT 0x00000040
445 /* NFCC is restoring after back to full power mode                      */
446 #define NFA_DM_FLAGS_NFCC_IS_RESTORING 0x00000100
447 /* NFCC power mode is updating                                          */
448 #define NFA_DM_FLAGS_SETTING_PWR_MODE 0x00000200
449 /* NFA DM is disabling NFC                                              */
450 #define NFA_DM_FLAGS_DM_DISABLING_NFC 0x00000400
451 /* NFA_SendRawFrame() is called since RF activation                     */
452 #define NFA_DM_FLAGS_RAW_FRAME 0x00000800
453 /* NFA_DisableListening() is called and engaged                         */
454 #define NFA_DM_FLAGS_LISTEN_DISABLED 0x00001000
455 /* Power Off Sleep                                                      */
456 #define NFA_DM_FLAGS_POWER_OFF_SLEEP 0x00008000
457 
458 /* Response to WLC RF Interface Extension start is not reported yet     */
459 #define NFA_DM_FLAGS_ENABLE_WLCP_PEND 0x00010000
460 /* WLCP RF Extension is started                                         */
461 #define NFA_DM_FLAGS_RF_EXT_ACTIVE 0x00020000
462 /* WLCP is ready to charge                                              */
463 #define NFA_DM_FLAGS_WLCP_ENABLED 0x00040000
464 
465 /* NFA_ChangeDiscoveryTech() is called and engaged                      */
466 #define NFA_DM_FLAGS_POLL_TECH_CHANGED 0x10000000
467 #define NFA_DM_FLAGS_LISTEN_TECH_CHANGED 0x20000000
468 #define NFA_DM_FLAGS_DEFAULT_TECH_CHANGED 0x40000000
469 /* stored parameters */
470 typedef struct {
471   uint8_t total_duration[NCI_PARAM_LEN_TOTAL_DURATION];
472 
473   uint8_t la_bit_frame_sdd[NCI_PARAM_LEN_LA_BIT_FRAME_SDD];
474   uint8_t la_bit_frame_sdd_len;
475   uint8_t la_platform_config[NCI_PARAM_LEN_LA_PLATFORM_CONFIG];
476   uint8_t la_platform_config_len;
477   uint8_t la_sel_info[NCI_PARAM_LEN_LA_SEL_INFO];
478   uint8_t la_sel_info_len;
479   uint8_t la_nfcid1[NCI_NFCID1_MAX_LEN];
480   uint8_t la_nfcid1_len;
481   uint8_t la_hist_by[NCI_MAX_HIS_BYTES_LEN];
482   uint8_t la_hist_by_len;
483 
484   uint8_t lb_sensb_info[NCI_PARAM_LEN_LB_SENSB_INFO];
485   uint8_t lb_sensb_info_len;
486   uint8_t lb_nfcid0[NCI_PARAM_LEN_LB_NFCID0];
487   uint8_t lb_nfcid0_len;
488   uint8_t lb_appdata[NCI_PARAM_LEN_LB_APPDATA];
489   uint8_t lb_appdata_len;
490   uint8_t lb_adc_fo[NCI_PARAM_LEN_LB_ADC_FO];
491   uint8_t lb_adc_fo_len;
492   uint8_t lb_h_info[NCI_MAX_ATTRIB_LEN];
493   uint8_t lb_h_info_len;
494 
495   uint8_t lf_protocol[NCI_PARAM_LEN_LF_PROTOCOL];
496   uint8_t lf_protocol_len;
497   uint8_t lf_t3t_flags2[NCI_PARAM_LEN_LF_T3T_FLAGS2];
498   uint8_t lf_t3t_flags2_len;
499   uint8_t lf_t3t_pmm[NCI_PARAM_LEN_LF_T3T_PMM];
500   uint8_t lf_t3t_id[NFA_CE_LISTEN_INFO_MAX]
501                    [NCI_PARAM_LEN_LF_T3T_ID(NCI_VERSION_2_0)];
502 
503   uint8_t fwi[NCI_PARAM_LEN_FWI];
504   uint8_t wt[NCI_PARAM_LEN_WT];
505   uint8_t atr_req_gen_bytes[NCI_MAX_GEN_BYTES_LEN];
506   uint8_t atr_req_gen_bytes_len;
507   uint8_t atr_res_gen_bytes[NCI_MAX_GEN_BYTES_LEN];
508   uint8_t atr_res_gen_bytes_len;
509 
510   uint8_t pf_rc[NCI_PARAM_LEN_PF_RC];
511 } tNFA_DM_PARAMS;
512 
513 /*
514 **  NFA_NDEF CHO callback
515 **  It returns TRUE if NDEF is handled by connection handover module.
516 */
517 typedef bool(tNFA_NDEF_CHO_CBACK)(uint32_t ndef_len, uint8_t* p_ndef_data);
518 
519 /* DM control block */
520 typedef struct {
521   uint32_t flags; /* NFA_DM flags (see definitions for NFA_DM_FLAGS_*)    */
522   tNFA_DM_CBACK* p_dm_cback; /* NFA DM callback */
523   TIMER_LIST_ENT tle;
524 
525   /* NFC link connection management */
526   tNFA_CONN_CBACK* p_conn_cback;  /* callback for connection events       */
527   tNFA_TECHNOLOGY_MASK poll_mask; /* technologies being polled            */
528 
529   tNFA_CONN_CBACK* p_excl_conn_cback; /* exclusive RF mode callback           */
530   tNFA_NDEF_CBACK* p_excl_ndef_cback; /* ndef callback for exclusive RF mdoe  */
531 
532   tNFA_NDEF_CHO_CBACK*
533       p_ndef_cho_cback; /* NDEF callback for static connection handover */
534 
535   tNFA_HANDLE poll_disc_handle; /* discovery handle for polling         */
536 
537   uint8_t* p_activate_ntf; /* temp holding activation notfication  */
538   tHAL_API_GET_MAX_NFCEE* get_max_ee;
539 
540   tNFC_RF_TECH_N_MODE
541       activated_tech_mode; /* previous activated technology and mode */
542   uint8_t activated_nfcid[NFC_KOVIO_MAX_LEN]; /* NFCID 0/1/2 or UID of
543                                                  ISO15694/Kovio  */
544   uint8_t activated_nfcid_len; /* length of NFCID or UID               */
545 
546   /* NFC link discovery management */
547   tNFA_DM_DISC_CB disc_cb;
548 
549   /* NDEF Type handler */
550   tNFA_DM_API_REG_NDEF_HDLR*
551       p_ndef_handler[NFA_NDEF_MAX_HANDLERS]; /* ndef handler table */
552 
553   /* stored parameters */
554   tNFA_DM_PARAMS params;
555 
556   /* SetConfig management */
557   uint32_t setcfg_pending_mask; /* Mask of to indicate whether pending
558                                    SET_CONFIGs require NFA_DM_SET_CONFIG_EVT.
559                                    LSB=oldest pending */
560   uint8_t setcfg_pending_num;   /* Number of setconfigs pending */
561 
562   /* NFCC power mode */
563   uint8_t nfcc_pwr_mode; /* NFA_DM_PWR_MODE_FULL or NFA_DM_PWR_MODE_OFF_SLEEP */
564 
565   uint8_t deactivate_cmd_retry_count; /*number of times the deactivation cmd
566                                          sent in case of error scenerio */
567 
568   uint8_t power_state; /* current screen/power  state */
569   uint32_t eDtaMode;   /* To enable the DTA type modes. */
570   uint8_t pending_power_state; /* pending screen state change received in
571                                   LISTEN_ACTIVE state which needs to be applied
572                                   after current transaction is completed*/
573   /* ChangeDiscoveryTech management */
574   tNFA_TECHNOLOGY_MASK change_poll_mask;   /* changing poll tech mask */
575   tNFA_TECHNOLOGY_MASK change_listen_mask; /* changing listen tech mask */
576 } tNFA_DM_CB;
577 
578 /* Internal function prototypes */
579 void nfa_dm_ndef_handle_message(tNFA_STATUS status, uint8_t* p_msg_buf,
580                                 uint32_t len);
581 void nfa_dm_ndef_dereg_all(void);
582 void nfa_dm_act_conn_cback_notify(uint8_t event, tNFA_CONN_EVT_DATA* p_data);
583 void nfa_dm_notify_activation_status(tNFA_STATUS status,
584                                      tNFA_TAG_PARAMS* p_params);
585 
586 bool nfa_dm_act_send_raw_vs(tNFA_DM_MSG* p_data);
587 
588 void nfa_dm_disable_complete(void);
589 
590 /* Internal functions from nfa_rw */
591 void nfa_rw_init(void);
592 void nfa_rw_proc_disc_evt(tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER* p_data,
593                           bool excl_rf_not_active);
594 tNFA_STATUS nfa_rw_send_raw_frame(NFC_HDR* p_data);
595 
596 /* Internal functions from nfa_ce */
597 void nfa_ce_init(void);
598 
599 /* Pointer to compile-time configuration structure */
600 extern tNFA_DM_DISC_FREQ_CFG* p_nfa_dm_rf_disc_freq_cfg;
601 extern tNFA_HCI_CFG* p_nfa_hci_cfg;
602 extern tNFA_DM_CFG* p_nfa_dm_cfg;
603 extern uint8_t* p_nfa_dm_ce_cfg;
604 extern uint8_t* p_nfa_dm_gen_cfg;
605 extern uint8_t nfa_ee_max_ee_cfg;
606 extern tNCI_DISCOVER_MAPS* p_nfa_dm_interface_mapping;
607 extern uint8_t nfa_dm_num_dm_interface_mapping;
608 extern bool nfa_poll_bail_out_mode;
609 
610 void nfa_dm_poll_disc_cback_dta_wrapper(tNFA_DM_RF_DISC_EVT event,
611                                         tNFC_DISCOVER* p_data);
612 extern unsigned char appl_dta_mode_flag;
613 
614 /* NFA device manager control block */
615 extern tNFA_DM_CB nfa_dm_cb;
616 
617 void nfa_dm_init(void);
618 
619 #if (NFC_NFCEE_INCLUDED == TRUE)
620 void nfa_ee_init(void);
621 void nfa_hci_init(void);
622 #else
623 #define nfa_ee_init()
624 #define nfa_hci_init()
625 #endif
626 
627 /* Action function prototypes */
628 bool nfa_dm_enable(tNFA_DM_MSG* p_data);
629 bool nfa_dm_disable(tNFA_DM_MSG* p_data);
630 bool nfa_dm_set_config(tNFA_DM_MSG* p_data);
631 bool nfa_dm_get_config(tNFA_DM_MSG* p_data);
632 bool nfa_dm_act_request_excl_rf_ctrl(tNFA_DM_MSG* p_data);
633 bool nfa_dm_act_release_excl_rf_ctrl(tNFA_DM_MSG* p_data);
634 bool nfa_dm_act_enable_polling(tNFA_DM_MSG* p_data);
635 bool nfa_dm_act_disable_polling(tNFA_DM_MSG* p_data);
636 bool nfa_dm_act_enable_listening(tNFA_DM_MSG* p_data);
637 bool nfa_dm_act_disable_listening(tNFA_DM_MSG* p_data);
638 bool nfa_dm_act_send_raw_frame(tNFA_DM_MSG* p_data);
639 bool nfa_dm_act_start_rf_discovery(tNFA_DM_MSG* p_data);
640 bool nfa_dm_act_stop_rf_discovery(tNFA_DM_MSG* p_data);
641 bool nfa_dm_act_set_rf_disc_duration(tNFA_DM_MSG* p_data);
642 bool nfa_dm_act_select(tNFA_DM_MSG* p_data);
643 bool nfa_dm_act_update_rf_params(tNFA_DM_MSG* p_data);
644 bool nfa_dm_act_deactivate(tNFA_DM_MSG* p_data);
645 bool nfa_dm_act_power_off_sleep(tNFA_DM_MSG* p_data);
646 bool nfa_dm_ndef_reg_hdlr(tNFA_DM_MSG* p_data);
647 bool nfa_dm_ndef_dereg_hdlr(tNFA_DM_MSG* p_data);
648 
649 bool nfa_dm_act_reg_vsc(tNFA_DM_MSG* p_data);
650 bool nfa_dm_act_send_vsc(tNFA_DM_MSG* p_data);
651 uint16_t nfa_dm_act_get_rf_disc_duration();
652 bool nfa_dm_act_disable_timeout(tNFA_DM_MSG* p_data);
653 
654 bool nfa_dm_set_power_sub_state(tNFA_DM_MSG* p_data);
655 
656 void nfa_dm_proc_nfcc_power_mode(uint8_t nfcc_power_mode);
657 
658 /* Main function prototypes */
659 bool nfa_dm_evt_hdlr(NFC_HDR* p_msg);
660 void nfa_dm_sys_enable(void);
661 void nfa_dm_sys_disable(void);
662 tNFA_STATUS nfa_dm_check_set_config(uint8_t tlv_list_len, uint8_t* p_tlv_list,
663                                     bool app_init);
664 
665 void nfa_dm_conn_cback_event_notify(uint8_t event, tNFA_CONN_EVT_DATA* p_data);
666 
667 /* Discovery function prototypes */
668 void nfa_dm_disc_sm_execute(tNFA_DM_RF_DISC_SM_EVENT event,
669                             tNFA_DM_RF_DISC_DATA* p_data);
670 tNFA_HANDLE nfa_dm_add_rf_discover(tNFA_DM_DISC_TECH_PROTO_MASK disc_mask,
671                                    tNFA_DM_DISC_HOST_ID host_id,
672                                    tNFA_DISCOVER_CBACK* p_disc_cback);
673 void nfa_dm_delete_rf_discover(tNFA_HANDLE handle);
674 void nfa_dm_start_excl_discovery(tNFA_TECHNOLOGY_MASK poll_tech_mask,
675                                  tNFA_LISTEN_CFG* p_listen_cfg,
676                                  tNFA_DISCOVER_CBACK* p_disc_cback);
677 void nfa_dm_rel_excl_rf_control_and_notify(void);
678 void nfa_dm_stop_excl_discovery(void);
679 void nfa_dm_disc_new_state(tNFA_DM_RF_DISC_STATE new_state);
680 
681 void nfa_dm_start_rf_discover(void);
682 void nfa_dm_rf_discover_select(uint8_t rf_disc_id, tNFA_NFC_PROTOCOL protocol,
683                                tNFA_INTF_TYPE rf_interface);
684 tNFA_STATUS nfa_dm_rf_deactivate(tNFA_DEACTIVATE_TYPE deactivate_type);
685 bool nfa_dm_is_protocol_supported(tNFA_NFC_PROTOCOL protocol, uint8_t sel_res);
686 bool nfa_dm_is_active(void);
687 tNFC_STATUS nfa_dm_disc_sleep_wakeup(void);
688 tNFC_STATUS nfa_dm_disc_start_kovio_presence_check(void);
689 bool nfa_dm_is_raw_frame_session(void);
690 
691 void nfa_dm_get_tech_route_block(uint8_t* listen_techmask, bool* enable);
692 void nfa_dm_start_wireless_power_transfer(uint8_t power_adj_req,
693                                           uint8_t wpt_time_int);
694 bool nfa_dm_act_change_discovery_tech(tNFA_DM_MSG* p_data);
695 
696 #if (NFC_NFCEE_INCLUDED == FALSE)
697 #define nfa_ee_get_tech_route(ps, ha) \
698   memset(ha, NFC_DH_ID, NFA_DM_MAX_TECH_ROUTE);
699 #endif
700 
701 std::string nfa_dm_nfc_revt_2_str(tNFC_RESPONSE_EVT event);
702 
703 #endif /* NFA_DM_INT_H */
704