nfc_int.h revision 45faad0ff5deeb0c676356345d99398cc4ab695a
1/****************************************************************************
2**
3**  File:        nfc_int.h
4**
5**  Description:   this file contains the main NFC Upper Layer
6**                 internal definitions and functions.
7**
8**  Copyright (c) 2009-2012, Broadcom Corp., All Rights Reserved.
9**  Broadcom Bluetooth Core. Proprietary and confidential.
10****************************************************************************/
11
12#ifndef NFC_INT_H_
13#define NFC_INT_H_
14
15
16#include "nfc_target.h"
17#include "gki.h"
18#include "nci_defs.h"
19#include "nfc_api.h"
20#include "btu_api.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/****************************************************************************
27** Internal NFC constants and definitions
28****************************************************************************/
29
30/****************************************************************************
31** NFC_TASK definitions
32****************************************************************************/
33
34/* NFC_TASK event masks */
35#define NFC_TASK_EVT_TRANSPORT_READY        EVENT_MASK(APPL_EVT_0)
36#define NFC_TASK_EVT_ENABLE                 EVENT_MASK(APPL_EVT_1)
37#define NFC_TASK_EVT_TERMINATE              EVENT_MASK(APPL_EVT_7)
38
39/* Error codes for BT_EVT_TO_NFC_ERR event */
40#define NFC_ERR_TRANSPORT                   0   /* fatal error in NCI transport */
41
42
43/* NFC Timer events */
44#define NFC_TTYPE_NCI_CMD_CMPL              0
45#define NFC_TTYPE_WAIT_2_DEACTIVATE         1
46
47#define NFC_TTYPE_LLCP_LINK_MANAGER         100
48#define NFC_TTYPE_LLCP_LINK_INACT           101
49#define NFC_TTYPE_LLCP_DATA_LINK            102
50#define NFC_TTYPE_LLCP_DELAY_FIRST_PDU      103
51#define NFC_TTYPE_RW_T1T_RESPONSE           104
52#define NFC_TTYPE_RW_T2T_RESPONSE           105
53#define NFC_TTYPE_RW_T3T_RESPONSE           106
54#define NFC_TTYPE_RW_T4T_RESPONSE           107
55#define NFC_TTYPE_RW_I93_RESPONSE           108
56#define NFC_TTYPE_CE_T4T_UPDATE             109
57#define NFC_TTYPE_VS_BASE                   200
58
59
60/* NFC Task event messages */
61
62enum
63{
64    NFC_STATE_NONE,     /* not start up yet         */
65    NFC_STATE_IDLE,     /* reset/init               */
66    NFC_STATE_OPEN,     /* NFC link is activated    */
67    NFC_STATE_CLOSING,  /* de-activating            */
68    NFC_STATE_RESTARTING,           /* restarting NFCC after reboot */
69    NFC_STATE_NFCC_POWER_OFF_SLEEP  /* NFCC is power-off sleep mode */
70};
71typedef UINT8 tNFC_STATE;
72
73/* NFC control block flags */
74#define NFC_FL_ENABLED                  0x0001  /* NFC enabled                                  */
75#define NFC_FL_ENABLE_PENDING           0x0002  /* NFC is being enabled (NFC_ENABLE_EVT pending)*/
76#define NFC_FL_NCI_TRANSPORT_ENABLED    0x0004  /* Transport enabled                            */
77#define NFC_FL_DEACTIVATING             0x0008  /* NFC_Deactivate() is called and the NCI cmd is not sent   */
78#define NFC_FL_W4_TRANSPORT_READY       0x0010  /* Waiting for NCI transport to be ready before enabling NFC*/
79#define NFC_FL_POWER_CYCLE_NFCC         0x0020  /* Power cycle NFCC                             */
80
81#define NFC_PEND_CONN_ID               0xFE
82#define NFC_CONN_ID_INT_MASK           0xF0
83#define NFC_CONN_ID_ID_MASK            NCI_CID_MASK
84#define NFC_CONN_NO_FC                 0xFF /* set num_buff to this for no flow control */
85#define NFC_NCI_CONN_NO_FC             0xFF
86
87typedef struct
88{
89    tNFC_CONN_CBACK *p_cback;   /* the callback function to receive the data        */
90    BUFFER_Q    tx_q;           /* transmit queue                                   */
91    BUFFER_Q    rx_q;           /* receive queue                                    */
92    UINT8       id;             /* NFCEE ID or RF Discovery ID or NFC_TEST_ID       */
93    UINT8       act_protocol;   /* the active protocol on this logical connection   */
94    UINT8       buff_size;      /* the max buffer size for this connection.     .   */
95    UINT8       num_buff;       /* num of buffers left to send on this connection   */
96    UINT8       init_credits;   /* initial num of buffer credits                    */
97    UINT8       conn_id;        /* the connection id assigned by NFCC for this conn */
98} tNFC_CONN_CB;
99
100#define NFC_SAVED_CMD_SIZE      2
101
102enum
103{
104    NFC_INT_ENABLE_END_EVT,     /* Right before reporting NFC_ENABLE_EVT */
105    NFC_INT_MBOX_EVT,           /* Received mailbox event */
106    NFC_INT_NCI_VS_RSP_EVT,     /* Received NCI VS response */
107    NFC_INT_NCI_VS_NTF_EVT,     /* Received NCI VS notification */
108    NFC_INT_TIMEOUT_EVT,        /* timeout event */
109    NFC_INT_DISABLE_EVT         /* Disabling the stack */
110};
111typedef UINT16   tNFC_INT_EVT;
112typedef BOOLEAN (tNFC_VS_EVT_HDLR) (tNFC_INT_EVT event, void *p);
113
114/* NFCC power state change pending callback */
115typedef void (tNFC_PWR_ST_CBACK) (void);
116
117/* NFC control blocks */
118typedef struct
119{
120    UINT16              flags;                      /* NFC control block flags - NFC_FL_* */
121    UINT8               last_cmd[NFC_SAVED_CMD_SIZE];/* the first few bytes of last NCI command(in case out of GKI buffer) */
122    tNFC_CONN_CB        conn_cb[NCI_MAX_CONN_CBS];
123    UINT8               conn_id[NFC_MAX_CONN_ID+1]; /* index: conn_id; conn_id[]: index(1 based) to conn_cb[] */
124    tNFC_DISCOVER_CBACK *p_discv_cback;
125    tNFC_RESPONSE_CBACK *p_resp_cback;
126    tNFC_TEST_CBACK     *p_test_cback;
127    tNFC_VS_CBACK       *p_vs_cb[NFC_NUM_VS_CBACKS];/* Register for vendor specific events  */
128
129#if (NFC_RW_ONLY == FALSE)
130    /* NFCC information at init rsp */
131    UINT32              nci_features;               /* the NCI features supported by NFCC */
132    UINT16              max_ce_table;               /* the max routing table size       */
133    UINT8               max_conn;                   /* the num of connections supported by NFCC */
134#endif
135
136    /* the data members in this section may be changed by NFC_<VendorSpecific>Init() */
137    tNFC_VS_EVT_HDLR    *p_vs_evt_hdlr;             /* VS processing for internal events */
138    const tNCI_DISCOVER_MAPS  *p_disc_maps;         /* NCI RF Discovery interface mapping */
139    UINT8               num_disc_maps;              /* number of RF Discovery interface mappings */
140    UINT16              nci_interfaces;             /* the NCI interfaces of NFCC       */
141    UINT8               vs_interface[NFC_NFCC_MAX_NUM_VS_INTERFACE];  /* the NCI VS interfaces of NFCC    */
142
143    /* NFC_TASK timer management */
144    TIMER_LIST_Q        timer_queue;                /* 1-sec timer event queue */
145    TIMER_LIST_Q        quick_timer_queue;
146
147    BUFFER_Q            nci_cmd_xmit_q;             /* NCI command queue */
148    BT_HDR              *p_nci_last_cmd;            /* the last command sent to NFCC; waiting for rsp */
149    BT_HDR              *p_frag_msg;                /* fragmented NCI message; waiting for last fragment */
150    TIMER_LIST_ENT      nci_cmd_cmpl_timer;         /* Timer for waiting for nci command response */
151    TIMER_LIST_ENT      deactivate_timer;           /* Timer to wait for deactivation */
152    UINT16              nci_cmd_cplt_tout;          /* NCI command timeout (in seconds) */
153    UINT8               nci_ctrl_size;              /* Max Control Packet Payload Size */
154    UINT8               nci_cmd_window;             /* Number of commands the controller can accecpt without waiting for response */
155    UINT8               nci_num_timeout;            /* number of NCI cmd timeout */
156
157    tNFC_STATE          nfc_state;
158    UINT8               trace_level;
159} tNFC_CB;
160
161
162/*****************************************************************************
163**  EXTERNAL FUNCTION DECLARATIONS
164*****************************************************************************/
165
166/* Global NFC data */
167#if NFC_DYNAMIC_MEMORY == FALSE
168NFC_API extern tNFC_CB  nfc_cb;
169#else
170NFC_API extern tNFC_CB *nfc_cb_ptr;
171#define nfc_cb (*nfc_cb_ptr)
172#endif
173
174/****************************************************************************
175** Internal nfc functions
176****************************************************************************/
177
178NFC_API extern void nfc_init(void);
179
180/* from nfc_utils.c */
181NFC_API extern tNFC_CONN_CB * nfc_alloc_conn_cb( tNFC_CONN_CBACK *p_cback);
182NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_conn_id(UINT8 conn_id);
183NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_handle(UINT8 target_handle);
184NFC_API extern void nfc_set_conn_id(tNFC_CONN_CB * p_cb, UINT8 conn_id);
185NFC_API extern void nfc_free_conn_cb( tNFC_CONN_CB *p_cb);
186NFC_API extern void nfc_reset_all_conn_cbs( void);
187NFC_API extern void nfc_data_event(tNFC_CONN_CB * p_cb);
188
189void nfc_ncif_send (BT_HDR *p_buf, BOOLEAN is_cmd);
190extern UINT8 nfc_ncif_send_data (tNFC_CONN_CB *p_cb, BT_HDR *p_data);
191NFC_API extern void nfc_ncif_cmd_timeout (void);
192NFC_API extern void nfc_wait_2_deactivate_timeout (void);
193NFC_API extern void nfc_ncif_update_window(BOOLEAN is_rsp);
194
195NFC_API extern BOOLEAN nfc_ncif_process_event (BT_HDR *p_msg);
196NFC_API extern void nfc_ncif_send_cmd (BT_HDR *p_buf);
197NFC_API extern void nfc_ncif_proc_discover_ntf(UINT8 *p, UINT16 plen);
198NFC_API extern void nfc_ncif_rf_management_status(tNFC_DISCOVER_EVT event, UINT8 status);
199NFC_API extern void nfc_ncif_set_config_status (UINT8 *p, UINT8 len);
200NFC_API extern void nfc_ncif_event_status(tNFC_RESPONSE_EVT event, UINT8 status);
201NFC_API extern void nfc_ncif_error_status(UINT8 conn_id, UINT8 status);
202NFC_API extern void nfc_ncif_proc_credits(UINT8 *p, UINT16 plen);
203NFC_API extern void nfc_ncif_proc_activate(UINT8 *p, UINT8 len);
204NFC_API extern void nfc_ncif_proc_deactivate(UINT8 status, UINT8 deact_type, BOOLEAN is_ntf);
205#if ((NFC_NFCEE_INCLUDED == TRUE) && (NFC_RW_ONLY == FALSE))
206NFC_API extern void nfc_ncif_proc_ee_action(UINT8 *p, UINT16 plen);
207NFC_API extern void nfc_ncif_proc_ee_discover_req(UINT8 *p, UINT16 plen);
208NFC_API extern void nfc_ncif_proc_get_routing(UINT8 *p, UINT8 len);
209#endif
210NFC_API extern void nfc_ncif_proc_conn_create_rsp (UINT8 *p, UINT16 plen, UINT8 dest_type);
211NFC_API extern void nfc_ncif_report_conn_close_evt (UINT8 conn_id, tNFC_STATUS status);
212NFC_API extern void nfc_ncif_proc_t3t_polling_ntf(UINT8 *p, UINT16 plen);
213NFC_API extern void nfc_ncif_proc_reset_rsp (UINT8 *p, BOOLEAN is_ntf);
214NFC_API extern void nfc_ncif_proc_init_rsp (BT_HDR *p_msg);
215NFC_API extern void nfc_ncif_proc_get_config_rsp (BT_HDR *p_msg);
216NFC_API extern void nfc_ncif_proc_data (BT_HDR *p_msg);
217extern void nfc_main_disable_complete(tNFC_STATUS status);
218
219#if (NFC_RW_ONLY == FALSE)
220NFC_API extern void nfc_ncif_proc_rf_field_ntf(UINT8 rf_status);
221#else
222#define nfc_ncif_proc_rf_field_ntf(rf_status)
223#endif
224
225/* From nci_main.c */
226NFC_API extern void nfc_notify_shared_transport_ready(void);
227
228/* From nfc_main.c */
229void nfc_enabled (tNFC_STATUS nfc_status, BT_HDR *p_init_rsp_msg);
230void nfc_set_state (tNFC_STATE nfc_state);
231void nfc_gen_cleanup(void);
232void nfc_main_cleanup(void);
233void nfc_main_handle_err(BT_HDR *p_err_msg);
234void nfc_main_flush_cmd_queue (void);
235
236/* Timer functions */
237void nfc_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
238UINT32 nfc_remaining_time (TIMER_LIST_ENT *p_tle);
239void nfc_stop_timer (TIMER_LIST_ENT *p_tle);
240
241void nfc_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
242void nfc_stop_quick_timer (TIMER_LIST_ENT *p_tle);
243void nfc_process_quick_timer_evt (void);
244#ifdef __cplusplus
245}
246#endif
247
248#endif /* NFC_INT_H_ */
249