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