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