]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add VLAN support.
authorxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Dec 2009 13:47:55 +0000 (13:47 +0000)
committerxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Dec 2009 13:47:55 +0000 (13:47 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9649 6f19259b-4bc3-4df7-8a09-765794883524

30 files changed:
MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.h
MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg/Universal/Network/MnpDxe/ComponentName.c
MdeModulePkg/Universal/Network/MnpDxe/ComponentName.h
MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c
MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c
MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.h
MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
MdeModulePkg/Universal/Network/MnpDxe/MnpImpl.h
MdeModulePkg/Universal/Network/MnpDxe/MnpIo.c
MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c
MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c [new file with mode: 0644]
MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.h [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfig.vfr [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDriver.c [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.h [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigNvData.h [new file with mode: 0644]
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigStrings.uni [new file with mode: 0644]

index d19e3ac9b186b0390e460278b4af7d2211f824de..039e04f696f4a7f4d860a1702cc5d65e5ebb6a15 100644 (file)
@@ -28,6 +28,9 @@ typedef UINT16          TCP_PORTNO;
 #define  NET_ETHER_ADDR_LEN    6\r
 #define  NET_IFTYPE_ETHERNET   0x01\r
 \r
+#define  NET_VLAN_TAG_LEN      4\r
+#define  ETHER_TYPE_VLAN       0x8100\r
+\r
 #define  EFI_IP_PROTO_UDP      0x11\r
 #define  EFI_IP_PROTO_TCP      0x06\r
 #define  EFI_IP_PROTO_ICMP     0x01\r
@@ -67,6 +70,20 @@ typedef struct {
   UINT16                EtherType;\r
 } ETHER_HEAD;\r
 \r
+//\r
+// 802.1Q VLAN Tag Control Information\r
+//\r
+typedef union {\r
+  struct {\r
+    UINT16              Vid      : 12;  // Unique VLAN identifier (0 to 4094)\r
+    UINT16              Cfi      : 1;   // Canonical Format Indicator\r
+    UINT16              Priority : 3;   // 802.1Q priority level (0 to 7)\r
+  } Bits;\r
+  UINT16                Uint16;\r
+} VLAN_TCI;\r
+\r
+#define VLAN_TCI_CFI_CANONICAL_MAC      0\r
+#define VLAN_TCI_CFI_NON_CANONICAL_MAC  1\r
 \r
 //\r
 // The EFI_IP4_HEADER is hard to use because the source and\r
@@ -960,18 +977,104 @@ NetLibDestroyServiceChild (
   );\r
 \r
 /**\r
-  Convert the mac address of the simple network protocol installed on\r
-  SnpHandle to a unicode string. Callers are responsible for freeing the\r
-  string storage.\r
+  Get handle with Simple Network Protocol installed on it.\r
+\r
+  There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r
+  If Simple Network Protocol is already installed on the ServiceHandle, the\r
+  ServiceHandle will be returned. If SNP is not installed on the ServiceHandle,\r
+  try to find its parent handle with SNP installed.\r
+\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+  @param[out]  Snp              The pointer to store the address of the SNP instance.\r
+                                This is an optional parameter that may be NULL.\r
+\r
+  @return The SNP handle, or NULL if not found.\r
+\r
+**/\r
+EFI_HANDLE\r
+EFIAPI\r
+NetLibGetSnpHandle (\r
+  IN   EFI_HANDLE                  ServiceHandle,\r
+  OUT  EFI_SIMPLE_NETWORK_PROTOCOL **Snp  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Retrieve VLAN ID of a VLAN device handle.\r
+\r
+  Search VLAN device path node in Device Path of specified ServiceHandle and\r
+  return its VLAN ID. If no VLAN device path node found, then this ServiceHandle\r
+  is not a VLAN device handle, and 0 will be returned.\r
+\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+\r
+  @return VLAN ID of the device handle, or 0 if not a VLAN device.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+NetLibGetVlanId (\r
+  IN EFI_HANDLE             ServiceHandle\r
+  );\r
+\r
+/**\r
+  Find VLAN device handle with specified VLAN ID.\r
+\r
+  The VLAN child device handle is created by VLAN Config Protocol on ControllerHandle.\r
+  This function will append VLAN device path node to the parent device path,\r
+  and then use LocateDevicePath() to find the correct VLAN device handle.\r
+\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+  @param[in]   VLanId           The configured VLAN ID for the VLAN device.\r
+\r
+  @return The VLAN device handle, or NULL if not found.\r
+\r
+**/\r
+EFI_HANDLE\r
+EFIAPI\r
+NetLibGetVlanHandle (\r
+  IN EFI_HANDLE             ControllerHandle,\r
+  IN UINT16                 VlanId\r
+  );\r
+\r
+/**\r
+  Get MAC address associated with the network service handle.\r
+\r
+  There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r
+  If SNP is installed on the ServiceHandle or its parent handle, MAC address will\r
+  be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP.\r
 \r
-  Get the mac address of the Simple Network protocol from the SnpHandle. Then convert\r
-  the mac address into a unicode string. It takes 2 unicode characters to represent \r
-  a 1 byte binary buffer, plus one unicode character for the null terminator.\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+  @param[out]  MacAddress       The pointer to store the returned MAC address.\r
+  @param[out]  AddressSize      The length of returned MAC address.\r
+\r
+  @retval EFI_SUCCESS           MAC address is returned successfully.\r
+  @retval Others                Failed to get SNP mode data.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+NetLibGetMacAddress (\r
+  IN  EFI_HANDLE            ServiceHandle,\r
+  OUT EFI_MAC_ADDRESS       *MacAddress,\r
+  OUT UINTN                 *AddressSize\r
+  );\r
+\r
+/**\r
+  Convert MAC address of the NIC associated with specified Service Binding Handle\r
+  to a unicode string. Callers are responsible for freeing the string storage.\r
 \r
+  Locate simple network protocol associated with the Service Binding Handle and\r
+  get the mac address from SNP. Then convert the mac address into a unicode\r
+  string. It takes 2 unicode characters to represent a 1 byte binary buffer.\r
+  Plus one unicode character for the null-terminator.\r
 \r
-  @param[in]   SnpHandle             The handle on which the simple network protocol is\r
-                                     installed.\r
-  @param[in]   ImageHandle           The image handle to act as the agent handle to\r
+  @param[in]   ServiceHandle         The handle where network service binding 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
@@ -984,7 +1087,7 @@ NetLibDestroyServiceChild (
 EFI_STATUS\r
 EFIAPI\r
 NetLibGetMacString (\r
-  IN  EFI_HANDLE            SnpHandle,\r
+  IN  EFI_HANDLE            ServiceHandle,\r
   IN  EFI_HANDLE            ImageHandle,\r
   OUT CHAR16                **MacString\r
   );\r
index ffcd70ca844109d3171ef01b10e11d5d2bf4efdd..f58783cdfd3f8046b77b3301fc9f6b97ee8f6339 100644 (file)
@@ -111,6 +111,21 @@ GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mMonthName[] = {
   "Dec"\r
 };\r
 \r
+//\r
+// VLAN device path node template\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED VLAN_DEVICE_PATH mNetVlanDevicePathTemplate = {\r
+  {\r
+    MESSAGING_DEVICE_PATH,\r
+    MSG_VLAN_DP,\r
+    {\r
+      (UINT8) (sizeof (VLAN_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (VLAN_DEVICE_PATH)) >> 8)\r
+    }\r
+  },\r
+  0\r
+};\r
+\r
 /**\r
   Locate the handles that support SNP, then open one of them\r
   to send the syslog packets. The caller isn't required to close\r
@@ -1772,18 +1787,289 @@ NetLibDestroyServiceChild (
   return Status;\r
 }\r
 \r
+/**\r
+  Get handle with Simple Network Protocol installed on it.\r
+\r
+  There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r
+  If Simple Network Protocol is already installed on the ServiceHandle, the\r
+  ServiceHandle will be returned. If SNP is not installed on the ServiceHandle,\r
+  try to find its parent handle with SNP installed.\r
+\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+  @param[out]  Snp              The pointer to store the address of the SNP instance.\r
+                                This is an optional parameter that may be NULL.\r
+\r
+  @return The SNP handle, or NULL if not found.\r
+\r
+**/\r
+EFI_HANDLE\r
+EFIAPI\r
+NetLibGetSnpHandle (\r
+  IN   EFI_HANDLE                  ServiceHandle,\r
+  OUT  EFI_SIMPLE_NETWORK_PROTOCOL **Snp  OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EFI_SIMPLE_NETWORK_PROTOCOL  *SnpInstance;\r
+  EFI_DEVICE_PATH_PROTOCOL     *DevicePath;\r
+  EFI_HANDLE                   SnpHandle;\r
+\r
+  //\r
+  // Try to open SNP from ServiceHandle\r
+  //\r
+  SnpInstance = NULL;\r
+  Status = gBS->HandleProtocol (ServiceHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &SnpInstance);\r
+  if (!EFI_ERROR (Status)) {\r
+    if (Snp != NULL) {\r
+      *Snp = SnpInstance;\r
+    }\r
+    return ServiceHandle;\r
+  }\r
+\r
+  //\r
+  // Failed to open SNP, try to get SNP handle by LocateDevicePath()\r
+  //\r
+  DevicePath = DevicePathFromHandle (ServiceHandle);\r
+  if (DevicePath == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  SnpHandle = NULL;\r
+  Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &DevicePath, &SnpHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Failed to find SNP handle\r
+    //\r
+    return NULL;\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (SnpHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &SnpInstance);\r
+  if (!EFI_ERROR (Status)) {\r
+    if (Snp != NULL) {\r
+      *Snp = SnpInstance;\r
+    }\r
+    return SnpHandle;\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Retrieve VLAN ID of a VLAN device handle.\r
+\r
+  Search VLAN device path node in Device Path of specified ServiceHandle and\r
+  return its VLAN ID. If no VLAN device path node found, then this ServiceHandle\r
+  is not a VLAN device handle, and 0 will be returned.\r
+\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+\r
+  @return VLAN ID of the device handle, or 0 if not a VLAN device.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+NetLibGetVlanId (\r
+  IN EFI_HANDLE             ServiceHandle\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Node;\r
+\r
+  DevicePath = DevicePathFromHandle (ServiceHandle);\r
+  if (DevicePath == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  Node = DevicePath;\r
+  while (!IsDevicePathEnd (Node)) {\r
+    if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) {\r
+      return ((VLAN_DEVICE_PATH *) Node)->VlanId;\r
+    }\r
+    Node = NextDevicePathNode (Node);\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+/**\r
+  Find VLAN device handle with specified VLAN ID.\r
+\r
+  The VLAN child device handle is created by VLAN Config Protocol on ControllerHandle.\r
+  This function will append VLAN device path node to the parent device path,\r
+  and then use LocateDevicePath() to find the correct VLAN device handle.\r
+\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+  @param[in]   VLanId           The configured VLAN ID for the VLAN device.\r
+\r
+  @return The VLAN device handle, or NULL if not found.\r
+\r
+**/\r
+EFI_HANDLE\r
+EFIAPI\r
+NetLibGetVlanHandle (\r
+  IN EFI_HANDLE             ControllerHandle,\r
+  IN UINT16                 VlanId\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *VlanDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  VLAN_DEVICE_PATH          VlanNode;\r
+  EFI_HANDLE                Handle;\r
+\r
+  ParentDevicePath = DevicePathFromHandle (ControllerHandle);\r
+  if (ParentDevicePath == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Construct VLAN device path\r
+  //\r
+  CopyMem (&VlanNode, &mNetVlanDevicePathTemplate, sizeof (VLAN_DEVICE_PATH));\r
+  VlanNode.VlanId = VlanId;\r
+  VlanDevicePath = AppendDevicePathNode (\r
+                     ParentDevicePath,\r
+                     (EFI_DEVICE_PATH_PROTOCOL *) &VlanNode\r
+                     );\r
+  if (VlanDevicePath == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Find VLAN device handle\r
+  //\r
+  Handle = NULL;\r
+  DevicePath = VlanDevicePath;\r
+  gBS->LocateDevicePath (\r
+         &gEfiDevicePathProtocolGuid,\r
+         &DevicePath,\r
+         &Handle\r
+         );\r
+  if (!IsDevicePathEnd (DevicePath)) {\r
+    //\r
+    // Device path is not exactly match\r
+    //\r
+    Handle = NULL;\r
+  }\r
+\r
+  FreePool (VlanDevicePath);\r
+  return Handle;\r
+}\r
 \r
 /**\r
-  Convert the mac address of the simple network protocol installed on\r
-  SnpHandle to a unicode string. Callers are responsible for freeing the\r
-  string storage.\r
+  Get MAC address associated with the network service handle.\r
+\r
+  There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r
+  If SNP is installed on the ServiceHandle or its parent handle, MAC address will\r
+  be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP.\r
+\r
+  @param[in]   ServiceHandle    The handle where network service binding protocols are\r
+                                installed on.\r
+  @param[out]  MacAddress       The pointer to store the returned MAC address.\r
+  @param[out]  AddressSize      The length of returned MAC address.\r
+\r
+  @retval EFI_SUCCESS           MAC address is returned successfully.\r
+  @retval Others                Failed to get SNP mode data.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+NetLibGetMacAddress (\r
+  IN  EFI_HANDLE            ServiceHandle,\r
+  OUT EFI_MAC_ADDRESS       *MacAddress,\r
+  OUT UINTN                 *AddressSize\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp;\r
+  EFI_SIMPLE_NETWORK_MODE      *SnpMode;\r
+  EFI_SIMPLE_NETWORK_MODE      SnpModeData;\r
+  EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
+  EFI_SERVICE_BINDING_PROTOCOL *MnpSb;\r
+  EFI_HANDLE                   *SnpHandle;\r
+  EFI_HANDLE                   MnpChildHandle;\r
+\r
+  ASSERT (MacAddress != NULL);\r
+  ASSERT (AddressSize != NULL);\r
+\r
+  //\r
+  // Try to get SNP handle\r
+  //\r
+  Snp = NULL;\r
+  SnpHandle = NetLibGetSnpHandle (ServiceHandle, &Snp);\r
+  if (SnpHandle != NULL) {\r
+    //\r
+    // SNP found, use it directly\r
+    //\r
+    SnpMode = Snp->Mode;\r
+  } else {\r
+    //\r
+    // Failed to get SNP handle, try to get MAC address from MNP\r
+    //\r
+    MnpChildHandle = NULL;\r
+    Status = gBS->HandleProtocol (\r
+                    ServiceHandle,\r
+                    &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+                    (VOID **) &MnpSb\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
 \r
-  Get the mac address of the Simple Network protocol from the SnpHandle. Then convert\r
-  the mac address into a unicode string. It takes 2 unicode characters to represent \r
-  a 1 byte binary buffer. Plus one unicode character for the null-terminator.\r
+    //\r
+    // Create a MNP child\r
+    //\r
+    Status = MnpSb->CreateChild (MnpSb, &MnpChildHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Open MNP protocol\r
+    //\r
+    Status = gBS->HandleProtocol (\r
+                    MnpChildHandle,\r
+                    &gEfiManagedNetworkProtocolGuid,\r
+                    (VOID **) &Mnp\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Try to get SNP mode from MNP\r
+    //\r
+    Status = Mnp->GetModeData (Mnp, NULL, &SnpModeData);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    SnpMode = &SnpModeData;\r
+\r
+    //\r
+    // Destroy the MNP child\r
+    //\r
+    MnpSb->DestroyChild (MnpSb, MnpChildHandle);\r
+  }\r
+\r
+  *AddressSize = SnpMode->HwAddressSize;\r
+  CopyMem (MacAddress->Addr, SnpMode->CurrentAddress.Addr, SnpMode->HwAddressSize);\r
 \r
+  return EFI_SUCCESS;\r
+}\r
 \r
-  @param[in]   SnpHandle             The handle where the simple network protocol is\r
+/**\r
+  Convert MAC address of the NIC associated with specified Service Binding Handle\r
+  to a unicode string. Callers are responsible for freeing the string storage.\r
+\r
+  Locate simple network protocol associated with the Service Binding Handle and\r
+  get the mac address from SNP. Then convert the mac address into a unicode\r
+  string. It takes 2 unicode characters to represent a 1 byte binary buffer.\r
+  Plus one unicode character for the null-terminator.\r
+\r
+  @param[in]   ServiceHandle         The handle where network service binding 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
@@ -1798,57 +2084,61 @@ NetLibDestroyServiceChild (
 EFI_STATUS\r
 EFIAPI\r
 NetLibGetMacString (\r
-  IN  EFI_HANDLE            SnpHandle,\r
+  IN  EFI_HANDLE            ServiceHandle,\r
   IN  EFI_HANDLE            ImageHandle,\r
   OUT CHAR16                **MacString\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE      *Mode;\r
-  CHAR16                       *MacAddress;\r
+  EFI_MAC_ADDRESS              MacAddress;\r
   UINT8                        *HwAddress;\r
+  UINTN                        HwAddressSize;\r
+  UINT16                       VlanId;\r
+  CHAR16                       *String;\r
   UINTN                        Index;\r
 \r
-  *MacString = NULL;\r
+  ASSERT (MacString != NULL);\r
 \r
   //\r
-  // Get the Simple Network protocol from the SnpHandle.\r
+  // Get MAC address of the network device\r
   //\r
-  Status = gBS->OpenProtocol (\r
-                  SnpHandle,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
-                  (VOID **) &Snp,\r
-                  ImageHandle,\r
-                  SnpHandle,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
+  Status = NetLibGetMacAddress (ServiceHandle, &MacAddress, &HwAddressSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  Mode = Snp->Mode;\r
-\r
   //\r
   // It takes 2 unicode characters to represent a 1 byte binary buffer.\r
+  // If VLAN is configured, it will need extra 5 characters like "\0005".\r
   // Plus one unicode character for the null-terminator.\r
   //\r
-  MacAddress = AllocatePool ((2 * Mode->HwAddressSize + 1) * sizeof (CHAR16));\r
-  if (MacAddress == NULL) {\r
+  String = AllocateZeroPool ((2 * HwAddressSize + 5 + 1) * sizeof (CHAR16));\r
+  if (String == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  *MacString = MacAddress;\r
+  *MacString = String;\r
 \r
   //\r
-  // Convert the mac address into a unicode string.\r
+  // Convert the MAC address into a unicode string.\r
   //\r
-  HwAddress = Mode->CurrentAddress.Addr;\r
-  for (Index = 0; Index < Mode->HwAddressSize; Index++) {\r
-    MacAddress += UnicodeValueToString (MacAddress, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);\r
+  HwAddress = &MacAddress.Addr[0];\r
+  for (Index = 0; Index < HwAddressSize; Index++) {\r
+    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);\r
   }\r
 \r
-  MacAddress[Mode->HwAddressSize * 2] = L'\0';\r
+  //\r
+  // Append VLAN ID if any\r
+  //\r
+  VlanId = NetLibGetVlanId (ServiceHandle);\r
+  if (VlanId != 0) {\r
+    *String++ = L'\\';\r
+    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);\r
+  }\r
 \r
+  //\r
+  // Null terminate the Unicode string\r
+  //\r
+  *String = L'\0';\r
 \r
   return EFI_SUCCESS;\r
 }\r
index 384eff8807b1c3606f94618e3fa247d548e50c70..f214be85182ba63d458a57739f626d0d49c26167 100644 (file)
   MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf\r
   MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf\r
   MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf\r
+  MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf\r
   MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf\r
   MdeModulePkg/Universal/Network/SnpDxe/SnpDxe.inf\r
   MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf\r
index 25d89f54e31e1f517ae32fc4006c53934b83154a..35214f2ce95b19c09d7f7b0ee286b22584c51516 100644 (file)
@@ -67,7 +67,7 @@ IScsiIpToStr (
 \r
 /**\r
   Update the list of iSCSI devices the iSCSI driver is controlling.\r
-  \r
+\r
   @retval EFI_SUCCESS            The callback successfully handled the action.\r
   @retval Others                 Other errors as indicated.   \r
 **/\r
@@ -84,19 +84,20 @@ IScsiUpdateDeviceList (
   UINTN                       HandleIndex;\r
   UINTN                       Index;\r
   UINTN                       LastDeviceIndex;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE     *Mode;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
   ISCSI_MAC_INFO              *CurMacInfo;\r
   ISCSI_MAC_INFO              TempMacInfo;\r
-  CHAR16                      MacString[65];\r
+  CHAR16                      MacString[70];\r
   UINTN                       DeviceListSize;\r
 \r
   //\r
-  // Dump all the handles the Simple Network Protocol is installed on.\r
+  // Dump all the handles the Managed Network Service Binding Protocol is installed on.\r
   //\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
+                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
                   NULL,\r
                   &NumHandles,\r
                   &Handles\r
@@ -127,14 +128,15 @@ IScsiUpdateDeviceList (
     LastDeviceIndex = 0;\r
 \r
     for (HandleIndex = 0; HandleIndex < NumHandles; HandleIndex++) {\r
-      gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
-\r
-      Mode = Snp->Mode;\r
+      Status = NetLibGetMacAddress (Handles[HandleIndex], &MacAddress, &HwAddressSize);\r
+      ASSERT (Status == EFI_SUCCESS);\r
+      VlanId = NetLibGetVlanId (Handles[HandleIndex]);\r
 \r
       for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) {\r
         CurMacInfo = &DeviceList->MacInfo[Index];\r
-        if ((CurMacInfo->Len == Mode->HwAddressSize) &&\r
-            (NET_MAC_EQUAL (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize))\r
+        if ((CurMacInfo->Len == HwAddressSize) &&\r
+            (CurMacInfo->VlanId == VlanId) &&\r
+            (NET_MAC_EQUAL (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize))\r
             ) {\r
           //\r
           // The previous configured NIC is still here.\r
@@ -163,7 +165,7 @@ IScsiUpdateDeviceList (
       // delete the variables\r
       //\r
       CurMacInfo = &DeviceList->MacInfo[Index];\r
-      IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, MacString);\r
+      IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, CurMacInfo->VlanId, MacString);\r
       gRT->SetVariable (MacString, &gEfiIScsiInitiatorNameProtocolGuid, 0, 0, NULL);\r
       gRT->SetVariable (MacString, &mIScsiCHAPAuthInfoGuid, 0, 0, NULL);\r
     }\r
@@ -181,12 +183,12 @@ IScsiUpdateDeviceList (
   DeviceList->NumDevice = (UINT8) NumHandles;\r
 \r
   for (Index = 0; Index < NumHandles; Index++) {\r
-    gBS->HandleProtocol (Handles[Index], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
-    Mode        = Snp->Mode;\r
+    NetLibGetMacAddress (Handles[Index], &MacAddress, &HwAddressSize);\r
 \r
     CurMacInfo  = &DeviceList->MacInfo[Index];\r
-    CopyMem (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize);\r
-    CurMacInfo->Len = (UINT8) Mode->HwAddressSize;\r
+    CopyMem (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize);\r
+    CurMacInfo->Len = (UINT8) HwAddressSize;\r
+    CurMacInfo->VlanId = NetLibGetVlanId (Handles[Index]);\r
   }\r
 \r
   gRT->SetVariable (\r
@@ -776,7 +778,9 @@ IScsiConfigUpdateForm (
   ISCSI_CONFIG_FORM_ENTRY     *ConfigFormEntry;\r
   BOOLEAN                     EntryExisted;\r
   EFI_STATUS                  Status;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
   CHAR16                      PortString[128];\r
   UINT16                      FormIndex;\r
   UINTN                       BufferSize;\r
@@ -813,17 +817,13 @@ IScsiConfigUpdateForm (
       ConfigFormEntry->Controller = Controller;\r
 \r
       //\r
-      // Get the simple network protocol and convert the MAC address into\r
-      // the formatted string.\r
+      // Get the MAC address and convert it into the formatted string.\r
       //\r
-      Status = gBS->HandleProtocol (\r
-                      Controller,\r
-                      &gEfiSimpleNetworkProtocolGuid,\r
-                      (VOID **)&Snp\r
-                      );\r
+      Status = NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize);\r
       ASSERT (Status == EFI_SUCCESS);\r
+      VlanId = NetLibGetVlanId (Controller);\r
 \r
-      IScsiMacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);\r
+      IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, ConfigFormEntry->MacString);\r
 \r
       //\r
       // Get the normal session configuration data.\r
index b0a748ae9ca62f505475a0ff7dd235df62de80af..5b2bc6a73bccc56ccff8efd845831c2f0d2e18eb 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The header file of IScsiConfig.c.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2004 - 2009, 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
@@ -70,6 +70,7 @@ extern UINT8  IScsiDxeStrings[];
 typedef struct _ISCSI_MAC_INFO {\r
   EFI_MAC_ADDRESS Mac;\r
   UINT8           Len;\r
+  UINT16          VlanId;\r
 } ISCSI_MAC_INFO;\r
 \r
 typedef struct _ISCSI_DEVICE_LIST {\r
index ca08da7fa410e89dd8abd55ad1d40f22d3c97ee0..6ca8a217f573251a39bac8ff44cd094f7383f3b0 100644 (file)
@@ -246,31 +246,6 @@ IScsiGetNICPciLocation (
   return (UINT16) ((Bus << 8) | (Device << 3) | Function);\r
 }\r
 \r
-/**\r
-  Get the MAC address of the controller.\r
-  \r
-  @param[in]  Controller    The handle of the controller.\r
-\r
-  @return EFI_MAC_ADDRESS * The mac address.\r
-**/\r
-EFI_MAC_ADDRESS *\r
-IScsiGetMacAddress (\r
-  IN EFI_HANDLE  Controller\r
-  )\r
-{\r
-  EFI_STATUS                  Status;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-\r
-  Status = gBS->HandleProtocol (\r
-                  Controller,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
-                  (VOID **) &Snp\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  return &Snp->Mode->PermanentAddress;\r
-}\r
-\r
 /**\r
   Fill the NIC and target sections in iSCSI Boot Firmware Table.\r
 \r
@@ -296,7 +271,8 @@ IScsiFillNICAndTargetSections (
   UINT16                                                *SectionOffset;\r
   UINTN                                                 Index;\r
   UINT16                                                Length;\r
-  EFI_MAC_ADDRESS                                       *Mac;\r
+  EFI_MAC_ADDRESS                                       MacAddress;\r
+  UINTN                                                 HwAddressSize;\r
   ISCSI_PRIVATE_PROTOCOL                                *IScsiIdentifier;\r
   EFI_STATUS                                            Status;\r
 \r
@@ -354,8 +330,11 @@ IScsiFillNICAndTargetSections (
     IScsiMapV4ToV6Addr (&SessionConfigData->SecondaryDns, &Nic->SecondaryDns);\r
     IScsiMapV4ToV6Addr (&SessionConfigData->DhcpServer, &Nic->DhcpServer);\r
 \r
-    Mac = IScsiGetMacAddress (DriverData->Controller);\r
-    CopyMem (Nic->Mac, Mac, sizeof (Nic->Mac));\r
+    Nic->VLanTag = NetLibGetVlanId (DriverData->Controller);\r
+\r
+    Status = NetLibGetMacAddress (DriverData->Controller, &MacAddress, &HwAddressSize);\r
+    ASSERT (Status == EFI_SUCCESS);\r
+    CopyMem (Nic->Mac, MacAddress.Addr, sizeof (Nic->Mac));\r
 \r
     //\r
     // Get the PCI location of the Nic.\r
index 2d951747ee60b87ce576383b9518a0d39b13a944..865acb090e429cea77a4fa79837871cd606be14d 100644 (file)
@@ -353,18 +353,21 @@ IScsiAsciiStrToIp (
 /**\r
   Convert the mac address into a hexadecimal encoded "-" seperated string.\r
 \r
-  @param[in]  Mac The mac address.\r
-  @param[in]  Len  Length in bytes of the mac address.\r
-  @param[out] Str The storage to return the mac string.\r
+  @param[in]  Mac     The mac address.\r
+  @param[in]  Len     Length in bytes of the mac address.\r
+  @param[in]  VlanId  VLAN ID of the network device.\r
+  @param[out] Str     The storage to return the mac string.\r
 **/\r
 VOID\r
 IScsiMacAddrToStr (\r
   IN  EFI_MAC_ADDRESS  *Mac,\r
   IN  UINT32           Len,\r
+  IN  UINT16           VlanId,\r
   OUT CHAR16           *Str\r
   )\r
 {\r
   UINT32  Index;\r
+  CHAR16  *String;\r
 \r
   for (Index = 0; Index < Len; Index++) {\r
     Str[3 * Index]      = (CHAR16) IScsiHexString[(Mac->Addr[Index] >> 4) & 0x0F];\r
@@ -372,7 +375,12 @@ IScsiMacAddrToStr (
     Str[3 * Index + 2]  = L'-';\r
   }\r
 \r
-  Str[3 * Index - 1] = L'\0';\r
+  String = &Str[3 * Index - 1] ;\r
+  if (VlanId != 0) {\r
+    String += UnicodeSPrint (String, 6 * sizeof (CHAR16), L"\\%04x", (UINTN) VlanId);\r
+  }\r
+\r
+  *String = L'\0';\r
 }\r
 \r
 /**\r
@@ -625,9 +633,10 @@ IScsiGetConfigData (
   EFI_STATUS                  Status;\r
   ISCSI_SESSION               *Session;\r
   UINTN                       BufferSize;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE     *Mode;\r
-  CHAR16                      MacString[65];\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
+  CHAR16                      MacString[70];\r
 \r
   //\r
   // get the iSCSI Initiator Name\r
@@ -643,21 +652,13 @@ IScsiGetConfigData (
     return Status;\r
   }\r
 \r
-  Status = gBS->HandleProtocol (\r
-                  Private->Controller,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
-                  (VOID **)&Snp\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Mode = Snp->Mode;\r
-\r
   //\r
   // Get the mac string, it's the name of various variable\r
   //\r
-  IScsiMacAddrToStr (&Mode->PermanentAddress, Mode->HwAddressSize, MacString);\r
+  Status = NetLibGetMacAddress (Private->Controller, &MacAddress, &HwAddressSize);\r
+  ASSERT (Status == EFI_SUCCESS);\r
+  VlanId = NetLibGetVlanId (Private->Controller);\r
+  IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacString);\r
 \r
   //\r
   // Get the normal configuration.\r
index 27e87942bef987aedb98b86aca681b58fef4a5b1..61a772f0cba6a3678f55e1373ea89841ef9109a8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous definitions for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2004 - 2009, 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
@@ -115,14 +115,16 @@ IScsiUnicodeStrToAsciiStr (
 /**\r
   Convert the mac address into a hexadecimal encoded "-" seperated string.\r
 \r
-  @param[in]  Mac The mac address.\r
-  @param[in]  Len  Length in bytes of the mac address.\r
-  @param[out] Str The storage to return the mac string.\r
+  @param[in]  Mac     The mac address.\r
+  @param[in]  Len     Length in bytes of the mac address.\r
+  @param[in]  VlanId  VLAN ID of the network device.\r
+  @param[out] Str     The storage to return the mac string.\r
 **/\r
 VOID\r
 IScsiMacAddrToStr (\r
   IN  EFI_MAC_ADDRESS  *Mac,\r
   IN  UINT32           Len,\r
+  IN  UINT16           VlanId,\r
   OUT CHAR16           *Str\r
   );\r
 \r
index e8814a1e9f438f8da82b5af0fad46a55f70baf56..457b6da04d863a01c0a44a92db2e801122c627fd 100644 (file)
@@ -89,7 +89,7 @@ typedef struct _IP4_CONFIG_FORM_ENTRY {
   LIST_ENTRY                    Link;\r
   IP4_CONFIG_INSTANCE           *Ip4ConfigInstance;\r
   EFI_HANDLE                    Controller;\r
-  CHAR16                        MacString[95];\r
+  CHAR16                        *MacString;\r
   EFI_STRING_ID                 PortTitleToken;\r
   EFI_STRING_ID                 PortTitleHelpToken;\r
   IP4_CONFIG_SESSION_DATA       SessionConfigData;\r
index 9e7850072ba6df1b37c8ddec6481467195d1ebdc..d7a04b60b4778134cb7cd2cc531a0fa468c4184d 100644 (file)
@@ -970,7 +970,6 @@ Ip4ConfigUpdateForm (
   IP4CONFIG_FORM_ENTRY        *ConfigFormEntry;\r
   BOOLEAN                     EntryExisted;\r
   EFI_STATUS                  Status;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
   CHAR16                      PortString[128];\r
   UINT16                      FormIndex;\r
   VOID                        *StartOpCodeHandle;\r
@@ -1006,19 +1005,9 @@ Ip4ConfigUpdateForm (
       InitializeListHead (&ConfigFormEntry->Link);\r
       ConfigFormEntry->Controller = Instance->Controller;\r
 \r
-      //\r
-      // Get the simple network protocol and convert the MAC address into\r
-      // the formatted string.\r
-      //\r
-      Status = gBS->HandleProtocol (\r
-                      Instance->Controller,\r
-                      &gEfiSimpleNetworkProtocolGuid,\r
-                      (VOID **)&Snp\r
-                      );\r
+      Status = NetLibGetMacString (Instance->Controller, Instance->Image, &ConfigFormEntry->MacString);\r
       ASSERT (Status == EFI_SUCCESS);\r
 \r
-      Ip4MacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);\r
-\r
       //\r
       // Compose the Port string and create a new EFI_STRING_ID.\r
       //\r
@@ -1039,6 +1028,7 @@ Ip4ConfigUpdateForm (
 \r
     mNumberOfIp4Devices--;\r
     RemoveEntryList (&ConfigFormEntry->Link);\r
+    FreePool (ConfigFormEntry->MacString);\r
     FreePool (ConfigFormEntry);\r
   }\r
 \r
index 1b7fa4e60345009c1ec71ab9d37651ef1e500744..5e297821a2cf028f66906166c87eec5f15814955 100644 (file)
@@ -291,6 +291,12 @@ Ip4CreateService (
   InsertHeadList (&IpSb->Interfaces, &IpSb->DefaultInterface->Link);\r
 \r
   IpSb->MaxPacketSize = IpSb->SnpMode.MaxPacketSize - sizeof (IP4_HEAD);\r
+  if (NetLibGetVlanId (IpSb->Controller) != 0) {\r
+    //\r
+    // This is a VLAN device, reduce MTU by VLAN tag length\r
+    //\r
+    IpSb->MaxPacketSize -= NET_VLAN_TAG_LEN;\r
+  }\r
   IpSb->MacString = NULL;\r
 \r
   *Service = IpSb;\r
index e8482a5404a40a3e671de1f106eca487dcef8573..be38685ad14efdd120f84449f1f592ed74f0b80b 100644 (file)
@@ -1,25 +1,24 @@
 /** @file\r
   UEFI Component Name(2) protocol implementation for MnpDxe driver.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation. <BR> \r
-All rights reserved. This program and the accompanying materials are licensed \r
-and made available under the terms and conditions of the BSD License which \r
-accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
+Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
 \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
 **/\r
 \r
-\r
-#include "MnpDriver.h"\r
-\r
+#include  "MnpDriver.h"\r
 \r
 //\r
 // EFI Component Name Protocol\r
 //\r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gMnpComponentName = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL   gMnpComponentName = {\r
   MnpComponentNameGetDriverName,\r
   MnpComponentNameGetControllerName,\r
   "eng"\r
@@ -28,14 +27,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gMnpComponentName = {
 //\r
 // EFI Component Name 2 Protocol\r
 //\r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2 = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL  gMnpComponentName2 = {\r
   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) MnpComponentNameGetDriverName,\r
   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) MnpComponentNameGetControllerName,\r
   "en"\r
 };\r
 \r
-\r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE      mMnpDriverNameTable[] = {\r
   {\r
     "eng;en",\r
     L"MNP Network Service Driver"\r
@@ -88,9 +86,9 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
 EFI_STATUS\r
 EFIAPI\r
 MnpComponentNameGetDriverName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
-  IN  CHAR8                        *Language,\r
-  OUT CHAR16                       **DriverName\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **DriverName\r
   )\r
 {\r
   return LookupUnicodeString2 (\r
@@ -149,9 +147,9 @@ MnpComponentNameGetDriverName (
                                 Language from the point of view of the driver\r
                                 specified by This.\r
 \r
-  @retval EFI_SUCCESS           The Unicode string for the user readable name \r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name\r
                                 specified by This, ControllerHandle, ChildHandle,\r
-                                                               and Language was returned in ControllerName.\r
+                                and Language was returned in ControllerName.\r
 \r
   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
 \r
@@ -173,11 +171,11 @@ MnpComponentNameGetDriverName (
 EFI_STATUS\r
 EFIAPI\r
 MnpComponentNameGetControllerName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
-  IN  EFI_HANDLE                                      ControllerHandle,\r
-  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
-  IN  CHAR8                                           *Language,\r
-  OUT CHAR16                                          **ControllerName\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     EFI_HANDLE                    ControllerHandle,\r
+  IN     EFI_HANDLE                    ChildHandle        OPTIONAL,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **ControllerName\r
   )\r
 {\r
   return EFI_UNSUPPORTED;\r
index 4d418062de90d6c6f4aaf0e4418e37729c05a391..956e49ce17e4a6d2ff48a2945e17aec3cd439863 100644 (file)
@@ -1,10 +1,11 @@
 /** @file\r
   The header file of UEFI Component Name(2) protocol.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation.<BR>\r
+Copyright (c) 2004 - 2009, 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
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
 http://opensource.org/licenses/bsd-license.php\r
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
@@ -18,8 +19,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/ComponentName.h>\r
 #include <Protocol/ComponentName2.h>\r
 \r
-extern EFI_COMPONENT_NAME2_PROTOCOL       gMnpComponentName2;\r
-extern EFI_COMPONENT_NAME_PROTOCOL        gMnpComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gMnpComponentName;\r
 \r
 /**\r
   Retrieves a Unicode string that is the user readable name of the driver.\r
@@ -63,12 +64,11 @@ extern EFI_COMPONENT_NAME_PROTOCOL        gMnpComponentName;
 EFI_STATUS\r
 EFIAPI\r
 MnpComponentNameGetDriverName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
-  IN  CHAR8                        *Language,\r
-  OUT CHAR16                       **DriverName\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **DriverName\r
   );\r
 \r
-\r
 /**\r
   Retrieves a Unicode string that is the user readable name of the controller\r
   that is being managed by a driver.\r
@@ -116,9 +116,9 @@ MnpComponentNameGetDriverName (
                                 Language from the point of view of the driver\r
                                 specified by This.\r
 \r
-  @retval EFI_SUCCESS           The Unicode string for the user readable name \r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name\r
                                 specified by This, ControllerHandle, ChildHandle,\r
-                                                               and Language was returned in ControllerName.\r
+                                and Language was returned in ControllerName.\r
 \r
   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
 \r
@@ -140,11 +140,11 @@ MnpComponentNameGetDriverName (
 EFI_STATUS\r
 EFIAPI\r
 MnpComponentNameGetControllerName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
-  IN  EFI_HANDLE                                      ControllerHandle,\r
-  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
-  IN  CHAR8                                           *Language,\r
-  OUT CHAR16                                          **ControllerName\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     EFI_HANDLE                    ControllerHandle,\r
+  IN     EFI_HANDLE                    ChildHandle        OPTIONAL,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **ControllerName\r
   );\r
 \r
 #endif\r
index 7659d7ef1085b55c6a922bbab295bca635865155..af642a50d9ff4092c206e6255214e7fe83e7c13e 100644 (file)
@@ -1,19 +1,20 @@
 /** @file\r
   Implementation of Managed Network Protocol private services.\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation. <BR> \r
-All rights reserved. This program and the accompanying materials are licensed \r
-and made available under the terms and conditions of the BSD License which \r
-accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
+Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
 \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
 **/\r
 \r
-\r
 #include "MnpImpl.h"\r
+#include "MnpVlan.h"\r
 \r
 EFI_SERVICE_BINDING_PROTOCOL    mMnpServiceBindingProtocol = {\r
   MnpServiceBindingCreateChild,\r
@@ -46,73 +47,70 @@ EFI_MANAGED_NETWORK_CONFIG_DATA mMnpDefaultConfigData = {
 \r
 \r
 /**\r
-  Add Count of net buffers to MnpServiceData->FreeNbufQue. The length of the net\r
-  buffer is specified by MnpServiceData->BufferLength. \r
+  Add Count of net buffers to MnpDeviceData->FreeNbufQue. The length of the net\r
+  buffer is specified by MnpDeviceData->BufferLength.\r
 \r
-  @param[in, out]  MnpServiceData        Pointer to the MNP_SERVICE_DATA.\r
+  @param[in, out]  MnpDeviceData         Pointer to the MNP_DEVICE_DATA.\r
   @param[in]       Count                 Number of NET_BUFFERs to add.\r
 \r
-  @retval EFI_SUCCESS           The specified amount of NET_BUFs are allocated \r
-                                and added to MnpServiceData->FreeNbufQue.\r
+  @retval EFI_SUCCESS           The specified amount of NET_BUFs are allocated\r
+                                and added to MnpDeviceData->FreeNbufQue.\r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate a NET_BUF structure.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpAddFreeNbuf (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN UINTN                 Count\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
+  IN     UINTN             Count\r
   )\r
 {\r
   EFI_STATUS  Status;\r
   UINTN       Index;\r
   NET_BUF     *Nbuf;\r
 \r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
-  ASSERT ((Count > 0) && (MnpServiceData->BufferLength > 0));\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
+  ASSERT ((Count > 0) && (MnpDeviceData->BufferLength > 0));\r
 \r
   Status = EFI_SUCCESS;\r
-\r
   for (Index = 0; Index < Count; Index++) {\r
-\r
-    Nbuf = NetbufAlloc (MnpServiceData->BufferLength + MnpServiceData->PaddingSize);\r
+    Nbuf = NetbufAlloc (MnpDeviceData->BufferLength + MnpDeviceData->PaddingSize);\r
     if (Nbuf == NULL) {\r
-\r
       DEBUG ((EFI_D_ERROR, "MnpAddFreeNbuf: NetBufAlloc failed.\n"));\r
+\r
       Status = EFI_OUT_OF_RESOURCES;\r
       break;\r
     }\r
 \r
-    if (MnpServiceData->PaddingSize > 0) {\r
+    if (MnpDeviceData->PaddingSize > 0) {\r
       //\r
       // Pad padding bytes before the media header\r
       //\r
-      NetbufAllocSpace (Nbuf, MnpServiceData->PaddingSize, NET_BUF_TAIL);\r
-      NetbufTrim (Nbuf, MnpServiceData->PaddingSize, NET_BUF_HEAD);\r
+      NetbufAllocSpace (Nbuf, MnpDeviceData->PaddingSize, NET_BUF_TAIL);\r
+      NetbufTrim (Nbuf, MnpDeviceData->PaddingSize, NET_BUF_HEAD);\r
     }\r
 \r
-    NetbufQueAppend (&MnpServiceData->FreeNbufQue, Nbuf);\r
+    NetbufQueAppend (&MnpDeviceData->FreeNbufQue, Nbuf);\r
   }\r
 \r
-  MnpServiceData->NbufCnt += Index;\r
-\r
+  MnpDeviceData->NbufCnt += Index;\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
-  Allocate a free NET_BUF from MnpServiceData->FreeNbufQue. If there is none\r
+  Allocate a free NET_BUF from MnpDeviceData->FreeNbufQue. If there is none\r
   in the queue, first try to allocate some and add them into the queue, then\r
   fetch the NET_BUF from the updated FreeNbufQue.\r
 \r
-  @param[in, out]  MnpServiceData        Pointer to the MNP_SERVICE_DATA.\r
+  @param[in, out]  MnpDeviceData        Pointer to the MNP_DEVICE_DATA.\r
 \r
-  @return     Pointer to the allocated free NET_BUF structure, if NULL the \r
+  @return     Pointer to the allocated free NET_BUF structure, if NULL the\r
               operation is failed.\r
 \r
 **/\r
 NET_BUF *\r
 MnpAllocNbuf (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData\r
   )\r
 {\r
   EFI_STATUS    Status;\r
@@ -120,37 +118,34 @@ MnpAllocNbuf (
   NET_BUF       *Nbuf;\r
   EFI_TPL       OldTpl;\r
 \r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
-  FreeNbufQue = &MnpServiceData->FreeNbufQue;\r
-\r
-  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+  FreeNbufQue = &MnpDeviceData->FreeNbufQue;\r
+  OldTpl      = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
   //\r
   // Check whether there are available buffers, or else try to add some.\r
   //\r
   if (FreeNbufQue->BufNum == 0) {\r
-\r
-    if ((MnpServiceData->NbufCnt + MNP_NET_BUFFER_INCREASEMENT) > MNP_MAX_NET_BUFFER_NUM) {\r
-\r
+    if ((MnpDeviceData->NbufCnt + MNP_NET_BUFFER_INCREASEMENT) > MNP_MAX_NET_BUFFER_NUM) {\r
       DEBUG (\r
         (EFI_D_ERROR,\r
         "MnpAllocNbuf: The maximum NET_BUF size is reached for MNP driver instance %p.\n",\r
-        MnpServiceData)\r
+        MnpDeviceData)\r
         );\r
 \r
       Nbuf = NULL;\r
       goto ON_EXIT;\r
     }\r
 \r
-    Status = MnpAddFreeNbuf (MnpServiceData, MNP_NET_BUFFER_INCREASEMENT);\r
+    Status = MnpAddFreeNbuf (MnpDeviceData, MNP_NET_BUFFER_INCREASEMENT);\r
     if (EFI_ERROR (Status)) {\r
-\r
       DEBUG (\r
         (EFI_D_ERROR,\r
         "MnpAllocNbuf: Failed to add NET_BUFs into the FreeNbufQue, %r.\n",\r
         Status)\r
         );\r
+\r
       //\r
       // Don't return NULL, perhaps MnpAddFreeNbuf does add some NET_BUFs but\r
       // the amount is less than MNP_NET_BUFFER_INCREASEMENT.\r
@@ -177,19 +172,19 @@ ON_EXIT:
 /**\r
   Try to reclaim the Nbuf into the buffer pool.\r
 \r
-  @param[in, out]  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in, out]  MnpDeviceData         Pointer to the mnp device context data.\r
   @param[in, out]  Nbuf                  Pointer to the NET_BUF to free.\r
 \r
 **/\r
 VOID\r
 MnpFreeNbuf (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
   IN OUT NET_BUF           *Nbuf\r
   )\r
 {\r
   EFI_TPL  OldTpl;\r
 \r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
   ASSERT (Nbuf->RefCnt > 1);\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
@@ -201,7 +196,15 @@ MnpFreeNbuf (
     // Trim all buffer contained in the Nbuf, then append it to the NbufQue.\r
     //\r
     NetbufTrim (Nbuf, Nbuf->TotalSize, NET_BUF_TAIL);\r
-    NetbufQueAppend (&MnpServiceData->FreeNbufQue, Nbuf);\r
+\r
+    if (NetbufAllocSpace (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD) != NULL) {\r
+      //\r
+      // There is space reserved for vlan tag in the head, reclaim it\r
+      //\r
+      NetbufTrim (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_TAIL);\r
+    }\r
+\r
+    NetbufQueAppend (&MnpDeviceData->FreeNbufQue, Nbuf);\r
   }\r
 \r
   gBS->RestoreTPL (OldTpl);\r
@@ -209,9 +212,9 @@ MnpFreeNbuf (
 \r
 \r
 /**\r
-  Initialize the mnp service context data.\r
+  Initialize the mnp device context data.\r
 \r
-  @param[in, out]  MnpServiceData     Pointer to the mnp service context data.\r
+  @param[in, out]  MnpDeviceData      Pointer to the mnp device context data.\r
   @param[in]       ImageHandle        The driver image handle.\r
   @param[in]       ControllerHandle   Handle of device to bind driver to.\r
 \r
@@ -221,24 +224,24 @@ MnpFreeNbuf (
 \r
 **/\r
 EFI_STATUS\r
-MnpInitializeServiceData (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN EFI_HANDLE            ImageHandle,\r
-  IN EFI_HANDLE            ControllerHandle\r
+MnpInitializeDeviceData (\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
+  IN     EFI_HANDLE        ImageHandle,\r
+  IN     EFI_HANDLE        ControllerHandle\r
   )\r
 {\r
-  EFI_STATUS                   Status;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE      *SnpMode;\r
-\r
-  MnpServiceData->Signature = MNP_SERVICE_DATA_SIGNATURE;\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
+  EFI_SIMPLE_NETWORK_MODE     *SnpMode;\r
 \r
-  MnpServiceData->ControllerHandle = ControllerHandle;\r
+  MnpDeviceData->Signature        = MNP_DEVICE_DATA_SIGNATURE;\r
+  MnpDeviceData->ImageHandle      = ImageHandle;\r
+  MnpDeviceData->ControllerHandle = ControllerHandle;\r
 \r
   //\r
-  // Copy the ServiceBinding structure.\r
+  // Copy the MNP Protocol interfaces from the template.\r
   //\r
-  MnpServiceData->ServiceBinding = mMnpServiceBindingProtocol;\r
+  CopyMem (&MnpDeviceData->VlanConfig, &mVlanConfigProtocolTemplate, sizeof (EFI_VLAN_CONFIG_PROTOCOL));\r
 \r
   //\r
   // Open the Simple Network protocol.\r
@@ -258,57 +261,65 @@ MnpInitializeServiceData (
   //\r
   // Get MTU from Snp.\r
   //\r
-  SnpMode             = Snp->Mode;\r
-  MnpServiceData->Snp = Snp;\r
-  MnpServiceData->Mtu = SnpMode->MaxPacketSize;\r
+  SnpMode            = Snp->Mode;\r
+  MnpDeviceData->Snp = Snp;\r
 \r
   //\r
   // Initialize the lists.\r
   //\r
-  InitializeListHead (&MnpServiceData->GroupAddressList);\r
-  InitializeListHead (&MnpServiceData->ChildrenList);\r
+  InitializeListHead (&MnpDeviceData->ServiceList);\r
+  InitializeListHead (&MnpDeviceData->GroupAddressList);\r
 \r
   //\r
   // Get the buffer length used to allocate NET_BUF to hold data received\r
   // from SNP. Do this before fill the FreeNetBufQue.\r
   //\r
-  MnpServiceData->BufferLength = MnpServiceData->Mtu + SnpMode->MediaHeaderSize + NET_ETHER_FCS_SIZE;\r
+  //\r
+  MnpDeviceData->BufferLength = SnpMode->MediaHeaderSize + NET_VLAN_TAG_LEN + SnpMode->MaxPacketSize + NET_ETHER_FCS_SIZE;\r
 \r
   //\r
   // Make sure the protocol headers immediately following the media header\r
-  // 4-byte aligned\r
+  // 4-byte aligned, and also preserve additional space for VLAN tag\r
   //\r
-  MnpServiceData->PaddingSize = (4 - SnpMode->MediaHeaderSize) & 0x3;\r
+  MnpDeviceData->PaddingSize = ((4 - SnpMode->MediaHeaderSize) & 0x3) + NET_VLAN_TAG_LEN;\r
+\r
+  //\r
+  // Initialize MAC string which will be used as VLAN configuration variable name\r
+  //\r
+  Status = NetLibGetMacString (ControllerHandle, ImageHandle, &MnpDeviceData->MacString);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR;\r
+  }\r
 \r
   //\r
   // Initialize the FreeNetBufQue and pre-allocate some NET_BUFs.\r
   //\r
-  NetbufQueInit (&MnpServiceData->FreeNbufQue);\r
-  Status = MnpAddFreeNbuf (MnpServiceData, MNP_INIT_NET_BUFFER_NUM);\r
+  NetbufQueInit (&MnpDeviceData->FreeNbufQue);\r
+  Status = MnpAddFreeNbuf (MnpDeviceData, MNP_INIT_NET_BUFFER_NUM);\r
   if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeDeviceData: MnpAddFreeNbuf failed, %r.\n", Status));\r
 \r
-    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: MnpAddFreeNbuf failed, %r.\n", Status));\r
     goto ERROR;\r
   }\r
+\r
   //\r
   // Get one NET_BUF from the FreeNbufQue for rx cache.\r
   //\r
-  MnpServiceData->RxNbufCache = MnpAllocNbuf (MnpServiceData);\r
+  MnpDeviceData->RxNbufCache = MnpAllocNbuf (MnpDeviceData);\r
   NetbufAllocSpace (\r
-    MnpServiceData->RxNbufCache,\r
-    MnpServiceData->BufferLength,\r
+    MnpDeviceData->RxNbufCache,\r
+    MnpDeviceData->BufferLength,\r
     NET_BUF_TAIL\r
     );\r
 \r
   //\r
   // Allocate buffer pool for tx.\r
   //\r
-  MnpServiceData->TxBuf = AllocatePool (MnpServiceData->Mtu + SnpMode->MediaHeaderSize);\r
-  if (MnpServiceData->TxBuf == NULL) {\r
+  MnpDeviceData->TxBuf = AllocatePool (MnpDeviceData->BufferLength);\r
+  if (MnpDeviceData->TxBuf == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeDeviceData: AllocatePool failed.\n"));\r
 \r
-    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: AllocatePool failed.\n"));\r
     Status = EFI_OUT_OF_RESOURCES;\r
-\r
     goto ERROR;\r
   }\r
 \r
@@ -319,12 +330,12 @@ MnpInitializeServiceData (
                   EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
                   TPL_CALLBACK,\r
                   MnpSystemPoll,\r
-                  MnpServiceData,\r
-                  &MnpServiceData->PollTimer\r
+                  MnpDeviceData,\r
+                  &MnpDeviceData->PollTimer\r
                   );\r
   if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeDeviceData: CreateEvent for poll timer failed.\n"));\r
 \r
-    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: CreateEvent for poll timer failed.\n"));\r
     goto ERROR;\r
   }\r
 \r
@@ -335,12 +346,12 @@ MnpInitializeServiceData (
                   EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
                   TPL_CALLBACK,\r
                   MnpCheckPacketTimeout,\r
-                  MnpServiceData,\r
-                  &MnpServiceData->TimeoutCheckTimer\r
+                  MnpDeviceData,\r
+                  &MnpDeviceData->TimeoutCheckTimer\r
                   );\r
   if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeDeviceData: CreateEvent for packet timeout check failed.\n"));\r
 \r
-    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: CreateEvent for packet timeout check failed.\n"));\r
     goto ERROR;\r
   }\r
 \r
@@ -352,43 +363,50 @@ MnpInitializeServiceData (
                   TPL_CALLBACK,\r
                   NULL,\r
                   NULL,\r
-                  &MnpServiceData->TxTimeoutEvent\r
+                  &MnpDeviceData->TxTimeoutEvent\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-\r
-    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: CreateEvent for tx timeout event failed.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeDeviceData: CreateEvent for tx timeout event failed.\n"));\r
   }\r
 \r
 ERROR:\r
-\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // Free the dynamic allocated resources if necessary.\r
     //\r
-    if (MnpServiceData->TimeoutCheckTimer != NULL) {\r
-\r
-      gBS->CloseEvent (MnpServiceData->TimeoutCheckTimer);\r
+    if (MnpDeviceData->MacString != NULL) {\r
+      FreePool (MnpDeviceData->MacString);\r
     }\r
 \r
-    if (MnpServiceData->PollTimer != NULL) {\r
-\r
-      gBS->CloseEvent (MnpServiceData->PollTimer);\r
+    if (MnpDeviceData->TimeoutCheckTimer != NULL) {\r
+      gBS->CloseEvent (MnpDeviceData->TimeoutCheckTimer);\r
     }\r
 \r
-    if (MnpServiceData->TxBuf != NULL) {\r
-\r
-      FreePool (MnpServiceData->TxBuf);\r
+    if (MnpDeviceData->PollTimer != NULL) {\r
+      gBS->CloseEvent (MnpDeviceData->PollTimer);\r
     }\r
 \r
-    if (MnpServiceData->RxNbufCache != NULL) {\r
-\r
-      MnpFreeNbuf (MnpServiceData, MnpServiceData->RxNbufCache);\r
+    if (MnpDeviceData->TxBuf != NULL) {\r
+      FreePool (MnpDeviceData->TxBuf);\r
     }\r
 \r
-    if (MnpServiceData->FreeNbufQue.BufNum != 0) {\r
+    if (MnpDeviceData->RxNbufCache != NULL) {\r
+      MnpFreeNbuf (MnpDeviceData, MnpDeviceData->RxNbufCache);\r
+    }\r
 \r
-      NetbufQueFlush (&MnpServiceData->FreeNbufQue);\r
+    if (MnpDeviceData->FreeNbufQue.BufNum != 0) {\r
+      NetbufQueFlush (&MnpDeviceData->FreeNbufQue);\r
     }\r
+\r
+    //\r
+    // Close the Simple Network Protocol.\r
+    //\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiSimpleNetworkProtocolGuid,\r
+          ImageHandle,\r
+          ControllerHandle\r
+          );\r
   }\r
 \r
   return Status;\r
@@ -396,80 +414,339 @@ ERROR:
 \r
 \r
 /**\r
-  Flush the mnp service context data.\r
+  Destroy the MNP device context data.\r
 \r
-  @param[in, out]  MnpServiceData    Pointer to the mnp service context data.\r
-  @param[in]       ImageHandle       The driver image handle.\r
+  @param[in, out]  MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in]       ImageHandle        The driver image handle.\r
 \r
 **/\r
 VOID\r
-MnpFlushServiceData (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN EFI_HANDLE            ImageHandle\r
+MnpDestroyDeviceData (\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
+  IN     EFI_HANDLE        ImageHandle\r
   )\r
 {\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
+\r
+  //\r
+  // Free Vlan Config variable name string\r
+  //\r
+  if (MnpDeviceData->MacString != NULL) {\r
+    FreePool (MnpDeviceData->MacString);\r
+  }\r
 \r
   //\r
   // The GroupAddressList must be empty.\r
   //\r
-  ASSERT (IsListEmpty (&MnpServiceData->GroupAddressList));\r
+  ASSERT (IsListEmpty (&MnpDeviceData->GroupAddressList));\r
 \r
   //\r
   // Close the event.\r
   //\r
-  gBS->CloseEvent (&MnpServiceData->TxTimeoutEvent);\r
-  gBS->CloseEvent (&MnpServiceData->TimeoutCheckTimer);\r
-  gBS->CloseEvent (&MnpServiceData->PollTimer);\r
+  gBS->CloseEvent (&MnpDeviceData->TxTimeoutEvent);\r
+  gBS->CloseEvent (&MnpDeviceData->TimeoutCheckTimer);\r
+  gBS->CloseEvent (&MnpDeviceData->PollTimer);\r
 \r
   //\r
   // Free the tx buffer.\r
   //\r
-  FreePool (MnpServiceData->TxBuf);\r
+  FreePool (MnpDeviceData->TxBuf);\r
 \r
   //\r
   // Free the RxNbufCache.\r
   //\r
-  MnpFreeNbuf (MnpServiceData, MnpServiceData->RxNbufCache);\r
+  MnpFreeNbuf (MnpDeviceData, MnpDeviceData->RxNbufCache);\r
 \r
   //\r
   // Flush the FreeNbufQue.\r
   //\r
-  MnpServiceData->NbufCnt -= MnpServiceData->FreeNbufQue.BufNum;\r
-  NetbufQueFlush (&MnpServiceData->FreeNbufQue);\r
+  MnpDeviceData->NbufCnt -= MnpDeviceData->FreeNbufQue.BufNum;\r
+  NetbufQueFlush (&MnpDeviceData->FreeNbufQue);\r
 \r
-  DEBUG_CODE (\r
+  //\r
+  // Close the Simple Network Protocol.\r
+  //\r
+  gBS->CloseProtocol (\r
+         MnpDeviceData->ControllerHandle,\r
+         &gEfiSimpleNetworkProtocolGuid,\r
+         ImageHandle,\r
+         MnpDeviceData->ControllerHandle\r
+         );\r
+}\r
+\r
+\r
+/**\r
+  Create mnp service context data.\r
+\r
+  @param[in]       MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in]       VlanId             The VLAN ID.\r
+  @param[in]       Priority           The VLAN priority. If VlanId is 0,\r
+                                      Priority is ignored.\r
+\r
+  @return A pointer to MNP_SERVICE_DATA or NULL if failed to create MNP service context.\r
 \r
-  if (MnpServiceData->NbufCnt != 0) {\r
+**/\r
+MNP_SERVICE_DATA *\r
+MnpCreateServiceData (\r
+  IN MNP_DEVICE_DATA     *MnpDeviceData,\r
+  IN UINT16              VlanId,\r
+  IN UINT8                Priority OPTIONAL\r
+  )\r
+{\r
+  EFI_HANDLE                MnpServiceHandle;\r
+  MNP_SERVICE_DATA          *MnpServiceData;\r
+  EFI_STATUS                Status;\r
+  EFI_SIMPLE_NETWORK_MODE   *SnpMode;\r
+  EFI_VLAN_CONFIG_PROTOCOL  *VlanConfig;\r
 \r
-    DEBUG ((EFI_D_WARN, "MnpFlushServiceData: Memory leak, MnpServiceData->NbufCnt != 0.\n"));\r
+  //\r
+  // Initialize the Mnp Service Data.\r
+  //\r
+  MnpServiceData = AllocateZeroPool (sizeof (MNP_SERVICE_DATA));\r
+  if (MnpServiceData == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "MnpCreateServiceData: Faild to allocate memory for the new Mnp Service Data.\n"));\r
+\r
+    return NULL;\r
   }\r
-  );\r
 \r
   //\r
-  // Close the Simple Network Protocol.\r
+  // Add to MNP service list\r
   //\r
-  gBS->CloseProtocol (\r
-        MnpServiceData->ControllerHandle,\r
-        &gEfiSimpleNetworkProtocolGuid,\r
-        ImageHandle,\r
-        MnpServiceData->ControllerHandle\r
-        );\r
+  InsertTailList (&MnpDeviceData->ServiceList, &MnpServiceData->Link);\r
+\r
+  MnpServiceData->Signature     = MNP_SERVICE_DATA_SIGNATURE;\r
+  MnpServiceData->MnpDeviceData = MnpDeviceData;\r
+\r
+  //\r
+  // Copy the ServiceBinding structure.\r
+  //\r
+  CopyMem (&MnpServiceData->ServiceBinding, &mMnpServiceBindingProtocol, sizeof (EFI_SERVICE_BINDING_PROTOCOL));\r
+\r
+  //\r
+  // Initialize the lists.\r
+  //\r
+  InitializeListHead (&MnpServiceData->ChildrenList);\r
+\r
+  SnpMode = MnpDeviceData->Snp->Mode;\r
+  if (VlanId != 0) {\r
+    //\r
+    // Create VLAN child handle\r
+    //\r
+    MnpServiceHandle = MnpCreateVlanChild (\r
+                         MnpDeviceData->ImageHandle,\r
+                         MnpDeviceData->ControllerHandle,\r
+                         VlanId,\r
+                         &MnpServiceData->DevicePath\r
+                         );\r
+    if (MnpServiceHandle == NULL) {\r
+      DEBUG ((EFI_D_ERROR, "MnpCreateServiceData: Faild to create child handle.\n"));\r
+\r
+      return NULL;\r
+    }\r
+\r
+    //\r
+    // Open VLAN Config Protocol by child\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    MnpDeviceData->ControllerHandle,\r
+                    &gEfiVlanConfigProtocolGuid,\r
+                    (VOID **) &VlanConfig,\r
+                    MnpDeviceData->ImageHandle,\r
+                    MnpServiceHandle,\r
+                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto Exit;\r
+    }\r
+\r
+    //\r
+    // Reduce MTU for VLAN device\r
+    //\r
+    MnpServiceData->Mtu = SnpMode->MaxPacketSize - NET_VLAN_TAG_LEN;\r
+  } else {\r
+    //\r
+    // VlanId set to 0 means rx/tx untagged frame\r
+    //\r
+    MnpServiceHandle    = MnpDeviceData->ControllerHandle;\r
+    MnpServiceData->Mtu = SnpMode->MaxPacketSize;\r
+  }\r
+\r
+  MnpServiceData->ServiceHandle = MnpServiceHandle;\r
+  MnpServiceData->VlanId        = VlanId;\r
+  MnpServiceData->Priority      = Priority;\r
+\r
+  //\r
+  // Install the MNP Service Binding Protocol\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &MnpServiceHandle,\r
+                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+                  &MnpServiceData->ServiceBinding,\r
+                  NULL\r
+                  );\r
+\r
+Exit:\r
+  if (EFI_ERROR (Status)) {\r
+    MnpDestroyServiceData (MnpServiceData);\r
+    MnpServiceData = NULL;\r
+  }\r
+\r
+  return MnpServiceData;\r
+}\r
+\r
+/**\r
+  Destroy the MNP service context data.\r
+\r
+  @param[in, out]  MnpServiceData    Pointer to the mnp service context data.\r
+\r
+  @retval EFI_SUCCESS           The mnp service context is destroyed.\r
+  @retval Others                Errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpDestroyServiceData (\r
+  IN OUT MNP_SERVICE_DATA    *MnpServiceData\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Uninstall the MNP Service Binding Protocol\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  MnpServiceData->ServiceHandle,\r
+                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+                  &MnpServiceData->ServiceBinding,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (MnpServiceData->VlanId != 0) {\r
+    //\r
+    // Close VlanConfig Protocol opened by VLAN child handle\r
+    //\r
+    Status = gBS->CloseProtocol (\r
+                    MnpServiceData->MnpDeviceData->ControllerHandle,\r
+                    &gEfiVlanConfigProtocolGuid,\r
+                    MnpServiceData->MnpDeviceData->ImageHandle,\r
+                    MnpServiceData->ServiceHandle\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Uninstall Device Path Protocol to destroy the VLAN child handle\r
+    //\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                    MnpServiceData->ServiceHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    MnpServiceData->DevicePath,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    if (MnpServiceData->DevicePath != NULL) {\r
+      FreePool (MnpServiceData->DevicePath);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Remove from MnpDeviceData service list\r
+  //\r
+  RemoveEntryList (&MnpServiceData->Link);\r
+\r
+  FreePool (MnpServiceData);\r
+\r
+  return Status;\r
 }\r
 \r
+/**\r
+  Destroy all child of the MNP service data.\r
+\r
+  @param[in, out]  MnpServiceData    Pointer to the mnp service context data.\r
+\r
+  @retval EFI_SUCCESS           All child are destroyed.\r
+  @retval Others                Failed to destroy all child.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpDestroyServiceChild (\r
+  IN OUT MNP_SERVICE_DATA    *MnpServiceData\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  MNP_INSTANCE_DATA             *Instance;\r
+  EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;\r
+\r
+  ServiceBinding = &MnpServiceData->ServiceBinding;\r
+  while (!IsListEmpty (&MnpServiceData->ChildrenList)) {\r
+    //\r
+    // Don't use NetListRemoveHead here, the remove opreration will be done\r
+    // in ServiceBindingDestroyChild.\r
+    //\r
+    Instance = NET_LIST_HEAD (\r
+                 &MnpServiceData->ChildrenList,\r
+                 MNP_INSTANCE_DATA,\r
+                 InstEntry\r
+                 );\r
+\r
+    Status = ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Find the MNP Service Data for given VLAN ID.\r
+\r
+  @param[in]  MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in]  VlanId             The VLAN ID.\r
+\r
+  @return A pointer to MNP_SERVICE_DATA or NULL if not found.\r
+\r
+**/\r
+MNP_SERVICE_DATA *\r
+MnpFindServiceData (\r
+  IN MNP_DEVICE_DATA     *MnpDeviceData,\r
+  IN UINT16              VlanId\r
+  )\r
+{\r
+  LIST_ENTRY        *Entry;\r
+  MNP_SERVICE_DATA  *MnpServiceData;\r
+\r
+  NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {\r
+    //\r
+    // Check VLAN ID of each Mnp Service Data\r
+    //\r
+    MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+    if (MnpServiceData->VlanId == VlanId) {\r
+      return MnpServiceData;\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
 \r
 /**\r
   Initialize the mnp instance context data.\r
 \r
   @param[in]       MnpServiceData   Pointer to the mnp service context data.\r
-  @param[in, out]  Instance         Pointer to the mnp instance context data \r
+  @param[in, out]  Instance         Pointer to the mnp instance context data\r
                                     to initialize.\r
 \r
 **/\r
 VOID\r
 MnpInitializeInstanceData (\r
-  IN MNP_SERVICE_DATA       *MnpServiceData,\r
-  IN OUT MNP_INSTANCE_DATA  *Instance\r
+  IN     MNP_SERVICE_DATA    *MnpServiceData,\r
+  IN OUT MNP_INSTANCE_DATA   *Instance\r
   )\r
 {\r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
@@ -525,9 +802,9 @@ MnpInitializeInstanceData (
 **/\r
 EFI_STATUS\r
 MnpTokenExist (\r
-  IN NET_MAP       *Map,\r
-  IN NET_MAP_ITEM  *Item,\r
-  IN VOID          *Arg\r
+  IN NET_MAP         *Map,\r
+  IN NET_MAP_ITEM    *Item,\r
+  IN VOID            *Arg\r
   )\r
 {\r
   EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token;\r
@@ -552,10 +829,10 @@ MnpTokenExist (
 \r
   @param[in, out]  Map               Pointer to the NET_MAP.\r
   @param[in, out]  Item              Pointer to the NET_MAP_ITEM.\r
-  @param[in]       Arg               Pointer to the Arg, it's a pointer to the \r
+  @param[in]       Arg               Pointer to the Arg, it's a pointer to the\r
                                      token to cancel.\r
 \r
-  @retval EFI_SUCCESS       The Arg is NULL, and the token in Item is cancelled, \r
+  @retval EFI_SUCCESS       The Arg is NULL, and the token in Item is cancelled,\r
                             or the Arg isn't NULL, and the token in Item is\r
                             different from the Arg.\r
   @retval EFI_ABORTED       The Arg isn't NULL, the token in Item mathces the\r
@@ -564,9 +841,9 @@ MnpTokenExist (
 **/\r
 EFI_STATUS\r
 MnpCancelTokens (\r
-  IN OUT NET_MAP       *Map,\r
-  IN OUT NET_MAP_ITEM  *Item,\r
-  IN VOID              *Arg\r
+  IN OUT NET_MAP         *Map,\r
+  IN OUT NET_MAP_ITEM    *Item,\r
+  IN     VOID            *Arg\r
   )\r
 {\r
   EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *TokenToCancel;\r
@@ -578,7 +855,7 @@ MnpCancelTokens (
     return EFI_SUCCESS;\r
   }\r
 \r
-  TokenToCancel         = (EFI_MANAGED_NETWORK_COMPLETION_TOKEN *) Item->Key;\r
+  TokenToCancel = (EFI_MANAGED_NETWORK_COMPLETION_TOKEN *) Item->Key;\r
 \r
   //\r
   // Remove the item from the map.\r
@@ -613,7 +890,7 @@ MnpCancelTokens (
 **/\r
 EFI_STATUS\r
 MnpStartSnp (\r
-  IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL     *Snp\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -629,7 +906,7 @@ MnpStartSnp (
     //\r
     // Initialize the simple network.\r
     //\r
-    Status  = Snp->Initialize (Snp, 0, 0);\r
+    Status = Snp->Initialize (Snp, 0, 0);\r
   }\r
 \r
   return Status;\r
@@ -647,7 +924,7 @@ MnpStartSnp (
 **/\r
 EFI_STATUS\r
 MnpStopSnp (\r
-  IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL     *Snp\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -657,8 +934,7 @@ MnpStopSnp (
   //\r
   // Shut down the simple network.\r
   //\r
-  Status = Snp->Shutdown (Snp);\r
-\r
+  Status  = Snp->Shutdown (Snp);\r
   if (!EFI_ERROR (Status)) {\r
     //\r
     // Stop the simple network.\r
@@ -686,32 +962,34 @@ MnpStopSnp (
 **/\r
 EFI_STATUS\r
 MnpStart (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN BOOLEAN               IsConfigUpdate,\r
-  IN BOOLEAN               EnableSystemPoll\r
+  IN OUT MNP_SERVICE_DATA    *MnpServiceData,\r
+  IN     BOOLEAN             IsConfigUpdate,\r
+  IN     BOOLEAN             EnableSystemPoll\r
   )\r
 {\r
   EFI_STATUS      Status;\r
   EFI_TIMER_DELAY TimerOpType;\r
+  MNP_DEVICE_DATA *MnpDeviceData;\r
 \r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
 \r
-  Status = EFI_SUCCESS;\r
+  Status        = EFI_SUCCESS;\r
+  MnpDeviceData = MnpServiceData->MnpDeviceData;\r
 \r
   if (!IsConfigUpdate) {\r
     //\r
     // If it's not a configuration update, increase the configured children number.\r
     //\r
-    MnpServiceData->ConfiguredChildrenNumber++;\r
+    MnpDeviceData->ConfiguredChildrenNumber++;\r
 \r
-    if (MnpServiceData->ConfiguredChildrenNumber == 1) {\r
+    if (MnpDeviceData->ConfiguredChildrenNumber == 1) {\r
       //\r
       // It's the first configured child, start the simple network.\r
       //\r
-      Status = MnpStartSnp (MnpServiceData->Snp);\r
+      Status = MnpStartSnp (MnpDeviceData->Snp);\r
       if (EFI_ERROR (Status)) {\r
-\r
         DEBUG ((EFI_D_ERROR, "MnpStart: MnpStartSnp failed, %r.\n", Status));\r
+\r
         goto ErrorExit;\r
       }\r
 \r
@@ -719,46 +997,45 @@ MnpStart (
       // Start the timeout timer.\r
       //\r
       Status = gBS->SetTimer (\r
-                      MnpServiceData->TimeoutCheckTimer,\r
+                      MnpDeviceData->TimeoutCheckTimer,\r
                       TimerPeriodic,\r
                       MNP_TIMEOUT_CHECK_INTERVAL\r
                       );\r
       if (EFI_ERROR (Status)) {\r
-\r
         DEBUG (\r
           (EFI_D_ERROR,\r
           "MnpStart, gBS->SetTimer for TimeoutCheckTimer %r.\n",\r
           Status)\r
           );\r
+\r
         goto ErrorExit;\r
       }\r
     }\r
   }\r
 \r
-  if (MnpServiceData->EnableSystemPoll ^ EnableSystemPoll) {\r
+  if (MnpDeviceData->EnableSystemPoll ^ EnableSystemPoll) {\r
     //\r
     // The EnableSystemPoll differs with the current state, disable or enable\r
     // the system poll.\r
     //\r
     TimerOpType = EnableSystemPoll ? TimerPeriodic : TimerCancel;\r
 \r
-    Status      = gBS->SetTimer (MnpServiceData->PollTimer, TimerOpType, MNP_SYS_POLL_INTERVAL);\r
+    Status      = gBS->SetTimer (MnpDeviceData->PollTimer, TimerOpType, MNP_SYS_POLL_INTERVAL);\r
     if (EFI_ERROR (Status)) {\r
-\r
       DEBUG ((EFI_D_ERROR, "MnpStart: gBS->SetTimer for PollTimer failed, %r.\n", Status));\r
+\r
       goto ErrorExit;\r
     }\r
 \r
-    MnpServiceData->EnableSystemPoll = EnableSystemPoll;\r
+    MnpDeviceData->EnableSystemPoll = EnableSystemPoll;\r
   }\r
 \r
   //\r
   // Change the receive filters if need.\r
   //\r
-  Status = MnpConfigReceiveFilters (MnpServiceData);\r
+  Status = MnpConfigReceiveFilters (MnpDeviceData);\r
 \r
 ErrorExit:\r
-\r
   return Status;\r
 }\r
 \r
@@ -774,25 +1051,27 @@ ErrorExit:
 **/\r
 EFI_STATUS\r
 MnpStop (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_SERVICE_DATA    *MnpServiceData\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS      Status;\r
+  MNP_DEVICE_DATA *MnpDeviceData;\r
 \r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
-  ASSERT (MnpServiceData->ConfiguredChildrenNumber > 0);\r
+  MnpDeviceData = MnpServiceData->MnpDeviceData;\r
+  ASSERT (MnpDeviceData->ConfiguredChildrenNumber > 0);\r
 \r
   //\r
   // Configure the receive filters.\r
   //\r
-  MnpConfigReceiveFilters (MnpServiceData);\r
+  MnpConfigReceiveFilters (MnpDeviceData);\r
 \r
   //\r
   // Decrease the children number.\r
   //\r
-  MnpServiceData->ConfiguredChildrenNumber--;\r
+  MnpDeviceData->ConfiguredChildrenNumber--;\r
 \r
-  if (MnpServiceData->ConfiguredChildrenNumber > 0) {\r
+  if (MnpDeviceData->ConfiguredChildrenNumber > 0) {\r
     //\r
     // If there are other configured chilren, return and keep the timers and\r
     // simple network unchanged.\r
@@ -803,25 +1082,23 @@ MnpStop (
   //\r
   // No configured children now.\r
   //\r
-\r
-  if (MnpServiceData->EnableSystemPoll) {\r
+  if (MnpDeviceData->EnableSystemPoll) {\r
     //\r
     //  The system poll in on, cancel the poll timer.\r
     //\r
-    Status  = gBS->SetTimer (MnpServiceData->PollTimer, TimerCancel, 0);\r
-    MnpServiceData->EnableSystemPoll = FALSE;\r
+    Status  = gBS->SetTimer (MnpDeviceData->PollTimer, TimerCancel, 0);\r
+    MnpDeviceData->EnableSystemPoll = FALSE;\r
   }\r
 \r
   //\r
   // Cancel the timeout timer.\r
   //\r
-  Status  = gBS->SetTimer (MnpServiceData->TimeoutCheckTimer, TimerCancel, 0);\r
+  Status = gBS->SetTimer (MnpDeviceData->TimeoutCheckTimer, TimerCancel, 0);\r
 \r
   //\r
   // Stop the simple network.\r
   //\r
-  Status  = MnpStopSnp (MnpServiceData->Snp);\r
-\r
+  Status = MnpStopSnp (MnpDeviceData->Snp);\r
   return Status;\r
 }\r
 \r
@@ -834,10 +1111,10 @@ MnpStop (
 **/\r
 VOID\r
 MnpFlushRcvdDataQueue (\r
-  IN OUT MNP_INSTANCE_DATA  *Instance\r
+  IN OUT MNP_INSTANCE_DATA   *Instance\r
   )\r
 {\r
-  EFI_TPL          OldTpl;\r
+  EFI_TPL         OldTpl;\r
   MNP_RXDATA_WRAP *RxDataWrap;\r
 \r
   NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
@@ -878,12 +1155,13 @@ MnpFlushRcvdDataQueue (
 **/\r
 EFI_STATUS\r
 MnpConfigureInstance (\r
-  IN OUT MNP_INSTANCE_DATA              *Instance,\r
-  IN EFI_MANAGED_NETWORK_CONFIG_DATA    *ConfigData OPTIONAL\r
+  IN OUT MNP_INSTANCE_DATA                 *Instance,\r
+  IN     EFI_MANAGED_NETWORK_CONFIG_DATA   *ConfigData OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                      Status;\r
   MNP_SERVICE_DATA                *MnpServiceData;\r
+  MNP_DEVICE_DATA                 *MnpDeviceData;\r
   EFI_MANAGED_NETWORK_CONFIG_DATA *OldConfigData;\r
   EFI_MANAGED_NETWORK_CONFIG_DATA *NewConfigData;\r
   BOOLEAN                         IsConfigUpdate;\r
@@ -900,7 +1178,8 @@ MnpConfigureInstance (
   Status          = EFI_SUCCESS;\r
 \r
   MnpServiceData  = Instance->MnpServiceData;\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  MnpDeviceData   = MnpServiceData->MnpDeviceData;\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
   IsConfigUpdate  = (BOOLEAN) ((Instance->Configured) && (ConfigData != NULL));\r
 \r
@@ -923,19 +1202,19 @@ MnpConfigureInstance (
   // Clear the receive counters according to the old ConfigData.\r
   //\r
   if (OldConfigData->EnableUnicastReceive) {\r
-    MnpServiceData->UnicastCount--;\r
+    MnpDeviceData->UnicastCount--;\r
   }\r
 \r
   if (OldConfigData->EnableMulticastReceive) {\r
-    MnpServiceData->MulticastCount--;\r
+    MnpDeviceData->MulticastCount--;\r
   }\r
 \r
   if (OldConfigData->EnableBroadcastReceive) {\r
-    MnpServiceData->BroadcastCount--;\r
+    MnpDeviceData->BroadcastCount--;\r
   }\r
 \r
   if (OldConfigData->EnablePromiscuousReceive) {\r
-    MnpServiceData->PromiscuousCount--;\r
+    MnpDeviceData->PromiscuousCount--;\r
   }\r
 \r
   //\r
@@ -943,35 +1222,32 @@ MnpConfigureInstance (
   // instance according to the new ConfigData.\r
   //\r
   if (NewConfigData->EnableUnicastReceive) {\r
-    MnpServiceData->UnicastCount++;\r
+    MnpDeviceData->UnicastCount++;\r
     Instance->ReceiveFilter |= MNP_RECEIVE_UNICAST;\r
   }\r
 \r
   if (NewConfigData->EnableMulticastReceive) {\r
-    MnpServiceData->MulticastCount++;\r
+    MnpDeviceData->MulticastCount++;\r
   }\r
 \r
   if (NewConfigData->EnableBroadcastReceive) {\r
-    MnpServiceData->BroadcastCount++;\r
+    MnpDeviceData->BroadcastCount++;\r
     Instance->ReceiveFilter |= MNP_RECEIVE_BROADCAST;\r
   }\r
 \r
   if (NewConfigData->EnablePromiscuousReceive) {\r
-    MnpServiceData->PromiscuousCount++;\r
+    MnpDeviceData->PromiscuousCount++;\r
   }\r
 \r
   if (OldConfigData->FlushQueuesOnReset) {\r
-\r
     MnpFlushRcvdDataQueue (Instance);\r
   }\r
 \r
   if (ConfigData == NULL) {\r
-\r
     Instance->ManagedNetwork.Cancel (&Instance->ManagedNetwork, NULL);\r
   }\r
 \r
   if (!NewConfigData->EnableMulticastReceive) {\r
-\r
     MnpGroupOp (Instance, FALSE, NULL, NULL);\r
   }\r
 \r
@@ -980,8 +1256,7 @@ MnpConfigureInstance (
   //\r
   CopyMem (OldConfigData, NewConfigData, sizeof (*OldConfigData));\r
 \r
-  Instance->Configured  = (BOOLEAN) (ConfigData != NULL);\r
-\r
+  Instance->Configured = (BOOLEAN) (ConfigData != NULL);\r
   if (Instance->Configured) {\r
     //\r
     // The instance is configured, start the Mnp.\r
@@ -1005,16 +1280,16 @@ MnpConfigureInstance (
   Configure the Snp receive filters according to the instances' receive filter\r
   settings.\r
 \r
-  @param[in]  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in]  MnpDeviceData         Pointer to the mnp device context data.\r
 \r
   @retval     EFI_SUCCESS           The receive filters is configured.\r
-  @retval     EFI_OUT_OF_RESOURCES  The receive filters can't be configured due \r
+  @retval     EFI_OUT_OF_RESOURCES  The receive filters can't be configured due\r
                                     to lack of memory resource.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpConfigReceiveFilters (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
+  IN MNP_DEVICE_DATA     *MnpDeviceData\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -1028,9 +1303,9 @@ MnpConfigReceiveFilters (
   UINT32                      Index;\r
   MNP_GROUP_ADDRESS           *GroupAddress;\r
 \r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
-  Snp = MnpServiceData->Snp;\r
+  Snp = MnpDeviceData->Snp;\r
 \r
   //\r
   // Initialize the enable filter and disable filter.\r
@@ -1038,14 +1313,14 @@ MnpConfigReceiveFilters (
   EnableFilterBits  = 0;\r
   DisableFilterBits = Snp->Mode->ReceiveFilterMask;\r
 \r
-  if (MnpServiceData->UnicastCount != 0) {\r
+  if (MnpDeviceData->UnicastCount != 0) {\r
     //\r
     // Enable unicast if any instance wants to receive unicast.\r
     //\r
     EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST;\r
   }\r
 \r
-  if (MnpServiceData->BroadcastCount != 0) {\r
+  if (MnpDeviceData->BroadcastCount != 0) {\r
     //\r
     // Enable broadcast if any instance wants to receive broadcast.\r
     //\r
@@ -1056,7 +1331,7 @@ MnpConfigReceiveFilters (
   MCastFilterCnt    = 0;\r
   ResetMCastFilters = TRUE;\r
 \r
-  if ((MnpServiceData->MulticastCount != 0) && (MnpServiceData->GroupAddressCount != 0)) {\r
+  if ((MnpDeviceData->MulticastCount != 0) && (MnpDeviceData->GroupAddressCount != 0)) {\r
     //\r
     // There are instances configured to receive multicast and already some group\r
     // addresses are joined.\r
@@ -1064,7 +1339,7 @@ MnpConfigReceiveFilters (
 \r
     ResetMCastFilters = FALSE;\r
 \r
-    if (MnpServiceData->GroupAddressCount <= Snp->Mode->MaxMCastFilterCount) {\r
+    if (MnpDeviceData->GroupAddressCount <= Snp->Mode->MaxMCastFilterCount) {\r
       //\r
       // The joind group address is less than simple network's maximum count.\r
       // Just configure the snp to do the multicast filtering.\r
@@ -1075,11 +1350,11 @@ MnpConfigReceiveFilters (
       //\r
       // Allocate pool for the mulicast addresses.\r
       //\r
-      MCastFilterCnt  = MnpServiceData->GroupAddressCount;\r
+      MCastFilterCnt  = MnpDeviceData->GroupAddressCount;\r
       MCastFilter     = AllocatePool (sizeof (EFI_MAC_ADDRESS) * MCastFilterCnt);\r
       if (MCastFilter == NULL) {\r
-\r
         DEBUG ((EFI_D_ERROR, "MnpConfigReceiveFilters: Failed to allocate memory resource for MCastFilter.\n"));\r
+\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
 \r
@@ -1087,9 +1362,9 @@ MnpConfigReceiveFilters (
       // Fill the multicast HW address buffer.\r
       //\r
       Index = 0;\r
-      NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) {\r
+      NET_LIST_FOR_EACH (Entry, &MnpDeviceData->GroupAddressList) {\r
 \r
-        GroupAddress            = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
+        GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
         CopyMem (MCastFilter + Index, &GroupAddress->Address, sizeof (*(MCastFilter + Index)));\r
         Index++;\r
 \r
@@ -1114,7 +1389,7 @@ MnpConfigReceiveFilters (
     }\r
   }\r
 \r
-  if (MnpServiceData->PromiscuousCount != 0) {\r
+  if (MnpDeviceData->PromiscuousCount != 0) {\r
     //\r
     // Enable promiscuous if any instance wants to receive promiscuous.\r
     //\r
@@ -1139,13 +1414,12 @@ MnpConfigReceiveFilters (
                   );\r
   DEBUG_CODE (\r
     if (EFI_ERROR (Status)) {\r
-\r
-    DEBUG (\r
-      (EFI_D_ERROR,\r
-      "MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n",\r
-      Status)\r
-      );\r
-  }\r
+      DEBUG (\r
+        (EFI_D_ERROR,\r
+        "MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n",\r
+        Status)\r
+        );\r
+    }\r
   );\r
 \r
   if (MCastFilter != NULL) {\r
@@ -1175,22 +1449,21 @@ MnpConfigReceiveFilters (
 **/\r
 EFI_STATUS\r
 MnpGroupOpAddCtrlBlk (\r
-  IN OUT MNP_INSTANCE_DATA        *Instance,\r
-  IN OUT MNP_GROUP_CONTROL_BLOCK  *CtrlBlk,\r
-  IN OUT MNP_GROUP_ADDRESS        *GroupAddress OPTIONAL,\r
-  IN EFI_MAC_ADDRESS              *MacAddress,\r
-  IN UINT32                       HwAddressSize\r
+  IN OUT MNP_INSTANCE_DATA         *Instance,\r
+  IN OUT MNP_GROUP_CONTROL_BLOCK   *CtrlBlk,\r
+  IN OUT MNP_GROUP_ADDRESS         *GroupAddress OPTIONAL,\r
+  IN     EFI_MAC_ADDRESS           *MacAddress,\r
+  IN     UINT32                    HwAddressSize\r
   )\r
 {\r
-  MNP_SERVICE_DATA  *MnpServiceData;\r
+  MNP_DEVICE_DATA  *MnpDeviceData;\r
 \r
   NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
 \r
-  MnpServiceData = Instance->MnpServiceData;\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
   if (GroupAddress == NULL) {\r
-\r
     ASSERT (MacAddress != NULL);\r
 \r
     //\r
@@ -1205,12 +1478,12 @@ MnpGroupOpAddCtrlBlk (
     }\r
 \r
     CopyMem (&GroupAddress->Address, MacAddress, sizeof (GroupAddress->Address));\r
-    GroupAddress->RefCnt  = 0;\r
+    GroupAddress->RefCnt = 0;\r
     InsertTailList (\r
-      &MnpServiceData->GroupAddressList,\r
+      &MnpDeviceData->GroupAddressList,\r
       &GroupAddress->AddrEntry\r
       );\r
-    MnpServiceData->GroupAddressCount++;\r
+    MnpDeviceData->GroupAddressCount++;\r
   }\r
 \r
   //\r
@@ -1240,17 +1513,17 @@ MnpGroupOpAddCtrlBlk (
 **/\r
 BOOLEAN\r
 MnpGroupOpDelCtrlBlk (\r
-  IN MNP_INSTANCE_DATA        *Instance,\r
-  IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk\r
+  IN MNP_INSTANCE_DATA           *Instance,\r
+  IN MNP_GROUP_CONTROL_BLOCK     *CtrlBlk\r
   )\r
 {\r
-  MNP_SERVICE_DATA  *MnpServiceData;\r
+  MNP_DEVICE_DATA   *MnpDeviceData;\r
   MNP_GROUP_ADDRESS *GroupAddress;\r
 \r
   NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
 \r
-  MnpServiceData = Instance->MnpServiceData;\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
   //\r
   // Remove and free the CtrlBlk.\r
@@ -1270,7 +1543,7 @@ MnpGroupOpDelCtrlBlk (
     //\r
     // Free this GroupAddress entry if no instance uses it.\r
     //\r
-    MnpServiceData->GroupAddressCount--;\r
+    MnpDeviceData->GroupAddressCount--;\r
     RemoveEntryList (&GroupAddress->AddrEntry);\r
     FreePool (GroupAddress);\r
 \r
@@ -1285,10 +1558,10 @@ MnpGroupOpDelCtrlBlk (
   Do the group operations for this instance.\r
 \r
   @param[in, out]  Instance        Pointer to the instance context data.\r
-  @param[in]       JoinFlag        Set to TRUE to join a group. Set to TRUE to \r
+  @param[in]       JoinFlag        Set to TRUE to join a group. Set to TRUE to\r
                                    leave a group/groups.\r
   @param[in]       MacAddress      Pointer to the group address to join or leave.\r
-  @param[in]       CtrlBlk         Pointer to the group control block if JoinFlag \r
+  @param[in]       CtrlBlk         Pointer to the group control block if JoinFlag\r
                                    is FALSE.\r
 \r
   @retval EFI_SUCCESS              The group operation finished.\r
@@ -1298,13 +1571,13 @@ MnpGroupOpDelCtrlBlk (
 **/\r
 EFI_STATUS\r
 MnpGroupOp (\r
-  IN OUT MNP_INSTANCE_DATA    *Instance,\r
-  IN BOOLEAN                  JoinFlag,\r
-  IN EFI_MAC_ADDRESS          *MacAddress OPTIONAL,\r
-  IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk OPTIONAL\r
+  IN OUT MNP_INSTANCE_DATA         *Instance,\r
+  IN     BOOLEAN                   JoinFlag,\r
+  IN     EFI_MAC_ADDRESS           *MacAddress OPTIONAL,\r
+  IN     MNP_GROUP_CONTROL_BLOCK   *CtrlBlk OPTIONAL\r
   )\r
 {\r
-  MNP_SERVICE_DATA        *MnpServiceData;\r
+  MNP_DEVICE_DATA         *MnpDeviceData;\r
   LIST_ENTRY              *Entry;\r
   LIST_ENTRY              *NextEntry;\r
   MNP_GROUP_ADDRESS       *GroupAddress;\r
@@ -1316,38 +1589,32 @@ MnpGroupOp (
 \r
   NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
 \r
-  MnpServiceData  = Instance->MnpServiceData;\r
-  SnpMode         = MnpServiceData->Snp->Mode;\r
+  MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;\r
+  SnpMode       = MnpDeviceData->Snp->Mode;\r
 \r
   if (JoinFlag) {\r
     //\r
     // A new gropu address is to be added.\r
     //\r
-\r
     GroupAddress  = NULL;\r
     AddressExist  = FALSE;\r
 \r
     //\r
     // Allocate memory for the control block.\r
     //\r
-    NewCtrlBlk    = AllocatePool (sizeof (MNP_GROUP_CONTROL_BLOCK));\r
+    NewCtrlBlk = AllocatePool (sizeof (MNP_GROUP_CONTROL_BLOCK));\r
     if (NewCtrlBlk == NULL) {\r
-\r
       DEBUG ((EFI_D_ERROR, "MnpGroupOp: Failed to allocate memory resource.\n"));\r
+\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) {\r
+    NET_LIST_FOR_EACH (Entry, &MnpDeviceData->GroupAddressList) {\r
       //\r
       // Check whether the MacAddress is already joined by other instances.\r
       //\r
       GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
-      if (0 == CompareMem (\r
-                MacAddress,\r
-                &GroupAddress->Address,\r
-                SnpMode->HwAddressSize\r
-                )) {\r
-\r
+      if (CompareMem (MacAddress, &GroupAddress->Address, SnpMode->HwAddressSize) == 0) {\r
         AddressExist = TRUE;\r
         break;\r
       }\r
@@ -1368,15 +1635,12 @@ MnpGroupOp (
               SnpMode->HwAddressSize\r
               );\r
     if (EFI_ERROR (Status)) {\r
-\r
       return Status;\r
     }\r
 \r
     NeedUpdate = TRUE;\r
   } else {\r
-\r
     if (MacAddress != NULL) {\r
-\r
       ASSERT (CtrlBlk != NULL);\r
 \r
       //\r
@@ -1411,7 +1675,7 @@ MnpGroupOp (
     //\r
     // Reconfigure the receive filters if necessary.\r
     //\r
-    Status = MnpConfigReceiveFilters (MnpServiceData);\r
+    Status = MnpConfigReceiveFilters (MnpDeviceData);\r
   }\r
 \r
   return Status;\r
index 7581b02e231c3a78e9bcaf16fa5c54279075937b..e3abd48cf393072fff81e4d2388f7e4fdd2bb68f 100644 (file)
@@ -1,11 +1,12 @@
 /** @file\r
   Implementation of driver entry point and driver binding protocol.\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation. <BR> \r
-All rights reserved. This program and the accompanying materials are licensed \r
-and made available under the terms and conditions of the BSD License which \r
-accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
+Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
 \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
@@ -14,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "MnpDriver.h"\r
 #include "MnpImpl.h"\r
-\r
+#include "MnpVlan.h"\r
 \r
 EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {\r
   MnpDriverBindingSupported,\r
@@ -35,7 +36,7 @@ EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {
 \r
   @param[in]  This                 Protocol instance pointer.\r
   @param[in]  ControllerHandle     Handle of device to test.\r
-  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific \r
+  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific\r
                                    child device to start.\r
 \r
   @retval EFI_SUCCESS              This driver supports this device.\r
@@ -46,29 +47,14 @@ EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {
 EFI_STATUS\r
 EFIAPI\r
 MnpDriverBindingSupported (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   ControllerHandle,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
   EFI_SIMPLE_NETWORK_PROTOCOL  *Snp;\r
 \r
-  //\r
-  // Test to see if MNP is already installed.\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  ControllerHandle,\r
-                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
-                  NULL,\r
-                  This->DriverBindingHandle,\r
-                  ControllerHandle,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    return EFI_ALREADY_STARTED;\r
-  }\r
-\r
   //\r
   // Test to open the Simple Network protocol BY_DRIVER.\r
   //\r
@@ -80,7 +66,6 @@ MnpDriverBindingSupported (
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
-\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -101,77 +86,159 @@ MnpDriverBindingSupported (
 \r
 /**\r
   Start this driver on ControllerHandle. This service is called by the\r
-  EFI boot service ConnectController(). In order to make drivers as small \r
+  EFI boot service ConnectController(). In order to make drivers as small\r
   as possible, there are a few calling restrictions for this service.\r
   ConnectController() must follow these calling restrictions. If any other\r
   agent wishes to call Start() it must also follow these calling restrictions.\r
 \r
   @param[in]       This                 Protocol instance pointer.\r
   @param[in]       ControllerHandle     Handle of device to bind driver to.\r
-  @param[in]       RemainingDevicePath  Optional parameter use to pick a specific \r
+  @param[in]       RemainingDevicePath  Optional parameter use to pick a specific\r
                                         child device to start.\r
 \r
   @retval EFI_SUCCESS           This driver is added to ControllerHandle.\r
   @retval EFI_ALREADY_STARTED   This driver is already running on ControllerHandle.\r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory for Mnp Service Data.\r
   @retval Others                This driver does not support this device.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 MnpDriverBindingStart (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   ControllerHandle,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
   )\r
 {\r
   EFI_STATUS        Status;\r
   MNP_SERVICE_DATA  *MnpServiceData;\r
-  BOOLEAN           MnpInitialized;\r
+  MNP_DEVICE_DATA   *MnpDeviceData;\r
+  LIST_ENTRY        *Entry;\r
+  VLAN_TCI          *VlanVariable;\r
+  UINTN             NumberOfVlan;\r
+  UINTN             Index;\r
 \r
-  MnpInitialized  = FALSE;\r
+  VlanVariable = NULL;\r
 \r
-  MnpServiceData  = AllocateZeroPool (sizeof (MNP_SERVICE_DATA));\r
-  if (MnpServiceData == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart(): Failed to allocate the Mnp Service Data.\n"));\r
+  //\r
+  // Initialize the Mnp Device Data\r
+  //\r
+  MnpDeviceData = AllocateZeroPool (sizeof (MNP_DEVICE_DATA));\r
+  if (MnpDeviceData == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart(): Failed to allocate the Mnp Device Data.\n"));\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  //\r
-  // Initialize the Mnp Service Data.\r
-  //\r
-  Status = MnpInitializeServiceData (MnpServiceData, This->DriverBindingHandle, ControllerHandle);\r
+  Status = MnpInitializeDeviceData (MnpDeviceData, This->DriverBindingHandle, ControllerHandle);\r
   if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart: MnpInitializeDeviceData failed, %r.\n", Status));\r
 \r
-    DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart: MnpInitializeServiceData failed, %r.\n",Status));\r
-    goto ErrorExit;\r
+    FreePool (MnpDeviceData);\r
+    return Status;\r
   }\r
 \r
-  MnpInitialized = TRUE;\r
+  //\r
+  // Check whether NIC driver has already produced VlanConfig protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  NULL,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // NIC hardware already implement VLAN,\r
+    // no need to provide software VLAN implementation in MNP driver\r
+    //\r
+    MnpDeviceData->NumberOfVlan = 0;\r
+    ZeroMem (&MnpDeviceData->VlanConfig, sizeof (EFI_VLAN_CONFIG_PROTOCOL));\r
+    MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);\r
+    Status = (MnpServiceData != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;\r
+    goto Exit;\r
+  }\r
 \r
   //\r
-  // Install the MNP Service Binding Protocol.\r
+  // Install VLAN Config Protocol\r
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &ControllerHandle,\r
-                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
-                  &MnpServiceData->ServiceBinding,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  &MnpDeviceData->VlanConfig,\r
                   NULL\r
                   );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
 \r
-ErrorExit:\r
+  //\r
+  // Get current VLAN configuration from EFI Variable\r
+  //\r
+  NumberOfVlan = 0;\r
+  Status = MnpGetVlanVariable (MnpDeviceData, &NumberOfVlan, &VlanVariable);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // No VLAN is set, create a default MNP service data for untagged frame\r
+    //\r
+    MnpDeviceData->NumberOfVlan = 0;\r
+    MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);\r
+    Status = (MnpServiceData != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Create MNP service data for each VLAN\r
+  //\r
+  MnpDeviceData->NumberOfVlan = NumberOfVlan;\r
+  for (Index = 0; Index < NumberOfVlan; Index++) {\r
+    MnpServiceData = MnpCreateServiceData (\r
+                       MnpDeviceData,\r
+                       VlanVariable[Index].Bits.Vid,\r
+                       (UINT8) VlanVariable[Index].Bits.Priority\r
+                       );\r
+\r
+    if (MnpServiceData == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+\r
+      goto Exit;\r
+    }\r
+  }\r
+\r
+Exit:\r
+  if (VlanVariable != NULL) {\r
+    FreePool (VlanVariable);\r
+  }\r
 \r
   if (EFI_ERROR (Status)) {\r
+    //\r
+    // Destroy all MNP service data\r
+    //\r
+    while (!IsListEmpty (&MnpDeviceData->ServiceList)) {\r
+      Entry = GetFirstNode (&MnpDeviceData->ServiceList);\r
+      MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+      MnpDestroyServiceData (MnpServiceData);\r
+    }\r
 \r
-    if (MnpInitialized) {\r
-      //\r
-      // Flush the Mnp Service Data.\r
-      //\r
-      MnpFlushServiceData (MnpServiceData, This->DriverBindingHandle);\r
+    //\r
+    // Uninstall the VLAN Config Protocol if any\r
+    //\r
+    if (MnpDeviceData->VlanConfig.Set != NULL) {\r
+      gBS->UninstallMultipleProtocolInterfaces (\r
+             MnpDeviceData->ControllerHandle,\r
+             &gEfiVlanConfigProtocolGuid,\r
+             &MnpDeviceData->VlanConfig,\r
+             NULL\r
+             );\r
     }\r
 \r
-    FreePool (MnpServiceData);\r
+    //\r
+    // Destroy Mnp Device Data\r
+    //\r
+    MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);\r
+    FreePool (MnpDeviceData);\r
   }\r
 \r
   return Status;\r
@@ -179,16 +246,16 @@ ErrorExit:
 \r
 /**\r
   Stop this driver on ControllerHandle. This service is called by the\r
-  EFI boot service DisconnectController(). In order to make drivers as \r
-  small as possible, there are a few calling restrictions for this service. \r
-  DisconnectController() must follow these calling restrictions. If any other \r
+  EFI boot service DisconnectController(). In order to make drivers as\r
+  small as possible, there are a few calling restrictions for this service.\r
+  DisconnectController() must follow these calling restrictions. If any other\r
   agent wishes to call Stop() it must also follow these calling restrictions.\r
-  \r
+\r
   @param[in]  This               Protocol instance pointer.\r
   @param[in]  ControllerHandle   Handle of device to stop driver on.\r
-  @param[in]  NumberOfChildren   Number of Handles in ChildHandleBuffer. If \r
-                                 number of children is zero stop the entire \r
-                                                                bus driver.\r
+  @param[in]  NumberOfChildren   Number of Handles in ChildHandleBuffer. If\r
+                                 number of children is zero stop the entire\r
+                                 bus driver.\r
   @param[in]  ChildHandleBuffer  List of Child Handles to Stop.\r
 \r
   @retval EFI_SUCCESS            This driver is removed ControllerHandle.\r
@@ -198,19 +265,22 @@ ErrorExit:
 EFI_STATUS\r
 EFIAPI\r
 MnpDriverBindingStop (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   ControllerHandle,\r
-  IN UINTN                        NumberOfChildren,\r
-  IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN UINTN                           NumberOfChildren,\r
+  IN EFI_HANDLE                      *ChildHandleBuffer OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
   EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;\r
+  EFI_VLAN_CONFIG_PROTOCOL      *VlanConfig;\r
+  MNP_DEVICE_DATA               *MnpDeviceData;\r
   MNP_SERVICE_DATA              *MnpServiceData;\r
-  MNP_INSTANCE_DATA             *Instance;\r
+  BOOLEAN                       AllChildrenStopped;\r
+  LIST_ENTRY                    *Entry;\r
 \r
   //\r
-  // Retrieve the MNP service binding protocol from the ControllerHandle.\r
+  // Try to retrieve MNP service binding protocol from the ControllerHandle\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -221,51 +291,77 @@ MnpDriverBindingStop (
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
+    //\r
+    // Retrieve VLAN Config Protocol from the ControllerHandle\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    ControllerHandle,\r
+                    &gEfiVlanConfigProtocolGuid,\r
+                    (VOID **) &VlanConfig,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "MnpDriverBindingStop: try to stop unknown Controller.\n"));\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
 \r
-    DEBUG (\r
-      (EFI_D_ERROR,\r
-      "MnpDriverBindingStop: Locate MNP Service Binding Protocol failed, %r.\n",\r
-      Status)\r
-      );\r
-    return EFI_DEVICE_ERROR;\r
+    MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (VlanConfig);\r
+  } else {\r
+    MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);\r
+    MnpDeviceData = MnpServiceData->MnpDeviceData;\r
   }\r
 \r
-  MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);\r
-\r
   if (NumberOfChildren == 0) {\r
     //\r
-    // Uninstall the MNP Service Binding Protocol.\r
+    // Destroy all MNP service data\r
     //\r
-    gBS->UninstallMultipleProtocolInterfaces (\r
-           ControllerHandle,\r
-           &gEfiManagedNetworkServiceBindingProtocolGuid,\r
-           ServiceBinding,\r
-           NULL\r
-           );\r
+    while (!IsListEmpty (&MnpDeviceData->ServiceList)) {\r
+      Entry = GetFirstNode (&MnpDeviceData->ServiceList);\r
+      MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+      MnpDestroyServiceData (MnpServiceData);\r
+    }\r
 \r
     //\r
-    // Flush the Mnp service data.\r
+    // Uninstall the VLAN Config Protocol if any\r
     //\r
-    MnpFlushServiceData (MnpServiceData, This->DriverBindingHandle);\r
+    if (MnpDeviceData->VlanConfig.Set != NULL) {\r
+      gBS->UninstallMultipleProtocolInterfaces (\r
+             MnpDeviceData->ControllerHandle,\r
+             &gEfiVlanConfigProtocolGuid,\r
+             &MnpDeviceData->VlanConfig,\r
+             NULL\r
+             );\r
+    }\r
 \r
-    FreePool (MnpServiceData);\r
-  } else {\r
-    while (!IsListEmpty (&MnpServiceData->ChildrenList)) {\r
-      //\r
-      // Don't use NetListRemoveHead here, the remove opreration will be done\r
-      // in ServiceBindingDestroyChild.\r
-      //\r
-      Instance = NET_LIST_HEAD (\r
-                   &MnpServiceData->ChildrenList,\r
-                   MNP_INSTANCE_DATA,\r
-                   InstEntry\r
-                   );\r
-\r
-      ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);\r
+    //\r
+    // Destroy the Mnp device data\r
+    //\r
+    MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);\r
+    FreePool (MnpDeviceData);\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Stop all MNP child\r
+  //\r
+  AllChildrenStopped = TRUE;\r
+  NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {\r
+    MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+\r
+    Status = MnpDestroyServiceChild (MnpServiceData);\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
     }\r
   }\r
 \r
-  return Status;\r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
@@ -275,12 +371,12 @@ MnpDriverBindingStop (
   @param[in]       This              Protocol instance pointer.\r
   @param[in, out]  ChildHandle       Pointer to the handle of the child to create. If\r
                                      it is NULL, then a new handle is created. If\r
-                                                                        it is not NULL, then the I/O services are added \r
-                                                                        to the existing child handle.\r
+                                     it is not NULL, then the I/O services are added\r
+                                     to the existing child handle.\r
 \r
-  @retval EFI_SUCCES                 The protocol was added to ChildHandle. \r
-  @retval EFI_INVALID_PARAMETER      ChildHandle is NULL. \r
-  @retval EFI_OUT_OF_RESOURCES       There are not enough resources availabe to \r
+  @retval EFI_SUCCES                 The protocol was added to ChildHandle.\r
+  @retval EFI_INVALID_PARAMETER      ChildHandle is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES       There are not enough resources availabe to\r
                                      create the child.\r
   @retval Others                     The child handle was not created.\r
 \r
@@ -288,18 +384,17 @@ MnpDriverBindingStop (
 EFI_STATUS\r
 EFIAPI\r
 MnpServiceBindingCreateChild (\r
-  IN EFI_SERVICE_BINDING_PROTOCOL  *This,\r
-  IN OUT EFI_HANDLE                *ChildHandle\r
+  IN     EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN OUT EFI_HANDLE                      *ChildHandle\r
   )\r
 {\r
   EFI_STATUS         Status;\r
   MNP_SERVICE_DATA   *MnpServiceData;\r
   MNP_INSTANCE_DATA  *Instance;\r
-  VOID               *Snp;\r
+  VOID               *MnpSb;\r
   EFI_TPL            OldTpl;\r
 \r
   if ((This == NULL) || (ChildHandle == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -310,8 +405,8 @@ MnpServiceBindingCreateChild (
   //\r
   Instance = AllocateZeroPool (sizeof (MNP_INSTANCE_DATA));\r
   if (Instance == NULL) {\r
-\r
     DEBUG ((EFI_D_ERROR, "MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n"));\r
+\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -327,12 +422,12 @@ MnpServiceBindingCreateChild (
                   NULL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-\r
     DEBUG (\r
       (EFI_D_ERROR,\r
       "MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n",\r
       Status)\r
       );\r
+\r
     goto ErrorExit;\r
   }\r
 \r
@@ -342,9 +437,9 @@ MnpServiceBindingCreateChild (
   Instance->Handle = *ChildHandle;\r
 \r
   Status = gBS->OpenProtocol (\r
-                  MnpServiceData->ControllerHandle,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
-                  (VOID **) &Snp,\r
+                  MnpServiceData->ServiceHandle,\r
+                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+                  (VOID **) &MnpSb,\r
                   gMnpDriverBinding.DriverBindingHandle,\r
                   Instance->Handle,\r
                   EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
@@ -385,16 +480,16 @@ ErrorExit:
 \r
 /**\r
   Destroys a child handle with a set of I/O services.\r
-   \r
-  The DestroyChild() function does the opposite of CreateChild(). It removes a \r
-  protocol that was installed by CreateChild() from ChildHandle. If the removed \r
-  protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. \r
-   \r
-  @param[in]  This               Pointer to the EFI_SERVICE_BINDING_PROTOCOL \r
+\r
+  The DestroyChild() function does the opposite of CreateChild(). It removes a\r
+  protocol that was installed by CreateChild() from ChildHandle. If the removed\r
+  protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
+\r
+  @param[in]  This               Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
                                  instance.\r
   @param[in]  ChildHandle        Handle of the child to destroy.\r
 \r
-  @retval EFI_SUCCES             The protocol was removed from ChildHandle. \r
+  @retval EFI_SUCCES             The protocol was removed from ChildHandle.\r
   @retval EFI_UNSUPPORTED        ChildHandle does not support the protocol that\r
                                  is being removed.\r
   @retval EFI_INVALID_PARAMETER  ChildHandle is not a valid UEFI handle.\r
@@ -407,8 +502,8 @@ ErrorExit:
 EFI_STATUS\r
 EFIAPI\r
 MnpServiceBindingDestroyChild (\r
-  IN EFI_SERVICE_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                    ChildHandle\r
+  IN EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                      ChildHandle\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
@@ -418,7 +513,6 @@ MnpServiceBindingDestroyChild (
   EFI_TPL                       OldTpl;\r
 \r
   if ((This == NULL) || (ChildHandle == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -436,7 +530,6 @@ MnpServiceBindingDestroyChild (
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -449,7 +542,6 @@ MnpServiceBindingDestroyChild (
   // will only excecute once.\r
   //\r
   if (Instance->Destroyed) {\r
-\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -459,9 +551,9 @@ MnpServiceBindingDestroyChild (
   // Close the Simple Network protocol.\r
   //\r
   gBS->CloseProtocol (\r
-         MnpServiceData->ControllerHandle,\r
-         &gEfiSimpleNetworkProtocolGuid,\r
-         gMnpDriverBinding.DriverBindingHandle,\r
+         MnpServiceData->ServiceHandle,\r
+         &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+         MnpServiceData->MnpDeviceData->ImageHandle,\r
          ChildHandle\r
          );\r
 \r
@@ -475,7 +567,6 @@ MnpServiceBindingDestroyChild (
                   NULL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-\r
     DEBUG (\r
       (EFI_D_ERROR,\r
       "MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",\r
@@ -523,7 +614,7 @@ MnpServiceBindingDestroyChild (
   @param[in]  ImageHandle  The image handle of the driver.\r
   @param[in]  SystemTable  The system table.\r
 \r
-  @retval EFI_SUCCES       The driver binding and component name protocols are \r
+  @retval EFI_SUCCES       The driver binding and component name protocols are\r
                            successfully installed.\r
   @retval Others           Other errors as indicated.\r
 \r
@@ -531,8 +622,8 @@ MnpServiceBindingDestroyChild (
 EFI_STATUS\r
 EFIAPI\r
 MnpDriverEntryPoint (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  IN EFI_HANDLE          ImageHandle,\r
+  IN EFI_SYSTEM_TABLE    *SystemTable\r
   )\r
 {\r
   return EfiLibInstallDriverBindingComponentName2 (\r
index b0153040617b847e8ff64e5b1dbb6b4b1794d621..e9698d2aacd8c0ad70d083875da0589e2222b27f 100644 (file)
@@ -1,11 +1,12 @@
 /** @file\r
   Declaration of strctures and functions for MnpDxe driver.\r
-    \r
-Copyright (c) 2005 - 2007, Intel Corporation. <BR> \r
-All rights reserved. This program and the accompanying materials are licensed \r
-and made available under the terms and conditions of the BSD License which \r
-accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
+\r
+Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
 \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
@@ -14,11 +15,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #ifndef _MNP_DRIVER_H_\r
 #define _MNP_DRIVER_H_\r
+\r
 #include <Uefi.h>\r
 \r
 #include <Protocol/ManagedNetwork.h>\r
 #include <Protocol/SimpleNetwork.h>\r
 #include <Protocol/ServiceBinding.h>\r
+#include <Protocol/VlanConfig.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
@@ -28,23 +31,31 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiLib.h>\r
 #include <Library/NetLib.h>\r
 #include <Library/DpcLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
 \r
 #include "ComponentName.h"\r
 \r
-#define MNP_SERVICE_DATA_SIGNATURE  SIGNATURE_32 ('M', 'n', 'p', 'S')\r
+#define MNP_DEVICE_DATA_SIGNATURE  SIGNATURE_32 ('M', 'n', 'p', 'D')\r
 \r
 typedef struct {\r
   UINT32                        Signature;\r
 \r
   EFI_HANDLE                    ControllerHandle;\r
+  EFI_HANDLE                    ImageHandle;\r
 \r
-  EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;\r
+  EFI_VLAN_CONFIG_PROTOCOL      VlanConfig;\r
+  UINTN                         NumberOfVlan;\r
+  CHAR16                        *MacString;\r
   EFI_SIMPLE_NETWORK_PROTOCOL   *Snp;\r
 \r
-  UINT32                        Mtu;\r
-\r
-  LIST_ENTRY                    ChildrenList;\r
-  UINTN                         ChildrenNumber;\r
+  //\r
+  // List of MNP_SERVICE_DATA\r
+  //\r
+  LIST_ENTRY                    ServiceList;\r
+  //\r
+  // Number of configured MNP Service Binding child\r
+  //\r
   UINTN                         ConfiguredChildrenNumber;\r
 \r
   LIST_ENTRY                    GroupAddressList;\r
@@ -73,8 +84,38 @@ typedef struct {
   UINT32                        PaddingSize;\r
   NET_BUF                       *RxNbufCache;\r
   UINT8                         *TxBuf;\r
+} MNP_DEVICE_DATA;\r
+\r
+#define MNP_DEVICE_DATA_FROM_THIS(a) \\r
+  CR ( \\r
+  (a), \\r
+  MNP_DEVICE_DATA, \\r
+  VlanConfig, \\r
+  MNP_DEVICE_DATA_SIGNATURE \\r
+  )\r
+\r
+#define MNP_SERVICE_DATA_SIGNATURE  SIGNATURE_32 ('M', 'n', 'p', 'S')\r
+\r
+typedef struct {\r
+  UINT32                        Signature;\r
+\r
+  LIST_ENTRY                    Link;\r
+\r
+  MNP_DEVICE_DATA               *MnpDeviceData;\r
+  EFI_HANDLE                    ServiceHandle;\r
+  EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+\r
+  LIST_ENTRY                    ChildrenList;\r
+  UINTN                         ChildrenNumber;\r
+\r
+  UINT32                        Mtu;\r
+\r
+  UINT16                        VlanId;\r
+  UINT8                         Priority;\r
 } MNP_SERVICE_DATA;\r
 \r
+\r
 #define MNP_SERVICE_DATA_FROM_THIS(a) \\r
   CR ( \\r
   (a), \\r
@@ -83,6 +124,15 @@ typedef struct {
   MNP_SERVICE_DATA_SIGNATURE \\r
   )\r
 \r
+#define MNP_SERVICE_DATA_FROM_LINK(a) \\r
+  CR ( \\r
+  (a), \\r
+  MNP_SERVICE_DATA, \\r
+  Link, \\r
+  MNP_SERVICE_DATA_SIGNATURE \\r
+  )\r
+\r
+\r
 /**\r
   Test to see if this driver supports ControllerHandle. This service\r
   is called by the EFI boot service ConnectController(). In\r
@@ -93,7 +143,7 @@ typedef struct {
 \r
   @param[in]  This                 Protocol instance pointer.\r
   @param[in]  ControllerHandle     Handle of device to test.\r
-  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific \r
+  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific\r
                                    child device to start.\r
 \r
   @retval EFI_SUCCESS              This driver supports this device.\r
@@ -104,50 +154,50 @@ typedef struct {
 EFI_STATUS\r
 EFIAPI\r
 MnpDriverBindingSupported (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   ControllerHandle,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
   );\r
 \r
 /**\r
   Start this driver on ControllerHandle. This service is called by the\r
-  EFI boot service ConnectController(). In order to make drivers as small \r
+  EFI boot service ConnectController(). In order to make drivers as small\r
   as possible, there are a few calling restrictions for this service.\r
   ConnectController() must follow these calling restrictions. If any other\r
   agent wishes to call Start() it must also follow these calling restrictions.\r
 \r
   @param[in]       This                 Protocol instance pointer.\r
   @param[in]       ControllerHandle     Handle of device to bind driver to.\r
-  @param[in]       RemainingDevicePath  Optional parameter use to pick a specific \r
+  @param[in]       RemainingDevicePath  Optional parameter use to pick a specific\r
                                         child device to start.\r
 \r
   @retval EFI_SUCCESS           This driver is added to ControllerHandle.\r
   @retval EFI_ALREADY_STARTED   This driver is already running on ControllerHandle.\r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory for Mnp Service Data.\r
   @retval Others                This driver does not support this device.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 MnpDriverBindingStart (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   ControllerHandle,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
   );\r
 \r
 \r
 /**\r
   Stop this driver on ControllerHandle. This service is called by the\r
-  EFI boot service DisconnectController(). In order to make drivers as \r
-  small as possible, there are a few calling restrictions for this service. \r
-  DisconnectController() must follow these calling restrictions. If any other \r
+  EFI boot service DisconnectController(). In order to make drivers as\r
+  small as possible, there are a few calling restrictions for this service.\r
+  DisconnectController() must follow these calling restrictions. If any other\r
   agent wishes to call Stop() it must also follow these calling restrictions.\r
-  \r
+\r
   @param[in]  This               Protocol instance pointer.\r
   @param[in]  ControllerHandle   Handle of device to stop driver on.\r
-  @param[in]  NumberOfChildren   Number of Handles in ChildHandleBuffer. If \r
-                                 number of children is zero stop the entire \r
-                                                                bus driver.\r
+  @param[in]  NumberOfChildren   Number of Handles in ChildHandleBuffer. If\r
+                                 number of children is zero stop the entire\r
+                                 bus driver.\r
   @param[in]  ChildHandleBuffer  List of Child Handles to Stop.\r
 \r
   @retval EFI_SUCCESS            This driver is removed ControllerHandle.\r
@@ -157,10 +207,10 @@ MnpDriverBindingStart (
 EFI_STATUS\r
 EFIAPI\r
 MnpDriverBindingStop (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   ControllerHandle,\r
-  IN UINTN                        NumberOfChildren,\r
-  IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN UINTN                           NumberOfChildren,\r
+  IN EFI_HANDLE                      *ChildHandleBuffer OPTIONAL\r
   );\r
 \r
 /**\r
@@ -169,12 +219,12 @@ MnpDriverBindingStop (
   @param[in]       This              Protocol instance pointer.\r
   @param[in, out]  ChildHandle       Pointer to the handle of the child to create. If\r
                                      it is NULL, then a new handle is created. If\r
-                                                                        it is not NULL, then the I/O services are added \r
-                                                                        to the existing child handle.\r
+                                     it is not NULL, then the I/O services are added\r
+                                     to the existing child handle.\r
 \r
-  @retval EFI_SUCCES                 The protocol was added to ChildHandle. \r
-  @retval EFI_INVALID_PARAMETER      ChildHandle is NULL. \r
-  @retval EFI_OUT_OF_RESOURCES       There are not enough resources availabe to \r
+  @retval EFI_SUCCES                 The protocol was added to ChildHandle.\r
+  @retval EFI_INVALID_PARAMETER      ChildHandle is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES       There are not enough resources availabe to\r
                                      create the child.\r
   @retval Others                     The child handle was not created.\r
 \r
@@ -182,22 +232,22 @@ MnpDriverBindingStop (
 EFI_STATUS\r
 EFIAPI\r
 MnpServiceBindingCreateChild (\r
-  IN EFI_SERVICE_BINDING_PROTOCOL  *This,\r
-  IN OUT EFI_HANDLE                *ChildHandle\r
+  IN     EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN OUT EFI_HANDLE                      *ChildHandle\r
   );\r
 \r
 /**\r
   Destroys a child handle with a set of I/O services.\r
-   \r
-  The DestroyChild() function does the opposite of CreateChild(). It removes a \r
-  protocol that was installed by CreateChild() from ChildHandle. If the removed \r
-  protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. \r
-   \r
-  @param[in]  This               Pointer to the EFI_SERVICE_BINDING_PROTOCOL \r
+\r
+  The DestroyChild() function does the opposite of CreateChild(). It removes a\r
+  protocol that was installed by CreateChild() from ChildHandle. If the removed\r
+  protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
+\r
+  @param[in]  This               Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
                                  instance.\r
   @param[in]  ChildHandle        Handle of the child to destroy.\r
 \r
-  @retval EFI_SUCCES             The protocol was removed from ChildHandle. \r
+  @retval EFI_SUCCES             The protocol was removed from ChildHandle.\r
   @retval EFI_UNSUPPORTED        ChildHandle does not support the protocol that\r
                                  is being removed.\r
   @retval EFI_INVALID_PARAMETER  ChildHandle is not a valid UEFI handle.\r
@@ -210,8 +260,8 @@ MnpServiceBindingCreateChild (
 EFI_STATUS\r
 EFIAPI\r
 MnpServiceBindingDestroyChild (\r
-  IN EFI_SERVICE_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                    ChildHandle\r
+  IN EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                      ChildHandle\r
   );\r
 \r
 #endif\r
index a03592bfb88219a7e61018e9cd7226072708f354..6347d97dee108deed0e7fe1b0e72d14432ce2a46 100644 (file)
@@ -1,16 +1,17 @@
-/** @file\r
-  Component description file for Mnp module.\r
-\r
-Copyright (c) 2006, 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
-http://opensource.org/licenses/bsd-license.php\r
-\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
+## @file\r
+#  Component description file for Mnp module.\r
+#\r
+#  Copyright (c) 2006 - 2009, 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
+#  http://opensource.org/licenses/bsd-license.php\r
+#\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
+##\r
 \r
-**/\r
 [Defines]\r
   INF_VERSION                    = 0x00010005\r
   BASE_NAME                      = MnpDxe\r
@@ -24,7 +25,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #\r
 #  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
 #\r
-#  DRIVER_BINDING                =  gMnpDriverBinding                        \r
+#  DRIVER_BINDING                =  gMnpDriverBinding\r
 #  COMPONENT_NAME                =  gMnpComponentName\r
 #  COMPONENT_NAME2               =  gMnpComponentName2\r
 #\r
@@ -38,13 +39,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   MnpDriver.c\r
   MnpConfig.c\r
   MnpImpl.h\r
-\r
+  MnpVlan.h\r
+  MnpVlan.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   MdeModulePkg/MdeModulePkg.dec\r
 \r
-\r
 [LibraryClasses]\r
   BaseLib\r
   BaseMemoryLib\r
@@ -57,6 +58,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   DpcLib\r
 \r
 [Protocols]\r
-  gEfiManagedNetworkServiceBindingProtocolGuid  # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiSimpleNetworkProtocolGuid                 # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiManagedNetworkProtocolGuid                # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiManagedNetworkServiceBindingProtocolGuid  ## PRODUCES\r
+  gEfiSimpleNetworkProtocolGuid                 ## CONSUMES\r
+  gEfiManagedNetworkProtocolGuid                ## PRODUCES\r
+  gEfiVlanConfigProtocolGuid                    ## SOMETIMES_PRODUCES\r
index b9fa4ab34326011299f5c9632ec1f09d022ed2ec..d35086221e0956eb3adba35fa2201e2e353b41e9 100644 (file)
@@ -1,10 +1,11 @@
 /** @file\r
   Declaration of structures and functions of MnpDxe driver.\r
-    \r
-Copyright (c) 2005 - 2009, Intel Corporation. <BR>\r
+\r
+Copyright (c) 2005 - 2009, 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
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
 http://opensource.org/licenses/bsd-license.php\r
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
@@ -90,6 +91,57 @@ typedef struct {
   UINT64                            TimeoutTick;\r
 } MNP_RXDATA_WRAP;\r
 \r
+\r
+/**\r
+  Initialize the mnp device context data.\r
+\r
+  @param[in, out]  MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in]       ImageHandle        The driver image handle.\r
+  @param[in]       ControllerHandle   Handle of device to bind driver to.\r
+\r
+  @retval EFI_SUCCESS           The mnp service context is initialized.\r
+  @retval EFI_UNSUPPORTED       ControllerHandle does not support Simple Network Protocol.\r
+  @retval Others                Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpInitializeDeviceData (\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
+  IN     EFI_HANDLE        ImageHandle,\r
+  IN     EFI_HANDLE        ControllerHandle\r
+  );\r
+\r
+/**\r
+  Destroy the MNP device context data.\r
+\r
+  @param[in, out]  MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in]       ImageHandle        The driver image handle.\r
+\r
+**/\r
+VOID\r
+MnpDestroyDeviceData (\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
+  IN     EFI_HANDLE        ImageHandle\r
+  );\r
+\r
+/**\r
+  Create mnp service context data.\r
+\r
+  @param[in]       MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in]       VlanId             The VLAN ID.\r
+  @param[in]       Priority           The VLAN priority. If VlanId is 0,\r
+                                      Priority is ignored.\r
+\r
+  @return A pointer to MNP_SERVICE_DATA or NULL if failed to create MNP service context.\r
+\r
+**/\r
+MNP_SERVICE_DATA *\r
+MnpCreateServiceData (\r
+  IN MNP_DEVICE_DATA     *MnpDeviceData,\r
+  IN UINT16              VlanId,\r
+  IN UINT8                Priority OPTIONAL\r
+  );\r
+\r
 /**\r
   Initialize the mnp service context data.\r
 \r
@@ -104,36 +156,66 @@ typedef struct {
 **/\r
 EFI_STATUS\r
 MnpInitializeServiceData (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN EFI_HANDLE            ImageHandle,\r
-  IN EFI_HANDLE            ControllerHandle\r
+  IN OUT MNP_SERVICE_DATA    *MnpServiceData,\r
+  IN     EFI_HANDLE          ImageHandle,\r
+  IN     EFI_HANDLE          ControllerHandle\r
   );\r
 \r
 /**\r
-  Flush the mnp service context data.\r
+  Destroy the MNP service context data.\r
 \r
   @param[in, out]  MnpServiceData    Pointer to the mnp service context data.\r
-  @param[in]       ImageHandle       The driver image handle.\r
+\r
+  @retval EFI_SUCCESS           The mnp service context is destroyed.\r
+  @retval Others                Errors as indicated.\r
 \r
 **/\r
-VOID\r
-MnpFlushServiceData (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN EFI_HANDLE            ImageHandle\r
+EFI_STATUS\r
+MnpDestroyServiceData (\r
+  IN OUT MNP_SERVICE_DATA    *MnpServiceData\r
+  );\r
+\r
+/**\r
+  Destroy all child of the MNP service data.\r
+\r
+  @param[in, out]  MnpServiceData    Pointer to the mnp service context data.\r
+\r
+  @retval EFI_SUCCESS           All child are destroyed.\r
+  @retval Others                Failed to destroy all child.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpDestroyServiceChild (\r
+  IN OUT MNP_SERVICE_DATA    *MnpServiceData\r
+  );\r
+\r
+/**\r
+  Find the MNP Service Data for given VLAN ID.\r
+\r
+  @param[in]  MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in]  VlanId             The VLAN ID.\r
+\r
+  @return A pointer to MNP_SERVICE_DATA or NULL if not found.\r
+\r
+**/\r
+MNP_SERVICE_DATA *\r
+MnpFindServiceData (\r
+  IN MNP_DEVICE_DATA     *MnpDeviceData,\r
+  IN UINT16              VlanId\r
   );\r
 \r
 /**\r
   Initialize the mnp instance context data.\r
 \r
   @param[in]       MnpServiceData   Pointer to the mnp service context data.\r
-  @param[in, out]  Instance         Pointer to the mnp instance context data \r
+  @param[in, out]  Instance         Pointer to the mnp instance context data\r
                                     to initialize.\r
 \r
 **/\r
 VOID\r
 MnpInitializeInstanceData (\r
-  IN MNP_SERVICE_DATA       *MnpServiceData,\r
-  IN OUT MNP_INSTANCE_DATA  *Instance\r
+  IN     MNP_SERVICE_DATA    *MnpServiceData,\r
+  IN OUT MNP_INSTANCE_DATA   *Instance\r
   );\r
 \r
 /**\r
@@ -152,9 +234,9 @@ MnpInitializeInstanceData (
 **/\r
 EFI_STATUS\r
 MnpTokenExist (\r
-  IN NET_MAP       *Map,\r
-  IN NET_MAP_ITEM  *Item,\r
-  IN VOID          *Arg\r
+  IN NET_MAP         *Map,\r
+  IN NET_MAP_ITEM    *Item,\r
+  IN VOID            *Arg\r
   );\r
 \r
 /**\r
@@ -162,10 +244,10 @@ MnpTokenExist (
 \r
   @param[in, out]  Map               Pointer to the NET_MAP.\r
   @param[in, out]  Item              Pointer to the NET_MAP_ITEM.\r
-  @param[in]       Arg               Pointer to the Arg, it's a pointer to the \r
+  @param[in]       Arg               Pointer to the Arg, it's a pointer to the\r
                                      token to cancel.\r
 \r
-  @retval EFI_SUCCESS       The Arg is NULL, and the token in Item is cancelled, \r
+  @retval EFI_SUCCESS       The Arg is NULL, and the token in Item is cancelled,\r
                             or the Arg isn't NULL, and the token in Item is\r
                             different from the Arg.\r
   @retval EFI_ABORTED       The Arg isn't NULL, the token in Item mathces the\r
@@ -174,9 +256,9 @@ MnpTokenExist (
 **/\r
 EFI_STATUS\r
 MnpCancelTokens (\r
-  IN OUT NET_MAP       *Map,\r
-  IN OUT NET_MAP_ITEM  *Item,\r
-  IN VOID              *Arg\r
+  IN OUT NET_MAP         *Map,\r
+  IN OUT NET_MAP_ITEM    *Item,\r
+  IN     VOID            *Arg\r
   );\r
 \r
 /**\r
@@ -187,7 +269,7 @@ MnpCancelTokens (
 **/\r
 VOID\r
 MnpFlushRcvdDataQueue (\r
-  IN OUT MNP_INSTANCE_DATA  *Instance\r
+  IN OUT MNP_INSTANCE_DATA   *Instance\r
   );\r
 \r
 /**\r
@@ -205,18 +287,18 @@ MnpFlushRcvdDataQueue (
 **/\r
 EFI_STATUS\r
 MnpConfigureInstance (\r
-  IN OUT MNP_INSTANCE_DATA              *Instance,\r
-  IN EFI_MANAGED_NETWORK_CONFIG_DATA    *ConfigData OPTIONAL\r
+  IN OUT MNP_INSTANCE_DATA                 *Instance,\r
+  IN     EFI_MANAGED_NETWORK_CONFIG_DATA   *ConfigData OPTIONAL\r
   );\r
 \r
 /**\r
   Do the group operations for this instance.\r
 \r
   @param[in, out]  Instance        Pointer to the instance context data.\r
-  @param[in]       JoinFlag        Set to TRUE to join a group. Set to TRUE to \r
+  @param[in]       JoinFlag        Set to TRUE to join a group. Set to TRUE to\r
                                    leave a group/groups.\r
   @param[in]       MacAddress      Pointer to the group address to join or leave.\r
-  @param[in]       CtrlBlk         Pointer to the group control block if JoinFlag \r
+  @param[in]       CtrlBlk         Pointer to the group control block if JoinFlag\r
                                    is FALSE.\r
 \r
   @retval EFI_SUCCESS              The group operation finished.\r
@@ -226,10 +308,10 @@ MnpConfigureInstance (
 **/\r
 EFI_STATUS\r
 MnpGroupOp (\r
-  IN OUT MNP_INSTANCE_DATA    *Instance,\r
-  IN BOOLEAN                  JoinFlag,\r
-  IN EFI_MAC_ADDRESS          *MacAddress OPTIONAL,\r
-  IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk OPTIONAL\r
+  IN OUT MNP_INSTANCE_DATA         *Instance,\r
+  IN     BOOLEAN                   JoinFlag,\r
+  IN     EFI_MAC_ADDRESS           *MacAddress OPTIONAL,\r
+  IN     MNP_GROUP_CONTROL_BLOCK   *CtrlBlk OPTIONAL\r
   );\r
 \r
 /**\r
@@ -243,27 +325,27 @@ MnpGroupOp (
 **/\r
 BOOLEAN\r
 MnpIsValidTxToken (\r
-  IN MNP_INSTANCE_DATA                     *Instance,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN MNP_INSTANCE_DATA                       *Instance,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   );\r
 \r
 /**\r
   Build the packet to transmit from the TxData passed in.\r
 \r
   @param[in]   MnpServiceData      Pointer to the mnp service context data.\r
-  @param[in]   TxData              Pointer to the transmit data containing the information \r
+  @param[in]   TxData              Pointer to the transmit data containing the information\r
                                    to build the packet.\r
   @param[out]  PktBuf              Pointer to record the address of the packet.\r
-  @param[out]  PktLen              Pointer to a UINT32 variable used to record the packet's \r
+  @param[out]  PktLen              Pointer to a UINT32 variable used to record the packet's\r
                                    length.\r
 \r
 **/\r
 VOID\r
 MnpBuildTxPacket (\r
-  IN  MNP_SERVICE_DATA                   *MnpServiceData,\r
-  IN  EFI_MANAGED_NETWORK_TRANSMIT_DATA  *TxData,\r
-  OUT UINT8                              **PktBuf,\r
-  OUT UINT32                             *PktLen\r
+  IN     MNP_SERVICE_DATA                    *MnpServiceData,\r
+  IN     EFI_MANAGED_NETWORK_TRANSMIT_DATA   *TxData,\r
+     OUT UINT8                               **PktBuf,\r
+     OUT UINT32                              *PktLen\r
   );\r
 \r
 /**\r
@@ -281,10 +363,10 @@ MnpBuildTxPacket (
 **/\r
 EFI_STATUS\r
 MnpSyncSendPacket (\r
-  IN MNP_SERVICE_DATA                          *MnpServiceData,\r
-  IN UINT8                                     *Packet,\r
-  IN UINT32                                    Length,\r
-  IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN     MNP_SERVICE_DATA                        *MnpServiceData,\r
+  IN     UINT8                                   *Packet,\r
+  IN     UINT32                                  Length,\r
+  IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   );\r
 \r
 /**\r
@@ -300,7 +382,7 @@ MnpSyncSendPacket (
 **/\r
 EFI_STATUS\r
 MnpInstanceDeliverPacket (\r
-  IN OUT MNP_INSTANCE_DATA  *Instance\r
+  IN OUT MNP_INSTANCE_DATA   *Instance\r
   );\r
 \r
 /**\r
@@ -314,14 +396,14 @@ MnpInstanceDeliverPacket (
 VOID\r
 EFIAPI\r
 MnpRecycleRxData (\r
-  IN EFI_EVENT  Event,\r
-  IN VOID       *Context\r
+  IN EFI_EVENT     Event,\r
+  IN VOID          *Context\r
   );\r
 \r
 /**\r
   Try to receive a packet and deliver it.\r
 \r
-  @param[in, out]  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in, out]  MnpDeviceData        Pointer to the mnp device context data.\r
 \r
   @retval EFI_SUCCESS           add return value to function comment\r
   @retval EFI_NOT_STARTED       The simple network protocol is not started.\r
@@ -331,35 +413,35 @@ MnpRecycleRxData (
 **/\r
 EFI_STATUS\r
 MnpReceivePacket (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData\r
   );\r
 \r
 /**\r
-  Allocate a free NET_BUF from MnpServiceData->FreeNbufQue. If there is none\r
+  Allocate a free NET_BUF from MnpDeviceData->FreeNbufQue. If there is none\r
   in the queue, first try to allocate some and add them into the queue, then\r
   fetch the NET_BUF from the updated FreeNbufQue.\r
 \r
-  @param[in, out]  MnpServiceData        Pointer to the MNP_SERVICE_DATA.\r
+  @param[in, out]  MnpDeviceData        Pointer to the MNP_DEVICE_DATA.\r
 \r
-  @return     Pointer to the allocated free NET_BUF structure, if NULL the \r
+  @return     Pointer to the allocated free NET_BUF structure, if NULL the\r
               operation is failed.\r
 \r
 **/\r
 NET_BUF *\r
 MnpAllocNbuf (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData\r
   );\r
 \r
 /**\r
   Try to reclaim the Nbuf into the buffer pool.\r
 \r
-  @param[in, out]  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in, out]  MnpDeviceData         Pointer to the mnp device context data.\r
   @param[in, out]  Nbuf                  Pointer to the NET_BUF to free.\r
 \r
 **/\r
 VOID\r
 MnpFreeNbuf (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
   IN OUT NET_BUF           *Nbuf\r
   );\r
 \r
@@ -369,13 +451,13 @@ MnpFreeNbuf (
   @param[in]  Event             The event this notify function registered to.\r
   @param[in]  Context           Pointer to the context data registered to the\r
                                 event.\r
-   \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
 MnpCheckPacketTimeout (\r
-  IN EFI_EVENT  Event,\r
-  IN VOID       *Context\r
+  IN EFI_EVENT     Event,\r
+  IN VOID          *Context\r
   );\r
 \r
 /**\r
@@ -389,16 +471,16 @@ MnpCheckPacketTimeout (
 VOID\r
 EFIAPI\r
 MnpSystemPoll (\r
-  IN EFI_EVENT  Event,\r
-  IN OUT VOID   *Context\r
+  IN     EFI_EVENT   Event,\r
+  IN OUT VOID        *Context\r
   );\r
 \r
 /**\r
   Returns the operational parameters for the current MNP child driver. May also\r
-  support returning the underlying SNP driver mode data.   \r
-   \r
+  support returning the underlying SNP driver mode data.\r
+\r
   The GetModeData() function is used to read the current mode data (operational\r
-  parameters) from the MNP or the underlying SNP. \r
+  parameters) from the MNP or the underlying SNP.\r
 \r
   @param[in]  This          Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type\r
@@ -407,7 +489,7 @@ MnpSystemPoll (
   @param[out] SnpModeData   Pointer to storage for SNP operational parameters. This\r
                             feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE\r
                             is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.\r
\r
+\r
   @retval EFI_SUCCESS           The operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER This is NULL.\r
   @retval EFI_UNSUPPORTED       The requested feature is unsupported in this\r
@@ -421,15 +503,15 @@ MnpSystemPoll (
 EFI_STATUS\r
 EFIAPI\r
 MnpGetModeData (\r
-  IN  EFI_MANAGED_NETWORK_PROTOCOL     *This,\r
-  OUT EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData, OPTIONAL\r
-  OUT EFI_SIMPLE_NETWORK_MODE          *SnpModeData    OPTIONAL\r
+  IN     EFI_MANAGED_NETWORK_PROTOCOL      *This,\r
+     OUT EFI_MANAGED_NETWORK_CONFIG_DATA   *MnpConfigData OPTIONAL,\r
+     OUT EFI_SIMPLE_NETWORK_MODE           *SnpModeData OPTIONAL\r
   );\r
 \r
 /**\r
-  Sets or clears the operational parameters for the MNP child driver. \r
-   \r
-  The Configure() function is used to set, change, or reset the operational \r
+  Sets or clears the operational parameters for the MNP child driver.\r
+\r
+  The Configure() function is used to set, change, or reset the operational\r
   parameters for the MNP child driver instance. Until the operational parameters\r
   have been set, no network traffic can be sent or received by this MNP child\r
   driver instance. Once the operational parameters have been reset, no more\r
@@ -481,14 +563,14 @@ MnpGetModeData (
 EFI_STATUS\r
 EFIAPI\r
 MnpConfigure (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL     *This,\r
-  IN EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL        *This,\r
+  IN EFI_MANAGED_NETWORK_CONFIG_DATA     *MnpConfigData OPTIONAL\r
   );\r
 \r
 /**\r
-  Translates an IP multicast address to a hardware (MAC) multicast address. This \r
-  function may be unsupported in some MNP implementations. \r
-   \r
+  Translates an IP multicast address to a hardware (MAC) multicast address. This\r
+  function may be unsupported in some MNP implementations.\r
+\r
   The McastIpToMac() function translates an IP multicast address to a hardware\r
   (MAC) multicast address. This function may be implemented by calling the\r
   underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be\r
@@ -499,7 +581,7 @@ MnpConfigure (
                           Set to FALSE if IpAddress is an IPv4 multicast address.\r
   @param[in]  IpAddress   Pointer to the multicast IP address (in network byte\r
                           order) to convert.\r
-  @param[out] MacAddress  Pointer to the resulting multicast MAC address. \r
+  @param[out] MacAddress  Pointer to the resulting multicast MAC address.\r
 \r
   @retval EFI_SUCCESS           The operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:\r
@@ -518,21 +600,21 @@ MnpConfigure (
 EFI_STATUS\r
 EFIAPI\r
 MnpMcastIpToMac (\r
-  IN  EFI_MANAGED_NETWORK_PROTOCOL  *This,\r
-  IN  BOOLEAN                       Ipv6Flag,\r
-  IN  EFI_IP_ADDRESS                *IpAddress,\r
-  OUT EFI_MAC_ADDRESS               *MacAddress\r
+  IN     EFI_MANAGED_NETWORK_PROTOCOL    *This,\r
+  IN     BOOLEAN                         Ipv6Flag,\r
+  IN     EFI_IP_ADDRESS                  *IpAddress,\r
+     OUT EFI_MAC_ADDRESS                 *MacAddress\r
   );\r
 \r
 /**\r
-  Enables and disables receive filters for multicast address. This function may \r
+  Enables and disables receive filters for multicast address. This function may\r
   be unsupported in some MNP implementations.\r
-   \r
-  The Groups() function only adds and removes multicast MAC addresses from the \r
+\r
+  The Groups() function only adds and removes multicast MAC addresses from the\r
   filter list. The MNP driver does not transmit or process Internet Group\r
   Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r
   NULL, then all joined groups are left.\r
-   \r
+\r
   @param[in]  This        Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  JoinFlag    Set to TRUE to join this multicast group.\r
                           Set to FALSE to leave this multicast group.\r
@@ -563,15 +645,15 @@ MnpMcastIpToMac (
 EFI_STATUS\r
 EFIAPI\r
 MnpGroups (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL  *This,\r
-  IN BOOLEAN                       JoinFlag,\r
-  IN EFI_MAC_ADDRESS               *MacAddress OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL    *This,\r
+  IN BOOLEAN                         JoinFlag,\r
+  IN EFI_MAC_ADDRESS                 *MacAddress OPTIONAL\r
   );\r
 \r
 /**\r
   Places asynchronous outgoing data packets into the transmit queue.\r
-   \r
-  The Transmit() function places a completion token into the transmit packet \r
+\r
+  The Transmit() function places a completion token into the transmit packet\r
   queue. This function is always asynchronous.\r
   The caller must fill in the Token.Event and Token.TxData fields in the\r
   completion token, and these fields cannot be NULL. When the transmit operation\r
@@ -581,12 +663,12 @@ MnpGroups (
   defragmented before it can be transmitted by the network device. Systems in\r
   which performance is critical should review the requirements and features of\r
   the underlying communications device and drivers.\r
\r
\r
+\r
+\r
   @param[in]  This    Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token   Pointer to a token associated with the transmit data\r
                       descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN\r
-                                         is defined in "Related Definitions" below.\r
+                      is defined in "Related Definitions" below.\r
 \r
   @retval EFI_SUCCESS            The transmit completion token was cached.\r
   @retval EFI_NOT_STARTED        This MNP child driver instance has not been\r
@@ -615,7 +697,7 @@ MnpGroups (
   @retval EFI_ACCESS_DENIED      The transmit completion token is already in the\r
                                  transmit queue.\r
   @retval EFI_OUT_OF_RESOURCES   The transmit data could not be queued due to a\r
-                                 lack of system resources (usually memory). \r
+                                 lack of system resources (usually memory).\r
   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.\r
                                  The MNP child driver instance has been reset to\r
                                  startup defaults.\r
@@ -626,13 +708,13 @@ MnpGroups (
 EFI_STATUS\r
 EFIAPI\r
 MnpTransmit (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   );\r
 \r
 /**\r
-  Aborts an asynchronous transmit or receive request. \r
-   \r
+  Aborts an asynchronous transmit or receive request.\r
+\r
   The Cancel() function is used to abort a pending transmit or receive request.\r
   If the token is in the transmit or receive request queues, after calling this\r
   function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r
@@ -643,8 +725,8 @@ MnpTransmit (
   @param[in]  This     Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token    Pointer to a token that has been issued by\r
                        EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r
-                       EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all \r
-                                          pending tokens are aborted.\r
+                       EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all\r
+                       pending tokens are aborted.\r
 \r
   @retval EFI_SUCCESS            The asynchronous I/O request was aborted and\r
                                  Token.Event was signaled. When Token is NULL,\r
@@ -662,20 +744,20 @@ MnpTransmit (
 EFI_STATUS\r
 EFIAPI\r
 MnpCancel (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token OPTIONAL\r
   );\r
 \r
 /**\r
   Places an asynchronous receiving request into the receiving queue.\r
-   \r
-  The Receive() function places a completion token into the receive packet \r
+\r
+  The Receive() function places a completion token into the receive packet\r
   queue. This function is always asynchronous.\r
   The caller must fill in the Token.Event field in the completion token, and\r
   this field cannot be NULL. When the receive operation completes, the MNP\r
   updates the Token.Status and Token.RxData fields and the Token.Event is\r
   signaled.\r
-   \r
+\r
   @param[in]  This      Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token     Pointer to a token associated with the receive\r
                         data descriptor. Type\r
@@ -704,14 +786,14 @@ MnpCancel (
 EFI_STATUS\r
 EFIAPI\r
 MnpReceive (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   );\r
 \r
 /**\r
-  Polls for incoming data packets and processes outgoing data packets. \r
-   \r
-  The Poll() function can be used by network drivers and applications to \r
+  Polls for incoming data packets and processes outgoing data packets.\r
+\r
+  The Poll() function can be used by network drivers and applications to\r
   increase the rate that data packets are moved between the communications\r
   device and the transmit and receive queues.\r
   Normally, a periodic timer event internally calls the Poll() function. But, in\r
@@ -737,23 +819,23 @@ MnpReceive (
 EFI_STATUS\r
 EFIAPI\r
 MnpPoll (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL  *This\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL    *This\r
   );\r
 \r
 /**\r
   Configure the Snp receive filters according to the instances' receive filter\r
   settings.\r
 \r
-  @param[in]  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in]  MnpDeviceData         Pointer to the mnp device context data.\r
 \r
   @retval     EFI_SUCCESS           The receive filters is configured.\r
-  @retval     EFI_OUT_OF_RESOURCES  The receive filters can't be configured due \r
+  @retval     EFI_OUT_OF_RESOURCES  The receive filters can't be configured due\r
                                     to lack of memory resource.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpConfigReceiveFilters (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
+  IN MNP_DEVICE_DATA     *MnpDeviceData\r
   );\r
 \r
 #endif\r
index 8cc7db8ad27934e92f4646f8a2340d98d2eb7a6b..65268a8d74202419a069b8463038ce0bb537d205 100644 (file)
@@ -1,10 +1,11 @@
 /** @file\r
   Implementation of Managed Network Protocol I/O functions.\r
-    \r
-Copyright (c) 2005 - 2009, Intel Corporation. <BR>\r
+\r
+Copyright (c) 2005 - 2009, 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
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
 http://opensource.org/licenses/bsd-license.php\r
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
@@ -13,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "MnpImpl.h"\r
+#include "MnpVlan.h"\r
 \r
 /**\r
   Validates the Mnp transmit token.\r
@@ -25,8 +27,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 BOOLEAN\r
 MnpIsValidTxToken (\r
-  IN MNP_INSTANCE_DATA                     *Instance,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN MNP_INSTANCE_DATA                       *Instance,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   )\r
 {\r
   MNP_SERVICE_DATA                  *MnpServiceData;\r
@@ -38,7 +40,7 @@ MnpIsValidTxToken (
   MnpServiceData = Instance->MnpServiceData;\r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
 \r
-  TxData  = Token->Packet.TxData;\r
+  TxData = Token->Packet.TxData;\r
 \r
   if ((Token->Event == NULL) || (TxData == NULL) || (TxData->FragmentCount == 0)) {\r
     //\r
@@ -105,25 +107,27 @@ MnpIsValidTxToken (
   Build the packet to transmit from the TxData passed in.\r
 \r
   @param[in]   MnpServiceData      Pointer to the mnp service context data.\r
-  @param[in]   TxData              Pointer to the transmit data containing the information \r
+  @param[in]   TxData              Pointer to the transmit data containing the information\r
                                    to build the packet.\r
   @param[out]  PktBuf              Pointer to record the address of the packet.\r
-  @param[out]  PktLen              Pointer to a UINT32 variable used to record the packet's \r
+  @param[out]  PktLen              Pointer to a UINT32 variable used to record the packet's\r
                                    length.\r
 \r
 **/\r
 VOID\r
 MnpBuildTxPacket (\r
-  IN  MNP_SERVICE_DATA                   *MnpServiceData,\r
-  IN  EFI_MANAGED_NETWORK_TRANSMIT_DATA  *TxData,\r
-  OUT UINT8                              **PktBuf,\r
-  OUT UINT32                             *PktLen\r
+  IN     MNP_SERVICE_DATA                    *MnpServiceData,\r
+  IN     EFI_MANAGED_NETWORK_TRANSMIT_DATA   *TxData,\r
+     OUT UINT8                               **PktBuf,\r
+     OUT UINT32                              *PktLen\r
   )\r
 {\r
   EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
   UINT8                   *DstPos;\r
   UINT16                  Index;\r
+  MNP_DEVICE_DATA         *MnpDerviceData;\r
 \r
+  MnpDerviceData = MnpServiceData->MnpDeviceData;\r
   if ((TxData->DestinationAddress == NULL) && (TxData->FragmentCount == 1)) {\r
     //\r
     // Media header is in FragmentTable and there is only one fragment,\r
@@ -137,8 +141,8 @@ MnpBuildTxPacket (
     // one fragment, copy the data into the packet buffer. Reserve the\r
     // media header space if necessary.\r
     //\r
-    SnpMode = MnpServiceData->Snp->Mode;\r
-    DstPos  = MnpServiceData->TxBuf;\r
+    SnpMode = MnpDerviceData->Snp->Mode;\r
+    DstPos  = MnpDerviceData->TxBuf;\r
 \r
     *PktLen = 0;\r
     if (TxData->DestinationAddress != NULL) {\r
@@ -165,7 +169,7 @@ MnpBuildTxPacket (
     //\r
     // Set the buffer pointer and the buffer length.\r
     //\r
-    *PktBuf = MnpServiceData->TxBuf;\r
+    *PktBuf = MnpDerviceData->TxBuf;\r
     *PktLen += TxData->DataLength + TxData->HeaderLength;\r
   }\r
 }\r
@@ -186,10 +190,10 @@ MnpBuildTxPacket (
 **/\r
 EFI_STATUS\r
 MnpSyncSendPacket (\r
-  IN MNP_SERVICE_DATA                          *MnpServiceData,\r
-  IN UINT8                                     *Packet,\r
-  IN UINT32                                    Length,\r
-  IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN     MNP_SERVICE_DATA                        *MnpServiceData,\r
+  IN     UINT8                                   *Packet,\r
+  IN     UINT32                                  Length,\r
+  IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   )\r
 {\r
   EFI_STATUS                        Status;\r
@@ -197,25 +201,32 @@ MnpSyncSendPacket (
   EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData;\r
   UINT32                            HeaderSize;\r
   UINT8                             *TxBuf;\r
+  MNP_DEVICE_DATA                   *MnpDeviceData;\r
+  UINT16                            ProtocolType;\r
 \r
-  Snp         = MnpServiceData->Snp;\r
-  TxData      = Token->Packet.TxData;\r
+  MnpDeviceData = MnpServiceData->MnpDeviceData;\r
+  Snp           = MnpDeviceData->Snp;\r
+  TxData        = Token->Packet.TxData;\r
 \r
-  HeaderSize  = Snp->Mode->MediaHeaderSize - TxData->HeaderLength;\r
+  HeaderSize    = Snp->Mode->MediaHeaderSize - TxData->HeaderLength;\r
 \r
   //\r
   // Start the timeout event.\r
   //\r
   Status = gBS->SetTimer (\r
-                  MnpServiceData->TxTimeoutEvent,\r
+                  MnpDeviceData->TxTimeoutEvent,\r
                   TimerRelative,\r
                   MNP_TX_TIMEOUT_TIME\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-\r
     goto SIGNAL_TOKEN;\r
   }\r
 \r
+  //\r
+  // Insert VLAN tag\r
+  //\r
+  MnpInsertVlanTag (MnpServiceData, TxData, &ProtocolType, &Packet, &Length);\r
+\r
   for (;;) {\r
     //\r
     // Transmit the packet through SNP.\r
@@ -227,10 +238,9 @@ MnpSyncSendPacket (
                     Packet,\r
                     TxData->SourceAddress,\r
                     TxData->DestinationAddress,\r
-                    &TxData->ProtocolType\r
+                    &ProtocolType\r
                     );\r
     if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) {\r
-\r
       Status = EFI_DEVICE_ERROR;\r
       break;\r
     }\r
@@ -247,22 +257,20 @@ MnpSyncSendPacket (
       //\r
       Snp->GetStatus (Snp, NULL, (VOID **) &TxBuf);\r
 \r
-      if (!EFI_ERROR (gBS->CheckEvent (MnpServiceData->TxTimeoutEvent))) {\r
-\r
+      if (!EFI_ERROR (gBS->CheckEvent (MnpDeviceData->TxTimeoutEvent))) {\r
         Status = EFI_TIMEOUT;\r
         break;\r
       }\r
     } while (TxBuf == NULL);\r
 \r
     if ((Status == EFI_SUCCESS) || (Status == EFI_TIMEOUT)) {\r
-\r
       break;\r
     } else {\r
       //\r
       // Status is EFI_NOT_READY. Restart the timer event and call Snp->Transmit again.\r
       //\r
       gBS->SetTimer (\r
-            MnpServiceData->TxTimeoutEvent,\r
+            MnpDeviceData->TxTimeoutEvent,\r
             TimerRelative,\r
             MNP_TX_TIMEOUT_TIME\r
             );\r
@@ -272,7 +280,7 @@ MnpSyncSendPacket (
   //\r
   // Cancel the timer event.\r
   //\r
-  gBS->SetTimer (MnpServiceData->TxTimeoutEvent, TimerCancel, 0);\r
+  gBS->SetTimer (MnpDeviceData->TxTimeoutEvent, TimerCancel, 0);\r
 \r
 SIGNAL_TOKEN:\r
 \r
@@ -301,18 +309,18 @@ SIGNAL_TOKEN:
 **/\r
 EFI_STATUS\r
 MnpInstanceDeliverPacket (\r
-  IN OUT MNP_INSTANCE_DATA  *Instance\r
+  IN OUT MNP_INSTANCE_DATA   *Instance\r
   )\r
 {\r
-  MNP_SERVICE_DATA                      *MnpServiceData;\r
+  MNP_DEVICE_DATA                       *MnpDeviceData;\r
   MNP_RXDATA_WRAP                       *RxDataWrap;\r
   NET_BUF                               *DupNbuf;\r
   EFI_MANAGED_NETWORK_RECEIVE_DATA      *RxData;\r
   EFI_SIMPLE_NETWORK_MODE               *SnpMode;\r
   EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *RxToken;\r
 \r
-  MnpServiceData = Instance->MnpServiceData;\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
   if (NetMapIsEmpty (&Instance->RxTokenMap) || IsListEmpty (&Instance->RcvdPacketQueue)) {\r
     //\r
@@ -329,7 +337,7 @@ MnpInstanceDeliverPacket (
     // There are other instances share this Nbuf, duplicate to get a\r
     // copy to allow the instance to do R/W operations.\r
     //\r
-    DupNbuf = MnpAllocNbuf (MnpServiceData);\r
+    DupNbuf = MnpAllocNbuf (MnpDeviceData);\r
     if (DupNbuf == NULL) {\r
       DEBUG ((EFI_D_WARN, "MnpDeliverPacket: Failed to allocate a free Nbuf.\n"));\r
 \r
@@ -340,7 +348,7 @@ MnpInstanceDeliverPacket (
     // Duplicate the net buffer.\r
     //\r
     NetbufDuplicate (RxDataWrap->Nbuf, DupNbuf, 0);\r
-    MnpFreeNbuf (MnpServiceData, RxDataWrap->Nbuf);\r
+    MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);\r
     RxDataWrap->Nbuf = DupNbuf;\r
   }\r
 \r
@@ -351,7 +359,7 @@ MnpInstanceDeliverPacket (
   Instance->RcvdPacketQueueSize--;\r
 \r
   RxData  = &RxDataWrap->RxData;\r
-  SnpMode = MnpServiceData->Snp->Mode;\r
+  SnpMode = MnpDeviceData->Snp->Mode;\r
 \r
   //\r
   // Set all the buffer pointers.\r
@@ -390,7 +398,7 @@ MnpInstanceDeliverPacket (
 **/\r
 VOID\r
 MnpDeliverPacket (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
+  IN MNP_SERVICE_DATA    *MnpServiceData\r
   )\r
 {\r
   LIST_ENTRY        *Entry;\r
@@ -421,12 +429,12 @@ MnpDeliverPacket (
 VOID\r
 EFIAPI\r
 MnpRecycleRxData (\r
-  IN EFI_EVENT  Event,\r
-  IN VOID       *Context\r
+  IN EFI_EVENT     Event,\r
+  IN VOID          *Context\r
   )\r
 {\r
-  MNP_RXDATA_WRAP   *RxDataWrap;\r
-  MNP_SERVICE_DATA  *MnpServiceData;\r
+  MNP_RXDATA_WRAP *RxDataWrap;\r
+  MNP_DEVICE_DATA *MnpDeviceData;\r
 \r
   ASSERT (Context != NULL);\r
 \r
@@ -435,13 +443,13 @@ MnpRecycleRxData (
 \r
   ASSERT (RxDataWrap->Nbuf != NULL);\r
 \r
-  MnpServiceData = RxDataWrap->Instance->MnpServiceData;\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  MnpDeviceData = RxDataWrap->Instance->MnpServiceData->MnpDeviceData;\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
   //\r
   // Free this Nbuf.\r
   //\r
-  MnpFreeNbuf (MnpServiceData, RxDataWrap->Nbuf);\r
+  MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);\r
   RxDataWrap->Nbuf = NULL;\r
 \r
   //\r
@@ -467,8 +475,8 @@ MnpRecycleRxData (
 **/\r
 VOID\r
 MnpQueueRcvdPacket (\r
-  IN OUT MNP_INSTANCE_DATA  *Instance,\r
-  IN OUT MNP_RXDATA_WRAP    *RxDataWrap\r
+  IN OUT MNP_INSTANCE_DATA   *Instance,\r
+  IN OUT MNP_RXDATA_WRAP     *RxDataWrap\r
   )\r
 {\r
   MNP_RXDATA_WRAP *OldRxDataWrap;\r
@@ -528,10 +536,10 @@ MnpQueueRcvdPacket (
 **/\r
 BOOLEAN\r
 MnpMatchPacket (\r
-  IN MNP_INSTANCE_DATA                 *Instance,\r
-  IN EFI_MANAGED_NETWORK_RECEIVE_DATA  *RxData,\r
-  IN MNP_GROUP_ADDRESS                 *GroupAddress OPTIONAL,\r
-  IN UINT8                             PktAttr\r
+  IN MNP_INSTANCE_DATA                   *Instance,\r
+  IN EFI_MANAGED_NETWORK_RECEIVE_DATA    *RxData,\r
+  IN MNP_GROUP_ADDRESS                   *GroupAddress OPTIONAL,\r
+  IN UINT8                               PktAttr\r
   )\r
 {\r
   EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData;\r
@@ -607,18 +615,20 @@ MnpMatchPacket (
 **/\r
 VOID\r
 MnpAnalysePacket (\r
-  IN  MNP_SERVICE_DATA                      *MnpServiceData,\r
-  IN  NET_BUF                               *Nbuf,\r
-  IN  OUT EFI_MANAGED_NETWORK_RECEIVE_DATA  *RxData,\r
-  OUT MNP_GROUP_ADDRESS                     **GroupAddress,\r
-  OUT UINT8                                 *PktAttr\r
+  IN     MNP_SERVICE_DATA                    *MnpServiceData,\r
+  IN     NET_BUF                             *Nbuf,\r
+  IN OUT EFI_MANAGED_NETWORK_RECEIVE_DATA    *RxData,\r
+     OUT MNP_GROUP_ADDRESS                   **GroupAddress,\r
+     OUT UINT8                               *PktAttr\r
   )\r
 {\r
   EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
+  MNP_DEVICE_DATA         *MnpDeviceData;\r
   UINT8                   *BufPtr;\r
   LIST_ENTRY              *Entry;\r
 \r
-  SnpMode = MnpServiceData->Snp->Mode;\r
+  MnpDeviceData = MnpServiceData->MnpDeviceData;\r
+  SnpMode       = MnpDeviceData->Snp->Mode;\r
 \r
   //\r
   // Get the packet buffer.\r
@@ -650,7 +660,7 @@ MnpAnalysePacket (
       //\r
       // It's multicast, try to match the multicast filters.\r
       //\r
-      NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) {\r
+      NET_LIST_FOR_EACH (Entry, &MnpDeviceData->GroupAddressList) {\r
 \r
         *GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
         if (NET_MAC_EQUAL (BufPtr, &((*GroupAddress)->Address), SnpMode->HwAddressSize)) {\r
@@ -667,7 +677,7 @@ MnpAnalysePacket (
         *GroupAddress           = NULL;\r
         RxData->PromiscuousFlag = TRUE;\r
 \r
-        if (MnpServiceData->PromiscuousCount == 0) {\r
+        if (MnpDeviceData->PromiscuousCount == 0) {\r
           //\r
           // Skip the below code, there is no receiver of this packet.\r
           //\r
@@ -703,8 +713,8 @@ MnpAnalysePacket (
 **/\r
 MNP_RXDATA_WRAP *\r
 MnpWrapRxData (\r
-  IN MNP_INSTANCE_DATA                 *Instance,\r
-  IN EFI_MANAGED_NETWORK_RECEIVE_DATA  *RxData\r
+  IN MNP_INSTANCE_DATA                   *Instance,\r
+  IN EFI_MANAGED_NETWORK_RECEIVE_DATA    *RxData\r
   )\r
 {\r
   EFI_STATUS      Status;\r
@@ -737,8 +747,8 @@ MnpWrapRxData (
                   &RxDataWrap->RxData.RecycleEvent\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-\r
     DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status));\r
+\r
     FreePool (RxDataWrap);\r
     return NULL;\r
   }\r
@@ -758,8 +768,8 @@ MnpWrapRxData (
 **/\r
 VOID\r
 MnpEnqueuePacket (\r
-  IN MNP_SERVICE_DATA   *MnpServiceData,\r
-  IN NET_BUF            *Nbuf\r
+  IN MNP_SERVICE_DATA    *MnpServiceData,\r
+  IN NET_BUF             *Nbuf\r
   )\r
 {\r
   LIST_ENTRY                        *Entry;\r
@@ -776,7 +786,7 @@ MnpEnqueuePacket (
   //\r
   MnpAnalysePacket (MnpServiceData, Nbuf, &RxData, &GroupAddress, &PktAttr);\r
 \r
-  if (RxData.PromiscuousFlag && (MnpServiceData->PromiscuousCount == 0)) {\r
+  if (RxData.PromiscuousFlag && (MnpServiceData->MnpDeviceData->PromiscuousCount == 0)) {\r
     //\r
     // No receivers, no more action need.\r
     //\r
@@ -799,7 +809,6 @@ MnpEnqueuePacket (
     // Check the packet against the instance receive filters.\r
     //\r
     if (MnpMatchPacket (Instance, &RxData, GroupAddress, PktAttr)) {\r
-\r
       //\r
       // Wrap the RxData.\r
       //\r
@@ -826,7 +835,7 @@ MnpEnqueuePacket (
 /**\r
   Try to receive a packet and deliver it.\r
 \r
-  @param[in, out]  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in, out]  MnpDeviceData        Pointer to the mnp device context data.\r
 \r
   @retval EFI_SUCCESS           add return value to function comment\r
   @retval EFI_NOT_STARTED       The simple network protocol is not started.\r
@@ -836,7 +845,7 @@ MnpEnqueuePacket (
 **/\r
 EFI_STATUS\r
 MnpReceivePacket (\r
-  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -846,10 +855,13 @@ MnpReceivePacket (
   UINTN                       BufLen;\r
   UINTN                       HeaderSize;\r
   UINT32                      Trimmed;\r
+  MNP_SERVICE_DATA            *MnpServiceData;\r
+  UINT16                      VlanId;\r
+  BOOLEAN                     IsVlanPacket;\r
 \r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
-  Snp = MnpServiceData->Snp;\r
+  Snp = MnpDeviceData->Snp;\r
   if (Snp->Mode->State != EfiSimpleNetworkInitialized) {\r
     //\r
     // The simple network protocol is not started.\r
@@ -857,20 +869,13 @@ MnpReceivePacket (
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  if (IsListEmpty (&MnpServiceData->ChildrenList)) {\r
-    //\r
-    // There is no child, no need to receive packets.\r
-    //\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  if (MnpServiceData->RxNbufCache == NULL) {\r
+  if (MnpDeviceData->RxNbufCache == NULL) {\r
     //\r
     // Try to get a new buffer as there may be buffers recycled.\r
     //\r
-    MnpServiceData->RxNbufCache = MnpAllocNbuf (MnpServiceData);\r
+    MnpDeviceData->RxNbufCache = MnpAllocNbuf (MnpDeviceData);\r
 \r
-    if (MnpServiceData->RxNbufCache == NULL) {\r
+    if (MnpDeviceData->RxNbufCache == NULL) {\r
       //\r
       // No availabe buffer in the buffer pool.\r
       //\r
@@ -878,13 +883,13 @@ MnpReceivePacket (
     }\r
 \r
     NetbufAllocSpace (\r
-      MnpServiceData->RxNbufCache,\r
-      MnpServiceData->BufferLength,\r
+      MnpDeviceData->RxNbufCache,\r
+      MnpDeviceData->BufferLength,\r
       NET_BUF_TAIL\r
       );\r
   }\r
 \r
-  Nbuf    = MnpServiceData->RxNbufCache;\r
+  Nbuf    = MnpDeviceData->RxNbufCache;\r
   BufLen  = Nbuf->TotalSize;\r
   BufPtr  = NetbufGetByte (Nbuf, 0, NULL);\r
   ASSERT (BufPtr != NULL);\r
@@ -894,7 +899,6 @@ MnpReceivePacket (
   //\r
   Status = Snp->Receive (Snp, &HeaderSize, &BufLen, BufPtr, NULL, NULL, NULL);\r
   if (EFI_ERROR (Status)) {\r
-\r
     DEBUG_CODE (\r
       if (Status != EFI_NOT_READY) {\r
         DEBUG ((EFI_D_WARN, "MnpReceivePacket: Snp->Receive() = %r.\n", Status));\r
@@ -908,7 +912,6 @@ MnpReceivePacket (
   // Sanity check.\r
   //\r
   if ((HeaderSize != Snp->Mode->MediaHeaderSize) || (BufLen < HeaderSize)) {\r
-\r
     DEBUG (\r
       (EFI_D_WARN,\r
       "MnpReceivePacket: Size error, HL:TL = %d:%d.\n",\r
@@ -927,6 +930,25 @@ MnpReceivePacket (
     ASSERT (Nbuf->TotalSize == BufLen);\r
   }\r
 \r
+  VlanId = 0;\r
+  IsVlanPacket = MnpRemoveVlanTag (MnpDeviceData, Nbuf, &VlanId);\r
+\r
+  MnpServiceData = MnpFindServiceData (MnpDeviceData, VlanId);\r
+  if (MnpServiceData == NULL) {\r
+    //\r
+    // VLAN is not set for this tagged frame, ignore this packet\r
+    //\r
+    if (Trimmed > 0) {\r
+      NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);\r
+    }\r
+\r
+    if (IsVlanPacket) {\r
+      NetbufAllocSpace (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);\r
+    }\r
+\r
+    goto EXIT;\r
+  }\r
+\r
   //\r
   // Enqueue the packet to the matched instances.\r
   //\r
@@ -937,16 +959,16 @@ MnpReceivePacket (
     // RefCnt > 2 indicates there is at least one receiver of this packet.\r
     // Free the current RxNbufCache and allocate a new one.\r
     //\r
-    MnpFreeNbuf (MnpServiceData, Nbuf);\r
+    MnpFreeNbuf (MnpDeviceData, Nbuf);\r
 \r
-    Nbuf                        = MnpAllocNbuf (MnpServiceData);\r
-    MnpServiceData->RxNbufCache = Nbuf;\r
+    Nbuf                       = MnpAllocNbuf (MnpDeviceData);\r
+    MnpDeviceData->RxNbufCache = Nbuf;\r
     if (Nbuf == NULL) {\r
       DEBUG ((EFI_D_ERROR, "MnpReceivePacket: Alloc packet for receiving cache failed.\n"));\r
       return EFI_DEVICE_ERROR;\r
     }\r
 \r
-    NetbufAllocSpace (Nbuf, MnpServiceData->BufferLength, NET_BUF_TAIL);\r
+    NetbufAllocSpace (Nbuf, MnpDeviceData->BufferLength, NET_BUF_TAIL);\r
   } else {\r
     //\r
     // No receiver for this packet.\r
@@ -954,6 +976,9 @@ MnpReceivePacket (
     if (Trimmed > 0) {\r
       NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);\r
     }\r
+    if (IsVlanPacket) {\r
+      NetbufAllocSpace (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);\r
+    }\r
 \r
     goto EXIT;\r
   }\r
@@ -964,7 +989,7 @@ MnpReceivePacket (
 \r
 EXIT:\r
 \r
-  ASSERT (Nbuf->TotalSize == MnpServiceData->BufferLength);\r
+  ASSERT (Nbuf->TotalSize == MnpDeviceData->BufferLength);\r
 \r
   return Status;\r
 }\r
@@ -976,66 +1001,70 @@ EXIT:
   @param[in]  Event             The event this notify function registered to.\r
   @param[in]  Context           Pointer to the context data registered to the\r
                                 event.\r
-   \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
 MnpCheckPacketTimeout (\r
-  IN EFI_EVENT  Event,\r
-  IN VOID       *Context\r
+  IN EFI_EVENT     Event,\r
+  IN VOID          *Context\r
   )\r
 {\r
+  MNP_DEVICE_DATA   *MnpDeviceData;\r
   MNP_SERVICE_DATA  *MnpServiceData;\r
   LIST_ENTRY        *Entry;\r
+  LIST_ENTRY        *ServiceEntry;\r
   LIST_ENTRY        *RxEntry;\r
   LIST_ENTRY        *NextEntry;\r
   MNP_INSTANCE_DATA *Instance;\r
   MNP_RXDATA_WRAP   *RxDataWrap;\r
   EFI_TPL           OldTpl;\r
 \r
-  MnpServiceData = (MNP_SERVICE_DATA *) Context;\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  MnpDeviceData = (MNP_DEVICE_DATA *) Context;\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
-  NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {\r
+  NET_LIST_FOR_EACH (ServiceEntry, &MnpDeviceData->ServiceList) {\r
+    MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (ServiceEntry);\r
 \r
-    Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);\r
-    NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
+    NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {\r
 \r
-    if (!Instance->Configured || (Instance->ConfigData.ReceivedQueueTimeoutValue == 0)) {\r
-      //\r
-      // This instance is not configured or there is no receive time out,\r
-      // just skip to the next instance.\r
-      //\r
-      continue;\r
-    }\r
+      Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);\r
+      NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
 \r
-    OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+      if (!Instance->Configured || (Instance->ConfigData.ReceivedQueueTimeoutValue == 0)) {\r
+        //\r
+        // This instance is not configured or there is no receive time out,\r
+        // just skip to the next instance.\r
+        //\r
+        continue;\r
+      }\r
 \r
-    NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {\r
+      OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-      RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);\r
+      NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {\r
 \r
-      //\r
-      // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
-      //\r
-      if (RxDataWrap->TimeoutTick >= (MNP_TIMEOUT_CHECK_INTERVAL / 10)) {\r
+        RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);\r
 \r
-        RxDataWrap->TimeoutTick -= (MNP_TIMEOUT_CHECK_INTERVAL / 10);\r
-      } else {\r
         //\r
-        // Drop the timeout packet.\r
+        // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
         //\r
-        DEBUG ((EFI_D_WARN, "MnpCheckPacketTimeout: Received packet timeout.\n"));\r
-        MnpRecycleRxData (NULL, RxDataWrap);\r
-        Instance->RcvdPacketQueueSize--;\r
+        if (RxDataWrap->TimeoutTick >= (MNP_TIMEOUT_CHECK_INTERVAL / 10)) {\r
+          RxDataWrap->TimeoutTick -= (MNP_TIMEOUT_CHECK_INTERVAL / 10);\r
+        } else {\r
+          //\r
+          // Drop the timeout packet.\r
+          //\r
+          DEBUG ((EFI_D_WARN, "MnpCheckPacketTimeout: Received packet timeout.\n"));\r
+          MnpRecycleRxData (NULL, RxDataWrap);\r
+          Instance->RcvdPacketQueueSize--;\r
+        }\r
       }\r
-    }\r
 \r
-    gBS->RestoreTPL (OldTpl);\r
+      gBS->RestoreTPL (OldTpl);\r
+    }\r
   }\r
 }\r
 \r
-\r
 /**\r
   Poll to receive the packets from Snp. This function is either called by upperlayer\r
   protocols/applications or the system poll timer notify mechanism.\r
@@ -1047,19 +1076,19 @@ MnpCheckPacketTimeout (
 VOID\r
 EFIAPI\r
 MnpSystemPoll (\r
-  IN EFI_EVENT  Event,\r
-  IN OUT VOID   *Context\r
+  IN     EFI_EVENT   Event,\r
+  IN OUT VOID        *Context\r
   )\r
 {\r
-  MNP_SERVICE_DATA  *MnpServiceData;\r
+  MNP_DEVICE_DATA  *MnpDeviceData;\r
 \r
-  MnpServiceData = (MNP_SERVICE_DATA *) Context;\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+  MnpDeviceData = (MNP_DEVICE_DATA *) Context;\r
+  NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
 \r
   //\r
   // Try to receive packets from Snp.\r
   //\r
-  MnpReceivePacket (MnpServiceData);\r
+  MnpReceivePacket (MnpDeviceData);\r
 \r
   //\r
   // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
index 86004cda84323ef21ad87e78d2c8613edbd18194..e34936f3b861c0736f423bef7d8c3897e64f6770 100644 (file)
@@ -1,10 +1,11 @@
 /** @file\r
   Implementation of Managed Network Protocol public services.\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation. <BR>\r
+Copyright (c) 2005 - 2009, 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
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
 http://opensource.org/licenses/bsd-license.php\r
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
@@ -16,10 +17,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 /**\r
   Returns the operational parameters for the current MNP child driver. May also\r
-  support returning the underlying SNP driver mode data.   \r
-   \r
+  support returning the underlying SNP driver mode data.\r
+\r
   The GetModeData() function is used to read the current mode data (operational\r
-  parameters) from the MNP or the underlying SNP. \r
+  parameters) from the MNP or the underlying SNP.\r
 \r
   @param[in]  This          Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type\r
@@ -28,7 +29,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @param[out] SnpModeData   Pointer to storage for SNP operational parameters. This\r
                             feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE\r
                             is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.\r
\r
+\r
   @retval EFI_SUCCESS           The operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER This is NULL.\r
   @retval EFI_UNSUPPORTED       The requested feature is unsupported in this\r
@@ -42,9 +43,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 EFI_STATUS\r
 EFIAPI\r
 MnpGetModeData (\r
-  IN  EFI_MANAGED_NETWORK_PROTOCOL     *This,\r
-  OUT EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData, OPTIONAL\r
-  OUT EFI_SIMPLE_NETWORK_MODE          *SnpModeData    OPTIONAL\r
+  IN     EFI_MANAGED_NETWORK_PROTOCOL      *This,\r
+     OUT EFI_MANAGED_NETWORK_CONFIG_DATA   *MnpConfigData OPTIONAL,\r
+     OUT EFI_SIMPLE_NETWORK_MODE           *SnpModeData OPTIONAL\r
   )\r
 {\r
   MNP_INSTANCE_DATA           *Instance;\r
@@ -53,7 +54,6 @@ MnpGetModeData (
   EFI_STATUS                  Status;\r
 \r
   if (This == NULL) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -72,7 +72,7 @@ MnpGetModeData (
     //\r
     // Copy the underlayer Snp mode data.\r
     //\r
-    Snp = Instance->MnpServiceData->Snp;\r
+    Snp = Instance->MnpServiceData->MnpDeviceData->Snp;\r
     CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));\r
   }\r
 \r
@@ -89,9 +89,9 @@ MnpGetModeData (
 \r
 \r
 /**\r
-  Sets or clears the operational parameters for the MNP child driver. \r
-   \r
-  The Configure() function is used to set, change, or reset the operational \r
+  Sets or clears the operational parameters for the MNP child driver.\r
+\r
+  The Configure() function is used to set, change, or reset the operational\r
   parameters for the MNP child driver instance. Until the operational parameters\r
   have been set, no network traffic can be sent or received by this MNP child\r
   driver instance. Once the operational parameters have been reset, no more\r
@@ -143,8 +143,8 @@ MnpGetModeData (
 EFI_STATUS\r
 EFIAPI\r
 MnpConfigure (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL     *This,\r
-  IN EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL        *This,\r
+  IN EFI_MANAGED_NETWORK_CONFIG_DATA     *MnpConfigData OPTIONAL\r
   )\r
 {\r
   MNP_INSTANCE_DATA  *Instance;\r
@@ -152,10 +152,10 @@ MnpConfigure (
   EFI_STATUS         Status;\r
 \r
   if ((This == NULL) ||\r
-    ((MnpConfigData != NULL) &&\r
-    (MnpConfigData->ProtocolTypeFilter > 0) &&\r
-    (MnpConfigData->ProtocolTypeFilter <= 1500))) {\r
-\r
+      ((MnpConfigData != NULL) &&\r
+       (MnpConfigData->ProtocolTypeFilter > 0) &&\r
+       (MnpConfigData->ProtocolTypeFilter <= 1500))\r
+     ) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -184,9 +184,9 @@ ON_EXIT:
 \r
 \r
 /**\r
-  Translates an IP multicast address to a hardware (MAC) multicast address. This \r
-  function may be unsupported in some MNP implementations. \r
-   \r
+  Translates an IP multicast address to a hardware (MAC) multicast address. This\r
+  function may be unsupported in some MNP implementations.\r
+\r
   The McastIpToMac() function translates an IP multicast address to a hardware\r
   (MAC) multicast address. This function may be implemented by calling the\r
   underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be\r
@@ -197,7 +197,7 @@ ON_EXIT:
                           Set to FALSE if IpAddress is an IPv4 multicast address.\r
   @param[in]  IpAddress   Pointer to the multicast IP address (in network byte\r
                           order) to convert.\r
-  @param[out] MacAddress  Pointer to the resulting multicast MAC address. \r
+  @param[out] MacAddress  Pointer to the resulting multicast MAC address.\r
 \r
   @retval EFI_SUCCESS           The operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:\r
@@ -216,10 +216,10 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpMcastIpToMac (\r
-  IN  EFI_MANAGED_NETWORK_PROTOCOL  *This,\r
-  IN  BOOLEAN                       Ipv6Flag,\r
-  IN  EFI_IP_ADDRESS                *IpAddress,\r
-  OUT EFI_MAC_ADDRESS               *MacAddress\r
+  IN     EFI_MANAGED_NETWORK_PROTOCOL    *This,\r
+  IN     BOOLEAN                         Ipv6Flag,\r
+  IN     EFI_IP_ADDRESS                  *IpAddress,\r
+     OUT EFI_MAC_ADDRESS                 *MacAddress\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -229,7 +229,6 @@ MnpMcastIpToMac (
   EFI_IPv6_ADDRESS            *Ip6Address;\r
 \r
   if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -254,10 +253,10 @@ MnpMcastIpToMac (
     goto ON_EXIT;\r
   }\r
 \r
-  Snp = Instance->MnpServiceData->Snp;\r
+  Snp = Instance->MnpServiceData->MnpDeviceData->Snp;\r
   ASSERT (Snp != NULL);\r
 \r
-  ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));  \r
+  ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));\r
 \r
   if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r
     if (!Ipv6Flag) {\r
@@ -273,10 +272,10 @@ MnpMcastIpToMac (
       MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r
     } else {\r
       //\r
-      // Translate the IPv6 address into a multicast MAC address if the NIC is an \r
+      // Translate the IPv6 address into a multicast MAC address if the NIC is an\r
       // ethernet NIC according to RFC2464.\r
       //\r
-      \r
+\r
       MacAddress->Addr[0] = 0x33;\r
       MacAddress->Addr[1] = 0x33;\r
       MacAddress->Addr[2] = Ip6Address->Addr[12];\r
@@ -305,14 +304,14 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  Enables and disables receive filters for multicast address. This function may \r
+  Enables and disables receive filters for multicast address. This function may\r
   be unsupported in some MNP implementations.\r
-   \r
-  The Groups() function only adds and removes multicast MAC addresses from the \r
+\r
+  The Groups() function only adds and removes multicast MAC addresses from the\r
   filter list. The MNP driver does not transmit or process Internet Group\r
   Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r
   NULL, then all joined groups are left.\r
-   \r
+\r
   @param[in]  This        Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  JoinFlag    Set to TRUE to join this multicast group.\r
                           Set to FALSE to leave this multicast group.\r
@@ -343,9 +342,9 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpGroups (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL  *This,\r
-  IN BOOLEAN                       JoinFlag,\r
-  IN EFI_MAC_ADDRESS               *MacAddress OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL    *This,\r
+  IN BOOLEAN                         JoinFlag,\r
+  IN EFI_MAC_ADDRESS                 *MacAddress OPTIONAL\r
   )\r
 {\r
   MNP_INSTANCE_DATA       *Instance;\r
@@ -365,12 +364,11 @@ MnpGroups (
   }\r
 \r
   Instance  = MNP_INSTANCE_DATA_FROM_THIS (This);\r
-  SnpMode   = Instance->MnpServiceData->Snp->Mode;\r
+  SnpMode   = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (!Instance->Configured) {\r
-\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
@@ -452,8 +450,8 @@ ON_EXIT:
 \r
 /**\r
   Places asynchronous outgoing data packets into the transmit queue.\r
-   \r
-  The Transmit() function places a completion token into the transmit packet \r
+\r
+  The Transmit() function places a completion token into the transmit packet\r
   queue. This function is always asynchronous.\r
   The caller must fill in the Token.Event and Token.TxData fields in the\r
   completion token, and these fields cannot be NULL. When the transmit operation\r
@@ -463,8 +461,8 @@ ON_EXIT:
   defragmented before it can be transmitted by the network device. Systems in\r
   which performance is critical should review the requirements and features of\r
   the underlying communications device and drivers.\r
\r
\r
+\r
+\r
   @param[in]  This    Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token   Pointer to a token associated with the transmit data\r
                       descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN\r
@@ -497,7 +495,7 @@ ON_EXIT:
   @retval EFI_ACCESS_DENIED      The transmit completion token is already in the\r
                                  transmit queue.\r
   @retval EFI_OUT_OF_RESOURCES   The transmit data could not be queued due to a\r
-                                 lack of system resources (usually memory). \r
+                                 lack of system resources (usually memory).\r
   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.\r
                                  The MNP child driver instance has been reset to\r
                                  startup defaults.\r
@@ -508,8 +506,8 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpTransmit (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   )\r
 {\r
   EFI_STATUS        Status;\r
@@ -520,7 +518,6 @@ MnpTransmit (
   EFI_TPL           OldTpl;\r
 \r
   if ((This == NULL) || (Token == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -564,14 +561,14 @@ ON_EXIT:
 \r
 /**\r
   Places an asynchronous receiving request into the receiving queue.\r
-   \r
-  The Receive() function places a completion token into the receive packet \r
+\r
+  The Receive() function places a completion token into the receive packet\r
   queue. This function is always asynchronous.\r
   The caller must fill in the Token.Event field in the completion token, and\r
   this field cannot be NULL. When the receive operation completes, the MNP\r
   updates the Token.Status and Token.RxData fields and the Token.Event is\r
   signaled.\r
-   \r
+\r
   @param[in]  This      Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token     Pointer to a token associated with the receive\r
                         data descriptor. Type\r
@@ -600,8 +597,8 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpReceive (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   )\r
 {\r
   EFI_STATUS         Status;\r
@@ -609,7 +606,6 @@ MnpReceive (
   EFI_TPL            OldTpl;\r
 \r
   if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -618,7 +614,6 @@ MnpReceive (
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (!Instance->Configured) {\r
-\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
@@ -628,7 +623,6 @@ MnpReceive (
   //\r
   Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);\r
   if (EFI_ERROR (Status)) {\r
-\r
     goto ON_EXIT;\r
   }\r
 \r
@@ -636,7 +630,6 @@ MnpReceive (
   // Insert the Token into the RxTokenMap.\r
   //\r
   Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);\r
-\r
   if (!EFI_ERROR (Status)) {\r
     //\r
     // Try to deliver any buffered packets.\r
@@ -656,8 +649,8 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  Aborts an asynchronous transmit or receive request. \r
-   \r
+  Aborts an asynchronous transmit or receive request.\r
+\r
   The Cancel() function is used to abort a pending transmit or receive request.\r
   If the token is in the transmit or receive request queues, after calling this\r
   function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r
@@ -668,7 +661,7 @@ ON_EXIT:
   @param[in]  This     Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token    Pointer to a token that has been issued by\r
                        EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r
-                       EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all \r
+                       EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all\r
                        pending tokens are aborted.\r
 \r
   @retval EFI_SUCCESS            The asynchronous I/O request was aborted and\r
@@ -687,8 +680,8 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpCancel (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token OPTIONAL\r
   )\r
 {\r
   EFI_STATUS         Status;\r
@@ -696,7 +689,6 @@ MnpCancel (
   EFI_TPL            OldTpl;\r
 \r
   if (This == NULL) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -705,7 +697,6 @@ MnpCancel (
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (!Instance->Configured) {\r
-\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
@@ -714,9 +705,7 @@ MnpCancel (
   // Iterate the RxTokenMap to cancel the specified Token.\r
   //\r
   Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);\r
-\r
   if (Token != NULL) {\r
-\r
     Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
   }\r
 \r
@@ -732,9 +721,9 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  Polls for incoming data packets and processes outgoing data packets. \r
-   \r
-  The Poll() function can be used by network drivers and applications to \r
+  Polls for incoming data packets and processes outgoing data packets.\r
+\r
+  The Poll() function can be used by network drivers and applications to\r
   increase the rate that data packets are moved between the communications\r
   device and the transmit and receive queues.\r
   Normally, a periodic timer event internally calls the Poll() function. But, in\r
@@ -760,7 +749,7 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpPoll (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL  *This\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL    *This\r
   )\r
 {\r
   EFI_STATUS         Status;\r
@@ -783,7 +772,7 @@ MnpPoll (
   //\r
   // Try to receive packets.\r
   //\r
-  Status = MnpReceivePacket (Instance->MnpServiceData);\r
+  Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData);\r
 \r
   //\r
   // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
@@ -795,4 +784,3 @@ ON_EXIT:
 \r
   return Status;\r
 }\r
-\r
diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c b/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c
new file mode 100644 (file)
index 0000000..1ba309c
--- /dev/null
@@ -0,0 +1,688 @@
+/** @file\r
+  VLAN Config Protocol implementation and VLAN packet process routine.\r
+\r
+Copyright (c) 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
+\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
+**/\r
+\r
+#include "MnpImpl.h"\r
+#include "MnpVlan.h"\r
+\r
+VLAN_DEVICE_PATH          mVlanDevicePathTemplate = {\r
+  {\r
+    MESSAGING_DEVICE_PATH,\r
+    MSG_VLAN_DP,\r
+    {\r
+      (UINT8) (sizeof (VLAN_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (VLAN_DEVICE_PATH)) >> 8)\r
+    }\r
+  },\r
+  0\r
+};\r
+\r
+EFI_VLAN_CONFIG_PROTOCOL  mVlanConfigProtocolTemplate = {\r
+  VlanConfigSet,\r
+  VlanConfigFind,\r
+  VlanConfigRemove\r
+};\r
+\r
+\r
+/**\r
+  Create a child handle for the VLAN ID.\r
+\r
+  @param[in]       ImageHandle        The driver image handle.\r
+  @param[in]       ControllerHandle   Handle of device to bind driver to.\r
+  @param[in]       VlanId             The VLAN ID.\r
+  @param[out]      Devicepath         Pointer to returned device path for child handle.\r
+\r
+  @return The handle of VLAN child or NULL if failed to create VLAN child.\r
+\r
+**/\r
+EFI_HANDLE\r
+MnpCreateVlanChild (\r
+  IN     EFI_HANDLE                  ImageHandle,\r
+  IN     EFI_HANDLE                  ControllerHandle,\r
+  IN     UINT16                      VlanId,\r
+     OUT EFI_DEVICE_PATH_PROTOCOL    **Devicepath OPTIONAL\r
+  )\r
+{\r
+  EFI_HANDLE                ChildHandle;\r
+  VLAN_DEVICE_PATH          VlanNode;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *VlanDevicePath;\r
+  EFI_STATUS                Status;\r
+\r
+  //\r
+  // Try to get parent device path\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
+                  ImageHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Construct device path for child handle: MAC + VLAN\r
+  //\r
+  CopyMem (&VlanNode, &mVlanDevicePathTemplate, sizeof (VLAN_DEVICE_PATH));\r
+  VlanNode.VlanId = VlanId;\r
+  VlanDevicePath = AppendDevicePathNode (\r
+                     ParentDevicePath,\r
+                     (EFI_DEVICE_PATH_PROTOCOL *) &VlanNode\r
+                     );\r
+  if (VlanDevicePath == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Create child VLAN handle by installing DevicePath protocol\r
+  //\r
+  ChildHandle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &ChildHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  VlanDevicePath,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (VlanDevicePath);\r
+    return NULL;\r
+  }\r
+\r
+  if (Devicepath != NULL) {\r
+    *Devicepath = VlanDevicePath;\r
+  }\r
+\r
+  return ChildHandle;\r
+}\r
+\r
+/**\r
+  Remove VLAN tag from a packet.\r
+\r
+  @param[in, out]  MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in, out]  Nbuf               Pointer to the NET_BUF to remove VLAN tag.\r
+  @param[out]      VlanId             Pointer to the returned VLAN ID.\r
+\r
+  @retval TRUE             VLAN tag is removed from this packet.\r
+  @retval FALSE            There is no VLAN tag in this packet.\r
+\r
+**/\r
+BOOLEAN\r
+MnpRemoveVlanTag (\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
+  IN OUT NET_BUF           *Nbuf,\r
+     OUT UINT16            *VlanId\r
+  )\r
+{\r
+  UINT8     *Packet;\r
+  UINTN     ProtocolOffset;\r
+  UINT16    ProtocolType;\r
+  VLAN_TCI  VlanTag;\r
+\r
+  ProtocolOffset = MnpDeviceData->Snp->Mode->HwAddressSize * 2;\r
+\r
+  //\r
+  // Get the packet buffer.\r
+  //\r
+  Packet = NetbufGetByte (Nbuf, 0, NULL);\r
+  ASSERT (Packet != NULL);\r
+\r
+  //\r
+  // Check whether this is VLAN tagged frame by Ether Type\r
+  //\r
+  *VlanId      = 0;\r
+  ProtocolType = NTOHS (*(UINT16 *) (Packet + ProtocolOffset));\r
+  if (ProtocolType != ETHER_TYPE_VLAN) {\r
+    //\r
+    // Not a VLAN tagged frame\r
+    //\r
+    return FALSE;\r
+  }\r
+\r
+  VlanTag.Uint16 = NTOHS (*(UINT16 *) (Packet + ProtocolOffset + sizeof (ProtocolType)));\r
+  *VlanId = VlanTag.Bits.Vid;\r
+\r
+  //\r
+  // Move hardware address (DA + SA) 4 bytes right to override VLAN tag\r
+  //\r
+  CopyMem (Packet + NET_VLAN_TAG_LEN, Packet, ProtocolOffset);\r
+\r
+  //\r
+  // Remove VLAN tag from the Nbuf\r
+  //\r
+  NetbufTrim (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);\r
+\r
+  return TRUE;\r
+}\r
+\r
+\r
+/**\r
+  Build the packet to transmit from the TxData passed in.\r
+\r
+  @param  MnpServiceData         Pointer to the mnp service context data.\r
+  @param  TxData                 Pointer to the transmit data containing the\r
+                                 information to build the packet.\r
+  @param  ProtocolType           Pointer to the Ethernet protocol type.\r
+  @param  Packet                 Pointer to record the address of the packet.\r
+  @param  Length                 Pointer to a UINT32 variable used to record the\r
+                                 packet's length.\r
+\r
+**/\r
+VOID\r
+MnpInsertVlanTag (\r
+  IN     MNP_SERVICE_DATA                    *MnpServiceData,\r
+  IN     EFI_MANAGED_NETWORK_TRANSMIT_DATA   *TxData,\r
+     OUT UINT16                              *ProtocolType,\r
+  IN OUT UINT8                               **Packet,\r
+  IN OUT UINT32                              *Length\r
+  )\r
+{\r
+  VLAN_TCI                *VlanTci;\r
+  UINT16                  *Tpid;\r
+  UINT16                  *EtherType;\r
+  MNP_DEVICE_DATA         *MnpDeviceData;\r
+  EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
+\r
+  if (MnpServiceData->VlanId == 0) {\r
+    *ProtocolType = TxData->ProtocolType;\r
+    return ;\r
+  }\r
+\r
+  MnpDeviceData = MnpServiceData->MnpDeviceData;\r
+  SnpMode       = MnpDeviceData->Snp->Mode;\r
+\r
+  *ProtocolType = ETHER_TYPE_VLAN;\r
+  *Length = *Length + NET_VLAN_TAG_LEN;\r
+  *Packet = *Packet - NET_VLAN_TAG_LEN;\r
+\r
+  Tpid    = (UINT16 *) (*Packet + SnpMode->MediaHeaderSize - sizeof (*ProtocolType));\r
+  VlanTci = (VLAN_TCI *) (UINTN) (Tpid + 1);\r
+  if (TxData->HeaderLength != 0) {\r
+    //\r
+    // Media header is in packet, move DA+SA 4 bytes left\r
+    //\r
+    CopyMem (\r
+      *Packet,\r
+      *Packet + NET_VLAN_TAG_LEN,\r
+      SnpMode->MediaHeaderSize - sizeof (*ProtocolType)\r
+      );\r
+    *Tpid = HTONS (ETHER_TYPE_VLAN);\r
+  } else {\r
+    //\r
+    // Media header not in packet, VLAN TCI and original protocol type becomes payload\r
+    //\r
+    EtherType  = (UINT16 *) (UINTN) (VlanTci + 1);\r
+    *EtherType = HTONS (TxData->ProtocolType);\r
+  }\r
+\r
+  VlanTci->Bits.Vid      = MnpServiceData->VlanId;\r
+  VlanTci->Bits.Cfi      = VLAN_TCI_CFI_CANONICAL_MAC;\r
+  VlanTci->Bits.Priority = MnpServiceData->Priority;\r
+  VlanTci->Uint16        = HTONS (VlanTci->Uint16);\r
+}\r
+\r
+\r
+/**\r
+  Get VLAN configuration variable.\r
+\r
+  @param[in]       MnpDeviceData      Pointer to the MNP device context data.\r
+  @param[out]      NumberOfVlan       Pointer to number of VLAN to be returned.\r
+  @param[out]      VlanVariable       Pointer to the buffer to return requested\r
+                                      array of VLAN_TCI.\r
+\r
+  @retval EFI_SUCCESS            The array of VLAN_TCI was returned in VlanVariable\r
+                                 and number of VLAN was returned in NumberOfVlan.\r
+  @retval EFI_NOT_FOUND          VLAN configuration variable not found.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the configuration.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpGetVlanVariable (\r
+  IN     MNP_DEVICE_DATA   *MnpDeviceData,\r
+     OUT UINTN             *NumberOfVlan,\r
+     OUT VLAN_TCI          **VlanVariable\r
+  )\r
+{\r
+  UINTN       BufferSize;\r
+  EFI_STATUS  Status;\r
+  VLAN_TCI    *Buffer;\r
+\r
+  //\r
+  // Get VLAN configuration from EFI Variable\r
+  //\r
+  Buffer = NULL;\r
+  BufferSize = 0;\r
+  Status = gRT->GetVariable (\r
+                  MnpDeviceData->MacString,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  NULL,\r
+                  &BufferSize,\r
+                  NULL\r
+                  );\r
+  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Allocate buffer to read the variable\r
+  //\r
+  Buffer = AllocateZeroPool (BufferSize);\r
+  if (Buffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = gRT->GetVariable (\r
+                  MnpDeviceData->MacString,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  NULL,\r
+                  &BufferSize,\r
+                  Buffer\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (Buffer);\r
+    return Status;\r
+  }\r
+\r
+  *NumberOfVlan = BufferSize / sizeof (VLAN_TCI);\r
+  *VlanVariable = Buffer;\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Set VLAN configuration variable.\r
+\r
+  @param[in] MnpDeviceData       Pointer to the MNP device context data.\r
+  @param[in] NumberOfVlan        Number of VLAN in array VlanVariable.\r
+  @param[in] VlanVariable        Pointer to array of VLAN_TCI.\r
+\r
+  @retval EFI_SUCCESS            The VLAN variable is successfully set.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough resource to set the configuration.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpSetVlanVariable (\r
+  IN MNP_DEVICE_DATA             *MnpDeviceData,\r
+  IN UINTN                       NumberOfVlan,\r
+  IN VLAN_TCI                    *VlanVariable\r
+  )\r
+{\r
+  return gRT->SetVariable (\r
+                MnpDeviceData->MacString,\r
+                &gEfiVlanConfigProtocolGuid,\r
+                EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                NumberOfVlan * sizeof (VLAN_TCI),\r
+                VlanVariable\r
+                );\r
+}\r
+\r
+\r
+/**\r
+  Create a VLAN device or modify the configuration parameter of an\r
+  already-configured VLAN.\r
+\r
+  The Set() function is used to create a new VLAN device or change the VLAN\r
+  configuration parameters. If the VlanId hasn't been configured in the\r
+  physical Ethernet device, a new VLAN device will be created. If a VLAN with\r
+  this VlanId is already configured, then related configuration will be updated\r
+  as the input parameters.\r
+\r
+  If VlanId is zero, the VLAN device will send and receive untagged frames.\r
+  Otherwise, the VLAN device will send and receive VLAN-tagged frames containing the VlanId.\r
+  If VlanId is out of scope of (0-4094), EFI_INVALID_PARAMETER is returned.\r
+  If Priority is out of the scope of (0-7), then EFI_INVALID_PARAMETER is returned.\r
+  If there is not enough system memory to perform the registration, then\r
+  EFI_OUT_OF_RESOURCES is returned.\r
+\r
+  @param[in] This                Points to the EFI_VLAN_CONFIG_PROTOCOL.\r
+  @param[in] VlanId              A unique identifier (1-4094) of the VLAN which is being created\r
+                                 or modified, or zero (0).\r
+  @param[in] Priority            3 bit priority in VLAN header. Priority 0 is default value. If\r
+                                 VlanId is zero (0), Priority is ignored.\r
+\r
+  @retval EFI_SUCCESS            The VLAN is successfully configured.\r
+  @retval EFI_INVALID_PARAMETER  One or more of following conditions is TRUE:\r
+                                 - This is NULL.\r
+                                 - VlanId is an invalid VLAN Identifier.\r
+                                 - Priority is invalid.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough system memory to perform the registration.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigSet (\r
+  IN EFI_VLAN_CONFIG_PROTOCOL    *This,\r
+  IN UINT16                      VlanId,\r
+  IN UINT8                       Priority\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  MNP_DEVICE_DATA   *MnpDeviceData;\r
+  MNP_SERVICE_DATA  *MnpServiceData;\r
+  VLAN_TCI          *OldVariable;\r
+  VLAN_TCI          *NewVariable;\r
+  UINTN             NumberOfVlan;\r
+  UINTN             Index;\r
+  BOOLEAN           IsAdd;\r
+  LIST_ENTRY        *Entry;\r
+\r
+  if ((This == NULL) || (VlanId > 4094) || (Priority > 7)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  IsAdd = FALSE;\r
+  MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (This);\r
+  if (MnpDeviceData->NumberOfVlan == 0) {\r
+    //\r
+    // No existing VLAN, this is the first VLAN to add\r
+    //\r
+    IsAdd = TRUE;\r
+    Entry = GetFirstNode (&MnpDeviceData->ServiceList);\r
+    MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+\r
+    if (VlanId != 0) {\r
+      //\r
+      // VlanId is not 0, need destroy the default MNP service data\r
+      //\r
+      Status = MnpDestroyServiceChild (MnpServiceData);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+\r
+      Status = MnpDestroyServiceData (MnpServiceData);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+\r
+      //\r
+      // Create a new MNP service data for this VLAN\r
+      //\r
+      MnpServiceData = MnpCreateServiceData (MnpDeviceData, VlanId, Priority);\r
+      if (MnpServiceData == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+    }\r
+  } else {\r
+    //\r
+    // Try to find VlanId in existing VLAN list\r
+    //\r
+    MnpServiceData = MnpFindServiceData (MnpDeviceData, VlanId);\r
+    if (MnpServiceData == NULL) {\r
+      //\r
+      // VlanId not found, create a new MNP service data\r
+      //\r
+      IsAdd = TRUE;\r
+      MnpServiceData = MnpCreateServiceData (MnpDeviceData, VlanId, Priority);\r
+      if (MnpServiceData == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+    }\r
+  }\r
+\r
+  MnpServiceData->VlanId = VlanId;\r
+  MnpServiceData->Priority = Priority;\r
+  if (IsAdd) {\r
+    MnpDeviceData->NumberOfVlan++;\r
+  }\r
+\r
+  //\r
+  // Update VLAN configuration variable\r
+  //\r
+  OldVariable  = NULL;\r
+  NewVariable  = NULL;\r
+  NumberOfVlan = 0;\r
+  MnpGetVlanVariable (MnpDeviceData, &NumberOfVlan, &OldVariable);\r
+\r
+  if (IsAdd) {\r
+    //\r
+    // VLAN not exist - add\r
+    //\r
+    NewVariable = AllocateZeroPool ((NumberOfVlan + 1) * sizeof (VLAN_TCI));\r
+    if (NewVariable == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
+    }\r
+\r
+    if (OldVariable != NULL) {\r
+      CopyMem (NewVariable, OldVariable, NumberOfVlan * sizeof (VLAN_TCI));\r
+    }\r
+\r
+    Index = NumberOfVlan++;\r
+  } else {\r
+    //\r
+    // VLAN already exist - update\r
+    //\r
+    for (Index = 0; Index < NumberOfVlan; Index++) {\r
+      if (OldVariable[Index].Bits.Vid == VlanId) {\r
+        break;\r
+      }\r
+    }\r
+    ASSERT (Index < NumberOfVlan);\r
+\r
+    NewVariable = OldVariable;\r
+    OldVariable = NULL;\r
+  }\r
+\r
+  NewVariable[Index].Bits.Vid      = VlanId;\r
+  NewVariable[Index].Bits.Priority = Priority;\r
+\r
+  Status = MnpSetVlanVariable (MnpDeviceData, NumberOfVlan, NewVariable);\r
+  FreePool (NewVariable);\r
+\r
+Exit:\r
+  if (OldVariable != NULL) {\r
+    FreePool (OldVariable);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Find configuration information for specified VLAN or all configured VLANs.\r
+\r
+  The Find() function is used to find the configuration information for matching\r
+  VLAN and allocate a buffer into which those entries are copied.\r
+\r
+  @param[in]  This               Points to the EFI_VLAN_CONFIG_PROTOCOL.\r
+  @param[in]  VlanId             Pointer to VLAN identifier. Set to NULL to find all\r
+                                 configured VLANs.\r
+  @param[out] NumberOfVlan       The number of VLANs which is found by the specified criteria.\r
+  @param[out] Entries            The buffer which receive the VLAN configuration.\r
+\r
+  @retval EFI_SUCCESS            The VLAN is successfully found.\r
+  @retval EFI_INVALID_PARAMETER  One or more of following conditions is TRUE:\r
+                                 - This is NULL.\r
+                                 - Specified VlanId is invalid.\r
+  @retval EFI_NOT_FOUND          No matching VLAN is found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigFind (\r
+  IN     EFI_VLAN_CONFIG_PROTOCOL    *This,\r
+  IN     UINT16                      *VlanId OPTIONAL,\r
+     OUT UINT16                      *NumberOfVlan,\r
+     OUT EFI_VLAN_FIND_DATA          **Entries\r
+  )\r
+{\r
+  MNP_DEVICE_DATA     *MnpDeviceData;\r
+  MNP_SERVICE_DATA    *MnpServiceData;\r
+  LIST_ENTRY          *Entry;\r
+  EFI_VLAN_FIND_DATA  *VlanData;\r
+\r
+  if ((This == NULL) || (VlanId != NULL && *VlanId > 4094) || (NumberOfVlan == NULL) || (Entries == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *NumberOfVlan = 0;\r
+  *Entries      = NULL;\r
+\r
+  MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (This);\r
+  if (MnpDeviceData->NumberOfVlan == 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  if (VlanId == NULL) {\r
+    //\r
+    // Return all current VLAN configuration\r
+    //\r
+    *NumberOfVlan = (UINT16) MnpDeviceData->NumberOfVlan;\r
+    VlanData = AllocateZeroPool (*NumberOfVlan * sizeof (EFI_VLAN_FIND_DATA));\r
+    if (VlanData == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    *Entries = VlanData;\r
+    NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {\r
+      MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+\r
+      VlanData->VlanId = MnpServiceData->VlanId;\r
+      VlanData->Priority = MnpServiceData->Priority;\r
+      VlanData++;\r
+    }\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // VlanId is specified, try to find it in current VLAN list\r
+  //\r
+  MnpServiceData = MnpFindServiceData (MnpDeviceData, *VlanId);\r
+  if (MnpServiceData == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  VlanData = AllocateZeroPool (sizeof (EFI_VLAN_FIND_DATA));\r
+  if (VlanData == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  VlanData->VlanId = MnpServiceData->VlanId;\r
+  VlanData->Priority = MnpServiceData->Priority;\r
+\r
+  *NumberOfVlan = 1;\r
+  *Entries = VlanData;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Remove the configured VLAN device.\r
+\r
+  The Remove() function is used to remove the specified VLAN device.\r
+  If the VlanId is out of the scope of (0-4094), EFI_INVALID_PARAMETER is returned.\r
+  If specified VLAN hasn't been previously configured, EFI_NOT_FOUND is returned.\r
+\r
+  @param[in] This                Points to the EFI_VLAN_CONFIG_PROTOCOL.\r
+  @param[in] VlanId              Identifier (0-4094) of the VLAN to be removed.\r
+\r
+  @retval EFI_SUCCESS            The VLAN is successfully removed.\r
+  @retval EFI_INVALID_PARAMETER  One or more of following conditions is TRUE:\r
+                                 - This is NULL.\r
+                                 - VlanId  is an invalid parameter.\r
+  @retval EFI_NOT_FOUND          The to-be-removed VLAN does not exist.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigRemove (\r
+  IN EFI_VLAN_CONFIG_PROTOCOL    *This,\r
+  IN UINT16                      VlanId\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  MNP_DEVICE_DATA   *MnpDeviceData;\r
+  MNP_SERVICE_DATA  *MnpServiceData;\r
+  LIST_ENTRY        *Entry;\r
+  VLAN_TCI          *VlanVariable;\r
+  VLAN_TCI          *VlanData;\r
+\r
+  if ((This == NULL) || (VlanId > 4094)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (This);\r
+  if (MnpDeviceData->NumberOfVlan == 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Try to find the VlanId\r
+  //\r
+  MnpServiceData = MnpFindServiceData (MnpDeviceData, VlanId);\r
+  if (MnpServiceData == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  MnpDeviceData->NumberOfVlan--;\r
+\r
+  if ((VlanId != 0) || (MnpDeviceData->NumberOfVlan != 0)) {\r
+    //\r
+    // If VlanId is not 0 or VlanId is 0 and it is not the last VLAN to remove,\r
+    // destroy its MNP service data\r
+    //\r
+    Status = MnpDestroyServiceChild (MnpServiceData);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = MnpDestroyServiceData (MnpServiceData);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if ((VlanId != 0) && (MnpDeviceData->NumberOfVlan == 0)) {\r
+    //\r
+    // This is the last VLAN to be removed, restore the default MNP service data\r
+    //\r
+    MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);\r
+    if (MnpServiceData == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Update VLAN configuration variable\r
+  //\r
+  VlanVariable = NULL;\r
+  if (MnpDeviceData->NumberOfVlan != 0) {\r
+    VlanVariable = AllocatePool (MnpDeviceData->NumberOfVlan * sizeof (VLAN_TCI));\r
+    if (VlanVariable == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    VlanData = VlanVariable;\r
+    NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {\r
+      MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+\r
+      VlanData->Bits.Vid      = MnpServiceData->VlanId;\r
+      VlanData->Bits.Priority = MnpServiceData->Priority;\r
+      VlanData++;\r
+    }\r
+  }\r
+\r
+  Status = MnpSetVlanVariable (MnpDeviceData, MnpDeviceData->NumberOfVlan, VlanVariable);\r
+\r
+  if (VlanVariable != NULL) {\r
+    FreePool (VlanVariable);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.h b/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.h
new file mode 100644 (file)
index 0000000..abd6727
--- /dev/null
@@ -0,0 +1,212 @@
+/** @file\r
+  Header file to be included by MnpVlan.c.\r
+\r
+Copyright (c) 2009, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
+\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
+**/\r
+\r
+#ifndef __MNP_VLAN_H__\r
+#define __MNP_VLAN_H__\r
+\r
+#include "MnpDriver.h"\r
+\r
+extern EFI_VLAN_CONFIG_PROTOCOL mVlanConfigProtocolTemplate;\r
+\r
+\r
+/**\r
+  Create a child handle for the VLAN ID.\r
+\r
+  @param[in]       ImageHandle        The driver image handle.\r
+  @param[in]       ControllerHandle   Handle of device to bind driver to.\r
+  @param[in]       VlanId             The VLAN ID.\r
+  @param[out]      Devicepath         Pointer to returned device path for child handle.\r
+\r
+  @return The handle of VLAN child or NULL if failed to create VLAN child.\r
+\r
+**/\r
+EFI_HANDLE\r
+MnpCreateVlanChild (\r
+  IN     EFI_HANDLE                  ImageHandle,\r
+  IN     EFI_HANDLE                  ControllerHandle,\r
+  IN     UINT16                      VlanId,\r
+     OUT EFI_DEVICE_PATH_PROTOCOL    **Devicepath OPTIONAL\r
+  );\r
+\r
+/**\r
+  Remove VLAN tag of a packet.\r
+\r
+  @param[in, out]  MnpDeviceData      Pointer to the mnp device context data.\r
+  @param[in, out]  Nbuf               Pointer to the NET_BUF to remove VLAN tag.\r
+  @param[out]      VlanId             Pointer to the returned VLAN ID.\r
+\r
+  @retval TRUE             VLAN tag is removed from this packet.\r
+  @retval FALSE            There is no VLAN tag in this packet.\r
+\r
+**/\r
+BOOLEAN\r
+MnpRemoveVlanTag (\r
+  IN OUT MNP_DEVICE_DATA   *MnpDeviceData,\r
+  IN OUT NET_BUF           *Nbuf,\r
+     OUT UINT16            *VlanId\r
+  );\r
+\r
+/**\r
+  Build the packet to transmit from the TxData passed in.\r
+\r
+  @param  MnpServiceData         Pointer to the mnp service context data.\r
+  @param  TxData                 Pointer to the transmit data containing the\r
+                                 information to build the packet.\r
+  @param  ProtocolType           Pointer to the Ethernet protocol type.\r
+  @param  Packet                 Pointer to record the address of the packet.\r
+  @param  Length                 Pointer to a UINT32 variable used to record the\r
+                                 packet's length.\r
+\r
+**/\r
+VOID\r
+MnpInsertVlanTag (\r
+  IN     MNP_SERVICE_DATA                    *MnpServiceData,\r
+  IN     EFI_MANAGED_NETWORK_TRANSMIT_DATA   *TxData,\r
+     OUT UINT16                              *ProtocolType,\r
+  IN OUT UINT8                               **Packet,\r
+  IN OUT UINT32                              *Length\r
+  );\r
+\r
+/**\r
+  Get VLAN configuration variable.\r
+\r
+  @param[in]       MnpDeviceData      Pointer to the MNP device context data.\r
+  @param[out]      NumberOfVlan       Pointer to number of VLAN to be returned.\r
+  @param[out]      VlanVariable       Pointer to the buffer to return requested\r
+                                      array of VLAN_TCI.\r
+\r
+  @retval EFI_SUCCESS            The array of VLAN_TCI was returned in VlanVariable\r
+                                 and number of VLAN was returned in NumberOfVlan.\r
+  @retval EFI_NOT_FOUND          VLAN configuration variable not found.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the configuration.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpGetVlanVariable (\r
+  IN     MNP_DEVICE_DATA   *MnpDeviceData,\r
+     OUT UINTN             *NumberOfVlan,\r
+     OUT VLAN_TCI          **VlanVariable\r
+  );\r
+\r
+/**\r
+  Set VLAN configuration variable.\r
+\r
+  @param[in] MnpDeviceData       Pointer to the MNP device context data.\r
+  @param[in] NumberOfVlan        Number of VLAN in array VlanVariable.\r
+  @param[in] VlanVariable        Pointer to array of VLAN_TCI.\r
+\r
+  @retval EFI_SUCCESS            The VLAN variable is successfully set.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough resource to set the configuration.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpSetVlanVariable (\r
+  IN MNP_DEVICE_DATA             *MnpDeviceData,\r
+  IN UINTN                       NumberOfVlan,\r
+  IN VLAN_TCI                    *VlanVariable\r
+  );\r
+\r
+/**\r
+  Create a VLAN device or modify the configuration parameter of an\r
+  already-configured VLAN.\r
+\r
+  The Set() function is used to create a new VLAN device or change the VLAN\r
+  configuration parameters. If the VlanId hasn't been configured in the\r
+  physical Ethernet device, a new VLAN device will be created. If a VLAN with\r
+  this VlanId is already configured, then related configuration will be updated\r
+  as the input parameters.\r
+\r
+  If VlanId is zero, the VLAN device will send and receive untagged frames.\r
+  Otherwise, the VLAN device will send and receive VLAN-tagged frames containing the VlanId.\r
+  If VlanId is out of scope of (0-4094), EFI_INVALID_PARAMETER is returned.\r
+  If Priority is out of the scope of (0-7), then EFI_INVALID_PARAMETER is returned.\r
+  If there is not enough system memory to perform the registration, then\r
+  EFI_OUT_OF_RESOURCES is returned.\r
+\r
+  @param[in] This                Points to the EFI_VLAN_CONFIG_PROTOCOL.\r
+  @param[in] VlanId              A unique identifier (1-4094) of the VLAN which is being created\r
+                                 or modified, or zero (0).\r
+  @param[in] Priority            3 bit priority in VLAN header. Priority 0 is default value. If\r
+                                 VlanId is zero (0), Priority is ignored.\r
+\r
+  @retval EFI_SUCCESS            The VLAN is successfully configured.\r
+  @retval EFI_INVALID_PARAMETER  One or more of following conditions is TRUE:\r
+                                 - This is NULL.\r
+                                 - VlanId is an invalid VLAN Identifier.\r
+                                 - Priority is invalid.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough system memory to perform the registration.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigSet (\r
+  IN EFI_VLAN_CONFIG_PROTOCOL    *This,\r
+  IN UINT16                      VlanId,\r
+  IN UINT8                       Priority\r
+  );\r
+\r
+/**\r
+  Find configuration information for specified VLAN or all configured VLANs.\r
+\r
+  The Find() function is used to find the configuration information for matching\r
+  VLAN and allocate a buffer into which those entries are copied.\r
+\r
+  @param[in]  This               Points to the EFI_VLAN_CONFIG_PROTOCOL.\r
+  @param[in]  VlanId             Pointer to VLAN identifier. Set to NULL to find all\r
+                                 configured VLANs.\r
+  @param[out] NumberOfVlan       The number of VLANs which is found by the specified criteria.\r
+  @param[out] Entries            The buffer which receive the VLAN configuration.\r
+\r
+  @retval EFI_SUCCESS            The VLAN is successfully found.\r
+  @retval EFI_INVALID_PARAMETER  One or more of following conditions is TRUE:\r
+                                 - This is NULL.\r
+                                 - Specified VlanId is invalid.\r
+  @retval EFI_NOT_FOUND          No matching VLAN is found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigFind (\r
+  IN     EFI_VLAN_CONFIG_PROTOCOL    *This,\r
+  IN     UINT16                      *VlanId OPTIONAL,\r
+     OUT UINT16                      *NumberOfVlan,\r
+     OUT EFI_VLAN_FIND_DATA          **Entries\r
+  );\r
+\r
+/**\r
+  Remove the configured VLAN device.\r
+\r
+  The Remove() function is used to remove the specified VLAN device.\r
+  If the VlanId is out of the scope of (0-4094), EFI_INVALID_PARAMETER is returned.\r
+  If specified VLAN hasn't been previously configured, EFI_NOT_FOUND is returned.\r
+\r
+  @param[in] This                Points to the EFI_VLAN_CONFIG_PROTOCOL.\r
+  @param[in] VlanId              Identifier (0-4094) of the VLAN to be removed.\r
+\r
+  @retval EFI_SUCCESS            The VLAN is successfully removed.\r
+  @retval EFI_INVALID_PARAMETER  One or more of following conditions is TRUE:\r
+                                 - This is NULL.\r
+                                 - VlanId  is an invalid parameter.\r
+  @retval EFI_NOT_FOUND          The to-be-removed VLAN does not exist.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigRemove (\r
+  IN EFI_VLAN_CONFIG_PROTOCOL    *This,\r
+  IN UINT16                      VlanId\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/ComponentName.c b/MdeModulePkg/Universal/Network/VlanConfigDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..7ff566c
--- /dev/null
@@ -0,0 +1,171 @@
+/** @file\r
+  UEFI Component Name(2) protocol implementation for VlanConfigDxe driver.\r
+\r
+Copyright (c) 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
+\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
+**/\r
+\r
+#include "VlanConfigImpl.h"\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL   gVlanConfigComponentName = {\r
+  VlanConfigComponentNameGetDriverName,\r
+  VlanConfigComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL  gVlanConfigComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) VlanConfigComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) VlanConfigComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE      mVlanConfigDriverNameTable[] = {\r
+  {\r
+    "eng;en",\r
+    L"VLAN Configuration Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigComponentNameGetDriverName (\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mVlanConfigDriverNameTable,\r
+           DriverName,\r
+           (BOOLEAN)(This == &gVlanConfigComponentName)\r
+           );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigComponentNameGetControllerName (\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     EFI_HANDLE                    ControllerHandle,\r
+  IN     EFI_HANDLE                    ChildHandle OPTIONAL,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **ControllerName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfig.vfr b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfig.vfr
new file mode 100644 (file)
index 0000000..f08a87e
--- /dev/null
@@ -0,0 +1,68 @@
+///** @file\r
+//  VLAN configuration formset.\r
+//\r
+//  Copyright (c) 2009, Intel Corporation.<BR>\r
+//  All rights reserved. This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions\r
+//  of the BSD License which accompanies this distribution.  The full\r
+//  text of the license may be found at<BR>\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\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
+//**/\r
+\r
+#include "VlanConfigNvData.h"\r
+\r
+formset\r
+  guid      = VLAN_CONFIG_PRIVATE_GUID,\r
+  title     = STRING_TOKEN(STR_VLAN_FORM_SET_TITLE),\r
+  help      = STRING_TOKEN(STR_VLAN_FORM_SET_TITLE_HELP),\r
+  classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID,\r
+\r
+  varstore VLAN_CONFIGURATION,\r
+    varid = VLAN_CONFIGURATION_VARSTORE_ID,\r
+    name  = VlanNvData,\r
+    guid  = VLAN_CONFIG_PRIVATE_GUID;\r
+\r
+  form formid = VLAN_CONFIGURATION_FORM_ID,\r
+    title = STRING_TOKEN(STR_VLAN_FORM_TITLE);\r
+\r
+    subtitle text = STRING_TOKEN(STR_VLAN_CREATE_VLAN);\r
+\r
+    numeric varid   = VlanNvData.VlanId,\r
+            prompt  = STRING_TOKEN(STR_VLAN_VID_PROMPT),\r
+            help    = STRING_TOKEN(STR_VLAN_VID_HELP),\r
+            minimum = 0,\r
+            maximum = 4094,\r
+    endnumeric;\r
+\r
+    numeric varid   = VlanNvData.Priority,\r
+            prompt  = STRING_TOKEN(STR_VLAN_PRIORITY_PROMPT),\r
+            help    = STRING_TOKEN(STR_VLAN_PRIORITY_HELP),\r
+            minimum = 0,\r
+            maximum = 7,\r
+    endnumeric;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_VLAN_ADD_VLAN_HELP),\r
+      text   = STRING_TOKEN(STR_VLAN_ADD_VLAN_PROMPT),\r
+      flags  = INTERACTIVE,\r
+      key    = VLAN_ADD_QUESTION_ID;\r
+\r
+    subtitle text = STRING_TOKEN(STR_VLAN_NULL_STRING);\r
+    subtitle text = STRING_TOKEN(STR_VLAN_VLAN_LIST);\r
+\r
+    label LABEL_VLAN_LIST;\r
+    label LABEL_END;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_VLAN_REMOVE_VLAN_HELP),\r
+      text   = STRING_TOKEN(STR_VLAN_REMOVE_VLAN_PROMPT),\r
+      flags  = INTERACTIVE,\r
+      key    = VLAN_REMOVE_QUESTION_ID;\r
+\r
+  endform;\r
+\r
+endformset;\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDriver.c b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDriver.c
new file mode 100644 (file)
index 0000000..f0c3ebb
--- /dev/null
@@ -0,0 +1,305 @@
+/** @file\r
+  The driver binding for VLAN configuration module.\r
+\r
+Copyright (c) 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
+\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
+**/\r
+\r
+#include "VlanConfigImpl.h"\r
+\r
+EFI_GUID gVlanConfigPrivateGuid = VLAN_CONFIG_PRIVATE_GUID;\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gVlanConfigDriverBinding = {\r
+  VlanConfigDriverBindingSupported,\r
+  VlanConfigDriverBindingStart,\r
+  VlanConfigDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  The entry point for IP4 config driver which install the driver\r
+  binding and component name protocol on its image.\r
+\r
+  @param[in]  ImageHandle        The image handle of the driver.\r
+  @param[in]  SystemTable        The system table.\r
+\r
+  @retval EFI_SUCCES             All the related protocols are installed on the driver.\r
+  @retval Others                 Failed to install protocols.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigDriverEntryPoint (\r
+  IN EFI_HANDLE          ImageHandle,\r
+  IN EFI_SYSTEM_TABLE    *SystemTable\r
+  )\r
+{\r
+  return EfiLibInstallDriverBindingComponentName2 (\r
+           ImageHandle,\r
+           SystemTable,\r
+           &gVlanConfigDriverBinding,\r
+           ImageHandle,\r
+           &gVlanConfigComponentName,\r
+           &gVlanConfigComponentName2\r
+           );\r
+}\r
+\r
+\r
+/**\r
+  Test to see if this driver supports ControllerHandle.\r
+\r
+  @param[in]  This                 Protocol instance pointer.\r
+  @param[in]  ControllerHandle     Handle of device to test\r
+  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                                   device to start.\r
+\r
+  @retval EFI_SUCCES           This driver supports this device\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on this device\r
+  @retval other                This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_VLAN_CONFIG_PROTOCOL  *VlanConfig;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  (VOID **) &VlanConfig,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Close the VlanConfig protocol opened for supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+         ControllerHandle,\r
+         &gEfiVlanConfigProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         ControllerHandle\r
+         );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Start this driver on ControllerHandle.\r
+\r
+  @param[in]  This                 Protocol instance pointer.\r
+  @param[in]  ControllerHandle     Handle of device to bind driver to\r
+  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                                   device to start.\r
+\r
+  @retval EFI_SUCCES           This driver is added to ControllerHandle\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
+  @retval other                This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_VLAN_CONFIG_PROTOCOL  *VlanConfig;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  VLAN_CONFIG_PRIVATE_DATA  *PrivateData;\r
+\r
+  //\r
+  // Check for multiple start\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gVlanConfigPrivateGuid,\r
+                  (VOID **) &PrivateData,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  //\r
+  // Open VlanConfig protocol by driver\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  (VOID **) &VlanConfig,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get parent device path\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  //\r
+  // Create a private data for this network device\r
+  //\r
+  PrivateData = AllocateCopyPool (sizeof (VLAN_CONFIG_PRIVATE_DATA), &mVlanConfigPrivateDateTemplate);\r
+  if (PrivateData == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  PrivateData->ImageHandle = This->DriverBindingHandle;\r
+  PrivateData->ControllerHandle = ControllerHandle;\r
+  PrivateData->VlanConfig = VlanConfig;\r
+  PrivateData->ParentDevicePath = DevicePath;\r
+\r
+  //\r
+  // Install VLAN configuration form\r
+  //\r
+  Status = InstallVlanConfigForm (PrivateData);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  //\r
+  // Install private GUID\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &ControllerHandle,\r
+                  &gVlanConfigPrivateGuid,\r
+                  PrivateData,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+  return Status;\r
+\r
+ErrorExit:\r
+  gBS->CloseProtocol (\r
+         ControllerHandle,\r
+         &gEfiVlanConfigProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         ControllerHandle\r
+         );\r
+\r
+  gBS->CloseProtocol (\r
+         ControllerHandle,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         ControllerHandle\r
+         );\r
+\r
+  if (PrivateData != NULL) {\r
+    UninstallVlanConfigForm (PrivateData);\r
+    FreePool (PrivateData);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Stop this driver on ControllerHandle.\r
+\r
+  @param[in]  This                 Protocol instance pointer.\r
+  @param[in]  ControllerHandle     Handle of device to stop driver on\r
+  @param[in]  NumberOfChildren     Number of Handles in ChildHandleBuffer. If number\r
+                                   of children is zero stop the entire bus driver.\r
+  @param[in]  ChildHandleBuffer    List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCES           This driver is removed ControllerHandle\r
+  @retval other                This driver was not removed from this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigDriverBindingStop (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN UINTN                           NumberOfChildren,\r
+  IN EFI_HANDLE                      *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  VLAN_CONFIG_PRIVATE_DATA  *PrivateData;\r
+\r
+  //\r
+  // Retrieve the PrivateData from ControllerHandle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gVlanConfigPrivateGuid,\r
+                  (VOID **) &PrivateData,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  ASSERT (PrivateData->Signature == VLAN_CONFIG_PRIVATE_DATA_SIGNATURE);\r
+\r
+  //\r
+  // Uninstall VLAN configuration Form\r
+  //\r
+  UninstallVlanConfigForm (PrivateData);\r
+\r
+  //\r
+  // Uninstall the private GUID\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  ControllerHandle,\r
+                  &gVlanConfigPrivateGuid,\r
+                  PrivateData,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->CloseProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle\r
+                  );\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
new file mode 100644 (file)
index 0000000..40b0433
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+#  Component description file for VLAN configuration module.\r
+#\r
+#  Copyright (c) 2009, Intel Corporation.\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
+#  http://opensource.org/licenses/bsd-license.php\r
+#\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
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = VlanConfigDxe\r
+  FILE_GUID                      = E4F61863-FE2C-4b56-A8F4-08519BC439DF\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = VlanConfigDriverEntryPoint\r
+  UNLOAD_IMAGE                   = NetLibDefaultUnload\r
+\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  VlanConfigDriver.c\r
+  VlanConfigImpl.c\r
+  VlanConfigImpl.h\r
+  VlanConfig.vfr\r
+  VlanConfigStrings.uni\r
+  VlanConfigNvData.h\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+  NetLib\r
+  HiiLib\r
+\r
+[Guids]\r
+  gEfiIfrTianoGuid\r
+\r
+[Protocols]\r
+  gEfiHiiConfigAccessProtocolGuid               ## PRODUCES\r
+  gEfiHiiConfigRoutingProtocolGuid              ## CONSUMES\r
+  gEfiVlanConfigProtocolGuid                    ## CONSUMES\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c
new file mode 100644 (file)
index 0000000..8d72f58
--- /dev/null
@@ -0,0 +1,551 @@
+/** @file\r
+  HII Config Access protocol implementation of VLAN configuration module.\r
+\r
+Copyright (c) 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
+\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
+**/\r
+\r
+#include "VlanConfigImpl.h"\r
+\r
+EFI_GUID                        mVlanFormSetGuid = VLAN_CONFIG_PRIVATE_GUID;\r
+CHAR16                          mVlanStorageName[] = L"VlanNvData";\r
+EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r
+\r
+VLAN_CONFIG_PRIVATE_DATA        mVlanConfigPrivateDateTemplate = {\r
+  VLAN_CONFIG_PRIVATE_DATA_SIGNATURE,\r
+  {\r
+    VlanExtractConfig,\r
+    VlanRouteConfig,\r
+    VlanCallback\r
+  }\r
+};\r
+\r
+VENDOR_DEVICE_PATH              mHiiVendorDevicePathNode = {\r
+  {\r
+    HARDWARE_DEVICE_PATH,\r
+    HW_VENDOR_DP,\r
+    {\r
+      (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
+    }\r
+  },\r
+  VLAN_CONFIG_PRIVATE_GUID\r
+};\r
+\r
+/**\r
+  This function allows a caller to extract the current configuration for one\r
+  or more named elements from the target driver.\r
+\r
+  @param[in]  This               Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param[in]  Request            A null-terminated Unicode string in\r
+                                 <ConfigRequest> format.\r
+  @param[out]  Progress          On return, points to a character in the Request\r
+                                 string. Points to the string's null terminator if\r
+                                 request was successful. Points to the most recent\r
+                                 '&' before the first failing name/value pair (or\r
+                                 the beginning of the string if the failure is in\r
+                                 the first name/value pair) if the request was not\r
+                                 successful.\r
+  @param[out]  Results           A null-terminated Unicode string in\r
+                                 <ConfigAltResp> format which has all values filled\r
+                                 in for the names in the Request string. String to\r
+                                 be allocated by the called function.\r
+\r
+  @retval EFI_SUCCESS            The Results is filled with the requested values.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough memory to store the results.\r
+  @retval EFI_INVALID_PARAMETER  Request is NULL, illegal syntax, or unknown name.\r
+  @retval EFI_NOT_FOUND          Routing data doesn't match any storage in this\r
+                                 driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanExtractConfig (\r
+  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL        *This,\r
+  IN CONST EFI_STRING                            Request,\r
+       OUT EFI_STRING                            *Progress,\r
+       OUT EFI_STRING                            *Results\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  UINTN               BufferSize;\r
+  VLAN_CONFIGURATION  Configuration;\r
+\r
+  if (Request == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Retrieve the pointer to the UEFI HII Config Routing Protocol\r
+  //\r
+  if (mHiiConfigRouting == NULL) {\r
+    gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mHiiConfigRouting);\r
+  }\r
+  ASSERT (mHiiConfigRouting != NULL);\r
+\r
+  //\r
+  // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
+  //\r
+  ZeroMem (&Configuration, sizeof (VLAN_CONFIGURATION));\r
+  BufferSize = sizeof (VLAN_CONFIG_PRIVATE_DATA);\r
+  Status = mHiiConfigRouting->BlockToConfig (\r
+                                mHiiConfigRouting,\r
+                                Request,\r
+                                (UINT8 *) &Configuration,\r
+                                BufferSize,\r
+                                Results,\r
+                                Progress\r
+                                );\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  This function processes the results of changes in configuration.\r
+\r
+  @param[in]  This               Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param[in]  Configuration      A null-terminated Unicode string in <ConfigResp>\r
+                                 format.\r
+  @param[out]  Progress          A pointer to a string filled in with the offset of\r
+                                 the most recent '&' before the first failing\r
+                                 name/value pair (or the beginning of the string if\r
+                                 the failure is in the first name/value pair) or\r
+                                 the terminating NULL if all was successful.\r
+\r
+  @retval EFI_SUCCESS            The Results is processed successfully.\r
+  @retval EFI_INVALID_PARAMETER  Configuration is NULL.\r
+  @retval EFI_NOT_FOUND          Routing data doesn't match any storage in this\r
+                                 driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanRouteConfig (\r
+  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL      *This,\r
+  IN CONST EFI_STRING                          Configuration,\r
+       OUT EFI_STRING                          *Progress\r
+  )\r
+{\r
+  if (Configuration == NULL || Progress == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *Progress = Configuration;\r
+  if (!HiiIsConfigHdrMatch (Configuration, &mVlanFormSetGuid, mVlanStorageName)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  *Progress = Configuration + StrLen (Configuration);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function processes the results of changes in configuration.\r
+\r
+  @param[in]  This               Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param[in]  Action             Specifies the type of action taken by the browser.\r
+  @param[in]  QuestionId         A unique value which is sent to the original\r
+                                 exporting driver so that it can identify the type\r
+                                 of data to expect.\r
+  @param[in]  Type               The type of value for the question.\r
+  @param[in]  Value              A pointer to the data being sent to the original\r
+                                 exporting driver.\r
+  @param[out] ActionRequest      On return, points to the action requested by the\r
+                                 callback function.\r
+\r
+  @retval EFI_SUCCESS            The callback successfully handled the action.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the\r
+                                 variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be saved.\r
+  @retval EFI_UNSUPPORTED        The specified Action is not supported by the\r
+                                 callback.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanCallback (\r
+  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL      *This,\r
+  IN     EFI_BROWSER_ACTION                    Action,\r
+  IN     EFI_QUESTION_ID                       QuestionId,\r
+  IN     UINT8                                 Type,\r
+  IN     EFI_IFR_TYPE_VALUE                    *Value,\r
+     OUT EFI_BROWSER_ACTION_REQUEST            *ActionRequest\r
+  )\r
+{\r
+  VLAN_CONFIG_PRIVATE_DATA  *PrivateData;\r
+  VLAN_CONFIGURATION        *Configuration;\r
+  EFI_VLAN_CONFIG_PROTOCOL  *VlanConfig;\r
+  UINTN                     Index;\r
+  EFI_HANDLE                VlanHandle;\r
+\r
+  PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
+    //\r
+    // On FORM_OPEN event, update current VLAN list\r
+    //\r
+    VlanUpdateForm (PrivateData);\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Get Browser data\r
+  //\r
+  Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r
+  ASSERT (Configuration != NULL);\r
+  HiiGetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
+\r
+  VlanConfig = PrivateData->VlanConfig;\r
+\r
+  switch (QuestionId) {\r
+  case VLAN_ADD_QUESTION_ID:\r
+    //\r
+    // Add a VLAN\r
+    //\r
+    VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r
+    VlanUpdateForm (PrivateData);\r
+\r
+    //\r
+    // Connect the newly created VLAN device\r
+    //\r
+    VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r
+    if (VlanHandle == NULL) {\r
+      //\r
+      // There may be no child handle created for VLAN ID 0, connect the parent handle\r
+      //\r
+      VlanHandle = PrivateData->ControllerHandle;\r
+    }\r
+    gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r
+\r
+    //\r
+    // Clear UI data\r
+    //\r
+    *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
+    Configuration->VlanId = 0;\r
+    Configuration->Priority = 0;\r
+    break;\r
+\r
+  case VLAN_REMOVE_QUESTION_ID:\r
+    //\r
+    // Remove VLAN\r
+    //\r
+    for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r
+      if (Configuration->VlanList[Index] != 0) {\r
+        //\r
+        // Checkbox is selected, need remove this VLAN\r
+        //\r
+        VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r
+      }\r
+    }\r
+\r
+    VlanUpdateForm (PrivateData);\r
+    if (PrivateData->NumberOfVlan == 0) {\r
+      //\r
+      // No VLAN device now, connect the physical NIC handle.\r
+      // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r
+      //\r
+      gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r
+    }\r
+\r
+    *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
+    ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
+    break;\r
+\r
+  default:\r
+    break;\r
+  }\r
+\r
+  HiiSetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
+  FreePool (Configuration);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  This function update VLAN list in the VLAN configuration Form.\r
+\r
+  @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
+\r
+**/\r
+VOID\r
+VlanUpdateForm (\r
+  IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
+  )\r
+{\r
+  EFI_VLAN_CONFIG_PROTOCOL  *VlanConfig;\r
+  UINT16                    NumberOfVlan;\r
+  UINTN                     Index;\r
+  EFI_VLAN_FIND_DATA        *VlanData;\r
+  VOID                      *StartOpCodeHandle;\r
+  EFI_IFR_GUID_LABEL        *StartLabel;\r
+  VOID                      *EndOpCodeHandle;\r
+  EFI_IFR_GUID_LABEL        *EndLabel;\r
+  CHAR16                    *String;\r
+  CHAR16                    VlanStr[30];\r
+  CHAR16                    VlanIdStr[6];\r
+  UINTN                     DigitalCount;\r
+  EFI_STRING_ID             StringId;\r
+\r
+  //\r
+  // Find current VLAN configuration\r
+  //\r
+  VlanData = NULL;\r
+  NumberOfVlan = 0;\r
+  VlanConfig = PrivateData->VlanConfig;\r
+  VlanConfig->Find (VlanConfig, NULL, &NumberOfVlan, &VlanData);\r
+\r
+  //\r
+  // Update VLAN configuration in PrivateData\r
+  //\r
+  if (NumberOfVlan > MAX_VLAN_NUMBER) {\r
+    NumberOfVlan = MAX_VLAN_NUMBER;\r
+  }\r
+  PrivateData->NumberOfVlan = NumberOfVlan;\r
+\r
+  //\r
+  // Init OpCode Handle\r
+  //\r
+  StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+  ASSERT (StartOpCodeHandle != NULL);\r
+\r
+  EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+  ASSERT (EndOpCodeHandle != NULL);\r
+\r
+  //\r
+  // Create Hii Extend Label OpCode as the start opcode\r
+  //\r
+  StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
+                                        StartOpCodeHandle,\r
+                                        &gEfiIfrTianoGuid,\r
+                                        NULL,\r
+                                        sizeof (EFI_IFR_GUID_LABEL)\r
+                                        );\r
+  StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+  StartLabel->Number       = LABEL_VLAN_LIST;\r
+\r
+  //\r
+  // Create Hii Extend Label OpCode as the end opcode\r
+  //\r
+  EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
+                                      EndOpCodeHandle,\r
+                                      &gEfiIfrTianoGuid,\r
+                                      NULL,\r
+                                      sizeof (EFI_IFR_GUID_LABEL)\r
+                                      );\r
+  EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+  EndLabel->Number       = LABEL_END;\r
+\r
+  ZeroMem (PrivateData->VlanId, MAX_VLAN_NUMBER);\r
+  for (Index = 0; Index < NumberOfVlan; Index++) {\r
+    String = VlanStr;\r
+\r
+    StrCpy (String, L"  VLAN ID:");\r
+    String += 10;\r
+    //\r
+    // Pad VlanId string up to 4 characters with space\r
+    //\r
+    DigitalCount = UnicodeValueToString (VlanIdStr, 0, VlanData[Index].VlanId, 5);\r
+    SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' ');\r
+    StrCpy (String + 4 - DigitalCount, VlanIdStr);\r
+    String += 4;\r
+\r
+    StrCpy (String, L", Priority:");\r
+    String += 11;\r
+    String += UnicodeValueToString (String, 0, VlanData[Index].Priority, 4);\r
+    *String = 0;\r
+\r
+    StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL);\r
+    ASSERT (StringId != 0);\r
+\r
+    HiiCreateCheckBoxOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (VLAN_LIST_VAR_OFFSET + Index),\r
+      VLAN_CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (VLAN_LIST_VAR_OFFSET + Index),\r
+      StringId,\r
+      STRING_TOKEN (STR_VLAN_VLAN_LIST_HELP),\r
+      0,\r
+      0,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Save VLAN id to private data\r
+    //\r
+    PrivateData->VlanId[Index] = VlanData[Index].VlanId;\r
+  }\r
+\r
+  HiiUpdateForm (\r
+    PrivateData->HiiHandle,     // HII handle\r
+    &mVlanFormSetGuid,          // Formset GUID\r
+    VLAN_CONFIGURATION_FORM_ID, // Form ID\r
+    StartOpCodeHandle,          // Label for where to insert opcodes\r
+    EndOpCodeHandle             // Replace data\r
+    );\r
+\r
+  HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
+\r
+  if (VlanData != NULL) {\r
+    FreePool (VlanData);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  This function publish the VLAN configuration Form for a network device. The\r
+  HII Config Access protocol will be installed on a child handle of the network\r
+  device.\r
+\r
+  @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
+\r
+  @retval EFI_SUCCESS            HII Form is installed for this network device.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough resource for HII Form installation.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+InstallVlanConfigForm (\r
+  IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_HII_HANDLE                  HiiHandle;\r
+  EFI_HANDLE                      DriverHandle;\r
+  CHAR16                          Str[40];\r
+  CHAR16                          *MacString;\r
+  EFI_DEVICE_PATH_PROTOCOL        *ChildDevicePath;\r
+  EFI_HII_CONFIG_ACCESS_PROTOCOL  *ConfigAccess;\r
+\r
+  //\r
+  // Create child handle and install HII Config Access Protocol\r
+  //\r
+  ChildDevicePath = AppendDevicePathNode (\r
+                      PrivateData->ParentDevicePath,\r
+                      (CONST EFI_DEVICE_PATH_PROTOCOL *) &mHiiVendorDevicePathNode\r
+                      );\r
+  if (ChildDevicePath == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  PrivateData->ChildDevicePath = ChildDevicePath;\r
+\r
+  DriverHandle = NULL;\r
+  ConfigAccess = &PrivateData->ConfigAccess;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &DriverHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  ChildDevicePath,\r
+                  &gEfiHiiConfigAccessProtocolGuid,\r
+                  ConfigAccess,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  PrivateData->DriverHandle = DriverHandle;\r
+\r
+  //\r
+  // Publish the HII package list\r
+  //\r
+  HiiHandle = HiiAddPackages (\r
+                &mVlanFormSetGuid,\r
+                DriverHandle,\r
+                VlanConfigDxeStrings,\r
+                VlanConfigBin,\r
+                NULL\r
+                );\r
+  if (HiiHandle == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  PrivateData->HiiHandle = HiiHandle;\r
+\r
+  //\r
+  // Update formset title\r
+  //\r
+  MacString = NULL;\r
+  Status = NetLibGetMacString (PrivateData->ControllerHandle, PrivateData->ImageHandle, &MacString);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  PrivateData->MacString = MacString;\r
+\r
+  StrCpy (Str, L"VLAN Configuration (MAC:");\r
+  StrCat (Str, MacString);\r
+  StrCat (Str, L")");\r
+  HiiSetString (\r
+    HiiHandle,\r
+    STRING_TOKEN (STR_VLAN_FORM_SET_TITLE),\r
+    Str,\r
+    NULL\r
+    );\r
+\r
+  //\r
+  // Update form title\r
+  //\r
+  HiiSetString (\r
+    HiiHandle,\r
+    STRING_TOKEN (STR_VLAN_FORM_TITLE),\r
+    Str,\r
+    NULL\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function remove the VLAN configuration Form for a network device. The\r
+  child handle for HII Config Access protocol will be destroyed.\r
+\r
+  @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
+\r
+**/\r
+VOID\r
+UninstallVlanConfigForm (\r
+  IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
+  )\r
+{\r
+  //\r
+  // Free MAC string\r
+  //\r
+  if (PrivateData->MacString != NULL) {\r
+    FreePool (PrivateData->MacString);\r
+    PrivateData->MacString = NULL;\r
+  }\r
+\r
+  //\r
+  // Uninstall HII package list\r
+  //\r
+  if (PrivateData->HiiHandle != NULL) {\r
+    HiiRemovePackages (PrivateData->HiiHandle);\r
+    PrivateData->HiiHandle = NULL;\r
+  }\r
+\r
+  //\r
+  // Uninstall HII Config Access Protocol\r
+  //\r
+  if (PrivateData->DriverHandle != NULL) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+           PrivateData->DriverHandle,\r
+           &gEfiDevicePathProtocolGuid,\r
+           PrivateData->ChildDevicePath,\r
+           &gEfiHiiConfigAccessProtocolGuid,\r
+           &PrivateData->ConfigAccess,\r
+           NULL\r
+           );\r
+    PrivateData->DriverHandle = NULL;\r
+\r
+    if (PrivateData->ChildDevicePath != NULL) {\r
+      FreePool (PrivateData->ChildDevicePath);\r
+      PrivateData->ChildDevicePath = NULL;\r
+    }\r
+  }\r
+}\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.h b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.h
new file mode 100644 (file)
index 0000000..00fcdce
--- /dev/null
@@ -0,0 +1,385 @@
+/** @file\r
+  Header file for driver binding protocol and HII config access protocol.\r
+\r
+Copyright (c) 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
+\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
+**/\r
+\r
+#ifndef __VLAN_CONFIG_IMPL_H__\r
+#define __VLAN_CONFIG_IMPL_H__\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/ComponentName2.h>\r
+#include <Protocol/HiiConfigAccess.h>\r
+#include <Protocol/HiiConfigRouting.h>\r
+#include <Protocol/VlanConfig.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/NetLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/PrintLib.h>\r
+\r
+#include <Guid/MdeModuleHii.h>\r
+\r
+#include "VlanConfigNvData.h"\r
+\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gVlanConfigComponentName2;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gVlanConfigComponentName;\r
+\r
+//\r
+// Tool generated IFR binary data and String package data\r
+//\r
+extern UINT8                        VlanConfigBin[];\r
+extern UINT8                        VlanConfigDxeStrings[];\r
+\r
+#define VLAN_LIST_VAR_OFFSET ((UINT16) OFFSET_OF (VLAN_CONFIGURATION, VlanList))\r
+\r
+typedef struct {\r
+  UINTN                           Signature;\r
+\r
+  EFI_HII_CONFIG_ACCESS_PROTOCOL  ConfigAccess;\r
+  EFI_HII_HANDLE                  HiiHandle;\r
+  EFI_HANDLE                      DriverHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL        *ChildDevicePath;\r
+\r
+  EFI_HANDLE                      ControllerHandle;\r
+  EFI_HANDLE                      ImageHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL        *ParentDevicePath;\r
+  EFI_VLAN_CONFIG_PROTOCOL        *VlanConfig;\r
+  CHAR16                          *MacString;\r
+\r
+  UINT16                          NumberOfVlan;\r
+  UINT16                          VlanId[MAX_VLAN_NUMBER];\r
+} VLAN_CONFIG_PRIVATE_DATA;\r
+\r
+#define VLAN_CONFIG_PRIVATE_DATA_SIGNATURE     SIGNATURE_32 ('V', 'C', 'P', 'D')\r
+#define VLAN_CONFIG_PRIVATE_DATA_FROM_THIS(a)  CR (a, VLAN_CONFIG_PRIVATE_DATA, ConfigAccess, VLAN_CONFIG_PRIVATE_DATA_SIGNATURE)\r
+\r
+extern VLAN_CONFIG_PRIVATE_DATA mVlanConfigPrivateDateTemplate;\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigComponentNameGetDriverName (\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **DriverName\r
+  );\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigComponentNameGetControllerName (\r
+  IN     EFI_COMPONENT_NAME_PROTOCOL   *This,\r
+  IN     EFI_HANDLE                    ControllerHandle,\r
+  IN     EFI_HANDLE                    ChildHandle OPTIONAL,\r
+  IN     CHAR8                         *Language,\r
+     OUT CHAR16                        **ControllerName\r
+  );\r
+\r
+/**\r
+  Test to see if this driver supports ControllerHandle.\r
+\r
+  @param[in]  This                 Protocol instance pointer.\r
+  @param[in]  ControllerHandle     Handle of device to test\r
+  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                                   device to start.\r
+\r
+  @retval EFI_SUCCES           This driver supports this device\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on this device\r
+  @retval other                This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
+  );\r
+\r
+/**\r
+  Start this driver on ControllerHandle.\r
+\r
+  @param[in]  This                 Protocol instance pointer.\r
+  @param[in]  ControllerHandle     Handle of device to bind driver to\r
+  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                                   device to start.\r
+\r
+  @retval EFI_SUCCES           This driver is added to ControllerHandle\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
+  @retval other                This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath OPTIONAL\r
+  );\r
+\r
+/**\r
+  Stop this driver on ControllerHandle.\r
+\r
+  @param[in]  This                 Protocol instance pointer.\r
+  @param[in]  ControllerHandle     Handle of device to stop driver on\r
+  @param[in]  NumberOfChildren     Number of Handles in ChildHandleBuffer. If number\r
+                                   of children is zero stop the entire bus driver.\r
+  @param[in]  ChildHandleBuffer    List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCES           This driver is removed ControllerHandle\r
+  @retval other                This driver was not removed from this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanConfigDriverBindingStop (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN EFI_HANDLE                      ControllerHandle,\r
+  IN UINTN                           NumberOfChildren,\r
+  IN EFI_HANDLE                      *ChildHandleBuffer\r
+  );\r
+\r
+/**\r
+  This function update VLAN list in the VLAN configuration Form.\r
+\r
+  @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
+\r
+**/\r
+VOID\r
+VlanUpdateForm (\r
+  IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
+  );\r
+\r
+/**\r
+  This function publish the VLAN configuration Form for a network device. The\r
+  HII Config Access protocol will be installed on a child handle of the network\r
+  device.\r
+\r
+  @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
+\r
+  @retval EFI_SUCCESS            HII Form is installed for this network device.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough resource for HII Form installation.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+InstallVlanConfigForm (\r
+  IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
+  );\r
+\r
+/**\r
+  This function remove the VLAN configuration Form for a network device. The\r
+  child handle for HII Config Access protocol will be destroyed.\r
+\r
+  @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
+\r
+**/\r
+VOID\r
+UninstallVlanConfigForm (\r
+  IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
+  );\r
+\r
+/**\r
+  This function allows a caller to extract the current configuration for one\r
+  or more named elements from the target driver.\r
+\r
+  @param[in]  This               Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param[in]  Request            A null-terminated Unicode string in\r
+                                 <ConfigRequest> format.\r
+  @param[out]  Progress          On return, points to a character in the Request\r
+                                 string. Points to the string's null terminator if\r
+                                 request was successful. Points to the most recent\r
+                                 '&' before the first failing name/value pair (or\r
+                                 the beginning of the string if the failure is in\r
+                                 the first name/value pair) if the request was not\r
+                                 successful.\r
+  @param[out]  Results           A null-terminated Unicode string in\r
+                                 <ConfigAltResp> format which has all values filled\r
+                                 in for the names in the Request string. String to\r
+                                 be allocated by the called function.\r
+\r
+  @retval EFI_SUCCESS            The Results is filled with the requested values.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough memory to store the results.\r
+  @retval EFI_INVALID_PARAMETER  Request is NULL, illegal syntax, or unknown name.\r
+  @retval EFI_NOT_FOUND          Routing data doesn't match any storage in this\r
+                                 driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanExtractConfig (\r
+  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL        *This,\r
+  IN CONST EFI_STRING                            Request,\r
+       OUT EFI_STRING                            *Progress,\r
+       OUT EFI_STRING                            *Results\r
+  );\r
+\r
+/**\r
+  This function processes the results of changes in configuration.\r
+\r
+  @param[in]  This               Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param[in]  Configuration      A null-terminated Unicode string in <ConfigResp>\r
+                                 format.\r
+  @param[out]  Progress          A pointer to a string filled in with the offset of\r
+                                 the most recent '&' before the first failing\r
+                                 name/value pair (or the beginning of the string if\r
+                                 the failure is in the first name/value pair) or\r
+                                 the terminating NULL if all was successful.\r
+\r
+  @retval EFI_SUCCESS            The Results is processed successfully.\r
+  @retval EFI_INVALID_PARAMETER  Configuration is NULL.\r
+  @retval EFI_NOT_FOUND          Routing data doesn't match any storage in this\r
+                                 driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanRouteConfig (\r
+  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL      *This,\r
+  IN CONST EFI_STRING                          Configuration,\r
+       OUT EFI_STRING                          *Progress\r
+  );\r
+\r
+/**\r
+  This function processes the results of changes in configuration.\r
+\r
+  @param[in]  This               Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param[in]  Action             Specifies the type of action taken by the browser.\r
+  @param[in]  QuestionId         A unique value which is sent to the original\r
+                                 exporting driver so that it can identify the type\r
+                                 of data to expect.\r
+  @param[in]  Type               The type of value for the question.\r
+  @param[in]  Value              A pointer to the data being sent to the original\r
+                                 exporting driver.\r
+  @param[out] ActionRequest      On return, points to the action requested by the\r
+                                 callback function.\r
+\r
+  @retval EFI_SUCCESS            The callback successfully handled the action.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the\r
+                                 variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be saved.\r
+  @retval EFI_UNSUPPORTED        The specified Action is not supported by the\r
+                                 callback.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VlanCallback (\r
+  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL      *This,\r
+  IN     EFI_BROWSER_ACTION                    Action,\r
+  IN     EFI_QUESTION_ID                       QuestionId,\r
+  IN     UINT8                                 Type,\r
+  IN     EFI_IFR_TYPE_VALUE                    *Value,\r
+     OUT EFI_BROWSER_ACTION_REQUEST            *ActionRequest\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigNvData.h b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigNvData.h
new file mode 100644 (file)
index 0000000..7de3af0
--- /dev/null
@@ -0,0 +1,50 @@
+/** @file\r
+  Header file for NV data structure definition.\r
+\r
+Copyright (c) 2009, Intel Corporation.<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The full\r
+text of the license may be found at<BR>\r
+http://opensource.org/licenses/bsd-license.php\r
+\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
+**/\r
+\r
+#ifndef __VLAN_CONFIG_NV_DATA_H__\r
+#define __VLAN_CONFIG_NV_DATA_H__\r
+\r
+#include <Guid/HiiPlatformSetupFormset.h>\r
+\r
+\r
+#define VLAN_CONFIG_PRIVATE_GUID \\r
+  { \\r
+    0xd79df6b0, 0xef44, 0x43bd, {0x97, 0x97, 0x43, 0xe9, 0x3b, 0xcf, 0x5f, 0xa8 } \\r
+  }\r
+\r
+#define VLAN_CONFIGURATION_VARSTORE_ID  0x0001\r
+#define VLAN_CONFIGURATION_FORM_ID      0x0001\r
+\r
+#define VLAN_ADD_QUESTION_ID            0x1000\r
+#define VLAN_REMOVE_QUESTION_ID         0x2000\r
+\r
+#define LABEL_VLAN_LIST                 0x0001\r
+#define LABEL_END                       0xffff\r
+\r
+//\r
+// The maximum number of VLAN that will be displayed on the menu\r
+//\r
+#define MAX_VLAN_NUMBER                 100\r
+\r
+//\r
+// Nv Data structure referenced by IFR\r
+//\r
+typedef struct {\r
+  UINT16  VlanId;\r
+  UINT8   Priority;\r
+  UINT8   VlanList[MAX_VLAN_NUMBER];\r
+} VLAN_CONFIGURATION;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigStrings.uni b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigStrings.uni
new file mode 100644 (file)
index 0000000..51e7dd8
Binary files /dev/null and b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigStrings.uni differ