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