1 | /** @file
|
---|
2 | Contains all EFI_UDP6_PROTOCOL interfaces.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "Udp6Impl.h"
|
---|
11 |
|
---|
12 | EFI_UDP6_PROTOCOL mUdp6Protocol = {
|
---|
13 | Udp6GetModeData,
|
---|
14 | Udp6Configure,
|
---|
15 | Udp6Groups,
|
---|
16 | Udp6Transmit,
|
---|
17 | Udp6Receive,
|
---|
18 | Udp6Cancel,
|
---|
19 | Udp6Poll
|
---|
20 | };
|
---|
21 |
|
---|
22 | /**
|
---|
23 | This function copies the current operational settings of this EFI UDPv6 Protocol
|
---|
24 | instance into user-supplied buffers. This function is used optionally to retrieve
|
---|
25 | the operational mode data of underlying networks or drivers.
|
---|
26 |
|
---|
27 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
|
---|
28 | @param[out] Udp6ConfigData The buffer in which the current UDP configuration
|
---|
29 | data is returned. This parameter is optional and
|
---|
30 | may be NULL.
|
---|
31 | @param[out] Ip6ModeData The buffer in which the current EFI IPv6 Protocol
|
---|
32 | mode data is returned. This parameter is optional
|
---|
33 | and may be NULL.
|
---|
34 | @param[out] MnpConfigData The buffer in which the current managed network
|
---|
35 | configuration data is returned. This parameter is
|
---|
36 | optional and may be NULL.
|
---|
37 | @param[out] SnpModeData The buffer in which the simple network mode data
|
---|
38 | is returned. This parameter is optional and may be NULL.
|
---|
39 |
|
---|
40 | @retval EFI_SUCCESS The mode data was read.
|
---|
41 | @retval EFI_NOT_STARTED When Udp6ConfigData is queried, no configuration
|
---|
42 | data is available because this instance has not
|
---|
43 | been started.
|
---|
44 | @retval EFI_INVALID_PARAMETER This is NULL.
|
---|
45 |
|
---|
46 | **/
|
---|
47 | EFI_STATUS
|
---|
48 | EFIAPI
|
---|
49 | Udp6GetModeData (
|
---|
50 | IN EFI_UDP6_PROTOCOL *This,
|
---|
51 | OUT EFI_UDP6_CONFIG_DATA *Udp6ConfigData OPTIONAL,
|
---|
52 | OUT EFI_IP6_MODE_DATA *Ip6ModeData OPTIONAL,
|
---|
53 | OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
|
---|
54 | OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
|
---|
55 | )
|
---|
56 | {
|
---|
57 | UDP6_INSTANCE_DATA *Instance;
|
---|
58 | EFI_IP6_PROTOCOL *Ip;
|
---|
59 | EFI_TPL OldTpl;
|
---|
60 | EFI_STATUS Status;
|
---|
61 |
|
---|
62 | if (This == NULL) {
|
---|
63 | return EFI_INVALID_PARAMETER;
|
---|
64 | }
|
---|
65 |
|
---|
66 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);
|
---|
67 |
|
---|
68 | if (!Instance->Configured && (Udp6ConfigData != NULL)) {
|
---|
69 | return EFI_NOT_STARTED;
|
---|
70 | }
|
---|
71 |
|
---|
72 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
73 |
|
---|
74 | if (Udp6ConfigData != NULL) {
|
---|
75 | //
|
---|
76 | // Set the Udp6ConfigData.
|
---|
77 | //
|
---|
78 | CopyMem (Udp6ConfigData, &Instance->ConfigData, sizeof (EFI_UDP6_CONFIG_DATA));
|
---|
79 | }
|
---|
80 |
|
---|
81 | Ip = Instance->IpInfo->Ip.Ip6;
|
---|
82 |
|
---|
83 | //
|
---|
84 | // Get the underlying Ip6ModeData, MnpConfigData and SnpModeData.
|
---|
85 | //
|
---|
86 | Status = Ip->GetModeData (Ip, Ip6ModeData, MnpConfigData, SnpModeData);
|
---|
87 |
|
---|
88 | gBS->RestoreTPL (OldTpl);
|
---|
89 |
|
---|
90 | return Status;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | This function is used to do the following:
|
---|
95 | Initialize and start this instance of the EFI UDPv6 Protocol.
|
---|
96 | Change the filtering rules and operational parameters.
|
---|
97 | Reset this instance of the EFI UDPv6 Protocol.
|
---|
98 |
|
---|
99 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
|
---|
100 | @param[in] UdpConfigData Pointer to the buffer to set the configuration
|
---|
101 | data. This parameter is optional and may be NULL.
|
---|
102 |
|
---|
103 | @retval EFI_SUCCESS The configuration settings were set, changed, or
|
---|
104 | reset successfully.
|
---|
105 | @retval EFI_NO_MAPPING When the UdpConfigData.UseAnyStationAddress is set
|
---|
106 | to true and there is no address available for the IP6
|
---|
107 | driver to bind a source address to this instance.
|
---|
108 | @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
|
---|
109 | This is NULL.
|
---|
110 | UdpConfigData.StationAddress is not a valid
|
---|
111 | unicast IPv6 address.
|
---|
112 | UdpConfigData.RemoteAddress is not a valid unicast
|
---|
113 | IPv6 address if it is not zero.
|
---|
114 | @retval EFI_ALREADY_STARTED The EFI UDPv6 Protocol instance is already
|
---|
115 | started/configured and must be stopped/reset
|
---|
116 | before it can be reconfigured. Only TrafficClass,
|
---|
117 | HopLimit, ReceiveTimeout, and TransmitTimeout can
|
---|
118 | be reconfigured without stopping the current
|
---|
119 | instance of the EFI UDPv6 Protocol.
|
---|
120 | @retval EFI_ACCESS_DENIED UdpConfigData.AllowDuplicatePort is FALSE and
|
---|
121 | UdpConfigData.StationPort is already used by another
|
---|
122 | instance.
|
---|
123 | @retval EFI_OUT_OF_RESOURCES The EFI UDPv6 Protocol driver cannot allocate
|
---|
124 | memory for this EFI UDPv6 Protocol instance.
|
---|
125 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred, and
|
---|
126 | this instance was not opened.
|
---|
127 |
|
---|
128 | **/
|
---|
129 | EFI_STATUS
|
---|
130 | EFIAPI
|
---|
131 | Udp6Configure (
|
---|
132 | IN EFI_UDP6_PROTOCOL *This,
|
---|
133 | IN EFI_UDP6_CONFIG_DATA *UdpConfigData OPTIONAL
|
---|
134 | )
|
---|
135 | {
|
---|
136 | EFI_STATUS Status;
|
---|
137 | UDP6_INSTANCE_DATA *Instance;
|
---|
138 | UDP6_SERVICE_DATA *Udp6Service;
|
---|
139 | EFI_TPL OldTpl;
|
---|
140 | EFI_IPv6_ADDRESS StationAddress;
|
---|
141 | EFI_IPv6_ADDRESS RemoteAddress;
|
---|
142 | EFI_IP6_CONFIG_DATA Ip6ConfigData;
|
---|
143 | EFI_IPv6_ADDRESS LocalAddr;
|
---|
144 | EFI_IPv6_ADDRESS RemoteAddr;
|
---|
145 |
|
---|
146 | if (This == NULL) {
|
---|
147 | return EFI_INVALID_PARAMETER;
|
---|
148 | }
|
---|
149 |
|
---|
150 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);
|
---|
151 |
|
---|
152 | if (!Instance->Configured && (UdpConfigData == NULL)) {
|
---|
153 | return EFI_SUCCESS;
|
---|
154 | }
|
---|
155 |
|
---|
156 | Udp6Service = Instance->Udp6Service;
|
---|
157 | Status = EFI_SUCCESS;
|
---|
158 | ASSERT (Udp6Service != NULL);
|
---|
159 |
|
---|
160 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
161 |
|
---|
162 | if (UdpConfigData != NULL) {
|
---|
163 | IP6_COPY_ADDRESS (&StationAddress, &UdpConfigData->StationAddress);
|
---|
164 | IP6_COPY_ADDRESS (&RemoteAddress, &UdpConfigData->RemoteAddress);
|
---|
165 |
|
---|
166 | if ((!NetIp6IsUnspecifiedAddr (&StationAddress) && !NetIp6IsValidUnicast (&StationAddress)) ||
|
---|
167 | (!NetIp6IsUnspecifiedAddr (&RemoteAddress) && !NetIp6IsValidUnicast (&RemoteAddress))
|
---|
168 | )
|
---|
169 | {
|
---|
170 | //
|
---|
171 | // If not use default address, and StationAddress is not a valid unicast
|
---|
172 | // if it is not IPv6 address or RemoteAddress is not a valid unicast IPv6
|
---|
173 | // address if it is not 0.
|
---|
174 | //
|
---|
175 | Status = EFI_INVALID_PARAMETER;
|
---|
176 | goto ON_EXIT;
|
---|
177 | }
|
---|
178 |
|
---|
179 | if (Instance->Configured) {
|
---|
180 | //
|
---|
181 | // The instance is already configured, try to do the re-configuration.
|
---|
182 | //
|
---|
183 | if (!Udp6IsReconfigurable (&Instance->ConfigData, UdpConfigData)) {
|
---|
184 | //
|
---|
185 | // If the new configuration data wants to change some unreconfigurable
|
---|
186 | // settings, return EFI_ALREADY_STARTED.
|
---|
187 | //
|
---|
188 | Status = EFI_ALREADY_STARTED;
|
---|
189 | goto ON_EXIT;
|
---|
190 | }
|
---|
191 |
|
---|
192 | //
|
---|
193 | // Save the reconfigurable parameters.
|
---|
194 | //
|
---|
195 | Instance->ConfigData.TrafficClass = UdpConfigData->TrafficClass;
|
---|
196 | Instance->ConfigData.HopLimit = UdpConfigData->HopLimit;
|
---|
197 | Instance->ConfigData.ReceiveTimeout = UdpConfigData->ReceiveTimeout;
|
---|
198 | Instance->ConfigData.TransmitTimeout = UdpConfigData->TransmitTimeout;
|
---|
199 | } else {
|
---|
200 | //
|
---|
201 | // Construct the Ip configuration data from the UdpConfigData.
|
---|
202 | //
|
---|
203 | Udp6BuildIp6ConfigData (UdpConfigData, &Ip6ConfigData);
|
---|
204 |
|
---|
205 | //
|
---|
206 | // Configure the Ip instance wrapped in the IpInfo.
|
---|
207 | //
|
---|
208 | Status = IpIoConfigIp (Instance->IpInfo, &Ip6ConfigData);
|
---|
209 | if (EFI_ERROR (Status)) {
|
---|
210 | if (Status == EFI_NO_MAPPING) {
|
---|
211 | Instance->IsNoMapping = TRUE;
|
---|
212 | }
|
---|
213 |
|
---|
214 | goto ON_EXIT;
|
---|
215 | }
|
---|
216 |
|
---|
217 | Instance->IsNoMapping = FALSE;
|
---|
218 |
|
---|
219 | //
|
---|
220 | // Save the configuration data.
|
---|
221 | //
|
---|
222 | CopyMem (
|
---|
223 | &Instance->ConfigData,
|
---|
224 | UdpConfigData,
|
---|
225 | sizeof (EFI_UDP6_CONFIG_DATA)
|
---|
226 | );
|
---|
227 | IP6_COPY_ADDRESS (&Instance->ConfigData.StationAddress, &Ip6ConfigData.StationAddress);
|
---|
228 | //
|
---|
229 | // Try to allocate the required port resource.
|
---|
230 | //
|
---|
231 | Status = Udp6Bind (&Udp6Service->ChildrenList, &Instance->ConfigData);
|
---|
232 | if (EFI_ERROR (Status)) {
|
---|
233 | //
|
---|
234 | // Reset the ip instance if bind fails.
|
---|
235 | //
|
---|
236 | IpIoConfigIp (Instance->IpInfo, NULL);
|
---|
237 | goto ON_EXIT;
|
---|
238 | }
|
---|
239 |
|
---|
240 | //
|
---|
241 | // Pre calculate the checksum for the pseudo head, ignore the UDP length first.
|
---|
242 | //
|
---|
243 | IP6_COPY_ADDRESS (&LocalAddr, &Instance->ConfigData.StationAddress);
|
---|
244 | IP6_COPY_ADDRESS (&RemoteAddr, &Instance->ConfigData.RemoteAddress);
|
---|
245 |
|
---|
246 | Instance->HeadSum = NetIp6PseudoHeadChecksum (
|
---|
247 | &LocalAddr,
|
---|
248 | &RemoteAddr,
|
---|
249 | EFI_IP_PROTO_UDP,
|
---|
250 | 0
|
---|
251 | );
|
---|
252 |
|
---|
253 | Instance->Configured = TRUE;
|
---|
254 | }
|
---|
255 | } else {
|
---|
256 | //
|
---|
257 | // UdpConfigData is NULL, reset the instance.
|
---|
258 | //
|
---|
259 | Instance->Configured = FALSE;
|
---|
260 | Instance->IsNoMapping = FALSE;
|
---|
261 |
|
---|
262 | //
|
---|
263 | // Reset the Ip instance wrapped in the IpInfo.
|
---|
264 | //
|
---|
265 | IpIoConfigIp (Instance->IpInfo, NULL);
|
---|
266 |
|
---|
267 | //
|
---|
268 | // Cancel all the user tokens.
|
---|
269 | //
|
---|
270 | Instance->Udp6Proto.Cancel (&Instance->Udp6Proto, NULL);
|
---|
271 |
|
---|
272 | //
|
---|
273 | // Remove the buffered RxData for this instance.
|
---|
274 | //
|
---|
275 | Udp6FlushRcvdDgram (Instance);
|
---|
276 |
|
---|
277 | ASSERT (IsListEmpty (&Instance->DeliveredDgramQue));
|
---|
278 | }
|
---|
279 |
|
---|
280 | ON_EXIT:
|
---|
281 |
|
---|
282 | gBS->RestoreTPL (OldTpl);
|
---|
283 |
|
---|
284 | return Status;
|
---|
285 | }
|
---|
286 |
|
---|
287 | /**
|
---|
288 | This function is used to enable and disable the multicast group filtering.
|
---|
289 |
|
---|
290 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
|
---|
291 | @param[in] JoinFlag Set to TRUE to join a multicast group. Set to
|
---|
292 | FALSE to leave one or all multicast groups.
|
---|
293 | @param[in] MulticastAddress Pointer to multicast group address to join or
|
---|
294 | leave. This parameter is optional and may be NULL.
|
---|
295 |
|
---|
296 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
297 | @retval EFI_NOT_STARTED The EFI UDPv6 Protocol instance has not been
|
---|
298 | started.
|
---|
299 | @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
|
---|
300 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
---|
301 | This is NULL.
|
---|
302 | JoinFlag is TRUE and MulticastAddress is NULL.
|
---|
303 | JoinFlag is TRUE and *MulticastAddress is not a
|
---|
304 | valid multicast address.
|
---|
305 | @retval EFI_ALREADY_STARTED The group address is already in the group table
|
---|
306 | (when JoinFlag is TRUE).
|
---|
307 | @retval EFI_NOT_FOUND The group address is not in the group table (when
|
---|
308 | JoinFlag is FALSE).
|
---|
309 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
|
---|
310 |
|
---|
311 | **/
|
---|
312 | EFI_STATUS
|
---|
313 | EFIAPI
|
---|
314 | Udp6Groups (
|
---|
315 | IN EFI_UDP6_PROTOCOL *This,
|
---|
316 | IN BOOLEAN JoinFlag,
|
---|
317 | IN EFI_IPv6_ADDRESS *MulticastAddress OPTIONAL
|
---|
318 | )
|
---|
319 | {
|
---|
320 | EFI_STATUS Status;
|
---|
321 | UDP6_INSTANCE_DATA *Instance;
|
---|
322 | EFI_IP6_PROTOCOL *Ip;
|
---|
323 | EFI_TPL OldTpl;
|
---|
324 | EFI_IPv6_ADDRESS *McastIp;
|
---|
325 |
|
---|
326 | if ((This == NULL) || (JoinFlag && (MulticastAddress == NULL))) {
|
---|
327 | return EFI_INVALID_PARAMETER;
|
---|
328 | }
|
---|
329 |
|
---|
330 | McastIp = NULL;
|
---|
331 |
|
---|
332 | if (JoinFlag) {
|
---|
333 | if (!IP6_IS_MULTICAST (MulticastAddress)) {
|
---|
334 | return EFI_INVALID_PARAMETER;
|
---|
335 | }
|
---|
336 |
|
---|
337 | McastIp = AllocateCopyPool (sizeof (EFI_IPv6_ADDRESS), MulticastAddress);
|
---|
338 | if (McastIp == NULL) {
|
---|
339 | return EFI_OUT_OF_RESOURCES;
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);
|
---|
344 | if (!Instance->Configured) {
|
---|
345 | if (McastIp != NULL) {
|
---|
346 | FreePool (McastIp);
|
---|
347 | }
|
---|
348 |
|
---|
349 | return EFI_NOT_STARTED;
|
---|
350 | }
|
---|
351 |
|
---|
352 | Ip = Instance->IpInfo->Ip.Ip6;
|
---|
353 |
|
---|
354 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
355 |
|
---|
356 | //
|
---|
357 | // Invoke the Ip instance the Udp6 instance consumes to do the group operation.
|
---|
358 | //
|
---|
359 | Status = Ip->Groups (Ip, JoinFlag, MulticastAddress);
|
---|
360 |
|
---|
361 | if (EFI_ERROR (Status)) {
|
---|
362 | goto ON_EXIT;
|
---|
363 | }
|
---|
364 |
|
---|
365 | //
|
---|
366 | // Keep a local copy of the configured multicast IPs because IpIo receives
|
---|
367 | // datagrams from the 0 station address IP instance and then UDP delivers to
|
---|
368 | // the matched instance. This copy of multicast IPs is used to avoid receive
|
---|
369 | // the multicast datagrams destinated to multicast IPs the other instances configured.
|
---|
370 | //
|
---|
371 | if (JoinFlag) {
|
---|
372 | Status = NetMapInsertTail (&Instance->McastIps, (VOID *)McastIp, NULL);
|
---|
373 | } else {
|
---|
374 | Status = NetMapIterate (&Instance->McastIps, Udp6LeaveGroup, MulticastAddress);
|
---|
375 | if ((MulticastAddress != NULL) && (Status == EFI_ABORTED)) {
|
---|
376 | Status = EFI_SUCCESS;
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | ON_EXIT:
|
---|
381 |
|
---|
382 | gBS->RestoreTPL (OldTpl);
|
---|
383 |
|
---|
384 | if (EFI_ERROR (Status)) {
|
---|
385 | if (McastIp != NULL) {
|
---|
386 | FreePool (McastIp);
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | return Status;
|
---|
391 | }
|
---|
392 |
|
---|
393 | /**
|
---|
394 | This function places a sending request to this instance of the EFI UDPv6 Protocol,
|
---|
395 | alongside the transmit data that was filled by the user.
|
---|
396 |
|
---|
397 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
|
---|
398 | @param[in] Token Pointer to the completion token that will be
|
---|
399 | placed into the transmit queue.
|
---|
400 |
|
---|
401 | @retval EFI_SUCCESS The data was queued for transmission.
|
---|
402 | @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
|
---|
403 | started.
|
---|
404 | @retval EFI_NO_MAPPING The under-layer IPv6 driver was responsible for
|
---|
405 | choosing a source address for this instance, but
|
---|
406 | no source address was available for use.
|
---|
407 | @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
|
---|
408 | This is NULL.
|
---|
409 | Token is NULL. Token.Event is NULL.
|
---|
410 | Token.Packet.TxData is NULL.
|
---|
411 | Token.Packet.TxData.FragmentCount is zero.
|
---|
412 | Token.Packet.TxData.DataLength is not equal to the
|
---|
413 | sum of fragment lengths.
|
---|
414 | One or more of the
|
---|
415 | Token.Packet.TxData.FragmentTable[].FragmentLength
|
---|
416 | fields is zero.
|
---|
417 | One or more of the
|
---|
418 | Token.Packet.TxData.FragmentTable[].FragmentBuffer
|
---|
419 | fields is NULL. One or more of the
|
---|
420 | Token.Packet.TxData.UdpSessionData.DestinationAddress
|
---|
421 | are not valid unicast IPv6
|
---|
422 | addresses if the UdpSessionData is not NULL.
|
---|
423 | Token.Packet.TxData.UdpSessionData.
|
---|
424 | DestinationAddress is NULL
|
---|
425 | Token.Packet.TxData.UdpSessionData.
|
---|
426 | DestinationPort
|
---|
427 | is zero.
|
---|
428 | Token.Packet.TxData.UdpSessionData is NULL and this
|
---|
429 | instance's UdpConfigData.RemoteAddress is unspecified.
|
---|
430 | @retval EFI_ACCESS_DENIED The transmit completion token with the same
|
---|
431 | Token.Event is already in the transmit queue.
|
---|
432 | @retval EFI_NOT_READY The completion token could not be queued because
|
---|
433 | the transmit queue is full.
|
---|
434 | @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
|
---|
435 | @retval EFI_NOT_FOUND There is no route to the destination network or
|
---|
436 | address.
|
---|
437 | @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
|
---|
438 | packet size. Or, the length of the IP header + UDP
|
---|
439 | header + data length is greater than MTU if
|
---|
440 | DoNotFragment is TRUE.
|
---|
441 |
|
---|
442 | **/
|
---|
443 | EFI_STATUS
|
---|
444 | EFIAPI
|
---|
445 | Udp6Transmit (
|
---|
446 | IN EFI_UDP6_PROTOCOL *This,
|
---|
447 | IN EFI_UDP6_COMPLETION_TOKEN *Token
|
---|
448 | )
|
---|
449 | {
|
---|
450 | EFI_STATUS Status;
|
---|
451 | UDP6_INSTANCE_DATA *Instance;
|
---|
452 | EFI_TPL OldTpl;
|
---|
453 | NET_BUF *Packet;
|
---|
454 | EFI_UDP_HEADER *Udp6Header;
|
---|
455 | EFI_UDP6_CONFIG_DATA *ConfigData;
|
---|
456 | EFI_IPv6_ADDRESS Source;
|
---|
457 | EFI_IPv6_ADDRESS Destination;
|
---|
458 | EFI_UDP6_TRANSMIT_DATA *TxData;
|
---|
459 | EFI_UDP6_SESSION_DATA *UdpSessionData;
|
---|
460 | UDP6_SERVICE_DATA *Udp6Service;
|
---|
461 | IP_IO_OVERRIDE Override;
|
---|
462 | UINT16 HeadSum;
|
---|
463 | EFI_IP_ADDRESS IpDestAddr;
|
---|
464 |
|
---|
465 | if ((This == NULL) || (Token == NULL)) {
|
---|
466 | return EFI_INVALID_PARAMETER;
|
---|
467 | }
|
---|
468 |
|
---|
469 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);
|
---|
470 |
|
---|
471 | if (!Instance->Configured) {
|
---|
472 | return EFI_NOT_STARTED;
|
---|
473 | }
|
---|
474 |
|
---|
475 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
476 |
|
---|
477 | //
|
---|
478 | // Validate the Token, if the token is invalid return the error code.
|
---|
479 | //
|
---|
480 | Status = Udp6ValidateTxToken (Instance, Token);
|
---|
481 | if (EFI_ERROR (Status)) {
|
---|
482 | goto ON_EXIT;
|
---|
483 | }
|
---|
484 |
|
---|
485 | if (EFI_ERROR (NetMapIterate (&Instance->TxTokens, Udp6TokenExist, Token)) ||
|
---|
486 | EFI_ERROR (NetMapIterate (&Instance->RxTokens, Udp6TokenExist, Token))
|
---|
487 | )
|
---|
488 | {
|
---|
489 | //
|
---|
490 | // Try to find a duplicate token in the two token maps, if found, return
|
---|
491 | // EFI_ACCESS_DENIED.
|
---|
492 | //
|
---|
493 | Status = EFI_ACCESS_DENIED;
|
---|
494 | goto ON_EXIT;
|
---|
495 | }
|
---|
496 |
|
---|
497 | TxData = Token->Packet.TxData;
|
---|
498 |
|
---|
499 | //
|
---|
500 | // Create a net buffer to hold the user buffer and the udp header.
|
---|
501 | //
|
---|
502 | Packet = NetbufFromExt (
|
---|
503 | (NET_FRAGMENT *)TxData->FragmentTable,
|
---|
504 | TxData->FragmentCount,
|
---|
505 | UDP6_HEADER_SIZE,
|
---|
506 | 0,
|
---|
507 | Udp6NetVectorExtFree,
|
---|
508 | NULL
|
---|
509 | );
|
---|
510 | if (Packet == NULL) {
|
---|
511 | Status = EFI_OUT_OF_RESOURCES;
|
---|
512 | goto ON_EXIT;
|
---|
513 | }
|
---|
514 |
|
---|
515 | //
|
---|
516 | // Store the IpIo in ProtoData.
|
---|
517 | //
|
---|
518 | Udp6Service = Instance->Udp6Service;
|
---|
519 | *((UINTN *)&Packet->ProtoData[0]) = (UINTN)(Udp6Service->IpIo);
|
---|
520 |
|
---|
521 | Udp6Header = (EFI_UDP_HEADER *)NetbufAllocSpace (Packet, UDP6_HEADER_SIZE, TRUE);
|
---|
522 | ASSERT (Udp6Header != NULL);
|
---|
523 | if (Udp6Header == NULL) {
|
---|
524 | Status = EFI_OUT_OF_RESOURCES;
|
---|
525 | goto ON_EXIT;
|
---|
526 | }
|
---|
527 |
|
---|
528 | ConfigData = &Instance->ConfigData;
|
---|
529 |
|
---|
530 | //
|
---|
531 | // Fill the udp header.
|
---|
532 | //
|
---|
533 | Udp6Header->SrcPort = HTONS (ConfigData->StationPort);
|
---|
534 | Udp6Header->DstPort = HTONS (ConfigData->RemotePort);
|
---|
535 | Udp6Header->Length = HTONS ((UINT16)Packet->TotalSize);
|
---|
536 | Udp6Header->Checksum = 0;
|
---|
537 | //
|
---|
538 | // Set the UDP Header in NET_BUF, this UDP header is for IP6 can fast get the
|
---|
539 | // Udp header for pseudoHeadCheckSum.
|
---|
540 | //
|
---|
541 | Packet->Udp = Udp6Header;
|
---|
542 | UdpSessionData = TxData->UdpSessionData;
|
---|
543 |
|
---|
544 | if (UdpSessionData != NULL) {
|
---|
545 | //
|
---|
546 | // Set the Destination according to the specified
|
---|
547 | // UdpSessionData.
|
---|
548 | //
|
---|
549 |
|
---|
550 | if (UdpSessionData->DestinationPort != 0) {
|
---|
551 | Udp6Header->DstPort = HTONS (UdpSessionData->DestinationPort);
|
---|
552 | }
|
---|
553 |
|
---|
554 | IP6_COPY_ADDRESS (&Source, &ConfigData->StationAddress);
|
---|
555 | if (!NetIp6IsUnspecifiedAddr (&UdpSessionData->DestinationAddress)) {
|
---|
556 | IP6_COPY_ADDRESS (&Destination, &UdpSessionData->DestinationAddress);
|
---|
557 | } else {
|
---|
558 | IP6_COPY_ADDRESS (&Destination, &ConfigData->RemoteAddress);
|
---|
559 | }
|
---|
560 |
|
---|
561 | //
|
---|
562 | // Calculate the pseudo head checksum using the overridden parameters.
|
---|
563 | //
|
---|
564 | if (!NetIp6IsUnspecifiedAddr (&ConfigData->StationAddress)) {
|
---|
565 | HeadSum = NetIp6PseudoHeadChecksum (
|
---|
566 | &Source,
|
---|
567 | &Destination,
|
---|
568 | EFI_IP_PROTO_UDP,
|
---|
569 | 0
|
---|
570 | );
|
---|
571 |
|
---|
572 | //
|
---|
573 | // calculate the checksum.
|
---|
574 | //
|
---|
575 | Udp6Header->Checksum = Udp6Checksum (Packet, HeadSum);
|
---|
576 | if (Udp6Header->Checksum == 0) {
|
---|
577 | //
|
---|
578 | // If the calculated checksum is 0, fill the Checksum field with all ones.
|
---|
579 | //
|
---|
580 | Udp6Header->Checksum = 0xffff;
|
---|
581 | }
|
---|
582 | } else {
|
---|
583 | //
|
---|
584 | // Set the checksum is zero if the ConfigData->StationAddress is unspecified
|
---|
585 | // and the Ipv6 will fill the correct value of this checksum.
|
---|
586 | //
|
---|
587 | Udp6Header->Checksum = 0;
|
---|
588 | }
|
---|
589 | } else {
|
---|
590 | //
|
---|
591 | // UdpSessionData is NULL, use the address and port information previously configured.
|
---|
592 | //
|
---|
593 | IP6_COPY_ADDRESS (&Destination, &ConfigData->RemoteAddress);
|
---|
594 |
|
---|
595 | HeadSum = Instance->HeadSum;
|
---|
596 | //
|
---|
597 | // calculate the checksum.
|
---|
598 | //
|
---|
599 | Udp6Header->Checksum = Udp6Checksum (Packet, HeadSum);
|
---|
600 | if (Udp6Header->Checksum == 0) {
|
---|
601 | //
|
---|
602 | // If the calculated checksum is 0, fill the Checksum field with all ones.
|
---|
603 | //
|
---|
604 | Udp6Header->Checksum = 0xffff;
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | //
|
---|
609 | // Fill the IpIo Override data.
|
---|
610 | //
|
---|
611 | Override.Ip6OverrideData.Protocol = EFI_IP_PROTO_UDP;
|
---|
612 | Override.Ip6OverrideData.HopLimit = ConfigData->HopLimit;
|
---|
613 | Override.Ip6OverrideData.FlowLabel = 0;
|
---|
614 |
|
---|
615 | //
|
---|
616 | // Save the token into the TxToken map.
|
---|
617 | //
|
---|
618 | Status = NetMapInsertTail (&Instance->TxTokens, Token, Packet);
|
---|
619 | if (EFI_ERROR (Status)) {
|
---|
620 | goto FREE_PACKET;
|
---|
621 | }
|
---|
622 |
|
---|
623 | //
|
---|
624 | // Send out this datagram through IpIo.
|
---|
625 | //
|
---|
626 | if (UdpSessionData != NULL) {
|
---|
627 | IP6_COPY_ADDRESS (&(IpDestAddr.v6), &Destination);
|
---|
628 | } else {
|
---|
629 | ZeroMem (&IpDestAddr.v6, sizeof (EFI_IPv6_ADDRESS));
|
---|
630 | }
|
---|
631 |
|
---|
632 | Status = IpIoSend (
|
---|
633 | Udp6Service->IpIo,
|
---|
634 | Packet,
|
---|
635 | Instance->IpInfo,
|
---|
636 | Instance,
|
---|
637 | Token,
|
---|
638 | &IpDestAddr,
|
---|
639 | &Override
|
---|
640 | );
|
---|
641 | if (EFI_ERROR (Status)) {
|
---|
642 | //
|
---|
643 | // Remove this token from the TxTokens.
|
---|
644 | //
|
---|
645 | Udp6RemoveToken (&Instance->TxTokens, Token);
|
---|
646 | }
|
---|
647 |
|
---|
648 | FREE_PACKET:
|
---|
649 |
|
---|
650 | NetbufFree (Packet);
|
---|
651 |
|
---|
652 | ON_EXIT:
|
---|
653 |
|
---|
654 | gBS->RestoreTPL (OldTpl);
|
---|
655 |
|
---|
656 | return Status;
|
---|
657 | }
|
---|
658 |
|
---|
659 | /**
|
---|
660 | This function places a completion token into the receive packet queue. This function
|
---|
661 | is always asynchronous.
|
---|
662 |
|
---|
663 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
|
---|
664 | @param[in] Token Pointer to a token that is associated with the
|
---|
665 | receive data descriptor.
|
---|
666 |
|
---|
667 | @retval EFI_SUCCESS The receive completion token was cached.
|
---|
668 | @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been
|
---|
669 | started.
|
---|
670 | @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
|
---|
671 | BOOTP, RARP, etc.) is not finished yet.
|
---|
672 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
---|
673 | This is NULL. Token is NULL. Token.Event is NULL.
|
---|
674 | @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
|
---|
675 | due to a lack of system resources (usually
|
---|
676 | memory).
|
---|
677 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
|
---|
678 | The EFI UDPv6 Protocol instance has been reset to
|
---|
679 | startup defaults.
|
---|
680 | @retval EFI_ACCESS_DENIED A receive completion token with the same
|
---|
681 | Token.Event is already in the receive queue.
|
---|
682 | @retval EFI_NOT_READY The receive request could not be queued because
|
---|
683 | the receive queue is full.
|
---|
684 |
|
---|
685 | **/
|
---|
686 | EFI_STATUS
|
---|
687 | EFIAPI
|
---|
688 | Udp6Receive (
|
---|
689 | IN EFI_UDP6_PROTOCOL *This,
|
---|
690 | IN EFI_UDP6_COMPLETION_TOKEN *Token
|
---|
691 | )
|
---|
692 | {
|
---|
693 | EFI_STATUS Status;
|
---|
694 | UDP6_INSTANCE_DATA *Instance;
|
---|
695 | EFI_TPL OldTpl;
|
---|
696 |
|
---|
697 | if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {
|
---|
698 | return EFI_INVALID_PARAMETER;
|
---|
699 | }
|
---|
700 |
|
---|
701 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);
|
---|
702 |
|
---|
703 | if (!Instance->Configured) {
|
---|
704 | return EFI_NOT_STARTED;
|
---|
705 | }
|
---|
706 |
|
---|
707 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
708 |
|
---|
709 | if (EFI_ERROR (NetMapIterate (&Instance->RxTokens, Udp6TokenExist, Token)) ||
|
---|
710 | EFI_ERROR (NetMapIterate (&Instance->TxTokens, Udp6TokenExist, Token))
|
---|
711 | )
|
---|
712 | {
|
---|
713 | //
|
---|
714 | // Return EFI_ACCESS_DENIED if the specified token is already in the TxTokens or
|
---|
715 | // RxTokens map.
|
---|
716 | //
|
---|
717 | Status = EFI_ACCESS_DENIED;
|
---|
718 | goto ON_EXIT;
|
---|
719 | }
|
---|
720 |
|
---|
721 | Token->Packet.RxData = NULL;
|
---|
722 |
|
---|
723 | //
|
---|
724 | // Save the token into the RxTokens map.
|
---|
725 | //
|
---|
726 | Status = NetMapInsertTail (&Instance->RxTokens, Token, NULL);
|
---|
727 | if (EFI_ERROR (Status)) {
|
---|
728 | Status = EFI_NOT_READY;
|
---|
729 | goto ON_EXIT;
|
---|
730 | }
|
---|
731 |
|
---|
732 | //
|
---|
733 | // If there is an icmp error, report it.
|
---|
734 | //
|
---|
735 | Udp6ReportIcmpError (Instance);
|
---|
736 |
|
---|
737 | //
|
---|
738 | // Try to delivered the received datagrams.
|
---|
739 | //
|
---|
740 | Udp6InstanceDeliverDgram (Instance);
|
---|
741 |
|
---|
742 | //
|
---|
743 | // Dispatch the DPC queued by the NotifyFunction of Token->Event.
|
---|
744 | //
|
---|
745 | DispatchDpc ();
|
---|
746 |
|
---|
747 | ON_EXIT:
|
---|
748 |
|
---|
749 | gBS->RestoreTPL (OldTpl);
|
---|
750 |
|
---|
751 | return Status;
|
---|
752 | }
|
---|
753 |
|
---|
754 | /**
|
---|
755 | This function is used to abort a pending transmit or receive request.
|
---|
756 |
|
---|
757 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
|
---|
758 | @param[in] Token Pointer to a token that has been issued by
|
---|
759 | EFI_UDP6_PROTOCOL.Transmit() or
|
---|
760 | EFI_UDP6_PROTOCOL.Receive(). This parameter is
|
---|
761 | optional and may be NULL.
|
---|
762 |
|
---|
763 | @retval EFI_SUCCESS The asynchronous I/O request was aborted, and
|
---|
764 | Token.Event was signaled. When Token is NULL, all
|
---|
765 | pending requests are aborted and their events are
|
---|
766 | signaled.
|
---|
767 | @retval EFI_INVALID_PARAMETER This is NULL.
|
---|
768 | @retval EFI_NOT_STARTED This instance has not been started.
|
---|
769 | @retval EFI_NO_MAPPING When using the default address, configuration
|
---|
770 | (DHCP, BOOTP, RARP, etc.) is not finished yet.
|
---|
771 | @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
|
---|
772 | request is not found in the transmit or receive
|
---|
773 | queue. It is either completed or not issued by
|
---|
774 | Transmit() or Receive().
|
---|
775 |
|
---|
776 | **/
|
---|
777 | EFI_STATUS
|
---|
778 | EFIAPI
|
---|
779 | Udp6Cancel (
|
---|
780 | IN EFI_UDP6_PROTOCOL *This,
|
---|
781 | IN EFI_UDP6_COMPLETION_TOKEN *Token OPTIONAL
|
---|
782 | )
|
---|
783 | {
|
---|
784 | EFI_STATUS Status;
|
---|
785 | UDP6_INSTANCE_DATA *Instance;
|
---|
786 | EFI_TPL OldTpl;
|
---|
787 |
|
---|
788 | if (This == NULL) {
|
---|
789 | return EFI_INVALID_PARAMETER;
|
---|
790 | }
|
---|
791 |
|
---|
792 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);
|
---|
793 |
|
---|
794 | if (!Instance->Configured) {
|
---|
795 | return EFI_NOT_STARTED;
|
---|
796 | }
|
---|
797 |
|
---|
798 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
799 |
|
---|
800 | //
|
---|
801 | // Cancel the tokens specified by Token for this instance.
|
---|
802 | //
|
---|
803 | Status = Udp6InstanceCancelToken (Instance, Token);
|
---|
804 |
|
---|
805 | //
|
---|
806 | // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
|
---|
807 | //
|
---|
808 | DispatchDpc ();
|
---|
809 |
|
---|
810 | gBS->RestoreTPL (OldTpl);
|
---|
811 |
|
---|
812 | return Status;
|
---|
813 | }
|
---|
814 |
|
---|
815 | /**
|
---|
816 | This function can be used by network drivers and applications to increase the rate that
|
---|
817 | data packets are moved between the communications device and the transmit/receive queues.
|
---|
818 |
|
---|
819 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.
|
---|
820 |
|
---|
821 | @retval EFI_SUCCESS Incoming or outgoing data was processed.
|
---|
822 | @retval EFI_INVALID_PARAMETER This is NULL.
|
---|
823 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
|
---|
824 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or
|
---|
825 | receive queue.
|
---|
826 |
|
---|
827 | **/
|
---|
828 | EFI_STATUS
|
---|
829 | EFIAPI
|
---|
830 | Udp6Poll (
|
---|
831 | IN EFI_UDP6_PROTOCOL *This
|
---|
832 | )
|
---|
833 | {
|
---|
834 | UDP6_INSTANCE_DATA *Instance;
|
---|
835 | EFI_IP6_PROTOCOL *Ip;
|
---|
836 |
|
---|
837 | if (This == NULL) {
|
---|
838 | return EFI_INVALID_PARAMETER;
|
---|
839 | }
|
---|
840 |
|
---|
841 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);
|
---|
842 | Ip = Instance->IpInfo->Ip.Ip6;
|
---|
843 |
|
---|
844 | //
|
---|
845 | // Invode the Ip instance consumed by the udp instance to do the poll operation.
|
---|
846 | //
|
---|
847 | return Ip->Poll (Ip);
|
---|
848 | }
|
---|