2 The implementation of IPSEC_CONFIG_PROTOCOL.
4 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "IpSecConfigImpl.h"
17 #include "IpSecDebug.h"
19 LIST_ENTRY mConfigData
[IPsecConfigDataTypeMaximum
];
20 BOOLEAN mSetBySelf
= FALSE
;
23 // Common CompareSelector routine entry for SPD/SAD/PAD.
25 IPSEC_COMPARE_SELECTOR mCompareSelector
[] = {
26 (IPSEC_COMPARE_SELECTOR
) CompareSpdSelector
,
27 (IPSEC_COMPARE_SELECTOR
) CompareSaId
,
28 (IPSEC_COMPARE_SELECTOR
) ComparePadId
32 // Common IsZeroSelector routine entry for SPD/SAD/PAD.
34 IPSEC_IS_ZERO_SELECTOR mIsZeroSelector
[] = {
35 (IPSEC_IS_ZERO_SELECTOR
) IsZeroSpdSelector
,
36 (IPSEC_IS_ZERO_SELECTOR
) IsZeroSaId
,
37 (IPSEC_IS_ZERO_SELECTOR
) IsZeroPadId
41 // Common DuplicateSelector routine entry for SPD/SAD/PAD.
43 IPSEC_DUPLICATE_SELECTOR mDuplicateSelector
[] = {
44 (IPSEC_DUPLICATE_SELECTOR
) DuplicateSpdSelector
,
45 (IPSEC_DUPLICATE_SELECTOR
) DuplicateSaId
,
46 (IPSEC_DUPLICATE_SELECTOR
) DuplicatePadId
50 // Common FixPolicyEntry routine entry for SPD/SAD/PAD.
52 IPSEC_FIX_POLICY_ENTRY mFixPolicyEntry
[] = {
53 (IPSEC_FIX_POLICY_ENTRY
) FixSpdEntry
,
54 (IPSEC_FIX_POLICY_ENTRY
) FixSadEntry
,
55 (IPSEC_FIX_POLICY_ENTRY
) FixPadEntry
59 // Common UnfixPolicyEntry routine entry for SPD/SAD/PAD.
61 IPSEC_FIX_POLICY_ENTRY mUnfixPolicyEntry
[] = {
62 (IPSEC_FIX_POLICY_ENTRY
) UnfixSpdEntry
,
63 (IPSEC_FIX_POLICY_ENTRY
) UnfixSadEntry
,
64 (IPSEC_FIX_POLICY_ENTRY
) UnfixPadEntry
68 // Common SetPolicyEntry routine entry for SPD/SAD/PAD.
70 IPSEC_SET_POLICY_ENTRY mSetPolicyEntry
[] = {
71 (IPSEC_SET_POLICY_ENTRY
) SetSpdEntry
,
72 (IPSEC_SET_POLICY_ENTRY
) SetSadEntry
,
73 (IPSEC_SET_POLICY_ENTRY
) SetPadEntry
77 // Common GetPolicyEntry routine entry for SPD/SAD/PAD.
79 IPSEC_GET_POLICY_ENTRY mGetPolicyEntry
[] = {
80 (IPSEC_GET_POLICY_ENTRY
) GetSpdEntry
,
81 (IPSEC_GET_POLICY_ENTRY
) GetSadEntry
,
82 (IPSEC_GET_POLICY_ENTRY
) GetPadEntry
86 // Routine entry for IpSecConfig protocol.
88 EFI_IPSEC_CONFIG_PROTOCOL mIpSecConfigInstance
= {
89 EfiIpSecConfigSetData
,
90 EfiIpSecConfigGetData
,
91 EfiIpSecConfigGetNextSelector
,
92 EfiIpSecConfigRegisterNotify
,
93 EfiIpSecConfigUnregisterNotify
97 Get the all IPSec configuration variables and store those variables
98 to the internal data structure.
100 This founction is called by IpSecConfigInitialize() that is to intialize the
101 IPsecConfiguration Protocol.
103 @param[in] Private Point to IPSEC_PRIVATE_DATA.
105 @retval EFI_OUT_OF_RESOURCES The required system resource could not be allocated.
106 @retval EFI_SUCCESS Restore the IPsec Configuration successfully.
107 @retval others Other errors is found during the variable getting.
112 IN IPSEC_PRIVATE_DATA
*Private
116 Check if the specified EFI_IP_ADDRESS_INFO is in EFI_IP_ADDRESS_INFO list.
118 @param[in] AddressInfo Pointer of IP_ADDRESS_INFO to be search in AddressInfo list.
119 @param[in] AddressInfoList A list that contains IP_ADDRESS_INFOs.
120 @param[in] AddressCount Point out how many IP_ADDRESS_INFO in the list.
122 @retval TRUE The specified AddressInfo is in the AddressInfoList.
123 @retval FALSE The specified AddressInfo is not in the AddressInfoList.
128 IN EFI_IP_ADDRESS_INFO
*AddressInfo
,
129 IN EFI_IP_ADDRESS_INFO
*AddressInfoList
,
130 IN UINT32 AddressCount
134 EFI_IP_ADDRESS ZeroAddress
;
136 ZeroMem(&ZeroAddress
, sizeof (EFI_IP_ADDRESS
));
139 // Zero Address means any address is matched.
141 if (AddressCount
== 1) {
143 &AddressInfoList
[0].Address
,
145 sizeof (EFI_IP_ADDRESS
)
150 for (Index
= 0; Index
< AddressCount
; Index
++) {
153 &AddressInfoList
[Index
].Address
,
154 sizeof (EFI_IP_ADDRESS
)
156 AddressInfo
->PrefixLength
== AddressInfoList
[Index
].PrefixLength
165 Compare two SPD Selectors.
167 Compare two SPD Selector by the fields of LocalAddressCount/RemoteAddressCount/
168 NextLayerProtocol/LocalPort/LocalPortRange/RemotePort/RemotePortRange and the
169 Local Addresses and remote Addresses.
171 @param[in] Selector1 Pointer of first SPD Selector.
172 @param[in] Selector2 Pointer of second SPD Selector.
174 @retval TRUE This two Selector have the same value in above fields.
175 @retval FALSE Not all above fields have the same value in these two Selectors.
180 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector1
,
181 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector2
184 EFI_IPSEC_SPD_SELECTOR
*SpdSel1
;
185 EFI_IPSEC_SPD_SELECTOR
*SpdSel2
;
189 SpdSel1
= &Selector1
->SpdSelector
;
190 SpdSel2
= &Selector2
->SpdSelector
;
194 // Compare the LocalAddressCount/RemoteAddressCount/NextLayerProtocol/
195 // LocalPort/LocalPortRange/RemotePort/RemotePortRange fields in the
196 // two Spdselectors. Since the SPD supports two directions, it needs to
197 // compare two directions.
199 if ((SpdSel1
->LocalAddressCount
!= SpdSel2
->LocalAddressCount
&&
200 SpdSel1
->LocalAddressCount
!= SpdSel2
->RemoteAddressCount
) ||
201 (SpdSel1
->RemoteAddressCount
!= SpdSel2
->RemoteAddressCount
&&
202 SpdSel1
->RemoteAddressCount
!= SpdSel2
->LocalAddressCount
) ||
203 SpdSel1
->NextLayerProtocol
!= SpdSel2
->NextLayerProtocol
||
204 SpdSel1
->LocalPort
!= SpdSel2
->LocalPort
||
205 SpdSel1
->LocalPortRange
!= SpdSel2
->LocalPortRange
||
206 SpdSel1
->RemotePort
!= SpdSel2
->RemotePort
||
207 SpdSel1
->RemotePortRange
!= SpdSel2
->RemotePortRange
214 // Compare the all LocalAddress fields in the two Spdselectors.
215 // First, SpdSel1->LocalAddress to SpdSel2->LocalAddress && Compare
216 // SpdSel1->RemoteAddress to SpdSel2->RemoteAddress. If all match, return
219 for (Index
= 0; Index
< SpdSel1
->LocalAddressCount
; Index
++) {
220 if (!IsInAddressInfoList (
221 &SpdSel1
->LocalAddress
[Index
],
222 SpdSel2
->LocalAddress
,
223 SpdSel2
->LocalAddressCount
230 for (Index
= 0; Index
< SpdSel2
->LocalAddressCount
; Index
++) {
231 if (!IsInAddressInfoList (
232 &SpdSel2
->LocalAddress
[Index
],
233 SpdSel1
->LocalAddress
,
234 SpdSel1
->LocalAddressCount
242 for (Index
= 0; Index
< SpdSel1
->RemoteAddressCount
; Index
++) {
243 if (!IsInAddressInfoList (
244 &SpdSel1
->RemoteAddress
[Index
],
245 SpdSel2
->RemoteAddress
,
246 SpdSel2
->RemoteAddressCount
254 for (Index
= 0; Index
< SpdSel2
->RemoteAddressCount
; Index
++) {
255 if (!IsInAddressInfoList (
256 &SpdSel2
->RemoteAddress
[Index
],
257 SpdSel1
->RemoteAddress
,
258 SpdSel1
->RemoteAddressCount
266 // Finish the one direction compare. If it is matched, return; otherwise,
267 // compare the other direction.
273 // Secondly, the SpdSel1->LocalAddress doesn't equal to SpdSel2->LocalAddress and
274 // SpdSel1->RemoteAddress doesn't equal to SpdSel2->RemoteAddress. Try to compare
275 // the RemoteAddress to LocalAddress.
278 for (Index
= 0; Index
< SpdSel1
->RemoteAddressCount
; Index
++) {
279 if (!IsInAddressInfoList (
280 &SpdSel1
->RemoteAddress
[Index
],
281 SpdSel2
->LocalAddress
,
282 SpdSel2
->LocalAddressCount
289 for (Index
= 0; Index
< SpdSel2
->RemoteAddressCount
; Index
++) {
290 if (!IsInAddressInfoList (
291 &SpdSel2
->RemoteAddress
[Index
],
292 SpdSel1
->LocalAddress
,
293 SpdSel1
->LocalAddressCount
301 for (Index
= 0; Index
< SpdSel1
->LocalAddressCount
; Index
++) {
302 if (!IsInAddressInfoList (
303 &SpdSel1
->LocalAddress
[Index
],
304 SpdSel2
->RemoteAddress
,
305 SpdSel2
->RemoteAddressCount
313 for (Index
= 0; Index
< SpdSel2
->LocalAddressCount
; Index
++) {
314 if (!IsInAddressInfoList (
315 &SpdSel2
->LocalAddress
[Index
],
316 SpdSel1
->RemoteAddress
,
317 SpdSel1
->RemoteAddressCount
328 Find if the two SPD Selectors has subordinative.
330 Compare two SPD Selector by the fields of LocalAddressCount/RemoteAddressCount/
331 NextLayerProtocol/LocalPort/LocalPortRange/RemotePort/RemotePortRange and the
332 Local Addresses and remote Addresses.
334 @param[in] Selector1 Pointer of first SPD Selector.
335 @param[in] Selector2 Pointer of second SPD Selector.
337 @retval TRUE The first SPD Selector is subordinate Selector of second SPD Selector.
338 @retval FALSE The first SPD Selector is not subordinate Selector of second
344 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector1
,
345 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector2
348 EFI_IPSEC_SPD_SELECTOR
*SpdSel1
;
349 EFI_IPSEC_SPD_SELECTOR
*SpdSel2
;
353 SpdSel1
= &Selector1
->SpdSelector
;
354 SpdSel2
= &Selector2
->SpdSelector
;
358 // Compare the LocalAddressCount/RemoteAddressCount/NextLayerProtocol/
359 // LocalPort/LocalPortRange/RemotePort/RemotePortRange fields in the
360 // two Spdselectors. Since the SPD supports two directions, it needs to
361 // compare two directions.
363 if (SpdSel1
->LocalAddressCount
> SpdSel2
->LocalAddressCount
||
364 SpdSel1
->RemoteAddressCount
> SpdSel2
->RemoteAddressCount
||
365 (SpdSel1
->NextLayerProtocol
!= SpdSel2
->NextLayerProtocol
&& SpdSel2
->NextLayerProtocol
!= 0xffff) ||
366 (SpdSel1
->LocalPort
> SpdSel2
->LocalPort
&& SpdSel2
->LocalPort
!= 0)||
367 (SpdSel1
->LocalPortRange
> SpdSel2
->LocalPortRange
&& SpdSel1
->LocalPort
!= 0)||
368 (SpdSel1
->RemotePort
> SpdSel2
->RemotePort
&& SpdSel2
->RemotePort
!= 0) ||
369 (SpdSel1
->RemotePortRange
> SpdSel2
->RemotePortRange
&& SpdSel2
->RemotePort
!= 0)
375 // Compare the all LocalAddress fields in the two Spdselectors.
376 // First, SpdSel1->LocalAddress to SpdSel2->LocalAddress && Compare
377 // SpdSel1->RemoteAddress to SpdSel2->RemoteAddress. If all match, return
381 for (Index
= 0; Index
< SpdSel1
->LocalAddressCount
; Index
++) {
382 if (!IsInAddressInfoList (
383 &SpdSel1
->LocalAddress
[Index
],
384 SpdSel2
->LocalAddress
,
385 SpdSel2
->LocalAddressCount
393 for (Index
= 0; Index
< SpdSel1
->RemoteAddressCount
; Index
++) {
394 if (!IsInAddressInfoList (
395 &SpdSel1
->RemoteAddress
[Index
],
396 SpdSel2
->RemoteAddress
,
397 SpdSel2
->RemoteAddressCount
411 // The SPD selector in SPD entry is two way.
413 // Compare the LocalAddressCount/RemoteAddressCount/NextLayerProtocol/
414 // LocalPort/LocalPortRange/RemotePort/RemotePortRange fields in the
415 // two Spdselectors. Since the SPD supports two directions, it needs to
416 // compare two directions.
419 if (SpdSel1
->LocalAddressCount
> SpdSel2
->RemoteAddressCount
||
420 SpdSel1
->RemoteAddressCount
> SpdSel2
->LocalAddressCount
||
421 (SpdSel1
->NextLayerProtocol
!= SpdSel2
->NextLayerProtocol
&& SpdSel2
->NextLayerProtocol
!= 0xffff) ||
422 (SpdSel1
->LocalPort
> SpdSel2
->RemotePort
&& SpdSel2
->RemotePort
!= 0)||
423 (SpdSel1
->LocalPortRange
> SpdSel2
->RemotePortRange
&& SpdSel1
->RemotePort
!= 0)||
424 (SpdSel1
->RemotePort
> SpdSel2
->LocalPort
&& SpdSel2
->LocalPort
!= 0) ||
425 (SpdSel1
->RemotePortRange
> SpdSel2
->LocalPortRange
&& SpdSel2
->LocalPort
!= 0)
432 // Compare the all LocalAddress fields in the two Spdselectors.
433 // First, SpdSel1->LocalAddress to SpdSel2->LocalAddress && Compare
434 // SpdSel1->RemoteAddress to SpdSel2->RemoteAddress. If all match, return
437 for (Index
= 0; Index
< SpdSel1
->LocalAddressCount
; Index
++) {
438 if (!IsInAddressInfoList (
439 &SpdSel1
->LocalAddress
[Index
],
440 SpdSel2
->RemoteAddress
,
441 SpdSel2
->RemoteAddressCount
449 for (Index
= 0; Index
< SpdSel1
->RemoteAddressCount
; Index
++) {
450 if (!IsInAddressInfoList (
451 &SpdSel1
->RemoteAddress
[Index
],
452 SpdSel2
->LocalAddress
,
453 SpdSel2
->LocalAddressCount
467 @param[in] Selector1 Pointer of first SA ID.
468 @param[in] Selector2 Pointer of second SA ID.
470 @retval TRUE This two Selectors have the same SA ID.
471 @retval FALSE This two Selecotrs don't have the same SA ID.
476 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector1
,
477 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector2
480 EFI_IPSEC_SA_ID
*SaId1
;
481 EFI_IPSEC_SA_ID
*SaId2
;
484 SaId1
= &Selector1
->SaId
;
485 SaId2
= &Selector2
->SaId
;
488 if (CompareMem (SaId1
, SaId2
, sizeof (EFI_IPSEC_SA_ID
)) != 0) {
498 @param[in] Selector1 Pointer of first PAD ID.
499 @param[in] Selector2 Pointer of second PAD ID.
501 @retval TRUE This two Selectors have the same PAD ID.
502 @retval FALSE This two Selecotrs don't have the same PAD ID.
507 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector1
,
508 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector2
511 EFI_IPSEC_PAD_ID
*PadId1
;
512 EFI_IPSEC_PAD_ID
*PadId2
;
515 PadId1
= &Selector1
->PadId
;
516 PadId2
= &Selector2
->PadId
;
520 // Compare the PeerIdValid fields in PadId.
522 if (PadId1
->PeerIdValid
!= PadId2
->PeerIdValid
) {
526 // Compare the PeerId fields in PadId if PeerIdValid is true.
529 PadId1
->PeerIdValid
&&
530 AsciiStriCmp ((CONST CHAR8
*) PadId1
->Id
.PeerId
, (CONST CHAR8
*) PadId2
->Id
.PeerId
) != 0
535 // Compare the IpAddress fields in PadId if PeerIdValid is false.
538 !PadId1
->PeerIdValid
&&
539 (PadId1
->Id
.IpAddress
.PrefixLength
!= PadId2
->Id
.IpAddress
.PrefixLength
||
540 CompareMem (&PadId1
->Id
.IpAddress
.Address
, &PadId2
->Id
.IpAddress
.Address
, sizeof (EFI_IP_ADDRESS
)) != 0)
549 Check if the SPD Selector is Zero by its LocalAddressCount and RemoteAddressCount
552 @param[in] Selector Pointer of the SPD Selector.
554 @retval TRUE If the SPD Selector is Zero.
555 @retval FALSE If the SPD Selector is not Zero.
560 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
563 EFI_IPSEC_SPD_SELECTOR
*SpdSel
;
566 SpdSel
= &Selector
->SpdSelector
;
569 if (SpdSel
->LocalAddressCount
== 0 && SpdSel
->RemoteAddressCount
== 0) {
577 Check if the SA ID is Zero by its DestAddress.
579 @param[in] Selector Pointer of the SA ID.
581 @retval TRUE If the SA ID is Zero.
582 @retval FALSE If the SA ID is not Zero.
587 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
591 EFI_IPSEC_CONFIG_SELECTOR ZeroSelector
;
595 ZeroMem (&ZeroSelector
, sizeof (EFI_IPSEC_CONFIG_SELECTOR
));
597 if (CompareMem (&ZeroSelector
, Selector
, sizeof (EFI_IPSEC_CONFIG_SELECTOR
)) == 0) {
605 Check if the PAD ID is Zero.
607 @param[in] Selector Pointer of the PAD ID.
609 @retval TRUE If the PAD ID is Zero.
610 @retval FALSE If the PAD ID is not Zero.
615 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
618 EFI_IPSEC_PAD_ID
*PadId
;
619 EFI_IPSEC_PAD_ID ZeroId
;
622 PadId
= &Selector
->PadId
;
625 ZeroMem (&ZeroId
, sizeof (EFI_IPSEC_PAD_ID
));
627 if (CompareMem (PadId
, &ZeroId
, sizeof (EFI_IPSEC_PAD_ID
)) == 0) {
635 Copy Source SPD Selector to the Destination SPD Selector.
637 @param[in, out] DstSel Pointer of Destination SPD Selector.
638 @param[in] SrcSel Pointer of Source SPD Selector.
639 @param[in, out] Size The size of the Destination SPD Selector. If it
640 not NULL and its value less than the size of
641 Source SPD Selector, the value of Source SPD
642 Selector's size will be passed to caller by this
645 @retval EFI_INVALID_PARAMETER If the Destination or Source SPD Selector is NULL
646 @retval EFI_BUFFER_TOO_SMALL If the input Size is less than size of the Source SPD Selector.
647 @retval EFI_SUCCESS Copy Source SPD Selector to the Destination SPD
648 Selector successfully.
652 DuplicateSpdSelector (
653 IN OUT EFI_IPSEC_CONFIG_SELECTOR
*DstSel
,
654 IN EFI_IPSEC_CONFIG_SELECTOR
*SrcSel
,
658 EFI_IPSEC_SPD_SELECTOR
*Dst
;
659 EFI_IPSEC_SPD_SELECTOR
*Src
;
661 Dst
= &DstSel
->SpdSelector
;
662 Src
= &SrcSel
->SpdSelector
;
664 if (Dst
== NULL
|| Src
== NULL
) {
665 return EFI_INVALID_PARAMETER
;
668 if (Size
!= NULL
&& (*Size
) < SIZE_OF_SPD_SELECTOR (Src
)) {
669 *Size
= SIZE_OF_SPD_SELECTOR (Src
);
670 return EFI_BUFFER_TOO_SMALL
;
673 // Copy the base structure of SPD selector.
675 CopyMem (Dst
, Src
, sizeof (EFI_IPSEC_SPD_SELECTOR
));
678 // Copy the local address array of SPD selector.
680 Dst
->LocalAddress
= (EFI_IP_ADDRESS_INFO
*) (Dst
+ 1);
684 sizeof (EFI_IP_ADDRESS_INFO
) * Dst
->LocalAddressCount
688 // Copy the remote address array of SPD selector.
690 Dst
->RemoteAddress
= Dst
->LocalAddress
+ Dst
->LocalAddressCount
;
694 sizeof (EFI_IP_ADDRESS_INFO
) * Dst
->RemoteAddressCount
701 Copy Source SA ID to the Destination SA ID.
703 @param[in, out] DstSel Pointer of Destination SA ID.
704 @param[in] SrcSel Pointer of Source SA ID.
705 @param[in, out] Size The size of the Destination SA ID. If it
706 not NULL and its value less than the size of
707 Source SA ID, the value of Source SA ID's size
708 will be passed to caller by this parameter.
710 @retval EFI_INVALID_PARAMETER If the Destination or Source SA ID is NULL.
711 @retval EFI_BUFFER_TOO_SMALL If the input Size less than size of source SA ID.
712 @retval EFI_SUCCESS Copy Source SA ID to the Destination SA ID successfully.
717 IN OUT EFI_IPSEC_CONFIG_SELECTOR
*DstSel
,
718 IN EFI_IPSEC_CONFIG_SELECTOR
*SrcSel
,
722 EFI_IPSEC_SA_ID
*Dst
;
723 EFI_IPSEC_SA_ID
*Src
;
728 if (Dst
== NULL
|| Src
== NULL
) {
729 return EFI_INVALID_PARAMETER
;
732 if (Size
!= NULL
&& *Size
< sizeof (EFI_IPSEC_SA_ID
)) {
733 *Size
= sizeof (EFI_IPSEC_SA_ID
);
734 return EFI_BUFFER_TOO_SMALL
;
737 CopyMem (Dst
, Src
, sizeof (EFI_IPSEC_SA_ID
));
743 Copy Source PAD ID to the Destination PAD ID.
745 @param[in, out] DstSel Pointer of Destination PAD ID.
746 @param[in] SrcSel Pointer of Source PAD ID.
747 @param[in, out] Size The size of the Destination PAD ID. If it
748 not NULL and its value less than the size of
749 Source PAD ID, the value of Source PAD ID's size
750 will be passed to caller by this parameter.
752 @retval EFI_INVALID_PARAMETER If the Destination or Source PAD ID is NULL.
753 @retval EFI_BUFFER_TOO_SMALL If the input Size less than size of source PAD ID .
754 @retval EFI_SUCCESS Copy Source PAD ID to the Destination PAD ID successfully.
759 IN OUT EFI_IPSEC_CONFIG_SELECTOR
*DstSel
,
760 IN EFI_IPSEC_CONFIG_SELECTOR
*SrcSel
,
764 EFI_IPSEC_PAD_ID
*Dst
;
765 EFI_IPSEC_PAD_ID
*Src
;
767 Dst
= &DstSel
->PadId
;
768 Src
= &SrcSel
->PadId
;
770 if (Dst
== NULL
|| Src
== NULL
) {
771 return EFI_INVALID_PARAMETER
;
774 if (Size
!= NULL
&& *Size
< sizeof (EFI_IPSEC_PAD_ID
)) {
775 *Size
= sizeof (EFI_IPSEC_PAD_ID
);
776 return EFI_BUFFER_TOO_SMALL
;
779 CopyMem (Dst
, Src
, sizeof (EFI_IPSEC_PAD_ID
));
785 Fix the value of some members of SPD Selector.
787 This function is called by IpSecCopyPolicyEntry()which copy the Policy
788 Entry into the Variable. Since some members in SPD Selector are pointers,
789 a physical address to relative address convertion is required before copying
790 this SPD entry into the variable.
792 @param[in] Selector Pointer of SPD Selector.
793 @param[in, out] Data Pointer of SPD Data.
798 IN EFI_IPSEC_SPD_SELECTOR
*Selector
,
799 IN OUT EFI_IPSEC_SPD_DATA
*Data
803 // It assumes that all ref buffers in SPD selector and data are
804 // stored in the continous memory and close to the base structure.
806 FIX_REF_BUF_ADDR (Selector
->LocalAddress
, Selector
);
807 FIX_REF_BUF_ADDR (Selector
->RemoteAddress
, Selector
);
809 if (Data
->ProcessingPolicy
!= NULL
) {
810 if (Data
->ProcessingPolicy
->TunnelOption
!= NULL
) {
811 FIX_REF_BUF_ADDR (Data
->ProcessingPolicy
->TunnelOption
, Data
);
814 FIX_REF_BUF_ADDR (Data
->ProcessingPolicy
, Data
);
820 Fix the value of some members of SA ID.
822 This function is called by IpSecCopyPolicyEntry()which copy the Policy
823 Entry into the Variable. Since some members in SA ID are pointers,
824 a physical address to relative address conversion is required before copying
825 this SAD into the variable.
827 @param[in] SaId Pointer of SA ID
828 @param[in, out] Data Pointer of SA Data.
833 IN EFI_IPSEC_SA_ID
*SaId
,
834 IN OUT EFI_IPSEC_SA_DATA2
*Data
838 // It assumes that all ref buffers in SAD selector and data are
839 // stored in the continous memory and close to the base structure.
841 if (Data
->AlgoInfo
.EspAlgoInfo
.AuthKey
!= NULL
) {
842 FIX_REF_BUF_ADDR (Data
->AlgoInfo
.EspAlgoInfo
.AuthKey
, Data
);
845 if (SaId
->Proto
== EfiIPsecESP
&& Data
->AlgoInfo
.EspAlgoInfo
.EncKey
!= NULL
) {
846 FIX_REF_BUF_ADDR (Data
->AlgoInfo
.EspAlgoInfo
.EncKey
, Data
);
849 if (Data
->SpdSelector
!= NULL
) {
850 if (Data
->SpdSelector
->LocalAddress
!= NULL
) {
851 FIX_REF_BUF_ADDR (Data
->SpdSelector
->LocalAddress
, Data
);
854 FIX_REF_BUF_ADDR (Data
->SpdSelector
->RemoteAddress
, Data
);
855 FIX_REF_BUF_ADDR (Data
->SpdSelector
, Data
);
861 Fix the value of some members of PAD ID.
863 This function is called by IpSecCopyPolicyEntry()which copy the Policy
864 Entry into the Variable. Since some members in PAD ID are pointers,
865 a physical address to relative address conversion is required before copying
866 this PAD into the variable.
868 @param[in] PadId Pointer of PAD ID.
869 @param[in, out] Data Pointer of PAD Data.
874 IN EFI_IPSEC_PAD_ID
*PadId
,
875 IN OUT EFI_IPSEC_PAD_DATA
*Data
879 // It assumes that all ref buffers in pad selector and data are
880 // stored in the continous memory and close to the base structure.
882 if (Data
->AuthData
!= NULL
) {
883 FIX_REF_BUF_ADDR (Data
->AuthData
, Data
);
886 if (Data
->RevocationData
!= NULL
) {
887 FIX_REF_BUF_ADDR (Data
->RevocationData
, Data
);
893 Recover the value of some members of SPD Selector.
895 This function is corresponding to FixSpdEntry(). It recovers the value of members
896 of SPD Selector that are fixed by FixSpdEntry().
898 @param[in, out] Selector Pointer of SPD Selector.
899 @param[in, out] Data Pointer of SPD Data.
904 IN OUT EFI_IPSEC_SPD_SELECTOR
*Selector
,
905 IN OUT EFI_IPSEC_SPD_DATA
*Data
909 // It assumes that all ref buffers in SPD selector and data are
910 // stored in the continous memory and close to the base structure.
912 UNFIX_REF_BUF_ADDR (Selector
->LocalAddress
, Selector
);
913 UNFIX_REF_BUF_ADDR (Selector
->RemoteAddress
, Selector
);
915 if (Data
->ProcessingPolicy
!= NULL
) {
916 UNFIX_REF_BUF_ADDR (Data
->ProcessingPolicy
, Data
);
917 if (Data
->ProcessingPolicy
->TunnelOption
!= NULL
) {
918 UNFIX_REF_BUF_ADDR (Data
->ProcessingPolicy
->TunnelOption
, Data
);
925 Recover the value of some members of SA ID.
927 This function is corresponding to FixSadEntry(). It recovers the value of members
928 of SAD ID that are fixed by FixSadEntry().
930 @param[in, out] SaId Pointer of SAD ID.
931 @param[in, out] Data Pointer of SAD Data.
936 IN OUT EFI_IPSEC_SA_ID
*SaId
,
937 IN OUT EFI_IPSEC_SA_DATA2
*Data
941 // It assumes that all ref buffers in SAD selector and data are
942 // stored in the continous memory and close to the base structure.
944 if (Data
->AlgoInfo
.EspAlgoInfo
.AuthKey
!= NULL
) {
945 UNFIX_REF_BUF_ADDR (Data
->AlgoInfo
.EspAlgoInfo
.AuthKey
, Data
);
948 if (SaId
->Proto
== EfiIPsecESP
&& Data
->AlgoInfo
.EspAlgoInfo
.EncKey
!= NULL
) {
949 UNFIX_REF_BUF_ADDR (Data
->AlgoInfo
.EspAlgoInfo
.EncKey
, Data
);
952 if (Data
->SpdSelector
!= NULL
) {
953 UNFIX_REF_BUF_ADDR (Data
->SpdSelector
, Data
);
954 if (Data
->SpdSelector
->LocalAddress
!= NULL
) {
955 UNFIX_REF_BUF_ADDR (Data
->SpdSelector
->LocalAddress
, Data
);
958 UNFIX_REF_BUF_ADDR (Data
->SpdSelector
->RemoteAddress
, Data
);
964 Recover the value of some members of PAD ID.
966 This function is corresponding to FixPadEntry(). It recovers the value of members
967 of PAD ID that are fixed by FixPadEntry().
969 @param[in] PadId Pointer of PAD ID.
970 @param[in, out] Data Pointer of PAD Data.
975 IN EFI_IPSEC_PAD_ID
*PadId
,
976 IN OUT EFI_IPSEC_PAD_DATA
*Data
980 // It assumes that all ref buffers in pad selector and data are
981 // stored in the continous memory and close to the base structure.
983 if (Data
->AuthData
!= NULL
) {
984 UNFIX_REF_BUF_ADDR (Data
->AuthData
, Data
);
987 if (Data
->RevocationData
!= NULL
) {
988 UNFIX_REF_BUF_ADDR (Data
->RevocationData
, Data
);
994 Set the security policy information for the EFI IPsec driver.
996 The IPsec configuration data has a unique selector/identifier separately to
997 identify a data entry.
999 @param[in] Selector Pointer to an entry selector on operated
1000 configuration data specified by DataType.
1001 A NULL Selector causes the entire specified-type
1002 configuration information to be flushed.
1003 @param[in] Data The data buffer to be set. The structure
1004 of the data buffer should be EFI_IPSEC_SPD_DATA.
1005 @param[in] Context Pointer to one entry selector that describes
1006 the expected position the new data entry will
1007 be added. If Context is NULL, the new entry will
1008 be appended the end of database.
1010 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1011 - Selector is not NULL and its LocalAddress
1012 is NULL or its RemoteAddress is NULL.
1013 - Data is not NULL and its Action is Protected
1014 and its plolicy is NULL.
1015 - Data is not NULL, its Action is not protected,
1016 and its policy is not NULL.
1017 - The Action of Data is Protected, its policy
1018 mode is Tunnel, and its tunnel option is NULL.
1019 - The Action of Data is protected and its policy
1020 mode is not Tunnel and it tunnel option is not NULL.
1021 @retval EFI_OUT_OF_RESOURCED The required system resource could not be allocated.
1022 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1027 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
1029 IN VOID
*Context OPTIONAL
1032 EFI_IPSEC_SPD_SELECTOR
*SpdSel
;
1033 EFI_IPSEC_SPD_DATA
*SpdData
;
1034 EFI_IPSEC_SPD_SELECTOR
*InsertBefore
;
1035 LIST_ENTRY
*SpdList
;
1036 LIST_ENTRY
*SadList
;
1038 LIST_ENTRY
*EntryInsertBefore
;
1041 LIST_ENTRY
*NextEntry
;
1042 IPSEC_SPD_ENTRY
*SpdEntry
;
1043 IPSEC_SAD_ENTRY
*SadEntry
;
1047 SpdSel
= (Selector
== NULL
) ? NULL
: &Selector
->SpdSelector
;
1048 SpdData
= (Data
== NULL
) ? NULL
: (EFI_IPSEC_SPD_DATA
*) Data
;
1049 InsertBefore
= (Context
== NULL
) ? NULL
: &((EFI_IPSEC_CONFIG_SELECTOR
*) Context
)->SpdSelector
;
1050 SpdList
= &mConfigData
[IPsecConfigDataTypeSpd
];
1052 if (SpdSel
!= NULL
) {
1053 if (SpdSel
->LocalAddress
== NULL
|| SpdSel
->RemoteAddress
== NULL
) {
1054 return EFI_INVALID_PARAMETER
;
1058 if (SpdData
!= NULL
) {
1059 if ((SpdData
->Action
== EfiIPsecActionProtect
&& SpdData
->ProcessingPolicy
== NULL
) ||
1060 (SpdData
->Action
!= EfiIPsecActionProtect
&& SpdData
->ProcessingPolicy
!= NULL
)
1062 return EFI_INVALID_PARAMETER
;
1065 if (SpdData
->Action
== EfiIPsecActionProtect
) {
1066 if ((SpdData
->ProcessingPolicy
->Mode
== EfiIPsecTunnel
&& SpdData
->ProcessingPolicy
->TunnelOption
== NULL
) ||
1067 (SpdData
->ProcessingPolicy
->Mode
!= EfiIPsecTunnel
&& SpdData
->ProcessingPolicy
->TunnelOption
!= NULL
)
1069 return EFI_INVALID_PARAMETER
;
1074 // The default behavior is to insert the node ahead of the header.
1076 EntryInsertBefore
= SpdList
;
1079 // Remove the existed SPD entry.
1081 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, SpdList
) {
1083 SpdEntry
= IPSEC_SPD_ENTRY_FROM_LIST (Entry
);
1085 if (SpdSel
== NULL
||
1086 CompareSpdSelector ((EFI_IPSEC_CONFIG_SELECTOR
*) SpdEntry
->Selector
, (EFI_IPSEC_CONFIG_SELECTOR
*) SpdSel
)
1089 // Record the existed entry position to keep the original order.
1091 EntryInsertBefore
= SpdEntry
->List
.ForwardLink
;
1092 RemoveEntryList (&SpdEntry
->List
);
1095 // Update the reverse ref of SAD entry in the SPD.sas list.
1097 SpdSas
= &SpdEntry
->Data
->Sas
;
1100 // TODO: Deleted the related SAs.
1102 NET_LIST_FOR_EACH (Entry2
, SpdSas
) {
1103 SadEntry
= IPSEC_SAD_ENTRY_FROM_SPD (Entry2
);
1104 SadEntry
->Data
->SpdEntry
= NULL
;
1108 // Free the existed SPD entry
1110 FreePool (SpdEntry
);
1114 // Return success here if only want to remove the SPD entry.
1116 if (SpdData
== NULL
|| SpdSel
== NULL
) {
1120 // Search the appointed entry position if InsertBefore is not NULL.
1122 if (InsertBefore
!= NULL
) {
1124 NET_LIST_FOR_EACH (Entry
, SpdList
) {
1125 SpdEntry
= IPSEC_SPD_ENTRY_FROM_LIST (Entry
);
1127 if (CompareSpdSelector (
1128 (EFI_IPSEC_CONFIG_SELECTOR
*) SpdEntry
->Selector
,
1129 (EFI_IPSEC_CONFIG_SELECTOR
*) InsertBefore
1131 EntryInsertBefore
= Entry
;
1138 // Do Padding for the different Arch.
1140 SpdEntrySize
= ALIGN_VARIABLE (sizeof (IPSEC_SPD_ENTRY
));
1141 SpdEntrySize
= ALIGN_VARIABLE (SpdEntrySize
+ (UINTN
)SIZE_OF_SPD_SELECTOR (SpdSel
));
1142 SpdEntrySize
+= IpSecGetSizeOfEfiSpdData (SpdData
);
1144 SpdEntry
= AllocateZeroPool (SpdEntrySize
);
1146 if (SpdEntry
== NULL
) {
1147 return EFI_OUT_OF_RESOURCES
;
1150 // Fix the address of Selector and Data buffer and copy them, which is
1151 // continous memory and close to the base structure of SPD entry.
1153 SpdEntry
->Selector
= (EFI_IPSEC_SPD_SELECTOR
*) ALIGN_POINTER ((SpdEntry
+ 1), sizeof (UINTN
));
1154 SpdEntry
->Data
= (IPSEC_SPD_DATA
*) ALIGN_POINTER (
1155 ((UINT8
*) SpdEntry
->Selector
+ SIZE_OF_SPD_SELECTOR (SpdSel
)),
1159 DuplicateSpdSelector (
1160 (EFI_IPSEC_CONFIG_SELECTOR
*) SpdEntry
->Selector
,
1161 (EFI_IPSEC_CONFIG_SELECTOR
*) SpdSel
,
1166 SpdEntry
->Data
->Name
,
1168 sizeof (SpdData
->Name
)
1170 SpdEntry
->Data
->PackageFlag
= SpdData
->PackageFlag
;
1171 SpdEntry
->Data
->Action
= SpdData
->Action
;
1174 // Fix the address of ProcessingPolicy and copy it if need, which is continous
1175 // memory and close to the base structure of SAD data.
1177 if (SpdData
->Action
!= EfiIPsecActionProtect
) {
1178 SpdEntry
->Data
->ProcessingPolicy
= NULL
;
1180 SpdEntry
->Data
->ProcessingPolicy
= (EFI_IPSEC_PROCESS_POLICY
*) ALIGN_POINTER (
1184 IpSecDuplicateProcessPolicy (SpdEntry
->Data
->ProcessingPolicy
, SpdData
->ProcessingPolicy
);
1187 // Update the sas list of the new SPD entry.
1189 InitializeListHead (&SpdEntry
->Data
->Sas
);
1191 SadList
= &mConfigData
[IPsecConfigDataTypeSad
];
1193 NET_LIST_FOR_EACH (Entry
, SadList
) {
1194 SadEntry
= IPSEC_SAD_ENTRY_FROM_LIST (Entry
);
1196 for (Index
= 0; Index
< SpdData
->SaIdCount
; Index
++) {
1199 (EFI_IPSEC_CONFIG_SELECTOR
*) &SpdData
->SaId
[Index
],
1200 (EFI_IPSEC_CONFIG_SELECTOR
*) SadEntry
->Id
1202 if (SadEntry
->Data
->SpdEntry
!= NULL
) {
1203 RemoveEntryList (&SadEntry
->BySpd
);
1205 InsertTailList (&SpdEntry
->Data
->Sas
, &SadEntry
->BySpd
);
1206 SadEntry
->Data
->SpdEntry
= SpdEntry
;
1207 DuplicateSpdSelector (
1208 (EFI_IPSEC_CONFIG_SELECTOR
*)SadEntry
->Data
->SpdSelector
,
1209 (EFI_IPSEC_CONFIG_SELECTOR
*)SpdEntry
->Selector
,
1216 // Insert the new SPD entry.
1218 InsertTailList (EntryInsertBefore
, &SpdEntry
->List
);
1224 Set the security association information for the EFI IPsec driver.
1226 The IPsec configuration data has a unique selector/identifier separately to
1227 identify a data entry.
1229 @param[in] Selector Pointer to an entry selector on operated
1230 configuration data specified by DataType.
1231 A NULL Selector causes the entire specified-type
1232 configuration information to be flushed.
1233 @param[in] Data The data buffer to be set. The structure
1234 of the data buffer should be EFI_IPSEC_SA_DATA.
1235 @param[in] Context Pointer to one entry selector which describes
1236 the expected position the new data entry will
1237 be added. If Context is NULL,the new entry will
1238 be appended the end of database.
1240 @retval EFI_OUT_OF_RESOURCED The required system resource could not be allocated.
1241 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1246 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
1248 IN VOID
*Context OPTIONAL
1251 IPSEC_SAD_ENTRY
*SadEntry
;
1252 IPSEC_SPD_ENTRY
*SpdEntry
;
1254 LIST_ENTRY
*NextEntry
;
1255 LIST_ENTRY
*SadList
;
1256 LIST_ENTRY
*SpdList
;
1257 EFI_IPSEC_SA_ID
*SaId
;
1258 EFI_IPSEC_SA_DATA2
*SaData
;
1259 EFI_IPSEC_SA_ID
*InsertBefore
;
1260 LIST_ENTRY
*EntryInsertBefore
;
1263 SaId
= (Selector
== NULL
) ? NULL
: &Selector
->SaId
;
1264 SaData
= (Data
== NULL
) ? NULL
: (EFI_IPSEC_SA_DATA2
*) Data
;
1265 InsertBefore
= (Context
== NULL
) ? NULL
: &((EFI_IPSEC_CONFIG_SELECTOR
*) Context
)->SaId
;
1266 SadList
= &mConfigData
[IPsecConfigDataTypeSad
];
1269 // The default behavior is to insert the node ahead of the header.
1271 EntryInsertBefore
= SadList
;
1274 // Remove the existed SAD entry.
1276 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, SadList
) {
1278 SadEntry
= IPSEC_SAD_ENTRY_FROM_LIST (Entry
);
1282 (EFI_IPSEC_CONFIG_SELECTOR
*) SadEntry
->Id
,
1283 (EFI_IPSEC_CONFIG_SELECTOR
*) SaId
1286 // Record the existed entry position to keep the original order.
1288 EntryInsertBefore
= SadEntry
->List
.ForwardLink
;
1291 // Update the related SAD.byspd field.
1293 if (SadEntry
->Data
->SpdEntry
!= NULL
) {
1294 RemoveEntryList (&SadEntry
->BySpd
);
1297 RemoveEntryList (&SadEntry
->List
);
1298 FreePool (SadEntry
);
1302 // Return success here if only want to remove the SAD entry
1304 if (SaData
== NULL
|| SaId
== NULL
) {
1308 // Search the appointed entry position if InsertBefore is not NULL.
1310 if (InsertBefore
!= NULL
) {
1312 NET_LIST_FOR_EACH (Entry
, SadList
) {
1313 SadEntry
= IPSEC_SAD_ENTRY_FROM_LIST (Entry
);
1316 (EFI_IPSEC_CONFIG_SELECTOR
*) SadEntry
->Id
,
1317 (EFI_IPSEC_CONFIG_SELECTOR
*) InsertBefore
1319 EntryInsertBefore
= Entry
;
1326 // Do Padding for different Arch.
1328 SadEntrySize
= ALIGN_VARIABLE (sizeof (IPSEC_SAD_ENTRY
));
1329 SadEntrySize
= ALIGN_VARIABLE (SadEntrySize
+ sizeof (EFI_IPSEC_SA_ID
));
1330 SadEntrySize
= ALIGN_VARIABLE (SadEntrySize
+ sizeof (IPSEC_SAD_DATA
));
1332 if (SaId
->Proto
== EfiIPsecAH
) {
1333 SadEntrySize
+= SaData
->AlgoInfo
.AhAlgoInfo
.AuthKeyLength
;
1335 SadEntrySize
= ALIGN_VARIABLE (SadEntrySize
+ SaData
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
);
1336 SadEntrySize
+= ALIGN_VARIABLE (SaData
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
);
1339 if (SaData
->SpdSelector
!= NULL
) {
1340 SadEntrySize
+= SadEntrySize
+ (UINTN
)SIZE_OF_SPD_SELECTOR (SaData
->SpdSelector
);
1342 SadEntry
= AllocateZeroPool (SadEntrySize
);
1344 if (SadEntry
== NULL
) {
1345 return EFI_OUT_OF_RESOURCES
;
1348 // Fix the address of Id and Data buffer and copy them, which is
1349 // continous memory and close to the base structure of SAD entry.
1351 SadEntry
->Id
= (EFI_IPSEC_SA_ID
*) ALIGN_POINTER ((SadEntry
+ 1), sizeof (UINTN
));
1352 SadEntry
->Data
= (IPSEC_SAD_DATA
*) ALIGN_POINTER ((SadEntry
->Id
+ 1), sizeof (UINTN
));
1354 CopyMem (SadEntry
->Id
, SaId
, sizeof (EFI_IPSEC_SA_ID
));
1356 SadEntry
->Data
->Mode
= SaData
->Mode
;
1357 SadEntry
->Data
->SequenceNumber
= SaData
->SNCount
;
1358 SadEntry
->Data
->AntiReplayWindowSize
= SaData
->AntiReplayWindows
;
1361 &SadEntry
->Data
->AntiReplayBitmap
,
1362 sizeof (SadEntry
->Data
->AntiReplayBitmap
)
1366 &SadEntry
->Data
->AlgoInfo
,
1367 sizeof (EFI_IPSEC_ALGO_INFO
)
1370 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthAlgoId
= SaData
->AlgoInfo
.EspAlgoInfo
.AuthAlgoId
;
1371 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
= SaData
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
;
1373 if (SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
!= 0) {
1374 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKey
= (VOID
*) ALIGN_POINTER ((SadEntry
->Data
+ 1), sizeof (UINTN
));
1376 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKey
,
1377 SaData
->AlgoInfo
.EspAlgoInfo
.AuthKey
,
1378 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
1382 if (SaId
->Proto
== EfiIPsecESP
) {
1383 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncAlgoId
= SaData
->AlgoInfo
.EspAlgoInfo
.EncAlgoId
;
1384 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
= SaData
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
;
1386 if (SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
!= 0) {
1387 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKey
= (VOID
*) ALIGN_POINTER (
1388 ((UINT8
*) (SadEntry
->Data
+ 1) +
1389 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
),
1393 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKey
,
1394 SaData
->AlgoInfo
.EspAlgoInfo
.EncKey
,
1395 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
1401 &SadEntry
->Data
->SaLifetime
,
1402 &SaData
->SaLifetime
,
1403 sizeof (EFI_IPSEC_SA_LIFETIME
)
1406 SadEntry
->Data
->PathMTU
= SaData
->PathMTU
;
1407 SadEntry
->Data
->SpdSelector
= NULL
;
1408 SadEntry
->Data
->ESNEnabled
= FALSE
;
1409 SadEntry
->Data
->ManualSet
= SaData
->ManualSet
;
1412 // Copy Tunnel Source/Destination Address
1414 if (SaData
->Mode
== EfiIPsecTunnel
) {
1416 &SadEntry
->Data
->TunnelDestAddress
,
1417 &SaData
->TunnelDestinationAddress
,
1418 sizeof (EFI_IP_ADDRESS
)
1421 &SadEntry
->Data
->TunnelSourceAddress
,
1422 &SaData
->TunnelSourceAddress
,
1423 sizeof (EFI_IP_ADDRESS
)
1427 // Update the spd.sas list of the spd entry specified by SAD selector
1429 SpdList
= &mConfigData
[IPsecConfigDataTypeSpd
];
1431 for (Entry
= SpdList
->ForwardLink
; Entry
!= SpdList
&& SaData
->SpdSelector
!= NULL
; Entry
= Entry
->ForwardLink
) {
1433 SpdEntry
= IPSEC_SPD_ENTRY_FROM_LIST (Entry
);
1434 if (IsSubSpdSelector (
1435 (EFI_IPSEC_CONFIG_SELECTOR
*) SaData
->SpdSelector
,
1436 (EFI_IPSEC_CONFIG_SELECTOR
*) SpdEntry
->Selector
1437 ) && SpdEntry
->Data
->Action
== EfiIPsecActionProtect
) {
1438 SadEntry
->Data
->SpdEntry
= SpdEntry
;
1439 SadEntry
->Data
->SpdSelector
= (EFI_IPSEC_SPD_SELECTOR
*)((UINT8
*)SadEntry
+
1441 (UINTN
)SIZE_OF_SPD_SELECTOR (SaData
->SpdSelector
)
1443 DuplicateSpdSelector (
1444 (EFI_IPSEC_CONFIG_SELECTOR
*) SadEntry
->Data
->SpdSelector
,
1445 (EFI_IPSEC_CONFIG_SELECTOR
*) SaData
->SpdSelector
,
1448 InsertTailList (&SpdEntry
->Data
->Sas
, &SadEntry
->BySpd
);
1452 // Insert the new SAD entry.
1454 InsertTailList (EntryInsertBefore
, &SadEntry
->List
);
1460 Set the peer authorization configuration information for the EFI IPsec driver.
1462 The IPsec configuration data has a unique selector/identifier separately to
1463 identify a data entry.
1465 @param[in] Selector Pointer to an entry selector on operated
1466 configuration data specified by DataType.
1467 A NULL Selector causes the entire specified-type
1468 configuration information to be flushed.
1469 @param[in] Data The data buffer to be set. The structure
1470 of the data buffer should be EFI_IPSEC_PAD_DATA.
1471 @param[in] Context Pointer to one entry selector that describes
1472 the expected position the new data entry will
1473 be added. If Context is NULL, the new entry will
1474 be appended the end of database.
1476 @retval EFI_OUT_OF_RESOURCES The required system resources could not be allocated.
1477 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1482 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
1484 IN VOID
*Context OPTIONAL
1487 IPSEC_PAD_ENTRY
*PadEntry
;
1488 EFI_IPSEC_PAD_ID
*PadId
;
1489 EFI_IPSEC_PAD_DATA
*PadData
;
1490 LIST_ENTRY
*PadList
;
1492 LIST_ENTRY
*NextEntry
;
1493 EFI_IPSEC_PAD_ID
*InsertBefore
;
1494 LIST_ENTRY
*EntryInsertBefore
;
1497 PadId
= (Selector
== NULL
) ? NULL
: &Selector
->PadId
;
1498 PadData
= (Data
== NULL
) ? NULL
: (EFI_IPSEC_PAD_DATA
*) Data
;
1499 InsertBefore
= (Context
== NULL
) ? NULL
: &((EFI_IPSEC_CONFIG_SELECTOR
*) Context
)->PadId
;
1500 PadList
= &mConfigData
[IPsecConfigDataTypePad
];
1503 // The default behavior is to insert the node ahead of the header.
1505 EntryInsertBefore
= PadList
;
1508 // Remove the existed pad entry.
1510 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, PadList
) {
1512 PadEntry
= IPSEC_PAD_ENTRY_FROM_LIST (Entry
);
1514 if (PadId
== NULL
||
1515 ComparePadId ((EFI_IPSEC_CONFIG_SELECTOR
*) PadEntry
->Id
, (EFI_IPSEC_CONFIG_SELECTOR
*) PadId
)
1518 // Record the existed entry position to keep the original order.
1520 EntryInsertBefore
= PadEntry
->List
.ForwardLink
;
1521 RemoveEntryList (&PadEntry
->List
);
1523 FreePool (PadEntry
);
1527 // Return success here if only want to remove the pad entry
1529 if (PadData
== NULL
|| PadId
== NULL
) {
1533 // Search the appointed entry position if InsertBefore is not NULL.
1535 if (InsertBefore
!= NULL
) {
1537 NET_LIST_FOR_EACH (Entry
, PadList
) {
1538 PadEntry
= IPSEC_PAD_ENTRY_FROM_LIST (Entry
);
1541 (EFI_IPSEC_CONFIG_SELECTOR
*) PadEntry
->Id
,
1542 (EFI_IPSEC_CONFIG_SELECTOR
*) InsertBefore
1544 EntryInsertBefore
= Entry
;
1551 // Do PADDING for different arch.
1553 PadEntrySize
= ALIGN_VARIABLE (sizeof (IPSEC_PAD_ENTRY
));
1554 PadEntrySize
= ALIGN_VARIABLE (PadEntrySize
+ sizeof (EFI_IPSEC_PAD_ID
));
1555 PadEntrySize
= ALIGN_VARIABLE (PadEntrySize
+ sizeof (EFI_IPSEC_PAD_DATA
));
1556 PadEntrySize
= ALIGN_VARIABLE (PadEntrySize
+ (PadData
->AuthData
!= NULL
? PadData
->AuthDataSize
: 0));
1557 PadEntrySize
+= PadData
->RevocationData
!= NULL
? PadData
->RevocationDataSize
: 0;
1559 PadEntry
= AllocateZeroPool (PadEntrySize
);
1561 if (PadEntry
== NULL
) {
1562 return EFI_OUT_OF_RESOURCES
;
1565 // Fix the address of Id and Data buffer and copy them, which is
1566 // continous memory and close to the base structure of pad entry.
1568 PadEntry
->Id
= (EFI_IPSEC_PAD_ID
*) ALIGN_POINTER ((PadEntry
+ 1), sizeof (UINTN
));
1569 PadEntry
->Data
= (EFI_IPSEC_PAD_DATA
*) ALIGN_POINTER ((PadEntry
->Id
+ 1), sizeof (UINTN
));
1571 CopyMem (PadEntry
->Id
, PadId
, sizeof (EFI_IPSEC_PAD_ID
));
1573 PadEntry
->Data
->AuthProtocol
= PadData
->AuthProtocol
;
1574 PadEntry
->Data
->AuthMethod
= PadData
->AuthMethod
;
1575 PadEntry
->Data
->IkeIdFlag
= PadData
->IkeIdFlag
;
1577 if (PadData
->AuthData
!= NULL
) {
1578 PadEntry
->Data
->AuthDataSize
= PadData
->AuthDataSize
;
1579 PadEntry
->Data
->AuthData
= (VOID
*) ALIGN_POINTER (PadEntry
->Data
+ 1, sizeof (UINTN
));
1581 PadEntry
->Data
->AuthData
,
1583 PadData
->AuthDataSize
1586 PadEntry
->Data
->AuthDataSize
= 0;
1587 PadEntry
->Data
->AuthData
= NULL
;
1590 if (PadData
->RevocationData
!= NULL
) {
1591 PadEntry
->Data
->RevocationDataSize
= PadData
->RevocationDataSize
;
1592 PadEntry
->Data
->RevocationData
= (VOID
*) ALIGN_POINTER (
1593 ((UINT8
*) (PadEntry
->Data
+ 1) + PadData
->AuthDataSize
),
1597 PadEntry
->Data
->RevocationData
,
1598 PadData
->RevocationData
,
1599 PadData
->RevocationDataSize
1602 PadEntry
->Data
->RevocationDataSize
= 0;
1603 PadEntry
->Data
->RevocationData
= NULL
;
1606 // Insert the new pad entry.
1608 InsertTailList (EntryInsertBefore
, &PadEntry
->List
);
1614 This function lookup the data entry from IPsec SPD. Return the configuration
1615 value of the specified SPD Entry.
1617 @param[in] Selector Pointer to an entry selector which is an identifier
1619 @param[in, out] DataSize On output the size of data returned in Data.
1620 @param[out] Data The buffer to return the contents of the IPsec
1621 configuration data. The type of the data buffer
1622 is associated with the DataType.
1624 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1625 @retval EFI_INVALID_PARAMETER Data is NULL and *DataSize is not zero.
1626 @retval EFI_NOT_FOUND The configuration data specified by Selector is not found.
1627 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has been
1628 updated with the size needed to complete the request.
1633 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
1634 IN OUT UINTN
*DataSize
,
1638 IPSEC_SPD_ENTRY
*SpdEntry
;
1639 IPSEC_SAD_ENTRY
*SadEntry
;
1640 EFI_IPSEC_SPD_SELECTOR
*SpdSel
;
1641 EFI_IPSEC_SPD_DATA
*SpdData
;
1642 LIST_ENTRY
*SpdList
;
1647 SpdSel
= &Selector
->SpdSelector
;
1648 SpdData
= (EFI_IPSEC_SPD_DATA
*) Data
;
1649 SpdList
= &mConfigData
[IPsecConfigDataTypeSpd
];
1651 NET_LIST_FOR_EACH (Entry
, SpdList
) {
1652 SpdEntry
= IPSEC_SPD_ENTRY_FROM_LIST (Entry
);
1655 // Find the required SPD entry
1657 if (CompareSpdSelector (
1658 (EFI_IPSEC_CONFIG_SELECTOR
*) SpdSel
,
1659 (EFI_IPSEC_CONFIG_SELECTOR
*) SpdEntry
->Selector
1662 RequiredSize
= IpSecGetSizeOfSpdData (SpdEntry
->Data
);
1663 if (*DataSize
< RequiredSize
) {
1664 *DataSize
= RequiredSize
;
1665 return EFI_BUFFER_TOO_SMALL
;
1668 if (SpdData
== NULL
) {
1669 return EFI_INVALID_PARAMETER
;
1672 *DataSize
= RequiredSize
;
1675 // Extract and fill all SaId array from the SPD.sas list
1677 SpdSas
= &SpdEntry
->Data
->Sas
;
1678 SpdData
->SaIdCount
= 0;
1680 NET_LIST_FOR_EACH (Entry
, SpdSas
) {
1681 SadEntry
= IPSEC_SAD_ENTRY_FROM_SPD (Entry
);
1683 &SpdData
->SaId
[SpdData
->SaIdCount
++],
1685 sizeof (EFI_IPSEC_SA_ID
)
1689 // Fill the other fields in SPD data.
1691 CopyMem (SpdData
->Name
, SpdEntry
->Data
->Name
, sizeof (SpdData
->Name
));
1693 SpdData
->PackageFlag
= SpdEntry
->Data
->PackageFlag
;
1694 SpdData
->Action
= SpdEntry
->Data
->Action
;
1696 if (SpdData
->Action
!= EfiIPsecActionProtect
) {
1697 SpdData
->ProcessingPolicy
= NULL
;
1699 SpdData
->ProcessingPolicy
= (EFI_IPSEC_PROCESS_POLICY
*) ((UINT8
*) SpdData
+ sizeof (EFI_IPSEC_SPD_DATA
) + (SpdData
->SaIdCount
- 1) * sizeof (EFI_IPSEC_SA_ID
));
1701 IpSecDuplicateProcessPolicy (
1702 SpdData
->ProcessingPolicy
,
1703 SpdEntry
->Data
->ProcessingPolicy
1711 return EFI_NOT_FOUND
;
1715 This function lookup the data entry from IPsec SAD. Return the configuration
1716 value of the specified SAD Entry.
1718 @param[in] Selector Pointer to an entry selector which is an identifier
1720 @param[in, out] DataSize On output, the size of data returned in Data.
1721 @param[out] Data The buffer to return the contents of the IPsec
1722 configuration data. The type of the data buffer
1723 is associated with the DataType.
1725 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1726 @retval EFI_NOT_FOUND The configuration data specified by Selector is not found.
1727 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has been
1728 updated with the size needed to complete the request.
1733 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
1734 IN OUT UINTN
*DataSize
,
1738 IPSEC_SAD_ENTRY
*SadEntry
;
1740 LIST_ENTRY
*SadList
;
1741 EFI_IPSEC_SA_ID
*SaId
;
1742 EFI_IPSEC_SA_DATA2
*SaData
;
1745 SaId
= &Selector
->SaId
;
1746 SaData
= (EFI_IPSEC_SA_DATA2
*) Data
;
1747 SadList
= &mConfigData
[IPsecConfigDataTypeSad
];
1749 NET_LIST_FOR_EACH (Entry
, SadList
) {
1750 SadEntry
= IPSEC_SAD_ENTRY_FROM_LIST (Entry
);
1753 // Find the required SAD entry.
1756 (EFI_IPSEC_CONFIG_SELECTOR
*) SaId
,
1757 (EFI_IPSEC_CONFIG_SELECTOR
*) SadEntry
->Id
1760 // Calculate the required size of the SAD entry.
1761 // Data Layout is follows:
1762 // |EFI_IPSEC_SA_DATA
1764 // |EncryptKey (Optional)
1765 // |SpdSelector (Optional)
1767 RequiredSize
= ALIGN_VARIABLE (sizeof (EFI_IPSEC_SA_DATA2
));
1769 if (SaId
->Proto
== EfiIPsecAH
) {
1770 RequiredSize
= ALIGN_VARIABLE (RequiredSize
+ SadEntry
->Data
->AlgoInfo
.AhAlgoInfo
.AuthKeyLength
);
1772 RequiredSize
= ALIGN_VARIABLE (RequiredSize
+ SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
);
1773 RequiredSize
= ALIGN_VARIABLE (RequiredSize
+ SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
);
1776 if (SadEntry
->Data
->SpdSelector
!= NULL
) {
1777 RequiredSize
+= SIZE_OF_SPD_SELECTOR (SadEntry
->Data
->SpdSelector
);
1780 if (*DataSize
< RequiredSize
) {
1781 *DataSize
= RequiredSize
;
1782 return EFI_BUFFER_TOO_SMALL
;
1786 // Fill the data fields of SAD entry.
1788 *DataSize
= RequiredSize
;
1789 SaData
->Mode
= SadEntry
->Data
->Mode
;
1790 SaData
->SNCount
= SadEntry
->Data
->SequenceNumber
;
1791 SaData
->AntiReplayWindows
= SadEntry
->Data
->AntiReplayWindowSize
;
1794 &SaData
->SaLifetime
,
1795 &SadEntry
->Data
->SaLifetime
,
1796 sizeof (EFI_IPSEC_SA_LIFETIME
)
1801 sizeof (EFI_IPSEC_ALGO_INFO
)
1804 if (SaId
->Proto
== EfiIPsecAH
) {
1806 // Copy AH alogrithm INFO to SaData
1808 SaData
->AlgoInfo
.AhAlgoInfo
.AuthAlgoId
= SadEntry
->Data
->AlgoInfo
.AhAlgoInfo
.AuthAlgoId
;
1809 SaData
->AlgoInfo
.AhAlgoInfo
.AuthKeyLength
= SadEntry
->Data
->AlgoInfo
.AhAlgoInfo
.AuthKeyLength
;
1810 if (SaData
->AlgoInfo
.AhAlgoInfo
.AuthKeyLength
!= 0) {
1811 SaData
->AlgoInfo
.AhAlgoInfo
.AuthKey
= (VOID
*) ALIGN_POINTER ((SaData
+ 1), sizeof (UINTN
));
1813 SaData
->AlgoInfo
.AhAlgoInfo
.AuthKey
,
1814 SadEntry
->Data
->AlgoInfo
.AhAlgoInfo
.AuthKey
,
1815 SaData
->AlgoInfo
.AhAlgoInfo
.AuthKeyLength
1818 } else if (SaId
->Proto
== EfiIPsecESP
) {
1820 // Copy ESP alogrithem INFO to SaData
1822 SaData
->AlgoInfo
.EspAlgoInfo
.AuthAlgoId
= SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthAlgoId
;
1823 SaData
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
= SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
;
1824 if (SaData
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
!= 0) {
1825 SaData
->AlgoInfo
.EspAlgoInfo
.AuthKey
= (VOID
*) ALIGN_POINTER ((SaData
+ 1), sizeof (UINTN
));
1827 SaData
->AlgoInfo
.EspAlgoInfo
.AuthKey
,
1828 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.AuthKey
,
1829 SaData
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
1833 SaData
->AlgoInfo
.EspAlgoInfo
.EncAlgoId
= SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncAlgoId
;
1834 SaData
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
= SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
;
1836 if (SaData
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
!= 0) {
1837 SaData
->AlgoInfo
.EspAlgoInfo
.EncKey
= (VOID
*) ALIGN_POINTER (
1838 ((UINT8
*) (SaData
+ 1) +
1839 SaData
->AlgoInfo
.EspAlgoInfo
.AuthKeyLength
),
1843 SaData
->AlgoInfo
.EspAlgoInfo
.EncKey
,
1844 SadEntry
->Data
->AlgoInfo
.EspAlgoInfo
.EncKey
,
1845 SaData
->AlgoInfo
.EspAlgoInfo
.EncKeyLength
1850 SaData
->PathMTU
= SadEntry
->Data
->PathMTU
;
1853 // Fill Tunnel Address if it is Tunnel Mode
1855 if (SadEntry
->Data
->Mode
== EfiIPsecTunnel
) {
1857 &SaData
->TunnelDestinationAddress
,
1858 &SadEntry
->Data
->TunnelDestAddress
,
1859 sizeof (EFI_IP_ADDRESS
)
1862 &SaData
->TunnelSourceAddress
,
1863 &SadEntry
->Data
->TunnelSourceAddress
,
1864 sizeof (EFI_IP_ADDRESS
)
1868 // Fill the spd selector field of SAD data
1870 if (SadEntry
->Data
->SpdSelector
!= NULL
) {
1872 SaData
->SpdSelector
= (EFI_IPSEC_SPD_SELECTOR
*) (
1875 SIZE_OF_SPD_SELECTOR (SadEntry
->Data
->SpdSelector
)
1878 DuplicateSpdSelector (
1879 (EFI_IPSEC_CONFIG_SELECTOR
*) SaData
->SpdSelector
,
1880 (EFI_IPSEC_CONFIG_SELECTOR
*) SadEntry
->Data
->SpdSelector
,
1886 SaData
->SpdSelector
= NULL
;
1889 SaData
->ManualSet
= SadEntry
->Data
->ManualSet
;
1895 return EFI_NOT_FOUND
;
1899 This function lookup the data entry from IPsec PAD. Return the configuration
1900 value of the specified PAD Entry.
1902 @param[in] Selector Pointer to an entry selector which is an identifier
1904 @param[in, out] DataSize On output the size of data returned in Data.
1905 @param[out] Data The buffer to return the contents of the IPsec
1906 configuration data. The type of the data buffer
1907 is associated with the DataType.
1909 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1910 @retval EFI_NOT_FOUND The configuration data specified by Selector is not found.
1911 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has been
1912 updated with the size needed to complete the request.
1917 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
1918 IN OUT UINTN
*DataSize
,
1922 IPSEC_PAD_ENTRY
*PadEntry
;
1923 LIST_ENTRY
*PadList
;
1925 EFI_IPSEC_PAD_ID
*PadId
;
1926 EFI_IPSEC_PAD_DATA
*PadData
;
1929 PadId
= &Selector
->PadId
;
1930 PadData
= (EFI_IPSEC_PAD_DATA
*) Data
;
1931 PadList
= &mConfigData
[IPsecConfigDataTypePad
];
1933 NET_LIST_FOR_EACH (Entry
, PadList
) {
1934 PadEntry
= IPSEC_PAD_ENTRY_FROM_LIST (Entry
);
1937 // Find the required pad entry.
1940 (EFI_IPSEC_CONFIG_SELECTOR
*) PadId
,
1941 (EFI_IPSEC_CONFIG_SELECTOR
*) PadEntry
->Id
1944 // Calculate the required size of the pad entry.
1946 RequiredSize
= ALIGN_VARIABLE (sizeof (EFI_IPSEC_PAD_DATA
));
1947 RequiredSize
= ALIGN_VARIABLE (RequiredSize
+ PadEntry
->Data
->AuthDataSize
);
1948 RequiredSize
+= PadEntry
->Data
->RevocationDataSize
;
1950 if (*DataSize
< RequiredSize
) {
1951 *DataSize
= RequiredSize
;
1952 return EFI_BUFFER_TOO_SMALL
;
1955 // Fill the data fields of pad entry
1957 *DataSize
= RequiredSize
;
1958 PadData
->AuthProtocol
= PadEntry
->Data
->AuthProtocol
;
1959 PadData
->AuthMethod
= PadEntry
->Data
->AuthMethod
;
1960 PadData
->IkeIdFlag
= PadEntry
->Data
->IkeIdFlag
;
1963 // Copy Authentication data.
1965 if (PadEntry
->Data
->AuthData
!= NULL
) {
1967 PadData
->AuthDataSize
= PadEntry
->Data
->AuthDataSize
;
1968 PadData
->AuthData
= (VOID
*) ALIGN_POINTER ((PadData
+ 1), sizeof (UINTN
));
1971 PadEntry
->Data
->AuthData
,
1972 PadData
->AuthDataSize
1976 PadData
->AuthDataSize
= 0;
1977 PadData
->AuthData
= NULL
;
1980 // Copy Revocation Data.
1982 if (PadEntry
->Data
->RevocationData
!= NULL
) {
1984 PadData
->RevocationDataSize
= PadEntry
->Data
->RevocationDataSize
;
1985 PadData
->RevocationData
= (VOID
*) ALIGN_POINTER (
1986 ((UINT8
*) (PadData
+ 1) + PadData
->AuthDataSize
),
1990 PadData
->RevocationData
,
1991 PadEntry
->Data
->RevocationData
,
1992 PadData
->RevocationDataSize
1996 PadData
->RevocationDataSize
= 0;
1997 PadData
->RevocationData
= NULL
;
2004 return EFI_NOT_FOUND
;
2008 Copy Source Process Policy to the Destination Process Policy.
2010 @param[in] Dst Pointer to the Source Process Policy.
2011 @param[in] Src Pointer to the Destination Process Policy.
2015 IpSecDuplicateProcessPolicy (
2016 IN EFI_IPSEC_PROCESS_POLICY
*Dst
,
2017 IN EFI_IPSEC_PROCESS_POLICY
*Src
2021 // Firstly copy the structure content itself.
2023 CopyMem (Dst
, Src
, sizeof (EFI_IPSEC_PROCESS_POLICY
));
2026 // Recursively copy the tunnel option if needed.
2028 if (Dst
->Mode
!= EfiIPsecTunnel
) {
2029 ASSERT (Dst
->TunnelOption
== NULL
);
2031 Dst
->TunnelOption
= (EFI_IPSEC_TUNNEL_OPTION
*) ALIGN_POINTER ((Dst
+ 1), sizeof (UINTN
));
2035 sizeof (EFI_IPSEC_TUNNEL_OPTION
)
2041 Calculate the a whole size of EFI_IPSEC_SPD_DATA, which includes the buffer size pointed
2042 to by the pointer members.
2044 @param[in] SpdData Pointer to a specified EFI_IPSEC_SPD_DATA.
2046 @return the whole size the specified EFI_IPSEC_SPD_DATA.
2050 IpSecGetSizeOfEfiSpdData (
2051 IN EFI_IPSEC_SPD_DATA
*SpdData
2056 Size
= ALIGN_VARIABLE (sizeof (IPSEC_SPD_DATA
));
2058 if (SpdData
->Action
== EfiIPsecActionProtect
) {
2059 Size
= ALIGN_VARIABLE (Size
+ sizeof (EFI_IPSEC_PROCESS_POLICY
));
2061 if (SpdData
->ProcessingPolicy
->Mode
== EfiIPsecTunnel
) {
2062 Size
= ALIGN_VARIABLE (Size
+ sizeof (EFI_IPSEC_TUNNEL_OPTION
));
2070 Calculate the a whole size of IPSEC_SPD_DATA which includes the buffer size pointed
2071 to by the pointer members and the buffer size used by the Sa List.
2073 @param[in] SpdData Pointer to the specified IPSEC_SPD_DATA.
2075 @return the whole size of IPSEC_SPD_DATA.
2079 IpSecGetSizeOfSpdData (
2080 IN IPSEC_SPD_DATA
*SpdData
2086 Size
= sizeof (EFI_IPSEC_SPD_DATA
) - sizeof (EFI_IPSEC_SA_ID
);
2088 if (SpdData
->Action
== EfiIPsecActionProtect
) {
2089 Size
+= sizeof (EFI_IPSEC_PROCESS_POLICY
);
2091 if (SpdData
->ProcessingPolicy
->Mode
== EfiIPsecTunnel
) {
2092 Size
+= sizeof (EFI_IPSEC_TUNNEL_OPTION
);
2096 NET_LIST_FOR_EACH (Link
, &SpdData
->Sas
) {
2097 Size
+= sizeof (EFI_IPSEC_SA_ID
);
2104 Get the IPsec Variable.
2106 Get the all variables which start with the string contained in VaraiableName.
2107 Since all IPsec related variable store in continual space, those kinds of
2108 variable can be searched by the EfiGetNextVariableName. Those variables also are
2109 returned in a continual buffer.
2111 @param[in] VariableName Pointer to a specified Variable Name.
2112 @param[in] VendorGuid Pointer to a specified Vendor Guid.
2113 @param[in] Attributes Point to memory location to return the attributes
2114 of variable. If the point is NULL, the parameter
2116 @param[in, out] DataSize As input, point to the maximum size of return
2117 Data-Buffer. As output, point to the actual
2118 size of the returned Data-Buffer.
2119 @param[in] Data Point to return Data-Buffer.
2121 @retval EFI_ABORTED If the Variable size which contained in the variable
2122 structure doesn't match the variable size obtained
2123 from the EFIGetVariable.
2124 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has
2125 been updated with the size needed to complete the request.
2126 @retval EFI_SUCCESS The function completed successfully.
2127 @retval others Other errors found during the variable getting.
2131 IN CHAR16
*VariableName
,
2132 IN EFI_GUID
*VendorGuid
,
2133 IN UINT32
*Attributes
, OPTIONAL
2134 IN OUT UINTN
*DataSize
,
2139 EFI_GUID VendorGuidI
;
2140 UINTN VariableNameLength
;
2141 CHAR16
*VariableNameI
;
2142 UINTN VariableNameISize
;
2143 UINTN VariableNameISizeNew
;
2144 UINTN VariableIndex
;
2145 UINTN VariableCount
;
2146 IP_SEC_VARIABLE_INFO IpSecVariableInfo
;
2150 // The variable name constructor is "VariableName + Info/0001/0002/... + NULL".
2151 // So the varialbe name is like "VariableNameInfo", "VariableName0001", ...
2152 // "VariableNameNULL".
2154 VariableNameLength
= StrLen (VariableName
);
2155 VariableNameISize
= (VariableNameLength
+ 5) * sizeof (CHAR16
);
2156 VariableNameI
= AllocateZeroPool (VariableNameISize
);
2157 ASSERT (VariableNameI
!= NULL
);
2160 // Construct the varible name of ipsecconfig meta data.
2162 UnicodeSPrint (VariableNameI
, VariableNameISize
, L
"%s%s", VariableName
, L
"Info");
2164 DataSizeI
= sizeof (IpSecVariableInfo
);
2166 Status
= gRT
->GetVariable (
2173 if (EFI_ERROR (Status
)) {
2177 if (*DataSize
< IpSecVariableInfo
.VariableSize
) {
2178 *DataSize
= IpSecVariableInfo
.VariableSize
;
2179 Status
= EFI_BUFFER_TOO_SMALL
;
2183 VariableCount
= IpSecVariableInfo
.VariableCount
;
2184 VariableNameI
[0] = L
'\0';
2186 while (VariableCount
!= 0) {
2188 // Get the variable name one by one in the variable database.
2190 VariableNameISizeNew
= VariableNameISize
;
2191 Status
= gRT
->GetNextVariableName (
2192 &VariableNameISizeNew
,
2196 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2197 VariableNameI
= ReallocatePool (
2199 VariableNameISizeNew
,
2202 if (VariableNameI
== NULL
) {
2203 Status
= EFI_OUT_OF_RESOURCES
;
2206 VariableNameISize
= VariableNameISizeNew
;
2208 Status
= gRT
->GetNextVariableName (
2209 &VariableNameISizeNew
,
2215 if (EFI_ERROR (Status
)) {
2219 // Check whether the current variable is the required "ipsecconfig".
2221 if (StrnCmp (VariableNameI
, VariableName
, VariableNameLength
) == 0 ||
2222 CompareGuid (VendorGuid
, &VendorGuidI
)
2225 // Parse the variable count of the current ipsecconfig data.
2227 VariableIndex
= StrDecimalToUintn (VariableNameI
+ VariableNameLength
);
2228 if (VariableIndex
!= 0 && VariableIndex
<= IpSecVariableInfo
.VariableCount
) {
2230 // Get the variable size of the current ipsecconfig data.
2233 Status
= gRT
->GetVariable (
2240 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
2242 // Validate the variable count and variable size.
2244 if (VariableIndex
!= IpSecVariableInfo
.VariableCount
) {
2246 // If the varaibe is not the last one, its size should be the max
2247 // size of the single variable.
2249 if (DataSizeI
!= IpSecVariableInfo
.SingleVariableSize
) {
2253 if (DataSizeI
!= IpSecVariableInfo
.VariableSize
% IpSecVariableInfo
.SingleVariableSize
) {
2258 // Get the variable data of the current ipsecconfig data and
2259 // store it into user buffer continously.
2261 Status
= gRT
->GetVariable (
2266 (UINT8
*) Data
+ (VariableIndex
- 1) * IpSecVariableInfo
.SingleVariableSize
2268 ASSERT_EFI_ERROR (Status
);
2274 // The VariableCount in "VariableNameInfo" varaible should have the correct
2275 // numbers of variables which name starts with VariableName.
2277 if (VariableCount
!= 0) {
2278 Status
= EFI_ABORTED
;
2282 if (VariableNameI
!= NULL
) {
2283 FreePool (VariableNameI
);
2289 Set the IPsec variables.
2291 Set all IPsec variables which start with the specified variable name. Those variables
2294 @param[in] VariableName The name of the vendor's variable. It is a
2295 Null-Terminated Unicode String.
2296 @param[in] VendorGuid Unify identifier for vendor.
2297 @param[in] Attributes Point to memory location to return the attributes of
2298 variable. If the point is NULL, the parameter would be ignored.
2299 @param[in] DataSize The size in bytes of Data-Buffer.
2300 @param[in] Data Points to the content of the variable.
2302 @retval EFI_SUCCESS The firmware successfully stored the variable and its data, as
2303 defined by the Attributes.
2304 @retval others Storing the variables failed.
2309 IN CHAR16
*VariableName
,
2310 IN EFI_GUID
*VendorGuid
,
2311 IN UINT32 Attributes
,
2317 CHAR16
*VariableNameI
;
2318 UINTN VariableNameSize
;
2319 UINTN VariableIndex
;
2320 IP_SEC_VARIABLE_INFO IpSecVariableInfo
;
2321 UINT64 MaximumVariableStorageSize
;
2322 UINT64 RemainingVariableStorageSize
;
2323 UINT64 MaximumVariableSize
;
2325 Status
= gRT
->QueryVariableInfo (
2327 &MaximumVariableStorageSize
,
2328 &RemainingVariableStorageSize
,
2329 &MaximumVariableSize
2331 if (EFI_ERROR (Status
)) {
2336 // "VariableName + Info/0001/0002/... + NULL"
2338 VariableNameSize
= (StrLen (VariableName
) + 5) * sizeof (CHAR16
);
2339 VariableNameI
= AllocateZeroPool (VariableNameSize
);
2341 if (VariableNameI
== NULL
) {
2342 Status
= EFI_OUT_OF_RESOURCES
;
2346 // Construct the variable of ipsecconfig general information. Like the total
2347 // numbers of the Ipsecconfig variables, the total size of all ipsecconfig variables.
2349 UnicodeSPrint (VariableNameI
, VariableNameSize
, L
"%s%s", VariableName
, L
"Info");
2350 MaximumVariableSize
-= VariableNameSize
;
2352 IpSecVariableInfo
.VariableCount
= (UINT32
) ((DataSize
+ (UINTN
) MaximumVariableSize
- 1) / (UINTN
) MaximumVariableSize
);
2353 IpSecVariableInfo
.VariableSize
= (UINT32
) DataSize
;
2354 IpSecVariableInfo
.SingleVariableSize
= (UINT32
) MaximumVariableSize
;
2357 // Set the variable of ipsecconfig general information.
2359 Status
= gRT
->SetVariable (
2363 sizeof (IpSecVariableInfo
),
2366 if (EFI_ERROR (Status
)) {
2367 DEBUG ((DEBUG_ERROR
, "Error set ipsecconfig meta data with %r\n", Status
));
2371 for (VariableIndex
= 0; VariableIndex
< IpSecVariableInfo
.VariableCount
; VariableIndex
++) {
2373 // Construct and set the variable of ipsecconfig data one by one.
2374 // The index of variable name begin from 0001, and the varaible name
2375 // likes "VariableName0001", "VaraiableName0002"....
2377 UnicodeSPrint (VariableNameI
, VariableNameSize
, L
"%s%04d", VariableName
, VariableIndex
+ 1);
2378 Status
= gRT
->SetVariable (
2382 (VariableIndex
== IpSecVariableInfo
.VariableCount
- 1) ?
2383 (DataSize
% (UINTN
) MaximumVariableSize
) :
2384 (UINTN
) MaximumVariableSize
,
2385 (UINT8
*) Data
+ VariableIndex
* (UINTN
) MaximumVariableSize
2388 if (EFI_ERROR (Status
)) {
2389 DEBUG ((DEBUG_ERROR
, "Error set ipsecconfig variable data with %r\n", Status
));
2395 if (VariableNameI
!= NULL
) {
2396 FreePool (VariableNameI
);
2403 Return the configuration value for the EFI IPsec driver.
2405 This function lookup the data entry from IPsec database or IKEv2 configuration
2406 information. The expected data type and unique identification are described in
2407 DataType and Selector parameters.
2409 @param[in] This Pointer to the EFI_IPSEC_CONFIG_PROTOCOL instance.
2410 @param[in] DataType The type of data to retrieve.
2411 @param[in] Selector Pointer to an entry selector that is an identifier of the IPsec
2412 configuration data entry.
2413 @param[in, out] DataSize On output the size of data returned in Data.
2414 @param[out] Data The buffer to return the contents of the IPsec configuration data.
2415 The type of the data buffer associated with the DataType.
2417 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
2418 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
2422 - Data is NULL and *DataSize is not zero
2423 @retval EFI_NOT_FOUND The configuration data specified by Selector is not found.
2424 @retval EFI_UNSUPPORTED The specified DataType is not supported.
2425 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has been
2426 updated with the size needed to complete the request.
2431 EfiIpSecConfigGetData (
2432 IN EFI_IPSEC_CONFIG_PROTOCOL
*This
,
2433 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType
,
2434 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
2435 IN OUT UINTN
*DataSize
,
2439 if (This
== NULL
|| Selector
== NULL
|| DataSize
== NULL
) {
2440 return EFI_INVALID_PARAMETER
;
2443 if (*DataSize
!= 0 && Data
== NULL
) {
2444 return EFI_INVALID_PARAMETER
;
2447 if (DataType
>= IPsecConfigDataTypeMaximum
) {
2448 return EFI_UNSUPPORTED
;
2451 return mGetPolicyEntry
[DataType
](Selector
, DataSize
, Data
);
2455 Set the security association, security policy and peer authorization configuration
2456 information for the EFI IPsec driver.
2458 This function is used to set the IPsec configuration information of type DataType for
2459 the EFI IPsec driver.
2460 The IPsec configuration data has a unique selector/identifier separately to identify
2461 a data entry. The selector structure depends on DataType's definition.
2462 Using SetData() with a Data of NULL causes the IPsec configuration data entry identified
2463 by DataType and Selector to be deleted.
2465 @param[in] This Pointer to the EFI_IPSEC_CONFIG_PROTOCOL instance.
2466 @param[in] DataType The type of data to be set.
2467 @param[in] Selector Pointer to an entry selector on operated configuration data
2468 specified by DataType. A NULL Selector causes the entire
2469 specified-type configuration information to be flushed.
2470 @param[in] Data The data buffer to be set. The structure of the data buffer is
2471 associated with the DataType.
2472 @param[in] InsertBefore Pointer to one entry selector which describes the expected
2473 position the new data entry will be added. If InsertBefore is NULL,
2474 the new entry will be appended to the end of the database.
2476 @retval EFI_SUCCESS The specified configuration entry data was set successfully.
2477 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
2479 @retval EFI_UNSUPPORTED The specified DataType is not supported.
2480 @retval EFI_OUT_OF_RESOURCED The required system resource could not be allocated.
2485 EfiIpSecConfigSetData (
2486 IN EFI_IPSEC_CONFIG_PROTOCOL
*This
,
2487 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType
,
2488 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
2490 IN EFI_IPSEC_CONFIG_SELECTOR
*InsertBefore OPTIONAL
2496 return EFI_INVALID_PARAMETER
;
2499 if (DataType
>= IPsecConfigDataTypeMaximum
) {
2500 return EFI_UNSUPPORTED
;
2503 Status
= mSetPolicyEntry
[DataType
](Selector
, Data
, InsertBefore
);
2505 if (!EFI_ERROR (Status
) && !mSetBySelf
) {
2507 // Save the updated config data into variable.
2516 Enumerates the current selector for IPsec configuration data entry.
2518 This function is called multiple times to retrieve the entry Selector in IPsec
2519 configuration database. On each call to GetNextSelector(), the next entry
2520 Selector are retrieved into the output interface.
2522 If the entire IPsec configuration database has been iterated, the error
2523 EFI_NOT_FOUND is returned.
2524 If the Selector buffer is too small for the next Selector copy, an
2525 EFI_BUFFER_TOO_SMALL error is returned, and SelectorSize is updated to reflect
2526 the size of buffer needed.
2528 On the initial call to GetNextSelector() to start the IPsec configuration database
2529 search, a pointer to the buffer with all zero value is passed in Selector. Calls
2530 to SetData() between calls to GetNextSelector may produce unpredictable results.
2532 @param[in] This Pointer to the EFI_IPSEC_CONFIG_PROTOCOL instance.
2533 @param[in] DataType The type of IPsec configuration data to retrieve.
2534 @param[in, out] SelectorSize The size of the Selector buffer.
2535 @param[in, out] Selector On input, supplies the pointer to last Selector that was
2536 returned by GetNextSelector().
2537 On output, returns one copy of the current entry Selector
2538 of a given DataType.
2540 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
2541 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
2543 - SelectorSize is NULL.
2545 @retval EFI_NOT_FOUND The next configuration data entry was not found.
2546 @retval EFI_UNSUPPORTED The specified DataType is not supported.
2547 @retval EFI_BUFFER_TOO_SMALL The SelectorSize is too small for the result. This parameter
2548 has been updated with the size needed to complete the search
2554 EfiIpSecConfigGetNextSelector (
2555 IN EFI_IPSEC_CONFIG_PROTOCOL
*This
,
2556 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType
,
2557 IN OUT UINTN
*SelectorSize
,
2558 IN OUT EFI_IPSEC_CONFIG_SELECTOR
*Selector
2562 IPSEC_COMMON_POLICY_ENTRY
*CommonEntry
;
2565 if (This
== NULL
|| Selector
== NULL
|| SelectorSize
== NULL
) {
2566 return EFI_INVALID_PARAMETER
;
2569 if (DataType
>= IPsecConfigDataTypeMaximum
) {
2570 return EFI_UNSUPPORTED
;
2575 NET_LIST_FOR_EACH (Link
, &mConfigData
[DataType
]) {
2576 CommonEntry
= BASE_CR (Link
, IPSEC_COMMON_POLICY_ENTRY
, List
);
2578 if (IsFound
|| (BOOLEAN
)(mIsZeroSelector
[DataType
](Selector
))) {
2580 // If found the appointed entry, then duplicate the next one and return,
2581 // or if the appointed entry is zero, then return the first one directly.
2583 return mDuplicateSelector
[DataType
](Selector
, CommonEntry
->Selector
, SelectorSize
);
2586 // Set the flag if find the appointed entry.
2588 IsFound
= mCompareSelector
[DataType
](Selector
, CommonEntry
->Selector
);
2592 return EFI_NOT_FOUND
;
2596 Register an event that is to be signaled whenever a configuration process on the
2597 specified IPsec configuration information is done.
2599 The register function is not surpport now and always returns EFI_UNSUPPORTED.
2601 @param[in] This Pointer to the EFI_IPSEC_CONFIG_PROTOCOL instance.
2602 @param[in] DataType The type of data to be registered the event for.
2603 @param[in] Event The event to be registered.
2605 @retval EFI_SUCCESS The event is registered successfully.
2606 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2607 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
2608 @retval EFI_UNSUPPORTED The notify registration is unsupported, or the specified
2609 DataType is not supported.
2614 EfiIpSecConfigRegisterNotify (
2615 IN EFI_IPSEC_CONFIG_PROTOCOL
*This
,
2616 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType
,
2620 return EFI_UNSUPPORTED
;
2624 Remove the specified event that was previously registered on the specified IPsec
2627 This function is not support now and alwasy return EFI_UNSUPPORTED.
2629 @param[in] This Pointer to the EFI_IPSEC_CONFIG_PROTOCOL instance.
2630 @param[in] DataType The configuration data type to remove the registered event for.
2631 @param[in] Event The event to be unregistered.
2633 @retval EFI_SUCCESS The event was removed successfully.
2634 @retval EFI_NOT_FOUND The Event specified by DataType could not be found in the
2636 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2637 @retval EFI_UNSUPPORTED The notify registration is unsupported, or the specified
2638 DataType is not supported.
2643 EfiIpSecConfigUnregisterNotify (
2644 IN EFI_IPSEC_CONFIG_PROTOCOL
*This
,
2645 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType
,
2649 return EFI_UNSUPPORTED
;
2653 Copy whole data in specified EFI_SIPEC_CONFIG_SELECTOR and the Data to a buffer.
2655 This function is a caller defined function, and it is called by the IpSecVisitConfigData().
2656 The orignal caller is IpSecConfigSave(), which calls the IpsecVisitConfigData() to
2657 copy all types of IPsec Config datas into one buffer and store this buffer into firmware in
2658 the form of several variables.
2660 @param[in] Type A specified IPSEC_CONFIG_DATA_TYPE.
2661 @param[in] Selector Points to a EFI_IPSEC_CONFIG_SELECTOR to be copied
2663 @param[in] Data Points to data to be copied to the buffer. The
2664 Data type is related to the Type.
2665 @param[in] SelectorSize The size of the Selector.
2666 @param[in] DataSize The size of the Data.
2667 @param[in, out] Buffer The buffer to store the Selector and Data.
2669 @retval EFI_SUCCESS Copy the Selector and Data to a buffer successfully.
2670 @retval EFI_OUT_OF_RESOURCES The required system resource could not be allocated.
2674 IpSecCopyPolicyEntry (
2675 IN EFI_IPSEC_CONFIG_DATA_TYPE Type
,
2676 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
2678 IN UINTN SelectorSize
,
2680 IN OUT IPSEC_VARIABLE_BUFFER
*Buffer
2683 IPSEC_VAR_ITEM_HEADER SelectorHeader
;
2684 IPSEC_VAR_ITEM_HEADER DataHeader
;
2688 if (Type
== IPsecConfigDataTypeSad
) {
2690 // Don't save automatically-generated SA entry into variable.
2692 if (((EFI_IPSEC_SA_DATA2
*) Data
)->ManualSet
== FALSE
) {
2697 // Increase the capacity size of the buffer if needed.
2699 EntrySize
= ALIGN_VARIABLE (sizeof (SelectorHeader
));
2700 EntrySize
= ALIGN_VARIABLE (EntrySize
+ SelectorSize
);
2701 EntrySize
= ALIGN_VARIABLE (EntrySize
+ sizeof (SelectorHeader
));
2702 EntrySize
= ALIGN_VARIABLE (EntrySize
+ DataSize
);
2704 //EntrySize = SelectorSize + DataSize + 2 * sizeof (SelectorHeader);
2705 if (Buffer
->Capacity
- Buffer
->Size
< EntrySize
) {
2707 // Calculate the required buffer
2709 Buffer
->Capacity
+= EntrySize
;
2710 TempPoint
= AllocatePool (Buffer
->Capacity
);
2712 if (TempPoint
== NULL
) {
2713 return EFI_OUT_OF_RESOURCES
;
2716 // Copy the old Buffer to new buffer and free the old one.
2718 CopyMem (TempPoint
, Buffer
->Ptr
, Buffer
->Size
);
2719 FreePool (Buffer
->Ptr
);
2721 Buffer
->Ptr
= TempPoint
;
2724 mFixPolicyEntry
[Type
](Selector
, Data
);
2727 // Fill the selector header and copy it into buffer.
2729 SelectorHeader
.Type
= (UINT8
) (Type
| IPSEC_VAR_ITEM_HEADER_LOGO_BIT
);
2730 SelectorHeader
.Size
= (UINT16
) SelectorSize
;
2733 Buffer
->Ptr
+ Buffer
->Size
,
2735 sizeof (SelectorHeader
)
2737 Buffer
->Size
= ALIGN_VARIABLE (Buffer
->Size
+ sizeof (SelectorHeader
));
2740 // Copy the selector into buffer.
2743 Buffer
->Ptr
+ Buffer
->Size
,
2747 Buffer
->Size
= ALIGN_VARIABLE (Buffer
->Size
+ SelectorSize
);
2750 // Fill the data header and copy it into buffer.
2752 DataHeader
.Type
= (UINT8
) Type
;
2753 DataHeader
.Size
= (UINT16
) DataSize
;
2756 Buffer
->Ptr
+ Buffer
->Size
,
2760 Buffer
->Size
= ALIGN_VARIABLE (Buffer
->Size
+ sizeof (DataHeader
));
2762 // Copy the data into buffer.
2765 Buffer
->Ptr
+ Buffer
->Size
,
2769 Buffer
->Size
= ALIGN_VARIABLE (Buffer
->Size
+ DataSize
);
2771 mUnfixPolicyEntry
[Type
](Selector
, Data
);
2777 Visit all IPsec Configurations of specified Type and call the caller defined
2780 @param[in] DataType The specified IPsec Config Data Type.
2781 @param[in] Routine The function defined by the caller.
2782 @param[in] Context The data passed to the Routine.
2784 @retval EFI_OUT_OF_RESOURCES The required system resource could not be allocated
2785 @retval EFI_SUCCESS This function completed successfully.
2789 IpSecVisitConfigData (
2790 IN EFI_IPSEC_CONFIG_DATA_TYPE DataType
,
2791 IN IPSEC_COPY_POLICY_ENTRY Routine
,
2795 EFI_STATUS GetNextStatus
;
2796 EFI_STATUS GetDataStatus
;
2797 EFI_STATUS RoutineStatus
;
2798 EFI_IPSEC_CONFIG_SELECTOR
*Selector
;
2802 UINTN SelectorBufferSize
;
2803 UINTN DataBufferSize
;
2804 BOOLEAN FirstGetNext
;
2806 FirstGetNext
= TRUE
;
2809 SelectorBufferSize
= sizeof (EFI_IPSEC_CONFIG_SELECTOR
);
2810 Selector
= AllocateZeroPool (SelectorBufferSize
);
2812 if (Selector
== NULL
) {
2813 return EFI_OUT_OF_RESOURCES
;
2818 // Get the real size of the selector.
2820 SelectorSize
= SelectorBufferSize
;
2821 GetNextStatus
= EfiIpSecConfigGetNextSelector (
2822 &mIpSecConfigInstance
,
2827 if (GetNextStatus
== EFI_BUFFER_TOO_SMALL
) {
2828 FreePool (Selector
);
2829 SelectorBufferSize
= SelectorSize
;
2831 // Allocate zero pool for the first selector, while store the last
2832 // selector content for the other selectors.
2835 Selector
= AllocateZeroPool (SelectorBufferSize
);
2837 Selector
= AllocateCopyPool (SelectorBufferSize
, Selector
);
2840 if (Selector
== NULL
) {
2841 return EFI_OUT_OF_RESOURCES
;
2844 // Get the content of the selector.
2846 GetNextStatus
= EfiIpSecConfigGetNextSelector (
2847 &mIpSecConfigInstance
,
2854 if (EFI_ERROR (GetNextStatus
)) {
2858 FirstGetNext
= FALSE
;
2861 // Get the real size of the policy entry according to the selector.
2863 DataSize
= DataBufferSize
;
2864 GetDataStatus
= EfiIpSecConfigGetData (
2865 &mIpSecConfigInstance
,
2871 if (GetDataStatus
== EFI_BUFFER_TOO_SMALL
) {
2876 DataBufferSize
= DataSize
;
2877 Data
= AllocateZeroPool (DataBufferSize
);
2880 return EFI_OUT_OF_RESOURCES
;
2883 // Get the content of the policy entry according to the selector.
2885 GetDataStatus
= EfiIpSecConfigGetData (
2886 &mIpSecConfigInstance
,
2894 if (EFI_ERROR (GetDataStatus
)) {
2898 // Prepare the buffer of updated policy entry, which is stored in
2899 // the continous memory, and then save into variable later.
2901 RoutineStatus
= Routine (
2909 if (EFI_ERROR (RoutineStatus
)) {
2918 if (Selector
!= NULL
) {
2919 FreePool (Selector
);
2926 This function is the subfunction of EFIIpSecConfigSetData.
2928 This function call IpSecSetVaraible to set the IPsec Configuration into the firmware.
2930 @retval EFI_OUT_OF_RESOURCES The required system resource could not be allocated.
2931 @retval EFI_SUCCESS Saved the configration successfully.
2932 @retval Others Other errors were found while obtaining the variable.
2940 IPSEC_VARIABLE_BUFFER Buffer
;
2942 EFI_IPSEC_CONFIG_DATA_TYPE Type
;
2945 Buffer
.Capacity
= IPSEC_DEFAULT_VARIABLE_SIZE
;
2946 Buffer
.Ptr
= AllocateZeroPool (Buffer
.Capacity
);
2948 if (Buffer
.Ptr
== NULL
) {
2949 return EFI_OUT_OF_RESOURCES
;
2952 // For each policy database, prepare the contious buffer to save into variable.
2954 for (Type
= IPsecConfigDataTypeSpd
; Type
< IPsecConfigDataTypeMaximum
; Type
++) {
2955 IpSecVisitConfigData (
2957 (IPSEC_COPY_POLICY_ENTRY
) IpSecCopyPolicyEntry
,
2962 // Save the updated policy database into variable.
2964 Status
= IpSecSetVariable (
2965 IPSECCONFIG_VARIABLE_NAME
,
2966 &gEfiIpSecConfigProtocolGuid
,
2967 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
2972 FreePool (Buffer
.Ptr
);
2978 Get the all IPSec configuration variables and store those variables
2979 to the internal data structure.
2981 This founction is called by IpSecConfigInitialize() which is to intialize the
2982 IPsecConfiguration Protocol.
2984 @param[in] Private Point to IPSEC_PRIVATE_DATA.
2986 @retval EFI_OUT_OF_RESOURCES The required system resource could not be allocated
2987 @retval EFI_SUCCESS Restore the IPsec Configuration successfully.
2988 @retval others Other errors is found while obtaining the variable.
2992 IpSecConfigRestore (
2993 IN IPSEC_PRIVATE_DATA
*Private
2999 IPSEC_VAR_ITEM_HEADER
*Header
;
3001 EFI_IPSEC_CONFIG_SELECTOR
*Selector
;
3002 EFI_IPSEC_CONFIG_DATA_TYPE Type
;
3008 Size
= sizeof (Value
);
3012 Status
= gRT
->GetVariable (
3013 IPSECCONFIG_STATUS_NAME
,
3014 &gEfiIpSecConfigProtocolGuid
,
3020 if (!EFI_ERROR (Status
) && Value
== IPSEC_STATUS_ENABLED
) {
3021 Private
->IpSec
.DisabledFlag
= FALSE
;
3024 // Get the real size of policy database in variable.
3026 Status
= IpSecGetVariable (
3027 IPSECCONFIG_VARIABLE_NAME
,
3028 &gEfiIpSecConfigProtocolGuid
,
3033 if (Status
== EFI_BUFFER_TOO_SMALL
) {
3035 Buffer
= AllocateZeroPool (BufferSize
);
3036 if (Buffer
== NULL
) {
3037 return EFI_OUT_OF_RESOURCES
;
3040 // Get the content of policy database in variable.
3042 Status
= IpSecGetVariable (
3043 IPSECCONFIG_VARIABLE_NAME
,
3044 &gEfiIpSecConfigProtocolGuid
,
3049 if (EFI_ERROR (Status
)) {
3054 for (Ptr
= Buffer
; Ptr
< Buffer
+ BufferSize
;) {
3056 Header
= (IPSEC_VAR_ITEM_HEADER
*) Ptr
;
3057 Type
= (EFI_IPSEC_CONFIG_DATA_TYPE
) (Header
->Type
& IPSEC_VAR_ITEM_HEADER_CONTENT_BIT
);
3058 ASSERT (((Header
->Type
& 0x80) == IPSEC_VAR_ITEM_HEADER_LOGO_BIT
) && (Type
< IPsecConfigDataTypeMaximum
));
3060 Selector
= (EFI_IPSEC_CONFIG_SELECTOR
*) ALIGN_POINTER (Header
+ 1, sizeof (UINTN
));
3061 Header
= (IPSEC_VAR_ITEM_HEADER
*) ALIGN_POINTER (
3062 (UINT8
*) Selector
+ Header
->Size
,
3065 ASSERT (Header
->Type
== Type
);
3067 Data
= ALIGN_POINTER (Header
+ 1, sizeof (UINTN
));
3069 mUnfixPolicyEntry
[Type
](Selector
, Data
);
3072 // Update each policy entry according to the content in variable.
3075 Status
= EfiIpSecConfigSetData (
3076 &Private
->IpSecConfig
,
3084 if (EFI_ERROR (Status
)) {
3089 Ptr
= ALIGN_POINTER ((UINT8
*) Data
+ Header
->Size
, sizeof (UINTN
));
3099 Install and Initialize IPsecConfig protocol
3101 @param[in, out] Private Pointer to IPSEC_PRIVATE_DATA. After this function finish,
3102 the pointer of IPsecConfig Protocol implementation will copy
3103 into its IPsecConfig member.
3105 @retval EFI_SUCCESS Initialized the IPsecConfig Protocol successfully.
3106 @retval Others Initializing the IPsecConfig Protocol failed.
3109 IpSecConfigInitialize (
3110 IN OUT IPSEC_PRIVATE_DATA
*Private
3113 EFI_IPSEC_CONFIG_DATA_TYPE Type
;
3116 &Private
->IpSecConfig
,
3117 &mIpSecConfigInstance
,
3118 sizeof (EFI_IPSEC_CONFIG_PROTOCOL
)
3122 // Initialize the list head of policy database.
3124 for (Type
= IPsecConfigDataTypeSpd
; Type
< IPsecConfigDataTypeMaximum
; Type
++) {
3125 InitializeListHead (&mConfigData
[Type
]);
3128 // Restore the content of policy database according to the variable.
3130 IpSecConfigRestore (Private
);
3132 return gBS
->InstallMultipleProtocolInterfaces (
3134 &gEfiIpSecConfigProtocolGuid
,
3135 &Private
->IpSecConfig
,