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