]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
1). Fix the debug level for DEBUG macro
[mirror_edk2.git] / MdeModulePkg / Library / DxeNetLib / DxeNetLib.c
index ee8b6797e5dc4b11bd5abaafe986c0a1f656cac2..bb0ac06851ffd81ab68b12d38eaf11e4cce42ab0 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
-\r
-Copyright (c) 2005 - 2007, Intel Corporation\r
+  Network library.\r
+  \r
+Copyright (c) 2005 - 2007, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -8,25 +9,16 @@ http://opensource.org/licenses/bsd-license.php
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
-  NetLib.c\r
-\r
-Abstract:\r
-\r
-\r
-\r
 **/\r
 \r
-#include <PiDxe.h>\r
+#include <Uefi.h>\r
 \r
 #include <Protocol/ServiceBinding.h>\r
 #include <Protocol/SimpleNetwork.h>\r
-#include <Protocol/LoadedImage.h>\r
 #include <Protocol/NicIp4Config.h>\r
 #include <Protocol/ComponentName.h>\r
 #include <Protocol/ComponentName2.h>\r
+#include <Protocol/Dpc.h>\r
 \r
 #include <Library/NetLib.h>\r
 #include <Library/BaseLib.h>\r
@@ -34,16 +26,17 @@ Abstract:
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
-\r
+#include <Library/DevicePathLib.h>\r
 \r
 EFI_DPC_PROTOCOL *mDpc = NULL;\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mNetLibHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
+\r
 //\r
 // All the supported IP4 maskes in host byte order.\r
 //\r
-IP4_ADDR  mIp4AllMasks[IP4_MASK_NUM] = {\r
+IP4_ADDR  gIp4AllMasks[IP4_MASK_NUM] = {\r
   0x00000000,\r
   0x80000000,\r
   0xC0000000,\r
@@ -84,45 +77,18 @@ IP4_ADDR  mIp4AllMasks[IP4_MASK_NUM] = {
 \r
 EFI_IPv4_ADDRESS  mZeroIp4Addr = {{0, 0, 0, 0}};\r
 \r
-/**\r
-  Converts the low nibble of a byte  to hex unicode character.\r
-\r
-  @param  Nibble  lower nibble of a byte.\r
-\r
-  @return Hex unicode character.\r
-\r
-**/\r
-CHAR16\r
-NibbleToHexChar (\r
-  IN UINT8      Nibble\r
-  )\r
-{\r
-  //\r
-  // Porting Guide:\r
-  // This library interface is simply obsolete.\r
-  // Include the source code to user code.\r
-  //\r
-\r
-  Nibble &= 0x0F;\r
-  if (Nibble <= 0x9) {\r
-    return (CHAR16)(Nibble + L'0');\r
-  }\r
-\r
-  return (CHAR16)(Nibble - 0xA + L'A');\r
-}\r
-\r
 /**\r
   Return the length of the mask. If the mask is invalid,\r
   return the invalid length 33, which is IP4_MASK_NUM.\r
   NetMask is in the host byte order.\r
 \r
-  @param  NetMask               The netmask to get the length from\r
-\r
-  @return The length of the netmask, IP4_MASK_NUM if the mask isn't\r
-  @return supported.\r
+  @param[in]  NetMask              The netmask to get the length from.\r
 \r
+  @return The length of the netmask, IP4_MASK_NUM if the mask isn't.\r
+  \r
 **/\r
 INTN\r
+EFIAPI\r
 NetGetMaskLength (\r
   IN IP4_ADDR               NetMask\r
   )\r
@@ -130,7 +96,7 @@ NetGetMaskLength (
   INTN                      Index;\r
 \r
   for (Index = 0; Index < IP4_MASK_NUM; Index++) {\r
-    if (NetMask == mIp4AllMasks[Index]) {\r
+    if (NetMask == gIp4AllMasks[Index]) {\r
       break;\r
     }\r
   }\r
@@ -144,12 +110,13 @@ NetGetMaskLength (
   Return the class of the address, such as class a, b, c.\r
   Addr is in host byte order.\r
 \r
-  @param  Addr                  The address to get the class from\r
+  @param[in]   Addr                  The address to get the class from.\r
 \r
-  @return IP address class, such as IP4_ADDR_CLASSA\r
+  @return IP address class, such as IP4_ADDR_CLASSA.\r
 \r
 **/\r
 INTN\r
+EFIAPI\r
 NetGetIpClass (\r
   IN IP4_ADDR               Addr\r
   )\r
@@ -182,13 +149,14 @@ NetGetIpClass (
   the netmask. If NetMask is zero, use the IP address's class to\r
   get the default mask.\r
 \r
-  @param  Ip                    The IP to check againist\r
-  @param  NetMask               The mask of the IP\r
+  @param[in]  Ip                    The IP to check against.\r
+  @param[in]  NetMask               The mask of the IP.\r
 \r
-  @return TRUE if IP is a valid unicast address on the network, otherwise FALSE\r
+  @return TRUE if IP is a valid unicast address on the network, otherwise FALSE.\r
 \r
 **/\r
 BOOLEAN\r
+EFIAPI\r
 Ip4IsUnicast (\r
   IN IP4_ADDR               Ip,\r
   IN IP4_ADDR               NetMask\r
@@ -203,7 +171,7 @@ Ip4IsUnicast (
   }\r
 \r
   if (NetMask == 0) {\r
-    NetMask = mIp4AllMasks[Class << 3];\r
+    NetMask = gIp4AllMasks[Class << 3];\r
   }\r
 \r
   if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {\r
@@ -217,12 +185,11 @@ Ip4IsUnicast (
 /**\r
   Initialize a random seed using current time.\r
 \r
-  None\r
-\r
   @return The random seed initialized with current time.\r
 \r
 **/\r
 UINT32\r
+EFIAPI\r
 NetRandomInitSeed (\r
   VOID\r
   )\r
@@ -243,19 +210,20 @@ NetRandomInitSeed (
   Extract a UINT32 from a byte stream, then convert it to host\r
   byte order. Use this function to avoid alignment error.\r
 \r
-  @param  Buf                   The buffer to extract the UINT32.\r
+  @param[in]  Buf                 The buffer to extract the UINT32.\r
 \r
   @return The UINT32 extracted.\r
 \r
 **/\r
 UINT32\r
+EFIAPI\r
 NetGetUint32 (\r
   IN UINT8                  *Buf\r
   )\r
 {\r
   UINT32                    Value;\r
 \r
-  NetCopyMem (&Value, Buf, sizeof (UINT32));\r
+  CopyMem (&Value, Buf, sizeof (UINT32));\r
   return NTOHL (Value);\r
 }\r
 \r
@@ -264,41 +232,41 @@ NetGetUint32 (
   Put a UINT32 to the byte stream. Convert it from host byte order\r
   to network byte order before putting.\r
 \r
-  @param  Buf                   The buffer to put the UINT32\r
-  @param  Data                  The data to put\r
-\r
-  @return None\r
-\r
+  @param[in, out]  Buf          The buffer to put the UINT32.\r
+  @param[in]      Data          The data to put.\r
+  \r
 **/\r
 VOID\r
+EFIAPI\r
 NetPutUint32 (\r
-  IN UINT8                  *Buf,\r
-  IN UINT32                 Data\r
+  IN OUT UINT8                 *Buf,\r
+  IN     UINT32                Data\r
   )\r
 {\r
   Data = HTONL (Data);\r
-  NetCopyMem (Buf, &Data, sizeof (UINT32));\r
+  CopyMem (Buf, &Data, sizeof (UINT32));\r
 }\r
 \r
 \r
 /**\r
-  Remove the first entry on the list\r
+  Remove the first entry on the list.\r
 \r
-  @param  Head                  The list header\r
+  @param[in, out]  Head                  The list header.\r
 \r
   @return The entry that is removed from the list, NULL if the list is empty.\r
 \r
 **/\r
-NET_LIST_ENTRY *\r
+LIST_ENTRY *\r
+EFIAPI\r
 NetListRemoveHead (\r
-  NET_LIST_ENTRY            *Head\r
+  IN OUT LIST_ENTRY            *Head\r
   )\r
 {\r
-  NET_LIST_ENTRY            *First;\r
+  LIST_ENTRY            *First;\r
 \r
   ASSERT (Head != NULL);\r
 \r
-  if (NetListIsEmpty (Head)) {\r
+  if (IsListEmpty (Head)) {\r
     return NULL;\r
   }\r
 \r
@@ -307,8 +275,8 @@ NetListRemoveHead (
   First->ForwardLink->BackLink  = Head;\r
 \r
   DEBUG_CODE (\r
-    First->ForwardLink  = (LIST_ENTRY     *) NULL;\r
-    First->BackLink     = (LIST_ENTRY     *) NULL;\r
+    First->ForwardLink  = (LIST_ENTRY *) NULL;\r
+    First->BackLink     = (LIST_ENTRY *) NULL;\r
   );\r
 \r
   return First;\r
@@ -316,23 +284,24 @@ NetListRemoveHead (
 \r
 \r
 /**\r
-  Remove the last entry on the list\r
+  Remove the last entry on the list.\r
 \r
-  @param  Head                  The list head\r
+  @param[in, out]  Head                  The list head.\r
 \r
   @return The entry that is removed from the list, NULL if the list is empty.\r
 \r
 **/\r
-NET_LIST_ENTRY *\r
+LIST_ENTRY *\r
+EFIAPI\r
 NetListRemoveTail (\r
-  NET_LIST_ENTRY            *Head\r
+  IN OUT LIST_ENTRY            *Head\r
   )\r
 {\r
-  NET_LIST_ENTRY            *Last;\r
+  LIST_ENTRY            *Last;\r
 \r
   ASSERT (Head != NULL);\r
 \r
-  if (NetListIsEmpty (Head)) {\r
+  if (IsListEmpty (Head)) {\r
     return NULL;\r
   }\r
 \r
@@ -341,8 +310,8 @@ NetListRemoveTail (
   Last->BackLink->ForwardLink = Head;\r
 \r
   DEBUG_CODE (\r
-    Last->ForwardLink = (LIST_ENTRY     *) NULL;\r
-    Last->BackLink    = (LIST_ENTRY     *) NULL;\r
+    Last->ForwardLink = (LIST_ENTRY *) NULL;\r
+    Last->BackLink    = (LIST_ENTRY *) NULL;\r
   );\r
 \r
   return Last;\r
@@ -350,18 +319,17 @@ NetListRemoveTail (
 \r
 \r
 /**\r
-  Insert the NewEntry after the PrevEntry\r
+  Insert the NewEntry after the PrevEntry.\r
 \r
-  @param  PrevEntry             The previous entry to insert after\r
-  @param  NewEntry              The new entry to insert\r
-\r
-  @return None\r
+  @param[in, out]  PrevEntry             The previous entry to insert after.\r
+  @param[in, out]  NewEntry              The new entry to insert.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 NetListInsertAfter (\r
-  IN NET_LIST_ENTRY         *PrevEntry,\r
-  IN NET_LIST_ENTRY         *NewEntry\r
+  IN OUT LIST_ENTRY         *PrevEntry,\r
+  IN OUT LIST_ENTRY         *NewEntry\r
   )\r
 {\r
   NewEntry->BackLink                = PrevEntry;\r
@@ -372,18 +340,17 @@ NetListInsertAfter (
 \r
 \r
 /**\r
-  Insert the NewEntry before the PostEntry\r
-\r
-  @param  PostEntry             The entry to insert before\r
-  @param  NewEntry              The new entry to insert\r
+  Insert the NewEntry before the PostEntry.\r
 \r
-  @return None\r
+  @param[in, out]  PostEntry             The entry to insert before.\r
+  @param[in, out]  NewEntry              The new entry to insert.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 NetListInsertBefore (\r
-  IN NET_LIST_ENTRY *PostEntry,\r
-  IN NET_LIST_ENTRY *NewEntry\r
+  IN OUT LIST_ENTRY     *PostEntry,\r
+  IN OUT LIST_ENTRY     *NewEntry\r
   )\r
 {\r
   NewEntry->ForwardLink             = PostEntry;\r
@@ -396,20 +363,19 @@ NetListInsertBefore (
 /**\r
   Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.\r
 \r
-  @param  Map                   The netmap to initialize\r
-\r
-  @return None\r
+  @param[in, out]  Map                   The netmap to initialize.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 NetMapInit (\r
-  IN NET_MAP                *Map\r
+  IN OUT NET_MAP                *Map\r
   )\r
 {\r
   ASSERT (Map != NULL);\r
 \r
-  NetListInit (&Map->Used);\r
-  NetListInit (&Map->Recycled);\r
+  InitializeListHead (&Map->Used);\r
+  InitializeListHead (&Map->Recycled);\r
   Map->Count = 0;\r
 }\r
 \r
@@ -417,53 +383,53 @@ NetMapInit (
 /**\r
   To clean up the netmap, that is, release allocated memories.\r
 \r
-  @param  Map                   The netmap to clean up.\r
-\r
-  @return None\r
+  @param[in, out]  Map                   The netmap to clean up.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 NetMapClean (\r
-  IN NET_MAP                *Map\r
+  IN OUT NET_MAP            *Map\r
   )\r
 {\r
   NET_MAP_ITEM              *Item;\r
-  NET_LIST_ENTRY            *Entry;\r
-  NET_LIST_ENTRY            *Next;\r
+  LIST_ENTRY                *Entry;\r
+  LIST_ENTRY                *Next;\r
 \r
   ASSERT (Map != NULL);\r
 \r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &Map->Used) {\r
     Item = NET_LIST_USER_STRUCT (Entry, NET_MAP_ITEM, Link);\r
 \r
-    NetListRemoveEntry (&Item->Link);\r
+    RemoveEntryList (&Item->Link);\r
     Map->Count--;\r
 \r
-    NetFreePool (Item);\r
+    gBS->FreePool (Item);\r
   }\r
 \r
-  ASSERT ((Map->Count == 0) && NetListIsEmpty (&Map->Used));\r
+  ASSERT ((Map->Count == 0) && IsListEmpty (&Map->Used));\r
 \r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &Map->Recycled) {\r
     Item = NET_LIST_USER_STRUCT (Entry, NET_MAP_ITEM, Link);\r
 \r
-    NetListRemoveEntry (&Item->Link);\r
-    NetFreePool (Item);\r
+    RemoveEntryList (&Item->Link);\r
+    gBS->FreePool (Item);\r
   }\r
 \r
-  ASSERT (NetListIsEmpty (&Map->Recycled));\r
+  ASSERT (IsListEmpty (&Map->Recycled));\r
 }\r
 \r
 \r
 /**\r
-  Test whether the netmap is empty\r
+  Test whether the netmap is empty.\r
 \r
-  @param  Map                   The net map to test\r
+  @param[in]  Map                   The net map to test.\r
 \r
   @return TRUE if the netmap is empty, otherwise FALSE.\r
 \r
 **/\r
 BOOLEAN\r
+EFIAPI\r
 NetMapIsEmpty (\r
   IN NET_MAP                *Map\r
   )\r
@@ -476,12 +442,13 @@ NetMapIsEmpty (
 /**\r
   Return the number of the <Key, Value> pairs in the netmap.\r
 \r
-  @param  Map                   The netmap to get the entry number\r
+  @param[in]  Map                   The netmap to get the entry number.\r
 \r
   @return The entry number in the netmap.\r
 \r
 **/\r
 UINTN\r
+EFIAPI\r
 NetMapGetCount (\r
   IN NET_MAP                *Map\r
   )\r
@@ -491,31 +458,31 @@ NetMapGetCount (
 \r
 \r
 /**\r
-  Allocate an item for the netmap. It will try to allocate\r
+  Allocate an item for the netmap. It will try to allocate.\r
   a batch of items and return one.\r
 \r
-  @param  Map                   The netmap to allocate item for\r
+  @param[in, out]  Map          The netmap to allocate item for.\r
 \r
-  @return The allocated item or NULL\r
+  @return                       The allocated item. If NULL, the\r
+                                allocation failed due to resource limit.\r
 \r
 **/\r
-STATIC\r
 NET_MAP_ITEM *\r
 NetMapAllocItem (\r
-  IN NET_MAP                *Map\r
+  IN OUT NET_MAP            *Map\r
   )\r
 {\r
   NET_MAP_ITEM              *Item;\r
-  NET_LIST_ENTRY            *Head;\r
+  LIST_ENTRY                *Head;\r
   UINTN                     Index;\r
 \r
   ASSERT (Map != NULL);\r
 \r
   Head = &Map->Recycled;\r
 \r
-  if (NetListIsEmpty (Head)) {\r
+  if (IsListEmpty (Head)) {\r
     for (Index = 0; Index < NET_MAP_INCREAMENT; Index++) {\r
-      Item = NetAllocatePool (sizeof (NET_MAP_ITEM));\r
+      Item = AllocatePool (sizeof (NET_MAP_ITEM));\r
 \r
       if (Item == NULL) {\r
         if (Index == 0) {\r
@@ -525,7 +492,7 @@ NetMapAllocItem (
         break;\r
       }\r
 \r
-      NetListInsertHead (Head, &Item->Link);\r
+      InsertHeadList (Head, &Item->Link);\r
     }\r
   }\r
 \r
@@ -539,17 +506,18 @@ NetMapAllocItem (
 /**\r
   Allocate an item to save the <Key, Value> pair to the head of the netmap.\r
 \r
-  @param  Map                   The netmap to insert into\r
-  @param  Key                   The user's key\r
-  @param  Value                 The user's value for the key\r
+  @param[in, out]  Map                   The netmap to insert into.\r
+  @param[in]       Key                   The user's key.\r
+  @param[in]       Value                 The user's value for the key.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  Failed to allocate the memory for the item\r
-  @retval EFI_SUCCESS           The item is inserted to the head\r
+  @retval EFI_OUT_OF_RESOURCES  Failed to allocate the memory for the item.\r
+  @retval EFI_SUCCESS           The item is inserted to the head.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetMapInsertHead (\r
-  IN NET_MAP                *Map,\r
+  IN OUT NET_MAP            *Map,\r
   IN VOID                   *Key,\r
   IN VOID                   *Value    OPTIONAL\r
   )\r
@@ -566,7 +534,7 @@ NetMapInsertHead (
 \r
   Item->Key   = Key;\r
   Item->Value = Value;\r
-  NetListInsertHead (&Map->Used, &Item->Link);\r
+  InsertHeadList (&Map->Used, &Item->Link);\r
 \r
   Map->Count++;\r
   return EFI_SUCCESS;\r
@@ -576,17 +544,18 @@ NetMapInsertHead (
 /**\r
   Allocate an item to save the <Key, Value> pair to the tail of the netmap.\r
 \r
-  @param  Map                   The netmap to insert into\r
-  @param  Key                   The user's key\r
-  @param  Value                 The user's value for the key\r
+  @param[in, out]  Map                   The netmap to insert into.\r
+  @param[in]       Key                   The user's key.\r
+  @param[in]       Value                 The user's value for the key.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  Failed to allocate the memory for the item\r
-  @retval EFI_SUCCESS           The item is inserted to the tail\r
+  @retval EFI_OUT_OF_RESOURCES  Failed to allocate the memory for the item.\r
+  @retval EFI_SUCCESS           The item is inserted to the tail.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetMapInsertTail (\r
-  IN NET_MAP                *Map,\r
+  IN OUT NET_MAP            *Map,\r
   IN VOID                   *Key,\r
   IN VOID                   *Value    OPTIONAL\r
   )\r
@@ -603,7 +572,7 @@ NetMapInsertTail (
 \r
   Item->Key   = Key;\r
   Item->Value = Value;\r
-  NetListInsertTail (&Map->Used, &Item->Link);\r
+  InsertTailList (&Map->Used, &Item->Link);\r
 \r
   Map->Count++;\r
 \r
@@ -612,22 +581,21 @@ NetMapInsertTail (
 \r
 \r
 /**\r
-  Check whther the item is in the Map\r
+  Check whther the item is in the Map.\r
 \r
-  @param  Map                   The netmap to search within\r
-  @param  Item                  The item to search\r
+  @param[in]  Map                   The netmap to search within.\r
+  @param[in]  Item                  The item to search.\r
 \r
   @return TRUE if the item is in the netmap, otherwise FALSE.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 NetItemInMap (\r
   IN NET_MAP                *Map,\r
   IN NET_MAP_ITEM           *Item\r
   )\r
 {\r
-  NET_LIST_ENTRY            *ListEntry;\r
+  LIST_ENTRY            *ListEntry;\r
 \r
   NET_LIST_FOR_EACH (ListEntry, &Map->Used) {\r
     if (ListEntry == &Item->Link) {\r
@@ -640,21 +608,22 @@ NetItemInMap (
 \r
 \r
 /**\r
-  Find the key in the netmap\r
+  Find the key in the netmap.\r
 \r
-  @param  Map                   The netmap to search within\r
-  @param  Key                   The key to search\r
+  @param[in]  Map                   The netmap to search within.\r
+  @param[in]  Key                   The key to search.\r
 \r
   @return The point to the item contains the Key, or NULL if Key isn't in the map.\r
 \r
 **/\r
 NET_MAP_ITEM *\r
+EFIAPI\r
 NetMapFindKey (\r
   IN  NET_MAP               *Map,\r
   IN  VOID                  *Key\r
   )\r
 {\r
-  NET_LIST_ENTRY          *Entry;\r
+  LIST_ENTRY              *Entry;\r
   NET_MAP_ITEM            *Item;\r
 \r
   ASSERT (Map != NULL);\r
@@ -672,28 +641,29 @@ NetMapFindKey (
 \r
 \r
 /**\r
-  Remove the item from the netmap\r
+  Remove the item from the netmap.\r
 \r
-  @param  Map                   The netmap to remove the item from\r
-  @param  Item                  The item to remove\r
-  @param  Value                 The variable to receive the value if not NULL\r
+  @param[in, out]  Map                   The netmap to remove the item from.\r
+  @param[in, out]  Item                  The item to remove.\r
+  @param[out]      Value                 The variable to receive the value if not NULL.\r
 \r
-  @return The key of the removed item.\r
+  @return                                The key of the removed item.\r
 \r
 **/\r
 VOID *\r
+EFIAPI\r
 NetMapRemoveItem (\r
-  IN  NET_MAP             *Map,\r
-  IN  NET_MAP_ITEM        *Item,\r
-  OUT VOID                **Value           OPTIONAL\r
+  IN  OUT NET_MAP             *Map,\r
+  IN  OUT NET_MAP_ITEM        *Item,\r
+  OUT VOID                    **Value           OPTIONAL\r
   )\r
 {\r
   ASSERT ((Map != NULL) && (Item != NULL));\r
   ASSERT (NetItemInMap (Map, Item));\r
 \r
-  NetListRemoveEntry (&Item->Link);\r
+  RemoveEntryList (&Item->Link);\r
   Map->Count--;\r
-  NetListInsertHead (&Map->Recycled, &Item->Link);\r
+  InsertHeadList (&Map->Recycled, &Item->Link);\r
 \r
   if (Value != NULL) {\r
     *Value = Item->Value;\r
@@ -704,17 +674,18 @@ NetMapRemoveItem (
 \r
 \r
 /**\r
-  Remove the first entry on the netmap\r
+  Remove the first entry on the netmap.\r
 \r
-  @param  Map                   The netmap to remove the head from\r
-  @param  Value                 The variable to receive the value if not NULL\r
+  @param[in, out]  Map                   The netmap to remove the head from.\r
+  @param[out]      Value                 The variable to receive the value if not NULL.\r
 \r
-  @return The key of the item removed\r
+  @return                                The key of the item removed.\r
 \r
 **/\r
 VOID *\r
+EFIAPI\r
 NetMapRemoveHead (\r
-  IN  NET_MAP               *Map,\r
+  IN OUT NET_MAP            *Map,\r
   OUT VOID                  **Value         OPTIONAL\r
   )\r
 {\r
@@ -724,12 +695,12 @@ NetMapRemoveHead (
   // Often, it indicates a programming error to remove\r
   // the first entry in an empty list\r
   //\r
-  ASSERT (Map && !NetListIsEmpty (&Map->Used));\r
+  ASSERT (Map && !IsListEmpty (&Map->Used));\r
 \r
   Item = NET_LIST_HEAD (&Map->Used, NET_MAP_ITEM, Link);\r
-  NetListRemoveEntry (&Item->Link);\r
+  RemoveEntryList (&Item->Link);\r
   Map->Count--;\r
-  NetListInsertHead (&Map->Recycled, &Item->Link);\r
+  InsertHeadList (&Map->Recycled, &Item->Link);\r
 \r
   if (Value != NULL) {\r
     *Value = Item->Value;\r
@@ -740,17 +711,18 @@ NetMapRemoveHead (
 \r
 \r
 /**\r
-  Remove the last entry on the netmap\r
+  Remove the last entry on the netmap.\r
 \r
-  @param  Map                   The netmap to remove the tail from\r
-  @param  Value                 The variable to receive the value if not NULL\r
+  @param[in, out]  Map                   The netmap to remove the tail from.\r
+  @param[out]      Value                 The variable to receive the value if not NULL.\r
 \r
-  @return The key of the item removed\r
+  @return                                The key of the item removed.\r
 \r
 **/\r
 VOID *\r
+EFIAPI\r
 NetMapRemoveTail (\r
-  IN  NET_MAP               *Map,\r
+  IN OUT NET_MAP            *Map,\r
   OUT VOID                  **Value       OPTIONAL\r
   )\r
 {\r
@@ -760,12 +732,12 @@ NetMapRemoveTail (
   // Often, it indicates a programming error to remove\r
   // the last entry in an empty list\r
   //\r
-  ASSERT (Map && !NetListIsEmpty (&Map->Used));\r
+  ASSERT (Map && !IsListEmpty (&Map->Used));\r
 \r
   Item = NET_LIST_TAIL (&Map->Used, NET_MAP_ITEM, Link);\r
-  NetListRemoveEntry (&Item->Link);\r
+  RemoveEntryList (&Item->Link);\r
   Map->Count--;\r
-  NetListInsertHead (&Map->Recycled, &Item->Link);\r
+  InsertHeadList (&Map->Recycled, &Item->Link);\r
 \r
   if (Value != NULL) {\r
     *Value = Item->Value;\r
@@ -781,14 +753,17 @@ NetMapRemoveTail (
   from the loop. It returns the CallBack's last return value. This\r
   function is delete safe for the current item.\r
 \r
-  @param  Map                   The Map to iterate through\r
-  @param  CallBack              The callback function to call for each item.\r
-  @param  Arg                   The opaque parameter to the callback\r
+  @param[in]  Map                   The Map to iterate through.\r
+  @param[in]  CallBack              The callback function to call for each item.\r
+  @param[in]  Arg                   The opaque parameter to the callback.\r
 \r
-  @return It returns the CallBack's last return value.\r
+  @retval EFI_SUCCESS            There is no item in the netmap or CallBack for each item\r
+                                 return EFI_SUCCESS.\r
+  @retval Others                 It returns the CallBack's last return value.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetMapIterate (\r
   IN NET_MAP                *Map,\r
   IN NET_MAP_CALLBACK       CallBack,\r
@@ -796,9 +771,9 @@ NetMapIterate (
   )\r
 {\r
 \r
-  NET_LIST_ENTRY            *Entry;\r
-  NET_LIST_ENTRY            *Next;\r
-  NET_LIST_ENTRY            *Head;\r
+  LIST_ENTRY            *Entry;\r
+  LIST_ENTRY            *Next;\r
+  LIST_ENTRY            *Head;\r
   NET_MAP_ITEM              *Item;\r
   EFI_STATUS                Result;\r
 \r
@@ -806,7 +781,7 @@ NetMapIterate (
 \r
   Head = &Map->Used;\r
 \r
-  if (NetListIsEmpty (Head)) {\r
+  if (IsListEmpty (Head)) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -826,7 +801,7 @@ NetMapIterate (
 /**\r
   This is the default unload handle for all the network drivers.\r
 \r
-  @param  ImageHandle           The drivers' driver image.\r
+  @param[in]  ImageHandle       The drivers' driver image.\r
 \r
   @retval EFI_SUCCESS           The image is unloaded.\r
   @retval Others                Failed to unload the image.\r
@@ -940,21 +915,22 @@ NetLibDefaultUnload (
 /**\r
   Create a child of the service that is identified by ServiceBindingGuid.\r
 \r
-  @param  Controller            The controller which has the service installed.\r
-  @param  Image                 The image handle used to open service.\r
-  @param  ServiceBindingGuid    The service's Guid.\r
-  @param  ChildHandle           The handle to receive the create child\r
+  @param[in]       Controller            The controller which has the service installed.\r
+  @param[in]       Image                 The image handle used to open service.\r
+  @param[in]       ServiceBindingGuid    The service's Guid.\r
+  @param[in, out]  ChildHandle           The handle to receive the create child\r
 \r
   @retval EFI_SUCCESS           The child is successfully created.\r
   @retval Others                Failed to create the child.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetLibCreateServiceChild (\r
   IN  EFI_HANDLE            Controller,\r
   IN  EFI_HANDLE            Image,\r
   IN  EFI_GUID              *ServiceBindingGuid,\r
-  OUT EFI_HANDLE            *ChildHandle\r
+  IN  OUT EFI_HANDLE        *ChildHandle\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
@@ -990,16 +966,17 @@ NetLibCreateServiceChild (
 /**\r
   Destory a child of the service that is identified by ServiceBindingGuid.\r
 \r
-  @param  Controller            The controller which has the service installed.\r
-  @param  Image                 The image handle used to open service.\r
-  @param  ServiceBindingGuid    The service's Guid.\r
-  @param  ChildHandle           The child to destory\r
+  @param[in]   Controller            The controller which has the service installed.\r
+  @param[in]   Image                 The image handle used to open service.\r
+  @param[in]   ServiceBindingGuid    The service's Guid.\r
+  @param[in]   ChildHandle           The child to destory\r
 \r
   @retval EFI_SUCCESS           The child is successfully destoried.\r
   @retval Others                Failed to destory the child.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetLibDestroyServiceChild (\r
   IN  EFI_HANDLE            Controller,\r
   IN  EFI_HANDLE            Image,\r
@@ -1041,22 +1018,24 @@ NetLibDestroyServiceChild (
   SnpHandle to a unicode string. Callers are responsible for freeing the\r
   string storage.\r
 \r
-  @param  SnpHandle             The handle where the simple network protocol is\r
-                                installed on.\r
-  @param  ImageHandle           The image handle used to act as the agent handle to\r
-                                get the simple network protocol.\r
-  @param  MacString             The pointer to store the address of the string\r
-                                representation of  the mac address.\r
-\r
+  @param[in]   SnpHandle             The handle where the simple network protocol is\r
+                                     installed on.\r
+  @param[in]   ImageHandle           The image handle used to act as the agent handle to\r
+                                     get the simple network protocol.\r
+  @param[out]  MacString             The pointer to store the address of the string\r
+                                     representation of  the mac address.\r
+  \r
+  @retval EFI_SUCCESS           Convert the mac address a unicode string successfully.\r
   @retval EFI_OUT_OF_RESOURCES  There are not enough memory resource.\r
-  @retval other                 Failed to open the simple network protocol.\r
+  @retval Others                Failed to open the simple network protocol.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetLibGetMacString (\r
-  IN           EFI_HANDLE  SnpHandle,\r
-  IN           EFI_HANDLE  ImageHandle,\r
-  IN OUT       CHAR16      **MacString\r
+  IN  EFI_HANDLE            SnpHandle,\r
+  IN  EFI_HANDLE            ImageHandle,\r
+  OUT CHAR16                **MacString\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -1088,7 +1067,7 @@ NetLibGetMacString (
   // It takes 2 unicode characters to represent a 1 byte binary buffer.\r
   // Plus one unicode character for the null-terminator.\r
   //\r
-  MacAddress = NetAllocatePool ((2 * Mode->HwAddressSize + 1) * sizeof (CHAR16));\r
+  MacAddress = AllocatePool ((2 * Mode->HwAddressSize + 1) * sizeof (CHAR16));\r
   if (MacAddress == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -1097,8 +1076,8 @@ NetLibGetMacString (
   // Convert the mac address into a unicode string.\r
   //\r
   for (Index = 0; Index < Mode->HwAddressSize; Index++) {\r
-    MacAddress[Index * 2]     = NibbleToHexChar ((UINT8) (Mode->CurrentAddress.Addr[Index] >> 4));\r
-    MacAddress[Index * 2 + 1] = NibbleToHexChar (Mode->CurrentAddress.Addr[Index]);\r
+    MacAddress[Index * 2]     = (CHAR16) mNetLibHexStr[(Mode->CurrentAddress.Addr[Index] >> 4) & 0x0F];\r
+    MacAddress[Index * 2 + 1] = (CHAR16) mNetLibHexStr[Mode->CurrentAddress.Addr[Index] & 0x0F];\r
   }\r
 \r
   MacAddress[Mode->HwAddressSize * 2] = L'\0';\r
@@ -1112,14 +1091,13 @@ NetLibGetMacString (
   Check the default address used by the IPv4 driver is static or dynamic (acquired\r
   from DHCP).\r
 \r
-  @param  Controller     The controller handle which has the NIC Ip4 Config Protocol\r
-                         relative with the default address to judge.\r
+  @param[in]   Controller     The controller handle which has the NIC Ip4 Config Protocol\r
+                              relative with the default address to judge.\r
 \r
   @retval TRUE           If the default address is static.\r
   @retval FALSE          If the default address is acquired from DHCP.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 NetLibDefaultAddressIsStatic (\r
   IN EFI_HANDLE  Controller\r
@@ -1146,7 +1124,7 @@ NetLibDefaultAddressIsStatic (
     return TRUE;\r
   }\r
 \r
-  ConfigInfo = NetAllocatePool (Len);\r
+  ConfigInfo = AllocatePool (Len);\r
   if (ConfigInfo == NULL) {\r
     return TRUE;\r
   }\r
@@ -1161,7 +1139,7 @@ NetLibDefaultAddressIsStatic (
 \r
 ON_EXIT:\r
 \r
-  NetFreePool (ConfigInfo);\r
+  gBS->FreePool (ConfigInfo);\r
 \r
   return IsStatic;\r
 }\r
@@ -1169,18 +1147,18 @@ ON_EXIT:
 /**\r
   Create an IPv4 device path node.\r
 \r
-  @param  Node                  Pointer to the IPv4 device path node.\r
-  @param  Controller            The handle where the NIC IP4 config protocol resides.\r
-  @param  LocalIp               The local IPv4 address.\r
-  @param  LocalPort             The local port.\r
-  @param  RemoteIp              The remote IPv4 address.\r
-  @param  RemotePort            The remote port.\r
-  @param  Protocol              The protocol type in the IP header.\r
-  @param  UseDefaultAddress     Whether this instance is using default address or not.\r
+  @param[in, out]  Node                  Pointer to the IPv4 device path node.\r
+  @param[in]       Controller            The handle where the NIC IP4 config protocol resides.\r
+  @param[in]       LocalIp               The local IPv4 address.\r
+  @param[in]       LocalPort             The local port.\r
+  @param[in]       RemoteIp              The remote IPv4 address.\r
+  @param[in]       RemotePort            The remote port.\r
+  @param[in]       Protocol              The protocol type in the IP header.\r
+  @param[in]       UseDefaultAddress     Whether this instance is using default address or not.\r
 \r
-  @retval None\r
 **/\r
 VOID\r
+EFIAPI\r
 NetLibCreateIPv4DPathNode (\r
   IN OUT IPv4_DEVICE_PATH  *Node,\r
   IN EFI_HANDLE            Controller,\r
@@ -1196,8 +1174,8 @@ NetLibCreateIPv4DPathNode (
   Node->Header.SubType = MSG_IPv4_DP;\r
   SetDevicePathNodeLength (&Node->Header, 19);\r
 \r
-  NetCopyMem (&Node->LocalIpAddress, &LocalIp, sizeof (EFI_IPv4_ADDRESS));\r
-  NetCopyMem (&Node->RemoteIpAddress, &RemoteIp, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Node->LocalIpAddress, &LocalIp, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Node->RemoteIpAddress, &RemoteIp, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   Node->LocalPort  = LocalPort;\r
   Node->RemotePort = RemotePort;\r
@@ -1222,13 +1200,14 @@ NetLibCreateIPv4DPathNode (
   IP opens these handle BY_DRIVER, use that info, we can get the\r
   UNDI/SNP handle.\r
 \r
-  @param  Controller            Then protocol handle to check\r
-  @param  ProtocolGuid          The protocol that is related with the handle.\r
+  @param[in]  Controller            Then protocol handle to check.\r
+  @param[in]  ProtocolGuid          The protocol that is related with the handle.\r
 \r
-  @return The UNDI/SNP handle or NULL.\r
+  @return The UNDI/SNP handle or NULL for errors.\r
 \r
 **/\r
 EFI_HANDLE\r
+EFIAPI\r
 NetLibGetNicHandle (\r
   IN EFI_HANDLE             Controller,\r
   IN EFI_GUID               *ProtocolGuid\r
@@ -1267,19 +1246,20 @@ NetLibGetNicHandle (
 /**\r
   Add a Deferred Procedure Call to the end of the DPC queue.\r
 \r
-  @DpcTpl           The EFI_TPL that the DPC should be invoked.\r
-  @DpcProcedure     Pointer to the DPC's function.\r
-  @DpcContext       Pointer to the DPC's context.  Passed to DpcProcedure\r
-                    when DpcProcedure is invoked.\r
+  @param[in]  DpcTpl           The EFI_TPL that the DPC should be invoked.\r
+  @param[in]  DpcProcedure     Pointer to the DPC's function.\r
+  @param[in]  DpcContext       Pointer to the DPC's context.  Passed to DpcProcedure\r
+                               when DpcProcedure is invoked.\r
 \r
   @retval  EFI_SUCCESS              The DPC was queued.\r
-  @retval  EFI_INVALID_PARAMETER    DpcTpl is not a valid EFI_TPL.\r
-                                    DpcProcedure is NULL.\r
+  @retval  EFI_INVALID_PARAMETER    DpcTpl is not a valid EFI_TPL, or DpcProcedure\r
+                                    is NULL.\r
   @retval  EFI_OUT_OF_RESOURCES     There are not enough resources available to\r
                                     add the DPC to the queue.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetLibQueueDpc (\r
   IN EFI_TPL            DpcTpl,\r
   IN EFI_DPC_PROCEDURE  DpcProcedure,\r
@@ -1290,13 +1270,17 @@ NetLibQueueDpc (
 }\r
 \r
 /**\r
-  Add a Deferred Procedure Call to the end of the DPC queue.\r
+  Dispatch the queue of DPCs. ALL DPCs that have been queued with a DpcTpl\r
+  value greater than or equal to the current TPL are invoked in the order that\r
+  they were queued.  DPCs with higher DpcTpl values are invoked before DPCs with\r
+  lower DpcTpl values.\r
 \r
   @retval  EFI_SUCCESS              One or more DPCs were invoked.\r
   @retval  EFI_NOT_FOUND            No DPCs were invoked.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 NetLibDispatchDpc (\r
   VOID\r
   )\r
@@ -1304,15 +1288,14 @@ NetLibDispatchDpc (
   return mDpc->DispatchDpc(mDpc);\r
 }\r
 \r
-\r
 /**\r
   The constructor function caches the pointer to DPC protocol.\r
 \r
   The constructor function locates DPC protocol from protocol database.\r
   It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r
 \r
-  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
-  @param  SystemTable   A pointer to the EFI System Table.\r
+  @param[in]  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param[in]  SystemTable   A pointer to the EFI System Table.\r
 \r
   @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
 \r