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