/** @file\r
VLAN Config Protocol implementation and VLAN packet process routine.\r
\r
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
-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
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
VlanTci->Uint16 = HTONS (VlanTci->Uint16);\r
}\r
\r
+/**\r
+ Check VLAN configuration variable and delete the duplicative content if has identical Vlan ID.\r
+\r
+ @param[in] MnpDeviceData Pointer to the MNP device context data.\r
+ @param[in] Buffer Pointer to the buffer contains the array of VLAN_TCI.\r
+ @param[in] NumberOfVlan Pointer to number of VLAN.\r
+ @param[out] NewNumberOfVlan Pointer to number of unique VLAN.\r
+\r
+ @retval EFI_SUCCESS The VLAN variable is successfully checked.\r
+ @retval EFI_OUT_OF_RESOURCES There is not enough resource to set the configuration.\r
+\r
+**/\r
+EFI_STATUS\r
+MnpCheckVlanVariable (\r
+ IN MNP_DEVICE_DATA *MnpDeviceData,\r
+ IN VLAN_TCI *Buffer,\r
+ IN UINTN NumberOfVlan,\r
+ OUT UINTN *NewNumberOfVlan\r
+ )\r
+{\r
+ UINTN Index;\r
+ UINTN Index2;\r
+ UINTN Count;\r
+ BOOLEAN FoundDuplicateItem;\r
+ EFI_STATUS Status;\r
+\r
+ Count = 0;\r
+ FoundDuplicateItem = FALSE;\r
+ Status = EFI_SUCCESS;\r
+\r
+ for (Index = 0; Index < NumberOfVlan; Index++) {\r
+ for (Index2 = Index + 1; Index2 < NumberOfVlan; Index2++) {\r
+ if (Buffer[Index].Bits.Vid == Buffer[Index2].Bits.Vid) {\r
+ FoundDuplicateItem = TRUE;\r
+ Count++;\r
+ break;\r
+ }\r
+ }\r
+ if (FoundDuplicateItem) {\r
+ for (Index2 = Index +1; Index2 < NumberOfVlan; Index++, Index2++) {\r
+ CopyMem (Buffer + Index, Buffer + Index2, sizeof (VLAN_TCI));\r
+ }\r
+ }\r
+ FoundDuplicateItem = FALSE;\r
+ }\r
+\r
+ *NewNumberOfVlan = NumberOfVlan - Count;\r
+ if (Count != 0) {\r
+ Status = MnpSetVlanVariable (MnpDeviceData, *NewNumberOfVlan, Buffer);\r
+ }\r
+\r
+ return Status;\r
+}\r
\r
/**\r
Get VLAN configuration variable.\r
UINTN BufferSize;\r
EFI_STATUS Status;\r
VLAN_TCI *Buffer;\r
+ UINTN NewNumberOfVlan;\r
\r
//\r
// Get VLAN configuration from EFI Variable\r
return Status;\r
}\r
\r
- *NumberOfVlan = BufferSize / sizeof (VLAN_TCI);\r
- *VlanVariable = Buffer;\r
+ Status = MnpCheckVlanVariable (MnpDeviceData, Buffer, BufferSize / sizeof (VLAN_TCI), &NewNumberOfVlan);\r
+ if (!EFI_ERROR (Status)) {\r
+ *NumberOfVlan = NewNumberOfVlan;\r
+ *VlanVariable = Buffer;\r
+ }\r
\r
return Status;\r
}\r
\r
-\r
/**\r
Set VLAN configuration variable.\r
\r