2 The operations for Child SA.
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Generate IKE Packet for CREATE_CHILD_SA exchange.
15 This IKE Packet would be the packet for creating new CHILD SA, or the packet for
16 rekeying existing IKE SA, or the packet for existing CHILD SA.
18 @param[in] SaSession Pointer to related SA session.
19 @param[in] Context The data passed by the caller.
21 return a pointer of IKE packet.
25 Ikev2CreateChildGenerator (
31 IKEV2_CHILD_SA_SESSION
*ChildSaSession
;
32 IKEV2_SA_SESSION
*IkeSaSession
;
33 IKE_PACKET
*IkePacket
;
34 IKE_PAYLOAD
*NotifyPayload
;
40 ChildSaSession
= (IKEV2_CHILD_SA_SESSION
*) SaSession
;
41 if (ChildSaSession
== NULL
) {
45 IkePacket
= IkePacketAlloc();
46 if (IkePacket
== NULL
) {
51 if (Context
!= NULL
) {
52 MessageId
= (UINT32
*) Context
;
55 IkePacket
->Header
->Version
= (UINT8
) (2 << 4);
56 IkePacket
->Header
->NextPayload
= IKEV2_PAYLOAD_TYPE_NOTIFY
;
57 IkePacket
->Header
->ExchangeType
= IKE_XCG_TYPE_CREATE_CHILD_SA
;
59 if (ChildSaSession
->SessionCommon
.IkeSessionType
== IkeSessionTypeChildSa
) {
61 // 1.a Fill the IkePacket->Hdr
63 IkePacket
->Header
->InitiatorCookie
= ChildSaSession
->IkeSaSession
->InitiatorCookie
;
64 IkePacket
->Header
->ResponderCookie
= ChildSaSession
->IkeSaSession
->ResponderCookie
;
66 if (MessageId
!= NULL
) {
67 IkePacket
->Header
->MessageId
= *MessageId
;
69 IkePacket
->Header
->MessageId
= ChildSaSession
->MessageId
;
72 if (ChildSaSession
->SessionCommon
.IsInitiator
) {
73 IkePacket
->Header
->Flags
= IKE_HEADER_FLAGS_INIT
;
77 IkeSaSession
= (IKEV2_SA_SESSION
*) SaSession
;
79 // 1.a Fill the IkePacket->Hdr
81 IkePacket
->Header
->InitiatorCookie
= IkeSaSession
->InitiatorCookie
;
82 IkePacket
->Header
->ResponderCookie
= IkeSaSession
->ResponderCookie
;
84 if (MessageId
!= NULL
) {
85 IkePacket
->Header
->MessageId
= *MessageId
;
87 IkePacket
->Header
->MessageId
= IkeSaSession
->MessageId
;
90 if (IkeSaSession
->SessionCommon
.IsInitiator
) {
91 IkePacket
->Header
->Flags
= IKE_HEADER_FLAGS_INIT
;
95 if (MessageId
!= NULL
) {
96 IkePacket
->Header
->Flags
|= IKE_HEADER_FLAGS_RESPOND
;
100 // According to RFC4306, Chapter 4.
101 // A minimal implementation may support the CREATE_CHILD_SA exchange only to
102 // recognize requests and reject them with a Notify payload of type NO_ADDITIONAL_SAS.
104 NotifyPayload
= Ikev2GenerateNotifyPayload (
106 IKEV2_PAYLOAD_TYPE_NONE
,
108 IKEV2_NOTIFICATION_NO_ADDITIONAL_SAS
,
113 if (NotifyPayload
== NULL
) {
114 IkePacketFree (IkePacket
);
118 IKE_PACKET_APPEND_PAYLOAD (IkePacket
, NotifyPayload
);
120 // TODO: Support the CREATE_CHILD_SA exchange.
126 Parse the IKE packet of CREATE_CHILD_SA exchange.
128 This function parse the IKE packet and save the related information to further
131 @param[in] SaSession Pointer to IKEv2_CHILD_SA_SESSION related to this Exchange.
132 @param[in] IkePacket Received packet to be parsed.
135 @retval EFI_SUCCESS The IKE Packet is acceptable.
136 @retval EFI_UNSUPPORTED Not support the CREATE_CHILD_SA request.
140 Ikev2CreateChildParser (
142 IN IKE_PACKET
*IkePacket
145 return EFI_UNSUPPORTED
;
149 Routine process before the payload decoding.
151 @param[in] SessionCommon Pointer to ChildSa SessionCommon.
152 @param[in] PayloadBuf Pointer to the payload.
153 @param[in] PayloadSize Size of PayloadBuf in byte.
154 @param[in] PayloadType Type of Payload.
158 Ikev2ChildSaBeforeDecodePayload (
159 IN UINT8
*SessionCommon
,
160 IN UINT8
*PayloadBuf
,
161 IN UINTN PayloadSize
,
169 Routine Process after the payload encoding.
171 @param[in] SessionCommon Pointer to ChildSa SessionCommon.
172 @param[in] PayloadBuf Pointer to the payload.
173 @param[in] PayloadSize Size of PayloadBuf in byte.
174 @param[in] PayloadType Type of Payload.
178 Ikev2ChildSaAfterEncodePayload (
179 IN UINT8
*SessionCommon
,
180 IN UINT8
*PayloadBuf
,
181 IN UINTN PayloadSize
,
187 IKEV2_PACKET_HANDLER mIkev2CreateChild
= {
191 Ikev2CreateChildParser
,
192 Ikev2CreateChildGenerator