1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifdef ESE_NFC_SYNCHRONIZATION
17 #include <linux/ese-nfc-sync.h>
18 #endif
19 #include <fcntl.h>
20 #include <sys/ioctl.h>
21 #include <sys/time.h>
22
23 #include <android-base/stringprintf.h>
24 #include <base/logging.h>
25 #include <phNxpExtns_MifareStd.h>
26
27 using android::base::StringPrintf;
28
29 extern phNxpExtns_Context_t gphNxpExtns_Context;
30 extern phFriNfc_NdefMap_t* NdefMap;
31 extern phNci_mfc_auth_cmd_t gAuthCmdBuf;
32
33 static NFCSTATUS phNxpExtns_ProcessSysMessage(phLibNfc_Message_t* msg);
34 static NFCSTATUS phNxpExtns_SendMsg(phLibNfc_Message_t* sysmsg);
35
36 #ifdef ESE_NFC_SYNCHRONIZATION
37 /* timing calculation structure*/
38 typedef struct time_cal {
39 struct timeval tv1;
40 struct timeval tv2;
41 } TimeCal;
42 static int fd_ese_nfc_sync; /*file descriptor to hold sync driver handle*/
43 #endif
44
45 /*******************************************************************************
46 **
47 ** Function EXTNS_Init
48 **
49 ** Description This function Initializes Mifare Classic Extns. Allocates
50 ** required memory and initializes the Mifare Classic Vars
51 **
52 ** Returns NFCSTATUS_SUCCESS if successfully initialized
53 ** NFCSTATUS_FAILED otherwise
54 **
55 *******************************************************************************/
EXTNS_Init(tNFA_DM_CBACK * p_nfa_dm_cback,tNFA_CONN_CBACK * p_nfa_conn_cback)56 NFCSTATUS EXTNS_Init(tNFA_DM_CBACK* p_nfa_dm_cback,
57 tNFA_CONN_CBACK* p_nfa_conn_cback) {
58 NFCSTATUS status = NFCSTATUS_FAILED;
59
60 /* Validate parameters */
61 if ((!p_nfa_dm_cback) || (!p_nfa_conn_cback)) {
62 LOG(ERROR) << StringPrintf("EXTNS_Init(): error null callback");
63 goto clean_and_return;
64 }
65
66 gphNxpExtns_Context.p_dm_cback = p_nfa_dm_cback;
67 gphNxpExtns_Context.p_conn_cback = p_nfa_conn_cback;
68
69 if (NFCSTATUS_SUCCESS != phNxpExtns_MfcModuleInit()) {
70 LOG(ERROR) << StringPrintf("ERROR: MFC Module Init Failed");
71 goto clean_and_return;
72 }
73 gphNxpExtns_Context.Extns_status = EXTNS_STATUS_OPEN;
74
75 status = NFCSTATUS_SUCCESS;
76 return status;
77
78 clean_and_return:
79 gphNxpExtns_Context.Extns_status = EXTNS_STATUS_CLOSE;
80 return status;
81 }
82
83 /*******************************************************************************
84 **
85 ** Function EXTNS_Close
86 **
87 ** Description This function de-initializes Mifare Classic Extns.
88 ** De-allocates memory
89 **
90 ** Returns None
91 **
92 *******************************************************************************/
EXTNS_Close(void)93 void EXTNS_Close(void) {
94 gphNxpExtns_Context.Extns_status = EXTNS_STATUS_CLOSE;
95 phNxpExtns_MfcModuleDeInit();
96 return;
97 }
98
99 /*******************************************************************************
100 **
101 ** Function EXTNS_MfcCallBack
102 **
103 ** Description Decodes Mifare Classic Tag Response
104 ** This is called from NFA_SendRaw Callback
105 **
106 ** Returns:
107 ** NFCSTATUS_SUCCESS if successfully initiated
108 ** NFCSTATUS_FAILED otherwise
109 **
110 *******************************************************************************/
EXTNS_MfcCallBack(uint8_t * buf,uint32_t buflen)111 NFCSTATUS EXTNS_MfcCallBack(uint8_t* buf, uint32_t buflen) {
112 NFCSTATUS status = NFCSTATUS_SUCCESS;
113
114 phLibNfc_Message_t msg;
115
116 msg.eMsgType = PH_NXPEXTNS_RX_DATA;
117 msg.pMsgData = buf;
118 msg.Size = buflen;
119
120 status = phNxpExtns_SendMsg(&msg);
121 if (NFCSTATUS_SUCCESS != status) {
122 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
123 }
124 return status;
125 }
126
127 /*******************************************************************************
128 **
129 ** Function EXTNS_MfcCheckNDef
130 **
131 ** Description Performs NDEF detection for Mifare Classic Tag
132 **
133 ** Upon successful completion of NDEF detection, a
134 ** NFA_NDEF_DETECT_EVT will be sent, to notify the application
135 ** of the NDEF attributes (NDEF total memory size, current
136 ** size, etc.).
137 **
138 ** Returns:
139 ** NFCSTATUS_SUCCESS if successfully initiated
140 ** NFCSTATUS_FAILED otherwise
141 **
142 *******************************************************************************/
EXTNS_MfcCheckNDef(void)143 NFCSTATUS EXTNS_MfcCheckNDef(void) {
144 NFCSTATUS status = NFCSTATUS_SUCCESS;
145 phLibNfc_Message_t msg;
146
147 msg.eMsgType = PH_NXPEXTNS_MIFARE_CHECK_NDEF;
148 msg.pMsgData = NULL;
149 msg.Size = 0;
150
151 status = phNxpExtns_SendMsg(&msg);
152 if (NFCSTATUS_SUCCESS != status) {
153 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
154 }
155
156 return status;
157 }
158
159 /*******************************************************************************
160 **
161 ** Function EXTNS_MfcReadNDef
162 **
163 ** Description Reads NDEF message from Mifare Classic Tag.
164 **
165 ** Upon receiving the NDEF message, the message will be sent to
166 ** the handler registered with
167 *EXTNS_MfcRegisterNDefTypeHandler.
168 **
169 ** Returns:
170 ** NFCSTATUS_SUCCESS if successfully initiated
171 ** NFCSTATUS_FAILED otherwise
172 **
173 *******************************************************************************/
EXTNS_MfcReadNDef(void)174 NFCSTATUS EXTNS_MfcReadNDef(void) {
175 NFCSTATUS status = NFCSTATUS_SUCCESS;
176
177 phLibNfc_Message_t msg;
178
179 msg.eMsgType = PH_NXPEXTNS_MIFARE_READ_NDEF;
180 msg.pMsgData = NULL;
181 msg.Size = 0;
182
183 status = phNxpExtns_SendMsg(&msg);
184 if (NFCSTATUS_SUCCESS != status) {
185 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
186 }
187
188 return status;
189 }
190 /*******************************************************************************
191 **
192 ** Function EXTNS_MfcPresenceCheck
193 **
194 ** Description Do the check presence for Mifare Classic Tag.
195 **
196 **
197 ** Returns:
198 ** NFCSTATUS_SUCCESS if successfully initiated
199 ** NFCSTATUS_FAILED otherwise
200 **
201 *******************************************************************************/
EXTNS_MfcPresenceCheck(void)202 NFCSTATUS EXTNS_MfcPresenceCheck(void) {
203 NFCSTATUS status = NFCSTATUS_SUCCESS;
204
205 phLibNfc_Message_t msg;
206
207 msg.eMsgType = PH_NXPEXTNS_MIFARE_PRESENCE_CHECK;
208 msg.pMsgData = NULL;
209 msg.Size = 0;
210
211 gAuthCmdBuf.status = NFCSTATUS_FAILED;
212 if (sem_init(&gAuthCmdBuf.semPresenceCheck, 0, 0) == -1) {
213 LOG(ERROR) << StringPrintf("%s: semaphore creation failed (errno=%d)",
214 __func__, errno);
215 return NFCSTATUS_FAILED;
216 }
217
218 status = phNxpExtns_SendMsg(&msg);
219 if (NFCSTATUS_SUCCESS != status) {
220 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
221 sem_destroy(&gAuthCmdBuf.semPresenceCheck);
222 }
223
224 return status;
225 }
226
227 /*******************************************************************************
228 **
229 ** Function EXTNS_MfcSetReadOnly
230 **
231 **
232 ** Description:
233 ** Sets tag as read only.
234 **
235 ** When tag is set as read only, or if an error occurs, the app will be
236 ** notified with NFA_SET_TAG_RO_EVT.
237 **
238 ** Returns:
239 ** NFCSTATUS_SUCCESS if successfully initiated
240 ** NFCSTATUS_FAILED otherwise
241 **
242 *******************************************************************************/
EXTNS_MfcSetReadOnly(uint8_t * key,uint8_t len)243 NFCSTATUS EXTNS_MfcSetReadOnly(uint8_t* key, uint8_t len) {
244 NFCSTATUS status = NFCSTATUS_SUCCESS;
245
246 phLibNfc_Message_t msg;
247
248 msg.eMsgType = PH_NXPEXTNS_MIFARE_READ_ONLY;
249 msg.pMsgData = key;
250 msg.Size = len;
251
252 status = phNxpExtns_SendMsg(&msg);
253 if (NFCSTATUS_SUCCESS != status) {
254 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
255 }
256
257 return status;
258 }
259
260 /*******************************************************************************
261 **
262 ** Function EXTNS_MfcWriteNDef
263 **
264 ** Description Writes NDEF data to Mifare Classic Tag.
265 **
266 ** When the entire message has been written, or if an error
267 ** occurs, the app will be notified with NFA_WRITE_CPLT_EVT.
268 **
269 ** p_data needs to be persistent until NFA_WRITE_CPLT_EVT
270 **
271 ** Returns:
272 ** NFCSTATUS_SUCCESS if successfully initiated
273 ** NFCSTATUS_FAILED otherwise
274 **
275 *******************************************************************************/
EXTNS_MfcWriteNDef(uint8_t * p_data,uint32_t len)276 NFCSTATUS EXTNS_MfcWriteNDef(uint8_t* p_data, uint32_t len) {
277 NFCSTATUS status = NFCSTATUS_SUCCESS;
278
279 phLibNfc_Message_t msg;
280
281 msg.eMsgType = PH_NXPEXTNS_MIFARE_WRITE_NDEF;
282 msg.pMsgData = p_data;
283 msg.Size = len;
284
285 status = phNxpExtns_SendMsg(&msg);
286 if (NFCSTATUS_SUCCESS != status) {
287 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
288 }
289
290 return status;
291 }
292
293 /*****************************************************************************
294 **
295 ** Function EXTNS_MfcFormatTag
296 **
297 ** Description Formats Mifare Classic Tag.
298 **
299 ** The NFA_RW_FORMAT_CPLT_EVT, status is used to
300 ** indicate if tag is successfully formated or not
301 **
302 ** Returns
303 ** NFCSTATUS_SUCCESS if successfully initiated
304 ** NFCSTATUS_FAILED otherwise
305 **
306 *****************************************************************************/
EXTNS_MfcFormatTag(uint8_t * key,uint8_t len)307 NFCSTATUS EXTNS_MfcFormatTag(uint8_t* key, uint8_t len) {
308 NFCSTATUS status = NFCSTATUS_SUCCESS;
309
310 phLibNfc_Message_t msg;
311
312 msg.eMsgType = PH_NXPEXTNS_MIFARE_FORMAT_NDEF;
313 msg.pMsgData = key;
314 msg.Size = len;
315
316 status = phNxpExtns_SendMsg(&msg);
317 if (NFCSTATUS_SUCCESS != status) {
318 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
319 }
320
321 return status;
322 }
323
324 /*****************************************************************************
325 **
326 ** Function EXTNS_MfcDisconnect
327 **
328 ** Description Disconnects Mifare Classic Tag.
329 **
330 ** Returns
331 ** NFCSTATUS_SUCCESS if successfully initiated
332 ** NFCSTATUS_FAILED otherwise
333 **
334 *****************************************************************************/
EXTNS_MfcDisconnect(void)335 NFCSTATUS EXTNS_MfcDisconnect(void) {
336 NFCSTATUS status = NFCSTATUS_SUCCESS;
337
338 phLibNfc_Message_t msg;
339
340 msg.eMsgType = PH_NXPEXTNS_DISCONNECT;
341 msg.pMsgData = NULL;
342 msg.Size = 0;
343
344 status = phNxpExtns_SendMsg(&msg);
345 if (NFCSTATUS_SUCCESS != status) {
346 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
347 }
348
349 return status;
350 }
351
352 /*****************************************************************************
353 **
354 ** Function EXTNS_MfcActivated
355 **
356 ** Description Activates Mifare Classic Tag.
357 **
358 ** Returns
359 ** NFCSTATUS_SUCCESS if successfully initiated
360 ** NFCSTATUS_FAILED otherwise
361 **
362 *****************************************************************************/
EXTNS_MfcActivated(void)363 NFCSTATUS EXTNS_MfcActivated(void) {
364 NFCSTATUS status = NFCSTATUS_SUCCESS;
365 phLibNfc_Message_t msg;
366
367 msg.eMsgType = PH_NXPEXTNS_ACTIVATED;
368 msg.pMsgData = NULL;
369 msg.Size = 0;
370
371 status = phNxpExtns_SendMsg(&msg);
372 if (NFCSTATUS_SUCCESS != status) {
373 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
374 }
375
376 return status;
377 }
378
379 /*******************************************************************************
380 **
381 ** Function EXTNS_MfcTransceive
382 **
383 ** Description Sends raw frame to Mifare Classic Tag.
384 **
385 ** Returns NFCSTATUS_SUCCESS if successfully initiated
386 ** NFCSTATUS_FAILED otherwise
387 **
388 *******************************************************************************/
EXTNS_MfcTransceive(uint8_t * p_data,uint32_t len)389 NFCSTATUS EXTNS_MfcTransceive(uint8_t* p_data, uint32_t len) {
390 NFCSTATUS status = NFCSTATUS_SUCCESS;
391
392 phLibNfc_Message_t msg;
393
394 msg.eMsgType = PH_NXPEXTNS_MIFARE_TRANSCEIVE;
395 msg.pMsgData = p_data;
396 msg.Size = len;
397
398 status = phNxpExtns_SendMsg(&msg);
399 if (NFCSTATUS_SUCCESS != status) {
400 LOG(ERROR) << StringPrintf("Error Sending msg to Extension Thread");
401 }
402
403 return status;
404 }
405
406 /*******************************************************************************
407 **
408 ** Function EXTNS_MfcInit
409 **
410 ** Description This function is used to Init Mifare Classic Extns.
411 ** This function should be called when the tag detected is
412 ** Mifare Classic.
413 **
414 ** Returns NFCSTATUS_SUCCESS
415 **
416 *******************************************************************************/
EXTNS_MfcInit(tNFA_ACTIVATED activationData)417 NFCSTATUS EXTNS_MfcInit(tNFA_ACTIVATED activationData) {
418 tNFC_ACTIVATE_DEVT rfDetail = activationData.activate_ntf;
419
420 NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak =
421 rfDetail.rf_tech_param.param.pa.sel_rsp;
422 NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.AtqA[0] =
423 rfDetail.rf_tech_param.param.pa.sens_res[0];
424 NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.AtqA[1] =
425 rfDetail.rf_tech_param.param.pa.sens_res[1];
426
427 return NFCSTATUS_SUCCESS;
428 }
429
430 /*******************************************************************************
431 **
432 ** Function phNxpExtns_ProcessSysMessage
433 **
434 ** Description Internal function to route the request from JNI and Callback
435 ** from NFA_SendRawFrame to right function
436 **
437 ** Returns NFCSTATUS_SUCCESS if valid request
438 ** NFCSTATUS_FAILED otherwise
439 **
440 *******************************************************************************/
phNxpExtns_ProcessSysMessage(phLibNfc_Message_t * msg)441 static NFCSTATUS phNxpExtns_ProcessSysMessage(phLibNfc_Message_t* msg) {
442 NFCSTATUS status = NFCSTATUS_SUCCESS;
443
444 if (gphNxpExtns_Context.Extns_status == EXTNS_STATUS_CLOSE) {
445 return NFCSTATUS_FAILED;
446 }
447
448 switch (msg->eMsgType) {
449 case PH_NXPEXTNS_RX_DATA:
450 status = Mfc_RecvPacket((uint8_t*)msg->pMsgData, msg->Size);
451 break;
452
453 case PH_NXPEXTNS_MIFARE_CHECK_NDEF:
454 pthread_mutex_init(&gAuthCmdBuf.syncmutex, NULL);
455 pthread_mutex_lock(&gAuthCmdBuf.syncmutex);
456 status = Mfc_CheckNdef();
457 pthread_mutex_unlock(&gAuthCmdBuf.syncmutex);
458 pthread_mutex_destroy(&gAuthCmdBuf.syncmutex);
459 break;
460
461 case PH_NXPEXTNS_MIFARE_READ_NDEF:
462 status = Mfc_ReadNdef();
463 break;
464
465 case PH_NXPEXTNS_MIFARE_WRITE_NDEF:
466 status = Mfc_WriteNdef((uint8_t*)msg->pMsgData, msg->Size);
467 break;
468
469 case PH_NXPEXTNS_MIFARE_FORMAT_NDEF:
470 status = Mfc_FormatNdef((uint8_t*)msg->pMsgData, msg->Size);
471 break;
472
473 case PH_NXPEXTNS_DISCONNECT:
474 Mfc_DeactivateCbackSelect();
475 break;
476
477 case PH_NXPEXTNS_ACTIVATED:
478 Mfc_ActivateCback();
479 break;
480
481 case PH_NXPEXTNS_MIFARE_TRANSCEIVE:
482 status = Mfc_Transceive((uint8_t*)msg->pMsgData, msg->Size);
483 break;
484
485 case PH_NXPEXTNS_MIFARE_READ_ONLY:
486 status = Mfc_SetReadOnly((uint8_t*)msg->pMsgData, msg->Size);
487 break;
488 case PH_NXPEXTNS_MIFARE_PRESENCE_CHECK:
489 pthread_mutex_init(&gAuthCmdBuf.syncmutex, NULL);
490 pthread_mutex_lock(&gAuthCmdBuf.syncmutex);
491 status = Mfc_PresenceCheck();
492 pthread_mutex_unlock(&gAuthCmdBuf.syncmutex);
493 pthread_mutex_destroy(&gAuthCmdBuf.syncmutex);
494 break;
495 default:
496 status = NFCSTATUS_FAILED;
497 LOG(ERROR) << StringPrintf("Illegal Command for Extension");
498 break;
499 }
500
501 return status;
502 }
503
504 /*******************************************************************************
505 **
506 ** Function phNxpExtns_SendMsg
507 **
508 ** Description unlocks phNxpExtns_ProcessSysMessage with a valid message
509 **
510 ** Returns NFCSTATUS_SUCCESS if successfully initiated
511 ** NFCSTATUS_FAILED otherwise
512 **
513 *******************************************************************************/
phNxpExtns_SendMsg(phLibNfc_Message_t * sysmsg)514 static NFCSTATUS phNxpExtns_SendMsg(phLibNfc_Message_t* sysmsg) {
515 NFCSTATUS status = NFCSTATUS_SUCCESS;
516
517 status = phNxpExtns_ProcessSysMessage(sysmsg);
518
519 return status;
520 }
521
522 /*******************************************************************************
523 **
524 ** Function EXTNS_MfcRegisterNDefTypeHandler
525 **
526 ** Description This function allows the applications to register for
527 ** specific types of NDEF records.
528 **
529 ** For records types which were not registered, the record will
530 ** be sent to the default handler.
531 **
532 ** Returns NFCSTATUS_SUCCESS
533 **
534 *******************************************************************************/
535 NFCSTATUS
EXTNS_MfcRegisterNDefTypeHandler(tNFA_NDEF_CBACK * ndefHandlerCallback)536 EXTNS_MfcRegisterNDefTypeHandler(tNFA_NDEF_CBACK* ndefHandlerCallback) {
537 NFCSTATUS status = NFCSTATUS_FAILED;
538 if (NULL != ndefHandlerCallback) {
539 gphNxpExtns_Context.p_ndef_cback = ndefHandlerCallback;
540 status = NFCSTATUS_SUCCESS;
541 }
542
543 return status;
544 }
545
546 /*******************************************************************************
547 ** Synchronizing Functions **
548 ** Synchronizes Callback in JNI and MFC Extns **
549 *******************************************************************************/
550
EXTNS_GetConnectFlag(void)551 bool_t EXTNS_GetConnectFlag(void) { return (gphNxpExtns_Context.ExtnsConnect); }
552
EXTNS_SetConnectFlag(bool_t flagval)553 void EXTNS_SetConnectFlag(bool_t flagval) {
554 gphNxpExtns_Context.ExtnsConnect = flagval;
555 }
556
EXTNS_GetDeactivateFlag(void)557 bool_t EXTNS_GetDeactivateFlag(void) {
558 return (gphNxpExtns_Context.ExtnsDeactivate);
559 }
560
EXTNS_SetDeactivateFlag(bool_t flagval)561 void EXTNS_SetDeactivateFlag(bool_t flagval) {
562 gphNxpExtns_Context.ExtnsDeactivate = flagval;
563 }
564
EXTNS_GetCallBackFlag(void)565 bool_t EXTNS_GetCallBackFlag(void) {
566 return (gphNxpExtns_Context.ExtnsCallBack);
567 }
568
EXTNS_SetCallBackFlag(bool_t flagval)569 void EXTNS_SetCallBackFlag(bool_t flagval) {
570 gphNxpExtns_Context.ExtnsCallBack = flagval;
571 }
EXTNS_GetPresenceCheckStatus(void)572 NFCSTATUS EXTNS_GetPresenceCheckStatus(void) {
573 struct timespec ts;
574
575 clock_gettime(CLOCK_REALTIME, &ts);
576 ts.tv_sec += 0;
577 ts.tv_nsec += 100 * 1000 * 1000; // 100 milisec
578 if (ts.tv_nsec >= 1000 * 1000 * 1000) {
579 ts.tv_sec += 1;
580 ts.tv_nsec = ts.tv_nsec - (1000 * 1000 * 1000);
581 }
582
583 if (sem_timedwait(&gAuthCmdBuf.semPresenceCheck, &ts)) {
584 LOG(ERROR) << StringPrintf("%s: failed to wait (errno=%d)", __func__,
585 errno);
586 sem_destroy(&gAuthCmdBuf.semPresenceCheck);
587 gAuthCmdBuf.auth_sent = false;
588 return NFCSTATUS_FAILED;
589 }
590 if (sem_destroy(&gAuthCmdBuf.semPresenceCheck)) {
591 LOG(ERROR) << StringPrintf(
592 "%s: Failed to destroy check Presence semaphore (errno=%d)", __func__,
593 errno);
594 }
595 return gAuthCmdBuf.status;
596 }
597
MfcPresenceCheckResult(NFCSTATUS status)598 void MfcPresenceCheckResult(NFCSTATUS status) {
599 gAuthCmdBuf.status = status;
600 EXTNS_SetCallBackFlag(true);
601 sem_post(&gAuthCmdBuf.semPresenceCheck);
602 }
MfcResetPresenceCheckStatus(void)603 void MfcResetPresenceCheckStatus(void) { gAuthCmdBuf.auth_sent = false; }
604 /*******************************************************************************
605 **
606 ** Function EXTNS_CheckMfcResponse
607 **
608 ** Description This function is called from JNI Transceive for Mifare
609 ** Classic Tag status interpretation and to send the required
610 ** status to application
611 **
612 ** Returns NFCSTATUS_SUCCESS
613 ** NFCSTATUS_FAILED
614 **
615 *******************************************************************************/
EXTNS_CheckMfcResponse(uint8_t ** sTransceiveData,uint32_t * sTransceiveDataLen)616 NFCSTATUS EXTNS_CheckMfcResponse(uint8_t** sTransceiveData,
617 uint32_t* sTransceiveDataLen) {
618 NFCSTATUS status = NFCSTATUS_SUCCESS;
619
620 if (*sTransceiveDataLen == 3) {
621 if ((*sTransceiveData)[0] == 0x10 && (*sTransceiveData)[1] != 0x0A) {
622 LOG(ERROR) << StringPrintf("Mifare Error in payload response");
623 *sTransceiveDataLen = 0x1;
624 *sTransceiveData += 1;
625 return NFCSTATUS_FAILED;
626 }
627 }
628 if ((*sTransceiveData)[0] == 0x40) {
629 *sTransceiveData += 1;
630 *sTransceiveDataLen = 0x01;
631 if ((*sTransceiveData)[0] == 0x03) {
632 *sTransceiveDataLen = 0x00;
633 status = NFCSTATUS_FAILED;
634 }
635 } else if ((*sTransceiveData)[0] == 0x10) {
636 *sTransceiveData += 1;
637 *sTransceiveDataLen = 0x10;
638 }
639
640 return status;
641 }
642