/** @file\r
Network library.\r
\r
-Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
#include <Uefi.h>\r
\r
+#include <IndustryStandard/SmBios.h>\r
+\r
#include <Protocol/DriverBinding.h>\r
#include <Protocol/ServiceBinding.h>\r
#include <Protocol/SimpleNetwork.h>\r
#include <Protocol/HiiConfigAccess.h>\r
\r
#include <Guid/NicIp4ConfigNvData.h>\r
+#include <Guid/SmBios.h>\r
\r
#include <Library/NetLib.h>\r
#include <Library/BaseLib.h>\r
(VOID **) &Mnp\r
);\r
if (EFI_ERROR (Status)) {\r
+ MnpSb->DestroyChild (MnpSb, MnpChildHandle);\r
return Status;\r
}\r
\r
//\r
Status = Mnp->GetModeData (Mnp, NULL, &SnpModeData);\r
if (EFI_ERROR (Status)) {\r
+ MnpSb->DestroyChild (MnpSb, MnpChildHandle);\r
return Status;\r
}\r
SnpMode = &SnpModeData;\r
\r
The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.\r
The header subtype of IPv4 device path node is MSG_IPv4_DP.\r
- The length of the IPv4 device path node in bytes is 19.\r
Get other info from parameters to make up the whole IPv4 device path node.\r
\r
@param[in, out] Node Pointer to the IPv4 device path node.\r
{\r
Node->Header.Type = MESSAGING_DEVICE_PATH;\r
Node->Header.SubType = MSG_IPv4_DP;\r
- SetDevicePathNodeLength (&Node->Header, 19);\r
+ SetDevicePathNodeLength (&Node->Header, sizeof (IPv4_DEVICE_PATH));\r
\r
CopyMem (&Node->LocalIpAddress, &LocalIp, sizeof (EFI_IPv4_ADDRESS));\r
CopyMem (&Node->RemoteIpAddress, &RemoteIp, sizeof (EFI_IPv4_ADDRESS));\r
} else {\r
Node->StaticIpAddress = NetLibDefaultAddressIsStatic (Controller);\r
}\r
+\r
+ //\r
+ // Set the Gateway IP address to default value 0:0:0:0.\r
+ // Set the Subnet mask to default value 255:255:255:0.\r
+ //\r
+ ZeroMem (&Node->GatewayIpAddress, sizeof (EFI_IPv4_ADDRESS));\r
+ SetMem (&Node->SubnetMask, sizeof (EFI_IPv4_ADDRESS), 0xff);\r
+ Node->SubnetMask.Addr[3] = 0;\r
}\r
\r
/**\r
Node->RemotePort = RemotePort;\r
\r
Node->Protocol = Protocol;\r
- Node->StaticIpAddress = FALSE;\r
+\r
+ //\r
+ // Set default value to IPAddressOrigin, PrefixLength.\r
+ // Set the Gateway IP address to unspecified address.\r
+ //\r
+ Node->IpAddressOrigin = 0;\r
+ Node->PrefixLength = IP6_PREFIX_LENGTH;\r
+ ZeroMem (&Node->GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));\r
}\r
\r
/**\r
LeadZeroCnt++;\r
}\r
} else {\r
- if ((Cnt == 4) && (*TempStr == '0') && (LeadZero == FALSE)) {\r
+ if ((Cnt == 4) && (*TempStr == '0') && !LeadZero) {\r
return EFI_INVALID_PARAMETER;\r
}\r
- if ((Cnt != 0) && (Cnt < 4) && (LeadZero == TRUE)) {\r
+ if ((Cnt != 0) && (Cnt < 4) && LeadZero) {\r
return EFI_INVALID_PARAMETER;\r
}\r
} \r
return Status;\r
}\r
\r
+\r
+\r
+/**\r
+ This function obtains the system guid from the smbios table.\r
+\r
+ @param[out] SystemGuid The pointer of the returned system guid.\r
+\r
+ @retval EFI_SUCCESS Successfully obtained the system guid.\r
+ @retval EFI_NOT_FOUND Did not find the SMBIOS table.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+NetLibGetSystemGuid (\r
+ OUT EFI_GUID *SystemGuid\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;\r
+ SMBIOS_STRUCTURE_POINTER Smbios;\r
+ SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r
+ CHAR8 *String;\r
+\r
+ SmbiosTable = NULL;\r
+ Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable);\r
+\r
+ if (EFI_ERROR (Status) || SmbiosTable == NULL) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;\r
+ SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);\r
+\r
+ do {\r
+ if (Smbios.Hdr->Type == 1) {\r
+ if (Smbios.Hdr->Length < 0x19) {\r
+ //\r
+ // Older version did not support UUID.\r
+ //\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ \r
+ //\r
+ // SMBIOS tables are byte packed so we need to do a byte copy to\r
+ // prevend alignment faults on Itanium-based platform.\r
+ //\r
+ CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof (EFI_GUID));\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // Go to the next SMBIOS structure. Each SMBIOS structure may include 2 parts:\r
+ // 1. Formatted section; 2. Unformatted string section. So, 2 steps are needed\r
+ // to skip one SMBIOS structure.\r
+ //\r
+ \r
+ //\r
+ // Step 1: Skip over formatted section.\r
+ //\r
+ String = (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length);\r
+ \r
+ //\r
+ // Step 2: Skip over unformated string section.\r
+ //\r
+ do {\r
+ //\r
+ // Each string is terminated with a NULL(00h) BYTE and the sets of strings\r
+ // is terminated with an additional NULL(00h) BYTE.\r
+ //\r
+ for ( ; *String != 0; String++) {\r
+ }\r
+\r
+ if (*(UINT8*)++String == 0) {\r
+ //\r
+ // Pointer to the next SMBIOS structure.\r
+ //\r
+ Smbios.Raw = (UINT8 *)++String;\r
+ break;\r
+ } \r
+ } while (TRUE);\r
+ } while (Smbios.Raw < SmbiosEnd.Raw);\r
+ return EFI_NOT_FOUND;\r
+}\r