/** @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
+Copyright (c) 2009 - 2018, 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
\r
\r
/**\r
- Build the packet to transmit from the TxData passed in.\r
+ Build the vlan 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
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
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
return gRT->SetVariable (\r
MnpDeviceData->MacString,\r
&gEfiVlanConfigProtocolGuid,\r
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
NumberOfVlan * sizeof (VLAN_TCI),\r
VlanVariable\r
);\r