]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | The implementation for ifcommand shell command.\r | |
3 | \r | |
4 | (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r | |
5 | Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r | |
6 | \r | |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php.\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | **/\r | |
15 | \r | |
16 | #include "UefiShellNetwork1CommandsLib.h"\r | |
17 | \r | |
18 | #define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE)\r | |
19 | #define EFI_IP4_TO_U32(EfiIpAddr) (*(IP4_ADDR*)((EfiIpAddr).Addr))\r | |
20 | \r | |
21 | BOOLEAN mIp4ConfigExist = FALSE;\r | |
22 | STATIC EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r | |
23 | \r | |
24 | STATIC CONST UINTN SecondsToNanoSeconds = 10000000;\r | |
25 | STATIC CONST CHAR16 DhcpString[5] = L"DHCP";\r | |
26 | STATIC CONST CHAR16 StaticString[7] = L"STATIC";\r | |
27 | STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";\r | |
28 | \r | |
29 | typedef struct {\r | |
30 | LIST_ENTRY Link;\r | |
31 | EFI_HANDLE Handle;\r | |
32 | NIC_ADDR NicAddress;\r | |
33 | CHAR16 Name[IP4_NIC_NAME_LENGTH];\r | |
34 | BOOLEAN MediaPresentSupported;\r | |
35 | BOOLEAN MediaPresent;\r | |
36 | EFI_IP4_CONFIG_PROTOCOL *Ip4Config;\r | |
37 | NIC_IP4_CONFIG_INFO *ConfigInfo;\r | |
38 | } NIC_INFO;\r | |
39 | \r | |
40 | typedef struct {\r | |
41 | EFI_IP_ADDRESS DestIp;\r | |
42 | EFI_MAC_ADDRESS DestMac;\r | |
43 | EFI_IP_ADDRESS LocalIp;\r | |
44 | EFI_MAC_ADDRESS LocalMac;\r | |
45 | UINT8 MacLen;\r | |
46 | EFI_EVENT OnResolved;\r | |
47 | BOOLEAN Duplicate;\r | |
48 | } ARP_REQUEST;\r | |
49 | \r | |
50 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r | |
51 | {L"-c", TypeValue},\r | |
52 | {L"-l", TypeValue},\r | |
53 | {L"-s", TypeMaxValue},\r | |
54 | {NULL, TypeMax}\r | |
55 | };\r | |
56 | \r | |
57 | STATIC LIST_ENTRY NicInfoList;\r | |
58 | STATIC BOOLEAN ArpResolved;\r | |
59 | STATIC BOOLEAN mTimeout;\r | |
60 | \r | |
61 | /**\r | |
62 | Count the space delimited items in a string.\r | |
63 | \r | |
64 | @param[in] String A pointer to the string to count.\r | |
65 | \r | |
66 | @return The number of space-delimited items.\r | |
67 | @retval 0xFF an error occured.\r | |
68 | **/\r | |
69 | UINT8\r | |
70 | EFIAPI\r | |
71 | CountSubItems (\r | |
72 | IN CONST CHAR16 *String\r | |
73 | )\r | |
74 | {\r | |
75 | CONST CHAR16 *Walker;\r | |
76 | UINT8 Count;\r | |
77 | \r | |
78 | if (String == NULL || *String == CHAR_NULL) {\r | |
79 | return (0xFF);\r | |
80 | }\r | |
81 | \r | |
82 | for (Walker = String, Count = 0 ; Walker != NULL && *Walker != CHAR_NULL ; Walker = (StrStr(Walker, L" ")==NULL?NULL:StrStr(Walker, L" ")+1), Count++);\r | |
83 | return (Count);\r | |
84 | }\r | |
85 | \r | |
86 | /**\r | |
87 | Find the NIC_INFO by the specified nic name.\r | |
88 | \r | |
89 | @param[in] Name The pointer to the string containing the NIC name.\r | |
90 | \r | |
91 | @return The pointer to the NIC_INFO if there is a NIC_INFO named by Name.\r | |
92 | @retval NULL No NIC_INFO was found for Name.\r | |
93 | **/\r | |
94 | NIC_INFO*\r | |
95 | EFIAPI\r | |
96 | IfconfigFindNicByName (\r | |
97 | IN CONST CHAR16 *Name\r | |
98 | )\r | |
99 | {\r | |
100 | LIST_ENTRY *Entry;\r | |
101 | LIST_ENTRY *NextEntry;\r | |
102 | NIC_INFO *Info;\r | |
103 | CHAR16 *TempString;\r | |
104 | \r | |
105 | NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {\r | |
106 | Info = BASE_CR (Entry, NIC_INFO, Link);\r | |
107 | TempString = (CHAR16*)Info->Name;\r | |
108 | \r | |
109 | if (StringNoCaseCompare (&Name, &TempString) == 0) {\r | |
110 | return Info;\r | |
111 | }\r | |
112 | }\r | |
113 | \r | |
114 | return NULL;\r | |
115 | }\r | |
116 | \r | |
117 | /**\r | |
118 | Tests whether a child handle is a child device of the controller.\r | |
119 | \r | |
120 | @param[in] ControllerHandle A handle for a (parent) controller to test.\r | |
121 | @param[in] ChildHandle A child handle to test.\r | |
122 | @param[in] ProtocolGuid Supplies the protocol that the child controller\r | |
123 | opens on its parent controller.\r | |
124 | \r | |
125 | @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.\r | |
126 | @retval EFI_UNSUPPORTED ChildHandle is not a child of the ControllerHandle.\r | |
127 | **/\r | |
128 | EFI_STATUS\r | |
129 | EFIAPI\r | |
130 | TestChildHandle (\r | |
131 | IN CONST EFI_HANDLE ControllerHandle,\r | |
132 | IN CONST EFI_HANDLE ChildHandle,\r | |
133 | IN CONST EFI_GUID *ProtocolGuid\r | |
134 | )\r | |
135 | {\r | |
136 | EFI_STATUS Status;\r | |
137 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
138 | UINTN EntryCount;\r | |
139 | UINTN Index;\r | |
140 | \r | |
141 | ASSERT (ProtocolGuid != NULL);\r | |
142 | \r | |
143 | //\r | |
144 | // Retrieve the list of agents that are consuming the specific protocol\r | |
145 | // on ControllerHandle.\r | |
146 | //\r | |
147 | Status = gBS->OpenProtocolInformation (\r | |
148 | ControllerHandle,\r | |
149 | (EFI_GUID *) ProtocolGuid,\r | |
150 | &OpenInfoBuffer,\r | |
151 | &EntryCount\r | |
152 | );\r | |
153 | if (EFI_ERROR (Status)) {\r | |
154 | return EFI_UNSUPPORTED;\r | |
155 | }\r | |
156 | \r | |
157 | //\r | |
158 | // Inspect if ChildHandle is one of the agents.\r | |
159 | //\r | |
160 | Status = EFI_UNSUPPORTED;\r | |
161 | for (Index = 0; Index < EntryCount; Index++) {\r | |
162 | if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r | |
163 | (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
164 | Status = EFI_SUCCESS;\r | |
165 | break;\r | |
166 | }\r | |
167 | }\r | |
168 | \r | |
169 | FreePool (OpenInfoBuffer);\r | |
170 | return Status;\r | |
171 | }\r | |
172 | \r | |
173 | /**\r | |
174 | Get the child handle of the NIC handle.\r | |
175 | \r | |
176 | @param[in] Controller Routing information: GUID.\r | |
177 | @param[out] ChildHandle Returned child handle.\r | |
178 | \r | |
179 | @retval EFI_SUCCESS Successfully to get child handle.\r | |
180 | **/\r | |
181 | EFI_STATUS \r | |
182 | GetChildHandle (\r | |
183 | IN EFI_HANDLE Controller,\r | |
184 | OUT EFI_HANDLE *ChildHandle\r | |
185 | )\r | |
186 | {\r | |
187 | EFI_STATUS Status;\r | |
188 | EFI_HANDLE *Handles;\r | |
189 | UINTN HandleCount;\r | |
190 | UINTN Index;\r | |
191 | EFI_DEVICE_PATH_PROTOCOL *ChildDeviceDevicePath;\r | |
192 | VENDOR_DEVICE_PATH *VendorDeviceNode;\r | |
193 | \r | |
194 | //\r | |
195 | // Locate all EFI Hii Config Access protocols\r | |
196 | //\r | |
197 | Status = gBS->LocateHandleBuffer (\r | |
198 | ByProtocol,\r | |
199 | &gEfiHiiConfigAccessProtocolGuid,\r | |
200 | NULL,\r | |
201 | &HandleCount,\r | |
202 | &Handles\r | |
203 | );\r | |
204 | if (EFI_ERROR (Status) || (HandleCount == 0)) {\r | |
205 | return Status;\r | |
206 | }\r | |
207 | \r | |
208 | Status = EFI_NOT_FOUND;\r | |
209 | \r | |
210 | for (Index = 0; Index < HandleCount; Index++) {\r | |
211 | \r | |
212 | Status = TestChildHandle (Controller, Handles[Index], &gEfiManagedNetworkServiceBindingProtocolGuid);\r | |
213 | if (!EFI_ERROR (Status)) {\r | |
214 | //\r | |
215 | // Get device path on the child handle\r | |
216 | //\r | |
217 | Status = gBS->HandleProtocol (\r | |
218 | Handles[Index],\r | |
219 | &gEfiDevicePathProtocolGuid,\r | |
220 | (VOID **) &ChildDeviceDevicePath\r | |
221 | );\r | |
222 | \r | |
223 | if (!EFI_ERROR (Status)) {\r | |
224 | while (!IsDevicePathEnd (ChildDeviceDevicePath)) {\r | |
225 | ChildDeviceDevicePath = NextDevicePathNode (ChildDeviceDevicePath);\r | |
226 | //\r | |
227 | // Parse one instance\r | |
228 | //\r | |
229 | if (ChildDeviceDevicePath->Type == HARDWARE_DEVICE_PATH && \r | |
230 | ChildDeviceDevicePath->SubType == HW_VENDOR_DP) {\r | |
231 | VendorDeviceNode = (VENDOR_DEVICE_PATH *) ChildDeviceDevicePath;\r | |
232 | if (CompareMem (&VendorDeviceNode->Guid, &gEfiNicIp4ConfigVariableGuid, sizeof (EFI_GUID)) == 0) {\r | |
233 | //\r | |
234 | // Found item matched gEfiNicIp4ConfigVariableGuid\r | |
235 | //\r | |
236 | *ChildHandle = Handles[Index];\r | |
237 | FreePool (Handles);\r | |
238 | return EFI_SUCCESS;\r | |
239 | }\r | |
240 | }\r | |
241 | }\r | |
242 | } \r | |
243 | }\r | |
244 | }\r | |
245 | \r | |
246 | FreePool (Handles);\r | |
247 | return Status; \r | |
248 | }\r | |
249 | \r | |
250 | /**\r | |
251 | Append OFFSET/WIDTH/VALUE items at the beginning of string.\r | |
252 | \r | |
253 | @param[in, out] String The pointer to the string to append onto.\r | |
254 | @param[in] MaxLen The max number of UNICODE char in String\r | |
255 | including the terminate NULL char.\r | |
256 | @param[in] Offset Offset value.\r | |
257 | @param[in] Width Width value.\r | |
258 | @param[in] Block Point to data buffer.\r | |
259 | \r | |
260 | @return The count of unicode character that were appended.\r | |
261 | **/\r | |
262 | UINTN\r | |
263 | EFIAPI\r | |
264 | AppendOffsetWidthValue (\r | |
265 | IN OUT CHAR16 *String,\r | |
266 | IN UINTN MaxLen,\r | |
267 | IN UINTN Offset,\r | |
268 | IN UINTN Width,\r | |
269 | IN CONST UINT8 *Block\r | |
270 | )\r | |
271 | \r | |
272 | {\r | |
273 | CHAR16 *OriString;\r | |
274 | \r | |
275 | OriString = String;\r | |
276 | \r | |
277 | StrnCpyS (String, MaxLen, L"&OFFSET=", 9);\r | |
278 | String += StrLen (L"&OFFSET=");\r | |
279 | String += UnicodeSPrint (String, 20, L"%x", Offset);\r | |
280 | \r | |
281 | StrnCpyS (String, MaxLen, L"&WIDTH=", 8);\r | |
282 | String += StrLen (L"&WIDTH=");\r | |
283 | String += UnicodeSPrint (String, 20, L"%x", Width);\r | |
284 | \r | |
285 | if (Block != NULL) {\r | |
286 | StrnCpyS (String, MaxLen, L"&VALUE=", 8);\r | |
287 | String += StrLen (L"&VALUE=");\r | |
288 | while ((Width--) != 0) {\r | |
289 | String += UnicodeSPrint (String, 20, L"%x", Block[Width]);\r | |
290 | }\r | |
291 | }\r | |
292 | \r | |
293 | return String - OriString;\r | |
294 | }\r | |
295 | \r | |
296 | /**\r | |
297 | Converts the unicode character of the string from uppercase to lowercase.\r | |
298 | This is a internal function.\r | |
299 | \r | |
300 | @param ConfigString String to be converted\r | |
301 | **/\r | |
302 | CHAR16* \r | |
303 | EFIAPI\r | |
304 | HiiToLower (\r | |
305 | IN CHAR16 *ConfigString\r | |
306 | )\r | |
307 | {\r | |
308 | CHAR16 *String;\r | |
309 | BOOLEAN Lower;\r | |
310 | \r | |
311 | //\r | |
312 | // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r | |
313 | //\r | |
314 | for (String = ConfigString, Lower = FALSE; String != NULL && *String != L'\0'; String++) {\r | |
315 | if (*String == L'=') {\r | |
316 | Lower = TRUE;\r | |
317 | } else if (*String == L'&') {\r | |
318 | Lower = FALSE;\r | |
319 | } else if (Lower && *String >= L'A' && *String <= L'F') {\r | |
320 | *String = (CHAR16) (*String - L'A' + L'a');\r | |
321 | }\r | |
322 | }\r | |
323 | \r | |
324 | return (ConfigString);\r | |
325 | }\r | |
326 | \r | |
327 | \r | |
328 | /**\r | |
329 | Construct <ConfigHdr> using routing information GUID/NAME/PATH.\r | |
330 | \r | |
331 | @param[in] Guid Routing information: GUID.\r | |
332 | @param[in] Name Routing information: NAME.\r | |
333 | @param[in] DriverHandle Driver handle which contains the routing information: PATH.\r | |
334 | \r | |
335 | @retval NULL An error occured.\r | |
336 | @return The pointer to configHdr string.\r | |
337 | **/\r | |
338 | CHAR16 *\r | |
339 | EFIAPI\r | |
340 | ConstructConfigHdr (\r | |
341 | IN CONST EFI_GUID *Guid,\r | |
342 | IN CONST CHAR16 *Name,\r | |
343 | IN EFI_HANDLE DriverHandle\r | |
344 | )\r | |
345 | {\r | |
346 | EFI_STATUS Status;\r | |
347 | CHAR16 *ConfigHdr;\r | |
348 | UINTN ConfigHdrBufferSize;\r | |
349 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
350 | CHAR16 *String;\r | |
351 | UINTN Index;\r | |
352 | UINT8 *Buffer;\r | |
353 | UINTN DevicePathLength;\r | |
354 | UINTN NameLength;\r | |
355 | \r | |
356 | //\r | |
357 | // Get the device path from handle installed EFI HII Config Access protocol\r | |
358 | //\r | |
359 | Status = gBS->HandleProtocol (\r | |
360 | DriverHandle,\r | |
361 | &gEfiDevicePathProtocolGuid,\r | |
362 | (VOID **) &DevicePath\r | |
363 | );\r | |
364 | if (EFI_ERROR (Status)) {\r | |
365 | return NULL;\r | |
366 | }\r | |
367 | \r | |
368 | DevicePathLength = GetDevicePathSize (DevicePath);\r | |
369 | NameLength = StrLen (Name);\r | |
370 | ConfigHdrBufferSize = (5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16);\r | |
371 | ConfigHdr = AllocateZeroPool (ConfigHdrBufferSize);\r | |
372 | if (ConfigHdr == NULL) {\r | |
373 | return NULL;\r | |
374 | } \r | |
375 | \r | |
376 | String = ConfigHdr;\r | |
377 | StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"GUID=", 6);\r | |
378 | String += StrLen (L"GUID=");\r | |
379 | \r | |
380 | //\r | |
381 | // Append Guid converted to <HexCh>32\r | |
382 | //\r | |
383 | for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {\r | |
384 | String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);\r | |
385 | }\r | |
386 | \r | |
387 | //\r | |
388 | // Append L"&NAME="\r | |
389 | //\r | |
390 | StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&NAME=", 7);\r | |
391 | String += StrLen (L"&NAME=");\r | |
392 | for (Index = 0; Index < NameLength ; Index++) {\r | |
393 | String += UnicodeSPrint (String, 10, L"00%x", Name[Index]);\r | |
394 | }\r | |
395 | \r | |
396 | //\r | |
397 | // Append L"&PATH="\r | |
398 | //\r | |
399 | StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&PATH=", 7);\r | |
400 | String += StrLen (L"&PATH=");\r | |
401 | for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {\r | |
402 | String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);\r | |
403 | }\r | |
404 | \r | |
405 | return (HiiToLower(ConfigHdr));\r | |
406 | }\r | |
407 | \r | |
408 | /**\r | |
409 | Get network physical device NIC information.\r | |
410 | \r | |
411 | @param[in] Handle The network physical device handle.\r | |
412 | @param[out] NicAddr NIC information.\r | |
413 | \r | |
414 | @retval EFI_SUCCESS Get NIC information successfully.\r | |
415 | **/ \r | |
416 | EFI_STATUS\r | |
417 | EFIAPI\r | |
418 | IfConfigGetNicMacInfo (\r | |
419 | IN EFI_HANDLE Handle,\r | |
420 | OUT NIC_ADDR *NicAddr\r | |
421 | ) \r | |
422 | {\r | |
423 | EFI_STATUS Status;\r | |
424 | EFI_HANDLE MnpHandle;\r | |
425 | EFI_SIMPLE_NETWORK_MODE SnpMode;\r | |
426 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
427 | \r | |
428 | MnpHandle = NULL;\r | |
429 | Mnp = NULL;\r | |
430 | \r | |
431 | Status = NetLibCreateServiceChild (\r | |
432 | Handle,\r | |
433 | gImageHandle, \r | |
434 | &gEfiManagedNetworkServiceBindingProtocolGuid,\r | |
435 | &MnpHandle\r | |
436 | );\r | |
437 | if (EFI_ERROR (Status)) {\r | |
438 | return Status;\r | |
439 | }\r | |
440 | \r | |
441 | Status = gBS->HandleProtocol (\r | |
442 | MnpHandle,\r | |
443 | &gEfiManagedNetworkProtocolGuid,\r | |
444 | (VOID **) &Mnp\r | |
445 | );\r | |
446 | if (EFI_ERROR (Status)) {\r | |
447 | goto ON_ERROR;\r | |
448 | }\r | |
449 | \r | |
450 | Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r | |
451 | if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r | |
452 | goto ON_ERROR;\r | |
453 | }\r | |
454 | \r | |
455 | NicAddr->Type = (UINT16) SnpMode.IfType;\r | |
456 | NicAddr->Len = (UINT8) SnpMode.HwAddressSize;\r | |
457 | CopyMem (&NicAddr->MacAddr, &SnpMode.CurrentAddress, NicAddr->Len);\r | |
458 | \r | |
459 | ON_ERROR:\r | |
460 | \r | |
461 | NetLibDestroyServiceChild (\r | |
462 | Handle,\r | |
463 | gImageHandle, \r | |
464 | &gEfiManagedNetworkServiceBindingProtocolGuid,\r | |
465 | MnpHandle\r | |
466 | );\r | |
467 | \r | |
468 | return Status;\r | |
469 | \r | |
470 | }\r | |
471 | \r | |
472 | /**\r | |
473 | Get network physical device NIC information.\r | |
474 | \r | |
475 | @param[in] Handle The network physical device handle.\r | |
476 | @param[out] MediaPresentSupported\r | |
477 | Upon successful return, TRUE is media present \r | |
478 | is supported. FALSE otherwise.\r | |
479 | @param[out] MediaPresent Upon successful return, TRUE is media present \r | |
480 | is enabled. FALSE otherwise.\r | |
481 | \r | |
482 | @retval EFI_SUCCESS The operation was successful.\r | |
483 | **/\r | |
484 | EFI_STATUS\r | |
485 | EFIAPI\r | |
486 | IfConfigGetNicMediaStatus (\r | |
487 | IN EFI_HANDLE Handle,\r | |
488 | OUT BOOLEAN *MediaPresentSupported,\r | |
489 | OUT BOOLEAN *MediaPresent\r | |
490 | ) \r | |
491 | \r | |
492 | {\r | |
493 | EFI_STATUS Status;\r | |
494 | EFI_HANDLE MnpHandle;\r | |
495 | EFI_SIMPLE_NETWORK_MODE SnpMode;\r | |
496 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
497 | \r | |
498 | MnpHandle = NULL;\r | |
499 | Mnp = NULL;\r | |
500 | \r | |
501 | Status = NetLibCreateServiceChild (\r | |
502 | Handle,\r | |
503 | gImageHandle, \r | |
504 | &gEfiManagedNetworkServiceBindingProtocolGuid,\r | |
505 | &MnpHandle\r | |
506 | );\r | |
507 | if (EFI_ERROR (Status)) {\r | |
508 | return Status;\r | |
509 | }\r | |
510 | \r | |
511 | Status = gBS->HandleProtocol (\r | |
512 | MnpHandle,\r | |
513 | &gEfiManagedNetworkProtocolGuid,\r | |
514 | (VOID **) &Mnp\r | |
515 | );\r | |
516 | if (EFI_ERROR (Status)) {\r | |
517 | goto ON_ERROR;\r | |
518 | }\r | |
519 | \r | |
520 | Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r | |
521 | if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r | |
522 | goto ON_ERROR;\r | |
523 | }\r | |
524 | \r | |
525 | *MediaPresentSupported = SnpMode.MediaPresentSupported;\r | |
526 | *MediaPresent = SnpMode.MediaPresent;\r | |
527 | \r | |
528 | ON_ERROR:\r | |
529 | \r | |
530 | NetLibDestroyServiceChild (\r | |
531 | Handle,\r | |
532 | gImageHandle, \r | |
533 | &gEfiManagedNetworkServiceBindingProtocolGuid,\r | |
534 | MnpHandle\r | |
535 | );\r | |
536 | \r | |
537 | return Status;\r | |
538 | \r | |
539 | }\r | |
540 | \r | |
541 | /**\r | |
542 | Get all Nic's information through HII service.\r | |
543 | \r | |
544 | @retval EFI_SUCCESS All the nic information is collected.\r | |
545 | **/\r | |
546 | EFI_STATUS\r | |
547 | EFIAPI\r | |
548 | IfconfigGetAllNicInfoByHii (\r | |
549 | VOID\r | |
550 | )\r | |
551 | {\r | |
552 | EFI_STATUS Status;\r | |
553 | EFI_HANDLE *Handles;\r | |
554 | UINTN HandleCount;\r | |
555 | CHAR16 *ConfigResp;\r | |
556 | UINTN ConfigRespBufferSize;\r | |
557 | CHAR16 *ConfigHdr;\r | |
558 | UINTN Index;\r | |
559 | CHAR16 *AccessProgress;\r | |
560 | CHAR16 *AccessResults;\r | |
561 | UINTN BufferSize;\r | |
562 | NIC_INFO *NicInfo;\r | |
563 | NIC_IP4_CONFIG_INFO *NicConfigRequest;\r | |
564 | NIC_IP4_CONFIG_INFO *NicConfig;\r | |
565 | CHAR16 *String;\r | |
566 | UINTN Length;\r | |
567 | UINTN Offset;\r | |
568 | EFI_HANDLE ChildHandle;\r | |
569 | \r | |
570 | AccessResults = NULL;\r | |
571 | ConfigHdr = NULL;\r | |
572 | ConfigResp = NULL;\r | |
573 | NicConfigRequest = NULL;\r | |
574 | NicInfo = NULL;\r | |
575 | \r | |
576 | InitializeListHead (&NicInfoList);\r | |
577 | \r | |
578 | //\r | |
579 | // Check if HII Config Routing protocol available.\r | |
580 | //\r | |
581 | Status = gBS->LocateProtocol (\r | |
582 | &gEfiHiiConfigRoutingProtocolGuid,\r | |
583 | NULL,\r | |
584 | (VOID**)&mHiiConfigRouting\r | |
585 | );\r | |
586 | if (EFI_ERROR (Status)) {\r | |
587 | return EFI_NOT_FOUND;\r | |
588 | }\r | |
589 | \r | |
590 | //\r | |
591 | // Locate all network device handles\r | |
592 | //\r | |
593 | Status = gBS->LocateHandleBuffer (\r | |
594 | ByProtocol,\r | |
595 | &gEfiManagedNetworkServiceBindingProtocolGuid,\r | |
596 | NULL,\r | |
597 | &HandleCount,\r | |
598 | &Handles\r | |
599 | );\r | |
600 | if (EFI_ERROR (Status) || (HandleCount == 0)) {\r | |
601 | return EFI_NOT_FOUND;\r | |
602 | }\r | |
603 | \r | |
604 | for (Index = 0; Index < HandleCount; Index++) {\r | |
605 | Status = GetChildHandle (Handles[Index], &ChildHandle);\r | |
606 | if (EFI_ERROR (Status)) {\r | |
607 | //\r | |
608 | // If failed to get Child handle, try NIC controller handle for back-compatibility.\r | |
609 | //\r | |
610 | ChildHandle = Handles[Index];\r | |
611 | }\r | |
612 | //\r | |
613 | // Construct configuration request string header\r | |
614 | //\r | |
615 | ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r | |
616 | if (ConfigHdr != NULL) {\r | |
617 | Length = StrLen (ConfigHdr);\r | |
618 | } else {\r | |
619 | Length = 0;\r | |
620 | }\r | |
621 | ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);\r | |
622 | ConfigResp = AllocateZeroPool (ConfigRespBufferSize);\r | |
623 | if (ConfigResp == NULL) {\r | |
624 | Status = EFI_OUT_OF_RESOURCES;\r | |
625 | goto ON_ERROR;\r | |
626 | }\r | |
627 | if (ConfigHdr != NULL) {\r | |
628 | StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r | |
629 | }\r | |
630 | \r | |
631 | //\r | |
632 | // Append OFFSET/WIDTH pair\r | |
633 | //\r | |
634 | String = ConfigResp + Length;\r | |
635 | Offset = 0;\r | |
636 | AppendOffsetWidthValue (String, \r | |
637 | ConfigRespBufferSize/sizeof(CHAR16) - Length, \r | |
638 | Offset, \r | |
639 | NIC_ITEM_CONFIG_SIZE, \r | |
640 | NULL\r | |
641 | );\r | |
642 | \r | |
643 | NicInfo = AllocateZeroPool (sizeof (NIC_INFO));\r | |
644 | if (NicInfo == NULL) {\r | |
645 | Status = EFI_OUT_OF_RESOURCES;\r | |
646 | goto ON_ERROR;\r | |
647 | }\r | |
648 | NicInfo->Handle = Handles[Index];\r | |
649 | \r | |
650 | //\r | |
651 | // Get network physical devcie MAC information\r | |
652 | //\r | |
653 | IfConfigGetNicMacInfo (Handles[Index], &NicInfo->NicAddress);\r | |
654 | if (NicInfo->NicAddress.Type == NET_IFTYPE_ETHERNET) {\r | |
655 | UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"eth%d", Index);\r | |
656 | } else {\r | |
657 | UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"unk%d", Index);\r | |
658 | }\r | |
659 | \r | |
660 | //\r | |
661 | // Get media status\r | |
662 | //\r | |
663 | IfConfigGetNicMediaStatus (Handles[Index], &NicInfo->MediaPresentSupported, &NicInfo->MediaPresent);\r | |
664 | \r | |
665 | NicConfigRequest = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r | |
666 | if (NicConfigRequest == NULL) {\r | |
667 | Status = EFI_OUT_OF_RESOURCES;\r | |
668 | goto ON_ERROR;\r | |
669 | }\r | |
670 | \r | |
671 | //\r | |
672 | // Get network parameters by HII service\r | |
673 | //\r | |
674 | Status = mHiiConfigRouting->ExtractConfig (\r | |
675 | mHiiConfigRouting,\r | |
676 | ConfigResp,\r | |
677 | &AccessProgress,\r | |
678 | &AccessResults\r | |
679 | );\r | |
680 | if (!EFI_ERROR (Status)) {\r | |
681 | BufferSize = NIC_ITEM_CONFIG_SIZE;\r | |
682 | Status = mHiiConfigRouting->ConfigToBlock (\r | |
683 | mHiiConfigRouting,\r | |
684 | AccessResults,\r | |
685 | (UINT8 *) NicConfigRequest,\r | |
686 | &BufferSize,\r | |
687 | &AccessProgress\r | |
688 | );\r | |
689 | if (!EFI_ERROR (Status)) {\r | |
690 | BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * NicConfigRequest->Ip4Info.RouteTableSize;\r | |
691 | NicConfig = AllocateZeroPool (BufferSize);\r | |
692 | if (NicConfig == NULL) {\r | |
693 | Status = EFI_OUT_OF_RESOURCES;\r | |
694 | goto ON_ERROR;\r | |
695 | }\r | |
696 | CopyMem (NicConfig, NicConfigRequest, BufferSize);\r | |
697 | \r | |
698 | //\r | |
699 | // If succeeds to get NIC configuration, fix up routetable pointer.\r | |
700 | //\r | |
701 | NicConfig->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (&NicConfig->Ip4Info + 1);\r | |
702 | NicInfo->ConfigInfo = NicConfig;\r | |
703 | \r | |
704 | } else {\r | |
705 | NicInfo->ConfigInfo = NULL;\r | |
706 | }\r | |
707 | \r | |
708 | FreePool (AccessResults);\r | |
709 | \r | |
710 | } else {\r | |
711 | NicInfo->ConfigInfo = NULL;\r | |
712 | }\r | |
713 | \r | |
714 | //\r | |
715 | // Add the Nic's info to the global NicInfoList.\r | |
716 | //\r | |
717 | InsertTailList (&NicInfoList, &NicInfo->Link);\r | |
718 | \r | |
719 | FreePool (NicConfigRequest);\r | |
720 | FreePool (ConfigResp);\r | |
721 | FreePool (ConfigHdr);\r | |
722 | }\r | |
723 | \r | |
724 | FreePool (Handles);\r | |
725 | \r | |
726 | return EFI_SUCCESS;\r | |
727 | \r | |
728 | ON_ERROR:\r | |
729 | if (AccessResults != NULL) {\r | |
730 | FreePool (AccessResults);\r | |
731 | }\r | |
732 | if (NicConfigRequest != NULL) {\r | |
733 | FreePool (NicConfigRequest);\r | |
734 | }\r | |
735 | if (NicInfo != NULL) {\r | |
736 | FreePool (NicInfo);\r | |
737 | }\r | |
738 | if (ConfigResp != NULL) {\r | |
739 | FreePool (ConfigResp);\r | |
740 | }\r | |
741 | if (ConfigHdr != NULL) {\r | |
742 | FreePool (ConfigHdr);\r | |
743 | }\r | |
744 | \r | |
745 | FreePool (Handles);\r | |
746 | \r | |
747 | return Status;\r | |
748 | }\r | |
749 | \r | |
750 | /**\r | |
751 | Set the address for the specified nic by HII service.\r | |
752 | \r | |
753 | @param[in] NicInfo A pointer to the NIC_INFO of the Nic to be configured.\r | |
754 | @param[in] Config The command line arguments for the set operation.\r | |
755 | \r | |
756 | @retval EFI_SUCCESS The address set operation is done.\r | |
757 | **/\r | |
758 | SHELL_STATUS\r | |
759 | EFIAPI\r | |
760 | IfconfigSetNicAddrByHii (\r | |
761 | IN CONST NIC_INFO *NicInfo,\r | |
762 | IN CONST NIC_IP4_CONFIG_INFO *Config\r | |
763 | )\r | |
764 | {\r | |
765 | EFI_STATUS Status;\r | |
766 | SHELL_STATUS ShellStatus;\r | |
767 | NIC_IP4_CONFIG_INFO *NicConfig;\r | |
768 | CHAR16 *ConfigResp;\r | |
769 | UINTN ConfigRespBufferSize;\r | |
770 | CHAR16 *ConfigHdr;\r | |
771 | CHAR16 *AccessProgress;\r | |
772 | CHAR16 *AccessResults;\r | |
773 | CHAR16 *String;\r | |
774 | UINTN Length;\r | |
775 | UINTN Offset;\r | |
776 | EFI_HANDLE ChildHandle;\r | |
777 | \r | |
778 | AccessResults = NULL;\r | |
779 | ConfigHdr = NULL;\r | |
780 | ConfigResp = NULL;\r | |
781 | NicConfig = NULL;\r | |
782 | ShellStatus = SHELL_SUCCESS;\r | |
783 | \r | |
784 | Status = GetChildHandle (NicInfo->Handle, &ChildHandle);\r | |
785 | if (EFI_ERROR (Status)) {\r | |
786 | //\r | |
787 | // If failed to get Child handle, try NIC controller handle for back-compatibility\r | |
788 | //\r | |
789 | ChildHandle = NicInfo->Handle;\r | |
790 | }\r | |
791 | //\r | |
792 | // Construct config request string header\r | |
793 | //\r | |
794 | ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r | |
795 | if (ConfigHdr != NULL) {\r | |
796 | Length = StrLen (ConfigHdr);\r | |
797 | } else {\r | |
798 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
799 | goto ON_EXIT;\r | |
800 | }\r | |
801 | ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);\r | |
802 | ConfigResp = AllocateZeroPool (ConfigRespBufferSize);\r | |
803 | if (ConfigResp == NULL) {\r | |
804 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
805 | goto ON_EXIT;\r | |
806 | }\r | |
807 | if (ConfigHdr != NULL) {\r | |
808 | StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r | |
809 | }\r | |
810 | \r | |
811 | NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r | |
812 | if (NicConfig == NULL) {\r | |
813 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
814 | goto ON_EXIT;\r | |
815 | }\r | |
816 | \r | |
817 | if (Config != NULL) {\r | |
818 | CopyMem (NicConfig, Config, sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * Config->Ip4Info.RouteTableSize);\r | |
819 | }\r | |
820 | \r | |
821 | //\r | |
822 | // Append OFFSET/WIDTH pair\r | |
823 | //\r | |
824 | String = ConfigResp + Length;\r | |
825 | Offset = 0;\r | |
826 | AppendOffsetWidthValue (String, \r | |
827 | ConfigRespBufferSize/sizeof(CHAR16) - Length,\r | |
828 | Offset, \r | |
829 | NIC_ITEM_CONFIG_SIZE, \r | |
830 | NULL\r | |
831 | );\r | |
832 | \r | |
833 | //\r | |
834 | // Call HII helper function to generate configuration string\r | |
835 | //\r | |
836 | Status = mHiiConfigRouting->BlockToConfig (\r | |
837 | mHiiConfigRouting,\r | |
838 | ConfigResp,\r | |
839 | (UINT8 *) NicConfig,\r | |
840 | NIC_ITEM_CONFIG_SIZE,\r | |
841 | &AccessResults,\r | |
842 | &AccessProgress\r | |
843 | );\r | |
844 | if (EFI_ERROR (Status)) {\r | |
845 | ShellStatus = SHELL_NOT_FOUND;\r | |
846 | goto ON_EXIT;\r | |
847 | }\r | |
848 | \r | |
849 | //\r | |
850 | // Set IP setting by HII servie\r | |
851 | //\r | |
852 | Status = mHiiConfigRouting->RouteConfig (\r | |
853 | mHiiConfigRouting,\r | |
854 | AccessResults,\r | |
855 | &AccessProgress\r | |
856 | );\r | |
857 | if (EFI_ERROR(Status)) {\r | |
858 | ShellStatus = SHELL_ACCESS_DENIED;\r | |
859 | }\r | |
860 | \r | |
861 | ON_EXIT:\r | |
862 | SHELL_FREE_NON_NULL(AccessResults);\r | |
863 | SHELL_FREE_NON_NULL(NicConfig);\r | |
864 | SHELL_FREE_NON_NULL(ConfigResp);\r | |
865 | SHELL_FREE_NON_NULL(ConfigHdr);\r | |
866 | \r | |
867 | return ShellStatus;\r | |
868 | }\r | |
869 | \r | |
870 | /**\r | |
871 | The callback function for the Arp address resolved event.\r | |
872 | \r | |
873 | @param[in] Event The event this function is registered to.\r | |
874 | @param[in] Context The context registered to the event.\r | |
875 | **/\r | |
876 | VOID\r | |
877 | EFIAPI\r | |
878 | IfconfigOnArpResolved (\r | |
879 | IN EFI_EVENT Event,\r | |
880 | IN VOID *Context\r | |
881 | )\r | |
882 | {\r | |
883 | ARP_REQUEST *Request;\r | |
884 | UINT8 Index;\r | |
885 | \r | |
886 | Request = (ARP_REQUEST *) Context;\r | |
887 | ASSERT (Request != NULL);\r | |
888 | \r | |
889 | Request->Duplicate = FALSE;\r | |
890 | \r | |
891 | if (0 == CompareMem (&Request->LocalMac, &Request->DestMac, Request->MacLen)) {\r | |
892 | ShellPrintHiiEx(\r | |
893 | -1, \r | |
894 | -1, \r | |
895 | NULL,\r | |
896 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
897 | gShellNetwork1HiiHandle, \r | |
898 | L"Already Configured",\r | |
899 | (UINTN)Request->DestIp.v4.Addr[0],\r | |
900 | (UINTN)Request->DestIp.v4.Addr[1],\r | |
901 | (UINTN)Request->DestIp.v4.Addr[2],\r | |
902 | (UINTN)Request->DestIp.v4.Addr[3]\r | |
903 | );\r | |
904 | ArpResolved = TRUE;\r | |
905 | return;\r | |
906 | }\r | |
907 | \r | |
908 | for (Index = 0; Index < Request->MacLen; Index++) {\r | |
909 | if (Request->DestMac.Addr[Index] != 0) {\r | |
910 | Request->Duplicate = TRUE;\r | |
911 | }\r | |
912 | }\r | |
913 | \r | |
914 | if (Request->Duplicate) {\r | |
915 | ShellPrintHiiEx(\r | |
916 | -1,\r | |
917 | -1,\r | |
918 | NULL,\r | |
919 | STRING_TOKEN(STR_IFCONFIG_CONF_IP_ADDR), \r | |
920 | gShellNetwork1HiiHandle, \r | |
921 | (UINTN)Request->DestMac.Addr[0], \r | |
922 | (UINTN)Request->DestMac.Addr[1], \r | |
923 | (UINTN)Request->DestMac.Addr[2],\r | |
924 | (UINTN)Request->DestMac.Addr[3], \r | |
925 | (UINTN)Request->DestMac.Addr[4], \r | |
926 | (UINTN)Request->DestMac.Addr[5]\r | |
927 | ); \r | |
928 | }\r | |
929 | \r | |
930 | ArpResolved = TRUE;\r | |
931 | return ;\r | |
932 | }\r | |
933 | \r | |
934 | /**\r | |
935 | Check whether the address to be configured conflicts with other hosts.\r | |
936 | \r | |
937 | @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.\r | |
938 | @param[in] IpAddr The IPv4 address to be configured to the Nic.\r | |
939 | \r | |
940 | @return TRUE Some other host already uses the IpAddr.\r | |
941 | @return FALSE The address is unused.\r | |
942 | **/\r | |
943 | BOOLEAN\r | |
944 | EFIAPI\r | |
945 | IfconfigIsIpDuplicate (\r | |
946 | IN NIC_INFO *NicInfo,\r | |
947 | IN IP4_ADDR IpAddr\r | |
948 | )\r | |
949 | {\r | |
950 | EFI_ARP_PROTOCOL *Arp;\r | |
951 | EFI_ARP_CONFIG_DATA ArpCfgData;\r | |
952 | EFI_HANDLE ArpHandle;\r | |
953 | ARP_REQUEST Request;\r | |
954 | EFI_STATUS Status;\r | |
955 | \r | |
956 | Arp = NULL;\r | |
957 | ArpHandle = NULL;\r | |
958 | ZeroMem (&Request, sizeof (ARP_REQUEST));\r | |
959 | \r | |
960 | Status = NetLibCreateServiceChild (\r | |
961 | NicInfo->Handle,\r | |
962 | gImageHandle, \r | |
963 | &gEfiArpServiceBindingProtocolGuid,\r | |
964 | &ArpHandle\r | |
965 | );\r | |
966 | \r | |
967 | if (EFI_ERROR (Status)) {\r | |
968 | return FALSE;\r | |
969 | }\r | |
970 | \r | |
971 | Status = gBS->OpenProtocol (\r | |
972 | ArpHandle,\r | |
973 | &gEfiArpProtocolGuid,\r | |
974 | (VOID**)&Arp,\r | |
975 | gImageHandle,\r | |
976 | ArpHandle,\r | |
977 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
978 | );\r | |
979 | \r | |
980 | if (EFI_ERROR (Status)) {\r | |
981 | goto ON_EXIT;\r | |
982 | }\r | |
983 | \r | |
984 | //\r | |
985 | // Set up the Arp requests\r | |
986 | //\r | |
987 | EFI_IP4_TO_U32 (Request.DestIp.v4) = IpAddr;\r | |
988 | EFI_IP4_TO_U32 (Request.LocalIp.v4) = 0xffffffff;\r | |
989 | Request.LocalMac = NicInfo->NicAddress.MacAddr;\r | |
990 | Request.MacLen = NicInfo->NicAddress.Len;\r | |
991 | \r | |
992 | Status = gBS->CreateEvent (\r | |
993 | EVT_NOTIFY_SIGNAL,\r | |
994 | TPL_CALLBACK,\r | |
995 | IfconfigOnArpResolved,\r | |
996 | (VOID *) &Request,\r | |
997 | &Request.OnResolved\r | |
998 | );\r | |
999 | \r | |
1000 | if (EFI_ERROR (Status)) {\r | |
1001 | goto ON_EXIT;\r | |
1002 | }\r | |
1003 | \r | |
1004 | ArpCfgData.SwAddressType = 0x0800;\r | |
1005 | ArpCfgData.SwAddressLength = 4;\r | |
1006 | ArpCfgData.StationAddress = &Request.LocalIp;\r | |
1007 | ArpCfgData.EntryTimeOut = 0;\r | |
1008 | ArpCfgData.RetryCount = 3;\r | |
1009 | ArpCfgData.RetryTimeOut = 0;\r | |
1010 | \r | |
1011 | Status = Arp->Configure (Arp, &ArpCfgData);\r | |
1012 | \r | |
1013 | if (EFI_ERROR (Status)) {\r | |
1014 | goto ON_EXIT;\r | |
1015 | }\r | |
1016 | \r | |
1017 | Status = Arp->Request (\r | |
1018 | Arp,\r | |
1019 | &Request.DestIp,\r | |
1020 | Request.OnResolved,\r | |
1021 | &Request.DestMac\r | |
1022 | );\r | |
1023 | \r | |
1024 | if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) {\r | |
1025 | goto ON_EXIT;\r | |
1026 | }\r | |
1027 | \r | |
1028 | while (!ArpResolved) {\r | |
1029 | \r | |
1030 | }\r | |
1031 | \r | |
1032 | ON_EXIT:\r | |
1033 | if (Request.OnResolved != NULL) {\r | |
1034 | gBS->CloseEvent (Request.OnResolved);\r | |
1035 | }\r | |
1036 | \r | |
1037 | NetLibDestroyServiceChild (\r | |
1038 | NicInfo->Handle, \r | |
1039 | gImageHandle, \r | |
1040 | &gEfiArpServiceBindingProtocolGuid, \r | |
1041 | ArpHandle\r | |
1042 | );\r | |
1043 | \r | |
1044 | return Request.Duplicate;\r | |
1045 | }\r | |
1046 | \r | |
1047 | /**\r | |
1048 | The callback function for the timer event used to get map.\r | |
1049 | \r | |
1050 | @param[in] Event The event this function is registered to.\r | |
1051 | @param[in] Context The context registered to the event.\r | |
1052 | **/\r | |
1053 | VOID\r | |
1054 | EFIAPI\r | |
1055 | TimeoutToGetMap (\r | |
1056 | IN EFI_EVENT Event,\r | |
1057 | IN VOID *Context\r | |
1058 | )\r | |
1059 | {\r | |
1060 | mTimeout = TRUE;\r | |
1061 | return ;\r | |
1062 | }\r | |
1063 | \r | |
1064 | /**\r | |
1065 | Create an IP child, use it to start the auto configuration, then destroy it.\r | |
1066 | \r | |
1067 | @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.\r | |
1068 | \r | |
1069 | @retval EFI_SUCCESS The configuration is done.\r | |
1070 | **/\r | |
1071 | EFI_STATUS\r | |
1072 | EFIAPI\r | |
1073 | IfconfigStartIp4(\r | |
1074 | IN NIC_INFO *NicInfo\r | |
1075 | )\r | |
1076 | {\r | |
1077 | EFI_IP4_PROTOCOL *Ip4;\r | |
1078 | EFI_HANDLE Ip4Handle;\r | |
1079 | EFI_HANDLE TimerToGetMap;\r | |
1080 | EFI_IP4_CONFIG_DATA Ip4ConfigData;\r | |
1081 | EFI_IP4_MODE_DATA Ip4Mode;\r | |
1082 | EFI_STATUS Status;\r | |
1083 | \r | |
1084 | //\r | |
1085 | // Get the Ip4ServiceBinding Protocol\r | |
1086 | //\r | |
1087 | Ip4Handle = NULL;\r | |
1088 | Ip4 = NULL;\r | |
1089 | TimerToGetMap = NULL;\r | |
1090 | \r | |
1091 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR), gShellNetwork1HiiHandle);\r | |
1092 | \r | |
1093 | Status = NetLibCreateServiceChild (\r | |
1094 | NicInfo->Handle,\r | |
1095 | gImageHandle,\r | |
1096 | &gEfiIp4ServiceBindingProtocolGuid,\r | |
1097 | &Ip4Handle\r | |
1098 | );\r | |
1099 | \r | |
1100 | if (EFI_ERROR (Status)) {\r | |
1101 | return Status;\r | |
1102 | }\r | |
1103 | \r | |
1104 | Status = gBS->OpenProtocol (\r | |
1105 | Ip4Handle,\r | |
1106 | &gEfiIp4ProtocolGuid,\r | |
1107 | (VOID **) &Ip4,\r | |
1108 | NicInfo->Handle,\r | |
1109 | gImageHandle,\r | |
1110 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1111 | );\r | |
1112 | \r | |
1113 | if (EFI_ERROR (Status)) {\r | |
1114 | goto ON_EXIT;\r | |
1115 | }\r | |
1116 | \r | |
1117 | Ip4ConfigData.DefaultProtocol = EFI_IP_PROTO_ICMP;\r | |
1118 | Ip4ConfigData.AcceptAnyProtocol = FALSE;\r | |
1119 | Ip4ConfigData.AcceptIcmpErrors = FALSE;\r | |
1120 | Ip4ConfigData.AcceptBroadcast = FALSE;\r | |
1121 | Ip4ConfigData.AcceptPromiscuous = FALSE;\r | |
1122 | Ip4ConfigData.UseDefaultAddress = TRUE;\r | |
1123 | ZeroMem (&Ip4ConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
1124 | ZeroMem (&Ip4ConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
1125 | Ip4ConfigData.TypeOfService = 0;\r | |
1126 | Ip4ConfigData.TimeToLive = 1;\r | |
1127 | Ip4ConfigData.DoNotFragment = FALSE;\r | |
1128 | Ip4ConfigData.RawData = FALSE;\r | |
1129 | Ip4ConfigData.ReceiveTimeout = 0;\r | |
1130 | Ip4ConfigData.TransmitTimeout = 0;\r | |
1131 | \r | |
1132 | Status = Ip4->Configure (Ip4, &Ip4ConfigData);\r | |
1133 | \r | |
1134 | if (Status == EFI_NO_MAPPING) {\r | |
1135 | mTimeout = FALSE;\r | |
1136 | Status = gBS->CreateEvent (\r | |
1137 | EVT_NOTIFY_SIGNAL | EVT_TIMER,\r | |
1138 | TPL_CALLBACK,\r | |
1139 | TimeoutToGetMap,\r | |
1140 | NULL,\r | |
1141 | &TimerToGetMap\r | |
1142 | );\r | |
1143 | \r | |
1144 | if (EFI_ERROR (Status)) {\r | |
1145 | goto ON_EXIT;\r | |
1146 | }\r | |
1147 | \r | |
1148 | Status = gBS->SetTimer (\r | |
1149 | TimerToGetMap,\r | |
1150 | TimerRelative,\r | |
1151 | MultU64x32 (SecondsToNanoSeconds, 5)\r | |
1152 | );\r | |
1153 | \r | |
1154 | if (EFI_ERROR (Status)) {\r | |
1155 | goto ON_EXIT;\r | |
1156 | }\r | |
1157 | \r | |
1158 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_WAIT_SET_DONE), gShellNetwork1HiiHandle);\r | |
1159 | \r | |
1160 | while (!mTimeout) {\r | |
1161 | Ip4->Poll (Ip4);\r | |
1162 | \r | |
1163 | if (!EFI_ERROR (Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL)) && \r | |
1164 | Ip4Mode.IsConfigured) { \r | |
1165 | break;\r | |
1166 | }\r | |
1167 | } \r | |
1168 | }\r | |
1169 | \r | |
1170 | Status = Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL);\r | |
1171 | \r | |
1172 | if ((Status == EFI_SUCCESS) && Ip4Mode.IsConfigured) {\r | |
1173 | ShellPrintHiiEx(\r | |
1174 | -1, \r | |
1175 | -1, \r | |
1176 | NULL,\r | |
1177 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
1178 | gShellNetwork1HiiHandle, \r | |
1179 | L"Default",\r | |
1180 | (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[0],\r | |
1181 | (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[1],\r | |
1182 | (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[2],\r | |
1183 | (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[3]\r | |
1184 | );\r | |
1185 | }\r | |
1186 | \r | |
1187 | ON_EXIT: \r | |
1188 | \r | |
1189 | if (EFI_ERROR (Status)) {\r | |
1190 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_DEF_ADDR_FAIL), gShellNetwork1HiiHandle);\r | |
1191 | }\r | |
1192 | \r | |
1193 | if (TimerToGetMap != NULL) {\r | |
1194 | gBS->SetTimer (TimerToGetMap, TimerCancel, 0);\r | |
1195 | gBS->CloseEvent (TimerToGetMap);\r | |
1196 | }\r | |
1197 | \r | |
1198 | NetLibDestroyServiceChild (\r | |
1199 | NicInfo->Handle,\r | |
1200 | gImageHandle,\r | |
1201 | &gEfiIp4ServiceBindingProtocolGuid,\r | |
1202 | Ip4Handle\r | |
1203 | );\r | |
1204 | \r | |
1205 | return Status;\r | |
1206 | }\r | |
1207 | \r | |
1208 | /**\r | |
1209 | Set the address for the nic specified by the params.\r | |
1210 | \r | |
1211 | @param[in] Argc The count of the passed in Params.\r | |
1212 | @param[in] Params The command line arguments for the set operation.\r | |
1213 | \r | |
1214 | @retval EFI_SUCCESS The address set operation is done.\r | |
1215 | @return Some error occurs.\r | |
1216 | **/\r | |
1217 | SHELL_STATUS\r | |
1218 | EFIAPI\r | |
1219 | IfconfigSetNicAddr (\r | |
1220 | IN UINTN Argc,\r | |
1221 | IN CONST CHAR16 *Params\r | |
1222 | )\r | |
1223 | {\r | |
1224 | NIC_IP4_CONFIG_INFO *Config;\r | |
1225 | NIC_IP4_CONFIG_INFO *OldConfig;\r | |
1226 | EFI_IP_ADDRESS Ip;\r | |
1227 | EFI_IP_ADDRESS Mask;\r | |
1228 | EFI_IP_ADDRESS Gateway;\r | |
1229 | NIC_INFO *Info;\r | |
1230 | BOOLEAN Permanent;\r | |
1231 | SHELL_STATUS ShellStatus;\r | |
1232 | CONST CHAR16 *Walker;\r | |
1233 | CHAR16 *Temp;\r | |
1234 | CONST CHAR16 *DhcpTemp;\r | |
1235 | CONST CHAR16 *StaticTemp;\r | |
1236 | CONST CHAR16 *PermTemp;\r | |
1237 | UINT32 NetworkBytes1;\r | |
1238 | UINT32 NetworkBytes2;\r | |
1239 | EFI_STATUS Status;\r | |
1240 | \r | |
1241 | Walker = Params;\r | |
1242 | Temp = NULL;\r | |
1243 | Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r | |
1244 | Info = IfconfigFindNicByName (Temp);\r | |
1245 | \r | |
1246 | if (Info == NULL) {\r | |
1247 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_NOT_FOUND), gShellNetwork1HiiHandle, Temp);\r | |
1248 | return SHELL_NOT_FOUND;\r | |
1249 | }\r | |
1250 | \r | |
1251 | Walker += StrLen(Temp) + 1;\r | |
1252 | FreePool(Temp);\r | |
1253 | Temp = NULL;\r | |
1254 | Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")==NULL?0:StrStr(Walker, L" ")-Walker);\r | |
1255 | \r | |
1256 | Config = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE));\r | |
1257 | if (Config == NULL) {\r | |
1258 | return SHELL_OUT_OF_RESOURCES;\r | |
1259 | }\r | |
1260 | \r | |
1261 | Config->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (Config + 1);\r | |
1262 | \r | |
1263 | OldConfig = Info->ConfigInfo;\r | |
1264 | Permanent = FALSE;\r | |
1265 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
1266 | \r | |
1267 | DhcpTemp = DhcpString;\r | |
1268 | StaticTemp = StaticString;\r | |
1269 | \r | |
1270 | if (StringNoCaseCompare(&Temp, &DhcpTemp) == 0) {\r | |
1271 | //\r | |
1272 | // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP permanent\r | |
1273 | //\r | |
1274 | if ((Argc != 2) && (Argc!= 3)) {\r | |
1275 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp); \r | |
1276 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1277 | goto ON_EXIT;\r | |
1278 | }\r | |
1279 | \r | |
1280 | if (Argc == 3) {\r | |
1281 | Walker += StrLen(Temp) + 1;\r | |
1282 | FreePool(Temp);\r | |
1283 | Temp = NULL;\r | |
1284 | Temp = StrnCatGrow(&Temp, NULL, Walker, 0);\r | |
1285 | \r | |
1286 | PermTemp = PermanentString;\r | |
1287 | if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {\r | |
1288 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing"); \r | |
1289 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1290 | goto ON_EXIT;\r | |
1291 | }\r | |
1292 | \r | |
1293 | Permanent = TRUE;\r | |
1294 | }\r | |
1295 | \r | |
1296 | if ((OldConfig != NULL) && (OldConfig->Source == IP4_CONFIG_SOURCE_DHCP) &&\r | |
1297 | (OldConfig->Permanent == Permanent)) {\r | |
1298 | \r | |
1299 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED), gShellNetwork1HiiHandle, Info->Name);\r | |
1300 | ShellStatus = SHELL_ALREADY_STARTED;\r | |
1301 | goto ON_EXIT;\r | |
1302 | }\r | |
1303 | \r | |
1304 | Config->Source = IP4_CONFIG_SOURCE_DHCP;\r | |
1305 | } else if (StringNoCaseCompare(&Temp, &StaticTemp) == 0) {\r | |
1306 | //\r | |
1307 | // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and\r | |
1308 | // eth0 static IP NETMASK GATEWAY permanent \r | |
1309 | //\r | |
1310 | if ((Argc != 5) && (Argc != 6)) {\r | |
1311 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp); \r | |
1312 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1313 | goto ON_EXIT;\r | |
1314 | }\r | |
1315 | \r | |
1316 | Walker += StrLen(Temp) + 1;\r | |
1317 | FreePool(Temp);\r | |
1318 | Temp = NULL;\r | |
1319 | Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r | |
1320 | \r | |
1321 | if (EFI_ERROR (NetLibStrToIp4 (Temp, &Ip.v4))) {\r | |
1322 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);\r | |
1323 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1324 | goto ON_EXIT;\r | |
1325 | }\r | |
1326 | \r | |
1327 | Walker += StrLen(Temp) + 1;\r | |
1328 | FreePool(Temp);\r | |
1329 | Temp = NULL;\r | |
1330 | Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r | |
1331 | if (EFI_ERROR (NetLibStrToIp4 (Temp, &Mask.v4))) {\r | |
1332 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);\r | |
1333 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1334 | goto ON_EXIT;\r | |
1335 | }\r | |
1336 | \r | |
1337 | Walker += StrLen(Temp) + 1;\r | |
1338 | FreePool(Temp);\r | |
1339 | Temp = NULL;\r | |
1340 | if (Argc == 6) {\r | |
1341 | Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r | |
1342 | } else {\r | |
1343 | Temp = StrnCatGrow(&Temp, NULL, Walker, 0);\r | |
1344 | }\r | |
1345 | if (EFI_ERROR (NetLibStrToIp4 (Temp, &Gateway.v4))) {\r | |
1346 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);\r | |
1347 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1348 | goto ON_EXIT;\r | |
1349 | }\r | |
1350 | \r | |
1351 | if (Argc == 6) {\r | |
1352 | Walker += StrLen(Temp) + 1;\r | |
1353 | FreePool(Temp);\r | |
1354 | Temp = NULL;\r | |
1355 | Temp = StrnCatGrow(&Temp, NULL, Walker, 0);\r | |
1356 | \r | |
1357 | PermTemp = PermanentString;\r | |
1358 | if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {\r | |
1359 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing"); \r | |
1360 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1361 | goto ON_EXIT;\r | |
1362 | }\r | |
1363 | \r | |
1364 | Permanent = TRUE;\r | |
1365 | }\r | |
1366 | \r | |
1367 | NetworkBytes1 = NTOHL (Ip.Addr[0]);\r | |
1368 | NetworkBytes2 = NTOHL (Mask.Addr[0]);\r | |
1369 | if ((Ip.Addr[0] == 0) || (Mask.Addr[0] == 0) ||\r | |
1370 | !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {\r | |
1371 | \r | |
1372 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_ADDR_PAIR), gShellNetwork1HiiHandle);\r | |
1373 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1374 | goto ON_EXIT;\r | |
1375 | }\r | |
1376 | \r | |
1377 | NetworkBytes1 = NTOHL (Gateway.Addr[0]);\r | |
1378 | if (!IP4_NET_EQUAL (Ip.Addr[0], Gateway.Addr[0], Mask.Addr[0]) ||\r | |
1379 | !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {\r | |
1380 | \r | |
1381 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY), gShellNetwork1HiiHandle);\r | |
1382 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1383 | goto ON_EXIT;\r | |
1384 | }\r | |
1385 | \r | |
1386 | //\r | |
1387 | // Set the configuration up, two route table entries are added:\r | |
1388 | // one for the direct connected network, and another for the \r | |
1389 | // default gateway. Remember, some structure members are cleared\r | |
1390 | // by AllocateZeroPool\r | |
1391 | //\r | |
1392 | Config->Source = IP4_CONFIG_SOURCE_STATIC;\r | |
1393 | Config->Ip4Info.RouteTableSize = 2;\r | |
1394 | \r | |
1395 | CopyMem (&Config->Ip4Info.StationAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
1396 | CopyMem (&Config->Ip4Info.SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
1397 | \r | |
1398 | Ip.Addr[0] = Ip.Addr[0] & Mask.Addr[0];\r | |
1399 | \r | |
1400 | CopyMem (&Config->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
1401 | CopyMem (&Config->Ip4Info.RouteTable[0].SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
1402 | CopyMem (&Config->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
1403 | } else {\r | |
1404 | // neither static or DHCP. error.\r | |
1405 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig"); \r | |
1406 | ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r | |
1407 | goto ON_EXIT;\r | |
1408 | }\r | |
1409 | \r | |
1410 | CopyMem (&Config->NicAddr, &Info->NicAddress, sizeof (NIC_ADDR));\r | |
1411 | Config->Permanent = Permanent;\r | |
1412 | \r | |
1413 | //\r | |
1414 | // Use HII service to set NIC address\r | |
1415 | //\r | |
1416 | ShellStatus = IfconfigSetNicAddrByHii (Info, Config);\r | |
1417 | if (ShellStatus != SHELL_SUCCESS) {\r | |
1418 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_SET_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);\r | |
1419 | goto ON_EXIT;\r | |
1420 | } \r | |
1421 | \r | |
1422 | Status = IfconfigStartIp4 (Info);\r | |
1423 | if (EFI_ERROR(Status)) {\r | |
1424 | ShellStatus = SHELL_ACCESS_DENIED;\r | |
1425 | }\r | |
1426 | \r | |
1427 | if (ShellStatus != SHELL_SUCCESS) {\r | |
1428 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_IP_CHILD_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);\r | |
1429 | }\r | |
1430 | \r | |
1431 | ON_EXIT:\r | |
1432 | SHELL_FREE_NON_NULL(Config);\r | |
1433 | \r | |
1434 | return ShellStatus;\r | |
1435 | }\r | |
1436 | \r | |
1437 | /**\r | |
1438 | Show the address information for the nic specified.\r | |
1439 | \r | |
1440 | @param[in] Name A pointer to the string containg the nic's name, if NULL, \r | |
1441 | all nics' information is shown.\r | |
1442 | **/\r | |
1443 | VOID\r | |
1444 | EFIAPI\r | |
1445 | IfconfigShowNicInfo (\r | |
1446 | IN CONST CHAR16 *Name\r | |
1447 | )\r | |
1448 | {\r | |
1449 | LIST_ENTRY *Entry;\r | |
1450 | LIST_ENTRY *NextEntry;\r | |
1451 | NIC_INFO *NicInfo;\r | |
1452 | UINT32 Index;\r | |
1453 | EFI_IP4_IPCONFIG_DATA *Ip4Config;\r | |
1454 | EFI_IPv4_ADDRESS Gateway;\r | |
1455 | CONST CHAR16 *TempString;\r | |
1456 | \r | |
1457 | NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {\r | |
1458 | NicInfo = BASE_CR (Entry, NIC_INFO, Link);\r | |
1459 | \r | |
1460 | TempString = (CHAR16*)NicInfo->Name;\r | |
1461 | if ((Name != NULL) && (StringNoCaseCompare (&Name, &TempString) != 0)) {\r | |
1462 | continue;\r | |
1463 | }\r | |
1464 | \r | |
1465 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NAME), gShellNetwork1HiiHandle, NicInfo->Name);\r | |
1466 | \r | |
1467 | ShellPrintHiiEx(\r | |
1468 | -1,\r | |
1469 | -1,\r | |
1470 | NULL,\r | |
1471 | STRING_TOKEN(STR_IFCONFIG_SHOW_MAC_ADDR), \r | |
1472 | gShellNetwork1HiiHandle, \r | |
1473 | (UINTN)NicInfo->NicAddress.MacAddr.Addr[0], \r | |
1474 | (UINTN)NicInfo->NicAddress.MacAddr.Addr[1], \r | |
1475 | (UINTN)NicInfo->NicAddress.MacAddr.Addr[2],\r | |
1476 | (UINTN)NicInfo->NicAddress.MacAddr.Addr[3], \r | |
1477 | (UINTN)NicInfo->NicAddress.MacAddr.Addr[4], \r | |
1478 | (UINTN)NicInfo->NicAddress.MacAddr.Addr[5]\r | |
1479 | ); \r | |
1480 | \r | |
1481 | Print (L" Media State: %s\n", NicInfo->MediaPresent ? L"Media present" : L"Media disconnected");\r | |
1482 | \r | |
1483 | if (NicInfo->ConfigInfo == NULL) {\r | |
1484 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NOT_CONFIGURED), gShellNetwork1HiiHandle);\r | |
1485 | continue;\r | |
1486 | } \r | |
1487 | \r | |
1488 | if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_DHCP) {\r | |
1489 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"DHCP");\r | |
1490 | } else if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_STATIC) {\r | |
1491 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"STATIC");\r | |
1492 | } else {\r | |
1493 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"Unknown");\r | |
1494 | }\r | |
1495 | \r | |
1496 | ShellPrintHiiEx(-1, -1, NULL,\r | |
1497 | STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS),\r | |
1498 | gShellNetwork1HiiHandle,\r | |
1499 | (NicInfo->ConfigInfo->Permanent? L"TRUE":L"FALSE")\r | |
1500 | );\r | |
1501 | \r | |
1502 | Ip4Config = &NicInfo->ConfigInfo->Ip4Info;\r | |
1503 | \r | |
1504 | ShellPrintHiiEx(\r | |
1505 | -1, \r | |
1506 | -1, \r | |
1507 | NULL,\r | |
1508 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
1509 | gShellNetwork1HiiHandle, \r | |
1510 | L"IP address",\r | |
1511 | (UINTN)Ip4Config->StationAddress.Addr[0],\r | |
1512 | (UINTN)Ip4Config->StationAddress.Addr[1],\r | |
1513 | (UINTN)Ip4Config->StationAddress.Addr[2],\r | |
1514 | (UINTN)Ip4Config->StationAddress.Addr[3]\r | |
1515 | );\r | |
1516 | ShellPrintHiiEx(\r | |
1517 | -1, \r | |
1518 | -1, \r | |
1519 | NULL,\r | |
1520 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
1521 | gShellNetwork1HiiHandle, \r | |
1522 | L"Mask",\r | |
1523 | (UINTN)Ip4Config->SubnetMask.Addr[0],\r | |
1524 | (UINTN)Ip4Config->SubnetMask.Addr[1],\r | |
1525 | (UINTN)Ip4Config->SubnetMask.Addr[2],\r | |
1526 | (UINTN)Ip4Config->SubnetMask.Addr[3]\r | |
1527 | );\r | |
1528 | \r | |
1529 | ZeroMem (&Gateway, sizeof (EFI_IPv4_ADDRESS));\r | |
1530 | \r | |
1531 | for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {\r | |
1532 | if ((CompareMem (&Ip4Config->RouteTable[Index].SubnetAddress, &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) &&\r | |
1533 | (CompareMem (&Ip4Config->RouteTable[Index].SubnetMask , &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) ){\r | |
1534 | CopyMem (&Gateway, &Ip4Config->RouteTable[Index].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
1535 | }\r | |
1536 | }\r | |
1537 | \r | |
1538 | ShellPrintHiiEx(\r | |
1539 | -1, \r | |
1540 | -1, \r | |
1541 | NULL,\r | |
1542 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
1543 | gShellNetwork1HiiHandle, \r | |
1544 | L"Gateway",\r | |
1545 | (UINTN)Gateway.Addr[0],\r | |
1546 | (UINTN)Gateway.Addr[1],\r | |
1547 | (UINTN)Gateway.Addr[2],\r | |
1548 | (UINTN)Gateway.Addr[3]\r | |
1549 | );\r | |
1550 | \r | |
1551 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE), gShellNetwork1HiiHandle, Ip4Config->RouteTableSize);\r | |
1552 | \r | |
1553 | for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {\r | |
1554 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX), gShellNetwork1HiiHandle, Index);\r | |
1555 | \r | |
1556 | ShellPrintHiiEx(\r | |
1557 | -1, \r | |
1558 | -1, \r | |
1559 | NULL,\r | |
1560 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
1561 | gShellNetwork1HiiHandle, \r | |
1562 | L"Subnet",\r | |
1563 | (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[0],\r | |
1564 | (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[1],\r | |
1565 | (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[2],\r | |
1566 | (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[3]\r | |
1567 | );\r | |
1568 | \r | |
1569 | ShellPrintHiiEx(\r | |
1570 | -1, \r | |
1571 | -1, \r | |
1572 | NULL,\r | |
1573 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
1574 | gShellNetwork1HiiHandle, \r | |
1575 | L"Netmask",\r | |
1576 | (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[0],\r | |
1577 | (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[1],\r | |
1578 | (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[2],\r | |
1579 | (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[3]\r | |
1580 | );\r | |
1581 | \r | |
1582 | ShellPrintHiiEx(\r | |
1583 | -1, \r | |
1584 | -1, \r | |
1585 | NULL,\r | |
1586 | STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r | |
1587 | gShellNetwork1HiiHandle, \r | |
1588 | L"Gateway",\r | |
1589 | (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[0],\r | |
1590 | (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[1],\r | |
1591 | (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[2],\r | |
1592 | (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[3]\r | |
1593 | );\r | |
1594 | }\r | |
1595 | }\r | |
1596 | \r | |
1597 | return ;\r | |
1598 | }\r | |
1599 | \r | |
1600 | /**\r | |
1601 | Clear address configuration for the nic specified.\r | |
1602 | \r | |
1603 | @param[in] Name A pointer to the string containg the nic's name, \r | |
1604 | if NULL, all nics address configurations are cleared.\r | |
1605 | \r | |
1606 | @retval EFI_SUCCESS The address configuration is cleared.\r | |
1607 | @return Some error occurs.\r | |
1608 | **/\r | |
1609 | EFI_STATUS\r | |
1610 | EFIAPI\r | |
1611 | IfconfigClearNicAddr (\r | |
1612 | IN CONST CHAR16 *Name\r | |
1613 | )\r | |
1614 | {\r | |
1615 | LIST_ENTRY *Entry;\r | |
1616 | LIST_ENTRY *NextEntry;\r | |
1617 | NIC_INFO *Info;\r | |
1618 | EFI_STATUS Status;\r | |
1619 | \r | |
1620 | NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {\r | |
1621 | Info = BASE_CR (Entry, NIC_INFO, Link);\r | |
1622 | \r | |
1623 | if ((Name != NULL) && (StrCmp (Name, Info->Name) != 0)) {\r | |
1624 | continue;\r | |
1625 | }\r | |
1626 | \r | |
1627 | // if (Info->NicIp4Config == NULL) { \r | |
1628 | Status = IfconfigSetNicAddrByHii (Info, NULL);\r | |
1629 | // } else {\r | |
1630 | // Status = Info->NicIp4Config->SetInfo (Info->NicIp4Config, NULL, TRUE);\r | |
1631 | // }\r | |
1632 | \r | |
1633 | if (EFI_ERROR (Status)) {\r | |
1634 | return Status;\r | |
1635 | }\r | |
1636 | }\r | |
1637 | \r | |
1638 | return EFI_SUCCESS;\r | |
1639 | \r | |
1640 | }\r | |
1641 | \r | |
1642 | /**\r | |
1643 | Function for 'ifconfig' command.\r | |
1644 | \r | |
1645 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
1646 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
1647 | **/\r | |
1648 | SHELL_STATUS\r | |
1649 | EFIAPI\r | |
1650 | ShellCommandRunIfconfig (\r | |
1651 | IN EFI_HANDLE ImageHandle,\r | |
1652 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1653 | )\r | |
1654 | {\r | |
1655 | EFI_STATUS Status;\r | |
1656 | LIST_ENTRY *Package;\r | |
1657 | CHAR16 *ProblemParam;\r | |
1658 | SHELL_STATUS ShellStatus;\r | |
1659 | BOOLEAN ListOperation;\r | |
1660 | BOOLEAN ClearOperation;\r | |
1661 | BOOLEAN SetOperation;\r | |
1662 | CONST CHAR16 *Item;\r | |
1663 | LIST_ENTRY *Entry;\r | |
1664 | NIC_INFO *Info;\r | |
1665 | \r | |
1666 | InitializeListHead (&NicInfoList);\r | |
1667 | Status = EFI_INVALID_PARAMETER;\r | |
1668 | ShellStatus = SHELL_SUCCESS;\r | |
1669 | \r | |
1670 | //\r | |
1671 | // initialize the shell lib (we must be in non-auto-init...)\r | |
1672 | //\r | |
1673 | Status = ShellInitialize();\r | |
1674 | ASSERT_EFI_ERROR(Status);\r | |
1675 | \r | |
1676 | //\r | |
1677 | // parse the command line\r | |
1678 | //\r | |
1679 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r | |
1680 | if (EFI_ERROR(Status)) {\r | |
1681 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
1682 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellNetwork1HiiHandle, L"ifconfig", ProblemParam); \r | |
1683 | FreePool(ProblemParam);\r | |
1684 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
1685 | } else {\r | |
1686 | ASSERT(FALSE);\r | |
1687 | }\r | |
1688 | \r | |
1689 | goto Done;\r | |
1690 | }\r | |
1691 | \r | |
1692 | ClearOperation = ShellCommandLineGetFlag(Package, L"-c");\r | |
1693 | ListOperation = ShellCommandLineGetFlag(Package, L"-l");\r | |
1694 | SetOperation = ShellCommandLineGetFlag(Package, L"-s");\r | |
1695 | \r | |
1696 | if ((ClearOperation && ListOperation)\r | |
1697 | ||(SetOperation && ListOperation)\r | |
1698 | ||(ClearOperation && SetOperation)\r | |
1699 | ) {\r | |
1700 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle, L"ifconfig"); \r | |
1701 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
1702 | goto Done;\r | |
1703 | } else if (!ClearOperation && !ListOperation && !SetOperation) {\r | |
1704 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig"); \r | |
1705 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
1706 | goto Done;\r | |
1707 | }\r | |
1708 | \r | |
1709 | \r | |
1710 | Status = IfconfigGetAllNicInfoByHii ();\r | |
1711 | if (EFI_ERROR (Status)) {\r | |
1712 | if (mIp4ConfigExist) {\r | |
1713 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL), gShellNetwork1HiiHandle, Status);\r | |
1714 | } else {\r | |
1715 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellNetwork1HiiHandle, L"ifconfig", L"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid); \r | |
1716 | }\r | |
1717 | \r | |
1718 | return SHELL_NOT_FOUND;\r | |
1719 | }\r | |
1720 | \r | |
1721 | if (ListOperation) {\r | |
1722 | Item = ShellCommandLineGetValue (Package, L"-l");\r | |
1723 | \r | |
1724 | if (Item != NULL && CountSubItems(Item) > 1) {\r | |
1725 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-l"); \r | |
1726 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
1727 | goto Done;\r | |
1728 | } \r | |
1729 | \r | |
1730 | //\r | |
1731 | // Show the configuration.\r | |
1732 | //\r | |
1733 | IfconfigShowNicInfo (Item);\r | |
1734 | } else if (SetOperation) {\r | |
1735 | Item = ShellCommandLineGetValue (Package, L"-s");\r | |
1736 | \r | |
1737 | //\r | |
1738 | // The correct command line arguments for setting address are:\r | |
1739 | // IfConfig -s eth0 DHCP [permanent]\r | |
1740 | // IfConfig -s eth0 static ip netmask gateway [permanent]\r | |
1741 | //\r | |
1742 | if (Item == NULL || (CountSubItems(Item) < 2) || (CountSubItems(Item) > 6) || (CountSubItems(Item) == 4)) {\r | |
1743 | ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_NO_VALUE), gShellNetwork1HiiHandle, L"ifconfig", L"-s"); \r | |
1744 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
1745 | goto Done;\r | |
1746 | }\r | |
1747 | \r | |
1748 | ShellStatus = IfconfigSetNicAddr (CountSubItems(Item), Item);\r | |
1749 | } else if (ClearOperation) {\r | |
1750 | Item = ShellCommandLineGetValue (Package, L"-c");\r | |
1751 | \r | |
1752 | if (Item != NULL && CountSubItems(Item) > 1) {\r | |
1753 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-c"); \r | |
1754 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
1755 | goto Done;\r | |
1756 | }\r | |
1757 | \r | |
1758 | IfconfigClearNicAddr (Item);\r | |
1759 | } else {\r | |
1760 | ASSERT(FALSE);\r | |
1761 | }\r | |
1762 | \r | |
1763 | Done:\r | |
1764 | while (!IsListEmpty (&NicInfoList)) {\r | |
1765 | Entry = NicInfoList.ForwardLink;\r | |
1766 | Info = BASE_CR (Entry, NIC_INFO, Link);\r | |
1767 | \r | |
1768 | RemoveEntryList (Entry);\r | |
1769 | \r | |
1770 | if (Info->ConfigInfo != NULL) {\r | |
1771 | FreePool (Info->ConfigInfo);\r | |
1772 | }\r | |
1773 | \r | |
1774 | FreePool (Info);\r | |
1775 | }\r | |
1776 | \r | |
1777 | if (Package != NULL) {\r | |
1778 | ShellCommandLineFreeVarList(Package);\r | |
1779 | }\r | |
1780 | \r | |
1781 | return (ShellStatus);\r | |
1782 | }\r |