2 Udp6 driver's whole implementation and internal data structures.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Protocol/Ip6.h>
16 #include <Protocol/Udp6.h>
18 #include <Library/IpIoLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/UefiRuntimeServicesTableLib.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/DpcLib.h>
27 #include <Library/PrintLib.h>
29 #include "Udp6Driver.h"
31 extern EFI_COMPONENT_NAME2_PROTOCOL gUdp6ComponentName2
;
32 extern EFI_COMPONENT_NAME_PROTOCOL gUdp6ComponentName
;
33 extern EFI_UNICODE_STRING_TABLE
*gUdp6ControllerNameTable
;
34 extern EFI_SERVICE_BINDING_PROTOCOL mUdp6ServiceBinding
;
35 extern EFI_UDP6_PROTOCOL mUdp6Protocol
;
36 extern UINT16 mUdp6RandomPort
;
39 // Define time out 50 milliseconds
41 #define UDP6_TIMEOUT_INTERVAL (50 * TICKS_PER_MS)
42 #define UDP6_HEADER_SIZE sizeof (EFI_UDP_HEADER)
43 #define UDP6_MAX_DATA_SIZE 65507
44 #define UDP6_PORT_KNOWN 1024
46 #define UDP6_SERVICE_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'p', '6')
47 #define UDP6_INSTANCE_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'p', 'S')
49 #define UDP6_SERVICE_DATA_FROM_THIS(a) \
54 UDP6_SERVICE_DATA_SIGNATURE \
57 #define UDP6_INSTANCE_DATA_FROM_THIS(a) \
62 UDP6_INSTANCE_DATA_SIGNATURE \
65 // Udp6 service contest data
67 typedef struct _UDP6_SERVICE_DATA
{
69 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
70 EFI_HANDLE ImageHandle
;
71 EFI_HANDLE ControllerHandle
;
72 LIST_ENTRY ChildrenList
;
75 EFI_EVENT TimeoutEvent
;
78 typedef struct _UDP6_INSTANCE_DATA
{
81 UDP6_SERVICE_DATA
*Udp6Service
;
82 EFI_UDP6_PROTOCOL Udp6Proto
;
83 EFI_UDP6_CONFIG_DATA ConfigData
;
84 EFI_HANDLE ChildHandle
;
90 LIST_ENTRY RcvdDgramQue
;
91 LIST_ENTRY DeliveredDgramQue
;
94 IP_IO_IP_INFO
*IpInfo
;
98 typedef struct _UDP6_RXDATA_WRAP
{
102 EFI_UDP6_RECEIVE_DATA RxData
;
106 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
107 UINTN NumberOfChildren
;
108 EFI_HANDLE
*ChildHandleBuffer
;
109 } UDP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
;
112 Clean the Udp service context data.
114 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
119 IN OUT UDP6_SERVICE_DATA
*Udp6Service
123 Create the Udp service context data.
125 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
126 @param[in] ImageHandle The image handle of this udp6 driver.
127 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
129 @retval EFI_SUCCESS The udp6 service context data was created and
131 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
132 @retval Others An error condition occurred.
137 IN UDP6_SERVICE_DATA
*Udp6Service
,
138 IN EFI_HANDLE ImageHandle
,
139 IN EFI_HANDLE ControllerHandle
143 This function cleans the udp instance.
145 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
150 IN OUT UDP6_INSTANCE_DATA
*Instance
154 This function intializes the new created udp instance.
156 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
157 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
162 IN UDP6_SERVICE_DATA
*Udp6Service
,
163 IN OUT UDP6_INSTANCE_DATA
*Instance
167 This function reports the received ICMP error.
169 @param[in] Instance Pointer to the udp instance context data.
173 Udp6ReportIcmpError (
174 IN UDP6_INSTANCE_DATA
*Instance
178 This function copies the current operational settings of this EFI UDPv6 Protocol
179 instance into user-supplied buffers. This function is used optionally to retrieve
180 the operational mode data of underlying networks or drivers.
182 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
183 @param[out] Udp6ConfigData The buffer in which the current UDP configuration
184 data is returned. This parameter is optional and
186 @param[out] Ip6ModeData The buffer in which the current EFI IPv6 Protocol
187 mode data is returned. This parameter is optional
189 @param[out] MnpConfigData The buffer in which the current managed network
190 configuration data is returned. This parameter
191 is optional and may be NULL.
192 @param[out] SnpModeData The buffer in which the simple network mode data
193 is returned. This parameter is optional and may be NULL.
195 @retval EFI_SUCCESS The mode data was read.
196 @retval EFI_NOT_STARTED When Udp6ConfigData is queried, no configuration
197 data is available because this instance has not
199 @retval EFI_INVALID_PARAMETER This is NULL.
205 IN EFI_UDP6_PROTOCOL
*This
,
206 OUT EFI_UDP6_CONFIG_DATA
*Udp6ConfigData OPTIONAL
,
207 OUT EFI_IP6_MODE_DATA
*Ip6ModeData OPTIONAL
,
208 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
209 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
213 This function is used to do the following:
214 Initialize and start this instance of the EFI UDPv6 Protocol.
215 Change the filtering rules and operational parameters.
216 Reset this instance of the EFI UDPv6 Protocol.
218 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
219 @param[in] UdpConfigData Pointer to the buffer to set the configuration
220 data. This parameter is optional and may be NULL.
222 @retval EFI_SUCCESS The configuration settings were set, changed, or
224 @retval EFI_NO_MAPPING When the UdpConifgData.UseAnyStationAddress is set
225 to true and there is no address available for IP6
226 driver to binding source address to this
228 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
230 UdpConfigData.StationAddress is not a valid
231 unicast IPv6 address.
232 UdpConfigData.RemoteAddress is not a valid unicast
233 IPv6 address, if it is not zero.
234 @retval EFI_ALREADY_STARTED The EFI UDPv6 Protocol instance is already
235 started/configured and must be stopped/reset
236 before it can be reconfigured. Only TrafficClass,
237 HopLimit, ReceiveTimeout, and TransmitTimeout can
238 be reconfigured without stopping the current
239 instance of the EFI UDPv6 Protocol.
240 @retval EFI_ACCESS_DENIED UdpConfigData.AllowDuplicatePort is FALSE, and
241 UdpConfigData.StationPort is already used by another
243 @retval EFI_OUT_OF_RESOURCES The EFI UDPv6 Protocol driver cannot allocate
244 memory for this EFI UDPv6 Protocol instance.
245 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred, and
246 this instance was not opened.
252 IN EFI_UDP6_PROTOCOL
*This
,
253 IN EFI_UDP6_CONFIG_DATA
*UdpConfigData OPTIONAL
257 This function places a sending request to this instance of the EFI UDPv6 Protocol,
258 alongside the transmit data that was filled by the user.
260 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
261 @param[in] Token Pointer to the completion token that will be
262 placed into the transmit queue.
264 @retval EFI_SUCCESS The data has been queued for transmission.
265 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
267 @retval EFI_NO_MAPPING The under-layer IPv6 driver was responsible for
268 choosing a source address for this instance, but
269 no source address was available for use.
270 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
271 This is NULL. Token is NULL. Token.Event is NULL.
272 Token.Packet.TxData is NULL.
273 Token.Packet.TxData.FragmentCount is zero.
274 Token.Packet.TxData.DataLength is not equal to the
275 sum of fragment lengths.
277 Token.Packet.TxData.FragmentTable[]
278 .FragmentLength fields is zero.
280 Token.Packet.TxData.FragmentTable[]
281 .FragmentBuffer fields is NULL.
283 Token.Packet.TxData.UdpSessionData.
284 DestinationAddres are not valid unicast IPv6
285 addresses, if the UdpSessionData is not NULL.
286 Token.Packet.TxData.UdpSessionData.
287 DestinationAddres is NULL
288 Token.Packet.TxData.UdpSessionData.
289 DestinatioPort is zero.
290 Token.Packet.TxData.UdpSessionData is
291 NULL and this instance's
292 UdpConfigData.RemoteAddress is unspecified.
293 @retval EFI_ACCESS_DENIED The transmit completion token with the same
294 Token.Event is already in the transmit queue.
295 @retval EFI_NOT_READY The completion token could not be queued because
296 the transmit queue is full.
297 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
298 @retval EFI_NOT_FOUND There is no route to the destination network or
300 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
301 packet size. Or the length of the IP header + UDP
302 header + data length is greater than MTU if
303 DoNotFragment is TRUE.
309 IN EFI_UDP6_PROTOCOL
*This
,
310 IN EFI_UDP6_COMPLETION_TOKEN
*Token
314 This function places a completion token into the receive packet queue. This function
315 is always asynchronous.
317 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
318 @param[in] Token Pointer to a token that is associated with the
319 receive data descriptor.
321 @retval EFI_SUCCESS The receive completion token is cached.
322 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
324 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
325 BOOTP, RARP, etc.) is not finished yet.
326 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
330 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
331 due to a lack of system resources (usually
333 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
334 The EFI UDPv6 Protocol instance has been reset to
336 @retval EFI_ACCESS_DENIED A receive completion token with the same
337 Token.Event is already in the receive queue.
338 @retval EFI_NOT_READY The receive request could not be queued because
339 the receive queue is full.
345 IN EFI_UDP6_PROTOCOL
*This
,
346 IN EFI_UDP6_COMPLETION_TOKEN
*Token
350 This function is used to abort a pending transmit or receive request.
352 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
353 @param[in] Token Pointer to a token that has been issued by
354 EFI_UDP6_PROTOCOL.Transmit() or
355 EFI_UDP6_PROTOCOL.Receive(). This parameter is
356 optional and may be NULL.
358 @retval EFI_SUCCESS The asynchronous I/O request is aborted and
359 Token.Event is signaled. When Token is NULL, all
360 pending requests are aborted and their events are
362 @retval EFI_INVALID_PARAMETER This is NULL.
363 @retval EFI_NOT_STARTED This instance has not been started.
364 @retval EFI_NO_MAPPING When using the default address, configuration
365 (DHCP, BOOTP, RARP, etc.) is not finished yet.
366 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
367 request is not found in the transmit or receive
368 queue. It either completed or was not issued by
369 Transmit() or Receive().
375 IN EFI_UDP6_PROTOCOL
*This
,
376 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
380 This function can be used by network drivers and applications to increase the rate that
381 data packets are moved between the communications device and the transmit/receive queues.
383 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
385 @retval EFI_SUCCESS Incoming or outgoing data was processed.
386 @retval EFI_INVALID_PARAMETER This is NULL.
387 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
388 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or
395 IN EFI_UDP6_PROTOCOL
*This
399 This function is used to enable and disable the multicast group filtering.
401 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
402 @param[in] JoinFlag Set to TRUE to join a multicast group. Set to
403 FALSE to leave one or all multicast groups.
404 @param[in] MulticastAddress Pointer to multicast group address to join or
405 leave. This parameter is optional and may be NULL.
407 @retval EFI_SUCCESS The operation completed successfully.
408 @retval EFI_NOT_STARTED The EFI UDPv6 Protocol instance has not been
410 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
411 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
412 This is NULL. JoinFlag is TRUE and
413 MulticastAddress is NULL. JoinFlag is TRUE and
414 *MulticastAddress is not a valid multicast
416 @retval EFI_ALREADY_STARTED The group address is already in the group table
417 (when JoinFlag is TRUE).
418 @retval EFI_NOT_FOUND The group address is not in the group table (when
420 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
426 IN EFI_UDP6_PROTOCOL
*This
,
428 IN EFI_IPv6_ADDRESS
*MulticastAddress OPTIONAL
432 This function tries to bind the udp instance according to the configured port
435 @param[in] InstanceList Pointer to the head of the list linking the udp
437 @param[in] ConfigData Pointer to the ConfigData of the instance to be
440 @retval EFI_SUCCESS The bound operation completed successfully.
441 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
442 already used by another instance.
443 @retval EFI_OUT_OF_RESOURCES No available port resources.
448 IN LIST_ENTRY
*InstanceList
,
449 IN EFI_UDP6_CONFIG_DATA
*ConfigData
453 This function builds the Ip6 configdata from the Udp6ConfigData.
455 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
456 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
460 Udp6BuildIp6ConfigData (
461 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
462 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
466 This function checks whether the specified Token duplicates with the one in the Map.
468 @param[in] Map Pointer to the NET_MAP.
469 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
471 @param[in] Context Pointer to the Token to be checked.
473 @retval EFI_SUCCESS The Token specified by Context differs from the
475 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
482 IN NET_MAP_ITEM
*Item
,
487 This function removes the specified Token from the TokenMap.
489 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
490 @param[in] Token Pointer to the Token to be removed.
492 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
493 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
498 IN NET_MAP
*TokenMap
,
499 IN EFI_UDP6_COMPLETION_TOKEN
*Token
503 This function is used to check whether the NewConfigData has any un-reconfigurable
504 parameters changed compared to the OldConfigData.
506 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
508 @param[in] NewConfigData Pointer to the new ConfigData.
510 @retval TRUE The instance is reconfigurable according to NewConfigData.
511 @retval FALSE The instance is not reconfigurable according to NewConfigData.
515 Udp6IsReconfigurable (
516 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
517 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
521 This function removes the multicast group specified by Arg from the Map.
523 @param[in] Map Pointer to the NET_MAP.
524 @param[in] Item Pointer to the NET_MAP_ITEM.
525 @param[in] Arg Pointer to the Arg. It is the pointer to a
526 multicast IPv6 Address. This parameter is
527 optional and may be NULL.
529 @retval EFI_SUCCESS The multicast address is removed.
530 @retval EFI_ABORTED The specified multicast address is removed, and the
538 IN NET_MAP_ITEM
*Item
,
539 IN VOID
*Arg OPTIONAL
543 This function validates the TxToken, it returns the error code according to the spec.
545 @param[in] Instance Pointer to the udp instance context data.
546 @param[in] TxToken Pointer to the token to be checked.
548 @retval EFI_SUCCESS The TxToken is valid.
549 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
551 Token.Packet.TxData is NULL.
552 Token.Packet.TxData.FragmentCount is zero.
553 Token.Packet.TxData.DataLength is not equal to the
554 sum of fragment lengths.
556 Token.Packet.TxData.FragmentTable[].FragmentLength
559 Token.Packet.TxData.FragmentTable[].FragmentBuffer
561 UdpSessionData.DestinationAddress are not valid
562 unicast IPv6 addresses if the UdpSessionData is
564 UdpSessionData.DestinationPort and
565 ConfigData.RemotePort are all zero if the
566 UdpSessionData is not NULL.
567 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
572 Udp6ValidateTxToken (
573 IN UDP6_INSTANCE_DATA
*Instance
,
574 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
578 This function is a dummy ext-free function for the NET_BUF created for the output
581 @param[in] Context Pointer to the context data.
586 Udp6NetVectorExtFree (
591 This function calculates the checksum for the Packet, utilizing the pre-calculated
592 pseudo header to reduce overhead.
594 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
595 @param[in] HeadSum Checksum of the pseudo header execpt the length
598 @return The 16-bit checksum of this udp datagram.
608 This function delivers the received datagrams to the specified instance.
610 @param[in] Instance Pointer to the instance context data.
614 Udp6InstanceDeliverDgram (
615 IN UDP6_INSTANCE_DATA
*Instance
619 Cancel Udp6 tokens from the Udp6 instance.
621 @param[in] Instance Pointer to the udp instance context data.
622 @param[in] Token Pointer to the token to be canceled. If NULL, all
623 tokens in this instance will be cancelled.
624 This parameter is optional and may be NULL.
626 @retval EFI_SUCCESS The Token is cancelled.
627 @retval EFI_NOT_FOUND The Token is not found.
631 Udp6InstanceCancelToken (
632 IN UDP6_INSTANCE_DATA
*Instance
,
633 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
637 This function removes all the Wrap datas in the RcvdDgramQue.
639 @param[in] Instance Pointer to the Udp6 Instance.
644 IN UDP6_INSTANCE_DATA
*Instance