X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FMtftp4Dxe%2FMtftp4Rrq.c;h=34fb6a0b6b31794826c8bd42372563671b5b7174;hb=e798cd87ca9a3a30c4cea50c5f5de84e10a8bc5a;hp=665114c7f8a3e2b415dfb9377fd900cab88d8a32;hpb=772db4bb33ae66fa20e39f786b5f80d107d450a5;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c index 665114c7f8..34fb6a0b6b 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c @@ -1,40 +1,45 @@ /** @file - -Copyright (c) 2006 - 2007, Intel Corporation + Routines to process Rrq (download). + +Copyright (c) 2006 - 2009, 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 -http://opensource.org/licenses/bsd-license.php +http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Mtftp4Rrq.c +**/ -Abstract: - Routines to process Rrq (download) +#include "Mtftp4Impl.h" -**/ +/** + The packet process callback for MTFTP download. -#include "Mtftp4Impl.h" + @param UdpPacket The packet received + @param EndPoint The local/remote access point of the packet + @param IoStatus The status of the receiving + @param Context Opaque parameter, which is the MTFTP session +**/ VOID +EFIAPI Mtftp4RrqInput ( IN NET_BUF *UdpPacket, - IN UDP_POINTS *Points, + IN UDP_END_POINT *EndPoint, IN EFI_STATUS IoStatus, IN VOID *Context ); /** - Start the MTFTP session to download. It will first initialize some - of the internal states then build and send a RRQ reqeuest packet, at - last, it will start receive for the downloading. + Start the MTFTP session to download. + + It will first initialize some of the internal states then build and send a RRQ + reqeuest packet, at last, it will start receive for the downloading. @param Instance The Mtftp session @param Operation The MTFTP opcode, it may be a EFI_MTFTP4_OPCODE_RRQ @@ -95,7 +100,6 @@ Mtftp4RrqSendAck ( NET_BUF *Packet; Packet = NetbufAlloc (sizeof (EFI_MTFTP4_ACK_HEADER)); - if (Packet == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -105,6 +109,7 @@ Mtftp4RrqSendAck ( sizeof (EFI_MTFTP4_ACK_HEADER), FALSE ); + ASSERT (Ack != NULL); Ack->Ack.OpCode = HTONS (EFI_MTFTP4_OPCODE_ACK); Ack->Ack.Block[0] = HTONS (BlkNo); @@ -130,9 +135,9 @@ Mtftp4RrqSendAck ( **/ EFI_STATUS Mtftp4RrqSaveBlock ( - IN MTFTP4_PROTOCOL *Instance, - IN EFI_MTFTP4_PACKET *Packet, - IN UINT32 Len + IN OUT MTFTP4_PROTOCOL *Instance, + IN EFI_MTFTP4_PACKET *Packet, + IN UINT32 Len ) { EFI_MTFTP4_TOKEN *Token; @@ -172,7 +177,7 @@ Mtftp4RrqSaveBlock ( Mtftp4SendError ( Instance, EFI_MTFTP4_ERRORCODE_ILLEGAL_OPERATION, - "User aborted download" + (UINT8 *) "User aborted download" ); return EFI_ABORTED; @@ -183,7 +188,7 @@ Mtftp4RrqSaveBlock ( Start = MultU64x32 (Block - 1, Instance->BlkSize); if (Start + DataLen <= Token->BufferSize) { - NetCopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen); + CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen); // // Update the file size when received the last block @@ -203,7 +208,7 @@ Mtftp4RrqSaveBlock ( Mtftp4SendError ( Instance, EFI_MTFTP4_ERRORCODE_DISK_FULL, - "User provided memory block is too small" + (UINT8 *) "User provided memory block is too small" ); return EFI_BUFFER_TOO_SMALL; @@ -215,8 +220,9 @@ Mtftp4RrqSaveBlock ( /** - Function to process the received data packets. It will save the block - then send back an ACK if it is active. + Function to process the received data packets. + + It will save the block then send back an ACK if it is active. @param Instance The downloading MTFTP session @param Packet The packet received @@ -231,11 +237,11 @@ Mtftp4RrqSaveBlock ( **/ EFI_STATUS Mtftp4RrqHandleData ( - IN MTFTP4_PROTOCOL *Instance, - IN EFI_MTFTP4_PACKET *Packet, - IN UINT32 Len, - IN BOOLEAN Multicast, - OUT BOOLEAN *Completed + IN MTFTP4_PROTOCOL *Instance, + IN EFI_MTFTP4_PACKET *Packet, + IN UINT32 Len, + IN BOOLEAN Multicast, + OUT BOOLEAN *Completed ) { EFI_STATUS Status; @@ -304,6 +310,7 @@ Mtftp4RrqHandleData ( /** Validate whether the options received in the server's OACK packet is valid. + The options are valid only if: 1. The server doesn't include options not requested by us 2. The server can only use smaller blksize than that is requested @@ -314,7 +321,8 @@ Mtftp4RrqHandleData ( @param Reply The options in the OACK packet @param Request The requested options - @return TRUE if the options in the OACK is OK, otherwise FALSE. + @retval TRUE The options in the OACK is OK. + @retval FALSE The options in the OACK is invalid. **/ BOOLEAN @@ -336,8 +344,8 @@ Mtftp4RrqOackValid ( // Server can only specify a smaller block size to be used and // return the timeout matches that requested. // - if (((Reply->Exist & MTFTP4_BLKSIZE_EXIST) && (Reply->BlkSize > Request->BlkSize)) || - ((Reply->Exist & MTFTP4_TIMEOUT_EXIST) && (Reply->Timeout != Request->Timeout))) { + if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) != 0)&& (Reply->BlkSize > Request->BlkSize)) || + (((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout))) { return FALSE; } @@ -346,7 +354,7 @@ Mtftp4RrqOackValid ( // setting. But if it use the specific multicast channel, it can't // change the setting. // - if ((Reply->Exist & MTFTP4_MCAST_EXIST) && (This->McastIp != 0)) { + if (((Reply->Exist & MTFTP4_MCAST_EXIST) != 0) && (This->McastIp != 0)) { if ((Reply->McastIp != 0) && (Reply->McastIp != This->McastIp)) { return FALSE; } @@ -363,18 +371,18 @@ Mtftp4RrqOackValid ( /** Configure a UDP IO port to receive the multicast. - @param McastIo The UDP IO port to configure + @param McastIo The UDP IO to configure @param Context The opaque parameter to the function which is the MTFTP session. - @retval EFI_SUCCESS The udp child is successfully configured. + @retval EFI_SUCCESS The UDP child is successfully configured. @retval Others Failed to configure the UDP child. **/ -STATIC EFI_STATUS +EFIAPI Mtftp4RrqConfigMcastPort ( - IN UDP_IO_PORT *McastIo, + IN UDP_IO *McastIo, IN VOID *Context ) { @@ -404,27 +412,48 @@ Mtftp4RrqConfigMcastPort ( UdpConfig.RemotePort = 0; Ip = HTONL (Instance->ServerIp); - NetCopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); - Status = McastIo->Udp->Configure (McastIo->Udp, &UdpConfig); + Status = McastIo->Protocol.Udp4->Configure (McastIo->Protocol.Udp4, &UdpConfig); if (EFI_ERROR (Status)) { return Status; } + if (!Config->UseDefaultSetting && + !EFI_IP4_EQUAL (&mZeroIp4Addr, &Config->GatewayIp)) { + // + // The station IP address is manually configured and the Gateway IP is not 0. + // Add the default route for this UDP instance. + // + Status = McastIo->Protocol.Udp4->Routes ( + McastIo->Protocol.Udp4, + FALSE, + &mZeroIp4Addr, + &mZeroIp4Addr, + &Config->GatewayIp + ); + + if (EFI_ERROR (Status)) { + McastIo->Protocol.Udp4->Configure (McastIo->Protocol.Udp4, NULL); + return Status; + } + } + // // join the multicast group // Ip = HTONL (Instance->McastIp); - NetCopyMem (&Group, &Ip, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Group, &Ip, sizeof (EFI_IPv4_ADDRESS)); - return McastIo->Udp->Groups (McastIo->Udp, TRUE, &Group); + return McastIo->Protocol.Udp4->Groups (McastIo->Protocol.Udp4, TRUE, &Group); } /** - Function to process the OACK. It will first validate the OACK - packet, then update the various negotiated parameters. + Function to process the OACK. + + It will first validate the OACK packet, then update the various negotiated parameters. @param Instance The download MTFTP session @param Packet The packet received @@ -440,11 +469,11 @@ Mtftp4RrqConfigMcastPort ( **/ EFI_STATUS Mtftp4RrqHandleOack ( - IN MTFTP4_PROTOCOL *Instance, - IN EFI_MTFTP4_PACKET *Packet, - IN UINT32 Len, - IN BOOLEAN Multicast, - OUT BOOLEAN *Completed + IN OUT MTFTP4_PROTOCOL *Instance, + IN EFI_MTFTP4_PACKET *Packet, + IN UINT32 Len, + IN BOOLEAN Multicast, + OUT BOOLEAN *Completed ) { MTFTP4_OPTION Reply; @@ -467,7 +496,7 @@ Mtftp4RrqHandleOack ( // // Parse and validate the options from server // - NetZeroMem (&Reply, sizeof (MTFTP4_OPTION)); + ZeroMem (&Reply, sizeof (MTFTP4_OPTION)); Status = Mtftp4ParseOptionOack (Packet, Len, &Reply); @@ -480,14 +509,14 @@ Mtftp4RrqHandleOack ( Mtftp4SendError ( Instance, EFI_MTFTP4_ERRORCODE_ILLEGAL_OPERATION, - "Mal-formated OACK packet" + (UINT8 *) "Mal-formated OACK packet" ); } return EFI_TFTP_ERROR; } - if (Reply.Exist & MTFTP4_MCAST_EXIST) { + if ((Reply.Exist & MTFTP4_MCAST_EXIST) != 0) { // // Save the multicast info. Always update the Master, only update the @@ -501,7 +530,7 @@ Mtftp4RrqHandleOack ( Mtftp4SendError ( Instance, EFI_MTFTP4_ERRORCODE_ILLEGAL_OPERATION, - "Illegal multicast setting" + (UINT8 *) "Illegal multicast setting" ); return EFI_TFTP_ERROR; @@ -512,10 +541,11 @@ Mtftp4RrqHandleOack ( // Instance->McastIp = Reply.McastIp; Instance->McastPort = Reply.McastPort; - Instance->McastUdpPort = UdpIoCreatePort ( + Instance->McastUdpPort = UdpIoCreateIo ( Instance->Service->Controller, Instance->Service->Image, Mtftp4RrqConfigMcastPort, + UDP_IO_UDP4_VERSION, Instance ); @@ -529,27 +559,27 @@ Mtftp4RrqHandleOack ( Mtftp4SendError ( Instance, EFI_MTFTP4_ERRORCODE_ACCESS_VIOLATION, - "Failed to create socket to receive multicast packet" + (UINT8 *) "Failed to create socket to receive multicast packet" ); return Status; } - + // // Update the parameters used. // if (Reply.BlkSize != 0) { Instance->BlkSize = Reply.BlkSize; } - + if (Reply.Timeout != 0) { Instance->Timeout = Reply.Timeout; - } - } - + } + } + } else { Instance->Master = TRUE; - + if (Reply.BlkSize != 0) { Instance->BlkSize = Reply.BlkSize; } @@ -558,7 +588,7 @@ Mtftp4RrqHandleOack ( Instance->Timeout = Reply.Timeout; } } - + // // Send an ACK to (Expected - 1) which is 0 for unicast download, // or tell the server we want to receive the Expected block. @@ -571,17 +601,16 @@ Mtftp4RrqHandleOack ( The packet process callback for MTFTP download. @param UdpPacket The packet received - @param Points The local/remote access point of the packet + @param EndPoint The local/remote access point of the packet @param IoStatus The status of the receiving @param Context Opaque parameter, which is the MTFTP session - @return None - **/ VOID +EFIAPI Mtftp4RrqInput ( IN NET_BUF *UdpPacket, - IN UDP_POINTS *Points, + IN UDP_END_POINT *EndPoint, IN EFI_STATUS IoStatus, IN VOID *Context ) @@ -612,7 +641,7 @@ Mtftp4RrqInput ( // // Find the port this packet is from to restart receive correctly. // - Multicast = (BOOLEAN) (Points->LocalAddr == Instance->McastIp); + Multicast = (BOOLEAN) (EndPoint->LocalAddr.Addr[0] == Instance->McastIp); if (UdpPacket->TotalSize < MTFTP4_OPCODE_LEN) { goto ON_EXIT; @@ -624,11 +653,11 @@ Mtftp4RrqInput ( // is required to use the same port as RemotePort to multicast the // data. // - if (Points->RemotePort != Instance->ConnectedPort) { + if (EndPoint->RemotePort != Instance->ConnectedPort) { if (Instance->ConnectedPort != 0) { goto ON_EXIT; } else { - Instance->ConnectedPort = Points->RemotePort; + Instance->ConnectedPort = EndPoint->RemotePort; } } @@ -638,7 +667,7 @@ Mtftp4RrqInput ( Len = UdpPacket->TotalSize; if (UdpPacket->BlockOpNum > 1) { - Packet = NetAllocatePool (Len); + Packet = AllocatePool (Len); if (Packet == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -675,7 +704,7 @@ Mtftp4RrqInput ( Mtftp4SendError ( Instance, EFI_MTFTP4_ERRORCODE_REQUEST_DENIED, - "User aborted the transfer" + (UINT8 *) "User aborted the transfer" ); } @@ -705,6 +734,9 @@ Mtftp4RrqInput ( case EFI_MTFTP4_OPCODE_ERROR: Status = EFI_TFTP_ERROR; break; + + default: + break; } ON_EXIT: @@ -714,7 +746,7 @@ ON_EXIT: // receive, otherwise end the session. // if ((Packet != NULL) && (UdpPacket->BlockOpNum > 1)) { - NetFreePool (Packet); + FreePool (Packet); } if (UdpPacket != NULL) {