blob: a55962a866741f05a31b33243cb0e8e0723b93b1 [file] [log] [blame]
nxpandroidc7611652015-09-23 16:42:05 +05301/******************************************************************************
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
nxpandroidc7611652015-09-23 16:42:05 +053019/******************************************************************************
20 *
21 * NFA interface for tag Reader/Writer
22 *
23 ******************************************************************************/
24#include <string.h>
nxf24591c1cbeab2018-02-21 17:32:26 +053025
26#include <android-base/stringprintf.h>
27#include <base/logging.h>
28
nxpandroidc7611652015-09-23 16:42:05 +053029#include "nfa_api.h"
nxpandroidc7611652015-09-23 16:42:05 +053030#include "nfa_rw_int.h"
nxf24591c1cbeab2018-02-21 17:32:26 +053031
32using android::base::StringPrintf;
33
34extern bool nfc_debug_enabled;
nxpandroidc7611652015-09-23 16:42:05 +053035
36/*****************************************************************************
37** Constants
38*****************************************************************************/
39
nxpandroidc7611652015-09-23 16:42:05 +053040/*****************************************************************************
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
nxpandroid8f6d0532017-07-12 18:25:30 +053057** and NFA_RwWriteNDef will perform NDEF detection internally
58** if not performed already. This API may be called to get a
nxpandroidc7611652015-09-23 16:42:05 +053059** 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*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +053067tNFA_STATUS NFA_RwDetectNDef(void) {
68 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +053069
nxf24591c1cbeab2018-02-21 17:32:26 +053070 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +053071
nxpandroid8f6d0532017-07-12 18:25:30 +053072 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
73 if (p_msg != NULL) {
74 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
75 p_msg->op = NFA_RW_OP_DETECT_NDEF;
nxpandroidc7611652015-09-23 16:42:05 +053076
nxpandroid8f6d0532017-07-12 18:25:30 +053077 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +053078
nxpandroid8f6d0532017-07-12 18:25:30 +053079 return (NFA_STATUS_OK);
80 }
nxpandroidc7611652015-09-23 16:42:05 +053081
nxpandroid8f6d0532017-07-12 18:25:30 +053082 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +053083}
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),
nxpandroid8f6d0532017-07-12 18:25:30 +053095** 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.).
nxpandroidc7611652015-09-23 16:42:05 +053098**
99** Upon receiving the NDEF message, the message will be sent to
100** the handler registered with NFA_RegisterNDefTypeHandler or
nxpandroid8f6d0532017-07-12 18:25:30 +0530101** NFA_RequestExclusiveRfControl (if exclusive RF mode is
102** active)
nxpandroidc7611652015-09-23 16:42:05 +0530103**
104** Returns:
105** NFA_STATUS_OK if successfully initiated
106** NFC_STATUS_REFUSED if tag does not support NDEF
nxpandroid8f6d0532017-07-12 18:25:30 +0530107** NFC_STATUS_NOT_INITIALIZED if NULL NDEF was detected on the
108** tag
nxpandroidc7611652015-09-23 16:42:05 +0530109** NFA_STATUS_FAILED otherwise
110**
111*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530112tNFA_STATUS NFA_RwReadNDef(void) {
113 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530114
nxf24591c1cbeab2018-02-21 17:32:26 +0530115 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +0530116
nxpandroid8f6d0532017-07-12 18:25:30 +0530117 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
118 if (p_msg != NULL) {
119 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
120 p_msg->op = NFA_RW_OP_READ_NDEF;
nxpandroidc7611652015-09-23 16:42:05 +0530121
nxpandroid8f6d0532017-07-12 18:25:30 +0530122 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530123
nxpandroid8f6d0532017-07-12 18:25:30 +0530124 return (NFA_STATUS_OK);
125 }
nxpandroidc7611652015-09-23 16:42:05 +0530126
nxpandroid8f6d0532017-07-12 18:25:30 +0530127 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530128}
129
nxpandroidc7611652015-09-23 16:42:05 +0530130/*******************************************************************************
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*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530151tNFA_STATUS NFA_RwWriteNDef(uint8_t* p_data, uint32_t len) {
152 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530153
nxf24591c1cbeab2018-02-21 17:32:26 +0530154 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("ndef len: %i", len);
nxpandroidc7611652015-09-23 16:42:05 +0530155
nxpandroid8f6d0532017-07-12 18:25:30 +0530156 /* Validate parameters */
157 if (p_data == NULL) return (NFA_STATUS_INVALID_PARAM);
nxpandroidc7611652015-09-23 16:42:05 +0530158
nxpandroid8f6d0532017-07-12 18:25:30 +0530159 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
160 if (p_msg != NULL) {
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);
nxpandroidc7611652015-09-23 16:42:05 +0530166
nxpandroid8f6d0532017-07-12 18:25:30 +0530167 return (NFA_STATUS_OK);
168 }
nxpandroidc7611652015-09-23 16:42:05 +0530169
nxpandroid8f6d0532017-07-12 18:25:30 +0530170 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530171}
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*****************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530189tNFA_STATUS NFA_RwPresenceCheck(tNFA_RW_PRES_CHK_OPTION option) {
190 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530191
nxf24591c1cbeab2018-02-21 17:32:26 +0530192 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +0530193
nxpandroid8f6d0532017-07-12 18:25:30 +0530194 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
195 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530199
nxpandroid8f6d0532017-07-12 18:25:30 +0530200 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530201
nxpandroid8f6d0532017-07-12 18:25:30 +0530202 return (NFA_STATUS_OK);
203 }
nxpandroidc7611652015-09-23 16:42:05 +0530204
nxpandroid8f6d0532017-07-12 18:25:30 +0530205 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530206}
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*****************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530222tNFA_STATUS NFA_RwFormatTag(void) {
223 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530224
nxf24591c1cbeab2018-02-21 17:32:26 +0530225 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +0530226
nxpandroid8f6d0532017-07-12 18:25:30 +0530227 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
228 if (p_msg != NULL) {
229 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
230 p_msg->op = NFA_RW_OP_FORMAT_TAG;
nxpandroidc7611652015-09-23 16:42:05 +0530231
nxpandroid8f6d0532017-07-12 18:25:30 +0530232 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530233
nxpandroid8f6d0532017-07-12 18:25:30 +0530234 return (NFA_STATUS_OK);
235 }
nxpandroidc7611652015-09-23 16:42:05 +0530236
nxpandroid8f6d0532017-07-12 18:25:30 +0530237 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530238}
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
nxf24591c1cbeab2018-02-21 17:32:26 +0530252** NFA_STATUS_REJECTED if protocol is not T1/T2/T5T
253** (or) if hard lock is not requested for protocol T5T
nxpandroidc7611652015-09-23 16:42:05 +0530254** NFA_STATUS_FAILED otherwise
255**
256*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530257tNFA_STATUS NFA_RwSetTagReadOnly(bool b_hard_lock) {
258 tNFA_RW_OPERATION* p_msg;
259 tNFC_PROTOCOL protocol = nfa_rw_cb.protocol;
nxpandroidc7611652015-09-23 16:42:05 +0530260
nxpandroid8f6d0532017-07-12 18:25:30 +0530261 if ((protocol != NFC_PROTOCOL_T1T) && (protocol != NFC_PROTOCOL_T2T) &&
nxf24591c1cbeab2018-02-21 17:32:26 +0530262 (protocol != NFC_PROTOCOL_T5T) && (protocol != NFC_PROTOCOL_ISO_DEP) &&
nxpandroid8f6d0532017-07-12 18:25:30 +0530263 (protocol != NFC_PROTOCOL_T3T)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530264 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
265 "Cannot Configure as read only for Protocol: "
nxpandroid8f6d0532017-07-12 18:25:30 +0530266 "%d",
267 protocol);
268 return (NFA_STATUS_REJECTED);
269 }
nxpandroidc7611652015-09-23 16:42:05 +0530270
nxf24591c1cbeab2018-02-21 17:32:26 +0530271 if ((!b_hard_lock && (protocol == NFC_PROTOCOL_T5T)) ||
nxpandroid8f6d0532017-07-12 18:25:30 +0530272 (b_hard_lock && (protocol == NFC_PROTOCOL_ISO_DEP))) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530273 DLOG_IF(INFO, nfc_debug_enabled)
274 << StringPrintf("Cannot %s for Protocol: %d",
275 b_hard_lock ? "Hard lock" : "Soft lock", protocol);
nxpandroid8f6d0532017-07-12 18:25:30 +0530276 return (NFA_STATUS_REJECTED);
277 }
nxpandroidc7611652015-09-23 16:42:05 +0530278
nxf24591c1cbeab2018-02-21 17:32:26 +0530279 DLOG_IF(INFO, nfc_debug_enabled)
280 << StringPrintf("%s", b_hard_lock ? "Hard lock" : "Soft lock");
nxpandroidc7611652015-09-23 16:42:05 +0530281
nxpandroid8f6d0532017-07-12 18:25:30 +0530282 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
283 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530288
nxpandroid8f6d0532017-07-12 18:25:30 +0530289 nfa_sys_sendmsg(p_msg);
290 return (NFA_STATUS_OK);
291 }
292 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530293}
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**
nxpandroid8f6d0532017-07-12 18:25:30 +0530321** 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/
nxpandroidc7611652015-09-23 16:42:05 +0530326** Lock bytes before issuing a write-request.
327**
328** Returns:
329** NFA_STATUS_OK if successfully initiated
nxpandroid8f6d0532017-07-12 18:25:30 +0530330** NFC_STATUS_REFUSED if tlv_type is NDEF & tag won't support
331** NDEF
nxpandroidc7611652015-09-23 16:42:05 +0530332** NFA_STATUS_FAILED otherwise
333**
334*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530335tNFA_STATUS NFA_RwLocateTlv(uint8_t tlv_type) {
336 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530337
nxf24591c1cbeab2018-02-21 17:32:26 +0530338 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +0530339
nxpandroid8f6d0532017-07-12 18:25:30 +0530340 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
341 if (p_msg != NULL) {
342 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
nxpandroidc7611652015-09-23 16:42:05 +0530343
nxpandroid8f6d0532017-07-12 18:25:30 +0530344 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);
nxpandroidc7611652015-09-23 16:42:05 +0530352
nxpandroid8f6d0532017-07-12 18:25:30 +0530353 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530354
nxpandroid8f6d0532017-07-12 18:25:30 +0530355 return (NFA_STATUS_OK);
356 }
nxpandroidc7611652015-09-23 16:42:05 +0530357
nxpandroid8f6d0532017-07-12 18:25:30 +0530358 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530359}
360
361/*******************************************************************************
362**
363** Function NFA_RwT1tRid
364**
365** Description:
366** Send a RID command to the activated Type 1 tag.
367**
nxpandroid8f6d0532017-07-12 18:25:30 +0530368** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530371**
372** Returns:
373** NFA_STATUS_OK if successfully initiated
374** NFA_STATUS_FAILED otherwise
375**
376*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530377tNFA_STATUS NFA_RwT1tRid(void) {
378 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530379
nxpandroid8f6d0532017-07-12 18:25:30 +0530380 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
381 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530385
nxpandroid8f6d0532017-07-12 18:25:30 +0530386 nfa_sys_sendmsg(p_msg);
387 return (NFA_STATUS_OK);
388 }
389 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530390}
391
392/*******************************************************************************
393**
394** Function NFA_RwT1tReadAll
395**
396** Description:
397** Send a RALL command to the activated Type 1 tag.
398**
nxpandroid8f6d0532017-07-12 18:25:30 +0530399** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530402**
403** Returns:
404** NFA_STATUS_OK if successfully initiated
405** NFA_STATUS_FAILED otherwise
406**
407*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530408tNFA_STATUS NFA_RwT1tReadAll(void) {
409 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530410
nxpandroid8f6d0532017-07-12 18:25:30 +0530411 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
412 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530416
nxpandroid8f6d0532017-07-12 18:25:30 +0530417 nfa_sys_sendmsg(p_msg);
418 return (NFA_STATUS_OK);
419 }
420 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530421}
422
423/*******************************************************************************
424**
425** Function NFA_RwT1tRead
426**
427** Description:
428** Send a READ command to the activated Type 1 tag.
429**
nxpandroid8f6d0532017-07-12 18:25:30 +0530430** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530433**
434** Returns:
435** NFA_STATUS_OK if successfully initiated
436** NFA_STATUS_FAILED otherwise
437**
438*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530439tNFA_STATUS NFA_RwT1tRead(uint8_t block_number, uint8_t index) {
440 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530441
nxpandroid8f6d0532017-07-12 18:25:30 +0530442 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
443 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530449
nxpandroid8f6d0532017-07-12 18:25:30 +0530450 nfa_sys_sendmsg(p_msg);
451 return (NFA_STATUS_OK);
452 }
453 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530454}
455
456/*******************************************************************************
457**
458** Function NFA_RwT1tWrite
459**
460** Description:
461** Send a WRITE command to the activated Type 1 tag.
462**
nxpandroid8f6d0532017-07-12 18:25:30 +0530463** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530466**
467** Returns:
468** NFA_STATUS_OK if successfully initiated
469** NFA_STATUS_FAILED otherwise
470**
471*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530472tNFA_STATUS NFA_RwT1tWrite(uint8_t block_number, uint8_t index, uint8_t data,
473 bool b_erase) {
474 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530475
nxpandroid8f6d0532017-07-12 18:25:30 +0530476 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
477 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530485
nxpandroid8f6d0532017-07-12 18:25:30 +0530486 nfa_sys_sendmsg(p_msg);
487 return (NFA_STATUS_OK);
488 }
489 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530490}
491
492/*******************************************************************************
493**
494** Function NFA_RwT1tReadSeg
495**
496** Description:
497** Send a RSEG command to the activated Type 1 tag.
498**
nxpandroid8f6d0532017-07-12 18:25:30 +0530499** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530502**
503** Returns:
504** NFA_STATUS_OK if successfully initiated
505** NFA_STATUS_FAILED otherwise
506**
507*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530508tNFA_STATUS NFA_RwT1tReadSeg(uint8_t segment_number) {
509 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530510
nxpandroid8f6d0532017-07-12 18:25:30 +0530511 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
512 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530517
nxpandroid8f6d0532017-07-12 18:25:30 +0530518 nfa_sys_sendmsg(p_msg);
519 return (NFA_STATUS_OK);
520 }
521 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530522}
523
524/*******************************************************************************
525**
526** Function NFA_RwT1tRead8
527**
528** Description:
529** Send a READ8 command to the activated Type 1 tag.
530**
nxpandroid8f6d0532017-07-12 18:25:30 +0530531** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530534**
535** Returns:
536** NFA_STATUS_OK if successfully initiated
537** NFA_STATUS_FAILED otherwise
538**
539*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530540tNFA_STATUS NFA_RwT1tRead8(uint8_t block_number) {
541 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530542
nxpandroid8f6d0532017-07-12 18:25:30 +0530543 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
544 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530549
nxpandroid8f6d0532017-07-12 18:25:30 +0530550 nfa_sys_sendmsg(p_msg);
551 return (NFA_STATUS_OK);
552 }
553 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530554}
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**
nxpandroid8f6d0532017-07-12 18:25:30 +0530563** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530566**
567** Returns:
568** NFA_STATUS_OK if successfully initiated
569** NFA_STATUS_FAILED otherwise
570**
571*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530572tNFA_STATUS NFA_RwT1tWrite8(uint8_t block_number, uint8_t* p_data,
573 bool b_erase) {
574 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530575
nxpandroid8f6d0532017-07-12 18:25:30 +0530576 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
577 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530583
nxpandroid8f6d0532017-07-12 18:25:30 +0530584 memcpy(p_msg->params.t1t_write.p_block_data, p_data, 8);
nxpandroidc7611652015-09-23 16:42:05 +0530585
nxpandroid8f6d0532017-07-12 18:25:30 +0530586 nfa_sys_sendmsg(p_msg);
587 return (NFA_STATUS_OK);
588 }
589 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530590}
591
592/*******************************************************************************
593**
594** Function NFA_RwT2tRead
595**
596** Description:
597** Send a READ command to the activated Type 2 tag.
598**
nxpandroid8f6d0532017-07-12 18:25:30 +0530599** 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.
nxpandroidc7611652015-09-23 16:42:05 +0530602**
603** Returns:
604** NFA_STATUS_OK if successfully initiated
605** NFA_STATUS_FAILED otherwise
606**
607*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530608tNFA_STATUS NFA_RwT2tRead(uint8_t block_number) {
609 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530610
nxf24591c1cbeab2018-02-21 17:32:26 +0530611 DLOG_IF(INFO, nfc_debug_enabled)
612 << StringPrintf("Block to read: %d", block_number);
nxpandroidc7611652015-09-23 16:42:05 +0530613
nxpandroid8f6d0532017-07-12 18:25:30 +0530614 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
615 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530620
nxpandroid8f6d0532017-07-12 18:25:30 +0530621 nfa_sys_sendmsg(p_msg);
622 return (NFA_STATUS_OK);
623 }
624 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530625}
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*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530642tNFA_STATUS NFA_RwT2tWrite(uint8_t block_number, uint8_t* p_data) {
643 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530644
nxf24591c1cbeab2018-02-21 17:32:26 +0530645 DLOG_IF(INFO, nfc_debug_enabled)
646 << StringPrintf("Block to write: %d", block_number);
nxpandroidc7611652015-09-23 16:42:05 +0530647
nxpandroid8f6d0532017-07-12 18:25:30 +0530648 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
649 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530653
nxpandroid8f6d0532017-07-12 18:25:30 +0530654 p_msg->params.t2t_write.block_number = block_number;
nxpandroidc7611652015-09-23 16:42:05 +0530655
nxpandroid8f6d0532017-07-12 18:25:30 +0530656 memcpy(p_msg->params.t2t_write.p_block_data, p_data, 4);
nxpandroidc7611652015-09-23 16:42:05 +0530657
nxpandroid8f6d0532017-07-12 18:25:30 +0530658 nfa_sys_sendmsg(p_msg);
659 return (NFA_STATUS_OK);
660 }
661 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530662}
663
664/*******************************************************************************
665**
666** Function NFA_RwT2tSectorSelect
667**
668** Description:
669** Send SECTOR SELECT command to the activated Type 2 tag.
670**
nxpandroid8f6d0532017-07-12 18:25:30 +0530671** When the sector select operation has completed (or if an error occurs),
672** the app will be notified with NFA_SECTOR_SELECT_CPLT_EVT.
nxpandroidc7611652015-09-23 16:42:05 +0530673**
674** Returns:
675** NFA_STATUS_OK if successfully initiated
676** NFA_STATUS_FAILED otherwise
677**
678*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530679tNFA_STATUS NFA_RwT2tSectorSelect(uint8_t sector_number) {
680 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530681
nxf24591c1cbeab2018-02-21 17:32:26 +0530682 DLOG_IF(INFO, nfc_debug_enabled)
683 << StringPrintf("sector to select: %d", sector_number);
nxpandroidc7611652015-09-23 16:42:05 +0530684
nxpandroid8f6d0532017-07-12 18:25:30 +0530685 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
686 if (p_msg != NULL) {
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;
nxpandroidc7611652015-09-23 16:42:05 +0530690
nxpandroid8f6d0532017-07-12 18:25:30 +0530691 p_msg->params.t2t_sector_select.sector_number = sector_number;
nxpandroidc7611652015-09-23 16:42:05 +0530692
nxpandroid8f6d0532017-07-12 18:25:30 +0530693 nfa_sys_sendmsg(p_msg);
694 return (NFA_STATUS_OK);
695 }
696 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530697}
698
699/*******************************************************************************
700**
701** Function NFA_RwT3tRead
702**
703** Description:
704** Send a CHECK (read) command to the activated Type 3 tag.
705**
nxpandroid8f6d0532017-07-12 18:25:30 +0530706** Data is returned to the application using the NFA_DATA_EVT. When the
707** read operation has completed, or if an error occurs, the app will be
708** notified with NFA_READ_CPLT_EVT.
nxpandroidc7611652015-09-23 16:42:05 +0530709**
710** Returns:
711** NFA_STATUS_OK if successfully initiated
712** NFA_STATUS_FAILED otherwise
713**
714*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530715tNFA_STATUS NFA_RwT3tRead(uint8_t num_blocks, tNFA_T3T_BLOCK_DESC* t3t_blocks) {
716 tNFA_RW_OPERATION* p_msg;
717 uint8_t* p_block_desc;
nxpandroidc7611652015-09-23 16:42:05 +0530718
nxf24591c1cbeab2018-02-21 17:32:26 +0530719 DLOG_IF(INFO, nfc_debug_enabled)
720 << StringPrintf("num_blocks to read: %i", num_blocks);
nxpandroidc7611652015-09-23 16:42:05 +0530721
nxpandroid8f6d0532017-07-12 18:25:30 +0530722 /* Validate parameters */
723 if ((num_blocks == 0) || (t3t_blocks == NULL))
724 return (NFA_STATUS_INVALID_PARAM);
nxpandroidc7611652015-09-23 16:42:05 +0530725
nxpandroid8f6d0532017-07-12 18:25:30 +0530726 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(
727 sizeof(tNFA_RW_OPERATION) + (num_blocks * sizeof(tNFA_T3T_BLOCK_DESC))));
728 if (p_msg != NULL) {
729 /* point to area after tNFA_RW_OPERATION */
730 p_block_desc = (uint8_t*)(p_msg + 1);
nxpandroidc7611652015-09-23 16:42:05 +0530731
nxpandroid8f6d0532017-07-12 18:25:30 +0530732 /* Fill in tNFA_RW_OPERATION struct */
733 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
734 p_msg->op = NFA_RW_OP_T3T_READ;
nxpandroidc7611652015-09-23 16:42:05 +0530735
nxpandroid8f6d0532017-07-12 18:25:30 +0530736 p_msg->params.t3t_read.num_blocks = num_blocks;
737 p_msg->params.t3t_read.p_block_desc = (tNFA_T3T_BLOCK_DESC*)p_block_desc;
nxpandroidc7611652015-09-23 16:42:05 +0530738
nxpandroid8f6d0532017-07-12 18:25:30 +0530739 /* Copy block descriptor list */
740 memcpy(p_block_desc, t3t_blocks,
741 (num_blocks * sizeof(tNFA_T3T_BLOCK_DESC)));
nxpandroidc7611652015-09-23 16:42:05 +0530742
nxpandroid8f6d0532017-07-12 18:25:30 +0530743 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530744
nxpandroid8f6d0532017-07-12 18:25:30 +0530745 return (NFA_STATUS_OK);
746 }
nxpandroidc7611652015-09-23 16:42:05 +0530747
nxpandroid8f6d0532017-07-12 18:25:30 +0530748 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530749}
750
751/*******************************************************************************
752**
753** Function NFA_RwT3tWrite
754**
755** Description:
756** Send an UPDATE (write) command to the activated Type 3 tag.
757**
758** When the write operation has completed (or if an error occurs), the
759** app will be notified with NFA_WRITE_CPLT_EVT.
760**
761** Returns:
762** NFA_STATUS_OK if successfully initiated
763** NFA_STATUS_FAILED otherwise
764**
765*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530766tNFA_STATUS NFA_RwT3tWrite(uint8_t num_blocks, tNFA_T3T_BLOCK_DESC* t3t_blocks,
767 uint8_t* p_data) {
768 tNFA_RW_OPERATION* p_msg;
nxf24591c1cbeab2018-02-21 17:32:26 +0530769 uint8_t *p_block_desc, *p_data_area;
nxpandroidc7611652015-09-23 16:42:05 +0530770
nxf24591c1cbeab2018-02-21 17:32:26 +0530771 DLOG_IF(INFO, nfc_debug_enabled)
772 << StringPrintf("num_blocks to write: %i", num_blocks);
nxpandroidc7611652015-09-23 16:42:05 +0530773
nxpandroid8f6d0532017-07-12 18:25:30 +0530774 /* Validate parameters */
775 if ((num_blocks == 0) || (t3t_blocks == NULL) | (p_data == NULL))
776 return (NFA_STATUS_INVALID_PARAM);
nxpandroidc7611652015-09-23 16:42:05 +0530777
nxpandroid8f6d0532017-07-12 18:25:30 +0530778 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
779 (uint16_t)(sizeof(tNFA_RW_OPERATION) +
780 (num_blocks * (sizeof(tNFA_T3T_BLOCK_DESC) + 16))));
781 if (p_msg != NULL) {
782 /* point to block descriptor and data areas after tNFA_RW_OPERATION */
783 p_block_desc = (uint8_t*)(p_msg + 1);
784 p_data_area = p_block_desc + (num_blocks * (sizeof(tNFA_T3T_BLOCK_DESC)));
nxpandroidc7611652015-09-23 16:42:05 +0530785
nxpandroid8f6d0532017-07-12 18:25:30 +0530786 /* Fill in tNFA_RW_OPERATION struct */
787 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
788 p_msg->op = NFA_RW_OP_T3T_WRITE;
nxpandroidc7611652015-09-23 16:42:05 +0530789
nxpandroid8f6d0532017-07-12 18:25:30 +0530790 p_msg->params.t3t_write.num_blocks = num_blocks;
791 p_msg->params.t3t_write.p_block_desc = (tNFA_T3T_BLOCK_DESC*)p_block_desc;
792 p_msg->params.t3t_write.p_block_data = p_data_area;
nxpandroidc7611652015-09-23 16:42:05 +0530793
nxpandroid8f6d0532017-07-12 18:25:30 +0530794 /* Copy block descriptor list */
795 memcpy(p_block_desc, t3t_blocks,
796 (num_blocks * sizeof(tNFA_T3T_BLOCK_DESC)));
nxpandroidc7611652015-09-23 16:42:05 +0530797
nxpandroid8f6d0532017-07-12 18:25:30 +0530798 /* Copy data */
799 memcpy(p_data_area, p_data, (num_blocks * 16));
nxpandroidc7611652015-09-23 16:42:05 +0530800
nxpandroid8f6d0532017-07-12 18:25:30 +0530801 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530802
nxpandroid8f6d0532017-07-12 18:25:30 +0530803 return (NFA_STATUS_OK);
804 }
nxpandroidc7611652015-09-23 16:42:05 +0530805
nxpandroid8f6d0532017-07-12 18:25:30 +0530806 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530807}
808
809/*******************************************************************************
810**
811** Function NFA_RwI93Inventory
812**
813** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +0530814** Send Inventory command to the activated ISO T5T tag with/without AFI
nxpandroidc7611652015-09-23 16:42:05 +0530815** If UID is provided then set UID[0]:MSB, ... UID[7]:LSB
816**
817** When the operation has completed (or if an error occurs), the
818** app will be notified with NFA_I93_CMD_CPLT_EVT.
819**
820** Returns:
821** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +0530822** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +0530823** NFA_STATUS_FAILED otherwise
824**
825*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530826tNFA_STATUS NFA_RwI93Inventory(bool afi_present, uint8_t afi, uint8_t* p_uid) {
827 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530828
nxf24591c1cbeab2018-02-21 17:32:26 +0530829 DLOG_IF(INFO, nfc_debug_enabled)
830 << StringPrintf("afi_present:%d, AFI: 0x%02X", afi_present, afi);
nxpandroidc7611652015-09-23 16:42:05 +0530831
nxf24591c1cbeab2018-02-21 17:32:26 +0530832 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530833 return (NFA_STATUS_WRONG_PROTOCOL);
834 }
835
836 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
837 if (p_msg != NULL) {
838 /* Fill in tNFA_RW_OPERATION struct */
839 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
840 p_msg->op = NFA_RW_OP_I93_INVENTORY;
841
842 p_msg->params.i93_cmd.afi_present = afi_present;
843 p_msg->params.i93_cmd.afi = afi;
844
845 if (p_uid) {
846 p_msg->params.i93_cmd.uid_present = true;
847 memcpy(p_msg->params.i93_cmd.uid, p_uid, I93_UID_BYTE_LEN);
848 } else {
849 p_msg->params.i93_cmd.uid_present = false;
nxpandroidc7611652015-09-23 16:42:05 +0530850 }
851
nxpandroid8f6d0532017-07-12 18:25:30 +0530852 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530853
nxpandroid8f6d0532017-07-12 18:25:30 +0530854 return (NFA_STATUS_OK);
855 }
nxpandroidc7611652015-09-23 16:42:05 +0530856
nxpandroid8f6d0532017-07-12 18:25:30 +0530857 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530858}
859
860/*******************************************************************************
861**
862** Function NFA_RwI93StayQuiet
863**
864** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +0530865** Send Stay Quiet command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +0530866**
867** When the operation has completed (or if an error occurs), the
868** app will be notified with NFA_I93_CMD_CPLT_EVT.
869**
870** Returns:
871** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +0530872** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +0530873** NFA_STATUS_FAILED otherwise
874**
875*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530876tNFA_STATUS NFA_RwI93StayQuiet(void) {
877 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530878
nxf24591c1cbeab2018-02-21 17:32:26 +0530879 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +0530880
nxf24591c1cbeab2018-02-21 17:32:26 +0530881 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530882 return (NFA_STATUS_WRONG_PROTOCOL);
883 }
nxpandroidc7611652015-09-23 16:42:05 +0530884
nxpandroid8f6d0532017-07-12 18:25:30 +0530885 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
886 if (p_msg != NULL) {
887 /* Fill in tNFA_RW_OPERATION struct */
888 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
889 p_msg->op = NFA_RW_OP_I93_STAY_QUIET;
nxpandroidc7611652015-09-23 16:42:05 +0530890
nxpandroid8f6d0532017-07-12 18:25:30 +0530891 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530892
nxpandroid8f6d0532017-07-12 18:25:30 +0530893 return (NFA_STATUS_OK);
894 }
nxpandroidc7611652015-09-23 16:42:05 +0530895
nxpandroid8f6d0532017-07-12 18:25:30 +0530896 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530897}
898
899/*******************************************************************************
900**
901** Function NFA_RwI93ReadSingleBlock
902**
903** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +0530904** Send Read Single Block command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +0530905**
nxpandroid8f6d0532017-07-12 18:25:30 +0530906** Data is returned to the application using the NFA_DATA_EVT. When the
907** read operation has completed, or if an error occurs, the app will be
908** notified with NFA_I93_CMD_CPLT_EVT.
nxpandroidc7611652015-09-23 16:42:05 +0530909**
910** Returns:
911** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +0530912** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +0530913** NFA_STATUS_FAILED otherwise
914**
915*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530916tNFA_STATUS NFA_RwI93ReadSingleBlock(uint8_t block_number) {
917 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530918
nxf24591c1cbeab2018-02-21 17:32:26 +0530919 DLOG_IF(INFO, nfc_debug_enabled)
920 << StringPrintf("block_number: 0x%02X", block_number);
nxpandroidc7611652015-09-23 16:42:05 +0530921
nxf24591c1cbeab2018-02-21 17:32:26 +0530922 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530923 return (NFA_STATUS_WRONG_PROTOCOL);
924 }
nxpandroidc7611652015-09-23 16:42:05 +0530925
nxpandroid8f6d0532017-07-12 18:25:30 +0530926 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
927 if (p_msg != NULL) {
928 /* Fill in tNFA_RW_OPERATION struct */
929 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
930 p_msg->op = NFA_RW_OP_I93_READ_SINGLE_BLOCK;
nxpandroidc7611652015-09-23 16:42:05 +0530931
nxpandroid8f6d0532017-07-12 18:25:30 +0530932 p_msg->params.i93_cmd.first_block_number = block_number;
nxpandroidc7611652015-09-23 16:42:05 +0530933
nxpandroid8f6d0532017-07-12 18:25:30 +0530934 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530935
nxpandroid8f6d0532017-07-12 18:25:30 +0530936 return (NFA_STATUS_OK);
937 }
nxpandroidc7611652015-09-23 16:42:05 +0530938
nxpandroid8f6d0532017-07-12 18:25:30 +0530939 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530940}
941
942/*******************************************************************************
943**
944** Function NFA_RwI93WriteSingleBlock
945**
946** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +0530947** Send Write Single Block command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +0530948**
949** When the write operation has completed (or if an error occurs), the
950** app will be notified with NFA_I93_CMD_CPLT_EVT.
951**
952** Returns:
953** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +0530954** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +0530955** NFA_STATUS_FAILED otherwise
956**
957*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530958tNFA_STATUS NFA_RwI93WriteSingleBlock(uint8_t block_number, uint8_t* p_data) {
959 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530960
nxf24591c1cbeab2018-02-21 17:32:26 +0530961 DLOG_IF(INFO, nfc_debug_enabled)
962 << StringPrintf("block_number: 0x%02X", block_number);
nxpandroidc7611652015-09-23 16:42:05 +0530963
nxf24591c1cbeab2018-02-21 17:32:26 +0530964 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530965 return (NFA_STATUS_WRONG_PROTOCOL);
966 }
nxpandroidc7611652015-09-23 16:42:05 +0530967
nxpandroid8f6d0532017-07-12 18:25:30 +0530968 /* we don't know block size of tag */
969 if ((nfa_rw_cb.i93_block_size == 0) || (nfa_rw_cb.i93_num_block == 0)) {
nxpandroidc7611652015-09-23 16:42:05 +0530970 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530971 }
972
973 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
974 (uint16_t)(sizeof(tNFA_RW_OPERATION) + nfa_rw_cb.i93_block_size));
975 if (p_msg != NULL) {
976 /* Fill in tNFA_RW_OPERATION struct */
977 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
978 p_msg->op = NFA_RW_OP_I93_WRITE_SINGLE_BLOCK;
979
980 p_msg->params.i93_cmd.first_block_number = block_number;
981 p_msg->params.i93_cmd.p_data = (uint8_t*)(p_msg + 1);
982
983 memcpy(p_msg->params.i93_cmd.p_data, p_data, nfa_rw_cb.i93_block_size);
984
985 nfa_sys_sendmsg(p_msg);
986
987 return (NFA_STATUS_OK);
988 }
989
990 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530991}
992
993/*******************************************************************************
994**
995** Function NFA_RwI93LockBlock
996**
997** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +0530998** Send Lock block command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +0530999**
1000** When the operation has completed (or if an error occurs), the
1001** app will be notified with NFA_I93_CMD_CPLT_EVT.
1002**
1003** Returns:
1004** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301005** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301006** NFA_STATUS_FAILED otherwise
1007**
1008*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301009tNFA_STATUS NFA_RwI93LockBlock(uint8_t block_number) {
1010 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301011
nxf24591c1cbeab2018-02-21 17:32:26 +05301012 DLOG_IF(INFO, nfc_debug_enabled)
1013 << StringPrintf("block_number: 0x%02X", block_number);
nxpandroidc7611652015-09-23 16:42:05 +05301014
nxf24591c1cbeab2018-02-21 17:32:26 +05301015 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301016 return (NFA_STATUS_WRONG_PROTOCOL);
1017 }
nxpandroidc7611652015-09-23 16:42:05 +05301018
nxpandroid8f6d0532017-07-12 18:25:30 +05301019 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1020 if (p_msg != NULL) {
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_LOCK_BLOCK;
nxpandroidc7611652015-09-23 16:42:05 +05301024
nxpandroid8f6d0532017-07-12 18:25:30 +05301025 p_msg->params.i93_cmd.first_block_number = block_number;
nxpandroidc7611652015-09-23 16:42:05 +05301026
nxpandroid8f6d0532017-07-12 18:25:30 +05301027 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301028
nxpandroid8f6d0532017-07-12 18:25:30 +05301029 return (NFA_STATUS_OK);
1030 }
nxpandroidc7611652015-09-23 16:42:05 +05301031
nxpandroid8f6d0532017-07-12 18:25:30 +05301032 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301033}
1034
1035/*******************************************************************************
1036**
1037** Function NFA_RwI93ReadMultipleBlocks
1038**
1039** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301040** Send Read Multiple Block command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301041**
nxpandroid8f6d0532017-07-12 18:25:30 +05301042** Data is returned to the application using the NFA_DATA_EVT. When the
1043** read operation has completed, or if an error occurs, the app will be
1044** notified with NFA_I93_CMD_CPLT_EVT.
nxpandroidc7611652015-09-23 16:42:05 +05301045**
1046** Returns:
1047** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301048** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301049** NFA_STATUS_FAILED otherwise
1050**
1051*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301052tNFA_STATUS NFA_RwI93ReadMultipleBlocks(uint8_t first_block_number,
1053 uint16_t number_blocks) {
1054 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301055
nxf24591c1cbeab2018-02-21 17:32:26 +05301056 DLOG_IF(INFO, nfc_debug_enabled)
1057 << StringPrintf("%d, %d", first_block_number, number_blocks);
nxpandroidc7611652015-09-23 16:42:05 +05301058
nxf24591c1cbeab2018-02-21 17:32:26 +05301059 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301060 return (NFA_STATUS_WRONG_PROTOCOL);
1061 }
nxpandroidc7611652015-09-23 16:42:05 +05301062
nxpandroid8f6d0532017-07-12 18:25:30 +05301063 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1064 if (p_msg != NULL) {
1065 /* Fill in tNFA_RW_OPERATION struct */
1066 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1067 p_msg->op = NFA_RW_OP_I93_READ_MULTI_BLOCK;
nxpandroidc7611652015-09-23 16:42:05 +05301068
nxpandroid8f6d0532017-07-12 18:25:30 +05301069 p_msg->params.i93_cmd.first_block_number = first_block_number;
1070 p_msg->params.i93_cmd.number_blocks = number_blocks;
nxpandroidc7611652015-09-23 16:42:05 +05301071
nxpandroid8f6d0532017-07-12 18:25:30 +05301072 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301073
nxpandroid8f6d0532017-07-12 18:25:30 +05301074 return (NFA_STATUS_OK);
1075 }
nxpandroidc7611652015-09-23 16:42:05 +05301076
nxpandroid8f6d0532017-07-12 18:25:30 +05301077 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301078}
1079
1080/*******************************************************************************
1081**
1082** Function NFA_RwI93WriteMultipleBlocks
1083**
1084** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301085** Send Write Multiple Block command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301086**
1087** When the write operation has completed (or if an error occurs), the
1088** app will be notified with NFA_I93_CMD_CPLT_EVT.
1089**
1090** Returns:
1091** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301092** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301093** NFA_STATUS_FAILED otherwise
1094**
1095*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301096tNFA_STATUS NFA_RwI93WriteMultipleBlocks(uint8_t first_block_number,
1097 uint16_t number_blocks,
1098 uint8_t* p_data) {
1099 tNFA_RW_OPERATION* p_msg;
1100 uint16_t data_length;
nxpandroidc7611652015-09-23 16:42:05 +05301101
nxf24591c1cbeab2018-02-21 17:32:26 +05301102 DLOG_IF(INFO, nfc_debug_enabled)
1103 << StringPrintf("%d, %d", first_block_number, number_blocks);
nxpandroidc7611652015-09-23 16:42:05 +05301104
nxf24591c1cbeab2018-02-21 17:32:26 +05301105 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301106 return (NFA_STATUS_WRONG_PROTOCOL);
1107 }
nxpandroidc7611652015-09-23 16:42:05 +05301108
nxpandroid8f6d0532017-07-12 18:25:30 +05301109 /* we don't know block size of tag */
1110 if ((nfa_rw_cb.i93_block_size == 0) || (nfa_rw_cb.i93_num_block == 0)) {
nxpandroidc7611652015-09-23 16:42:05 +05301111 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +05301112 }
1113
1114 data_length = nfa_rw_cb.i93_block_size * number_blocks;
1115
1116 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
1117 (uint16_t)(sizeof(tNFA_RW_OPERATION) + data_length));
1118 if (p_msg != NULL) {
1119 /* Fill in tNFA_RW_OPERATION struct */
1120 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1121 p_msg->op = NFA_RW_OP_I93_WRITE_MULTI_BLOCK;
1122
1123 p_msg->params.i93_cmd.first_block_number = first_block_number;
1124 p_msg->params.i93_cmd.number_blocks = number_blocks;
1125 p_msg->params.i93_cmd.p_data = (uint8_t*)(p_msg + 1);
1126
1127 memcpy(p_msg->params.i93_cmd.p_data, p_data, data_length);
1128
1129 nfa_sys_sendmsg(p_msg);
1130
1131 return (NFA_STATUS_OK);
1132 }
1133
1134 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301135}
1136
1137/*******************************************************************************
1138**
1139** Function NFA_RwI93Select
1140**
1141** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301142** Send Select command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301143**
1144** UID[0]: 0xE0, MSB
1145** UID[1]: IC Mfg Code
1146** ...
1147** UID[7]: LSB
1148**
1149** When the operation has completed (or if an error occurs), the
1150** app will be notified with NFA_I93_CMD_CPLT_EVT.
1151**
1152** Returns:
1153** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301154** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301155** NFA_STATUS_FAILED otherwise
1156**
1157*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301158tNFA_STATUS NFA_RwI93Select(uint8_t* p_uid) {
1159 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301160
nxf24591c1cbeab2018-02-21 17:32:26 +05301161 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1162 "UID: [%02X%02X%02X...]", *(p_uid), *(p_uid + 1), *(p_uid + 2));
nxpandroidc7611652015-09-23 16:42:05 +05301163
nxf24591c1cbeab2018-02-21 17:32:26 +05301164 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301165 return (NFA_STATUS_WRONG_PROTOCOL);
1166 }
nxpandroidc7611652015-09-23 16:42:05 +05301167
nxpandroid8f6d0532017-07-12 18:25:30 +05301168 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
1169 (uint16_t)(sizeof(tNFA_RW_OPERATION) + I93_UID_BYTE_LEN));
1170 if (p_msg != NULL) {
1171 /* Fill in tNFA_RW_OPERATION struct */
1172 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1173 p_msg->op = NFA_RW_OP_I93_SELECT;
nxpandroidc7611652015-09-23 16:42:05 +05301174
nxpandroid8f6d0532017-07-12 18:25:30 +05301175 p_msg->params.i93_cmd.p_data = (uint8_t*)(p_msg + 1);
1176 memcpy(p_msg->params.i93_cmd.p_data, p_uid, I93_UID_BYTE_LEN);
nxpandroidc7611652015-09-23 16:42:05 +05301177
nxpandroid8f6d0532017-07-12 18:25:30 +05301178 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301179
nxpandroid8f6d0532017-07-12 18:25:30 +05301180 return (NFA_STATUS_OK);
1181 }
nxpandroidc7611652015-09-23 16:42:05 +05301182
nxpandroid8f6d0532017-07-12 18:25:30 +05301183 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301184}
1185
1186/*******************************************************************************
1187**
1188** Function NFA_RwI93ResetToReady
1189**
1190** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301191** Send Reset to ready command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301192**
1193** When the operation has completed (or if an error occurs), the
1194** app will be notified with NFA_I93_CMD_CPLT_EVT.
1195**
1196** Returns:
1197** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301198** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301199** NFA_STATUS_FAILED otherwise
1200**
1201*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301202tNFA_STATUS NFA_RwI93ResetToReady(void) {
1203 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301204
nxf24591c1cbeab2018-02-21 17:32:26 +05301205 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +05301206
nxf24591c1cbeab2018-02-21 17:32:26 +05301207 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301208 return (NFA_STATUS_WRONG_PROTOCOL);
1209 }
nxpandroidc7611652015-09-23 16:42:05 +05301210
nxpandroid8f6d0532017-07-12 18:25:30 +05301211 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1212 if (p_msg != NULL) {
1213 /* Fill in tNFA_RW_OPERATION struct */
1214 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1215 p_msg->op = NFA_RW_OP_I93_RESET_TO_READY;
nxpandroidc7611652015-09-23 16:42:05 +05301216
nxpandroid8f6d0532017-07-12 18:25:30 +05301217 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301218
nxpandroid8f6d0532017-07-12 18:25:30 +05301219 return (NFA_STATUS_OK);
1220 }
nxpandroidc7611652015-09-23 16:42:05 +05301221
nxpandroid8f6d0532017-07-12 18:25:30 +05301222 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301223}
1224
1225/*******************************************************************************
1226**
1227** Function NFA_RwI93WriteAFI
1228**
1229** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301230** Send Write AFI command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301231**
1232** When the operation has completed (or if an error occurs), the
1233** app will be notified with NFA_I93_CMD_CPLT_EVT.
1234**
1235** Returns:
1236** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301237** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301238** NFA_STATUS_FAILED otherwise
1239**
1240*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301241tNFA_STATUS NFA_RwI93WriteAFI(uint8_t afi) {
1242 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301243
nxf24591c1cbeab2018-02-21 17:32:26 +05301244 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("AFI: 0x%02X", afi);
nxpandroidc7611652015-09-23 16:42:05 +05301245
nxf24591c1cbeab2018-02-21 17:32:26 +05301246 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301247 return (NFA_STATUS_WRONG_PROTOCOL);
1248 }
nxpandroidc7611652015-09-23 16:42:05 +05301249
nxpandroid8f6d0532017-07-12 18:25:30 +05301250 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1251 if (p_msg != NULL) {
1252 /* Fill in tNFA_RW_OPERATION struct */
1253 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1254 p_msg->op = NFA_RW_OP_I93_WRITE_AFI;
nxpandroidc7611652015-09-23 16:42:05 +05301255
nxpandroid8f6d0532017-07-12 18:25:30 +05301256 p_msg->params.i93_cmd.afi = afi;
nxpandroidc7611652015-09-23 16:42:05 +05301257
nxpandroid8f6d0532017-07-12 18:25:30 +05301258 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301259
nxpandroid8f6d0532017-07-12 18:25:30 +05301260 return (NFA_STATUS_OK);
1261 }
nxpandroidc7611652015-09-23 16:42:05 +05301262
nxpandroid8f6d0532017-07-12 18:25:30 +05301263 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301264}
1265
1266/*******************************************************************************
1267**
1268** Function NFA_RwI93LockAFI
1269**
1270** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301271** Send Lock AFI command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301272**
1273** When the operation has completed (or if an error occurs), the
1274** app will be notified with NFA_I93_CMD_CPLT_EVT.
1275**
1276** Returns:
1277** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301278** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301279** NFA_STATUS_FAILED otherwise
1280**
1281*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301282tNFA_STATUS NFA_RwI93LockAFI(void) {
1283 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301284
nxf24591c1cbeab2018-02-21 17:32:26 +05301285 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +05301286
nxf24591c1cbeab2018-02-21 17:32:26 +05301287 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301288 return (NFA_STATUS_WRONG_PROTOCOL);
1289 }
nxpandroidc7611652015-09-23 16:42:05 +05301290
nxpandroid8f6d0532017-07-12 18:25:30 +05301291 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1292 if (p_msg != NULL) {
1293 /* Fill in tNFA_RW_OPERATION struct */
1294 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1295 p_msg->op = NFA_RW_OP_I93_LOCK_AFI;
nxpandroidc7611652015-09-23 16:42:05 +05301296
nxpandroid8f6d0532017-07-12 18:25:30 +05301297 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301298
nxpandroid8f6d0532017-07-12 18:25:30 +05301299 return (NFA_STATUS_OK);
1300 }
nxpandroidc7611652015-09-23 16:42:05 +05301301
nxpandroid8f6d0532017-07-12 18:25:30 +05301302 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301303}
1304
1305/*******************************************************************************
1306**
1307** Function NFA_RwI93WriteDSFID
1308**
1309** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301310** Send Write DSFID command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301311**
1312** When the operation has completed (or if an error occurs), the
1313** app will be notified with NFA_I93_CMD_CPLT_EVT.
1314**
1315** Returns:
1316** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301317** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301318** NFA_STATUS_FAILED otherwise
1319**
1320*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301321tNFA_STATUS NFA_RwI93WriteDSFID(uint8_t dsfid) {
1322 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301323
nxf24591c1cbeab2018-02-21 17:32:26 +05301324 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("DSFID: 0x%02X", dsfid);
nxpandroidc7611652015-09-23 16:42:05 +05301325
nxf24591c1cbeab2018-02-21 17:32:26 +05301326 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301327 return (NFA_STATUS_WRONG_PROTOCOL);
1328 }
nxpandroidc7611652015-09-23 16:42:05 +05301329
nxpandroid8f6d0532017-07-12 18:25:30 +05301330 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1331 if (p_msg != NULL) {
1332 /* Fill in tNFA_RW_OPERATION struct */
1333 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1334 p_msg->op = NFA_RW_OP_I93_WRITE_DSFID;
nxpandroidc7611652015-09-23 16:42:05 +05301335
nxpandroid8f6d0532017-07-12 18:25:30 +05301336 p_msg->params.i93_cmd.dsfid = dsfid;
nxpandroidc7611652015-09-23 16:42:05 +05301337
nxpandroid8f6d0532017-07-12 18:25:30 +05301338 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301339
nxpandroid8f6d0532017-07-12 18:25:30 +05301340 return (NFA_STATUS_OK);
1341 }
nxpandroidc7611652015-09-23 16:42:05 +05301342
nxpandroid8f6d0532017-07-12 18:25:30 +05301343 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301344}
1345
1346/*******************************************************************************
1347**
1348** Function NFA_RwI93LockDSFID
1349**
1350** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301351** Send Lock DSFID command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301352**
1353** When the operation has completed (or if an error occurs), the
1354** app will be notified with NFA_I93_CMD_CPLT_EVT.
1355**
1356** Returns:
1357** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301358** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301359** NFA_STATUS_FAILED otherwise
1360**
1361*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301362tNFA_STATUS NFA_RwI93LockDSFID(void) {
1363 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301364
nxf24591c1cbeab2018-02-21 17:32:26 +05301365 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +05301366
nxf24591c1cbeab2018-02-21 17:32:26 +05301367 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301368 return (NFA_STATUS_WRONG_PROTOCOL);
1369 }
nxpandroidc7611652015-09-23 16:42:05 +05301370
nxpandroid8f6d0532017-07-12 18:25:30 +05301371 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1372 if (p_msg != NULL) {
1373 /* Fill in tNFA_RW_OPERATION struct */
1374 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1375 p_msg->op = NFA_RW_OP_I93_LOCK_DSFID;
nxpandroidc7611652015-09-23 16:42:05 +05301376
nxpandroid8f6d0532017-07-12 18:25:30 +05301377 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301378
nxpandroid8f6d0532017-07-12 18:25:30 +05301379 return (NFA_STATUS_OK);
1380 }
nxpandroidc7611652015-09-23 16:42:05 +05301381
nxpandroid8f6d0532017-07-12 18:25:30 +05301382 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301383}
1384
1385/*******************************************************************************
1386**
1387** Function NFA_RwI93GetSysInfo
1388**
1389** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301390** Send Get system information command to the activated T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301391** If UID is provided then set UID[0]:MSB, ... UID[7]:LSB
1392**
1393** When the operation has completed (or if an error occurs), the
1394** app will be notified with NFA_I93_CMD_CPLT_EVT.
1395**
1396** Returns:
1397** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301398** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301399** NFA_STATUS_FAILED otherwise
1400**
1401*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301402tNFA_STATUS NFA_RwI93GetSysInfo(uint8_t* p_uid) {
1403 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301404
nxf24591c1cbeab2018-02-21 17:32:26 +05301405 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +05301406
nxf24591c1cbeab2018-02-21 17:32:26 +05301407 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301408 return (NFA_STATUS_WRONG_PROTOCOL);
1409 }
1410
1411 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1412 if (p_msg != NULL) {
1413 /* Fill in tNFA_RW_OPERATION struct */
1414 p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
1415 p_msg->op = NFA_RW_OP_I93_GET_SYS_INFO;
1416
1417 if (p_uid) {
1418 p_msg->params.i93_cmd.uid_present = true;
1419 memcpy(p_msg->params.i93_cmd.uid, p_uid, I93_UID_BYTE_LEN);
1420 } else {
1421 p_msg->params.i93_cmd.uid_present = false;
nxpandroidc7611652015-09-23 16:42:05 +05301422 }
1423
nxpandroid8f6d0532017-07-12 18:25:30 +05301424 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301425
nxpandroid8f6d0532017-07-12 18:25:30 +05301426 return (NFA_STATUS_OK);
1427 }
nxpandroidc7611652015-09-23 16:42:05 +05301428
nxpandroid8f6d0532017-07-12 18:25:30 +05301429 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301430}
1431
1432/*******************************************************************************
1433**
1434** Function NFA_RwI93GetMultiBlockSecurityStatus
1435**
1436** Description:
nxf24591c1cbeab2018-02-21 17:32:26 +05301437** Send Get Multiple block security status command to the activated
1438** T5T tag.
nxpandroidc7611652015-09-23 16:42:05 +05301439**
nxpandroid8f6d0532017-07-12 18:25:30 +05301440** Data is returned to the application using the NFA_DATA_EVT. When the
1441** read operation has completed, or if an error occurs, the app will be
1442** notified with NFA_I93_CMD_CPLT_EVT.
nxpandroidc7611652015-09-23 16:42:05 +05301443**
1444** Returns:
1445** NFA_STATUS_OK if successfully initiated
nxf24591c1cbeab2018-02-21 17:32:26 +05301446** NFA_STATUS_WRONG_PROTOCOL: T5T tag not activated
nxpandroidc7611652015-09-23 16:42:05 +05301447** NFA_STATUS_FAILED otherwise
1448**
1449*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301450tNFA_STATUS NFA_RwI93GetMultiBlockSecurityStatus(uint8_t first_block_number,
1451 uint16_t number_blocks) {
1452 tNFA_RW_OPERATION* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +05301453
nxf24591c1cbeab2018-02-21 17:32:26 +05301454 DLOG_IF(INFO, nfc_debug_enabled)
1455 << StringPrintf("%d, %d", first_block_number, number_blocks);
nxpandroidc7611652015-09-23 16:42:05 +05301456
nxf24591c1cbeab2018-02-21 17:32:26 +05301457 if (nfa_rw_cb.protocol != NFC_PROTOCOL_T5T) {
nxpandroid8f6d0532017-07-12 18:25:30 +05301458 return (NFA_STATUS_WRONG_PROTOCOL);
1459 }
nxpandroidc7611652015-09-23 16:42:05 +05301460
nxpandroid8f6d0532017-07-12 18:25:30 +05301461 p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
1462 if (p_msg != NULL) {
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_MULTI_BLOCK_STATUS;
nxpandroidc7611652015-09-23 16:42:05 +05301466
nxpandroid8f6d0532017-07-12 18:25:30 +05301467 p_msg->params.i93_cmd.first_block_number = first_block_number;
1468 p_msg->params.i93_cmd.number_blocks = number_blocks;
nxpandroidc7611652015-09-23 16:42:05 +05301469
nxpandroid8f6d0532017-07-12 18:25:30 +05301470 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +05301471
nxpandroid8f6d0532017-07-12 18:25:30 +05301472 return (NFA_STATUS_OK);
1473 }
nxpandroidc7611652015-09-23 16:42:05 +05301474
nxpandroid8f6d0532017-07-12 18:25:30 +05301475 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +05301476}