-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
RedfishDiscoverDxe.c
2129 lines (1844 loc) · 87 KB
/
RedfishDiscoverDxe.c
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
/** @file
The implementation of EFI Redfish Discover Protocol.
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2022, AMD Incorporated. All rights reserved.
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "RedfishDiscoverInternal.h"
LIST_ENTRY mRedfishDiscoverList;
LIST_ENTRY mRedfishInstanceList;
EFI_SMBIOS_PROTOCOL *mSmbios = NULL;
UINTN mNumNetworkInterface = 0;
UINTN mNumRestExInstance = 0;
LIST_ENTRY mEfiRedfishDiscoverNetworkInterface;
LIST_ENTRY mEfiRedfishDiscoverRestExInstance;
EFI_GUID mRedfishDiscoverTcp4InstanceGuid = EFI_REDFISH_DISCOVER_TCP4_INSTANCE_GUID;
EFI_GUID mRedfishDiscoverTcp6InstanceGuid = EFI_REDFISH_DISCOVER_TCP6_INSTANCE_GUID;
EFI_GUID mRedfishDiscoverRestExInstanceGuid = EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_GUID;
EFI_STATUS
EFIAPI
Tcp4GetSubnetInfo (
IN EFI_HANDLE ImageHandle,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
);
EFI_STATUS
EFIAPI
Tcp6GetSubnetInfo (
IN EFI_HANDLE ImageHandle,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
);
static REDFISH_DISCOVER_REQUIRED_PROTOCOL gRequiredProtocol[] = {
{
ProtocolTypeTcp4,
L"TCP4 Service Binding Protocol",
&gEfiTcp4ProtocolGuid,
&gEfiTcp4ServiceBindingProtocolGuid,
&mRedfishDiscoverTcp4InstanceGuid,
Tcp4GetSubnetInfo
},
{
ProtocolTypeTcp6,
L"TCP6 Service Binding Protocol",
&gEfiTcp6ProtocolGuid,
&gEfiTcp6ServiceBindingProtocolGuid,
&mRedfishDiscoverTcp6InstanceGuid,
Tcp6GetSubnetInfo
},
{
ProtocolTypeRestEx,
L"REST EX Service Binding Protocol",
&gEfiRestExProtocolGuid,
&gEfiRestExServiceBindingProtocolGuid,
&mRedfishDiscoverRestExInstanceGuid,
NULL
}
};
/**
This function creates REST EX instance for the found Resfish service.
by known owner handle.
@param[in] Instance EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE
@param[in] Token Client token.
@retval NULL Instance not found.
@retval EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE The instance owned by this owner.
**/
EFI_STATUS
CreateRestExInstance (
IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
IN EFI_REDFISH_DISCOVERED_TOKEN *Token
)
{
EFI_STATUS Status;
Status = RestExLibCreateChild (
Instance->Owner,
FixedPcdGetBool (PcdRedfishDiscoverAccessModeInBand) ? EfiRestExServiceInBandAccess : EfiRestExServiceOutOfBandAccess,
EfiRestExConfigHttp,
EfiRestExServiceRedfish,
&Token->DiscoverList.RedfishInstances->Information.RedfishRestExHandle
);
return Status;
}
/**
This function gets EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE
by known owner handle.
@param[in] ImageHandle Image handle owns EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE.
@param[in] TargetNetworkInterface Target network interface used by this EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE.
@param[in] DiscoverFlags EFI_REDFISH_DISCOVER_FLAG
@retval NULL Instance not found.
@retval EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE The instance owned by this owner.
**/
EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *
GetInstanceByOwner (
IN EFI_HANDLE ImageHandle,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *TargetNetworkInterface,
IN EFI_REDFISH_DISCOVER_FLAG DiscoverFlags
)
{
EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *ThisInstance;
if (IsListEmpty (&mRedfishDiscoverList)) {
return NULL;
}
ThisInstance =
(EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *)GetFirstNode (&mRedfishDiscoverList);
while (TRUE) {
if ((ThisInstance->Owner == ImageHandle) &&
(ThisInstance->DiscoverFlags == DiscoverFlags) &&
(ThisInstance->NetworkInterface == TargetNetworkInterface))
{
return ThisInstance;
}
if (IsNodeAtEnd (&mRedfishDiscoverList, &ThisInstance->Entry)) {
break;
}
ThisInstance =
(EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *)GetNextNode (&mRedfishDiscoverList, &ThisInstance->Entry);
}
return NULL;
}
/**
This function gets the subnet information of this TCP4 instance.
@param[in] ImageHandle EFI handle with this image.
@param[in] Instance Instance of Network interface.
@retval EFI_STATUS Get subnet information successfully.
@retval Otherwise Fail to get subnet information.
**/
EFI_STATUS
EFIAPI
Tcp4GetSubnetInfo (
IN EFI_HANDLE ImageHandle,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
)
{
EFI_STATUS Status;
EFI_TCP4_PROTOCOL *Tcp4;
EFI_TCP4_CONFIG_DATA Tcp4CfgData;
EFI_TCP4_OPTION Tcp4Option;
EFI_IP4_MODE_DATA IpModedata;
UINT8 SubnetMaskIndex;
UINT8 BitMask;
UINT8 PrefixLength;
BOOLEAN GotPrefixLength;
if (Instance == NULL) {
return EFI_INVALID_PARAMETER;
}
Tcp4 = (EFI_TCP4_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
ZeroMem ((VOID *)&Tcp4CfgData, sizeof (EFI_TCP4_CONFIG_DATA));
ZeroMem ((VOID *)&Tcp4Option, sizeof (EFI_TCP4_OPTION));
// Give a local host IP address just for getting subnet information.
Tcp4CfgData.AccessPoint.UseDefaultAddress = TRUE;
Tcp4CfgData.AccessPoint.RemoteAddress.Addr[0] = 127;
Tcp4CfgData.AccessPoint.RemoteAddress.Addr[1] = 0;
Tcp4CfgData.AccessPoint.RemoteAddress.Addr[2] = 0;
Tcp4CfgData.AccessPoint.RemoteAddress.Addr[3] = 1;
Tcp4CfgData.AccessPoint.RemotePort = 80;
Tcp4CfgData.AccessPoint.ActiveFlag = TRUE;
Tcp4CfgData.ControlOption = &Tcp4Option;
Tcp4Option.ReceiveBufferSize = 65535;
Tcp4Option.SendBufferSize = 65535;
Tcp4Option.MaxSynBackLog = 5;
Tcp4Option.ConnectionTimeout = 60;
Tcp4Option.DataRetries = 12;
Tcp4Option.FinTimeout = 2;
Tcp4Option.KeepAliveProbes = 6;
Tcp4Option.KeepAliveTime = 7200;
Tcp4Option.KeepAliveInterval = 30;
Tcp4Option.EnableNagle = TRUE;
Status = Tcp4->Configure (Tcp4, &Tcp4CfgData);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't get subnet information\n", __func__));
return Status;
}
Status = Tcp4->GetModeData (Tcp4, NULL, NULL, &IpModedata, NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __func__));
return Status;
}
IP4_COPY_ADDRESS (&Instance->SubnetMask, &IpModedata.ConfigData.SubnetMask);
Instance->SubnetAddr.v4.Addr[0] = IpModedata.ConfigData.StationAddress.Addr[0] & Instance->SubnetMask.v4.Addr[0];
Instance->SubnetAddr.v4.Addr[1] = IpModedata.ConfigData.StationAddress.Addr[1] & Instance->SubnetMask.v4.Addr[1];
Instance->SubnetAddr.v4.Addr[2] = IpModedata.ConfigData.StationAddress.Addr[2] & Instance->SubnetMask.v4.Addr[2];
Instance->SubnetAddr.v4.Addr[3] = IpModedata.ConfigData.StationAddress.Addr[3] & Instance->SubnetMask.v4.Addr[3];
//
// Calculate the subnet mask prefix.
//
GotPrefixLength = FALSE;
PrefixLength = 0;
SubnetMaskIndex = 0;
while (GotPrefixLength == FALSE && SubnetMaskIndex < 4) {
BitMask = 0x80;
while (BitMask != 0) {
if ((Instance->SubnetMask.v4.Addr[SubnetMaskIndex] & BitMask) != 0) {
PrefixLength++;
} else {
GotPrefixLength = TRUE;
break;
}
BitMask = BitMask >> 1;
}
SubnetMaskIndex++;
}
Instance->SubnetPrefixLength = PrefixLength;
return EFI_SUCCESS;
}
/**
This function gets the subnet information of this TCP6 instance.
@param[in] ImageHandle EFI handle with this image.
@param[in] Instance Instance of Network interface.
@retval EFI_STATUS Get subnet information successfully.
@retval Otherwise Fail to get subnet information.
**/
EFI_STATUS
EFIAPI
Tcp6GetSubnetInfo (
IN EFI_HANDLE ImageHandle,
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance
)
{
EFI_STATUS Status;
EFI_TCP6_PROTOCOL *Tcp6;
EFI_IP6_MODE_DATA IpModedata;
if (Instance == NULL) {
return EFI_INVALID_PARAMETER;
}
Tcp6 = (EFI_TCP6_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
ZeroMem ((VOID *)&IpModedata, sizeof (EFI_IP6_MODE_DATA));
Status = Tcp6->GetModeData (Tcp6, NULL, NULL, &IpModedata, NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __func__));
return Status;
}
if (IpModedata.AddressCount == 0) {
DEBUG ((DEBUG_INFO, "%a: No IPv6 address configured.\n", __func__));
Instance->SubnetAddrInfoIPv6Number = 0;
return EFI_SUCCESS;
}
if (Instance->SubnetAddrInfoIPv6 != NULL) {
FreePool (Instance->SubnetAddrInfoIPv6);
Instance->SubnetAddrInfoIPv6 = NULL;
}
Instance->SubnetAddrInfoIPv6 = AllocateZeroPool (IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO));
if (Instance->SubnetAddrInfoIPv6 == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory for IPv6 subnet address information\n", __func__));
return EFI_OUT_OF_RESOURCES;
}
Instance->SubnetAddrInfoIPv6Number = IpModedata.AddressCount;
if ((IpModedata.AddressCount != 0) && (IpModedata.AddressList != NULL)) {
CopyMem (
(VOID *)Instance->SubnetAddrInfoIPv6,
(VOID *)&IpModedata.AddressList,
IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO)
);
FreePool (IpModedata.AddressList);
}
return EFI_SUCCESS;
}
/**
This function searches EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
instance with the given EFI_REDFISH_DISCOVER_NETWORK_INTERFACE.
@param[in] TargetNetworkInterface EFI_REDFISH_DISCOVER_NETWORK_INTERFACE.
NULL for all EFI_REDFISH_DISCOVER_NETWORK_INTERFACEs.
@retval Non-NULL EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL is returned.
@retval NULL Non of EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL instance is returned.
**/
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *
GetTargetNetworkInterfaceInternal (
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *TargetNetworkInterface
)
{
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
return ThisNetworkInterface;
}
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
return NULL;
}
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
}
return NULL;
}
/**
This function searches EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
instance with the given Controller handle.
@param[in] ControllerHandle The controller handle associated with network interface.
@retval Non-NULL EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL is returned.
@retval NULL Non of EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL instance is returned.
**/
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *
GetTargetNetworkInterfaceInternalByController (
IN EFI_HANDLE ControllerHandle
)
{
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if (ThisNetworkInterface->OpenDriverControllerHandle == ControllerHandle) {
return ThisNetworkInterface;
}
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
return NULL;
}
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
}
return NULL;
}
/**
This function validate if target network interface is ready for discovering
Redfish service.
@param[in] TargetNetworkInterface EFI_REDFISH_DISCOVER_NETWORK_INTERFACE.
NULL for all EFI_REDFISH_DISCOVER_NETWORK_INTERFACEs.
@param[in] Flags EFI_REDFISH_DISCOVER_FLAG
@retval EFI_SUCCESS Target network interface is ready to use.
@retval EFI_UNSUPPORTED Target network interface is not ready to use.
**/
EFI_STATUS
ValidateTargetNetworkInterface (
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *TargetNetworkInterface,
IN EFI_REDFISH_DISCOVER_FLAG Flags
)
{
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface) && (TargetNetworkInterface == NULL)) {
return EFI_UNSUPPORTED;
}
if (TargetNetworkInterface == NULL) {
return EFI_SUCCESS; // Return EFI_SUCCESS if no network interface is specified.
}
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
break;
}
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
return EFI_UNSUPPORTED;
}
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
}
if ((Flags & EFI_REDFISH_DISCOVER_SSDP) != 0) {
// Validate if UDP4/6 is supported on the given network interface.
// SSDP is not supported.
return EFI_SUCCESS;
}
if (ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle == NULL) {
return EFI_UNSUPPORTED; // The required protocol on this network interface is not found.
}
return EFI_SUCCESS;
}
/**
This function returns number of network interface instance.
@retval UINTN Number of network interface instances.
**/
UINTN
NumberOfNetworkInterface (
VOID
)
{
UINTN Num;
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
return 0;
}
Num = 1;
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
break;
}
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
Num++;
}
return Num;
}
/**
This function checks the IP version supported on this
network interface.
@param[in] ThisNetworkInterface EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
@retval TRUE Is IPv6, otherwise IPv4.
**/
BOOLEAN
CheckIsIpVersion6 (
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface
)
{
if (ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp6) {
return TRUE;
}
return FALSE;
}
/**
This function discover Redfish service through SMBIOS host interface.
@param[in] Instance EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE
@retval EFI_SUCCESS Redfish service is discovered through SMBIOS Host interface.
@retval Others Fail to discover Redfish service through SMBIOS host interface
**/
EFI_STATUS
DiscoverRedfishHostInterface (
IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance
)
{
EFI_STATUS Status;
REDFISH_OVER_IP_PROTOCOL_DATA *Data;
REDFISH_INTERFACE_DATA *DeviceDescriptor;
CHAR8 UuidStr[sizeof "00000000-0000-0000-0000-000000000000" + 1];
CHAR16 Ipv6Str[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + 1];
CHAR8 RedfishServiceLocateStr[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + 1];
UINTN StrSize;
UINTN MacCompareStatus;
BOOLEAN IsHttps;
Data = NULL;
DeviceDescriptor = NULL;
if (mSmbios == NULL) {
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&mSmbios);
if (EFI_ERROR (Status)) {
return Status;
}
}
Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, &Data); // Search for SMBIOS type 42h
if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
//
// Check if we can reach out Redfish service using this network interface.
// Check with MAC address using Device Descriptor Data Device Type 04 and Type 05.
// Those two types of Redfish host interface device has MAC information.
//
if (DeviceDescriptor->DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
MacCompareStatus = CompareMem (&Instance->NetworkInterface->MacAddress, &DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV2.MacAddress, 6);
} else if (DeviceDescriptor->DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2) {
MacCompareStatus = CompareMem (&Instance->NetworkInterface->MacAddress, &DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress, 6);
} else {
return EFI_UNSUPPORTED;
}
if (MacCompareStatus != 0) {
return EFI_UNSUPPORTED;
}
Instance->HostAddrFormat = Data->HostIpAddressFormat;
if (Data->HostIpAddressFormat == REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4) {
IP4_COPY_ADDRESS ((VOID *)&Instance->HostIpAddress.v4, (VOID *)Data->HostIpAddress);
IP4_COPY_ADDRESS ((VOID *)&Instance->HostSubnetMask.v4, (VOID *)Data->HostIpMask);
if (EFI_IP4_EQUAL (&Instance->HostIpAddress.v4, &mZeroIp4Addr)) {
DEBUG ((DEBUG_ERROR, "%a: invalid host IP address: zero address\n", __func__));
//
// Invalid IP address detected. Change address format to Unknown and use system default address.
//
Instance->HostAddrFormat = REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
}
if (!IP4_IS_VALID_NETMASK (EFI_IP4 (Instance->HostSubnetMask.v4))) {
DEBUG ((DEBUG_ERROR, "%a: invalid subnet mask address\n", __func__));
//
// Invalid subnet mast address detected. Change address format to Unknown and use system default address.
//
Instance->HostAddrFormat = REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
}
} else if (Data->HostIpAddressFormat == REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6) {
IP6_COPY_ADDRESS ((VOID *)&Instance->HostIpAddress.v6, (VOID *)Data->HostIpAddress);
}
if (Data->RedfishServiceIpAddressFormat == REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4) {
IP4_COPY_ADDRESS ((VOID *)&Instance->TargetIpAddress.v4, (VOID *)Data->RedfishServiceIpAddress);
if (EFI_IP4_EQUAL (&Instance->TargetIpAddress.v4, &mZeroIp4Addr)) {
DEBUG ((DEBUG_ERROR, "%a: invalid service IP address: zero address\n", __func__));
}
} else {
IP6_COPY_ADDRESS ((VOID *)&Instance->TargetIpAddress.v6, (VOID *)Data->RedfishServiceIpAddress);
}
if (Instance->HostIntfValidation) {
DEBUG ((DEBUG_ERROR, "%a:Send UPnP unicast SSDP to validate this Redfish Host Interface is not supported.\n", __func__));
Status = EFI_UNSUPPORTED;
} else {
//
// Add this instance to list without detail information of Redfish
// service.
//
IsHttps = FALSE;
if (Data->RedfishServiceIpPort == 443) {
IsHttps = TRUE;
}
StrSize = sizeof (UuidStr);
AsciiSPrint (UuidStr, StrSize, "%g", &Data->ServiceUuid);
//
// Generate Redfish service location string.
//
if (Data->RedfishServiceIpAddressFormat == REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6) {
NetLibIp6ToStr ((IPv6_ADDRESS *)&Data->RedfishServiceIpAddress, Ipv6Str, sizeof (Ipv6Str));
if ((Data->RedfishServiceIpPort == 0) || (IsHttps == TRUE)) {
AsciiSPrintUnicodeFormat (
RedfishServiceLocateStr,
sizeof (RedfishServiceLocateStr),
L"%s",
Ipv6Str
);
} else {
AsciiSPrintUnicodeFormat (
RedfishServiceLocateStr,
sizeof (RedfishServiceLocateStr),
L"[%s]:%d",
Ipv6Str,
Data->RedfishServiceIpPort
);
}
} else {
if ((Data->RedfishServiceIpPort == 0) || (IsHttps == TRUE)) {
AsciiSPrint (
RedfishServiceLocateStr,
sizeof (RedfishServiceLocateStr),
"%d.%d.%d.%d",
Data->RedfishServiceIpAddress[0],
Data->RedfishServiceIpAddress[1],
Data->RedfishServiceIpAddress[2],
Data->RedfishServiceIpAddress[3]
);
} else {
AsciiSPrint (
RedfishServiceLocateStr,
sizeof (RedfishServiceLocateStr),
"%d.%d.%d.%d:%d",
Data->RedfishServiceIpAddress[0],
Data->RedfishServiceIpAddress[1],
Data->RedfishServiceIpAddress[2],
Data->RedfishServiceIpAddress[3],
Data->RedfishServiceIpPort
);
}
}
Status = AddAndSignalNewRedfishService (
Instance,
NULL,
RedfishServiceLocateStr,
UuidStr,
NULL,
NULL,
NULL,
NULL,
IsHttps
);
}
}
return Status;
}
/**
The function adds a new found Redfish service to internal list and
notify client.
@param[in] Instance EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE.
@param[in] RedfishVersion Redfish version.
@param[in] RedfishLocation Redfish location.
@param[in] Uuid Service UUID string.
@param[in] Os OS string.
@param[in] OsVer OS version string.
@param[in] Product Product string.
@param[in] ProductVer Product version string.
@param[in] UseHttps Redfish service requires secured connection.
@retval EFI_SUCCESS Redfish service is added to list successfully.
**/
EFI_STATUS
AddAndSignalNewRedfishService (
IN EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance,
IN UINTN *RedfishVersion OPTIONAL,
IN CHAR8 *RedfishLocation OPTIONAL,
IN CHAR8 *Uuid OPTIONAL,
IN CHAR8 *Os OPTIONAL,
IN CHAR8 *OsVer OPTIONAL,
IN CHAR8 *Product OPTIONAL,
IN CHAR8 *ProductVer OPTIONAL,
IN BOOLEAN UseHttps
)
{
BOOLEAN NewFound;
BOOLEAN InfoRefresh;
BOOLEAN RestExOpened;
BOOLEAN DeleteRestEx;
EFI_STATUS Status;
EFI_REDFISH_DISCOVERED_INTERNAL_LIST *DiscoveredList;
EFI_REDFISH_DISCOVERED_INSTANCE *DiscoveredInstance;
CHAR16 *Char16Uuid;
EFI_REST_EX_PROTOCOL *RestEx;
EFI_REST_EX_HTTP_CONFIG_DATA *RestExHttpConfigData;
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NetworkInterface;
NewFound = TRUE;
InfoRefresh = FALSE;
Char16Uuid = NULL;
RestExOpened = FALSE;
DeleteRestEx = FALSE;
DEBUG ((DEBUG_INFO, "%a:Add this instance to Redfish instance list.\n", __func__));
if (Uuid != NULL) {
Char16Uuid = (CHAR16 *)AllocateZeroPool (AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
AsciiStrToUnicodeStrS ((const CHAR8 *)Uuid, Char16Uuid, AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
}
DiscoveredList = NULL;
DiscoveredInstance = NULL;
RestExHttpConfigData = NULL;
NetworkInterface = Instance->NetworkInterface;
if (!IsListEmpty (&mRedfishInstanceList)) {
//
// Is this a duplicate redfish service.
//
DiscoveredList = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetFirstNode (&mRedfishInstanceList);
NewFound = FALSE;
do {
if ((Char16Uuid == NULL) || (DiscoveredList->Instance->Information.Uuid == NULL)) {
//
// Check if this Redfish instance already found using IP address.
//
if (!CheckIsIpVersion6 (NetworkInterface)) {
if (CompareMem (
(VOID *)&Instance->TargetIpAddress.v4,
(VOID *)&DiscoveredList->Instance->Information.RedfishHostIpAddress.v4,
sizeof (EFI_IPv4_ADDRESS)
) == 0)
{
DiscoveredInstance = DiscoveredList->Instance;
if ((DiscoveredList->Instance->Information.Uuid == NULL) &&
(Char16Uuid != NULL))
{
InfoRefresh = TRUE;
DiscoveredInstance = DiscoveredList->Instance;
DEBUG ((DEBUG_INFO, "*** This Redfish Service information refresh ***\n"));
}
break;
}
} else {
if (CompareMem (
(VOID *)&Instance->TargetIpAddress.v6,
(VOID *)&DiscoveredList->Instance->Information.RedfishHostIpAddress.v6,
sizeof (EFI_IPv6_ADDRESS)
) == 0)
{
DiscoveredInstance = DiscoveredList->Instance;
break;
}
}
} else {
//
// Check if this Redfish instance already found using UUID.
//
if (StrCmp ((const CHAR16 *)Char16Uuid, (const CHAR16 *)DiscoveredList->Instance->Information.Uuid) == 0) {
DiscoveredInstance = DiscoveredList->Instance;
break;
}
}
if (IsNodeAtEnd (&mRedfishInstanceList, &DiscoveredList->NextInstance)) {
NewFound = TRUE;
break;
}
DiscoveredList = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)GetNextNode (&mRedfishInstanceList, &DiscoveredList->NextInstance);
} while (TRUE);
}
if (NewFound || InfoRefresh) {
if (!InfoRefresh) {
DiscoveredList = (EFI_REDFISH_DISCOVERED_INTERNAL_LIST *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_INTERNAL_LIST));
if (DiscoveredList == NULL) {
return EFI_OUT_OF_RESOURCES;
}
InitializeListHead (&DiscoveredList->NextInstance);
DiscoveredInstance = (EFI_REDFISH_DISCOVERED_INSTANCE *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_INSTANCE));
if (DiscoveredInstance == NULL) {
FreePool ((VOID *)DiscoveredList);
return EFI_OUT_OF_RESOURCES;
}
}
DEBUG ((DEBUG_INFO, "*** Redfish Service Information ***\n"));
DiscoveredInstance->Information.UseHttps = UseHttps;
if (RedfishVersion != NULL) {
DiscoveredInstance->Information.RedfishVersion = *RedfishVersion;
DEBUG ((DEBUG_INFO, "Redfish service version: %d.\n", DiscoveredInstance->Information.RedfishVersion));
}
if (RedfishLocation != NULL) {
DiscoveredInstance->Information.Location = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)RedfishLocation) * sizeof (CHAR16));
AsciiStrToUnicodeStrS ((const CHAR8 *)RedfishLocation, DiscoveredInstance->Information.Location, AsciiStrSize ((const CHAR8 *)RedfishLocation) * sizeof (CHAR16));
DEBUG ((DEBUG_INFO, "Redfish service location: %s.\n", DiscoveredInstance->Information.Location));
}
if (Uuid != NULL) {
DiscoveredInstance->Information.Uuid = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
AsciiStrToUnicodeStrS ((const CHAR8 *)Uuid, DiscoveredInstance->Information.Uuid, AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
DEBUG ((DEBUG_INFO, "Service UUID: %s.\n", DiscoveredInstance->Information.Uuid));
}
if (Os != NULL) {
DiscoveredInstance->Information.Os = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Os) * sizeof (CHAR16));
AsciiStrToUnicodeStrS ((const CHAR8 *)Os, DiscoveredInstance->Information.Os, AsciiStrSize ((const CHAR8 *)Os) * sizeof (CHAR16));
DEBUG ((DEBUG_INFO, "Redfish service OS: %s, Version:%s.\n", DiscoveredInstance->Information.Os, DiscoveredInstance->Information.OsVersion));
}
if (OsVer != NULL) {
DiscoveredInstance->Information.OsVersion = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)OsVer) * sizeof (CHAR16));
AsciiStrToUnicodeStrS ((const CHAR8 *)OsVer, DiscoveredInstance->Information.OsVersion, AsciiStrSize ((const CHAR8 *)OsVer) * sizeof (CHAR16));
}
if ((Product != NULL) && (ProductVer != NULL)) {
DiscoveredInstance->Information.Product = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Product) * sizeof (CHAR16));
AsciiStrToUnicodeStrS ((const CHAR8 *)Product, DiscoveredInstance->Information.Product, AsciiStrSize ((const CHAR8 *)Product) * sizeof (CHAR16));
DiscoveredInstance->Information.ProductVer = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)ProductVer) * sizeof (CHAR16));
AsciiStrToUnicodeStrS ((const CHAR8 *)ProductVer, DiscoveredInstance->Information.ProductVer, AsciiStrSize ((const CHAR8 *)ProductVer) * sizeof (CHAR16));
DEBUG ((DEBUG_INFO, "Redfish service product: %s, Version:%s.\n", DiscoveredInstance->Information.Product, DiscoveredInstance->Information.ProductVer));
}
if (RedfishLocation == NULL) {
// This is the Redfish reported from SMBIOS 42h
// without validation.
IP4_COPY_ADDRESS ((VOID *)&DiscoveredInstance->Information.RedfishHostIpAddress.v4, (VOID *)&Instance->TargetIpAddress.v4);
}
if (!InfoRefresh) {
DiscoveredList->Instance = DiscoveredInstance;
InsertTailList (&mRedfishInstanceList, &DiscoveredList->NextInstance);
}
DiscoveredInstance->Status = EFI_SUCCESS;
} else {
if (DiscoveredList != NULL) {
DEBUG ((DEBUG_INFO, "*** This Redfish Service was already found ***\n"));
if (DiscoveredInstance->Information.Uuid != NULL) {
DEBUG ((DEBUG_INFO, "Service UUID: %s.\n", DiscoveredInstance->Information.Uuid));
} else {
DEBUG ((DEBUG_INFO, "Service UUID: unknown.\n"));
}
}
}
if (Char16Uuid != NULL) {
FreePool ((VOID *)Char16Uuid);
}
Status = EFI_SUCCESS;
if (NewFound || InfoRefresh) {
//
// Build up EFI_REDFISH_DISCOVERED_LIST in token.
//
Instance->DiscoverToken->DiscoverList.NumberOfServiceFound = 1;
Instance->DiscoverToken->DiscoverList.RedfishInstances = DiscoveredInstance;
DiscoveredInstance->Status = EFI_SUCCESS;
if (!InfoRefresh) {
Status = CreateRestExInstance (Instance, Instance->DiscoverToken); // Create REST EX child.
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a:Can't create REST EX child instance.\n", __func__));
goto ON_EXIT;
}
Status = gBS->OpenProtocol (
// Configure local host information.
Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
&gEfiRestExProtocolGuid,
(VOID **)&RestEx,
Instance->NetworkInterface->OpenDriverAgentHandle,
Instance->NetworkInterface->OpenDriverControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
DeleteRestEx = TRUE;
goto ERROR_EXIT;
}
RestExOpened = TRUE;
RestExHttpConfigData = AllocateZeroPool (sizeof (EFI_REST_EX_HTTP_CONFIG_DATA));
if (RestExHttpConfigData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
DeleteRestEx = TRUE;
goto EXIT_FREE_CONFIG_DATA;
}
RestExHttpConfigData->SendReceiveTimeout = 5000;
RestExHttpConfigData->HttpConfigData.HttpVersion = HttpVersion11;
RestExHttpConfigData->HttpConfigData.LocalAddressIsIPv6 = CheckIsIpVersion6 (NetworkInterface);
if (RestExHttpConfigData->HttpConfigData.LocalAddressIsIPv6) {
RestExHttpConfigData->HttpConfigData.AccessPoint.IPv6Node = AllocateZeroPool (sizeof (EFI_HTTPv6_ACCESS_POINT));
if (RestExHttpConfigData->HttpConfigData.AccessPoint.IPv6Node == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto EXIT_FREE_CONFIG_DATA;
}
if (Instance->HostAddrFormat == REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6) {
IP6_COPY_ADDRESS (&RestExHttpConfigData->HttpConfigData.AccessPoint.IPv6Node->LocalAddress, &Instance->HostIpAddress.v6);
}
} else {
RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node = AllocateZeroPool (sizeof (EFI_HTTPv4_ACCESS_POINT));
if (RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto EXIT_FREE_CONFIG_DATA;
}
if (Instance->HostAddrFormat == REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4) {
RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node->UseDefaultAddress = FALSE;
IP4_COPY_ADDRESS (&RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node->LocalAddress, &Instance->HostIpAddress.v4);
IP4_COPY_ADDRESS (&RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node->LocalSubnet, &Instance->HostSubnetMask.v4);
} else {
RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node->UseDefaultAddress = TRUE;
}
}
Status = RestEx->Configure (
RestEx,
(EFI_REST_EX_CONFIG_DATA)(UINT8 *)RestExHttpConfigData
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a:REST EX configured..\n", __func__));
DeleteRestEx = TRUE;
goto EXIT_FREE_ALL;
}
//
// Signal client, close REST EX before signaling client.
//
if (RestExOpened) {
gBS->CloseProtocol (
Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
&gEfiRestExProtocolGuid,
Instance->NetworkInterface->OpenDriverAgentHandle,
Instance->NetworkInterface->OpenDriverControllerHandle
);
RestExOpened = FALSE;
}
}
Status = gBS->SignalEvent (Instance->DiscoverToken->Event);
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a:No event to signal!\n", __func__));
}
}
EXIT_FREE_ALL:;
if ((RestExHttpConfigData != NULL) && (RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node != NULL)) {
FreePool (RestExHttpConfigData->HttpConfigData.AccessPoint.IPv4Node);
}
EXIT_FREE_CONFIG_DATA:;
if (RestExHttpConfigData != NULL) {
FreePool ((VOID *)RestExHttpConfigData);
}
if (RestExOpened) {
gBS->CloseProtocol (
Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
&gEfiRestExProtocolGuid,
Instance->NetworkInterface->OpenDriverAgentHandle,
Instance->NetworkInterface->OpenDriverControllerHandle
);
}
ERROR_EXIT:;
if (DeleteRestEx && RestExOpened) {
gBS->CloseProtocol (
Instance->DiscoverToken->DiscoverList.RedfishInstances->Information.RedfishRestExHandle,
&gEfiRestExProtocolGuid,
Instance->NetworkInterface->OpenDriverAgentHandle,
Instance->NetworkInterface->OpenDriverControllerHandle
);
}
ON_EXIT:;
return Status;
}
/**
This function gets the subnet information of this network interface instance.
can discover Redfish service on it.
@param[in] Instance EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL instance.
@param[in] ImageHandle EFI Image handle request the network interface list.
@retval EFI_SUCCESS
**/
EFI_STATUS
NetworkInterfaceGetSubnetInfo (
IN EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *Instance,
IN EFI_HANDLE ImageHandle
)
{
EFI_STATUS Status;
UINT32 ProtocolType;
UINT32 IPv6InfoIndex;
EFI_IP6_ADDRESS_INFO *ThisSubnetAddrInfoIPv6;
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *NewNetworkInterface;
if (Instance->GotSubnetInfo) {
return EFI_SUCCESS;
}
ProtocolType = Instance->NetworkProtocolType;
if ((gRequiredProtocol[ProtocolType].GetSubnetInfo != NULL) && (Instance->GotSubnetInfo == FALSE)) {
Status = gRequiredProtocol[ProtocolType].GetSubnetInfo (
ImageHandle,
Instance
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a:Failed to get Subnet infomation.\n", __func__));