]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Common.h
CommitLineData
83cbd279 1/** @file\r
3e8c18da 2 Common definition for IP4.\r
d1102dba
LG
3\r
4Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
83cbd279 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
83cbd279 13**/\r
14\r
15#ifndef __EFI_IP4_COMMON_H__\r
16#define __EFI_IP4_COMMON_H__\r
17\r
18typedef struct _IP4_INTERFACE IP4_INTERFACE;\r
19typedef struct _IP4_PROTOCOL IP4_PROTOCOL;\r
20typedef struct _IP4_SERVICE IP4_SERVICE;\r
21\r
f6b7393c 22#define IP4_ETHER_PROTO 0x0800\r
23\r
24//\r
25// The packet is received as link level broadcast/multicast/promiscuous.\r
26//\r
27#define IP4_LINK_BROADCAST 0x00000001\r
28#define IP4_LINK_MULTICAST 0x00000002\r
29#define IP4_LINK_PROMISC 0x00000004\r
30\r
31//\r
32// IP4 address cast type classfication. Keep it true that any\r
33// type bigger than or equal to LOCAL_BROADCAST is broadcast.\r
34//\r
35#define IP4_PROMISCUOUS 1\r
36#define IP4_LOCAL_HOST 2\r
37#define IP4_MULTICAST 3\r
38#define IP4_LOCAL_BROADCAST 4 // Destination is 255.255.255.255\r
39#define IP4_SUBNET_BROADCAST 5\r
40#define IP4_NET_BROADCAST 6\r
41\r
42//\r
43// IP4 header flags\r
44//\r
45#define IP4_HEAD_DF_MASK 0x4000\r
46#define IP4_HEAD_MF_MASK 0x2000\r
47#define IP4_HEAD_OFFSET_MASK 0x1fff\r
83cbd279 48\r
49#define IP4_ALLZERO_ADDRESS 0x00000000u\r
50#define IP4_ALLONE_ADDRESS 0xFFFFFFFFu\r
51#define IP4_ALLSYSTEM_ADDRESS 0xE0000001u\r
52#define IP4_ALLROUTER_ADDRESS 0xE0000002u\r
53\r
96e1079f 54///\r
55/// Compose the fragment field to be used in the IP4 header.\r
56///\r
83cbd279 57#define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \\r
58 ((UINT16)(((Df) ? 0x4000 : 0) | ((Mf) ? 0x2000 : 0) | (((Offset) >> 3) & 0x1fff)))\r
59\r
60#define IP4_LAST_FRAGMENT(FragmentField) \\r
61 (((FragmentField) & IP4_HEAD_MF_MASK) == 0)\r
62\r
63#define IP4_FIRST_FRAGMENT(FragmentField) \\r
64 ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))\r
65\r
216f7970 66#define IP4_DO_NOT_FRAGMENT(FragmentField) \\r
67 ((BOOLEAN)(((FragmentField) & IP4_HEAD_DF_MASK) == IP4_HEAD_DF_MASK))\r
68\r
83cbd279 69#define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)\r
70\r
96e1079f 71///\r
72/// Conver the Microsecond to second. IP transmit/receive time is\r
73/// in the unit of microsecond. IP ticks once per second.\r
74///\r
83cbd279 75#define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)\r
76\r
2ff29212 77/**\r
78 Return the cast type (Unicast/Boradcast) specific to an\r
79 interface. All the addresses are host byte ordered.\r
80\r
3e8c18da 81 @param[in] IpAddr The IP address to classify in host byte order\r
82 @param[in] IpIf The interface that IpAddr received from\r
2ff29212 83\r
84 @return The cast type of this IP address specific to the interface.\r
85 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address\r
86 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the\r
87 interface\r
88 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface\r
89 @retval 0 Otherwise.\r
90\r
91**/\r
83cbd279 92INTN\r
93Ip4GetNetCast (\r
2ff29212 94 IN IP4_ADDR IpAddr,\r
95 IN IP4_INTERFACE *IpIf\r
83cbd279 96 );\r
97\r
2ff29212 98/**\r
99 Find the cast type of the packet related to the local host.\r
100 This isn't the same as link layer cast type. For example, DHCP\r
101 server may send local broadcast to the local unicast MAC.\r
102\r
3e8c18da 103 @param[in] IpSb The IP4 service binding instance that received the\r
104 packet\r
105 @param[in] Dst The destination address in the packet (host byte\r
106 order)\r
107 @param[in] Src The source address in the packet (host byte order)\r
2ff29212 108\r
109 @return The cast type for the Dst, it will return on the first non-promiscuous\r
110 cast type to a configured interface. If the packet doesn't match any of\r
111 the interface, multicast address and local broadcast address are checked.\r
112\r
113**/\r
83cbd279 114INTN\r
115Ip4GetHostCast (\r
2ff29212 116 IN IP4_SERVICE *IpSb,\r
117 IN IP4_ADDR Dst,\r
118 IN IP4_ADDR Src\r
83cbd279 119 );\r
120\r
2ff29212 121/**\r
122 Find an interface whose configured IP address is Ip.\r
123\r
3e8c18da 124 @param[in] IpSb The IP4 service binding instance\r
125 @param[in] Ip The Ip address (host byte order) to find\r
2ff29212 126\r
127 @return The IP4_INTERFACE point if found, otherwise NULL\r
128\r
129**/\r
83cbd279 130IP4_INTERFACE *\r
131Ip4FindInterface (\r
2ff29212 132 IN IP4_SERVICE *IpSb,\r
133 IN IP4_ADDR Ip\r
83cbd279 134 );\r
135\r
2ff29212 136/**\r
137 Find an interface that Ip is on that connected network.\r
138\r
3e8c18da 139 @param[in] IpSb The IP4 service binding instance\r
140 @param[in] Ip The Ip address (host byte order) to find\r
2ff29212 141\r
142 @return The IP4_INTERFACE point if found, otherwise NULL\r
143\r
144**/\r
83cbd279 145IP4_INTERFACE *\r
146Ip4FindNet (\r
2ff29212 147 IN IP4_SERVICE *IpSb,\r
148 IN IP4_ADDR Ip\r
83cbd279 149 );\r
150\r
2ff29212 151/**\r
152 Find an interface of the service with the same Ip/Netmask pair.\r
153\r
3e8c18da 154 @param[in] IpSb Ip4 service binding instance\r
155 @param[in] Ip The Ip adress to find (host byte order)\r
156 @param[in] Netmask The network to find (host byte order)\r
2ff29212 157\r
158 @return The IP4_INTERFACE point if found, otherwise NULL\r
159\r
160**/\r
83cbd279 161IP4_INTERFACE *\r
162Ip4FindStationAddress (\r
2ff29212 163 IN IP4_SERVICE *IpSb,\r
164 IN IP4_ADDR Ip,\r
165 IN IP4_ADDR Netmask\r
83cbd279 166 );\r
167\r
2ff29212 168/**\r
169 Get the MAC address for a multicast IP address. Call\r
170 Mnp's McastIpToMac to find the MAC address in stead of\r
171 hard code the NIC to be Ethernet.\r
172\r
3e8c18da 173 @param[in] Mnp The Mnp instance to get the MAC address.\r
174 @param[in] Multicast The multicast IP address to translate.\r
175 @param[out] Mac The buffer to hold the translated address.\r
2ff29212 176\r
177 @retval EFI_SUCCESS if the multicast IP is successfully translated to a\r
178 multicast MAC address.\r
179 @retval other Otherwise some error.\r
180\r
181**/\r
83cbd279 182EFI_STATUS\r
183Ip4GetMulticastMac (\r
184 IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,\r
185 IN IP4_ADDR Multicast,\r
186 OUT EFI_MAC_ADDRESS *Mac\r
187 );\r
188\r
2ff29212 189/**\r
190 Convert the multibyte field in IP header's byter order.\r
191 In spite of its name, it can also be used to convert from\r
192 host to network byte order.\r
193\r
3e8c18da 194 @param[in] Head The IP head to convert\r
2ff29212 195\r
196 @return Point to the converted IP head\r
197\r
198**/\r
83cbd279 199IP4_HEAD *\r
200Ip4NtohHead (\r
2ff29212 201 IN IP4_HEAD *Head\r
83cbd279 202 );\r
203\r
f1222593
JW
204\r
205/**\r
206 Validate that Ip/Netmask pair is OK to be used as station\r
207 address. Only continuous netmasks are supported. and check\r
208 that StationAddress is a unicast address on the newtwork.\r
209\r
210 @param[in] Ip The IP address to validate.\r
211 @param[in] Netmask The netmaks of the IP.\r
212\r
213 @retval TRUE The Ip/Netmask pair is valid.\r
214 @retval FALSE The Ip/Netmask pair is invalid.\r
215\r
216**/\r
217BOOLEAN\r
218Ip4StationAddressValid (\r
219 IN IP4_ADDR Ip,\r
220 IN IP4_ADDR Netmask\r
221 );\r
222\r
83cbd279 223#endif\r