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