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