1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
/*
* Copyright (C) 2010 NXP Semiconductors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*!
* \file phLibNfc_SE.c
* Project: NFC FRI / HALDL
*
* $Date: Thu Apr 22 13:59:50 2010 $
* $Author: ing07385 $
* $Revision: 1.65 $
* $Aliases: NFC_FRI1.1_WK1014_SDK,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1019_SDK,NFC_FRI1.1_WK1024_SDK $
*
*/
/*
************************* Header Files ***************************************
*/
#include <phNfcStatus.h>
#include <phLibNfc.h>
#include <phHal4Nfc.h>
#include <phOsalNfc.h>
#include <phLibNfc_Internal.h>
#include <phLibNfc_SE.h>
#include <phLibNfc_ndef_raw.h>
#include <phLibNfc_initiator.h>
#include <phLibNfc_discovery.h>
/*
*************************** Macro's ****************************************
*/
#ifndef STATIC_DISABLE
#define STATIC static
#else
#define STATIC
#endif
/*
*************************** Global Variables **********************************
*/
/*This Structure contains the Secure Element information*/
phLibNfc_SE_List_t sSecuredElementInfo[PHLIBNFC_MAXNO_OF_SE];
/*
*************************** Static Function Declaration ***********************
*/
/* Response callback for SE Set Mode*/
STATIC
void phLibNfc_SE_SetMode_cb(void *context, NFCSTATUS status);
/* SE register listner response notification */
STATIC
void phLibNfc_SeNotification(void *context,
phHal_eNotificationType_t type,
phHal4Nfc_NotificationInfo_t info,
NFCSTATUS status
);
/*
*************************** Function Definitions ******************************
*/
/**
* Registers notification handler to handle secure element specific events
*/
NFCSTATUS phLibNfc_SE_NtfRegister (
pphLibNfc_SE_NotificationCb_t pSE_NotificationCb,
void *pContext
)
{
NFCSTATUS Status = NFCSTATUS_SUCCESS;
pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
if((NULL == gpphLibContext) ||
(gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
{
Status = NFCSTATUS_NOT_INITIALISED;
}
else if((pSE_NotificationCb == NULL)
||(NULL == pContext))
{
/*parameters sent by upper layer are not valid*/
Status = NFCSTATUS_INVALID_PARAMETER;
}
else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
{
Status = NFCSTATUS_SHUTDOWN;
}
else
{
/*Register SE notification with lower layer.
Any activity on Smx or UICC will be notified */
Status = phHal4Nfc_RegisterNotification(
pLibContext->psHwReference,
eRegisterSecureElement,
phLibNfc_SeNotification,
(void*)pLibContext);
if(Status == NFCSTATUS_SUCCESS)
{
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb = pSE_NotificationCb;
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt=pContext;
}
else
{
/* Registration failed */
Status = NFCSTATUS_FAILED;
}
}
return Status;
}
/**
* SE Notification events are notified with this callback
*/
STATIC void phLibNfc_SeNotification(void *context,
phHal_eNotificationType_t type,
phHal4Nfc_NotificationInfo_t info,
NFCSTATUS status)
{
pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)context;
phHal_sEventInfo_t *pEvtInfo = NULL;
phLibNfc_uSeEvtInfo_t Se_Trans_Info={{{0,0},{0,0}}};
phLibNfc_SE_List_t *pSeInfo=NULL;
if(pLibContext != gpphLibContext)
{
/*wrong context returned*/
phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
}
else
{
if((status == NFCSTATUS_SUCCESS) && (type == NFC_EVENT_NOTIFICATION))
{
pEvtInfo = info.psEventInfo;
status = NFCSTATUS_SUCCESS;
if((pEvtInfo->eventSource == phHal_ePICC_DevType )
&& (pEvtInfo->eventHost == phHal_eHostController) )
{
sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type = phLibNfc_SE_Type_SmartMX;
/* Smartx Mx is Activated */
pSeInfo = &sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX];
}
if(pEvtInfo->eventHost == phHal_eUICCHost)
{
/* UICC is Activate */
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type = phLibNfc_SE_Type_UICC;
pSeInfo = &sSecuredElementInfo[LIBNFC_SE_UICC_INDEX];
}
else
{
/*presently Smx event source is not supported */
}
if(pSeInfo!=NULL)
{
switch(pEvtInfo->eventType)
{
case NFC_EVT_TRANSACTION:
{
if((pEvtInfo->eventInfo.aid.length != 0) && ((pEvtInfo->eventInfo.aid.length <= 16))) // PLG
{
/*copy the Application id on which transaction happened*/
Se_Trans_Info.UiccEvtInfo.aid.buffer =pEvtInfo->eventInfo.aid.buffer;
Se_Trans_Info.UiccEvtInfo.aid.length =pEvtInfo->eventInfo.aid.length;
}
else
{
// PLG patch
Se_Trans_Info.UiccEvtInfo.aid.buffer = NULL;
Se_Trans_Info.UiccEvtInfo.aid.length = 0;
}
if((pEvtInfo->eventHost == phHal_eUICCHost)
&& (info.psEventInfo->eventInfo.uicc_info.param.length
!= 0))
{
/*copy the parameters info on which transaction happened*/
Se_Trans_Info.UiccEvtInfo.param.buffer =
info.psEventInfo->eventInfo.uicc_info.param.buffer;
Se_Trans_Info.UiccEvtInfo.param.length =
info.psEventInfo->eventInfo.uicc_info.param.length;
}
/*Notify to upper layer that transaction had happened on the
one of the application stored in UICC or Smx*/
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtStartTransaction,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_APDU_RECEIVED:
{
if ((pEvtInfo->eventInfo.aid.length != 0) && ((pEvtInfo->eventInfo.aid.length <= 16)))
{
/* Copy received APDU to aid buffer. */
Se_Trans_Info.UiccEvtInfo.aid.buffer = pEvtInfo->eventInfo.aid.buffer;
Se_Trans_Info.UiccEvtInfo.aid.length = pEvtInfo->eventInfo.aid.length;
}
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtApduReceived,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_MIFARE_ACCESS:
{
/* copy the Block MIFARE accessed */
Se_Trans_Info.UiccEvtInfo.aid.buffer = pEvtInfo->eventInfo.aid.buffer;
Se_Trans_Info.UiccEvtInfo.aid.length = pEvtInfo->eventInfo.aid.length;
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtMifareAccess,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_EMV_CARD_REMOVAL:
{
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtCardRemoval,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_END_OF_TRANSACTION:
{
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtEndTransaction,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_CONNECTIVITY:
{
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtConnectivity,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_START_OF_TRANSACTION:
{
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtTypeTransaction,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_FIELD_ON:
{
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtFieldOn,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
case NFC_EVT_FIELD_OFF:
{
(*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
phLibNfc_eSE_EvtFieldOff,
pSeInfo->hSecureElement,
&Se_Trans_Info,
status);
break;
}
default:
{
break;
}
}
}
else
{
}
}
}
return;
}
/**
* Unregister the Secured Element Notification.
*/
NFCSTATUS phLibNfc_SE_NtfUnregister(void)
{
NFCSTATUS Status = NFCSTATUS_SUCCESS;
pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
if((NULL == gpphLibContext) ||
(gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
{
/*Lib Nfc is not initialized*/
Status = NFCSTATUS_NOT_INITIALISED;
}
else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
{
Status = NFCSTATUS_SHUTDOWN;
}
else
{
/*Unregister SE event notification with lower layer.
even some transaction happens on UICC or Smx will not
be notified afterworlds */
Status = phHal4Nfc_UnregisterNotification(
pLibContext->psHwReference,
eRegisterSecureElement,
pLibContext);
if(Status != NFCSTATUS_SUCCESS)
{
/*Unregister failed*/
Status=NFCSTATUS_FAILED;
}
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb=NULL;
pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt=NULL;
}
return Status;
}
/**
* Get list of available Secure Elements
*/
NFCSTATUS phLibNfc_SE_GetSecureElementList(
phLibNfc_SE_List_t* pSE_List,
uint8_t* uSE_count
)
{
NFCSTATUS Status = NFCSTATUS_SUCCESS;
uint8_t uNo_Of_SE = 0;
if((NULL == gpphLibContext) ||
(gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
{
Status = NFCSTATUS_NOT_INITIALISED;
}
else if((NULL ==pSE_List) || (NULL ==uSE_count))
{
Status = NFCSTATUS_INVALID_PARAMETER;
}
else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
{
Status = NFCSTATUS_SHUTDOWN;
}
else
{
/*Check for which type of Secure Element is available*/
if(gpphLibContext->psHwReference->uicc_connected==TRUE)
{
/* Populate the UICC type */
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type = phLibNfc_SE_Type_UICC;
/* Populate the UICC handle */
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement =(phLibNfc_Handle)
(LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
#ifdef NXP_HAL_ENABLE_SMX
pSE_List[LIBNFC_SE_UICC_INDEX].eSE_Type =
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type;
pSE_List[LIBNFC_SE_UICC_INDEX].hSecureElement = (phLibNfc_Handle)
(LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
pSE_List[LIBNFC_SE_UICC_INDEX].eSE_CurrentState =
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState;
#else
pSE_List->eSE_Type =
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type;
pSE_List->hSecureElement = (phLibNfc_Handle)
(LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
pSE_List->eSE_CurrentState =
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState;
#endif
/* update the No of SE retrieved */
uNo_Of_SE ++;
}
if (gpphLibContext->psHwReference->smx_connected ==TRUE)
{
/* if the Smx is also connected to the PN544 */
/* Populate the SMX type */
sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type = phLibNfc_SE_Type_SmartMX;
/* Populate the SMX handle */
sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement =(phLibNfc_Handle)
(LIBNFC_SE_SMARTMX_INDEX + LIBNFC_SE_BASE_HANDLE);
pSE_List[LIBNFC_SE_SMARTMX_INDEX].eSE_Type =
sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type;
pSE_List[LIBNFC_SE_SMARTMX_INDEX].hSecureElement = (phLibNfc_Handle)
(LIBNFC_SE_SMARTMX_INDEX + LIBNFC_SE_BASE_HANDLE);
pSE_List[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState =
sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState;
/* update the No of SE retrieved */
uNo_Of_SE ++;
}
*uSE_count = uNo_Of_SE;
}
return Status;
}
/**
* Sets secure element mode.
* This function configures SE to specific mode based on activation mode type
*/
NFCSTATUS phLibNfc_SE_SetMode ( phLibNfc_Handle hSE_Handle,
phLibNfc_eSE_ActivationMode eActivation_mode,
pphLibNfc_SE_SetModeRspCb_t pSE_SetMode_Rsp_cb,
void * pContext
)
{
NFCSTATUS Status = NFCSTATUS_SUCCESS;
phHal_eEmulationType_t eEmulationType = NFC_SMARTMX_EMULATION;
pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
if((NULL == gpphLibContext) ||
(gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
{
Status = NFCSTATUS_NOT_INITIALISED;
}
else if((pSE_SetMode_Rsp_cb ==NULL)
||(NULL == pContext)||(NULL==(void *)hSE_Handle))
{
Status=NFCSTATUS_INVALID_PARAMETER;
}
else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
{
Status = NFCSTATUS_SHUTDOWN;
}
else if((pLibContext->status.GenCb_pending_status == TRUE)
||(NULL!=pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb))
{
/*previous callback is pending still*/
Status =NFCSTATUS_REJECTED;
}
else
{
switch(eActivation_mode)
{
case phLibNfc_SE_ActModeVirtual:
{
if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
{
eEmulationType = NFC_UICC_EMULATION;
/*Enable the UICC -External reader can see it*/
pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = TRUE;
}
else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
{
eEmulationType = NFC_SMARTMX_EMULATION;
/*Enable the SMX -External reader can see it*/
pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = TRUE;
}
else
{
Status=NFCSTATUS_INVALID_HANDLE;
}
if(Status==NFCSTATUS_SUCCESS)
{
if(pLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)
{
pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeVirtual;
}
pLibContext->sCardEmulCfg.emuType = eEmulationType;
Status = phHal4Nfc_ConfigParameters(
pLibContext->psHwReference,
NFC_EMULATION_CONFIG,
(phHal_uConfig_t*)&pLibContext->sCardEmulCfg,
phLibNfc_SE_SetMode_cb,
pLibContext);
}
}
break;
case phLibNfc_SE_ActModeVirtualVolatile:
{
if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
{
eEmulationType = NFC_SMARTMX_EMULATION;
/*Enable the SMX -External reader can see it*/
pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = TRUE;
pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeVirtualVolatile;
Status = phHal4Nfc_Switch_SMX_Mode(
pLibContext->psHwReference,
eSmartMx_Virtual,
phLibNfc_SE_SetMode_cb,
pLibContext
);
}
else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
{
eEmulationType = NFC_UICC_EMULATION;
/*Enable the UICC -External reader can see it*/
pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = TRUE;
pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeVirtualVolatile;
Status = phHal4Nfc_Switch_Swp_Mode(
pLibContext->psHwReference,
eSWP_Switch_On,
phLibNfc_SE_SetMode_cb,
pLibContext
);
}
else
{
Status = NFCSTATUS_INVALID_HANDLE;
}
}
break;
case phLibNfc_SE_ActModeDefault:
{
if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
{
Status = phHal4Nfc_Switch_SMX_Mode(
pLibContext->psHwReference,
eSmartMx_Default,
phLibNfc_SE_SetMode_cb,
pLibContext
);
}
else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
{
Status = phHal4Nfc_Switch_Swp_Mode(
pLibContext->psHwReference,
eSWP_Switch_Default,
phLibNfc_SE_SetMode_cb,
pLibContext
);
}
else
{
Status = NFCSTATUS_INVALID_HANDLE;
}
}
break;
case phLibNfc_SE_ActModeWired:
{
if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
{
if(pLibContext->CBInfo.pClientNtfRegRespCB!=NULL)
{
/*Disable the SMX -External reader can't see it anymore*/
pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = FALSE;
pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeWired;
Status = phHal4Nfc_Switch_SMX_Mode(
pLibContext->psHwReference,
eSmartMx_Wired,
phLibNfc_SE_SetMode_cb,
pLibContext
);
}
}
else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
{
/*This mode is not applicable to UICC*/
Status = NFCSTATUS_REJECTED;
}
else
{
Status = NFCSTATUS_INVALID_HANDLE;
}
}
break;
case phLibNfc_SE_ActModeOff:
{
/*UICC emulation deactivate*/
if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
{
eEmulationType = NFC_UICC_EMULATION;
/*Disable the UICC -External reader can't see it anymore*/
pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = FALSE;
}
else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
{
eEmulationType = NFC_SMARTMX_EMULATION;
/*Disable the SMX -External reader can't see it anymore*/
pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation=FALSE;
}
else
{
Status = NFCSTATUS_INVALID_HANDLE;
}
if(Status==NFCSTATUS_SUCCESS)
{
pLibContext->sCardEmulCfg.emuType = eEmulationType;
if(pLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)
{
pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeOff;
}
Status = phHal4Nfc_ConfigParameters(pLibContext->psHwReference,
NFC_EMULATION_CONFIG,
(phHal_uConfig_t*)&pLibContext->sCardEmulCfg,
phLibNfc_SE_SetMode_cb,
pLibContext);
}
}
break;
default:
Status=NFCSTATUS_INVALID_PARAMETER;
break;
}/*End of eActivation_mode switch */
if(Status==NFCSTATUS_PENDING)
{
pLibContext->sSeContext.hSetemp=hSE_Handle;
pLibContext->status.GenCb_pending_status = TRUE;
pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = pSE_SetMode_Rsp_cb;
pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt=pContext;
}
else if(Status == NFCSTATUS_INVALID_HANDLE)
{
Status= Status;
}
else
{
Status = NFCSTATUS_FAILED;
}
}
return Status;
}
/**
* Callback for Se Set mode
*/
STATIC void phLibNfc_SE_SetMode_cb(void *context, NFCSTATUS status)
{
/* Note that we don't use the passed in context here;
* the reason is that there are race-conditions around
* the place where this context is stored (mostly in combination
* with LLCP), and we may actually get the wrong context.
* Since this callback always uses the global context
* we don't need the passed in context anyway.
*/
pphLibNfc_LibContext_t pLibContext=gpphLibContext;
pphLibNfc_SE_SetModeRspCb_t pUpperLayerCb=NULL;
void *pUpperContext=NULL;
phLibNfc_Handle hSeHandle=0;
uint8_t TempState=FALSE;
if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
{
/*If shutdown is called in between allow shutdown to happen*/
phLibNfc_Pending_Shutdown();
status = NFCSTATUS_SHUTDOWN;
}
else
{
if(status == NFCSTATUS_SUCCESS)
{
hSeHandle = pLibContext->sSeContext.hSetemp;
if(hSeHandle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
{
if(TRUE==pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc)
{
/*If Activation mode was virtual allow external reader to see it*/
pLibContext->sSeContext.uUiccActivate = TRUE;
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState = phLibNfc_SE_Active;
}
else
{
/*If Activation mode was wired don't allow external reader to see it*/
pLibContext->sSeContext.uUiccActivate = FALSE;
sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState =
phLibNfc_SE_Inactive;
}
status = NFCSTATUS_SUCCESS;
TempState = pLibContext->sSeContext.uUiccActivate;
}
else if (hSeHandle==sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
{
if(TRUE==pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation)
{
/*If Activation mode was virtual allow external reader to see it*/
pLibContext->sSeContext.uSmxActivate = TRUE;
sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState =
phLibNfc_SE_Active;
}
else
{
/*If Activation mode was wired don't allow external reader to see it*/
pLibContext->sSeContext.uSmxActivate = FALSE;
sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState=
phLibNfc_SE_Inactive;
}
status = NFCSTATUS_SUCCESS;
TempState = pLibContext->sSeContext.uSmxActivate;
}
else
{
status = NFCSTATUS_FAILED;
}
}
else
{
status = NFCSTATUS_FAILED;
}
pLibContext->status.GenCb_pending_status = FALSE;
}
pUpperLayerCb = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb;
pUpperContext = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt;
pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = NULL;
pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt = NULL;
PHNFC_UNUSED_VARIABLE(TempState);
/* Call the upper layer cb */
if(pUpperLayerCb!= NULL )
{
(*pUpperLayerCb)(pUpperContext,
hSeHandle,
status);
}
return;
}
|