X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FLibrary%2FDxeNetLib%2FDxeNetLib.c;h=fd4a9e15a892cb26f3d94dfdca95705f6e0cab1f;hb=d1050b9dff1cace252aff86630bfdb59dff5f507;hp=41e8b30e36a4c711c0d3a22b2e8a48b46f109d68;hpb=2f88bd3a1296c522317f1c21377876de63de5be7;p=mirror_edk2.git diff --git a/NetworkPkg/Library/DxeNetLib/DxeNetLib.c b/NetworkPkg/Library/DxeNetLib/DxeNetLib.c index 41e8b30e36..fd4a9e15a8 100644 --- a/NetworkPkg/Library/DxeNetLib/DxeNetLib.c +++ b/NetworkPkg/Library/DxeNetLib/DxeNetLib.c @@ -32,8 +32,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include -#define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE) -#define DEFAULT_ZERO_START ((UINTN) ~0) +#define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE) +#define DEFAULT_ZERO_START ((UINTN) ~0) // // All the supported IP4 masks in host byte order. @@ -77,25 +77,27 @@ GLOBAL_REMOVE_IF_UNREFERENCED IP4_ADDR gIp4AllMasks[IP4_MASK_NUM] = { 0xFFFFFFFF, }; -GLOBAL_REMOVE_IF_UNREFERENCED EFI_IPv4_ADDRESS mZeroIp4Addr = {{0, 0, 0, 0}}; +GLOBAL_REMOVE_IF_UNREFERENCED EFI_IPv4_ADDRESS mZeroIp4Addr = { + { 0, 0, 0, 0 } +}; // // Any error level digitally larger than mNetDebugLevelMax // will be silently discarded. // -GLOBAL_REMOVE_IF_UNREFERENCED UINTN mNetDebugLevelMax = NETDEBUG_LEVEL_ERROR; -GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogPacketSeq = 0xDEADBEEF; +GLOBAL_REMOVE_IF_UNREFERENCED UINTN mNetDebugLevelMax = NETDEBUG_LEVEL_ERROR; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogPacketSeq = 0xDEADBEEF; // // You can change mSyslogDstMac mSyslogDstIp and mSyslogSrcIp // here to direct the syslog packets to the syslog deamon. The // default is broadcast to both the ethernet and IP. // -GLOBAL_REMOVE_IF_UNREFERENCED UINT8 mSyslogDstMac[NET_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogDstIp = 0xffffffff; -GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogSrcIp = 0; +GLOBAL_REMOVE_IF_UNREFERENCED UINT8 mSyslogDstMac[NET_ETHER_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogDstIp = 0xffffffff; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogSrcIp = 0; -GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mMonthName[] = { +GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mMonthName[] = { "Jan", "Feb", "Mar", @@ -113,13 +115,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mMonthName[] = { // // VLAN device path node template // -GLOBAL_REMOVE_IF_UNREFERENCED VLAN_DEVICE_PATH mNetVlanDevicePathTemplate = { +GLOBAL_REMOVE_IF_UNREFERENCED VLAN_DEVICE_PATH mNetVlanDevicePathTemplate = { { MESSAGING_DEVICE_PATH, MSG_VLAN_DP, { - (UINT8) (sizeof (VLAN_DEVICE_PATH)), - (UINT8) ((sizeof (VLAN_DEVICE_PATH)) >> 8) + (UINT8)(sizeof (VLAN_DEVICE_PATH)), + (UINT8)((sizeof (VLAN_DEVICE_PATH)) >> 8) } }, 0 @@ -138,11 +140,11 @@ SyslogLocateSnp ( VOID ) { - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - EFI_STATUS Status; - EFI_HANDLE *Handles; - UINTN HandleCount; - UINTN Index; + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN HandleCount; + UINTN Index; // // Locate the handles which has SNP installed. @@ -169,13 +171,13 @@ SyslogLocateSnp ( Status = gBS->HandleProtocol ( Handles[Index], &gEfiSimpleNetworkProtocolGuid, - (VOID **) &Snp + (VOID **)&Snp ); if ((Status == EFI_SUCCESS) && (Snp != NULL) && (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) && - (Snp->Mode->MaxPacketSize >= NET_SYSLOG_PACKET_LEN)) { - + (Snp->Mode->MaxPacketSize >= NET_SYSLOG_PACKET_LEN)) + { break; } @@ -204,15 +206,15 @@ SyslogLocateSnp ( **/ EFI_STATUS SyslogSendPacket ( - IN CHAR8 *Packet, - IN UINT32 Length + IN CHAR8 *Packet, + IN UINT32 Length ) { - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - ETHER_HEAD *Ether; - EFI_STATUS Status; - EFI_EVENT TimeoutEvent; - UINT8 *TxBuf; + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + ETHER_HEAD *Ether; + EFI_STATUS Status; + EFI_EVENT TimeoutEvent; + UINT8 *TxBuf; ASSERT (Packet != NULL); @@ -222,7 +224,7 @@ SyslogSendPacket ( return EFI_DEVICE_ERROR; } - Ether = (ETHER_HEAD *) Packet; + Ether = (ETHER_HEAD *)Packet; CopyMem (Ether->SrcMac, Snp->Mode->CurrentAddress.Addr, NET_ETHER_ADDR_LEN); // @@ -246,7 +248,7 @@ SyslogSendPacket ( goto ON_EXIT; } - for (;;) { + for ( ; ;) { // // Transmit the packet through SNP. // @@ -268,13 +270,12 @@ SyslogSendPacket ( // // Get the recycled transmit buffer status. // - Snp->GetStatus (Snp, NULL, (VOID **) &TxBuf); + Snp->GetStatus (Snp, NULL, (VOID **)&TxBuf); if (!EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) { Status = EFI_TIMEOUT; break; } - } while (TxBuf == NULL); if ((Status == EFI_SUCCESS) || (Status == EFI_TIMEOUT)) { @@ -312,71 +313,71 @@ ON_EXIT: **/ UINT32 SyslogBuildPacket ( - IN UINT32 Level, - IN UINT8 *Module, - IN UINT8 *File, - IN UINT32 Line, - IN UINT8 *Message, - IN UINT32 BufLen, - OUT CHAR8 *Buf + IN UINT32 Level, + IN UINT8 *Module, + IN UINT8 *File, + IN UINT32 Line, + IN UINT8 *Message, + IN UINT32 BufLen, + OUT CHAR8 *Buf ) { - EFI_STATUS Status; - ETHER_HEAD *Ether; - IP4_HEAD *Ip4; - EFI_UDP_HEADER *Udp4; - EFI_TIME Time; - UINT32 Pri; - UINT32 Len; + EFI_STATUS Status; + ETHER_HEAD *Ether; + IP4_HEAD *Ip4; + EFI_UDP_HEADER *Udp4; + EFI_TIME Time; + UINT32 Pri; + UINT32 Len; // // Fill in the Ethernet header. Leave alone the source MAC. // SyslogSendPacket will fill in the address for us. // - Ether = (ETHER_HEAD *) Buf; + Ether = (ETHER_HEAD *)Buf; CopyMem (Ether->DstMac, mSyslogDstMac, NET_ETHER_ADDR_LEN); ZeroMem (Ether->SrcMac, NET_ETHER_ADDR_LEN); Ether->EtherType = HTONS (0x0800); // IPv4 protocol - Buf += sizeof (ETHER_HEAD); - BufLen -= sizeof (ETHER_HEAD); + Buf += sizeof (ETHER_HEAD); + BufLen -= sizeof (ETHER_HEAD); // // Fill in the IP header // - Ip4 = (IP4_HEAD *) Buf; - Ip4->HeadLen = 5; - Ip4->Ver = 4; - Ip4->Tos = 0; - Ip4->TotalLen = 0; - Ip4->Id = (UINT16) mSyslogPacketSeq; - Ip4->Fragment = 0; - Ip4->Ttl = 16; - Ip4->Protocol = 0x11; - Ip4->Checksum = 0; - Ip4->Src = mSyslogSrcIp; - Ip4->Dst = mSyslogDstIp; + Ip4 = (IP4_HEAD *)Buf; + Ip4->HeadLen = 5; + Ip4->Ver = 4; + Ip4->Tos = 0; + Ip4->TotalLen = 0; + Ip4->Id = (UINT16)mSyslogPacketSeq; + Ip4->Fragment = 0; + Ip4->Ttl = 16; + Ip4->Protocol = 0x11; + Ip4->Checksum = 0; + Ip4->Src = mSyslogSrcIp; + Ip4->Dst = mSyslogDstIp; - Buf += sizeof (IP4_HEAD); - BufLen -= sizeof (IP4_HEAD); + Buf += sizeof (IP4_HEAD); + BufLen -= sizeof (IP4_HEAD); // // Fill in the UDP header, Udp checksum is optional. Leave it zero. // - Udp4 = (EFI_UDP_HEADER *) Buf; - Udp4->SrcPort = HTONS (514); - Udp4->DstPort = HTONS (514); - Udp4->Length = 0; - Udp4->Checksum = 0; + Udp4 = (EFI_UDP_HEADER *)Buf; + Udp4->SrcPort = HTONS (514); + Udp4->DstPort = HTONS (514); + Udp4->Length = 0; + Udp4->Checksum = 0; - Buf += sizeof (EFI_UDP_HEADER); - BufLen -= sizeof (EFI_UDP_HEADER); + Buf += sizeof (EFI_UDP_HEADER); + BufLen -= sizeof (EFI_UDP_HEADER); // // Build the syslog message body with Timestamp machine module Message // - Pri = ((NET_SYSLOG_FACILITY & 31) << 3) | (Level & 7); + Pri = ((NET_SYSLOG_FACILITY & 31) << 3) | (Level & 7); Status = gRT->GetTime (&Time, NULL); if (EFI_ERROR (Status)) { return 0; @@ -386,38 +387,38 @@ SyslogBuildPacket ( // Use %a to format the ASCII strings, %s to format UNICODE strings // Len = 0; - Len += (UINT32) AsciiSPrint ( - Buf, - BufLen, - "<%d> %a %d %d:%d:%d ", - Pri, - mMonthName [Time.Month-1], - Time.Day, - Time.Hour, - Time.Minute, - Time.Second - ); + Len += (UINT32)AsciiSPrint ( + Buf, + BufLen, + "<%d> %a %d %d:%d:%d ", + Pri, + mMonthName[Time.Month-1], + Time.Day, + Time.Hour, + Time.Minute, + Time.Second + ); - Len += (UINT32) AsciiSPrint ( - Buf + Len, - BufLen - Len, - "Tiano %a: %a (Line: %d File: %a)", - Module, - Message, - Line, - File - ); - Len ++; + Len += (UINT32)AsciiSPrint ( + Buf + Len, + BufLen - Len, + "Tiano %a: %a (Line: %d File: %a)", + Module, + Message, + Line, + File + ); + Len++; // // OK, patch the IP length/checksum and UDP length fields. // - Len += sizeof (EFI_UDP_HEADER); - Udp4->Length = HTONS ((UINT16) Len); + Len += sizeof (EFI_UDP_HEADER); + Udp4->Length = HTONS ((UINT16)Len); - Len += sizeof (IP4_HEAD); - Ip4->TotalLen = HTONS ((UINT16) Len); - Ip4->Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Ip4, sizeof (IP4_HEAD))); + Len += sizeof (IP4_HEAD); + Ip4->TotalLen = HTONS ((UINT16)Len); + Ip4->Checksum = (UINT16)(~NetblockChecksum ((UINT8 *)Ip4, sizeof (IP4_HEAD))); return Len + sizeof (ETHER_HEAD); } @@ -451,16 +452,16 @@ SyslogBuildPacket ( CHAR8 * EFIAPI NetDebugASPrint ( - IN CHAR8 *Format, + IN CHAR8 *Format, ... ) { - VA_LIST Marker; - CHAR8 *Buf; + VA_LIST Marker; + CHAR8 *Buf; ASSERT (Format != NULL); - Buf = (CHAR8 *) AllocatePool (NET_DEBUG_MSG_LEN); + Buf = (CHAR8 *)AllocatePool (NET_DEBUG_MSG_LEN); if (Buf == NULL) { return NULL; @@ -494,21 +495,21 @@ NetDebugASPrint ( EFI_STATUS EFIAPI NetDebugOutput ( - IN UINT32 Level, - IN UINT8 *Module, - IN UINT8 *File, - IN UINT32 Line, - IN UINT8 *Message + IN UINT32 Level, + IN UINT8 *Module, + IN UINT8 *File, + IN UINT32 Line, + IN UINT8 *Message ) { - CHAR8 *Packet; - UINT32 Len; - EFI_STATUS Status; + CHAR8 *Packet; + UINT32 Len; + EFI_STATUS Status; // // Check whether the message should be sent out // - if (Message == NULL || File == NULL || Module == NULL) { + if ((Message == NULL) || (File == NULL) || (Module == NULL)) { return EFI_INVALID_PARAMETER; } @@ -522,7 +523,7 @@ NetDebugOutput ( // that the message plus the ethernet/ip/udp header is shorter // than this // - Packet = (CHAR8 *) AllocatePool (NET_SYSLOG_PACKET_LEN); + Packet = (CHAR8 *)AllocatePool (NET_SYSLOG_PACKET_LEN); if (Packet == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -554,6 +555,7 @@ ON_EXIT: FreePool (Message); return Status; } + /** Return the length of the mask. @@ -569,10 +571,10 @@ ON_EXIT: INTN EFIAPI NetGetMaskLength ( - IN IP4_ADDR NetMask + IN IP4_ADDR NetMask ) { - INTN Index; + INTN Index; for (Index = 0; Index <= IP4_MASK_MAX; Index++) { if (NetMask == gIp4AllMasks[Index]) { @@ -583,8 +585,6 @@ NetGetMaskLength ( return Index; } - - /** Return the class of the IP address, such as class A, B, C. Addr is in host byte order. @@ -614,32 +614,26 @@ NetGetMaskLength ( INTN EFIAPI NetGetIpClass ( - IN IP4_ADDR Addr + IN IP4_ADDR Addr ) { - UINT8 ByteOne; + UINT8 ByteOne; - ByteOne = (UINT8) (Addr >> 24); + ByteOne = (UINT8)(Addr >> 24); if ((ByteOne & 0x80) == 0) { return IP4_ADDR_CLASSA; - } else if ((ByteOne & 0xC0) == 0x80) { return IP4_ADDR_CLASSB; - } else if ((ByteOne & 0xE0) == 0xC0) { return IP4_ADDR_CLASSC; - } else if ((ByteOne & 0xF0) == 0xE0) { return IP4_ADDR_CLASSD; - } else { return IP4_ADDR_CLASSE; - } } - /** Check whether the IP is a valid unicast address according to the netmask. @@ -660,15 +654,15 @@ NetGetIpClass ( BOOLEAN EFIAPI NetIp4IsUnicast ( - IN IP4_ADDR Ip, - IN IP4_ADDR NetMask + IN IP4_ADDR Ip, + IN IP4_ADDR NetMask ) { - INTN MaskLength; + INTN MaskLength; ASSERT (NetMask != 0); - if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) { + if ((Ip == 0) || IP4_IS_LOCAL_BROADCAST (Ip)) { return FALSE; } @@ -702,11 +696,11 @@ NetIp4IsUnicast ( BOOLEAN EFIAPI NetIp6IsValidUnicast ( - IN EFI_IPv6_ADDRESS *Ip6 + IN EFI_IPv6_ADDRESS *Ip6 ) { - UINT8 Byte; - UINT8 Index; + UINT8 Byte; + UINT8 Index; ASSERT (Ip6 != NULL); @@ -722,7 +716,7 @@ NetIp6IsValidUnicast ( Byte = Ip6->Addr[Index]; - if (Byte == 0x0 || Byte == 0x1) { + if ((Byte == 0x0) || (Byte == 0x1)) { return FALSE; } @@ -743,10 +737,10 @@ NetIp6IsValidUnicast ( BOOLEAN EFIAPI NetIp6IsUnspecifiedAddr ( - IN EFI_IPv6_ADDRESS *Ip6 + IN EFI_IPv6_ADDRESS *Ip6 ) { - UINT8 Index; + UINT8 Index; ASSERT (Ip6 != NULL); @@ -773,10 +767,10 @@ NetIp6IsUnspecifiedAddr ( BOOLEAN EFIAPI NetIp6IsLinkLocalAddr ( - IN EFI_IPv6_ADDRESS *Ip6 + IN EFI_IPv6_ADDRESS *Ip6 ) { - UINT8 Index; + UINT8 Index; ASSERT (Ip6 != NULL); @@ -814,14 +808,14 @@ NetIp6IsLinkLocalAddr ( BOOLEAN EFIAPI NetIp6IsNetEqual ( - EFI_IPv6_ADDRESS *Ip1, - EFI_IPv6_ADDRESS *Ip2, - UINT8 PrefixLength + EFI_IPv6_ADDRESS *Ip1, + EFI_IPv6_ADDRESS *Ip2, + UINT8 PrefixLength ) { - UINT8 Byte; - UINT8 Bit; - UINT8 Mask; + UINT8 Byte; + UINT8 Bit; + UINT8 Mask; ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_MAX)); @@ -829,20 +823,21 @@ NetIp6IsNetEqual ( return TRUE; } - Byte = (UINT8) (PrefixLength / 8); - Bit = (UINT8) (PrefixLength % 8); + Byte = (UINT8)(PrefixLength / 8); + Bit = (UINT8)(PrefixLength % 8); if (CompareMem (Ip1, Ip2, Byte) != 0) { return FALSE; } if (Bit > 0) { - Mask = (UINT8) (0xFF << (8 - Bit)); + Mask = (UINT8)(0xFF << (8 - Bit)); ASSERT (Byte < 16); if (Byte >= 16) { return FALSE; } + if ((Ip1->Addr[Byte] & Mask) != (Ip2->Addr[Byte] & Mask)) { return FALSE; } @@ -851,7 +846,6 @@ NetIp6IsNetEqual ( return TRUE; } - /** Switches the endianess of an IPv6 address @@ -869,11 +863,11 @@ NetIp6IsNetEqual ( EFI_IPv6_ADDRESS * EFIAPI Ip6Swap128 ( - EFI_IPv6_ADDRESS *Ip6 + EFI_IPv6_ADDRESS *Ip6 ) { - UINT64 High; - UINT64 Low; + UINT64 High; + UINT64 Low; ASSERT (Ip6 != NULL); @@ -905,22 +899,21 @@ NetRandomInitSeed ( VOID ) { - EFI_TIME Time; - UINT32 Seed; - UINT64 MonotonicCount; + EFI_TIME Time; + UINT32 Seed; + UINT64 MonotonicCount; gRT->GetTime (&Time, NULL); - Seed = (Time.Hour << 24 | Time.Day << 16 | Time.Minute << 8 | Time.Second); + Seed = (Time.Hour << 24 | Time.Day << 16 | Time.Minute << 8 | Time.Second); Seed ^= Time.Nanosecond; Seed ^= Time.Year << 7; gBS->GetNextMonotonicCount (&MonotonicCount); - Seed += (UINT32) MonotonicCount; + Seed += (UINT32)MonotonicCount; return Seed; } - /** Extract a UINT32 from a byte stream. @@ -937,10 +930,10 @@ NetRandomInitSeed ( UINT32 EFIAPI NetGetUint32 ( - IN UINT8 *Buf + IN UINT8 *Buf ) { - UINT32 Value; + UINT32 Value; ASSERT (Buf != NULL); @@ -948,7 +941,6 @@ NetGetUint32 ( return NTOHL (Value); } - /** Put a UINT32 to the byte stream in network byte order. @@ -964,8 +956,8 @@ NetGetUint32 ( VOID EFIAPI NetPutUint32 ( - IN OUT UINT8 *Buf, - IN UINT32 Data + IN OUT UINT8 *Buf, + IN UINT32 Data ) { ASSERT (Buf != NULL); @@ -974,7 +966,6 @@ NetPutUint32 ( CopyMem (Buf, &Data, sizeof (UINT32)); } - /** Remove the first node entry on the list, and return the removed node entry. @@ -996,10 +987,10 @@ NetPutUint32 ( LIST_ENTRY * EFIAPI NetListRemoveHead ( - IN OUT LIST_ENTRY *Head + IN OUT LIST_ENTRY *Head ) { - LIST_ENTRY *First; + LIST_ENTRY *First; ASSERT (Head != NULL); @@ -1007,19 +998,18 @@ NetListRemoveHead ( return NULL; } - First = Head->ForwardLink; - Head->ForwardLink = First->ForwardLink; - First->ForwardLink->BackLink = Head; + First = Head->ForwardLink; + Head->ForwardLink = First->ForwardLink; + First->ForwardLink->BackLink = Head; DEBUG_CODE ( - First->ForwardLink = (LIST_ENTRY *) NULL; - First->BackLink = (LIST_ENTRY *) NULL; - ); + First->ForwardLink = (LIST_ENTRY *)NULL; + First->BackLink = (LIST_ENTRY *)NULL; + ); return First; } - /** Remove the last node entry on the list and and return the removed node entry. @@ -1041,10 +1031,10 @@ NetListRemoveHead ( LIST_ENTRY * EFIAPI NetListRemoveTail ( - IN OUT LIST_ENTRY *Head + IN OUT LIST_ENTRY *Head ) { - LIST_ENTRY *Last; + LIST_ENTRY *Last; ASSERT (Head != NULL); @@ -1057,14 +1047,13 @@ NetListRemoveTail ( Last->BackLink->ForwardLink = Head; DEBUG_CODE ( - Last->ForwardLink = (LIST_ENTRY *) NULL; - Last->BackLink = (LIST_ENTRY *) NULL; - ); + Last->ForwardLink = (LIST_ENTRY *)NULL; + Last->BackLink = (LIST_ENTRY *)NULL; + ); return Last; } - /** Insert a new node entry after a designated node entry of a doubly linked list. @@ -1080,19 +1069,18 @@ NetListRemoveTail ( VOID EFIAPI NetListInsertAfter ( - IN OUT LIST_ENTRY *PrevEntry, - IN OUT LIST_ENTRY *NewEntry + IN OUT LIST_ENTRY *PrevEntry, + IN OUT LIST_ENTRY *NewEntry ) { ASSERT (PrevEntry != NULL && NewEntry != NULL); - NewEntry->BackLink = PrevEntry; - NewEntry->ForwardLink = PrevEntry->ForwardLink; - PrevEntry->ForwardLink->BackLink = NewEntry; - PrevEntry->ForwardLink = NewEntry; + NewEntry->BackLink = PrevEntry; + NewEntry->ForwardLink = PrevEntry->ForwardLink; + PrevEntry->ForwardLink->BackLink = NewEntry; + PrevEntry->ForwardLink = NewEntry; } - /** Insert a new node entry before a designated node entry of a doubly linked list. @@ -1108,16 +1096,16 @@ NetListInsertAfter ( VOID EFIAPI NetListInsertBefore ( - IN OUT LIST_ENTRY *PostEntry, - IN OUT LIST_ENTRY *NewEntry + IN OUT LIST_ENTRY *PostEntry, + IN OUT LIST_ENTRY *NewEntry ) { ASSERT (PostEntry != NULL && NewEntry != NULL); - NewEntry->ForwardLink = PostEntry; - NewEntry->BackLink = PostEntry->BackLink; - PostEntry->BackLink->ForwardLink = NewEntry; - PostEntry->BackLink = NewEntry; + NewEntry->ForwardLink = PostEntry; + NewEntry->BackLink = PostEntry->BackLink; + PostEntry->BackLink->ForwardLink = NewEntry; + PostEntry->BackLink = NewEntry; } /** @@ -1145,31 +1133,32 @@ NetListInsertBefore ( EFI_STATUS EFIAPI NetDestroyLinkList ( - IN LIST_ENTRY *List, - IN NET_DESTROY_LINK_LIST_CALLBACK CallBack, - IN VOID *Context OPTIONAL, - OUT UINTN *ListLength OPTIONAL + IN LIST_ENTRY *List, + IN NET_DESTROY_LINK_LIST_CALLBACK CallBack, + IN VOID *Context OPTIONAL, + OUT UINTN *ListLength OPTIONAL ) { - UINTN PreviousLength; - LIST_ENTRY *Entry; - LIST_ENTRY *Ptr; - UINTN Length; - EFI_STATUS Status; + UINTN PreviousLength; + LIST_ENTRY *Entry; + LIST_ENTRY *Ptr; + UINTN Length; + EFI_STATUS Status; - if (List == NULL || CallBack == NULL) { + if ((List == NULL) || (CallBack == NULL)) { return EFI_INVALID_PARAMETER; } Length = 0; do { PreviousLength = Length; - Entry = GetFirstNode (List); + Entry = GetFirstNode (List); while (!IsNull (List, Entry)) { Status = CallBack (Entry, Context); if (EFI_ERROR (Status)) { return Status; } + // // Walk through the list to see whether the Entry has been removed or not. // If the Entry still exists, just try to destroy the next one. @@ -1180,18 +1169,22 @@ NetDestroyLinkList ( break; } } + if (Ptr == Entry) { Entry = GetNextNode (List, Entry); } else { Entry = GetFirstNode (List); } } - for (Length = 0, Ptr = List->ForwardLink; Ptr != List; Length++, Ptr = Ptr->ForwardLink); + + for (Length = 0, Ptr = List->ForwardLink; Ptr != List; Length++, Ptr = Ptr->ForwardLink) { + } } while (Length != PreviousLength); if (ListLength != NULL) { *ListLength = Length; } + return EFI_SUCCESS; } @@ -1210,14 +1203,14 @@ NetDestroyLinkList ( BOOLEAN EFIAPI NetIsInHandleBuffer ( - IN EFI_HANDLE Handle, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + IN EFI_HANDLE Handle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL ) { - UINTN Index; + UINTN Index; - if (NumberOfChildren == 0 || ChildHandleBuffer == NULL) { + if ((NumberOfChildren == 0) || (ChildHandleBuffer == NULL)) { return FALSE; } @@ -1230,7 +1223,6 @@ NetIsInHandleBuffer ( return FALSE; } - /** Initialize the netmap. Netmap is a reposity to keep the pairs. @@ -1248,7 +1240,7 @@ NetIsInHandleBuffer ( VOID EFIAPI NetMapInit ( - IN OUT NET_MAP *Map + IN OUT NET_MAP *Map ) { ASSERT (Map != NULL); @@ -1258,7 +1250,6 @@ NetMapInit ( Map->Count = 0; } - /** To clean up the netmap, that is, release allocated memories. @@ -1274,12 +1265,12 @@ NetMapInit ( VOID EFIAPI NetMapClean ( - IN OUT NET_MAP *Map + IN OUT NET_MAP *Map ) { - NET_MAP_ITEM *Item; - LIST_ENTRY *Entry; - LIST_ENTRY *Next; + NET_MAP_ITEM *Item; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; ASSERT (Map != NULL); @@ -1304,7 +1295,6 @@ NetMapClean ( ASSERT (IsListEmpty (&Map->Recycled)); } - /** Test whether the netmap is empty and return true if it is. @@ -1320,14 +1310,13 @@ NetMapClean ( BOOLEAN EFIAPI NetMapIsEmpty ( - IN NET_MAP *Map + IN NET_MAP *Map ) { ASSERT (Map != NULL); - return (BOOLEAN) (Map->Count == 0); + return (BOOLEAN)(Map->Count == 0); } - /** Return the number of the pairs in the netmap. @@ -1341,14 +1330,13 @@ NetMapIsEmpty ( UINTN EFIAPI NetMapGetCount ( - IN NET_MAP *Map + IN NET_MAP *Map ) { ASSERT (Map != NULL); return Map->Count; } - /** Return one allocated item. @@ -1367,12 +1355,12 @@ NetMapGetCount ( **/ NET_MAP_ITEM * NetMapAllocItem ( - IN OUT NET_MAP *Map + IN OUT NET_MAP *Map ) { - NET_MAP_ITEM *Item; - LIST_ENTRY *Head; - UINTN Index; + NET_MAP_ITEM *Item; + LIST_ENTRY *Head; + UINTN Index; ASSERT (Map != NULL); @@ -1400,7 +1388,6 @@ NetMapAllocItem ( return Item; } - /** Allocate an item to save the pair to the head of the netmap. @@ -1422,12 +1409,12 @@ NetMapAllocItem ( EFI_STATUS EFIAPI NetMapInsertHead ( - IN OUT NET_MAP *Map, - IN VOID *Key, - IN VOID *Value OPTIONAL + IN OUT NET_MAP *Map, + IN VOID *Key, + IN VOID *Value OPTIONAL ) { - NET_MAP_ITEM *Item; + NET_MAP_ITEM *Item; ASSERT (Map != NULL && Key != NULL); @@ -1445,7 +1432,6 @@ NetMapInsertHead ( return EFI_SUCCESS; } - /** Allocate an item to save the pair to the tail of the netmap. @@ -1467,12 +1453,12 @@ NetMapInsertHead ( EFI_STATUS EFIAPI NetMapInsertTail ( - IN OUT NET_MAP *Map, - IN VOID *Key, - IN VOID *Value OPTIONAL + IN OUT NET_MAP *Map, + IN VOID *Key, + IN VOID *Value OPTIONAL ) { - NET_MAP_ITEM *Item; + NET_MAP_ITEM *Item; ASSERT (Map != NULL && Key != NULL); @@ -1491,7 +1477,6 @@ NetMapInsertTail ( return EFI_SUCCESS; } - /** Check whether the item is in the Map and return TRUE if it is. @@ -1506,11 +1491,11 @@ NetMapInsertTail ( **/ BOOLEAN NetItemInMap ( - IN NET_MAP *Map, - IN NET_MAP_ITEM *Item + IN NET_MAP *Map, + IN NET_MAP_ITEM *Item ) { - LIST_ENTRY *ListEntry; + LIST_ENTRY *ListEntry; ASSERT (Map != NULL && Item != NULL); @@ -1523,7 +1508,6 @@ NetItemInMap ( return FALSE; } - /** Find the key in the netmap and returns the point to the item contains the Key. @@ -1542,12 +1526,12 @@ NetItemInMap ( NET_MAP_ITEM * EFIAPI NetMapFindKey ( - IN NET_MAP *Map, - IN VOID *Key + IN NET_MAP *Map, + IN VOID *Key ) { - LIST_ENTRY *Entry; - NET_MAP_ITEM *Item; + LIST_ENTRY *Entry; + NET_MAP_ITEM *Item; ASSERT (Map != NULL && Key != NULL); @@ -1562,7 +1546,6 @@ NetMapFindKey ( return NULL; } - /** Remove the node entry of the item from the netmap and return the key of the removed item. @@ -1585,9 +1568,9 @@ NetMapFindKey ( VOID * EFIAPI NetMapRemoveItem ( - IN OUT NET_MAP *Map, - IN OUT NET_MAP_ITEM *Item, - OUT VOID **Value OPTIONAL + IN OUT NET_MAP *Map, + IN OUT NET_MAP_ITEM *Item, + OUT VOID **Value OPTIONAL ) { ASSERT ((Map != NULL) && (Item != NULL)); @@ -1604,7 +1587,6 @@ NetMapRemoveItem ( return Item->Key; } - /** Remove the first node entry on the netmap and return the key of the removed item. @@ -1625,8 +1607,8 @@ NetMapRemoveItem ( VOID * EFIAPI NetMapRemoveHead ( - IN OUT NET_MAP *Map, - OUT VOID **Value OPTIONAL + IN OUT NET_MAP *Map, + OUT VOID **Value OPTIONAL ) { NET_MAP_ITEM *Item; @@ -1649,7 +1631,6 @@ NetMapRemoveHead ( return Item->Key; } - /** Remove the last node entry on the netmap and return the key of the removed item. @@ -1670,11 +1651,11 @@ NetMapRemoveHead ( VOID * EFIAPI NetMapRemoveTail ( - IN OUT NET_MAP *Map, - OUT VOID **Value OPTIONAL + IN OUT NET_MAP *Map, + OUT VOID **Value OPTIONAL ) { - NET_MAP_ITEM *Item; + NET_MAP_ITEM *Item; // // Often, it indicates a programming error to remove @@ -1694,7 +1675,6 @@ NetMapRemoveTail ( return Item->Key; } - /** Iterate through the netmap and call CallBack for each item. @@ -1717,17 +1697,16 @@ NetMapRemoveTail ( EFI_STATUS EFIAPI NetMapIterate ( - IN NET_MAP *Map, - IN NET_MAP_CALLBACK CallBack, - IN VOID *Arg OPTIONAL + IN NET_MAP *Map, + IN NET_MAP_CALLBACK CallBack, + IN VOID *Arg OPTIONAL ) { - - LIST_ENTRY *Entry; - LIST_ENTRY *Next; - LIST_ENTRY *Head; - NET_MAP_ITEM *Item; - EFI_STATUS Result; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + LIST_ENTRY *Head; + NET_MAP_ITEM *Item; + EFI_STATUS Result; ASSERT ((Map != NULL) && (CallBack != NULL)); @@ -1749,7 +1728,6 @@ NetMapIterate ( return EFI_SUCCESS; } - /** This is the default unload handle for all the network drivers. @@ -1765,17 +1743,17 @@ NetMapIterate ( EFI_STATUS EFIAPI NetLibDefaultUnload ( - IN EFI_HANDLE ImageHandle + IN EFI_HANDLE ImageHandle ) { - EFI_STATUS Status; - EFI_HANDLE *DeviceHandleBuffer; - UINTN DeviceHandleCount; - UINTN Index; - UINTN Index2; - EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; - EFI_COMPONENT_NAME_PROTOCOL *ComponentName; - EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2; + EFI_STATUS Status; + EFI_HANDLE *DeviceHandleBuffer; + UINTN DeviceHandleCount; + UINTN Index; + UINTN Index2; + EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; + EFI_COMPONENT_NAME_PROTOCOL *ComponentName; + EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2; // // Get the list of all the handles in the handle database. @@ -1798,7 +1776,7 @@ NetLibDefaultUnload ( Status = gBS->HandleProtocol ( DeviceHandleBuffer[Index], &gEfiDriverBindingProtocolGuid, - (VOID **) &DriverBinding + (VOID **)&DriverBinding ); if (EFI_ERROR (Status)) { continue; @@ -1824,15 +1802,15 @@ NetLibDefaultUnload ( // Uninstall all the protocols installed in the driver entry point // gBS->UninstallProtocolInterface ( - DriverBinding->DriverBindingHandle, - &gEfiDriverBindingProtocolGuid, - DriverBinding - ); + DriverBinding->DriverBindingHandle, + &gEfiDriverBindingProtocolGuid, + DriverBinding + ); Status = gBS->HandleProtocol ( DeviceHandleBuffer[Index], &gEfiComponentNameProtocolGuid, - (VOID **) &ComponentName + (VOID **)&ComponentName ); if (!EFI_ERROR (Status)) { gBS->UninstallProtocolInterface ( @@ -1845,7 +1823,7 @@ NetLibDefaultUnload ( Status = gBS->HandleProtocol ( DeviceHandleBuffer[Index], &gEfiComponentName2ProtocolGuid, - (VOID **) &ComponentName2 + (VOID **)&ComponentName2 ); if (!EFI_ERROR (Status)) { gBS->UninstallProtocolInterface ( @@ -1866,8 +1844,6 @@ NetLibDefaultUnload ( return EFI_SUCCESS; } - - /** Create a child of the service that is identified by ServiceBindingGuid. @@ -1888,16 +1864,15 @@ NetLibDefaultUnload ( EFI_STATUS EFIAPI NetLibCreateServiceChild ( - IN EFI_HANDLE Controller, - IN EFI_HANDLE Image, - IN EFI_GUID *ServiceBindingGuid, - IN OUT EFI_HANDLE *ChildHandle + IN EFI_HANDLE Controller, + IN EFI_HANDLE Image, + IN EFI_GUID *ServiceBindingGuid, + IN OUT EFI_HANDLE *ChildHandle ) { EFI_STATUS Status; EFI_SERVICE_BINDING_PROTOCOL *Service; - ASSERT ((ServiceBindingGuid != NULL) && (ChildHandle != NULL)); // @@ -1906,7 +1881,7 @@ NetLibCreateServiceChild ( Status = gBS->OpenProtocol ( Controller, ServiceBindingGuid, - (VOID **) &Service, + (VOID **)&Service, Image, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL @@ -1923,7 +1898,6 @@ NetLibCreateServiceChild ( return Status; } - /** Destroy a child of the service that is identified by ServiceBindingGuid. @@ -1943,10 +1917,10 @@ NetLibCreateServiceChild ( EFI_STATUS EFIAPI NetLibDestroyServiceChild ( - IN EFI_HANDLE Controller, - IN EFI_HANDLE Image, - IN EFI_GUID *ServiceBindingGuid, - IN EFI_HANDLE ChildHandle + IN EFI_HANDLE Controller, + IN EFI_HANDLE Image, + IN EFI_GUID *ServiceBindingGuid, + IN EFI_HANDLE ChildHandle ) { EFI_STATUS Status; @@ -1960,7 +1934,7 @@ NetLibDestroyServiceChild ( Status = gBS->OpenProtocol ( Controller, ServiceBindingGuid, - (VOID **) &Service, + (VOID **)&Service, Image, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL @@ -1996,8 +1970,8 @@ NetLibDestroyServiceChild ( EFI_HANDLE EFIAPI NetLibGetSnpHandle ( - IN EFI_HANDLE ServiceHandle, - OUT EFI_SIMPLE_NETWORK_PROTOCOL **Snp OPTIONAL + IN EFI_HANDLE ServiceHandle, + OUT EFI_SIMPLE_NETWORK_PROTOCOL **Snp OPTIONAL ) { EFI_STATUS Status; @@ -2009,11 +1983,12 @@ NetLibGetSnpHandle ( // Try to open SNP from ServiceHandle // SnpInstance = NULL; - Status = gBS->HandleProtocol (ServiceHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &SnpInstance); + Status = gBS->HandleProtocol (ServiceHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&SnpInstance); if (!EFI_ERROR (Status)) { if (Snp != NULL) { *Snp = SnpInstance; } + return ServiceHandle; } @@ -2026,7 +2001,7 @@ NetLibGetSnpHandle ( } SnpHandle = NULL; - Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &DevicePath, &SnpHandle); + Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &DevicePath, &SnpHandle); if (EFI_ERROR (Status)) { // // Failed to find SNP handle @@ -2034,11 +2009,12 @@ NetLibGetSnpHandle ( return NULL; } - Status = gBS->HandleProtocol (SnpHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &SnpInstance); + Status = gBS->HandleProtocol (SnpHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&SnpInstance); if (!EFI_ERROR (Status)) { if (Snp != NULL) { *Snp = SnpInstance; } + return SnpHandle; } @@ -2061,7 +2037,7 @@ NetLibGetSnpHandle ( UINT16 EFIAPI NetLibGetVlanId ( - IN EFI_HANDLE ServiceHandle + IN EFI_HANDLE ServiceHandle ) { EFI_DEVICE_PATH_PROTOCOL *DevicePath; @@ -2074,9 +2050,10 @@ NetLibGetVlanId ( Node = DevicePath; while (!IsDevicePathEnd (Node)) { - if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) { - return ((VLAN_DEVICE_PATH *) Node)->VlanId; + if ((Node->Type == MESSAGING_DEVICE_PATH) && (Node->SubType == MSG_VLAN_DP)) { + return ((VLAN_DEVICE_PATH *)Node)->VlanId; } + Node = NextDevicePathNode (Node); } @@ -2100,8 +2077,8 @@ NetLibGetVlanId ( EFI_HANDLE EFIAPI NetLibGetVlanHandle ( - IN EFI_HANDLE ControllerHandle, - IN UINT16 VlanId + IN EFI_HANDLE ControllerHandle, + IN UINT16 VlanId ) { EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; @@ -2120,10 +2097,10 @@ NetLibGetVlanHandle ( // CopyMem (&VlanNode, &mNetVlanDevicePathTemplate, sizeof (VLAN_DEVICE_PATH)); VlanNode.VlanId = VlanId; - VlanDevicePath = AppendDevicePathNode ( - ParentDevicePath, - (EFI_DEVICE_PATH_PROTOCOL *) &VlanNode - ); + VlanDevicePath = AppendDevicePathNode ( + ParentDevicePath, + (EFI_DEVICE_PATH_PROTOCOL *)&VlanNode + ); if (VlanDevicePath == NULL) { return NULL; } @@ -2131,7 +2108,7 @@ NetLibGetVlanHandle ( // // Find VLAN device handle // - Handle = NULL; + Handle = NULL; DevicePath = VlanDevicePath; gBS->LocateDevicePath ( &gEfiDevicePathProtocolGuid, @@ -2171,19 +2148,19 @@ NetLibGetVlanHandle ( EFI_STATUS EFIAPI NetLibGetMacAddress ( - IN EFI_HANDLE ServiceHandle, - OUT EFI_MAC_ADDRESS *MacAddress, - OUT UINTN *AddressSize + IN EFI_HANDLE ServiceHandle, + OUT EFI_MAC_ADDRESS *MacAddress, + OUT UINTN *AddressSize ) { - EFI_STATUS Status; - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - EFI_SIMPLE_NETWORK_MODE *SnpMode; - EFI_SIMPLE_NETWORK_MODE SnpModeData; - EFI_MANAGED_NETWORK_PROTOCOL *Mnp; - EFI_SERVICE_BINDING_PROTOCOL *MnpSb; - EFI_HANDLE SnpHandle; - EFI_HANDLE MnpChildHandle; + EFI_STATUS Status; + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + EFI_SIMPLE_NETWORK_MODE *SnpMode; + EFI_SIMPLE_NETWORK_MODE SnpModeData; + EFI_MANAGED_NETWORK_PROTOCOL *Mnp; + EFI_SERVICE_BINDING_PROTOCOL *MnpSb; + EFI_HANDLE SnpHandle; + EFI_HANDLE MnpChildHandle; ASSERT (MacAddress != NULL); ASSERT (AddressSize != NULL); @@ -2191,7 +2168,7 @@ NetLibGetMacAddress ( // // Try to get SNP handle // - Snp = NULL; + Snp = NULL; SnpHandle = NetLibGetSnpHandle (ServiceHandle, &Snp); if (SnpHandle != NULL) { // @@ -2203,11 +2180,11 @@ NetLibGetMacAddress ( // Failed to get SNP handle, try to get MAC address from MNP // MnpChildHandle = NULL; - Status = gBS->HandleProtocol ( - ServiceHandle, - &gEfiManagedNetworkServiceBindingProtocolGuid, - (VOID **) &MnpSb - ); + Status = gBS->HandleProtocol ( + ServiceHandle, + &gEfiManagedNetworkServiceBindingProtocolGuid, + (VOID **)&MnpSb + ); if (EFI_ERROR (Status)) { return Status; } @@ -2226,7 +2203,7 @@ NetLibGetMacAddress ( Status = gBS->HandleProtocol ( MnpChildHandle, &gEfiManagedNetworkProtocolGuid, - (VOID **) &Mnp + (VOID **)&Mnp ); if (EFI_ERROR (Status)) { MnpSb->DestroyChild (MnpSb, MnpChildHandle); @@ -2241,6 +2218,7 @@ NetLibGetMacAddress ( MnpSb->DestroyChild (MnpSb, MnpChildHandle); return Status; } + SnpMode = &SnpModeData; // @@ -2282,19 +2260,19 @@ NetLibGetMacAddress ( EFI_STATUS EFIAPI NetLibGetMacString ( - IN EFI_HANDLE ServiceHandle, - IN EFI_HANDLE ImageHandle OPTIONAL, - OUT CHAR16 **MacString + IN EFI_HANDLE ServiceHandle, + IN EFI_HANDLE ImageHandle OPTIONAL, + OUT CHAR16 **MacString ) { - EFI_STATUS Status; - EFI_MAC_ADDRESS MacAddress; - UINT8 *HwAddress; - UINTN HwAddressSize; - UINT16 VlanId; - CHAR16 *String; - UINTN Index; - UINTN BufferSize; + EFI_STATUS Status; + EFI_MAC_ADDRESS MacAddress; + UINT8 *HwAddress; + UINTN HwAddressSize; + UINT16 VlanId; + CHAR16 *String; + UINTN Index; + UINTN BufferSize; ASSERT (MacString != NULL); @@ -2312,10 +2290,11 @@ NetLibGetMacString ( // Plus one unicode character for the null-terminator. // BufferSize = (2 * HwAddressSize + 5 + 1) * sizeof (CHAR16); - String = AllocateZeroPool (BufferSize); + String = AllocateZeroPool (BufferSize); if (String == NULL) { return EFI_OUT_OF_RESOURCES; } + *MacString = String; // @@ -2390,8 +2369,8 @@ NetLibGetMacString ( EFI_STATUS EFIAPI NetLibDetectMedia ( - IN EFI_HANDLE ServiceHandle, - OUT BOOLEAN *MediaPresent + IN EFI_HANDLE ServiceHandle, + OUT BOOLEAN *MediaPresent ) { EFI_STATUS Status; @@ -2410,7 +2389,7 @@ NetLibDetectMedia ( // // Get SNP handle // - Snp = NULL; + Snp = NULL; SnpHandle = NetLibGetSnpHandle (ServiceHandle, &Snp); if (SnpHandle == NULL) { return EFI_INVALID_PARAMETER; @@ -2485,6 +2464,7 @@ NetLibDetectMedia ( if (!EFI_ERROR (Status)) { Status = Snp->Stop (Snp); } + if (EFI_ERROR (Status)) { goto Exit; } @@ -2496,6 +2476,7 @@ NetLibDetectMedia ( if (!EFI_ERROR (Status)) { Status = Snp->Initialize (Snp, 0, 0); } + if (EFI_ERROR (Status)) { goto Exit; } @@ -2599,9 +2580,9 @@ Exit: EFI_STATUS EFIAPI NetLibDetectMediaWaitTimeout ( - IN EFI_HANDLE ServiceHandle, - IN UINT64 Timeout, - OUT EFI_STATUS *MediaState + IN EFI_HANDLE ServiceHandle, + IN UINT64 Timeout, + OUT EFI_STATUS *MediaState ) { EFI_STATUS Status; @@ -2618,13 +2599,14 @@ NetLibDetectMediaWaitTimeout ( if (MediaState == NULL) { return EFI_INVALID_PARAMETER; } + *MediaState = EFI_SUCCESS; MediaInfo = NULL; // // Get SNP handle // - Snp = NULL; + Snp = NULL; SnpHandle = NetLibGetSnpHandle (ServiceHandle, &Snp); if (SnpHandle == NULL) { return EFI_INVALID_PARAMETER; @@ -2633,12 +2615,11 @@ NetLibDetectMediaWaitTimeout ( Status = gBS->HandleProtocol ( SnpHandle, &gEfiAdapterInformationProtocolGuid, - (VOID *) &Aip + (VOID *)&Aip ); if (EFI_ERROR (Status)) { - MediaPresent = TRUE; - Status = NetLibDetectMedia (ServiceHandle, &MediaPresent); + Status = NetLibDetectMedia (ServiceHandle, &MediaPresent); if (!EFI_ERROR (Status)) { if (MediaPresent) { *MediaState = EFI_SUCCESS; @@ -2656,30 +2637,26 @@ NetLibDetectMediaWaitTimeout ( Status = Aip->GetInformation ( Aip, &gEfiAdapterInfoMediaStateGuid, - (VOID **) &MediaInfo, + (VOID **)&MediaInfo, &DataSize ); if (!EFI_ERROR (Status)) { - *MediaState = MediaInfo->MediaState; FreePool (MediaInfo); - if (*MediaState != EFI_NOT_READY || Timeout < MEDIA_STATE_DETECT_TIME_INTERVAL) { - + if ((*MediaState != EFI_NOT_READY) || (Timeout < MEDIA_STATE_DETECT_TIME_INTERVAL)) { return EFI_SUCCESS; } } else { - if (MediaInfo != NULL) { FreePool (MediaInfo); } if (Status == EFI_UNSUPPORTED) { - // // If gEfiAdapterInfoMediaStateGuid is not supported, call NetLibDetectMedia to get media state! // MediaPresent = TRUE; - Status = NetLibDetectMedia (ServiceHandle, &MediaPresent); + Status = NetLibDetectMedia (ServiceHandle, &MediaPresent); if (!EFI_ERROR (Status)) { if (MediaPresent) { *MediaState = EFI_SUCCESS; @@ -2687,6 +2664,7 @@ NetLibDetectMediaWaitTimeout ( *MediaState = EFI_NO_MEDIA; } } + return Status; } @@ -2699,7 +2677,7 @@ NetLibDetectMediaWaitTimeout ( Timer = NULL; TimeRemained = Timeout; - Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer); + Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } @@ -2711,39 +2689,37 @@ NetLibDetectMediaWaitTimeout ( MEDIA_STATE_DETECT_TIME_INTERVAL ); if (EFI_ERROR (Status)) { - gBS->CloseEvent(Timer); + gBS->CloseEvent (Timer); return EFI_DEVICE_ERROR; } do { TimerStatus = gBS->CheckEvent (Timer); if (!EFI_ERROR (TimerStatus)) { - TimeRemained -= MEDIA_STATE_DETECT_TIME_INTERVAL; - Status = Aip->GetInformation ( - Aip, - &gEfiAdapterInfoMediaStateGuid, - (VOID **) &MediaInfo, - &DataSize - ); + Status = Aip->GetInformation ( + Aip, + &gEfiAdapterInfoMediaStateGuid, + (VOID **)&MediaInfo, + &DataSize + ); if (!EFI_ERROR (Status)) { - *MediaState = MediaInfo->MediaState; FreePool (MediaInfo); } else { - if (MediaInfo != NULL) { FreePool (MediaInfo); } - gBS->CloseEvent(Timer); + + gBS->CloseEvent (Timer); return Status; } } } while (TimerStatus == EFI_NOT_READY); } while (*MediaState == EFI_NOT_READY && TimeRemained >= MEDIA_STATE_DETECT_TIME_INTERVAL); - gBS->CloseEvent(Timer); - if (*MediaState == EFI_NOT_READY && TimeRemained < MEDIA_STATE_DETECT_TIME_INTERVAL) { + gBS->CloseEvent (Timer); + if ((*MediaState == EFI_NOT_READY) && (TimeRemained < MEDIA_STATE_DETECT_TIME_INTERVAL)) { return EFI_TIMEOUT; } else { return EFI_SUCCESS; @@ -2770,22 +2746,22 @@ NetLibDefaultAddressIsStatic ( IN EFI_HANDLE Controller ) { - EFI_STATUS Status; - EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2; - UINTN DataSize; - EFI_IP4_CONFIG2_POLICY Policy; - BOOLEAN IsStatic; + EFI_STATUS Status; + EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2; + UINTN DataSize; + EFI_IP4_CONFIG2_POLICY Policy; + BOOLEAN IsStatic; Ip4Config2 = NULL; DataSize = sizeof (EFI_IP4_CONFIG2_POLICY); - IsStatic = TRUE; + IsStatic = TRUE; // // Get Ip4Config2 policy. // - Status = gBS->HandleProtocol (Controller, &gEfiIp4Config2ProtocolGuid, (VOID **) &Ip4Config2); + Status = gBS->HandleProtocol (Controller, &gEfiIp4Config2ProtocolGuid, (VOID **)&Ip4Config2); if (EFI_ERROR (Status)) { goto ON_EXIT; } @@ -2795,7 +2771,7 @@ NetLibDefaultAddressIsStatic ( goto ON_EXIT; } - IsStatic = (BOOLEAN) (Policy == Ip4Config2PolicyStatic); + IsStatic = (BOOLEAN)(Policy == Ip4Config2PolicyStatic); ON_EXIT: @@ -2907,7 +2883,7 @@ NetLibCreateIPv6DPathNode ( Node->LocalPort = LocalPort; Node->RemotePort = RemotePort; - Node->Protocol = Protocol; + Node->Protocol = Protocol; // // Set default value to IPAddressOrigin, PrefixLength. @@ -2940,15 +2916,15 @@ NetLibCreateIPv6DPathNode ( EFI_HANDLE EFIAPI NetLibGetNicHandle ( - IN EFI_HANDLE Controller, - IN EFI_GUID *ProtocolGuid + IN EFI_HANDLE Controller, + IN EFI_GUID *ProtocolGuid ) { - EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenBuffer; - EFI_HANDLE Handle; - EFI_STATUS Status; - UINTN OpenCount; - UINTN Index; + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenBuffer; + EFI_HANDLE Handle; + EFI_STATUS Status; + UINTN OpenCount; + UINTN Index; ASSERT (ProtocolGuid != NULL); @@ -2989,12 +2965,12 @@ NetLibGetNicHandle ( EFI_STATUS EFIAPI NetLibAsciiStrToIp4 ( - IN CONST CHAR8 *String, - OUT EFI_IPv4_ADDRESS *Ip4Address + IN CONST CHAR8 *String, + OUT EFI_IPv4_ADDRESS *Ip4Address ) { - RETURN_STATUS Status; - CHAR8 *EndPointer; + RETURN_STATUS Status; + CHAR8 *EndPointer; Status = AsciiStrToIpv4Address (String, &EndPointer, Ip4Address, NULL); if (RETURN_ERROR (Status) || (*EndPointer != '\0')) { @@ -3004,7 +2980,6 @@ NetLibAsciiStrToIp4 ( } } - /** Convert one Null-terminated ASCII string to EFI_IPv6_ADDRESS. The format of the string is defined in RFC 4291 - Text Representation of Addresses. @@ -3019,12 +2994,12 @@ NetLibAsciiStrToIp4 ( EFI_STATUS EFIAPI NetLibAsciiStrToIp6 ( - IN CONST CHAR8 *String, - OUT EFI_IPv6_ADDRESS *Ip6Address + IN CONST CHAR8 *String, + OUT EFI_IPv6_ADDRESS *Ip6Address ) { - RETURN_STATUS Status; - CHAR8 *EndPointer; + RETURN_STATUS Status; + CHAR8 *EndPointer; Status = AsciiStrToIpv6Address (String, &EndPointer, Ip6Address, NULL); if (RETURN_ERROR (Status) || (*EndPointer != '\0')) { @@ -3034,7 +3009,6 @@ NetLibAsciiStrToIp6 ( } } - /** Convert one Null-terminated Unicode string (decimal dotted) to EFI_IPv4_ADDRESS. @@ -3048,12 +3022,12 @@ NetLibAsciiStrToIp6 ( EFI_STATUS EFIAPI NetLibStrToIp4 ( - IN CONST CHAR16 *String, - OUT EFI_IPv4_ADDRESS *Ip4Address + IN CONST CHAR16 *String, + OUT EFI_IPv4_ADDRESS *Ip4Address ) { - RETURN_STATUS Status; - CHAR16 *EndPointer; + RETURN_STATUS Status; + CHAR16 *EndPointer; Status = StrToIpv4Address (String, &EndPointer, Ip4Address, NULL); if (RETURN_ERROR (Status) || (*EndPointer != L'\0')) { @@ -3063,7 +3037,6 @@ NetLibStrToIp4 ( } } - /** Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS. The format of the string is defined in RFC 4291 - Text Representation of Addresses. @@ -3078,12 +3051,12 @@ NetLibStrToIp4 ( EFI_STATUS EFIAPI NetLibStrToIp6 ( - IN CONST CHAR16 *String, - OUT EFI_IPv6_ADDRESS *Ip6Address + IN CONST CHAR16 *String, + OUT EFI_IPv6_ADDRESS *Ip6Address ) { - RETURN_STATUS Status; - CHAR16 *EndPointer; + RETURN_STATUS Status; + CHAR16 *EndPointer; Status = StrToIpv6Address (String, &EndPointer, Ip6Address, NULL); if (RETURN_ERROR (Status) || (*EndPointer != L'\0')) { @@ -3109,13 +3082,13 @@ NetLibStrToIp6 ( EFI_STATUS EFIAPI NetLibStrToIp6andPrefix ( - IN CONST CHAR16 *String, - OUT EFI_IPv6_ADDRESS *Ip6Address, - OUT UINT8 *PrefixLength + IN CONST CHAR16 *String, + OUT EFI_IPv6_ADDRESS *Ip6Address, + OUT UINT8 *PrefixLength ) { - RETURN_STATUS Status; - CHAR16 *EndPointer; + RETURN_STATUS Status; + CHAR16 *EndPointer; Status = StrToIpv6Address (String, &EndPointer, Ip6Address, PrefixLength); if (RETURN_ERROR (Status) || (*EndPointer != L'\0')) { @@ -3142,21 +3115,21 @@ NetLibStrToIp6andPrefix ( EFI_STATUS EFIAPI NetLibIp6ToStr ( - IN EFI_IPv6_ADDRESS *Ip6Address, - OUT CHAR16 *String, - IN UINTN StringSize + IN EFI_IPv6_ADDRESS *Ip6Address, + OUT CHAR16 *String, + IN UINTN StringSize ) { - UINT16 Ip6Addr[8]; - UINTN Index; - UINTN LongestZerosStart; - UINTN LongestZerosLength; - UINTN CurrentZerosStart; - UINTN CurrentZerosLength; - CHAR16 Buffer[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; - CHAR16 *Ptr; - - if (Ip6Address == NULL || String == NULL || StringSize == 0) { + UINT16 Ip6Addr[8]; + UINTN Index; + UINTN LongestZerosStart; + UINTN LongestZerosLength; + UINTN CurrentZerosStart; + UINTN CurrentZerosLength; + CHAR16 Buffer[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; + CHAR16 *Ptr; + + if ((Ip6Address == NULL) || (String == NULL) || (StringSize == 0)) { return EFI_INVALID_PARAMETER; } @@ -3178,25 +3151,26 @@ NetLibIp6ToStr ( for (Index = 0; Index < 8; Index++) { if (Ip6Addr[Index] == 0) { if (CurrentZerosStart == DEFAULT_ZERO_START) { - CurrentZerosStart = Index; + CurrentZerosStart = Index; CurrentZerosLength = 1; } else { CurrentZerosLength++; } } else { if (CurrentZerosStart != DEFAULT_ZERO_START) { - if (CurrentZerosLength > 2 && (LongestZerosStart == (DEFAULT_ZERO_START) || CurrentZerosLength > LongestZerosLength)) { + if ((CurrentZerosLength > 2) && ((LongestZerosStart == (DEFAULT_ZERO_START)) || (CurrentZerosLength > LongestZerosLength))) { LongestZerosStart = CurrentZerosStart; LongestZerosLength = CurrentZerosLength; } + CurrentZerosStart = DEFAULT_ZERO_START; CurrentZerosLength = 0; } } } - if (CurrentZerosStart != DEFAULT_ZERO_START && CurrentZerosLength > 2) { - if (LongestZerosStart == DEFAULT_ZERO_START || LongestZerosLength < CurrentZerosLength) { + if ((CurrentZerosStart != DEFAULT_ZERO_START) && (CurrentZerosLength > 2)) { + if ((LongestZerosStart == DEFAULT_ZERO_START) || (LongestZerosLength < CurrentZerosLength)) { LongestZerosStart = CurrentZerosStart; LongestZerosLength = CurrentZerosLength; } @@ -3204,21 +3178,25 @@ NetLibIp6ToStr ( Ptr = Buffer; for (Index = 0; Index < 8; Index++) { - if (LongestZerosStart != DEFAULT_ZERO_START && Index >= LongestZerosStart && Index < LongestZerosStart + LongestZerosLength) { + if ((LongestZerosStart != DEFAULT_ZERO_START) && (Index >= LongestZerosStart) && (Index < LongestZerosStart + LongestZerosLength)) { if (Index == LongestZerosStart) { *Ptr++ = L':'; } + continue; } + if (Index != 0) { *Ptr++ = L':'; } - Ptr += UnicodeSPrint(Ptr, 10, L"%x", Ip6Addr[Index]); + + Ptr += UnicodeSPrint (Ptr, 10, L"%x", Ip6Addr[Index]); } - if (LongestZerosStart != DEFAULT_ZERO_START && LongestZerosStart + LongestZerosLength == 8) { + if ((LongestZerosStart != DEFAULT_ZERO_START) && (LongestZerosStart + LongestZerosLength == 8)) { *Ptr++ = L':'; } + *Ptr = L'\0'; if ((UINTN)Ptr - (UINTN)Buffer > StringSize) { @@ -3244,7 +3222,7 @@ NetLibIp6ToStr ( EFI_STATUS EFIAPI NetLibGetSystemGuid ( - OUT EFI_GUID *SystemGuid + OUT EFI_GUID *SystemGuid ) { EFI_STATUS Status; @@ -3257,17 +3235,18 @@ NetLibGetSystemGuid ( ASSERT (SystemGuid != NULL); SmbiosTable = NULL; - Status = EfiGetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID **) &Smbios30Table); - if (!(EFI_ERROR (Status) || Smbios30Table == NULL)) { - Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) Smbios30Table->TableAddress; - SmbiosEnd.Raw = (UINT8 *) (UINTN) (Smbios30Table->TableAddress + Smbios30Table->TableMaximumSize); + Status = EfiGetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID **)&Smbios30Table); + if (!(EFI_ERROR (Status) || (Smbios30Table == NULL))) { + Smbios.Hdr = (SMBIOS_STRUCTURE *)(UINTN)Smbios30Table->TableAddress; + SmbiosEnd.Raw = (UINT8 *)(UINTN)(Smbios30Table->TableAddress + Smbios30Table->TableMaximumSize); } else { - Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable); - if (EFI_ERROR (Status) || SmbiosTable == NULL) { + Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **)&SmbiosTable); + if (EFI_ERROR (Status) || (SmbiosTable == NULL)) { return EFI_NOT_FOUND; } - Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress; - SmbiosEnd.Raw = (UINT8 *) ((UINTN) SmbiosTable->TableAddress + SmbiosTable->TableLength); + + Smbios.Hdr = (SMBIOS_STRUCTURE *)(UINTN)SmbiosTable->TableAddress; + SmbiosEnd.Raw = (UINT8 *)((UINTN)SmbiosTable->TableAddress + SmbiosTable->TableLength); } do { @@ -3296,7 +3275,7 @@ NetLibGetSystemGuid ( // // Step 1: Skip over formatted section. // - String = (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length); + String = (CHAR8 *)(Smbios.Raw + Smbios.Hdr->Length); // // Step 2: Skip over unformatted string section. @@ -3309,7 +3288,7 @@ NetLibGetSystemGuid ( for ( ; *String != 0; String++) { } - if (*(UINT8*)++String == 0) { + if (*(UINT8 *)++String == 0) { // // Pointer to the next SMBIOS structure. // @@ -3318,6 +3297,7 @@ NetLibGetSystemGuid ( } } while (TRUE); } while (Smbios.Raw < SmbiosEnd.Raw); + return EFI_NOT_FOUND; } @@ -3341,15 +3321,15 @@ NetLibGetSystemGuid ( CHAR8 * EFIAPI NetLibCreateDnsQName ( - IN CHAR16 *DomainName + IN CHAR16 *DomainName ) { - CHAR8 *QueryName; - UINTN QueryNameSize; - CHAR8 *Header; - CHAR8 *Tail; - UINTN Len; - UINTN Index; + CHAR8 *QueryName; + UINTN QueryNameSize; + CHAR8 *Header; + CHAR8 *Tail; + UINTN Len; + UINTN Index; ASSERT (DomainName != NULL); @@ -3373,22 +3353,23 @@ NetLibCreateDnsQName ( } Header = QueryName; - Tail = Header + 1; - Len = 0; + Tail = Header + 1; + Len = 0; for (Index = 0; DomainName[Index] != 0; Index++) { - *Tail = (CHAR8) DomainName[Index]; + *Tail = (CHAR8)DomainName[Index]; if (*Tail == '.') { - *Header = (CHAR8) Len; - Header = Tail; - Tail ++; + *Header = (CHAR8)Len; + Header = Tail; + Tail++; Len = 0; } else { Tail++; Len++; } } - *Header = (CHAR8) Len; - *Tail = 0; + + *Header = (CHAR8)Len; + *Tail = 0; return QueryName; }