33 MnpServiceData = Instance->MnpServiceData;
34 NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
36 TxData = Token->Packet.TxData;
38 if ((Token->Event ==
NULL) || (TxData ==
NULL) || (TxData->FragmentCount == 0)) {
43 DEBUG ((DEBUG_WARN,
"MnpIsValidTxToken: Invalid Token.\n"));
47 if ((TxData->DestinationAddress !=
NULL) && (TxData->HeaderLength != 0)) {
52 DEBUG ((DEBUG_WARN,
"MnpIsValidTxToken: DestinationAddress isn't NULL, HeaderLength must be 0.\n"));
57 FragmentTable = TxData->FragmentTable;
58 for (Index = 0; Index < TxData->FragmentCount; Index++) {
59 if ((FragmentTable[Index].FragmentLength == 0) || (FragmentTable[Index].FragmentBuffer ==
NULL)) {
63 DEBUG ((DEBUG_WARN,
"MnpIsValidTxToken: Invalid FragmentLength or FragmentBuffer.\n"));
67 TotalLength += FragmentTable[Index].FragmentLength;
70 if ((TxData->DestinationAddress ==
NULL) && (FragmentTable[0].FragmentLength < TxData->HeaderLength)) {
77 if (TotalLength != (TxData->DataLength + TxData->HeaderLength)) {
82 DEBUG ((DEBUG_WARN,
"MnpIsValidTxData: Invalid Datalength compared with the sum of fragment length.\n"));
86 if (TxData->DataLength > MnpServiceData->Mtu) {
90 DEBUG ((DEBUG_WARN,
"MnpIsValidTxData: TxData->DataLength exceeds Mtu.\n"));
125 MnpDeviceData = MnpServiceData->MnpDeviceData;
129 return EFI_OUT_OF_RESOURCES;
135 if (MnpServiceData->VlanId != 0) {
136 *PktBuf = TxBuf + NET_VLAN_TAG_LEN;
141 if ((TxData->DestinationAddress ==
NULL) && (TxData->FragmentCount == 1)) {
144 TxData->FragmentTable[0].FragmentBuffer,
145 TxData->FragmentTable[0].FragmentLength
148 *PktLen = TxData->FragmentTable[0].FragmentLength;
155 SnpMode = MnpDeviceData->Snp->
Mode;
158 if (TxData->DestinationAddress !=
NULL) {
167 for (Index = 0; Index < TxData->FragmentCount; Index++) {
173 TxData->FragmentTable[Index].FragmentBuffer,
174 TxData->FragmentTable[Index].FragmentLength
176 DstPos += TxData->FragmentTable[Index].FragmentLength;
182 *PktLen += TxData->DataLength + TxData->HeaderLength;
220 MnpDeviceData = MnpServiceData->MnpDeviceData;
221 Snp = MnpDeviceData->Snp;
222 TxData = Token->Packet.TxData;
234 DEBUG ((DEBUG_WARN,
"MnpSyncSendPacket: No network cable detected.\n"));
235 Token->Status = EFI_NO_MEDIA;
239 if (MnpServiceData->VlanId != 0) {
245 ProtocolType = TxData->ProtocolType;
251 Status = Snp->Transmit (
256 TxData->SourceAddress,
257 TxData->DestinationAddress,
260 if (Status == EFI_NOT_READY) {
262 if (EFI_ERROR (Status)) {
263 Token->Status = EFI_DEVICE_ERROR;
267 Status = Snp->Transmit (
272 TxData->SourceAddress,
273 TxData->DestinationAddress,
278 if (EFI_ERROR (Status)) {
279 Token->Status = EFI_DEVICE_ERROR;
284 gBS->SignalEvent (Token->Event);
317 MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;
318 NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
327 ASSERT (Instance->RcvdPacketQueueSize != 0);
329 RxDataWrap = NET_LIST_HEAD (&Instance->RcvdPacketQueue,
MNP_RXDATA_WRAP, WrapEntry);
330 if (RxDataWrap->Nbuf->RefCnt > 2) {
336 if (DupNbuf ==
NULL) {
337 DEBUG ((DEBUG_WARN,
"MnpDeliverPacket: Failed to allocate a free Nbuf.\n"));
339 return EFI_OUT_OF_RESOURCES;
347 RxDataWrap->Nbuf = DupNbuf;
354 Instance->RcvdPacketQueueSize--;
356 RxData = &RxDataWrap->RxData;
357 SnpMode = MnpDeviceData->Snp->
Mode;
363 RxData->DestinationAddress = RxData->MediaHeader;
364 RxData->SourceAddress = (UINT8 *)RxData->MediaHeader + SnpMode->
HwAddressSize;
365 RxData->PacketData = (UINT8 *)RxData->MediaHeader + SnpMode->
MediaHeaderSize;
370 InsertTailList (&Instance->RxDeliveredPacketQueue, &RxDataWrap->WrapEntry);
380 RxToken->Packet.
RxData = &RxDataWrap->RxData;
401 NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
403 NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
405 NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
432 ASSERT (Context !=
NULL);
435 NET_CHECK_SIGNATURE (RxDataWrap->Instance, MNP_INSTANCE_DATA_SIGNATURE);
437 ASSERT (RxDataWrap->Nbuf !=
NULL);
439 MnpDeviceData = RxDataWrap->Instance->MnpServiceData->MnpDeviceData;
440 NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
446 RxDataWrap->Nbuf =
NULL;
451 gBS->CloseEvent (RxDataWrap->RxData.RecycleEvent);
476 NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
482 if (Instance->RcvdPacketQueueSize == MNP_MAX_RCVD_PACKET_QUE_SIZE) {
483 DEBUG ((DEBUG_WARN,
"MnpQueueRcvdPacket: Drop one packet bcz queue size limit reached.\n"));
488 OldRxDataWrap = NET_LIST_HEAD (
489 &Instance->RcvdPacketQueue,
498 Instance->RcvdPacketQueueSize--;
504 RxDataWrap->TimeoutTick = Instance->ConfigData.ReceivedQueueTimeoutValue;
509 InsertTailList (&Instance->RcvdPacketQueue, &RxDataWrap->WrapEntry);
510 Instance->RcvdPacketQueueSize++;
539 NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
541 ConfigData = &Instance->ConfigData;
560 if ((Instance->ReceiveFilter & PktAttr) != 0) {
568 ASSERT (GroupAddress !=
NULL);
570 NET_LIST_FOR_EACH (Entry, &Instance->GroupCtrlBlkList) {
572 if (GroupCtrlBlk->GroupAddress == GroupAddress) {
617 MnpDeviceData = MnpServiceData->MnpDeviceData;
618 SnpMode = MnpDeviceData->Snp->
Mode;
624 ASSERT (BufPtr !=
NULL);
629 RxData->BroadcastFlag =
FALSE;
630 RxData->MulticastFlag =
FALSE;
631 RxData->PromiscuousFlag =
FALSE;
632 *PktAttr = UNICAST_PACKET;
644 RxData->BroadcastFlag =
TRUE;
645 *PktAttr = BROADCAST_PACKET;
646 }
else if ((*BufPtr & 0x01) == 0x1) {
650 NET_LIST_FOR_EACH (Entry, &MnpDeviceData->GroupAddressList) {
652 if (NET_MAC_EQUAL (BufPtr, &((*GroupAddress)->Address), SnpMode->
HwAddressSize)) {
653 RxData->MulticastFlag =
TRUE;
658 if (!RxData->MulticastFlag) {
663 *GroupAddress =
NULL;
664 RxData->PromiscuousFlag =
TRUE;
666 if (MnpDeviceData->PromiscuousCount == 0) {
674 RxData->PromiscuousFlag =
TRUE;
683 RxData->PacketLength = Nbuf->TotalSize;
686 RxData->DataLength = RxData->PacketLength - RxData->HeaderLength;
687 RxData->ProtocolType = NTOHS (*(UINT16 *)(BufPtr + 2 * SnpMode->
HwAddressSize));
712 if (RxDataWrap ==
NULL) {
713 DEBUG ((DEBUG_ERROR,
"MnpDispatchPacket: Failed to allocate a MNP_RXDATA_WRAP.\n"));
717 RxDataWrap->Instance = Instance;
722 CopyMem (&RxDataWrap->RxData, RxData, sizeof (RxDataWrap->RxData));
727 Status =
gBS->CreateEvent (
732 &RxDataWrap->RxData.RecycleEvent
734 if (EFI_ERROR (Status)) {
735 DEBUG ((DEBUG_ERROR,
"MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status));
772 if (RxData.PromiscuousFlag && (MnpServiceData->MnpDeviceData->PromiscuousCount == 0)) {
782 NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
784 NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
786 if (!Instance->Configured) {
798 if (RxDataWrap ==
NULL) {
805 RxDataWrap->Nbuf = Nbuf;
806 NET_GET_REF (RxDataWrap->Nbuf);
841 BOOLEAN IsVlanPacket;
843 NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
845 Snp = MnpDeviceData->Snp;
846 if (Snp->
Mode->
State != EfiSimpleNetworkInitialized) {
850 return EFI_NOT_STARTED;
853 if (MnpDeviceData->RxNbufCache ==
NULL) {
857 MnpDeviceData->RxNbufCache =
MnpAllocNbuf (MnpDeviceData);
859 if (MnpDeviceData->RxNbufCache ==
NULL) {
863 return EFI_DEVICE_ERROR;
867 MnpDeviceData->RxNbufCache,
868 MnpDeviceData->BufferLength,
873 Nbuf = MnpDeviceData->RxNbufCache;
874 BufLen = Nbuf->TotalSize;
876 ASSERT (BufPtr !=
NULL);
881 Status = Snp->Receive (Snp, &HeaderSize, &BufLen, BufPtr,
NULL,
NULL,
NULL);
882 if (EFI_ERROR (Status)) {
884 if (Status != EFI_NOT_READY) {
885 DEBUG ((DEBUG_WARN,
"MnpReceivePacket: Snp->Receive() = %r.\n", Status));
899 "MnpReceivePacket: Size error, HL:TL = %d:%d.\n",
903 return EFI_DEVICE_ERROR;
907 if (Nbuf->TotalSize != BufLen) {
911 Trimmed =
NetbufTrim (Nbuf, Nbuf->TotalSize - (UINT32)BufLen, NET_BUF_TAIL);
912 ASSERT (Nbuf->TotalSize == BufLen);
916 if (MnpDeviceData->NumberOfVlan != 0) {
922 IsVlanPacket =
FALSE;
926 if (MnpServiceData ==
NULL) {
946 if (Nbuf->RefCnt > 2) {
954 MnpDeviceData->RxNbufCache = Nbuf;
956 DEBUG ((DEBUG_ERROR,
"MnpReceivePacket: Alloc packet for receiving cache failed.\n"));
957 return EFI_DEVICE_ERROR;
983 ASSERT (Nbuf->TotalSize == MnpDeviceData->BufferLength);
1013 NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
1015 NET_LIST_FOR_EACH (ServiceEntry, &MnpDeviceData->ServiceList) {
1016 MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (ServiceEntry);
1018 NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {
1020 NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);
1030 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1032 NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {
1033 RxDataWrap = NET_LIST_USER_STRUCT (RxEntry,
MNP_RXDATA_WRAP, WrapEntry);
1038 if (RxDataWrap->TimeoutTick >= (MNP_TIMEOUT_CHECK_INTERVAL / 10)) {
1039 RxDataWrap->TimeoutTick -= (MNP_TIMEOUT_CHECK_INTERVAL / 10);
1044 DEBUG ((DEBUG_WARN,
"MnpCheckPacketTimeout: Received packet timeout.\n"));
1046 Instance->RcvdPacketQueueSize--;
1050 gBS->RestoreTPL (OldTpl);
1071 UINT32 InterruptStatus;
1074 NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
1076 Snp = MnpDeviceData->Snp;
1082 Snp->GetStatus (Snp, &InterruptStatus,
NULL);
1104 NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI DispatchDpc(VOID)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
MNP_SERVICE_DATA * MnpFindServiceData(IN MNP_DEVICE_DATA *MnpDeviceData, IN UINT16 VlanId)
UINT8 * MnpAllocTxBuf(IN OUT MNP_DEVICE_DATA *MnpDeviceData)
VOID MnpFreeNbuf(IN OUT MNP_DEVICE_DATA *MnpDeviceData, IN OUT NET_BUF *Nbuf)
EFI_STATUS MnpRecycleTxBuf(IN OUT MNP_DEVICE_DATA *MnpDeviceData)
NET_BUF * MnpAllocNbuf(IN OUT MNP_DEVICE_DATA *MnpDeviceData)
MNP_RXDATA_WRAP * MnpWrapRxData(IN MNP_INSTANCE_DATA *Instance, IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData)
VOID EFIAPI MnpCheckMediaStatus(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS MnpSyncSendPacket(IN MNP_SERVICE_DATA *MnpServiceData, IN UINT8 *Packet, IN UINT32 Length, IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token)
EFI_STATUS MnpReceivePacket(IN OUT MNP_DEVICE_DATA *MnpDeviceData)
EFI_STATUS MnpInstanceDeliverPacket(IN OUT MNP_INSTANCE_DATA *Instance)
BOOLEAN MnpMatchPacket(IN MNP_INSTANCE_DATA *Instance, IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData, IN MNP_GROUP_ADDRESS *GroupAddress OPTIONAL, IN UINT8 PktAttr)
VOID EFIAPI MnpRecycleRxData(IN EFI_EVENT Event, IN VOID *Context)
BOOLEAN MnpIsValidTxToken(IN MNP_INSTANCE_DATA *Instance, IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token)
VOID EFIAPI MnpSystemPoll(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS MnpBuildTxPacket(IN MNP_SERVICE_DATA *MnpServiceData, IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData, OUT UINT8 **PktBuf, OUT UINT32 *PktLen)
VOID MnpDeliverPacket(IN MNP_SERVICE_DATA *MnpServiceData)
VOID EFIAPI MnpCheckPacketTimeout(IN EFI_EVENT Event, IN VOID *Context)
VOID MnpEnqueuePacket(IN MNP_SERVICE_DATA *MnpServiceData, IN NET_BUF *Nbuf)
VOID MnpQueueRcvdPacket(IN OUT MNP_INSTANCE_DATA *Instance, IN OUT MNP_RXDATA_WRAP *RxDataWrap)
VOID MnpAnalysePacket(IN MNP_SERVICE_DATA *MnpServiceData, IN NET_BUF *Nbuf, IN OUT EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData, OUT MNP_GROUP_ADDRESS **GroupAddress, OUT UINT8 *PktAttr)
BOOLEAN MnpRemoveVlanTag(IN OUT MNP_DEVICE_DATA *MnpDeviceData, IN OUT NET_BUF *Nbuf, OUT UINT16 *VlanId)
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)
LIST_ENTRY *EFIAPI NetListRemoveHead(IN OUT LIST_ENTRY *Head)
UINT32 EFIAPI NetbufTrim(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)
UINT8 *EFIAPI NetbufAllocSpace(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)
NET_BUF *EFIAPI NetbufDuplicate(IN NET_BUF *Nbuf, IN OUT NET_BUF *Duplicate OPTIONAL, IN UINT32 HeadSpace)
BOOLEAN EFIAPI NetMapIsEmpty(IN NET_MAP *Map)
UINT8 *EFIAPI NetbufGetByte(IN NET_BUF *Nbuf, IN UINT32 Offset, OUT UINT32 *Index OPTIONAL)
VOID *EFIAPI NetMapRemoveHead(IN OUT NET_MAP *Map, OUT VOID **Value OPTIONAL)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
#define SIGNAL_TOKEN(Token, TokenStatus)
EFI_SIMPLE_NETWORK_MODE * Mode
EFI_MANAGED_NETWORK_RECEIVE_DATA * RxData
BOOLEAN EnableMulticastReceive
UINT32 ReceivedQueueTimeoutValue
UINT16 ProtocolTypeFilter
BOOLEAN EnablePromiscuousReceive
EFI_MAC_ADDRESS CurrentAddress
BOOLEAN MediaPresentSupported
EFI_MAC_ADDRESS BroadcastAddress