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