X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FMtftp4Dxe%2FMtftp4Option.c;h=e40561a96b26b82f52e6ae13453906647f0c3ecd;hb=de005223b77c473d45c9c8a11147f6968325f73e;hp=f413c763053015d0b54d1b83e2e81e12c6e17f14;hpb=e48e37fce2611df7a52aff271835ff72ee396d9b;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c index f413c76305..e40561a96b 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c @@ -1,22 +1,15 @@ /** @file + Routines to process MTFTP4 options. -Copyright (c) 2006, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2010, 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: - - Mtftp4Option.c - -Abstract: - routines to process MTFTP4 options - - **/ #include "Mtftp4Impl.h" @@ -29,6 +22,134 @@ CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS] = { }; +/** + Check whether two ascii strings are equel, ignore the case. + + @param Str1 The first ascii string + @param Str2 The second ascii string + + @retval TRUE Two strings are equal when case is ignored. + @retval FALSE Two string are not equal. + +**/ +BOOLEAN +NetStringEqualNoCase ( + IN UINT8 *Str1, + IN UINT8 *Str2 + ) +{ + UINT8 Ch1; + UINT8 Ch2; + + ASSERT ((Str1 != NULL) && (Str2 != NULL)); + + for (; (*Str1 != '\0') && (*Str2 != '\0'); Str1++, Str2++) { + Ch1 = *Str1; + Ch2 = *Str2; + + // + // Convert them to lower case then compare two + // + if (('A' <= Ch1) && (Ch1 <= 'Z')) { + Ch1 += 'a' - 'A'; + } + + if (('A' <= Ch2) && (Ch2 <= 'Z')) { + Ch2 += 'a' - 'A'; + } + + if (Ch1 != Ch2) { + return FALSE; + } + } + + return (BOOLEAN) (*Str1 == *Str2); +} + + +/** + Convert a string to a UINT32 number. + + @param Str The string to convert from + + @return The number get from the string + +**/ +UINT32 +NetStringToU32 ( + IN UINT8 *Str + ) +{ + UINT32 Num; + + ASSERT (Str != NULL); + + Num = 0; + + for (; NET_IS_DIGIT (*Str); Str++) { + Num = Num * 10 + (*Str - '0'); + } + + return Num; +} + + +/** + Convert a string of the format "192.168.0.1" to an IP address. + + @param Str The string representation of IP + @param Ip The varible to get IP. + + @retval EFI_INVALID_PARAMETER The IP string is invalid. + @retval EFI_SUCCESS The IP is parsed into the Ip + +**/ +EFI_STATUS +NetStringToIp ( + IN UINT8 *Str, + OUT IP4_ADDR *Ip + ) +{ + UINT32 Byte; + UINT32 Addr; + UINTN Index; + + *Ip = 0; + Addr = 0; + + for (Index = 0; Index < 4; Index++) { + if (!NET_IS_DIGIT (*Str)) { + return EFI_INVALID_PARAMETER; + } + + Byte = NetStringToU32 (Str); + + if (Byte > 255) { + return EFI_INVALID_PARAMETER; + } + + Addr = (Addr << 8) | Byte; + + // + // Skip all the digitals and check whether the sepeator is the dot + // + while (NET_IS_DIGIT (*Str)) { + Str++; + } + + if ((Index < 3) && (*Str != '.')) { + return EFI_INVALID_PARAMETER; + } + + Str++; + } + + *Ip = Addr; + + return EFI_SUCCESS; +} + + /** Go through the packet to fill the Options array with the start addresses of each MTFTP option name/value pair. @@ -44,13 +165,12 @@ CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS] = { @retval EFI_SUCCESS The packet has been parsed into the Options array. **/ -STATIC EFI_STATUS Mtftp4FillOptions ( - IN EFI_MTFTP4_PACKET *Packet, - IN UINT32 PacketLen, - IN OUT UINT32 *Count, - OUT EFI_MTFTP4_OPTION *Options OPTIONAL + IN EFI_MTFTP4_PACKET *Packet, + IN UINT32 PacketLen, + IN OUT UINT32 *Count, + OUT EFI_MTFTP4_OPTION *Options OPTIONAL ) { UINT8 *Cur; @@ -104,8 +224,9 @@ Mtftp4FillOptions ( /** - Allocate and fill in a array of Mtftp options from the Packet. It - first calls Mtftp4FillOption to get the option number, then allocate + Allocate and fill in a array of Mtftp options from the Packet. + + It first calls Mtftp4FillOption to get the option number, then allocate the array, at last, call Mtftp4FillOption again to save the options. @param Packet The packet to parse @@ -121,10 +242,10 @@ Mtftp4FillOptions ( **/ EFI_STATUS Mtftp4ExtractOptions ( - IN EFI_MTFTP4_PACKET *Packet, - IN UINT32 PacketLen, - IN OUT UINT32 *OptionCount, - OUT EFI_MTFTP4_OPTION **OptionList OPTIONAL + IN EFI_MTFTP4_PACKET *Packet, + IN UINT32 PacketLen, + OUT UINT32 *OptionCount, + OUT EFI_MTFTP4_OPTION **OptionList OPTIONAL ) { EFI_STATUS Status; @@ -178,135 +299,6 @@ Mtftp4ExtractOptions ( } -/** - Check whether two ascii strings are equel, ignore the case. - - @param Str1 The first ascii string - @param Str2 The second ascii string - - @retval TRUE Two strings are equal when case is ignored. - @retval FALSE Two string are not equal. - -**/ -BOOLEAN -NetStringEqualNoCase ( - IN UINT8 *Str1, - IN UINT8 *Str2 - ) -{ - UINT8 Ch1; - UINT8 Ch2; - - ASSERT ((Str1 != NULL) && (Str2 != NULL)); - - for (; (*Str1 != '\0') && (*Str2 != '\0'); Str1++, Str2++) { - Ch1 = *Str1; - Ch2 = *Str2; - - // - // Convert them to lower case then compare two - // - if (('A' <= Ch1) && (Ch1 <= 'Z')) { - Ch1 += 'a' - 'A'; - } - - if (('A' <= Ch2) && (Ch2 <= 'Z')) { - Ch2 += 'a' - 'A'; - } - - if (Ch1 != Ch2) { - return FALSE; - } - } - - return (BOOLEAN) (*Str1 == *Str2); -} - - -/** - Convert a string to a UINT32 number. - - @param Str The string to convert from - - @return The number get from the string - -**/ -UINT32 -NetStringToU32 ( - IN UINT8 *Str - ) -{ - UINT32 Num; - - ASSERT (Str != NULL); - - Num = 0; - - for (; NET_IS_DIGIT (*Str); Str++) { - Num = Num * 10 + (*Str - '0'); - } - - return Num; -} - - -/** - Convert a string of the format "192.168.0.1" to an IP address. - - @param Str The string representation of IP - @param Ip The varible to get IP. - - @retval EFI_INVALID_PARAMETER The IP string is invalid. - @retval EFI_SUCCESS The IP is parsed into the Ip - -**/ -STATIC -EFI_STATUS -NetStringToIp ( - IN UINT8 *Str, - OUT IP4_ADDR *Ip - ) -{ - UINT32 Byte; - UINT32 Addr; - UINTN Index; - - *Ip = 0; - Addr = 0; - - for (Index = 0; Index < 4; Index++) { - if (!NET_IS_DIGIT (*Str)) { - return EFI_INVALID_PARAMETER; - } - - Byte = NetStringToU32 (Str); - - if (Byte > 255) { - return EFI_INVALID_PARAMETER; - } - - Addr = (Addr << 8) | Byte; - - // - // Skip all the digitals and check whether the sepeator is the dot - // - while (NET_IS_DIGIT (*Str)) { - Str++; - } - - if ((Index < 3) && (*Str != '.')) { - return EFI_INVALID_PARAMETER; - } - - Str++; - } - - *Ip = Addr; - - return EFI_SUCCESS; -} - - /** Parse the MTFTP multicast option. @@ -317,11 +309,10 @@ NetStringToIp ( @retval EFI_SUCCESS The multicast value is parsed into the Option **/ -STATIC EFI_STATUS Mtftp4ExtractMcast ( - IN UINT8 *Value, - IN MTFTP4_OPTION *Option + IN UINT8 *Value, + IN OUT MTFTP4_OPTION *Option ) { EFI_STATUS Status; @@ -340,7 +331,7 @@ Mtftp4ExtractMcast ( return Status; } - while (*Value && (*Value != ',')) { + while ((*Value != 0) && (*Value != ',')) { Value++; } } @@ -364,7 +355,7 @@ Mtftp4ExtractMcast ( return EFI_INVALID_PARAMETER; } - Option->McastPort = (UINT16)Num; + Option->McastPort = (UINT16) Num; while (NET_IS_DIGIT (*Value)) { Value++; @@ -386,7 +377,7 @@ Mtftp4ExtractMcast ( return EFI_INVALID_PARAMETER; } - Option->Master = (BOOLEAN)(Num == 1); + Option->Master = (BOOLEAN) (Num == 1); while (NET_IS_DIGIT (*Value)) { Value++; @@ -405,7 +396,7 @@ Mtftp4ExtractMcast ( can access directly. @param Options The option array, which contains addresses of each - option's name/value string. + option's name/value string. @param Count The number of options in the Options @param Request Whether this is a request or OACK. The format of multicast is different according to this setting. @@ -418,10 +409,10 @@ Mtftp4ExtractMcast ( **/ EFI_STATUS Mtftp4ParseOption ( - IN EFI_MTFTP4_OPTION *Options, - IN UINT32 Count, - IN BOOLEAN Request, - OUT MTFTP4_OPTION *MtftpOption + IN EFI_MTFTP4_OPTION *Options, + IN UINT32 Count, + IN BOOLEAN Request, + OUT MTFTP4_OPTION *MtftpOption ) { EFI_STATUS Status; @@ -518,9 +509,9 @@ Mtftp4ParseOption ( **/ EFI_STATUS Mtftp4ParseOptionOack ( - IN EFI_MTFTP4_PACKET *Packet, - IN UINT32 PacketLen, - OUT MTFTP4_OPTION *MtftpOption + IN EFI_MTFTP4_PACKET *Packet, + IN UINT32 PacketLen, + OUT MTFTP4_OPTION *MtftpOption ) { EFI_MTFTP4_OPTION *OptionList; @@ -534,9 +525,10 @@ Mtftp4ParseOptionOack ( if (EFI_ERROR (Status) || (Count == 0)) { return Status; } + ASSERT (OptionList != NULL); Status = Mtftp4ParseOption (OptionList, Count, FALSE, MtftpOption); - gBS->FreePool (OptionList); + FreePool (OptionList); return Status; }