• 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   NFA_RW_OP_T2T_READ_DYN_LOCKS,
99 
100   /* Exclusive Type-3 tag operations */
101   NFA_RW_OP_T3T_READ,
102   NFA_RW_OP_T3T_WRITE,
103   NFA_RW_OP_T3T_GET_SYSTEM_CODES,
104 
105   /* Exclusive ISO 15693 tag operations */
106   NFA_RW_OP_I93_INVENTORY,
107   NFA_RW_OP_I93_STAY_QUIET,
108   NFA_RW_OP_I93_READ_SINGLE_BLOCK,
109   NFA_RW_OP_I93_WRITE_SINGLE_BLOCK,
110   NFA_RW_OP_I93_LOCK_BLOCK,
111   NFA_RW_OP_I93_READ_MULTI_BLOCK,
112   NFA_RW_OP_I93_WRITE_MULTI_BLOCK,
113   NFA_RW_OP_I93_SELECT,
114   NFA_RW_OP_I93_RESET_TO_READY,
115   NFA_RW_OP_I93_WRITE_AFI,
116   NFA_RW_OP_I93_LOCK_AFI,
117   NFA_RW_OP_I93_WRITE_DSFID,
118   NFA_RW_OP_I93_LOCK_DSFID,
119   NFA_RW_OP_I93_GET_SYS_INFO,
120   NFA_RW_OP_I93_GET_MULTI_BLOCK_STATUS,
121   NFA_RW_OP_I93_SET_ADDR_MODE,
122   NFA_RW_OP_MAX
123 };
124 typedef uint8_t tNFA_RW_OP;
125 
126 /* Enumeration of parameter structios for nfa_rw operations */
127 
128 /* NFA_RW_OP_WRITE_NDEF params */
129 typedef struct {
130   uint32_t len;
131   uint8_t* p_data;
132 } tNFA_RW_OP_PARAMS_WRITE_NDEF;
133 
134 /* NFA_RW_OP_SEND_RAW_FRAME params */
135 typedef struct { NFC_HDR* p_data; } tNFA_RW_OP_PARAMS_SEND_RAW_FRAME;
136 
137 /* NFA_RW_OP_SET_TAG_RO params */
138 typedef struct { bool b_hard_lock; } tNFA_RW_OP_PARAMS_CONFIG_READ_ONLY;
139 
140 /* NFA_RW_OP_T1T_READ params */
141 typedef struct {
142   uint8_t segment_number;
143   uint8_t block_number;
144   uint8_t index;
145 } tNFA_RW_OP_PARAMS_T1T_READ;
146 
147 /* NFA_RW_OP_T1T_WRITE_E8,NFA_RW_OP_T1T_WRITE_NE8
148    NFA_RW_OP_T1T_WRITE_E, NFA_RW_OP_T1T_WRITE_NE params  */
149 typedef struct {
150   bool b_erase;
151   uint8_t block_number;
152   uint8_t index;
153   uint8_t p_block_data[8];
154 } tNFA_RW_OP_PARAMS_T1T_WRITE;
155 
156 /* NFA_RW_OP_T2T_READ params */
157 typedef struct { uint8_t block_number; } tNFA_RW_OP_PARAMS_T2T_READ;
158 
159 /* NFA_RW_OP_T2T_WRITE params */
160 typedef struct {
161   uint8_t block_number;
162   uint8_t p_block_data[4];
163 } tNFA_RW_OP_PARAMS_T2T_WRITE;
164 
165 /* NFA_RW_OP_T2T_SECTOR_SELECT params */
166 typedef struct { uint8_t sector_number; } tNFA_RW_OP_PARAMS_T2T_SECTOR_SELECT;
167 
168 /* NFA_RW_OP_T2T_READ_DYN_LOCKS params */
169 typedef struct {
170   bool read_dyn_locks;
171 } tNFA_RW_OP_PARAMS_T2T_READ_DYN_LOCKS;
172 
173 /* NFA_RW_OP_T3T_READ params */
174 typedef struct {
175   uint8_t num_blocks;
176   tNFA_T3T_BLOCK_DESC* p_block_desc;
177 } tNFA_RW_OP_PARAMS_T3T_READ;
178 
179 /* NFA_RW_OP_T3T_WRITE params */
180 typedef struct {
181   uint8_t num_blocks;
182   tNFA_T3T_BLOCK_DESC* p_block_desc;
183   uint8_t* p_block_data;
184 } tNFA_RW_OP_PARAMS_T3T_WRITE;
185 
186 /* NFA_RW_OP_I93_XXX params */
187 typedef struct {
188   bool uid_present;
189   uint8_t uid[I93_UID_BYTE_LEN];
190   bool afi_present;
191   uint8_t afi;
192   uint8_t dsfid;
193   bool addr_mode;
194   uint16_t first_block_number;
195   uint16_t number_blocks;
196   uint8_t* p_data;
197 } tNFA_RW_OP_PARAMS_I93_CMD;
198 
199 /* Union of params for all reader/writer operations */
200 typedef union {
201   /* params for NFA_RW_OP_WRITE_NDEF */
202   tNFA_RW_OP_PARAMS_WRITE_NDEF write_ndef;
203 
204   /* params for NFA_RW_OP_SEND_RAW_FRAME */
205   tNFA_RW_OP_PARAMS_SEND_RAW_FRAME send_raw_frame;
206 
207   /* params for NFA_RW_OP_SET_TAG_RO */
208   tNFA_RW_OP_PARAMS_CONFIG_READ_ONLY set_readonly;
209 
210   /* params for NFA_RW_OP_T2T_READ and NFA_RW_OP_T1T_WRITE */
211   tNFA_RW_OP_PARAMS_T1T_READ t1t_read;
212   tNFA_RW_OP_PARAMS_T1T_WRITE t1t_write;
213 
214   /* params for NFA_RW_OP_T2T_READ,NFA_RW_OP_T2T_WRITE and
215    * NFA_RW_OP_T2T_SECTOR_SELECT */
216   tNFA_RW_OP_PARAMS_T2T_READ t2t_read;
217   tNFA_RW_OP_PARAMS_T2T_WRITE t2t_write;
218   tNFA_RW_OP_PARAMS_T2T_SECTOR_SELECT t2t_sector_select;
219   tNFA_RW_OP_PARAMS_T2T_READ_DYN_LOCKS t2t_read_dyn_locks;
220 
221   /* params for NFA_RW_OP_T3T_READ and NFA_RW_OP_T3T_WRITE */
222   tNFA_RW_OP_PARAMS_T3T_READ t3t_read;
223   tNFA_RW_OP_PARAMS_T3T_WRITE t3t_write;
224 
225   /* params for NFA_RW_OP_PRESENCE_CHECK */
226   tNFA_RW_PRES_CHK_OPTION option;
227 
228   /* params for ISO 15693 */
229   tNFA_RW_OP_PARAMS_I93_CMD i93_cmd;
230 
231 } tNFA_RW_OP_PARAMS;
232 
233 /* data type for NFA_RW_op_req_EVT */
234 typedef struct {
235   NFC_HDR hdr;
236   tNFA_RW_OP op; /* NFA RW operation */
237   tNFA_RW_OP_PARAMS params;
238 } tNFA_RW_OPERATION;
239 
240 /* data type for NFA_RW_ACTIVATE_NTF */
241 typedef struct {
242   NFC_HDR hdr;
243   tNFC_ACTIVATE_DEVT* p_activate_params; /* Data from NFC_ACTIVATE_DEVT      */
244   bool excl_rf_not_active;               /* TRUE if not in exclusive RF mode */
245 } tNFA_RW_ACTIVATE_NTF;
246 
247 /* union of all data types */
248 typedef union {
249   /* GKI event buffer header */
250   NFC_HDR hdr;
251   tNFA_RW_OPERATION op_req;
252   tNFA_RW_ACTIVATE_NTF activate_ntf;
253 } tNFA_RW_MSG;
254 
255 /* NDEF detection status */
256 enum {
257   NFA_RW_NDEF_ST_UNKNOWN = 0, /* NDEF detection not performed yet */
258   NFA_RW_NDEF_ST_TRUE,        /* Tag is NDEF */
259   NFA_RW_NDEF_ST_FALSE        /* Tag is not NDEF */
260 };
261 typedef uint8_t tNFA_RW_NDEF_ST;
262 
263 /* flags for RW control block */
264 /* Activation while not in exclusive RF mode                                */
265 #define NFA_RW_FL_NOT_EXCL_RF_MODE 0x01
266 /* Waiting for response from tag for auto-presence check                    */
267 #define NFA_RW_FL_AUTO_PRESENCE_CHECK_BUSY 0x02
268 /* Read only tag                                                            */
269 #define NFA_RW_FL_TAG_IS_READONLY 0x04
270 /* Busy retrieving additional tag information                               */
271 #define NFA_RW_FL_ACTIVATION_NTF_PENDING 0x08
272 /* Tag operation is in progress                                             */
273 #define NFA_RW_FL_API_BUSY 0x10
274 /* Tag is been activated                                                    */
275 #define NFA_RW_FL_ACTIVATED 0x20
276 /* NDEF DETECTed OK                                                         */
277 #define NFA_RW_FL_NDEF_OK 0x40
278 
279 /* NFA RW control block */
280 typedef struct {
281   tNFA_RW_OP cur_op; /* Current operation */
282 
283   TIMER_LIST_ENT tle; /* list entry for nfa_rw timer */
284   tNFA_RW_MSG*
285       p_pending_msg; /* Pending API (if busy performing presence check) */
286 
287   /* Tag info */
288   tNFC_PROTOCOL protocol;
289   tNFC_INTF_TYPE intf_type;
290   uint8_t pa_sel_res;
291   tNFC_RF_TECH_N_MODE activated_tech_mode; /* activated technology and mode */
292 
293   bool b_hard_lock;
294 
295   tNFA_RW_MSG*
296       p_buffer_rw_msg; /* Buffer to hold incoming cmd while reading tag id */
297 
298   /* TLV info */
299   tNFA_RW_TLV_ST tlv_st; /* TLV detection status */
300 
301   /* NDEF info */
302   tNFA_RW_NDEF_ST ndef_st; /* NDEF detection status */
303   uint32_t ndef_max_size;  /* max number of bytes available for NDEF data */
304   uint32_t ndef_cur_size;  /* current size of stored NDEF data (in bytes) */
305   uint8_t* p_ndef_buf;
306   uint32_t ndef_rd_offset; /* current read-offset of incoming NDEF data */
307 
308   /* Current NDEF Write info */
309   uint8_t* p_ndef_wr_buf; /* Pointer to NDEF data being written */
310   uint32_t ndef_wr_len;   /* Length of NDEF data being written */
311 
312   /* Reactivating type 2 tag after NACK rsp */
313   tRW_EVENT halt_event; /* Event ID from stack after NACK response */
314   tRW_DATA rw_data;     /* Event Data from stack after NACK response */
315   bool skip_dyn_locks;  /* To skip reading dynamic locks during NDEF Detect */
316 
317   /* Flags (see defintions for NFA_RW_FL_* ) */
318   uint8_t flags;
319 
320   /* ISO 15693 tag memory information */
321   uint16_t i93_afi_location;
322   uint8_t i93_dsfid;
323   uint8_t i93_block_size;
324   uint16_t i93_num_block;
325   uint8_t i93_uid[I93_UID_BYTE_LEN];
326   uint8_t i93_addr_mode;
327 } tNFA_RW_CB;
328 extern tNFA_RW_CB nfa_rw_cb;
329 
330 /* type definition for action functions */
331 typedef bool (*tNFA_RW_ACTION)(tNFA_RW_MSG* p_data);
332 
333 /* Internal nfa_rw function prototypes */
334 extern void nfa_rw_stop_presence_check_timer(void);
335 
336 /* Action function prototypes */
337 extern bool nfa_rw_handle_op_req(tNFA_RW_MSG* p_data);
338 extern bool nfa_rw_activate_ntf(tNFA_RW_MSG* p_data);
339 extern bool nfa_rw_deactivate_ntf(tNFA_RW_MSG* p_data);
340 extern bool nfa_rw_presence_check_tick(tNFA_RW_MSG* p_data);
341 extern bool nfa_rw_presence_check_timeout(tNFA_RW_MSG* p_data);
342 extern void nfa_rw_handle_sleep_wakeup_rsp(tNFC_STATUS status);
343 extern void nfa_rw_handle_presence_check_rsp(tNFC_STATUS status);
344 extern void nfa_rw_command_complete(void);
345 extern bool nfa_rw_handle_event(NFC_HDR* p_msg);
346 
347 extern void nfa_rw_free_ndef_rx_buf(void);
348 extern void nfa_rw_sys_disable(void);
349 
350 #endif /* NFA_DM_INT_H */
351