Add VLAN support.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9649 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
xdu2 2009-12-30 13:47:55 +00:00
parent 1204fe8319
commit 779ae35798
30 changed files with 4310 additions and 944 deletions

View File

@ -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.
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.
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.
@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
@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.
@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] 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
);

View File

@ -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;
}
/**
Convert the mac address of the simple network protocol installed on
SnpHandle to a unicode string. Callers are responsible for freeing the
string storage.
Retrieve VLAN ID of a VLAN device handle.
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.
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.
@param[in] SnpHandle The handle where the simple network protocol is
@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;
}
/**
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;
}
//
// 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;
}
/**
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;
}

View File

@ -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

View File

@ -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.

View File

@ -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 {

View File

@ -246,31 +246,6 @@ IScsiGetNICPciLocation (
return (UINT16) ((Bus << 8) | (Device << 3) | Function);
}
/**
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.
@ -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.

View File

@ -355,16 +355,19 @@ IScsiAsciiStrToIp (
@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.

View File

@ -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
@ -117,12 +117,14 @@ IScsiUnicodeStrToAsciiStr (
@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
);

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -1,10 +1,11 @@
/** @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
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,
@ -12,10 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "MnpDriver.h"
//
// EFI Component Name Protocol
//
@ -34,7 +33,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2 =
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
{
"eng;en",

View File

@ -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,
@ -68,7 +69,6 @@ MnpComponentNameGetDriverName (
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
/** @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
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,
@ -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,
@ -54,21 +55,6 @@ MnpDriverBindingSupported (
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.
//
@ -80,7 +66,6 @@ MnpDriverBindingSupported (
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
@ -127,51 +112,133 @@ MnpDriverBindingStart (
{
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
);
ErrorExit:
if (EFI_ERROR (Status)) {
if (MnpInitialized) {
//
// Flush the Mnp Service Data.
//
MnpFlushServiceData (MnpServiceData, This->DriverBindingHandle);
goto Exit;
}
FreePool (MnpServiceData);
//
// 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);
}
//
// Uninstall the VLAN Config Protocol if any
//
if (MnpDeviceData->VlanConfig.Set != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
MnpDeviceData->ControllerHandle,
&gEfiVlanConfigProtocolGuid,
&MnpDeviceData->VlanConfig,
NULL
);
}
//
// Destroy Mnp Device Data
//
MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);
FreePool (MnpDeviceData);
}
return Status;
@ -206,11 +273,14 @@ MnpDriverBindingStop (
{
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)) {
DEBUG (
(EFI_D_ERROR,
"MnpDriverBindingStop: Locate MNP Service Binding Protocol failed, %r.\n",
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;
}
MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (VlanConfig);
} else {
MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);
MnpDeviceData = MnpServiceData->MnpDeviceData;
}
if (NumberOfChildren == 0) {
//
// Uninstall the MNP Service Binding Protocol.
// Destroy all MNP service data
//
while (!IsListEmpty (&MnpDeviceData->ServiceList)) {
Entry = GetFirstNode (&MnpDeviceData->ServiceList);
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
MnpDestroyServiceData (MnpServiceData);
}
//
// Uninstall the VLAN Config Protocol if any
//
if (MnpDeviceData->VlanConfig.Set != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
ControllerHandle,
&gEfiManagedNetworkServiceBindingProtocolGuid,
ServiceBinding,
MnpDeviceData->ControllerHandle,
&gEfiVlanConfigProtocolGuid,
&MnpDeviceData->VlanConfig,
NULL
);
}
//
// Flush the Mnp service data.
// Destroy the Mnp device data
//
MnpFlushServiceData (MnpServiceData, This->DriverBindingHandle);
MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);
FreePool (MnpDeviceData);
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
);
return EFI_SUCCESS;
}
ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
//
// 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;
}
@ -295,11 +391,10 @@ MnpServiceBindingCreateChild (
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
@ -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",

View File

@ -1,10 +1,11 @@
/** @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
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,
@ -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

View File

@ -1,16 +1,17 @@
/** @file
Component description file for Mnp module.
## @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.
#
##
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.
**/
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MnpDxe
@ -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

View File

@ -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.
@ -110,16 +162,46 @@ MnpInitializeServiceData (
);
/**
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
);
/**
@ -321,7 +403,7 @@ MnpRecycleRxData (
/**
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,15 +413,15 @@ 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
operation is failed.
@ -347,19 +429,19 @@ MnpReceivePacket (
**/
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
);
@ -422,7 +504,7 @@ EFI_STATUS
EFIAPI
MnpGetModeData (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
);
@ -744,7 +826,7 @@ MnpPoll (
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
@ -753,7 +835,7 @@ MnpPoll (
**/
EFI_STATUS
MnpConfigReceiveFilters (
IN MNP_SERVICE_DATA *MnpServiceData
IN MNP_DEVICE_DATA *MnpDeviceData
);
#endif

View File

@ -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.
@ -123,7 +125,9 @@ MnpBuildTxPacket (
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;
}
}
@ -197,8 +201,11 @@ MnpSyncSendPacket (
EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData;
UINT32 HeaderSize;
UINT8 *TxBuf;
MNP_DEVICE_DATA *MnpDeviceData;
UINT16 ProtocolType;
Snp = MnpServiceData->Snp;
MnpDeviceData = MnpServiceData->MnpDeviceData;
Snp = MnpDeviceData->Snp;
TxData = Token->Packet.TxData;
HeaderSize = Snp->Mode->MediaHeaderSize - TxData->HeaderLength;
@ -207,15 +214,19 @@ MnpSyncSendPacket (
// 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:
@ -304,15 +312,15 @@ MnpInstanceDeliverPacket (
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.
@ -426,7 +434,7 @@ MnpRecycleRxData (
)
{
MNP_RXDATA_WRAP *RxDataWrap;
MNP_SERVICE_DATA *MnpServiceData;
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;
//
@ -615,10 +623,12 @@ MnpAnalysePacket (
)
{
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.
//
@ -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;
}
@ -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;
}
@ -985,16 +1010,21 @@ MnpCheckPacketTimeout (
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 (ServiceEntry, &MnpDeviceData->ServiceList) {
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (ServiceEntry);
NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
@ -1019,7 +1049,6 @@ MnpCheckPacketTimeout (
// TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.
//
if (RxDataWrap->TimeoutTick >= (MNP_TIMEOUT_CHECK_INTERVAL / 10)) {
RxDataWrap->TimeoutTick -= (MNP_TIMEOUT_CHECK_INTERVAL / 10);
} else {
//
@ -1033,9 +1062,9 @@ MnpCheckPacketTimeout (
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.
@ -1051,15 +1080,15 @@ MnpSystemPoll (
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.

View File

@ -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,
@ -43,7 +44,7 @@ EFI_STATUS
EFIAPI
MnpGetModeData (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
)
{
@ -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));
}
@ -154,8 +154,8 @@ MnpConfigure (
if ((This == NULL) ||
((MnpConfigData != NULL) &&
(MnpConfigData->ProtocolTypeFilter > 0) &&
(MnpConfigData->ProtocolTypeFilter <= 1500))) {
(MnpConfigData->ProtocolTypeFilter <= 1500))
) {
return EFI_INVALID_PARAMETER;
}
@ -229,7 +229,6 @@ MnpMcastIpToMac (
EFI_IPv6_ADDRESS *Ip6Address;
if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -254,7 +253,7 @@ MnpMcastIpToMac (
goto ON_EXIT;
}
Snp = Instance->MnpServiceData->Snp;
Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
ASSERT (Snp != NULL);
ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));
@ -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;
}
@ -520,7 +518,6 @@ MnpTransmit (
EFI_TPL OldTpl;
if ((This == NULL) || (Token == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -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.
@ -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;
}
@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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