]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Common.h
CommitLineData
83cbd279 1/** @file\r
3e8c18da 2 Common definition for IP4.\r
3 \r
e5eed7d3
HT
4Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>\r
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
66#define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)\r
67\r
96e1079f 68///\r
69/// Conver the Microsecond to second. IP transmit/receive time is\r
70/// in the unit of microsecond. IP ticks once per second.\r
71///\r
83cbd279 72#define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)\r
73\r
2ff29212 74/**\r
75 Return the cast type (Unicast/Boradcast) specific to an\r
76 interface. All the addresses are host byte ordered.\r
77\r
3e8c18da 78 @param[in] IpAddr The IP address to classify in host byte order\r
79 @param[in] IpIf The interface that IpAddr received from\r
2ff29212 80\r
81 @return The cast type of this IP address specific to the interface.\r
82 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address\r
83 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the\r
84 interface\r
85 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface\r
86 @retval 0 Otherwise.\r
87\r
88**/\r
83cbd279 89INTN\r
90Ip4GetNetCast (\r
2ff29212 91 IN IP4_ADDR IpAddr,\r
92 IN IP4_INTERFACE *IpIf\r
83cbd279 93 );\r
94\r
2ff29212 95/**\r
96 Find the cast type of the packet related to the local host.\r
97 This isn't the same as link layer cast type. For example, DHCP\r
98 server may send local broadcast to the local unicast MAC.\r
99\r
3e8c18da 100 @param[in] IpSb The IP4 service binding instance that received the\r
101 packet\r
102 @param[in] Dst The destination address in the packet (host byte\r
103 order)\r
104 @param[in] Src The source address in the packet (host byte order)\r
2ff29212 105\r
106 @return The cast type for the Dst, it will return on the first non-promiscuous\r
107 cast type to a configured interface. If the packet doesn't match any of\r
108 the interface, multicast address and local broadcast address are checked.\r
109\r
110**/\r
83cbd279 111INTN\r
112Ip4GetHostCast (\r
2ff29212 113 IN IP4_SERVICE *IpSb,\r
114 IN IP4_ADDR Dst,\r
115 IN IP4_ADDR Src\r
83cbd279 116 );\r
117\r
2ff29212 118/**\r
119 Find an interface whose configured IP address is Ip.\r
120\r
3e8c18da 121 @param[in] IpSb The IP4 service binding instance\r
122 @param[in] Ip The Ip address (host byte order) to find\r
2ff29212 123\r
124 @return The IP4_INTERFACE point if found, otherwise NULL\r
125\r
126**/\r
83cbd279 127IP4_INTERFACE *\r
128Ip4FindInterface (\r
2ff29212 129 IN IP4_SERVICE *IpSb,\r
130 IN IP4_ADDR Ip\r
83cbd279 131 );\r
132\r
2ff29212 133/**\r
134 Find an interface that Ip is on that connected network.\r
135\r
3e8c18da 136 @param[in] IpSb The IP4 service binding instance\r
137 @param[in] Ip The Ip address (host byte order) to find\r
2ff29212 138\r
139 @return The IP4_INTERFACE point if found, otherwise NULL\r
140\r
141**/\r
83cbd279 142IP4_INTERFACE *\r
143Ip4FindNet (\r
2ff29212 144 IN IP4_SERVICE *IpSb,\r
145 IN IP4_ADDR Ip\r
83cbd279 146 );\r
147\r
2ff29212 148/**\r
149 Find an interface of the service with the same Ip/Netmask pair.\r
150\r
3e8c18da 151 @param[in] IpSb Ip4 service binding instance\r
152 @param[in] Ip The Ip adress to find (host byte order)\r
153 @param[in] Netmask The network to find (host byte order)\r
2ff29212 154\r
155 @return The IP4_INTERFACE point if found, otherwise NULL\r
156\r
157**/\r
83cbd279 158IP4_INTERFACE *\r
159Ip4FindStationAddress (\r
2ff29212 160 IN IP4_SERVICE *IpSb,\r
161 IN IP4_ADDR Ip,\r
162 IN IP4_ADDR Netmask\r
83cbd279 163 );\r
164\r
2ff29212 165/**\r
166 Get the MAC address for a multicast IP address. Call\r
167 Mnp's McastIpToMac to find the MAC address in stead of\r
168 hard code the NIC to be Ethernet.\r
169\r
3e8c18da 170 @param[in] Mnp The Mnp instance to get the MAC address.\r
171 @param[in] Multicast The multicast IP address to translate.\r
172 @param[out] Mac The buffer to hold the translated address.\r
2ff29212 173\r
174 @retval EFI_SUCCESS if the multicast IP is successfully translated to a\r
175 multicast MAC address.\r
176 @retval other Otherwise some error.\r
177\r
178**/\r
83cbd279 179EFI_STATUS\r
180Ip4GetMulticastMac (\r
181 IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,\r
182 IN IP4_ADDR Multicast,\r
183 OUT EFI_MAC_ADDRESS *Mac\r
184 );\r
185\r
2ff29212 186/**\r
187 Convert the multibyte field in IP header's byter order.\r
188 In spite of its name, it can also be used to convert from\r
189 host to network byte order.\r
190\r
3e8c18da 191 @param[in] Head The IP head to convert\r
2ff29212 192\r
193 @return Point to the converted IP head\r
194\r
195**/\r
83cbd279 196IP4_HEAD *\r
197Ip4NtohHead (\r
2ff29212 198 IN IP4_HEAD *Head\r
83cbd279 199 );\r
200\r
2ff29212 201/**\r
202 Set the Ip4 variable data.\r
203 \r
204 Save the list of all of the IPv4 addresses and subnet masks that are currently\r
205 being used to volatile variable storage.\r
206\r
3e8c18da 207 @param[in] IpSb Ip4 service binding instance\r
2ff29212 208\r
209 @retval EFI_SUCCESS Successfully set variable.\r
210 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.\r
211 @retval other Set variable failed.\r
212\r
213**/\r
83cbd279 214EFI_STATUS\r
215Ip4SetVariableData (\r
2ff29212 216 IN IP4_SERVICE *IpSb\r
83cbd279 217 );\r
218\r
2ff29212 219/**\r
220 Clear the variable and free the resource.\r
221\r
3e8c18da 222 @param[in] IpSb Ip4 service binding instance\r
2ff29212 223\r
224**/\r
83cbd279 225VOID\r
226Ip4ClearVariableData (\r
2ff29212 227 IN IP4_SERVICE *IpSb\r
83cbd279 228 );\r
229\r
230#endif\r