1 /******************************************************************************
2 *
3 * Copyright (C) 2024 The Android Open Source Project.
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 #include "NativeT4tNfcee.h"
20
21 #include <android-base/logging.h>
22 #include <android-base/stringprintf.h>
23 #include <nativehelper/ScopedPrimitiveArray.h>
24
25 #include "NfcJniUtil.h"
26 #include "nfa_nfcee_api.h"
27 #include "nfa_nfcee_int.h"
28 #include "nfc_config.h"
29
30 using android::base::StringPrintf;
31
32 /*Considering NCI response timeout which is 2s, Timeout set 100ms more*/
33 #define T4TNFCEE_TIMEOUT 2100
34 #define T4TOP_TIMEOUT 200
35 #define FILE_ID_LEN 0x02
36
37 extern bool gActivated;
38 namespace android {
39 extern bool isDiscoveryStarted();
40 extern void startRfDiscovery(bool isStart);
41 extern bool nfcManager_isNfcActive();
42 } // namespace android
43
44 NativeT4tNfcee NativeT4tNfcee::sNativeT4tNfceeInstance;
45 bool NativeT4tNfcee::sIsNfcOffTriggered = false;
46
NativeT4tNfcee()47 NativeT4tNfcee::NativeT4tNfcee() {
48 mBusy = false;
49 memset(&mReadData, 0x00, sizeof(tNFA_RX_DATA));
50 mT4tOpStatus = NFA_STATUS_FAILED;
51 }
52
53 /*****************************************************************************
54 **
55 ** Function: getInstance
56 **
57 ** Description: Get the NativeT4tNfcee singleton object.
58 **
59 ** Returns: NativeT4tNfcee object.
60 **
61 *******************************************************************************/
getInstance()62 NativeT4tNfcee& NativeT4tNfcee::getInstance() {
63 return sNativeT4tNfceeInstance;
64 }
65
66 /*******************************************************************************
67 **
68 ** Function: initialize
69 **
70 ** Description: Initialize all member variables.
71 **
72 ** Returns: None.
73 **
74 *******************************************************************************/
initialize(void)75 void NativeT4tNfcee::initialize(void) {
76 sIsNfcOffTriggered = false;
77 mBusy = false;
78 }
79
80 /*****************************************************************************
81 **
82 ** Function: onNfccShutdown
83 **
84 ** Description: This api shall be called in NFC OFF case.
85 **
86 ** Returns: none.
87 **
88 *******************************************************************************/
onNfccShutdown()89 void NativeT4tNfcee::onNfccShutdown() {
90 static const char fn[] = "NativeT4tNfcee:onNfccShutdown";
91 LOG(DEBUG) << StringPrintf("%s", fn);
92 sIsNfcOffTriggered = true;
93 if (mBusy) {
94 /* Unblock JNI APIs */
95 {
96 SyncEventGuard g(mT4tNfcOffEvent);
97 if (mT4tNfcOffEvent.wait(T4TOP_TIMEOUT) == false) {
98 SyncEventGuard ga(mT4tNfcEeRWCEvent);
99 mT4tNfcEeRWCEvent.notifyOne();
100 }
101 }
102 /* Try to close the connection with t4t nfcee, discard the status */
103 (void)closeConnection();
104 resetBusy();
105 }
106 }
107 /*******************************************************************************
108 **
109 ** Function: t4tClearData
110 **
111 ** Description: This API will set all the T4T NFCEE NDEF data to zero.
112 ** This API can be called regardless of NDEF file lock state.
113 **
114 ** Returns: boolean : Return the Success or fail of the operation.
115 ** Return "True" when operation is successful. else "False"
116 **
117 *******************************************************************************/
t4tClearData(JNIEnv * e,jobject o)118 jboolean NativeT4tNfcee::t4tClearData(JNIEnv* e, jobject o) {
119 static const char fn[] = "NativeT4tNfcee:t4tClearData";
120 LOG(DEBUG) << StringPrintf("%s", fn);
121 /*Local variable Initialization*/
122 uint8_t pFileId[] = {0xE1, 0x04};
123 jbyteArray fileIdArray = e->NewByteArray(sizeof(pFileId));
124 e->SetByteArrayRegion(fileIdArray, 0, sizeof(pFileId), (jbyte*)pFileId);
125 bool clear_status = false;
126
127 /*Validate Precondition*/
128 T4TNFCEE_STATUS_t t4tNfceeStatus =
129 validatePreCondition(OP_CLEAR, fileIdArray);
130
131 switch (t4tNfceeStatus) {
132 case STATUS_SUCCESS:
133 /*NFC is ON*/
134 clear_status = performT4tClearData(pFileId);
135 break;
136 default:
137 LOG(ERROR) << StringPrintf("%s: Exit, Returning status=%d", fn,
138 clear_status);
139 break;
140 }
141
142 return clear_status;
143 }
144 /*******************************************************************************
145 **
146 ** Function: performT4tClearData
147 **
148 ** Description: This api clear the T4T Nfcee data
149 **
150 ** Returns: boolean : Return the Success or fail of the operation.
151 ** Return "True" when operation is successful. else "False"
152 **
153 *******************************************************************************/
performT4tClearData(uint8_t * fileId)154 jboolean NativeT4tNfcee::performT4tClearData(uint8_t* fileId) {
155 static const char fn[] = "NativeT4tNfcee:performT4tClearData";
156 bool t4tClearReturn = false;
157 tNFA_STATUS status = NFA_STATUS_FAILED;
158
159 /*Open connection and stop discovery*/
160 if (setup() != NFA_STATUS_OK) return t4tClearReturn;
161
162 /*Clear Ndef data*/
163 SyncEventGuard g(mT4tNfcEeRWCEvent);
164 status = NFA_T4tNfcEeClear(fileId);
165 if (status == NFA_STATUS_OK) {
166 if (mT4tNfcEeRWCEvent.wait(T4TNFCEE_TIMEOUT) == false)
167 t4tClearReturn = false;
168 else {
169 if (mT4tOpStatus == NFA_STATUS_OK) {
170 t4tClearReturn = true;
171 }
172 }
173 }
174
175 /*Close connection and start discovery*/
176 cleanup();
177 LOG(DEBUG) << StringPrintf("%s: t4tClearReturn=%d", fn, t4tClearReturn);
178 return t4tClearReturn;
179 }
180 /*******************************************************************************
181 **
182 ** Function: getT4tStatus
183 **
184 ** Description: This API will get T4T NDEF NFCEE status.
185 **
186 ** Returns: boolean : Indicates whether T4T NDEF NFCEE Read or write
187 ** operation is under process
188 ** Return "True" when operation is in progress. else "False"
189 **
190 *******************************************************************************/
getT4tStatus(JNIEnv * e,jobject o)191 jboolean NativeT4tNfcee::getT4tStatus(JNIEnv* e, jobject o) {
192 static const char fn[] = "NativeT4tNfcee:getT4tStatus";
193
194 bool t4tStatus = false;
195 t4tStatus = NFA_T4tNfcEeIsProcessing();
196
197 LOG(DEBUG) << StringPrintf("%s: status=%d", fn, t4tStatus);
198 return t4tStatus;
199 }
200 /*******************************************************************************
201 **
202 ** Function: isT4tNdefNfceeEmulationSupported
203 **
204 ** Description: This API will tell whether T4T NDEF NFCEE emulation is
205 ** supported or not.
206 **
207 ** Returns: boolean : Indicates whether T4T NDEF NFCEE emulation is
208 ** supported or not
209 ** Return "True" emulation is supported. else "False"
210 **
211 *******************************************************************************/
isT4tNdefNfceeEmulationSupported(JNIEnv * e,jobject o)212 jboolean NativeT4tNfcee::isT4tNdefNfceeEmulationSupported(JNIEnv* e,
213 jobject o) {
214 static const char fn[] = "NativeT4tNfcee:isT4tNdefNfceeEmulationSupported";
215 bool t4tStatus = false;
216 t4tStatus = NFA_T4tNfcEeIsEmulationSupported();
217 LOG(DEBUG) << StringPrintf("%s: status=%d", fn, t4tStatus);
218 return t4tStatus;
219 }
220
221 /*******************************************************************************
222 **
223 ** Function: t4tWriteData
224 **
225 ** Description: Write the data into the T4T file of the specific file ID
226 **
227 ** Returns: Return the size of data written
228 ** Return negative number of error code
229 **
230 *******************************************************************************/
t4tWriteData(JNIEnv * e,jobject object,jbyteArray fileId,jbyteArray data)231 jint NativeT4tNfcee::t4tWriteData(JNIEnv* e, jobject object, jbyteArray fileId,
232 jbyteArray data) {
233 static const char fn[] = "NativeT4tNfcee:t4tWriteData";
234 tNFA_STATUS status = NFA_STATUS_FAILED;
235
236 LOG(DEBUG) << StringPrintf("%s", fn);
237 T4TNFCEE_STATUS_t t4tNfceeStatus =
238 validatePreCondition(OP_WRITE, fileId, data);
239 if (t4tNfceeStatus != STATUS_SUCCESS) return t4tNfceeStatus;
240
241 ScopedByteArrayRO bytes(e, fileId);
242 if (bytes.size() < FILE_ID_LEN) {
243 LOG(ERROR) << StringPrintf("%s: Wrong File Id", fn);
244 return ERROR_INVALID_FILE_ID;
245 }
246
247 ScopedByteArrayRO bytesData(e, data);
248 if (bytesData.size() == 0x00) {
249 LOG(ERROR) << StringPrintf("%s: Empty Data", fn);
250 return ERROR_EMPTY_PAYLOAD;
251 }
252
253 if (setup() != NFA_STATUS_OK) return ERROR_CONNECTION_FAILED;
254
255 uint8_t* pFileId = NULL;
256 pFileId = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0]));
257
258 uint8_t* pData = NULL;
259 pData = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytesData[0]));
260
261 jint t4tWriteReturn = STATUS_FAILED;
262 {
263 SyncEventGuard g(mT4tNfcEeRWCEvent);
264 status = NFA_T4tNfcEeWrite(pFileId, pData, bytesData.size());
265 if (status == NFA_STATUS_OK) {
266 if (mT4tNfcEeRWCEvent.wait(T4TNFCEE_TIMEOUT) == false)
267 t4tWriteReturn = STATUS_FAILED;
268 else {
269 if (mT4tOpStatus == NFA_STATUS_OK) {
270 /*if status is success then return length of data written*/
271 t4tWriteReturn = mReadData.len;
272 } else if (mT4tOpStatus == NFA_STATUS_REJECTED) {
273 t4tWriteReturn = ERROR_NDEF_VALIDATION_FAILED;
274 } else if (mT4tOpStatus == NFA_T4T_STATUS_INVALID_FILE_ID) {
275 t4tWriteReturn = ERROR_INVALID_FILE_ID;
276 } else if (mT4tOpStatus == NFA_STATUS_READ_ONLY) {
277 t4tWriteReturn = ERROR_WRITE_PERMISSION;
278 } else {
279 t4tWriteReturn = STATUS_FAILED;
280 }
281 }
282 }
283 }
284
285 /*Close connection and start discovery*/
286 cleanup();
287 LOG(ERROR) << StringPrintf("%s: Exit: Returnig status =%d", fn,
288 t4tWriteReturn);
289 return t4tWriteReturn;
290 }
291
292 /*******************************************************************************
293 **
294 ** Function: t4tReadData
295 **
296 ** Description: Read the data from the T4T file of the specific file ID.
297 **
298 ** Returns: byte[] : all the data previously written to the specific
299 ** file ID.
300 ** Return one byte '0xFF' if the data was never written to the
301 ** specific file ID,
302 ** Return null if reading fails.
303 **
304 *******************************************************************************/
t4tReadData(JNIEnv * e,jobject object,jbyteArray fileId)305 jbyteArray NativeT4tNfcee::t4tReadData(JNIEnv* e, jobject object,
306 jbyteArray fileId) {
307 static const char fn[] = "NativeT4tNfcee:t4tReadData";
308 tNFA_STATUS status = NFA_STATUS_FAILED;
309
310 LOG(DEBUG) << StringPrintf("%s", fn);
311 T4TNFCEE_STATUS_t t4tNfceeStatus = validatePreCondition(OP_READ, fileId);
312 if (t4tNfceeStatus != STATUS_SUCCESS) return NULL;
313
314 ScopedByteArrayRO bytes(e, fileId);
315 ScopedLocalRef<jbyteArray> result(e, NULL);
316 if (bytes.size() < FILE_ID_LEN) {
317 LOG(ERROR) << StringPrintf("%s: Wrong File Id", fn);
318 return NULL;
319 }
320
321 if (setup() != NFA_STATUS_OK) return NULL;
322
323 uint8_t* pFileId = NULL;
324 pFileId = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0]));
325
326 { /*syncEvent code section*/
327 SyncEventGuard g(mT4tNfcEeRWCEvent);
328 sRxDataBuffer.clear();
329 status = NFA_T4tNfcEeRead(pFileId);
330 if ((status != NFA_STATUS_OK) ||
331 (mT4tNfcEeRWCEvent.wait(T4TNFCEE_TIMEOUT) == false)) {
332 LOG(ERROR) << StringPrintf("%s: Read Failed, status = 0x%X", fn, status);
333 cleanup();
334 return NULL;
335 }
336 }
337
338 if (sRxDataBuffer.size() > 0) {
339 result.reset(e->NewByteArray(sRxDataBuffer.size()));
340 if (result.get() != NULL) {
341 e->SetByteArrayRegion(result.get(), 0, sRxDataBuffer.size(),
342 (const jbyte*)sRxDataBuffer.data());
343 } else {
344 result.reset(e->NewByteArray(0x00));
345 e->SetByteArrayRegion(result.get(), 0, 0x00, (jbyte*){});
346 LOG(ERROR) << StringPrintf("%s: Failed to allocate java byte array", fn);
347 }
348 sRxDataBuffer.clear();
349 } else if (mT4tOpStatus == NFA_T4T_STATUS_INVALID_FILE_ID) {
350 result.reset(e->NewByteArray(0x00));
351 e->SetByteArrayRegion(result.get(), 0, 0x00, (jbyte*){});
352 }
353 /*Close connection and start discovery*/
354 cleanup();
355 return result.release();
356 }
357
358 /*******************************************************************************
359 **
360 ** Function: openConnection
361 **
362 ** Description: Open T4T Nfcee Connection
363 **
364 ** Returns: Status
365 **
366 *******************************************************************************/
openConnection()367 tNFA_STATUS NativeT4tNfcee::openConnection() {
368 static const char fn[] = "NativeT4tNfcee:openConnection";
369 tNFA_STATUS status = NFA_STATUS_FAILED;
370 LOG(DEBUG) << StringPrintf("%s", fn);
371 SyncEventGuard g(mT4tNfcEeEvent);
372 status = NFA_T4tNfcEeOpenConnection();
373 if (status == NFA_STATUS_OK) {
374 if (mT4tNfcEeEvent.wait(T4TNFCEE_TIMEOUT) == false) {
375 status = NFA_STATUS_FAILED;
376 LOG(ERROR) << StringPrintf(
377 "%s: NFA_T4tNfcEeOpenConnection Failed, status = 0x%X", fn, status);
378 } else
379 status = mT4tNfcEeEventStat;
380 }
381 return status;
382 }
383
384 /*******************************************************************************
385 **
386 ** Function: closeConnection
387 **
388 ** Description: Close T4T Nfcee Connection
389 **
390 ** Returns: Status
391 **
392 *******************************************************************************/
closeConnection()393 tNFA_STATUS NativeT4tNfcee::closeConnection() {
394 static const char fn[] = "NativeT4tNfcee:closeConnection";
395 tNFA_STATUS status = NFA_STATUS_FAILED;
396 LOG(DEBUG) << StringPrintf("%s", fn);
397 {
398 SyncEventGuard g(mT4tNfcEeEvent);
399 status = NFA_T4tNfcEeCloseConnection();
400 if (status == NFA_STATUS_OK) {
401 if (mT4tNfcEeEvent.wait(T4TNFCEE_TIMEOUT) == false) {
402 status = NFA_STATUS_FAILED;
403 LOG(ERROR) << StringPrintf(
404 "%s: NFA_T4tNfcEeCloseConnection Failed, status = 0x%X", fn,
405 status);
406 } else
407 status = mT4tNfcEeEventStat;
408 }
409 }
410 return status;
411 }
412
413 /*******************************************************************************
414 **
415 ** Function: setup
416 **
417 ** Description: stops Discovery and opens T4TNFCEE connection
418 **
419 ** Returns: Status
420 **
421 *******************************************************************************/
setup(void)422 tNFA_STATUS NativeT4tNfcee::setup(void) {
423 static const char fn[] = "NativeT4tNfcee:setup";
424 LOG(DEBUG) << StringPrintf("%s", fn);
425 tNFA_STATUS status = NFA_STATUS_FAILED;
426 setBusy();
427 if (android::isDiscoveryStarted()) {
428 android::startRfDiscovery(false);
429 }
430
431 status = openConnection();
432 if (status != NFA_STATUS_OK) {
433 LOG(ERROR) << StringPrintf("%s: openConnection Failed, status = 0x%X", fn,
434 status);
435 if (!android::isDiscoveryStarted()) android::startRfDiscovery(true);
436 resetBusy();
437 }
438 return status;
439 }
440 /*******************************************************************************
441 **
442 ** Function: cleanup
443 **
444 ** Description: closes connection and starts discovery
445 **
446 ** Returns: Status
447 **
448 *******************************************************************************/
cleanup(void)449 void NativeT4tNfcee::cleanup(void) {
450 static const char fn[] = "NativeT4tNfcee:cleanup";
451 LOG(DEBUG) << StringPrintf("%s", fn);
452 if (sIsNfcOffTriggered) {
453 SyncEventGuard g(mT4tNfcOffEvent);
454 mT4tNfcOffEvent.notifyOne();
455 LOG(ERROR) << StringPrintf("%s: Nfc Off triggered", fn);
456 return;
457 }
458 if (closeConnection() != NFA_STATUS_OK) {
459 LOG(ERROR) << StringPrintf("%s: closeConnection Failed", fn);
460 }
461 if (!android::isDiscoveryStarted()) {
462 android::startRfDiscovery(true);
463 }
464 resetBusy();
465 }
466
467 /*******************************************************************************
468 **
469 ** Function: validatePreCondition
470 **
471 ** Description: Runs precondition checks for requested operation
472 **
473 ** Returns: Status
474 **
475 *******************************************************************************/
validatePreCondition(T4TNFCEE_OPERATIONS_t op,jbyteArray fileId,jbyteArray data)476 T4TNFCEE_STATUS_t NativeT4tNfcee::validatePreCondition(T4TNFCEE_OPERATIONS_t op,
477 jbyteArray fileId,
478 jbyteArray data) {
479 static const char fn[] = "NativeT4tNfcee:validatePreCondition";
480 T4TNFCEE_STATUS_t t4tNfceeStatus = STATUS_SUCCESS;
481 if (!android::nfcManager_isNfcActive()) {
482 t4tNfceeStatus = ERROR_NFC_NOT_ON;
483 } else if (sIsNfcOffTriggered) {
484 t4tNfceeStatus = ERROR_NFC_OFF_TRIGGERED;
485 } else if (gActivated) {
486 t4tNfceeStatus = ERROR_RF_ACTIVATED;
487 } else if (fileId == NULL) {
488 LOG(ERROR) << StringPrintf("%s: Invalid File Id", fn);
489 t4tNfceeStatus = ERROR_INVALID_FILE_ID;
490 }
491
492 switch (op) {
493 case OP_READ:
494 break;
495 case OP_WRITE:
496 if (data == NULL) {
497 LOG(ERROR) << StringPrintf("%s: Empty data", fn);
498 t4tNfceeStatus = ERROR_EMPTY_PAYLOAD;
499 }
500 break;
501 case OP_CLEAR:
502 [[fallthrough]];
503 default:
504 break;
505 }
506 return t4tNfceeStatus;
507 }
508
509 /*******************************************************************************
510 **
511 ** Function: t4tReadComplete
512 **
513 ** Description: Updates read data to the waiting READ API
514 **
515 ** Returns: none
516 **
517 *******************************************************************************/
t4tReadComplete(tNFA_STATUS status,tNFA_RX_DATA data)518 void NativeT4tNfcee::t4tReadComplete(tNFA_STATUS status, tNFA_RX_DATA data) {
519 static const char fn[] = "NativeT4tNfcee:t4tReadComplete";
520 LOG(DEBUG) << StringPrintf("%s", fn);
521 mT4tOpStatus = status;
522 if (status == NFA_STATUS_OK) {
523 if (data.len > 0) {
524 sRxDataBuffer.insert(sRxDataBuffer.end(), data.p_data,
525 data.p_data + data.len);
526 LOG(DEBUG) << StringPrintf("%s: Read Data len new=%d ", fn, data.len);
527 }
528 }
529 SyncEventGuard g(mT4tNfcEeRWCEvent);
530 mT4tNfcEeRWCEvent.notifyOne();
531 }
532
533 /*******************************************************************************
534 **
535 ** Function: t4tWriteComplete
536 **
537 ** Description: Returns write complete information
538 **
539 ** Returns: none
540 **
541 *******************************************************************************/
t4tWriteComplete(tNFA_STATUS status,tNFA_RX_DATA data)542 void NativeT4tNfcee::t4tWriteComplete(tNFA_STATUS status, tNFA_RX_DATA data) {
543 static const char fn[] = "NativeT4tNfcee:t4tWriteComplete";
544 mReadData.len = 0x00;
545 LOG(DEBUG) << StringPrintf("%s", fn);
546 if (status == NFA_STATUS_OK) mReadData.len = data.len;
547 mT4tOpStatus = status;
548 SyncEventGuard g(mT4tNfcEeRWCEvent);
549 mT4tNfcEeRWCEvent.notifyOne();
550 }
551 /*******************************************************************************
552 **
553 ** Function: t4tClearComplete
554 **
555 ** Description: Update T4T clear data status, waiting T4tClearData API.
556 **
557 ** Returns: none
558 **
559 *******************************************************************************/
t4tClearComplete(tNFA_STATUS status)560 void NativeT4tNfcee::t4tClearComplete(tNFA_STATUS status) {
561 static const char fn[] = "NativeT4tNfcee:t4tClearComplete";
562 LOG(DEBUG) << StringPrintf("%s", fn);
563 mT4tOpStatus = status;
564 SyncEventGuard g(mT4tNfcEeRWCEvent);
565 mT4tNfcEeRWCEvent.notifyOne();
566 }
567 /*******************************************************************************
568 **
569 ** Function: t4tNfceeEventHandler
570 **
571 ** Description: Handles callback events received from lower layer
572 **
573 ** Returns: none
574 **
575 *******************************************************************************/
eventHandler(uint8_t event,tNFA_CONN_EVT_DATA * eventData)576 void NativeT4tNfcee::eventHandler(uint8_t event,
577 tNFA_CONN_EVT_DATA* eventData) {
578 static const char fn[] = "NativeT4tNfcee:eventHandler";
579 switch (event) {
580 case NFA_T4TNFCEE_EVT:
581 LOG(DEBUG) << StringPrintf("%s: NFA_T4TNFCEE_EVT", fn);
582 {
583 SyncEventGuard guard(mT4tNfcEeEvent);
584 mT4tNfcEeEventStat = eventData->status;
585 mT4tNfcEeEvent.notifyOne();
586 }
587 break;
588
589 case NFA_T4TNFCEE_READ_CPLT_EVT:
590 LOG(DEBUG) << StringPrintf("%s: NFA_T4TNFCEE_READ_CPLT_EVT", fn);
591 t4tReadComplete(eventData->status, eventData->data);
592 break;
593
594 case NFA_T4TNFCEE_WRITE_CPLT_EVT:
595 LOG(DEBUG) << StringPrintf("%s: NFA_T4TNFCEE_WRITE_CPLT_EVT", fn);
596 t4tWriteComplete(eventData->status, eventData->data);
597 break;
598
599 case NFA_T4TNFCEE_CLEAR_CPLT_EVT:
600 LOG(DEBUG) << StringPrintf("%s: NFA_T4TNFCEE_CLEAR_CPLT_EVT", fn);
601 t4tClearComplete(eventData->status);
602 break;
603
604 case NFA_T4TNFCEE_READ_CC_DATA_CPLT_EVT:
605 LOG(DEBUG) << StringPrintf("%s: NFA_T4TNFCEE_READ_CC_DATA_CPLT_EVT", fn);
606 t4tReadComplete(eventData->status, eventData->data);
607 break;
608
609 default:
610 LOG(DEBUG) << StringPrintf("%s: unknown Event", fn);
611 break;
612 }
613 }
614
615 /*******************************************************************************
616 **
617 ** Function: isT4tNfceeBusy
618 **
619 ** Description: Returns True if T4tNfcee operation is ongoing else false
620 **
621 ** Returns: true/false
622 **
623 *******************************************************************************/
isT4tNfceeBusy(void)624 bool NativeT4tNfcee::isT4tNfceeBusy(void) { return mBusy; }
625
626 /*******************************************************************************
627 **
628 ** Function: setBusy
629 **
630 ** Description: Sets busy flag indicating T4T operation is ongoing
631 **
632 ** Returns: none
633 **
634 *******************************************************************************/
setBusy()635 void NativeT4tNfcee::setBusy() { mBusy = true; }
636
637 /*******************************************************************************
638 **
639 ** Function: resetBusy
640 **
641 ** Description: Resets busy flag indicating T4T operation is completed
642 **
643 ** Returns: none
644 **
645 *******************************************************************************/
resetBusy()646 void NativeT4tNfcee::resetBusy() { mBusy = false; }
647 /*******************************************************************************
648 **
649 ** Function: getT4TNfceeAid
650 **
651 ** Description: Get the T4T Nfcee AID.
652 **
653 ** Returns: T4T AID: vector<uint8_t>
654 **
655 *******************************************************************************/
getT4TNfceeAid()656 vector<uint8_t> NativeT4tNfcee::getT4TNfceeAid() {
657 static const char fn[] = "NativeT4tNfcee:getT4TNfceeAid";
658 std::vector<uint8_t> t4tNfceeAidBuf;
659 if (NfcConfig::hasKey(NAME_T4T_NDEF_NFCEE_AID)) {
660 t4tNfceeAidBuf = NfcConfig::getBytes(NAME_T4T_NDEF_NFCEE_AID);
661 }
662
663 return t4tNfceeAidBuf;
664 }
665
666 /*******************************************************************************
667 **
668 ** Function: checkAndUpdateT4TAid
669 **
670 ** Description: Check and update T4T Ndef Nfcee AID.
671 **
672 ** Returns: void
673 **
674 *******************************************************************************/
checkAndUpdateT4TAid(uint8_t * t4tNdefAid,uint8_t * t4tNdefAidLen)675 void NativeT4tNfcee::checkAndUpdateT4TAid(uint8_t* t4tNdefAid,
676 uint8_t* t4tNdefAidLen) {
677 vector<uint8_t> t4tNfceeAidBuf = getT4TNfceeAid();
678 if (t4tNfceeAidBuf.size() != 0) {
679 uint8_t* t4tAidBuf = t4tNfceeAidBuf.data();
680 *t4tNdefAidLen = t4tNfceeAidBuf.size();
681 memcpy(t4tNdefAid, t4tAidBuf, *t4tNdefAidLen);
682 }
683 }
684