11UINT16 mUdp4RandomPort;
111 IN VOID *Arg OPTIONAL
274 Udp4Service->Signature = UDP4_SERVICE_DATA_SIGNATURE;
275 Udp4Service->ServiceBinding = mUdp4ServiceBinding;
276 Udp4Service->ImageHandle = ImageHandle;
277 Udp4Service->ControllerHandle = ControllerHandle;
278 Udp4Service->ChildrenNumber = 0;
285 Udp4Service->IpIo =
IpIoCreate (ImageHandle, ControllerHandle, IP_VERSION_4);
286 if (Udp4Service->IpIo ==
NULL) {
287 return EFI_OUT_OF_RESOURCES;
304 Status =
IpIoOpen (Udp4Service->IpIo, &OpenData);
305 if (EFI_ERROR (Status)) {
312 Status =
gBS->CreateEvent (
313 EVT_TIMER | EVT_NOTIFY_SIGNAL,
317 &Udp4Service->TimeoutEvent
319 if (EFI_ERROR (Status)) {
326 Status =
gBS->SetTimer (
327 Udp4Service->TimeoutEvent,
329 UDP4_TIMEOUT_INTERVAL
331 if (EFI_ERROR (Status)) {
339 if (Udp4Service->TimeoutEvent !=
NULL) {
340 gBS->CloseEvent (Udp4Service->TimeoutEvent);
367 gBS->CloseEvent (Udp4Service->TimeoutEvent);
399 NET_CHECK_SIGNATURE (Udp4Service, UDP4_SERVICE_DATA_SIGNATURE);
401 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {
406 NET_CHECK_SIGNATURE (Instance, UDP4_INSTANCE_DATA_SIGNATURE);
408 if (!Instance->Configured || (Instance->ConfigData.ReceiveTimeout == 0)) {
415 NET_LIST_FOR_EACH_SAFE (WrapEntry, NextEntry, &Instance->RcvdDgramQue) {
424 if (Wrap->TimeoutTick < (UDP4_TIMEOUT_INTERVAL / 10)) {
430 Wrap->TimeoutTick -= (UDP4_TIMEOUT_INTERVAL / 10);
452 Instance->Signature = UDP4_INSTANCE_DATA_SIGNATURE;
471 Instance->Udp4Service = Udp4Service;
472 CopyMem (&Instance->Udp4Proto, &mUdp4Protocol, sizeof (Instance->Udp4Proto));
474 Instance->Configured =
FALSE;
475 Instance->IsNoMapping =
FALSE;
476 Instance->InDestroy =
FALSE;
518 NET_LIST_FOR_EACH (Entry, InstanceList) {
523 ConfigData = &Instance->ConfigData;
525 if (!Instance->Configured || ConfigData->AcceptAnyPort) {
533 if (EFI_IP4_EQUAL (&ConfigData->StationAddress, Address) &&
534 (ConfigData->StationPort == Port))
574 if (ConfigData->AcceptAnyPort) {
578 StationAddress = &ConfigData->StationAddress;
580 if (ConfigData->StationPort != 0) {
581 if (!ConfigData->AllowDuplicatePort &&
587 return EFI_ACCESS_DENIED;
594 if (ConfigData->AllowDuplicatePort) {
598 ConfigData->StationPort = mUdp4RandomPort;
600 StartPort = mUdp4RandomPort;
604 if (mUdp4RandomPort == 0) {
605 mUdp4RandomPort = UDP4_PORT_KNOWN;
608 if (mUdp4RandomPort == StartPort) {
612 return EFI_OUT_OF_RESOURCES;
616 ConfigData->StationPort = mUdp4RandomPort;
620 if (mUdp4RandomPort == 0) {
621 mUdp4RandomPort = UDP4_PORT_KNOWN;
646 if ((NewConfigData->AcceptAnyPort != OldConfigData->AcceptAnyPort) ||
647 (NewConfigData->AcceptBroadcast != OldConfigData->AcceptBroadcast) ||
648 (NewConfigData->AcceptPromiscuous != OldConfigData->AcceptPromiscuous) ||
649 (NewConfigData->AllowDuplicatePort != OldConfigData->AllowDuplicatePort)
658 if ((!NewConfigData->AcceptAnyPort) &&
659 (NewConfigData->StationPort != OldConfigData->StationPort)
668 if (!NewConfigData->AcceptPromiscuous) {
669 if (NewConfigData->UseDefaultAddress != OldConfigData->UseDefaultAddress) {
676 if (!NewConfigData->UseDefaultAddress &&
677 (!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) ||
678 !EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask))
689 if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &OldConfigData->RemoteAddress)) {
696 if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) &&
697 (NewConfigData->RemotePort != OldConfigData->RemotePort)
725 CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData,
sizeof (*Ip4ConfigData));
727 Ip4ConfigData->DefaultProtocol = EFI_IP_PROTO_UDP;
728 Ip4ConfigData->AcceptBroadcast = Udp4ConfigData->AcceptBroadcast;
729 Ip4ConfigData->AcceptPromiscuous = Udp4ConfigData->AcceptPromiscuous;
730 Ip4ConfigData->UseDefaultAddress = Udp4ConfigData->UseDefaultAddress;
737 Ip4ConfigData->ReceiveTimeout = (UINT32)(-1);
777 IP4_ADDR SourceAddress;
778 IP4_ADDR GatewayAddress;
780 if (TxToken->Event ==
NULL) {
781 return EFI_INVALID_PARAMETER;
784 TxData = TxToken->Packet.TxData;
786 if ((TxData ==
NULL) || (TxData->FragmentCount == 0)) {
787 return EFI_INVALID_PARAMETER;
791 for (Index = 0; Index < TxData->FragmentCount; Index++) {
792 if ((TxData->FragmentTable[Index].FragmentBuffer ==
NULL) ||
793 (TxData->FragmentTable[Index].FragmentLength == 0))
798 return EFI_INVALID_PARAMETER;
801 TotalLen += TxData->FragmentTable[Index].FragmentLength;
804 if (TotalLen != TxData->DataLength) {
809 return EFI_INVALID_PARAMETER;
812 if (TxData->GatewayAddress !=
NULL) {
813 CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR));
815 if (!Instance->ConfigData.UseDefaultAddress &&
816 (EFI_NTOHL (Instance->ConfigData.SubnetMask) != 0) &&
817 !
NetIp4IsUnicast (NTOHL (GatewayAddress), EFI_NTOHL (Instance->ConfigData.SubnetMask)))
822 return EFI_INVALID_PARAMETER;
826 ConfigData = &Instance->ConfigData;
827 UdpSessionData = TxData->UdpSessionData;
829 if (UdpSessionData !=
NULL) {
830 CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR));
832 if ((SourceAddress != 0) &&
833 !Instance->ConfigData.UseDefaultAddress &&
834 (EFI_NTOHL (Instance->ConfigData.SubnetMask) != 0) &&
835 !
NetIp4IsUnicast (HTONL (SourceAddress), EFI_NTOHL (Instance->ConfigData.SubnetMask)))
841 return EFI_INVALID_PARAMETER;
844 if ((UdpSessionData->DestinationPort == 0) && (ConfigData->RemotePort == 0)) {
848 return EFI_INVALID_PARAMETER;
851 if (EFI_IP4_EQUAL (&UdpSessionData->DestinationAddress, &mZeroIp4Addr)) {
855 return EFI_INVALID_PARAMETER;
857 }
else if (EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr)) {
862 return EFI_INVALID_PARAMETER;
865 if (TxData->DataLength > UDP4_MAX_DATA_SIZE) {
866 return EFI_BAD_BUFFER_SIZE;
899 if ((Token == TokenInItem) || (Token->Event == TokenInItem->Event)) {
904 return EFI_ACCESS_DENIED;
932 Checksum =
NetAddChecksum (Checksum, HTONS ((UINT16)Packet->TotalSize));
934 return (UINT16) ~Checksum;
969 return EFI_NOT_FOUND;
1002 Token->Status = Status;
1003 gBS->SignalEvent (Token->Event);
1030 NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE);
1072 IN VOID *Arg OPTIONAL
1079 if ((McastIp !=
NULL) && (!EFI_IP4_EQUAL (McastIp, &(Item->Key)))) {
1092 if (McastIp !=
NULL) {
1123 IN VOID *Arg OPTIONAL
1130 if ((Arg !=
NULL) && (Item->Key != Arg)) {
1134 if (Item->Value !=
NULL) {
1141 Packet = (
NET_BUF *)(Item->Value);
1142 IpIo = (
IP_IO *)(*((
UINTN *)&Packet->ProtoData[0]));
1152 TokenToCancel->Status = EFI_ABORTED;
1153 gBS->SignalEvent (TokenToCancel->Event);
1213 if ((Token !=
NULL) && (Status == EFI_ABORTED)) {
1232 return EFI_NOT_FOUND;
1262 IP4_ADDR Destination;
1264 ConfigData = &Instance->ConfigData;
1266 if (ConfigData->AcceptPromiscuous) {
1273 if ((!ConfigData->AcceptAnyPort && (Udp4Session->DestinationPort != ConfigData->StationPort)) ||
1274 ((ConfigData->RemotePort != 0) && (Udp4Session->SourcePort != ConfigData->RemotePort))
1283 if (!EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr) &&
1284 !EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress)
1293 if (EFI_IP4_EQUAL (&ConfigData->StationAddress, &mZeroIp4Addr) ||
1294 EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress)
1304 CopyMem (&Destination, &Udp4Session->DestinationAddress, sizeof (IP4_ADDR));
1306 if (IP4_IS_LOCAL_BROADCAST (Destination) && ConfigData->AcceptBroadcast) {
1313 if (IP4_IS_MULTICAST (NTOHL (Destination)) &&
1357 gBS->CloseEvent (Wrap->RxData.RecycleSignal);
1397 CopyMem (&Wrap->RxData, RxData, sizeof (Wrap->RxData));
1402 Status =
gBS->CreateEvent (
1407 &Wrap->RxData.RecycleSignal
1409 if (EFI_ERROR (Status)) {
1414 Wrap->Packet = Packet;
1415 Wrap->TimeoutTick = Instance->ConfigData.ReceiveTimeout;
1446 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {
1452 if (!Instance->Configured) {
1465 NET_GET_REF (Packet);
1498 if (NET_BUF_SHARED (Wrap->Packet)) {
1519 RxData = &Wrap->RxData;
1520 RxData->FragmentCount = Wrap->Packet->BlockOpNum;
1525 &RxData->FragmentCount
1529 Token->Packet.RxData = &Wrap->RxData;
1531 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1533 gBS->RestoreTPL (OldTpl);
1535 gBS->SignalEvent (Token->Event);
1553 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {
1559 if (!Instance->Configured) {
1602 ASSERT (Udp4Header !=
NULL);
1604 if (Udp4Header->Checksum != 0) {
1609 NetSession->Source.Addr[0],
1610 NetSession->Dest.Addr[0],
1624 Udp4Session = &RxData.UdpSession;
1625 Udp4Session->SourcePort = NTOHS (Udp4Header->SrcPort);
1626 Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort);
1636 RxData.DataLength = (UINT32)Packet->TotalSize;
1643 if (Enqueued == 0) {
1688 IpSender =
IpIoFindSender (&IpIo, NetSession->IpVersion, &NetSession->Dest);
1689 if (IpSender ==
NULL) {
1697 IpHdr = NetSession->IpHdr.Ip4Hdr;
1703 sizeof (
IP4_HEAD)) + ICMP_ERROR_PACKET_LENGTH;
1709 if (Packet ==
NULL) {
1717 ASSERT (IcmpErrHdr !=
NULL);
1722 IcmpErrHdr->Head.Type = ICMP_TYPE_UNREACH;
1723 IcmpErrHdr->Head.Code = ICMP_CODE_UNREACH_PORT;
1724 IcmpErrHdr->Head.Checksum = 0;
1725 IcmpErrHdr->Fourth = 0;
1736 CopyMem (Ptr, Udp4Header, ICMP_ERROR_PACKET_LENGTH);
1746 Override.Ip4OverrideData.DoNotFragment =
FALSE;
1747 Override.Ip4OverrideData.TypeOfService = 0;
1748 Override.Ip4OverrideData.TimeToLive = 255;
1749 Override.Ip4OverrideData.Protocol = EFI_IP_PROTO_ICMP;
1757 IpIoSend (IpIo, Packet, IpSender,
NULL,
NULL, &NetSession->Source, &Override);
1792 ASSERT (Udp4Header !=
NULL);
1797 Udp4Session.SourcePort = NTOHS (Udp4Header->DstPort);
1798 Udp4Session.DestinationPort = NTOHS (Udp4Header->SrcPort);
1800 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {
1806 if (!Instance->Configured) {
1816 if (IcmpError > ICMP_ERR_UNREACH_PORT) {
1817 Instance->IcmpError = EFI_ICMP_ERROR;
1852 if (EFI_ERROR (Instance->IcmpError)) {
1858 if (Token !=
NULL) {
1862 Token->Status = Instance->IcmpError;
1863 gBS->SignalEvent (Token->Event);
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
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)
EFI_STATUS EFIAPI IpIoDestroy(IN OUT IP_IO *IpIo)
IP_IO *EFIAPI IpIoCreate(IN EFI_HANDLE Image, IN EFI_HANDLE Controller, IN UINT8 IpVersion)
#define EFI_IP4_HEADER_LEN(HdrPtr)
EFI_STATUS EFIAPI IpIoOpen(IN OUT IP_IO *IpIo, IN IP_IO_OPEN_DATA *OpenData)
EFI_STATUS EFIAPI IpIoSend(IN OUT IP_IO *IpIo, IN OUT NET_BUF *Pkt, IN IP_IO_IP_INFO *Sender OPTIONAL, IN VOID *Context OPTIONAL, IN VOID *NotifyData OPTIONAL, IN EFI_IP_ADDRESS *Dest OPTIONAL, IN IP_IO_OVERRIDE *OverrideData OPTIONAL)
VOID EFIAPI IpIoCancelTxToken(IN IP_IO *IpIo, IN VOID *Packet)
IP_IO_IP_INFO *EFIAPI IpIoFindSender(IN OUT IP_IO **IpIo, IN UINT8 IpVersion, IN EFI_IP_ADDRESS *Src)
EFI_STATUS EFIAPI IpIoGetIcmpErrStatus(IN UINT8 IcmpError, IN UINT8 IpVersion, OUT BOOLEAN *IsHard OPTIONAL, OUT BOOLEAN *Notify OPTIONAL)
VOID EFIAPI NetbufFree(IN NET_BUF *Nbuf)
LIST_ENTRY *EFIAPI NetListRemoveHead(IN OUT LIST_ENTRY *Head)
UINT32 EFIAPI NetbufTrim(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)
UINT16 EFIAPI NetbufChecksum(IN NET_BUF *Nbuf)
EFI_STATUS EFIAPI NetbufBuildExt(IN NET_BUF *Nbuf, IN OUT NET_FRAGMENT *ExtFragment, IN OUT UINT32 *ExtNum)
BOOLEAN EFIAPI NetIp4IsUnicast(IN IP4_ADDR Ip, IN IP4_ADDR NetMask)
VOID EFIAPI NetMapClean(IN OUT NET_MAP *Map)
NET_MAP_ITEM *EFIAPI NetMapFindKey(IN NET_MAP *Map, IN VOID *Key)
UINT16 EFIAPI NetAddChecksum(IN UINT16 Checksum1, IN UINT16 Checksum2)
NET_BUF *EFIAPI NetbufAlloc(IN UINT32 Len)
VOID EFIAPI NetMapInit(IN OUT NET_MAP *Map)
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)
UINT16 EFIAPI NetPseudoHeadChecksum(IN IP4_ADDR Src, IN IP4_ADDR Dst, IN UINT8 Proto, IN UINT16 Len)
UINT8 *EFIAPI NetbufGetByte(IN NET_BUF *Nbuf, IN UINT32 Offset, OUT UINT32 *Index OPTIONAL)
VOID *EFIAPI NetMapRemoveItem(IN OUT NET_MAP *Map, IN OUT NET_MAP_ITEM *Item, OUT VOID **Value OPTIONAL)
VOID *EFIAPI NetMapRemoveHead(IN OUT NET_MAP *Map, OUT VOID **Value OPTIONAL)
EFI_STATUS EFIAPI NetMapIterate(IN NET_MAP *Map, IN NET_MAP_CALLBACK CallBack, IN VOID *Arg OPTIONAL)
UINTN EFIAPI NetMapGetCount(IN NET_MAP *Map)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID Udp4Demultiplex(IN UDP4_SERVICE_DATA *Udp4Service, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet)
EFI_STATUS Udp4ValidateTxToken(IN UDP4_INSTANCE_DATA *Instance, IN EFI_UDP4_COMPLETION_TOKEN *TxToken)
EFI_STATUS EFIAPI Udp4CancelTokens(IN NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Arg OPTIONAL)
EFI_STATUS Udp4CreateService(IN OUT UDP4_SERVICE_DATA *Udp4Service, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ControllerHandle)
EFI_STATUS Udp4RemoveToken(IN OUT NET_MAP *TokenMap, IN EFI_UDP4_COMPLETION_TOKEN *Token)
VOID Udp4IcmpHandler(IN UDP4_SERVICE_DATA *Udp4Service, IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet)
EFI_STATUS EFIAPI Udp4LeaveGroup(IN OUT NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Arg OPTIONAL)
BOOLEAN Udp4FindInstanceByPort(IN LIST_ENTRY *InstanceList, IN EFI_IPv4_ADDRESS *Address, IN UINT16 Port)
VOID EFIAPI Udp4DgramSent(IN EFI_STATUS Status, IN VOID *Context, IN IP_IO_IP_PROTOCOL Sender, IN VOID *NotifyData)
BOOLEAN Udp4IsReconfigurable(IN EFI_UDP4_CONFIG_DATA *OldConfigData, IN EFI_UDP4_CONFIG_DATA *NewConfigData)
VOID Udp4InstanceDeliverDgram(IN UDP4_INSTANCE_DATA *Instance)
VOID Udp4DeliverDgram(IN UDP4_SERVICE_DATA *Udp4Service)
VOID EFIAPI Udp4CheckTimeout(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS Udp4Bind(IN LIST_ENTRY *InstanceList, IN OUT EFI_UDP4_CONFIG_DATA *ConfigData)
VOID Udp4InitInstance(IN UDP4_SERVICE_DATA *Udp4Service, IN OUT UDP4_INSTANCE_DATA *Instance)
VOID EFIAPI Udp4NetVectorExtFree(VOID *Context)
UINTN Udp4EnqueueDgram(IN UDP4_SERVICE_DATA *Udp4Service, IN NET_BUF *Packet, IN EFI_UDP4_RECEIVE_DATA *RxData)
VOID Udp4BuildIp4ConfigData(IN EFI_UDP4_CONFIG_DATA *Udp4ConfigData, IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData)
BOOLEAN Udp4MatchDgram(IN UDP4_INSTANCE_DATA *Instance, IN EFI_UDP4_SESSION_DATA *Udp4Session)
VOID Udp4SendPortUnreach(IN IP_IO *IpIo, IN EFI_NET_SESSION_DATA *NetSession, IN VOID *Udp4Header)
EFI_STATUS Udp4InstanceCancelToken(IN UDP4_INSTANCE_DATA *Instance, IN EFI_UDP4_COMPLETION_TOKEN *Token OPTIONAL)
UINT16 Udp4Checksum(IN NET_BUF *Packet, IN UINT16 HeadSum)
EFI_STATUS EFIAPI Udp4TokenExist(IN NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Context)
VOID Udp4ReportIcmpError(IN UDP4_INSTANCE_DATA *Instance)
UDP4_RXDATA_WRAP * Udp4WrapRxData(IN UDP4_INSTANCE_DATA *Instance, IN NET_BUF *Packet, IN EFI_UDP4_RECEIVE_DATA *RxData)
VOID EFIAPI Udp4DgramRcvd(IN EFI_STATUS Status, IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet, IN VOID *Context)
VOID Udp4FlushRcvdDgram(IN UDP4_INSTANCE_DATA *Instance)
VOID Udp4CleanService(IN UDP4_SERVICE_DATA *Udp4Service)
VOID EFIAPI Udp4RecycleRxDataWrap(IN EFI_EVENT Event, IN VOID *Context)
VOID Udp4CleanInstance(IN UDP4_INSTANCE_DATA *Instance)
PKT_RCVD_NOTIFY PktRcvdNotify
Receive callback.
VOID * SndContext
Context data used by send callback.
IP_IO_IP_CONFIG_DATA IpConfigData
Configuration of the IP instance.
VOID * RcvdContext
Context data used by receive callback.
PKT_SENT_NOTIFY PktSentNotify
Send callback.