blob: 8ceeeae05c5bfb420499eec6f6a753c6b2db5e6a [file] [log] [blame]
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001/******************************************************************************
2 *
Evan Chue9629ba2014-01-31 11:18:47 -05003 * Copyright (C) 2009-2014 Broadcom Corporation
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08004 *
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
Martijn Coenen5c65c3a2013-03-27 13:23:36 -070019
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080020/******************************************************************************
21 *
22 * this file contains the main NFC Upper Layer internal definitions and
23 * functions.
24 *
25 ******************************************************************************/
26
27#ifndef NFC_INT_H_
28#define NFC_INT_H_
29
30#include "nfc_target.h"
31#include "gki.h"
32#include "nci_defs.h"
33#include "nfc_api.h"
34#include "btu_api.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/****************************************************************************
41** Internal NFC constants and definitions
42****************************************************************************/
43
44/****************************************************************************
45** NFC_TASK definitions
46****************************************************************************/
47
48/* NFC_TASK event masks */
49#define NFC_TASK_EVT_TRANSPORT_READY EVENT_MASK (APPL_EVT_0)
50
51/* NFC Timer events */
52#define NFC_TTYPE_NCI_WAIT_RSP 0
53#define NFC_TTYPE_WAIT_2_DEACTIVATE 1
54
55#define NFC_TTYPE_LLCP_LINK_MANAGER 100
56#define NFC_TTYPE_LLCP_LINK_INACT 101
57#define NFC_TTYPE_LLCP_DATA_LINK 102
58#define NFC_TTYPE_LLCP_DELAY_FIRST_PDU 103
59#define NFC_TTYPE_RW_T1T_RESPONSE 104
60#define NFC_TTYPE_RW_T2T_RESPONSE 105
61#define NFC_TTYPE_RW_T3T_RESPONSE 106
62#define NFC_TTYPE_RW_T4T_RESPONSE 107
63#define NFC_TTYPE_RW_I93_RESPONSE 108
64#define NFC_TTYPE_CE_T4T_UPDATE 109
Jizhou Liao2ef08962015-06-08 16:11:04 -070065#define NFC_TTYPE_P2P_PRIO_RESPONSE 110 /* added for p2p prio logic timer */
66#define NFC_TTYPE_P2P_PRIO_LOGIC_CLEANUP 111 /* added for p2p prio logic clenaup */
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080067#define NFC_TTYPE_VS_BASE 200
68
69
70/* NFC Task event messages */
71
72enum
73{
74 NFC_STATE_NONE, /* not start up yet */
75 NFC_STATE_W4_HAL_OPEN, /* waiting for HAL_NFC_OPEN_CPLT_EVT */
76 NFC_STATE_CORE_INIT, /* sending CORE_RESET and CORE_INIT */
77 NFC_STATE_W4_POST_INIT_CPLT, /* waiting for HAL_NFC_POST_INIT_CPLT_EVT */
78 NFC_STATE_IDLE, /* normal operation (discovery state) */
79 NFC_STATE_OPEN, /* NFC link is activated */
80 NFC_STATE_CLOSING, /* de-activating */
81 NFC_STATE_W4_HAL_CLOSE, /* waiting for HAL_NFC_POST_INIT_CPLT_EVT */
82 NFC_STATE_NFCC_POWER_OFF_SLEEP /* NFCC is power-off sleep mode */
83};
84typedef UINT8 tNFC_STATE;
85
Jizhou Liao2ef08962015-06-08 16:11:04 -070086/* DM P2P Priority event type */
87enum
88{
89 NFA_DM_P2P_PRIO_RSP = 0x01, /* P2P priority event from RSP */
90 NFA_DM_P2P_PRIO_NTF /* P2P priority event from NTF */
91};
92
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080093/* NFC control block flags */
94#define NFC_FL_DEACTIVATING 0x0001 /* NFC_Deactivate () is called and the NCI cmd is not sent */
95#define NFC_FL_RESTARTING 0x0002 /* restarting NFCC after PowerOffSleep */
96#define NFC_FL_POWER_OFF_SLEEP 0x0004 /* enterning power off sleep mode */
97#define NFC_FL_POWER_CYCLE_NFCC 0x0008 /* Power cycle NFCC */
98#define NFC_FL_CONTROL_REQUESTED 0x0010 /* HAL requested control on NCI command window */
99#define NFC_FL_CONTROL_GRANTED 0x0020 /* NCI command window is on the HAL side */
100#define NFC_FL_DISCOVER_PENDING 0x0040 /* NCI command window is on the HAL side */
Evan Chu1ba9dcc2013-09-10 10:54:20 +0200101#define NFC_FL_HAL_REQUESTED 0x0080 /* NFC_FL_CONTROL_REQUESTED on HAL request */
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800102
103#define NFC_PEND_CONN_ID 0xFE
104#define NFC_CONN_ID_INT_MASK 0xF0
105#define NFC_CONN_ID_ID_MASK NCI_CID_MASK
106#define NFC_CONN_NO_FC 0xFF /* set num_buff to this for no flow control */
107#define NFC_NCI_CONN_NO_FC 0xFF
108
109#if (NFC_RW_ONLY == FALSE)
110/* only allow the entries that the NFCC can support */
111#define NFC_CHECK_MAX_CONN() {if (max > nfc_cb.max_conn) max = nfc_cb.max_conn;}
112#else
113#define NFC_CHECK_MAX_CONN()
114#endif
115
116typedef struct
117{
118 tNFC_CONN_CBACK *p_cback; /* the callback function to receive the data */
119 BUFFER_Q tx_q; /* transmit queue */
120 BUFFER_Q rx_q; /* receive queue */
121 UINT8 id; /* NFCEE ID or RF Discovery ID or NFC_TEST_ID */
122 UINT8 act_protocol; /* the active protocol on this logical connection */
123 UINT8 conn_id; /* the connection id assigned by NFCC for this conn */
124 UINT8 buff_size; /* the max buffer size for this connection. . */
125 UINT8 num_buff; /* num of buffers left to send on this connection */
126 UINT8 init_credits; /* initial num of buffer credits */
127} tNFC_CONN_CB;
128
129/* This data type is for NFC task to send a NCI VS command to NCIT task */
130typedef struct
131{
132 BT_HDR bt_hdr; /* the NCI command */
133 tNFC_VS_CBACK *p_cback; /* the callback function to receive RSP */
134} tNFC_NCI_VS_MSG;
135
136/* This data type is for HAL event */
137typedef struct
138{
139 BT_HDR hdr;
140 UINT8 hal_evt; /* HAL event code */
141 UINT8 status; /* tHAL_NFC_STATUS */
142} tNFC_HAL_EVT_MSG;
143
144#define NFC_RECEIVE_MSGS_OFFSET (10) /* callback function pointer(8; use 8 to be safe + NFC_SAVED_CMD_SIZE(2) */
145
146/* NFCC power state change pending callback */
147typedef void (tNFC_PWR_ST_CBACK) (void);
148#define NFC_SAVED_HDR_SIZE (2)
149/* data Reassembly error (in BT_HDR.layer_specific) */
150#define NFC_RAS_TOO_BIG 0x08
151#define NFC_RAS_FRAGMENTED 0x01
152
153/* NCI command buffer contains a VSC (in BT_HDR.layer_specific) */
154#define NFC_WAIT_RSP_VSC 0x01
155
156/* NFC control blocks */
157typedef struct
158{
159 UINT16 flags; /* NFC control block flags - NFC_FL_* */
160 tNFC_CONN_CB conn_cb[NCI_MAX_CONN_CBS];
161 UINT8 conn_id[NFC_MAX_CONN_ID+1]; /* index: conn_id; conn_id[]: index(1 based) to conn_cb[] */
162 tNFC_DISCOVER_CBACK *p_discv_cback;
163 tNFC_RESPONSE_CBACK *p_resp_cback;
164 tNFC_TEST_CBACK *p_test_cback;
165 tNFC_VS_CBACK *p_vs_cb[NFC_NUM_VS_CBACKS];/* Register for vendor specific events */
166
167#if (NFC_RW_ONLY == FALSE)
168 /* NFCC information at init rsp */
169 UINT32 nci_features; /* the NCI features supported by NFCC */
170 UINT16 max_ce_table; /* the max routing table size */
171 UINT8 max_conn; /* the num of connections supported by NFCC */
172#endif
173 UINT8 nci_ctrl_size; /* Max Control Packet Payload Size */
174
175 const tNCI_DISCOVER_MAPS *p_disc_maps; /* NCI RF Discovery interface mapping */
176 UINT8 vs_interface[NFC_NFCC_MAX_NUM_VS_INTERFACE]; /* the NCI VS interfaces of NFCC */
177 UINT16 nci_interfaces; /* the NCI interfaces of NFCC */
178 UINT8 num_disc_maps; /* number of RF Discovery interface mappings */
179 void *p_disc_pending; /* the parameters associated with pending NFC_DiscoveryStart */
180
181 /* NFC_TASK timer management */
182 TIMER_LIST_Q timer_queue; /* 1-sec timer event queue */
183 TIMER_LIST_Q quick_timer_queue;
184
185 TIMER_LIST_ENT deactivate_timer; /* Timer to wait for deactivation */
186
187 tNFC_STATE nfc_state;
Evan Chua24be4f2013-11-13 15:30:16 -0500188 BOOLEAN reassembly; /* Reassemble fragmented data pkt */
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800189 UINT8 trace_level;
190 UINT8 last_hdr[NFC_SAVED_HDR_SIZE];/* part of last NCI command header */
191 UINT8 last_cmd[NFC_SAVED_CMD_SIZE];/* part of last NCI command payload */
192 void *p_vsc_cback; /* the callback function for last VSC command */
193 BUFFER_Q nci_cmd_xmit_q; /* NCI command queue */
194 TIMER_LIST_ENT nci_wait_rsp_timer; /* Timer for waiting for nci command response */
195 UINT16 nci_wait_rsp_tout; /* NCI command timeout (in ms) */
196 UINT8 nci_wait_rsp; /* layer_specific for last NCI message */
197
198 UINT8 nci_cmd_window; /* Number of commands the controller can accecpt without waiting for response */
199
200 BT_HDR *p_nci_init_rsp; /* holding INIT_RSP until receiving HAL_NFC_POST_INIT_CPLT_EVT */
201 tHAL_NFC_ENTRY *p_hal;
202
203} tNFC_CB;
204
205
206/*****************************************************************************
207** EXTERNAL FUNCTION DECLARATIONS
208*****************************************************************************/
209
210/* Global NFC data */
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800211NFC_API extern tNFC_CB nfc_cb;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800212
213/****************************************************************************
214** Internal nfc functions
215****************************************************************************/
216
217NFC_API extern void nfc_init(void);
218
219/* from nfc_utils.c */
220NFC_API extern tNFC_CONN_CB * nfc_alloc_conn_cb ( tNFC_CONN_CBACK *p_cback);
221NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_conn_id (UINT8 conn_id);
222NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_handle (UINT8 target_handle);
223NFC_API extern void nfc_set_conn_id (tNFC_CONN_CB * p_cb, UINT8 conn_id);
224NFC_API extern void nfc_free_conn_cb (tNFC_CONN_CB *p_cb);
225NFC_API extern void nfc_reset_all_conn_cbs (void);
226NFC_API extern void nfc_data_event (tNFC_CONN_CB * p_cb);
227
228void nfc_ncif_send (BT_HDR *p_buf, BOOLEAN is_cmd);
229extern UINT8 nfc_ncif_send_data (tNFC_CONN_CB *p_cb, BT_HDR *p_data);
230NFC_API extern void nfc_ncif_cmd_timeout (void);
231NFC_API extern void nfc_wait_2_deactivate_timeout (void);
232
233NFC_API extern BOOLEAN nfc_ncif_process_event (BT_HDR *p_msg);
234NFC_API extern void nfc_ncif_check_cmd_queue (BT_HDR *p_buf);
235NFC_API extern void nfc_ncif_send_cmd (BT_HDR *p_buf);
236NFC_API extern void nfc_ncif_proc_discover_ntf (UINT8 *p, UINT16 plen);
237NFC_API extern void nfc_ncif_rf_management_status (tNFC_DISCOVER_EVT event, UINT8 status);
238NFC_API extern void nfc_ncif_set_config_status (UINT8 *p, UINT8 len);
239NFC_API extern void nfc_ncif_event_status (tNFC_RESPONSE_EVT event, UINT8 status);
240NFC_API extern void nfc_ncif_error_status (UINT8 conn_id, UINT8 status);
241NFC_API extern void nfc_ncif_proc_credits(UINT8 *p, UINT16 plen);
242NFC_API extern void nfc_ncif_proc_activate (UINT8 *p, UINT8 len);
243NFC_API extern void nfc_ncif_proc_deactivate (UINT8 status, UINT8 deact_type, BOOLEAN is_ntf);
244#if ((NFC_NFCEE_INCLUDED == TRUE) && (NFC_RW_ONLY == FALSE))
245NFC_API extern void nfc_ncif_proc_ee_action (UINT8 *p, UINT16 plen);
246NFC_API extern void nfc_ncif_proc_ee_discover_req (UINT8 *p, UINT16 plen);
247NFC_API extern void nfc_ncif_proc_get_routing (UINT8 *p, UINT8 len);
248#endif
249NFC_API extern void nfc_ncif_proc_conn_create_rsp (UINT8 *p, UINT16 plen, UINT8 dest_type);
250NFC_API extern void nfc_ncif_report_conn_close_evt (UINT8 conn_id, tNFC_STATUS status);
251NFC_API extern void nfc_ncif_proc_t3t_polling_ntf (UINT8 *p, UINT16 plen);
252NFC_API extern void nfc_ncif_proc_reset_rsp (UINT8 *p, BOOLEAN is_ntf);
253NFC_API extern void nfc_ncif_proc_init_rsp (BT_HDR *p_msg);
254NFC_API extern void nfc_ncif_proc_get_config_rsp (BT_HDR *p_msg);
255NFC_API extern void nfc_ncif_proc_data (BT_HDR *p_msg);
Jizhou Liao2ef08962015-06-08 16:11:04 -0700256NFC_API extern BOOLEAN nfa_dm_p2p_prio_logic(UINT8 event, UINT8 *p, UINT8 ntf_rsp);
257NFC_API extern void nfa_dm_p2p_timer_event ();
258NFC_API extern void nfa_dm_p2p_prio_logic_cleanup ();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800259
260#if (NFC_RW_ONLY == FALSE)
261NFC_API extern void nfc_ncif_proc_rf_field_ntf (UINT8 rf_status);
262#else
263#define nfc_ncif_proc_rf_field_ntf(rf_status)
264#endif
265
266/* From nfc_task.c */
267NFC_API extern UINT32 nfc_task (UINT32 param);
268void nfc_task_shutdown_nfcc (void);
269
270/* From nfc_main.c */
271void nfc_enabled (tNFC_STATUS nfc_status, BT_HDR *p_init_rsp_msg);
272void nfc_set_state (tNFC_STATE nfc_state);
273void nfc_main_flush_cmd_queue (void);
274void nfc_gen_cleanup (void);
275void nfc_main_handle_hal_evt (tNFC_HAL_EVT_MSG *p_msg);
276
277/* Timer functions */
278void nfc_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
279UINT32 nfc_remaining_time (TIMER_LIST_ENT *p_tle);
280void nfc_stop_timer (TIMER_LIST_ENT *p_tle);
281
282void nfc_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
283void nfc_stop_quick_timer (TIMER_LIST_ENT *p_tle);
284void nfc_process_quick_timer_evt (void);
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700285
286
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800287#ifdef __cplusplus
288}
289#endif
290
291#endif /* NFC_INT_H_ */