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