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