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