1 /** @file
2   The assistant function declaration for IpSecConfig application.
3 
4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 
6   This program and the accompanying materials
7   are licensed and made available under the terms and conditions of the BSD License
8   which accompanies this distribution.  The full text of the license may be found at
9   http://opensource.org/licenses/bsd-license.php.
10 
11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #ifndef _HELPER_H_
17 #define _HELPER_H_
18 
19 #define  FORMAT_NUMBER 0x1
20 #define  FORMAT_STRING 0x2
21 
22 /**
23   Helper function called to change input parameter in string format to number.
24 
25   @param[in]      FlagStr         The pointer to the flag string.
26   @param[in]      Maximum         most value number.
27   @param[in, out] ValuePtr        The pointer to the input parameter in string format.
28   @param[in]      ByteCount       The valid byte count
29   @param[in]      Map             The pointer to the STR2INT table.
30   @param[in]      ParamPackage    The pointer to the ParamPackage list.
31   @param[in]      FormatMask      The bit mask.
32                                   BIT 0 set indicates the value of flag might be number.
33                                   BIT 1 set indicates the value of flag might be a string that needs to be looked up.
34 
35   @retval EFI_SUCCESS              The operation completed successfully.
36   @retval EFI_NOT_FOUND            The input parameter can't be found.
37   @retval EFI_INVALID_PARAMETER    The input parameter is an invalid input.
38 **/
39 EFI_STATUS
40 GetNumber (
41   IN     CHAR16        *FlagStr,
42   IN     UINT64        Maximum,
43   IN OUT VOID          *ValuePtr,
44   IN     UINTN         ByteCount,
45   IN     STR2INT       *Map,
46   IN     LIST_ENTRY    *ParamPackage,
47   IN     UINT32        FormatMask
48   );
49 
50 /**
51   Helper function called to convert a string containing an (Ipv4) Internet Protocol dotted address
52   into a proper address for the EFI_IP_ADDRESS structure.
53 
54   @param[in]  Ptr    The pointer to the string containing an (Ipv4) Internet Protocol dotted address.
55   @param[out] Ip     The pointer to the Ip address structure to contain the result.
56 
57   @retval EFI_SUCCESS              The operation completed successfully.
58   @retval EFI_INVALID_PARAMETER    Invalid parameter.
59 **/
60 EFI_STATUS
61 EfiInetAddr2 (
62   IN  CHAR16            *Ptr,
63   OUT EFI_IP_ADDRESS    *Ip
64   );
65 
66 /**
67   Helper function called to calculate the prefix length associated with the string
68   containing an Ipv4 or Ipv6 Internet Protocol address.
69 
70   @param[in]  Ptr     The pointer to the string containing an Ipv4 or Ipv6 Internet Protocol address.
71   @param[out] Addr    The pointer to the EFI_IP_ADDRESS_INFO structure to contain the result.
72 
73   @retval EFI_SUCCESS              The operation completed successfully.
74   @retval EFI_INVALID_PARAMETER    Invalid parameter.
75   @retval Others                   Other mistake case.
76 **/
77 EFI_STATUS
78 EfiInetAddrRange (
79   IN  CHAR16                 *Ptr,
80   OUT EFI_IP_ADDRESS_INFO    *Addr
81   );
82 
83 /**
84   Helper function called to calculate the port range associated with the string.
85 
86   @param[in]  Ptr          The pointer to the string containing a port and range.
87   @param[out] Port         The pointer to the Port to contain the result.
88   @param[out] PortRange    The pointer to the PortRange to contain the result.
89 
90   @retval EFI_SUCCESS              The operation completed successfully.
91   @retval EFI_INVALID_PARAMETER    Invalid parameter.
92   @retval Others                   Other mistake case.
93 **/
94 EFI_STATUS
95 EfiInetPortRange (
96   IN  CHAR16    *Ptr,
97   OUT UINT16    *Port,
98   OUT UINT16    *PortRange
99   );
100 
101 /**
102   Helper function called to transfer a string to an unsigned integer.
103 
104   @param[in]  Str       The pointer to the string.
105   @param[out] Status    The operation status.
106 
107   @return The integer value of a converted str.
108 **/
109 UINT64
110 StrToUInteger (
111   IN  CONST CHAR16    *Str,
112   OUT EFI_STATUS      *Status
113   );
114 
115 /**
116   Helper function called to transfer a string to an unsigned integer according to the map table.
117 
118   @param[in] Str    The pointer to the string.
119   @param[in] Map    The pointer to the map table.
120 
121   @return The integer value of converted str. If not found, then return -1.
122 **/
123 UINT32
124 MapStringToInteger (
125   IN CONST CHAR16    *Str,
126   IN STR2INT         *Map
127   );
128 
129 /**
130   Helper function called to transfer an unsigned integer to a string according to the map table.
131 
132   @param[in] Integer    The pointer to the string.
133   @param[in] Map        The pointer to the map table.
134 
135   @return The converted str. If not found, then return NULL.
136 **/
137 CHAR16 *
138 MapIntegerToString (
139   IN UINT32     Integer,
140   IN STR2INT    *Map
141   );
142 
143 #endif
144