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_ETHER_ADDR_LEN 6
#define NET_IFTYPE_ETHERNET 0x01 #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_UDP 0x11
#define EFI_IP_PROTO_TCP 0x06 #define EFI_IP_PROTO_TCP 0x06
#define EFI_IP_PROTO_ICMP 0x01 #define EFI_IP_PROTO_ICMP 0x01
@ -67,6 +70,20 @@ typedef struct {
UINT16 EtherType; UINT16 EtherType;
} ETHER_HEAD; } 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 // 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 Get handle with Simple Network Protocol installed on it.
SnpHandle to a unicode string. Callers are responsible for freeing the
string storage.
Get the mac address of the Simple Network protocol from the SnpHandle. Then convert There should be MNP Service Binding Protocol installed on the input ServiceHandle.
the mac address into a unicode string. It takes 2 unicode characters to represent If Simple Network Protocol is already installed on the ServiceHandle, the
a 1 byte binary buffer, plus one unicode character for the null terminator. 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 @return The SNP handle, or NULL if not found.
installed.
@param[in] ImageHandle The image handle to act as the agent handle to **/
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. get the simple network protocol.
@param[out] MacString The pointer to store the address of the string @param[out] MacString The pointer to store the address of the string
representation of the mac address. representation of the mac address.
@ -984,7 +1087,7 @@ NetLibDestroyServiceChild (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
NetLibGetMacString ( NetLibGetMacString (
IN EFI_HANDLE SnpHandle, IN EFI_HANDLE ServiceHandle,
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
OUT CHAR16 **MacString OUT CHAR16 **MacString
); );

View File

@ -111,6 +111,21 @@ GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mMonthName[] = {
"Dec" "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 Locate the handles that support SNP, then open one of them
to send the syslog packets. The caller isn't required to close to send the syslog packets. The caller isn't required to close
@ -1772,18 +1787,289 @@ NetLibDestroyServiceChild (
return Status; 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 Retrieve VLAN ID of a VLAN device handle.
SnpHandle to a unicode string. Callers are responsible for freeing the
string storage.
Get the mac address of the Simple Network protocol from the SnpHandle. Then convert Search VLAN device path node in Device Path of specified ServiceHandle and
the mac address into a unicode string. It takes 2 unicode characters to represent return its VLAN ID. If no VLAN device path node found, then this ServiceHandle
a 1 byte binary buffer. Plus one unicode character for the null-terminator. 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. installed on.
@param[in] ImageHandle The image handle used to act as the agent handle to @param[in] ImageHandle The image handle used to act as the agent handle to
get the simple network protocol. get the simple network protocol.
@ -1798,57 +2084,61 @@ NetLibDestroyServiceChild (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
NetLibGetMacString ( NetLibGetMacString (
IN EFI_HANDLE SnpHandle, IN EFI_HANDLE ServiceHandle,
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
OUT CHAR16 **MacString OUT CHAR16 **MacString
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp; EFI_MAC_ADDRESS MacAddress;
EFI_SIMPLE_NETWORK_MODE *Mode;
CHAR16 *MacAddress;
UINT8 *HwAddress; UINT8 *HwAddress;
UINTN HwAddressSize;
UINT16 VlanId;
CHAR16 *String;
UINTN Index; 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 ( Status = NetLibGetMacAddress (ServiceHandle, &MacAddress, &HwAddressSize);
SnpHandle,
&gEfiSimpleNetworkProtocolGuid,
(VOID **) &Snp,
ImageHandle,
SnpHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Mode = Snp->Mode;
// //
// It takes 2 unicode characters to represent a 1 byte binary buffer. // 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. // Plus one unicode character for the null-terminator.
// //
MacAddress = AllocatePool ((2 * Mode->HwAddressSize + 1) * sizeof (CHAR16)); String = AllocateZeroPool ((2 * HwAddressSize + 5 + 1) * sizeof (CHAR16));
if (MacAddress == NULL) { if (String == NULL) {
return EFI_OUT_OF_RESOURCES; 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; HwAddress = &MacAddress.Addr[0];
for (Index = 0; Index < Mode->HwAddressSize; Index++) { for (Index = 0; Index < HwAddressSize; Index++) {
MacAddress += UnicodeValueToString (MacAddress, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2); 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; return EFI_SUCCESS;
} }

View File

@ -306,6 +306,7 @@
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf
MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
MdeModulePkg/Universal/Network/SnpDxe/SnpDxe.inf MdeModulePkg/Universal/Network/SnpDxe/SnpDxe.inf
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

View File

@ -67,7 +67,7 @@ IScsiIpToStr (
/** /**
Update the list of iSCSI devices the iSCSI driver is controlling. Update the list of iSCSI devices the iSCSI driver is controlling.
@retval EFI_SUCCESS The callback successfully handled the action. @retval EFI_SUCCESS The callback successfully handled the action.
@retval Others Other errors as indicated. @retval Others Other errors as indicated.
**/ **/
@ -84,19 +84,20 @@ IScsiUpdateDeviceList (
UINTN HandleIndex; UINTN HandleIndex;
UINTN Index; UINTN Index;
UINTN LastDeviceIndex; UINTN LastDeviceIndex;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp; EFI_MAC_ADDRESS MacAddress;
EFI_SIMPLE_NETWORK_MODE *Mode; UINTN HwAddressSize;
UINT16 VlanId;
ISCSI_MAC_INFO *CurMacInfo; ISCSI_MAC_INFO *CurMacInfo;
ISCSI_MAC_INFO TempMacInfo; ISCSI_MAC_INFO TempMacInfo;
CHAR16 MacString[65]; CHAR16 MacString[70];
UINTN DeviceListSize; 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 ( Status = gBS->LocateHandleBuffer (
ByProtocol, ByProtocol,
&gEfiSimpleNetworkProtocolGuid, &gEfiManagedNetworkServiceBindingProtocolGuid,
NULL, NULL,
&NumHandles, &NumHandles,
&Handles &Handles
@ -127,14 +128,15 @@ IScsiUpdateDeviceList (
LastDeviceIndex = 0; LastDeviceIndex = 0;
for (HandleIndex = 0; HandleIndex < NumHandles; HandleIndex++) { for (HandleIndex = 0; HandleIndex < NumHandles; HandleIndex++) {
gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp); Status = NetLibGetMacAddress (Handles[HandleIndex], &MacAddress, &HwAddressSize);
ASSERT (Status == EFI_SUCCESS);
Mode = Snp->Mode; VlanId = NetLibGetVlanId (Handles[HandleIndex]);
for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) { for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) {
CurMacInfo = &DeviceList->MacInfo[Index]; CurMacInfo = &DeviceList->MacInfo[Index];
if ((CurMacInfo->Len == Mode->HwAddressSize) && if ((CurMacInfo->Len == HwAddressSize) &&
(NET_MAC_EQUAL (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize)) (CurMacInfo->VlanId == VlanId) &&
(NET_MAC_EQUAL (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize))
) { ) {
// //
// The previous configured NIC is still here. // The previous configured NIC is still here.
@ -163,7 +165,7 @@ IScsiUpdateDeviceList (
// delete the variables // delete the variables
// //
CurMacInfo = &DeviceList->MacInfo[Index]; 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, &gEfiIScsiInitiatorNameProtocolGuid, 0, 0, NULL);
gRT->SetVariable (MacString, &mIScsiCHAPAuthInfoGuid, 0, 0, NULL); gRT->SetVariable (MacString, &mIScsiCHAPAuthInfoGuid, 0, 0, NULL);
} }
@ -181,12 +183,12 @@ IScsiUpdateDeviceList (
DeviceList->NumDevice = (UINT8) NumHandles; DeviceList->NumDevice = (UINT8) NumHandles;
for (Index = 0; Index < NumHandles; Index++) { for (Index = 0; Index < NumHandles; Index++) {
gBS->HandleProtocol (Handles[Index], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp); NetLibGetMacAddress (Handles[Index], &MacAddress, &HwAddressSize);
Mode = Snp->Mode;
CurMacInfo = &DeviceList->MacInfo[Index]; CurMacInfo = &DeviceList->MacInfo[Index];
CopyMem (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize); CopyMem (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize);
CurMacInfo->Len = (UINT8) Mode->HwAddressSize; CurMacInfo->Len = (UINT8) HwAddressSize;
CurMacInfo->VlanId = NetLibGetVlanId (Handles[Index]);
} }
gRT->SetVariable ( gRT->SetVariable (
@ -776,7 +778,9 @@ IScsiConfigUpdateForm (
ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry; ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry;
BOOLEAN EntryExisted; BOOLEAN EntryExisted;
EFI_STATUS Status; EFI_STATUS Status;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp; EFI_MAC_ADDRESS MacAddress;
UINTN HwAddressSize;
UINT16 VlanId;
CHAR16 PortString[128]; CHAR16 PortString[128];
UINT16 FormIndex; UINT16 FormIndex;
UINTN BufferSize; UINTN BufferSize;
@ -813,17 +817,13 @@ IScsiConfigUpdateForm (
ConfigFormEntry->Controller = Controller; ConfigFormEntry->Controller = Controller;
// //
// Get the simple network protocol and convert the MAC address into // Get the MAC address and convert it into the formatted string.
// the formatted string.
// //
Status = gBS->HandleProtocol ( Status = NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize);
Controller,
&gEfiSimpleNetworkProtocolGuid,
(VOID **)&Snp
);
ASSERT (Status == EFI_SUCCESS); 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. // Get the normal session configuration data.

View File

@ -1,7 +1,7 @@
/** @file /** @file
The header file of IScsiConfig.c. 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 All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 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 { typedef struct _ISCSI_MAC_INFO {
EFI_MAC_ADDRESS Mac; EFI_MAC_ADDRESS Mac;
UINT8 Len; UINT8 Len;
UINT16 VlanId;
} ISCSI_MAC_INFO; } ISCSI_MAC_INFO;
typedef struct _ISCSI_DEVICE_LIST { typedef struct _ISCSI_DEVICE_LIST {

View File

@ -246,31 +246,6 @@ IScsiGetNICPciLocation (
return (UINT16) ((Bus << 8) | (Device << 3) | Function); 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. Fill the NIC and target sections in iSCSI Boot Firmware Table.
@ -296,7 +271,8 @@ IScsiFillNICAndTargetSections (
UINT16 *SectionOffset; UINT16 *SectionOffset;
UINTN Index; UINTN Index;
UINT16 Length; UINT16 Length;
EFI_MAC_ADDRESS *Mac; EFI_MAC_ADDRESS MacAddress;
UINTN HwAddressSize;
ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier; ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
EFI_STATUS Status; EFI_STATUS Status;
@ -354,8 +330,11 @@ IScsiFillNICAndTargetSections (
IScsiMapV4ToV6Addr (&SessionConfigData->SecondaryDns, &Nic->SecondaryDns); IScsiMapV4ToV6Addr (&SessionConfigData->SecondaryDns, &Nic->SecondaryDns);
IScsiMapV4ToV6Addr (&SessionConfigData->DhcpServer, &Nic->DhcpServer); IScsiMapV4ToV6Addr (&SessionConfigData->DhcpServer, &Nic->DhcpServer);
Mac = IScsiGetMacAddress (DriverData->Controller); Nic->VLanTag = NetLibGetVlanId (DriverData->Controller);
CopyMem (Nic->Mac, Mac, sizeof (Nic->Mac));
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. // Get the PCI location of the Nic.

View File

@ -353,18 +353,21 @@ IScsiAsciiStrToIp (
/** /**
Convert the mac address into a hexadecimal encoded "-" seperated string. Convert the mac address into a hexadecimal encoded "-" seperated string.
@param[in] Mac The mac address. @param[in] Mac The mac address.
@param[in] Len Length in bytes of the mac address. @param[in] Len Length in bytes of the mac address.
@param[out] Str The storage to return the mac string. @param[in] VlanId VLAN ID of the network device.
@param[out] Str The storage to return the mac string.
**/ **/
VOID VOID
IScsiMacAddrToStr ( IScsiMacAddrToStr (
IN EFI_MAC_ADDRESS *Mac, IN EFI_MAC_ADDRESS *Mac,
IN UINT32 Len, IN UINT32 Len,
IN UINT16 VlanId,
OUT CHAR16 *Str OUT CHAR16 *Str
) )
{ {
UINT32 Index; UINT32 Index;
CHAR16 *String;
for (Index = 0; Index < Len; Index++) { for (Index = 0; Index < Len; Index++) {
Str[3 * Index] = (CHAR16) IScsiHexString[(Mac->Addr[Index] >> 4) & 0x0F]; Str[3 * Index] = (CHAR16) IScsiHexString[(Mac->Addr[Index] >> 4) & 0x0F];
@ -372,7 +375,12 @@ IScsiMacAddrToStr (
Str[3 * Index + 2] = L'-'; 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; EFI_STATUS Status;
ISCSI_SESSION *Session; ISCSI_SESSION *Session;
UINTN BufferSize; UINTN BufferSize;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp; EFI_MAC_ADDRESS MacAddress;
EFI_SIMPLE_NETWORK_MODE *Mode; UINTN HwAddressSize;
CHAR16 MacString[65]; UINT16 VlanId;
CHAR16 MacString[70];
// //
// get the iSCSI Initiator Name // get the iSCSI Initiator Name
@ -643,21 +652,13 @@ IScsiGetConfigData (
return Status; 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 // 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. // Get the normal configuration.

View File

@ -1,7 +1,7 @@
/** @file /** @file
Miscellaneous definitions for iSCSI driver. 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 All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
@ -115,14 +115,16 @@ IScsiUnicodeStrToAsciiStr (
/** /**
Convert the mac address into a hexadecimal encoded "-" seperated string. Convert the mac address into a hexadecimal encoded "-" seperated string.
@param[in] Mac The mac address. @param[in] Mac The mac address.
@param[in] Len Length in bytes of the mac address. @param[in] Len Length in bytes of the mac address.
@param[out] Str The storage to return the mac string. @param[in] VlanId VLAN ID of the network device.
@param[out] Str The storage to return the mac string.
**/ **/
VOID VOID
IScsiMacAddrToStr ( IScsiMacAddrToStr (
IN EFI_MAC_ADDRESS *Mac, IN EFI_MAC_ADDRESS *Mac,
IN UINT32 Len, IN UINT32 Len,
IN UINT16 VlanId,
OUT CHAR16 *Str OUT CHAR16 *Str
); );

View File

@ -89,7 +89,7 @@ typedef struct _IP4_CONFIG_FORM_ENTRY {
LIST_ENTRY Link; LIST_ENTRY Link;
IP4_CONFIG_INSTANCE *Ip4ConfigInstance; IP4_CONFIG_INSTANCE *Ip4ConfigInstance;
EFI_HANDLE Controller; EFI_HANDLE Controller;
CHAR16 MacString[95]; CHAR16 *MacString;
EFI_STRING_ID PortTitleToken; EFI_STRING_ID PortTitleToken;
EFI_STRING_ID PortTitleHelpToken; EFI_STRING_ID PortTitleHelpToken;
IP4_CONFIG_SESSION_DATA SessionConfigData; IP4_CONFIG_SESSION_DATA SessionConfigData;

View File

@ -970,7 +970,6 @@ Ip4ConfigUpdateForm (
IP4CONFIG_FORM_ENTRY *ConfigFormEntry; IP4CONFIG_FORM_ENTRY *ConfigFormEntry;
BOOLEAN EntryExisted; BOOLEAN EntryExisted;
EFI_STATUS Status; EFI_STATUS Status;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
CHAR16 PortString[128]; CHAR16 PortString[128];
UINT16 FormIndex; UINT16 FormIndex;
VOID *StartOpCodeHandle; VOID *StartOpCodeHandle;
@ -1006,19 +1005,9 @@ Ip4ConfigUpdateForm (
InitializeListHead (&ConfigFormEntry->Link); InitializeListHead (&ConfigFormEntry->Link);
ConfigFormEntry->Controller = Instance->Controller; ConfigFormEntry->Controller = Instance->Controller;
// Status = NetLibGetMacString (Instance->Controller, Instance->Image, &ConfigFormEntry->MacString);
// Get the simple network protocol and convert the MAC address into
// the formatted string.
//
Status = gBS->HandleProtocol (
Instance->Controller,
&gEfiSimpleNetworkProtocolGuid,
(VOID **)&Snp
);
ASSERT (Status == EFI_SUCCESS); ASSERT (Status == EFI_SUCCESS);
Ip4MacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);
// //
// Compose the Port string and create a new EFI_STRING_ID. // Compose the Port string and create a new EFI_STRING_ID.
// //
@ -1039,6 +1028,7 @@ Ip4ConfigUpdateForm (
mNumberOfIp4Devices--; mNumberOfIp4Devices--;
RemoveEntryList (&ConfigFormEntry->Link); RemoveEntryList (&ConfigFormEntry->Link);
FreePool (ConfigFormEntry->MacString);
FreePool (ConfigFormEntry); FreePool (ConfigFormEntry);
} }

View File

@ -291,6 +291,12 @@ Ip4CreateService (
InsertHeadList (&IpSb->Interfaces, &IpSb->DefaultInterface->Link); InsertHeadList (&IpSb->Interfaces, &IpSb->DefaultInterface->Link);
IpSb->MaxPacketSize = IpSb->SnpMode.MaxPacketSize - sizeof (IP4_HEAD); 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; IpSb->MacString = NULL;
*Service = IpSb; *Service = IpSb;

View File

@ -1,25 +1,24 @@
/** @file /** @file
UEFI Component Name(2) protocol implementation for MnpDxe driver. UEFI Component Name(2) protocol implementation for MnpDxe driver.
Copyright (c) 2005 - 2007, Intel Corporation. <BR> Copyright (c) 2005 - 2009, Intel Corporation.<BR>
All rights reserved. This program and the accompanying materials are licensed All rights reserved. This program and the accompanying materials
and made available under the terms and conditions of the BSD License which are licensed and made available under the terms and conditions
accompanies this distribution. The full text of the license may be found at of the BSD License which accompanies this distribution. The full
http://opensource.org/licenses/bsd-license.php 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, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "MnpDriver.h"
#include "MnpDriver.h"
// //
// EFI Component Name Protocol // EFI Component Name Protocol
// //
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName = {
MnpComponentNameGetDriverName, MnpComponentNameGetDriverName,
MnpComponentNameGetControllerName, MnpComponentNameGetControllerName,
"eng" "eng"
@ -28,14 +27,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName = {
// //
// EFI Component Name 2 Protocol // EFI Component Name 2 Protocol
// //
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2 = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) MnpComponentNameGetDriverName, (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) MnpComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) MnpComponentNameGetControllerName, (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) MnpComponentNameGetControllerName,
"en" "en"
}; };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
{ {
"eng;en", "eng;en",
L"MNP Network Service Driver" L"MNP Network Service Driver"
@ -88,9 +86,9 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpComponentNameGetDriverName ( MnpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
) )
{ {
return LookupUnicodeString2 ( return LookupUnicodeString2 (
@ -149,9 +147,9 @@ MnpComponentNameGetDriverName (
Language from the point of view of the driver Language from the point of view of the driver
specified by This. specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name @retval EFI_SUCCESS The Unicode string for the user readable name
specified by This, ControllerHandle, ChildHandle, specified by This, ControllerHandle, ChildHandle,
and Language was returned in ControllerName. and Language was returned in ControllerName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@ -173,11 +171,11 @@ MnpComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpComponentNameGetControllerName ( MnpComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
) )
{ {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;

View File

@ -1,10 +1,11 @@
/** @file /** @file
The header file of UEFI Component Name(2) protocol. 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 All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions
which accompanies this distribution. The full text of the license may be found at 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 http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
@ -18,8 +19,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/ComponentName.h> #include <Protocol/ComponentName.h>
#include <Protocol/ComponentName2.h> #include <Protocol/ComponentName2.h>
extern EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2; extern EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2;
extern EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName;
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -63,12 +64,11 @@ extern EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName;
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpComponentNameGetDriverName ( MnpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -116,9 +116,9 @@ MnpComponentNameGetDriverName (
Language from the point of view of the driver Language from the point of view of the driver
specified by This. specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name @retval EFI_SUCCESS The Unicode string for the user readable name
specified by This, ControllerHandle, ChildHandle, specified by This, ControllerHandle, ChildHandle,
and Language was returned in ControllerName. and Language was returned in ControllerName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@ -140,11 +140,11 @@ MnpComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpComponentNameGetControllerName ( MnpComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,12 @@
/** @file /** @file
Implementation of driver entry point and driver binding protocol. Implementation of driver entry point and driver binding protocol.
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 All rights reserved. This program and the accompanying materials
and made available under the terms and conditions of the BSD License which are licensed and made available under the terms and conditions
accompanies this distribution. The full text of the license may be found at of the BSD License which accompanies this distribution. The full
http://opensource.org/licenses/bsd-license.php 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, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -14,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "MnpDriver.h" #include "MnpDriver.h"
#include "MnpImpl.h" #include "MnpImpl.h"
#include "MnpVlan.h"
EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = { EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {
MnpDriverBindingSupported, MnpDriverBindingSupported,
@ -35,7 +36,7 @@ EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to test. @param[in] ControllerHandle Handle of device to test.
@param[in] RemainingDevicePath Optional parameter use to pick a specific @param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start. child device to start.
@retval EFI_SUCCESS This driver supports this device. @retval EFI_SUCCESS This driver supports this device.
@ -46,29 +47,14 @@ EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpDriverBindingSupported ( MnpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp; 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. // Test to open the Simple Network protocol BY_DRIVER.
// //
@ -80,7 +66,6 @@ MnpDriverBindingSupported (
ControllerHandle, ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER EFI_OPEN_PROTOCOL_BY_DRIVER
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -101,77 +86,159 @@ MnpDriverBindingSupported (
/** /**
Start this driver on ControllerHandle. This service is called by the Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make drivers as small EFI boot service ConnectController(). In order to make drivers as small
as possible, there are a few calling restrictions for this service. as possible, there are a few calling restrictions for this service.
ConnectController() must follow these calling restrictions. If any other ConnectController() must follow these calling restrictions. If any other
agent wishes to call Start() it must also follow these calling restrictions. agent wishes to call Start() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to. @param[in] ControllerHandle Handle of device to bind driver to.
@param[in] RemainingDevicePath Optional parameter use to pick a specific @param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start. child device to start.
@retval EFI_SUCCESS This driver is added to ControllerHandle. @retval EFI_SUCCESS This driver is added to ControllerHandle.
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle. @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data.
@retval Others This driver does not support this device. @retval Others This driver does not support this device.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpDriverBindingStart ( MnpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
MNP_SERVICE_DATA *MnpServiceData; 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) { // Initialize the Mnp Device Data
DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart(): Failed to allocate the Mnp Service Data.\n")); //
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; return EFI_OUT_OF_RESOURCES;
} }
// Status = MnpInitializeDeviceData (MnpDeviceData, This->DriverBindingHandle, ControllerHandle);
// Initialize the Mnp Service Data.
//
Status = MnpInitializeServiceData (MnpServiceData, This->DriverBindingHandle, ControllerHandle);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart: MnpInitializeDeviceData failed, %r.\n", Status));
DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart: MnpInitializeServiceData failed, %r.\n",Status)); FreePool (MnpDeviceData);
goto ErrorExit; 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 ( Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle, &ControllerHandle,
&gEfiManagedNetworkServiceBindingProtocolGuid, &gEfiVlanConfigProtocolGuid,
&MnpServiceData->ServiceBinding, &MnpDeviceData->VlanConfig,
NULL NULL
); );
if (EFI_ERROR (Status)) {
goto Exit;
}
ErrorExit: //
// Get current VLAN configuration from EFI Variable
//
NumberOfVlan = 0;
Status = MnpGetVlanVariable (MnpDeviceData, &NumberOfVlan, &VlanVariable);
if (EFI_ERROR (Status)) {
//
// No VLAN is set, create a default MNP service data for untagged frame
//
MnpDeviceData->NumberOfVlan = 0;
MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);
Status = (MnpServiceData != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
goto Exit;
}
//
// Create MNP service data for each VLAN
//
MnpDeviceData->NumberOfVlan = NumberOfVlan;
for (Index = 0; Index < NumberOfVlan; Index++) {
MnpServiceData = MnpCreateServiceData (
MnpDeviceData,
VlanVariable[Index].Bits.Vid,
(UINT8) VlanVariable[Index].Bits.Priority
);
if (MnpServiceData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
}
Exit:
if (VlanVariable != NULL) {
FreePool (VlanVariable);
}
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
//
if (MnpInitialized) { // Destroy all MNP service data
// //
// Flush the Mnp Service Data. while (!IsListEmpty (&MnpDeviceData->ServiceList)) {
// Entry = GetFirstNode (&MnpDeviceData->ServiceList);
MnpFlushServiceData (MnpServiceData, This->DriverBindingHandle); MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
MnpDestroyServiceData (MnpServiceData);
} }
FreePool (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; return Status;
@ -179,16 +246,16 @@ ErrorExit:
/** /**
Stop this driver on ControllerHandle. This service is called by the Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to make drivers as EFI boot service DisconnectController(). In order to make drivers as
small as possible, there are a few calling restrictions for this service. small as possible, there are a few calling restrictions for this service.
DisconnectController() must follow these calling restrictions. If any other DisconnectController() must follow these calling restrictions. If any other
agent wishes to call Stop() it must also follow these calling restrictions. agent wishes to call Stop() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to stop driver on. @param[in] ControllerHandle Handle of device to stop driver on.
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If
number of children is zero stop the entire number of children is zero stop the entire
bus driver. bus driver.
@param[in] ChildHandleBuffer List of Child Handles to Stop. @param[in] ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle. @retval EFI_SUCCESS This driver is removed ControllerHandle.
@ -198,19 +265,22 @@ ErrorExit:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpDriverBindingStop ( MnpDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren, IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;
MNP_DEVICE_DATA *MnpDeviceData;
MNP_SERVICE_DATA *MnpServiceData; 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 ( Status = gBS->OpenProtocol (
ControllerHandle, ControllerHandle,
@ -221,51 +291,77 @@ MnpDriverBindingStop (
EFI_OPEN_PROTOCOL_GET_PROTOCOL EFI_OPEN_PROTOCOL_GET_PROTOCOL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
//
// Retrieve VLAN Config Protocol from the ControllerHandle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiVlanConfigProtocolGuid,
(VOID **) &VlanConfig,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MnpDriverBindingStop: try to stop unknown Controller.\n"));
return EFI_DEVICE_ERROR;
}
DEBUG ( MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (VlanConfig);
(EFI_D_ERROR, } else {
"MnpDriverBindingStop: Locate MNP Service Binding Protocol failed, %r.\n", MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);
Status) MnpDeviceData = MnpServiceData->MnpDeviceData;
);
return EFI_DEVICE_ERROR;
} }
MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);
if (NumberOfChildren == 0) { if (NumberOfChildren == 0) {
// //
// Uninstall the MNP Service Binding Protocol. // Destroy all MNP service data
// //
gBS->UninstallMultipleProtocolInterfaces ( while (!IsListEmpty (&MnpDeviceData->ServiceList)) {
ControllerHandle, Entry = GetFirstNode (&MnpDeviceData->ServiceList);
&gEfiManagedNetworkServiceBindingProtocolGuid, MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
ServiceBinding, MnpDestroyServiceData (MnpServiceData);
NULL }
);
// //
// Flush the Mnp service data. // Uninstall the VLAN Config Protocol if any
// //
MnpFlushServiceData (MnpServiceData, This->DriverBindingHandle); if (MnpDeviceData->VlanConfig.Set != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
MnpDeviceData->ControllerHandle,
&gEfiVlanConfigProtocolGuid,
&MnpDeviceData->VlanConfig,
NULL
);
}
FreePool (MnpServiceData); //
} else { // Destroy the Mnp device data
while (!IsListEmpty (&MnpServiceData->ChildrenList)) { //
// MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);
// Don't use NetListRemoveHead here, the remove opreration will be done FreePool (MnpDeviceData);
// in ServiceBindingDestroyChild.
//
Instance = NET_LIST_HEAD (
&MnpServiceData->ChildrenList,
MNP_INSTANCE_DATA,
InstEntry
);
ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); return EFI_SUCCESS;
}
//
// Stop all MNP child
//
AllChildrenStopped = TRUE;
NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
Status = MnpDestroyServiceChild (MnpServiceData);
if (EFI_ERROR (Status)) {
AllChildrenStopped = FALSE;
} }
} }
return Status; if (!AllChildrenStopped) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
} }
@ -275,12 +371,12 @@ MnpDriverBindingStop (
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in, out] ChildHandle Pointer to the handle of the child to create. If @param[in, out] ChildHandle Pointer to the handle of the child to create. If
it is NULL, then a new handle is created. If it is NULL, then a new handle is created. If
it is not NULL, then the I/O services are added it is not NULL, then the I/O services are added
to the existing child handle. to the existing child handle.
@retval EFI_SUCCES The protocol was added to ChildHandle. @retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL. @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to
create the child. create the child.
@retval Others The child handle was not created. @retval Others The child handle was not created.
@ -288,18 +384,17 @@ MnpDriverBindingStop (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpServiceBindingCreateChild ( MnpServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle IN OUT EFI_HANDLE *ChildHandle
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
MNP_SERVICE_DATA *MnpServiceData; MNP_SERVICE_DATA *MnpServiceData;
MNP_INSTANCE_DATA *Instance; MNP_INSTANCE_DATA *Instance;
VOID *Snp; VOID *MnpSb;
EFI_TPL OldTpl; EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) { if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -310,8 +405,8 @@ MnpServiceBindingCreateChild (
// //
Instance = AllocateZeroPool (sizeof (MNP_INSTANCE_DATA)); Instance = AllocateZeroPool (sizeof (MNP_INSTANCE_DATA));
if (Instance == NULL) { if (Instance == NULL) {
DEBUG ((EFI_D_ERROR, "MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n")); DEBUG ((EFI_D_ERROR, "MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n"));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -327,12 +422,12 @@ MnpServiceBindingCreateChild (
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ( DEBUG (
(EFI_D_ERROR, (EFI_D_ERROR,
"MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n", "MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n",
Status) Status)
); );
goto ErrorExit; goto ErrorExit;
} }
@ -342,9 +437,9 @@ MnpServiceBindingCreateChild (
Instance->Handle = *ChildHandle; Instance->Handle = *ChildHandle;
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
MnpServiceData->ControllerHandle, MnpServiceData->ServiceHandle,
&gEfiSimpleNetworkProtocolGuid, &gEfiManagedNetworkServiceBindingProtocolGuid,
(VOID **) &Snp, (VOID **) &MnpSb,
gMnpDriverBinding.DriverBindingHandle, gMnpDriverBinding.DriverBindingHandle,
Instance->Handle, Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@ -385,16 +480,16 @@ ErrorExit:
/** /**
Destroys a child handle with a set of I/O services. Destroys a child handle with a set of I/O services.
The DestroyChild() function does the opposite of CreateChild(). It removes a The DestroyChild() function does the opposite of CreateChild(). It removes a
protocol that was installed by CreateChild() from ChildHandle. If the removed protocol that was installed by CreateChild() from ChildHandle. If the removed
protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.
@param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL
instance. instance.
@param[in] ChildHandle Handle of the child to destroy. @param[in] ChildHandle Handle of the child to destroy.
@retval EFI_SUCCES The protocol was removed from ChildHandle. @retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that
is being removed. is being removed.
@retval EFI_INVALID_PARAMETER ChildHandle is not a valid UEFI handle. @retval EFI_INVALID_PARAMETER ChildHandle is not a valid UEFI handle.
@ -407,8 +502,8 @@ ErrorExit:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpServiceBindingDestroyChild ( MnpServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle IN EFI_HANDLE ChildHandle
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -418,7 +513,6 @@ MnpServiceBindingDestroyChild (
EFI_TPL OldTpl; EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) { if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -436,7 +530,6 @@ MnpServiceBindingDestroyChild (
EFI_OPEN_PROTOCOL_GET_PROTOCOL EFI_OPEN_PROTOCOL_GET_PROTOCOL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -449,7 +542,6 @@ MnpServiceBindingDestroyChild (
// will only excecute once. // will only excecute once.
// //
if (Instance->Destroyed) { if (Instance->Destroyed) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -459,9 +551,9 @@ MnpServiceBindingDestroyChild (
// Close the Simple Network protocol. // Close the Simple Network protocol.
// //
gBS->CloseProtocol ( gBS->CloseProtocol (
MnpServiceData->ControllerHandle, MnpServiceData->ServiceHandle,
&gEfiSimpleNetworkProtocolGuid, &gEfiManagedNetworkServiceBindingProtocolGuid,
gMnpDriverBinding.DriverBindingHandle, MnpServiceData->MnpDeviceData->ImageHandle,
ChildHandle ChildHandle
); );
@ -475,7 +567,6 @@ MnpServiceBindingDestroyChild (
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ( DEBUG (
(EFI_D_ERROR, (EFI_D_ERROR,
"MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n", "MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",
@ -523,7 +614,7 @@ MnpServiceBindingDestroyChild (
@param[in] ImageHandle The image handle of the driver. @param[in] ImageHandle The image handle of the driver.
@param[in] SystemTable The system table. @param[in] SystemTable The system table.
@retval EFI_SUCCES The driver binding and component name protocols are @retval EFI_SUCCES The driver binding and component name protocols are
successfully installed. successfully installed.
@retval Others Other errors as indicated. @retval Others Other errors as indicated.
@ -531,8 +622,8 @@ MnpServiceBindingDestroyChild (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpDriverEntryPoint ( MnpDriverEntryPoint (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
return EfiLibInstallDriverBindingComponentName2 ( return EfiLibInstallDriverBindingComponentName2 (

View File

@ -1,11 +1,12 @@
/** @file /** @file
Declaration of strctures and functions for MnpDxe driver. Declaration of strctures and functions for MnpDxe driver.
Copyright (c) 2005 - 2007, Intel Corporation. <BR> Copyright (c) 2005 - 2009, Intel Corporation.<BR>
All rights reserved. This program and the accompanying materials are licensed All rights reserved. This program and the accompanying materials
and made available under the terms and conditions of the BSD License which are licensed and made available under the terms and conditions
accompanies this distribution. The full text of the license may be found at of the BSD License which accompanies this distribution. The full
http://opensource.org/licenses/bsd-license.php 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, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -14,11 +15,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef _MNP_DRIVER_H_ #ifndef _MNP_DRIVER_H_
#define _MNP_DRIVER_H_ #define _MNP_DRIVER_H_
#include <Uefi.h> #include <Uefi.h>
#include <Protocol/ManagedNetwork.h> #include <Protocol/ManagedNetwork.h>
#include <Protocol/SimpleNetwork.h> #include <Protocol/SimpleNetwork.h>
#include <Protocol/ServiceBinding.h> #include <Protocol/ServiceBinding.h>
#include <Protocol/VlanConfig.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.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/UefiLib.h>
#include <Library/NetLib.h> #include <Library/NetLib.h>
#include <Library/DpcLib.h> #include <Library/DpcLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include "ComponentName.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 { typedef struct {
UINT32 Signature; UINT32 Signature;
EFI_HANDLE ControllerHandle; 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; EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
UINT32 Mtu; //
// List of MNP_SERVICE_DATA
LIST_ENTRY ChildrenList; //
UINTN ChildrenNumber; LIST_ENTRY ServiceList;
//
// Number of configured MNP Service Binding child
//
UINTN ConfiguredChildrenNumber; UINTN ConfiguredChildrenNumber;
LIST_ENTRY GroupAddressList; LIST_ENTRY GroupAddressList;
@ -73,8 +84,38 @@ typedef struct {
UINT32 PaddingSize; UINT32 PaddingSize;
NET_BUF *RxNbufCache; NET_BUF *RxNbufCache;
UINT8 *TxBuf; 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; } MNP_SERVICE_DATA;
#define MNP_SERVICE_DATA_FROM_THIS(a) \ #define MNP_SERVICE_DATA_FROM_THIS(a) \
CR ( \ CR ( \
(a), \ (a), \
@ -83,6 +124,15 @@ typedef struct {
MNP_SERVICE_DATA_SIGNATURE \ 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 Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In is called by the EFI boot service ConnectController(). In
@ -93,7 +143,7 @@ typedef struct {
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to test. @param[in] ControllerHandle Handle of device to test.
@param[in] RemainingDevicePath Optional parameter use to pick a specific @param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start. child device to start.
@retval EFI_SUCCESS This driver supports this device. @retval EFI_SUCCESS This driver supports this device.
@ -104,50 +154,50 @@ typedef struct {
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpDriverBindingSupported ( MnpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
); );
/** /**
Start this driver on ControllerHandle. This service is called by the Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make drivers as small EFI boot service ConnectController(). In order to make drivers as small
as possible, there are a few calling restrictions for this service. as possible, there are a few calling restrictions for this service.
ConnectController() must follow these calling restrictions. If any other ConnectController() must follow these calling restrictions. If any other
agent wishes to call Start() it must also follow these calling restrictions. agent wishes to call Start() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to. @param[in] ControllerHandle Handle of device to bind driver to.
@param[in] RemainingDevicePath Optional parameter use to pick a specific @param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start. child device to start.
@retval EFI_SUCCESS This driver is added to ControllerHandle. @retval EFI_SUCCESS This driver is added to ControllerHandle.
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle. @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data.
@retval Others This driver does not support this device. @retval Others This driver does not support this device.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpDriverBindingStart ( MnpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
); );
/** /**
Stop this driver on ControllerHandle. This service is called by the Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to make drivers as EFI boot service DisconnectController(). In order to make drivers as
small as possible, there are a few calling restrictions for this service. small as possible, there are a few calling restrictions for this service.
DisconnectController() must follow these calling restrictions. If any other DisconnectController() must follow these calling restrictions. If any other
agent wishes to call Stop() it must also follow these calling restrictions. agent wishes to call Stop() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to stop driver on. @param[in] ControllerHandle Handle of device to stop driver on.
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If
number of children is zero stop the entire number of children is zero stop the entire
bus driver. bus driver.
@param[in] ChildHandleBuffer List of Child Handles to Stop. @param[in] ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle. @retval EFI_SUCCESS This driver is removed ControllerHandle.
@ -157,10 +207,10 @@ MnpDriverBindingStart (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpDriverBindingStop ( MnpDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren, IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
); );
/** /**
@ -169,12 +219,12 @@ MnpDriverBindingStop (
@param[in] This Protocol instance pointer. @param[in] This Protocol instance pointer.
@param[in, out] ChildHandle Pointer to the handle of the child to create. If @param[in, out] ChildHandle Pointer to the handle of the child to create. If
it is NULL, then a new handle is created. If it is NULL, then a new handle is created. If
it is not NULL, then the I/O services are added it is not NULL, then the I/O services are added
to the existing child handle. to the existing child handle.
@retval EFI_SUCCES The protocol was added to ChildHandle. @retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL. @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to
create the child. create the child.
@retval Others The child handle was not created. @retval Others The child handle was not created.
@ -182,22 +232,22 @@ MnpDriverBindingStop (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpServiceBindingCreateChild ( MnpServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle IN OUT EFI_HANDLE *ChildHandle
); );
/** /**
Destroys a child handle with a set of I/O services. Destroys a child handle with a set of I/O services.
The DestroyChild() function does the opposite of CreateChild(). It removes a The DestroyChild() function does the opposite of CreateChild(). It removes a
protocol that was installed by CreateChild() from ChildHandle. If the removed protocol that was installed by CreateChild() from ChildHandle. If the removed
protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.
@param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL
instance. instance.
@param[in] ChildHandle Handle of the child to destroy. @param[in] ChildHandle Handle of the child to destroy.
@retval EFI_SUCCES The protocol was removed from ChildHandle. @retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that
is being removed. is being removed.
@retval EFI_INVALID_PARAMETER ChildHandle is not a valid UEFI handle. @retval EFI_INVALID_PARAMETER ChildHandle is not a valid UEFI handle.
@ -210,8 +260,8 @@ MnpServiceBindingCreateChild (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpServiceBindingDestroyChild ( MnpServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle IN EFI_HANDLE ChildHandle
); );
#endif #endif

View File

@ -1,16 +1,17 @@
/** @file ## @file
Component description file for Mnp module. # 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] [Defines]
INF_VERSION = 0x00010005 INF_VERSION = 0x00010005
BASE_NAME = MnpDxe BASE_NAME = MnpDxe
@ -24,7 +25,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
# #
# VALID_ARCHITECTURES = IA32 X64 IPF EBC # VALID_ARCHITECTURES = IA32 X64 IPF EBC
# #
# DRIVER_BINDING = gMnpDriverBinding # DRIVER_BINDING = gMnpDriverBinding
# COMPONENT_NAME = gMnpComponentName # COMPONENT_NAME = gMnpComponentName
# COMPONENT_NAME2 = gMnpComponentName2 # COMPONENT_NAME2 = gMnpComponentName2
# #
@ -38,13 +39,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
MnpDriver.c MnpDriver.c
MnpConfig.c MnpConfig.c
MnpImpl.h MnpImpl.h
MnpVlan.h
MnpVlan.c
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec MdeModulePkg/MdeModulePkg.dec
[LibraryClasses] [LibraryClasses]
BaseLib BaseLib
BaseMemoryLib BaseMemoryLib
@ -57,6 +58,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
DpcLib DpcLib
[Protocols] [Protocols]
gEfiManagedNetworkServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiManagedNetworkServiceBindingProtocolGuid ## PRODUCES
gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiSimpleNetworkProtocolGuid ## CONSUMES
gEfiManagedNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiManagedNetworkProtocolGuid ## PRODUCES
gEfiVlanConfigProtocolGuid ## SOMETIMES_PRODUCES

View File

@ -1,10 +1,11 @@
/** @file /** @file
Declaration of structures and functions of MnpDxe driver. 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 All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions
which accompanies this distribution. The full text of the license may be found at 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 http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
@ -90,6 +91,57 @@ typedef struct {
UINT64 TimeoutTick; UINT64 TimeoutTick;
} MNP_RXDATA_WRAP; } 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. Initialize the mnp service context data.
@ -104,36 +156,66 @@ typedef struct {
**/ **/
EFI_STATUS EFI_STATUS
MnpInitializeServiceData ( MnpInitializeServiceData (
IN OUT MNP_SERVICE_DATA *MnpServiceData, IN OUT MNP_SERVICE_DATA *MnpServiceData,
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_HANDLE ControllerHandle IN EFI_HANDLE ControllerHandle
); );
/** /**
Flush the mnp service context data. Destroy the MNP service context data.
@param[in, out] MnpServiceData Pointer to the mnp service context data. @param[in, 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 EFI_STATUS
MnpFlushServiceData ( MnpDestroyServiceData (
IN OUT MNP_SERVICE_DATA *MnpServiceData, IN OUT MNP_SERVICE_DATA *MnpServiceData
IN EFI_HANDLE ImageHandle );
/**
Destroy all child of the MNP service data.
@param[in, out] MnpServiceData Pointer to the mnp service context data.
@retval EFI_SUCCESS All child are destroyed.
@retval Others Failed to destroy all child.
**/
EFI_STATUS
MnpDestroyServiceChild (
IN OUT MNP_SERVICE_DATA *MnpServiceData
);
/**
Find the MNP Service Data for given VLAN ID.
@param[in] MnpDeviceData Pointer to the mnp device context data.
@param[in] VlanId The VLAN ID.
@return A pointer to MNP_SERVICE_DATA or NULL if not found.
**/
MNP_SERVICE_DATA *
MnpFindServiceData (
IN MNP_DEVICE_DATA *MnpDeviceData,
IN UINT16 VlanId
); );
/** /**
Initialize the mnp instance context data. Initialize the mnp instance context data.
@param[in] MnpServiceData Pointer to the mnp service context data. @param[in] MnpServiceData Pointer to the mnp service context data.
@param[in, out] Instance Pointer to the mnp instance context data @param[in, out] Instance Pointer to the mnp instance context data
to initialize. to initialize.
**/ **/
VOID VOID
MnpInitializeInstanceData ( MnpInitializeInstanceData (
IN MNP_SERVICE_DATA *MnpServiceData, IN MNP_SERVICE_DATA *MnpServiceData,
IN OUT MNP_INSTANCE_DATA *Instance IN OUT MNP_INSTANCE_DATA *Instance
); );
/** /**
@ -152,9 +234,9 @@ MnpInitializeInstanceData (
**/ **/
EFI_STATUS EFI_STATUS
MnpTokenExist ( MnpTokenExist (
IN NET_MAP *Map, IN NET_MAP *Map,
IN NET_MAP_ITEM *Item, IN NET_MAP_ITEM *Item,
IN VOID *Arg IN VOID *Arg
); );
/** /**
@ -162,10 +244,10 @@ MnpTokenExist (
@param[in, out] Map Pointer to the NET_MAP. @param[in, out] Map Pointer to the NET_MAP.
@param[in, out] Item Pointer to the NET_MAP_ITEM. @param[in, out] Item Pointer to the NET_MAP_ITEM.
@param[in] Arg Pointer to the Arg, it's a pointer to the @param[in] Arg Pointer to the Arg, it's a pointer to the
token to cancel. token to cancel.
@retval EFI_SUCCESS The Arg is NULL, and the token in Item is cancelled, @retval EFI_SUCCESS The Arg is NULL, and the token in Item is cancelled,
or the Arg isn't NULL, and the token in Item is or the Arg isn't NULL, and the token in Item is
different from the Arg. different from the Arg.
@retval EFI_ABORTED The Arg isn't NULL, the token in Item mathces the @retval EFI_ABORTED The Arg isn't NULL, the token in Item mathces the
@ -174,9 +256,9 @@ MnpTokenExist (
**/ **/
EFI_STATUS EFI_STATUS
MnpCancelTokens ( MnpCancelTokens (
IN OUT NET_MAP *Map, IN OUT NET_MAP *Map,
IN OUT NET_MAP_ITEM *Item, IN OUT NET_MAP_ITEM *Item,
IN VOID *Arg IN VOID *Arg
); );
/** /**
@ -187,7 +269,7 @@ MnpCancelTokens (
**/ **/
VOID VOID
MnpFlushRcvdDataQueue ( MnpFlushRcvdDataQueue (
IN OUT MNP_INSTANCE_DATA *Instance IN OUT MNP_INSTANCE_DATA *Instance
); );
/** /**
@ -205,18 +287,18 @@ MnpFlushRcvdDataQueue (
**/ **/
EFI_STATUS EFI_STATUS
MnpConfigureInstance ( MnpConfigureInstance (
IN OUT MNP_INSTANCE_DATA *Instance, IN OUT MNP_INSTANCE_DATA *Instance,
IN EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData OPTIONAL IN EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData OPTIONAL
); );
/** /**
Do the group operations for this instance. Do the group operations for this instance.
@param[in, out] Instance Pointer to the instance context data. @param[in, out] Instance Pointer to the instance context data.
@param[in] JoinFlag Set to TRUE to join a group. Set to TRUE to @param[in] JoinFlag Set to TRUE to join a group. Set to TRUE to
leave a group/groups. leave a group/groups.
@param[in] MacAddress Pointer to the group address to join or leave. @param[in] MacAddress Pointer to the group address to join or leave.
@param[in] CtrlBlk Pointer to the group control block if JoinFlag @param[in] CtrlBlk Pointer to the group control block if JoinFlag
is FALSE. is FALSE.
@retval EFI_SUCCESS The group operation finished. @retval EFI_SUCCESS The group operation finished.
@ -226,10 +308,10 @@ MnpConfigureInstance (
**/ **/
EFI_STATUS EFI_STATUS
MnpGroupOp ( MnpGroupOp (
IN OUT MNP_INSTANCE_DATA *Instance, IN OUT MNP_INSTANCE_DATA *Instance,
IN BOOLEAN JoinFlag, IN BOOLEAN JoinFlag,
IN EFI_MAC_ADDRESS *MacAddress OPTIONAL, IN EFI_MAC_ADDRESS *MacAddress OPTIONAL,
IN MNP_GROUP_CONTROL_BLOCK *CtrlBlk OPTIONAL IN MNP_GROUP_CONTROL_BLOCK *CtrlBlk OPTIONAL
); );
/** /**
@ -243,27 +325,27 @@ MnpGroupOp (
**/ **/
BOOLEAN BOOLEAN
MnpIsValidTxToken ( MnpIsValidTxToken (
IN MNP_INSTANCE_DATA *Instance, IN MNP_INSTANCE_DATA *Instance,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
); );
/** /**
Build the packet to transmit from the TxData passed in. Build the packet to transmit from the TxData passed in.
@param[in] MnpServiceData Pointer to the mnp service context data. @param[in] MnpServiceData Pointer to the mnp service context data.
@param[in] TxData Pointer to the transmit data containing the information @param[in] TxData Pointer to the transmit data containing the information
to build the packet. to build the packet.
@param[out] PktBuf Pointer to record the address of the packet. @param[out] PktBuf Pointer to record the address of the packet.
@param[out] PktLen Pointer to a UINT32 variable used to record the packet's @param[out] PktLen Pointer to a UINT32 variable used to record the packet's
length. length.
**/ **/
VOID VOID
MnpBuildTxPacket ( MnpBuildTxPacket (
IN MNP_SERVICE_DATA *MnpServiceData, IN MNP_SERVICE_DATA *MnpServiceData,
IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData, IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,
OUT UINT8 **PktBuf, OUT UINT8 **PktBuf,
OUT UINT32 *PktLen OUT UINT32 *PktLen
); );
/** /**
@ -281,10 +363,10 @@ MnpBuildTxPacket (
**/ **/
EFI_STATUS EFI_STATUS
MnpSyncSendPacket ( MnpSyncSendPacket (
IN MNP_SERVICE_DATA *MnpServiceData, IN MNP_SERVICE_DATA *MnpServiceData,
IN UINT8 *Packet, IN UINT8 *Packet,
IN UINT32 Length, IN UINT32 Length,
IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
); );
/** /**
@ -300,7 +382,7 @@ MnpSyncSendPacket (
**/ **/
EFI_STATUS EFI_STATUS
MnpInstanceDeliverPacket ( MnpInstanceDeliverPacket (
IN OUT MNP_INSTANCE_DATA *Instance IN OUT MNP_INSTANCE_DATA *Instance
); );
/** /**
@ -314,14 +396,14 @@ MnpInstanceDeliverPacket (
VOID VOID
EFIAPI EFIAPI
MnpRecycleRxData ( MnpRecycleRxData (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
); );
/** /**
Try to receive a packet and deliver it. 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_SUCCESS add return value to function comment
@retval EFI_NOT_STARTED The simple network protocol is not started. @retval EFI_NOT_STARTED The simple network protocol is not started.
@ -331,35 +413,35 @@ MnpRecycleRxData (
**/ **/
EFI_STATUS EFI_STATUS
MnpReceivePacket ( 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 in the queue, first try to allocate some and add them into the queue, then
fetch the NET_BUF from the updated FreeNbufQue. fetch the NET_BUF from the updated FreeNbufQue.
@param[in, out] MnpServiceData Pointer to the MNP_SERVICE_DATA. @param[in, out] MnpDeviceData Pointer to the MNP_DEVICE_DATA.
@return Pointer to the allocated free NET_BUF structure, if NULL the @return Pointer to the allocated free NET_BUF structure, if NULL the
operation is failed. operation is failed.
**/ **/
NET_BUF * NET_BUF *
MnpAllocNbuf ( MnpAllocNbuf (
IN OUT MNP_SERVICE_DATA *MnpServiceData IN OUT MNP_DEVICE_DATA *MnpDeviceData
); );
/** /**
Try to reclaim the Nbuf into the buffer pool. 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. @param[in, out] Nbuf Pointer to the NET_BUF to free.
**/ **/
VOID VOID
MnpFreeNbuf ( MnpFreeNbuf (
IN OUT MNP_SERVICE_DATA *MnpServiceData, IN OUT MNP_DEVICE_DATA *MnpDeviceData,
IN OUT NET_BUF *Nbuf IN OUT NET_BUF *Nbuf
); );
@ -369,13 +451,13 @@ MnpFreeNbuf (
@param[in] Event The event this notify function registered to. @param[in] Event The event this notify function registered to.
@param[in] Context Pointer to the context data registered to the @param[in] Context Pointer to the context data registered to the
event. event.
**/ **/
VOID VOID
EFIAPI EFIAPI
MnpCheckPacketTimeout ( MnpCheckPacketTimeout (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
); );
/** /**
@ -389,16 +471,16 @@ MnpCheckPacketTimeout (
VOID VOID
EFIAPI EFIAPI
MnpSystemPoll ( MnpSystemPoll (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN OUT VOID *Context IN OUT VOID *Context
); );
/** /**
Returns the operational parameters for the current MNP child driver. May also Returns the operational parameters for the current MNP child driver. May also
support returning the underlying SNP driver mode data. support returning the underlying SNP driver mode data.
The GetModeData() function is used to read the current mode data (operational The GetModeData() function is used to read the current mode data (operational
parameters) from the MNP or the underlying SNP. parameters) from the MNP or the underlying SNP.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type
@ -407,7 +489,7 @@ MnpSystemPoll (
@param[out] SnpModeData Pointer to storage for SNP operational parameters. This @param[out] SnpModeData Pointer to storage for SNP operational parameters. This
feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE
is defined in the EFI_SIMPLE_NETWORK_PROTOCOL. is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.
@retval EFI_SUCCESS The operation completed successfully. @retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER This is NULL. @retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this @retval EFI_UNSUPPORTED The requested feature is unsupported in this
@ -421,15 +503,15 @@ MnpSystemPoll (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpGetModeData ( MnpGetModeData (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, 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 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
); );
/** /**
Sets or clears the operational parameters for the MNP child driver. Sets or clears the operational parameters for the MNP child driver.
The Configure() function is used to set, change, or reset the operational The Configure() function is used to set, change, or reset the operational
parameters for the MNP child driver instance. Until the operational parameters parameters for the MNP child driver instance. Until the operational parameters
have been set, no network traffic can be sent or received by this MNP child have been set, no network traffic can be sent or received by this MNP child
driver instance. Once the operational parameters have been reset, no more driver instance. Once the operational parameters have been reset, no more
@ -481,14 +563,14 @@ MnpGetModeData (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpConfigure ( MnpConfigure (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL
); );
/** /**
Translates an IP multicast address to a hardware (MAC) multicast address. This Translates an IP multicast address to a hardware (MAC) multicast address. This
function may be unsupported in some MNP implementations. function may be unsupported in some MNP implementations.
The McastIpToMac() function translates an IP multicast address to a hardware The McastIpToMac() function translates an IP multicast address to a hardware
(MAC) multicast address. This function may be implemented by calling the (MAC) multicast address. This function may be implemented by calling the
underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be
@ -499,7 +581,7 @@ MnpConfigure (
Set to FALSE if IpAddress is an IPv4 multicast address. Set to FALSE if IpAddress is an IPv4 multicast address.
@param[in] IpAddress Pointer to the multicast IP address (in network byte @param[in] IpAddress Pointer to the multicast IP address (in network byte
order) to convert. order) to convert.
@param[out] MacAddress Pointer to the resulting multicast MAC address. @param[out] MacAddress Pointer to the resulting multicast MAC address.
@retval EFI_SUCCESS The operation completed successfully. @retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER One of the following conditions is TRUE: @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:
@ -518,21 +600,21 @@ MnpConfigure (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpMcastIpToMac ( MnpMcastIpToMac (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN Ipv6Flag, IN BOOLEAN Ipv6Flag,
IN EFI_IP_ADDRESS *IpAddress, IN EFI_IP_ADDRESS *IpAddress,
OUT EFI_MAC_ADDRESS *MacAddress OUT EFI_MAC_ADDRESS *MacAddress
); );
/** /**
Enables and disables receive filters for multicast address. This function may Enables and disables receive filters for multicast address. This function may
be unsupported in some MNP implementations. be unsupported in some MNP implementations.
The Groups() function only adds and removes multicast MAC addresses from the The Groups() function only adds and removes multicast MAC addresses from the
filter list. The MNP driver does not transmit or process Internet Group filter list. The MNP driver does not transmit or process Internet Group
Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is
NULL, then all joined groups are left. NULL, then all joined groups are left.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] JoinFlag Set to TRUE to join this multicast group. @param[in] JoinFlag Set to TRUE to join this multicast group.
Set to FALSE to leave this multicast group. Set to FALSE to leave this multicast group.
@ -563,15 +645,15 @@ MnpMcastIpToMac (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpGroups ( MnpGroups (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN JoinFlag, IN BOOLEAN JoinFlag,
IN EFI_MAC_ADDRESS *MacAddress OPTIONAL IN EFI_MAC_ADDRESS *MacAddress OPTIONAL
); );
/** /**
Places asynchronous outgoing data packets into the transmit queue. Places asynchronous outgoing data packets into the transmit queue.
The Transmit() function places a completion token into the transmit packet The Transmit() function places a completion token into the transmit packet
queue. This function is always asynchronous. queue. This function is always asynchronous.
The caller must fill in the Token.Event and Token.TxData fields in the The caller must fill in the Token.Event and Token.TxData fields in the
completion token, and these fields cannot be NULL. When the transmit operation completion token, and these fields cannot be NULL. When the transmit operation
@ -581,12 +663,12 @@ MnpGroups (
defragmented before it can be transmitted by the network device. Systems in defragmented before it can be transmitted by the network device. Systems in
which performance is critical should review the requirements and features of which performance is critical should review the requirements and features of
the underlying communications device and drivers. the underlying communications device and drivers.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the transmit data @param[in] Token Pointer to a token associated with the transmit data
descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN
is defined in "Related Definitions" below. is defined in "Related Definitions" below.
@retval EFI_SUCCESS The transmit completion token was cached. @retval EFI_SUCCESS The transmit completion token was cached.
@retval EFI_NOT_STARTED This MNP child driver instance has not been @retval EFI_NOT_STARTED This MNP child driver instance has not been
@ -615,7 +697,7 @@ MnpGroups (
@retval EFI_ACCESS_DENIED The transmit completion token is already in the @retval EFI_ACCESS_DENIED The transmit completion token is already in the
transmit queue. transmit queue.
@retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
lack of system resources (usually memory). lack of system resources (usually memory).
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
The MNP child driver instance has been reset to The MNP child driver instance has been reset to
startup defaults. startup defaults.
@ -626,13 +708,13 @@ MnpGroups (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpTransmit ( MnpTransmit (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
); );
/** /**
Aborts an asynchronous transmit or receive request. Aborts an asynchronous transmit or receive request.
The Cancel() function is used to abort a pending transmit or receive request. The Cancel() function is used to abort a pending transmit or receive request.
If the token is in the transmit or receive request queues, after calling this If the token is in the transmit or receive request queues, after calling this
function, Token.Status will be set to EFI_ABORTED and then Token.Event will be function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
@ -643,8 +725,8 @@ MnpTransmit (
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token that has been issued by @param[in] Token Pointer to a token that has been issued by
EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all
pending tokens are aborted. pending tokens are aborted.
@retval EFI_SUCCESS The asynchronous I/O request was aborted and @retval EFI_SUCCESS The asynchronous I/O request was aborted and
Token.Event was signaled. When Token is NULL, Token.Event was signaled. When Token is NULL,
@ -662,20 +744,20 @@ MnpTransmit (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpCancel ( MnpCancel (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL
); );
/** /**
Places an asynchronous receiving request into the receiving queue. Places an asynchronous receiving request into the receiving queue.
The Receive() function places a completion token into the receive packet The Receive() function places a completion token into the receive packet
queue. This function is always asynchronous. queue. This function is always asynchronous.
The caller must fill in the Token.Event field in the completion token, and The caller must fill in the Token.Event field in the completion token, and
this field cannot be NULL. When the receive operation completes, the MNP this field cannot be NULL. When the receive operation completes, the MNP
updates the Token.Status and Token.RxData fields and the Token.Event is updates the Token.Status and Token.RxData fields and the Token.Event is
signaled. signaled.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the receive @param[in] Token Pointer to a token associated with the receive
data descriptor. Type data descriptor. Type
@ -704,14 +786,14 @@ MnpCancel (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpReceive ( MnpReceive (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
); );
/** /**
Polls for incoming data packets and processes outgoing data packets. Polls for incoming data packets and processes outgoing data packets.
The Poll() function can be used by network drivers and applications to The Poll() function can be used by network drivers and applications to
increase the rate that data packets are moved between the communications increase the rate that data packets are moved between the communications
device and the transmit and receive queues. device and the transmit and receive queues.
Normally, a periodic timer event internally calls the Poll() function. But, in Normally, a periodic timer event internally calls the Poll() function. But, in
@ -737,23 +819,23 @@ MnpReceive (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpPoll ( MnpPoll (
IN EFI_MANAGED_NETWORK_PROTOCOL *This IN EFI_MANAGED_NETWORK_PROTOCOL *This
); );
/** /**
Configure the Snp receive filters according to the instances' receive filter Configure the Snp receive filters according to the instances' receive filter
settings. 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_SUCCESS The receive filters is configured.
@retval EFI_OUT_OF_RESOURCES The receive filters can't be configured due @retval EFI_OUT_OF_RESOURCES The receive filters can't be configured due
to lack of memory resource. to lack of memory resource.
**/ **/
EFI_STATUS EFI_STATUS
MnpConfigReceiveFilters ( MnpConfigReceiveFilters (
IN MNP_SERVICE_DATA *MnpServiceData IN MNP_DEVICE_DATA *MnpDeviceData
); );
#endif #endif

View File

@ -1,10 +1,11 @@
/** @file /** @file
Implementation of Managed Network Protocol I/O functions. 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 All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions
which accompanies this distribution. The full text of the license may be found at 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 http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 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 "MnpImpl.h"
#include "MnpVlan.h"
/** /**
Validates the Mnp transmit token. Validates the Mnp transmit token.
@ -25,8 +27,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
BOOLEAN BOOLEAN
MnpIsValidTxToken ( MnpIsValidTxToken (
IN MNP_INSTANCE_DATA *Instance, IN MNP_INSTANCE_DATA *Instance,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
) )
{ {
MNP_SERVICE_DATA *MnpServiceData; MNP_SERVICE_DATA *MnpServiceData;
@ -38,7 +40,7 @@ MnpIsValidTxToken (
MnpServiceData = Instance->MnpServiceData; MnpServiceData = Instance->MnpServiceData;
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
TxData = Token->Packet.TxData; TxData = Token->Packet.TxData;
if ((Token->Event == NULL) || (TxData == NULL) || (TxData->FragmentCount == 0)) { if ((Token->Event == NULL) || (TxData == NULL) || (TxData->FragmentCount == 0)) {
// //
@ -105,25 +107,27 @@ MnpIsValidTxToken (
Build the packet to transmit from the TxData passed in. Build the packet to transmit from the TxData passed in.
@param[in] MnpServiceData Pointer to the mnp service context data. @param[in] MnpServiceData Pointer to the mnp service context data.
@param[in] TxData Pointer to the transmit data containing the information @param[in] TxData Pointer to the transmit data containing the information
to build the packet. to build the packet.
@param[out] PktBuf Pointer to record the address of the packet. @param[out] PktBuf Pointer to record the address of the packet.
@param[out] PktLen Pointer to a UINT32 variable used to record the packet's @param[out] PktLen Pointer to a UINT32 variable used to record the packet's
length. length.
**/ **/
VOID VOID
MnpBuildTxPacket ( MnpBuildTxPacket (
IN MNP_SERVICE_DATA *MnpServiceData, IN MNP_SERVICE_DATA *MnpServiceData,
IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData, IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,
OUT UINT8 **PktBuf, OUT UINT8 **PktBuf,
OUT UINT32 *PktLen OUT UINT32 *PktLen
) )
{ {
EFI_SIMPLE_NETWORK_MODE *SnpMode; EFI_SIMPLE_NETWORK_MODE *SnpMode;
UINT8 *DstPos; UINT8 *DstPos;
UINT16 Index; UINT16 Index;
MNP_DEVICE_DATA *MnpDerviceData;
MnpDerviceData = MnpServiceData->MnpDeviceData;
if ((TxData->DestinationAddress == NULL) && (TxData->FragmentCount == 1)) { if ((TxData->DestinationAddress == NULL) && (TxData->FragmentCount == 1)) {
// //
// Media header is in FragmentTable and there is only one fragment, // 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 // one fragment, copy the data into the packet buffer. Reserve the
// media header space if necessary. // media header space if necessary.
// //
SnpMode = MnpServiceData->Snp->Mode; SnpMode = MnpDerviceData->Snp->Mode;
DstPos = MnpServiceData->TxBuf; DstPos = MnpDerviceData->TxBuf;
*PktLen = 0; *PktLen = 0;
if (TxData->DestinationAddress != NULL) { if (TxData->DestinationAddress != NULL) {
@ -165,7 +169,7 @@ MnpBuildTxPacket (
// //
// Set the buffer pointer and the buffer length. // Set the buffer pointer and the buffer length.
// //
*PktBuf = MnpServiceData->TxBuf; *PktBuf = MnpDerviceData->TxBuf;
*PktLen += TxData->DataLength + TxData->HeaderLength; *PktLen += TxData->DataLength + TxData->HeaderLength;
} }
} }
@ -186,10 +190,10 @@ MnpBuildTxPacket (
**/ **/
EFI_STATUS EFI_STATUS
MnpSyncSendPacket ( MnpSyncSendPacket (
IN MNP_SERVICE_DATA *MnpServiceData, IN MNP_SERVICE_DATA *MnpServiceData,
IN UINT8 *Packet, IN UINT8 *Packet,
IN UINT32 Length, IN UINT32 Length,
IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -197,25 +201,32 @@ MnpSyncSendPacket (
EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData; EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData;
UINT32 HeaderSize; UINT32 HeaderSize;
UINT8 *TxBuf; UINT8 *TxBuf;
MNP_DEVICE_DATA *MnpDeviceData;
UINT16 ProtocolType;
Snp = MnpServiceData->Snp; MnpDeviceData = MnpServiceData->MnpDeviceData;
TxData = Token->Packet.TxData; Snp = MnpDeviceData->Snp;
TxData = Token->Packet.TxData;
HeaderSize = Snp->Mode->MediaHeaderSize - TxData->HeaderLength; HeaderSize = Snp->Mode->MediaHeaderSize - TxData->HeaderLength;
// //
// Start the timeout event. // Start the timeout event.
// //
Status = gBS->SetTimer ( Status = gBS->SetTimer (
MnpServiceData->TxTimeoutEvent, MnpDeviceData->TxTimeoutEvent,
TimerRelative, TimerRelative,
MNP_TX_TIMEOUT_TIME MNP_TX_TIMEOUT_TIME
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto SIGNAL_TOKEN; goto SIGNAL_TOKEN;
} }
//
// Insert VLAN tag
//
MnpInsertVlanTag (MnpServiceData, TxData, &ProtocolType, &Packet, &Length);
for (;;) { for (;;) {
// //
// Transmit the packet through SNP. // Transmit the packet through SNP.
@ -227,10 +238,9 @@ MnpSyncSendPacket (
Packet, Packet,
TxData->SourceAddress, TxData->SourceAddress,
TxData->DestinationAddress, TxData->DestinationAddress,
&TxData->ProtocolType &ProtocolType
); );
if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) { if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) {
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
break; break;
} }
@ -247,22 +257,20 @@ MnpSyncSendPacket (
// //
Snp->GetStatus (Snp, NULL, (VOID **) &TxBuf); Snp->GetStatus (Snp, NULL, (VOID **) &TxBuf);
if (!EFI_ERROR (gBS->CheckEvent (MnpServiceData->TxTimeoutEvent))) { if (!EFI_ERROR (gBS->CheckEvent (MnpDeviceData->TxTimeoutEvent))) {
Status = EFI_TIMEOUT; Status = EFI_TIMEOUT;
break; break;
} }
} while (TxBuf == NULL); } while (TxBuf == NULL);
if ((Status == EFI_SUCCESS) || (Status == EFI_TIMEOUT)) { if ((Status == EFI_SUCCESS) || (Status == EFI_TIMEOUT)) {
break; break;
} else { } else {
// //
// Status is EFI_NOT_READY. Restart the timer event and call Snp->Transmit again. // Status is EFI_NOT_READY. Restart the timer event and call Snp->Transmit again.
// //
gBS->SetTimer ( gBS->SetTimer (
MnpServiceData->TxTimeoutEvent, MnpDeviceData->TxTimeoutEvent,
TimerRelative, TimerRelative,
MNP_TX_TIMEOUT_TIME MNP_TX_TIMEOUT_TIME
); );
@ -272,7 +280,7 @@ MnpSyncSendPacket (
// //
// Cancel the timer event. // Cancel the timer event.
// //
gBS->SetTimer (MnpServiceData->TxTimeoutEvent, TimerCancel, 0); gBS->SetTimer (MnpDeviceData->TxTimeoutEvent, TimerCancel, 0);
SIGNAL_TOKEN: SIGNAL_TOKEN:
@ -301,18 +309,18 @@ SIGNAL_TOKEN:
**/ **/
EFI_STATUS EFI_STATUS
MnpInstanceDeliverPacket ( MnpInstanceDeliverPacket (
IN OUT MNP_INSTANCE_DATA *Instance IN OUT MNP_INSTANCE_DATA *Instance
) )
{ {
MNP_SERVICE_DATA *MnpServiceData; MNP_DEVICE_DATA *MnpDeviceData;
MNP_RXDATA_WRAP *RxDataWrap; MNP_RXDATA_WRAP *RxDataWrap;
NET_BUF *DupNbuf; NET_BUF *DupNbuf;
EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData; EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData;
EFI_SIMPLE_NETWORK_MODE *SnpMode; EFI_SIMPLE_NETWORK_MODE *SnpMode;
EFI_MANAGED_NETWORK_COMPLETION_TOKEN *RxToken; EFI_MANAGED_NETWORK_COMPLETION_TOKEN *RxToken;
MnpServiceData = Instance->MnpServiceData; MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
if (NetMapIsEmpty (&Instance->RxTokenMap) || IsListEmpty (&Instance->RcvdPacketQueue)) { if (NetMapIsEmpty (&Instance->RxTokenMap) || IsListEmpty (&Instance->RcvdPacketQueue)) {
// //
@ -329,7 +337,7 @@ MnpInstanceDeliverPacket (
// There are other instances share this Nbuf, duplicate to get a // There are other instances share this Nbuf, duplicate to get a
// copy to allow the instance to do R/W operations. // copy to allow the instance to do R/W operations.
// //
DupNbuf = MnpAllocNbuf (MnpServiceData); DupNbuf = MnpAllocNbuf (MnpDeviceData);
if (DupNbuf == NULL) { if (DupNbuf == NULL) {
DEBUG ((EFI_D_WARN, "MnpDeliverPacket: Failed to allocate a free Nbuf.\n")); DEBUG ((EFI_D_WARN, "MnpDeliverPacket: Failed to allocate a free Nbuf.\n"));
@ -340,7 +348,7 @@ MnpInstanceDeliverPacket (
// Duplicate the net buffer. // Duplicate the net buffer.
// //
NetbufDuplicate (RxDataWrap->Nbuf, DupNbuf, 0); NetbufDuplicate (RxDataWrap->Nbuf, DupNbuf, 0);
MnpFreeNbuf (MnpServiceData, RxDataWrap->Nbuf); MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);
RxDataWrap->Nbuf = DupNbuf; RxDataWrap->Nbuf = DupNbuf;
} }
@ -351,7 +359,7 @@ MnpInstanceDeliverPacket (
Instance->RcvdPacketQueueSize--; Instance->RcvdPacketQueueSize--;
RxData = &RxDataWrap->RxData; RxData = &RxDataWrap->RxData;
SnpMode = MnpServiceData->Snp->Mode; SnpMode = MnpDeviceData->Snp->Mode;
// //
// Set all the buffer pointers. // Set all the buffer pointers.
@ -390,7 +398,7 @@ MnpInstanceDeliverPacket (
**/ **/
VOID VOID
MnpDeliverPacket ( MnpDeliverPacket (
IN MNP_SERVICE_DATA *MnpServiceData IN MNP_SERVICE_DATA *MnpServiceData
) )
{ {
LIST_ENTRY *Entry; LIST_ENTRY *Entry;
@ -421,12 +429,12 @@ MnpDeliverPacket (
VOID VOID
EFIAPI EFIAPI
MnpRecycleRxData ( MnpRecycleRxData (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
MNP_RXDATA_WRAP *RxDataWrap; MNP_RXDATA_WRAP *RxDataWrap;
MNP_SERVICE_DATA *MnpServiceData; MNP_DEVICE_DATA *MnpDeviceData;
ASSERT (Context != NULL); ASSERT (Context != NULL);
@ -435,13 +443,13 @@ MnpRecycleRxData (
ASSERT (RxDataWrap->Nbuf != NULL); ASSERT (RxDataWrap->Nbuf != NULL);
MnpServiceData = RxDataWrap->Instance->MnpServiceData; MnpDeviceData = RxDataWrap->Instance->MnpServiceData->MnpDeviceData;
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
// //
// Free this Nbuf. // Free this Nbuf.
// //
MnpFreeNbuf (MnpServiceData, RxDataWrap->Nbuf); MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);
RxDataWrap->Nbuf = NULL; RxDataWrap->Nbuf = NULL;
// //
@ -467,8 +475,8 @@ MnpRecycleRxData (
**/ **/
VOID VOID
MnpQueueRcvdPacket ( MnpQueueRcvdPacket (
IN OUT MNP_INSTANCE_DATA *Instance, IN OUT MNP_INSTANCE_DATA *Instance,
IN OUT MNP_RXDATA_WRAP *RxDataWrap IN OUT MNP_RXDATA_WRAP *RxDataWrap
) )
{ {
MNP_RXDATA_WRAP *OldRxDataWrap; MNP_RXDATA_WRAP *OldRxDataWrap;
@ -528,10 +536,10 @@ MnpQueueRcvdPacket (
**/ **/
BOOLEAN BOOLEAN
MnpMatchPacket ( MnpMatchPacket (
IN MNP_INSTANCE_DATA *Instance, IN MNP_INSTANCE_DATA *Instance,
IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData, IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,
IN MNP_GROUP_ADDRESS *GroupAddress OPTIONAL, IN MNP_GROUP_ADDRESS *GroupAddress OPTIONAL,
IN UINT8 PktAttr IN UINT8 PktAttr
) )
{ {
EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData; EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData;
@ -607,18 +615,20 @@ MnpMatchPacket (
**/ **/
VOID VOID
MnpAnalysePacket ( MnpAnalysePacket (
IN MNP_SERVICE_DATA *MnpServiceData, IN MNP_SERVICE_DATA *MnpServiceData,
IN NET_BUF *Nbuf, IN NET_BUF *Nbuf,
IN OUT EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData, IN OUT EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,
OUT MNP_GROUP_ADDRESS **GroupAddress, OUT MNP_GROUP_ADDRESS **GroupAddress,
OUT UINT8 *PktAttr OUT UINT8 *PktAttr
) )
{ {
EFI_SIMPLE_NETWORK_MODE *SnpMode; EFI_SIMPLE_NETWORK_MODE *SnpMode;
MNP_DEVICE_DATA *MnpDeviceData;
UINT8 *BufPtr; UINT8 *BufPtr;
LIST_ENTRY *Entry; LIST_ENTRY *Entry;
SnpMode = MnpServiceData->Snp->Mode; MnpDeviceData = MnpServiceData->MnpDeviceData;
SnpMode = MnpDeviceData->Snp->Mode;
// //
// Get the packet buffer. // Get the packet buffer.
@ -650,7 +660,7 @@ MnpAnalysePacket (
// //
// It's multicast, try to match the multicast filters. // 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); *GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);
if (NET_MAC_EQUAL (BufPtr, &((*GroupAddress)->Address), SnpMode->HwAddressSize)) { if (NET_MAC_EQUAL (BufPtr, &((*GroupAddress)->Address), SnpMode->HwAddressSize)) {
@ -667,7 +677,7 @@ MnpAnalysePacket (
*GroupAddress = NULL; *GroupAddress = NULL;
RxData->PromiscuousFlag = TRUE; RxData->PromiscuousFlag = TRUE;
if (MnpServiceData->PromiscuousCount == 0) { if (MnpDeviceData->PromiscuousCount == 0) {
// //
// Skip the below code, there is no receiver of this packet. // Skip the below code, there is no receiver of this packet.
// //
@ -703,8 +713,8 @@ MnpAnalysePacket (
**/ **/
MNP_RXDATA_WRAP * MNP_RXDATA_WRAP *
MnpWrapRxData ( MnpWrapRxData (
IN MNP_INSTANCE_DATA *Instance, IN MNP_INSTANCE_DATA *Instance,
IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -737,8 +747,8 @@ MnpWrapRxData (
&RxDataWrap->RxData.RecycleEvent &RxDataWrap->RxData.RecycleEvent
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status)); DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status));
FreePool (RxDataWrap); FreePool (RxDataWrap);
return NULL; return NULL;
} }
@ -758,8 +768,8 @@ MnpWrapRxData (
**/ **/
VOID VOID
MnpEnqueuePacket ( MnpEnqueuePacket (
IN MNP_SERVICE_DATA *MnpServiceData, IN MNP_SERVICE_DATA *MnpServiceData,
IN NET_BUF *Nbuf IN NET_BUF *Nbuf
) )
{ {
LIST_ENTRY *Entry; LIST_ENTRY *Entry;
@ -776,7 +786,7 @@ MnpEnqueuePacket (
// //
MnpAnalysePacket (MnpServiceData, Nbuf, &RxData, &GroupAddress, &PktAttr); 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. // No receivers, no more action need.
// //
@ -799,7 +809,6 @@ MnpEnqueuePacket (
// Check the packet against the instance receive filters. // Check the packet against the instance receive filters.
// //
if (MnpMatchPacket (Instance, &RxData, GroupAddress, PktAttr)) { if (MnpMatchPacket (Instance, &RxData, GroupAddress, PktAttr)) {
// //
// Wrap the RxData. // Wrap the RxData.
// //
@ -826,7 +835,7 @@ MnpEnqueuePacket (
/** /**
Try to receive a packet and deliver it. 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_SUCCESS add return value to function comment
@retval EFI_NOT_STARTED The simple network protocol is not started. @retval EFI_NOT_STARTED The simple network protocol is not started.
@ -836,7 +845,7 @@ MnpEnqueuePacket (
**/ **/
EFI_STATUS EFI_STATUS
MnpReceivePacket ( MnpReceivePacket (
IN OUT MNP_SERVICE_DATA *MnpServiceData IN OUT MNP_DEVICE_DATA *MnpDeviceData
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -846,10 +855,13 @@ MnpReceivePacket (
UINTN BufLen; UINTN BufLen;
UINTN HeaderSize; UINTN HeaderSize;
UINT32 Trimmed; 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) { if (Snp->Mode->State != EfiSimpleNetworkInitialized) {
// //
// The simple network protocol is not started. // The simple network protocol is not started.
@ -857,20 +869,13 @@ MnpReceivePacket (
return EFI_NOT_STARTED; return EFI_NOT_STARTED;
} }
if (IsListEmpty (&MnpServiceData->ChildrenList)) { if (MnpDeviceData->RxNbufCache == NULL) {
//
// There is no child, no need to receive packets.
//
return EFI_SUCCESS;
}
if (MnpServiceData->RxNbufCache == NULL) {
// //
// Try to get a new buffer as there may be buffers recycled. // 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. // No availabe buffer in the buffer pool.
// //
@ -878,13 +883,13 @@ MnpReceivePacket (
} }
NetbufAllocSpace ( NetbufAllocSpace (
MnpServiceData->RxNbufCache, MnpDeviceData->RxNbufCache,
MnpServiceData->BufferLength, MnpDeviceData->BufferLength,
NET_BUF_TAIL NET_BUF_TAIL
); );
} }
Nbuf = MnpServiceData->RxNbufCache; Nbuf = MnpDeviceData->RxNbufCache;
BufLen = Nbuf->TotalSize; BufLen = Nbuf->TotalSize;
BufPtr = NetbufGetByte (Nbuf, 0, NULL); BufPtr = NetbufGetByte (Nbuf, 0, NULL);
ASSERT (BufPtr != NULL); ASSERT (BufPtr != NULL);
@ -894,7 +899,6 @@ MnpReceivePacket (
// //
Status = Snp->Receive (Snp, &HeaderSize, &BufLen, BufPtr, NULL, NULL, NULL); Status = Snp->Receive (Snp, &HeaderSize, &BufLen, BufPtr, NULL, NULL, NULL);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG_CODE ( DEBUG_CODE (
if (Status != EFI_NOT_READY) { if (Status != EFI_NOT_READY) {
DEBUG ((EFI_D_WARN, "MnpReceivePacket: Snp->Receive() = %r.\n", Status)); DEBUG ((EFI_D_WARN, "MnpReceivePacket: Snp->Receive() = %r.\n", Status));
@ -908,7 +912,6 @@ MnpReceivePacket (
// Sanity check. // Sanity check.
// //
if ((HeaderSize != Snp->Mode->MediaHeaderSize) || (BufLen < HeaderSize)) { if ((HeaderSize != Snp->Mode->MediaHeaderSize) || (BufLen < HeaderSize)) {
DEBUG ( DEBUG (
(EFI_D_WARN, (EFI_D_WARN,
"MnpReceivePacket: Size error, HL:TL = %d:%d.\n", "MnpReceivePacket: Size error, HL:TL = %d:%d.\n",
@ -927,6 +930,25 @@ MnpReceivePacket (
ASSERT (Nbuf->TotalSize == BufLen); 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. // Enqueue the packet to the matched instances.
// //
@ -937,16 +959,16 @@ MnpReceivePacket (
// RefCnt > 2 indicates there is at least one receiver of this packet. // RefCnt > 2 indicates there is at least one receiver of this packet.
// Free the current RxNbufCache and allocate a new one. // Free the current RxNbufCache and allocate a new one.
// //
MnpFreeNbuf (MnpServiceData, Nbuf); MnpFreeNbuf (MnpDeviceData, Nbuf);
Nbuf = MnpAllocNbuf (MnpServiceData); Nbuf = MnpAllocNbuf (MnpDeviceData);
MnpServiceData->RxNbufCache = Nbuf; MnpDeviceData->RxNbufCache = Nbuf;
if (Nbuf == NULL) { if (Nbuf == NULL) {
DEBUG ((EFI_D_ERROR, "MnpReceivePacket: Alloc packet for receiving cache failed.\n")); DEBUG ((EFI_D_ERROR, "MnpReceivePacket: Alloc packet for receiving cache failed.\n"));
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
NetbufAllocSpace (Nbuf, MnpServiceData->BufferLength, NET_BUF_TAIL); NetbufAllocSpace (Nbuf, MnpDeviceData->BufferLength, NET_BUF_TAIL);
} else { } else {
// //
// No receiver for this packet. // No receiver for this packet.
@ -954,6 +976,9 @@ MnpReceivePacket (
if (Trimmed > 0) { if (Trimmed > 0) {
NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL); NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);
} }
if (IsVlanPacket) {
NetbufAllocSpace (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);
}
goto EXIT; goto EXIT;
} }
@ -964,7 +989,7 @@ MnpReceivePacket (
EXIT: EXIT:
ASSERT (Nbuf->TotalSize == MnpServiceData->BufferLength); ASSERT (Nbuf->TotalSize == MnpDeviceData->BufferLength);
return Status; return Status;
} }
@ -976,66 +1001,70 @@ EXIT:
@param[in] Event The event this notify function registered to. @param[in] Event The event this notify function registered to.
@param[in] Context Pointer to the context data registered to the @param[in] Context Pointer to the context data registered to the
event. event.
**/ **/
VOID VOID
EFIAPI EFIAPI
MnpCheckPacketTimeout ( MnpCheckPacketTimeout (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
MNP_DEVICE_DATA *MnpDeviceData;
MNP_SERVICE_DATA *MnpServiceData; MNP_SERVICE_DATA *MnpServiceData;
LIST_ENTRY *Entry; LIST_ENTRY *Entry;
LIST_ENTRY *ServiceEntry;
LIST_ENTRY *RxEntry; LIST_ENTRY *RxEntry;
LIST_ENTRY *NextEntry; LIST_ENTRY *NextEntry;
MNP_INSTANCE_DATA *Instance; MNP_INSTANCE_DATA *Instance;
MNP_RXDATA_WRAP *RxDataWrap; MNP_RXDATA_WRAP *RxDataWrap;
EFI_TPL OldTpl; EFI_TPL OldTpl;
MnpServiceData = (MNP_SERVICE_DATA *) Context; MnpDeviceData = (MNP_DEVICE_DATA *) Context;
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) { NET_LIST_FOR_EACH (ServiceEntry, &MnpDeviceData->ServiceList) {
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (ServiceEntry);
Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry); NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
if (!Instance->Configured || (Instance->ConfigData.ReceivedQueueTimeoutValue == 0)) { Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);
// NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
// This instance is not configured or there is no receive time out,
// just skip to the next instance.
//
continue;
}
OldTpl = gBS->RaiseTPL (TPL_NOTIFY); if (!Instance->Configured || (Instance->ConfigData.ReceivedQueueTimeoutValue == 0)) {
NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {
RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);
//
// 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 {
// //
// Drop the timeout packet. // This instance is not configured or there is no receive time out,
// just skip to the next instance.
// //
DEBUG ((EFI_D_WARN, "MnpCheckPacketTimeout: Received packet timeout.\n")); continue;
MnpRecycleRxData (NULL, RxDataWrap);
Instance->RcvdPacketQueueSize--;
} }
}
gBS->RestoreTPL (OldTpl); OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {
RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);
//
// 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 {
//
// Drop the timeout packet.
//
DEBUG ((EFI_D_WARN, "MnpCheckPacketTimeout: Received packet timeout.\n"));
MnpRecycleRxData (NULL, RxDataWrap);
Instance->RcvdPacketQueueSize--;
}
}
gBS->RestoreTPL (OldTpl);
}
} }
} }
/** /**
Poll to receive the packets from Snp. This function is either called by upperlayer Poll to receive the packets from Snp. This function is either called by upperlayer
protocols/applications or the system poll timer notify mechanism. protocols/applications or the system poll timer notify mechanism.
@ -1047,19 +1076,19 @@ MnpCheckPacketTimeout (
VOID VOID
EFIAPI EFIAPI
MnpSystemPoll ( MnpSystemPoll (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN OUT VOID *Context IN OUT VOID *Context
) )
{ {
MNP_SERVICE_DATA *MnpServiceData; MNP_DEVICE_DATA *MnpDeviceData;
MnpServiceData = (MNP_SERVICE_DATA *) Context; MnpDeviceData = (MNP_DEVICE_DATA *) Context;
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
// //
// Try to receive packets from Snp. // Try to receive packets from Snp.
// //
MnpReceivePacket (MnpServiceData); MnpReceivePacket (MnpDeviceData);
// //
// Dispatch the DPC queued by the NotifyFunction of rx token's events. // Dispatch the DPC queued by the NotifyFunction of rx token's events.

View File

@ -1,10 +1,11 @@
/** @file /** @file
Implementation of Managed Network Protocol public services. 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 All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions
which accompanies this distribution. The full text of the license may be found at 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 http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
@ -16,10 +17,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
/** /**
Returns the operational parameters for the current MNP child driver. May also Returns the operational parameters for the current MNP child driver. May also
support returning the underlying SNP driver mode data. support returning the underlying SNP driver mode data.
The GetModeData() function is used to read the current mode data (operational The GetModeData() function is used to read the current mode data (operational
parameters) from the MNP or the underlying SNP. parameters) from the MNP or the underlying SNP.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type
@ -28,7 +29,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@param[out] SnpModeData Pointer to storage for SNP operational parameters. This @param[out] SnpModeData Pointer to storage for SNP operational parameters. This
feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE
is defined in the EFI_SIMPLE_NETWORK_PROTOCOL. is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.
@retval EFI_SUCCESS The operation completed successfully. @retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER This is NULL. @retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this @retval EFI_UNSUPPORTED The requested feature is unsupported in this
@ -42,9 +43,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpGetModeData ( MnpGetModeData (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, 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 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
) )
{ {
MNP_INSTANCE_DATA *Instance; MNP_INSTANCE_DATA *Instance;
@ -53,7 +54,6 @@ MnpGetModeData (
EFI_STATUS Status; EFI_STATUS Status;
if (This == NULL) { if (This == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -72,7 +72,7 @@ MnpGetModeData (
// //
// Copy the underlayer Snp mode data. // Copy the underlayer Snp mode data.
// //
Snp = Instance->MnpServiceData->Snp; Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData)); CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));
} }
@ -89,9 +89,9 @@ MnpGetModeData (
/** /**
Sets or clears the operational parameters for the MNP child driver. Sets or clears the operational parameters for the MNP child driver.
The Configure() function is used to set, change, or reset the operational The Configure() function is used to set, change, or reset the operational
parameters for the MNP child driver instance. Until the operational parameters parameters for the MNP child driver instance. Until the operational parameters
have been set, no network traffic can be sent or received by this MNP child have been set, no network traffic can be sent or received by this MNP child
driver instance. Once the operational parameters have been reset, no more driver instance. Once the operational parameters have been reset, no more
@ -143,8 +143,8 @@ MnpGetModeData (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpConfigure ( MnpConfigure (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL
) )
{ {
MNP_INSTANCE_DATA *Instance; MNP_INSTANCE_DATA *Instance;
@ -152,10 +152,10 @@ MnpConfigure (
EFI_STATUS Status; EFI_STATUS Status;
if ((This == NULL) || if ((This == NULL) ||
((MnpConfigData != NULL) && ((MnpConfigData != NULL) &&
(MnpConfigData->ProtocolTypeFilter > 0) && (MnpConfigData->ProtocolTypeFilter > 0) &&
(MnpConfigData->ProtocolTypeFilter <= 1500))) { (MnpConfigData->ProtocolTypeFilter <= 1500))
) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -184,9 +184,9 @@ ON_EXIT:
/** /**
Translates an IP multicast address to a hardware (MAC) multicast address. This Translates an IP multicast address to a hardware (MAC) multicast address. This
function may be unsupported in some MNP implementations. function may be unsupported in some MNP implementations.
The McastIpToMac() function translates an IP multicast address to a hardware The McastIpToMac() function translates an IP multicast address to a hardware
(MAC) multicast address. This function may be implemented by calling the (MAC) multicast address. This function may be implemented by calling the
underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be
@ -197,7 +197,7 @@ ON_EXIT:
Set to FALSE if IpAddress is an IPv4 multicast address. Set to FALSE if IpAddress is an IPv4 multicast address.
@param[in] IpAddress Pointer to the multicast IP address (in network byte @param[in] IpAddress Pointer to the multicast IP address (in network byte
order) to convert. order) to convert.
@param[out] MacAddress Pointer to the resulting multicast MAC address. @param[out] MacAddress Pointer to the resulting multicast MAC address.
@retval EFI_SUCCESS The operation completed successfully. @retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER One of the following conditions is TRUE: @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:
@ -216,10 +216,10 @@ ON_EXIT:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpMcastIpToMac ( MnpMcastIpToMac (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN Ipv6Flag, IN BOOLEAN Ipv6Flag,
IN EFI_IP_ADDRESS *IpAddress, IN EFI_IP_ADDRESS *IpAddress,
OUT EFI_MAC_ADDRESS *MacAddress OUT EFI_MAC_ADDRESS *MacAddress
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -229,7 +229,6 @@ MnpMcastIpToMac (
EFI_IPv6_ADDRESS *Ip6Address; EFI_IPv6_ADDRESS *Ip6Address;
if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) { if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -254,10 +253,10 @@ MnpMcastIpToMac (
goto ON_EXIT; goto ON_EXIT;
} }
Snp = Instance->MnpServiceData->Snp; Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
ASSERT (Snp != NULL); ASSERT (Snp != NULL);
ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS)); ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));
if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) { if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {
if (!Ipv6Flag) { if (!Ipv6Flag) {
@ -273,10 +272,10 @@ MnpMcastIpToMac (
MacAddress->Addr[5] = IpAddress->v4.Addr[3]; MacAddress->Addr[5] = IpAddress->v4.Addr[3];
} else { } else {
// //
// Translate the IPv6 address into a multicast MAC address if the NIC is an // Translate the IPv6 address into a multicast MAC address if the NIC is an
// ethernet NIC according to RFC2464. // ethernet NIC according to RFC2464.
// //
MacAddress->Addr[0] = 0x33; MacAddress->Addr[0] = 0x33;
MacAddress->Addr[1] = 0x33; MacAddress->Addr[1] = 0x33;
MacAddress->Addr[2] = Ip6Address->Addr[12]; MacAddress->Addr[2] = Ip6Address->Addr[12];
@ -305,14 +304,14 @@ ON_EXIT:
} }
/** /**
Enables and disables receive filters for multicast address. This function may Enables and disables receive filters for multicast address. This function may
be unsupported in some MNP implementations. be unsupported in some MNP implementations.
The Groups() function only adds and removes multicast MAC addresses from the The Groups() function only adds and removes multicast MAC addresses from the
filter list. The MNP driver does not transmit or process Internet Group filter list. The MNP driver does not transmit or process Internet Group
Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is
NULL, then all joined groups are left. NULL, then all joined groups are left.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] JoinFlag Set to TRUE to join this multicast group. @param[in] JoinFlag Set to TRUE to join this multicast group.
Set to FALSE to leave this multicast group. Set to FALSE to leave this multicast group.
@ -343,9 +342,9 @@ ON_EXIT:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpGroups ( MnpGroups (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN JoinFlag, IN BOOLEAN JoinFlag,
IN EFI_MAC_ADDRESS *MacAddress OPTIONAL IN EFI_MAC_ADDRESS *MacAddress OPTIONAL
) )
{ {
MNP_INSTANCE_DATA *Instance; MNP_INSTANCE_DATA *Instance;
@ -365,12 +364,11 @@ MnpGroups (
} }
Instance = MNP_INSTANCE_DATA_FROM_THIS (This); Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
SnpMode = Instance->MnpServiceData->Snp->Mode; SnpMode = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;
OldTpl = gBS->RaiseTPL (TPL_CALLBACK); OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) { if (!Instance->Configured) {
Status = EFI_NOT_STARTED; Status = EFI_NOT_STARTED;
goto ON_EXIT; goto ON_EXIT;
} }
@ -452,8 +450,8 @@ ON_EXIT:
/** /**
Places asynchronous outgoing data packets into the transmit queue. Places asynchronous outgoing data packets into the transmit queue.
The Transmit() function places a completion token into the transmit packet The Transmit() function places a completion token into the transmit packet
queue. This function is always asynchronous. queue. This function is always asynchronous.
The caller must fill in the Token.Event and Token.TxData fields in the The caller must fill in the Token.Event and Token.TxData fields in the
completion token, and these fields cannot be NULL. When the transmit operation completion token, and these fields cannot be NULL. When the transmit operation
@ -463,8 +461,8 @@ ON_EXIT:
defragmented before it can be transmitted by the network device. Systems in defragmented before it can be transmitted by the network device. Systems in
which performance is critical should review the requirements and features of which performance is critical should review the requirements and features of
the underlying communications device and drivers. the underlying communications device and drivers.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the transmit data @param[in] Token Pointer to a token associated with the transmit data
descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN
@ -497,7 +495,7 @@ ON_EXIT:
@retval EFI_ACCESS_DENIED The transmit completion token is already in the @retval EFI_ACCESS_DENIED The transmit completion token is already in the
transmit queue. transmit queue.
@retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
lack of system resources (usually memory). lack of system resources (usually memory).
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
The MNP child driver instance has been reset to The MNP child driver instance has been reset to
startup defaults. startup defaults.
@ -508,8 +506,8 @@ ON_EXIT:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpTransmit ( MnpTransmit (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -520,7 +518,6 @@ MnpTransmit (
EFI_TPL OldTpl; EFI_TPL OldTpl;
if ((This == NULL) || (Token == NULL)) { if ((This == NULL) || (Token == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -564,14 +561,14 @@ ON_EXIT:
/** /**
Places an asynchronous receiving request into the receiving queue. Places an asynchronous receiving request into the receiving queue.
The Receive() function places a completion token into the receive packet The Receive() function places a completion token into the receive packet
queue. This function is always asynchronous. queue. This function is always asynchronous.
The caller must fill in the Token.Event field in the completion token, and The caller must fill in the Token.Event field in the completion token, and
this field cannot be NULL. When the receive operation completes, the MNP this field cannot be NULL. When the receive operation completes, the MNP
updates the Token.Status and Token.RxData fields and the Token.Event is updates the Token.Status and Token.RxData fields and the Token.Event is
signaled. signaled.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the receive @param[in] Token Pointer to a token associated with the receive
data descriptor. Type data descriptor. Type
@ -600,8 +597,8 @@ ON_EXIT:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpReceive ( MnpReceive (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -609,7 +606,6 @@ MnpReceive (
EFI_TPL OldTpl; EFI_TPL OldTpl;
if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) { if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -618,7 +614,6 @@ MnpReceive (
OldTpl = gBS->RaiseTPL (TPL_CALLBACK); OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) { if (!Instance->Configured) {
Status = EFI_NOT_STARTED; Status = EFI_NOT_STARTED;
goto ON_EXIT; goto ON_EXIT;
} }
@ -628,7 +623,6 @@ MnpReceive (
// //
Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token); Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ON_EXIT; goto ON_EXIT;
} }
@ -636,7 +630,6 @@ MnpReceive (
// Insert the Token into the RxTokenMap. // Insert the Token into the RxTokenMap.
// //
Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL); Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
// Try to deliver any buffered packets. // Try to deliver any buffered packets.
@ -656,8 +649,8 @@ ON_EXIT:
} }
/** /**
Aborts an asynchronous transmit or receive request. Aborts an asynchronous transmit or receive request.
The Cancel() function is used to abort a pending transmit or receive request. The Cancel() function is used to abort a pending transmit or receive request.
If the token is in the transmit or receive request queues, after calling this If the token is in the transmit or receive request queues, after calling this
function, Token.Status will be set to EFI_ABORTED and then Token.Event will be function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
@ -668,7 +661,7 @@ ON_EXIT:
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token that has been issued by @param[in] Token Pointer to a token that has been issued by
EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all
pending tokens are aborted. pending tokens are aborted.
@retval EFI_SUCCESS The asynchronous I/O request was aborted and @retval EFI_SUCCESS The asynchronous I/O request was aborted and
@ -687,8 +680,8 @@ ON_EXIT:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpCancel ( MnpCancel (
IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -696,7 +689,6 @@ MnpCancel (
EFI_TPL OldTpl; EFI_TPL OldTpl;
if (This == NULL) { if (This == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -705,7 +697,6 @@ MnpCancel (
OldTpl = gBS->RaiseTPL (TPL_CALLBACK); OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) { if (!Instance->Configured) {
Status = EFI_NOT_STARTED; Status = EFI_NOT_STARTED;
goto ON_EXIT; goto ON_EXIT;
} }
@ -714,9 +705,7 @@ MnpCancel (
// Iterate the RxTokenMap to cancel the specified Token. // Iterate the RxTokenMap to cancel the specified Token.
// //
Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token); Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);
if (Token != NULL) { if (Token != NULL) {
Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND; Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;
} }
@ -732,9 +721,9 @@ ON_EXIT:
} }
/** /**
Polls for incoming data packets and processes outgoing data packets. Polls for incoming data packets and processes outgoing data packets.
The Poll() function can be used by network drivers and applications to The Poll() function can be used by network drivers and applications to
increase the rate that data packets are moved between the communications increase the rate that data packets are moved between the communications
device and the transmit and receive queues. device and the transmit and receive queues.
Normally, a periodic timer event internally calls the Poll() function. But, in Normally, a periodic timer event internally calls the Poll() function. But, in
@ -760,7 +749,7 @@ ON_EXIT:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MnpPoll ( MnpPoll (
IN EFI_MANAGED_NETWORK_PROTOCOL *This IN EFI_MANAGED_NETWORK_PROTOCOL *This
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -783,7 +772,7 @@ MnpPoll (
// //
// Try to receive packets. // 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. // Dispatch the DPC queued by the NotifyFunction of rx token's events.
@ -795,4 +784,3 @@ ON_EXIT:
return Status; 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