TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishPlatformConfig.c
Go to the documentation of this file.
1
11#include <Uefi.h>
12#include <Library/DebugLib.h>
13#include <Library/NetLib.h>
17#include <Library/UefiLib.h>
19
20UINTN Argc;
21CHAR16 **Argv;
22
31 VOID
32 )
33{
34 EFI_STATUS Status;
35 EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;
36
37 Status = gBS->HandleProtocol (
39 &gEfiShellParametersProtocolGuid,
40 (VOID **)&ShellParameters
41 );
42 if (EFI_ERROR (Status)) {
43 return Status;
44 }
45
46 Argc = ShellParameters->Argc;
47 Argv = ShellParameters->Argv;
48 return EFI_SUCCESS;
49}
50
56VOID
58 VOID
59 )
60{
61 Print (L"\n");
62 Print (L"Format (Only Ipv4 Address is supported):\n");
63 Print (L"RedfishPlatformConfig.efi -s HostIpAddress HostIpMask RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\n");
64 Print (L"OR:\n");
65 Print (L"RedfishPlatformConfig.efi -a RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\n");
66 Print (L"\n");
67}
68
81EFIAPI
83 IN EFI_HANDLE ImageHandle,
84 IN EFI_SYSTEM_TABLE *SystemTable
85 )
86{
87 EFI_STATUS Status;
88 RETURN_STATUS ReturnStatus;
89
90 UINT8 HostIpAssignmentType;
91 EFI_IPv4_ADDRESS HostIpAddress;
92 EFI_IPv4_ADDRESS HostIpMask;
93 EFI_IPv4_ADDRESS RedfishServiceIpAddress;
94 EFI_IPv4_ADDRESS RedfishServiceIpMask;
95 UINTN RedfishServiceIpPort;
96
97 Status = GetArg ();
98 if (EFI_ERROR (Status)) {
99 return Status;
100 }
101
102 //
103 // Format is like :
104 // RedfishPlatformConfig.efi -s HostIpAddress HostIpMask RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort
105 // RedfishPlatformConfig.efi -a RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort
106 //
107 if ((Argc != 7) && (Argc != 5)) {
108 PrintHelp ();
109 return EFI_UNSUPPORTED;
110 }
111
112 if (StrCmp (Argv[1], L"-s") == 0) {
113 HostIpAssignmentType = 1;
114
115 Status = NetLibStrToIp4 (Argv[2], &HostIpAddress);
116 if (EFI_ERROR (Status)) {
117 PrintHelp ();
118 return Status;
119 }
120
121 Status = NetLibStrToIp4 (Argv[3], &HostIpMask);
122 if (EFI_ERROR (Status)) {
123 PrintHelp ();
124 return Status;
125 }
126
127 Status = NetLibStrToIp4 (Argv[4], &RedfishServiceIpAddress);
128 if (EFI_ERROR (Status)) {
129 PrintHelp ();
130 return Status;
131 }
132
133 Status = NetLibStrToIp4 (Argv[5], &RedfishServiceIpMask);
134 if (EFI_ERROR (Status)) {
135 PrintHelp ();
136 return Status;
137 }
138
139 ReturnStatus = StrDecimalToUintnS (Argv[6], NULL, &RedfishServiceIpPort);
140 if (RETURN_ERROR (ReturnStatus)) {
141 PrintHelp ();
142 return Status;
143 }
144
145 Status = gRT->SetVariable (
146 L"HostIpAssignmentType",
147 &gEmuRedfishServiceGuid,
148 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
149 sizeof (UINT8),
150 &HostIpAssignmentType
151 );
152 if (EFI_ERROR (Status)) {
153 return Status;
154 }
155
156 Status = gRT->SetVariable (
157 L"HostIpAddress",
158 &gEmuRedfishServiceGuid,
159 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
160 sizeof (EFI_IPv4_ADDRESS),
161 &HostIpAddress
162 );
163 if (EFI_ERROR (Status)) {
164 return Status;
165 }
166
167 Status = gRT->SetVariable (
168 L"HostIpMask",
169 &gEmuRedfishServiceGuid,
170 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
171 sizeof (EFI_IPv4_ADDRESS),
172 &HostIpMask
173 );
174 if (EFI_ERROR (Status)) {
175 return Status;
176 }
177
178 Status = gRT->SetVariable (
179 L"RedfishServiceIpAddress",
180 &gEmuRedfishServiceGuid,
181 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
182 sizeof (EFI_IPv4_ADDRESS),
183 &RedfishServiceIpAddress
184 );
185 if (EFI_ERROR (Status)) {
186 return Status;
187 }
188
189 Status = gRT->SetVariable (
190 L"RedfishServiceIpMask",
191 &gEmuRedfishServiceGuid,
192 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
193 sizeof (EFI_IPv4_ADDRESS),
194 &RedfishServiceIpMask
195 );
196 if (EFI_ERROR (Status)) {
197 return Status;
198 }
199
200 Status = gRT->SetVariable (
201 L"RedfishServiceIpPort",
202 &gEmuRedfishServiceGuid,
203 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
204 sizeof (UINT16),
205 &RedfishServiceIpPort
206 );
207 if (EFI_ERROR (Status)) {
208 return Status;
209 }
210
211 Print (L"\n");
212 Print (L"HostIpAssignmentType is Static!\n");
213 Print (L"HostIpAddress: %s has been set Successfully!\n", Argv[2]);
214 Print (L"HostIpMask: %s has been set Successfully!\n", Argv[3]);
215 Print (L"RedfishServiceIpAddress: %s has been set Successfully!\n", Argv[4]);
216 Print (L"RedfishServiceIpMask: %s has been set Successfully!\n", Argv[5]);
217 Print (L"RedfishServiceIpPort: %s has been set Successfully!\n", Argv[6]);
218 Print (L"Please Restart!\n");
219 } else if (StrCmp (Argv[1], L"-a") == 0) {
220 HostIpAssignmentType = 3;
221
222 Status = NetLibStrToIp4 (Argv[2], &RedfishServiceIpAddress);
223 if (EFI_ERROR (Status)) {
224 PrintHelp ();
225 return Status;
226 }
227
228 Status = NetLibStrToIp4 (Argv[3], &RedfishServiceIpMask);
229 if (EFI_ERROR (Status)) {
230 PrintHelp ();
231 return Status;
232 }
233
234 ReturnStatus = StrDecimalToUintnS (Argv[4], NULL, &RedfishServiceIpPort);
235 if (RETURN_ERROR (ReturnStatus)) {
236 PrintHelp ();
237 return Status;
238 }
239
240 Status = gRT->SetVariable (
241 L"HostIpAssignmentType",
242 &gEmuRedfishServiceGuid,
243 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
244 sizeof (UINT8),
245 &HostIpAssignmentType
246 );
247 if (EFI_ERROR (Status)) {
248 return Status;
249 }
250
251 Status = gRT->SetVariable (
252 L"RedfishServiceIpAddress",
253 &gEmuRedfishServiceGuid,
254 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
255 sizeof (EFI_IPv4_ADDRESS),
256 &RedfishServiceIpAddress
257 );
258 if (EFI_ERROR (Status)) {
259 return Status;
260 }
261
262 Status = gRT->SetVariable (
263 L"RedfishServiceIpMask",
264 &gEmuRedfishServiceGuid,
265 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
266 sizeof (EFI_IPv4_ADDRESS),
267 &RedfishServiceIpMask
268 );
269 if (EFI_ERROR (Status)) {
270 return Status;
271 }
272
273 Status = gRT->SetVariable (
274 L"RedfishServiceIpPort",
275 &gEmuRedfishServiceGuid,
276 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
277 sizeof (UINT16),
278 &RedfishServiceIpPort
279 );
280 if (EFI_ERROR (Status)) {
281 return Status;
282 }
283
284 Print (L"\n");
285 Print (L"HostIpAssignmentType is Auto!\n");
286 Print (L"RedfishServiceIpAddress: %s has been set Successfully!\n", Argv[2]);
287 Print (L"RedfishServiceIpMask: %s has been set Successfully!\n", Argv[3]);
288 Print (L"RedfishServiceIpPort: %s has been set Successfully!\n", Argv[4]);
289 Print (L"Please Restart!\n");
290 } else if ((StrCmp (Argv[1], L"-h") == 0) || (StrCmp (Argv[1], L"-help") == 0)) {
291 PrintHelp ();
292 } else {
293 PrintHelp ();
294 return EFI_UNSUPPORTED;
295 }
296
297 return EFI_SUCCESS;
298}
UINT64 UINTN
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
RETURN_STATUS EFIAPI StrDecimalToUintnS(IN CONST CHAR16 *String, OUT CHAR16 **EndPointer OPTIONAL, OUT UINTN *Data)
Definition: SafeString.c:631
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define IN
Definition: Base.h:279
EFI_STATUS EFIAPI NetLibStrToIp4(IN CONST CHAR16 *String, OUT EFI_IPv4_ADDRESS *Ip4Address)
Definition: DxeNetLib.c:3125
VOID PrintHelp(VOID)
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS GetArg(VOID)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113
#define EFI_VARIABLE_NON_VOLATILE