]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Ip6Dxe/Ip6Common.h
1. Fix bugs for PXE-IPv6 to accommodate the situation:
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Common.h
1 /** @file
2 Common definition and functions for IP6 driver.
3
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __EFI_IP6_COMMON_H__
17 #define __EFI_IP6_COMMON_H__
18
19 #define IP6_LINK_EQUAL(Mac1, Mac2) (CompareMem ((Mac1), (Mac2), sizeof (EFI_MAC_ADDRESS)) == 0)
20
21 //
22 // Convert the Microsecond to second. IP transmit/receive time is
23 // in the unit of microsecond. IP ticks once per second.
24 //
25 #define IP6_US_TO_SEC(Us) (((Us) + 999999) / 1000000)
26
27 #define IP6_ETHER_PROTO 0x86DD
28
29 #define IP6_MAC_LEN 6
30 #define IP6_IF_ID_LEN 8
31
32 #define IP6_INTERFACE_LOCAL_SCOPE 1
33 #define IP6_LINK_LOCAL_SCOPE 2
34 #define IP6_SITE_LOCAL_SCOPE 5
35
36 #define IP6_INFINIT_LIFETIME 0xFFFFFFFF
37
38 #define IP6_HOP_LIMIT 255
39 //
40 // Make it to 64 since all 54 bits are zero.
41 //
42 #define IP6_LINK_LOCAL_PREFIX_LENGTH 64
43
44 #define IP6_TIMER_INTERVAL_IN_MS 100
45 #define IP6_ONE_SECOND_IN_MS 1000
46
47 //
48 // The packet is received as link level broadcast/multicast/promiscuous.
49 //
50 #define IP6_LINK_BROADCAST 0x00000001
51 #define IP6_LINK_MULTICAST 0x00000002
52 #define IP6_LINK_PROMISC 0x00000004
53
54 #define IP6_U_BIT 0x02
55
56 typedef enum {
57 Ip6Promiscuous = 1,
58 Ip6Unicast,
59 Ip6Multicast,
60 Ip6AnyCast
61 } IP6_ADDRESS_TYPE;
62
63 typedef struct _IP6_INTERFACE IP6_INTERFACE;
64 typedef struct _IP6_PROTOCOL IP6_PROTOCOL;
65 typedef struct _IP6_SERVICE IP6_SERVICE;
66 typedef struct _IP6_ADDRESS_INFO IP6_ADDRESS_INFO;
67
68 /**
69 Build a array of EFI_IP6_ADDRESS_INFO to be returned to the caller. The number
70 of EFI_IP6_ADDRESS_INFO is also returned. If AddressList is NULL,
71 only the address count is returned.
72
73 @param[in] IpSb The IP6 service binding instance.
74 @param[out] AddressCount The number of returned addresses.
75 @param[out] AddressList The pointer to the array of EFI_IP6_ADDRESS_INFO.
76 This is an optional parameter.
77
78
79 @retval EFI_SUCCESS The address array is successfully build
80 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the address info.
81 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
82
83 **/
84 EFI_STATUS
85 Ip6BuildEfiAddressList (
86 IN IP6_SERVICE *IpSb,
87 OUT UINT32 *AddressCount,
88 OUT EFI_IP6_ADDRESS_INFO **AddressList OPTIONAL
89 );
90
91 /**
92 Generate the multicast addresses identify the group of all IPv6 nodes or IPv6
93 routers defined in RFC4291.
94
95 All Nodes Addresses: FF01::1, FF02::1.
96 All Router Addresses: FF01::2, FF02::2, FF05::2.
97
98 @param[in] Router If TRUE, generate all routers addresses,
99 else generate all node addresses.
100 @param[in] Scope interface-local(1), link-local(2), or site-local(5)
101 @param[out] Ip6Addr The generated multicast address.
102
103 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
104 @retval EFI_SUCCESS The address is generated.
105
106 **/
107 EFI_STATUS
108 Ip6SetToAllNodeMulticast (
109 IN BOOLEAN Router,
110 IN UINT8 Scope,
111 OUT EFI_IPv6_ADDRESS *Ip6Addr
112 );
113
114 /**
115 This function converts MAC address to 64 bits interface ID according to RFC4291
116 and returns the interface ID. Currently only 48-bit MAC address is supported by
117 this function.
118
119 @param[in, out] IpSb The IP6 service binding instance.
120
121 @retval NULL The operation fails.
122 @return Pointer to the generated interface ID.
123
124 **/
125 UINT8 *
126 Ip6CreateInterfaceID (
127 IN OUT IP6_SERVICE *IpSb
128 );
129
130 /**
131 This function creates link-local address from interface identifier. The
132 interface identifier is normally created from MAC address. It might be manually
133 configured by administrator if the link-local address created from MAC address
134 is a duplicate address.
135
136 @param[in, out] IpSb The IP6 service binding instance.
137
138 @retval NULL If the operation fails.
139 @return The generated Link Local address, in network order.
140
141 **/
142 EFI_IPv6_ADDRESS *
143 Ip6CreateLinkLocalAddr (
144 IN OUT IP6_SERVICE *IpSb
145 );
146
147 /**
148 Compute the solicited-node multicast address for an unicast or anycast address,
149 by taking the low-order 24 bits of this address, and appending those bits to
150 the prefix FF02:0:0:0:0:1:FF00::/104.
151
152 @param Ip6Addr The unicast or anycast address, in network order.
153 @param MulticastAddr The generated solicited-node multicast address,
154 in network order.
155
156 **/
157 VOID
158 Ip6CreateSNMulticastAddr (
159 IN EFI_IPv6_ADDRESS *Ip6Addr,
160 OUT EFI_IPv6_ADDRESS *MulticastAddr
161 );
162
163 /**
164 Check whether the incoming Ipv6 address is a solicited-node multicast address.
165
166 @param[in] Ip6 Ip6 address, in network order.
167
168 @retval TRUE Yes, solicited-node multicast address
169 @retval FALSE No
170
171 **/
172 BOOLEAN
173 Ip6IsSNMulticastAddr (
174 IN EFI_IPv6_ADDRESS *Ip6
175 );
176
177 /**
178 Check whether the incoming IPv6 address is one of the maintained address in
179 the IP6 service binding instance.
180
181 @param[in] IpSb Points to a IP6 service binding instance
182 @param[in] Address The IP6 address to be checked.
183 @param[out] Interface If not NULL, output the IP6 interface which
184 maintains the Address.
185 @param[out] AddressInfo If not NULL, output the IP6 address information
186 of the Address.
187
188 @retval TRUE Yes, it is one of the maintained addresses.
189 @retval FALSE No, it is not one of the maintained addresses.
190
191 **/
192 BOOLEAN
193 Ip6IsOneOfSetAddress (
194 IN IP6_SERVICE *IpSb,
195 IN EFI_IPv6_ADDRESS *Address,
196 OUT IP6_INTERFACE **Interface OPTIONAL,
197 OUT IP6_ADDRESS_INFO **AddressInfo OPTIONAL
198 );
199
200 /**
201 Check whether the incoming MAC address is valid.
202
203 @param[in] IpSb Points to a IP6 service binding instance.
204 @param[in] LinkAddress The MAC address.
205
206 @retval TRUE Yes, it is valid.
207 @retval FALSE No, it is not valid.
208
209 **/
210 BOOLEAN
211 Ip6IsValidLinkAddress (
212 IN IP6_SERVICE *IpSb,
213 IN EFI_MAC_ADDRESS *LinkAddress
214 );
215
216
217 /**
218 Copy the PrefixLength bits from Src to Dest.
219
220 @param[out] Dest A pointer to the buffer to copy to.
221 @param[in] Src A pointer to the buffer to copy from.
222 @param[in] PrefixLength The number of bits to copy.
223
224 **/
225 VOID
226 Ip6CopyAddressByPrefix (
227 OUT EFI_IPv6_ADDRESS *Dest,
228 IN EFI_IPv6_ADDRESS *Src,
229 IN UINT8 PrefixLength
230 );
231
232 /**
233 Insert a node IP6_ADDRESS_INFO to an IP6 interface.
234
235 @param[in, out] IpIf Points to an IP6 interface.
236 @param[in] AddrInfo Points to an IP6_ADDRESS_INFO.
237
238 **/
239 VOID
240 Ip6AddAddr (
241 IN OUT IP6_INTERFACE *IpIf,
242 IN IP6_ADDRESS_INFO *AddrInfo
243 );
244
245 /**
246 Remove the IPv6 address from the address list node points to IP6_ADDRESS_INFO.
247
248 This function removes the matching IPv6 addresses from the address list and
249 adjusts the address count of the address list. If IpSb is not NULL, this function
250 calls Ip6LeaveGroup to see whether it should call Mnp->Groups() to remove the
251 its solicited-node multicast MAC address from the filter list and sends out
252 a Multicast Listener Done. If Prefix is NULL, all address in the address list
253 will be removed. If Prefix is not NULL, the address that matching the Prefix
254 with PrefixLength in the address list will be removed.
255
256 @param[in] IpSb NULL or points to IP6 service binding instance.
257 @param[in, out] AddressList address list array
258 @param[in, out] AddressCount the count of addresses in address list array
259 @param[in] Prefix NULL or an IPv6 address prefix
260 @param[in] PrefixLength the length of Prefix
261
262 @retval EFI_SUCCESS The operation completed successfully.
263 @retval EFI_NOT_FOUND The address matching the Prefix with PrefixLength
264 cannot be found in address list.
265 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
266
267 **/
268 EFI_STATUS
269 Ip6RemoveAddr (
270 IN IP6_SERVICE *IpSb OPTIONAL,
271 IN OUT LIST_ENTRY *AddressList,
272 IN OUT UINT32 *AddressCount,
273 IN EFI_IPv6_ADDRESS *Prefix OPTIONAL,
274 IN UINT8 PrefixLength
275 );
276
277 /**
278 Set the Ip6 variable data.
279
280 @param[in] IpSb Points to an IP6 service binding instance
281
282 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.
283 @retval other Set variable failed.
284
285 **/
286 EFI_STATUS
287 Ip6SetVariableData (
288 IN IP6_SERVICE *IpSb
289 );
290
291 /**
292 Clear the variable and free the resource.
293
294 @param[in] IpSb Ip6 service binding instance.
295
296 **/
297 VOID
298 Ip6ClearVariableData (
299 IN IP6_SERVICE *IpSb
300 );
301
302 /**
303 Get the MAC address for a multicast IP address. Call
304 Mnp's McastIpToMac to find the MAC address instead of
305 hard-coding the NIC to be Ethernet.
306
307 @param[in] Mnp The Mnp instance to get the MAC address.
308 @param[in] Multicast The multicast IP address to translate.
309 @param[out] Mac The buffer to hold the translated address.
310
311 @retval EFI_SUCCESS The multicast IP is successfully
312 translated to a multicast MAC address.
313 @retval Other The address is not converted because an error occurred.
314
315 **/
316 EFI_STATUS
317 Ip6GetMulticastMac (
318 IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
319 IN EFI_IPv6_ADDRESS *Multicast,
320 OUT EFI_MAC_ADDRESS *Mac
321 );
322
323 /**
324 Convert the multibyte field in IP header's byter order.
325 In spite of its name, it can also be used to convert from
326 host to network byte order.
327
328 @param[in, out] Head The IP head to convert.
329
330 @return Point to the converted IP head.
331
332 **/
333 EFI_IP6_HEADER *
334 Ip6NtohHead (
335 IN OUT EFI_IP6_HEADER *Head
336 );
337
338 #endif