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