• 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 NFA_RW
22  *
23  ******************************************************************************/
24 #ifndef NFA_RW_INT_H
25 #define NFA_RW_INT_H
26 
27 #include "nfa_api.h"
28 #include "nfa_rw_api.h"
29 #include "nfa_sys.h"
30 #include "nfc_api.h"
31 #include "rw_api.h"
32 
33 /*****************************************************************************
34 **  Constants and data types
35 *****************************************************************************/
36 
37 /* Interval for performing presence check (in ms) */
38 #ifndef NFA_RW_PRESENCE_CHECK_INTERVAL
39 #define NFA_RW_PRESENCE_CHECK_INTERVAL 750
40 #endif
41 
42 /* TLV detection status */
43 #define NFA_RW_TLV_DETECT_ST_OP_NOT_STARTED 0x00 /* No Tlv detected */
44 /* Lock control tlv detected */
45 #define NFA_RW_TLV_DETECT_ST_LOCK_TLV_OP_COMPLETE 0x01
46 /* Memory control tlv detected */
47 #define NFA_RW_TLV_DETECT_ST_MEM_TLV_OP_COMPLETE 0x02
48 /* Both Lock and Memory control Tlvs are detected */
49 #define NFA_RW_TLV_DETECT_ST_COMPLETE 0x03
50 
51 /* Tag deselect cmd*/
52 #define NFA_RW_TAG_DESELECT_CMD 0xC2
53 
54 #define NFA_RW_TAG_SLP_REQ_LEN 0x02
55 
56 /* Tag sleep req cmd*/
57 extern uint8_t NFA_RW_TAG_SLP_REQ[];
58 
59 typedef uint8_t tNFA_RW_TLV_ST;
60 
61 /* RW events */
62 enum {
63   NFA_RW_OP_REQUEST_EVT = NFA_SYS_EVT_START(NFA_ID_RW),
64   NFA_RW_ACTIVATE_NTF_EVT,
65   NFA_RW_DEACTIVATE_NTF_EVT,
66   NFA_RW_PRESENCE_CHECK_TICK_EVT,
67   NFA_RW_PRESENCE_CHECK_TIMEOUT_EVT,
68   NFA_RW_MAX_EVT
69 };
70 
71 /* BTA_RW operations */
72 enum {
73   NFA_RW_OP_DETECT_NDEF,
74   NFA_RW_OP_READ_NDEF,
75   NFA_RW_OP_WRITE_NDEF,
76   NFA_RW_OP_PRESENCE_CHECK,
77   NFA_RW_OP_FORMAT_TAG,
78   NFA_RW_OP_SEND_RAW_FRAME,
79 
80   /* Exclusive Type-1,Type-2 tag operations */
81   NFA_RW_OP_DETECT_LOCK_TLV,
82   NFA_RW_OP_DETECT_MEM_TLV,
83   NFA_RW_OP_SET_TAG_RO,
84 
85   /* Exclusive Type-1 tag operations */
86   NFA_RW_OP_T1T_RID,
87   NFA_RW_OP_T1T_RALL,
88   NFA_RW_OP_T1T_READ,
89   NFA_RW_OP_T1T_WRITE,
90   NFA_RW_OP_T1T_RSEG,
91   NFA_RW_OP_T1T_READ8,
92   NFA_RW_OP_T1T_WRITE8,
93 
94   /* Exclusive Type-2 tag operations */
95   NFA_RW_OP_T2T_READ,
96   NFA_RW_OP_T2T_WRITE,
97   NFA_RW_OP_T2T_SECTOR_SELECT,
98 
99   /* Exclusive Type-3 tag operations */
100   NFA_RW_OP_T3T_READ,
101   NFA_RW_OP_T3T_WRITE,
102   NFA_RW_OP_T3T_GET_SYSTEM_CODES,
103 
104   /* Exclusive ISO 15693 tag operations */
105   NFA_RW_OP_I93_INVENTORY,
106   NFA_RW_OP_I93_STAY_QUIET,
107   NFA_RW_OP_I93_READ_SINGLE_BLOCK,
108   NFA_RW_OP_I93_WRITE_SINGLE_BLOCK,
109   NFA_RW_OP_I93_LOCK_BLOCK,
110   NFA_RW_OP_I93_READ_MULTI_BLOCK,
111   NFA_RW_OP_I93_WRITE_MULTI_BLOCK,
112   NFA_RW_OP_I93_SELECT,
113   NFA_RW_OP_I93_RESET_TO_READY,
114   NFA_RW_OP_I93_WRITE_AFI,
115   NFA_RW_OP_I93_LOCK_AFI,
116   NFA_RW_OP_I93_WRITE_DSFID,
117   NFA_RW_OP_I93_LOCK_DSFID,
118   NFA_RW_OP_I93_GET_SYS_INFO,
119   NFA_RW_OP_I93_GET_MULTI_BLOCK_STATUS,
120 
121   NFA_RW_OP_MAX
122 };
123 typedef uint8_t tNFA_RW_OP;
124 
125 /* Enumeration of parameter structios for nfa_rw operations */
126 
127 /* NFA_RW_OP_WRITE_NDEF params */
128 typedef struct {
129   uint32_t len;
130   uint8_t* p_data;
131 } tNFA_RW_OP_PARAMS_WRITE_NDEF;
132 
133 /* NFA_RW_OP_SEND_RAW_FRAME params */
134 typedef struct { NFC_HDR* p_data; } tNFA_RW_OP_PARAMS_SEND_RAW_FRAME;
135 
136 /* NFA_RW_OP_SET_TAG_RO params */
137 typedef struct { bool b_hard_lock; } tNFA_RW_OP_PARAMS_CONFIG_READ_ONLY;
138 
139 /* NFA_RW_OP_T1T_READ params */
140 typedef struct {
141   uint8_t segment_number;
142   uint8_t block_number;
143   uint8_t index;
144 } tNFA_RW_OP_PARAMS_T1T_READ;
145 
146 /* NFA_RW_OP_T1T_WRITE_E8,NFA_RW_OP_T1T_WRITE_NE8
147    NFA_RW_OP_T1T_WRITE_E, NFA_RW_OP_T1T_WRITE_NE params  */
148 typedef struct {
149   bool b_erase;
150   uint8_t block_number;
151   uint8_t index;
152   uint8_t p_block_data[8];
153 } tNFA_RW_OP_PARAMS_T1T_WRITE;
154 
155 /* NFA_RW_OP_T2T_READ params */
156 typedef struct { uint8_t block_number; } tNFA_RW_OP_PARAMS_T2T_READ;
157 
158 /* NFA_RW_OP_T2T_WRITE params */
159 typedef struct {
160   uint8_t block_number;
161   uint8_t p_block_data[4];
162 } tNFA_RW_OP_PARAMS_T2T_WRITE;
163 
164 /* NFA_RW_OP_T2T_SECTOR_SELECT params */
165 typedef struct { uint8_t sector_number; } tNFA_RW_OP_PARAMS_T2T_SECTOR_SELECT;
166 
167 /* NFA_RW_OP_T3T_READ params */
168 typedef struct {
169   uint8_t num_blocks;
170   tNFA_T3T_BLOCK_DESC* p_block_desc;
171 } tNFA_RW_OP_PARAMS_T3T_READ;
172 
173 /* NFA_RW_OP_T3T_WRITE params */
174 typedef struct {
175   uint8_t num_blocks;
176   tNFA_T3T_BLOCK_DESC* p_block_desc;
177   uint8_t* p_block_data;
178 } tNFA_RW_OP_PARAMS_T3T_WRITE;
179 
180 /* NFA_RW_OP_I93_XXX params */
181 typedef struct {
182   bool uid_present;
183   uint8_t uid[I93_UID_BYTE_LEN];
184   bool afi_present;
185   uint8_t afi;
186   uint8_t dsfid;
187   uint16_t first_block_number;
188   uint16_t number_blocks;
189   uint8_t* p_data;
190 } tNFA_RW_OP_PARAMS_I93_CMD;
191 
192 /* Union of params for all reader/writer operations */
193 typedef union {
194   /* params for NFA_RW_OP_WRITE_NDEF */
195   tNFA_RW_OP_PARAMS_WRITE_NDEF write_ndef;
196 
197   /* params for NFA_RW_OP_SEND_RAW_FRAME */
198   tNFA_RW_OP_PARAMS_SEND_RAW_FRAME send_raw_frame;
199 
200   /* params for NFA_RW_OP_SET_TAG_RO */
201   tNFA_RW_OP_PARAMS_CONFIG_READ_ONLY set_readonly;
202 
203   /* params for NFA_RW_OP_T2T_READ and NFA_RW_OP_T1T_WRITE */
204   tNFA_RW_OP_PARAMS_T1T_READ t1t_read;
205   tNFA_RW_OP_PARAMS_T1T_WRITE t1t_write;
206 
207   /* params for NFA_RW_OP_T2T_READ,NFA_RW_OP_T2T_WRITE and
208    * NFA_RW_OP_T2T_SECTOR_SELECT */
209   tNFA_RW_OP_PARAMS_T2T_READ t2t_read;
210   tNFA_RW_OP_PARAMS_T2T_WRITE t2t_write;
211   tNFA_RW_OP_PARAMS_T2T_SECTOR_SELECT t2t_sector_select;
212 
213   /* params for NFA_RW_OP_T3T_READ and NFA_RW_OP_T3T_WRITE */
214   tNFA_RW_OP_PARAMS_T3T_READ t3t_read;
215   tNFA_RW_OP_PARAMS_T3T_WRITE t3t_write;
216 
217   /* params for NFA_RW_OP_PRESENCE_CHECK */
218   tNFA_RW_PRES_CHK_OPTION option;
219 
220   /* params for ISO 15693 */
221   tNFA_RW_OP_PARAMS_I93_CMD i93_cmd;
222 
223 } tNFA_RW_OP_PARAMS;
224 
225 /* data type for NFA_RW_op_req_EVT */
226 typedef struct {
227   NFC_HDR hdr;
228   tNFA_RW_OP op; /* NFA RW operation */
229   tNFA_RW_OP_PARAMS params;
230 } tNFA_RW_OPERATION;
231 
232 /* data type for NFA_RW_ACTIVATE_NTF */
233 typedef struct {
234   NFC_HDR hdr;
235   tNFC_ACTIVATE_DEVT* p_activate_params; /* Data from NFC_ACTIVATE_DEVT      */
236   bool excl_rf_not_active;               /* TRUE if not in exclusive RF mode */
237 } tNFA_RW_ACTIVATE_NTF;
238 
239 /* union of all data types */
240 typedef union {
241   /* GKI event buffer header */
242   NFC_HDR hdr;
243   tNFA_RW_OPERATION op_req;
244   tNFA_RW_ACTIVATE_NTF activate_ntf;
245 } tNFA_RW_MSG;
246 
247 /* NDEF detection status */
248 enum {
249   NFA_RW_NDEF_ST_UNKNOWN = 0, /* NDEF detection not performed yet */
250   NFA_RW_NDEF_ST_TRUE,        /* Tag is NDEF */
251   NFA_RW_NDEF_ST_FALSE        /* Tag is not NDEF */
252 };
253 typedef uint8_t tNFA_RW_NDEF_ST;
254 
255 /* flags for RW control block */
256 /* Activation while not in exclusive RF mode                                */
257 #define NFA_RW_FL_NOT_EXCL_RF_MODE 0x01
258 /* Waiting for response from tag for auto-presence check                    */
259 #define NFA_RW_FL_AUTO_PRESENCE_CHECK_BUSY 0x02
260 /* Read only tag                                                            */
261 #define NFA_RW_FL_TAG_IS_READONLY 0x04
262 /* Busy retrieving additional tag information                               */
263 #define NFA_RW_FL_ACTIVATION_NTF_PENDING 0x08
264 /* Tag operation is in progress                                             */
265 #define NFA_RW_FL_API_BUSY 0x10
266 /* Tag is been activated                                                    */
267 #define NFA_RW_FL_ACTIVATED 0x20
268 /* NDEF DETECTed OK                                                         */
269 #define NFA_RW_FL_NDEF_OK 0x40
270 
271 /* NFA RW control block */
272 typedef struct {
273   tNFA_RW_OP cur_op; /* Current operation */
274 
275   TIMER_LIST_ENT tle; /* list entry for nfa_rw timer */
276   tNFA_RW_MSG*
277       p_pending_msg; /* Pending API (if busy performing presence check) */
278 
279   /* Tag info */
280   tNFC_PROTOCOL protocol;
281   tNFC_INTF_TYPE intf_type;
282   uint8_t pa_sel_res;
283   tNFC_RF_TECH_N_MODE activated_tech_mode; /* activated technology and mode */
284 
285   bool b_hard_lock;
286 
287   tNFA_RW_MSG*
288       p_buffer_rw_msg; /* Buffer to hold incoming cmd while reading tag id */
289 
290   /* TLV info */
291   tNFA_RW_TLV_ST tlv_st; /* TLV detection status */
292 
293   /* NDEF info */
294   tNFA_RW_NDEF_ST ndef_st; /* NDEF detection status */
295   uint32_t ndef_max_size;  /* max number of bytes available for NDEF data */
296   uint32_t ndef_cur_size;  /* current size of stored NDEF data (in bytes) */
297   uint8_t* p_ndef_buf;
298   uint32_t ndef_rd_offset; /* current read-offset of incoming NDEF data */
299 
300   /* Current NDEF Write info */
301   uint8_t* p_ndef_wr_buf; /* Pointer to NDEF data being written */
302   uint32_t ndef_wr_len;   /* Length of NDEF data being written */
303 
304   /* Reactivating type 2 tag after NACK rsp */
305   tRW_EVENT halt_event; /* Event ID from stack after NACK response */
306   tRW_DATA rw_data;     /* Event Data from stack after NACK response */
307   bool skip_dyn_locks;  /* To skip reading dynamic locks during NDEF Detect */
308 
309   /* Flags (see defintions for NFA_RW_FL_* ) */
310   uint8_t flags;
311 
312   /* ISO 15693 tag memory information */
313   uint16_t i93_afi_location;
314   uint8_t i93_dsfid;
315   uint8_t i93_block_size;
316   uint16_t i93_num_block;
317   uint8_t i93_uid[I93_UID_BYTE_LEN];
318 } tNFA_RW_CB;
319 extern tNFA_RW_CB nfa_rw_cb;
320 
321 /* type definition for action functions */
322 typedef bool (*tNFA_RW_ACTION)(tNFA_RW_MSG* p_data);
323 
324 /* Internal nfa_rw function prototypes */
325 extern void nfa_rw_stop_presence_check_timer(void);
326 
327 /* Action function prototypes */
328 extern bool nfa_rw_handle_op_req(tNFA_RW_MSG* p_data);
329 extern bool nfa_rw_activate_ntf(tNFA_RW_MSG* p_data);
330 extern bool nfa_rw_deactivate_ntf(tNFA_RW_MSG* p_data);
331 extern bool nfa_rw_presence_check_tick(tNFA_RW_MSG* p_data);
332 extern bool nfa_rw_presence_check_timeout(tNFA_RW_MSG* p_data);
333 extern void nfa_rw_handle_sleep_wakeup_rsp(tNFC_STATUS status);
334 extern void nfa_rw_handle_presence_check_rsp(tNFC_STATUS status);
335 extern void nfa_rw_command_complete(void);
336 extern bool nfa_rw_handle_event(NFC_HDR* p_msg);
337 
338 extern void nfa_rw_free_ndef_rx_buf(void);
339 extern void nfa_rw_sys_disable(void);
340 
341 #endif /* NFA_DM_INT_H */
342