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