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