blob: 405d0e98dca1970bb94d69e53fa490ad1f55e61e [file] [log] [blame]
nxpandroid64fd68c2015-09-23 16:45:15 +05301/*
2 * Copyright (C) 2012 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/******************************************************************************
17 *
18 * The original Work has been changed by NXP Semiconductors.
19 *
20 * Copyright (C) 2015 NXP Semiconductors
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 *
34 ******************************************************************************/
35#include <semaphore.h>
36#include <errno.h>
37#include "OverrideLog.h"
38#include "NfcJniUtil.h"
39#include "SyncEvent.h"
40#include "JavaClassConstants.h"
41#include "config.h"
42#include "NfcAdaptation.h"
43
44extern "C"
45{
46#include "nfa_api.h"
47#include "nfa_rw_api.h"
48}
49/* Structure to store screen state */
50typedef enum screen_state
51{
52 NFA_SCREEN_STATE_DEFAULT = 0x00,
53 NFA_SCREEN_STATE_OFF,
54 NFA_SCREEN_STATE_LOCKED,
55 NFA_SCREEN_STATE_UNLOCKED
56}eScreenState_t;
57typedef struct nxp_feature_data
58{
59 SyncEvent NxpFeatureConfigEvt;
60 tNFA_STATUS wstatus;
61 UINT8 rsp_data[255];
62 UINT8 rsp_len;
63}Nxp_Feature_Data_t;
64
65extern INT32 gActualSeCount;
nxpandroid34627bd2016-05-27 15:52:30 +053066#if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE))
67extern UINT8 sSelectedUicc;
68#endif
nxpandroid64fd68c2015-09-23 16:45:15 +053069namespace android
70{
71static Nxp_Feature_Data_t gnxpfeature_conf;
72void SetCbStatus(tNFA_STATUS status);
73tNFA_STATUS GetCbStatus(void);
74static void NxpResponse_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param);
75static void NxpResponse_SetDhlf_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param);
76static void NxpResponse_SetVenConfig_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param);
77}
78
79namespace android
80{
81void SetCbStatus(tNFA_STATUS status)
82{
83 gnxpfeature_conf.wstatus = status;
84}
85
86tNFA_STATUS GetCbStatus(void)
87{
88 return gnxpfeature_conf.wstatus;
89}
90
91static void NxpResponse_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param)
92{
93 (void)event;
94 ALOGD("NxpResponse_Cb Received length data = 0x%x status = 0x%x", param_len, p_param[3]);
95
96 if(p_param[3] == 0x00)
97 {
98 SetCbStatus(NFA_STATUS_OK);
99 }
100 else
101 {
102 SetCbStatus(NFA_STATUS_FAILED);
103 }
104
105 SyncEventGuard guard(gnxpfeature_conf.NxpFeatureConfigEvt);
106 gnxpfeature_conf.NxpFeatureConfigEvt.notifyOne ();
107
108}
109static void NxpResponse_SetDhlf_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param)
110{
111 (void)event;
112 ALOGD("NxpResponse_SetDhlf_Cb Received length data = 0x%x status = 0x%x", param_len, p_param[3]);
113
114 if(p_param[3] == 0x00)
115 {
116 SetCbStatus(NFA_STATUS_OK);
117 }
118 else
119 {
120 SetCbStatus(NFA_STATUS_FAILED);
121 }
122
123 SyncEventGuard guard(gnxpfeature_conf.NxpFeatureConfigEvt);
124 gnxpfeature_conf.NxpFeatureConfigEvt.notifyOne ();
125
126}
127
128static void NxpResponse_SetVenConfig_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param)
129{
130 ALOGD("NxpResponse_SetVenConfig_Cb Received length data = 0x%x status = 0x%x", param_len, p_param[3]);
131 if(p_param[3] == 0x00)
132 {
133 SetCbStatus(NFA_STATUS_OK);
134 }
135 else
136 {
137 SetCbStatus(NFA_STATUS_FAILED);
138 }
139 SyncEventGuard guard(gnxpfeature_conf.NxpFeatureConfigEvt);
140 gnxpfeature_conf.NxpFeatureConfigEvt.notifyOne ();
141}
142
143static void NxpResponse_SetSWPBitRate_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param)
144{
145 ALOGD("NxpResponse_SetSWPBitRate_CbReceived length data = 0x%x status = 0x%x", param_len, p_param[3]);
146 if(p_param[3] == 0x00)
147 {
148 SetCbStatus(NFA_STATUS_OK);
149 }
150 else
151 {
152 SetCbStatus(NFA_STATUS_FAILED);
153 }
154 SyncEventGuard guard(gnxpfeature_conf.NxpFeatureConfigEvt);
155 gnxpfeature_conf.NxpFeatureConfigEvt.notifyOne ();
156}
157
nxpandroid1153eb32015-11-06 18:46:58 +0530158#if(NXP_EXTNS == TRUE)
nxpandroid34627bd2016-05-27 15:52:30 +0530159#if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)
160/*******************************************************************************
161 **
162 ** Function: NxpResponse_SwitchUICC_Cb
163 **
164 ** Description: Callback for siwtch UICC is handled
165 ** Notifies NxpFeatureConfigEvt
166 **
167 ** Returns: None
168 **
169 *******************************************************************************/
170static void NxpResponse_SwitchUICC_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param)
171{
172 ALOGD("NxpResponse_SwitchUICC_Cb length data = 0x%x status = 0x%x", param_len, p_param[3]);
173 if(p_param[3] == 0x00)
174 {
175 SetCbStatus(NFA_STATUS_OK);
176 }
177 else
178 {
179 SetCbStatus(NFA_STATUS_FAILED);
180 }
181 SyncEventGuard guard(gnxpfeature_conf.NxpFeatureConfigEvt);
182 gnxpfeature_conf.NxpFeatureConfigEvt.notifyOne ();
183}
184#endif
185#if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))
nxpandroid64fd68c2015-09-23 16:45:15 +0530186/*******************************************************************************
187 **
188 ** Function: NxpResponse_EnableAGCDebug_Cb()
189 **
190 ** Description: Cb to handle the response of AGC command
191 **
192 ** Returns: success/failure
193 **
194 *******************************************************************************/
195static void NxpResponse_EnableAGCDebug_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param)
196{
197 ALOGD("NxpResponse_EnableAGCDebug_Cb Received length data = 0x%x", param_len);
198 SetCbStatus(NFA_STATUS_FAILED);
199 if(param_len > 0)
200 {
201 gnxpfeature_conf.rsp_len = param_len;
202 memcpy(gnxpfeature_conf.rsp_data, p_param, gnxpfeature_conf.rsp_len);
203 SetCbStatus(NFA_STATUS_OK);
204 }
205 SyncEventGuard guard(gnxpfeature_conf.NxpFeatureConfigEvt);
206 gnxpfeature_conf.NxpFeatureConfigEvt.notifyOne ();
207}
208/*******************************************************************************
209 **
210 ** Function: printDataByte()
211 **
212 ** Description: Prints the AGC values
213 **
214 ** Returns: success/failure
215 **
216 *******************************************************************************/
217static void printDataByte(UINT16 param_len, UINT8 *p_param)
218{
219 char print_buffer[param_len * 3 + 1];
220 memset (print_buffer, 0, sizeof(print_buffer));
221 for (int i = 0; i < param_len; i++)
222 {
223 snprintf(&print_buffer[i * 2], 3 ,"%02X", p_param[i]);
224 }
225 ALOGD("AGC Dynamic RSSI values = %s", print_buffer);
226}
227/*******************************************************************************
228 **
229 ** Function: SendAGCDebugCommand()
230 **
231 ** Description: Sends the AGC Debug command.This enables dynamic RSSI
232 ** look up table filling for different "TX RF settings" and enables
233 ** MWdebug prints.
234 **
235 ** Returns: success/failure
236 **
237 *******************************************************************************/
238tNFA_STATUS SendAGCDebugCommand()
239{
240 tNFA_STATUS status = NFA_STATUS_FAILED;
241 uint8_t cmd_buf[] = {0x2F, 0x33, 0x04, 0x40, 0x00, 0x40, 0xD8};
242 uint8_t dynamic_rssi_buf[50];
243 ALOGD("%s: enter", __FUNCTION__);
244 SetCbStatus(NFA_STATUS_FAILED);
245 gnxpfeature_conf.rsp_len = 0;
246 memset(gnxpfeature_conf.rsp_data, 0, 50);
247 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
248 status = NFA_SendNxpNciCommand(sizeof(cmd_buf), cmd_buf, NxpResponse_EnableAGCDebug_Cb);
249 if (status == NFA_STATUS_OK)
250 {
251 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
252 gnxpfeature_conf.NxpFeatureConfigEvt.wait(1000); /* wait for callback */
253 }
254 else
255 { tNFA_STATUS status = NFA_STATUS_FAILED;
256 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
257 }
258 status = GetCbStatus();
259 if(status == NFA_STATUS_OK && gnxpfeature_conf.rsp_len > 0)
260 {
261 printDataByte(gnxpfeature_conf.rsp_len, gnxpfeature_conf.rsp_data);
262 }
263 return status;
264}
265#endif
266/*******************************************************************************
267 **
268 ** Function: EmvCo_dosetPoll
269 **
270 ** Description: Enable/disable Emv Co polling
271 **
272 ** Returns: success/failure
273 **
274 *******************************************************************************/
275tNFA_STATUS EmvCo_dosetPoll(jboolean enable)
276{
277 tNFA_STATUS status = NFA_STATUS_FAILED;
278 uint8_t cmd_buf[] ={0x20, 0x02, 0x05, 0x01, 0xA0, 0x44, 0x01, 0x00};
279
280 ALOGD("%s: enter", __FUNCTION__);
281
282 SetCbStatus(NFA_STATUS_FAILED);
283 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
284 if(enable)
285 {
286 NFA_SetEmvCoState(TRUE);
287 ALOGD("EMV-CO polling profile");
288 cmd_buf[7] = 0x01; /*EMV-CO Poll*/
289 }
290 else
291 {
292 NFA_SetEmvCoState(FALSE);
293 ALOGD("NFC forum polling profile");
294 }
295 status = NFA_SendNxpNciCommand(sizeof(cmd_buf), cmd_buf, NxpResponse_Cb);
296 if (status == NFA_STATUS_OK) {
297 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
298 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
299 } else {
300 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
301 }
302
303 status = GetCbStatus();
304 return status;
305}
306
307/*******************************************************************************
308 **
309 ** Function: SetScreenState
310 **
311 ** Description: set/clear SetScreenState
312 **
313 ** Returns: success/failure
314 **
315 *******************************************************************************/
316tNFA_STATUS SetScreenState(jint state)
317{
318 tNFA_STATUS status = NFA_STATUS_FAILED;
319 uint8_t screen_off_state_cmd_buff[] = {0x2F, 0x15, 0x01, 0x01};
320
321 ALOGD("%s: enter", __FUNCTION__);
322
323 SetCbStatus(NFA_STATUS_FAILED);
324 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
325 if(state == NFA_SCREEN_STATE_OFF)
326 {
327 ALOGD("Set Screen OFF");
328 screen_off_state_cmd_buff[3] = 0x01;
329 }
330 else if(state == NFA_SCREEN_STATE_LOCKED)
331 {
332 ALOGD("Screen ON-locked");
333 screen_off_state_cmd_buff[3] = 0x02;
334 }
335 else if(state == NFA_SCREEN_STATE_UNLOCKED)
336 {
337 ALOGD("Screen ON-Unlocked");
338 screen_off_state_cmd_buff[3] = 0x00;
339 }
340 else
341 {
342 ALOGD("Invalid screen state");
343 }
344 status = NFA_SendNxpNciCommand(sizeof(screen_off_state_cmd_buff), screen_off_state_cmd_buff, NxpResponse_SetDhlf_Cb);
345 if (status == NFA_STATUS_OK) {
346 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
347 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
348 } else {
349 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
350 }
351
352 status = GetCbStatus();
353 return status;
354}
355
nxpandroid64fd68c2015-09-23 16:45:15 +0530356/*******************************************************************************
357 **
358 ** Function: SendAutonomousMode
359 **
360 ** Description: set/clear SetDHListenFilter
361 **
362 ** Returns: success/failure
363 **
364 *******************************************************************************/
365tNFA_STATUS SendAutonomousMode(jint state ,uint8_t num)
366{
367 tNFA_STATUS status = NFA_STATUS_FAILED;
368 uint8_t autonomos_cmd_buff[] = {0x2F, 0x00, 0x01, 0x00};
369 uint8_t core_standby = 0x0;
370
371
372 ALOGD("%s: enter", __FUNCTION__);
373
374 SetCbStatus(NFA_STATUS_FAILED);
375 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
376 if(state == NFA_SCREEN_STATE_OFF )
377 {
378 ALOGD("Set Screen OFF");
379 /*Standby mode is automatically set with Autonomous mode
380 * Value of core_standby will not be considering when state is in SCREEN_OFF Mode*/
381 autonomos_cmd_buff[3] = 0x02;
382 }
383 else if(state == NFA_SCREEN_STATE_UNLOCKED )
384 {
385 ALOGD("Screen ON-Unlocked");
386 core_standby = num;
387 autonomos_cmd_buff[3] = 0x00 | core_standby;
388 }
389 else if(state == NFA_SCREEN_STATE_LOCKED)
390 {
391 core_standby = num;
392 autonomos_cmd_buff[3] = 0x00 | core_standby;
393 }
394 else
395 {
396 ALOGD("Invalid screen state");
397 return NFA_STATUS_FAILED;
398 }
399 status = NFA_SendNxpNciCommand(sizeof(autonomos_cmd_buff), autonomos_cmd_buff, NxpResponse_SetDhlf_Cb);
400 if (status == NFA_STATUS_OK) {
401 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
402 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
403 } else {
404 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
405 }
406
407 status = GetCbStatus();
408 return status;
409}
nxpandroid64fd68c2015-09-23 16:45:15 +0530410//Factory Test Code --start
411/*******************************************************************************
412 **
413 ** Function: Nxp_SelfTest
414 **
415 ** Description: SelfTest SWP, PRBS
416 **
417 ** Returns: success/failure
418 **
419 *******************************************************************************/
420tNFA_STATUS Nxp_SelfTest(uint8_t testcase, uint8_t* param)
421{
422 tNFA_STATUS status = NFA_STATUS_FAILED;
423 uint8_t swp_test[] ={0x2F, 0x3E, 0x01, 0x00}; //SWP SelfTest
nxpandroid34627bd2016-05-27 15:52:30 +0530424#if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))
nxpandroid64fd68c2015-09-23 16:45:15 +0530425 uint8_t prbs_test[] ={0x2F, 0x30, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF}; //PRBS SelfTest
426 uint8_t cmd_buf[9] = {0,};
427#else
428 uint8_t prbs_test[] ={0x2F, 0x30, 0x04, 0x00, 0x00, 0x01, 0xFF}; //PRBS SelfTest
429 uint8_t cmd_buf[7] = {0,};
430#endif
431 //Factory Test Code for PRBS STOP --/
432// uint8_t prbs_stop[] ={0x2F, 0x30, 0x04, 0x53, 0x54, 0x4F, 0x50}; //STOP!! /*commented to eliminate unused variable warning*/
433 uint8_t rst_cmd[] ={0x20, 0x00, 0x01, 0x00}; //CORE_RESET_CMD
434 uint8_t init_cmd[] ={0x20, 0x01, 0x00}; //CORE_INIT_CMD
435 uint8_t prop_ext_act_cmd[] ={0x2F, 0x02, 0x00}; //CORE_INIT_CMD
436
437 //Factory Test Code for PRBS STOP --/
438 uint8_t cmd_len = 0;
439
440 ALOGD("%s: enter", __FUNCTION__);
441
442 NfcAdaptation& theInstance = NfcAdaptation::GetInstance();
443 tHAL_NFC_ENTRY* halFuncEntries = theInstance.GetHalEntryFuncs ();
444
445 SetCbStatus(NFA_STATUS_FAILED);
446 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
447
448 memset(cmd_buf, 0x00, sizeof(cmd_buf));
449
450 switch(testcase){
451 case 0 ://SWP Self-Test
452 cmd_len = sizeof(swp_test);
453 swp_test[3] = param[0]; //select channel 0x00:UICC(SWP1) 0x01:eSE(SWP2)
454 memcpy(cmd_buf, swp_test, 4);
455 break;
456
457 case 1 ://PRBS Test start
458 cmd_len = sizeof(prbs_test);
459 //Technology to stream 0x00:TypeA 0x01:TypeB 0x02:TypeF
460 //Bitrate 0x00:106kbps 0x01:212kbps 0x02:424kbps 0x03:848kbps
461 memcpy(&prbs_test[3], param, (cmd_len-5));
462 memcpy(cmd_buf, prbs_test, cmd_len);
463 break;
464
465 //Factory Test Code
466 case 2 ://step1. PRBS Test stop : VEN RESET
467 halFuncEntries->power_cycle();
468 return NFCSTATUS_SUCCESS;
469 break;
470
471 case 3 ://step2. PRBS Test stop : CORE RESET
472 cmd_len = sizeof(rst_cmd);
473 memcpy(cmd_buf, rst_cmd, 4);
474 break;
475
476 case 4 ://step3. PRBS Test stop : CORE_INIT
477 cmd_len = sizeof(init_cmd);
478 memcpy(cmd_buf, init_cmd, cmd_len);
479 break;
480 //Factory Test Code
481
482 case 5 ://step5. : NXP_ACT_PROP_EXTN
483 cmd_len = sizeof(prop_ext_act_cmd);
484 memcpy(cmd_buf, prop_ext_act_cmd, 3);
485 break;
486
487 default :
488 ALOGD("NXP_SelfTest Invalid Parameter!!");
489 return status;
490 }
491
492 status = NFA_SendNxpNciCommand(cmd_len, cmd_buf, NxpResponse_SetDhlf_Cb);
493 if (status == NFA_STATUS_OK) {
494 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
495 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
496 } else {
497 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
498 }
499
500 status = GetCbStatus();
501 return status;
502}
503//Factory Test Code --end
504
505/*******************************************************************************
506 **
507 ** Function: SetVenConfigValue
508 **
509 ** Description: setting the Ven Config Value
510 **
511 ** Returns: success/failure
512 **
513 *******************************************************************************/
nxpandroida9a68ba2016-01-14 21:12:17 +0530514tNFA_STATUS SetVenConfigValue(jint nfcMode)
nxpandroid64fd68c2015-09-23 16:45:15 +0530515{
516 tNFA_STATUS status = NFA_STATUS_FAILED;
517 uint8_t cmd_buf[] = {0x20, 0x02, 0x05, 0x01, 0xA0, 0x07, 0x01, 0x03};
518 ALOGD("%s: enter", __FUNCTION__);
nxpandroida9a68ba2016-01-14 21:12:17 +0530519 if(nfcMode == NFC_MODE_OFF)
nxpandroid64fd68c2015-09-23 16:45:15 +0530520 {
521 ALOGD("Setting the VEN_CFG to 2, Disable ESE events");
522 cmd_buf[7] = 0x02;
523 }
nxpandroida9a68ba2016-01-14 21:12:17 +0530524 else if(nfcMode == NFC_MODE_ON)
nxpandroid64fd68c2015-09-23 16:45:15 +0530525 {
526 ALOGD("Setting the VEN_CFG to 3, Make ");
527 cmd_buf[7] = 0x03;
528 }
529 else
530 {
531 ALOGE("Wrong VEN_CFG Value");
532 return status;
533 }
534 SetCbStatus(NFA_STATUS_FAILED);
535 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
536 status = NFA_SendNxpNciCommand(sizeof(cmd_buf), cmd_buf, NxpResponse_SetVenConfig_Cb);
537 if (status == NFA_STATUS_OK)
538 {
539 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
540 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
541 }
542 else
543 {
544 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
545 }
546 status = GetCbStatus();
547 return status;
548}
549
550static void NxpResponse_GetSwpStausValueCb(UINT8 event, UINT16 param_len, UINT8 *p_param)
551{
552 ALOGD("NxpResponse_GetSwpStausValueCb length data = 0x%x status = 0x%x", param_len, p_param[3]);
553 if(p_param[3] == 0x00)
554 {
555 if (p_param[8] != 0x00)
556 {
557 ALOGD("SWP1 Interface is enabled");
nxpandroid34627bd2016-05-27 15:52:30 +0530558#if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)
559 sSelectedUicc = (p_param[8] & 0x0F);
560#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530561 gActualSeCount++;
562 }
563 if (p_param[12] != 0x00)
564 {
565 ALOGD("SWP2 Interface is enabled");
566 gActualSeCount++;
567 }
568 }
569 else
570 {
571 /* for fail case assign max no of smx */
572 gActualSeCount = 3;
573 }
574 SetCbStatus(NFA_STATUS_OK);
575 SyncEventGuard guard(gnxpfeature_conf.NxpFeatureConfigEvt);
576 gnxpfeature_conf.NxpFeatureConfigEvt.notifyOne ();
577}
578/*******************************************************************************
579 **
580 ** Function: GetSwpStausValue
581 **
582 ** Description: Get the current SWP1 and SWP2 status
583 **
584 ** Returns: success/failure
585 **
586 *******************************************************************************/
587tNFA_STATUS GetSwpStausValue(void)
588{
589 tNFA_STATUS status = NFA_STATUS_FAILED;
590 gActualSeCount = 1; /* default ese present */
591 uint8_t cmd_buf[] = {0x20, 0x03, 0x05, 0x02, 0xA0, 0xEC, 0xA0, 0xED};
592 ALOGD("%s: enter", __FUNCTION__);
593
594 SetCbStatus(NFA_STATUS_FAILED);
595 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
596 status = NFA_SendNxpNciCommand(sizeof(cmd_buf), cmd_buf, NxpResponse_GetSwpStausValueCb);
597 if (status == NFA_STATUS_OK)
598 {
599 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
600 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
601 }
602 else
603 {
604 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
605 }
606 status = GetCbStatus();
607 ALOGD("%s : gActualSeCount = %d",__FUNCTION__, gActualSeCount);
608 return status;
609}
610
611#if(NFC_NXP_HFO_SETTINGS == TRUE)
612/*******************************************************************************
613 **
614 ** Function: SetHfoConfigValue
615 **
616 ** Description: Configuring the HFO clock in case of phone power off
617 ** to make CE works in phone off.
618 **
619 ** Returns: success/failure
620 **
621 *******************************************************************************/
622tNFA_STATUS SetHfoConfigValue(void)
623{
624/* set 4 RF registers for phone off
625 *
626# A0, 0D, 06, 06, 83, 10, 10, 40, 00 RF_CLIF_CFG_TARGET CLIF_DPLL_GEAR_REG
627# A0, 0D, 06, 06, 82, 13, 14, 17, 00 RF_CLIF_CFG_TARGET CLIF_DPLL_INIT_REG
628# A0, 0D, 06, 06, 84, AA, 85, 00, 00 RF_CLIF_CFG_TARGET CLIF_DPLL_INIT_FREQ_REG
629# A0, 0D, 06, 06, 81, 63, 02, 00, 00 RF_CLIF_CFG_TARGET CLIF_DPLL_CONTROL_REG
630*/
631/* default value of four registers in nxp-ALMSL.conf need to set in full power on
632# A0, 0D, 06, 06, 83, 55, 2A, 04, 00 RF_CLIF_CFG_TARGET CLIF_DPLL_GEAR_REG
633# A0, 0D, 06, 06, 82, 33, 14, 17, 00 RF_CLIF_CFG_TARGET CLIF_DPLL_INIT_REG
634# A0, 0D, 06, 06, 84, AA, 85, 00, 80 RF_CLIF_CFG_TARGET CLIF_DPLL_INIT_FREQ_REG
635# A0, 0D, 06, 06, 81, 63, 00, 00, 00 RF_CLIF_CFG_TARGET CLIF_DPLL_CONTROL_REG
636
637*/
638 tNFA_STATUS status = NFA_STATUS_FAILED;
639 uint8_t cmd_buf[] = {0x20, 0x02, 0x29, 0x05, 0xA0, 0x03, 0x01, 0x06,
640 0xA0, 0x0D, 0x06, 0x06, 0x83, 0x10, 0x10, 0x40, 0x00,
641 0xA0, 0x0D, 0x06, 0x06, 0x82, 0x13, 0x14, 0x17, 0x00,
642 0xA0, 0x0D, 0x06, 0x06, 0x84, 0xAA, 0x85, 0x00, 0x00,
643 0xA0, 0x0D, 0x06, 0x06, 0x81, 0x63, 0x02, 0x00, 0x00 };
644 ALOGD("%s: enter", __FUNCTION__);
645
646 SetCbStatus(NFA_STATUS_FAILED);
647 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
648 status = NFA_SendNxpNciCommand(sizeof(cmd_buf), cmd_buf, NxpResponse_SetVenConfig_Cb);
649 if (status == NFA_STATUS_OK)
650 {
651 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
652 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
653 }
654 else
655 {
656 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
657 }
658 status = GetCbStatus();
659 if (NFA_STATUS_OK == status)
660 {
661 ALOGD ("%s: HFO Settinng Success", __FUNCTION__);
662 // TBD write value in temp file in /data/nfc
663 // At next boot hal will read this file and re-apply the
664 // Default Clock setting
665 }
666 ALOGD("%s: exit", __FUNCTION__);
667 return status;
668}
669#endif
670
671/*******************************************************************************
672 **
673 ** Function: ResetEseSession
674 **
675 ** Description: Resets the Ese session identity to FF
676 **
677 ** Returns: success/failure
678 **
679 *******************************************************************************/
680tNFA_STATUS ResetEseSession()
681{
682 tNFA_STATUS status = NFA_STATUS_FAILED;
683 static uint8_t cmd_buf[] = { 0x20, 0x02, 0x0C, 0x01,
684 0xA0, 0xEB, 0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
685 ALOGD("%s: enter", __FUNCTION__);
686
687 SetCbStatus(NFA_STATUS_FAILED);
688 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
689 status = NFA_SendNxpNciCommand(sizeof(cmd_buf), cmd_buf, NxpResponse_Cb);
690 if (status == NFA_STATUS_OK)
691 {
692 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
693 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
694 }
695 else
696 {
697 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
698 }
699 status = GetCbStatus();
700 if (NFA_STATUS_OK == status)
701 {
702 ALOGD ("%s: ResetEseSession identity is Success", __FUNCTION__);
703 }
704 ALOGD("%s: exit", __FUNCTION__);
705 return status;
706}
707/*******************************************************************************
708 **
709 ** Function: SetUICC_SWPBitRate()
710 **
711 ** Description: Get All UICC Parameters and set SWP bit rate
712 **
713 ** Returns: success/failure
714 **
715 *******************************************************************************/
716tNFA_STATUS SetUICC_SWPBitRate(bool isMifareSupported)
717{
718 tNFA_STATUS status = NFA_STATUS_FAILED;
719 uint8_t cmd_buf[] ={0x20, 0x02, 0x05, 0x01, 0xA0, 0xC0, 0x01, 0x03};
720
721 if(isMifareSupported)
722 {
723 ALOGD("Setting the SWP_BITRATE_INT1 to 0x06 (1250 kb/s)");
724 cmd_buf[7] = 0x06;
725 }
726 else
727 {
728 ALOGD("Setting the SWP_BITRATE_INT1 to 0x04 (910 kb/s)");
729 cmd_buf[7] = 0x04;
730 }
731
732 SetCbStatus(NFA_STATUS_FAILED);
733 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
734 status = NFA_SendNxpNciCommand(sizeof(cmd_buf), cmd_buf, NxpResponse_SetSWPBitRate_Cb);
735 if (status == NFA_STATUS_OK)
736 {
737 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
738 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
739 }
740 else
741 {
742 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
743 }
744 status = GetCbStatus();
745 return status;
746}
nxpandroid34627bd2016-05-27 15:52:30 +0530747
748void start_timer_msec(struct timeval *start_tv)
749{
750 gettimeofday(start_tv, NULL);
751}
752
753long stop_timer_getdifference_msec(struct timeval *start_tv, struct timeval *stop_tv)
754{
755 gettimeofday(stop_tv, NULL);
756 return ((long) (stop_tv->tv_sec - start_tv->tv_sec)*1000L +
757 (long) (stop_tv->tv_usec - start_tv->tv_usec)/1000L);
758}
759
760#endif
761#if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)
762/*******************************************************************************
763 **
764 ** Function: Set_EERegisterValue()
765 **
766 ** Description: Prepare NCI_SET_CONFIG command with configuration parameter
767 ** value, masking bits and bit value
768 **
769 ** Returns: success/failure
770 **
771 *******************************************************************************/
772tNFA_STATUS Set_EERegisterValue(UINT16 RegAddr, uint8_t bitVal)
773{
774 tNFA_STATUS status = NFC_STATUS_FAILED;
775 uint8_t swp1conf[] = {0x20,0x02,0x05,0x01,0x00,0x00,0x01,0x00};
776 ALOGD ("Enter: Prepare SWP1 configurations");
777 swp1conf[4] = (uint8_t)((RegAddr & 0xFF00)>>8);
778 swp1conf[5] = (uint8_t)(RegAddr & 0x00FF);
779 swp1conf[7] = (uint8_t)(0xFF & bitVal);
780 //swp1conf[7] = 0x01;
781 ALOGD ("Exit: Prepare SWP1 configurations");
782
783 SetCbStatus(NFA_STATUS_FAILED);
784 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
785
786 status = NFA_SendNxpNciCommand(sizeof(swp1conf), swp1conf, NxpResponse_SwitchUICC_Cb);
787 if (status == NFA_STATUS_OK)
788 {
789 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
790 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
791 status = NFA_STATUS_FAILED;
792 }
793 else
794 {
795 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
796 }
797 status = GetCbStatus();
798 return status;
799}
800
801#endif
802#if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE))
803/*******************************************************************************
804+ **
805+ ** Function: NxpNfc_Write_Cmd()
806+ **
807+ ** Description: Writes the command to NFCC
808+ **
809+ ** Returns: success/failure
810+ **
811+ *******************************************************************************/
812tNFA_STATUS NxpNfc_Write_Cmd_Common(uint8_t retlen, uint8_t* buffer)
813{
814 tNFA_STATUS status = NFA_STATUS_FAILED;
815 SetCbStatus(NFA_STATUS_FAILED);
816 SyncEventGuard guard (gnxpfeature_conf.NxpFeatureConfigEvt);
817 status = NFA_SendNxpNciCommand(retlen, buffer, NxpResponse_Cb);
818 if (status == NFA_STATUS_OK)
819 {
820 ALOGD ("%s: Success NFA_SendNxpNciCommand", __FUNCTION__);
821 gnxpfeature_conf.NxpFeatureConfigEvt.wait(); /* wait for callback */
822 }
823 else
824 {
825 ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__);
826 }
827 status = GetCbStatus();
828 return status;
829}
nxpandroid64fd68c2015-09-23 16:45:15 +0530830#endif
831} /*namespace android*/