2 Udp6 driver's whole implementation and internal data structures.
4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/Ip6.h>
22 #include <Protocol/Udp6.h>
24 #include <Library/IpIoLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiRuntimeServicesTableLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/BaseLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/DpcLib.h>
33 #include <Library/PrintLib.h>
35 #include "Udp6Driver.h"
37 extern EFI_COMPONENT_NAME2_PROTOCOL gUdp6ComponentName2
;
38 extern EFI_COMPONENT_NAME_PROTOCOL gUdp6ComponentName
;
39 extern EFI_UNICODE_STRING_TABLE
*gUdp6ControllerNameTable
;
40 extern EFI_SERVICE_BINDING_PROTOCOL mUdp6ServiceBinding
;
41 extern EFI_UDP6_PROTOCOL mUdp6Protocol
;
42 extern UINT16 mUdp6RandomPort
;
45 // Define time out 50 milliseconds
47 #define UDP6_TIMEOUT_INTERVAL (50 * TICKS_PER_MS)
48 #define UDP6_HEADER_SIZE sizeof (EFI_UDP_HEADER)
49 #define UDP6_MAX_DATA_SIZE 65507
50 #define UDP6_PORT_KNOWN 1024
52 #define UDP6_SERVICE_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'p', '6')
53 #define UDP6_INSTANCE_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'p', 'S')
55 #define UDP6_SERVICE_DATA_FROM_THIS(a) \
60 UDP6_SERVICE_DATA_SIGNATURE \
63 #define UDP6_INSTANCE_DATA_FROM_THIS(a) \
68 UDP6_INSTANCE_DATA_SIGNATURE \
71 // Udp6 service contest data
73 typedef struct _UDP6_SERVICE_DATA
{
75 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
76 EFI_HANDLE ImageHandle
;
77 EFI_HANDLE ControllerHandle
;
78 LIST_ENTRY ChildrenList
;
81 EFI_EVENT TimeoutEvent
;
85 typedef struct _UDP6_INSTANCE_DATA
{
88 UDP6_SERVICE_DATA
*Udp6Service
;
89 EFI_UDP6_PROTOCOL Udp6Proto
;
90 EFI_UDP6_CONFIG_DATA ConfigData
;
91 EFI_HANDLE ChildHandle
;
97 LIST_ENTRY RcvdDgramQue
;
98 LIST_ENTRY DeliveredDgramQue
;
100 EFI_STATUS IcmpError
;
101 IP_IO_IP_INFO
*IpInfo
;
103 } UDP6_INSTANCE_DATA
;
105 typedef struct _UDP6_RXDATA_WRAP
{
109 EFI_UDP6_RECEIVE_DATA RxData
;
113 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
114 UINTN NumberOfChildren
;
115 EFI_HANDLE
*ChildHandleBuffer
;
116 } UDP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
;
119 Clean the Udp service context data.
121 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
126 IN OUT UDP6_SERVICE_DATA
*Udp6Service
130 Create the Udp service context data.
132 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
133 @param[in] ImageHandle The image handle of this udp6 driver.
134 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
136 @retval EFI_SUCCESS The udp6 service context data was created and
138 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
139 @retval Others An error condition occurred.
144 IN UDP6_SERVICE_DATA
*Udp6Service
,
145 IN EFI_HANDLE ImageHandle
,
146 IN EFI_HANDLE ControllerHandle
150 Set the Udp6 variable data.
152 @param[in] Udp6Service Udp6 service data.
154 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the
156 @retval other Set variable failed.
160 Udp6SetVariableData (
161 IN UDP6_SERVICE_DATA
*Udp6Service
165 This function cleans the udp instance.
167 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
172 IN OUT UDP6_INSTANCE_DATA
*Instance
176 Clear the variable and free the resource.
178 @param[in, out] Udp6Service Udp6 service data.
182 Udp6ClearVariableData (
183 IN OUT UDP6_SERVICE_DATA
*Udp6Service
187 This function intializes the new created udp instance.
189 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
190 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
195 IN UDP6_SERVICE_DATA
*Udp6Service
,
196 IN OUT UDP6_INSTANCE_DATA
*Instance
200 This function reports the received ICMP error.
202 @param[in] Instance Pointer to the udp instance context data.
206 Udp6ReportIcmpError (
207 IN UDP6_INSTANCE_DATA
*Instance
211 This function copies the current operational settings of this EFI UDPv6 Protocol
212 instance into user-supplied buffers. This function is used optionally to retrieve
213 the operational mode data of underlying networks or drivers.
215 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
216 @param[out] Udp6ConfigData The buffer in which the current UDP configuration
217 data is returned. This parameter is optional and
219 @param[out] Ip6ModeData The buffer in which the current EFI IPv6 Protocol
220 mode data is returned. This parameter is optional
222 @param[out] MnpConfigData The buffer in which the current managed network
223 configuration data is returned. This parameter
224 is optional and may be NULL.
225 @param[out] SnpModeData The buffer in which the simple network mode data
226 is returned. This parameter is optional and may be NULL.
228 @retval EFI_SUCCESS The mode data was read.
229 @retval EFI_NOT_STARTED When Udp6ConfigData is queried, no configuration
230 data is available because this instance has not
232 @retval EFI_INVALID_PARAMETER This is NULL.
238 IN EFI_UDP6_PROTOCOL
*This
,
239 OUT EFI_UDP6_CONFIG_DATA
*Udp6ConfigData OPTIONAL
,
240 OUT EFI_IP6_MODE_DATA
*Ip6ModeData OPTIONAL
,
241 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
242 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
246 This function is used to do the following:
247 Initialize and start this instance of the EFI UDPv6 Protocol.
248 Change the filtering rules and operational parameters.
249 Reset this instance of the EFI UDPv6 Protocol.
251 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
252 @param[in] UdpConfigData Pointer to the buffer to set the configuration
253 data. This parameter is optional and may be NULL.
255 @retval EFI_SUCCESS The configuration settings were set, changed, or
257 @retval EFI_NO_MAPPING When the UdpConifgData.UseAnyStationAddress is set
258 to true and there is no address available for IP6
259 driver to binding source address to this
261 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
263 UdpConfigData.StationAddress is not a valid
264 unicast IPv6 address.
265 UdpConfigData.RemoteAddress is not a valid unicast
266 IPv6 address, if it is not zero.
267 @retval EFI_ALREADY_STARTED The EFI UDPv6 Protocol instance is already
268 started/configured and must be stopped/reset
269 before it can be reconfigured. Only TrafficClass,
270 HopLimit, ReceiveTimeout, and TransmitTimeout can
271 be reconfigured without stopping the current
272 instance of the EFI UDPv6 Protocol.
273 @retval EFI_ACCESS_DENIED UdpConfigData.AllowDuplicatePort is FALSE, and
274 UdpConfigData.StationPort is already used by another
276 @retval EFI_OUT_OF_RESOURCES The EFI UDPv6 Protocol driver cannot allocate
277 memory for this EFI UDPv6 Protocol instance.
278 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred, and
279 this instance was not opened.
285 IN EFI_UDP6_PROTOCOL
*This
,
286 IN EFI_UDP6_CONFIG_DATA
*UdpConfigData OPTIONAL
290 This function places a sending request to this instance of the EFI UDPv6 Protocol,
291 alongside the transmit data that was filled by the user.
293 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
294 @param[in] Token Pointer to the completion token that will be
295 placed into the transmit queue.
297 @retval EFI_SUCCESS The data has been queued for transmission.
298 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
300 @retval EFI_NO_MAPPING The under-layer IPv6 driver was responsible for
301 choosing a source address for this instance, but
302 no source address was available for use.
303 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
304 This is NULL. Token is NULL. Token.Event is NULL.
305 Token.Packet.TxData is NULL.
306 Token.Packet.TxData.FragmentCount is zero.
307 Token.Packet.TxData.DataLength is not equal to the
308 sum of fragment lengths.
310 Token.Packet.TxData.FragmentTable[]
311 .FragmentLength fields is zero.
313 Token.Packet.TxData.FragmentTable[]
314 .FragmentBuffer fields is NULL.
316 Token.Packet.TxData.UdpSessionData.
317 DestinationAddres are not valid unicast IPv6
318 addresses, if the UdpSessionData is not NULL.
319 Token.Packet.TxData.UdpSessionData.
320 DestinationAddres is NULL
321 Token.Packet.TxData.UdpSessionData.
322 DestinatioPort is zero.
323 Token.Packet.TxData.UdpSessionData is
324 NULL and this instance's
325 UdpConfigData.RemoteAddress is unspecified.
326 @retval EFI_ACCESS_DENIED The transmit completion token with the same
327 Token.Event is already in the transmit queue.
328 @retval EFI_NOT_READY The completion token could not be queued because
329 the transmit queue is full.
330 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
331 @retval EFI_NOT_FOUND There is no route to the destination network or
333 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
334 packet size. Or the length of the IP header + UDP
335 header + data length is greater than MTU if
336 DoNotFragment is TRUE.
342 IN EFI_UDP6_PROTOCOL
*This
,
343 IN EFI_UDP6_COMPLETION_TOKEN
*Token
347 This function places a completion token into the receive packet queue. This function
348 is always asynchronous.
350 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
351 @param[in] Token Pointer to a token that is associated with the
352 receive data descriptor.
354 @retval EFI_SUCCESS The receive completion token is cached.
355 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
357 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
358 BOOTP, RARP, etc.) is not finished yet.
359 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
363 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
364 due to a lack of system resources (usually
366 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
367 The EFI UDPv6 Protocol instance has been reset to
369 @retval EFI_ACCESS_DENIED A receive completion token with the same
370 Token.Event is already in the receive queue.
371 @retval EFI_NOT_READY The receive request could not be queued because
372 the receive queue is full.
378 IN EFI_UDP6_PROTOCOL
*This
,
379 IN EFI_UDP6_COMPLETION_TOKEN
*Token
383 This function is used to abort a pending transmit or receive request.
385 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
386 @param[in] Token Pointer to a token that has been issued by
387 EFI_UDP6_PROTOCOL.Transmit() or
388 EFI_UDP6_PROTOCOL.Receive(). This parameter is
389 optional and may be NULL.
391 @retval EFI_SUCCESS The asynchronous I/O request is aborted and
392 Token.Event is signaled. When Token is NULL, all
393 pending requests are aborted and their events are
395 @retval EFI_INVALID_PARAMETER This is NULL.
396 @retval EFI_NOT_STARTED This instance has not been started.
397 @retval EFI_NO_MAPPING When using the default address, configuration
398 (DHCP, BOOTP, RARP, etc.) is not finished yet.
399 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
400 request is not found in the transmit or receive
401 queue. It either completed or was not issued by
402 Transmit() or Receive().
408 IN EFI_UDP6_PROTOCOL
*This
,
409 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
413 This function can be used by network drivers and applications to increase the rate that
414 data packets are moved between the communications device and the transmit/receive queues.
416 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
418 @retval EFI_SUCCESS Incoming or outgoing data was processed.
419 @retval EFI_INVALID_PARAMETER This is NULL.
420 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
421 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or
428 IN EFI_UDP6_PROTOCOL
*This
432 This function is used to enable and disable the multicast group filtering.
434 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
435 @param[in] JoinFlag Set to TRUE to join a multicast group. Set to
436 FALSE to leave one or all multicast groups.
437 @param[in] MulticastAddress Pointer to multicast group address to join or
438 leave. This parameter is optional and may be NULL.
440 @retval EFI_SUCCESS The operation completed successfully.
441 @retval EFI_NOT_STARTED The EFI UDPv6 Protocol instance has not been
443 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
444 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
445 This is NULL. JoinFlag is TRUE and
446 MulticastAddress is NULL. JoinFlag is TRUE and
447 *MulticastAddress is not a valid multicast
449 @retval EFI_ALREADY_STARTED The group address is already in the group table
450 (when JoinFlag is TRUE).
451 @retval EFI_NOT_FOUND The group address is not in the group table (when
453 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
459 IN EFI_UDP6_PROTOCOL
*This
,
461 IN EFI_IPv6_ADDRESS
*MulticastAddress OPTIONAL
465 This function tries to bind the udp instance according to the configured port
468 @param[in] InstanceList Pointer to the head of the list linking the udp
470 @param[in] ConfigData Pointer to the ConfigData of the instance to be
473 @retval EFI_SUCCESS The bound operation completed successfully.
474 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
475 already used by another instance.
476 @retval EFI_OUT_OF_RESOURCES No available port resources.
481 IN LIST_ENTRY
*InstanceList
,
482 IN EFI_UDP6_CONFIG_DATA
*ConfigData
486 This function builds the Ip6 configdata from the Udp6ConfigData.
488 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
489 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
493 Udp6BuildIp6ConfigData (
494 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
495 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
499 This function checks whether the specified Token duplicates with the one in the Map.
501 @param[in] Map Pointer to the NET_MAP.
502 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
504 @param[in] Context Pointer to the Token to be checked.
506 @retval EFI_SUCCESS The Token specified by Context differs from the
508 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
515 IN NET_MAP_ITEM
*Item
,
520 This function removes the specified Token from the TokenMap.
522 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
523 @param[in] Token Pointer to the Token to be removed.
525 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
526 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
531 IN NET_MAP
*TokenMap
,
532 IN EFI_UDP6_COMPLETION_TOKEN
*Token
536 This function is used to check whether the NewConfigData has any un-reconfigurable
537 parameters changed compared to the OldConfigData.
539 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
541 @param[in] NewConfigData Pointer to the new ConfigData.
543 @retval TRUE The instance is reconfigurable according to NewConfigData.
544 @retval FALSE The instance is not reconfigurable according to NewConfigData.
548 Udp6IsReconfigurable (
549 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
550 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
554 This function removes the multicast group specified by Arg from the Map.
556 @param[in] Map Pointer to the NET_MAP.
557 @param[in] Item Pointer to the NET_MAP_ITEM.
558 @param[in] Arg Pointer to the Arg. It is the pointer to a
559 multicast IPv6 Address. This parameter is
560 optional and may be NULL.
562 @retval EFI_SUCCESS The multicast address is removed.
563 @retval EFI_ABORTED The specified multicast address is removed, and the
571 IN NET_MAP_ITEM
*Item
,
572 IN VOID
*Arg OPTIONAL
576 This function validates the TxToken, it returns the error code according to the spec.
578 @param[in] Instance Pointer to the udp instance context data.
579 @param[in] TxToken Pointer to the token to be checked.
581 @retval EFI_SUCCESS The TxToken is valid.
582 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
584 Token.Packet.TxData is NULL.
585 Token.Packet.TxData.FragmentCount is zero.
586 Token.Packet.TxData.DataLength is not equal to the
587 sum of fragment lengths.
589 Token.Packet.TxData.FragmentTable[].FragmentLength
592 Token.Packet.TxData.FragmentTable[].FragmentBuffer
594 UdpSessionData.DestinationAddress are not valid
595 unicast IPv6 addresses if the UdpSessionData is
597 UdpSessionData.DestinationPort and
598 ConfigData.RemotePort are all zero if the
599 UdpSessionData is not NULL.
600 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
605 Udp6ValidateTxToken (
606 IN UDP6_INSTANCE_DATA
*Instance
,
607 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
611 This function is a dummy ext-free function for the NET_BUF created for the output
614 @param[in] Context Pointer to the context data.
619 Udp6NetVectorExtFree (
624 This function calculates the checksum for the Packet, utilizing the pre-calculated
625 pseudo header to reduce overhead.
627 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
628 @param[in] HeadSum Checksum of the pseudo header execpt the length
631 @return The 16-bit checksum of this udp datagram.
641 This function delivers the received datagrams to the specified instance.
643 @param[in] Instance Pointer to the instance context data.
647 Udp6InstanceDeliverDgram (
648 IN UDP6_INSTANCE_DATA
*Instance
652 Cancel Udp6 tokens from the Udp6 instance.
654 @param[in] Instance Pointer to the udp instance context data.
655 @param[in] Token Pointer to the token to be canceled. If NULL, all
656 tokens in this instance will be cancelled.
657 This parameter is optional and may be NULL.
659 @retval EFI_SUCCESS The Token is cancelled.
660 @retval EFI_NOT_FOUND The Token is not found.
664 Udp6InstanceCancelToken (
665 IN UDP6_INSTANCE_DATA
*Instance
,
666 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
670 This function removes all the Wrap datas in the RcvdDgramQue.
672 @param[in] Instance Pointer to the Udp6 Instance.
677 IN UDP6_INSTANCE_DATA
*Instance