/** @file\r
\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2006 - 2008, Intel Corporation \r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
//\r
// Iterate all the rxdatas belonging to this udp instance.\r
//\r
- Wrap = NET_LIST_USER_STRUCT (Entry, UDP4_RXDATA_WRAP, Link);\r
+ Wrap = NET_LIST_USER_STRUCT (WrapEntry, UDP4_RXDATA_WRAP, Link);\r
\r
if (Wrap->TimeoutTick <= UDP4_TIMEOUT_INTERVAL / 1000) {\r
//\r
ControllerHandle,\r
This->DriverBindingHandle,\r
&gEfiUdp4ServiceBindingProtocolGuid,\r
- &Private->Udp4Child\r
+ &Private->Udp4ReadChild\r
);\r
\r
if (EFI_ERROR (Status)) {\r
goto ON_ERROR;\r
}\r
\r
+ //\r
+ // The UDP instance for EfiPxeBcUdpRead\r
+ //\r
Status = gBS->OpenProtocol (\r
- Private->Udp4Child,\r
+ Private->Udp4ReadChild,\r
&gEfiUdp4ProtocolGuid,\r
- (VOID **) &Private->Udp4,\r
+ (VOID **) &Private->Udp4Read,\r
This->DriverBindingHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
goto ON_ERROR;\r
}\r
\r
+ //\r
+ // The UDP instance for EfiPxeBcUdpWrite\r
+ //\r
+ Status = NetLibCreateServiceChild (\r
+ ControllerHandle, \r
+ This->DriverBindingHandle,\r
+ &gEfiUdp4ServiceBindingProtocolGuid,\r
+ &Private->Udp4WriteChild\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Private->Udp4WriteChild,\r
+ &gEfiUdp4ProtocolGuid,\r
+ (VOID **) &Private->Udp4Write,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
ZeroMem (&Private->Udp4CfgData, sizeof (EFI_UDP4_CONFIG_DATA));\r
Private->Udp4CfgData.AcceptBroadcast = FALSE;\r
Private->Udp4CfgData.AcceptPromiscuous = FALSE;\r
- Private->Udp4CfgData.AcceptAnyPort = FALSE;\r
+ Private->Udp4CfgData.AcceptAnyPort = TRUE;\r
Private->Udp4CfgData.AllowDuplicatePort = TRUE;\r
Private->Udp4CfgData.TypeOfService = DEFAULT_ToS;\r
Private->Udp4CfgData.TimeToLive = DEFAULT_TTL;\r
Private->Udp4CfgData.DoNotFragment = FALSE;\r
- Private->Udp4CfgData.ReceiveTimeout = 10000; // 10 milliseconds\r
+ Private->Udp4CfgData.ReceiveTimeout = 50000; // 50 milliseconds\r
Private->Udp4CfgData.UseDefaultAddress = FALSE;\r
\r
- PxeBcInitSeedPacket (&Private->SeedPacket, Private->Udp4);\r
+ PxeBcInitSeedPacket (&Private->SeedPacket, Private->Udp4Read);\r
Private->MacLen = Private->SeedPacket.Dhcp4.Header.HwAddrLen;\r
CopyMem (&Private->Mac, &Private->SeedPacket.Dhcp4.Header.ClientHwAddr[0], Private->MacLen);\r
\r
\r
ON_ERROR:\r
\r
- if (Private->Udp4Child != NULL) {\r
+ if (Private->Udp4WriteChild != NULL) {\r
+ gBS->CloseProtocol (\r
+ Private->Udp4WriteChild,\r
+ &gEfiUdp4ProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
+ NetLibDestroyServiceChild (\r
+ ControllerHandle,\r
+ This->DriverBindingHandle,\r
+ &gEfiUdp4ServiceBindingProtocolGuid,\r
+ Private->Udp4WriteChild\r
+ );\r
+ }\r
+\r
+ if (Private->Udp4ReadChild != NULL) {\r
gBS->CloseProtocol (\r
- Private->Udp4Child,\r
+ Private->Udp4ReadChild,\r
&gEfiUdp4ProtocolGuid,\r
This->DriverBindingHandle,\r
ControllerHandle\r
ControllerHandle,\r
This->DriverBindingHandle,\r
&gEfiUdp4ServiceBindingProtocolGuid,\r
- Private->Udp4Child\r
+ Private->Udp4ReadChild\r
);\r
}\r
\r
if (!EFI_ERROR (Status)) {\r
\r
gBS->CloseProtocol (\r
- Private->Udp4Child,\r
+ Private->Udp4WriteChild,\r
+ &gEfiUdp4ProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ NicHandle\r
+ );\r
+ NetLibDestroyServiceChild (\r
+ ControllerHandle,\r
+ This->DriverBindingHandle,\r
+ &gEfiUdp4ServiceBindingProtocolGuid,\r
+ Private->Udp4WriteChild\r
+ );\r
+\r
+ gBS->CloseProtocol (\r
+ Private->Udp4ReadChild,\r
&gEfiUdp4ProtocolGuid,\r
This->DriverBindingHandle,\r
NicHandle\r
NicHandle,\r
This->DriverBindingHandle,\r
&gEfiUdp4ServiceBindingProtocolGuid,\r
- Private->Udp4Child\r
+ Private->Udp4ReadChild\r
);\r
\r
gBS->CloseProtocol (\r
//\r
// Configure the udp4 instance to let it receive data\r
//\r
- Status = Private->Udp4->Configure (Private->Udp4, &Private->Udp4CfgData);\r
+ Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
Mode->Started = FALSE;\r
\r
-\r
- //\r
- // Reset and leave joined groups\r
- //\r
- Private->Udp4->Groups (Private->Udp4, FALSE, NULL);\r
-\r
- Private->Udp4->Configure (Private->Udp4, NULL);\r
+ Private->CurrentUdpSrcPort = 0;\r
+ Private->Udp4Write->Configure (Private->Udp4Write, NULL);\r
+ Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
\r
Private->Dhcp4->Stop (Private->Dhcp4);\r
Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r
EFI_UDP4_SESSION_DATA Udp4Session;\r
EFI_STATUS Status;\r
BOOLEAN IsDone;\r
- UINT16 RandomSrcPort;\r
EFI_PXE_BASE_CODE_MODE *Mode;\r
EFI_MAC_ADDRESS TempMacAddr;\r
\r
}\r
\r
Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
- Udp4 = Private->Udp4;\r
+ Udp4 = Private->Udp4Write;\r
Mode = &Private->Mode;\r
+ if (!Mode->Started) {\r
+ return EFI_NOT_STARTED;\r
+ }\r
\r
if (!Private->AddressIsOk && (SrcIp == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
\r
Mode->IcmpErrorReceived = FALSE;\r
\r
- if (SrcIp == NULL) {\r
- SrcIp = &Private->StationIp;\r
-\r
- if (GatewayIp == NULL) {\r
- GatewayIp = &Private->GatewayIp;\r
+ if ((Private->CurrentUdpSrcPort == 0) ||\r
+ ((SrcPort != NULL) && (*SrcPort != Private->CurrentUdpSrcPort))) {\r
+ //\r
+ // Port is changed, (re)configure the Udp4Write instance\r
+ //\r
+ if (SrcPort != NULL) {\r
+ Private->CurrentUdpSrcPort = *SrcPort;\r
}\r
- }\r
-\r
- if ((SrcPort == NULL) || (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT)) {\r
- RandomSrcPort = (UINT16) (NET_RANDOM (NetRandomInitSeed ()) % 10000 + 1024);\r
-\r
- if (SrcPort == NULL) {\r
\r
- SrcPort = &RandomSrcPort;\r
- } else {\r
-\r
- *SrcPort = RandomSrcPort;\r
+ Status = PxeBcConfigureUdpWriteInstance (\r
+ Udp4,\r
+ &Private->StationIp.v4,\r
+ &Private->SubnetMask.v4,\r
+ &Private->GatewayIp.v4,\r
+ &Private->CurrentUdpSrcPort\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ Private->CurrentUdpSrcPort = 0;\r
+ return EFI_INVALID_PARAMETER;\r
}\r
}\r
\r
\r
CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r
Udp4Session.DestinationPort = *DestPort;\r
- CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));\r
- Udp4Session.SourcePort = *SrcPort;\r
+ if (SrcIp != NULL) {\r
+ CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));\r
+ }\r
+ if (SrcPort != NULL) {\r
+ Udp4Session.SourcePort = *SrcPort;\r
+ }\r
\r
FragCount = (HeaderSize != NULL) ? 2 : 1;\r
Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) AllocatePool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r
DataLength += (UINT32) *HeaderSize;\r
}\r
\r
- Udp4TxData->GatewayAddress = (EFI_IPv4_ADDRESS *) GatewayIp;\r
+ if (GatewayIp != NULL) {\r
+ Udp4TxData->GatewayAddress = (EFI_IPv4_ADDRESS *) GatewayIp;\r
+ }\r
Udp4TxData->UdpSessionData = &Udp4Session;\r
Udp4TxData->DataLength = DataLength;\r
Token.Packet.TxData = Udp4TxData;\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderPtr == NULL) && (*HeaderSize != 0))) {\r
+ if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderSize != NULL) && (HeaderPtr == NULL))) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
\r
Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
Mode = Private->PxeBc.Mode;\r
- Udp4 = Private->Udp4;\r
+ Udp4 = Private->Udp4Read;\r
\r
if (!Mode->Started) {\r
return EFI_NOT_STARTED;\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
+TRY_AGAIN:\r
+\r
IsDone = FALSE;\r
Status = Udp4->Receive (Udp4, &Token);\r
if (EFI_ERROR (Status)) {\r
}\r
\r
if (Matched) {\r
+ Matched = FALSE;\r
+\r
//\r
// Match the destination ip of the received udp dgram\r
//\r
// Recycle the RxData\r
//\r
gBS->SignalEvent (RxData->RecycleSignal);\r
+\r
+ if (!Matched) {\r
+ goto TRY_AGAIN;\r
+ }\r
}\r
\r
ON_EXIT:\r
// Clear the UDP instance configuration, all joined groups will be left\r
// during the operation.\r
//\r
- Private->Udp4->Configure (Private->Udp4, NULL);\r
+ Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
Private->Udp4CfgData.AcceptPromiscuous = FALSE;\r
Private->Udp4CfgData.AcceptBroadcast = FALSE;\r
\r
//\r
// Configure the UDP instance with the new configuration.\r
//\r
- Status = Private->Udp4->Configure (Private->Udp4, &Private->Udp4CfgData);\r
+ Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Configure the UDP instance with the new configuration.\r
//\r
- Status = Private->Udp4->Configure (Private->Udp4, &Private->Udp4CfgData);\r
+ Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Join the mutilcast group\r
//\r
- Status = Private->Udp4->Groups (Private->Udp4, TRUE, &NewFilter->IpList[Index].v4);\r
+ Status = Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &NewFilter->IpList[Index].v4);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
switch (Status) {\r
\r
case EFI_SUCCESS:\r
- break;\r
+ return EFI_SUCCESS;\r
\r
case EFI_BUFFER_TOO_SMALL:\r
if (Buffer != NULL) {\r
/** @file
-Copyright (c) 2007, Intel Corporation
+Copyright (c) 2007 - 2008, 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
EFI_HANDLE Dhcp4Child;
EFI_HANDLE Ip4Child;
EFI_HANDLE Mtftp4Child;
- EFI_HANDLE Udp4Child;
-
+ EFI_HANDLE Udp4ReadChild;
+ EFI_HANDLE Udp4WriteChild;
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
EFI_IP4_PROTOCOL *Ip4;
EFI_IP4_CONFIG_DATA Ip4ConfigData;
EFI_MTFTP4_PROTOCOL *Mtftp4;
- EFI_UDP4_PROTOCOL *Udp4;
+ EFI_UDP4_PROTOCOL *Udp4Read;
+ EFI_UDP4_PROTOCOL *Udp4Write;
+ UINT16 CurrentUdpSrcPort;
EFI_UDP4_CONFIG_DATA Udp4CfgData;
\r
if (BlockSize != NULL) {\r
\r
- ReqOpt[0].OptionStr = (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
+ ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
ReqOpt[0].ValueStr = OptBuf;\r
UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);\r
OptCnt++;\r
\r
if (BlockSize != NULL) {\r
\r
- ReqOpt[0].OptionStr = (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
+ ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
ReqOpt[0].ValueStr = OptBuf;\r
UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);\r
OptCnt++;\r
\r
if (BlockSize != NULL) {\r
\r
- ReqOpt[0].OptionStr = (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
+ ReqOpt[0].OptionStr = (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];\r
ReqOpt[0].ValueStr = OptBuf;\r
UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);\r
OptCnt++;\r
/** @file\r
\r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation \r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
*((BOOLEAN *) Context) = TRUE;\r
}\r
\r
+EFI_STATUS\r
+PxeBcConfigureUdpWriteInstance (\r
+ IN EFI_UDP4_PROTOCOL *Udp4,\r
+ IN EFI_IPv4_ADDRESS *StationIp,\r
+ IN EFI_IPv4_ADDRESS *SubnetMask,\r
+ IN EFI_IPv4_ADDRESS *Gateway,\r
+ IN OUT UINT16 *SrcPort\r
+ )\r
+{\r
+ EFI_UDP4_CONFIG_DATA Udp4CfgData;\r
+ EFI_STATUS Status;\r
+\r
+ ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r
+\r
+ Udp4CfgData.ReceiveTimeout = 1000;\r
+ Udp4CfgData.TypeOfService = DEFAULT_ToS;\r
+ Udp4CfgData.TimeToLive = DEFAULT_TTL;\r
+\r
+ CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r
+ CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask));\r
+\r
+ Udp4CfgData.StationPort = *SrcPort;\r
+\r
+ //\r
+ // Reset the instance.\r
+ //\r
+ Udp4->Configure (Udp4, NULL);\r
+\r
+ Status = Udp4->Configure (Udp4, &Udp4CfgData);\r
+ if (!EFI_ERROR (Status) && (Gateway->Addr[0] != 0)) {\r
+ //\r
+ // basic configuration OK, need to add the default route entry\r
+ //\r
+ Status = Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway);\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // roll back\r
+ //\r
+ Udp4->Configure (Udp4, NULL);\r
+ }\r
+ }\r
+\r
+ if (!EFI_ERROR (Status) && (*SrcPort == 0)) {\r
+ Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL);\r
+ *SrcPort = Udp4CfgData.StationPort;\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
\r
/**\r
Convert number to ASCII value\r
/** @file
-Copyright (c) 2007, Intel Corporation
+Copyright (c) 2007 - 2008, 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
)
;
+EFI_STATUS
+PxeBcConfigureUdpWriteInstance (
+ IN EFI_UDP4_PROTOCOL *Udp4,
+ IN EFI_IPv4_ADDRESS *StationIp,
+ IN EFI_IPv4_ADDRESS *SubnetMask,
+ IN EFI_IPv4_ADDRESS *Gateway,
+ IN OUT UINT16 *SrcPort
+ );
VOID
CvtNum (
IN UINTN Number,