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