2007-07-24 10:06:37 +02:00
|
|
|
/** @file
|
2009-01-16 01:09:52 +01:00
|
|
|
Implementation of Managed Network Protocol I/O functions.
|
2009-12-30 14:47:55 +01:00
|
|
|
|
2018-06-27 15:08:52 +02:00
|
|
|
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:05:13 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
2008-10-14 17:34:00 +02:00
|
|
|
#include "MnpImpl.h"
|
2009-12-30 14:47:55 +01:00
|
|
|
#include "MnpVlan.h"
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Validates the Mnp transmit token.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] Instance Pointer to the Mnp instance context data.
|
|
|
|
@param[in] Token Pointer to the transmit token to check.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@return The Token is valid or not.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
MnpIsValidTxToken (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_INSTANCE_DATA *Instance,
|
|
|
|
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
MNP_SERVICE_DATA *MnpServiceData;
|
|
|
|
EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData;
|
|
|
|
UINT32 Index;
|
|
|
|
UINT32 TotalLength;
|
|
|
|
EFI_MANAGED_NETWORK_FRAGMENT_DATA *FragmentTable;
|
|
|
|
|
|
|
|
MnpServiceData = Instance->MnpServiceData;
|
|
|
|
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
TxData = Token->Packet.TxData;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
if ((Token->Event == NULL) || (TxData == NULL) || (TxData->FragmentCount == 0)) {
|
|
|
|
//
|
|
|
|
// The token is invalid if the Event is NULL, or the TxData is NULL, or
|
|
|
|
// the fragment count is zero.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpIsValidTxToken: Invalid Token.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((TxData->DestinationAddress != NULL) && (TxData->HeaderLength != 0)) {
|
|
|
|
//
|
|
|
|
// The token is invalid if the HeaderLength isn't zero while the DestinationAddress
|
|
|
|
// is NULL (The destination address is already put into the packet).
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpIsValidTxToken: DestinationAddress isn't NULL, HeaderLength must be 0.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TotalLength = 0;
|
|
|
|
FragmentTable = TxData->FragmentTable;
|
|
|
|
for (Index = 0; Index < TxData->FragmentCount; Index++) {
|
|
|
|
|
|
|
|
if ((FragmentTable[Index].FragmentLength == 0) || (FragmentTable[Index].FragmentBuffer == NULL)) {
|
|
|
|
//
|
|
|
|
// The token is invalid if any FragmentLength is zero or any FragmentBuffer is NULL.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpIsValidTxToken: Invalid FragmentLength or FragmentBuffer.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TotalLength += FragmentTable[Index].FragmentLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((TxData->DestinationAddress == NULL) && (FragmentTable[0].FragmentLength < TxData->HeaderLength)) {
|
|
|
|
//
|
|
|
|
// Media header is split between fragments.
|
|
|
|
//
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TotalLength != (TxData->DataLength + TxData->HeaderLength)) {
|
|
|
|
//
|
|
|
|
// The length calculated from the fragment information doesn't equal to the
|
|
|
|
// sum of the DataLength and the HeaderLength.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpIsValidTxData: Invalid Datalength compared with the sum of fragment length.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TxData->DataLength > MnpServiceData->Mtu) {
|
|
|
|
//
|
|
|
|
// The total length is larger than the MTU.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpIsValidTxData: TxData->DataLength exceeds Mtu.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Build the packet to transmit from the TxData passed in.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] MnpServiceData Pointer to the mnp service context data.
|
2009-12-30 14:47:55 +01:00
|
|
|
@param[in] TxData Pointer to the transmit data containing the information
|
2009-02-03 08:56:54 +01:00
|
|
|
to build the packet.
|
|
|
|
@param[out] PktBuf Pointer to record the address of the packet.
|
2009-12-30 14:47:55 +01:00
|
|
|
@param[out] PktLen Pointer to a UINT32 variable used to record the packet's
|
2009-02-03 08:56:54 +01:00
|
|
|
length.
|
|
|
|
|
2016-01-08 03:38:34 +01:00
|
|
|
@retval EFI_SUCCESS TxPackage is built.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES The deliver fails due to lack of memory resource.
|
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
**/
|
2016-01-08 03:38:34 +01:00
|
|
|
EFI_STATUS
|
2007-07-24 10:06:37 +02:00
|
|
|
MnpBuildTxPacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_SERVICE_DATA *MnpServiceData,
|
|
|
|
IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,
|
|
|
|
OUT UINT8 **PktBuf,
|
|
|
|
OUT UINT32 *PktLen
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_SIMPLE_NETWORK_MODE *SnpMode;
|
|
|
|
UINT8 *DstPos;
|
|
|
|
UINT16 Index;
|
2016-01-08 03:38:34 +01:00
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
|
|
|
UINT8 *TxBuf;
|
2018-06-27 15:08:52 +02:00
|
|
|
|
2016-01-08 03:38:34 +01:00
|
|
|
MnpDeviceData = MnpServiceData->MnpDeviceData;
|
2018-06-27 15:08:52 +02:00
|
|
|
|
2016-01-08 03:38:34 +01:00
|
|
|
TxBuf = MnpAllocTxBuf (MnpDeviceData);
|
|
|
|
if (TxBuf == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2018-06-27 15:08:52 +02:00
|
|
|
|
2014-01-06 03:17:12 +01:00
|
|
|
//
|
2016-01-08 03:38:34 +01:00
|
|
|
// Reserve space for vlan tag if needed.
|
2014-01-06 03:17:12 +01:00
|
|
|
//
|
2016-01-08 03:38:34 +01:00
|
|
|
if (MnpServiceData->VlanId != 0) {
|
|
|
|
*PktBuf = TxBuf + NET_VLAN_TAG_LEN;
|
|
|
|
} else {
|
|
|
|
*PktBuf = TxBuf;
|
|
|
|
}
|
2018-06-27 15:08:52 +02:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
if ((TxData->DestinationAddress == NULL) && (TxData->FragmentCount == 1)) {
|
2013-12-23 09:43:09 +01:00
|
|
|
CopyMem (
|
|
|
|
*PktBuf,
|
|
|
|
TxData->FragmentTable[0].FragmentBuffer,
|
|
|
|
TxData->FragmentTable[0].FragmentLength
|
|
|
|
);
|
2018-06-27 15:08:52 +02:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
*PktLen = TxData->FragmentTable[0].FragmentLength;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Either media header isn't in FragmentTable or there is more than
|
|
|
|
// one fragment, copy the data into the packet buffer. Reserve the
|
|
|
|
// media header space if necessary.
|
|
|
|
//
|
2018-06-27 15:08:52 +02:00
|
|
|
SnpMode = MnpDeviceData->Snp->Mode;
|
2014-01-06 03:17:12 +01:00
|
|
|
DstPos = *PktBuf;
|
2007-07-24 10:06:37 +02:00
|
|
|
*PktLen = 0;
|
|
|
|
if (TxData->DestinationAddress != NULL) {
|
|
|
|
//
|
|
|
|
// If dest address is not NULL, move DstPos to reserve space for the
|
|
|
|
// media header. Add the media header length to buflen.
|
|
|
|
//
|
|
|
|
DstPos += SnpMode->MediaHeaderSize;
|
|
|
|
*PktLen += SnpMode->MediaHeaderSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < TxData->FragmentCount; Index++) {
|
|
|
|
//
|
|
|
|
// Copy the data.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (
|
2007-07-24 10:06:37 +02:00
|
|
|
DstPos,
|
|
|
|
TxData->FragmentTable[Index].FragmentBuffer,
|
|
|
|
TxData->FragmentTable[Index].FragmentLength
|
|
|
|
);
|
|
|
|
DstPos += TxData->FragmentTable[Index].FragmentLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2014-01-06 03:17:12 +01:00
|
|
|
// Set the buffer length.
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
*PktLen += TxData->DataLength + TxData->HeaderLength;
|
|
|
|
}
|
2016-01-08 03:38:34 +01:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-06-27 15:08:52 +02:00
|
|
|
Synchronously send out the packet.
|
2016-01-08 03:38:34 +01:00
|
|
|
|
2020-02-07 02:07:56 +01:00
|
|
|
This function places the packet buffer to SNP driver's tansmit queue. The packet
|
|
|
|
can be considered successfully sent out once SNP accept the packet, while the
|
2016-01-08 03:38:34 +01:00
|
|
|
packet buffer recycle is deferred for better performance.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] MnpServiceData Pointer to the mnp service context data.
|
2020-02-07 02:07:56 +01:00
|
|
|
@param[in] Packet Pointer to the packet buffer.
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] Length The length of the packet.
|
|
|
|
@param[in, out] Token Pointer to the token the packet generated from.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@retval EFI_SUCCESS The packet is sent out.
|
|
|
|
@retval EFI_TIMEOUT Time out occurs, the packet isn't sent.
|
|
|
|
@retval EFI_DEVICE_ERROR An unexpected network error occurs.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
MnpSyncSendPacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_SERVICE_DATA *MnpServiceData,
|
|
|
|
IN UINT8 *Packet,
|
|
|
|
IN UINT32 Length,
|
|
|
|
IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
|
|
|
|
EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData;
|
|
|
|
UINT32 HeaderSize;
|
2009-12-30 14:47:55 +01:00
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
|
|
|
UINT16 ProtocolType;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData = MnpServiceData->MnpDeviceData;
|
|
|
|
Snp = MnpDeviceData->Snp;
|
|
|
|
TxData = Token->Packet.TxData;
|
2016-01-08 03:38:34 +01:00
|
|
|
Token->Status = EFI_SUCCESS;
|
2009-12-30 14:47:55 +01:00
|
|
|
HeaderSize = Snp->Mode->MediaHeaderSize - TxData->HeaderLength;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2010-02-03 05:37:53 +01:00
|
|
|
//
|
|
|
|
// Check media status before transmit packet.
|
|
|
|
// Note: media status will be updated by periodic timer MediaDetectTimer.
|
|
|
|
//
|
2010-03-16 14:16:19 +01:00
|
|
|
if (Snp->Mode->MediaPresentSupported && !Snp->Mode->MediaPresent) {
|
2010-02-03 05:37:53 +01:00
|
|
|
//
|
|
|
|
// Media not present, skip packet transmit and report EFI_NO_MEDIA
|
|
|
|
//
|
2010-03-16 14:16:19 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpSyncSendPacket: No network cable detected.\n"));
|
2016-01-08 03:38:34 +01:00
|
|
|
Token->Status = EFI_NO_MEDIA;
|
2007-07-24 10:06:37 +02:00
|
|
|
goto SIGNAL_TOKEN;
|
|
|
|
}
|
|
|
|
|
2018-06-27 15:08:52 +02:00
|
|
|
|
2013-12-23 09:43:09 +01:00
|
|
|
if (MnpServiceData->VlanId != 0) {
|
|
|
|
//
|
|
|
|
// Insert VLAN tag
|
|
|
|
//
|
|
|
|
MnpInsertVlanTag (MnpServiceData, TxData, &ProtocolType, &Packet, &Length);
|
|
|
|
} else {
|
|
|
|
ProtocolType = TxData->ProtocolType;
|
|
|
|
}
|
2009-12-30 14:47:55 +01:00
|
|
|
|
2016-01-08 03:38:34 +01:00
|
|
|
//
|
|
|
|
// Transmit the packet through SNP.
|
|
|
|
//
|
|
|
|
Status = Snp->Transmit (
|
|
|
|
Snp,
|
|
|
|
HeaderSize,
|
|
|
|
Length,
|
|
|
|
Packet,
|
|
|
|
TxData->SourceAddress,
|
|
|
|
TxData->DestinationAddress,
|
|
|
|
&ProtocolType
|
|
|
|
);
|
|
|
|
if (Status == EFI_NOT_READY) {
|
|
|
|
Status = MnpRecycleTxBuf (MnpDeviceData);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Token->Status = EFI_DEVICE_ERROR;
|
|
|
|
goto SIGNAL_TOKEN;
|
|
|
|
}
|
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
Status = Snp->Transmit (
|
|
|
|
Snp,
|
|
|
|
HeaderSize,
|
|
|
|
Length,
|
|
|
|
Packet,
|
|
|
|
TxData->SourceAddress,
|
|
|
|
TxData->DestinationAddress,
|
2009-12-30 14:47:55 +01:00
|
|
|
&ProtocolType
|
2018-06-27 15:08:52 +02:00
|
|
|
);
|
2016-01-08 03:38:34 +01:00
|
|
|
}
|
2018-06-27 15:08:52 +02:00
|
|
|
|
2016-01-08 03:38:34 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Token->Status = EFI_DEVICE_ERROR;
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SIGNAL_TOKEN:
|
|
|
|
|
|
|
|
gBS->SignalEvent (Token->Event);
|
|
|
|
|
2007-11-20 06:42:23 +01:00
|
|
|
//
|
|
|
|
// Dispatch the DPC queued by the NotifyFunction of Token->Event.
|
|
|
|
//
|
2009-07-12 00:51:51 +02:00
|
|
|
DispatchDpc ();
|
2007-11-20 06:42:23 +01:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Try to deliver the received packet to the instance.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in, out] Instance Pointer to the mnp instance context data.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The received packet is delivered, or there is no
|
|
|
|
packet to deliver, or there is no available receive
|
|
|
|
token.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES The deliver fails due to lack of memory resource.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
MnpInstanceDeliverPacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN OUT MNP_INSTANCE_DATA *Instance
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2009-12-30 14:47:55 +01:00
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
2007-07-24 10:06:37 +02:00
|
|
|
MNP_RXDATA_WRAP *RxDataWrap;
|
|
|
|
NET_BUF *DupNbuf;
|
|
|
|
EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData;
|
|
|
|
EFI_SIMPLE_NETWORK_MODE *SnpMode;
|
|
|
|
EFI_MANAGED_NETWORK_COMPLETION_TOKEN *RxToken;
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;
|
|
|
|
NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
if (NetMapIsEmpty (&Instance->RxTokenMap) || IsListEmpty (&Instance->RcvdPacketQueue)) {
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// No pending received data or no available receive token, return.
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT (Instance->RcvdPacketQueueSize != 0);
|
|
|
|
|
|
|
|
RxDataWrap = NET_LIST_HEAD (&Instance->RcvdPacketQueue, MNP_RXDATA_WRAP, WrapEntry);
|
|
|
|
if (RxDataWrap->Nbuf->RefCnt > 2) {
|
|
|
|
//
|
|
|
|
// There are other instances share this Nbuf, duplicate to get a
|
|
|
|
// copy to allow the instance to do R/W operations.
|
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
DupNbuf = MnpAllocNbuf (MnpDeviceData);
|
2007-07-24 10:06:37 +02:00
|
|
|
if (DupNbuf == NULL) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpDeliverPacket: Failed to allocate a free Nbuf.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Duplicate the net buffer.
|
|
|
|
//
|
|
|
|
NetbufDuplicate (RxDataWrap->Nbuf, DupNbuf, 0);
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);
|
2007-07-24 10:06:37 +02:00
|
|
|
RxDataWrap->Nbuf = DupNbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// All resources are OK, remove the packet from the queue.
|
|
|
|
//
|
|
|
|
NetListRemoveHead (&Instance->RcvdPacketQueue);
|
|
|
|
Instance->RcvdPacketQueueSize--;
|
|
|
|
|
|
|
|
RxData = &RxDataWrap->RxData;
|
2009-12-30 14:47:55 +01:00
|
|
|
SnpMode = MnpDeviceData->Snp->Mode;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Set all the buffer pointers.
|
|
|
|
//
|
|
|
|
RxData->MediaHeader = NetbufGetByte (RxDataWrap->Nbuf, 0, NULL);
|
|
|
|
RxData->DestinationAddress = RxData->MediaHeader;
|
|
|
|
RxData->SourceAddress = (UINT8 *) RxData->MediaHeader + SnpMode->HwAddressSize;
|
|
|
|
RxData->PacketData = (UINT8 *) RxData->MediaHeader + SnpMode->MediaHeaderSize;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Insert this RxDataWrap into the delivered queue.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
InsertTailList (&Instance->RxDeliveredPacketQueue, &RxDataWrap->WrapEntry);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get the receive token from the RxTokenMap.
|
|
|
|
//
|
|
|
|
RxToken = NetMapRemoveHead (&Instance->RxTokenMap, NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Signal this token's event.
|
|
|
|
//
|
|
|
|
RxToken->Packet.RxData = &RxDataWrap->RxData;
|
|
|
|
RxToken->Status = EFI_SUCCESS;
|
|
|
|
gBS->SignalEvent (RxToken->Event);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deliver the received packet for the instances belonging to the MnpServiceData.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] MnpServiceData Pointer to the mnp service context data.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
MnpDeliverPacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_SERVICE_DATA *MnpServiceData
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *Entry;
|
2007-07-24 10:06:37 +02:00
|
|
|
MNP_INSTANCE_DATA *Instance;
|
|
|
|
|
|
|
|
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
|
|
|
|
|
|
|
|
NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
|
|
|
|
Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);
|
|
|
|
NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Try to deliver packet for this instance.
|
|
|
|
//
|
|
|
|
MnpInstanceDeliverPacket (Instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Recycle the RxData and other resources used to hold and deliver the received
|
|
|
|
packet.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] Event The event this notify function registered to.
|
2020-02-07 02:07:56 +01:00
|
|
|
@param[in] Context Pointer to the context data registered to the Event.
|
2009-02-03 08:56:54 +01:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
MnpRecycleRxData (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2009-12-30 14:47:55 +01:00
|
|
|
MNP_RXDATA_WRAP *RxDataWrap;
|
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
ASSERT (Context != NULL);
|
|
|
|
|
|
|
|
RxDataWrap = (MNP_RXDATA_WRAP *) Context;
|
|
|
|
NET_CHECK_SIGNATURE (RxDataWrap->Instance, MNP_INSTANCE_DATA_SIGNATURE);
|
|
|
|
|
|
|
|
ASSERT (RxDataWrap->Nbuf != NULL);
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData = RxDataWrap->Instance->MnpServiceData->MnpDeviceData;
|
|
|
|
NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Free this Nbuf.
|
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);
|
2007-07-24 10:06:37 +02:00
|
|
|
RxDataWrap->Nbuf = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Close the recycle event.
|
|
|
|
//
|
|
|
|
gBS->CloseEvent (RxDataWrap->RxData.RecycleEvent);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Remove this Wrap entry from the list.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
RemoveEntryList (&RxDataWrap->WrapEntry);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-11-13 07:13:59 +01:00
|
|
|
FreePool (RxDataWrap);
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Queue the received packet into instance's receive queue.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in, out] Instance Pointer to the mnp instance context data.
|
|
|
|
@param[in, out] RxDataWrap Pointer to the Wrap structure containing the
|
|
|
|
received data and other information.
|
2007-07-24 10:06:37 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
MnpQueueRcvdPacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN OUT MNP_INSTANCE_DATA *Instance,
|
|
|
|
IN OUT MNP_RXDATA_WRAP *RxDataWrap
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
MNP_RXDATA_WRAP *OldRxDataWrap;
|
|
|
|
|
|
|
|
NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check the queue size. If it exceeds the limit, drop one packet
|
|
|
|
// from the head.
|
|
|
|
//
|
|
|
|
if (Instance->RcvdPacketQueueSize == MNP_MAX_RCVD_PACKET_QUE_SIZE) {
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpQueueRcvdPacket: Drop one packet bcz queue size limit reached.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get the oldest packet.
|
|
|
|
//
|
|
|
|
OldRxDataWrap = NET_LIST_HEAD (
|
|
|
|
&Instance->RcvdPacketQueue,
|
|
|
|
MNP_RXDATA_WRAP,
|
|
|
|
WrapEntry
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Recycle this OldRxDataWrap, this entry will be removed by the callee.
|
|
|
|
//
|
|
|
|
MnpRecycleRxData (NULL, (VOID *) OldRxDataWrap);
|
|
|
|
Instance->RcvdPacketQueueSize--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Update the timeout tick using the configured parameter.
|
|
|
|
//
|
|
|
|
RxDataWrap->TimeoutTick = Instance->ConfigData.ReceivedQueueTimeoutValue;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Insert this Wrap into the instance queue.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
InsertTailList (&Instance->RcvdPacketQueue, &RxDataWrap->WrapEntry);
|
2007-07-24 10:06:37 +02:00
|
|
|
Instance->RcvdPacketQueueSize++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Match the received packet with the instance receive filters.
|
|
|
|
|
2009-01-16 01:09:52 +01:00
|
|
|
@param[in] Instance Pointer to the mnp instance context data.
|
|
|
|
@param[in] RxData Pointer to the EFI_MANAGED_NETWORK_RECEIVE_DATA.
|
|
|
|
@param[in] GroupAddress Pointer to the GroupAddress, the GroupAddress is
|
2007-07-24 10:06:37 +02:00
|
|
|
non-NULL and it contains the destination multicast
|
|
|
|
mac address of the received packet if the packet
|
|
|
|
destinated to a multicast mac address.
|
2009-01-16 01:09:52 +01:00
|
|
|
@param[in] PktAttr The received packets attribute.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@return The received packet matches the instance's receive filters or not.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
MnpMatchPacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_INSTANCE_DATA *Instance,
|
|
|
|
IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,
|
|
|
|
IN MNP_GROUP_ADDRESS *GroupAddress OPTIONAL,
|
|
|
|
IN UINT8 PktAttr
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData;
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *Entry;
|
2007-07-24 10:06:37 +02:00
|
|
|
MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;
|
|
|
|
|
|
|
|
NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
|
|
|
|
|
|
|
|
ConfigData = &Instance->ConfigData;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check the protocol type.
|
|
|
|
//
|
|
|
|
if ((ConfigData->ProtocolTypeFilter != 0) && (ConfigData->ProtocolTypeFilter != RxData->ProtocolType)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-11-20 06:42:23 +01:00
|
|
|
if (ConfigData->EnablePromiscuousReceive) {
|
|
|
|
//
|
|
|
|
// Always match if this instance is configured to be promiscuous.
|
|
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// The protocol type is matched, check receive filter, include unicast and broadcast.
|
|
|
|
//
|
|
|
|
if ((Instance->ReceiveFilter & PktAttr) != 0) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check multicast addresses.
|
|
|
|
//
|
|
|
|
if (ConfigData->EnableMulticastReceive && RxData->MulticastFlag) {
|
|
|
|
|
|
|
|
ASSERT (GroupAddress != NULL);
|
|
|
|
|
|
|
|
NET_LIST_FOR_EACH (Entry, &Instance->GroupCtrlBlkList) {
|
|
|
|
|
|
|
|
GroupCtrlBlk = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_CONTROL_BLOCK, CtrlBlkEntry);
|
|
|
|
if (GroupCtrlBlk->GroupAddress == GroupAddress) {
|
|
|
|
//
|
|
|
|
// The instance is configured to receiveing packets destinated to this
|
|
|
|
// multicast address.
|
|
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// No match.
|
|
|
|
//
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Analyse the received packets.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] MnpServiceData Pointer to the mnp service context data.
|
|
|
|
@param[in] Nbuf Pointer to the net buffer holding the received
|
|
|
|
packet.
|
|
|
|
@param[in, out] RxData Pointer to the buffer used to save the analysed
|
|
|
|
result in EFI_MANAGED_NETWORK_RECEIVE_DATA.
|
|
|
|
@param[out] GroupAddress Pointer to pointer to a MNP_GROUP_ADDRESS used to
|
|
|
|
pass out the address of the multicast address the
|
|
|
|
received packet destinated to.
|
|
|
|
@param[out] PktAttr Pointer to the buffer used to save the analysed
|
|
|
|
packet attribute.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
MnpAnalysePacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_SERVICE_DATA *MnpServiceData,
|
|
|
|
IN NET_BUF *Nbuf,
|
|
|
|
IN OUT EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,
|
|
|
|
OUT MNP_GROUP_ADDRESS **GroupAddress,
|
|
|
|
OUT UINT8 *PktAttr
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_SIMPLE_NETWORK_MODE *SnpMode;
|
2009-12-30 14:47:55 +01:00
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
2007-07-24 10:06:37 +02:00
|
|
|
UINT8 *BufPtr;
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *Entry;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData = MnpServiceData->MnpDeviceData;
|
|
|
|
SnpMode = MnpDeviceData->Snp->Mode;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get the packet buffer.
|
|
|
|
//
|
|
|
|
BufPtr = NetbufGetByte (Nbuf, 0, NULL);
|
|
|
|
ASSERT (BufPtr != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set the initial values.
|
|
|
|
//
|
|
|
|
RxData->BroadcastFlag = FALSE;
|
|
|
|
RxData->MulticastFlag = FALSE;
|
|
|
|
RxData->PromiscuousFlag = FALSE;
|
|
|
|
*PktAttr = UNICAST_PACKET;
|
|
|
|
|
|
|
|
if (!NET_MAC_EQUAL (&SnpMode->CurrentAddress, BufPtr, SnpMode->HwAddressSize)) {
|
|
|
|
//
|
|
|
|
// This packet isn't destinated to our current mac address, it't not unicast.
|
|
|
|
//
|
|
|
|
*PktAttr = 0;
|
|
|
|
|
|
|
|
if (NET_MAC_EQUAL (&SnpMode->BroadcastAddress, BufPtr, SnpMode->HwAddressSize)) {
|
|
|
|
//
|
|
|
|
// It's broadcast.
|
|
|
|
//
|
|
|
|
RxData->BroadcastFlag = TRUE;
|
|
|
|
*PktAttr = BROADCAST_PACKET;
|
|
|
|
} else if ((*BufPtr & 0x01) == 0x1) {
|
|
|
|
//
|
|
|
|
// It's multicast, try to match the multicast filters.
|
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
NET_LIST_FOR_EACH (Entry, &MnpDeviceData->GroupAddressList) {
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
*GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);
|
|
|
|
if (NET_MAC_EQUAL (BufPtr, &((*GroupAddress)->Address), SnpMode->HwAddressSize)) {
|
|
|
|
RxData->MulticastFlag = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RxData->MulticastFlag) {
|
|
|
|
//
|
|
|
|
// No match, set GroupAddress to NULL. This multicast packet must
|
|
|
|
// be the result of PROMISUCOUS or PROMISUCOUS_MULTICAST flag is on.
|
|
|
|
//
|
|
|
|
*GroupAddress = NULL;
|
|
|
|
RxData->PromiscuousFlag = TRUE;
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
if (MnpDeviceData->PromiscuousCount == 0) {
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// Skip the below code, there is no receiver of this packet.
|
|
|
|
//
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RxData->PromiscuousFlag = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
ZeroMem (&RxData->Timestamp, sizeof (EFI_TIME));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Fill the common parts of RxData.
|
|
|
|
//
|
|
|
|
RxData->PacketLength = Nbuf->TotalSize;
|
|
|
|
RxData->HeaderLength = SnpMode->MediaHeaderSize;
|
|
|
|
RxData->AddressLength = SnpMode->HwAddressSize;
|
|
|
|
RxData->DataLength = RxData->PacketLength - RxData->HeaderLength;
|
|
|
|
RxData->ProtocolType = NTOHS (*(UINT16 *) (BufPtr + 2 * SnpMode->HwAddressSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wrap the RxData.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] Instance Pointer to the mnp instance context data.
|
|
|
|
@param[in] RxData Pointer to the receive data to wrap.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@return Pointer to a MNP_RXDATA_WRAP which wraps the RxData.
|
|
|
|
|
|
|
|
**/
|
|
|
|
MNP_RXDATA_WRAP *
|
|
|
|
MnpWrapRxData (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_INSTANCE_DATA *Instance,
|
|
|
|
IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
MNP_RXDATA_WRAP *RxDataWrap;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate memory.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
RxDataWrap = AllocatePool (sizeof (MNP_RXDATA_WRAP));
|
2007-07-24 10:06:37 +02:00
|
|
|
if (RxDataWrap == NULL) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: Failed to allocate a MNP_RXDATA_WRAP.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RxDataWrap->Instance = Instance;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill the RxData in RxDataWrap,
|
|
|
|
//
|
2007-08-23 04:19:41 +02:00
|
|
|
CopyMem (&RxDataWrap->RxData, RxData, sizeof (RxDataWrap->RxData));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Create the recycle event.
|
|
|
|
//
|
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-02-14 10:40:22 +01:00
|
|
|
TPL_NOTIFY,
|
2007-07-24 10:06:37 +02:00
|
|
|
MnpRecycleRxData,
|
|
|
|
RxDataWrap,
|
|
|
|
&RxDataWrap->RxData.RecycleEvent
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status));
|
2009-12-30 14:47:55 +01:00
|
|
|
|
2009-11-13 07:13:59 +01:00
|
|
|
FreePool (RxDataWrap);
|
2007-07-24 10:06:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RxDataWrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enqueue the received the packets to the instances belonging to the
|
|
|
|
MnpServiceData.
|
|
|
|
|
2009-02-03 08:56:54 +01:00
|
|
|
@param[in] MnpServiceData Pointer to the mnp service context data.
|
|
|
|
@param[in] Nbuf Pointer to the net buffer representing the received
|
|
|
|
packet.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
MnpEnqueuePacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN MNP_SERVICE_DATA *MnpServiceData,
|
|
|
|
IN NET_BUF *Nbuf
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *Entry;
|
2007-07-24 10:06:37 +02:00
|
|
|
MNP_INSTANCE_DATA *Instance;
|
|
|
|
EFI_MANAGED_NETWORK_RECEIVE_DATA RxData;
|
|
|
|
UINT8 PktAttr;
|
|
|
|
MNP_GROUP_ADDRESS *GroupAddress;
|
|
|
|
MNP_RXDATA_WRAP *RxDataWrap;
|
|
|
|
|
2007-10-09 11:30:52 +02:00
|
|
|
|
|
|
|
GroupAddress = NULL;
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// First, analyse the packet header.
|
|
|
|
//
|
|
|
|
MnpAnalysePacket (MnpServiceData, Nbuf, &RxData, &GroupAddress, &PktAttr);
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
if (RxData.PromiscuousFlag && (MnpServiceData->MnpDeviceData->PromiscuousCount == 0)) {
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// No receivers, no more action need.
|
|
|
|
//
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Iterate the children to find match.
|
|
|
|
//
|
|
|
|
NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
|
|
|
|
|
|
|
|
Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);
|
|
|
|
NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
|
|
|
|
|
|
|
|
if (!Instance->Configured) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check the packet against the instance receive filters.
|
|
|
|
//
|
|
|
|
if (MnpMatchPacket (Instance, &RxData, GroupAddress, PktAttr)) {
|
|
|
|
//
|
|
|
|
// Wrap the RxData.
|
|
|
|
//
|
2007-08-23 04:19:41 +02:00
|
|
|
RxDataWrap = MnpWrapRxData (Instance, &RxData);
|
2007-07-24 10:06:37 +02:00
|
|
|
if (RxDataWrap == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Associate RxDataWrap with Nbuf and increase the RefCnt.
|
|
|
|
//
|
|
|
|
RxDataWrap->Nbuf = Nbuf;
|
|
|
|
NET_GET_REF (RxDataWrap->Nbuf);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Queue the packet into the instance queue.
|
|
|
|
//
|
|
|
|
MnpQueueRcvdPacket (Instance, RxDataWrap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Try to receive a packet and deliver it.
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS add return value to function comment
|
|
|
|
@retval EFI_NOT_STARTED The simple network protocol is not started.
|
|
|
|
@retval EFI_NOT_READY No packet received.
|
|
|
|
@retval EFI_DEVICE_ERROR An unexpected error occurs.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
MnpReceivePacket (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN OUT MNP_DEVICE_DATA *MnpDeviceData
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
|
|
|
|
NET_BUF *Nbuf;
|
|
|
|
UINT8 *BufPtr;
|
|
|
|
UINTN BufLen;
|
|
|
|
UINTN HeaderSize;
|
|
|
|
UINT32 Trimmed;
|
2009-12-30 14:47:55 +01:00
|
|
|
MNP_SERVICE_DATA *MnpServiceData;
|
|
|
|
UINT16 VlanId;
|
|
|
|
BOOLEAN IsVlanPacket;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
Snp = MnpDeviceData->Snp;
|
2007-07-24 10:06:37 +02:00
|
|
|
if (Snp->Mode->State != EfiSimpleNetworkInitialized) {
|
|
|
|
//
|
|
|
|
// The simple network protocol is not started.
|
|
|
|
//
|
|
|
|
return EFI_NOT_STARTED;
|
|
|
|
}
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
if (MnpDeviceData->RxNbufCache == NULL) {
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// Try to get a new buffer as there may be buffers recycled.
|
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData->RxNbufCache = MnpAllocNbuf (MnpDeviceData);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
if (MnpDeviceData->RxNbufCache == NULL) {
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
2016-07-08 08:21:04 +02:00
|
|
|
// No available buffer in the buffer pool.
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
NetbufAllocSpace (
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData->RxNbufCache,
|
|
|
|
MnpDeviceData->BufferLength,
|
2007-07-24 10:06:37 +02:00
|
|
|
NET_BUF_TAIL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
Nbuf = MnpDeviceData->RxNbufCache;
|
2007-07-24 10:06:37 +02:00
|
|
|
BufLen = Nbuf->TotalSize;
|
|
|
|
BufPtr = NetbufGetByte (Nbuf, 0, NULL);
|
|
|
|
ASSERT (BufPtr != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Receive packet through Snp.
|
|
|
|
//
|
|
|
|
Status = Snp->Receive (Snp, &HeaderSize, &BufLen, BufPtr, NULL, NULL, NULL);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG_CODE (
|
|
|
|
if (Status != EFI_NOT_READY) {
|
2008-04-02 10:45:36 +02:00
|
|
|
DEBUG ((EFI_D_WARN, "MnpReceivePacket: Snp->Receive() = %r.\n", Status));
|
|
|
|
}
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Sanity check.
|
|
|
|
//
|
|
|
|
if ((HeaderSize != Snp->Mode->MediaHeaderSize) || (BufLen < HeaderSize)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG (
|
|
|
|
(EFI_D_WARN,
|
|
|
|
"MnpReceivePacket: Size error, HL:TL = %d:%d.\n",
|
2007-07-24 10:06:37 +02:00
|
|
|
HeaderSize,
|
|
|
|
BufLen)
|
|
|
|
);
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Trimmed = 0;
|
|
|
|
if (Nbuf->TotalSize != BufLen) {
|
|
|
|
//
|
|
|
|
// Trim the packet from tail.
|
|
|
|
//
|
|
|
|
Trimmed = NetbufTrim (Nbuf, Nbuf->TotalSize - (UINT32) BufLen, NET_BUF_TAIL);
|
|
|
|
ASSERT (Nbuf->TotalSize == BufLen);
|
|
|
|
}
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
VlanId = 0;
|
2010-08-04 03:15:50 +02:00
|
|
|
if (MnpDeviceData->NumberOfVlan != 0) {
|
|
|
|
//
|
|
|
|
// VLAN is configured, remove the VLAN tag if any
|
|
|
|
//
|
|
|
|
IsVlanPacket = MnpRemoveVlanTag (MnpDeviceData, Nbuf, &VlanId);
|
|
|
|
} else {
|
|
|
|
IsVlanPacket = FALSE;
|
|
|
|
}
|
2009-12-30 14:47:55 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// Enqueue the packet to the matched instances.
|
|
|
|
//
|
|
|
|
MnpEnqueuePacket (MnpServiceData, Nbuf);
|
|
|
|
|
|
|
|
if (Nbuf->RefCnt > 2) {
|
|
|
|
//
|
|
|
|
// RefCnt > 2 indicates there is at least one receiver of this packet.
|
|
|
|
// Free the current RxNbufCache and allocate a new one.
|
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpFreeNbuf (MnpDeviceData, Nbuf);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
Nbuf = MnpAllocNbuf (MnpDeviceData);
|
|
|
|
MnpDeviceData->RxNbufCache = Nbuf;
|
2007-07-24 10:06:37 +02:00
|
|
|
if (Nbuf == NULL) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "MnpReceivePacket: Alloc packet for receiving cache failed.\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
NetbufAllocSpace (Nbuf, MnpDeviceData->BufferLength, NET_BUF_TAIL);
|
2007-07-24 10:06:37 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// No receiver for this packet.
|
|
|
|
//
|
2007-07-30 04:37:10 +02:00
|
|
|
if (Trimmed > 0) {
|
|
|
|
NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);
|
|
|
|
}
|
2009-12-30 14:47:55 +01:00
|
|
|
if (IsVlanPacket) {
|
|
|
|
NetbufAllocSpace (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);
|
|
|
|
}
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Deliver the queued packets.
|
|
|
|
//
|
|
|
|
MnpDeliverPacket (MnpServiceData);
|
|
|
|
|
|
|
|
EXIT:
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
ASSERT (Nbuf->TotalSize == MnpDeviceData->BufferLength);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Remove the received packets if timeout occurs.
|
|
|
|
|
2010-02-03 05:37:53 +01:00
|
|
|
@param[in] Event The event this notify function registered to.
|
|
|
|
@param[in] Context Pointer to the context data registered to the event.
|
2009-12-30 14:47:55 +01:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
MnpCheckPacketTimeout (
|
2009-12-30 14:47:55 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2009-12-30 14:47:55 +01:00
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
2007-07-24 10:06:37 +02:00
|
|
|
MNP_SERVICE_DATA *MnpServiceData;
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *Entry;
|
2009-12-30 14:47:55 +01:00
|
|
|
LIST_ENTRY *ServiceEntry;
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *RxEntry;
|
|
|
|
LIST_ENTRY *NextEntry;
|
2007-07-24 10:06:37 +02:00
|
|
|
MNP_INSTANCE_DATA *Instance;
|
|
|
|
MNP_RXDATA_WRAP *RxDataWrap;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData = (MNP_DEVICE_DATA *) Context;
|
|
|
|
NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
NET_LIST_FOR_EACH (ServiceEntry, &MnpDeviceData->ServiceList) {
|
|
|
|
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (ServiceEntry);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);
|
|
|
|
NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
if (!Instance->Configured || (Instance->ConfigData.ReceivedQueueTimeoutValue == 0)) {
|
|
|
|
//
|
|
|
|
// This instance is not configured or there is no receive time out,
|
|
|
|
// just skip to the next instance.
|
|
|
|
//
|
|
|
|
continue;
|
|
|
|
}
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
// TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
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--;
|
|
|
|
}
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
}
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:37:53 +01:00
|
|
|
/**
|
|
|
|
Poll to update MediaPresent field in SNP ModeData by Snp->GetStatus().
|
|
|
|
|
|
|
|
@param[in] Event The event this notify function registered to.
|
|
|
|
@param[in] Context Pointer to the context data registered to the event.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
MnpCheckMediaStatus (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
|
|
|
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
|
|
|
|
UINT32 InterruptStatus;
|
|
|
|
|
|
|
|
MnpDeviceData = (MNP_DEVICE_DATA *) Context;
|
|
|
|
NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
|
|
|
|
|
|
|
|
Snp = MnpDeviceData->Snp;
|
|
|
|
if (Snp->Mode->MediaPresentSupported) {
|
|
|
|
//
|
|
|
|
// Upon successful return of GetStatus(), the MediaPresent field of
|
|
|
|
// EFI_SIMPLE_NETWORK_MODE will be updated to reflect any change of media status
|
|
|
|
//
|
|
|
|
Snp->GetStatus (Snp, &InterruptStatus, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
/**
|
|
|
|
Poll to receive the packets from Snp. This function is either called by upperlayer
|
|
|
|
protocols/applications or the system poll timer notify mechanism.
|
|
|
|
|
2010-02-03 05:37:53 +01:00
|
|
|
@param[in] Event The event this notify function registered to.
|
|
|
|
@param[in] Context Pointer to the context data registered to the event.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
MnpSystemPoll (
|
2010-02-03 05:37:53 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2009-12-30 14:47:55 +01:00
|
|
|
MNP_DEVICE_DATA *MnpDeviceData;
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpDeviceData = (MNP_DEVICE_DATA *) Context;
|
|
|
|
NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Try to receive packets from Snp.
|
|
|
|
//
|
2009-12-30 14:47:55 +01:00
|
|
|
MnpReceivePacket (MnpDeviceData);
|
2007-11-20 06:42:23 +01:00
|
|
|
|
2009-07-10 08:59:07 +02:00
|
|
|
//
|
|
|
|
// Dispatch the DPC queued by the NotifyFunction of rx token's events.
|
|
|
|
//
|
2009-07-12 00:51:51 +02:00
|
|
|
DispatchDpc ();
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|