2 Udp6 driver's whole implementation and internal data structures.
4 Copyright (c) 2009 - 2010, 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>
34 #include "Udp6Driver.h"
36 extern EFI_COMPONENT_NAME2_PROTOCOL gUdp6ComponentName2
;
37 extern EFI_COMPONENT_NAME_PROTOCOL gUdp6ComponentName
;
38 extern EFI_SERVICE_BINDING_PROTOCOL mUdp6ServiceBinding
;
39 extern EFI_UDP6_PROTOCOL mUdp6Protocol
;
40 extern UINT16 mUdp6RandomPort
;
43 // Define time out 50 milliseconds
45 #define UDP6_TIMEOUT_INTERVAL (50 * TICKS_PER_MS)
46 #define UDP6_HEADER_SIZE sizeof (EFI_UDP_HEADER)
47 #define UDP6_MAX_DATA_SIZE 65507
48 #define UDP6_PORT_KNOWN 1024
50 #define UDP6_SERVICE_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'p', '6')
51 #define UDP6_INSTANCE_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'p', 'S')
53 #define UDP6_SERVICE_DATA_FROM_THIS(a) \
58 UDP6_SERVICE_DATA_SIGNATURE \
61 #define UDP6_INSTANCE_DATA_FROM_THIS(a) \
66 UDP6_INSTANCE_DATA_SIGNATURE \
69 // Udp6 service contest data
71 typedef struct _UDP6_SERVICE_DATA
{
73 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
74 EFI_HANDLE ImageHandle
;
75 EFI_HANDLE ControllerHandle
;
76 LIST_ENTRY ChildrenList
;
79 EFI_EVENT TimeoutEvent
;
83 typedef struct _UDP6_INSTANCE_DATA
{
86 UDP6_SERVICE_DATA
*Udp6Service
;
87 EFI_UDP6_PROTOCOL Udp6Proto
;
88 EFI_UDP6_CONFIG_DATA ConfigData
;
89 EFI_HANDLE ChildHandle
;
95 LIST_ENTRY RcvdDgramQue
;
96 LIST_ENTRY DeliveredDgramQue
;
99 IP_IO_IP_INFO
*IpInfo
;
101 } UDP6_INSTANCE_DATA
;
103 typedef struct _UDP6_RXDATA_WRAP
{
107 EFI_UDP6_RECEIVE_DATA RxData
;
111 Clean the Udp service context data.
113 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
118 IN OUT UDP6_SERVICE_DATA
*Udp6Service
122 Create the Udp service context data.
124 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
125 @param[in] ImageHandle The image handle of this udp6 driver.
126 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
128 @retval EFI_SUCCESS The udp6 service context data was created and
130 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
131 @retval Others An error condition occurred.
136 IN UDP6_SERVICE_DATA
*Udp6Service
,
137 IN EFI_HANDLE ImageHandle
,
138 IN EFI_HANDLE ControllerHandle
142 Set the Udp6 variable data.
144 @param[in] Udp6Service Udp6 service data.
146 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the
148 @retval other Set variable failed.
152 Udp6SetVariableData (
153 IN UDP6_SERVICE_DATA
*Udp6Service
157 This function cleans the udp instance.
159 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
164 IN OUT UDP6_INSTANCE_DATA
*Instance
168 Clear the variable and free the resource.
170 @param[in, out] Udp6Service Udp6 service data.
174 Udp6ClearVariableData (
175 IN OUT UDP6_SERVICE_DATA
*Udp6Service
179 This function intializes the new created udp instance.
181 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
182 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
187 IN UDP6_SERVICE_DATA
*Udp6Service
,
188 IN OUT UDP6_INSTANCE_DATA
*Instance
192 This function reports the received ICMP error.
194 @param[in] Instance Pointer to the udp instance context data.
198 Udp6ReportIcmpError (
199 IN UDP6_INSTANCE_DATA
*Instance
203 This function copies the current operational settings of this EFI UDPv6 Protocol
204 instance into user-supplied buffers. This function is used optionally to retrieve
205 the operational mode data of underlying networks or drivers.
207 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
208 @param[out] Udp6ConfigData The buffer in which the current UDP configuration
209 data is returned. This parameter is optional and
211 @param[out] Ip6ModeData The buffer in which the current EFI IPv6 Protocol
212 mode data is returned. This parameter is optional
214 @param[out] MnpConfigData The buffer in which the current managed network
215 configuration data is returned. This parameter
216 is optional and may be NULL.
217 @param[out] SnpModeData The buffer in which the simple network mode data
218 is returned. This parameter is optional and may be NULL.
220 @retval EFI_SUCCESS The mode data was read.
221 @retval EFI_NOT_STARTED When Udp6ConfigData is queried, no configuration
222 data is available because this instance has not
224 @retval EFI_INVALID_PARAMETER This is NULL.
230 IN EFI_UDP6_PROTOCOL
*This
,
231 OUT EFI_UDP6_CONFIG_DATA
*Udp6ConfigData OPTIONAL
,
232 OUT EFI_IP6_MODE_DATA
*Ip6ModeData OPTIONAL
,
233 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
234 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
238 This function is used to do the following:
239 Initialize and start this instance of the EFI UDPv6 Protocol.
240 Change the filtering rules and operational parameters.
241 Reset this instance of the EFI UDPv6 Protocol.
243 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
244 @param[in] UdpConfigData Pointer to the buffer to set the configuration
245 data. This parameter is optional and may be NULL.
247 @retval EFI_SUCCESS The configuration settings were set, changed, or
249 @retval EFI_NO_MAPPING When the UdpConifgData.UseAnyStationAddress is set
250 to true and there is no address available for IP6
251 driver to binding source address to this
253 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
255 UdpConfigData.StationAddress is not a valid
256 unicast IPv6 address.
257 UdpConfigData.RemoteAddress is not a valid unicast
258 IPv6 address, if it is not zero.
259 @retval EFI_ALREADY_STARTED The EFI UDPv6 Protocol instance is already
260 started/configured and must be stopped/reset
261 before it can be reconfigured. Only TrafficClass,
262 HopLimit, ReceiveTimeout, and TransmitTimeout can
263 be reconfigured without stopping the current
264 instance of the EFI UDPv6 Protocol.
265 @retval EFI_ACCESS_DENIED UdpConfigData.AllowDuplicatePort is FALSE, and
266 UdpConfigData.StationPort is already used by another
268 @retval EFI_OUT_OF_RESOURCES The EFI UDPv6 Protocol driver cannot allocate
269 memory for this EFI UDPv6 Protocol instance.
270 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred, and
271 this instance was not opened.
277 IN EFI_UDP6_PROTOCOL
*This
,
278 IN EFI_UDP6_CONFIG_DATA
*UdpConfigData OPTIONAL
282 This function places a sending request to this instance of the EFI UDPv6 Protocol,
283 alongside the transmit data that was filled by the user.
285 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
286 @param[in] Token Pointer to the completion token that will be
287 placed into the transmit queue.
289 @retval EFI_SUCCESS The data has been queued for transmission.
290 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
292 @retval EFI_NO_MAPPING The under-layer IPv6 driver was responsible for
293 choosing a source address for this instance, but
294 no source address was available for use.
295 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
296 This is NULL. Token is NULL. Token.Event is NULL.
297 Token.Packet.TxData is NULL.
298 Token.Packet.TxData.FragmentCount is zero.
299 Token.Packet.TxData.DataLength is not equal to the
300 sum of fragment lengths.
302 Token.Packet.TxData.FragmentTable[]
303 .FragmentLength fields is zero.
305 Token.Packet.TxData.FragmentTable[]
306 .FragmentBuffer fields is NULL.
308 Token.Packet.TxData.UdpSessionData.
309 DestinationAddres are not valid unicast IPv6
310 addresses, if the UdpSessionData is not NULL.
311 Token.Packet.TxData.UdpSessionData.
312 DestinationAddres is NULL
313 Token.Packet.TxData.UdpSessionData.
314 DestinatioPort is zero.
315 Token.Packet.TxData.UdpSessionData is
316 NULL and this instance's
317 UdpConfigData.RemoteAddress is unspecified.
318 @retval EFI_ACCESS_DENIED The transmit completion token with the same
319 Token.Event is already in the transmit queue.
320 @retval EFI_NOT_READY The completion token could not be queued because
321 the transmit queue is full.
322 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
323 @retval EFI_NOT_FOUND There is no route to the destination network or
325 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
326 packet size. Or the length of the IP header + UDP
327 header + data length is greater than MTU if
328 DoNotFragment is TRUE.
334 IN EFI_UDP6_PROTOCOL
*This
,
335 IN EFI_UDP6_COMPLETION_TOKEN
*Token
339 This function places a completion token into the receive packet queue. This function
340 is always asynchronous.
342 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
343 @param[in] Token Pointer to a token that is associated with the
344 receive data descriptor.
346 @retval EFI_SUCCESS The receive completion token is cached.
347 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
349 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
350 BOOTP, RARP, etc.) is not finished yet.
351 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
355 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
356 due to a lack of system resources (usually
358 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
359 The EFI UDPv6 Protocol instance has been reset to
361 @retval EFI_ACCESS_DENIED A receive completion token with the same
362 Token.Event is already in the receive queue.
363 @retval EFI_NOT_READY The receive request could not be queued because
364 the receive queue is full.
370 IN EFI_UDP6_PROTOCOL
*This
,
371 IN EFI_UDP6_COMPLETION_TOKEN
*Token
375 This function is used to abort a pending transmit or receive request.
377 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
378 @param[in] Token Pointer to a token that has been issued by
379 EFI_UDP6_PROTOCOL.Transmit() or
380 EFI_UDP6_PROTOCOL.Receive(). This parameter is
381 optional and may be NULL.
383 @retval EFI_SUCCESS The asynchronous I/O request is aborted and
384 Token.Event is signaled. When Token is NULL, all
385 pending requests are aborted and their events are
387 @retval EFI_INVALID_PARAMETER This is NULL.
388 @retval EFI_NOT_STARTED This instance has not been started.
389 @retval EFI_NO_MAPPING When using the default address, configuration
390 (DHCP, BOOTP, RARP, etc.) is not finished yet.
391 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
392 request is not found in the transmit or receive
393 queue. It either completed or was not issued by
394 Transmit() or Receive().
400 IN EFI_UDP6_PROTOCOL
*This
,
401 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
405 This function can be used by network drivers and applications to increase the rate that
406 data packets are moved between the communications device and the transmit/receive queues.
408 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
410 @retval EFI_SUCCESS Incoming or outgoing data was processed.
411 @retval EFI_INVALID_PARAMETER This is NULL.
412 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
413 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or
420 IN EFI_UDP6_PROTOCOL
*This
424 This function is used to enable and disable the multicast group filtering.
426 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
427 @param[in] JoinFlag Set to TRUE to join a multicast group. Set to
428 FALSE to leave one or all multicast groups.
429 @param[in] MulticastAddress Pointer to multicast group address to join or
430 leave. This parameter is optional and may be NULL.
432 @retval EFI_SUCCESS The operation completed successfully.
433 @retval EFI_NOT_STARTED The EFI UDPv6 Protocol instance has not been
435 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
436 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
437 This is NULL. JoinFlag is TRUE and
438 MulticastAddress is NULL. JoinFlag is TRUE and
439 *MulticastAddress is not a valid multicast
441 @retval EFI_ALREADY_STARTED The group address is already in the group table
442 (when JoinFlag is TRUE).
443 @retval EFI_NOT_FOUND The group address is not in the group table (when
445 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
451 IN EFI_UDP6_PROTOCOL
*This
,
453 IN EFI_IPv6_ADDRESS
*MulticastAddress OPTIONAL
457 This function tries to bind the udp instance according to the configured port
460 @param[in] InstanceList Pointer to the head of the list linking the udp
462 @param[in] ConfigData Pointer to the ConfigData of the instance to be
465 @retval EFI_SUCCESS The bound operation completed successfully.
466 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
467 already used by another instance.
468 @retval EFI_OUT_OF_RESOURCES No available port resources.
473 IN LIST_ENTRY
*InstanceList
,
474 IN EFI_UDP6_CONFIG_DATA
*ConfigData
478 This function builds the Ip6 configdata from the Udp6ConfigData.
480 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
481 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
485 Udp6BuildIp6ConfigData (
486 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
487 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
491 This function checks whether the specified Token duplicates with the one in the Map.
493 @param[in] Map Pointer to the NET_MAP.
494 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
496 @param[in] Context Pointer to the Token to be checked.
498 @retval EFI_SUCCESS The Token specified by Context differs from the
500 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
507 IN NET_MAP_ITEM
*Item
,
512 This function removes the specified Token from the TokenMap.
514 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
515 @param[in] Token Pointer to the Token to be removed.
517 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
518 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
523 IN NET_MAP
*TokenMap
,
524 IN EFI_UDP6_COMPLETION_TOKEN
*Token
528 This function is used to check whether the NewConfigData has any un-reconfigurable
529 parameters changed compared to the OldConfigData.
531 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
533 @param[in] NewConfigData Pointer to the new ConfigData.
535 @retval TRUE The instance is reconfigurable according to NewConfigData.
536 @retval FALSE The instance is not reconfigurable according to NewConfigData.
540 Udp6IsReconfigurable (
541 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
542 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
546 This function removes the multicast group specified by Arg from the Map.
548 @param[in] Map Pointer to the NET_MAP.
549 @param[in] Item Pointer to the NET_MAP_ITEM.
550 @param[in] Arg Pointer to the Arg. It is the pointer to a
551 multicast IPv6 Address. This parameter is
552 optional and may be NULL.
554 @retval EFI_SUCCESS The multicast address is removed.
555 @retval EFI_ABORTED The specified multicast address is removed, and the
563 IN NET_MAP_ITEM
*Item
,
564 IN VOID
*Arg OPTIONAL
568 This function validates the TxToken, it returns the error code according to the spec.
570 @param[in] Instance Pointer to the udp instance context data.
571 @param[in] TxToken Pointer to the token to be checked.
573 @retval EFI_SUCCESS The TxToken is valid.
574 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
576 Token.Packet.TxData is NULL.
577 Token.Packet.TxData.FragmentCount is zero.
578 Token.Packet.TxData.DataLength is not equal to the
579 sum of fragment lengths.
581 Token.Packet.TxData.FragmentTable[].FragmentLength
584 Token.Packet.TxData.FragmentTable[].FragmentBuffer
586 UdpSessionData.DestinationAddress are not valid
587 unicast IPv6 addresses if the UdpSessionData is
589 UdpSessionData.DestinationPort and
590 ConfigData.RemotePort are all zero if the
591 UdpSessionData is not NULL.
592 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
597 Udp6ValidateTxToken (
598 IN UDP6_INSTANCE_DATA
*Instance
,
599 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
603 This function is a dummy ext-free function for the NET_BUF created for the output
606 @param[in] Context Pointer to the context data.
611 Udp6NetVectorExtFree (
616 This function calculates the checksum for the Packet, utilizing the pre-calculated
617 pseudo header to reduce overhead.
619 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
620 @param[in] HeadSum Checksum of the pseudo header execpt the length
623 @return The 16-bit checksum of this udp datagram.
633 This function delivers the received datagrams to the specified instance.
635 @param[in] Instance Pointer to the instance context data.
639 Udp6InstanceDeliverDgram (
640 IN UDP6_INSTANCE_DATA
*Instance
644 Cancel Udp6 tokens from the Udp6 instance.
646 @param[in] Instance Pointer to the udp instance context data.
647 @param[in] Token Pointer to the token to be canceled. If NULL, all
648 tokens in this instance will be cancelled.
649 This parameter is optional and may be NULL.
651 @retval EFI_SUCCESS The Token is cancelled.
652 @retval EFI_NOT_FOUND The Token is not found.
656 Udp6InstanceCancelToken (
657 IN UDP6_INSTANCE_DATA
*Instance
,
658 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
662 This function removes all the Wrap datas in the RcvdDgramQue.
664 @param[in] Instance Pointer to the Udp6 Instance.
669 IN UDP6_INSTANCE_DATA
*Instance