]>
Commit | Line | Data |
---|---|---|
97b38d4e | 1 | /** @file\r |
2 | This library provides basic function for UEFI network stack.\r | |
3 | \r | |
4 | Copyright (c) 2005 - 2008, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #ifndef _NET_LIB_H_\r | |
16 | #define _NET_LIB_H_\r | |
17 | \r | |
18 | #include <Library/BaseMemoryLib.h>\r | |
19 | #include <Library/MemoryAllocationLib.h>\r | |
20 | #include <Protocol/DriverBinding.h>\r | |
21 | #include <Protocol/ComponentName.h>\r | |
22 | #include <Protocol/DriverConfiguration.h>\r | |
23 | #include <Protocol/DriverDiagnostics.h>\r | |
24 | #include <Protocol/Dpc.h>\r | |
25 | \r | |
26 | typedef UINT32 IP4_ADDR;\r | |
27 | typedef UINT32 TCP_SEQNO;\r | |
28 | typedef UINT16 TCP_PORTNO;\r | |
29 | \r | |
30 | typedef enum {\r | |
31 | NET_ETHER_ADDR_LEN = 6,\r | |
32 | NET_IFTYPE_ETHERNET = 0x01,\r | |
33 | \r | |
34 | EFI_IP_PROTO_UDP = 0x11,\r | |
35 | EFI_IP_PROTO_TCP = 0x06,\r | |
36 | EFI_IP_PROTO_ICMP = 0x01,\r | |
37 | \r | |
38 | //\r | |
d7db0902 | 39 | // The address classification\r |
97b38d4e | 40 | //\r |
41 | IP4_ADDR_CLASSA = 1,\r | |
42 | IP4_ADDR_CLASSB,\r | |
43 | IP4_ADDR_CLASSC,\r | |
44 | IP4_ADDR_CLASSD,\r | |
45 | IP4_ADDR_CLASSE,\r | |
46 | \r | |
47 | IP4_MASK_NUM = 33\r | |
48 | } IP4_CLASS_TYPE;\r | |
49 | \r | |
50 | #pragma pack(1)\r | |
51 | \r | |
52 | //\r | |
53 | // Ethernet head definition\r | |
54 | //\r | |
55 | typedef struct {\r | |
56 | UINT8 DstMac [NET_ETHER_ADDR_LEN];\r | |
57 | UINT8 SrcMac [NET_ETHER_ADDR_LEN];\r | |
58 | UINT16 EtherType;\r | |
59 | } ETHER_HEAD;\r | |
60 | \r | |
61 | \r | |
62 | //\r | |
63 | // The EFI_IP4_HEADER is hard to use because the source and\r | |
64 | // destination address are defined as EFI_IPv4_ADDRESS, which\r | |
65 | // is a structure. Two structures can't be compared or masked\r | |
66 | // directly. This is why there is an internal representation.\r | |
67 | //\r | |
68 | typedef struct {\r | |
69 | UINT8 HeadLen : 4;\r | |
70 | UINT8 Ver : 4;\r | |
71 | UINT8 Tos;\r | |
72 | UINT16 TotalLen;\r | |
73 | UINT16 Id;\r | |
74 | UINT16 Fragment;\r | |
75 | UINT8 Ttl;\r | |
76 | UINT8 Protocol;\r | |
77 | UINT16 Checksum;\r | |
78 | IP4_ADDR Src;\r | |
79 | IP4_ADDR Dst;\r | |
80 | } IP4_HEAD;\r | |
81 | \r | |
82 | \r | |
83 | //\r | |
84 | // ICMP head definition. ICMP message is categoried as either an error\r | |
85 | // message or query message. Two message types have their own head format.\r | |
86 | //\r | |
87 | typedef struct {\r | |
88 | UINT8 Type;\r | |
89 | UINT8 Code;\r | |
90 | UINT16 Checksum;\r | |
91 | } IP4_ICMP_HEAD;\r | |
92 | \r | |
93 | typedef struct {\r | |
94 | IP4_ICMP_HEAD Head;\r | |
95 | UINT32 Fourth; // 4th filed of the head, it depends on Type.\r | |
96 | IP4_HEAD IpHead;\r | |
97 | } IP4_ICMP_ERROR_HEAD;\r | |
98 | \r | |
99 | typedef struct {\r | |
100 | IP4_ICMP_HEAD Head;\r | |
101 | UINT16 Id;\r | |
102 | UINT16 Seq;\r | |
103 | } IP4_ICMP_QUERY_HEAD;\r | |
104 | \r | |
105 | \r | |
106 | //\r | |
107 | // UDP header definition\r | |
108 | //\r | |
109 | typedef struct {\r | |
110 | UINT16 SrcPort;\r | |
111 | UINT16 DstPort;\r | |
112 | UINT16 Length;\r | |
113 | UINT16 Checksum;\r | |
114 | } EFI_UDP4_HEADER;\r | |
115 | \r | |
116 | \r | |
117 | //\r | |
118 | // TCP header definition\r | |
119 | //\r | |
120 | typedef struct {\r | |
121 | TCP_PORTNO SrcPort;\r | |
122 | TCP_PORTNO DstPort;\r | |
123 | TCP_SEQNO Seq;\r | |
124 | TCP_SEQNO Ack;\r | |
125 | UINT8 Res : 4;\r | |
126 | UINT8 HeadLen : 4;\r | |
127 | UINT8 Flag;\r | |
128 | UINT16 Wnd;\r | |
129 | UINT16 Checksum;\r | |
130 | UINT16 Urg;\r | |
131 | } TCP_HEAD;\r | |
132 | \r | |
133 | #pragma pack()\r | |
134 | \r | |
135 | #define NET_MAC_EQUAL(pMac1, pMac2, Len) \\r | |
136 | (CompareMem ((pMac1), (pMac2), Len) == 0)\r | |
137 | \r | |
138 | #define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \\r | |
139 | (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))\r | |
140 | \r | |
141 | #define NTOHL(x) (UINT32)((((UINT32) (x) & 0xff) << 24) | \\r | |
142 | (((UINT32) (x) & 0xff00) << 8) | \\r | |
143 | (((UINT32) (x) & 0xff0000) >> 8) | \\r | |
144 | (((UINT32) (x) & 0xff000000) >> 24))\r | |
145 | \r | |
146 | #define HTONL(x) NTOHL(x)\r | |
147 | \r | |
148 | #define NTOHS(x) (UINT16)((((UINT16) (x) & 0xff) << 8) | \\r | |
149 | (((UINT16) (x) & 0xff00) >> 8))\r | |
150 | \r | |
151 | #define HTONS(x) NTOHS(x)\r | |
152 | \r | |
153 | //\r | |
154 | // Test the IP's attribute, All the IPs are in host byte order.\r | |
155 | //\r | |
156 | #define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)\r | |
157 | #define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)\r | |
158 | #define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))\r | |
159 | #define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != IP4_MASK_NUM)\r | |
160 | \r | |
161 | //\r | |
162 | // Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.\r | |
163 | //\r | |
164 | #define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))\r | |
165 | #define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))\r | |
166 | #define EFI_IP4_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)\r | |
167 | \r | |
168 | /**\r | |
169 | Return the length of the mask. If the mask is invalid,\r | |
170 | return the invalid length 33, which is IP4_MASK_NUM.\r | |
171 | NetMask is in the host byte order.\r | |
172 | \r | |
ae213b7d | 173 | @param[in] NetMask The netmask to get the length from.\r |
97b38d4e | 174 | \r |
ae213b7d | 175 | @return The length of the netmask, IP4_MASK_NUM if the mask isn't.\r |
176 | \r | |
97b38d4e | 177 | **/\r |
178 | INTN\r | |
179 | EFIAPI\r | |
180 | NetGetMaskLength (\r | |
ae213b7d | 181 | IN IP4_ADDR NetMask\r |
97b38d4e | 182 | );\r |
183 | \r | |
184 | /**\r | |
185 | Return the class of the address, such as class a, b, c.\r | |
186 | Addr is in host byte order.\r | |
187 | \r | |
ae213b7d | 188 | @param[in] Addr The address to get the class from.\r |
97b38d4e | 189 | \r |
ae213b7d | 190 | @return IP address class, such as IP4_ADDR_CLASSA.\r |
97b38d4e | 191 | \r |
192 | **/\r | |
193 | INTN\r | |
194 | EFIAPI\r | |
195 | NetGetIpClass (\r | |
196 | IN IP4_ADDR Addr\r | |
197 | );\r | |
198 | \r | |
199 | /**\r | |
200 | Check whether the IP is a valid unicast address according to\r | |
201 | the netmask. If NetMask is zero, use the IP address's class to\r | |
202 | get the default mask.\r | |
203 | \r | |
ae213b7d | 204 | @param[in] Ip The IP to check against.\r |
205 | @param[in] NetMask The mask of the IP.\r | |
97b38d4e | 206 | \r |
ae213b7d | 207 | @return TRUE if IP is a valid unicast address on the network, otherwise FALSE.\r |
97b38d4e | 208 | \r |
209 | **/\r | |
210 | BOOLEAN\r | |
ae213b7d | 211 | EFIAPI\r |
97b38d4e | 212 | Ip4IsUnicast (\r |
213 | IN IP4_ADDR Ip,\r | |
214 | IN IP4_ADDR NetMask\r | |
215 | );\r | |
216 | \r | |
217 | extern IP4_ADDR gIp4AllMasks [IP4_MASK_NUM];\r | |
218 | \r | |
219 | \r | |
220 | extern EFI_IPv4_ADDRESS mZeroIp4Addr;\r | |
221 | \r | |
222 | #define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))\r | |
223 | #define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))\r | |
224 | #define NET_IS_LOWER_CASE_CHAR(Ch) (('a' <= (Ch)) && ((Ch) <= 'z'))\r | |
225 | #define NET_IS_UPPER_CASE_CHAR(Ch) (('A' <= (Ch)) && ((Ch) <= 'Z'))\r | |
226 | \r | |
227 | #define TICKS_PER_MS 10000U\r | |
228 | #define TICKS_PER_SECOND 10000000U\r | |
229 | \r | |
230 | #define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)\r | |
231 | \r | |
232 | /**\r | |
233 | Extract a UINT32 from a byte stream, then convert it to host\r | |
234 | byte order. Use this function to avoid alignment error.\r | |
235 | \r | |
ae213b7d | 236 | @param[in] Buf The buffer to extract the UINT32.\r |
97b38d4e | 237 | \r |
238 | @return The UINT32 extracted.\r | |
239 | \r | |
240 | **/\r | |
241 | UINT32\r | |
242 | EFIAPI\r | |
243 | NetGetUint32 (\r | |
244 | IN UINT8 *Buf\r | |
245 | );\r | |
246 | \r | |
247 | /**\r | |
248 | Put a UINT32 to the byte stream. Convert it from host byte order\r | |
249 | to network byte order before putting.\r | |
250 | \r | |
ae213b7d | 251 | @param[in, out] Buf The buffer to put the UINT32.\r |
252 | @param[in] Data The data to put.\r | |
253 | \r | |
97b38d4e | 254 | **/\r |
255 | VOID\r | |
256 | EFIAPI\r | |
257 | NetPutUint32 (\r | |
ae213b7d | 258 | IN OUT UINT8 *Buf,\r |
259 | IN UINT32 Data\r | |
97b38d4e | 260 | );\r |
261 | \r | |
262 | /**\r | |
263 | Initialize a random seed using current time.\r | |
264 | \r | |
97b38d4e | 265 | @return The random seed initialized with current time.\r |
266 | \r | |
267 | **/\r | |
268 | UINT32\r | |
269 | EFIAPI\r | |
270 | NetRandomInitSeed (\r | |
271 | VOID\r | |
272 | );\r | |
273 | \r | |
274 | \r | |
275 | #define NET_LIST_USER_STRUCT(Entry, Type, Field) \\r | |
50d7ebad | 276 | BASE_CR(Entry, Type, Field)\r |
97b38d4e | 277 | \r |
278 | #define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \\r | |
279 | CR(Entry, Type, Field, Sig)\r | |
280 | \r | |
281 | //\r | |
282 | // Iterate through the doule linked list. It is NOT delete safe\r | |
283 | //\r | |
284 | #define NET_LIST_FOR_EACH(Entry, ListHead) \\r | |
285 | for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)\r | |
286 | \r | |
287 | //\r | |
288 | // Iterate through the doule linked list. This is delete-safe.\r | |
289 | // Don't touch NextEntry. Also, don't use this macro if list\r | |
290 | // entries other than the Entry may be deleted when processing\r | |
291 | // the current Entry.\r | |
292 | //\r | |
293 | #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \\r | |
294 | for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \\r | |
295 | Entry != (ListHead); \\r | |
296 | Entry = NextEntry, NextEntry = Entry->ForwardLink \\r | |
297 | )\r | |
298 | \r | |
299 | //\r | |
300 | // Make sure the list isn't empty before get the frist/last record.\r | |
301 | //\r | |
302 | #define NET_LIST_HEAD(ListHead, Type, Field) \\r | |
303 | NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)\r | |
304 | \r | |
305 | #define NET_LIST_TAIL(ListHead, Type, Field) \\r | |
306 | NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)\r | |
307 | \r | |
308 | \r | |
309 | /**\r | |
ae213b7d | 310 | Remove the first entry on the list.\r |
97b38d4e | 311 | \r |
ae213b7d | 312 | @param[in, out] Head The list header.\r |
97b38d4e | 313 | \r |
314 | @return The entry that is removed from the list, NULL if the list is empty.\r | |
315 | \r | |
316 | **/\r | |
317 | LIST_ENTRY *\r | |
318 | EFIAPI\r | |
319 | NetListRemoveHead (\r | |
ae213b7d | 320 | IN OUT LIST_ENTRY *Head\r |
97b38d4e | 321 | );\r |
322 | \r | |
323 | /**\r | |
ae213b7d | 324 | Remove the last entry on the list.\r |
97b38d4e | 325 | \r |
ae213b7d | 326 | @param[in, out] Head The list head.\r |
97b38d4e | 327 | \r |
328 | @return The entry that is removed from the list, NULL if the list is empty.\r | |
329 | \r | |
330 | **/\r | |
331 | LIST_ENTRY *\r | |
332 | EFIAPI\r | |
333 | NetListRemoveTail (\r | |
ae213b7d | 334 | IN OUT LIST_ENTRY *Head\r |
97b38d4e | 335 | );\r |
336 | \r | |
337 | /**\r | |
338 | Insert the NewEntry after the PrevEntry.\r | |
339 | \r | |
ae213b7d | 340 | @param[in, out] PrevEntry The previous entry to insert after.\r |
341 | @param[in, out] NewEntry The new entry to insert.\r | |
97b38d4e | 342 | \r |
343 | **/\r | |
344 | VOID\r | |
345 | EFIAPI\r | |
346 | NetListInsertAfter (\r | |
ae213b7d | 347 | IN OUT LIST_ENTRY *PrevEntry,\r |
348 | IN OUT LIST_ENTRY *NewEntry\r | |
97b38d4e | 349 | );\r |
350 | \r | |
351 | /**\r | |
352 | Insert the NewEntry before the PostEntry.\r | |
353 | \r | |
ae213b7d | 354 | @param[in, out] PostEntry The entry to insert before.\r |
355 | @param[in, out] NewEntry The new entry to insert.\r | |
97b38d4e | 356 | \r |
357 | **/\r | |
358 | VOID\r | |
359 | EFIAPI\r | |
360 | NetListInsertBefore (\r | |
ae213b7d | 361 | IN OUT LIST_ENTRY *PostEntry,\r |
362 | IN OUT LIST_ENTRY *NewEntry\r | |
97b38d4e | 363 | );\r |
364 | \r | |
365 | \r | |
366 | //\r | |
367 | // Object container: EFI network stack spec defines various kinds of\r | |
368 | // tokens. The drivers can share code to manage those objects.\r | |
369 | //\r | |
370 | typedef struct {\r | |
371 | LIST_ENTRY Link;\r | |
372 | VOID *Key;\r | |
373 | VOID *Value;\r | |
374 | } NET_MAP_ITEM;\r | |
375 | \r | |
376 | typedef struct {\r | |
377 | LIST_ENTRY Used;\r | |
378 | LIST_ENTRY Recycled;\r | |
379 | UINTN Count;\r | |
380 | } NET_MAP;\r | |
381 | \r | |
382 | #define NET_MAP_INCREAMENT 64\r | |
383 | \r | |
384 | /**\r | |
385 | Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.\r | |
386 | \r | |
ae213b7d | 387 | @param[in, out] Map The netmap to initialize.\r |
97b38d4e | 388 | \r |
389 | **/\r | |
390 | VOID\r | |
391 | EFIAPI\r | |
392 | NetMapInit (\r | |
ae213b7d | 393 | IN OUT NET_MAP *Map\r |
97b38d4e | 394 | );\r |
395 | \r | |
396 | /**\r | |
397 | To clean up the netmap, that is, release allocated memories.\r | |
398 | \r | |
ae213b7d | 399 | @param[in, out] Map The netmap to clean up.\r |
97b38d4e | 400 | \r |
401 | **/\r | |
402 | VOID\r | |
403 | EFIAPI\r | |
404 | NetMapClean (\r | |
ae213b7d | 405 | IN OUT NET_MAP *Map\r |
97b38d4e | 406 | );\r |
407 | \r | |
408 | /**\r | |
ae213b7d | 409 | Test whether the netmap is empty.\r |
97b38d4e | 410 | \r |
ae213b7d | 411 | @param[in] Map The net map to test.\r |
97b38d4e | 412 | \r |
413 | @return TRUE if the netmap is empty, otherwise FALSE.\r | |
414 | \r | |
415 | **/\r | |
416 | BOOLEAN\r | |
417 | EFIAPI\r | |
418 | NetMapIsEmpty (\r | |
419 | IN NET_MAP *Map\r | |
420 | );\r | |
421 | \r | |
422 | /**\r | |
423 | Return the number of the <Key, Value> pairs in the netmap.\r | |
424 | \r | |
ae213b7d | 425 | @param[in] Map The netmap to get the entry number.\r |
97b38d4e | 426 | \r |
427 | @return The entry number in the netmap.\r | |
428 | \r | |
429 | **/\r | |
430 | UINTN\r | |
431 | EFIAPI\r | |
432 | NetMapGetCount (\r | |
433 | IN NET_MAP *Map\r | |
434 | );\r | |
435 | \r | |
436 | /**\r | |
437 | Allocate an item to save the <Key, Value> pair to the head of the netmap.\r | |
438 | \r | |
ae213b7d | 439 | @param[in, out] Map The netmap to insert into.\r |
440 | @param[in] Key The user's key.\r | |
441 | @param[in] Value The user's value for the key.\r | |
97b38d4e | 442 | \r |
ae213b7d | 443 | @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.\r |
444 | @retval EFI_SUCCESS The item is inserted to the head.\r | |
97b38d4e | 445 | \r |
446 | **/\r | |
447 | EFI_STATUS\r | |
448 | EFIAPI\r | |
449 | NetMapInsertHead (\r | |
ae213b7d | 450 | IN OUT NET_MAP *Map,\r |
97b38d4e | 451 | IN VOID *Key,\r |
452 | IN VOID *Value OPTIONAL\r | |
453 | );\r | |
454 | \r | |
455 | /**\r | |
456 | Allocate an item to save the <Key, Value> pair to the tail of the netmap.\r | |
457 | \r | |
ae213b7d | 458 | @param[in, out] Map The netmap to insert into.\r |
459 | @param[in] Key The user's key.\r | |
460 | @param[in] Value The user's value for the key.\r | |
97b38d4e | 461 | \r |
ae213b7d | 462 | @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.\r |
463 | @retval EFI_SUCCESS The item is inserted to the tail.\r | |
97b38d4e | 464 | \r |
465 | **/\r | |
466 | EFI_STATUS\r | |
467 | EFIAPI\r | |
468 | NetMapInsertTail (\r | |
ae213b7d | 469 | IN OUT NET_MAP *Map,\r |
97b38d4e | 470 | IN VOID *Key,\r |
471 | IN VOID *Value OPTIONAL\r | |
472 | );\r | |
473 | \r | |
474 | /**\r | |
ae213b7d | 475 | Find the key in the netmap.\r |
97b38d4e | 476 | \r |
ae213b7d | 477 | @param[in] Map The netmap to search within.\r |
478 | @param[in] Key The key to search.\r | |
97b38d4e | 479 | \r |
480 | @return The point to the item contains the Key, or NULL if Key isn't in the map.\r | |
481 | \r | |
482 | **/\r | |
ae213b7d | 483 | NET_MAP_ITEM *\r |
97b38d4e | 484 | EFIAPI\r |
485 | NetMapFindKey (\r | |
486 | IN NET_MAP *Map,\r | |
487 | IN VOID *Key\r | |
488 | );\r | |
489 | \r | |
490 | /**\r | |
ae213b7d | 491 | Remove the item from the netmap.\r |
97b38d4e | 492 | \r |
ae213b7d | 493 | @param[in, out] Map The netmap to remove the item from.\r |
494 | @param[in, out] Item The item to remove.\r | |
495 | @param[out] Value The variable to receive the value if not NULL.\r | |
97b38d4e | 496 | \r |
ae213b7d | 497 | @return The key of the removed item.\r |
97b38d4e | 498 | \r |
499 | **/\r | |
500 | VOID *\r | |
501 | EFIAPI\r | |
502 | NetMapRemoveItem (\r | |
ae213b7d | 503 | IN OUT NET_MAP *Map,\r |
504 | IN OUT NET_MAP_ITEM *Item,\r | |
505 | OUT VOID **Value OPTIONAL\r | |
97b38d4e | 506 | );\r |
507 | \r | |
508 | /**\r | |
509 | Remove the first entry on the netmap.\r | |
510 | \r | |
ae213b7d | 511 | @param[in, out] Map The netmap to remove the head from.\r |
512 | @param[out] Value The variable to receive the value if not NULL.\r | |
97b38d4e | 513 | \r |
ae213b7d | 514 | @return The key of the item removed.\r |
97b38d4e | 515 | \r |
516 | **/\r | |
517 | VOID *\r | |
518 | EFIAPI\r | |
519 | NetMapRemoveHead (\r | |
ae213b7d | 520 | IN OUT NET_MAP *Map,\r |
521 | OUT VOID **Value OPTIONAL\r | |
97b38d4e | 522 | );\r |
523 | \r | |
524 | /**\r | |
525 | Remove the last entry on the netmap.\r | |
526 | \r | |
ae213b7d | 527 | @param[in, out] Map The netmap to remove the tail from.\r |
528 | @param[out] Value The variable to receive the value if not NULL.\r | |
97b38d4e | 529 | \r |
ae213b7d | 530 | @return The key of the item removed.\r |
97b38d4e | 531 | \r |
532 | **/\r | |
533 | VOID *\r | |
534 | EFIAPI\r | |
535 | NetMapRemoveTail (\r | |
ae213b7d | 536 | IN OUT NET_MAP *Map,\r |
537 | OUT VOID **Value OPTIONAL\r | |
97b38d4e | 538 | );\r |
539 | \r | |
540 | typedef\r | |
541 | EFI_STATUS\r | |
542 | (*NET_MAP_CALLBACK) (\r | |
543 | IN NET_MAP *Map,\r | |
544 | IN NET_MAP_ITEM *Item,\r | |
545 | IN VOID *Arg\r | |
546 | );\r | |
547 | \r | |
548 | /**\r | |
549 | Iterate through the netmap and call CallBack for each item. It will\r | |
550 | contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break\r | |
551 | from the loop. It returns the CallBack's last return value. This\r | |
552 | function is delete safe for the current item.\r | |
553 | \r | |
ae213b7d | 554 | @param[in] Map The Map to iterate through.\r |
555 | @param[in] CallBack The callback function to call for each item.\r | |
556 | @param[in] Arg The opaque parameter to the callback.\r | |
97b38d4e | 557 | \r |
ae213b7d | 558 | @retval EFI_SUCCESS There is no item in the netmap or CallBack for each item\r |
559 | return EFI_SUCCESS.\r | |
560 | @retval Others It returns the CallBack's last return value.\r | |
97b38d4e | 561 | \r |
562 | **/\r | |
563 | EFI_STATUS\r | |
564 | EFIAPI\r | |
565 | NetMapIterate (\r | |
566 | IN NET_MAP *Map,\r | |
567 | IN NET_MAP_CALLBACK CallBack,\r | |
ae213b7d | 568 | IN VOID *Arg\r |
97b38d4e | 569 | );\r |
570 | \r | |
571 | \r | |
572 | //\r | |
573 | // Helper functions to implement driver binding and service binding protocols.\r | |
574 | //\r | |
575 | /**\r | |
576 | Create a child of the service that is identified by ServiceBindingGuid.\r | |
577 | \r | |
ae213b7d | 578 | @param[in] Controller The controller which has the service installed.\r |
579 | @param[in] Image The image handle used to open service.\r | |
580 | @param[in] ServiceBindingGuid The service's Guid.\r | |
581 | @param[in, out] ChildHandle The handle to receive the create child\r | |
97b38d4e | 582 | \r |
583 | @retval EFI_SUCCESS The child is successfully created.\r | |
584 | @retval Others Failed to create the child.\r | |
585 | \r | |
586 | **/\r | |
587 | EFI_STATUS\r | |
588 | EFIAPI\r | |
589 | NetLibCreateServiceChild (\r | |
ae213b7d | 590 | IN EFI_HANDLE Controller,\r |
591 | IN EFI_HANDLE Image,\r | |
97b38d4e | 592 | IN EFI_GUID *ServiceBindingGuid,\r |
ae213b7d | 593 | IN OUT EFI_HANDLE *ChildHandle\r |
97b38d4e | 594 | );\r |
595 | \r | |
596 | /**\r | |
597 | Destory a child of the service that is identified by ServiceBindingGuid.\r | |
598 | \r | |
ae213b7d | 599 | @param[in] Controller The controller which has the service installed.\r |
600 | @param[in] Image The image handle used to open service.\r | |
601 | @param[in] ServiceBindingGuid The service's Guid.\r | |
602 | @param[in] ChildHandle The child to destory\r | |
97b38d4e | 603 | \r |
604 | @retval EFI_SUCCESS The child is successfully destoried.\r | |
605 | @retval Others Failed to destory the child.\r | |
606 | \r | |
607 | **/\r | |
608 | EFI_STATUS\r | |
609 | EFIAPI\r | |
610 | NetLibDestroyServiceChild (\r | |
ae213b7d | 611 | IN EFI_HANDLE Controller,\r |
612 | IN EFI_HANDLE Image,\r | |
97b38d4e | 613 | IN EFI_GUID *ServiceBindingGuid,\r |
614 | IN EFI_HANDLE ChildHandle\r | |
615 | );\r | |
616 | \r | |
617 | /**\r | |
618 | Convert the mac address of the simple network protocol installed on\r | |
619 | SnpHandle to a unicode string. Callers are responsible for freeing the\r | |
620 | string storage.\r | |
621 | \r | |
ae213b7d | 622 | @param[in] SnpHandle The handle where the simple network protocol is\r |
623 | installed on.\r | |
624 | @param[in] ImageHandle The image handle used to act as the agent handle to\r | |
625 | get the simple network protocol.\r | |
626 | @param[out] MacString The pointer to store the address of the string\r | |
627 | representation of the mac address.\r | |
628 | \r | |
629 | @retval EFI_SUCCESS Convert the mac address a unicode string successfully.\r | |
97b38d4e | 630 | @retval EFI_OUT_OF_RESOURCES There are not enough memory resource.\r |
ae213b7d | 631 | @retval Others Failed to open the simple network protocol.\r |
97b38d4e | 632 | \r |
633 | **/\r | |
634 | EFI_STATUS\r | |
635 | EFIAPI\r | |
636 | NetLibGetMacString (\r | |
ae213b7d | 637 | IN EFI_HANDLE SnpHandle,\r |
638 | IN EFI_HANDLE ImageHandle,\r | |
639 | OUT CHAR16 **MacString\r | |
97b38d4e | 640 | );\r |
641 | \r | |
642 | /**\r | |
643 | Create an IPv4 device path node.\r | |
644 | \r | |
ae213b7d | 645 | @param[in, out] Node Pointer to the IPv4 device path node.\r |
646 | @param[in] Controller The handle where the NIC IP4 config protocol resides.\r | |
647 | @param[in] LocalIp The local IPv4 address.\r | |
648 | @param[in] LocalPort The local port.\r | |
649 | @param[in] RemoteIp The remote IPv4 address.\r | |
650 | @param[in] RemotePort The remote port.\r | |
651 | @param[in] Protocol The protocol type in the IP header.\r | |
652 | @param[in] UseDefaultAddress Whether this instance is using default address or not.\r | |
97b38d4e | 653 | \r |
97b38d4e | 654 | **/\r |
655 | VOID\r | |
656 | EFIAPI\r | |
657 | NetLibCreateIPv4DPathNode (\r | |
658 | IN OUT IPv4_DEVICE_PATH *Node,\r | |
659 | IN EFI_HANDLE Controller,\r | |
660 | IN IP4_ADDR LocalIp,\r | |
661 | IN UINT16 LocalPort,\r | |
662 | IN IP4_ADDR RemoteIp,\r | |
663 | IN UINT16 RemotePort,\r | |
664 | IN UINT16 Protocol,\r | |
665 | IN BOOLEAN UseDefaultAddress\r | |
666 | );\r | |
667 | \r | |
668 | /**\r | |
669 | Find the UNDI/SNP handle from controller and protocol GUID.\r | |
670 | For example, IP will open a MNP child to transmit/receive\r | |
671 | packets, when MNP is stopped, IP should also be stopped. IP\r | |
672 | needs to find its own private data which is related the IP's\r | |
673 | service binding instance that is install on UNDI/SNP handle.\r | |
674 | Now, the controller is either a MNP or ARP child handle. But\r | |
675 | IP opens these handle BY_DRIVER, use that info, we can get the\r | |
676 | UNDI/SNP handle.\r | |
677 | \r | |
ae213b7d | 678 | @param[in] Controller Then protocol handle to check.\r |
679 | @param[in] ProtocolGuid The protocol that is related with the handle.\r | |
97b38d4e | 680 | \r |
ae213b7d | 681 | @return The UNDI/SNP handle or NULL for errors.\r |
97b38d4e | 682 | \r |
683 | **/\r | |
684 | EFI_HANDLE\r | |
685 | EFIAPI\r | |
686 | NetLibGetNicHandle (\r | |
687 | IN EFI_HANDLE Controller,\r | |
688 | IN EFI_GUID *ProtocolGuid\r | |
689 | );\r | |
690 | \r | |
691 | /**\r | |
692 | Add a Deferred Procedure Call to the end of the DPC queue.\r | |
693 | \r | |
ae213b7d | 694 | @param[in] DpcTpl The EFI_TPL that the DPC should be invoked.\r |
695 | @param[in] DpcProcedure Pointer to the DPC's function.\r | |
696 | @param[in] DpcContext Pointer to the DPC's context. Passed to DpcProcedure\r | |
697 | when DpcProcedure is invoked.\r | |
97b38d4e | 698 | \r |
699 | @retval EFI_SUCCESS The DPC was queued.\r | |
ae213b7d | 700 | @retval EFI_INVALID_PARAMETER DpcTpl is not a valid EFI_TPL, or DpcProcedure\r |
701 | is NULL.\r | |
97b38d4e | 702 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r |
703 | add the DPC to the queue.\r | |
704 | \r | |
705 | **/\r | |
706 | EFI_STATUS\r | |
707 | EFIAPI\r | |
708 | NetLibQueueDpc (\r | |
709 | IN EFI_TPL DpcTpl,\r | |
710 | IN EFI_DPC_PROCEDURE DpcProcedure,\r | |
711 | IN VOID *DpcContext OPTIONAL\r | |
712 | );\r | |
713 | \r | |
714 | /**\r | |
ae213b7d | 715 | Dispatch the queue of DPCs. ALL DPCs that have been queued with a DpcTpl\r |
716 | value greater than or equal to the current TPL are invoked in the order that\r | |
717 | they were queued. DPCs with higher DpcTpl values are invoked before DPCs with\r | |
718 | lower DpcTpl values.\r | |
97b38d4e | 719 | \r |
720 | @retval EFI_SUCCESS One or more DPCs were invoked.\r | |
721 | @retval EFI_NOT_FOUND No DPCs were invoked.\r | |
722 | \r | |
723 | **/\r | |
724 | EFI_STATUS\r | |
725 | EFIAPI\r | |
726 | NetLibDispatchDpc (\r | |
727 | VOID\r | |
728 | );\r | |
729 | \r | |
730 | /**\r | |
731 | This is the default unload handle for all the network drivers.\r | |
732 | \r | |
ae213b7d | 733 | @param[in] ImageHandle The drivers' driver image.\r |
97b38d4e | 734 | \r |
735 | @retval EFI_SUCCESS The image is unloaded.\r | |
736 | @retval Others Failed to unload the image.\r | |
737 | \r | |
738 | **/\r | |
739 | EFI_STATUS\r | |
740 | EFIAPI\r | |
741 | NetLibDefaultUnload (\r | |
742 | IN EFI_HANDLE ImageHandle\r | |
743 | );\r | |
744 | \r | |
745 | typedef enum {\r | |
746 | //\r | |
747 | //Various signatures\r | |
748 | //\r | |
f3f2e05d | 749 | NET_BUF_SIGNATURE = SIGNATURE_32 ('n', 'b', 'u', 'f'),\r |
750 | NET_VECTOR_SIGNATURE = SIGNATURE_32 ('n', 'v', 'e', 'c'),\r | |
751 | NET_QUE_SIGNATURE = SIGNATURE_32 ('n', 'b', 'q', 'u'),\r | |
97b38d4e | 752 | \r |
753 | \r | |
754 | NET_PROTO_DATA = 64, // Opaque buffer for protocols\r | |
755 | NET_BUF_HEAD = 1, // Trim or allocate space from head\r | |
756 | NET_BUF_TAIL = 0, // Trim or allocate space from tail\r | |
757 | NET_VECTOR_OWN_FIRST = 0x01 // We allocated the 1st block in the vector\r | |
758 | } NET_SIGNATURE_TYPE;\r | |
759 | \r | |
760 | #define NET_CHECK_SIGNATURE(PData, SIGNATURE) \\r | |
761 | ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))\r | |
762 | \r | |
763 | #define NET_SWAP_SHORT(Value) \\r | |
764 | ((((Value) & 0xff) << 8) | (((Value) >> 8) & 0xff))\r | |
765 | \r | |
766 | //\r | |
767 | // Single memory block in the vector.\r | |
768 | //\r | |
769 | typedef struct {\r | |
770 | UINT32 Len; // The block's length\r | |
771 | UINT8 *Bulk; // The block's Data\r | |
772 | } NET_BLOCK;\r | |
773 | \r | |
774 | typedef VOID (*NET_VECTOR_EXT_FREE) (VOID *Arg);\r | |
775 | \r | |
776 | //\r | |
777 | //NET_VECTOR contains several blocks to hold all packet's\r | |
778 | //fragments and other house-keeping stuff for sharing. It\r | |
779 | //doesn't specify the where actual packet fragment begins.\r | |
780 | //\r | |
781 | typedef struct {\r | |
782 | UINT32 Signature;\r | |
783 | INTN RefCnt; // Reference count to share NET_VECTOR.\r | |
784 | NET_VECTOR_EXT_FREE Free; // external function to free NET_VECTOR\r | |
785 | VOID *Arg; // opeque argument to Free\r | |
786 | UINT32 Flag; // Flags, NET_VECTOR_OWN_FIRST\r | |
787 | UINT32 Len; // Total length of the assocated BLOCKs\r | |
788 | \r | |
789 | UINT32 BlockNum;\r | |
790 | NET_BLOCK Block[1];\r | |
791 | } NET_VECTOR;\r | |
792 | \r | |
793 | //\r | |
794 | //NET_BLOCK_OP operate on the NET_BLOCK, It specifies\r | |
795 | //where the actual fragment begins and where it ends\r | |
796 | //\r | |
797 | typedef struct {\r | |
798 | UINT8 *BlockHead; // Block's head, or the smallest valid Head\r | |
799 | UINT8 *BlockTail; // Block's tail. BlockTail-BlockHead=block length\r | |
800 | UINT8 *Head; // 1st byte of the data in the block\r | |
801 | UINT8 *Tail; // Tail of the data in the block, Tail-Head=Size\r | |
802 | UINT32 Size; // The size of the data\r | |
803 | } NET_BLOCK_OP;\r | |
804 | \r | |
805 | \r | |
806 | //\r | |
807 | //NET_BUF is the buffer manage structure used by the\r | |
808 | //network stack. Every network packet may be fragmented,\r | |
809 | //and contains multiple fragments. The Vector points to\r | |
810 | //memory blocks used by the each fragment, and BlockOp\r | |
811 | //specifies where each fragment begins and ends.\r | |
812 | //\r | |
813 | //It also contains a opaque area for protocol to store\r | |
814 | //per-packet informations. Protocol must be caution not\r | |
815 | //to overwrite the members after that.\r | |
816 | //\r | |
817 | typedef struct {\r | |
818 | UINT32 Signature;\r | |
819 | INTN RefCnt;\r | |
820 | LIST_ENTRY List; // The List this NET_BUF is on\r | |
821 | \r | |
822 | IP4_HEAD *Ip; // Network layer header, for fast access\r | |
823 | TCP_HEAD *Tcp; // Transport layer header, for fast access\r | |
824 | UINT8 ProtoData [NET_PROTO_DATA]; //Protocol specific data\r | |
825 | \r | |
826 | NET_VECTOR *Vector; // The vector containing the packet\r | |
827 | \r | |
828 | UINT32 BlockOpNum; // Total number of BlockOp in the buffer\r | |
829 | UINT32 TotalSize; // Total size of the actual packet\r | |
830 | NET_BLOCK_OP BlockOp[1]; // Specify the position of actual packet\r | |
831 | } NET_BUF;\r | |
832 | \r | |
833 | \r | |
834 | //\r | |
835 | //A queue of NET_BUFs, It is just a thin extension of\r | |
836 | //NET_BUF functions.\r | |
837 | //\r | |
838 | typedef struct {\r | |
839 | UINT32 Signature;\r | |
840 | INTN RefCnt;\r | |
841 | LIST_ENTRY List; // The List this buffer queue is on\r | |
842 | \r | |
843 | LIST_ENTRY BufList; // list of queued buffers\r | |
844 | UINT32 BufSize; // total length of DATA in the buffers\r | |
845 | UINT32 BufNum; // total number of buffers on the chain\r | |
846 | } NET_BUF_QUEUE;\r | |
847 | \r | |
848 | //\r | |
849 | // Pseudo header for TCP and UDP checksum\r | |
850 | //\r | |
851 | #pragma pack(1)\r | |
852 | typedef struct {\r | |
853 | IP4_ADDR SrcIp;\r | |
854 | IP4_ADDR DstIp;\r | |
855 | UINT8 Reserved;\r | |
856 | UINT8 Protocol;\r | |
857 | UINT16 Len;\r | |
858 | } NET_PSEUDO_HDR;\r | |
859 | #pragma pack()\r | |
860 | \r | |
861 | //\r | |
862 | // The fragment entry table used in network interfaces. This is\r | |
863 | // the same as NET_BLOCK now. Use two different to distinguish\r | |
864 | // the two in case that NET_BLOCK be enhanced later.\r | |
865 | //\r | |
866 | typedef struct {\r | |
867 | UINT32 Len;\r | |
868 | UINT8 *Bulk;\r | |
869 | } NET_FRAGMENT;\r | |
870 | \r | |
871 | #define NET_GET_REF(PData) ((PData)->RefCnt++)\r | |
872 | #define NET_PUT_REF(PData) ((PData)->RefCnt--)\r | |
50d7ebad | 873 | #define NETBUF_FROM_PROTODATA(Info) BASE_CR((Info), NET_BUF, ProtoData)\r |
97b38d4e | 874 | \r |
875 | #define NET_BUF_SHARED(Buf) \\r | |
876 | (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))\r | |
877 | \r | |
878 | #define NET_VECTOR_SIZE(BlockNum) \\r | |
879 | (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))\r | |
880 | \r | |
881 | #define NET_BUF_SIZE(BlockOpNum) \\r | |
882 | (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))\r | |
883 | \r | |
884 | #define NET_HEADSPACE(BlockOp) \\r | |
885 | (UINTN)((BlockOp)->Head - (BlockOp)->BlockHead)\r | |
886 | \r | |
887 | #define NET_TAILSPACE(BlockOp) \\r | |
888 | (UINTN)((BlockOp)->BlockTail - (BlockOp)->Tail)\r | |
889 | \r | |
890 | /**\r | |
891 | Allocate a single block NET_BUF. Upon allocation, all the\r | |
892 | free space is in the tail room.\r | |
893 | \r | |
ae213b7d | 894 | @param[in] Len The length of the block.\r |
97b38d4e | 895 | \r |
7557df4d | 896 | @return Pointer to the allocated NET_BUF, or NULL if the \r |
897 | allocation failed due to resource limit.\r | |
97b38d4e | 898 | \r |
899 | **/\r | |
900 | NET_BUF *\r | |
901 | EFIAPI\r | |
902 | NetbufAlloc (\r | |
903 | IN UINT32 Len\r | |
904 | );\r | |
905 | \r | |
906 | /**\r | |
7557df4d | 907 | Free the net buffer and its associated NET_VECTOR.\r |
908 | \r | |
909 | Decrease the reference count of the net buffer by one. Free the associated net\r | |
910 | vector and itself if the reference count of the net buffer is decreased to 0. \r | |
911 | The net vector free operation just decrease the reference count of the net \r | |
912 | vector by one and do the real resource free operation when the reference count\r | |
913 | of the net vector is 0. \r | |
914 | \r | |
ae213b7d | 915 | @param[in] Nbuf Pointer to the NET_BUF to be freed.\r |
97b38d4e | 916 | \r |
917 | **/\r | |
918 | VOID\r | |
919 | EFIAPI\r | |
920 | NetbufFree (\r | |
921 | IN NET_BUF *Nbuf\r | |
922 | );\r | |
923 | \r | |
924 | /**\r | |
7557df4d | 925 | Get the index of NET_BLOCK_OP that contains the byte at Offset in the net \r |
926 | buffer. \r | |
927 | \r | |
928 | This can be used to, for example, retrieve the IP header in the packet. It \r | |
929 | also can be used to get the fragment that contains the byte which is used \r | |
930 | mainly by the library implementation itself. \r | |
97b38d4e | 931 | \r |
7557df4d | 932 | @param[in] Nbuf Pointer to the net buffer.\r |
933 | @param[in] Offset The offset of the byte.\r | |
934 | @param[out] Index Index of the NET_BLOCK_OP that contains the byte at \r | |
935 | Offset.\r | |
97b38d4e | 936 | \r |
7557df4d | 937 | @return Pointer to the Offset'th byte of data in the net buffer, or NULL\r |
938 | if there is no such data in the net buffer.\r | |
97b38d4e | 939 | \r |
940 | **/\r | |
941 | UINT8 *\r | |
942 | EFIAPI\r | |
943 | NetbufGetByte (\r | |
944 | IN NET_BUF *Nbuf,\r | |
945 | IN UINT32 Offset,\r | |
ae213b7d | 946 | OUT UINT32 *Index OPTIONAL\r |
97b38d4e | 947 | );\r |
948 | \r | |
949 | /**\r | |
7557df4d | 950 | Create a copy of the net buffer that shares the associated net vector. \r |
951 | \r | |
952 | The reference count of the newly created net buffer is set to 1. The reference \r | |
953 | count of the associated net vector is increased by one. \r | |
97b38d4e | 954 | \r |
ae213b7d | 955 | @param[in] Nbuf Pointer to the net buffer to be cloned.\r |
97b38d4e | 956 | \r |
7557df4d | 957 | @return Pointer to the cloned net buffer, or NULL if the\r |
ae213b7d | 958 | allocation failed due to resource limit.\r |
97b38d4e | 959 | \r |
960 | **/\r | |
7557df4d | 961 | NET_BUF *\r |
97b38d4e | 962 | EFIAPI\r |
963 | NetbufClone (\r | |
964 | IN NET_BUF *Nbuf\r | |
965 | );\r | |
966 | \r | |
967 | /**\r | |
7557df4d | 968 | Create a duplicated copy of the net buffer with data copied and HeadSpace\r |
969 | bytes of head space reserved.\r | |
970 | \r | |
971 | The duplicated net buffer will allocate its own memory to hold the data of the\r | |
972 | source net buffer.\r | |
973 | \r | |
974 | @param[in] Nbuf Pointer to the net buffer to be duplicated from.\r | |
975 | @param[in, out] Duplicate Pointer to the net buffer to duplicate to, if \r | |
976 | NULL a new net buffer is allocated.\r | |
977 | @param[in] HeadSpace Length of the head space to reserve.\r | |
978 | \r | |
979 | @return Pointer to the duplicated net buffer, or NULL if\r | |
980 | the allocation failed due to resource limit.\r | |
97b38d4e | 981 | \r |
982 | **/\r | |
983 | NET_BUF *\r | |
984 | EFIAPI\r | |
985 | NetbufDuplicate (\r | |
986 | IN NET_BUF *Nbuf,\r | |
ae213b7d | 987 | IN OUT NET_BUF *Duplicate OPTIONAL,\r |
97b38d4e | 988 | IN UINT32 HeadSpace\r |
989 | );\r | |
990 | \r | |
991 | /**\r | |
7557df4d | 992 | Create a NET_BUF structure which contains Len byte data of Nbuf starting from \r |
993 | Offset. \r | |
994 | \r | |
995 | A new NET_BUF structure will be created but the associated data in NET_VECTOR \r | |
996 | is shared. This function exists to do IP packet fragmentation. \r | |
997 | \r | |
998 | @param[in] Nbuf Pointer to the net buffer to be extracted.\r | |
999 | @param[in] Offset Starting point of the data to be included in the new \r | |
1000 | net buffer.\r | |
1001 | @param[in] Len Bytes of data to be included in the new net buffer. \r | |
1002 | @param[in] HeadSpace Bytes of head space to reserve for protocol header. \r | |
1003 | \r | |
1004 | @return Pointer to the cloned net buffer, or NULL if the \r | |
1005 | allocation failed due to resource limit.\r | |
97b38d4e | 1006 | \r |
1007 | **/\r | |
1008 | NET_BUF *\r | |
1009 | EFIAPI\r | |
1010 | NetbufGetFragment (\r | |
1011 | IN NET_BUF *Nbuf,\r | |
1012 | IN UINT32 Offset,\r | |
1013 | IN UINT32 Len,\r | |
1014 | IN UINT32 HeadSpace\r | |
1015 | );\r | |
1016 | \r | |
1017 | /**\r | |
7557df4d | 1018 | Reserve some space in the header room of the net buffer.\r |
1019 | \r | |
1020 | Upon allocation, all the space are in the tail room of the buffer. Call this \r | |
1021 | function to move some space to the header room. This function is quite limited\r | |
1022 | in that it can only reserve space from the first block of an empty NET_BUF not \r | |
1023 | built from the external. But it should be enough for the network stack. \r | |
97b38d4e | 1024 | \r |
7557df4d | 1025 | @param[in, out] Nbuf Pointer to the net buffer.\r |
1026 | @param[in] Len The length of buffer to be reserved from the header.\r | |
97b38d4e | 1027 | \r |
1028 | **/\r | |
1029 | VOID\r | |
1030 | EFIAPI\r | |
1031 | NetbufReserve (\r | |
ae213b7d | 1032 | IN OUT NET_BUF *Nbuf,\r |
97b38d4e | 1033 | IN UINT32 Len\r |
1034 | );\r | |
1035 | \r | |
1036 | /**\r | |
7557df4d | 1037 | Allocate Len bytes of space from the header or tail of the buffer. \r |
97b38d4e | 1038 | \r |
7557df4d | 1039 | @param[in, out] Nbuf Pointer to the net buffer.\r |
1040 | @param[in] Len The length of the buffer to be allocated.\r | |
1041 | @param[in] FromHead The flag to indicate whether reserve the data \r | |
1042 | from head (TRUE) or tail (FALSE).\r | |
97b38d4e | 1043 | \r |
7557df4d | 1044 | @return Pointer to the first byte of the allocated buffer, \r |
1045 | or NULL if there is no sufficient space.\r | |
97b38d4e | 1046 | \r |
1047 | **/\r | |
7557df4d | 1048 | UINT8*\r |
97b38d4e | 1049 | EFIAPI\r |
1050 | NetbufAllocSpace (\r | |
ae213b7d | 1051 | IN OUT NET_BUF *Nbuf,\r |
97b38d4e | 1052 | IN UINT32 Len,\r |
1053 | IN BOOLEAN FromHead\r | |
1054 | );\r | |
1055 | \r | |
1056 | /**\r | |
7557df4d | 1057 | Trim Len bytes from the header or tail of the net buffer. \r |
97b38d4e | 1058 | \r |
7557df4d | 1059 | @param[in, out] Nbuf Pointer to the net buffer.\r |
1060 | @param[in] Len The length of the data to be trimmed.\r | |
1061 | @param[in] FromHead The flag to indicate whether trim data from head \r | |
1062 | (TRUE) or tail (FALSE).\r | |
97b38d4e | 1063 | \r |
7557df4d | 1064 | @return Length of the actually trimmed data, which is possible to be less \r |
1065 | than Len because the TotalSize of Nbuf is less than Len.\r | |
97b38d4e | 1066 | \r |
1067 | **/\r | |
1068 | UINT32\r | |
1069 | EFIAPI\r | |
1070 | NetbufTrim (\r | |
ae213b7d | 1071 | IN OUT NET_BUF *Nbuf,\r |
97b38d4e | 1072 | IN UINT32 Len,\r |
1073 | IN BOOLEAN FromHead\r | |
1074 | );\r | |
1075 | \r | |
1076 | /**\r | |
7557df4d | 1077 | Copy Len bytes of data from the specific offset of the net buffer to the \r |
1078 | destination memory.\r | |
1079 | \r | |
1080 | The Len bytes of data may cross the several fragments of the net buffer.\r | |
1081 | \r | |
1082 | @param[in] Nbuf Pointer to the net buffer.\r | |
1083 | @param[in] Offset The sequence number of the first byte to copy.\r | |
1084 | @param[in] Len Length of the data to copy.\r | |
1085 | @param[in] Dest The destination of the data to copy to.\r | |
1086 | \r | |
1087 | @return The length of the actual copied data, or 0 if the offset\r | |
1088 | specified exceeds exceeds the total size of net buffer.\r | |
97b38d4e | 1089 | \r |
1090 | **/\r | |
1091 | UINT32\r | |
1092 | EFIAPI\r | |
1093 | NetbufCopy (\r | |
1094 | IN NET_BUF *Nbuf,\r | |
1095 | IN UINT32 Offset,\r | |
1096 | IN UINT32 Len,\r | |
1097 | IN UINT8 *Dest\r | |
1098 | );\r | |
1099 | \r | |
1100 | /**\r | |
7557df4d | 1101 | Build a NET_BUF from external blocks. \r |
1102 | \r | |
1103 | A new NET_BUF structure will be created from external blocks. Additional block\r | |
1104 | of memory will be allocated to hold reserved HeadSpace bytes of header room\r | |
1105 | and existing HeadLen bytes of header but the external blocks are shared by the\r | |
1106 | net buffer to avoid data copying.\r | |
97b38d4e | 1107 | \r |
ae213b7d | 1108 | @param[in] ExtFragment Pointer to the data block.\r |
7557df4d | 1109 | @param[in] ExtNum The number of the data blocks.\r |
ae213b7d | 1110 | @param[in] HeadSpace The head space to be reserved.\r |
1111 | @param[in] HeadLen The length of the protocol header, This function\r | |
1112 | will pull that number of data into a linear block.\r | |
1113 | @param[in] ExtFree Pointer to the caller provided free function.\r | |
1114 | @param[in] Arg The argument passed to ExtFree when ExtFree is\r | |
1115 | called.\r | |
97b38d4e | 1116 | \r |
7557df4d | 1117 | @return Pointer to the net buffer built from the data blocks, \r |
1118 | or NULL if the allocation failed due to resource\r | |
1119 | limit.\r | |
97b38d4e | 1120 | \r |
1121 | **/\r | |
1122 | NET_BUF *\r | |
1123 | EFIAPI\r | |
1124 | NetbufFromExt (\r | |
1125 | IN NET_FRAGMENT *ExtFragment,\r | |
1126 | IN UINT32 ExtNum,\r | |
1127 | IN UINT32 HeadSpace,\r | |
1128 | IN UINT32 HeadLen,\r | |
1129 | IN NET_VECTOR_EXT_FREE ExtFree,\r | |
1130 | IN VOID *Arg OPTIONAL\r | |
1131 | );\r | |
1132 | \r | |
1133 | /**\r | |
7557df4d | 1134 | Build a fragment table to contain the fragments in the net buffer. This is the\r |
1135 | opposite operation of the NetbufFromExt. \r | |
1136 | \r | |
ae213b7d | 1137 | @param[in] Nbuf Point to the net buffer.\r |
1138 | @param[in, out] ExtFragment Pointer to the data block.\r | |
7557df4d | 1139 | @param[in, out] ExtNum The number of the data blocks.\r |
97b38d4e | 1140 | \r |
7557df4d | 1141 | @retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than \r |
1142 | ExtNum.\r | |
1143 | @retval EFI_SUCCESS Fragment table is built successfully.\r | |
97b38d4e | 1144 | \r |
1145 | **/\r | |
1146 | EFI_STATUS\r | |
1147 | EFIAPI\r | |
1148 | NetbufBuildExt (\r | |
1149 | IN NET_BUF *Nbuf,\r | |
ae213b7d | 1150 | IN OUT NET_FRAGMENT *ExtFragment,\r |
1151 | IN OUT UINT32 *ExtNum\r | |
97b38d4e | 1152 | );\r |
1153 | \r | |
1154 | /**\r | |
7557df4d | 1155 | Build a net buffer from a list of net buffers.\r |
1156 | \r | |
1157 | All the fragments will be collected from the list of NEW_BUF and then a new \r | |
1158 | net buffer will be created through NetbufFromExt. \r | |
1159 | \r | |
1160 | @param[in] BufList A List of the net buffer.\r | |
1161 | @param[in] HeadSpace The head space to be reserved.\r | |
1162 | @param[in] HeaderLen The length of the protocol header, This function\r | |
1163 | will pull that number of data into a linear block.\r | |
1164 | @param[in] ExtFree Pointer to the caller provided free function.\r | |
1165 | @param[in] Arg The argument passed to ExtFree when ExtFree is called.\r | |
1166 | \r | |
1167 | @return Pointer to the net buffer built from the list of net \r | |
1168 | buffers.\r | |
97b38d4e | 1169 | \r |
1170 | **/\r | |
1171 | NET_BUF *\r | |
1172 | EFIAPI\r | |
1173 | NetbufFromBufList (\r | |
1174 | IN LIST_ENTRY *BufList,\r | |
1175 | IN UINT32 HeadSpace,\r | |
1176 | IN UINT32 HeaderLen,\r | |
1177 | IN NET_VECTOR_EXT_FREE ExtFree,\r | |
ae213b7d | 1178 | IN VOID *Arg OPTIONAL\r |
97b38d4e | 1179 | );\r |
1180 | \r | |
1181 | /**\r | |
1182 | Free a list of net buffers.\r | |
1183 | \r | |
ae213b7d | 1184 | @param[in, out] Head Pointer to the head of linked net buffers.\r |
97b38d4e | 1185 | \r |
1186 | **/\r | |
1187 | VOID\r | |
1188 | EFIAPI\r | |
1189 | NetbufFreeList (\r | |
ae213b7d | 1190 | IN OUT LIST_ENTRY *Head\r |
97b38d4e | 1191 | );\r |
1192 | \r | |
1193 | /**\r | |
1194 | Initiate the net buffer queue.\r | |
1195 | \r | |
7557df4d | 1196 | @param[in, out] NbufQue Pointer to the net buffer queue to be initialized.\r |
97b38d4e | 1197 | \r |
1198 | **/\r | |
1199 | VOID\r | |
1200 | EFIAPI\r | |
1201 | NetbufQueInit (\r | |
ae213b7d | 1202 | IN OUT NET_BUF_QUEUE *NbufQue\r |
97b38d4e | 1203 | );\r |
1204 | \r | |
1205 | /**\r | |
7557df4d | 1206 | Allocate and initialize a net buffer queue.\r |
97b38d4e | 1207 | \r |
7557df4d | 1208 | @return Pointer to the allocated net buffer queue, or NULL if the\r |
1209 | allocation failed due to resource limit.\r | |
97b38d4e | 1210 | \r |
1211 | **/\r | |
1212 | NET_BUF_QUEUE *\r | |
1213 | EFIAPI\r | |
1214 | NetbufQueAlloc (\r | |
1215 | VOID\r | |
1216 | );\r | |
1217 | \r | |
1218 | /**\r | |
7557df4d | 1219 | Free a net buffer queue. \r |
1220 | \r | |
1221 | Decrease the reference count of the net buffer queue by one. The real resource\r | |
1222 | free operation isn't performed until the reference count of the net buffer \r | |
1223 | queue is decreased to 0.\r | |
97b38d4e | 1224 | \r |
7557df4d | 1225 | @param[in] NbufQue Pointer to the net buffer queue to be freed.\r |
97b38d4e | 1226 | \r |
1227 | **/\r | |
1228 | VOID\r | |
1229 | EFIAPI\r | |
1230 | NetbufQueFree (\r | |
1231 | IN NET_BUF_QUEUE *NbufQue\r | |
1232 | );\r | |
1233 | \r | |
1234 | /**\r | |
7557df4d | 1235 | Remove a net buffer from the head in the specific queue and return it.\r |
97b38d4e | 1236 | \r |
ae213b7d | 1237 | @param[in, out] NbufQue Pointer to the net buffer queue.\r |
97b38d4e | 1238 | \r |
7557df4d | 1239 | @return Pointer to the net buffer removed from the specific queue, \r |
1240 | or NULL if there is no net buffer in the specific queue.\r | |
97b38d4e | 1241 | \r |
1242 | **/\r | |
1243 | NET_BUF *\r | |
1244 | EFIAPI\r | |
1245 | NetbufQueRemove (\r | |
ae213b7d | 1246 | IN OUT NET_BUF_QUEUE *NbufQue\r |
97b38d4e | 1247 | );\r |
1248 | \r | |
1249 | /**\r | |
7557df4d | 1250 | Append a net buffer to the net buffer queue.\r |
97b38d4e | 1251 | \r |
7557df4d | 1252 | @param[in, out] NbufQue Pointer to the net buffer queue.\r |
1253 | @param[in, out] Nbuf Pointer to the net buffer to be appended.\r | |
97b38d4e | 1254 | \r |
1255 | **/\r | |
1256 | VOID\r | |
1257 | EFIAPI\r | |
1258 | NetbufQueAppend (\r | |
ae213b7d | 1259 | IN OUT NET_BUF_QUEUE *NbufQue,\r |
1260 | IN OUT NET_BUF *Nbuf\r | |
97b38d4e | 1261 | );\r |
1262 | \r | |
1263 | /**\r | |
7557df4d | 1264 | Copy Len bytes of data from the net buffer queue at the specific offset to the\r |
1265 | destination memory.\r | |
1266 | \r | |
1267 | The copying operation is the same as NetbufCopy but applies to the net buffer\r | |
1268 | queue instead of the net buffer.\r | |
1269 | \r | |
1270 | @param[in] NbufQue Pointer to the net buffer queue.\r | |
1271 | @param[in] Offset The sequence number of the first byte to copy.\r | |
1272 | @param[in] Len Length of the data to copy.\r | |
1273 | @param[out] Dest The destination of the data to copy to.\r | |
1274 | \r | |
1275 | @return The length of the actual copied data, or 0 if the offset \r | |
1276 | specified exceeds the total size of net buffer queue.\r | |
97b38d4e | 1277 | \r |
1278 | **/\r | |
1279 | UINT32\r | |
1280 | EFIAPI\r | |
1281 | NetbufQueCopy (\r | |
1282 | IN NET_BUF_QUEUE *NbufQue,\r | |
1283 | IN UINT32 Offset,\r | |
1284 | IN UINT32 Len,\r | |
ae213b7d | 1285 | OUT UINT8 *Dest\r |
97b38d4e | 1286 | );\r |
1287 | \r | |
1288 | /**\r | |
7557df4d | 1289 | Trim Len bytes of data from the queue header, release any of the net buffer \r |
1290 | whom is trimmed wholely.\r | |
1291 | \r | |
1292 | The trimming operation is the same as NetbufTrim but applies to the net buffer\r | |
1293 | queue instead of the net buffer.\r | |
97b38d4e | 1294 | \r |
ae213b7d | 1295 | @param[in, out] NbufQue Pointer to the net buffer queue.\r |
1296 | @param[in] Len Length of the data to trim.\r | |
97b38d4e | 1297 | \r |
7557df4d | 1298 | @return The actual length of the data trimmed.\r |
97b38d4e | 1299 | \r |
1300 | **/\r | |
1301 | UINT32\r | |
1302 | EFIAPI\r | |
1303 | NetbufQueTrim (\r | |
ae213b7d | 1304 | IN OUT NET_BUF_QUEUE *NbufQue,\r |
97b38d4e | 1305 | IN UINT32 Len\r |
1306 | );\r | |
1307 | \r | |
1308 | \r | |
1309 | /**\r | |
1310 | Flush the net buffer queue.\r | |
1311 | \r | |
ae213b7d | 1312 | @param[in, out] NbufQue Pointer to the queue to be flushed.\r |
97b38d4e | 1313 | \r |
1314 | **/\r | |
1315 | VOID\r | |
1316 | EFIAPI\r | |
1317 | NetbufQueFlush (\r | |
ae213b7d | 1318 | IN OUT NET_BUF_QUEUE *NbufQue\r |
97b38d4e | 1319 | );\r |
1320 | \r | |
1321 | /**\r | |
7557df4d | 1322 | Compute the checksum for a bulk of data.\r |
97b38d4e | 1323 | \r |
ae213b7d | 1324 | @param[in] Bulk Pointer to the data.\r |
1325 | @param[in] Len Length of the data, in bytes.\r | |
97b38d4e | 1326 | \r |
ae213b7d | 1327 | @return The computed checksum.\r |
97b38d4e | 1328 | \r |
1329 | **/\r | |
1330 | UINT16\r | |
1331 | EFIAPI\r | |
1332 | NetblockChecksum (\r | |
1333 | IN UINT8 *Bulk,\r | |
1334 | IN UINT32 Len\r | |
1335 | );\r | |
1336 | \r | |
1337 | /**\r | |
1338 | Add two checksums.\r | |
1339 | \r | |
ae213b7d | 1340 | @param[in] Checksum1 The first checksum to be added.\r |
1341 | @param[in] Checksum2 The second checksum to be added.\r | |
97b38d4e | 1342 | \r |
ae213b7d | 1343 | @return The new checksum.\r |
97b38d4e | 1344 | \r |
1345 | **/\r | |
1346 | UINT16\r | |
1347 | EFIAPI\r | |
1348 | NetAddChecksum (\r | |
1349 | IN UINT16 Checksum1,\r | |
1350 | IN UINT16 Checksum2\r | |
1351 | );\r | |
1352 | \r | |
1353 | /**\r | |
1354 | Compute the checksum for a NET_BUF.\r | |
1355 | \r | |
ae213b7d | 1356 | @param[in] Nbuf Pointer to the net buffer.\r |
97b38d4e | 1357 | \r |
ae213b7d | 1358 | @return The computed checksum.\r |
97b38d4e | 1359 | \r |
1360 | **/\r | |
1361 | UINT16\r | |
1362 | EFIAPI\r | |
1363 | NetbufChecksum (\r | |
1364 | IN NET_BUF *Nbuf\r | |
1365 | );\r | |
1366 | \r | |
1367 | /**\r | |
7557df4d | 1368 | Compute the checksum for TCP/UDP pseudo header. \r |
1369 | \r | |
1370 | Src and Dst are in network byte order, and Len is in host byte order.\r | |
97b38d4e | 1371 | \r |
ae213b7d | 1372 | @param[in] Src The source address of the packet.\r |
1373 | @param[in] Dst The destination address of the packet.\r | |
1374 | @param[in] Proto The protocol type of the packet.\r | |
1375 | @param[in] Len The length of the packet.\r | |
97b38d4e | 1376 | \r |
ae213b7d | 1377 | @return The computed checksum.\r |
97b38d4e | 1378 | \r |
1379 | **/\r | |
1380 | UINT16\r | |
1381 | EFIAPI\r | |
1382 | NetPseudoHeadChecksum (\r | |
1383 | IN IP4_ADDR Src,\r | |
1384 | IN IP4_ADDR Dst,\r | |
1385 | IN UINT8 Proto,\r | |
1386 | IN UINT16 Len\r | |
1387 | );\r | |
1388 | \r | |
1389 | #endif\r |