/** @file
The assistant function implementation for IpSecConfig application.
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "IpSecConfig.h"
#include "Helper.h"
/**
Helper function called to change an input parameter in the string format to a number.
@param[in] FlagStr The pointer to the flag string.
@param[in] Maximum Greatest value number.
@param[in, out] ValuePtr The pointer to the input parameter in string format.
@param[in] ByteCount The valid byte count
@param[in] Map The pointer to the STR2INT table.
@param[in] ParamPackage The pointer to the ParamPackage list.
@param[in] FormatMask The bit mask.
BIT 0 set indicates the value of a flag might be a number.
BIT 1 set indicates the value of a flag might be a string that needs to be looked up.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_NOT_FOUND The input parameter can't be found.
@retval EFI_INVALID_PARAMETER The input parameter is an invalid input.
**/
)
{
Value64 = 0;
return EFI_NOT_FOUND;
} else {
//
// Try to convert to integer directly if MaybeNumber is TRUE.
//
if ((FormatMask & FORMAT_NUMBER) != 0) {
//
// Convert successfully.
//
//
// But the result is invalid
//
-1,
-1,
NULL,
);
return EFI_INVALID_PARAMETER;
}
}
}
//
// Convert falied, so use String->Integer map.
//
//
// Cannot find the string in the map.
//
-1,
-1,
NULL,
);
}
Print (L"\n");
return EFI_INVALID_PARAMETER;
}
}
return EFI_SUCCESS;
}
}
/**
Helper function called to convert a string containing an Ipv4 or Ipv6 Internet Protocol address
into a proper address for the EFI_IP_ADDRESS structure.
@param[in] Ptr The pointer to the string containing an Ipv4 or Ipv6 Internet Protocol address.
@param[out] Ip The pointer to the EFI_IP_ADDRESS structure to contain the result.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER Invalid parameter.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// Parse the input address as Ipv4 Address first.
//
return Status;
}
return Status;
}
/**
Helper function called to calculate the prefix length associated with the string
containing an Ipv4 or Ipv6 Internet Protocol address.
@param[in] Ptr The pointer to the string containing an Ipv4 or Ipv6 Internet Protocol address.
@param[out] Addr The pointer to the EFI_IP_ADDRESS_INFO structure to contain the result.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval Others Other mistake case.
**/
)
{
return EFI_INVALID_PARAMETER;
}
Addr->PrefixLength = 0;
} else {
}
return Status;
}
}
return Status;
}
/**
Helper function called to calculate the port range associated with the string.
@param[in] Ptr The pointer to the string containing a port and range.
@param[out] Port The pointer to the Port to contain the result.
@param[out] PortRange The pointer to the PortRange to contain the result.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval Others Other mistake case.
**/
)
{
;
}
*BreakPtr = L'\0';
return Status;
}
*PortRange = 0;
if (*BreakPtr == L':') {
BreakPtr++;
return Status;
}
return EFI_INVALID_PARAMETER;
}
}
return EFI_SUCCESS;
}
/**
Helper function called to transfer a string to an unsigned integer.
@param[in] Str The pointer to the string.
@param[out] Status The operation status.
@return The integer value of converted Str.
**/
)
{
Base = 10;
Value = 0;
*Status = EFI_ABORTED;
//
// Skip leading white space.
//
Str++;
}
//
// For NULL Str, just return.
//
if (*Str == 0) {
return 0;
}
//
// Skip white space in tail.
//
while (*StrTail == ' ') {
*StrTail = 0;
StrTail--;
}
//
// Check hex prefix '0x'.
//
Str += 2;
Len -= 2;
Base = 16;
}
if (Len == 0) {
return 0;
}
//
// Convert the string to value.
//
if (Base == 16) {
//
// Overflow here x16.
//
return 0;
}
} else {
//
// Overflow here x8.
//
return 0;
}
//
// Overflow here.
//
return 0;
}
}
}
} else {
//
// Unexpected Char encountered.
//
return 0;
}
}
*Status = EFI_SUCCESS;
return Value;
}
/**
Helper function called to transfer a string to an unsigned integer according to the map table.
@param[in] Str The pointer to the string.
@param[in] Map The pointer to the map table.
@return The integer value of converted Str. If not found, then return -1.
**/
)
{
}
}
return (UINT32) -1;
}
/**
Helper function called to transfer an unsigned integer to a string according to the map table.
@param[in] Integer The pointer to the string.
@param[in] Map The pointer to the map table.
@return The converted Str. If not found, then return NULL.
**/
CHAR16 *
)
{
}
}
return NULL;
}