]>
Commit | Line | Data |
---|---|---|
97b38d4e | 1 | /** @file\r |
1204fe83 | 2 | This library is only intended to be used by UEFI network stack modules.\r |
e9b67286 | 3 | It provides basic functions for the UEFI network stack.\r |
97b38d4e | 4 | \r |
9f5ca5ef | 5 | Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r |
cd5ebaa0 | 6 | This program and the accompanying materials\r |
97b38d4e | 7 | are licensed and made available under the terms and conditions of the BSD License\r |
64a80549 | 8 | which accompanies this distribution. The full text of the license may be found at<BR>\r |
97b38d4e | 9 | http://opensource.org/licenses/bsd-license.php\r |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef _NET_LIB_H_\r | |
17 | #define _NET_LIB_H_\r | |
18 | \r | |
fb115c61 | 19 | #include <Protocol/Ip6.h>\r |
20 | \r | |
1204fe83 | 21 | #include <Library/BaseLib.h>\r |
7b126c2e | 22 | #include <Library/BaseMemoryLib.h>\r |
1204fe83 | 23 | \r |
97b38d4e | 24 | typedef UINT32 IP4_ADDR;\r |
25 | typedef UINT32 TCP_SEQNO;\r | |
26 | typedef UINT16 TCP_PORTNO;\r | |
27 | \r | |
b45b45b2 | 28 | \r |
29 | #define NET_ETHER_ADDR_LEN 6\r | |
30 | #define NET_IFTYPE_ETHERNET 0x01\r | |
31 | \r | |
779ae357 | 32 | #define NET_VLAN_TAG_LEN 4\r |
33 | #define ETHER_TYPE_VLAN 0x8100\r | |
34 | \r | |
b45b45b2 | 35 | #define EFI_IP_PROTO_UDP 0x11\r |
36 | #define EFI_IP_PROTO_TCP 0x06\r | |
37 | #define EFI_IP_PROTO_ICMP 0x01\r | |
f6b7393c | 38 | #define IP4_PROTO_IGMP 0x02\r |
39 | #define IP6_ICMP 58\r | |
dba6e9a9 JW |
40 | #define DNS_MAX_NAME_SIZE 255\r |
41 | #define DNS_MAX_MESSAGE_SIZE 512\r | |
b45b45b2 | 42 | \r |
43 | //\r | |
44 | // The address classification\r | |
45 | //\r | |
3289dcba FS |
46 | #define IP4_ADDR_CLASSA 1 // Deprecated\r |
47 | #define IP4_ADDR_CLASSB 2 // Deprecated\r | |
48 | #define IP4_ADDR_CLASSC 3 // Deprecated\r | |
b45b45b2 | 49 | #define IP4_ADDR_CLASSD 4\r |
50 | #define IP4_ADDR_CLASSE 5\r | |
51 | \r | |
52 | #define IP4_MASK_NUM 33\r | |
f6b7393c | 53 | #define IP6_PREFIX_NUM 129\r |
b45b45b2 | 54 | \r |
364f4efa ZL |
55 | #define IP4_MASK_MAX 32 \r |
56 | #define IP6_PREFIX_MAX 128\r | |
57 | \r | |
b45b45b2 | 58 | #define IP6_HOP_BY_HOP 0\r |
59 | #define IP6_DESTINATION 60\r | |
25400c63 | 60 | #define IP6_ROUTING 43\r |
b45b45b2 | 61 | #define IP6_FRAGMENT 44\r |
62 | #define IP6_AH 51\r | |
63 | #define IP6_ESP 50\r | |
64 | #define IP6_NO_NEXT_HEADER 59\r | |
65 | \r | |
a1503a32 | 66 | #define IP_VERSION_4 4\r |
67 | #define IP_VERSION_6 6\r | |
fb115c61 | 68 | \r |
501793fa RN |
69 | #define IP6_PREFIX_LENGTH 64\r |
70 | \r | |
a57cdf33 JW |
71 | //\r |
72 | // DNS QTYPE values\r | |
73 | //\r | |
74 | #define DNS_TYPE_A 1\r | |
75 | #define DNS_TYPE_NS 2\r | |
76 | #define DNS_TYPE_CNAME 5\r | |
77 | #define DNS_TYPE_SOA 6\r | |
78 | #define DNS_TYPE_WKS 11\r | |
79 | #define DNS_TYPE_PTR 12\r | |
80 | #define DNS_TYPE_HINFO 13\r | |
81 | #define DNS_TYPE_MINFO 14\r | |
82 | #define DNS_TYPE_MX 15\r | |
83 | #define DNS_TYPE_TXT 16\r | |
84 | #define DNS_TYPE_AAAA 28\r | |
85 | #define DNS_TYPE_SRV_RR 33\r | |
86 | #define DNS_TYPE_AXFR 252\r | |
87 | #define DNS_TYPE_MAILB 253\r | |
88 | #define DNS_TYPE_ANY 255\r | |
89 | \r | |
90 | //\r | |
91 | // DNS QCLASS values\r | |
92 | //\r | |
93 | #define DNS_CLASS_INET 1\r | |
94 | #define DNS_CLASS_CH 3\r | |
95 | #define DNS_CLASS_HS 4\r | |
96 | #define DNS_CLASS_ANY 255\r | |
97 | \r | |
ca4e4323 | 98 | //\r |
99 | // Number of 100ns units time Interval for network media state detect\r | |
100 | //\r | |
101 | #define MEDIA_STATE_DETECT_TIME_INTERVAL 1000000U\r | |
102 | \r | |
103 | \r | |
97b38d4e | 104 | #pragma pack(1)\r |
105 | \r | |
106 | //\r | |
107 | // Ethernet head definition\r | |
108 | //\r | |
109 | typedef struct {\r | |
110 | UINT8 DstMac [NET_ETHER_ADDR_LEN];\r | |
111 | UINT8 SrcMac [NET_ETHER_ADDR_LEN];\r | |
112 | UINT16 EtherType;\r | |
113 | } ETHER_HEAD;\r | |
114 | \r | |
779ae357 | 115 | //\r |
116 | // 802.1Q VLAN Tag Control Information\r | |
117 | //\r | |
118 | typedef union {\r | |
119 | struct {\r | |
120 | UINT16 Vid : 12; // Unique VLAN identifier (0 to 4094)\r | |
121 | UINT16 Cfi : 1; // Canonical Format Indicator\r | |
122 | UINT16 Priority : 3; // 802.1Q priority level (0 to 7)\r | |
123 | } Bits;\r | |
124 | UINT16 Uint16;\r | |
125 | } VLAN_TCI;\r | |
126 | \r | |
127 | #define VLAN_TCI_CFI_CANONICAL_MAC 0\r | |
128 | #define VLAN_TCI_CFI_NON_CANONICAL_MAC 1\r | |
97b38d4e | 129 | \r |
130 | //\r | |
131 | // The EFI_IP4_HEADER is hard to use because the source and\r | |
132 | // destination address are defined as EFI_IPv4_ADDRESS, which\r | |
133 | // is a structure. Two structures can't be compared or masked\r | |
134 | // directly. This is why there is an internal representation.\r | |
135 | //\r | |
136 | typedef struct {\r | |
137 | UINT8 HeadLen : 4;\r | |
138 | UINT8 Ver : 4;\r | |
139 | UINT8 Tos;\r | |
140 | UINT16 TotalLen;\r | |
141 | UINT16 Id;\r | |
142 | UINT16 Fragment;\r | |
143 | UINT8 Ttl;\r | |
144 | UINT8 Protocol;\r | |
145 | UINT16 Checksum;\r | |
146 | IP4_ADDR Src;\r | |
147 | IP4_ADDR Dst;\r | |
148 | } IP4_HEAD;\r | |
149 | \r | |
150 | \r | |
151 | //\r | |
e9b67286 | 152 | // ICMP head definition. Each ICMP message is categorized as either an error\r |
97b38d4e | 153 | // message or query message. Two message types have their own head format.\r |
154 | //\r | |
155 | typedef struct {\r | |
156 | UINT8 Type;\r | |
157 | UINT8 Code;\r | |
158 | UINT16 Checksum;\r | |
159 | } IP4_ICMP_HEAD;\r | |
160 | \r | |
161 | typedef struct {\r | |
162 | IP4_ICMP_HEAD Head;\r | |
163 | UINT32 Fourth; // 4th filed of the head, it depends on Type.\r | |
164 | IP4_HEAD IpHead;\r | |
165 | } IP4_ICMP_ERROR_HEAD;\r | |
166 | \r | |
167 | typedef struct {\r | |
168 | IP4_ICMP_HEAD Head;\r | |
169 | UINT16 Id;\r | |
170 | UINT16 Seq;\r | |
171 | } IP4_ICMP_QUERY_HEAD;\r | |
172 | \r | |
fb115c61 | 173 | typedef struct {\r |
174 | UINT8 Type;\r | |
175 | UINT8 Code;\r | |
176 | UINT16 Checksum;\r | |
177 | } IP6_ICMP_HEAD;\r | |
178 | \r | |
179 | typedef struct {\r | |
180 | IP6_ICMP_HEAD Head;\r | |
181 | UINT32 Fourth;\r | |
182 | EFI_IP6_HEADER IpHead;\r | |
183 | } IP6_ICMP_ERROR_HEAD;\r | |
184 | \r | |
185 | typedef struct {\r | |
186 | IP6_ICMP_HEAD Head;\r | |
187 | UINT32 Fourth;\r | |
188 | } IP6_ICMP_INFORMATION_HEAD;\r | |
97b38d4e | 189 | \r |
190 | //\r | |
191 | // UDP header definition\r | |
192 | //\r | |
193 | typedef struct {\r | |
194 | UINT16 SrcPort;\r | |
195 | UINT16 DstPort;\r | |
196 | UINT16 Length;\r | |
197 | UINT16 Checksum;\r | |
fb115c61 | 198 | } EFI_UDP_HEADER;\r |
97b38d4e | 199 | \r |
200 | //\r | |
201 | // TCP header definition\r | |
202 | //\r | |
203 | typedef struct {\r | |
204 | TCP_PORTNO SrcPort;\r | |
205 | TCP_PORTNO DstPort;\r | |
206 | TCP_SEQNO Seq;\r | |
207 | TCP_SEQNO Ack;\r | |
208 | UINT8 Res : 4;\r | |
209 | UINT8 HeadLen : 4;\r | |
210 | UINT8 Flag;\r | |
211 | UINT16 Wnd;\r | |
212 | UINT16 Checksum;\r | |
213 | UINT16 Urg;\r | |
214 | } TCP_HEAD;\r | |
215 | \r | |
216 | #pragma pack()\r | |
217 | \r | |
218 | #define NET_MAC_EQUAL(pMac1, pMac2, Len) \\r | |
219 | (CompareMem ((pMac1), (pMac2), Len) == 0)\r | |
220 | \r | |
221 | #define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \\r | |
222 | (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))\r | |
223 | \r | |
1204fe83 | 224 | #define NTOHL(x) SwapBytes32 (x)\r |
97b38d4e | 225 | \r |
226 | #define HTONL(x) NTOHL(x)\r | |
227 | \r | |
1204fe83 | 228 | #define NTOHS(x) SwapBytes16 (x)\r |
97b38d4e | 229 | \r |
f6b7393c | 230 | #define HTONS(x) NTOHS(x)\r |
231 | #define NTOHLL(x) SwapBytes64 (x)\r | |
232 | #define HTONLL(x) NTOHLL(x)\r | |
233 | #define NTOHLLL(x) Ip6Swap128 (x)\r | |
234 | #define HTONLLL(x) NTOHLLL(x)\r | |
97b38d4e | 235 | \r |
236 | //\r | |
237 | // Test the IP's attribute, All the IPs are in host byte order.\r | |
238 | //\r | |
239 | #define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)\r | |
3289dcba | 240 | #define IP4_IS_UNSPECIFIED(Ip) ((Ip) == 0)\r |
97b38d4e | 241 | #define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)\r |
242 | #define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))\r | |
364f4efa | 243 | #define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != (IP4_MASK_MAX + 1))\r |
97b38d4e | 244 | \r |
3a15fd52 | 245 | #define IP6_IS_MULTICAST(Ip6) (((Ip6)->Addr[0]) == 0xFF)\r |
246 | \r | |
97b38d4e | 247 | //\r |
248 | // Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.\r | |
249 | //\r | |
250 | #define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))\r | |
251 | #define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))\r | |
252 | #define EFI_IP4_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)\r | |
253 | \r | |
fb115c61 | 254 | #define EFI_IP6_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv6_ADDRESS)) == 0)\r |
255 | \r | |
42372879 | 256 | #define IP4_COPY_ADDRESS(Dest, Src) (CopyMem ((Dest), (Src), sizeof (EFI_IPv4_ADDRESS)))\r |
f6b7393c | 257 | #define IP6_COPY_ADDRESS(Dest, Src) (CopyMem ((Dest), (Src), sizeof (EFI_IPv6_ADDRESS)))\r |
258 | #define IP6_COPY_LINK_ADDRESS(Mac1, Mac2) (CopyMem ((Mac1), (Mac2), sizeof (EFI_MAC_ADDRESS)))\r | |
259 | \r | |
260 | //\r | |
1204fe83 | 261 | // The debug level definition. This value is also used as the\r |
86ac8fb2 | 262 | // syslog's severity level. Don't change it.\r |
f6b7393c | 263 | //\r |
264 | #define NETDEBUG_LEVEL_TRACE 5\r | |
265 | #define NETDEBUG_LEVEL_WARNING 4\r | |
266 | #define NETDEBUG_LEVEL_ERROR 3\r | |
267 | \r | |
268 | //\r | |
1204fe83 | 269 | // Network debug message is sent out as syslog packet.\r |
f6b7393c | 270 | //\r |
1204fe83 | 271 | #define NET_SYSLOG_FACILITY 16 // Syslog local facility local use\r |
272 | #define NET_SYSLOG_PACKET_LEN 512\r | |
273 | #define NET_SYSLOG_TX_TIMEOUT (500 * 1000 * 10) // 500ms\r | |
274 | #define NET_DEBUG_MSG_LEN 470 // 512 - (ether+ip4+udp4 head length)\r | |
f6b7393c | 275 | \r |
276 | //\r | |
1204fe83 | 277 | // The debug output expects the ASCII format string, Use %a to print ASCII\r |
278 | // string, and %s to print UNICODE string. PrintArg must be enclosed in ().\r | |
f6b7393c | 279 | // For example: NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name));\r |
280 | //\r | |
281 | #define NET_DEBUG_TRACE(Module, PrintArg) \\r | |
282 | NetDebugOutput ( \\r | |
283 | NETDEBUG_LEVEL_TRACE, \\r | |
284 | Module, \\r | |
285 | __FILE__, \\r | |
286 | __LINE__, \\r | |
287 | NetDebugASPrint PrintArg \\r | |
288 | )\r | |
289 | \r | |
290 | #define NET_DEBUG_WARNING(Module, PrintArg) \\r | |
291 | NetDebugOutput ( \\r | |
292 | NETDEBUG_LEVEL_WARNING, \\r | |
293 | Module, \\r | |
294 | __FILE__, \\r | |
295 | __LINE__, \\r | |
296 | NetDebugASPrint PrintArg \\r | |
297 | )\r | |
298 | \r | |
299 | #define NET_DEBUG_ERROR(Module, PrintArg) \\r | |
300 | NetDebugOutput ( \\r | |
301 | NETDEBUG_LEVEL_ERROR, \\r | |
302 | Module, \\r | |
303 | __FILE__, \\r | |
304 | __LINE__, \\r | |
305 | NetDebugASPrint PrintArg \\r | |
306 | )\r | |
307 | \r | |
308 | /**\r | |
1204fe83 | 309 | Allocate a buffer, then format the message to it. This is a\r |
310 | help function for the NET_DEBUG_XXX macros. The PrintArg of\r | |
311 | these macros treats the variable length print parameters as a\r | |
f6b7393c | 312 | single parameter, and pass it to the NetDebugASPrint. For\r |
313 | example, NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name))\r | |
1204fe83 | 314 | if extracted to:\r |
315 | \r | |
f6b7393c | 316 | NetDebugOutput (\r |
1204fe83 | 317 | NETDEBUG_LEVEL_TRACE,\r |
318 | "Tcp",\r | |
f6b7393c | 319 | __FILE__,\r |
320 | __LINE__,\r | |
1204fe83 | 321 | NetDebugASPrint ("State transit to %a\n", Name)\r |
322 | )\r | |
323 | \r | |
f6b7393c | 324 | @param Format The ASCII format string.\r |
1204fe83 | 325 | @param ... The variable length parameter whose format is determined\r |
f6b7393c | 326 | by the Format string.\r |
327 | \r | |
328 | @return The buffer containing the formatted message,\r | |
64a80549 | 329 | or NULL if memory allocation failed.\r |
f6b7393c | 330 | \r |
331 | **/\r | |
332 | CHAR8 *\r | |
e798cd87 | 333 | EFIAPI\r |
f6b7393c | 334 | NetDebugASPrint (\r |
335 | IN CHAR8 *Format,\r | |
336 | ...\r | |
337 | );\r | |
338 | \r | |
339 | /**\r | |
340 | Builds an UDP4 syslog packet and send it using SNP.\r | |
341 | \r | |
342 | This function will locate a instance of SNP then send the message through it.\r | |
343 | Because it isn't open the SNP BY_DRIVER, apply caution when using it.\r | |
344 | \r | |
86ac8fb2 GL |
345 | @param Level The severity level of the message.\r |
346 | @param Module The Module that generates the log.\r | |
f6b7393c | 347 | @param File The file that contains the log.\r |
348 | @param Line The exact line that contains the log.\r | |
349 | @param Message The user message to log.\r | |
350 | \r | |
351 | @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r | |
352 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet\r | |
1204fe83 | 353 | @retval EFI_SUCCESS The log is discard because that it is more verbose\r |
f6b7393c | 354 | than the mNetDebugLevelMax. Or, it has been sent out.\r |
1204fe83 | 355 | **/\r |
f6b7393c | 356 | EFI_STATUS\r |
e798cd87 | 357 | EFIAPI\r |
f6b7393c | 358 | NetDebugOutput (\r |
1204fe83 | 359 | IN UINT32 Level,\r |
f6b7393c | 360 | IN UINT8 *Module,\r |
361 | IN UINT8 *File,\r | |
362 | IN UINT32 Line,\r | |
363 | IN UINT8 *Message\r | |
364 | );\r | |
365 | \r | |
fb115c61 | 366 | \r |
97b38d4e | 367 | /**\r |
1204fe83 | 368 | Return the length of the mask.\r |
369 | \r | |
e9b67286 | 370 | Return the length of the mask. Valid values are 0 to 32.\r |
3a1ab4bc | 371 | If the mask is invalid, return the invalid length 33, which is IP4_MASK_NUM.\r |
97b38d4e | 372 | NetMask is in the host byte order.\r |
373 | \r | |
ae213b7d | 374 | @param[in] NetMask The netmask to get the length from.\r |
97b38d4e | 375 | \r |
e9b67286 | 376 | @return The length of the netmask, or IP4_MASK_NUM (33) if the mask is invalid.\r |
1204fe83 | 377 | \r |
97b38d4e | 378 | **/\r |
379 | INTN\r | |
380 | EFIAPI\r | |
381 | NetGetMaskLength (\r | |
ae213b7d | 382 | IN IP4_ADDR NetMask\r |
97b38d4e | 383 | );\r |
384 | \r | |
385 | /**\r | |
3a1ab4bc | 386 | Return the class of the IP address, such as class A, B, C.\r |
97b38d4e | 387 | Addr is in host byte order.\r |
1204fe83 | 388 | \r |
3289dcba FS |
389 | [ATTENTION]\r |
390 | Classful addressing (IP class A/B/C) has been deprecated according to RFC4632.\r | |
391 | Caller of this function could only check the returned value against\r | |
392 | IP4_ADDR_CLASSD (multicast) or IP4_ADDR_CLASSE (reserved) now.\r | |
393 | \r | |
3a1ab4bc | 394 | The address of class A starts with 0.\r |
395 | If the address belong to class A, return IP4_ADDR_CLASSA.\r | |
1204fe83 | 396 | The address of class B starts with 10.\r |
3a1ab4bc | 397 | If the address belong to class B, return IP4_ADDR_CLASSB.\r |
1204fe83 | 398 | The address of class C starts with 110.\r |
3a1ab4bc | 399 | If the address belong to class C, return IP4_ADDR_CLASSC.\r |
1204fe83 | 400 | The address of class D starts with 1110.\r |
3a1ab4bc | 401 | If the address belong to class D, return IP4_ADDR_CLASSD.\r |
402 | The address of class E starts with 1111.\r | |
403 | If the address belong to class E, return IP4_ADDR_CLASSE.\r | |
97b38d4e | 404 | \r |
1204fe83 | 405 | \r |
ae213b7d | 406 | @param[in] Addr The address to get the class from.\r |
97b38d4e | 407 | \r |
ae213b7d | 408 | @return IP address class, such as IP4_ADDR_CLASSA.\r |
97b38d4e | 409 | \r |
410 | **/\r | |
411 | INTN\r | |
412 | EFIAPI\r | |
413 | NetGetIpClass (\r | |
414 | IN IP4_ADDR Addr\r | |
415 | );\r | |
416 | \r | |
417 | /**\r | |
418 | Check whether the IP is a valid unicast address according to\r | |
3289dcba | 419 | the netmask. \r |
1204fe83 | 420 | \r |
3289dcba FS |
421 | ASSERT if NetMask is zero.\r |
422 | \r | |
29788f17 FS |
423 | If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,\r |
424 | except when the originator is one of the endpoints of a point-to-point link with a 31-bit\r | |
425 | mask (RFC3021).\r | |
426 | \r | |
ae213b7d | 427 | @param[in] Ip The IP to check against.\r |
428 | @param[in] NetMask The mask of the IP.\r | |
97b38d4e | 429 | \r |
3289dcba | 430 | @return TRUE if IP is a valid unicast address on the network, otherwise FALSE.\r |
97b38d4e | 431 | \r |
432 | **/\r | |
433 | BOOLEAN\r | |
ae213b7d | 434 | EFIAPI\r |
f6b7393c | 435 | NetIp4IsUnicast (\r |
97b38d4e | 436 | IN IP4_ADDR Ip,\r |
437 | IN IP4_ADDR NetMask\r | |
438 | );\r | |
439 | \r | |
fb115c61 | 440 | /**\r |
441 | Check whether the incoming IPv6 address is a valid unicast address.\r | |
442 | \r | |
443 | If the address is a multicast address has binary 0xFF at the start, it is not\r | |
444 | a valid unicast address. If the address is unspecified ::, it is not a valid\r | |
445 | unicast address to be assigned to any node. If the address is loopback address\r | |
446 | ::1, it is also not a valid unicast address to be assigned to any physical\r | |
1204fe83 | 447 | interface.\r |
fb115c61 | 448 | \r |
449 | @param[in] Ip6 The IPv6 address to check against.\r | |
450 | \r | |
451 | @return TRUE if Ip6 is a valid unicast address on the network, otherwise FALSE.\r | |
452 | \r | |
1204fe83 | 453 | **/\r |
fb115c61 | 454 | BOOLEAN\r |
e798cd87 | 455 | EFIAPI\r |
f6b7393c | 456 | NetIp6IsValidUnicast (\r |
457 | IN EFI_IPv6_ADDRESS *Ip6\r | |
458 | );\r | |
459 | \r | |
460 | \r | |
461 | /**\r | |
462 | Check whether the incoming Ipv6 address is the unspecified address or not.\r | |
463 | \r | |
464 | @param[in] Ip6 - Ip6 address, in network order.\r | |
465 | \r | |
64a80549 | 466 | @retval TRUE - Yes, incoming Ipv6 address is the unspecified address.\r |
467 | @retval FALSE - The incoming Ipv6 address is not the unspecified address\r | |
1204fe83 | 468 | \r |
f6b7393c | 469 | **/\r |
470 | BOOLEAN\r | |
e798cd87 | 471 | EFIAPI\r |
f6b7393c | 472 | NetIp6IsUnspecifiedAddr (\r |
fb115c61 | 473 | IN EFI_IPv6_ADDRESS *Ip6\r |
474 | );\r | |
475 | \r | |
f6b7393c | 476 | /**\r |
477 | Check whether the incoming Ipv6 address is a link-local address.\r | |
478 | \r | |
479 | @param[in] Ip6 - Ip6 address, in network order.\r | |
480 | \r | |
64a80549 | 481 | @retval TRUE - The incoming Ipv6 address is a link-local address.\r |
482 | @retval FALSE - The incoming Ipv6 address is not a link-local address.\r | |
1204fe83 | 483 | \r |
f6b7393c | 484 | **/\r |
485 | BOOLEAN\r | |
e798cd87 | 486 | EFIAPI\r |
f6b7393c | 487 | NetIp6IsLinkLocalAddr (\r |
488 | IN EFI_IPv6_ADDRESS *Ip6\r | |
489 | );\r | |
490 | \r | |
491 | /**\r | |
492 | Check whether the Ipv6 address1 and address2 are on the connected network.\r | |
493 | \r | |
494 | @param[in] Ip1 - Ip6 address1, in network order.\r | |
495 | @param[in] Ip2 - Ip6 address2, in network order.\r | |
496 | @param[in] PrefixLength - The prefix length of the checking net.\r | |
497 | \r | |
64a80549 | 498 | @retval TRUE - Yes, the Ipv6 address1 and address2 are connected.\r |
499 | @retval FALSE - No the Ipv6 address1 and address2 are not connected.\r | |
1204fe83 | 500 | \r |
f6b7393c | 501 | **/\r |
502 | BOOLEAN\r | |
e798cd87 | 503 | EFIAPI\r |
f6b7393c | 504 | NetIp6IsNetEqual (\r |
505 | EFI_IPv6_ADDRESS *Ip1,\r | |
506 | EFI_IPv6_ADDRESS *Ip2,\r | |
507 | UINT8 PrefixLength\r | |
508 | );\r | |
509 | \r | |
b45b45b2 | 510 | /**\r |
64a80549 | 511 | Switches the endianess of an IPv6 address.\r |
b45b45b2 | 512 | \r |
513 | This function swaps the bytes in a 128-bit IPv6 address to switch the value\r | |
514 | from little endian to big endian or vice versa. The byte swapped value is\r | |
515 | returned.\r | |
516 | \r | |
64a80549 | 517 | @param Ip6 Points to an IPv6 address.\r |
b45b45b2 | 518 | \r |
519 | @return The byte swapped IPv6 address.\r | |
520 | \r | |
521 | **/\r | |
522 | EFI_IPv6_ADDRESS *\r | |
e798cd87 | 523 | EFIAPI\r |
b45b45b2 | 524 | Ip6Swap128 (\r |
525 | EFI_IPv6_ADDRESS *Ip6\r | |
526 | );\r | |
527 | \r | |
8d7e5af1 | 528 | extern IP4_ADDR gIp4AllMasks[IP4_MASK_NUM];\r |
97b38d4e | 529 | \r |
530 | \r | |
531 | extern EFI_IPv4_ADDRESS mZeroIp4Addr;\r | |
532 | \r | |
533 | #define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))\r | |
418373a1 | 534 | #define NET_IS_HEX(Ch) ((('0' <= (Ch)) && ((Ch) <= '9')) || (('A' <= (Ch)) && ((Ch) <= 'F')) || (('a' <= (Ch)) && ((Ch) <= 'f')))\r |
97b38d4e | 535 | #define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))\r |
536 | #define NET_IS_LOWER_CASE_CHAR(Ch) (('a' <= (Ch)) && ((Ch) <= 'z'))\r | |
537 | #define NET_IS_UPPER_CASE_CHAR(Ch) (('A' <= (Ch)) && ((Ch) <= 'Z'))\r | |
538 | \r | |
539 | #define TICKS_PER_MS 10000U\r | |
540 | #define TICKS_PER_SECOND 10000000U\r | |
541 | \r | |
542 | #define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)\r | |
543 | \r | |
544 | /**\r | |
3a1ab4bc | 545 | Extract a UINT32 from a byte stream.\r |
1204fe83 | 546 | \r |
547 | This function copies a UINT32 from a byte stream, and then converts it from Network\r | |
3a1ab4bc | 548 | byte order to host byte order. Use this function to avoid alignment error.\r |
97b38d4e | 549 | \r |
ae213b7d | 550 | @param[in] Buf The buffer to extract the UINT32.\r |
97b38d4e | 551 | \r |
552 | @return The UINT32 extracted.\r | |
553 | \r | |
554 | **/\r | |
555 | UINT32\r | |
556 | EFIAPI\r | |
557 | NetGetUint32 (\r | |
558 | IN UINT8 *Buf\r | |
559 | );\r | |
560 | \r | |
561 | /**\r | |
1204fe83 | 562 | Puts a UINT32 into the byte stream in network byte order.\r |
563 | \r | |
64a80549 | 564 | Converts a UINT32 from host byte order to network byte order, then copies it to the\r |
3a1ab4bc | 565 | byte stream.\r |
97b38d4e | 566 | \r |
64a80549 | 567 | @param[in, out] Buf The buffer in which to put the UINT32.\r |
3b1464d5 | 568 | @param[in] Data The data to be converted and put into the byte stream.\r |
1204fe83 | 569 | \r |
97b38d4e | 570 | **/\r |
571 | VOID\r | |
572 | EFIAPI\r | |
573 | NetPutUint32 (\r | |
ae213b7d | 574 | IN OUT UINT8 *Buf,\r |
575 | IN UINT32 Data\r | |
97b38d4e | 576 | );\r |
577 | \r | |
578 | /**\r | |
2bd25290 | 579 | Initialize a random seed using current time and monotonic count.\r |
1204fe83 | 580 | \r |
2bd25290 FS |
581 | Get current time and monotonic count first. Then initialize a random seed \r |
582 | based on some basic mathematics operation on the hour, day, minute, second,\r | |
583 | nanosecond and year of the current time and the monotonic count value.\r | |
1204fe83 | 584 | \r |
2bd25290 | 585 | @return The random seed initialized with current time.\r |
97b38d4e | 586 | \r |
587 | **/\r | |
588 | UINT32\r | |
589 | EFIAPI\r | |
590 | NetRandomInitSeed (\r | |
591 | VOID\r | |
592 | );\r | |
593 | \r | |
594 | \r | |
595 | #define NET_LIST_USER_STRUCT(Entry, Type, Field) \\r | |
50d7ebad | 596 | BASE_CR(Entry, Type, Field)\r |
97b38d4e | 597 | \r |
598 | #define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \\r | |
599 | CR(Entry, Type, Field, Sig)\r | |
600 | \r | |
601 | //\r | |
e9b67286 | 602 | // Iterate through the double linked list. It is NOT delete safe\r |
97b38d4e | 603 | //\r |
604 | #define NET_LIST_FOR_EACH(Entry, ListHead) \\r | |
605 | for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)\r | |
606 | \r | |
607 | //\r | |
e9b67286 | 608 | // Iterate through the double linked list. This is delete-safe.\r |
97b38d4e | 609 | // Don't touch NextEntry. Also, don't use this macro if list\r |
610 | // entries other than the Entry may be deleted when processing\r | |
611 | // the current Entry.\r | |
612 | //\r | |
613 | #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \\r | |
614 | for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \\r | |
615 | Entry != (ListHead); \\r | |
616 | Entry = NextEntry, NextEntry = Entry->ForwardLink \\r | |
617 | )\r | |
618 | \r | |
619 | //\r | |
e9b67286 | 620 | // Make sure the list isn't empty before getting the first/last record.\r |
97b38d4e | 621 | //\r |
622 | #define NET_LIST_HEAD(ListHead, Type, Field) \\r | |
623 | NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)\r | |
624 | \r | |
625 | #define NET_LIST_TAIL(ListHead, Type, Field) \\r | |
626 | NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)\r | |
627 | \r | |
628 | \r | |
629 | /**\r | |
3a1ab4bc | 630 | Remove the first node entry on the list, and return the removed node entry.\r |
1204fe83 | 631 | \r |
e9b67286 | 632 | Removes the first node entry from a doubly linked list. It is up to the caller of\r |
633 | this function to release the memory used by the first node, if that is required. On\r | |
1204fe83 | 634 | exit, the removed node is returned.\r |
3a1ab4bc | 635 | \r |
636 | If Head is NULL, then ASSERT().\r | |
637 | If Head was not initialized, then ASSERT().\r | |
638 | If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r | |
639 | linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,\r | |
1204fe83 | 640 | then ASSERT().\r |
97b38d4e | 641 | \r |
ae213b7d | 642 | @param[in, out] Head The list header.\r |
97b38d4e | 643 | \r |
3a1ab4bc | 644 | @return The first node entry that is removed from the list, NULL if the list is empty.\r |
97b38d4e | 645 | \r |
646 | **/\r | |
647 | LIST_ENTRY *\r | |
648 | EFIAPI\r | |
649 | NetListRemoveHead (\r | |
ae213b7d | 650 | IN OUT LIST_ENTRY *Head\r |
97b38d4e | 651 | );\r |
652 | \r | |
653 | /**\r | |
e9b67286 | 654 | Remove the last node entry on the list and return the removed node entry.\r |
3a1ab4bc | 655 | \r |
656 | Removes the last node entry from a doubly linked list. It is up to the caller of\r | |
e9b67286 | 657 | this function to release the memory used by the first node, if that is required. On\r |
1204fe83 | 658 | exit, the removed node is returned.\r |
97b38d4e | 659 | \r |
3a1ab4bc | 660 | If Head is NULL, then ASSERT().\r |
661 | If Head was not initialized, then ASSERT().\r | |
662 | If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r | |
663 | linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,\r | |
1204fe83 | 664 | then ASSERT().\r |
665 | \r | |
ae213b7d | 666 | @param[in, out] Head The list head.\r |
97b38d4e | 667 | \r |
3a1ab4bc | 668 | @return The last node entry that is removed from the list, NULL if the list is empty.\r |
97b38d4e | 669 | \r |
670 | **/\r | |
671 | LIST_ENTRY *\r | |
672 | EFIAPI\r | |
673 | NetListRemoveTail (\r | |
ae213b7d | 674 | IN OUT LIST_ENTRY *Head\r |
97b38d4e | 675 | );\r |
676 | \r | |
677 | /**\r | |
3a1ab4bc | 678 | Insert a new node entry after a designated node entry of a doubly linked list.\r |
1204fe83 | 679 | \r |
e9b67286 | 680 | Inserts a new node entry designated by NewEntry after the node entry designated by PrevEntry\r |
3a1ab4bc | 681 | of the doubly linked list.\r |
1204fe83 | 682 | \r |
683 | @param[in, out] PrevEntry The entry after which to insert.\r | |
ae213b7d | 684 | @param[in, out] NewEntry The new entry to insert.\r |
97b38d4e | 685 | \r |
686 | **/\r | |
687 | VOID\r | |
688 | EFIAPI\r | |
689 | NetListInsertAfter (\r | |
ae213b7d | 690 | IN OUT LIST_ENTRY *PrevEntry,\r |
691 | IN OUT LIST_ENTRY *NewEntry\r | |
97b38d4e | 692 | );\r |
693 | \r | |
694 | /**\r | |
3a1ab4bc | 695 | Insert a new node entry before a designated node entry of a doubly linked list.\r |
1204fe83 | 696 | \r |
e9b67286 | 697 | Inserts a new node entry designated by NewEntry before the node entry designated by PostEntry\r |
3a1ab4bc | 698 | of the doubly linked list.\r |
1204fe83 | 699 | \r |
ae213b7d | 700 | @param[in, out] PostEntry The entry to insert before.\r |
701 | @param[in, out] NewEntry The new entry to insert.\r | |
97b38d4e | 702 | \r |
703 | **/\r | |
704 | VOID\r | |
705 | EFIAPI\r | |
706 | NetListInsertBefore (\r | |
ae213b7d | 707 | IN OUT LIST_ENTRY *PostEntry,\r |
708 | IN OUT LIST_ENTRY *NewEntry\r | |
97b38d4e | 709 | );\r |
710 | \r | |
216f7970 | 711 | /**\r |
712 | Callback function which provided by user to remove one node in NetDestroyLinkList process.\r | |
713 | \r | |
714 | @param[in] Entry The entry to be removed.\r | |
715 | @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r | |
716 | \r | |
717 | @retval EFI_SUCCESS The entry has been removed successfully.\r | |
718 | @retval Others Fail to remove the entry.\r | |
719 | \r | |
720 | **/\r | |
721 | typedef\r | |
722 | EFI_STATUS\r | |
723 | (EFIAPI *NET_DESTROY_LINK_LIST_CALLBACK) (\r | |
724 | IN LIST_ENTRY *Entry,\r | |
725 | IN VOID *Context OPTIONAL\r | |
1f7eb561 | 726 | );\r |
216f7970 | 727 | \r |
728 | /**\r | |
729 | Safe destroy nodes in a linked list, and return the length of the list after all possible operations finished.\r | |
730 | \r | |
731 | Destroy network children list by list traversals is not safe due to graph dependencies between nodes.\r | |
732 | This function performs a safe traversal to destroy these nodes by checking to see if the node being destroyed\r | |
733 | has been removed from the list or not.\r | |
734 | If it has been removed, then restart the traversal from the head.\r | |
735 | If it hasn't been removed, then continue with the next node directly.\r | |
736 | This function will end the iterate and return the CallBack's last return value if error happens,\r | |
737 | or retrun EFI_SUCCESS if 2 complete passes are made with no changes in the number of children in the list. \r | |
738 | \r | |
739 | @param[in] List The head of the list.\r | |
740 | @param[in] CallBack Pointer to the callback function to destroy one node in the list.\r | |
741 | @param[in] Context Pointer to the callback function's context: corresponds to the\r | |
742 | parameter Context in NET_DESTROY_LINK_LIST_CALLBACK.\r | |
743 | @param[out] ListLength The length of the link list if the function returns successfully.\r | |
744 | \r | |
745 | @retval EFI_SUCCESS Two complete passes are made with no changes in the number of children.\r | |
746 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
747 | @retval Others Return the CallBack's last return value.\r | |
748 | \r | |
749 | **/\r | |
750 | EFI_STATUS\r | |
751 | EFIAPI\r | |
752 | NetDestroyLinkList (\r | |
753 | IN LIST_ENTRY *List,\r | |
754 | IN NET_DESTROY_LINK_LIST_CALLBACK CallBack,\r | |
755 | IN VOID *Context, OPTIONAL\r | |
756 | OUT UINTN *ListLength OPTIONAL\r | |
1f7eb561 | 757 | );\r |
216f7970 | 758 | \r |
759 | /**\r | |
760 | This function checks the input Handle to see if it's one of these handles in ChildHandleBuffer.\r | |
761 | \r | |
762 | @param[in] Handle Handle to be checked.\r | |
763 | @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer.\r | |
764 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r | |
765 | if NumberOfChildren is 0.\r | |
766 | \r | |
86ac8fb2 | 767 | @retval TRUE Found the input Handle in ChildHandleBuffer.\r |
216f7970 | 768 | @retval FALSE Can't find the input Handle in ChildHandleBuffer.\r |
769 | \r | |
770 | **/\r | |
771 | BOOLEAN\r | |
1f7eb561 | 772 | EFIAPI\r |
216f7970 | 773 | NetIsInHandleBuffer (\r |
774 | IN EFI_HANDLE Handle,\r | |
775 | IN UINTN NumberOfChildren,\r | |
776 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
1f7eb561 | 777 | );\r |
97b38d4e | 778 | \r |
779 | //\r | |
780 | // Object container: EFI network stack spec defines various kinds of\r | |
781 | // tokens. The drivers can share code to manage those objects.\r | |
782 | //\r | |
783 | typedef struct {\r | |
784 | LIST_ENTRY Link;\r | |
785 | VOID *Key;\r | |
786 | VOID *Value;\r | |
787 | } NET_MAP_ITEM;\r | |
788 | \r | |
789 | typedef struct {\r | |
790 | LIST_ENTRY Used;\r | |
791 | LIST_ENTRY Recycled;\r | |
792 | UINTN Count;\r | |
793 | } NET_MAP;\r | |
794 | \r | |
795 | #define NET_MAP_INCREAMENT 64\r | |
796 | \r | |
797 | /**\r | |
798 | Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.\r | |
1204fe83 | 799 | \r |
800 | Initialize the forward and backward links of two head nodes donated by Map->Used\r | |
3a1ab4bc | 801 | and Map->Recycled of two doubly linked lists.\r |
802 | Initializes the count of the <Key, Value> pairs in the netmap to zero.\r | |
1204fe83 | 803 | \r |
3a1ab4bc | 804 | If Map is NULL, then ASSERT().\r |
805 | If the address of Map->Used is NULL, then ASSERT().\r | |
806 | If the address of Map->Recycled is NULl, then ASSERT().\r | |
1204fe83 | 807 | \r |
ae213b7d | 808 | @param[in, out] Map The netmap to initialize.\r |
97b38d4e | 809 | \r |
810 | **/\r | |
811 | VOID\r | |
812 | EFIAPI\r | |
813 | NetMapInit (\r | |
ae213b7d | 814 | IN OUT NET_MAP *Map\r |
97b38d4e | 815 | );\r |
816 | \r | |
817 | /**\r | |
818 | To clean up the netmap, that is, release allocated memories.\r | |
1204fe83 | 819 | \r |
e9b67286 | 820 | Removes all nodes of the Used doubly linked list and frees memory of all related netmap items.\r |
3a1ab4bc | 821 | Removes all nodes of the Recycled doubly linked list and free memory of all related netmap items.\r |
e9b67286 | 822 | The number of the <Key, Value> pairs in the netmap is set to zero.\r |
1204fe83 | 823 | \r |
3a1ab4bc | 824 | If Map is NULL, then ASSERT().\r |
1204fe83 | 825 | \r |
ae213b7d | 826 | @param[in, out] Map The netmap to clean up.\r |
97b38d4e | 827 | \r |
828 | **/\r | |
829 | VOID\r | |
830 | EFIAPI\r | |
831 | NetMapClean (\r | |
ae213b7d | 832 | IN OUT NET_MAP *Map\r |
97b38d4e | 833 | );\r |
834 | \r | |
835 | /**\r | |
3a1ab4bc | 836 | Test whether the netmap is empty and return true if it is.\r |
1204fe83 | 837 | \r |
3a1ab4bc | 838 | If the number of the <Key, Value> pairs in the netmap is zero, return TRUE.\r |
1204fe83 | 839 | \r |
3a1ab4bc | 840 | If Map is NULL, then ASSERT().\r |
1204fe83 | 841 | \r |
842 | \r | |
ae213b7d | 843 | @param[in] Map The net map to test.\r |
97b38d4e | 844 | \r |
845 | @return TRUE if the netmap is empty, otherwise FALSE.\r | |
846 | \r | |
847 | **/\r | |
848 | BOOLEAN\r | |
849 | EFIAPI\r | |
850 | NetMapIsEmpty (\r | |
851 | IN NET_MAP *Map\r | |
852 | );\r | |
853 | \r | |
854 | /**\r | |
855 | Return the number of the <Key, Value> pairs in the netmap.\r | |
856 | \r | |
ae213b7d | 857 | @param[in] Map The netmap to get the entry number.\r |
97b38d4e | 858 | \r |
859 | @return The entry number in the netmap.\r | |
860 | \r | |
861 | **/\r | |
862 | UINTN\r | |
863 | EFIAPI\r | |
864 | NetMapGetCount (\r | |
865 | IN NET_MAP *Map\r | |
866 | );\r | |
867 | \r | |
868 | /**\r | |
869 | Allocate an item to save the <Key, Value> pair to the head of the netmap.\r | |
1204fe83 | 870 | \r |
3a1ab4bc | 871 | Allocate an item to save the <Key, Value> pair and add corresponding node entry\r |
1204fe83 | 872 | to the beginning of the Used doubly linked list. The number of the <Key, Value>\r |
3a1ab4bc | 873 | pairs in the netmap increase by 1.\r |
97b38d4e | 874 | \r |
3a1ab4bc | 875 | If Map is NULL, then ASSERT().\r |
1204fe83 | 876 | \r |
ae213b7d | 877 | @param[in, out] Map The netmap to insert into.\r |
878 | @param[in] Key The user's key.\r | |
879 | @param[in] Value The user's value for the key.\r | |
97b38d4e | 880 | \r |
ae213b7d | 881 | @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.\r |
882 | @retval EFI_SUCCESS The item is inserted to the head.\r | |
97b38d4e | 883 | \r |
884 | **/\r | |
885 | EFI_STATUS\r | |
886 | EFIAPI\r | |
887 | NetMapInsertHead (\r | |
ae213b7d | 888 | IN OUT NET_MAP *Map,\r |
97b38d4e | 889 | IN VOID *Key,\r |
890 | IN VOID *Value OPTIONAL\r | |
891 | );\r | |
892 | \r | |
893 | /**\r | |
894 | Allocate an item to save the <Key, Value> pair to the tail of the netmap.\r | |
895 | \r | |
3a1ab4bc | 896 | Allocate an item to save the <Key, Value> pair and add corresponding node entry\r |
1204fe83 | 897 | to the tail of the Used doubly linked list. The number of the <Key, Value>\r |
3a1ab4bc | 898 | pairs in the netmap increase by 1.\r |
899 | \r | |
900 | If Map is NULL, then ASSERT().\r | |
1204fe83 | 901 | \r |
ae213b7d | 902 | @param[in, out] Map The netmap to insert into.\r |
903 | @param[in] Key The user's key.\r | |
904 | @param[in] Value The user's value for the key.\r | |
97b38d4e | 905 | \r |
ae213b7d | 906 | @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.\r |
907 | @retval EFI_SUCCESS The item is inserted to the tail.\r | |
97b38d4e | 908 | \r |
909 | **/\r | |
910 | EFI_STATUS\r | |
911 | EFIAPI\r | |
912 | NetMapInsertTail (\r | |
ae213b7d | 913 | IN OUT NET_MAP *Map,\r |
97b38d4e | 914 | IN VOID *Key,\r |
915 | IN VOID *Value OPTIONAL\r | |
916 | );\r | |
917 | \r | |
918 | /**\r | |
e9b67286 | 919 | Finds the key in the netmap and returns the point to the item containing the Key.\r |
1204fe83 | 920 | \r |
921 | Iterate the Used doubly linked list of the netmap to get every item. Compare the key of every\r | |
3a1ab4bc | 922 | item with the key to search. It returns the point to the item contains the Key if found.\r |
97b38d4e | 923 | \r |
3a1ab4bc | 924 | If Map is NULL, then ASSERT().\r |
1204fe83 | 925 | \r |
ae213b7d | 926 | @param[in] Map The netmap to search within.\r |
927 | @param[in] Key The key to search.\r | |
97b38d4e | 928 | \r |
929 | @return The point to the item contains the Key, or NULL if Key isn't in the map.\r | |
930 | \r | |
931 | **/\r | |
ae213b7d | 932 | NET_MAP_ITEM *\r |
97b38d4e | 933 | EFIAPI\r |
934 | NetMapFindKey (\r | |
935 | IN NET_MAP *Map,\r | |
936 | IN VOID *Key\r | |
937 | );\r | |
938 | \r | |
939 | /**\r | |
3a1ab4bc | 940 | Remove the node entry of the item from the netmap and return the key of the removed item.\r |
1204fe83 | 941 | \r |
942 | Remove the node entry of the item from the Used doubly linked list of the netmap.\r | |
943 | The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node\r | |
3a1ab4bc | 944 | entry of the item to the Recycled doubly linked list of the netmap. If Value is not NULL,\r |
945 | Value will point to the value of the item. It returns the key of the removed item.\r | |
1204fe83 | 946 | \r |
3a1ab4bc | 947 | If Map is NULL, then ASSERT().\r |
948 | If Item is NULL, then ASSERT().\r | |
949 | if item in not in the netmap, then ASSERT().\r | |
1204fe83 | 950 | \r |
ae213b7d | 951 | @param[in, out] Map The netmap to remove the item from.\r |
952 | @param[in, out] Item The item to remove.\r | |
953 | @param[out] Value The variable to receive the value if not NULL.\r | |
97b38d4e | 954 | \r |
ae213b7d | 955 | @return The key of the removed item.\r |
97b38d4e | 956 | \r |
957 | **/\r | |
958 | VOID *\r | |
959 | EFIAPI\r | |
960 | NetMapRemoveItem (\r | |
ae213b7d | 961 | IN OUT NET_MAP *Map,\r |
962 | IN OUT NET_MAP_ITEM *Item,\r | |
963 | OUT VOID **Value OPTIONAL\r | |
97b38d4e | 964 | );\r |
965 | \r | |
966 | /**\r | |
3a1ab4bc | 967 | Remove the first node entry on the netmap and return the key of the removed item.\r |
97b38d4e | 968 | \r |
1204fe83 | 969 | Remove the first node entry from the Used doubly linked list of the netmap.\r |
970 | The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node\r | |
3a1ab4bc | 971 | entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,\r |
972 | parameter Value will point to the value of the item. It returns the key of the removed item.\r | |
1204fe83 | 973 | \r |
3a1ab4bc | 974 | If Map is NULL, then ASSERT().\r |
975 | If the Used doubly linked list is empty, then ASSERT().\r | |
1204fe83 | 976 | \r |
ae213b7d | 977 | @param[in, out] Map The netmap to remove the head from.\r |
978 | @param[out] Value The variable to receive the value if not NULL.\r | |
97b38d4e | 979 | \r |
ae213b7d | 980 | @return The key of the item removed.\r |
97b38d4e | 981 | \r |
982 | **/\r | |
983 | VOID *\r | |
984 | EFIAPI\r | |
985 | NetMapRemoveHead (\r | |
ae213b7d | 986 | IN OUT NET_MAP *Map,\r |
987 | OUT VOID **Value OPTIONAL\r | |
97b38d4e | 988 | );\r |
989 | \r | |
990 | /**\r | |
3a1ab4bc | 991 | Remove the last node entry on the netmap and return the key of the removed item.\r |
97b38d4e | 992 | \r |
1204fe83 | 993 | Remove the last node entry from the Used doubly linked list of the netmap.\r |
994 | The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node\r | |
3a1ab4bc | 995 | entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,\r |
996 | parameter Value will point to the value of the item. It returns the key of the removed item.\r | |
1204fe83 | 997 | \r |
3a1ab4bc | 998 | If Map is NULL, then ASSERT().\r |
999 | If the Used doubly linked list is empty, then ASSERT().\r | |
1204fe83 | 1000 | \r |
ae213b7d | 1001 | @param[in, out] Map The netmap to remove the tail from.\r |
1002 | @param[out] Value The variable to receive the value if not NULL.\r | |
97b38d4e | 1003 | \r |
ae213b7d | 1004 | @return The key of the item removed.\r |
97b38d4e | 1005 | \r |
1006 | **/\r | |
1007 | VOID *\r | |
1008 | EFIAPI\r | |
1009 | NetMapRemoveTail (\r | |
ae213b7d | 1010 | IN OUT NET_MAP *Map,\r |
1011 | OUT VOID **Value OPTIONAL\r | |
97b38d4e | 1012 | );\r |
1013 | \r | |
1014 | typedef\r | |
1015 | EFI_STATUS\r | |
e798cd87 | 1016 | (EFIAPI *NET_MAP_CALLBACK) (\r |
97b38d4e | 1017 | IN NET_MAP *Map,\r |
1018 | IN NET_MAP_ITEM *Item,\r | |
1019 | IN VOID *Arg\r | |
1020 | );\r | |
1021 | \r | |
1022 | /**\r | |
3a1ab4bc | 1023 | Iterate through the netmap and call CallBack for each item.\r |
1204fe83 | 1024 | \r |
86ac8fb2 | 1025 | It will continue the traverse if CallBack returns EFI_SUCCESS, otherwise, break\r |
1204fe83 | 1026 | from the loop. It returns the CallBack's last return value. This function is\r |
3a1ab4bc | 1027 | delete safe for the current item.\r |
97b38d4e | 1028 | \r |
3a1ab4bc | 1029 | If Map is NULL, then ASSERT().\r |
1030 | If CallBack is NULL, then ASSERT().\r | |
1204fe83 | 1031 | \r |
ae213b7d | 1032 | @param[in] Map The Map to iterate through.\r |
1033 | @param[in] CallBack The callback function to call for each item.\r | |
1034 | @param[in] Arg The opaque parameter to the callback.\r | |
97b38d4e | 1035 | \r |
64a80549 | 1036 | @retval EFI_SUCCESS There is no item in the netmap, or CallBack for each item\r |
1037 | returns EFI_SUCCESS.\r | |
ae213b7d | 1038 | @retval Others It returns the CallBack's last return value.\r |
97b38d4e | 1039 | \r |
1040 | **/\r | |
1041 | EFI_STATUS\r | |
1042 | EFIAPI\r | |
1043 | NetMapIterate (\r | |
1044 | IN NET_MAP *Map,\r | |
1045 | IN NET_MAP_CALLBACK CallBack,\r | |
f6b7393c | 1046 | IN VOID *Arg OPTIONAL\r |
97b38d4e | 1047 | );\r |
1048 | \r | |
1049 | \r | |
1050 | //\r | |
1051 | // Helper functions to implement driver binding and service binding protocols.\r | |
1052 | //\r | |
1053 | /**\r | |
1054 | Create a child of the service that is identified by ServiceBindingGuid.\r | |
1204fe83 | 1055 | \r |
3a1ab4bc | 1056 | Get the ServiceBinding Protocol first, then use it to create a child.\r |
97b38d4e | 1057 | \r |
3a1ab4bc | 1058 | If ServiceBindingGuid is NULL, then ASSERT().\r |
1059 | If ChildHandle is NULL, then ASSERT().\r | |
1204fe83 | 1060 | \r |
ae213b7d | 1061 | @param[in] Controller The controller which has the service installed.\r |
1062 | @param[in] Image The image handle used to open service.\r | |
1063 | @param[in] ServiceBindingGuid The service's Guid.\r | |
e9b67286 | 1064 | @param[in, out] ChildHandle The handle to receive the created child.\r |
97b38d4e | 1065 | \r |
e9b67286 | 1066 | @retval EFI_SUCCESS The child was successfully created.\r |
97b38d4e | 1067 | @retval Others Failed to create the child.\r |
1068 | \r | |
1069 | **/\r | |
1070 | EFI_STATUS\r | |
1071 | EFIAPI\r | |
1072 | NetLibCreateServiceChild (\r | |
ae213b7d | 1073 | IN EFI_HANDLE Controller,\r |
1074 | IN EFI_HANDLE Image,\r | |
97b38d4e | 1075 | IN EFI_GUID *ServiceBindingGuid,\r |
ae213b7d | 1076 | IN OUT EFI_HANDLE *ChildHandle\r |
97b38d4e | 1077 | );\r |
1078 | \r | |
1079 | /**\r | |
e9b67286 | 1080 | Destroy a child of the service that is identified by ServiceBindingGuid.\r |
1204fe83 | 1081 | \r |
3a1ab4bc | 1082 | Get the ServiceBinding Protocol first, then use it to destroy a child.\r |
1204fe83 | 1083 | \r |
3a1ab4bc | 1084 | If ServiceBindingGuid is NULL, then ASSERT().\r |
1204fe83 | 1085 | \r |
ae213b7d | 1086 | @param[in] Controller The controller which has the service installed.\r |
1087 | @param[in] Image The image handle used to open service.\r | |
1088 | @param[in] ServiceBindingGuid The service's Guid.\r | |
e9b67286 | 1089 | @param[in] ChildHandle The child to destroy.\r |
97b38d4e | 1090 | \r |
64a80549 | 1091 | @retval EFI_SUCCESS The child was destroyed.\r |
e9b67286 | 1092 | @retval Others Failed to destroy the child.\r |
97b38d4e | 1093 | \r |
1094 | **/\r | |
1095 | EFI_STATUS\r | |
1096 | EFIAPI\r | |
1097 | NetLibDestroyServiceChild (\r | |
ae213b7d | 1098 | IN EFI_HANDLE Controller,\r |
1099 | IN EFI_HANDLE Image,\r | |
97b38d4e | 1100 | IN EFI_GUID *ServiceBindingGuid,\r |
1101 | IN EFI_HANDLE ChildHandle\r | |
1102 | );\r | |
1103 | \r | |
1104 | /**\r | |
779ae357 | 1105 | Get handle with Simple Network Protocol installed on it.\r |
1106 | \r | |
1107 | There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r | |
1108 | If Simple Network Protocol is already installed on the ServiceHandle, the\r | |
1109 | ServiceHandle will be returned. If SNP is not installed on the ServiceHandle,\r | |
1110 | try to find its parent handle with SNP installed.\r | |
1111 | \r | |
1112 | @param[in] ServiceHandle The handle where network service binding protocols are\r | |
1113 | installed on.\r | |
1114 | @param[out] Snp The pointer to store the address of the SNP instance.\r | |
1115 | This is an optional parameter that may be NULL.\r | |
1116 | \r | |
1117 | @return The SNP handle, or NULL if not found.\r | |
1118 | \r | |
1119 | **/\r | |
1120 | EFI_HANDLE\r | |
1121 | EFIAPI\r | |
1122 | NetLibGetSnpHandle (\r | |
1123 | IN EFI_HANDLE ServiceHandle,\r | |
1124 | OUT EFI_SIMPLE_NETWORK_PROTOCOL **Snp OPTIONAL\r | |
1125 | );\r | |
1126 | \r | |
1127 | /**\r | |
1128 | Retrieve VLAN ID of a VLAN device handle.\r | |
1129 | \r | |
1130 | Search VLAN device path node in Device Path of specified ServiceHandle and\r | |
1131 | return its VLAN ID. If no VLAN device path node found, then this ServiceHandle\r | |
1132 | is not a VLAN device handle, and 0 will be returned.\r | |
1133 | \r | |
1134 | @param[in] ServiceHandle The handle where network service binding protocols are\r | |
1135 | installed on.\r | |
1136 | \r | |
1137 | @return VLAN ID of the device handle, or 0 if not a VLAN device.\r | |
97b38d4e | 1138 | \r |
779ae357 | 1139 | **/\r |
1140 | UINT16\r | |
1141 | EFIAPI\r | |
1142 | NetLibGetVlanId (\r | |
1143 | IN EFI_HANDLE ServiceHandle\r | |
1144 | );\r | |
1145 | \r | |
1146 | /**\r | |
1147 | Find VLAN device handle with specified VLAN ID.\r | |
1148 | \r | |
1149 | The VLAN child device handle is created by VLAN Config Protocol on ControllerHandle.\r | |
1150 | This function will append VLAN device path node to the parent device path,\r | |
1151 | and then use LocateDevicePath() to find the correct VLAN device handle.\r | |
1152 | \r | |
e2851998 | 1153 | @param[in] ControllerHandle The handle where network service binding protocols are\r |
779ae357 | 1154 | installed on.\r |
e2851998 | 1155 | @param[in] VlanId The configured VLAN ID for the VLAN device.\r |
779ae357 | 1156 | \r |
1157 | @return The VLAN device handle, or NULL if not found.\r | |
1158 | \r | |
1159 | **/\r | |
1160 | EFI_HANDLE\r | |
1161 | EFIAPI\r | |
1162 | NetLibGetVlanHandle (\r | |
1163 | IN EFI_HANDLE ControllerHandle,\r | |
1164 | IN UINT16 VlanId\r | |
1165 | );\r | |
1166 | \r | |
1167 | /**\r | |
1168 | Get MAC address associated with the network service handle.\r | |
1169 | \r | |
1170 | There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r | |
1171 | If SNP is installed on the ServiceHandle or its parent handle, MAC address will\r | |
1172 | be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP.\r | |
1173 | \r | |
1174 | @param[in] ServiceHandle The handle where network service binding protocols are\r | |
1175 | installed on.\r | |
1176 | @param[out] MacAddress The pointer to store the returned MAC address.\r | |
1177 | @param[out] AddressSize The length of returned MAC address.\r | |
1178 | \r | |
64a80549 | 1179 | @retval EFI_SUCCESS MAC address was returned successfully.\r |
779ae357 | 1180 | @retval Others Failed to get SNP mode data.\r |
1181 | \r | |
1182 | **/\r | |
1183 | EFI_STATUS\r | |
1184 | EFIAPI\r | |
1185 | NetLibGetMacAddress (\r | |
1186 | IN EFI_HANDLE ServiceHandle,\r | |
1187 | OUT EFI_MAC_ADDRESS *MacAddress,\r | |
1188 | OUT UINTN *AddressSize\r | |
1189 | );\r | |
1190 | \r | |
1191 | /**\r | |
1192 | Convert MAC address of the NIC associated with specified Service Binding Handle\r | |
1193 | to a unicode string. Callers are responsible for freeing the string storage.\r | |
3a1ab4bc | 1194 | \r |
779ae357 | 1195 | Locate simple network protocol associated with the Service Binding Handle and\r |
1196 | get the mac address from SNP. Then convert the mac address into a unicode\r | |
1197 | string. It takes 2 unicode characters to represent a 1 byte binary buffer.\r | |
1198 | Plus one unicode character for the null-terminator.\r | |
3a1ab4bc | 1199 | \r |
779ae357 | 1200 | @param[in] ServiceHandle The handle where network service binding protocol is\r |
64a80549 | 1201 | installed.\r |
779ae357 | 1202 | @param[in] ImageHandle The image handle used to act as the agent handle to\r |
b00ed21a | 1203 | get the simple network protocol. This parameter is\r |
1204 | optional and may be NULL.\r | |
ae213b7d | 1205 | @param[out] MacString The pointer to store the address of the string\r |
1206 | representation of the mac address.\r | |
1204fe83 | 1207 | \r |
64a80549 | 1208 | @retval EFI_SUCCESS Converted the mac address a unicode string successfully.\r |
1209 | @retval EFI_OUT_OF_RESOURCES There are not enough memory resources.\r | |
ae213b7d | 1210 | @retval Others Failed to open the simple network protocol.\r |
97b38d4e | 1211 | \r |
1212 | **/\r | |
1213 | EFI_STATUS\r | |
1214 | EFIAPI\r | |
1215 | NetLibGetMacString (\r | |
779ae357 | 1216 | IN EFI_HANDLE ServiceHandle,\r |
b00ed21a | 1217 | IN EFI_HANDLE ImageHandle, OPTIONAL\r |
ae213b7d | 1218 | OUT CHAR16 **MacString\r |
97b38d4e | 1219 | );\r |
1220 | \r | |
dd29f3ed | 1221 | /**\r |
1222 | Detect media status for specified network device.\r | |
1223 | \r | |
1224 | The underlying UNDI driver may or may not support reporting media status from\r | |
1225 | GET_STATUS command (PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED). This routine\r | |
3b1464d5 | 1226 | will try to invoke Snp->GetStatus() to get the media status. If media is already\r |
1227 | present, it returns directly. If media is not present, it will stop SNP and then\r | |
1228 | restart SNP to get the latest media status. This provides an opportunity to get \r | |
64a80549 | 1229 | the correct media status for old UNDI driver, which doesn't support reporting \r |
1230 | media status from GET_STATUS command.\r | |
1231 | Note: there are two limitations for the current algorithm:\r | |
1232 | 1) For UNDI with this capability, when the cable is not attached, there will\r | |
1233 | be an redundant Stop/Start() process.\r | |
3b1464d5 | 1234 | 2) for UNDI without this capability, in case that network cable is attached when\r |
1235 | Snp->Initialize() is invoked while network cable is unattached later,\r | |
1236 | NetLibDetectMedia() will report MediaPresent as TRUE, causing upper layer\r | |
1237 | apps to wait for timeout time.\r | |
dd29f3ed | 1238 | \r |
1239 | @param[in] ServiceHandle The handle where network service binding protocols are\r | |
64a80549 | 1240 | installed.\r |
dd29f3ed | 1241 | @param[out] MediaPresent The pointer to store the media status.\r |
1242 | \r | |
1243 | @retval EFI_SUCCESS Media detection success.\r | |
64a80549 | 1244 | @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network device handle.\r |
1245 | @retval EFI_UNSUPPORTED The network device does not support media detection.\r | |
1246 | @retval EFI_DEVICE_ERROR SNP is in an unknown state.\r | |
dd29f3ed | 1247 | \r |
1248 | **/\r | |
1249 | EFI_STATUS\r | |
1250 | EFIAPI\r | |
1251 | NetLibDetectMedia (\r | |
1252 | IN EFI_HANDLE ServiceHandle,\r | |
1253 | OUT BOOLEAN *MediaPresent\r | |
1254 | );\r | |
1255 | \r | |
ca4e4323 | 1256 | /**\r |
1257 | \r | |
1258 | Detect media state for a network device. This routine will wait for a period of time at \r | |
1259 | a specified checking interval when a certain network is under connecting until connection \r | |
1260 | process finishes or timeout. If Aip protocol is supported by low layer drivers, three kinds\r | |
1261 | of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and EFI_NO_MEDIA, represents\r | |
1262 | connected state, connecting state and no media state respectively. When function detects \r | |
1263 | the current state is EFI_NOT_READY, it will loop to wait for next time's check until state \r | |
1264 | turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supported, function will \r | |
1265 | call NetLibDetectMedia() and return state directly.\r | |
1266 | \r | |
1267 | @param[in] ServiceHandle The handle where network service binding protocols are\r | |
1268 | installed on.\r | |
1269 | @param[in] Timeout The maximum number of 100ns units to wait when network\r | |
1270 | is connecting. Zero value means detect once and return\r | |
1271 | immediately.\r | |
1272 | @param[out] MediaState The pointer to the detected media state.\r | |
1273 | \r | |
1274 | @retval EFI_SUCCESS Media detection success.\r | |
1275 | @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network device handle or \r | |
1276 | MediaState pointer is NULL.\r | |
1277 | @retval EFI_DEVICE_ERROR A device error occurred.\r | |
1278 | @retval EFI_TIMEOUT Network is connecting but timeout.\r | |
1279 | \r | |
1280 | **/\r | |
1281 | EFI_STATUS\r | |
1282 | EFIAPI\r | |
1283 | NetLibDetectMediaWaitTimeout (\r | |
1284 | IN EFI_HANDLE ServiceHandle,\r | |
1285 | IN UINT64 Timeout,\r | |
1286 | OUT EFI_STATUS *MediaState\r | |
1287 | );\r | |
1288 | \r | |
1289 | \r | |
97b38d4e | 1290 | /**\r |
1291 | Create an IPv4 device path node.\r | |
1204fe83 | 1292 | \r |
3a1ab4bc | 1293 | The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.\r |
1294 | The header subtype of IPv4 device path node is MSG_IPv4_DP.\r | |
1295 | The length of the IPv4 device path node in bytes is 19.\r | |
64a80549 | 1296 | Get other information from parameters to make up the whole IPv4 device path node.\r |
97b38d4e | 1297 | \r |
64a80549 | 1298 | @param[in, out] Node The pointer to the IPv4 device path node.\r |
f6b7393c | 1299 | @param[in] Controller The controller handle.\r |
ae213b7d | 1300 | @param[in] LocalIp The local IPv4 address.\r |
1301 | @param[in] LocalPort The local port.\r | |
1302 | @param[in] RemoteIp The remote IPv4 address.\r | |
1303 | @param[in] RemotePort The remote port.\r | |
1304 | @param[in] Protocol The protocol type in the IP header.\r | |
1305 | @param[in] UseDefaultAddress Whether this instance is using default address or not.\r | |
97b38d4e | 1306 | \r |
97b38d4e | 1307 | **/\r |
1308 | VOID\r | |
1309 | EFIAPI\r | |
1310 | NetLibCreateIPv4DPathNode (\r | |
1311 | IN OUT IPv4_DEVICE_PATH *Node,\r | |
1312 | IN EFI_HANDLE Controller,\r | |
1313 | IN IP4_ADDR LocalIp,\r | |
1314 | IN UINT16 LocalPort,\r | |
1315 | IN IP4_ADDR RemoteIp,\r | |
1316 | IN UINT16 RemotePort,\r | |
1317 | IN UINT16 Protocol,\r | |
1318 | IN BOOLEAN UseDefaultAddress\r | |
1319 | );\r | |
1320 | \r | |
f6b7393c | 1321 | /**\r |
1322 | Create an IPv6 device path node.\r | |
1204fe83 | 1323 | \r |
f6b7393c | 1324 | The header type of IPv6 device path node is MESSAGING_DEVICE_PATH.\r |
1325 | The header subtype of IPv6 device path node is MSG_IPv6_DP.\r | |
1326 | The length of the IPv6 device path node in bytes is 43.\r | |
64a80549 | 1327 | Get other information from parameters to make up the whole IPv6 device path node.\r |
f6b7393c | 1328 | \r |
64a80549 | 1329 | @param[in, out] Node The pointer to the IPv6 device path node.\r |
f6b7393c | 1330 | @param[in] Controller The controller handle.\r |
1331 | @param[in] LocalIp The local IPv6 address.\r | |
1332 | @param[in] LocalPort The local port.\r | |
1333 | @param[in] RemoteIp The remote IPv6 address.\r | |
1334 | @param[in] RemotePort The remote port.\r | |
1335 | @param[in] Protocol The protocol type in the IP header.\r | |
1336 | \r | |
1337 | **/\r | |
1338 | VOID\r | |
1339 | EFIAPI\r | |
1340 | NetLibCreateIPv6DPathNode (\r | |
1341 | IN OUT IPv6_DEVICE_PATH *Node,\r | |
1342 | IN EFI_HANDLE Controller,\r | |
1343 | IN EFI_IPv6_ADDRESS *LocalIp,\r | |
1344 | IN UINT16 LocalPort,\r | |
1345 | IN EFI_IPv6_ADDRESS *RemoteIp,\r | |
1346 | IN UINT16 RemotePort,\r | |
1347 | IN UINT16 Protocol\r | |
1348 | );\r | |
1349 | \r | |
1350 | \r | |
97b38d4e | 1351 | /**\r |
1352 | Find the UNDI/SNP handle from controller and protocol GUID.\r | |
1204fe83 | 1353 | \r |
e9b67286 | 1354 | For example, IP will open an MNP child to transmit/receive\r |
1355 | packets. When MNP is stopped, IP should also be stopped. IP\r | |
64a80549 | 1356 | needs to find its own private data that is related the IP's\r |
1357 | service binding instance that is installed on the UNDI/SNP handle.\r | |
1358 | The controller is then either an MNP or an ARP child handle. Note that\r | |
86ac8fb2 | 1359 | IP opens these handles using BY_DRIVER. Use that information to get the\r |
97b38d4e | 1360 | UNDI/SNP handle.\r |
1361 | \r | |
64a80549 | 1362 | @param[in] Controller The protocol handle to check.\r |
ae213b7d | 1363 | @param[in] ProtocolGuid The protocol that is related with the handle.\r |
97b38d4e | 1364 | \r |
ae213b7d | 1365 | @return The UNDI/SNP handle or NULL for errors.\r |
97b38d4e | 1366 | \r |
1367 | **/\r | |
1368 | EFI_HANDLE\r | |
1369 | EFIAPI\r | |
1370 | NetLibGetNicHandle (\r | |
1371 | IN EFI_HANDLE Controller,\r | |
1372 | IN EFI_GUID *ProtocolGuid\r | |
1373 | );\r | |
1374 | \r | |
97b38d4e | 1375 | /**\r |
1376 | This is the default unload handle for all the network drivers.\r | |
1377 | \r | |
3a1ab4bc | 1378 | Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r |
1379 | Uninstall all the protocols installed in the driver entry point.\r | |
1204fe83 | 1380 | \r |
ae213b7d | 1381 | @param[in] ImageHandle The drivers' driver image.\r |
97b38d4e | 1382 | \r |
1383 | @retval EFI_SUCCESS The image is unloaded.\r | |
1384 | @retval Others Failed to unload the image.\r | |
1385 | \r | |
1386 | **/\r | |
1387 | EFI_STATUS\r | |
1388 | EFIAPI\r | |
1389 | NetLibDefaultUnload (\r | |
1390 | IN EFI_HANDLE ImageHandle\r | |
1391 | );\r | |
1392 | \r | |
e4ef0031 | 1393 | /**\r |
1394 | Convert one Null-terminated ASCII string (decimal dotted) to EFI_IPv4_ADDRESS.\r | |
1395 | \r | |
1396 | @param[in] String The pointer to the Ascii string.\r | |
1397 | @param[out] Ip4Address The pointer to the converted IPv4 address.\r | |
1398 | \r | |
64a80549 | 1399 | @retval EFI_SUCCESS Converted to an IPv4 address successfully.\r |
86ac8fb2 | 1400 | @retval EFI_INVALID_PARAMETER The string is malformatted, or Ip4Address is NULL.\r |
e4ef0031 | 1401 | \r |
1402 | **/\r | |
1403 | EFI_STATUS\r | |
e798cd87 | 1404 | EFIAPI\r |
e4ef0031 | 1405 | NetLibAsciiStrToIp4 (\r |
1406 | IN CONST CHAR8 *String,\r | |
1407 | OUT EFI_IPv4_ADDRESS *Ip4Address\r | |
1408 | );\r | |
1409 | \r | |
1410 | /**\r | |
1411 | Convert one Null-terminated ASCII string to EFI_IPv6_ADDRESS. The format of the\r | |
86ac8fb2 | 1412 | string is defined in RFC 4291 - Text Representation of Addresses.\r |
e4ef0031 | 1413 | \r |
1414 | @param[in] String The pointer to the Ascii string.\r | |
1415 | @param[out] Ip6Address The pointer to the converted IPv6 address.\r | |
1416 | \r | |
64a80549 | 1417 | @retval EFI_SUCCESS Converted to an IPv6 address successfully.\r |
86ac8fb2 | 1418 | @retval EFI_INVALID_PARAMETER The string is malformatted, or Ip6Address is NULL.\r |
e4ef0031 | 1419 | \r |
1420 | **/\r | |
1421 | EFI_STATUS\r | |
e798cd87 | 1422 | EFIAPI\r |
e4ef0031 | 1423 | NetLibAsciiStrToIp6 (\r |
1424 | IN CONST CHAR8 *String,\r | |
1425 | OUT EFI_IPv6_ADDRESS *Ip6Address\r | |
1426 | );\r | |
1427 | \r | |
1428 | /**\r | |
1429 | Convert one Null-terminated Unicode string (decimal dotted) to EFI_IPv4_ADDRESS.\r | |
1430 | \r | |
1431 | @param[in] String The pointer to the Ascii string.\r | |
1432 | @param[out] Ip4Address The pointer to the converted IPv4 address.\r | |
1433 | \r | |
64a80549 | 1434 | @retval EFI_SUCCESS Converted to an IPv4 address successfully.\r |
86ac8fb2 | 1435 | @retval EFI_INVALID_PARAMETER The string is mal-formatted or Ip4Address is NULL.\r |
e4ef0031 | 1436 | \r |
1437 | **/\r | |
1438 | EFI_STATUS\r | |
e798cd87 | 1439 | EFIAPI\r |
e4ef0031 | 1440 | NetLibStrToIp4 (\r |
1441 | IN CONST CHAR16 *String,\r | |
1442 | OUT EFI_IPv4_ADDRESS *Ip4Address\r | |
1443 | );\r | |
1444 | \r | |
1445 | /**\r | |
1446 | Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS. The format of\r | |
86ac8fb2 | 1447 | the string is defined in RFC 4291 - Text Representation of Addresses.\r |
e4ef0031 | 1448 | \r |
1449 | @param[in] String The pointer to the Ascii string.\r | |
1450 | @param[out] Ip6Address The pointer to the converted IPv6 address.\r | |
1451 | \r | |
64a80549 | 1452 | @retval EFI_SUCCESS Converted to an IPv6 address successfully.\r |
86ac8fb2 | 1453 | @retval EFI_INVALID_PARAMETER The string is malformatted or Ip6Address is NULL.\r |
e4ef0031 | 1454 | \r |
1455 | **/\r | |
1456 | EFI_STATUS\r | |
e798cd87 | 1457 | EFIAPI\r |
e4ef0031 | 1458 | NetLibStrToIp6 (\r |
1459 | IN CONST CHAR16 *String,\r | |
1460 | OUT EFI_IPv6_ADDRESS *Ip6Address\r | |
1461 | );\r | |
1462 | \r | |
1463 | /**\r | |
1464 | Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS and prefix length.\r | |
86ac8fb2 | 1465 | The format of the string is defined in RFC 4291 - Text Representation of Addresses\r |
e4ef0031 | 1466 | Prefixes: ipv6-address/prefix-length.\r |
1467 | \r | |
1468 | @param[in] String The pointer to the Ascii string.\r | |
1469 | @param[out] Ip6Address The pointer to the converted IPv6 address.\r | |
1470 | @param[out] PrefixLength The pointer to the converted prefix length.\r | |
1471 | \r | |
64a80549 | 1472 | @retval EFI_SUCCESS Converted to an IPv6 address successfully.\r |
86ac8fb2 | 1473 | @retval EFI_INVALID_PARAMETER The string is malformatted, or Ip6Address is NULL.\r |
e4ef0031 | 1474 | \r |
1475 | **/\r | |
1476 | EFI_STATUS\r | |
e798cd87 | 1477 | EFIAPI\r |
e4ef0031 | 1478 | NetLibStrToIp6andPrefix (\r |
1479 | IN CONST CHAR16 *String,\r | |
1480 | OUT EFI_IPv6_ADDRESS *Ip6Address,\r | |
1481 | OUT UINT8 *PrefixLength\r | |
1482 | );\r | |
b45b45b2 | 1483 | \r |
216f7970 | 1484 | /**\r |
1485 | \r | |
1486 | Convert one EFI_IPv6_ADDRESS to Null-terminated Unicode string.\r | |
1487 | The text representation of address is defined in RFC 4291.\r | |
1488 | \r | |
1489 | @param[in] Ip6Address The pointer to the IPv6 address.\r | |
1490 | @param[out] String The buffer to return the converted string.\r | |
1491 | @param[in] StringSize The length in bytes of the input String.\r | |
1492 | \r | |
1493 | @retval EFI_SUCCESS Convert to string successfully.\r | |
1494 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
1495 | @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small for the result. BufferSize has been \r | |
1496 | updated with the size needed to complete the request.\r | |
1497 | **/\r | |
1498 | EFI_STATUS\r | |
1499 | EFIAPI\r | |
1500 | NetLibIp6ToStr (\r | |
1501 | IN EFI_IPv6_ADDRESS *Ip6Address,\r | |
1502 | OUT CHAR16 *String,\r | |
1503 | IN UINTN StringSize\r | |
1504 | );\r | |
1505 | \r | |
b45b45b2 | 1506 | //\r |
e4ef0031 | 1507 | // Various signatures\r |
b45b45b2 | 1508 | //\r |
1509 | #define NET_BUF_SIGNATURE SIGNATURE_32 ('n', 'b', 'u', 'f')\r | |
1510 | #define NET_VECTOR_SIGNATURE SIGNATURE_32 ('n', 'v', 'e', 'c')\r | |
1511 | #define NET_QUE_SIGNATURE SIGNATURE_32 ('n', 'b', 'q', 'u')\r | |
97b38d4e | 1512 | \r |
1513 | \r | |
b45b45b2 | 1514 | #define NET_PROTO_DATA 64 // Opaque buffer for protocols\r |
1515 | #define NET_BUF_HEAD 1 // Trim or allocate space from head\r | |
1516 | #define NET_BUF_TAIL 0 // Trim or allocate space from tail\r | |
1517 | #define NET_VECTOR_OWN_FIRST 0x01 // We allocated the 1st block in the vector\r | |
97b38d4e | 1518 | \r |
1519 | #define NET_CHECK_SIGNATURE(PData, SIGNATURE) \\r | |
1520 | ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))\r | |
1521 | \r | |
97b38d4e | 1522 | //\r |
1523 | // Single memory block in the vector.\r | |
1524 | //\r | |
1525 | typedef struct {\r | |
1526 | UINT32 Len; // The block's length\r | |
1527 | UINT8 *Bulk; // The block's Data\r | |
1528 | } NET_BLOCK;\r | |
1529 | \r | |
e798cd87 | 1530 | typedef VOID (EFIAPI *NET_VECTOR_EXT_FREE) (VOID *Arg);\r |
97b38d4e | 1531 | \r |
1532 | //\r | |
1533 | //NET_VECTOR contains several blocks to hold all packet's\r | |
1534 | //fragments and other house-keeping stuff for sharing. It\r | |
1535 | //doesn't specify the where actual packet fragment begins.\r | |
1536 | //\r | |
1537 | typedef struct {\r | |
1538 | UINT32 Signature;\r | |
1539 | INTN RefCnt; // Reference count to share NET_VECTOR.\r | |
1540 | NET_VECTOR_EXT_FREE Free; // external function to free NET_VECTOR\r | |
86ac8fb2 | 1541 | VOID *Arg; // opaque argument to Free\r |
97b38d4e | 1542 | UINT32 Flag; // Flags, NET_VECTOR_OWN_FIRST\r |
86ac8fb2 | 1543 | UINT32 Len; // Total length of the associated BLOCKs\r |
97b38d4e | 1544 | \r |
1545 | UINT32 BlockNum;\r | |
1546 | NET_BLOCK Block[1];\r | |
1547 | } NET_VECTOR;\r | |
1548 | \r | |
1549 | //\r | |
e9b67286 | 1550 | //NET_BLOCK_OP operates on the NET_BLOCK. It specifies\r |
1551 | //where the actual fragment begins and ends\r | |
97b38d4e | 1552 | //\r |
1553 | typedef struct {\r | |
1554 | UINT8 *BlockHead; // Block's head, or the smallest valid Head\r | |
1555 | UINT8 *BlockTail; // Block's tail. BlockTail-BlockHead=block length\r | |
1556 | UINT8 *Head; // 1st byte of the data in the block\r | |
1557 | UINT8 *Tail; // Tail of the data in the block, Tail-Head=Size\r | |
1558 | UINT32 Size; // The size of the data\r | |
1559 | } NET_BLOCK_OP;\r | |
1560 | \r | |
f6b7393c | 1561 | typedef union {\r |
1562 | IP4_HEAD *Ip4;\r | |
1563 | EFI_IP6_HEADER *Ip6;\r | |
1564 | } NET_IP_HEAD;\r | |
97b38d4e | 1565 | \r |
1566 | //\r | |
1567 | //NET_BUF is the buffer manage structure used by the\r | |
e9b67286 | 1568 | //network stack. Every network packet may be fragmented. The Vector points to\r |
1569 | //memory blocks used by each fragment, and BlockOp\r | |
97b38d4e | 1570 | //specifies where each fragment begins and ends.\r |
1571 | //\r | |
e9b67286 | 1572 | //It also contains an opaque area for the protocol to store\r |
1573 | //per-packet information. Protocol must be careful not\r | |
97b38d4e | 1574 | //to overwrite the members after that.\r |
1575 | //\r | |
1576 | typedef struct {\r | |
f6b7393c | 1577 | UINT32 Signature;\r |
1578 | INTN RefCnt;\r | |
1579 | LIST_ENTRY List; // The List this NET_BUF is on\r | |
97b38d4e | 1580 | \r |
f6b7393c | 1581 | NET_IP_HEAD Ip; // Network layer header, for fast access\r |
1582 | TCP_HEAD *Tcp; // Transport layer header, for fast access\r | |
1583 | EFI_UDP_HEADER *Udp; // User Datagram Protocol header\r | |
1584 | UINT8 ProtoData [NET_PROTO_DATA]; //Protocol specific data\r | |
97b38d4e | 1585 | \r |
f6b7393c | 1586 | NET_VECTOR *Vector; // The vector containing the packet\r |
97b38d4e | 1587 | \r |
f6b7393c | 1588 | UINT32 BlockOpNum; // Total number of BlockOp in the buffer\r |
1589 | UINT32 TotalSize; // Total size of the actual packet\r | |
1590 | NET_BLOCK_OP BlockOp[1]; // Specify the position of actual packet\r | |
97b38d4e | 1591 | } NET_BUF;\r |
1592 | \r | |
97b38d4e | 1593 | //\r |
e9b67286 | 1594 | //A queue of NET_BUFs. It is a thin extension of\r |
97b38d4e | 1595 | //NET_BUF functions.\r |
1596 | //\r | |
1597 | typedef struct {\r | |
1598 | UINT32 Signature;\r | |
1599 | INTN RefCnt;\r | |
1600 | LIST_ENTRY List; // The List this buffer queue is on\r | |
1601 | \r | |
1602 | LIST_ENTRY BufList; // list of queued buffers\r | |
1603 | UINT32 BufSize; // total length of DATA in the buffers\r | |
1604 | UINT32 BufNum; // total number of buffers on the chain\r | |
1605 | } NET_BUF_QUEUE;\r | |
1606 | \r | |
1607 | //\r | |
1608 | // Pseudo header for TCP and UDP checksum\r | |
1609 | //\r | |
1610 | #pragma pack(1)\r | |
1611 | typedef struct {\r | |
1612 | IP4_ADDR SrcIp;\r | |
1613 | IP4_ADDR DstIp;\r | |
1614 | UINT8 Reserved;\r | |
1615 | UINT8 Protocol;\r | |
1616 | UINT16 Len;\r | |
1617 | } NET_PSEUDO_HDR;\r | |
f6b7393c | 1618 | \r |
1619 | typedef struct {\r | |
1620 | EFI_IPv6_ADDRESS SrcIp;\r | |
1621 | EFI_IPv6_ADDRESS DstIp;\r | |
1622 | UINT32 Len;\r | |
1623 | UINT32 Reserved:24;\r | |
1624 | UINT32 NextHeader:8;\r | |
1625 | } NET_IP6_PSEUDO_HDR;\r | |
97b38d4e | 1626 | #pragma pack()\r |
1627 | \r | |
1628 | //\r | |
1629 | // The fragment entry table used in network interfaces. This is\r | |
1630 | // the same as NET_BLOCK now. Use two different to distinguish\r | |
1631 | // the two in case that NET_BLOCK be enhanced later.\r | |
1632 | //\r | |
1633 | typedef struct {\r | |
1634 | UINT32 Len;\r | |
1635 | UINT8 *Bulk;\r | |
1636 | } NET_FRAGMENT;\r | |
1637 | \r | |
1638 | #define NET_GET_REF(PData) ((PData)->RefCnt++)\r | |
1639 | #define NET_PUT_REF(PData) ((PData)->RefCnt--)\r | |
50d7ebad | 1640 | #define NETBUF_FROM_PROTODATA(Info) BASE_CR((Info), NET_BUF, ProtoData)\r |
97b38d4e | 1641 | \r |
1642 | #define NET_BUF_SHARED(Buf) \\r | |
1643 | (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))\r | |
1644 | \r | |
1645 | #define NET_VECTOR_SIZE(BlockNum) \\r | |
1646 | (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))\r | |
1647 | \r | |
1648 | #define NET_BUF_SIZE(BlockOpNum) \\r | |
1649 | (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))\r | |
1650 | \r | |
1651 | #define NET_HEADSPACE(BlockOp) \\r | |
809e2bbf | 1652 | ((UINTN)((BlockOp)->Head) - (UINTN)((BlockOp)->BlockHead))\r |
97b38d4e | 1653 | \r |
1654 | #define NET_TAILSPACE(BlockOp) \\r | |
809e2bbf | 1655 | ((UINTN)((BlockOp)->BlockTail) - (UINTN)((BlockOp)->Tail))\r |
97b38d4e | 1656 | \r |
1657 | /**\r | |
1658 | Allocate a single block NET_BUF. Upon allocation, all the\r | |
1659 | free space is in the tail room.\r | |
1660 | \r | |
ae213b7d | 1661 | @param[in] Len The length of the block.\r |
97b38d4e | 1662 | \r |
64a80549 | 1663 | @return The pointer to the allocated NET_BUF, or NULL if the\r |
1664 | allocation failed due to resource limitations.\r | |
97b38d4e | 1665 | \r |
1666 | **/\r | |
1667 | NET_BUF *\r | |
1668 | EFIAPI\r | |
1669 | NetbufAlloc (\r | |
1670 | IN UINT32 Len\r | |
1671 | );\r | |
1672 | \r | |
1673 | /**\r | |
7557df4d | 1674 | Free the net buffer and its associated NET_VECTOR.\r |
1204fe83 | 1675 | \r |
7557df4d | 1676 | Decrease the reference count of the net buffer by one. Free the associated net\r |
1204fe83 | 1677 | vector and itself if the reference count of the net buffer is decreased to 0.\r |
1678 | The net vector free operation decreases the reference count of the net\r | |
e9b67286 | 1679 | vector by one, and performs the resource free operation when the reference count\r |
1204fe83 | 1680 | of the net vector is 0.\r |
1681 | \r | |
64a80549 | 1682 | @param[in] Nbuf The pointer to the NET_BUF to be freed.\r |
97b38d4e | 1683 | \r |
1684 | **/\r | |
1685 | VOID\r | |
1686 | EFIAPI\r | |
1687 | NetbufFree (\r | |
1688 | IN NET_BUF *Nbuf\r | |
1689 | );\r | |
1690 | \r | |
1691 | /**\r | |
1204fe83 | 1692 | Get the index of NET_BLOCK_OP that contains the byte at Offset in the net\r |
1693 | buffer.\r | |
1694 | \r | |
1695 | For example, this function can be used to retrieve the IP header in the packet. It\r | |
1696 | also can be used to get the fragment that contains the byte used\r | |
1697 | mainly by the library implementation itself.\r | |
97b38d4e | 1698 | \r |
64a80549 | 1699 | @param[in] Nbuf The pointer to the net buffer.\r |
7557df4d | 1700 | @param[in] Offset The offset of the byte.\r |
1204fe83 | 1701 | @param[out] Index Index of the NET_BLOCK_OP that contains the byte at\r |
7557df4d | 1702 | Offset.\r |
97b38d4e | 1703 | \r |
64a80549 | 1704 | @return The pointer to the Offset'th byte of data in the net buffer, or NULL\r |
7557df4d | 1705 | if there is no such data in the net buffer.\r |
97b38d4e | 1706 | \r |
1707 | **/\r | |
1708 | UINT8 *\r | |
1709 | EFIAPI\r | |
1710 | NetbufGetByte (\r | |
1711 | IN NET_BUF *Nbuf,\r | |
1712 | IN UINT32 Offset,\r | |
ae213b7d | 1713 | OUT UINT32 *Index OPTIONAL\r |
97b38d4e | 1714 | );\r |
1715 | \r | |
1716 | /**\r | |
1204fe83 | 1717 | Create a copy of the net buffer that shares the associated net vector.\r |
1718 | \r | |
1719 | The reference count of the newly created net buffer is set to 1. The reference\r | |
1720 | count of the associated net vector is increased by one.\r | |
97b38d4e | 1721 | \r |
64a80549 | 1722 | @param[in] Nbuf The pointer to the net buffer to be cloned.\r |
97b38d4e | 1723 | \r |
64a80549 | 1724 | @return The pointer to the cloned net buffer, or NULL if the\r |
1725 | allocation failed due to resource limitations.\r | |
97b38d4e | 1726 | \r |
1727 | **/\r | |
7557df4d | 1728 | NET_BUF *\r |
97b38d4e | 1729 | EFIAPI\r |
1730 | NetbufClone (\r | |
1731 | IN NET_BUF *Nbuf\r | |
1732 | );\r | |
1733 | \r | |
1734 | /**\r | |
7557df4d | 1735 | Create a duplicated copy of the net buffer with data copied and HeadSpace\r |
1736 | bytes of head space reserved.\r | |
1204fe83 | 1737 | \r |
7557df4d | 1738 | The duplicated net buffer will allocate its own memory to hold the data of the\r |
1739 | source net buffer.\r | |
1204fe83 | 1740 | \r |
64a80549 | 1741 | @param[in] Nbuf The pointer to the net buffer to be duplicated from.\r |
1742 | @param[in, out] Duplicate The pointer to the net buffer to duplicate to. If\r | |
1743 | NULL, a new net buffer is allocated.\r | |
1744 | @param[in] HeadSpace The length of the head space to reserve.\r | |
7557df4d | 1745 | \r |
64a80549 | 1746 | @return The pointer to the duplicated net buffer, or NULL if\r |
1747 | the allocation failed due to resource limitations.\r | |
97b38d4e | 1748 | \r |
1749 | **/\r | |
1750 | NET_BUF *\r | |
1751 | EFIAPI\r | |
1752 | NetbufDuplicate (\r | |
1753 | IN NET_BUF *Nbuf,\r | |
ae213b7d | 1754 | IN OUT NET_BUF *Duplicate OPTIONAL,\r |
97b38d4e | 1755 | IN UINT32 HeadSpace\r |
1756 | );\r | |
1757 | \r | |
1758 | /**\r | |
1204fe83 | 1759 | Create a NET_BUF structure which contains Len byte data of Nbuf starting from\r |
1760 | Offset.\r | |
1761 | \r | |
1762 | A new NET_BUF structure will be created but the associated data in NET_VECTOR\r | |
64a80549 | 1763 | is shared. This function exists to perform IP packet fragmentation.\r |
7557df4d | 1764 | \r |
64a80549 | 1765 | @param[in] Nbuf The pointer to the net buffer to be extracted.\r |
1204fe83 | 1766 | @param[in] Offset Starting point of the data to be included in the new\r |
7557df4d | 1767 | net buffer.\r |
64a80549 | 1768 | @param[in] Len The bytes of data to be included in the new net buffer.\r |
1769 | @param[in] HeadSpace The bytes of the head space to reserve for the protocol header.\r | |
7557df4d | 1770 | \r |
64a80549 | 1771 | @return The pointer to the cloned net buffer, or NULL if the\r |
1772 | allocation failed due to resource limitations.\r | |
97b38d4e | 1773 | \r |
1774 | **/\r | |
1775 | NET_BUF *\r | |
1776 | EFIAPI\r | |
1777 | NetbufGetFragment (\r | |
1778 | IN NET_BUF *Nbuf,\r | |
1779 | IN UINT32 Offset,\r | |
1780 | IN UINT32 Len,\r | |
1781 | IN UINT32 HeadSpace\r | |
1782 | );\r | |
1783 | \r | |
1784 | /**\r | |
7557df4d | 1785 | Reserve some space in the header room of the net buffer.\r |
1786 | \r | |
1204fe83 | 1787 | Upon allocation, all the space is in the tail room of the buffer. Call this\r |
64a80549 | 1788 | function to move space to the header room. This function is quite limited\r |
1204fe83 | 1789 | in that it can only reserve space from the first block of an empty NET_BUF not\r |
64a80549 | 1790 | built from the external. However, it should be enough for the network stack.\r |
97b38d4e | 1791 | \r |
64a80549 | 1792 | @param[in, out] Nbuf The pointer to the net buffer.\r |
7557df4d | 1793 | @param[in] Len The length of buffer to be reserved from the header.\r |
97b38d4e | 1794 | \r |
1795 | **/\r | |
1796 | VOID\r | |
1797 | EFIAPI\r | |
1798 | NetbufReserve (\r | |
ae213b7d | 1799 | IN OUT NET_BUF *Nbuf,\r |
97b38d4e | 1800 | IN UINT32 Len\r |
1801 | );\r | |
1802 | \r | |
1803 | /**\r | |
1204fe83 | 1804 | Allocate Len bytes of space from the header or tail of the buffer.\r |
97b38d4e | 1805 | \r |
64a80549 | 1806 | @param[in, out] Nbuf The pointer to the net buffer.\r |
7557df4d | 1807 | @param[in] Len The length of the buffer to be allocated.\r |
64a80549 | 1808 | @param[in] FromHead The flag to indicate whether to reserve the data\r |
7557df4d | 1809 | from head (TRUE) or tail (FALSE).\r |
97b38d4e | 1810 | \r |
64a80549 | 1811 | @return The pointer to the first byte of the allocated buffer,\r |
1812 | or NULL, if there is no sufficient space.\r | |
97b38d4e | 1813 | \r |
1814 | **/\r | |
7557df4d | 1815 | UINT8*\r |
97b38d4e | 1816 | EFIAPI\r |
1817 | NetbufAllocSpace (\r | |
ae213b7d | 1818 | IN OUT NET_BUF *Nbuf,\r |
97b38d4e | 1819 | IN UINT32 Len,\r |
1820 | IN BOOLEAN FromHead\r | |
1821 | );\r | |
1822 | \r | |
1823 | /**\r | |
64a80549 | 1824 | Trim Len bytes from the header or the tail of the net buffer.\r |
97b38d4e | 1825 | \r |
64a80549 | 1826 | @param[in, out] Nbuf The pointer to the net buffer.\r |
7557df4d | 1827 | @param[in] Len The length of the data to be trimmed.\r |
64a80549 | 1828 | @param[in] FromHead The flag to indicate whether trim data is from the \r |
1829 | head (TRUE) or the tail (FALSE).\r | |
97b38d4e | 1830 | \r |
64a80549 | 1831 | @return The length of the actual trimmed data, which may be less\r |
e9b67286 | 1832 | than Len if the TotalSize of Nbuf is less than Len.\r |
97b38d4e | 1833 | \r |
1834 | **/\r | |
1835 | UINT32\r | |
1836 | EFIAPI\r | |
1837 | NetbufTrim (\r | |
ae213b7d | 1838 | IN OUT NET_BUF *Nbuf,\r |
97b38d4e | 1839 | IN UINT32 Len,\r |
1840 | IN BOOLEAN FromHead\r | |
1841 | );\r | |
1842 | \r | |
1843 | /**\r | |
1204fe83 | 1844 | Copy Len bytes of data from the specific offset of the net buffer to the\r |
7557df4d | 1845 | destination memory.\r |
1204fe83 | 1846 | \r |
e9b67286 | 1847 | The Len bytes of data may cross several fragments of the net buffer.\r |
1204fe83 | 1848 | \r |
64a80549 | 1849 | @param[in] Nbuf The pointer to the net buffer.\r |
7557df4d | 1850 | @param[in] Offset The sequence number of the first byte to copy.\r |
64a80549 | 1851 | @param[in] Len The length of the data to copy.\r |
7557df4d | 1852 | @param[in] Dest The destination of the data to copy to.\r |
1853 | \r | |
1854 | @return The length of the actual copied data, or 0 if the offset\r | |
361468ed | 1855 | specified exceeds the total size of net buffer.\r |
97b38d4e | 1856 | \r |
1857 | **/\r | |
1858 | UINT32\r | |
1859 | EFIAPI\r | |
1860 | NetbufCopy (\r | |
1861 | IN NET_BUF *Nbuf,\r | |
1862 | IN UINT32 Offset,\r | |
1863 | IN UINT32 Len,\r | |
1864 | IN UINT8 *Dest\r | |
1865 | );\r | |
1866 | \r | |
1867 | /**\r | |
1204fe83 | 1868 | Build a NET_BUF from external blocks.\r |
1869 | \r | |
e9b67286 | 1870 | A new NET_BUF structure will be created from external blocks. An additional block\r |
7557df4d | 1871 | of memory will be allocated to hold reserved HeadSpace bytes of header room\r |
e9b67286 | 1872 | and existing HeadLen bytes of header, but the external blocks are shared by the\r |
7557df4d | 1873 | net buffer to avoid data copying.\r |
97b38d4e | 1874 | \r |
64a80549 | 1875 | @param[in] ExtFragment The pointer to the data block.\r |
7557df4d | 1876 | @param[in] ExtNum The number of the data blocks.\r |
ae213b7d | 1877 | @param[in] HeadSpace The head space to be reserved.\r |
e9b67286 | 1878 | @param[in] HeadLen The length of the protocol header. The function\r |
1879 | pulls this amount of data into a linear block.\r | |
64a80549 | 1880 | @param[in] ExtFree The pointer to the caller-provided free function.\r |
ae213b7d | 1881 | @param[in] Arg The argument passed to ExtFree when ExtFree is\r |
1882 | called.\r | |
97b38d4e | 1883 | \r |
64a80549 | 1884 | @return The pointer to the net buffer built from the data blocks,\r |
7557df4d | 1885 | or NULL if the allocation failed due to resource\r |
1886 | limit.\r | |
97b38d4e | 1887 | \r |
1888 | **/\r | |
1889 | NET_BUF *\r | |
1890 | EFIAPI\r | |
1891 | NetbufFromExt (\r | |
1892 | IN NET_FRAGMENT *ExtFragment,\r | |
1893 | IN UINT32 ExtNum,\r | |
1894 | IN UINT32 HeadSpace,\r | |
1895 | IN UINT32 HeadLen,\r | |
1896 | IN NET_VECTOR_EXT_FREE ExtFree,\r | |
1897 | IN VOID *Arg OPTIONAL\r | |
1898 | );\r | |
1899 | \r | |
1900 | /**\r | |
7557df4d | 1901 | Build a fragment table to contain the fragments in the net buffer. This is the\r |
1204fe83 | 1902 | opposite operation of the NetbufFromExt.\r |
1903 | \r | |
64a80549 | 1904 | @param[in] Nbuf Points to the net buffer.\r |
1905 | @param[in, out] ExtFragment The pointer to the data block.\r | |
7557df4d | 1906 | @param[in, out] ExtNum The number of the data blocks.\r |
97b38d4e | 1907 | \r |
1204fe83 | 1908 | @retval EFI_BUFFER_TOO_SMALL The number of non-empty blocks is bigger than\r |
7557df4d | 1909 | ExtNum.\r |
64a80549 | 1910 | @retval EFI_SUCCESS The fragment table was built successfully.\r |
97b38d4e | 1911 | \r |
1912 | **/\r | |
1913 | EFI_STATUS\r | |
1914 | EFIAPI\r | |
1915 | NetbufBuildExt (\r | |
1916 | IN NET_BUF *Nbuf,\r | |
ae213b7d | 1917 | IN OUT NET_FRAGMENT *ExtFragment,\r |
1918 | IN OUT UINT32 *ExtNum\r | |
97b38d4e | 1919 | );\r |
1920 | \r | |
1921 | /**\r | |
7557df4d | 1922 | Build a net buffer from a list of net buffers.\r |
1204fe83 | 1923 | \r |
64a80549 | 1924 | All the fragments will be collected from the list of NEW_BUF, and then a new\r |
1204fe83 | 1925 | net buffer will be created through NetbufFromExt.\r |
1926 | \r | |
7557df4d | 1927 | @param[in] BufList A List of the net buffer.\r |
1928 | @param[in] HeadSpace The head space to be reserved.\r | |
e9b67286 | 1929 | @param[in] HeaderLen The length of the protocol header. The function\r |
1930 | pulls this amount of data into a linear block.\r | |
64a80549 | 1931 | @param[in] ExtFree The pointer to the caller provided free function.\r |
7557df4d | 1932 | @param[in] Arg The argument passed to ExtFree when ExtFree is called.\r |
1933 | \r | |
64a80549 | 1934 | @return The pointer to the net buffer built from the list of net\r |
7557df4d | 1935 | buffers.\r |
97b38d4e | 1936 | \r |
1937 | **/\r | |
1938 | NET_BUF *\r | |
1939 | EFIAPI\r | |
1940 | NetbufFromBufList (\r | |
1941 | IN LIST_ENTRY *BufList,\r | |
1942 | IN UINT32 HeadSpace,\r | |
1943 | IN UINT32 HeaderLen,\r | |
1944 | IN NET_VECTOR_EXT_FREE ExtFree,\r | |
ae213b7d | 1945 | IN VOID *Arg OPTIONAL\r |
97b38d4e | 1946 | );\r |
1947 | \r | |
1948 | /**\r | |
1949 | Free a list of net buffers.\r | |
1950 | \r | |
64a80549 | 1951 | @param[in, out] Head The pointer to the head of linked net buffers.\r |
97b38d4e | 1952 | \r |
1953 | **/\r | |
1954 | VOID\r | |
1955 | EFIAPI\r | |
1956 | NetbufFreeList (\r | |
ae213b7d | 1957 | IN OUT LIST_ENTRY *Head\r |
97b38d4e | 1958 | );\r |
1959 | \r | |
1960 | /**\r | |
1961 | Initiate the net buffer queue.\r | |
1962 | \r | |
64a80549 | 1963 | @param[in, out] NbufQue The pointer to the net buffer queue to be initialized.\r |
97b38d4e | 1964 | \r |
1965 | **/\r | |
1966 | VOID\r | |
1967 | EFIAPI\r | |
1968 | NetbufQueInit (\r | |
ae213b7d | 1969 | IN OUT NET_BUF_QUEUE *NbufQue\r |
97b38d4e | 1970 | );\r |
1971 | \r | |
1972 | /**\r | |
7557df4d | 1973 | Allocate and initialize a net buffer queue.\r |
97b38d4e | 1974 | \r |
64a80549 | 1975 | @return The pointer to the allocated net buffer queue, or NULL if the\r |
7557df4d | 1976 | allocation failed due to resource limit.\r |
97b38d4e | 1977 | \r |
1978 | **/\r | |
1979 | NET_BUF_QUEUE *\r | |
1980 | EFIAPI\r | |
1981 | NetbufQueAlloc (\r | |
1982 | VOID\r | |
1983 | );\r | |
1984 | \r | |
1985 | /**\r | |
1204fe83 | 1986 | Free a net buffer queue.\r |
1987 | \r | |
7557df4d | 1988 | Decrease the reference count of the net buffer queue by one. The real resource\r |
1204fe83 | 1989 | free operation isn't performed until the reference count of the net buffer\r |
7557df4d | 1990 | queue is decreased to 0.\r |
97b38d4e | 1991 | \r |
64a80549 | 1992 | @param[in] NbufQue The pointer to the net buffer queue to be freed.\r |
97b38d4e | 1993 | \r |
1994 | **/\r | |
1995 | VOID\r | |
1996 | EFIAPI\r | |
1997 | NetbufQueFree (\r | |
1998 | IN NET_BUF_QUEUE *NbufQue\r | |
1999 | );\r | |
2000 | \r | |
2001 | /**\r | |
7557df4d | 2002 | Remove a net buffer from the head in the specific queue and return it.\r |
97b38d4e | 2003 | \r |
64a80549 | 2004 | @param[in, out] NbufQue The pointer to the net buffer queue.\r |
97b38d4e | 2005 | \r |
64a80549 | 2006 | @return The pointer to the net buffer removed from the specific queue,\r |
7557df4d | 2007 | or NULL if there is no net buffer in the specific queue.\r |
97b38d4e | 2008 | \r |
2009 | **/\r | |
2010 | NET_BUF *\r | |
2011 | EFIAPI\r | |
2012 | NetbufQueRemove (\r | |
ae213b7d | 2013 | IN OUT NET_BUF_QUEUE *NbufQue\r |
97b38d4e | 2014 | );\r |
2015 | \r | |
2016 | /**\r | |
7557df4d | 2017 | Append a net buffer to the net buffer queue.\r |
97b38d4e | 2018 | \r |
64a80549 | 2019 | @param[in, out] NbufQue The pointer to the net buffer queue.\r |
2020 | @param[in, out] Nbuf The pointer to the net buffer to be appended.\r | |
97b38d4e | 2021 | \r |
2022 | **/\r | |
2023 | VOID\r | |
2024 | EFIAPI\r | |
2025 | NetbufQueAppend (\r | |
ae213b7d | 2026 | IN OUT NET_BUF_QUEUE *NbufQue,\r |
2027 | IN OUT NET_BUF *Nbuf\r | |
97b38d4e | 2028 | );\r |
2029 | \r | |
2030 | /**\r | |
7557df4d | 2031 | Copy Len bytes of data from the net buffer queue at the specific offset to the\r |
2032 | destination memory.\r | |
1204fe83 | 2033 | \r |
64a80549 | 2034 | The copying operation is the same as NetbufCopy, but applies to the net buffer\r |
7557df4d | 2035 | queue instead of the net buffer.\r |
1204fe83 | 2036 | \r |
64a80549 | 2037 | @param[in] NbufQue The pointer to the net buffer queue.\r |
7557df4d | 2038 | @param[in] Offset The sequence number of the first byte to copy.\r |
64a80549 | 2039 | @param[in] Len The length of the data to copy.\r |
7557df4d | 2040 | @param[out] Dest The destination of the data to copy to.\r |
2041 | \r | |
1204fe83 | 2042 | @return The length of the actual copied data, or 0 if the offset\r |
7557df4d | 2043 | specified exceeds the total size of net buffer queue.\r |
97b38d4e | 2044 | \r |
2045 | **/\r | |
2046 | UINT32\r | |
2047 | EFIAPI\r | |
2048 | NetbufQueCopy (\r | |
2049 | IN NET_BUF_QUEUE *NbufQue,\r | |
2050 | IN UINT32 Offset,\r | |
2051 | IN UINT32 Len,\r | |
ae213b7d | 2052 | OUT UINT8 *Dest\r |
97b38d4e | 2053 | );\r |
2054 | \r | |
2055 | /**\r | |
3b1464d5 | 2056 | Trim Len bytes of data from the buffer queue and free any net buffer\r |
2057 | that is completely trimmed.\r | |
1204fe83 | 2058 | \r |
7557df4d | 2059 | The trimming operation is the same as NetbufTrim but applies to the net buffer\r |
2060 | queue instead of the net buffer.\r | |
97b38d4e | 2061 | \r |
64a80549 | 2062 | @param[in, out] NbufQue The pointer to the net buffer queue.\r |
2063 | @param[in] Len The length of the data to trim.\r | |
97b38d4e | 2064 | \r |
7557df4d | 2065 | @return The actual length of the data trimmed.\r |
97b38d4e | 2066 | \r |
2067 | **/\r | |
2068 | UINT32\r | |
2069 | EFIAPI\r | |
2070 | NetbufQueTrim (\r | |
ae213b7d | 2071 | IN OUT NET_BUF_QUEUE *NbufQue,\r |
97b38d4e | 2072 | IN UINT32 Len\r |
2073 | );\r | |
2074 | \r | |
2075 | \r | |
2076 | /**\r | |
2077 | Flush the net buffer queue.\r | |
2078 | \r | |
64a80549 | 2079 | @param[in, out] NbufQue The pointer to the queue to be flushed.\r |
97b38d4e | 2080 | \r |
2081 | **/\r | |
2082 | VOID\r | |
2083 | EFIAPI\r | |
2084 | NetbufQueFlush (\r | |
ae213b7d | 2085 | IN OUT NET_BUF_QUEUE *NbufQue\r |
97b38d4e | 2086 | );\r |
2087 | \r | |
2088 | /**\r | |
7557df4d | 2089 | Compute the checksum for a bulk of data.\r |
97b38d4e | 2090 | \r |
64a80549 | 2091 | @param[in] Bulk The pointer to the data.\r |
2092 | @param[in] Len The length of the data, in bytes.\r | |
97b38d4e | 2093 | \r |
ae213b7d | 2094 | @return The computed checksum.\r |
97b38d4e | 2095 | \r |
2096 | **/\r | |
2097 | UINT16\r | |
2098 | EFIAPI\r | |
2099 | NetblockChecksum (\r | |
2100 | IN UINT8 *Bulk,\r | |
2101 | IN UINT32 Len\r | |
2102 | );\r | |
2103 | \r | |
2104 | /**\r | |
2105 | Add two checksums.\r | |
2106 | \r | |
ae213b7d | 2107 | @param[in] Checksum1 The first checksum to be added.\r |
2108 | @param[in] Checksum2 The second checksum to be added.\r | |
97b38d4e | 2109 | \r |
ae213b7d | 2110 | @return The new checksum.\r |
97b38d4e | 2111 | \r |
2112 | **/\r | |
2113 | UINT16\r | |
2114 | EFIAPI\r | |
2115 | NetAddChecksum (\r | |
2116 | IN UINT16 Checksum1,\r | |
2117 | IN UINT16 Checksum2\r | |
2118 | );\r | |
2119 | \r | |
2120 | /**\r | |
2121 | Compute the checksum for a NET_BUF.\r | |
2122 | \r | |
64a80549 | 2123 | @param[in] Nbuf The pointer to the net buffer.\r |
97b38d4e | 2124 | \r |
ae213b7d | 2125 | @return The computed checksum.\r |
97b38d4e | 2126 | \r |
2127 | **/\r | |
2128 | UINT16\r | |
2129 | EFIAPI\r | |
2130 | NetbufChecksum (\r | |
2131 | IN NET_BUF *Nbuf\r | |
2132 | );\r | |
2133 | \r | |
2134 | /**\r | |
1204fe83 | 2135 | Compute the checksum for TCP/UDP pseudo header.\r |
2136 | \r | |
7557df4d | 2137 | Src and Dst are in network byte order, and Len is in host byte order.\r |
97b38d4e | 2138 | \r |
ae213b7d | 2139 | @param[in] Src The source address of the packet.\r |
2140 | @param[in] Dst The destination address of the packet.\r | |
2141 | @param[in] Proto The protocol type of the packet.\r | |
2142 | @param[in] Len The length of the packet.\r | |
97b38d4e | 2143 | \r |
ae213b7d | 2144 | @return The computed checksum.\r |
97b38d4e | 2145 | \r |
2146 | **/\r | |
2147 | UINT16\r | |
2148 | EFIAPI\r | |
2149 | NetPseudoHeadChecksum (\r | |
2150 | IN IP4_ADDR Src,\r | |
2151 | IN IP4_ADDR Dst,\r | |
2152 | IN UINT8 Proto,\r | |
2153 | IN UINT16 Len\r | |
2154 | );\r | |
2155 | \r | |
f6b7393c | 2156 | /**\r |
64a80549 | 2157 | Compute the checksum for the TCP6/UDP6 pseudo header.\r |
1204fe83 | 2158 | \r |
f6b7393c | 2159 | Src and Dst are in network byte order, and Len is in host byte order.\r |
2160 | \r | |
2161 | @param[in] Src The source address of the packet.\r | |
2162 | @param[in] Dst The destination address of the packet.\r | |
2163 | @param[in] NextHeader The protocol type of the packet.\r | |
2164 | @param[in] Len The length of the packet.\r | |
2165 | \r | |
2166 | @return The computed checksum.\r | |
2167 | \r | |
2168 | **/\r | |
2169 | UINT16\r | |
e798cd87 | 2170 | EFIAPI\r |
f6b7393c | 2171 | NetIp6PseudoHeadChecksum (\r |
2172 | IN EFI_IPv6_ADDRESS *Src,\r | |
2173 | IN EFI_IPv6_ADDRESS *Dst,\r | |
2174 | IN UINT8 NextHeader,\r | |
2175 | IN UINT32 Len\r | |
2176 | );\r | |
705f53a9 | 2177 | \r |
2178 | /**\r | |
2179 | The function frees the net buffer which allocated by the IP protocol. It releases \r | |
2180 | only the net buffer and doesn't call the external free function. \r | |
2181 | \r | |
2182 | This function should be called after finishing the process of mIpSec->ProcessExt() \r | |
2183 | for outbound traffic. The (EFI_IPSEC2_PROTOCOL)->ProcessExt() allocates a new \r | |
2184 | buffer for the ESP, so there needs a function to free the old net buffer.\r | |
2185 | \r | |
2186 | @param[in] Nbuf The network buffer to be freed.\r | |
2187 | \r | |
2188 | **/\r | |
2189 | VOID\r | |
2190 | NetIpSecNetbufFree (\r | |
2191 | NET_BUF *Nbuf\r | |
2192 | );\r | |
57b301b5 | 2193 | \r |
2194 | /**\r | |
2195 | This function obtains the system guid from the smbios table.\r | |
2196 | \r | |
2197 | @param[out] SystemGuid The pointer of the returned system guid.\r | |
2198 | \r | |
2199 | @retval EFI_SUCCESS Successfully obtained the system guid.\r | |
2200 | @retval EFI_NOT_FOUND Did not find the SMBIOS table.\r | |
2201 | \r | |
2202 | **/\r | |
2203 | EFI_STATUS\r | |
2204 | EFIAPI\r | |
2205 | NetLibGetSystemGuid (\r | |
2206 | OUT EFI_GUID *SystemGuid\r | |
2207 | );\r | |
2208 | \r | |
dba6e9a9 JW |
2209 | /**\r |
2210 | Create Dns QName according the queried domain name. \r | |
2211 | QName is a domain name represented as a sequence of labels, \r | |
2212 | where each label consists of a length octet followed by that \r | |
2213 | number of octets. The QName terminates with the zero \r | |
2214 | length octet for the null label of the root. Caller should \r | |
2215 | take responsibility to free the buffer in returned pointer.\r | |
2216 | \r | |
2217 | @param DomainName The pointer to the queried domain name string. \r | |
2218 | \r | |
2219 | @retval NULL Failed to fill QName.\r | |
2220 | @return QName filled successfully.\r | |
2221 | \r | |
2222 | **/ \r | |
2223 | CHAR8 *\r | |
2224 | EFIAPI\r | |
2225 | NetLibCreateDnsQName (\r | |
2226 | IN CHAR16 *DomainName\r | |
2227 | );\r | |
2228 | \r | |
97b38d4e | 2229 | #endif\r |