1 /** @file
2   EFI UDPv4 protocol implementation.
3 
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _UDP4_IMPL_H_
10 #define _UDP4_IMPL_H_
11 
12 #include <Uefi.h>
13 
14 #include <Protocol/Ip4.h>
15 #include <Protocol/Udp4.h>
16 
17 #include <Library/IpIoLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiRuntimeServicesTableLib.h>
20 #include <Library/UefiDriverEntryPoint.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/UefiLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/TimerLib.h>
27 #include <Library/DpcLib.h>
28 #include <Library/PrintLib.h>
29 
30 #include "Udp4Driver.h"
31 
32 
33 extern EFI_COMPONENT_NAME_PROTOCOL     gUdp4ComponentName;
34 extern EFI_COMPONENT_NAME2_PROTOCOL    gUdp4ComponentName2;
35 extern EFI_UNICODE_STRING_TABLE        *gUdpControllerNameTable;
36 extern EFI_SERVICE_BINDING_PROTOCOL    mUdp4ServiceBinding;
37 extern EFI_UDP4_PROTOCOL               mUdp4Protocol;
38 extern UINT16                          mUdp4RandomPort;
39 
40 #define ICMP_ERROR_PACKET_LENGTH  8
41 
42 #define UDP4_TIMEOUT_INTERVAL (50 * TICKS_PER_MS)  // 50 milliseconds
43 
44 #define UDP4_HEADER_SIZE      sizeof (EFI_UDP_HEADER)
45 #define UDP4_MAX_DATA_SIZE    65507
46 
47 #define UDP4_PORT_KNOWN       1024
48 
49 #define UDP4_SERVICE_DATA_SIGNATURE  SIGNATURE_32('U', 'd', 'p', '4')
50 
51 #define UDP4_SERVICE_DATA_FROM_THIS(a) \
52   CR ( \
53   (a), \
54   UDP4_SERVICE_DATA, \
55   ServiceBinding, \
56   UDP4_SERVICE_DATA_SIGNATURE \
57   )
58 
59 typedef struct _UDP4_SERVICE_DATA_ {
60   UINT32                        Signature;
61   EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;
62   EFI_HANDLE                    ImageHandle;
63   EFI_HANDLE                    ControllerHandle;
64   LIST_ENTRY                    ChildrenList;
65   UINTN                         ChildrenNumber;
66   IP_IO                         *IpIo;
67 
68   EFI_EVENT                     TimeoutEvent;
69 } UDP4_SERVICE_DATA;
70 
71 #define UDP4_INSTANCE_DATA_SIGNATURE  SIGNATURE_32('U', 'd', 'p', 'I')
72 
73 #define UDP4_INSTANCE_DATA_FROM_THIS(a) \
74   CR ( \
75   (a), \
76   UDP4_INSTANCE_DATA, \
77   Udp4Proto, \
78   UDP4_INSTANCE_DATA_SIGNATURE \
79   )
80 
81 typedef struct _UDP4_INSTANCE_DATA_ {
82   UINT32                Signature;
83   LIST_ENTRY            Link;
84 
85   UDP4_SERVICE_DATA     *Udp4Service;
86   EFI_UDP4_PROTOCOL     Udp4Proto;
87   EFI_UDP4_CONFIG_DATA  ConfigData;
88   EFI_HANDLE            ChildHandle;
89   BOOLEAN               Configured;
90   BOOLEAN               IsNoMapping;
91 
92   NET_MAP               TxTokens;
93   NET_MAP               RxTokens;
94 
95   NET_MAP               McastIps;
96 
97   LIST_ENTRY            RcvdDgramQue;
98   LIST_ENTRY            DeliveredDgramQue;
99 
100   UINT16                HeadSum;
101 
102   EFI_STATUS            IcmpError;
103 
104   IP_IO_IP_INFO         *IpInfo;
105 
106   BOOLEAN               InDestroy;
107 } UDP4_INSTANCE_DATA;
108 
109 typedef struct _UDP4_RXDATA_WRAP_ {
110   LIST_ENTRY             Link;
111   NET_BUF                *Packet;
112   UINT32                 TimeoutTick;
113   EFI_UDP4_RECEIVE_DATA  RxData;
114 } UDP4_RXDATA_WRAP;
115 
116 typedef struct {
117   EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;
118   UINTN                         NumberOfChildren;
119   EFI_HANDLE                    *ChildHandleBuffer;
120 } UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
121 
122 /**
123   Reads the current operational settings.
124 
125   The GetModeData() function copies the current operational settings of this EFI
126   UDPv4 Protocol instance into user-supplied buffers. This function is used
127   optionally to retrieve the operational mode data of underlying networks or
128   drivers.
129 
130   @param[in]  This              Pointer to the EFI_UDP4_PROTOCOL instance.
131   @param[out] Udp4ConfigData    Pointer to the buffer to receive the current configuration data.
132   @param[out] Ip4ModeData       Pointer to the EFI IPv4 Protocol mode data structure.
133   @param[out] MnpConfigData     Pointer to the managed network configuration data structure.
134   @param[out] SnpModeData       Pointer to the simple network mode data structure.
135 
136   @retval EFI_SUCCESS           The mode data was read.
137   @retval EFI_NOT_STARTED       When Udp4ConfigData is queried, no configuration data is
138                                 available because this instance has not been started.
139   @retval EFI_INVALID_PARAMETER This is NULL.
140 
141 **/
142 EFI_STATUS
143 EFIAPI
144 Udp4GetModeData (
145   IN  EFI_UDP4_PROTOCOL                *This,
146   OUT EFI_UDP4_CONFIG_DATA             *Udp4ConfigData OPTIONAL,
147   OUT EFI_IP4_MODE_DATA                *Ip4ModeData    OPTIONAL,
148   OUT EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData  OPTIONAL,
149   OUT EFI_SIMPLE_NETWORK_MODE          *SnpModeData    OPTIONAL
150   );
151 
152 /**
153   Initializes, changes, or resets the operational parameters for this instance of the EFI UDPv4
154   Protocol.
155 
156   The Configure() function is used to do the following:
157   * Initialize and start this instance of the EFI UDPv4 Protocol.
158   * Change the filtering rules and operational parameters.
159   * Reset this instance of the EFI UDPv4 Protocol.
160   Until these parameters are initialized, no network traffic can be sent or
161   received by this instance. This instance can be also reset by calling Configure()
162   with UdpConfigData set to NULL. Once reset, the receiving queue and transmitting
163   queue are flushed and no traffic is allowed through this instance.
164   With different parameters in UdpConfigData, Configure() can be used to bind
165   this instance to specified port.
166 
167   @param[in]  This              Pointer to the EFI_UDP4_PROTOCOL instance.
168   @param[in]  UdpConfigData     Pointer to the buffer to receive the current configuration data.
169 
170   @retval EFI_SUCCESS           The configuration settings were set, changed, or reset successfully.
171   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
172                                 RARP, etc.) is not finished yet.
173   @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
174   @retval EFI_ALREADY_STARTED   The EFI UDPv4 Protocol instance is already started/configured
175                                 and must be stopped/reset before it can be reconfigured.
176   @retval EFI_ACCESS_DENIED     UdpConfigData. AllowDuplicatePort is FALSE
177                                 and UdpConfigData.StationPort is already used by
178                                 other instance.
179   @retval EFI_OUT_OF_RESOURCES  The EFI UDPv4 Protocol driver cannot allocate memory for this
180                                 EFI UDPv4 Protocol instance.
181   @retval EFI_DEVICE_ERROR      An unexpected network or system error occurred and this instance
182                                  was not opened.
183 
184 **/
185 EFI_STATUS
186 EFIAPI
187 Udp4Configure (
188   IN EFI_UDP4_PROTOCOL     *This,
189   IN EFI_UDP4_CONFIG_DATA  *UdpConfigData OPTIONAL
190   );
191 
192 /**
193   Joins and leaves multicast groups.
194 
195   The Groups() function is used to enable and disable the multicast group
196   filtering. If the JoinFlag is FALSE and the MulticastAddress is NULL, then all
197   currently joined groups are left.
198 
199   @param[in]  This              Pointer to the EFI_UDP4_PROTOCOL instance.
200   @param[in]  JoinFlag          Set to TRUE to join a multicast group. Set to FALSE to leave one
201                                 or all multicast groups.
202   @param[in]  MulticastAddress  Pointer to multicast group address to join or leave.
203 
204   @retval EFI_SUCCESS           The operation completed successfully.
205   @retval EFI_NOT_STARTED       The EFI UDPv4 Protocol instance has not been started.
206   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
207                                 RARP, etc.) is not finished yet.
208   @retval EFI_OUT_OF_RESOURCES  Could not allocate resources to join the group.
209   @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
210                                 - This is NULL.
211                                 - JoinFlag is TRUE and MulticastAddress is NULL.
212                                 - JoinFlag is TRUE and *MulticastAddress is not
213                                   a valid multicast address.
214   @retval EFI_ALREADY_STARTED   The group address is already in the group table (when
215                                 JoinFlag is TRUE).
216   @retval EFI_NOT_FOUND         The group address is not in the group table (when JoinFlag is
217                                 FALSE).
218   @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.
219 
220 **/
221 EFI_STATUS
222 EFIAPI
223 Udp4Groups (
224   IN EFI_UDP4_PROTOCOL  *This,
225   IN BOOLEAN            JoinFlag,
226   IN EFI_IPv4_ADDRESS   *MulticastAddress OPTIONAL
227   );
228 
229 /**
230   Adds and deletes routing table entries.
231 
232   The Routes() function adds a route to or deletes a route from the routing table.
233   Routes are determined by comparing the SubnetAddress with the destination IP
234   address and arithmetically AND-ing it with the SubnetMask. The gateway address
235   must be on the same subnet as the configured station address.
236   The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
237   The default route matches all destination IP addresses that do not match any
238   other routes.
239   A zero GatewayAddress is a nonroute. Packets are sent to the destination IP
240   address if it can be found in the Address Resolution Protocol (ARP) cache or
241   on the local subnet. One automatic nonroute entry will be inserted into the
242   routing table for outgoing packets that are addressed to a local subnet
243   (gateway address of 0.0.0.0).
244   Each instance of the EFI UDPv4 Protocol has its own independent routing table.
245   Instances of the EFI UDPv4 Protocol that use the default IP address will also
246   have copies of the routing table provided by the EFI_IP4_CONFIG_PROTOCOL. These
247   copies will be updated automatically whenever the IP driver reconfigures its
248   instances; as a result, the previous modification to these copies will be lost.
249 
250   @param[in]  This              Pointer to the EFI_UDP4_PROTOCOL instance.
251   @param[in]  DeleteRoute       Set to TRUE to delete this route from the routing table.
252                                 Set to FALSE to add this route to the routing table.
253   @param[in]  SubnetAddress     The destination network address that needs to be routed.
254   @param[in]  SubnetMask        The subnet mask of SubnetAddress.
255   @param[in]  GatewayAddress    The gateway IP address for this route.
256 
257   @retval EFI_SUCCESS           The operation completed successfully.
258   @retval EFI_NOT_STARTED       The EFI UDPv4 Protocol instance has not been started.
259   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
260                                 - RARP, etc.) is not finished yet.
261   @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
262   @retval EFI_OUT_OF_RESOURCES  Could not add the entry to the routing table.
263   @retval EFI_NOT_FOUND         This route is not in the routing table.
264   @retval EFI_ACCESS_DENIED     The route is already defined in the routing table.
265 
266 **/
267 EFI_STATUS
268 EFIAPI
269 Udp4Routes (
270   IN EFI_UDP4_PROTOCOL  *This,
271   IN BOOLEAN            DeleteRoute,
272   IN EFI_IPv4_ADDRESS   *SubnetAddress,
273   IN EFI_IPv4_ADDRESS   *SubnetMask,
274   IN EFI_IPv4_ADDRESS   *GatewayAddress
275   );
276 
277 /**
278   Queues outgoing data packets into the transmit queue.
279 
280   The Transmit() function places a sending request to this instance of the EFI
281   UDPv4 Protocol, alongside the transmit data that was filled by the user. Whenever
282   the packet in the token is sent out or some errors occur, the Token.Event will
283   be signaled and Token.Status is updated. Providing a proper notification function
284   and context for the event will enable the user to receive the notification and
285   transmitting status.
286 
287   @param[in]  This              Pointer to the EFI_UDP4_PROTOCOL instance.
288   @param[in]  Token             Pointer to the completion token that will be placed into the
289                                 transmit queue.
290 
291   @retval EFI_SUCCESS           The data has been queued for transmission.
292   @retval EFI_NOT_STARTED       This EFI UDPv4 Protocol instance has not been started.
293   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
294                                 RARP, etc.) is not finished yet.
295   @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
296   @retval EFI_ACCESS_DENIED     The transmit completion token with the same
297                                 Token.Event was already in the transmit queue.
298   @retval EFI_NOT_READY         The completion token could not be queued because the
299                                 transmit queue is full.
300   @retval EFI_OUT_OF_RESOURCES  Could not queue the transmit data.
301   @retval EFI_NOT_FOUND         There is no route to the destination network or address.
302   @retval EFI_BAD_BUFFER_SIZE   The data length is greater than the maximum UDP packet
303                                 size. Or the length of the IP header + UDP header + data
304                                 length is greater than MTU if DoNotFragment is TRUE.
305 
306 **/
307 EFI_STATUS
308 EFIAPI
309 Udp4Transmit (
310   IN EFI_UDP4_PROTOCOL          *This,
311   IN EFI_UDP4_COMPLETION_TOKEN  *Token
312   );
313 
314 /**
315   Places an asynchronous receive request into the receiving queue.
316 
317   The Receive() function places a completion token into the receive packet queue.
318   This function is always asynchronous.
319   The caller must fill in the Token.Event field in the completion token, and this
320   field cannot be NULL. When the receive operation completes, the EFI UDPv4 Protocol
321   driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
322   is signaled. Providing a proper notification function and context for the event
323   will enable the user to receive the notification and receiving status. That
324   notification function is guaranteed to not be re-entered.
325 
326   @param[in]  This              Pointer to the EFI_UDP4_PROTOCOL instance.
327   @param[in]  Token             Pointer to a token that is associated with
328                                 the receive data descriptor.
329 
330   @retval EFI_SUCCESS           The receive completion token was cached.
331   @retval EFI_NOT_STARTED       This EFI UDPv4 Protocol instance has not been started.
332   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP, RARP, etc.)
333                                 is not finished yet.
334   @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
335   @retval EFI_OUT_OF_RESOURCES  The receive completion token could not be queued due to a lack of system
336                                 resources (usually memory).
337   @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.
338   @retval EFI_ACCESS_DENIED     A receive completion token with the same Token.Event was already in
339                                 the receive queue.
340   @retval EFI_NOT_READY         The receive request could not be queued because the receive queue is full.
341 
342 **/
343 EFI_STATUS
344 EFIAPI
345 Udp4Receive (
346   IN EFI_UDP4_PROTOCOL          *This,
347   IN EFI_UDP4_COMPLETION_TOKEN  *Token
348   );
349 
350 /**
351   Aborts an asynchronous transmit or receive request.
352 
353   The Cancel() function is used to abort a pending transmit or receive request.
354   If the token is in the transmit or receive request queues, after calling this
355   function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
356   signaled. If the token is not in one of the queues, which usually means that
357   the asynchronous operation has completed, this function will not signal the
358   token and EFI_NOT_FOUND is returned.
359 
360   @param[in]  This  Pointer to the EFI_UDP4_PROTOCOL instance.
361   @param[in]  Token Pointer to a token that has been issued by
362                     EFI_UDP4_PROTOCOL.Transmit() or
363                     EFI_UDP4_PROTOCOL.Receive().If NULL, all pending
364                     tokens are aborted.
365 
366   @retval  EFI_SUCCESS           The asynchronous I/O request was aborted and Token.Event
367                                  was signaled. When Token is NULL, all pending requests are
368                                  aborted and their events are signaled.
369   @retval  EFI_INVALID_PARAMETER This is NULL.
370   @retval  EFI_NOT_STARTED       This instance has not been started.
371   @retval  EFI_NO_MAPPING        When using the default address, configuration (DHCP, BOOTP,
372                                  RARP, etc.) is not finished yet.
373   @retval  EFI_NOT_FOUND         When Token is not NULL, the asynchronous I/O request was
374                                  not found in the transmit or receive queue. It has either completed
375                                  or was not issued by Transmit() and Receive().
376 
377 **/
378 EFI_STATUS
379 EFIAPI
380 Udp4Cancel (
381   IN EFI_UDP4_PROTOCOL          *This,
382   IN EFI_UDP4_COMPLETION_TOKEN  *Token OPTIONAL
383   );
384 
385 /**
386   Polls for incoming data packets and processes outgoing data packets.
387 
388   The Poll() function can be used by network drivers and applications to increase
389   the rate that data packets are moved between the communications device and the
390   transmit and receive queues.
391   In some systems, the periodic timer event in the managed network driver may not
392   poll the underlying communications device fast enough to transmit and/or receive
393   all data packets without missing incoming packets or dropping outgoing packets.
394   Drivers and applications that are experiencing packet loss should try calling
395   the Poll() function more often.
396 
397   @param[in]  This  Pointer to the EFI_UDP4_PROTOCOL instance.
398 
399   @retval EFI_SUCCESS           Incoming or outgoing data was processed.
400   @retval EFI_INVALID_PARAMETER This is NULL.
401   @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.
402   @retval EFI_TIMEOUT           Data was dropped out of the transmit and/or receive queue.
403 
404 **/
405 EFI_STATUS
406 EFIAPI
407 Udp4Poll (
408   IN EFI_UDP4_PROTOCOL  *This
409   );
410 
411 /**
412   Create the Udp service context data.
413 
414   @param[in, out] Udp4Service      Pointer to the UDP4_SERVICE_DATA.
415   @param[in]      ImageHandle      The image handle of this udp4 driver.
416   @param[in]      ControllerHandle The controller handle this udp4 driver binds on.
417 
418   @retval EFI_SUCCESS              The udp4 service context data is created and
419                                    initialized.
420   @retval EFI_OUT_OF_RESOURCES     Cannot allocate memory.
421   @retval other                    Other error occurs.
422 
423 **/
424 EFI_STATUS
425 Udp4CreateService (
426   IN OUT UDP4_SERVICE_DATA  *Udp4Service,
427   IN     EFI_HANDLE         ImageHandle,
428   IN     EFI_HANDLE         ControllerHandle
429   );
430 
431 /**
432   Clean the Udp service context data.
433 
434   @param[in]  Udp4Service            Pointer to the UDP4_SERVICE_DATA.
435 
436 **/
437 VOID
438 Udp4CleanService (
439   IN UDP4_SERVICE_DATA  *Udp4Service
440   );
441 
442 /**
443   This function initializes the new created udp instance.
444 
445   @param[in]      Udp4Service       Pointer to the UDP4_SERVICE_DATA.
446   @param[in, out] Instance          Pointer to the un-initialized UDP4_INSTANCE_DATA.
447 
448 **/
449 VOID
450 Udp4InitInstance (
451   IN     UDP4_SERVICE_DATA   *Udp4Service,
452   IN OUT UDP4_INSTANCE_DATA  *Instance
453   );
454 
455 /**
456   This function cleans the udp instance.
457 
458   @param[in]  Instance               Pointer to the UDP4_INSTANCE_DATA to clean.
459 
460 **/
461 VOID
462 Udp4CleanInstance (
463   IN UDP4_INSTANCE_DATA  *Instance
464   );
465 
466 /**
467   This function tries to bind the udp instance according to the configured port
468   allocation strategy.
469 
470   @param[in]      InstanceList   Pointer to the head of the list linking the udp
471                                  instances.
472   @param[in, out] ConfigData     Pointer to the ConfigData of the instance to be
473                                  bound. ConfigData->StationPort will be assigned
474                                  with an available port value on success.
475 
476   @retval EFI_SUCCESS            The bound operation is completed successfully.
477   @retval EFI_ACCESS_DENIED      The <Address, Port> specified by the ConfigData is
478                                  already used by other instance.
479   @retval EFI_OUT_OF_RESOURCES   No available port resources.
480 
481 **/
482 EFI_STATUS
483 Udp4Bind (
484   IN     LIST_ENTRY            *InstanceList,
485   IN OUT EFI_UDP4_CONFIG_DATA  *ConfigData
486   );
487 
488 /**
489   This function is used to check whether the NewConfigData has any un-reconfigurable
490   parameters changed compared to the OldConfigData.
491 
492   @param[in]  OldConfigData      Pointer to the current ConfigData the udp instance
493                                  uses.
494   @param[in]  NewConfigData      Pointer to the new ConfigData.
495 
496   @retval TRUE     The instance is reconfigurable.
497   @retval FALSE    Otherwise.
498 
499 **/
500 BOOLEAN
501 Udp4IsReconfigurable (
502   IN EFI_UDP4_CONFIG_DATA  *OldConfigData,
503   IN EFI_UDP4_CONFIG_DATA  *NewConfigData
504   );
505 
506 /**
507   This function builds the Ip4 configdata from the Udp4ConfigData.
508 
509   @param[in]       Udp4ConfigData    Pointer to the EFI_UDP4_CONFIG_DATA.
510   @param[in, out]  Ip4ConfigData     Pointer to the EFI_IP4_CONFIG_DATA.
511 
512 **/
513 VOID
514 Udp4BuildIp4ConfigData (
515   IN     EFI_UDP4_CONFIG_DATA  *Udp4ConfigData,
516   IN OUT EFI_IP4_CONFIG_DATA   *Ip4ConfigData
517   );
518 
519 /**
520   This function validates the TxToken, it returns the error code according to the spec.
521 
522   @param[in]  Instance           Pointer to the udp instance context data.
523   @param[in]  TxToken            Pointer to the token to be checked.
524 
525   @retval EFI_SUCCESS            The TxToken is valid.
526   @retval EFI_INVALID_PARAMETER  One or more of the following are TRUE: This is
527                                  NULL. Token is NULL. Token.Event is NULL.
528                                  Token.Packet.TxData is NULL.
529                                  Token.Packet.TxData.FragmentCount is zero.
530                                  Token.Packet.TxData.DataLength is not equal to the
531                                  sum of fragment lengths. One or more of the
532                                  Token.Packet.TxData.FragmentTable[].
533                                  FragmentLength fields is zero. One or more of the
534                                  Token.Packet.TxData.FragmentTable[].
535                                  FragmentBuffer fields is NULL.
536                                  Token.Packet.TxData. GatewayAddress is not a
537                                  unicast IPv4 address if it is not NULL. One or
538                                  more IPv4 addresses in Token.Packet.TxData.
539                                  UdpSessionData are not valid unicast IPv4
540                                  addresses if the UdpSessionData is not NULL.
541   @retval EFI_BAD_BUFFER_SIZE    The data length is greater than the maximum UDP
542                                  packet size.
543 
544 **/
545 EFI_STATUS
546 Udp4ValidateTxToken (
547   IN UDP4_INSTANCE_DATA         *Instance,
548   IN EFI_UDP4_COMPLETION_TOKEN  *TxToken
549   );
550 
551 /**
552   This function checks whether the specified Token duplicates with the one in the Map.
553 
554   @param[in]  Map                Pointer to the NET_MAP.
555   @param[in]  Item               Pointer to the NET_MAP_ITEM contain the pointer to
556                                  the Token.
557   @param[in]  Context            Pointer to the Token to be checked.
558 
559   @retval EFI_SUCCESS            The Token specified by Context differs from the
560                                  one in the Item.
561   @retval EFI_ACCESS_DENIED      The Token duplicates with the one in the Item.
562 
563 **/
564 EFI_STATUS
565 EFIAPI
566 Udp4TokenExist (
567   IN NET_MAP       *Map,
568   IN NET_MAP_ITEM  *Item,
569   IN VOID          *Context
570   );
571 
572 /**
573   This function calculates the checksum for the Packet, utilizing the pre-calculated
574   pseudo HeadSum to reduce some overhead.
575 
576   @param[in]  Packet             Pointer to the NET_BUF contains the udp datagram.
577   @param[in]  HeadSum            Checksum of the pseudo header except the length
578                                  field.
579 
580   @retval The 16-bit checksum of this udp datagram.
581 
582 **/
583 UINT16
584 Udp4Checksum (
585   IN NET_BUF *Packet,
586   IN UINT16  HeadSum
587   );
588 
589 /**
590   This function removes the specified Token from the TokenMap.
591 
592   @param[in, out] TokenMap       Pointer to the NET_MAP containing the tokens.
593   @param[in]      Token          Pointer to the Token to be removed.
594 
595   @retval EFI_SUCCESS            The specified Token is removed from the TokenMap.
596   @retval EFI_NOT_FOUND          The specified Token is not found in the TokenMap.
597 
598 **/
599 EFI_STATUS
600 Udp4RemoveToken (
601   IN OUT NET_MAP                    *TokenMap,
602   IN     EFI_UDP4_COMPLETION_TOKEN  *Token
603   );
604 
605 /**
606   This function removes the multicast group specified by Arg from the Map.
607 
608   @param[in, out] Map            Pointer to the NET_MAP.
609   @param[in]      Item           Pointer to the NET_MAP_ITEM.
610   @param[in]      Arg            Pointer to the Arg, it's the pointer to a
611                                  multicast IPv4 Address.
612 
613   @retval EFI_SUCCESS            The multicast address is removed.
614   @retval EFI_ABORTED            The specified multicast address is removed and the
615                                  Arg is not NULL.
616 
617 **/
618 EFI_STATUS
619 EFIAPI
620 Udp4LeaveGroup (
621   IN OUT NET_MAP       *Map,
622   IN     NET_MAP_ITEM  *Item,
623   IN     VOID          *Arg OPTIONAL
624   );
625 
626 /**
627   This function removes all the Wrap datas in the RcvdDgramQue.
628 
629   @param[in]  Instance           Pointer to the udp instance context data.
630 
631 **/
632 VOID
633 Udp4FlushRcvdDgram (
634   IN UDP4_INSTANCE_DATA  *Instance
635   );
636 
637 /**
638   Cancel Udp4 tokens from the Udp4 instance.
639 
640   @param[in]  Instance           Pointer to the udp instance context data.
641   @param[in]  Token              Pointer to the token to be canceled, if NULL, all
642                                  tokens in this instance will be cancelled.
643 
644   @retval EFI_SUCCESS            The Token is cancelled.
645   @retval EFI_NOT_FOUND          The Token is not found.
646 
647 **/
648 EFI_STATUS
649 Udp4InstanceCancelToken (
650   IN UDP4_INSTANCE_DATA         *Instance,
651   IN EFI_UDP4_COMPLETION_TOKEN  *Token OPTIONAL
652   );
653 
654 /**
655   This function delivers the received datagrams for the specified instance.
656 
657   @param[in]  Instance               Pointer to the instance context data.
658 
659 **/
660 VOID
661 Udp4InstanceDeliverDgram (
662   IN UDP4_INSTANCE_DATA  *Instance
663   );
664 
665 /**
666   This function reports the received ICMP error.
667 
668   @param[in]  Instance               Pointer to the udp instance context data.
669 
670 **/
671 VOID
672 Udp4ReportIcmpError (
673   IN UDP4_INSTANCE_DATA  *Instance
674   );
675 
676 /**
677   This function is a dummy ext-free function for the NET_BUF created for the output
678   udp datagram.
679 
680   @param[in]  Context                Pointer to the context data.
681 
682 **/
683 VOID
684 EFIAPI
685 Udp4NetVectorExtFree (
686   VOID  *Context
687   );
688 
689 #endif
690