2 Udp6 driver's whole implementation and internal data structures.
4 Copyright (c) 2009 - 2014, 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
;
84 typedef struct _UDP6_INSTANCE_DATA
{
87 UDP6_SERVICE_DATA
*Udp6Service
;
88 EFI_UDP6_PROTOCOL Udp6Proto
;
89 EFI_UDP6_CONFIG_DATA ConfigData
;
90 EFI_HANDLE ChildHandle
;
96 LIST_ENTRY RcvdDgramQue
;
97 LIST_ENTRY DeliveredDgramQue
;
100 IP_IO_IP_INFO
*IpInfo
;
102 } UDP6_INSTANCE_DATA
;
104 typedef struct _UDP6_RXDATA_WRAP
{
108 EFI_UDP6_RECEIVE_DATA RxData
;
112 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
113 UINTN NumberOfChildren
;
114 EFI_HANDLE
*ChildHandleBuffer
;
115 } UDP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
;
118 Clean the Udp service context data.
120 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
125 IN OUT UDP6_SERVICE_DATA
*Udp6Service
129 Create the Udp service context data.
131 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
132 @param[in] ImageHandle The image handle of this udp6 driver.
133 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
135 @retval EFI_SUCCESS The udp6 service context data was created and
137 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
138 @retval Others An error condition occurred.
143 IN UDP6_SERVICE_DATA
*Udp6Service
,
144 IN EFI_HANDLE ImageHandle
,
145 IN EFI_HANDLE ControllerHandle
149 This function cleans the udp instance.
151 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
156 IN OUT UDP6_INSTANCE_DATA
*Instance
160 This function intializes the new created udp instance.
162 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
163 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
168 IN UDP6_SERVICE_DATA
*Udp6Service
,
169 IN OUT UDP6_INSTANCE_DATA
*Instance
173 This function reports the received ICMP error.
175 @param[in] Instance Pointer to the udp instance context data.
179 Udp6ReportIcmpError (
180 IN UDP6_INSTANCE_DATA
*Instance
184 This function copies the current operational settings of this EFI UDPv6 Protocol
185 instance into user-supplied buffers. This function is used optionally to retrieve
186 the operational mode data of underlying networks or drivers.
188 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
189 @param[out] Udp6ConfigData The buffer in which the current UDP configuration
190 data is returned. This parameter is optional and
192 @param[out] Ip6ModeData The buffer in which the current EFI IPv6 Protocol
193 mode data is returned. This parameter is optional
195 @param[out] MnpConfigData The buffer in which the current managed network
196 configuration data is returned. This parameter
197 is optional and may be NULL.
198 @param[out] SnpModeData The buffer in which the simple network mode data
199 is returned. This parameter is optional and may be NULL.
201 @retval EFI_SUCCESS The mode data was read.
202 @retval EFI_NOT_STARTED When Udp6ConfigData is queried, no configuration
203 data is available because this instance has not
205 @retval EFI_INVALID_PARAMETER This is NULL.
211 IN EFI_UDP6_PROTOCOL
*This
,
212 OUT EFI_UDP6_CONFIG_DATA
*Udp6ConfigData OPTIONAL
,
213 OUT EFI_IP6_MODE_DATA
*Ip6ModeData OPTIONAL
,
214 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
215 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
219 This function is used to do the following:
220 Initialize and start this instance of the EFI UDPv6 Protocol.
221 Change the filtering rules and operational parameters.
222 Reset this instance of the EFI UDPv6 Protocol.
224 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
225 @param[in] UdpConfigData Pointer to the buffer to set the configuration
226 data. This parameter is optional and may be NULL.
228 @retval EFI_SUCCESS The configuration settings were set, changed, or
230 @retval EFI_NO_MAPPING When the UdpConifgData.UseAnyStationAddress is set
231 to true and there is no address available for IP6
232 driver to binding source address to this
234 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
236 UdpConfigData.StationAddress is not a valid
237 unicast IPv6 address.
238 UdpConfigData.RemoteAddress is not a valid unicast
239 IPv6 address, if it is not zero.
240 @retval EFI_ALREADY_STARTED The EFI UDPv6 Protocol instance is already
241 started/configured and must be stopped/reset
242 before it can be reconfigured. Only TrafficClass,
243 HopLimit, ReceiveTimeout, and TransmitTimeout can
244 be reconfigured without stopping the current
245 instance of the EFI UDPv6 Protocol.
246 @retval EFI_ACCESS_DENIED UdpConfigData.AllowDuplicatePort is FALSE, and
247 UdpConfigData.StationPort is already used by another
249 @retval EFI_OUT_OF_RESOURCES The EFI UDPv6 Protocol driver cannot allocate
250 memory for this EFI UDPv6 Protocol instance.
251 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred, and
252 this instance was not opened.
258 IN EFI_UDP6_PROTOCOL
*This
,
259 IN EFI_UDP6_CONFIG_DATA
*UdpConfigData OPTIONAL
263 This function places a sending request to this instance of the EFI UDPv6 Protocol,
264 alongside the transmit data that was filled by the user.
266 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
267 @param[in] Token Pointer to the completion token that will be
268 placed into the transmit queue.
270 @retval EFI_SUCCESS The data has been queued for transmission.
271 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
273 @retval EFI_NO_MAPPING The under-layer IPv6 driver was responsible for
274 choosing a source address for this instance, but
275 no source address was available for use.
276 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
277 This is NULL. Token is NULL. Token.Event is NULL.
278 Token.Packet.TxData is NULL.
279 Token.Packet.TxData.FragmentCount is zero.
280 Token.Packet.TxData.DataLength is not equal to the
281 sum of fragment lengths.
283 Token.Packet.TxData.FragmentTable[]
284 .FragmentLength fields is zero.
286 Token.Packet.TxData.FragmentTable[]
287 .FragmentBuffer fields is NULL.
289 Token.Packet.TxData.UdpSessionData.
290 DestinationAddres are not valid unicast IPv6
291 addresses, if the UdpSessionData is not NULL.
292 Token.Packet.TxData.UdpSessionData.
293 DestinationAddres is NULL
294 Token.Packet.TxData.UdpSessionData.
295 DestinatioPort is zero.
296 Token.Packet.TxData.UdpSessionData is
297 NULL and this instance's
298 UdpConfigData.RemoteAddress is unspecified.
299 @retval EFI_ACCESS_DENIED The transmit completion token with the same
300 Token.Event is already in the transmit queue.
301 @retval EFI_NOT_READY The completion token could not be queued because
302 the transmit queue is full.
303 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
304 @retval EFI_NOT_FOUND There is no route to the destination network or
306 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
307 packet size. Or the length of the IP header + UDP
308 header + data length is greater than MTU if
309 DoNotFragment is TRUE.
315 IN EFI_UDP6_PROTOCOL
*This
,
316 IN EFI_UDP6_COMPLETION_TOKEN
*Token
320 This function places a completion token into the receive packet queue. This function
321 is always asynchronous.
323 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
324 @param[in] Token Pointer to a token that is associated with the
325 receive data descriptor.
327 @retval EFI_SUCCESS The receive completion token is cached.
328 @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
330 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
331 BOOTP, RARP, etc.) is not finished yet.
332 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
336 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
337 due to a lack of system resources (usually
339 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
340 The EFI UDPv6 Protocol instance has been reset to
342 @retval EFI_ACCESS_DENIED A receive completion token with the same
343 Token.Event is already in the receive queue.
344 @retval EFI_NOT_READY The receive request could not be queued because
345 the receive queue is full.
351 IN EFI_UDP6_PROTOCOL
*This
,
352 IN EFI_UDP6_COMPLETION_TOKEN
*Token
356 This function is used to abort a pending transmit or receive request.
358 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
359 @param[in] Token Pointer to a token that has been issued by
360 EFI_UDP6_PROTOCOL.Transmit() or
361 EFI_UDP6_PROTOCOL.Receive(). This parameter is
362 optional and may be NULL.
364 @retval EFI_SUCCESS The asynchronous I/O request is aborted and
365 Token.Event is signaled. When Token is NULL, all
366 pending requests are aborted and their events are
368 @retval EFI_INVALID_PARAMETER This is NULL.
369 @retval EFI_NOT_STARTED This instance has not been started.
370 @retval EFI_NO_MAPPING When using the default address, configuration
371 (DHCP, BOOTP, RARP, etc.) is not finished yet.
372 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
373 request is not found in the transmit or receive
374 queue. It either completed or was not issued by
375 Transmit() or Receive().
381 IN EFI_UDP6_PROTOCOL
*This
,
382 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
386 This function can be used by network drivers and applications to increase the rate that
387 data packets are moved between the communications device and the transmit/receive queues.
389 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
391 @retval EFI_SUCCESS Incoming or outgoing data was processed.
392 @retval EFI_INVALID_PARAMETER This is NULL.
393 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
394 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or
401 IN EFI_UDP6_PROTOCOL
*This
405 This function is used to enable and disable the multicast group filtering.
407 @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
408 @param[in] JoinFlag Set to TRUE to join a multicast group. Set to
409 FALSE to leave one or all multicast groups.
410 @param[in] MulticastAddress Pointer to multicast group address to join or
411 leave. This parameter is optional and may be NULL.
413 @retval EFI_SUCCESS The operation completed successfully.
414 @retval EFI_NOT_STARTED The EFI UDPv6 Protocol instance has not been
416 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
417 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
418 This is NULL. JoinFlag is TRUE and
419 MulticastAddress is NULL. JoinFlag is TRUE and
420 *MulticastAddress is not a valid multicast
422 @retval EFI_ALREADY_STARTED The group address is already in the group table
423 (when JoinFlag is TRUE).
424 @retval EFI_NOT_FOUND The group address is not in the group table (when
426 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
432 IN EFI_UDP6_PROTOCOL
*This
,
434 IN EFI_IPv6_ADDRESS
*MulticastAddress OPTIONAL
438 This function tries to bind the udp instance according to the configured port
441 @param[in] InstanceList Pointer to the head of the list linking the udp
443 @param[in] ConfigData Pointer to the ConfigData of the instance to be
446 @retval EFI_SUCCESS The bound operation completed successfully.
447 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
448 already used by another instance.
449 @retval EFI_OUT_OF_RESOURCES No available port resources.
454 IN LIST_ENTRY
*InstanceList
,
455 IN EFI_UDP6_CONFIG_DATA
*ConfigData
459 This function builds the Ip6 configdata from the Udp6ConfigData.
461 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
462 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
466 Udp6BuildIp6ConfigData (
467 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
468 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
472 This function checks whether the specified Token duplicates with the one in the Map.
474 @param[in] Map Pointer to the NET_MAP.
475 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
477 @param[in] Context Pointer to the Token to be checked.
479 @retval EFI_SUCCESS The Token specified by Context differs from the
481 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
488 IN NET_MAP_ITEM
*Item
,
493 This function removes the specified Token from the TokenMap.
495 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
496 @param[in] Token Pointer to the Token to be removed.
498 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
499 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
504 IN NET_MAP
*TokenMap
,
505 IN EFI_UDP6_COMPLETION_TOKEN
*Token
509 This function is used to check whether the NewConfigData has any un-reconfigurable
510 parameters changed compared to the OldConfigData.
512 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
514 @param[in] NewConfigData Pointer to the new ConfigData.
516 @retval TRUE The instance is reconfigurable according to NewConfigData.
517 @retval FALSE The instance is not reconfigurable according to NewConfigData.
521 Udp6IsReconfigurable (
522 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
523 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
527 This function removes the multicast group specified by Arg from the Map.
529 @param[in] Map Pointer to the NET_MAP.
530 @param[in] Item Pointer to the NET_MAP_ITEM.
531 @param[in] Arg Pointer to the Arg. It is the pointer to a
532 multicast IPv6 Address. This parameter is
533 optional and may be NULL.
535 @retval EFI_SUCCESS The multicast address is removed.
536 @retval EFI_ABORTED The specified multicast address is removed, and the
544 IN NET_MAP_ITEM
*Item
,
545 IN VOID
*Arg OPTIONAL
549 This function validates the TxToken, it returns the error code according to the spec.
551 @param[in] Instance Pointer to the udp instance context data.
552 @param[in] TxToken Pointer to the token to be checked.
554 @retval EFI_SUCCESS The TxToken is valid.
555 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
557 Token.Packet.TxData is NULL.
558 Token.Packet.TxData.FragmentCount is zero.
559 Token.Packet.TxData.DataLength is not equal to the
560 sum of fragment lengths.
562 Token.Packet.TxData.FragmentTable[].FragmentLength
565 Token.Packet.TxData.FragmentTable[].FragmentBuffer
567 UdpSessionData.DestinationAddress are not valid
568 unicast IPv6 addresses if the UdpSessionData is
570 UdpSessionData.DestinationPort and
571 ConfigData.RemotePort are all zero if the
572 UdpSessionData is not NULL.
573 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
578 Udp6ValidateTxToken (
579 IN UDP6_INSTANCE_DATA
*Instance
,
580 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
584 This function is a dummy ext-free function for the NET_BUF created for the output
587 @param[in] Context Pointer to the context data.
592 Udp6NetVectorExtFree (
597 This function calculates the checksum for the Packet, utilizing the pre-calculated
598 pseudo header to reduce overhead.
600 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
601 @param[in] HeadSum Checksum of the pseudo header execpt the length
604 @return The 16-bit checksum of this udp datagram.
614 This function delivers the received datagrams to the specified instance.
616 @param[in] Instance Pointer to the instance context data.
620 Udp6InstanceDeliverDgram (
621 IN UDP6_INSTANCE_DATA
*Instance
625 Cancel Udp6 tokens from the Udp6 instance.
627 @param[in] Instance Pointer to the udp instance context data.
628 @param[in] Token Pointer to the token to be canceled. If NULL, all
629 tokens in this instance will be cancelled.
630 This parameter is optional and may be NULL.
632 @retval EFI_SUCCESS The Token is cancelled.
633 @retval EFI_NOT_FOUND The Token is not found.
637 Udp6InstanceCancelToken (
638 IN UDP6_INSTANCE_DATA
*Instance
,
639 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
643 This function removes all the Wrap datas in the RcvdDgramQue.
645 @param[in] Instance Pointer to the Udp6 Instance.
650 IN UDP6_INSTANCE_DATA
*Instance