1 /** @file
2 The operations for Child SA.
3
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5
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.
10
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.
13
14 **/
15
16 #include "Utility.h"
17
18 /**
19 Generate IKE Packet for CREATE_CHILD_SA exchange.
20
21 This IKE Packet would be the packet for creating new CHILD SA, or the packet for
22 rekeying existing IKE SA, or the packet for existing CHILD SA.
23
24 @param[in] SaSession Pointer to related SA session.
25 @param[in] Context The data passed by the caller.
26
27 return a pointer of IKE packet.
28
29 **/
30 IKE_PACKET *
Ikev2CreateChildGenerator(IN UINT8 * SaSession,IN VOID * Context)31 Ikev2CreateChildGenerator (
32 IN UINT8 *SaSession,
33 IN VOID *Context
34 )
35 {
36
37 IKEV2_CHILD_SA_SESSION *ChildSaSession;
38 IKEV2_SA_SESSION *IkeSaSession;
39 IKE_PACKET *IkePacket;
40 IKE_PAYLOAD *NotifyPayload;
41 UINT32 *MessageId;
42
43 ChildSaSession = (IKEV2_CHILD_SA_SESSION *) SaSession;
44 IkePacket = IkePacketAlloc();
45 MessageId = NULL;
46
47 if (IkePacket == NULL) {
48 return NULL;
49 }
50 if (ChildSaSession == NULL) {
51 return NULL;
52 }
53
54 if (Context != NULL) {
55 MessageId = (UINT32 *) Context;
56 }
57
58 IkePacket->Header->Version = (UINT8) (2 << 4);
59 IkePacket->Header->NextPayload = IKEV2_PAYLOAD_TYPE_NOTIFY;
60 IkePacket->Header->ExchangeType = IKE_XCG_TYPE_CREATE_CHILD_SA;
61
62 if (ChildSaSession->SessionCommon.IkeSessionType == IkeSessionTypeChildSa) {
63 //
64 // 1.a Fill the IkePacket->Hdr
65 //
66 IkePacket->Header->InitiatorCookie = ChildSaSession->IkeSaSession->InitiatorCookie;
67 IkePacket->Header->ResponderCookie = ChildSaSession->IkeSaSession->ResponderCookie;
68
69 if (MessageId != NULL) {
70 IkePacket->Header->MessageId = *MessageId;
71 } else {
72 IkePacket->Header->MessageId = ChildSaSession->MessageId;
73 }
74
75 if (ChildSaSession->SessionCommon.IsInitiator) {
76 IkePacket->Header->Flags = IKE_HEADER_FLAGS_CHILD_INIT;
77 } else {
78 IkePacket->Header->Flags = IKE_HEADER_FLAGS_RESPOND;
79 }
80
81 } else {
82 IkeSaSession = (IKEV2_SA_SESSION *) SaSession;
83 //
84 // 1.a Fill the IkePacket->Hdr
85 //
86 IkePacket->Header->InitiatorCookie = IkeSaSession->InitiatorCookie;
87 IkePacket->Header->ResponderCookie = IkeSaSession->ResponderCookie;
88
89 if (MessageId != NULL) {
90 IkePacket->Header->MessageId = *MessageId;
91 } else {
92 IkePacket->Header->MessageId = IkeSaSession->MessageId;
93 }
94
95 if (IkeSaSession->SessionCommon.IsInitiator) {
96 IkePacket->Header->Flags = IKE_HEADER_FLAGS_CHILD_INIT;
97 } else {
98 IkePacket->Header->Flags = IKE_HEADER_FLAGS_RESPOND;
99 }
100 }
101
102 //
103 // According to RFC4306, Chapter 4.
104 // A minimal implementation may support the CREATE_CHILD_SA exchange only to
105 // recognize requests and reject them with a Notify payload of type NO_ADDITIONAL_SAS.
106 //
107 NotifyPayload = Ikev2GenerateNotifyPayload (
108 0,
109 IKEV2_PAYLOAD_TYPE_NONE,
110 0,
111 IKEV2_NOTIFICATION_NO_ADDITIONAL_SAS,
112 NULL,
113 NULL,
114 0
115 );
116
117 IKE_PACKET_APPEND_PAYLOAD (IkePacket, NotifyPayload);
118 //
119 // TODO: Support the CREATE_CHILD_SA exchange.
120 //
121 return IkePacket;
122 }
123
124 /**
125 Parse the IKE packet of CREATE_CHILD_SA exchange.
126
127 This function parse the IKE packet and save the related information to further
128 calculation.
129
130 @param[in] SaSession Pointer to IKEv2_CHILD_SA_SESSION related to this Exchange.
131 @param[in] IkePacket Received packet to be parsed.
132
133
134 @retval EFI_SUCCESS The IKE Packet is acceptable.
135 @retval EFI_UNSUPPORTED Not support the CREATE_CHILD_SA request.
136
137 **/
138 EFI_STATUS
Ikev2CreateChildParser(IN UINT8 * SaSession,IN IKE_PACKET * IkePacket)139 Ikev2CreateChildParser (
140 IN UINT8 *SaSession,
141 IN IKE_PACKET *IkePacket
142 )
143 {
144 return EFI_UNSUPPORTED;
145 }
146
147 /**
148 Routine process before the payload decoding.
149
150 @param[in] SessionCommon Pointer to ChildSa SessionCommon.
151 @param[in] PayloadBuf Pointer to the payload.
152 @param[in] PayloadSize Size of PayloadBuf in byte.
153 @param[in] PayloadType Type of Payload.
154
155 **/
156 VOID
Ikev2ChildSaBeforeDecodePayload(IN UINT8 * SessionCommon,IN UINT8 * PayloadBuf,IN UINTN PayloadSize,IN UINT8 PayloadType)157 Ikev2ChildSaBeforeDecodePayload (
158 IN UINT8 *SessionCommon,
159 IN UINT8 *PayloadBuf,
160 IN UINTN PayloadSize,
161 IN UINT8 PayloadType
162 )
163 {
164
165 }
166
167 /**
168 Routine Process after the payload encoding.
169
170 @param[in] SessionCommon Pointer to ChildSa SessionCommon.
171 @param[in] PayloadBuf Pointer to the payload.
172 @param[in] PayloadSize Size of PayloadBuf in byte.
173 @param[in] PayloadType Type of Payload.
174
175 **/
176 VOID
Ikev2ChildSaAfterEncodePayload(IN UINT8 * SessionCommon,IN UINT8 * PayloadBuf,IN UINTN PayloadSize,IN UINT8 PayloadType)177 Ikev2ChildSaAfterEncodePayload (
178 IN UINT8 *SessionCommon,
179 IN UINT8 *PayloadBuf,
180 IN UINTN PayloadSize,
181 IN UINT8 PayloadType
182 )
183 {
184 }
185
186 IKEV2_PACKET_HANDLER mIkev2CreateChild = {
187 //
188 // Create Child
189 //
190 Ikev2CreateChildParser,
191 Ikev2CreateChildGenerator
192 };
193