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