]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
MdeModulePkg: Fix some typos of "according"
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Udp4Dxe / Udp4Impl.c
... / ...
CommitLineData
1/** @file\r
2 The implementation of the Udp4 protocol.\r
3 \r
4Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include "Udp4Impl.h"\r
17\r
18UINT16 mUdp4RandomPort;\r
19\r
20/**\r
21 This function checks and timeouts the I/O datagrams holding by the corresponding\r
22 service context.\r
23\r
24 @param[in] Event The event this function registered to.\r
25 @param[in] Context The context data registered during the creation of\r
26 the Event.\r
27\r
28**/\r
29VOID\r
30EFIAPI\r
31Udp4CheckTimeout (\r
32 IN EFI_EVENT Event,\r
33 IN VOID *Context\r
34 );\r
35\r
36/**\r
37 This function finds the udp instance by the specified <Address, Port> pair.\r
38\r
39 @param[in] InstanceList Pointer to the head of the list linking the udp\r
40 instances.\r
41 @param[in] Address Pointer to the specified IPv4 address.\r
42 @param[in] Port The udp port number.\r
43\r
44 @retval TRUE The specified <Address, Port> pair is found.\r
45 @retval FALSE Otherwise.\r
46\r
47**/\r
48BOOLEAN\r
49Udp4FindInstanceByPort (\r
50 IN LIST_ENTRY *InstanceList,\r
51 IN EFI_IPv4_ADDRESS *Address,\r
52 IN UINT16 Port\r
53 );\r
54\r
55/**\r
56 This function is the packet transmitting notify function registered to the IpIo\r
57 interface. It's called to signal the udp TxToken when IpIo layer completes the\r
58 transmitting of the udp datagram.\r
59\r
60 @param[in] Status The completion status of the output udp datagram.\r
61 @param[in] Context Pointer to the context data.\r
62 @param[in] Sender Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
63 @param[in] NotifyData Pointer to the notify data.\r
64\r
65**/\r
66VOID\r
67EFIAPI\r
68Udp4DgramSent (\r
69 IN EFI_STATUS Status,\r
70 IN VOID *Context,\r
71 IN IP_IO_IP_PROTOCOL Sender,\r
72 IN VOID *NotifyData\r
73 );\r
74\r
75/**\r
76 This function processes the received datagram passed up by the IpIo layer.\r
77\r
78 @param[in] Status The status of this udp datagram.\r
79 @param[in] IcmpError The IcmpError code, only available when Status is\r
80 EFI_ICMP_ERROR.\r
81 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.\r
82 @param[in] Packet Pointer to the NET_BUF containing the received udp\r
83 datagram.\r
84 @param[in] Context Pointer to the context data.\r
85\r
86**/\r
87VOID\r
88EFIAPI\r
89Udp4DgramRcvd (\r
90 IN EFI_STATUS Status,\r
91 IN UINT8 IcmpError,\r
92 IN EFI_NET_SESSION_DATA *NetSession,\r
93 IN NET_BUF *Packet,\r
94 IN VOID *Context\r
95 );\r
96\r
97/**\r
98 This function cancels the token specified by Arg in the Map. This is a callback\r
99 used by Udp4InstanceCancelToken().\r
100\r
101 @param[in] Map Pointer to the NET_MAP.\r
102 @param[in] Item Pointer to the NET_MAP_ITEM.\r
103 @param[in] Arg Pointer to the token to be cancelled, if NULL,\r
104 the token specified by Item is cancelled.\r
105\r
106 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token\r
107 is not the same as that in the Item if Arg is not\r
108 NULL.\r
109 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is\r
110 cancelled.\r
111\r
112**/\r
113EFI_STATUS\r
114EFIAPI\r
115Udp4CancelTokens (\r
116 IN NET_MAP *Map,\r
117 IN NET_MAP_ITEM *Item,\r
118 IN VOID *Arg OPTIONAL\r
119 );\r
120\r
121/**\r
122 This function matches the received udp datagram with the Instance.\r
123\r
124 @param[in] Instance Pointer to the udp instance context data.\r
125 @param[in] Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted\r
126 from the received udp datagram.\r
127\r
128 @retval TRUE The udp datagram matches the receiving requirments of the\r
129 udp Instance.\r
130 @retval FALSE Otherwise.\r
131\r
132**/\r
133BOOLEAN\r
134Udp4MatchDgram (\r
135 IN UDP4_INSTANCE_DATA *Instance,\r
136 IN EFI_UDP4_SESSION_DATA *Udp4Session\r
137 );\r
138\r
139/**\r
140 This function removes the Wrap specified by Context and release relevant resources.\r
141\r
142 @param[in] Event The Event this notify function registered to.\r
143 @param[in] Context Pointer to the context data.\r
144\r
145**/\r
146VOID\r
147EFIAPI\r
148Udp4RecycleRxDataWrap (\r
149 IN EFI_EVENT Event,\r
150 IN VOID *Context\r
151 );\r
152\r
153/**\r
154 This function wraps the Packet and the RxData.\r
155\r
156 @param[in] Instance Pointer to the instance context data.\r
157 @param[in] Packet Pointer to the buffer containing the received\r
158 datagram.\r
159 @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
160 datagram.\r
161\r
162 @return Pointer to the structure wrapping the RxData and the Packet.\r
163\r
164**/\r
165UDP4_RXDATA_WRAP *\r
166Udp4WrapRxData (\r
167 IN UDP4_INSTANCE_DATA *Instance,\r
168 IN NET_BUF *Packet,\r
169 IN EFI_UDP4_RECEIVE_DATA *RxData\r
170 );\r
171\r
172/**\r
173 This function enqueues the received datagram into the instances' receiving queues.\r
174\r
175 @param[in] Udp4Service Pointer to the udp service context data.\r
176 @param[in] Packet Pointer to the buffer containing the received\r
177 datagram.\r
178 @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
179 datagram.\r
180\r
181 @return The times this datagram is enqueued.\r
182\r
183**/\r
184UINTN\r
185Udp4EnqueueDgram (\r
186 IN UDP4_SERVICE_DATA *Udp4Service,\r
187 IN NET_BUF *Packet,\r
188 IN EFI_UDP4_RECEIVE_DATA *RxData\r
189 );\r
190\r
191/**\r
192 This function delivers the datagrams enqueued in the instances.\r
193\r
194 @param[in] Udp4Service Pointer to the udp service context data.\r
195\r
196**/\r
197VOID\r
198Udp4DeliverDgram (\r
199 IN UDP4_SERVICE_DATA *Udp4Service\r
200 );\r
201\r
202/**\r
203 This function demultiplexes the received udp datagram to the appropriate instances.\r
204\r
205 @param[in] Udp4Service Pointer to the udp service context data.\r
206 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from\r
207 the received datagram.\r
208 @param[in] Packet Pointer to the buffer containing the received udp\r
209 datagram.\r
210\r
211**/\r
212VOID\r
213Udp4Demultiplex (\r
214 IN UDP4_SERVICE_DATA *Udp4Service,\r
215 IN EFI_NET_SESSION_DATA *NetSession,\r
216 IN NET_BUF *Packet\r
217 );\r
218\r
219/**\r
220 This function handles the received Icmp Error message and demultiplexes it to the\r
221 instance.\r
222\r
223 @param[in] Udp4Service Pointer to the udp service context data.\r
224 @param[in] IcmpError The icmp error code.\r
225 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted\r
226 from the received Icmp Error packet.\r
227 @param[in] Packet Pointer to the Icmp Error packet.\r
228\r
229**/\r
230VOID\r
231Udp4IcmpHandler (\r
232 IN UDP4_SERVICE_DATA *Udp4Service,\r
233 IN UINT8 IcmpError,\r
234 IN EFI_NET_SESSION_DATA *NetSession,\r
235 IN NET_BUF *Packet\r
236 );\r
237\r
238/**\r
239 This function builds and sends out a icmp port unreachable message.\r
240\r
241 @param[in] IpIo Pointer to the IP_IO instance.\r
242 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet\r
243 causes this icmp error message.\r
244 @param[in] Udp4Header Pointer to the udp header of the datagram causes\r
245 this icmp error message.\r
246\r
247**/\r
248VOID\r
249Udp4SendPortUnreach (\r
250 IN IP_IO *IpIo,\r
251 IN EFI_NET_SESSION_DATA *NetSession,\r
252 IN VOID *Udp4Header\r
253 );\r
254\r
255\r
256/**\r
257 Create the Udp service context data.\r
258\r
259 @param[in, out] Udp4Service Pointer to the UDP4_SERVICE_DATA.\r
260 @param[in] ImageHandle The image handle of this udp4 driver.\r
261 @param[in] ControllerHandle The controller handle this udp4 driver binds on.\r
262\r
263 @retval EFI_SUCCESS The udp4 service context data is created and\r
264 initialized.\r
265 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.\r
266 @retval other Other error occurs.\r
267\r
268**/\r
269EFI_STATUS\r
270Udp4CreateService (\r
271 IN OUT UDP4_SERVICE_DATA *Udp4Service,\r
272 IN EFI_HANDLE ImageHandle,\r
273 IN EFI_HANDLE ControllerHandle\r
274 )\r
275{\r
276 EFI_STATUS Status;\r
277 IP_IO_OPEN_DATA OpenData;\r
278 EFI_IP4_CONFIG_DATA *Ip4ConfigData;\r
279\r
280 ZeroMem (Udp4Service, sizeof (UDP4_SERVICE_DATA));\r
281\r
282 Udp4Service->Signature = UDP4_SERVICE_DATA_SIGNATURE;\r
283 Udp4Service->ServiceBinding = mUdp4ServiceBinding;\r
284 Udp4Service->ImageHandle = ImageHandle;\r
285 Udp4Service->ControllerHandle = ControllerHandle;\r
286 Udp4Service->ChildrenNumber = 0;\r
287\r
288 InitializeListHead (&Udp4Service->ChildrenList);\r
289\r
290 //\r
291 // Create the IpIo for this service context.\r
292 //\r
293 Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle, IP_VERSION_4);\r
294 if (Udp4Service->IpIo == NULL) {\r
295 return EFI_OUT_OF_RESOURCES;\r
296 }\r
297\r
298 //\r
299 // Set the OpenData used to open the IpIo.\r
300 //\r
301 Ip4ConfigData = &OpenData.IpConfigData.Ip4CfgData;\r
302 CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
303 Ip4ConfigData->AcceptBroadcast = TRUE;\r
304 OpenData.RcvdContext = (VOID *) Udp4Service;\r
305 OpenData.SndContext = NULL;\r
306 OpenData.PktRcvdNotify = Udp4DgramRcvd;\r
307 OpenData.PktSentNotify = Udp4DgramSent;\r
308\r
309 //\r
310 // Configure and start the IpIo.\r
311 //\r
312 Status = IpIoOpen (Udp4Service->IpIo, &OpenData);\r
313 if (EFI_ERROR (Status)) {\r
314 goto ON_ERROR;\r
315 }\r
316\r
317 //\r
318 // Create the event for Udp timeout checking.\r
319 //\r
320 Status = gBS->CreateEvent (\r
321 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
322 TPL_CALLBACK,\r
323 Udp4CheckTimeout,\r
324 Udp4Service,\r
325 &Udp4Service->TimeoutEvent\r
326 );\r
327 if (EFI_ERROR (Status)) {\r
328 goto ON_ERROR;\r
329 }\r
330\r
331 //\r
332 // Start the timeout timer event.\r
333 //\r
334 Status = gBS->SetTimer (\r
335 Udp4Service->TimeoutEvent,\r
336 TimerPeriodic,\r
337 UDP4_TIMEOUT_INTERVAL\r
338 );\r
339 if (EFI_ERROR (Status)) {\r
340 goto ON_ERROR;\r
341 }\r
342\r
343 return EFI_SUCCESS;\r
344\r
345ON_ERROR:\r
346\r
347 if (Udp4Service->TimeoutEvent != NULL) {\r
348 gBS->CloseEvent (Udp4Service->TimeoutEvent);\r
349 }\r
350\r
351 IpIoDestroy (Udp4Service->IpIo);\r
352\r
353 return Status;\r
354}\r
355\r
356\r
357/**\r
358 Clean the Udp service context data.\r
359\r
360 @param[in] Udp4Service Pointer to the UDP4_SERVICE_DATA.\r
361\r
362**/\r
363VOID\r
364Udp4CleanService (\r
365 IN UDP4_SERVICE_DATA *Udp4Service\r
366 )\r
367{\r
368 //\r
369 // Cancel the TimeoutEvent timer.\r
370 //\r
371 gBS->SetTimer (Udp4Service->TimeoutEvent, TimerCancel, 0);\r
372\r
373 //\r
374 // Close the TimeoutEvent timer.\r
375 //\r
376 gBS->CloseEvent (Udp4Service->TimeoutEvent);\r
377\r
378 //\r
379 // Destroy the IpIo.\r
380 //\r
381 IpIoDestroy (Udp4Service->IpIo);\r
382}\r
383\r
384\r
385/**\r
386 This function checks and timeouts the I/O datagrams holding by the corresponding\r
387 service context.\r
388\r
389 @param[in] Event The event this function registered to.\r
390 @param[in] Context The context data registered during the creation of\r
391 the Event.\r
392\r
393**/\r
394VOID\r
395EFIAPI\r
396Udp4CheckTimeout (\r
397 IN EFI_EVENT Event,\r
398 IN VOID *Context\r
399 )\r
400{\r
401 UDP4_SERVICE_DATA *Udp4Service;\r
402 LIST_ENTRY *Entry;\r
403 UDP4_INSTANCE_DATA *Instance;\r
404 LIST_ENTRY *WrapEntry;\r
405 LIST_ENTRY *NextEntry;\r
406 UDP4_RXDATA_WRAP *Wrap;\r
407\r
408 Udp4Service = (UDP4_SERVICE_DATA *) Context;\r
409 NET_CHECK_SIGNATURE (Udp4Service, UDP4_SERVICE_DATA_SIGNATURE);\r
410\r
411 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
412 //\r
413 // Iterate all the instances belonging to this service context.\r
414 //\r
415 Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
416 NET_CHECK_SIGNATURE (Instance, UDP4_INSTANCE_DATA_SIGNATURE);\r
417\r
418 if (!Instance->Configured || (Instance->ConfigData.ReceiveTimeout == 0)) {\r
419 //\r
420 // Skip this instance if it's not configured or no receive timeout.\r
421 //\r
422 continue;\r
423 }\r
424\r
425 NET_LIST_FOR_EACH_SAFE (WrapEntry, NextEntry, &Instance->RcvdDgramQue) {\r
426 //\r
427 // Iterate all the rxdatas belonging to this udp instance.\r
428 //\r
429 Wrap = NET_LIST_USER_STRUCT (WrapEntry, UDP4_RXDATA_WRAP, Link);\r
430\r
431 //\r
432 // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
433 //\r
434 if (Wrap->TimeoutTick < (UDP4_TIMEOUT_INTERVAL / 10)) {\r
435 //\r
436 // Remove this RxData if it timeouts.\r
437 //\r
438 Udp4RecycleRxDataWrap (NULL, (VOID *) Wrap);\r
439 } else {\r
440 Wrap->TimeoutTick -= (UDP4_TIMEOUT_INTERVAL / 10);\r
441 }\r
442 }\r
443 }\r
444}\r
445\r
446\r
447/**\r
448 This function intializes the new created udp instance.\r
449\r
450 @param[in] Udp4Service Pointer to the UDP4_SERVICE_DATA.\r
451 @param[in, out] Instance Pointer to the un-initialized UDP4_INSTANCE_DATA.\r
452\r
453**/\r
454VOID\r
455Udp4InitInstance (\r
456 IN UDP4_SERVICE_DATA *Udp4Service,\r
457 IN OUT UDP4_INSTANCE_DATA *Instance\r
458 )\r
459{\r
460 //\r
461 // Set the signature.\r
462 //\r
463 Instance->Signature = UDP4_INSTANCE_DATA_SIGNATURE;\r
464\r
465 //\r
466 // Init the lists.\r
467 //\r
468 InitializeListHead (&Instance->Link);\r
469 InitializeListHead (&Instance->RcvdDgramQue);\r
470 InitializeListHead (&Instance->DeliveredDgramQue);\r
471\r
472 //\r
473 // Init the NET_MAPs.\r
474 //\r
475 NetMapInit (&Instance->TxTokens);\r
476 NetMapInit (&Instance->RxTokens);\r
477 NetMapInit (&Instance->McastIps);\r
478\r
479 //\r
480 // Save the pointer to the UDP4_SERVICE_DATA, and initialize other members.\r
481 //\r
482 Instance->Udp4Service = Udp4Service;\r
483 CopyMem (&Instance->Udp4Proto, &mUdp4Protocol, sizeof (Instance->Udp4Proto));\r
484 Instance->IcmpError = EFI_SUCCESS;\r
485 Instance->Configured = FALSE;\r
486 Instance->IsNoMapping = FALSE;\r
487 Instance->InDestroy = FALSE;\r
488}\r
489\r
490\r
491/**\r
492 This function cleans the udp instance.\r
493\r
494 @param[in] Instance Pointer to the UDP4_INSTANCE_DATA to clean.\r
495\r
496**/\r
497VOID\r
498Udp4CleanInstance (\r
499 IN UDP4_INSTANCE_DATA *Instance\r
500 )\r
501{\r
502 NetMapClean (&Instance->McastIps);\r
503 NetMapClean (&Instance->RxTokens);\r
504 NetMapClean (&Instance->TxTokens);\r
505}\r
506\r
507\r
508/**\r
509 This function finds the udp instance by the specified <Address, Port> pair.\r
510\r
511 @param[in] InstanceList Pointer to the head of the list linking the udp\r
512 instances.\r
513 @param[in] Address Pointer to the specified IPv4 address.\r
514 @param[in] Port The udp port number.\r
515\r
516 @retval TRUE The specified <Address, Port> pair is found.\r
517 @retval FALSE Otherwise.\r
518\r
519**/\r
520BOOLEAN\r
521Udp4FindInstanceByPort (\r
522 IN LIST_ENTRY *InstanceList,\r
523 IN EFI_IPv4_ADDRESS *Address,\r
524 IN UINT16 Port\r
525 )\r
526{\r
527 LIST_ENTRY *Entry;\r
528 UDP4_INSTANCE_DATA *Instance;\r
529 EFI_UDP4_CONFIG_DATA *ConfigData;\r
530\r
531 NET_LIST_FOR_EACH (Entry, InstanceList) {\r
532 //\r
533 // Iterate all the udp instances.\r
534 //\r
535 Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
536 ConfigData = &Instance->ConfigData;\r
537\r
538 if (!Instance->Configured || ConfigData->AcceptAnyPort) {\r
539 //\r
540 // If the instance is not configured or the configdata of the instance indicates\r
541 // this instance accepts any port, skip it.\r
542 //\r
543 continue;\r
544 }\r
545\r
546 if (EFI_IP4_EQUAL (&ConfigData->StationAddress, Address) &&\r
547 (ConfigData->StationPort == Port)) {\r
548 //\r
549 // if both the address and the port are the same, return TRUE.\r
550 //\r
551 return TRUE;\r
552 }\r
553 }\r
554\r
555 //\r
556 // return FALSE when matching fails.\r
557 //\r
558 return FALSE;\r
559}\r
560\r
561\r
562/**\r
563 This function tries to bind the udp instance according to the configured port\r
564 allocation strategy.\r
565\r
566 @param[in] InstanceList Pointer to the head of the list linking the udp\r
567 instances.\r
568 @param[in, out] ConfigData Pointer to the ConfigData of the instance to be\r
569 bound. ConfigData->StationPort will be assigned\r
570 with an available port value on success.\r
571\r
572 @retval EFI_SUCCESS The bound operation is completed successfully.\r
573 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is\r
574 already used by other instance.\r
575 @retval EFI_OUT_OF_RESOURCES No available port resources.\r
576\r
577**/\r
578EFI_STATUS\r
579Udp4Bind (\r
580 IN LIST_ENTRY *InstanceList,\r
581 IN OUT EFI_UDP4_CONFIG_DATA *ConfigData\r
582 )\r
583{\r
584 EFI_IPv4_ADDRESS *StationAddress;\r
585 UINT16 StartPort;\r
586\r
587 if (ConfigData->AcceptAnyPort) {\r
588 return EFI_SUCCESS;\r
589 }\r
590\r
591 StationAddress = &ConfigData->StationAddress;\r
592\r
593 if (ConfigData->StationPort != 0) {\r
594\r
595 if (!ConfigData->AllowDuplicatePort &&\r
596 Udp4FindInstanceByPort (InstanceList, StationAddress, ConfigData->StationPort)) {\r
597 //\r
598 // Do not allow duplicate port and the port is already used by other instance.\r
599 //\r
600 return EFI_ACCESS_DENIED;\r
601 }\r
602 } else {\r
603 //\r
604 // select a random port for this instance;\r
605 //\r
606\r
607 if (ConfigData->AllowDuplicatePort) {\r
608 //\r
609 // Just pick up the random port if the instance allows duplicate port.\r
610 //\r
611 ConfigData->StationPort = mUdp4RandomPort;\r
612 } else {\r
613\r
614 StartPort = mUdp4RandomPort;\r
615\r
616 while (Udp4FindInstanceByPort(InstanceList, StationAddress, mUdp4RandomPort)) {\r
617\r
618 mUdp4RandomPort++;\r
619 if (mUdp4RandomPort == 0) {\r
620 mUdp4RandomPort = UDP4_PORT_KNOWN;\r
621 }\r
622\r
623 if (mUdp4RandomPort == StartPort) {\r
624 //\r
625 // No available port.\r
626 //\r
627 return EFI_OUT_OF_RESOURCES;\r
628 }\r
629 }\r
630\r
631 ConfigData->StationPort = mUdp4RandomPort;\r
632 }\r
633\r
634 mUdp4RandomPort++;\r
635 if (mUdp4RandomPort == 0) {\r
636 mUdp4RandomPort = UDP4_PORT_KNOWN;\r
637 }\r
638 }\r
639\r
640 return EFI_SUCCESS;\r
641}\r
642\r
643\r
644/**\r
645 This function is used to check whether the NewConfigData has any un-reconfigurable\r
646 parameters changed compared to the OldConfigData.\r
647\r
648 @param[in] OldConfigData Pointer to the current ConfigData the udp instance\r
649 uses.\r
650 @param[in] NewConfigData Pointer to the new ConfigData.\r
651\r
652 @retval TRUE The instance is reconfigurable.\r
653 @retval FALSE Otherwise.\r
654\r
655**/\r
656BOOLEAN\r
657Udp4IsReconfigurable (\r
658 IN EFI_UDP4_CONFIG_DATA *OldConfigData,\r
659 IN EFI_UDP4_CONFIG_DATA *NewConfigData\r
660 )\r
661{\r
662 if ((NewConfigData->AcceptAnyPort != OldConfigData->AcceptAnyPort) ||\r
663 (NewConfigData->AcceptBroadcast != OldConfigData->AcceptBroadcast) ||\r
664 (NewConfigData->AcceptPromiscuous != OldConfigData->AcceptPromiscuous) ||\r
665 (NewConfigData->AllowDuplicatePort != OldConfigData->AllowDuplicatePort)\r
666 ) {\r
667 //\r
668 // The receiving filter parameters cannot be changed.\r
669 //\r
670 return FALSE;\r
671 }\r
672\r
673 if ((!NewConfigData->AcceptAnyPort) &&\r
674 (NewConfigData->StationPort != OldConfigData->StationPort)\r
675 ) {\r
676 //\r
677 // The port is not changeable.\r
678 //\r
679 return FALSE;\r
680 }\r
681\r
682 if (!NewConfigData->AcceptPromiscuous) {\r
683\r
684 if (NewConfigData->UseDefaultAddress != OldConfigData->UseDefaultAddress) {\r
685 //\r
686 // The NewConfigData differs to the old one on the UseDefaultAddress.\r
687 //\r
688 return FALSE;\r
689 }\r
690\r
691 if (!NewConfigData->UseDefaultAddress &&\r
692 (!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) ||\r
693 !EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask))\r
694 ) {\r
695 //\r
696 // If the instance doesn't use the default address, and the new address or\r
697 // new subnet mask is different from the old values.\r
698 //\r
699 return FALSE;\r
700 }\r
701 }\r
702\r
703 if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &OldConfigData->RemoteAddress)) {\r
704 //\r
705 // The remoteaddress is not the same.\r
706 //\r
707 return FALSE;\r
708 }\r
709\r
710 if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) &&\r
711 NewConfigData->RemotePort != OldConfigData->RemotePort\r
712 ) {\r
713 //\r
714 // The RemotePort differs if it's designated in the configdata.\r
715 //\r
716 return FALSE;\r
717 }\r
718\r
719 //\r
720 // All checks pass, return TRUE.\r
721 //\r
722 return TRUE;\r
723}\r
724\r
725\r
726/**\r
727 This function builds the Ip4 configdata from the Udp4ConfigData.\r
728\r
729 @param[in] Udp4ConfigData Pointer to the EFI_UDP4_CONFIG_DATA.\r
730 @param[in, out] Ip4ConfigData Pointer to the EFI_IP4_CONFIG_DATA.\r
731\r
732**/\r
733VOID\r
734Udp4BuildIp4ConfigData (\r
735 IN EFI_UDP4_CONFIG_DATA *Udp4ConfigData,\r
736 IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData\r
737 )\r
738{\r
739 CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (*Ip4ConfigData));\r
740\r
741 Ip4ConfigData->DefaultProtocol = EFI_IP_PROTO_UDP;\r
742 Ip4ConfigData->AcceptBroadcast = Udp4ConfigData->AcceptBroadcast;\r
743 Ip4ConfigData->AcceptPromiscuous = Udp4ConfigData->AcceptPromiscuous;\r
744 Ip4ConfigData->UseDefaultAddress = Udp4ConfigData->UseDefaultAddress;\r
745 CopyMem (&Ip4ConfigData->StationAddress, &Udp4ConfigData->StationAddress, sizeof (EFI_IPv4_ADDRESS));\r
746 CopyMem (&Ip4ConfigData->SubnetMask, &Udp4ConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
747\r
748 //\r
749 // use the -1 magic number to disable the receiving process of the ip instance.\r
750 //\r
751 Ip4ConfigData->ReceiveTimeout = (UINT32) (-1);\r
752}\r
753\r
754\r
755/**\r
756 This function validates the TxToken, it returns the error code according to the spec.\r
757\r
758 @param[in] Instance Pointer to the udp instance context data.\r
759 @param[in] TxToken Pointer to the token to be checked.\r
760\r
761 @retval EFI_SUCCESS The TxToken is valid.\r
762 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE: This is\r
763 NULL. Token is NULL. Token.Event is NULL.\r
764 Token.Packet.TxData is NULL.\r
765 Token.Packet.TxData.FragmentCount is zero.\r
766 Token.Packet.TxData.DataLength is not equal to the\r
767 sum of fragment lengths. One or more of the\r
768 Token.Packet.TxData.FragmentTable[].\r
769 FragmentLength fields is zero. One or more of the\r
770 Token.Packet.TxData.FragmentTable[].\r
771 FragmentBuffer fields is NULL.\r
772 Token.Packet.TxData. GatewayAddress is not a\r
773 unicast IPv4 address if it is not NULL. One or\r
774 more IPv4 addresses in Token.Packet.TxData.\r
775 UdpSessionData are not valid unicast IPv4\r
776 addresses if the UdpSessionData is not NULL.\r
777 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP\r
778 packet size.\r
779\r
780**/\r
781EFI_STATUS\r
782Udp4ValidateTxToken (\r
783 IN UDP4_INSTANCE_DATA *Instance,\r
784 IN EFI_UDP4_COMPLETION_TOKEN *TxToken\r
785 )\r
786{\r
787 EFI_UDP4_TRANSMIT_DATA *TxData;\r
788 UINT32 Index;\r
789 UINT32 TotalLen;\r
790 EFI_UDP4_CONFIG_DATA *ConfigData;\r
791 EFI_UDP4_SESSION_DATA *UdpSessionData;\r
792 IP4_ADDR SourceAddress;\r
793 IP4_ADDR GatewayAddress;\r
794\r
795 if (TxToken->Event == NULL) {\r
796 return EFI_INVALID_PARAMETER;\r
797 }\r
798\r
799 TxData = TxToken->Packet.TxData;\r
800\r
801 if ((TxData == NULL) || (TxData->FragmentCount == 0)) {\r
802 return EFI_INVALID_PARAMETER;\r
803 }\r
804\r
805 TotalLen = 0;\r
806 for (Index = 0; Index < TxData->FragmentCount; Index++) {\r
807\r
808 if ((TxData->FragmentTable[Index].FragmentBuffer == NULL) ||\r
809 (TxData->FragmentTable[Index].FragmentLength == 0)) {\r
810 //\r
811 // if the FragmentBuffer is NULL or the FragmentLeng is zero.\r
812 //\r
813 return EFI_INVALID_PARAMETER;\r
814 }\r
815\r
816 TotalLen += TxData->FragmentTable[Index].FragmentLength;\r
817 }\r
818\r
819 if (TotalLen != TxData->DataLength) {\r
820 //\r
821 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the\r
822 // DataLength.\r
823 //\r
824 return EFI_INVALID_PARAMETER;\r
825 }\r
826\r
827 if (TxData->GatewayAddress != NULL) {\r
828 CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR));\r
829\r
830 if (!Instance->ConfigData.UseDefaultAddress &&\r
831 (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
832 !NetIp4IsUnicast (NTOHL (GatewayAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\r
833 //\r
834 // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.\r
835 //\r
836 return EFI_INVALID_PARAMETER;\r
837 }\r
838 }\r
839\r
840 ConfigData = &Instance->ConfigData;\r
841 UdpSessionData = TxData->UdpSessionData;\r
842\r
843 if (UdpSessionData != NULL) {\r
844\r
845 CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR));\r
846\r
847 if ((SourceAddress != 0) && \r
848 !Instance->ConfigData.UseDefaultAddress &&\r
849 (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
850 !NetIp4IsUnicast (HTONL (SourceAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\r
851 //\r
852 // Check whether SourceAddress is a valid IPv4 address in case it's not zero.\r
853 // The configured station address is used if SourceAddress is zero.\r
854 //\r
855 return EFI_INVALID_PARAMETER;\r
856 }\r
857\r
858 if ((UdpSessionData->DestinationPort == 0) && (ConfigData->RemotePort == 0)) {\r
859 //\r
860 // Ambiguous, no avalaible DestinationPort for this token.\r
861 //\r
862 return EFI_INVALID_PARAMETER;\r
863 }\r
864\r
865 if (EFI_IP4_EQUAL (&UdpSessionData->DestinationAddress, &mZeroIp4Addr)) {\r
866 //\r
867 // The DestinationAddress specified in the UdpSessionData is 0.\r
868 //\r
869 return EFI_INVALID_PARAMETER;\r
870 }\r
871 } else if (EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr)) {\r
872 //\r
873 // the configured RemoteAddress is all zero, and the user doens't override the\r
874 // destination address.\r
875 //\r
876 return EFI_INVALID_PARAMETER;\r
877 }\r
878\r
879 if (TxData->DataLength > UDP4_MAX_DATA_SIZE) {\r
880 return EFI_BAD_BUFFER_SIZE;\r
881 }\r
882\r
883 return EFI_SUCCESS;\r
884}\r
885\r
886\r
887/**\r
888 This function checks whether the specified Token duplicates with the one in the Map.\r
889\r
890 @param[in] Map Pointer to the NET_MAP.\r
891 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to\r
892 the Token.\r
893 @param[in] Context Pointer to the Token to be checked.\r
894\r
895 @retval EFI_SUCCESS The Token specified by Context differs from the\r
896 one in the Item.\r
897 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.\r
898\r
899**/\r
900EFI_STATUS\r
901EFIAPI\r
902Udp4TokenExist (\r
903 IN NET_MAP *Map,\r
904 IN NET_MAP_ITEM *Item,\r
905 IN VOID *Context\r
906 )\r
907{\r
908 EFI_UDP4_COMPLETION_TOKEN *Token;\r
909 EFI_UDP4_COMPLETION_TOKEN *TokenInItem;\r
910\r
911 Token = (EFI_UDP4_COMPLETION_TOKEN*) Context;\r
912 TokenInItem = (EFI_UDP4_COMPLETION_TOKEN*) Item->Key;\r
913\r
914 if ((Token == TokenInItem) || (Token->Event == TokenInItem->Event)) {\r
915 //\r
916 // The Token duplicates with the TokenInItem in case either the two pointers are the\r
917 // same or the Events of these two tokens are the same.\r
918 //\r
919 return EFI_ACCESS_DENIED;\r
920 }\r
921\r
922 return EFI_SUCCESS;\r
923}\r
924\r
925\r
926/**\r
927 This function calculates the checksum for the Packet, utilizing the pre-calculated\r
928 pseudo HeadSum to reduce some overhead.\r
929\r
930 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.\r
931 @param[in] HeadSum Checksum of the pseudo header execpt the length\r
932 field.\r
933\r
934 @retval The 16-bit checksum of this udp datagram.\r
935\r
936**/\r
937UINT16\r
938Udp4Checksum (\r
939 IN NET_BUF *Packet,\r
940 IN UINT16 HeadSum\r
941 )\r
942{\r
943 UINT16 Checksum;\r
944\r
945 Checksum = NetbufChecksum (Packet);\r
946 Checksum = NetAddChecksum (Checksum, HeadSum);\r
947\r
948 Checksum = NetAddChecksum (Checksum, HTONS ((UINT16) Packet->TotalSize));\r
949\r
950 return (UINT16) ~Checksum;\r
951}\r
952\r
953\r
954/**\r
955 This function removes the specified Token from the TokenMap.\r
956\r
957 @param[in, out] TokenMap Pointer to the NET_MAP containing the tokens.\r
958 @param[in] Token Pointer to the Token to be removed.\r
959\r
960 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.\r
961 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.\r
962\r
963**/\r
964EFI_STATUS\r
965Udp4RemoveToken (\r
966 IN OUT NET_MAP *TokenMap,\r
967 IN EFI_UDP4_COMPLETION_TOKEN *Token\r
968 )\r
969{\r
970 NET_MAP_ITEM *Item;\r
971\r
972 //\r
973 // Find the Token first.\r
974 //\r
975 Item = NetMapFindKey (TokenMap, (VOID *) Token);\r
976\r
977 if (Item != NULL) {\r
978 //\r
979 // Remove the token if it's found in the map.\r
980 //\r
981 NetMapRemoveItem (TokenMap, Item, NULL);\r
982\r
983 return EFI_SUCCESS;\r
984 }\r
985\r
986 return EFI_NOT_FOUND;\r
987}\r
988\r
989\r
990/**\r
991 This function is the packet transmitting notify function registered to the IpIo\r
992 interface. It's called to signal the udp TxToken when IpIo layer completes the\r
993 transmitting of the udp datagram.\r
994\r
995 @param[in] Status The completion status of the output udp datagram.\r
996 @param[in] Context Pointer to the context data.\r
997 @param[in] Sender Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
998 @param[in] NotifyData Pointer to the notify data.\r
999\r
1000**/\r
1001VOID\r
1002EFIAPI\r
1003Udp4DgramSent (\r
1004 IN EFI_STATUS Status,\r
1005 IN VOID *Context,\r
1006 IN IP_IO_IP_PROTOCOL Sender,\r
1007 IN VOID *NotifyData\r
1008 )\r
1009{\r
1010 UDP4_INSTANCE_DATA *Instance;\r
1011 EFI_UDP4_COMPLETION_TOKEN *Token;\r
1012\r
1013 Instance = (UDP4_INSTANCE_DATA *) Context;\r
1014 Token = (EFI_UDP4_COMPLETION_TOKEN *) NotifyData;\r
1015\r
1016 if (Udp4RemoveToken (&Instance->TxTokens, Token) == EFI_SUCCESS) {\r
1017 //\r
1018 // The token may be cancelled. Only signal it if the remove operation succeeds.\r
1019 //\r
1020 Token->Status = Status;\r
1021 gBS->SignalEvent (Token->Event);\r
1022 DispatchDpc ();\r
1023 }\r
1024}\r
1025\r
1026\r
1027/**\r
1028 This function processes the received datagram passed up by the IpIo layer.\r
1029\r
1030 @param[in] Status The status of this udp datagram.\r
1031 @param[in] IcmpError The IcmpError code, only available when Status is\r
1032 EFI_ICMP_ERROR.\r
1033 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.\r
1034 @param[in] Packet Pointer to the NET_BUF containing the received udp\r
1035 datagram.\r
1036 @param[in] Context Pointer to the context data.\r
1037\r
1038**/\r
1039VOID\r
1040EFIAPI\r
1041Udp4DgramRcvd (\r
1042 IN EFI_STATUS Status,\r
1043 IN UINT8 IcmpError,\r
1044 IN EFI_NET_SESSION_DATA *NetSession,\r
1045 IN NET_BUF *Packet,\r
1046 IN VOID *Context\r
1047 )\r
1048{\r
1049 NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE);\r
1050\r
1051 //\r
1052 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.\r
1053 //\r
1054 if (Status == EFI_SUCCESS) {\r
1055 //\r
1056 // Demultiplex the received datagram.\r
1057 //\r
1058 Udp4Demultiplex ((UDP4_SERVICE_DATA *) Context, NetSession, Packet);\r
1059 } else {\r
1060 //\r
1061 // Handle the ICMP_ERROR packet.\r
1062 //\r
1063 Udp4IcmpHandler ((UDP4_SERVICE_DATA *) Context, IcmpError, NetSession, Packet);\r
1064 }\r
1065\r
1066 //\r
1067 // Dispatch the DPC queued by the NotifyFunction of the rx token's events\r
1068 // which are signaled with received data.\r
1069 //\r
1070 DispatchDpc ();\r
1071}\r
1072\r
1073\r
1074/**\r
1075 This function removes the multicast group specified by Arg from the Map.\r
1076\r
1077 @param[in, out] Map Pointer to the NET_MAP.\r
1078 @param[in] Item Pointer to the NET_MAP_ITEM.\r
1079 @param[in] Arg Pointer to the Arg, it's the pointer to a\r
1080 multicast IPv4 Address.\r
1081\r
1082 @retval EFI_SUCCESS The multicast address is removed.\r
1083 @retval EFI_ABORTED The specified multicast address is removed and the\r
1084 Arg is not NULL.\r
1085\r
1086**/\r
1087EFI_STATUS\r
1088EFIAPI\r
1089Udp4LeaveGroup (\r
1090 IN OUT NET_MAP *Map,\r
1091 IN NET_MAP_ITEM *Item,\r
1092 IN VOID *Arg OPTIONAL\r
1093 )\r
1094{\r
1095 EFI_IPv4_ADDRESS *McastIp;\r
1096\r
1097 McastIp = Arg;\r
1098\r
1099 if ((McastIp != NULL) && (!EFI_IP4_EQUAL (McastIp, &(Item->Key)))) {\r
1100 //\r
1101 // McastIp is not NULL and the multicast address contained in the Item\r
1102 // is not the same as McastIp.\r
1103 //\r
1104 return EFI_SUCCESS;\r
1105 }\r
1106\r
1107 //\r
1108 // Remove this Item.\r
1109 //\r
1110 NetMapRemoveItem (Map, Item, NULL);\r
1111\r
1112 if (McastIp != NULL) {\r
1113 //\r
1114 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.\r
1115 //\r
1116 return EFI_ABORTED;\r
1117 }\r
1118\r
1119 return EFI_SUCCESS;\r
1120}\r
1121\r
1122\r
1123/**\r
1124 This function cancels the token specified by Arg in the Map. This is a callback\r
1125 used by Udp4InstanceCancelToken().\r
1126\r
1127 @param[in] Map Pointer to the NET_MAP.\r
1128 @param[in] Item Pointer to the NET_MAP_ITEM.\r
1129 @param[in] Arg Pointer to the token to be cancelled, if NULL,\r
1130 the token specified by Item is cancelled.\r
1131\r
1132 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token\r
1133 is not the same as that in the Item if Arg is not\r
1134 NULL.\r
1135 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is\r
1136 cancelled.\r
1137\r
1138**/\r
1139EFI_STATUS\r
1140EFIAPI\r
1141Udp4CancelTokens (\r
1142 IN NET_MAP *Map,\r
1143 IN NET_MAP_ITEM *Item,\r
1144 IN VOID *Arg OPTIONAL\r
1145 )\r
1146{\r
1147 EFI_UDP4_COMPLETION_TOKEN *TokenToCancel;\r
1148 NET_BUF *Packet;\r
1149 IP_IO *IpIo;\r
1150\r
1151 if ((Arg != NULL) && (Item->Key != Arg)) {\r
1152 return EFI_SUCCESS;\r
1153 }\r
1154\r
1155 if (Item->Value != NULL) {\r
1156 //\r
1157 // If the token is a transmit token, the corresponding Packet is recorded in\r
1158 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken\r
1159 // will invoke Udp4DgramSent, the token will be signaled and this Item will\r
1160 // be removed from the Map there.\r
1161 //\r
1162 Packet = (NET_BUF *) (Item->Value);\r
1163 IpIo = (IP_IO *) (*((UINTN *) &Packet->ProtoData[0]));\r
1164\r
1165 IpIoCancelTxToken (IpIo, Packet);\r
1166 } else {\r
1167 //\r
1168 // The token is a receive token. Abort it and remove it from the Map.\r
1169 //\r
1170 TokenToCancel = (EFI_UDP4_COMPLETION_TOKEN *) Item->Key;\r
1171 NetMapRemoveItem (Map, Item, NULL);\r
1172\r
1173 TokenToCancel->Status = EFI_ABORTED;\r
1174 gBS->SignalEvent (TokenToCancel->Event);\r
1175 }\r
1176\r
1177 if (Arg != NULL) {\r
1178 return EFI_ABORTED;\r
1179 }\r
1180\r
1181 return EFI_SUCCESS;\r
1182}\r
1183\r
1184\r
1185/**\r
1186 This function removes all the Wrap datas in the RcvdDgramQue.\r
1187\r
1188 @param[in] Instance Pointer to the udp instance context data.\r
1189\r
1190**/\r
1191VOID\r
1192Udp4FlushRcvdDgram (\r
1193 IN UDP4_INSTANCE_DATA *Instance\r
1194 )\r
1195{\r
1196 UDP4_RXDATA_WRAP *Wrap;\r
1197\r
1198 while (!IsListEmpty (&Instance->RcvdDgramQue)) {\r
1199 //\r
1200 // Iterate all the Wraps in the RcvdDgramQue.\r
1201 //\r
1202 Wrap = NET_LIST_HEAD (&Instance->RcvdDgramQue, UDP4_RXDATA_WRAP, Link);\r
1203\r
1204 //\r
1205 // The Wrap will be removed from the RcvdDgramQue by this function call.\r
1206 //\r
1207 Udp4RecycleRxDataWrap (NULL, (VOID *) Wrap);\r
1208 }\r
1209}\r
1210\r
1211\r
1212\r
1213/**\r
1214 Cancel Udp4 tokens from the Udp4 instance.\r
1215\r
1216 @param[in] Instance Pointer to the udp instance context data.\r
1217 @param[in] Token Pointer to the token to be canceled, if NULL, all\r
1218 tokens in this instance will be cancelled.\r
1219\r
1220 @retval EFI_SUCCESS The Token is cancelled.\r
1221 @retval EFI_NOT_FOUND The Token is not found.\r
1222\r
1223**/\r
1224EFI_STATUS\r
1225Udp4InstanceCancelToken (\r
1226 IN UDP4_INSTANCE_DATA *Instance,\r
1227 IN EFI_UDP4_COMPLETION_TOKEN *Token OPTIONAL\r
1228 )\r
1229{\r
1230 EFI_STATUS Status;\r
1231\r
1232 //\r
1233 // Cancel this token from the TxTokens map.\r
1234 //\r
1235 Status = NetMapIterate (&Instance->TxTokens, Udp4CancelTokens, Token);\r
1236\r
1237 if ((Token != NULL) && (Status == EFI_ABORTED)) {\r
1238 //\r
1239 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from\r
1240 // the TxTokens, just return success.\r
1241 //\r
1242 return EFI_SUCCESS;\r
1243 }\r
1244\r
1245 //\r
1246 // Try to cancel this token from the RxTokens map in condition either the Token\r
1247 // is NULL or the specified Token is not in TxTokens.\r
1248 //\r
1249 Status = NetMapIterate (&Instance->RxTokens, Udp4CancelTokens, Token);\r
1250\r
1251 if ((Token != NULL) && (Status == EFI_SUCCESS)) {\r
1252 //\r
1253 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the\r
1254 // TxTokens nor the RxTokens, or say, it's not found.\r
1255 //\r
1256 return EFI_NOT_FOUND;\r
1257 }\r
1258\r
1259 ASSERT ((Token != NULL) || ((0 == NetMapGetCount (&Instance->TxTokens))\r
1260 && (0 == NetMapGetCount (&Instance->RxTokens))));\r
1261\r
1262 return EFI_SUCCESS;\r
1263}\r
1264\r
1265\r
1266/**\r
1267 This function matches the received udp datagram with the Instance.\r
1268\r
1269 @param[in] Instance Pointer to the udp instance context data.\r
1270 @param[in] Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted\r
1271 from the received udp datagram.\r
1272\r
1273 @retval TRUE The udp datagram matches the receiving requirments of the\r
1274 udp Instance.\r
1275 @retval FALSE Otherwise.\r
1276\r
1277**/\r
1278BOOLEAN\r
1279Udp4MatchDgram (\r
1280 IN UDP4_INSTANCE_DATA *Instance,\r
1281 IN EFI_UDP4_SESSION_DATA *Udp4Session\r
1282 )\r
1283{\r
1284 EFI_UDP4_CONFIG_DATA *ConfigData;\r
1285 IP4_ADDR Destination;\r
1286\r
1287 ConfigData = &Instance->ConfigData;\r
1288\r
1289 if (ConfigData->AcceptPromiscuous) {\r
1290 //\r
1291 // Always matches if this instance is in the promiscuous state.\r
1292 //\r
1293 return TRUE;\r
1294 }\r
1295\r
1296 if ((!ConfigData->AcceptAnyPort && (Udp4Session->DestinationPort != ConfigData->StationPort)) ||\r
1297 ((ConfigData->RemotePort != 0) && (Udp4Session->SourcePort != ConfigData->RemotePort))\r
1298 ) {\r
1299 //\r
1300 // The local port or the remote port doesn't match.\r
1301 //\r
1302 return FALSE;\r
1303 }\r
1304\r
1305 if (!EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr) &&\r
1306 !EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress)\r
1307 ) {\r
1308 //\r
1309 // This datagram doesn't come from the instance's specified sender.\r
1310 //\r
1311 return FALSE;\r
1312 }\r
1313\r
1314 if (EFI_IP4_EQUAL (&ConfigData->StationAddress, &mZeroIp4Addr) ||\r
1315 EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress)\r
1316 ) {\r
1317 //\r
1318 // The instance is configured to receive datagrams destined to any station IP or\r
1319 // the destination address of this datagram matches the configured station IP.\r
1320 //\r
1321 return TRUE;\r
1322 }\r
1323\r
1324 CopyMem (&Destination, &Udp4Session->DestinationAddress, sizeof (IP4_ADDR));\r
1325\r
1326 if (IP4_IS_LOCAL_BROADCAST (Destination) && ConfigData->AcceptBroadcast) {\r
1327 //\r
1328 // The instance is configured to receive broadcast and this is a broadcast packet.\r
1329 //\r
1330 return TRUE;\r
1331 }\r
1332\r
1333 if (IP4_IS_MULTICAST (NTOHL (Destination)) &&\r
1334 NetMapFindKey (&Instance->McastIps, (VOID *) (UINTN) Destination) != NULL\r
1335 ) {\r
1336 //\r
1337 // It's a multicast packet and the multicast address is accepted by this instance.\r
1338 //\r
1339 return TRUE;\r
1340 }\r
1341\r
1342 return FALSE;\r
1343}\r
1344\r
1345\r
1346/**\r
1347 This function removes the Wrap specified by Context and release relevant resources.\r
1348\r
1349 @param[in] Event The Event this notify function registered to.\r
1350 @param[in] Context Pointer to the context data.\r
1351\r
1352**/\r
1353VOID\r
1354EFIAPI\r
1355Udp4RecycleRxDataWrap (\r
1356 IN EFI_EVENT Event,\r
1357 IN VOID *Context\r
1358 )\r
1359{\r
1360 UDP4_RXDATA_WRAP *Wrap;\r
1361\r
1362 Wrap = (UDP4_RXDATA_WRAP *) Context;\r
1363\r
1364 //\r
1365 // Remove the Wrap from the list it belongs to.\r
1366 //\r
1367 RemoveEntryList (&Wrap->Link);\r
1368\r
1369 //\r
1370 // Free the Packet associated with this Wrap.\r
1371 //\r
1372 NetbufFree (Wrap->Packet);\r
1373\r
1374 //\r
1375 // Close the event.\r
1376 //\r
1377 gBS->CloseEvent (Wrap->RxData.RecycleSignal);\r
1378\r
1379 FreePool (Wrap);\r
1380}\r
1381\r
1382\r
1383/**\r
1384 This function wraps the Packet and the RxData.\r
1385\r
1386 @param[in] Instance Pointer to the instance context data.\r
1387 @param[in] Packet Pointer to the buffer containing the received\r
1388 datagram.\r
1389 @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
1390 datagram.\r
1391\r
1392 @return Pointer to the structure wrapping the RxData and the Packet.\r
1393\r
1394**/\r
1395UDP4_RXDATA_WRAP *\r
1396Udp4WrapRxData (\r
1397 IN UDP4_INSTANCE_DATA *Instance,\r
1398 IN NET_BUF *Packet,\r
1399 IN EFI_UDP4_RECEIVE_DATA *RxData\r
1400 )\r
1401{\r
1402 EFI_STATUS Status;\r
1403 UDP4_RXDATA_WRAP *Wrap;\r
1404\r
1405 //\r
1406 // Allocate buffer for the Wrap.\r
1407 //\r
1408 Wrap = AllocatePool (sizeof (UDP4_RXDATA_WRAP) +\r
1409 (Packet->BlockOpNum - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r
1410 if (Wrap == NULL) {\r
1411 return NULL;\r
1412 }\r
1413\r
1414 InitializeListHead (&Wrap->Link);\r
1415\r
1416 CopyMem (&Wrap->RxData, RxData, sizeof (Wrap->RxData));\r
1417\r
1418 //\r
1419 // Create the Recycle event.\r
1420 //\r
1421 Status = gBS->CreateEvent (\r
1422 EVT_NOTIFY_SIGNAL,\r
1423 TPL_NOTIFY,\r
1424 Udp4RecycleRxDataWrap,\r
1425 Wrap,\r
1426 &Wrap->RxData.RecycleSignal\r
1427 );\r
1428 if (EFI_ERROR (Status)) {\r
1429 FreePool (Wrap);\r
1430 return NULL;\r
1431 }\r
1432\r
1433 Wrap->Packet = Packet;\r
1434 Wrap->TimeoutTick = Instance->ConfigData.ReceiveTimeout;\r
1435\r
1436 return Wrap;\r
1437}\r
1438\r
1439\r
1440/**\r
1441 This function enqueues the received datagram into the instances' receiving queues.\r
1442\r
1443 @param[in] Udp4Service Pointer to the udp service context data.\r
1444 @param[in] Packet Pointer to the buffer containing the received\r
1445 datagram.\r
1446 @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
1447 datagram.\r
1448\r
1449 @return The times this datagram is enqueued.\r
1450\r
1451**/\r
1452UINTN\r
1453Udp4EnqueueDgram (\r
1454 IN UDP4_SERVICE_DATA *Udp4Service,\r
1455 IN NET_BUF *Packet,\r
1456 IN EFI_UDP4_RECEIVE_DATA *RxData\r
1457 )\r
1458{\r
1459 LIST_ENTRY *Entry;\r
1460 UDP4_INSTANCE_DATA *Instance;\r
1461 UDP4_RXDATA_WRAP *Wrap;\r
1462 UINTN Enqueued;\r
1463\r
1464 Enqueued = 0;\r
1465\r
1466 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
1467 //\r
1468 // Iterate the instances.\r
1469 //\r
1470 Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
1471\r
1472 if (!Instance->Configured) {\r
1473 continue;\r
1474 }\r
1475\r
1476 if (Udp4MatchDgram (Instance, &RxData->UdpSession)) {\r
1477 //\r
1478 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.\r
1479 //\r
1480 Wrap = Udp4WrapRxData (Instance, Packet, RxData);\r
1481 if (Wrap == NULL) {\r
1482 continue;\r
1483 }\r
1484\r
1485 NET_GET_REF (Packet);\r
1486\r
1487 InsertTailList (&Instance->RcvdDgramQue, &Wrap->Link);\r
1488\r
1489 Enqueued++;\r
1490 }\r
1491 }\r
1492\r
1493 return Enqueued;\r
1494}\r
1495\r
1496\r
1497/**\r
1498 This function delivers the received datagrams for the specified instance.\r
1499\r
1500 @param[in] Instance Pointer to the instance context data.\r
1501\r
1502**/\r
1503VOID\r
1504Udp4InstanceDeliverDgram (\r
1505 IN UDP4_INSTANCE_DATA *Instance\r
1506 )\r
1507{\r
1508 UDP4_RXDATA_WRAP *Wrap;\r
1509 EFI_UDP4_COMPLETION_TOKEN *Token;\r
1510 NET_BUF *Dup;\r
1511 EFI_UDP4_RECEIVE_DATA *RxData;\r
1512 EFI_TPL OldTpl;\r
1513\r
1514 if (!IsListEmpty (&Instance->RcvdDgramQue) &&\r
1515 !NetMapIsEmpty (&Instance->RxTokens)) {\r
1516\r
1517 Wrap = NET_LIST_HEAD (&Instance->RcvdDgramQue, UDP4_RXDATA_WRAP, Link);\r
1518\r
1519 if (NET_BUF_SHARED (Wrap->Packet)) {\r
1520 //\r
1521 // Duplicate the Packet if it is shared between instances.\r
1522 //\r
1523 Dup = NetbufDuplicate (Wrap->Packet, NULL, 0);\r
1524 if (Dup == NULL) {\r
1525 return;\r
1526 }\r
1527\r
1528 NetbufFree (Wrap->Packet);\r
1529\r
1530 Wrap->Packet = Dup;\r
1531 }\r
1532\r
1533 NetListRemoveHead (&Instance->RcvdDgramQue);\r
1534\r
1535 Token = (EFI_UDP4_COMPLETION_TOKEN *) NetMapRemoveHead (&Instance->RxTokens, NULL);\r
1536\r
1537 //\r
1538 // Build the FragmentTable and set the FragmentCount in RxData.\r
1539 //\r
1540 RxData = &Wrap->RxData;\r
1541 RxData->FragmentCount = Wrap->Packet->BlockOpNum;\r
1542\r
1543 NetbufBuildExt (\r
1544 Wrap->Packet,\r
1545 (NET_FRAGMENT *) RxData->FragmentTable,\r
1546 &RxData->FragmentCount\r
1547 );\r
1548\r
1549 Token->Status = EFI_SUCCESS;\r
1550 Token->Packet.RxData = &Wrap->RxData;\r
1551\r
1552 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1553 InsertTailList (&Instance->DeliveredDgramQue, &Wrap->Link);\r
1554 gBS->RestoreTPL (OldTpl);\r
1555\r
1556 gBS->SignalEvent (Token->Event);\r
1557 }\r
1558}\r
1559\r
1560\r
1561/**\r
1562 This function delivers the datagrams enqueued in the instances.\r
1563\r
1564 @param[in] Udp4Service Pointer to the udp service context data.\r
1565\r
1566**/\r
1567VOID\r
1568Udp4DeliverDgram (\r
1569 IN UDP4_SERVICE_DATA *Udp4Service\r
1570 )\r
1571{\r
1572 LIST_ENTRY *Entry;\r
1573 UDP4_INSTANCE_DATA *Instance;\r
1574\r
1575 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
1576 //\r
1577 // Iterate the instances.\r
1578 //\r
1579 Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
1580\r
1581 if (!Instance->Configured) {\r
1582 continue;\r
1583 }\r
1584\r
1585 //\r
1586 // Deliver the datagrams of this instance.\r
1587 //\r
1588 Udp4InstanceDeliverDgram (Instance);\r
1589 }\r
1590}\r
1591\r
1592\r
1593/**\r
1594 This function demultiplexes the received udp datagram to the appropriate instances.\r
1595\r
1596 @param[in] Udp4Service Pointer to the udp service context data.\r
1597 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from\r
1598 the received datagram.\r
1599 @param[in] Packet Pointer to the buffer containing the received udp\r
1600 datagram.\r
1601\r
1602**/\r
1603VOID\r
1604Udp4Demultiplex (\r
1605 IN UDP4_SERVICE_DATA *Udp4Service,\r
1606 IN EFI_NET_SESSION_DATA *NetSession,\r
1607 IN NET_BUF *Packet\r
1608 )\r
1609{\r
1610 EFI_UDP_HEADER *Udp4Header;\r
1611 UINT16 HeadSum;\r
1612 EFI_UDP4_RECEIVE_DATA RxData;\r
1613 EFI_UDP4_SESSION_DATA *Udp4Session;\r
1614 UINTN Enqueued;\r
1615\r
1616 if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
1617 NetbufFree (Packet);\r
1618 return;\r
1619 }\r
1620\r
1621 //\r
1622 // Get the datagram header from the packet buffer.\r
1623 //\r
1624 Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
1625 ASSERT (Udp4Header != NULL);\r
1626\r
1627 if (Udp4Header->Checksum != 0) {\r
1628 //\r
1629 // check the checksum.\r
1630 //\r
1631 HeadSum = NetPseudoHeadChecksum (\r
1632 NetSession->Source.Addr[0],\r
1633 NetSession->Dest.Addr[0],\r
1634 EFI_IP_PROTO_UDP,\r
1635 0\r
1636 );\r
1637\r
1638 if (Udp4Checksum (Packet, HeadSum) != 0) {\r
1639 //\r
1640 // Wrong checksum.\r
1641 //\r
1642 NetbufFree (Packet);\r
1643 return;\r
1644 }\r
1645 }\r
1646\r
1647 Udp4Session = &RxData.UdpSession;\r
1648 Udp4Session->SourcePort = NTOHS (Udp4Header->SrcPort);\r
1649 Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort);\r
1650\r
1651 CopyMem (&Udp4Session->SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
1652 CopyMem (&Udp4Session->DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
1653\r
1654 //\r
1655 // Trim the UDP header.\r
1656 //\r
1657 NetbufTrim (Packet, UDP4_HEADER_SIZE, TRUE);\r
1658\r
1659 RxData.DataLength = (UINT32) Packet->TotalSize;\r
1660\r
1661 //\r
1662 // Try to enqueue this datagram into the instances.\r
1663 //\r
1664 Enqueued = Udp4EnqueueDgram (Udp4Service, Packet, &RxData);\r
1665\r
1666 if (Enqueued == 0) {\r
1667 //\r
1668 // Send the port unreachable ICMP packet before we free this NET_BUF\r
1669 //\r
1670 Udp4SendPortUnreach (Udp4Service->IpIo, NetSession, Udp4Header);\r
1671 }\r
1672\r
1673 //\r
1674 // Try to free the packet before deliver it.\r
1675 //\r
1676 NetbufFree (Packet);\r
1677\r
1678 if (Enqueued > 0) {\r
1679 //\r
1680 // Deliver the datagram.\r
1681 //\r
1682 Udp4DeliverDgram (Udp4Service);\r
1683 }\r
1684}\r
1685\r
1686\r
1687/**\r
1688 This function builds and sends out a icmp port unreachable message.\r
1689\r
1690 @param[in] IpIo Pointer to the IP_IO instance.\r
1691 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet\r
1692 causes this icmp error message.\r
1693 @param[in] Udp4Header Pointer to the udp header of the datagram causes\r
1694 this icmp error message.\r
1695\r
1696**/\r
1697VOID\r
1698Udp4SendPortUnreach (\r
1699 IN IP_IO *IpIo,\r
1700 IN EFI_NET_SESSION_DATA *NetSession,\r
1701 IN VOID *Udp4Header\r
1702 )\r
1703{\r
1704 NET_BUF *Packet;\r
1705 UINT32 Len;\r
1706 IP4_ICMP_ERROR_HEAD *IcmpErrHdr;\r
1707 EFI_IP4_HEADER *IpHdr;\r
1708 UINT8 *Ptr;\r
1709 IP_IO_OVERRIDE Override;\r
1710 IP_IO_IP_INFO *IpSender;\r
1711\r
1712 IpSender = IpIoFindSender (&IpIo, NetSession->IpVersion, &NetSession->Dest);\r
1713 if (IpSender == NULL) {\r
1714 //\r
1715 // No appropriate sender, since we cannot send out the ICMP message through\r
1716 // the default zero station address IP instance, abort.\r
1717 //\r
1718 return;\r
1719 }\r
1720\r
1721 IpHdr = NetSession->IpHdr.Ip4Hdr;\r
1722\r
1723 //\r
1724 // Calculate the required length of the icmp error message.\r
1725 //\r
1726 Len = sizeof (IP4_ICMP_ERROR_HEAD) + (EFI_IP4_HEADER_LEN (IpHdr) -\r
1727 sizeof (IP4_HEAD)) + ICMP_ERROR_PACKET_LENGTH;\r
1728\r
1729 //\r
1730 // Allocate buffer for the icmp error message.\r
1731 //\r
1732 Packet = NetbufAlloc (Len);\r
1733 if (Packet == NULL) {\r
1734 return;\r
1735 }\r
1736\r
1737 //\r
1738 // Allocate space for the IP4_ICMP_ERROR_HEAD.\r
1739 //\r
1740 IcmpErrHdr = (IP4_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE);\r
1741 ASSERT (IcmpErrHdr != NULL);\r
1742\r
1743 //\r
1744 // Set the required fields for the icmp port unreachable message.\r
1745 //\r
1746 IcmpErrHdr->Head.Type = ICMP_TYPE_UNREACH;\r
1747 IcmpErrHdr->Head.Code = ICMP_CODE_UNREACH_PORT;\r
1748 IcmpErrHdr->Head.Checksum = 0;\r
1749 IcmpErrHdr->Fourth = 0;\r
1750\r
1751 //\r
1752 // Copy the IP header of the datagram tragged the error.\r
1753 //\r
1754 CopyMem (&IcmpErrHdr->IpHead, IpHdr, EFI_IP4_HEADER_LEN (IpHdr));\r
1755\r
1756 //\r
1757 // Copy the UDP header.\r
1758 //\r
1759 Ptr = (UINT8 *) &IcmpErrHdr->IpHead + EFI_IP4_HEADER_LEN (IpHdr);\r
1760 CopyMem (Ptr, Udp4Header, ICMP_ERROR_PACKET_LENGTH);\r
1761\r
1762 //\r
1763 // Calculate the checksum.\r
1764 //\r
1765 IcmpErrHdr->Head.Checksum = (UINT16) ~(NetbufChecksum (Packet));\r
1766\r
1767 //\r
1768 // Fill the override data.\r
1769 //\r
1770 Override.Ip4OverrideData.DoNotFragment = FALSE;\r
1771 Override.Ip4OverrideData.TypeOfService = 0;\r
1772 Override.Ip4OverrideData.TimeToLive = 255;\r
1773 Override.Ip4OverrideData.Protocol = EFI_IP_PROTO_ICMP;\r
1774\r
1775 CopyMem (&Override.Ip4OverrideData.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
1776 ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
1777\r
1778 //\r
1779 // Send out this icmp packet.\r
1780 //\r
1781 IpIoSend (IpIo, Packet, IpSender, NULL, NULL, &NetSession->Source, &Override);\r
1782\r
1783 NetbufFree (Packet);\r
1784}\r
1785\r
1786\r
1787/**\r
1788 This function handles the received Icmp Error message and demultiplexes it to the\r
1789 instance.\r
1790\r
1791 @param[in] Udp4Service Pointer to the udp service context data.\r
1792 @param[in] IcmpError The icmp error code.\r
1793 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted\r
1794 from the received Icmp Error packet.\r
1795 @param[in] Packet Pointer to the Icmp Error packet.\r
1796\r
1797**/\r
1798VOID\r
1799Udp4IcmpHandler (\r
1800 IN UDP4_SERVICE_DATA *Udp4Service,\r
1801 IN UINT8 IcmpError,\r
1802 IN EFI_NET_SESSION_DATA *NetSession,\r
1803 IN NET_BUF *Packet\r
1804 )\r
1805{\r
1806 EFI_UDP_HEADER *Udp4Header;\r
1807 EFI_UDP4_SESSION_DATA Udp4Session;\r
1808 LIST_ENTRY *Entry;\r
1809 UDP4_INSTANCE_DATA *Instance;\r
1810\r
1811 if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
1812 NetbufFree (Packet);\r
1813 return;\r
1814 }\r
1815 \r
1816 Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
1817 ASSERT (Udp4Header != NULL);\r
1818\r
1819 CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
1820 CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
1821\r
1822 Udp4Session.SourcePort = NTOHS (Udp4Header->DstPort);\r
1823 Udp4Session.DestinationPort = NTOHS (Udp4Header->SrcPort);\r
1824\r
1825 NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
1826 //\r
1827 // Iterate all the instances.\r
1828 //\r
1829 Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
1830\r
1831 if (!Instance->Configured) {\r
1832 continue;\r
1833 }\r
1834\r
1835 if (Udp4MatchDgram (Instance, &Udp4Session)) {\r
1836 //\r
1837 // Translate the Icmp Error code according to the udp spec.\r
1838 //\r
1839 Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, IP_VERSION_4, NULL, NULL);\r
1840\r
1841 if (IcmpError > ICMP_ERR_UNREACH_PORT) {\r
1842 Instance->IcmpError = EFI_ICMP_ERROR;\r
1843 }\r
1844\r
1845 //\r
1846 // Notify the instance with the received Icmp Error.\r
1847 //\r
1848 Udp4ReportIcmpError (Instance);\r
1849\r
1850 break;\r
1851 }\r
1852 }\r
1853\r
1854 NetbufFree (Packet);\r
1855}\r
1856\r
1857\r
1858/**\r
1859 This function reports the received ICMP error.\r
1860\r
1861 @param[in] Instance Pointer to the udp instance context data.\r
1862\r
1863**/\r
1864VOID\r
1865Udp4ReportIcmpError (\r
1866 IN UDP4_INSTANCE_DATA *Instance\r
1867 )\r
1868{\r
1869 EFI_UDP4_COMPLETION_TOKEN *Token;\r
1870\r
1871 if (NetMapIsEmpty (&Instance->RxTokens)) {\r
1872 //\r
1873 // There are no receive tokens to deliver the ICMP error.\r
1874 //\r
1875 return;\r
1876 }\r
1877\r
1878 if (EFI_ERROR (Instance->IcmpError)) {\r
1879 //\r
1880 // Try to get a RxToken from the RxTokens map.\r
1881 //\r
1882 Token = (EFI_UDP4_COMPLETION_TOKEN *) NetMapRemoveHead (&Instance->RxTokens, NULL);\r
1883\r
1884 if (Token != NULL) {\r
1885 //\r
1886 // Report the error through the Token.\r
1887 //\r
1888 Token->Status = Instance->IcmpError;\r
1889 gBS->SignalEvent (Token->Event);\r
1890\r
1891 //\r
1892 // Clear the IcmpError.\r
1893 //\r
1894 Instance->IcmpError = EFI_SUCCESS;\r
1895 }\r
1896 }\r
1897}\r
1898\r
1899\r
1900/**\r
1901 This function is a dummy ext-free function for the NET_BUF created for the output\r
1902 udp datagram.\r
1903\r
1904 @param[in] Context Pointer to the context data.\r
1905\r
1906**/\r
1907VOID\r
1908EFIAPI\r
1909Udp4NetVectorExtFree (\r
1910 VOID *Context\r
1911 )\r
1912{\r
1913}\r
1914\r