]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
code scrub fix
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Common.h
CommitLineData
83cbd279 1/** @file\r
3e8c18da 2 Common definition for IP4.\r
3 \r
4Copyright (c) 2005 - 2006, Intel Corporation.<BR>\r
83cbd279 5All rights reserved. This program and the accompanying materials\r
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
22\r
5405e9a6 23typedef enum {\r
83cbd279 24 IP4_ETHER_PROTO = 0x0800,\r
25\r
26 IP4_PROTO_ICMP = 0x01,\r
27 IP4_PROTO_IGMP = 0x02,\r
28\r
29 //\r
30 // The packet is received as link level broadcast/multicast/promiscuous.\r
31 //\r
32 IP4_LINK_BROADCAST = 0x00000001,\r
33 IP4_LINK_MULTICAST = 0x00000002,\r
34 IP4_LINK_PROMISC = 0x00000004,\r
35\r
36 //\r
37 // IP4 address cast type classfication. Keep it true that any\r
38 // type bigger than or equal to LOCAL_BROADCAST is broadcast.\r
39 //\r
40 IP4_PROMISCUOUS = 1,\r
41 IP4_LOCAL_HOST,\r
42 IP4_MULTICAST,\r
43 IP4_LOCAL_BROADCAST, // Destination is 255.255.255.255\r
44 IP4_SUBNET_BROADCAST,\r
45 IP4_NET_BROADCAST,\r
46\r
47 //\r
48 // IP4 header flags\r
49 //\r
50 IP4_HEAD_DF_MASK = 0x4000,\r
51 IP4_HEAD_MF_MASK = 0x2000,\r
52 IP4_HEAD_OFFSET_MASK = 0x1fff\r
5405e9a6 53} IP_ENUM_TYPES;\r
83cbd279 54\r
55#define IP4_ALLZERO_ADDRESS 0x00000000u\r
56#define IP4_ALLONE_ADDRESS 0xFFFFFFFFu\r
57#define IP4_ALLSYSTEM_ADDRESS 0xE0000001u\r
58#define IP4_ALLROUTER_ADDRESS 0xE0000002u\r
59\r
96e1079f 60///\r
61/// Compose the fragment field to be used in the IP4 header.\r
62///\r
83cbd279 63#define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \\r
64 ((UINT16)(((Df) ? 0x4000 : 0) | ((Mf) ? 0x2000 : 0) | (((Offset) >> 3) & 0x1fff)))\r
65\r
66#define IP4_LAST_FRAGMENT(FragmentField) \\r
67 (((FragmentField) & IP4_HEAD_MF_MASK) == 0)\r
68\r
69#define IP4_FIRST_FRAGMENT(FragmentField) \\r
70 ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))\r
71\r
72#define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)\r
73\r
96e1079f 74///\r
75/// Conver the Microsecond to second. IP transmit/receive time is\r
76/// in the unit of microsecond. IP ticks once per second.\r
77///\r
83cbd279 78#define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)\r
79\r
2ff29212 80/**\r
81 Return the cast type (Unicast/Boradcast) specific to an\r
82 interface. All the addresses are host byte ordered.\r
83\r
3e8c18da 84 @param[in] IpAddr The IP address to classify in host byte order\r
85 @param[in] IpIf The interface that IpAddr received from\r
2ff29212 86\r
87 @return The cast type of this IP address specific to the interface.\r
88 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address\r
89 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the\r
90 interface\r
91 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface\r
92 @retval 0 Otherwise.\r
93\r
94**/\r
83cbd279 95INTN\r
96Ip4GetNetCast (\r
2ff29212 97 IN IP4_ADDR IpAddr,\r
98 IN IP4_INTERFACE *IpIf\r
83cbd279 99 );\r
100\r
2ff29212 101/**\r
102 Find the cast type of the packet related to the local host.\r
103 This isn't the same as link layer cast type. For example, DHCP\r
104 server may send local broadcast to the local unicast MAC.\r
105\r
3e8c18da 106 @param[in] IpSb The IP4 service binding instance that received the\r
107 packet\r
108 @param[in] Dst The destination address in the packet (host byte\r
109 order)\r
110 @param[in] Src The source address in the packet (host byte order)\r
2ff29212 111\r
112 @return The cast type for the Dst, it will return on the first non-promiscuous\r
113 cast type to a configured interface. If the packet doesn't match any of\r
114 the interface, multicast address and local broadcast address are checked.\r
115\r
116**/\r
83cbd279 117INTN\r
118Ip4GetHostCast (\r
2ff29212 119 IN IP4_SERVICE *IpSb,\r
120 IN IP4_ADDR Dst,\r
121 IN IP4_ADDR Src\r
83cbd279 122 );\r
123\r
2ff29212 124/**\r
125 Find an interface whose configured IP address is Ip.\r
126\r
3e8c18da 127 @param[in] IpSb The IP4 service binding instance\r
128 @param[in] Ip The Ip address (host byte order) to find\r
2ff29212 129\r
130 @return The IP4_INTERFACE point if found, otherwise NULL\r
131\r
132**/\r
83cbd279 133IP4_INTERFACE *\r
134Ip4FindInterface (\r
2ff29212 135 IN IP4_SERVICE *IpSb,\r
136 IN IP4_ADDR Ip\r
83cbd279 137 );\r
138\r
2ff29212 139/**\r
140 Find an interface that Ip is on that connected network.\r
141\r
3e8c18da 142 @param[in] IpSb The IP4 service binding instance\r
143 @param[in] Ip The Ip address (host byte order) to find\r
2ff29212 144\r
145 @return The IP4_INTERFACE point if found, otherwise NULL\r
146\r
147**/\r
83cbd279 148IP4_INTERFACE *\r
149Ip4FindNet (\r
2ff29212 150 IN IP4_SERVICE *IpSb,\r
151 IN IP4_ADDR Ip\r
83cbd279 152 );\r
153\r
2ff29212 154/**\r
155 Find an interface of the service with the same Ip/Netmask pair.\r
156\r
3e8c18da 157 @param[in] IpSb Ip4 service binding instance\r
158 @param[in] Ip The Ip adress to find (host byte order)\r
159 @param[in] Netmask The network to find (host byte order)\r
2ff29212 160\r
161 @return The IP4_INTERFACE point if found, otherwise NULL\r
162\r
163**/\r
83cbd279 164IP4_INTERFACE *\r
165Ip4FindStationAddress (\r
2ff29212 166 IN IP4_SERVICE *IpSb,\r
167 IN IP4_ADDR Ip,\r
168 IN IP4_ADDR Netmask\r
83cbd279 169 );\r
170\r
2ff29212 171/**\r
172 Get the MAC address for a multicast IP address. Call\r
173 Mnp's McastIpToMac to find the MAC address in stead of\r
174 hard code the NIC to be Ethernet.\r
175\r
3e8c18da 176 @param[in] Mnp The Mnp instance to get the MAC address.\r
177 @param[in] Multicast The multicast IP address to translate.\r
178 @param[out] Mac The buffer to hold the translated address.\r
2ff29212 179\r
180 @retval EFI_SUCCESS if the multicast IP is successfully translated to a\r
181 multicast MAC address.\r
182 @retval other Otherwise some error.\r
183\r
184**/\r
83cbd279 185EFI_STATUS\r
186Ip4GetMulticastMac (\r
187 IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,\r
188 IN IP4_ADDR Multicast,\r
189 OUT EFI_MAC_ADDRESS *Mac\r
190 );\r
191\r
2ff29212 192/**\r
193 Convert the multibyte field in IP header's byter order.\r
194 In spite of its name, it can also be used to convert from\r
195 host to network byte order.\r
196\r
3e8c18da 197 @param[in] Head The IP head to convert\r
2ff29212 198\r
199 @return Point to the converted IP head\r
200\r
201**/\r
83cbd279 202IP4_HEAD *\r
203Ip4NtohHead (\r
2ff29212 204 IN IP4_HEAD *Head\r
83cbd279 205 );\r
206\r
2ff29212 207/**\r
208 Set the Ip4 variable data.\r
209 \r
210 Save the list of all of the IPv4 addresses and subnet masks that are currently\r
211 being used to volatile variable storage.\r
212\r
3e8c18da 213 @param[in] IpSb Ip4 service binding instance\r
2ff29212 214\r
215 @retval EFI_SUCCESS Successfully set variable.\r
216 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.\r
217 @retval other Set variable failed.\r
218\r
219**/\r
83cbd279 220EFI_STATUS\r
221Ip4SetVariableData (\r
2ff29212 222 IN IP4_SERVICE *IpSb\r
83cbd279 223 );\r
224\r
2ff29212 225/**\r
226 Clear the variable and free the resource.\r
227\r
3e8c18da 228 @param[in] IpSb Ip4 service binding instance\r
2ff29212 229\r
230**/\r
83cbd279 231VOID\r
232Ip4ClearVariableData (\r
2ff29212 233 IN IP4_SERVICE *IpSb\r
83cbd279 234 );\r
235\r
236#endif\r