• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2010-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  *  NFA interface for tag Reader/Writer
23  *
24  ******************************************************************************/
25 #include <string.h>
26 #include "nfa_api.h"
27 #include "nfa_sys.h"
28 #include "nfa_rw_int.h"
29 #include "nfa_sys_int.h"
30 
31 /*****************************************************************************
32 **  Constants
33 *****************************************************************************/
34 
35 
36 /*****************************************************************************
37 **  APIs
38 *****************************************************************************/
39 
40 /*******************************************************************************
41 **
42 ** Function         NFA_RwDetectNDef
43 **
44 ** Description      Perform the NDEF detection procedure  using the appropriate
45 **                  method for the currently activated tag.
46 **
47 **                  Upon successful completion of NDEF detection, a
48 **                  NFA_NDEF_DETECT_EVT will be sent, to notify the application
49 **                  of the NDEF attributes (NDEF total memory size, current
50 **                  size, etc.).
51 **
52 **                  It is not mandatory to call this function -  NFA_RwReadNDef
53 **                  and NFA_RwWriteNDef will perform NDEF detection internally if
54 **                  not performed already. This API may be called to get a
55 **                  tag's NDEF size before issuing a write-request.
56 **
57 ** Returns:
58 **                  NFA_STATUS_OK if successfully initiated
59 **                  NFC_STATUS_REFUSED if tag does not support NDEF
60 **                  NFA_STATUS_FAILED otherwise
61 **
62 *******************************************************************************/
NFA_RwDetectNDef(void)63 tNFA_STATUS NFA_RwDetectNDef (void)
64 {
65     tNFA_RW_OPERATION *p_msg;
66 
67     NFA_TRACE_API0 ("NFA_RwDetectNDef");
68 
69     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
70     {
71         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
72         p_msg->op        = NFA_RW_OP_DETECT_NDEF;
73 
74         nfa_sys_sendmsg (p_msg);
75 
76         return (NFA_STATUS_OK);
77     }
78 
79     return (NFA_STATUS_FAILED);
80 }
81 
82 /*******************************************************************************
83 **
84 ** Function         NFA_RwReadNDef
85 **
86 ** Description      Read NDEF message from tag. This function will internally
87 **                  perform the NDEF detection procedure (if not performed
88 **                  previously), and read the NDEF tag data using the
89 **                  appropriate method for the currently activated tag.
90 **
91 **                  Upon successful completion of NDEF detection (if performed),
92 **                  a NFA_NDEF_DETECT_EVT will be sent, to notify the application
93 **                  of the NDEF attributes (NDEF total memory size, current size,
94 **                  etc.).
95 **
96 **                  Upon receiving the NDEF message, the message will be sent to
97 **                  the handler registered with NFA_RegisterNDefTypeHandler or
98 **                  NFA_RequestExclusiveRfControl (if exclusive RF mode is active)
99 **
100 ** Returns:
101 **                  NFA_STATUS_OK if successfully initiated
102 **                  NFC_STATUS_REFUSED if tag does not support NDEF
103 **                  NFC_STATUS_NOT_INITIALIZED if NULL NDEF was detected on the tag
104 **                  NFA_STATUS_FAILED otherwise
105 **
106 *******************************************************************************/
NFA_RwReadNDef(void)107 tNFA_STATUS NFA_RwReadNDef (void)
108 {
109     tNFA_RW_OPERATION *p_msg;
110 
111     NFA_TRACE_API0 ("NFA_RwReadNDef");
112 
113     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
114     {
115         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
116         p_msg->op        = NFA_RW_OP_READ_NDEF;
117 
118         nfa_sys_sendmsg (p_msg);
119 
120         return (NFA_STATUS_OK);
121     }
122 
123     return (NFA_STATUS_FAILED);
124 }
125 
126 
127 
128 /*******************************************************************************
129 **
130 ** Function         NFA_RwWriteNDef
131 **
132 ** Description      Write NDEF data to the activated tag. This function will
133 **                  internally perform NDEF detection if necessary, and write
134 **                  the NDEF tag data using the appropriate method for the
135 **                  currently activated tag.
136 **
137 **                  When the entire message has been written, or if an error
138 **                  occurs, the app will be notified with NFA_WRITE_CPLT_EVT.
139 **
140 **                  p_data needs to be persistent until NFA_WRITE_CPLT_EVT
141 **
142 **
143 ** Returns:
144 **                  NFA_STATUS_OK if successfully initiated
145 **                  NFC_STATUS_REFUSED if tag does not support NDEF/locked
146 **                  NFA_STATUS_FAILED otherwise
147 **
148 *******************************************************************************/
NFA_RwWriteNDef(UINT8 * p_data,UINT32 len)149 tNFA_STATUS NFA_RwWriteNDef (UINT8 *p_data, UINT32 len)
150 {
151     tNFA_RW_OPERATION *p_msg;
152 
153     NFA_TRACE_API2 ("NFA_RwWriteNDef (): ndef p_data=%08x, len: %i", p_data, len);
154 
155     /* Validate parameters */
156     if (p_data == NULL)
157         return (NFA_STATUS_INVALID_PARAM);
158 
159     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
160     {
161         p_msg->hdr.event                = NFA_RW_OP_REQUEST_EVT;
162         p_msg->op                       = NFA_RW_OP_WRITE_NDEF;
163         p_msg->params.write_ndef.len    = len;
164         p_msg->params.write_ndef.p_data = p_data;
165         nfa_sys_sendmsg (p_msg);
166 
167         return (NFA_STATUS_OK);
168     }
169 
170     return (NFA_STATUS_FAILED);
171 }
172 
173 /*****************************************************************************
174 **
175 ** Function         NFA_RwPresenceCheck
176 **
177 ** Description      Check if the tag is still in the field.
178 **
179 **                  The NFA_RW_PRESENCE_CHECK_EVT w/ status is used to
180 **                  indicate presence or non-presence.
181 **
182 **                  option is used only with ISO-DEP protocol
183 **
184 ** Returns
185 **                  NFA_STATUS_OK if successfully initiated
186 **                  NFA_STATUS_FAILED otherwise
187 **
188 *****************************************************************************/
NFA_RwPresenceCheck(tNFA_RW_PRES_CHK_OPTION option)189 tNFA_STATUS NFA_RwPresenceCheck (tNFA_RW_PRES_CHK_OPTION option)
190 {
191     tNFA_RW_OPERATION *p_msg;
192 
193     NFA_TRACE_API0 ("NFA_RwPresenceCheck");
194 
195     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
196     {
197         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
198         p_msg->op        = NFA_RW_OP_PRESENCE_CHECK;
199         p_msg->params.option    = option;
200 
201         nfa_sys_sendmsg (p_msg);
202 
203         return (NFA_STATUS_OK);
204     }
205 
206     return (NFA_STATUS_FAILED);
207 }
208 
209 /*****************************************************************************
210 **
211 ** Function         NFA_RwFormatTag
212 **
213 ** Description      Check if the tag is NDEF Formatable. If yes Format the tag
214 **
215 **                  The NFA_RW_FORMAT_CPLT_EVT w/ status is used to
216 **                  indicate if tag is successfully formated or not
217 **
218 ** Returns
219 **                  NFA_STATUS_OK if successfully initiated
220 **                  NFA_STATUS_FAILED otherwise
221 **
222 *****************************************************************************/
NFA_RwFormatTag(void)223 tNFA_STATUS NFA_RwFormatTag (void)
224 {
225     tNFA_RW_OPERATION *p_msg;
226 
227     NFA_TRACE_API0 ("NFA_RwFormatTag");
228 
229     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16)(sizeof (tNFA_RW_OPERATION)))) != NULL)
230     {
231         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
232         p_msg->op        = NFA_RW_OP_FORMAT_TAG;
233 
234         nfa_sys_sendmsg (p_msg);
235 
236         return (NFA_STATUS_OK);
237     }
238 
239     return (NFA_STATUS_FAILED);
240 }
241 
242 /*******************************************************************************
243 **
244 ** Function         NFA_RwSetTagReadOnly
245 **
246 ** Description:
247 **      Sets tag as read only.
248 **
249 **      When tag is set as read only, or if an error occurs, the app will be
250 **      notified with NFA_SET_TAG_RO_EVT.
251 **
252 ** Returns:
253 **      NFA_STATUS_OK if successfully initiated
254 **      NFA_STATUS_REJECTED if protocol is not T1/T2/ISO15693
255 **                 (or) if hard lock is not requested for protocol ISO15693
256 **      NFA_STATUS_FAILED otherwise
257 **
258 *******************************************************************************/
NFA_RwSetTagReadOnly(BOOLEAN b_hard_lock)259 tNFA_STATUS NFA_RwSetTagReadOnly (BOOLEAN b_hard_lock)
260 {
261     tNFA_RW_OPERATION *p_msg;
262     tNFC_PROTOCOL      protocol = nfa_rw_cb.protocol;
263 
264     if ((protocol != NFC_PROTOCOL_T1T) && (protocol != NFC_PROTOCOL_T2T) && (protocol != NFC_PROTOCOL_15693) && (protocol != NFC_PROTOCOL_ISO_DEP) && (protocol != NFC_PROTOCOL_T3T))
265     {
266         NFA_TRACE_API1 ("NFA_RwSetTagReadOnly (): Cannot Configure as read only for Protocol: %d", protocol);
267         return (NFA_STATUS_REJECTED);
268     }
269 
270     if (  (!b_hard_lock && (protocol == NFC_PROTOCOL_15693))
271         ||(b_hard_lock && (protocol == NFC_PROTOCOL_ISO_DEP))  )
272     {
273         NFA_TRACE_API2 ("NFA_RwSetTagReadOnly (): Cannot %s for Protocol: %d", b_hard_lock ? "Hard lock" : "Soft lock", protocol);
274         return (NFA_STATUS_REJECTED);
275     }
276 
277     NFA_TRACE_API1 ("NFA_RwSetTagReadOnly (): %s", b_hard_lock ? "Hard lock" : "Soft lock");
278 
279     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
280     {
281         /* Fill in tNFA_RW_OPERATION struct */
282         p_msg->hdr.event                       = NFA_RW_OP_REQUEST_EVT;
283         p_msg->op                              = NFA_RW_OP_SET_TAG_RO;
284         p_msg->params.set_readonly.b_hard_lock = b_hard_lock;
285 
286         nfa_sys_sendmsg (p_msg);
287         return (NFA_STATUS_OK);
288     }
289     return (NFA_STATUS_FAILED);
290 }
291 
292 /*******************************************************************************
293 ** Tag specific APIs
294 ** (note: for Type-4 tags, use NFA_SendRawFrame to exchange APDUs)
295 *******************************************************************************/
296 
297 /*******************************************************************************
298 **
299 ** Function         NFA_RwLocateTlv
300 **
301 ** Description:
302 **      Search for the Lock/Memory contril TLV on the activated Type1/Type2 tag
303 **
304 **      Data is returned to the application using the NFA_TLV_DETECT_EVT. When
305 **      search operation has completed, or if an error occurs, the app will be
306 **      notified with NFA_TLV_DETECT_EVT.
307 **
308 ** Description      Perform the TLV detection procedure  using the appropriate
309 **                  method for the currently activated tag.
310 **
311 **                  Upon successful completion of TLV detection in T1/T2 tag, a
312 **                  NFA_TLV_DETECT_EVT will be sent, to notify the application
313 **                  of the TLV attributes (total lock/reserved bytes etc.).
314 **                  However if the TLV type specified is NDEF then it is same as
315 **                  calling NFA_RwDetectNDef and should expect to receive
316 **                  NFA_NDEF_DETECT_EVT instead of NFA_TLV_DETECT_EVT
317 **
318 **                  It is not mandatory to call this function -  NFA_RwDetectNDef,
319 **                  NFA_RwReadNDef and NFA_RwWriteNDef will perform TLV detection
320 **                  internally if not performed already. An application may call
321 **                  this API to check the a tag/card-emulator's total Reserved/
322 **                  Lock bytes before issuing a write-request.
323 **
324 ** Returns:
325 **                  NFA_STATUS_OK if successfully initiated
326 **                  NFC_STATUS_REFUSED if tlv_type is NDEF & tag won't support NDEF
327 **                  NFA_STATUS_FAILED otherwise
328 **
329 *******************************************************************************/
NFA_RwLocateTlv(UINT8 tlv_type)330 tNFA_STATUS NFA_RwLocateTlv (UINT8 tlv_type)
331 {
332     tNFA_RW_OPERATION *p_msg;
333 
334     NFA_TRACE_API0 ("NFA_RwLocateTlv");
335 
336     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
337     {
338         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
339 
340         if (tlv_type == TAG_LOCK_CTRL_TLV)
341         {
342             p_msg->op = NFA_RW_OP_DETECT_LOCK_TLV;
343         }
344         else if (tlv_type == TAG_MEM_CTRL_TLV)
345         {
346             p_msg->op = NFA_RW_OP_DETECT_MEM_TLV;
347         }
348         else if (tlv_type == TAG_NDEF_TLV)
349         {
350             p_msg->op = NFA_RW_OP_DETECT_NDEF;
351         }
352         else
353             return (NFA_STATUS_FAILED);
354 
355         nfa_sys_sendmsg (p_msg);
356 
357         return (NFA_STATUS_OK);
358     }
359 
360     return (NFA_STATUS_FAILED);
361 }
362 
363 /*******************************************************************************
364 **
365 ** Function         NFA_RwT1tRid
366 **
367 ** Description:
368 **      Send a RID command to the activated Type 1 tag.
369 **
370 **      Data is returned to the application using the NFA_DATA_EVT. When the read
371 **      operation has completed, or if an error occurs, the app will be notified with
372 **      NFA_READ_CPLT_EVT.
373 **
374 ** Returns:
375 **      NFA_STATUS_OK if successfully initiated
376 **      NFA_STATUS_FAILED otherwise
377 **
378 *******************************************************************************/
NFA_RwT1tRid(void)379 tNFA_STATUS NFA_RwT1tRid (void)
380 {
381     tNFA_RW_OPERATION *p_msg;
382 
383     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
384     {
385         /* Fill in tNFA_RW_OPERATION struct */
386         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
387         p_msg->op        = NFA_RW_OP_T1T_RID;
388 
389         nfa_sys_sendmsg (p_msg);
390         return (NFA_STATUS_OK);
391     }
392     return (NFA_STATUS_FAILED);
393 }
394 
395 /*******************************************************************************
396 **
397 ** Function         NFA_RwT1tReadAll
398 **
399 ** Description:
400 **      Send a RALL command to the activated Type 1 tag.
401 **
402 **      Data is returned to the application using the NFA_DATA_EVT. When the read
403 **      operation has completed, or if an error occurs, the app will be notified with
404 **      NFA_READ_CPLT_EVT.
405 **
406 ** Returns:
407 **      NFA_STATUS_OK if successfully initiated
408 **      NFA_STATUS_FAILED otherwise
409 **
410 *******************************************************************************/
NFA_RwT1tReadAll(void)411 tNFA_STATUS NFA_RwT1tReadAll (void)
412 {
413     tNFA_RW_OPERATION *p_msg;
414 
415     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
416     {
417         /* Fill in tNFA_RW_OPERATION struct */
418         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
419         p_msg->op        = NFA_RW_OP_T1T_RALL;
420 
421         nfa_sys_sendmsg (p_msg);
422         return (NFA_STATUS_OK);
423     }
424     return (NFA_STATUS_FAILED);
425 }
426 
427 /*******************************************************************************
428 **
429 ** Function         NFA_RwT1tRead
430 **
431 ** Description:
432 **      Send a READ command to the activated Type 1 tag.
433 **
434 **      Data is returned to the application using the NFA_DATA_EVT. When the read
435 **      operation has completed, or if an error occurs, the app will be notified with
436 **      NFA_READ_CPLT_EVT.
437 **
438 ** Returns:
439 **      NFA_STATUS_OK if successfully initiated
440 **      NFA_STATUS_FAILED otherwise
441 **
442 *******************************************************************************/
NFA_RwT1tRead(UINT8 block_number,UINT8 index)443 tNFA_STATUS NFA_RwT1tRead (UINT8 block_number, UINT8 index)
444 {
445     tNFA_RW_OPERATION *p_msg;
446 
447     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
448     {
449         /* Fill in tNFA_RW_OPERATION struct */
450         p_msg->hdr.event                    = NFA_RW_OP_REQUEST_EVT;
451         p_msg->op                           = NFA_RW_OP_T1T_READ;
452         p_msg->params.t1t_read.block_number = block_number;
453         p_msg->params.t1t_read.index        = index;
454 
455         nfa_sys_sendmsg (p_msg);
456         return (NFA_STATUS_OK);
457     }
458     return (NFA_STATUS_FAILED);
459 }
460 
461 /*******************************************************************************
462 **
463 ** Function         NFA_RwT1tWrite
464 **
465 ** Description:
466 **      Send a WRITE command to the activated Type 1 tag.
467 **
468 **      Data is returned to the application using the NFA_DATA_EVT. When the write
469 **      operation has completed, or if an error occurs, the app will be notified with
470 **      NFA_WRITE_CPLT_EVT.
471 **
472 ** Returns:
473 **      NFA_STATUS_OK if successfully initiated
474 **      NFA_STATUS_FAILED otherwise
475 **
476 *******************************************************************************/
NFA_RwT1tWrite(UINT8 block_number,UINT8 index,UINT8 data,BOOLEAN b_erase)477 tNFA_STATUS NFA_RwT1tWrite (UINT8 block_number, UINT8 index, UINT8 data, BOOLEAN b_erase)
478 {
479     tNFA_RW_OPERATION *p_msg;
480 
481     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
482     {
483         /* Fill in tNFA_RW_OPERATION struct */
484         p_msg->hdr.event                     = NFA_RW_OP_REQUEST_EVT;
485         p_msg->params.t1t_write.b_erase      = b_erase;
486         p_msg->op                            = NFA_RW_OP_T1T_WRITE;
487         p_msg->params.t1t_write.block_number = block_number;
488         p_msg->params.t1t_write.index        = index;
489         p_msg->params.t1t_write.p_block_data[0] = data;
490 
491         nfa_sys_sendmsg (p_msg);
492         return (NFA_STATUS_OK);
493     }
494     return (NFA_STATUS_FAILED);
495 }
496 
497 /*******************************************************************************
498 **
499 ** Function         NFA_RwT1tReadSeg
500 **
501 ** Description:
502 **      Send a RSEG command to the activated Type 1 tag.
503 **
504 **      Data is returned to the application using the NFA_DATA_EVT. When the read
505 **      operation has completed, or if an error occurs, the app will be notified with
506 **      NFA_READ_CPLT_EVT.
507 **
508 ** Returns:
509 **      NFA_STATUS_OK if successfully initiated
510 **      NFA_STATUS_FAILED otherwise
511 **
512 *******************************************************************************/
NFA_RwT1tReadSeg(UINT8 segment_number)513 tNFA_STATUS NFA_RwT1tReadSeg (UINT8 segment_number)
514 {
515     tNFA_RW_OPERATION *p_msg;
516 
517     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
518     {
519         /* Fill in tNFA_RW_OPERATION struct */
520         p_msg->hdr.event                      = NFA_RW_OP_REQUEST_EVT;
521         p_msg->op                             = NFA_RW_OP_T1T_RSEG;
522         p_msg->params.t1t_read.segment_number = segment_number;
523 
524         nfa_sys_sendmsg (p_msg);
525         return (NFA_STATUS_OK);
526     }
527     return (NFA_STATUS_FAILED);
528 }
529 
530 /*******************************************************************************
531 **
532 ** Function         NFA_RwT1tRead8
533 **
534 ** Description:
535 **      Send a READ8 command to the activated Type 1 tag.
536 **
537 **      Data is returned to the application using the NFA_DATA_EVT. When the read
538 **      operation has completed, or if an error occurs, the app will be notified with
539 **      NFA_READ_CPLT_EVT.
540 **
541 ** Returns:
542 **      NFA_STATUS_OK if successfully initiated
543 **      NFA_STATUS_FAILED otherwise
544 **
545 *******************************************************************************/
NFA_RwT1tRead8(UINT8 block_number)546 tNFA_STATUS NFA_RwT1tRead8 (UINT8 block_number)
547 {
548     tNFA_RW_OPERATION *p_msg;
549 
550     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
551     {
552         /* Fill in tNFA_RW_OPERATION struct */
553         p_msg->hdr.event                     = NFA_RW_OP_REQUEST_EVT;
554         p_msg->op                            = NFA_RW_OP_T1T_READ8;
555         p_msg->params.t1t_write.block_number = block_number;
556 
557         nfa_sys_sendmsg (p_msg);
558         return (NFA_STATUS_OK);
559     }
560     return (NFA_STATUS_FAILED);
561 }
562 
563 /*******************************************************************************
564 **
565 ** Function         NFA_RwT1tWrite8
566 **
567 ** Description:
568 **      Send a WRITE8_E / WRITE8_NE command to the activated Type 1 tag.
569 **
570 **      Data is returned to the application using the NFA_DATA_EVT. When the read
571 **      operation has completed, or if an error occurs, the app will be notified with
572 **      NFA_READ_CPLT_EVT.
573 **
574 ** Returns:
575 **      NFA_STATUS_OK if successfully initiated
576 **      NFA_STATUS_FAILED otherwise
577 **
578 *******************************************************************************/
NFA_RwT1tWrite8(UINT8 block_number,UINT8 * p_data,BOOLEAN b_erase)579 tNFA_STATUS NFA_RwT1tWrite8 (UINT8 block_number, UINT8 *p_data, BOOLEAN b_erase)
580 {
581     tNFA_RW_OPERATION *p_msg;
582 
583     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
584     {
585         /* Fill in tNFA_RW_OPERATION struct */
586         p_msg->hdr.event                     = NFA_RW_OP_REQUEST_EVT;
587         p_msg->params.t1t_write.b_erase      = b_erase;
588         p_msg->op                            = NFA_RW_OP_T1T_WRITE8;
589         p_msg->params.t1t_write.block_number = block_number;
590 
591         memcpy (p_msg->params.t1t_write.p_block_data,p_data,8);
592 
593         nfa_sys_sendmsg (p_msg);
594         return (NFA_STATUS_OK);
595     }
596     return (NFA_STATUS_FAILED);
597 }
598 
599 /*******************************************************************************
600 **
601 ** Function         NFA_RwT2tRead
602 **
603 ** Description:
604 **      Send a READ command to the activated Type 2 tag.
605 **
606 **      Data is returned to the application using the NFA_DATA_EVT. When the read
607 **      operation has completed, or if an error occurs, the app will be notified with
608 **      NFA_READ_CPLT_EVT.
609 **
610 ** Returns:
611 **      NFA_STATUS_OK if successfully initiated
612 **      NFA_STATUS_FAILED otherwise
613 **
614 *******************************************************************************/
NFA_RwT2tRead(UINT8 block_number)615 tNFA_STATUS NFA_RwT2tRead (UINT8 block_number)
616 {
617     tNFA_RW_OPERATION *p_msg;
618 
619     NFA_TRACE_API1 ("NFA_RwT2tRead (): Block to read: %d", block_number);
620 
621     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
622     {
623         /* Fill in tNFA_RW_OPERATION struct */
624         p_msg->hdr.event                    = NFA_RW_OP_REQUEST_EVT;
625         p_msg->op                           = NFA_RW_OP_T2T_READ;
626         p_msg->params.t2t_read.block_number = block_number;
627 
628         nfa_sys_sendmsg (p_msg);
629         return (NFA_STATUS_OK);
630     }
631     return (NFA_STATUS_FAILED);
632 }
633 
634 /*******************************************************************************
635 **
636 ** Function         NFA_RwT2tWrite
637 **
638 ** Description:
639 **      Send an WRITE command to the activated Type 2 tag.
640 **
641 **      When the write operation has completed (or if an error occurs), the
642 **      app will be notified with NFA_WRITE_CPLT_EVT.
643 **
644 ** Returns:
645 **      NFA_STATUS_OK if successfully initiated
646 **      NFA_STATUS_FAILED otherwise
647 **
648 *******************************************************************************/
NFA_RwT2tWrite(UINT8 block_number,UINT8 * p_data)649 tNFA_STATUS NFA_RwT2tWrite (UINT8 block_number,	UINT8 *p_data)
650 {
651     tNFA_RW_OPERATION *p_msg;
652 
653     NFA_TRACE_API1 ("NFA_RwT2tWrite (): Block to write: %d", block_number);
654 
655     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
656     {
657         /* Fill in tNFA_RW_OPERATION struct */
658         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
659         p_msg->op        = NFA_RW_OP_T2T_WRITE;
660 
661         p_msg->params.t2t_write.block_number = block_number;
662 
663         memcpy (p_msg->params.t2t_write.p_block_data,p_data,4);
664 
665         nfa_sys_sendmsg (p_msg);
666         return (NFA_STATUS_OK);
667     }
668     return (NFA_STATUS_FAILED);
669 }
670 
671 /*******************************************************************************
672 **
673 ** Function         NFA_RwT2tSectorSelect
674 **
675 ** Description:
676 **      Send SECTOR SELECT command to the activated Type 2 tag.
677 **
678 **      When the sector select operation has completed (or if an error occurs), the
679 **      app will be notified with NFA_SECTOR_SELECT_CPLT_EVT.
680 **
681 ** Returns:
682 **      NFA_STATUS_OK if successfully initiated
683 **      NFA_STATUS_FAILED otherwise
684 **
685 *******************************************************************************/
NFA_RwT2tSectorSelect(UINT8 sector_number)686 tNFA_STATUS NFA_RwT2tSectorSelect (UINT8 sector_number)
687 {
688     tNFA_RW_OPERATION *p_msg;
689 
690     NFA_TRACE_API1 ("NFA_RwT2tRead (): sector to select: %d", sector_number);
691 
692     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
693     {
694         /* Fill in tNFA_RW_OPERATION struct */
695         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
696         p_msg->op        = NFA_RW_OP_T2T_SECTOR_SELECT;
697 
698         p_msg->params.t2t_sector_select.sector_number = sector_number;
699 
700         nfa_sys_sendmsg (p_msg);
701         return (NFA_STATUS_OK);
702     }
703     return (NFA_STATUS_FAILED);
704 }
705 
706 /*******************************************************************************
707 **
708 ** Function         NFA_RwT3tRead
709 **
710 ** Description:
711 **      Send a CHECK (read) command to the activated Type 3 tag.
712 **
713 **      Data is returned to the application using the NFA_DATA_EVT. When the read
714 **      operation has completed, or if an error occurs, the app will be notified with
715 **      NFA_READ_CPLT_EVT.
716 **
717 ** Returns:
718 **      NFA_STATUS_OK if successfully initiated
719 **      NFA_STATUS_FAILED otherwise
720 **
721 *******************************************************************************/
NFA_RwT3tRead(UINT8 num_blocks,tNFA_T3T_BLOCK_DESC * t3t_blocks)722 tNFA_STATUS NFA_RwT3tRead (UINT8 num_blocks, tNFA_T3T_BLOCK_DESC *t3t_blocks)
723 {
724     tNFA_RW_OPERATION *p_msg;
725     UINT8 *p_block_desc;
726 
727     NFA_TRACE_API1 ("NFA_RwT3tRead (): num_blocks to read: %i", num_blocks);
728 
729     /* Validate parameters */
730     if ((num_blocks == 0) || (t3t_blocks == NULL))
731         return (NFA_STATUS_INVALID_PARAM);
732 
733     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION) + (num_blocks * sizeof (tNFA_T3T_BLOCK_DESC))))) != NULL)
734     {
735         /* point to area after tNFA_RW_OPERATION */
736         p_block_desc = (UINT8 *) (p_msg+1);
737 
738         /* Fill in tNFA_RW_OPERATION struct */
739         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
740         p_msg->op        = NFA_RW_OP_T3T_READ;
741 
742         p_msg->params.t3t_read.num_blocks   = num_blocks;
743         p_msg->params.t3t_read.p_block_desc = (tNFA_T3T_BLOCK_DESC *) p_block_desc;
744 
745         /* Copy block descriptor list */
746         memcpy (p_block_desc, t3t_blocks, (num_blocks * sizeof (tNFA_T3T_BLOCK_DESC)));
747 
748         nfa_sys_sendmsg (p_msg);
749 
750         return (NFA_STATUS_OK);
751     }
752 
753     return (NFA_STATUS_FAILED);
754 }
755 
756 /*******************************************************************************
757 **
758 ** Function         NFA_RwT3tWrite
759 **
760 ** Description:
761 **      Send an UPDATE (write) command to the activated Type 3 tag.
762 **
763 **      When the write operation has completed (or if an error occurs), the
764 **      app will be notified with NFA_WRITE_CPLT_EVT.
765 **
766 ** Returns:
767 **      NFA_STATUS_OK if successfully initiated
768 **      NFA_STATUS_FAILED otherwise
769 **
770 *******************************************************************************/
NFA_RwT3tWrite(UINT8 num_blocks,tNFA_T3T_BLOCK_DESC * t3t_blocks,UINT8 * p_data)771 tNFA_STATUS NFA_RwT3tWrite (UINT8 num_blocks, tNFA_T3T_BLOCK_DESC *t3t_blocks,	UINT8 *p_data)
772 {
773     tNFA_RW_OPERATION *p_msg;
774     UINT8 *p_block_desc, *p_data_area;
775 
776     NFA_TRACE_API1 ("NFA_RwT3tWrite (): num_blocks to write: %i", num_blocks);
777 
778     /* Validate parameters */
779     if ((num_blocks == 0) || (t3t_blocks == NULL) | (p_data == NULL))
780         return (NFA_STATUS_INVALID_PARAM);
781 
782     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION) + (num_blocks * (sizeof (tNFA_T3T_BLOCK_DESC) + 16))))) != NULL)
783     {
784         /* point to block descriptor and data areas after tNFA_RW_OPERATION */
785         p_block_desc = (UINT8 *) (p_msg+1);
786         p_data_area  = p_block_desc + (num_blocks * (sizeof (tNFA_T3T_BLOCK_DESC)));
787 
788         /* Fill in tNFA_RW_OPERATION struct */
789         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
790         p_msg->op        = NFA_RW_OP_T3T_WRITE;
791 
792         p_msg->params.t3t_write.num_blocks   = num_blocks;
793         p_msg->params.t3t_write.p_block_desc = (tNFA_T3T_BLOCK_DESC *) p_block_desc;
794         p_msg->params.t3t_write.p_block_data = p_data_area;
795 
796         /* Copy block descriptor list */
797         memcpy (p_block_desc, t3t_blocks, (num_blocks * sizeof (tNFA_T3T_BLOCK_DESC)));
798 
799         /* Copy data */
800         memcpy (p_data_area, p_data, (num_blocks * 16));
801 
802         nfa_sys_sendmsg (p_msg);
803 
804         return (NFA_STATUS_OK);
805     }
806 
807     return (NFA_STATUS_FAILED);
808 }
809 
810 /*******************************************************************************
811 **
812 ** Function         NFA_RwI93Inventory
813 **
814 ** Description:
815 **      Send Inventory command to the activated ISO 15693 tag with/without AFI
816 **      If UID is provided then set UID[0]:MSB, ... UID[7]:LSB
817 **
818 **      When the operation has completed (or if an error occurs), the
819 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
820 **
821 ** Returns:
822 **      NFA_STATUS_OK if successfully initiated
823 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
824 **      NFA_STATUS_FAILED otherwise
825 **
826 *******************************************************************************/
NFA_RwI93Inventory(BOOLEAN afi_present,UINT8 afi,UINT8 * p_uid)827 tNFA_STATUS NFA_RwI93Inventory (BOOLEAN afi_present, UINT8 afi, UINT8 *p_uid)
828 {
829     tNFA_RW_OPERATION *p_msg;
830 
831     NFA_TRACE_API2 ("NFA_RwI93Inventory (): afi_present:%d, AFI: 0x%02X", afi_present, afi);
832 
833     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
834     {
835         return (NFA_STATUS_WRONG_PROTOCOL);
836     }
837 
838     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
839     {
840         /* Fill in tNFA_RW_OPERATION struct */
841         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
842         p_msg->op        = NFA_RW_OP_I93_INVENTORY;
843 
844         p_msg->params.i93_cmd.afi_present = afi_present;
845         p_msg->params.i93_cmd.afi = afi;
846 
847         if (p_uid)
848         {
849             p_msg->params.i93_cmd.uid_present = TRUE;
850             memcpy (p_msg->params.i93_cmd.uid, p_uid, I93_UID_BYTE_LEN);
851         }
852         else
853         {
854             p_msg->params.i93_cmd.uid_present = FALSE;
855         }
856 
857         nfa_sys_sendmsg (p_msg);
858 
859         return (NFA_STATUS_OK);
860     }
861 
862     return (NFA_STATUS_FAILED);
863 }
864 
865 /*******************************************************************************
866 **
867 ** Function         NFA_RwI93StayQuiet
868 **
869 ** Description:
870 **      Send Stay Quiet command to the activated ISO 15693 tag.
871 **
872 **      When the operation has completed (or if an error occurs), the
873 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
874 **
875 ** Returns:
876 **      NFA_STATUS_OK if successfully initiated
877 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
878 **      NFA_STATUS_FAILED otherwise
879 **
880 *******************************************************************************/
NFA_RwI93StayQuiet(void)881 tNFA_STATUS NFA_RwI93StayQuiet (void)
882 {
883     tNFA_RW_OPERATION *p_msg;
884 
885     NFA_TRACE_API0 ("NFA_RwI93StayQuiet ()");
886 
887     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
888     {
889         return (NFA_STATUS_WRONG_PROTOCOL);
890     }
891 
892     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
893     {
894         /* Fill in tNFA_RW_OPERATION struct */
895         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
896         p_msg->op        = NFA_RW_OP_I93_STAY_QUIET;
897 
898         nfa_sys_sendmsg (p_msg);
899 
900         return (NFA_STATUS_OK);
901     }
902 
903     return (NFA_STATUS_FAILED);
904 }
905 
906 /*******************************************************************************
907 **
908 ** Function         NFA_RwI93ReadSingleBlock
909 **
910 ** Description:
911 **      Send Read Single Block command to the activated ISO 15693 tag.
912 **
913 **      Data is returned to the application using the NFA_DATA_EVT. When the read
914 **      operation has completed, or if an error occurs, the app will be notified with
915 **      NFA_I93_CMD_CPLT_EVT.
916 **
917 ** Returns:
918 **      NFA_STATUS_OK if successfully initiated
919 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
920 **      NFA_STATUS_FAILED otherwise
921 **
922 *******************************************************************************/
NFA_RwI93ReadSingleBlock(UINT8 block_number)923 tNFA_STATUS NFA_RwI93ReadSingleBlock (UINT8 block_number)
924 {
925     tNFA_RW_OPERATION *p_msg;
926 
927     NFA_TRACE_API1 ("NFA_RwI93ReadSingleBlock (): block_number: 0x%02X", block_number);
928 
929     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
930     {
931         return (NFA_STATUS_WRONG_PROTOCOL);
932     }
933 
934     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
935     {
936         /* Fill in tNFA_RW_OPERATION struct */
937         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
938         p_msg->op        = NFA_RW_OP_I93_READ_SINGLE_BLOCK;
939 
940         p_msg->params.i93_cmd.first_block_number = block_number;
941 
942         nfa_sys_sendmsg (p_msg);
943 
944         return (NFA_STATUS_OK);
945     }
946 
947     return (NFA_STATUS_FAILED);
948 }
949 
950 /*******************************************************************************
951 **
952 ** Function         NFA_RwI93WriteSingleBlock
953 **
954 ** Description:
955 **      Send Write Single Block command to the activated ISO 15693 tag.
956 **
957 **      When the write operation has completed (or if an error occurs), the
958 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
959 **
960 ** Returns:
961 **      NFA_STATUS_OK if successfully initiated
962 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
963 **      NFA_STATUS_FAILED otherwise
964 **
965 *******************************************************************************/
NFA_RwI93WriteSingleBlock(UINT8 block_number,UINT8 * p_data)966 tNFA_STATUS NFA_RwI93WriteSingleBlock (UINT8 block_number,
967                                        UINT8 *p_data)
968 {
969     tNFA_RW_OPERATION *p_msg;
970 
971     NFA_TRACE_API1 ("NFA_RwI93WriteSingleBlock (): block_number: 0x%02X", block_number);
972 
973     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
974     {
975         return (NFA_STATUS_WRONG_PROTOCOL);
976     }
977 
978     /* we don't know block size of tag */
979     if (  (nfa_rw_cb.i93_block_size == 0)
980         ||(nfa_rw_cb.i93_num_block == 0)  )
981     {
982         return (NFA_STATUS_FAILED);
983     }
984 
985     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION) + nfa_rw_cb.i93_block_size))) != NULL)
986     {
987         /* Fill in tNFA_RW_OPERATION struct */
988         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
989         p_msg->op        = NFA_RW_OP_I93_WRITE_SINGLE_BLOCK;
990 
991         p_msg->params.i93_cmd.first_block_number = block_number;
992         p_msg->params.i93_cmd.p_data             = (UINT8*) (p_msg + 1);
993 
994         memcpy (p_msg->params.i93_cmd.p_data, p_data, nfa_rw_cb.i93_block_size);
995 
996         nfa_sys_sendmsg (p_msg);
997 
998         return (NFA_STATUS_OK);
999     }
1000 
1001     return (NFA_STATUS_FAILED);
1002 }
1003 
1004 /*******************************************************************************
1005 **
1006 ** Function         NFA_RwI93LockBlock
1007 **
1008 ** Description:
1009 **      Send Lock block command to the activated ISO 15693 tag.
1010 **
1011 **      When the operation has completed (or if an error occurs), the
1012 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1013 **
1014 ** Returns:
1015 **      NFA_STATUS_OK if successfully initiated
1016 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1017 **      NFA_STATUS_FAILED otherwise
1018 **
1019 *******************************************************************************/
NFA_RwI93LockBlock(UINT8 block_number)1020 tNFA_STATUS NFA_RwI93LockBlock (UINT8 block_number)
1021 {
1022     tNFA_RW_OPERATION *p_msg;
1023 
1024     NFA_TRACE_API1 ("NFA_RwI93LockBlock (): block_number: 0x%02X", block_number);
1025 
1026     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1027     {
1028         return (NFA_STATUS_WRONG_PROTOCOL);
1029     }
1030 
1031     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1032     {
1033         /* Fill in tNFA_RW_OPERATION struct */
1034         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1035         p_msg->op        = NFA_RW_OP_I93_LOCK_BLOCK;
1036 
1037         p_msg->params.i93_cmd.first_block_number = block_number;
1038 
1039         nfa_sys_sendmsg (p_msg);
1040 
1041         return (NFA_STATUS_OK);
1042     }
1043 
1044     return (NFA_STATUS_FAILED);
1045 }
1046 
1047 /*******************************************************************************
1048 **
1049 ** Function         NFA_RwI93ReadMultipleBlocks
1050 **
1051 ** Description:
1052 **      Send Read Multiple Block command to the activated ISO 15693 tag.
1053 **
1054 **      Data is returned to the application using the NFA_DATA_EVT. When the read
1055 **      operation has completed, or if an error occurs, the app will be notified with
1056 **      NFA_I93_CMD_CPLT_EVT.
1057 **
1058 ** Returns:
1059 **      NFA_STATUS_OK if successfully initiated
1060 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1061 **      NFA_STATUS_FAILED otherwise
1062 **
1063 *******************************************************************************/
NFA_RwI93ReadMultipleBlocks(UINT8 first_block_number,UINT16 number_blocks)1064 tNFA_STATUS NFA_RwI93ReadMultipleBlocks (UINT8  first_block_number,
1065                                          UINT16 number_blocks)
1066 {
1067     tNFA_RW_OPERATION *p_msg;
1068 
1069     NFA_TRACE_API2 ("NFA_RwI93ReadMultipleBlocks(): %d, %d", first_block_number, number_blocks);
1070 
1071     if ( nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1072     {
1073         return (NFA_STATUS_WRONG_PROTOCOL);
1074     }
1075 
1076     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1077     {
1078         /* Fill in tNFA_RW_OPERATION struct */
1079         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1080         p_msg->op        = NFA_RW_OP_I93_READ_MULTI_BLOCK;
1081 
1082         p_msg->params.i93_cmd.first_block_number = first_block_number;
1083         p_msg->params.i93_cmd.number_blocks      = number_blocks;
1084 
1085         nfa_sys_sendmsg (p_msg);
1086 
1087         return (NFA_STATUS_OK);
1088     }
1089 
1090     return (NFA_STATUS_FAILED);
1091 }
1092 
1093 /*******************************************************************************
1094 **
1095 ** Function         NFA_RwI93WriteMultipleBlocks
1096 **
1097 ** Description:
1098 **      Send Write Multiple Block command to the activated ISO 15693 tag.
1099 **
1100 **      When the write operation has completed (or if an error occurs), the
1101 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1102 **
1103 ** Returns:
1104 **      NFA_STATUS_OK if successfully initiated
1105 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1106 **      NFA_STATUS_FAILED otherwise
1107 **
1108 *******************************************************************************/
NFA_RwI93WriteMultipleBlocks(UINT8 first_block_number,UINT16 number_blocks,UINT8 * p_data)1109 tNFA_STATUS NFA_RwI93WriteMultipleBlocks (UINT8  first_block_number,
1110                                           UINT16 number_blocks,
1111                                           UINT8 *p_data)
1112 {
1113     tNFA_RW_OPERATION *p_msg;
1114     UINT16      data_length;
1115 
1116     NFA_TRACE_API2 ("NFA_RwI93WriteMultipleBlocks (): %d, %d", first_block_number, number_blocks);
1117 
1118     if ( nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1119     {
1120         return (NFA_STATUS_WRONG_PROTOCOL);
1121     }
1122 
1123     /* we don't know block size of tag */
1124     if ((nfa_rw_cb.i93_block_size == 0) || (nfa_rw_cb.i93_num_block == 0))
1125     {
1126         return (NFA_STATUS_FAILED);
1127     }
1128 
1129     data_length = nfa_rw_cb.i93_block_size * number_blocks;
1130 
1131     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION) + data_length))) != NULL)
1132     {
1133         /* Fill in tNFA_RW_OPERATION struct */
1134         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1135         p_msg->op        = NFA_RW_OP_I93_WRITE_MULTI_BLOCK;
1136 
1137         p_msg->params.i93_cmd.first_block_number = first_block_number;
1138         p_msg->params.i93_cmd.number_blocks      = number_blocks;
1139         p_msg->params.i93_cmd.p_data             = (UINT8*) (p_msg + 1);
1140 
1141         memcpy (p_msg->params.i93_cmd.p_data, p_data, data_length);
1142 
1143         nfa_sys_sendmsg (p_msg);
1144 
1145         return (NFA_STATUS_OK);
1146     }
1147 
1148     return (NFA_STATUS_FAILED);
1149 }
1150 
1151 /*******************************************************************************
1152 **
1153 ** Function         NFA_RwI93Select
1154 **
1155 ** Description:
1156 **      Send Select command to the activated ISO 15693 tag.
1157 **
1158 **      UID[0]: 0xE0, MSB
1159 **      UID[1]: IC Mfg Code
1160 **      ...
1161 **      UID[7]: LSB
1162 **
1163 **      When the operation has completed (or if an error occurs), the
1164 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1165 **
1166 ** Returns:
1167 **      NFA_STATUS_OK if successfully initiated
1168 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1169 **      NFA_STATUS_FAILED otherwise
1170 **
1171 *******************************************************************************/
NFA_RwI93Select(UINT8 * p_uid)1172 tNFA_STATUS NFA_RwI93Select (UINT8 *p_uid)
1173 {
1174     tNFA_RW_OPERATION *p_msg;
1175 
1176     NFA_TRACE_API3 ("NFA_RwI93Select (): UID: [%02X%02X%02X...]", *(p_uid), *(p_uid+1), *(p_uid+2));
1177 
1178     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1179     {
1180         return (NFA_STATUS_WRONG_PROTOCOL);
1181     }
1182 
1183     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION) + I93_UID_BYTE_LEN))) != NULL)
1184     {
1185         /* Fill in tNFA_RW_OPERATION struct */
1186         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1187         p_msg->op        = NFA_RW_OP_I93_SELECT;
1188 
1189         p_msg->params.i93_cmd.p_data = (UINT8 *) (p_msg + 1);
1190         memcpy (p_msg->params.i93_cmd.p_data, p_uid, I93_UID_BYTE_LEN);
1191 
1192         nfa_sys_sendmsg (p_msg);
1193 
1194         return (NFA_STATUS_OK);
1195     }
1196 
1197     return (NFA_STATUS_FAILED);
1198 }
1199 
1200 /*******************************************************************************
1201 **
1202 ** Function         NFA_RwI93ResetToReady
1203 **
1204 ** Description:
1205 **      Send Reset to ready command to the activated ISO 15693 tag.
1206 **
1207 **      When the operation has completed (or if an error occurs), the
1208 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1209 **
1210 ** Returns:
1211 **      NFA_STATUS_OK if successfully initiated
1212 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1213 **      NFA_STATUS_FAILED otherwise
1214 **
1215 *******************************************************************************/
NFA_RwI93ResetToReady(void)1216 tNFA_STATUS NFA_RwI93ResetToReady (void)
1217 {
1218     tNFA_RW_OPERATION *p_msg;
1219 
1220     NFA_TRACE_API0 ("NFA_RwI93ResetToReady ()");
1221 
1222     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1223     {
1224         return (NFA_STATUS_WRONG_PROTOCOL);
1225     }
1226 
1227     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1228     {
1229         /* Fill in tNFA_RW_OPERATION struct */
1230         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1231         p_msg->op        = NFA_RW_OP_I93_RESET_TO_READY;
1232 
1233         nfa_sys_sendmsg (p_msg);
1234 
1235         return (NFA_STATUS_OK);
1236     }
1237 
1238     return (NFA_STATUS_FAILED);
1239 }
1240 
1241 /*******************************************************************************
1242 **
1243 ** Function         NFA_RwI93WriteAFI
1244 **
1245 ** Description:
1246 **      Send Write AFI command to the activated ISO 15693 tag.
1247 **
1248 **      When the operation has completed (or if an error occurs), the
1249 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1250 **
1251 ** Returns:
1252 **      NFA_STATUS_OK if successfully initiated
1253 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1254 **      NFA_STATUS_FAILED otherwise
1255 **
1256 *******************************************************************************/
NFA_RwI93WriteAFI(UINT8 afi)1257 tNFA_STATUS NFA_RwI93WriteAFI (UINT8 afi)
1258 {
1259     tNFA_RW_OPERATION *p_msg;
1260 
1261     NFA_TRACE_API1 ("NFA_RwI93WriteAFI (): AFI: 0x%02X", afi);
1262 
1263     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1264     {
1265         return (NFA_STATUS_WRONG_PROTOCOL);
1266     }
1267 
1268     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1269     {
1270         /* Fill in tNFA_RW_OPERATION struct */
1271         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1272         p_msg->op        = NFA_RW_OP_I93_WRITE_AFI;
1273 
1274         p_msg->params.i93_cmd.afi = afi;
1275 
1276         nfa_sys_sendmsg (p_msg);
1277 
1278         return (NFA_STATUS_OK);
1279     }
1280 
1281     return (NFA_STATUS_FAILED);
1282 }
1283 
1284 /*******************************************************************************
1285 **
1286 ** Function         NFA_RwI93LockAFI
1287 **
1288 ** Description:
1289 **      Send Lock AFI command to the activated ISO 15693 tag.
1290 **
1291 **      When the operation has completed (or if an error occurs), the
1292 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1293 **
1294 ** Returns:
1295 **      NFA_STATUS_OK if successfully initiated
1296 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1297 **      NFA_STATUS_FAILED otherwise
1298 **
1299 *******************************************************************************/
NFA_RwI93LockAFI(void)1300 tNFA_STATUS NFA_RwI93LockAFI (void)
1301 {
1302     tNFA_RW_OPERATION *p_msg;
1303 
1304     NFA_TRACE_API0 ("NFA_RwI93LockAFI ()");
1305 
1306     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1307     {
1308         return (NFA_STATUS_WRONG_PROTOCOL);
1309     }
1310 
1311     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1312     {
1313         /* Fill in tNFA_RW_OPERATION struct */
1314         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1315         p_msg->op        = NFA_RW_OP_I93_LOCK_AFI;
1316 
1317         nfa_sys_sendmsg (p_msg);
1318 
1319         return (NFA_STATUS_OK);
1320     }
1321 
1322     return (NFA_STATUS_FAILED);
1323 }
1324 
1325 /*******************************************************************************
1326 **
1327 ** Function         NFA_RwI93WriteDSFID
1328 **
1329 ** Description:
1330 **      Send Write DSFID command to the activated ISO 15693 tag.
1331 **
1332 **      When the operation has completed (or if an error occurs), the
1333 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1334 **
1335 ** Returns:
1336 **      NFA_STATUS_OK if successfully initiated
1337 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1338 **      NFA_STATUS_FAILED otherwise
1339 **
1340 *******************************************************************************/
NFA_RwI93WriteDSFID(UINT8 dsfid)1341 tNFA_STATUS NFA_RwI93WriteDSFID (UINT8 dsfid)
1342 {
1343     tNFA_RW_OPERATION *p_msg;
1344 
1345     NFA_TRACE_API1 ("NFA_RwI93WriteDSFID (): DSFID: 0x%02X", dsfid);
1346 
1347     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1348     {
1349         return (NFA_STATUS_WRONG_PROTOCOL);
1350     }
1351 
1352     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1353     {
1354         /* Fill in tNFA_RW_OPERATION struct */
1355         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1356         p_msg->op        = NFA_RW_OP_I93_WRITE_DSFID;
1357 
1358         p_msg->params.i93_cmd.dsfid = dsfid;
1359 
1360         nfa_sys_sendmsg (p_msg);
1361 
1362         return (NFA_STATUS_OK);
1363     }
1364 
1365     return (NFA_STATUS_FAILED);
1366 }
1367 
1368 /*******************************************************************************
1369 **
1370 ** Function         NFA_RwI93LockDSFID
1371 **
1372 ** Description:
1373 **      Send Lock DSFID command to the activated ISO 15693 tag.
1374 **
1375 **      When the operation has completed (or if an error occurs), the
1376 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1377 **
1378 ** Returns:
1379 **      NFA_STATUS_OK if successfully initiated
1380 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1381 **      NFA_STATUS_FAILED otherwise
1382 **
1383 *******************************************************************************/
NFA_RwI93LockDSFID(void)1384 tNFA_STATUS NFA_RwI93LockDSFID (void)
1385 {
1386     tNFA_RW_OPERATION *p_msg;
1387 
1388     NFA_TRACE_API0 ("NFA_RwI93LockDSFID ()");
1389 
1390     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1391     {
1392         return (NFA_STATUS_WRONG_PROTOCOL);
1393     }
1394 
1395     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1396     {
1397         /* Fill in tNFA_RW_OPERATION struct */
1398         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1399         p_msg->op        = NFA_RW_OP_I93_LOCK_DSFID;
1400 
1401         nfa_sys_sendmsg (p_msg);
1402 
1403         return (NFA_STATUS_OK);
1404     }
1405 
1406     return (NFA_STATUS_FAILED);
1407 }
1408 
1409 /*******************************************************************************
1410 **
1411 ** Function         NFA_RwI93GetSysInfo
1412 **
1413 ** Description:
1414 **      Send Get system information command to the activated ISO 15693 tag.
1415 **      If UID is provided then set UID[0]:MSB, ... UID[7]:LSB
1416 **
1417 **      When the operation has completed (or if an error occurs), the
1418 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
1419 **
1420 ** Returns:
1421 **      NFA_STATUS_OK if successfully initiated
1422 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1423 **      NFA_STATUS_FAILED otherwise
1424 **
1425 *******************************************************************************/
NFA_RwI93GetSysInfo(UINT8 * p_uid)1426 tNFA_STATUS NFA_RwI93GetSysInfo (UINT8 *p_uid)
1427 {
1428     tNFA_RW_OPERATION *p_msg;
1429 
1430     NFA_TRACE_API0 ("NFA_RwI93GetSysInfo ()");
1431 
1432     if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1433     {
1434         return (NFA_STATUS_WRONG_PROTOCOL);
1435     }
1436 
1437     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1438     {
1439         /* Fill in tNFA_RW_OPERATION struct */
1440         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1441         p_msg->op        = NFA_RW_OP_I93_GET_SYS_INFO;
1442 
1443         if (p_uid)
1444         {
1445             p_msg->params.i93_cmd.uid_present = TRUE;
1446             memcpy (p_msg->params.i93_cmd.uid, p_uid, I93_UID_BYTE_LEN);
1447         }
1448         else
1449         {
1450             p_msg->params.i93_cmd.uid_present = FALSE;
1451         }
1452 
1453         nfa_sys_sendmsg (p_msg);
1454 
1455         return (NFA_STATUS_OK);
1456     }
1457 
1458     return (NFA_STATUS_FAILED);
1459 }
1460 
1461 /*******************************************************************************
1462 **
1463 ** Function         NFA_RwI93GetMultiBlockSecurityStatus
1464 **
1465 ** Description:
1466 **      Send Get Multiple block security status command to the activated ISO 15693 tag.
1467 **
1468 **      Data is returned to the application using the NFA_DATA_EVT. When the read
1469 **      operation has completed, or if an error occurs, the app will be notified with
1470 **      NFA_I93_CMD_CPLT_EVT.
1471 **
1472 ** Returns:
1473 **      NFA_STATUS_OK if successfully initiated
1474 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
1475 **      NFA_STATUS_FAILED otherwise
1476 **
1477 *******************************************************************************/
NFA_RwI93GetMultiBlockSecurityStatus(UINT8 first_block_number,UINT16 number_blocks)1478 tNFA_STATUS NFA_RwI93GetMultiBlockSecurityStatus (UINT8  first_block_number,
1479                                                   UINT16 number_blocks)
1480 {
1481     tNFA_RW_OPERATION *p_msg;
1482 
1483     NFA_TRACE_API2 ("NFA_RwI93GetMultiBlockSecurityStatus(): %d, %d", first_block_number, number_blocks);
1484 
1485     if ( nfa_rw_cb.protocol != NFC_PROTOCOL_15693)
1486     {
1487         return (NFA_STATUS_WRONG_PROTOCOL);
1488     }
1489 
1490     if ((p_msg = (tNFA_RW_OPERATION *) GKI_getbuf ((UINT16) (sizeof (tNFA_RW_OPERATION)))) != NULL)
1491     {
1492         /* Fill in tNFA_RW_OPERATION struct */
1493         p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1494         p_msg->op        = NFA_RW_OP_I93_GET_MULTI_BLOCK_STATUS;
1495 
1496         p_msg->params.i93_cmd.first_block_number = first_block_number;
1497         p_msg->params.i93_cmd.number_blocks      = number_blocks;
1498 
1499         nfa_sys_sendmsg (p_msg);
1500 
1501         return (NFA_STATUS_OK);
1502     }
1503 
1504     return (NFA_STATUS_FAILED);
1505 }
1506