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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
|
/*
* 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 hHciNfc_AdminMgmt.c *
* \brief HCI Admin Gate Management Routines. *
* *
* *
* Project: NFC-FRI-1.1 *
* *
* $Date: Mon Apr 5 19:23:34 2010 $ *
* $Author: ing04880 $ *
* $Revision: 1.47 $ *
* $Aliases: NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
* *
* =========================================================================== *
*/
/*
***************************** Header File Inclusion ****************************
*/
#include <phNfcCompId.h>
#include <phHciNfc_Pipe.h>
#include <phHciNfc_AdminMgmt.h>
#include <phHciNfc_DevMgmt.h>
#include <phOsalNfc.h>
/*
****************************** Macro Definitions *******************************
*/
#define SESSION_INDEX 0x01U
#define MAX_PIPE_INDEX 0x02U
#define WHITELIST_INDEX 0x03U
#define HOST_LIST_INDEX 0x04U
/* Max Whitelist Supported by the Device*/
#define SESSIONID_LEN 0x08U
#define WHITELIST_MAX_LEN 0x03U
#define HOST_LIST_MAX_LEN 0x05U
/* Address Definitions for HW Configuration */
#define NFC_ADDRESS_UICC_SESSION 0x9EA2U
/*
*************************** Structure and Enumeration ***************************
*/
typedef enum phHciNfc_Admin_Seq{
ADMIN_PIPE_OPEN = 0x00U,
ADMIN_GET_HOST_LIST,
ADMIN_GET_WHITE_LIST,
ADMIN_GET_SESSION,
ADMIN_VERIFY_SESSION,
ADMIN_CLEAR_UICC_PIPES,
ADMIN_CLEAR_PIPES,
ADMIN_PIPE_REOPEN,
ADMIN_CREATE_PIPES,
ADMIN_SET_SESSION,
ADMIN_SET_WHITE_LIST,
ADMIN_UPDATE_PIPES,
ADMIN_PIPE_CLOSE,
ADMIN_DELETE_PIPES,
ADMIN_END_SEQUENCE
} phHciNfc_Admin_Seq_t;
/* Information structure for the Admin Gate */
typedef struct phHciNfc_AdminGate_Info{
/* Current running Sequence of the Admin Management */
phHciNfc_Admin_Seq_t current_seq;
/* Next running Sequence of the Admin Management */
phHciNfc_Admin_Seq_t next_seq;
/* Pointer to the Admin Pipe Information */
phHciNfc_Pipe_Info_t *admin_pipe_info;
/* Sequence for the Pipe Initialisation */
phHciNfc_PipeMgmt_Seq_t pipe_seq;
/* Session ID of the Device */
uint8_t session_id[SESSIONID_LEN];
/* Max number of pipes that can be created on the Device */
uint8_t max_pipe;
/* List of Hosts that can be access the device Admin Gate. */
uint8_t whitelist[WHITELIST_MAX_LEN];
/* Host List from the Host Controller */
uint8_t host_list[HOST_LIST_MAX_LEN];
} phHciNfc_AdminGate_Info_t;
/*
*************************** Static Function Declaration **************************
*/
/**
* \ingroup grp_hci_nfc
*
* The phHciNfc_Recv_Admin_Response function interprets the received AdminGate
* response from the Host Controller Gate.
*
* \param[in] psHciContext psHciContext is the pointer to HCI Layer
* context Structure.
* \param[in] pHwRef pHwRef is the Information of
* the Device Interface Link .
* \param[in,out] pResponse Response received from the Host Cotroller
* Admin gate.
* \param[in] length length contains the length of the
* response received from the Host Controller.
*
* \retval NFCSTATUS_PENDING AdminGate Response to be received is pending.
* \retval NFCSTATUS_SUCCESS AdminGate Response received Successfully.
* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
* could not be interpreted properly.
* \retval Other errors Errors related to the other layers
*
*/
static
NFCSTATUS
phHciNfc_Recv_Admin_Response(
void *psHciContext,
void *pHwRef,
uint8_t *pResponse,
#ifdef ONE_BYTE_LEN
uint8_t length
#else
uint16_t length
#endif
);
static
NFCSTATUS
phHciNfc_Admin_InfoUpdate(
phHciNfc_sContext_t *psHciContext,
phHal_sHwReference_t *pHwRef,
uint8_t index,
uint8_t *reg_value,
uint8_t reg_length
);
static
NFCSTATUS
phHciNfc_Recv_Admin_Cmd (
void *psContext,
void *pHwRef,
uint8_t *pCmd,
#ifdef ONE_BYTE_LEN
uint8_t length
#else
uint16_t length
#endif
);
static
NFCSTATUS
phHciNfc_Recv_Admin_Event (
void *psContext,
void *pHwRef,
uint8_t *pEvent,
#ifdef ONE_BYTE_LEN
uint8_t length
#else
uint16_t length
#endif
);
/*
*************************** Function Definitions ***************************
*/
/*!
* \brief Initialisation of Admin Gate and Establish the Session .
*
* This function initialses the Admin Gates and Establishes the Session by creating
* all the required pipes and sets the Session ID
*
*/
NFCSTATUS
phHciNfc_Admin_Initialise(
phHciNfc_sContext_t *psHciContext,
void *pHwRef
)
{
NFCSTATUS status = NFCSTATUS_SUCCESS;
phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
phHciNfc_AdminGate_Info_t *p_admin_info=NULL;
uint8_t length = 0;
if( (NULL == psHciContext)
|| (NULL == pHwRef )
)
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
if( ( NULL == psHciContext->p_admin_info )
&& (phHciNfc_Allocate_Resource((void **)(&p_admin_info),
sizeof(phHciNfc_AdminGate_Info_t))== NFCSTATUS_SUCCESS)
)
{
psHciContext->p_admin_info = (void *) p_admin_info;
p_admin_info->current_seq = ADMIN_PIPE_OPEN;
p_admin_info->next_seq = ADMIN_END_SEQUENCE;
p_admin_info->admin_pipe_info = NULL;
}
else
{
p_admin_info = (phHciNfc_AdminGate_Info_t * )
psHciContext->p_admin_info ;
}
if( NULL == p_admin_info)
{
status = PHNFCSTVAL(CID_NFC_HCI,
NFCSTATUS_INSUFFICIENT_RESOURCES);
}
else
{
switch(p_admin_info->current_seq)
{
/* Admin pipe open sequence , Initially open the Admin Pipe */
case ADMIN_PIPE_OPEN:
{
if(phHciNfc_Allocate_Resource((void **)(&p_pipe_info),
sizeof(phHciNfc_Pipe_Info_t))!= NFCSTATUS_SUCCESS)
{
status = PHNFCSTVAL(CID_NFC_HCI,
NFCSTATUS_INSUFFICIENT_RESOURCES);
}
else
{
/* Populate the pipe information in the pipe handle */
((phHciNfc_Pipe_Info_t *)p_pipe_info)->pipe.pipe_id =
PIPETYPE_STATIC_ADMIN;
((phHciNfc_Pipe_Info_t *)p_pipe_info)->recv_resp =
&phHciNfc_Recv_Admin_Response;
((phHciNfc_Pipe_Info_t *)p_pipe_info)->recv_cmd =
&phHciNfc_Recv_Admin_Cmd;
((phHciNfc_Pipe_Info_t *)p_pipe_info)->recv_event =
&phHciNfc_Recv_Admin_Event;
psHciContext->p_pipe_list[PIPETYPE_STATIC_ADMIN] =
p_pipe_info ;
status = phHciNfc_Open_Pipe( psHciContext,
pHwRef,p_pipe_info );
if(status == NFCSTATUS_SUCCESS)
{
p_admin_info->admin_pipe_info = p_pipe_info ;
p_admin_info->next_seq = ADMIN_GET_SESSION;
status = NFCSTATUS_PENDING;
}
}
break;
}
case ADMIN_GET_SESSION:
{
p_pipe_info = p_admin_info->admin_pipe_info;
p_pipe_info->reg_index = SESSION_INDEX;
p_pipe_info->prev_status =
phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
(uint8_t)HCI_ADMIN_PIPE_ID,
(uint8_t)ANY_GET_PARAMETER);
if(NFCSTATUS_PENDING == p_pipe_info->prev_status )
{
#ifdef UICC_SESSION_RESET
p_admin_info->next_seq = ADMIN_CLEAR_UICC_PIPES;
#elif defined (ESTABLISH_SESSION)
p_admin_info->next_seq = ADMIN_VERIFY_SESSION;
#else
p_admin_info->next_seq = ADMIN_CLEAR_PIPES;
#endif
status = NFCSTATUS_PENDING;
}
break;
}
#ifdef UICC_SESSION_RESET
case ADMIN_CLEAR_UICC_PIPES:
{
uint8_t config = 0x00;
p_pipe_info = p_admin_info->admin_pipe_info;
/* TODO: Implement the Clear UICC PIPES Using
* Memory configuration.
*/
status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
NFC_ADDRESS_UICC_SESSION , config );
if(NFCSTATUS_PENDING == status )
{
p_admin_info->next_seq = ADMIN_CLEAR_PIPES;
status = NFCSTATUS_PENDING;
}
break;
}
#endif
case ADMIN_VERIFY_SESSION:
{
phHal_sHwConfig_t *p_hw_config =
(phHal_sHwConfig_t *) psHciContext->p_config_params;
phHal_sHwReference_t *p_hw_ref =
(phHal_sHwReference_t *) pHwRef;
int cmp_val = 0;
p_pipe_info = p_admin_info->admin_pipe_info;
cmp_val = phOsalNfc_MemCompare(p_hw_config->session_id ,
p_hw_ref->session_id ,
sizeof(p_hw_ref->session_id));
if((cmp_val == 0)
&& ( HCI_SESSION == psHciContext->init_mode)
)
{
psHciContext->hci_mode = hciMode_Session;
status = phHciNfc_Update_Pipe( psHciContext, pHwRef,
&p_admin_info->pipe_seq );
if((status == NFCSTATUS_SUCCESS)
&& (NULL != p_pipe_info))
{
p_pipe_info->reg_index = MAX_PIPE_INDEX;
status = phHciNfc_Send_Generic_Cmd( psHciContext,
pHwRef, (uint8_t)HCI_ADMIN_PIPE_ID,
(uint8_t)ANY_GET_PARAMETER );
p_pipe_info->prev_status = status;
if(NFCSTATUS_PENDING == status )
{
p_admin_info->next_seq = ADMIN_PIPE_CLOSE;
status = NFCSTATUS_SUCCESS;
}
}
else
{
status = PHNFCSTVAL(CID_NFC_HCI,
NFCSTATUS_INVALID_HCI_SEQUENCE);
}
break;
}
else
{
/* To clear the pipe information*/
psHciContext->hci_mode = hciMode_Override;
p_admin_info->current_seq = ADMIN_CLEAR_PIPES;
}
}
/* fall through */
case ADMIN_CLEAR_PIPES:
{
p_pipe_info = p_admin_info->admin_pipe_info;
p_pipe_info->prev_status =
phHciNfc_Send_Admin_Cmd( psHciContext,
pHwRef, ADM_CLEAR_ALL_PIPE,
length, p_pipe_info);
status = ((p_pipe_info->prev_status == NFCSTATUS_PENDING)?
NFCSTATUS_SUCCESS :
p_pipe_info->prev_status);
if(status == NFCSTATUS_SUCCESS)
{
p_admin_info->next_seq = ADMIN_PIPE_REOPEN;
status = NFCSTATUS_PENDING;
}
break;
}
/* Admin pipe Re-Open sequence , Re-Open the Admin Pipe */
case ADMIN_PIPE_REOPEN:
{
p_pipe_info = p_admin_info->admin_pipe_info;
status = phHciNfc_Open_Pipe( psHciContext,
pHwRef,p_pipe_info );
if(status == NFCSTATUS_SUCCESS)
{
p_admin_info->next_seq = ADMIN_CREATE_PIPES;
status = NFCSTATUS_PENDING;
}
break;
}
case ADMIN_CREATE_PIPES:
{
status = phHciNfc_Create_All_Pipes( psHciContext, pHwRef,
&p_admin_info->pipe_seq );
if(status == NFCSTATUS_SUCCESS)
{
p_admin_info->next_seq = ADMIN_GET_WHITE_LIST;
status = NFCSTATUS_PENDING;
}
break;
}
case ADMIN_GET_WHITE_LIST:
{
p_pipe_info = p_admin_info->admin_pipe_info;
if(NULL == p_pipe_info )
{
status = PHNFCSTVAL(CID_NFC_HCI,
NFCSTATUS_INVALID_HCI_SEQUENCE);
}
else
{
p_pipe_info->reg_index = WHITELIST_INDEX;
status = phHciNfc_Send_Generic_Cmd( psHciContext,
pHwRef, (uint8_t)HCI_ADMIN_PIPE_ID,
(uint8_t)ANY_GET_PARAMETER );
p_pipe_info->prev_status = status;
if(HCI_SELF_TEST == psHciContext->init_mode)
{
status = ((NFCSTATUS_PENDING == status )?
NFCSTATUS_SUCCESS : status);
}
else
{
if(NFCSTATUS_PENDING == status )
{
p_admin_info->next_seq = ADMIN_GET_HOST_LIST;
/* status = NFCSTATUS_SUCCESS; */
}
}
}
break;
}
case ADMIN_GET_HOST_LIST:
{
p_pipe_info = p_admin_info->admin_pipe_info;
if(NULL == p_pipe_info )
{
status = PHNFCSTVAL(CID_NFC_HCI,
NFCSTATUS_INVALID_HCI_SEQUENCE);
}
else
{
p_pipe_info->reg_index = HOST_LIST_INDEX;
status = phHciNfc_Send_Generic_Cmd( psHciContext,
pHwRef, (uint8_t)HCI_ADMIN_PIPE_ID,
(uint8_t)ANY_GET_PARAMETER );
p_pipe_info->prev_status = status;
if(NFCSTATUS_PENDING == status )
{
#if defined(HOST_WHITELIST)
p_admin_info->next_seq = ADMIN_SET_WHITE_LIST;
#else
p_admin_info->next_seq = ADMIN_SET_SESSION;
status = NFCSTATUS_SUCCESS;
#endif
}
}
break;
}
case ADMIN_SET_WHITE_LIST:
{
p_pipe_info = p_admin_info->admin_pipe_info;
if(NULL == p_pipe_info )
{
status = PHNFCSTVAL(CID_NFC_HCI,
NFCSTATUS_INVALID_HCI_SEQUENCE);
}
else
{
uint8_t i = 0;
for (i = 0; i < WHITELIST_MAX_LEN - 2; i++ )
{
p_admin_info->whitelist[i] = i + 2;
}
status = phHciNfc_Set_Param(psHciContext, pHwRef,
p_pipe_info, WHITELIST_INDEX,
(uint8_t *)p_admin_info->whitelist, i );
if(NFCSTATUS_PENDING == status )
{
p_admin_info->next_seq = ADMIN_SET_SESSION;
status = NFCSTATUS_SUCCESS;
}
}
break;
}
case ADMIN_SET_SESSION:
{
phHal_sHwConfig_t *p_hw_config =
(phHal_sHwConfig_t *) psHciContext->p_config_params;
p_pipe_info = p_admin_info->admin_pipe_info;
status = phHciNfc_Set_Param(psHciContext, pHwRef, p_pipe_info,
SESSION_INDEX, (uint8_t *)(p_hw_config->session_id),
sizeof(p_hw_config->session_id));
if(NFCSTATUS_PENDING == p_pipe_info->prev_status )
{
p_admin_info->next_seq = ADMIN_PIPE_CLOSE;
status = NFCSTATUS_SUCCESS;
}
break;
}
default:
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
break;
}
}/* End of the Sequence Switch */
}/* End of the Admin Info Memory Check */
}/* End of Null context Check */
return status;
}
#ifdef HOST_EMULATION
/*!
* \brief Creates the Card Emulation Gate Pipes .
*
* This function Creates the Card Emulation Gate.
*/
NFCSTATUS
phHciNfc_Admin_CE_Init(
phHciNfc_sContext_t *psHciContext,
void *pHwRef,
phHciNfc_GateID_t ce_gate
)
{
NFCSTATUS status = NFCSTATUS_SUCCESS;
/* phHciNfc_Pipe_Info_t *pipe_info = NULL; */
phHciNfc_AdminGate_Info_t *p_admin_info=NULL;
if( (NULL == psHciContext) || (NULL == pHwRef) )
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
if( NULL != psHciContext->p_admin_info )
{
p_admin_info = psHciContext->p_admin_info;
switch(ce_gate)
{
/* Card Emulation A Gate Pipe Creation */
case phHciNfc_CETypeAGate:
{
p_admin_info->pipe_seq = PIPE_CARD_A_CREATE;
break;
}
/* Card Emulation B Gate Pipe Creation */
case phHciNfc_CETypeBGate:
{
p_admin_info->pipe_seq = PIPE_CARD_B_CREATE;
break;
}
default:
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_HCI_GATE_NOT_SUPPORTED);
break;
}
} /* End of CE Gate Switch */
if (NFCSTATUS_SUCCESS == status)
{
status = phHciNfc_CE_Pipes_OP( psHciContext,
pHwRef, &p_admin_info->pipe_seq );
if(status == NFCSTATUS_SUCCESS)
{
p_admin_info->next_seq = ADMIN_END_SEQUENCE;
/* status = NFCSTATUS_PENDING; */
}
}
}/* End of NULL Check for the Admin_Info */
} /* End of Null Check for the Context */
return status;
}
#endif
/*!
* \brief Releases the resources allocated the Admin Management.
*
* This function Releases the resources allocated the Admin Management
* and resets the hardware to the reset state.
*/
NFCSTATUS
phHciNfc_Admin_Release(
phHciNfc_sContext_t *psHciContext,
void *pHwRef,
phHciNfc_HostID_t host_type
)
{
NFCSTATUS status = NFCSTATUS_SUCCESS;
phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
if( (NULL == psHciContext) || (NULL == pHwRef) )
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
if( NULL != psHciContext->p_admin_info )
{
if(phHciNfc_UICCHostID != host_type)
{
p_pipe_info = psHciContext->p_pipe_list[PIPETYPE_STATIC_ADMIN];
status = phHciNfc_Close_Pipe( psHciContext,
pHwRef, p_pipe_info );
}
}/* End of NULL Check for the Admin_Info */
} /* End of Null Check for the Context */
return status;
}
/*!
* \brief Sends the HCI Admin Event to the corresponding peripheral device.
*
* This function sends the HCI Admin Events to the connected NFC Pheripheral
* device
*/
NFCSTATUS
phHciNfc_Send_Admin_Event (
phHciNfc_sContext_t *psHciContext,
void *pHwRef,
uint8_t event,
uint8_t length,
void *params
)
{
phHciNfc_HCP_Packet_t *hcp_packet = NULL;
phHciNfc_AdminGate_Info_t *p_admin_info=NULL;
NFCSTATUS status = NFCSTATUS_SUCCESS;
if( (NULL == psHciContext)
|| (NULL == pHwRef)
)
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
psHciContext->tx_total = 0 ;
length += HCP_HEADER_LEN ;
p_admin_info = psHciContext->p_admin_info;
if( EVT_HOT_PLUG == event )
{
/* Use the HCP Packet Structure to Construct the send HCP
* Packet data.
*/
hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
(uint8_t) HCI_ADMIN_PIPE_ID,
HCP_MSG_TYPE_EVENT, event);
}
else
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INSTRUCTION);
}
if( NFCSTATUS_SUCCESS == status )
{
p_admin_info->admin_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT;
p_admin_info->admin_pipe_info->prev_msg = event ;
p_admin_info->admin_pipe_info->param_info = params ;
psHciContext->tx_total = length;
psHciContext->response_pending = FALSE ;
status = phHciNfc_Send_HCP( (void *)psHciContext, (void *)pHwRef );
p_admin_info->admin_pipe_info->prev_status = NFCSTATUS_PENDING;
}
}
return status;
}
/*!
* \brief Sends the HCI Admin Commands to the corresponding peripheral device.
*
* This function sends the HCI Admin Commands to the connected NFC Pheripheral
* device
*/
NFCSTATUS
phHciNfc_Send_Admin_Cmd (
phHciNfc_sContext_t *psHciContext,
void *pHwRef,
uint8_t cmd,
uint8_t length,
void *params
)
{
phHciNfc_HCP_Packet_t *hcp_packet = NULL;
phHciNfc_HCP_Message_t *hcp_message = NULL;
phHciNfc_AdminGate_Info_t *p_admin_info=NULL;
phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
uint8_t i=0;
NFCSTATUS status = NFCSTATUS_SUCCESS;
if( (NULL == psHciContext)
|| (NULL == pHwRef)
|| (NULL == params)
)
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
p_pipe_info = (phHciNfc_Pipe_Info_t *) params;
psHciContext->tx_total = 0 ;
length += HCP_HEADER_LEN ;
p_admin_info = psHciContext->p_admin_info;
switch( cmd )
{
case ADM_CREATE_PIPE:
{
hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
/* Use the HCP Packet Structure to Construct the send HCP
* Packet data.
*/
phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
(uint8_t) HCI_ADMIN_PIPE_ID,
HCP_MSG_TYPE_COMMAND, cmd);
hcp_message = &(hcp_packet->msg.message);
/* Source HOST ID Parameter is not passed as a
* parameter in the HCI SPEC */
/* hcp_message->payload[i++] = p_pipe_info->pipe.source.host_id; */
hcp_message->payload[i++] = p_pipe_info->pipe.source.gate_id;
hcp_message->payload[i++] = p_pipe_info->pipe.dest.host_id;
hcp_message->payload[i++] = p_pipe_info->pipe.dest.gate_id;
break;
}
case ADM_DELETE_PIPE:
{
uint8_t pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
pipe_id = p_pipe_info->pipe.pipe_id;
if( pipe_id < PIPETYPE_DYNAMIC )
{
/* The Static Pipes cannot be Deleted */
status = PHNFCSTVAL(CID_NFC_HCI,
NFCSTATUS_INVALID_PARAMETER );
HCI_DEBUG("phHciNfc_Send_Admin_Cmd: Static Pipe %u "
"Cannot be Deleted \n",pipe_id);
}
else
{
/* Use the HCP Packet Structure to Construct the send HCP
* Packet data.
*/
hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
(uint8_t) HCI_ADMIN_PIPE_ID,
HCP_MSG_TYPE_COMMAND, cmd);
hcp_message = &(hcp_packet->msg.message);
hcp_message->payload[i++] = pipe_id ;
}
break;
}
case ADM_CLEAR_ALL_PIPE:
{
/* Use the HCP Packet Structure to Construct the send HCP
* Packet data.
*/
hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
(uint8_t) HCI_ADMIN_PIPE_ID,
HCP_MSG_TYPE_COMMAND, cmd);
hcp_message = &(hcp_packet->msg.message);
break;
}
/* These are notifications and can not be sent by the Host */
/* case ADM_NOTIFY_PIPE_CREATED: */
/* case ADM_NOTIFY_PIPE_DELETED: */
/* case ADM_NOTIFY_ALL_PIPE_CLEARED: */
default:
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_COMMAND);
break;
}
if( NFCSTATUS_SUCCESS == status )
{
p_admin_info->admin_pipe_info->sent_msg_type = HCP_MSG_TYPE_COMMAND;
p_admin_info->admin_pipe_info->prev_msg = cmd;
p_admin_info->admin_pipe_info->param_info = p_pipe_info;
psHciContext->tx_total = length;
psHciContext->response_pending = TRUE;
status = phHciNfc_Send_HCP( (void *)psHciContext, (void *)pHwRef );
p_admin_info->admin_pipe_info->prev_status = NFCSTATUS_PENDING;
}
}
return status;
}
/*!
* \brief Receives the HCI Response from the corresponding peripheral device.
*
* This function receives the HCI Command Response from the connected NFC
* Pheripheral device.
*/
static
NFCSTATUS
phHciNfc_Recv_Admin_Response(
void *psContext,
void *pHwRef,
uint8_t *pResponse,
#ifdef ONE_BYTE_LEN
uint8_t length
#else
uint16_t length
#endif
)
{
phHciNfc_sContext_t *psHciContext =
(phHciNfc_sContext_t *)psContext ;
phHciNfc_HCP_Packet_t *hcp_packet = NULL;
phHciNfc_HCP_Message_t *hcp_message = NULL;
phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
phHciNfc_AdminGate_Info_t *p_admin_info = NULL;
NFCSTATUS status = NFCSTATUS_SUCCESS;
uint8_t pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
uint8_t prev_cmd = 0;
NFCSTATUS prev_status = NFCSTATUS_SUCCESS;
if( (NULL == psHciContext) || (NULL == pHwRef) )
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else if ( NULL == psHciContext->p_admin_info )
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
}
else
{
hcp_packet = (phHciNfc_HCP_Packet_t *)pResponse;
hcp_message = &hcp_packet->msg.message;
p_admin_info = psHciContext->p_admin_info;
prev_cmd = p_admin_info->admin_pipe_info->prev_msg ;
prev_status = p_admin_info->admin_pipe_info->prev_status ;
if(prev_status == NFCSTATUS_PENDING)
{
switch(prev_cmd)
{
case ANY_SET_PARAMETER:
{
break;
}
case ANY_GET_PARAMETER:
{
status = phHciNfc_Admin_InfoUpdate(psHciContext,
(phHal_sHwReference_t *)pHwRef,
p_admin_info->admin_pipe_info->reg_index,
&pResponse[HCP_HEADER_LEN],
(uint8_t)(length - HCP_HEADER_LEN));
break;
}
case ANY_OPEN_PIPE:
{
break;
}
case ANY_CLOSE_PIPE:
{
phOsalNfc_FreeMemory(p_admin_info->admin_pipe_info);
p_admin_info->admin_pipe_info = NULL;
psHciContext->p_pipe_list[PIPETYPE_STATIC_ADMIN] = NULL;
break;
}
case ADM_CREATE_PIPE:
{
p_pipe_info = (phHciNfc_Pipe_Info_t *)
p_admin_info->admin_pipe_info->param_info;
pipe_id = hcp_message->payload[RESPONSE_PIPEID_OFFSET];
status = phHciNfc_Update_PipeInfo(psHciContext,
&(p_admin_info->pipe_seq), pipe_id, p_pipe_info);
if(NFCSTATUS_SUCCESS == status )
{
psHciContext->p_pipe_list[pipe_id] = p_pipe_info;
p_pipe_info->pipe.pipe_id = pipe_id;
}
break;
}
case ADM_DELETE_PIPE:
{
p_pipe_info = (phHciNfc_Pipe_Info_t *)
p_admin_info->admin_pipe_info->param_info;
if ( NULL != p_pipe_info )
{
pipe_id = p_pipe_info->pipe.pipe_id;
status = phHciNfc_Update_PipeInfo(
psHciContext, &(p_admin_info->pipe_seq),
(uint8_t) HCI_UNKNOWN_PIPE_ID, p_pipe_info);
if(NFCSTATUS_SUCCESS == status )
{
phOsalNfc_FreeMemory(p_pipe_info);
psHciContext->p_pipe_list[pipe_id] = NULL;
}
}
break;
}
case ADM_CLEAR_ALL_PIPE:
{
break;
}
default:
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
HCI_DEBUG("%s: Default Statement Should Not Occur \n",
"phHciNfc_Recv_Admin_Response");
break;
}
}
}
if( NFCSTATUS_SUCCESS == status )
{
if( NULL != p_admin_info->admin_pipe_info)
{
p_admin_info->admin_pipe_info->prev_status = NFCSTATUS_SUCCESS;
}
p_admin_info->current_seq = p_admin_info->next_seq;
}
}
return status;
}
/*!
* \brief Receives the HCI Admin Commands from the corresponding peripheral device.
*
* This function receives the HCI Admin Commands from the connected NFC Pheripheral
* device
*/
static
NFCSTATUS
phHciNfc_Recv_Admin_Cmd (
void *psContext,
void *pHwRef,
uint8_t *pCmd,
#ifdef ONE_BYTE_LEN
uint8_t length
#else
uint16_t length
#endif
)
{
phHciNfc_sContext_t *psHciContext =
(phHciNfc_sContext_t *)psContext ;
phHciNfc_HCP_Packet_t *hcp_packet = NULL;
phHciNfc_HCP_Message_t *hcp_message = NULL;
phHciNfc_AdminGate_Info_t *p_admin_info=NULL;
phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
uint8_t index=0;
uint8_t pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
uint8_t cmd = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;
uint8_t response = (uint8_t) ANY_OK;
NFCSTATUS status = NFCSTATUS_SUCCESS;
if( (NULL == psHciContext)
|| (NULL == pHwRef)
|| (HCP_HEADER_LEN > length )
)
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
hcp_packet = (phHciNfc_HCP_Packet_t *)pCmd;
hcp_message = &hcp_packet->msg.message;
p_admin_info = psHciContext->p_admin_info;
/* Get the Command instruction bits from the Message Header */
cmd = (uint8_t) GET_BITS8( hcp_message->msg_header,
HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
switch( cmd )
{
/* These are notifications sent by the Host Controller */
case ADM_NOTIFY_PIPE_CREATED:
{
pipe_id = hcp_message->payload[RESPONSE_PIPEID_OFFSET];
p_pipe_info = (phHciNfc_Pipe_Info_t *)
phOsalNfc_GetMemory(sizeof(phHciNfc_Pipe_Info_t));
memset(p_pipe_info, 0, sizeof(phHciNfc_Pipe_Info_t));
if(NULL != p_pipe_info)
{
/* The Source Host is the UICC Host */
p_pipe_info->pipe.source.host_id =
hcp_message->payload[index++];
/* The Source Gate is same as the Destination Gate */
p_pipe_info->pipe.source.gate_id =
hcp_message->payload[index++];
/* The Source Host is the Terminal Host */
p_pipe_info->pipe.dest.host_id =
hcp_message->payload[index++];
p_pipe_info->pipe.dest.gate_id =
hcp_message->payload[index++];
p_pipe_info->pipe.pipe_id =
hcp_message->payload[index++];
}
status = phHciNfc_Update_PipeInfo(psHciContext,
&(p_admin_info->pipe_seq), pipe_id, p_pipe_info);
if( NFCSTATUS_SUCCESS == status )
{
psHciContext->p_pipe_list[pipe_id] = p_pipe_info;
if (NULL != p_pipe_info)
{
p_pipe_info->pipe.pipe_id = pipe_id;
}
}
break;
}
case ADM_NOTIFY_PIPE_DELETED:
{
pipe_id = hcp_message->payload[index++];
p_pipe_info = psHciContext->p_pipe_list[pipe_id];
if ( NULL != p_pipe_info )
{
status = phHciNfc_Update_PipeInfo(
psHciContext, &(p_admin_info->pipe_seq),
(uint8_t) HCI_UNKNOWN_PIPE_ID, p_pipe_info);
if(NFCSTATUS_SUCCESS == status )
{
phOsalNfc_FreeMemory(p_pipe_info);
psHciContext->p_pipe_list[pipe_id] = NULL;
}
}
break;
}
/* TODO: Since we receive the Host ID, we need to clear
* all the pipes created with the host
*/
case ADM_NOTIFY_ALL_PIPE_CLEARED:
{
break;
}
/* case ADM_CREATE_PIPE: */
/* case ADM_DELETE_PIPE: */
/* case ADM_CLEAR_ALL_PIPE: */
default:
{
response = ANY_E_CMD_NOT_SUPPORTED;
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_COMMAND_NOT_SUPPORTED);
break;
}
}
hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
(uint8_t) HCI_ADMIN_PIPE_ID,
HCP_MSG_TYPE_RESPONSE, response );
psHciContext->tx_total = HCP_HEADER_LEN;
status = phHciNfc_Send_HCP( (void *)psHciContext, (void *)pHwRef );
p_admin_info->admin_pipe_info->recv_msg_type = HCP_MSG_TYPE_COMMAND;
p_admin_info->admin_pipe_info->sent_msg_type = HCP_MSG_TYPE_RESPONSE;
p_admin_info->admin_pipe_info->prev_msg = response;
p_admin_info->admin_pipe_info->prev_status = NFCSTATUS_PENDING;
}
return status;
}
/*!
* \brief Receives the HCI Admin Event from the corresponding peripheral device.
*
* This function receives the HCI Admin Events from the connected NFC Pheripheral
* device
*/
static
NFCSTATUS
phHciNfc_Recv_Admin_Event (
void *psContext,
void *pHwRef,
uint8_t *pEvent,
#ifdef ONE_BYTE_LEN
uint8_t length
#else
uint16_t length
#endif
)
{
phHciNfc_sContext_t *psHciContext =
(phHciNfc_sContext_t *)psContext ;
phHciNfc_HCP_Packet_t *hcp_packet = NULL;
phHciNfc_HCP_Message_t *hcp_message = NULL;
uint8_t event = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;
NFCSTATUS status = NFCSTATUS_SUCCESS;
if( (NULL == psHciContext)
|| (NULL == pHwRef)
|| (HCP_HEADER_LEN > length )
)
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
hcp_packet = (phHciNfc_HCP_Packet_t *)pEvent;
hcp_message = &hcp_packet->msg.message;
/* Get the Command instruction bits from the Message Header */
event = (uint8_t) GET_BITS8( hcp_message->msg_header,
HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
if( EVT_HOT_PLUG == event )
{
status = phHciNfc_Send_Admin_Event ( psHciContext, pHwRef,
EVT_HOT_PLUG, 0 ,NULL);
}
else
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INSTRUCTION);
}
}
return status;
}
static
NFCSTATUS
phHciNfc_Admin_InfoUpdate(
phHciNfc_sContext_t *psHciContext,
phHal_sHwReference_t *pHwRef,
uint8_t index,
uint8_t *reg_value,
uint8_t reg_length
)
{
phHciNfc_AdminGate_Info_t *p_admin_info=NULL;
uint8_t i=0;
NFCSTATUS status = NFCSTATUS_SUCCESS;
if(NULL == reg_value)
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
}
else
{
p_admin_info = psHciContext->p_admin_info ;
HCI_PRINT_BUFFER("Admin Mgmt Info Buffer",reg_value,reg_length);
switch(index)
{
case SESSION_INDEX :
{
for(i=0 ;(reg_length == SESSIONID_LEN)&&(i < reg_length); i++)
{
p_admin_info->session_id[i] = reg_value[i];
pHwRef->session_id[i] = reg_value[i];
}
break;
}
case MAX_PIPE_INDEX :
{
p_admin_info->max_pipe = reg_value[i];
break;
}
case WHITELIST_INDEX :
{
for(i=0 ;(reg_length <= WHITELIST_MAX_LEN)&&(i < reg_length); i++)
{
p_admin_info->whitelist[i] = reg_value[i];
}
break;
}
case HOST_LIST_INDEX :
{
for(i=0 ;(reg_length <= HOST_LIST_MAX_LEN)&&(i < reg_length); i++)
{
p_admin_info->host_list[i] = reg_value[i];
}
break;
}
default:
{
status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
break;
} /*End of the default Switch Case */
} /*End of the Index Switch */
} /* End of Context and the Identity information validity check */
return status;
}
|