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