#include <Library/DebugLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+UdpIoOnDgramSentDpc (\r
+ IN VOID *Context\r
+ );\r
\r
STATIC\r
VOID\r
EFI_UDP4_TRANSMIT_DATA *UdpTxData;\r
EFI_STATUS Status;\r
UINT32 Count;\r
+ IP4_ADDR Ip;\r
\r
- Token = NetAllocatePool (sizeof (UDP_TX_TOKEN) +\r
+ Token = AllocatePool (sizeof (UDP_TX_TOKEN) +\r
sizeof (EFI_UDP4_FRAGMENT_DATA) * (Packet->BlockOpNum - 1));\r
\r
if (Token == NULL) {\r
}\r
\r
Token->Signature = UDP_IO_TX_SIGNATURE;\r
- NetListInit (&Token->Link);\r
+ InitializeListHead (&Token->Link);\r
\r
Token->UdpIo = UdpIo;\r
Token->CallBack = CallBack;\r
\r
Status = gBS->CreateEvent (\r
EVT_NOTIFY_SIGNAL,\r
- TPL_CALLBACK,\r
+ TPL_NOTIFY,\r
UdpIoOnDgramSent,\r
Token,\r
&UdpToken->Event\r
);\r
\r
if (EFI_ERROR (Status)) {\r
- NetFreePool (Token);\r
+ gBS->FreePool (Token);\r
return NULL;\r
}\r
\r
UdpTxData->GatewayAddress = NULL;\r
\r
if (EndPoint != NULL) {\r
- EFI_IP4 (Token->UdpSession.SourceAddress) = HTONL (EndPoint->LocalAddr);\r
- EFI_IP4 (Token->UdpSession.DestinationAddress) = HTONL (EndPoint->RemoteAddr);\r
- Token->UdpSession.SourcePort = EndPoint->LocalPort;\r
- Token->UdpSession.DestinationPort = EndPoint->RemotePort;\r
- UdpTxData->UdpSessionData = &Token->UdpSession;\r
+ Ip = HTONL (EndPoint->LocalAddr);\r
+ CopyMem (&Token->UdpSession.SourceAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+\r
+ Ip = HTONL (EndPoint->RemoteAddr);\r
+ CopyMem (&Token->UdpSession.DestinationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+\r
+ Token->UdpSession.SourcePort = EndPoint->LocalPort;\r
+ Token->UdpSession.DestinationPort = EndPoint->RemotePort;\r
+ UdpTxData->UdpSessionData = &Token->UdpSession;\r
}\r
\r
if (Gateway != 0) {\r
- EFI_IP4 (Token->Gateway) = HTONL (Gateway);\r
+ Ip = HTONL (Gateway);\r
+ CopyMem (&Token->Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+\r
UdpTxData->GatewayAddress = &Token->Gateway;\r
}\r
\r
)\r
{\r
gBS->CloseEvent (Token->UdpToken.Event);\r
- NetFreePool (Token);\r
+ gBS->FreePool (Token);\r
}\r
\r
\r
UDP_RX_TOKEN *Token;\r
EFI_STATUS Status;\r
\r
- Token = NetAllocatePool (sizeof (UDP_RX_TOKEN));\r
+ Token = AllocatePool (sizeof (UDP_RX_TOKEN));\r
\r
if (Token == NULL) {\r
return NULL;\r
\r
Status = gBS->CreateEvent (\r
EVT_NOTIFY_SIGNAL,\r
- TPL_CALLBACK,\r
+ TPL_NOTIFY,\r
UdpIoOnDgramRcvd,\r
Token,\r
&Token->UdpToken.Event\r
);\r
\r
if (EFI_ERROR (Status)) {\r
- NetFreePool (Token);\r
+ gBS->FreePool (Token);\r
return NULL;\r
}\r
\r
)\r
{\r
gBS->CloseEvent (Token->UdpToken.Event);\r
- NetFreePool (Token);\r
+ gBS->FreePool (Token);\r
}\r
\r
\r
\r
ASSERT (Configure != NULL);\r
\r
- UdpIo = NetAllocatePool (sizeof (UDP_IO_PORT));\r
+ UdpIo = AllocatePool (sizeof (UDP_IO_PORT));\r
\r
if (UdpIo == NULL) {\r
return NULL;\r
}\r
\r
UdpIo->Signature = UDP_IO_SIGNATURE;\r
- NetListInit (&UdpIo->Link);\r
+ InitializeListHead (&UdpIo->Link);\r
UdpIo->RefCnt = 1;\r
\r
UdpIo->Controller = Controller;\r
UdpIo->Image = Image;\r
\r
- NetListInit (&UdpIo->SentDatagram);\r
+ InitializeListHead (&UdpIo->SentDatagram);\r
UdpIo->RecvRequest = NULL;\r
UdpIo->UdpHandle = NULL;\r
\r
Status = gBS->OpenProtocol (\r
UdpIo->UdpHandle,\r
&gEfiUdp4ProtocolGuid,\r
- &UdpIo->Udp,\r
+ (VOID **) &UdpIo->Udp,\r
Image,\r
Controller,\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
);\r
\r
FREE_MEM:\r
- NetFreePool (UdpIo);\r
+ gBS->FreePool (UdpIo);\r
return NULL;\r
}\r
\r
IN VOID *Context\r
)\r
{\r
- NET_LIST_ENTRY *Entry;\r
- NET_LIST_ENTRY *Next;\r
+ LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Next;\r
UDP_TX_TOKEN *Token;\r
\r
NET_LIST_FOR_EACH_SAFE (Entry, Next, &UdpIo->SentDatagram) {\r
Token = NET_LIST_USER_STRUCT (Entry, UDP_TX_TOKEN, Link);\r
\r
if ((ToCancel == NULL) || (ToCancel (Token, Context))) {\r
- NetListRemoveEntry (Entry);\r
UdpIo->Udp->Cancel (UdpIo->Udp, &Token->UdpToken);\r
- Token->CallBack (Token->Packet, NULL, IoStatus, Token->Context);\r
- UdpIoFreeTxToken (Token);\r
}\r
}\r
}\r
UdpIoCancelDgrams (UdpIo, EFI_ABORTED, NULL, NULL);\r
\r
if ((RxToken = UdpIo->RecvRequest) != NULL) {\r
- UdpIo->RecvRequest = NULL;\r
UdpIo->Udp->Cancel (UdpIo->Udp, &RxToken->UdpToken);\r
- UdpIoFreeRxToken (RxToken);\r
}\r
\r
//\r
UdpIo->UdpHandle\r
);\r
\r
- NetListRemoveEntry (&UdpIo->Link);\r
- NetFreePool (UdpIo);\r
+ if (!IsListEmpty(&UdpIo->Link)) {\r
+ RemoveEntryList (&UdpIo->Link);\r
+ }\r
+\r
+ gBS->FreePool (UdpIo);\r
return EFI_SUCCESS;\r
}\r
\r
UdpIoCancelDgrams (UdpIo, EFI_ABORTED, NULL, NULL);\r
\r
if ((RxToken = UdpIo->RecvRequest) != NULL) {\r
- UdpIo->RecvRequest = NULL;\r
UdpIo->Udp->Cancel (UdpIo->Udp, &RxToken->UdpToken);\r
- UdpIoFreeRxToken (RxToken);\r
}\r
\r
UdpIo->Udp->Configure (UdpIo->Udp, NULL);\r
It will remove the packet from the local list then call\r
the packet owner's callback function.\r
\r
- @param Event The event signalled.\r
@param Context The UDP TX Token.\r
\r
@return None\r
STATIC\r
VOID\r
EFIAPI\r
-UdpIoOnDgramSent (\r
- IN EFI_EVENT Event,\r
+UdpIoOnDgramSentDpc (\r
IN VOID *Context\r
)\r
{\r
Token = (UDP_TX_TOKEN *) Context;\r
ASSERT (Token->Signature == UDP_IO_TX_SIGNATURE);\r
\r
- NetListRemoveEntry (&Token->Link);\r
+ RemoveEntryList (&Token->Link);\r
Token->CallBack (Token->Packet, NULL, Token->UdpToken.Status, Token->Context);\r
\r
UdpIoFreeTxToken (Token);\r
}\r
\r
+/**\r
+ Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK.\r
+\r
+ @param Event The event signalled.\r
+ @param Context The UDP TX Token.\r
+\r
+ @return None\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+UdpIoOnDgramSent (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ //\r
+ // Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK\r
+ //\r
+ NetLibQueueDpc (TPL_CALLBACK, UdpIoOnDgramSentDpc, Context);\r
+}\r
+\r
\r
/**\r
Send a packet through the UDP IO port.\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
+ //\r
+ // Insert the tx token into SendDatagram list before transmitting it. Remove\r
+ // it from the list if the returned status is not EFI_SUCCESS.\r
+ //\r
+ InsertHeadList (&UdpIo->SentDatagram, &Token->Link);\r
Status = UdpIo->Udp->Transmit (UdpIo->Udp, &Token->UdpToken);\r
-\r
if (EFI_ERROR (Status)) {\r
+ RemoveEntryList (&Token->Link);\r
UdpIoFreeTxToken (Token);\r
return Status;\r
}\r
\r
- NetListInsertHead (&UdpIo->SentDatagram, &Token->Link);\r
return EFI_SUCCESS;\r
}\r
\r
UdpIoFreeRxToken (Token);\r
}\r
\r
-\r
/**\r
The event handle for UDP receive request. It will build\r
a NET_BUF from the recieved UDP data, then deliver it\r
to the receiver.\r
\r
- @param Event The UDP receive request event\r
@param Context The UDP RX token.\r
\r
@return None\r
STATIC\r
VOID\r
EFIAPI\r
-UdpIoOnDgramRcvd (\r
- IN EFI_EVENT Event,\r
+UdpIoOnDgramRcvdDpc (\r
IN VOID *Context\r
)\r
{\r
UdpRxData = UdpToken->Packet.RxData;\r
\r
if (EFI_ERROR (UdpToken->Status) || (UdpRxData == NULL)) {\r
- Token->CallBack (NULL, NULL, UdpToken->Status, Token->Context);\r
- UdpIoFreeRxToken (Token);\r
+ if (UdpToken->Status != EFI_ABORTED) {\r
+ //\r
+ // Invoke the CallBack only if the reception is not actively aborted.\r
+ //\r
+ Token->CallBack (NULL, NULL, UdpToken->Status, Token->Context);\r
+ }\r
\r
- goto ON_EXIT;\r
+ UdpIoFreeRxToken (Token);\r
+ return;\r
}\r
\r
//\r
Token->CallBack (NULL, NULL, EFI_OUT_OF_RESOURCES, Token->Context);\r
\r
UdpIoFreeRxToken (Token);\r
- goto ON_EXIT;\r
+ return;\r
}\r
\r
UdpSession = &UdpRxData->UdpSession;\r
- Points.LocalAddr = EFI_NTOHL (UdpSession->DestinationAddress);\r
Points.LocalPort = UdpSession->DestinationPort;\r
- Points.RemoteAddr = EFI_NTOHL (UdpSession->SourceAddress);\r
Points.RemotePort = UdpSession->SourcePort;\r
\r
+ CopyMem (&Points.LocalAddr, &UdpSession->DestinationAddress, sizeof (IP4_ADDR));\r
+ CopyMem (&Points.RemoteAddr, &UdpSession->SourceAddress, sizeof (IP4_ADDR));\r
+ Points.LocalAddr = NTOHL (Points.LocalAddr);\r
+ Points.RemoteAddr = NTOHL (Points.RemoteAddr);\r
+\r
Token->CallBack (Netbuf, &Points, EFI_SUCCESS, Token->Context);\r
+}\r
+\r
+/**\r
+ Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK.\r
+\r
+ @param Event The UDP receive request event.\r
+ @param Context The UDP RX token.\r
+\r
+ @return None\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+UdpIoOnDgramRcvd (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK\r
+\r
+Arguments:\r
+\r
+ Event - The UDP receive request event\r
+ Context - The UDP RX token.\r
+\r
+Returns:\r
\r
-ON_EXIT:\r
- return;\r
+ None\r
+\r
+--*/\r
+{\r
+ //\r
+ // Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK\r
+ //\r
+ NetLibQueueDpc (TPL_CALLBACK, UdpIoOnDgramRcvdDpc, Context);\r
}\r
\r
\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
+ UdpIo->RecvRequest = Token;\r
Status = UdpIo->Udp->Receive (UdpIo->Udp, &Token->UdpToken);\r
\r
if (EFI_ERROR (Status)) {\r
+ UdpIo->RecvRequest = NULL;\r
UdpIoFreeRxToken (Token);\r
- return Status;\r
}\r
\r
- UdpIo->RecvRequest = Token;\r
- return EFI_SUCCESS;\r
+ return Status;\r
}\r