1 /** @file
2 The implementation of construct ENTRY_INDEXER in IpSecConfig application.
3
4 Copyright (c) 2009 - 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 "IpSecConfig.h"
17 #include "Indexer.h"
18 #include "Helper.h"
19
20 /**
21 Fill in SPD_ENTRY_INDEXER through ParamPackage list.
22
23 @param[in, out] Indexer The pointer to the SPD_ENTRY_INDEXER structure.
24 @param[in] ParamPackage The pointer to the ParamPackage list.
25
26 @retval EFI_SUCCESS Filled in SPD_ENTRY_INDEXER successfully.
27 **/
28 EFI_STATUS
ConstructSpdIndexer(IN OUT SPD_ENTRY_INDEXER * Indexer,IN LIST_ENTRY * ParamPackage)29 ConstructSpdIndexer (
30 IN OUT SPD_ENTRY_INDEXER *Indexer,
31 IN LIST_ENTRY *ParamPackage
32 )
33 {
34 EFI_STATUS Status;
35 UINT64 Value64;
36 CONST CHAR16 *ValueStr;
37
38 ValueStr = NULL;
39
40 if (ShellCommandLineGetFlag (ParamPackage, L"-i")) {
41 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-i");
42 } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
43 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
44 } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
45 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
46 } else {
47 return EFI_INVALID_PARAMETER;
48 }
49
50 if (ValueStr == NULL) {
51 return EFI_INVALID_PARAMETER;
52 }
53
54 Value64 = StrToUInteger (ValueStr, &Status);
55 if (!EFI_ERROR (Status)) {
56 Indexer->Index = (UINTN) Value64;
57 ZeroMem (Indexer->Name, MAX_PEERID_LEN);
58 } else {
59 UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) Indexer->Name, MAX_PEERID_LEN);
60 }
61
62 return EFI_SUCCESS;
63 }
64
65 /**
66 Fill in SAD_ENTRY_INDEXER through ParamPackage list.
67
68 @param[in, out] Indexer The pointer to the SAD_ENTRY_INDEXER structure.
69 @param[in] ParamPackage The pointer to the ParamPackage list.
70
71 @retval EFI_SUCCESS Filled in SPD_ENTRY_INDEXER successfully.
72 @retval EFI_INVALID_PARAMETER The mistaken user input in ParamPackage list.
73 **/
74 EFI_STATUS
ConstructSadIndexer(IN OUT SAD_ENTRY_INDEXER * Indexer,IN LIST_ENTRY * ParamPackage)75 ConstructSadIndexer (
76 IN OUT SAD_ENTRY_INDEXER *Indexer,
77 IN LIST_ENTRY *ParamPackage
78 )
79 {
80 EFI_STATUS Status;
81 EFI_STATUS Status1;
82 UINT64 Value64;
83 CONST CHAR16 *ValueStr;
84
85 ValueStr = NULL;
86
87 if (ShellCommandLineGetFlag (ParamPackage, L"-i")) {
88 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-i");
89 } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
90 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
91 } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
92 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
93 } else {
94 return EFI_INVALID_PARAMETER;
95 }
96
97 if (ValueStr == NULL) {
98 return EFI_INVALID_PARAMETER;
99 }
100
101 Value64 = StrToUInteger (ValueStr, &Status);
102 if (!EFI_ERROR (Status)) {
103 Indexer->Index = (UINTN) Value64;
104 ZeroMem (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID));
105 } else {
106 if ((!ShellCommandLineGetFlag (ParamPackage, L"--lookup-spi")) ||
107 (!ShellCommandLineGetFlag (ParamPackage, L"--lookup-ipsec-proto")) ||
108 (!ShellCommandLineGetFlag (ParamPackage, L"--lookup-dest"))) {
109 ShellPrintHiiEx (
110 -1,
111 -1,
112 NULL,
113 STRING_TOKEN (STR_IPSEC_CONFIG_MISSING_ONE_OF_PARAMETERS),
114 mHiiHandle,
115 mAppName,
116 L"--lookup-spi --lookup-ipsec-proto --lookup-dest"
117 );
118 return EFI_INVALID_PARAMETER;
119 }
120
121 Status = GetNumber (
122 L"--lookup-spi",
123 (UINT32) -1,
124 &Indexer->SaId.Spi,
125 sizeof (UINT32),
126 NULL,
127 ParamPackage,
128 FORMAT_NUMBER
129 );
130 Status1 = GetNumber (
131 L"--lookup-ipsec-proto",
132 0,
133 &Indexer->SaId.Proto,
134 sizeof (EFI_IPSEC_PROTOCOL_TYPE),
135 mMapIpSecProtocol,
136 ParamPackage,
137 FORMAT_STRING
138 );
139
140 if (EFI_ERROR (Status) || EFI_ERROR (Status1)) {
141 return EFI_INVALID_PARAMETER;
142 }
143
144 ValueStr = ShellCommandLineGetValue (ParamPackage, L"--lookup-dest");
145 ASSERT (ValueStr != NULL);
146
147 Status = EfiInetAddr2 ((CHAR16 *) ValueStr, &Indexer->SaId.DestAddress);
148 if (EFI_ERROR (Status)) {
149 ShellPrintHiiEx (
150 -1,
151 -1,
152 NULL,
153 STRING_TOKEN (STR_IPSEC_CONFIG_INCORRECT_PARAMETER_VALUE),
154 mHiiHandle,
155 mAppName,
156 L"--lookup-dest",
157 ValueStr
158 );
159 return EFI_INVALID_PARAMETER;
160 }
161 }
162
163 return EFI_SUCCESS;
164 }
165
166 /**
167 Fill in PAD_ENTRY_INDEXER through ParamPackage list.
168
169 @param[in, out] Indexer The pointer to the PAD_ENTRY_INDEXER structure.
170 @param[in] ParamPackage The pointer to the ParamPackage list.
171
172 @retval EFI_SUCCESS Filled in PAD_ENTRY_INDEXER successfully.
173 @retval EFI_INVALID_PARAMETER The mistaken user input in ParamPackage list.
174 **/
175 EFI_STATUS
ConstructPadIndexer(IN OUT PAD_ENTRY_INDEXER * Indexer,IN LIST_ENTRY * ParamPackage)176 ConstructPadIndexer (
177 IN OUT PAD_ENTRY_INDEXER *Indexer,
178 IN LIST_ENTRY *ParamPackage
179 )
180 {
181 EFI_STATUS Status;
182 UINT64 Value64;
183 CONST CHAR16 *ValueStr;
184
185 ValueStr = NULL;
186
187 if (ShellCommandLineGetFlag (ParamPackage, L"-i")) {
188 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-i");
189 } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
190 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
191 } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
192 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
193 } else {
194 return EFI_INVALID_PARAMETER;
195 }
196
197 if (ValueStr == NULL) {
198 return EFI_INVALID_PARAMETER;
199 }
200
201 Value64 = StrToUInteger (ValueStr, &Status);
202
203 if (!EFI_ERROR (Status)) {
204 Indexer->Index = (UINTN) Value64;
205 ZeroMem (&Indexer->PadId, sizeof (EFI_IPSEC_PAD_ID));
206 } else {
207
208 if (ShellCommandLineGetFlag (ParamPackage, L"--lookup-peer-address")) {
209 ValueStr = ShellCommandLineGetValue (ParamPackage, L"--lookup-peer-address");
210 ASSERT (ValueStr != NULL);
211
212 Indexer->PadId.PeerIdValid = FALSE;
213 Status = EfiInetAddrRange ((CHAR16 *) ValueStr, &Indexer->PadId.Id.IpAddress);
214 if (EFI_ERROR (Status)) {
215 ShellPrintHiiEx (
216 -1,
217 -1,
218 NULL,
219 STRING_TOKEN (STR_IPSEC_CONFIG_INCORRECT_PARAMETER_VALUE),
220 mHiiHandle,
221 mAppName,
222 L"--lookup-peer-address",
223 ValueStr
224 );
225 return EFI_INVALID_PARAMETER;
226 }
227 } else {
228 ValueStr = ShellCommandLineGetValue (ParamPackage, L"--lookup-peer-id");
229 if (ValueStr == NULL) {
230 ShellPrintHiiEx (
231 -1,
232 -1,
233 NULL,
234 STRING_TOKEN (STR_IPSEC_CONFIG_MISSING_ONE_OF_PARAMETERS),
235 mHiiHandle,
236 mAppName,
237 L"--lookup-peer-address --lookup-peer-id"
238 );
239 return EFI_INVALID_PARAMETER;
240 }
241
242 Indexer->PadId.PeerIdValid = TRUE;
243 ZeroMem (Indexer->PadId.Id.PeerId, MAX_PEERID_LEN);
244 StrnCpyS ((CHAR16 *) Indexer->PadId.Id.PeerId, MAX_PEERID_LEN / sizeof (CHAR16), ValueStr, MAX_PEERID_LEN / sizeof (CHAR16) - 1);
245 }
246 }
247
248 return EFI_SUCCESS;
249 }
250
251 CONSTRUCT_POLICY_ENTRY_INDEXER mConstructPolicyEntryIndexer[] = {
252 (CONSTRUCT_POLICY_ENTRY_INDEXER) ConstructSpdIndexer,
253 (CONSTRUCT_POLICY_ENTRY_INDEXER) ConstructSadIndexer,
254 (CONSTRUCT_POLICY_ENTRY_INDEXER) ConstructPadIndexer
255 };
256