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