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