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