]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/TcpDxe/TcpMain.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / NetworkPkg / TcpDxe / TcpMain.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 Implementation of EFI_TCP4_PROTOCOL and EFI_TCP6_PROTOCOL.\r
3\r
581900d9 4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
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 "TcpMain.h"\r
17\r
18/**\r
19 Check the integrity of the data buffer.\r
20\r
21 @param[in] DataLen The total length of the data buffer.\r
22 @param[in] FragmentCount The fragment count of the fragment table.\r
23 @param[in] FragmentTable Pointer to the fragment table of the data\r
24 buffer.\r
25\r
26 @retval EFI_SUCCESS The integrity check passed.\r
27 @retval EFI_INVALID_PARAMETER The integrity check failed.\r
28\r
29**/\r
30EFI_STATUS\r
31TcpChkDataBuf (\r
32 IN UINT32 DataLen,\r
33 IN UINT32 FragmentCount,\r
34 IN EFI_TCP4_FRAGMENT_DATA *FragmentTable\r
35 )\r
36{\r
37 UINT32 Index;\r
38\r
39 UINT32 Len;\r
40\r
41 for (Index = 0, Len = 0; Index < FragmentCount; Index++) {\r
42 Len = Len + FragmentTable[Index].FragmentLength;\r
43 }\r
44\r
45 if (DataLen != Len) {\r
46 return EFI_INVALID_PARAMETER;\r
47 }\r
48\r
49 return EFI_SUCCESS;\r
50}\r
51\r
52/**\r
53 Get the current operational status.\r
54\r
55 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
56 @param[out] Tcp4State Pointer to the buffer to receive the current TCP\r
57 state. Optional parameter that may be NULL.\r
58 @param[out] Tcp4ConfigData Pointer to the buffer to receive the current TCP\r
59 configuration. Optional parameter that may be NULL.\r
60 @param[out] Ip4ModeData Pointer to the buffer to receive the current\r
61 IPv4 configuration. Optional parameter that may be NULL.\r
62 @param[out] MnpConfigData Pointer to the buffer to receive the current MNP\r
63 configuration data indirectly used by the TCPv4\r
64 Instance. Optional parameter that may be NULL.\r
65 @param[out] SnpModeData Pointer to the buffer to receive the current SNP\r
66 configuration data indirectly used by the TCPv4\r
67 Instance. Optional parameter that may be NULL.\r
68\r
69 @retval EFI_SUCCESS The mode data was read.\r
70 @retval EFI_NOT_STARTED No configuration data is available because this\r
71 instance hasn't been started.\r
72 @retval EFI_INVALID_PARAMETER This is NULL.\r
73\r
74**/\r
75EFI_STATUS\r
76EFIAPI\r
77Tcp4GetModeData (\r
581900d9 78 IN EFI_TCP4_PROTOCOL *This,\r
79 OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL,\r
80 OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL,\r
81 OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,\r
82 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,\r
83 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r
a3bcde70
HT
84 )\r
85{\r
86 TCP4_MODE_DATA TcpMode;\r
87 SOCKET *Sock;\r
88\r
89 if (NULL == This) {\r
90 return EFI_INVALID_PARAMETER;\r
91 }\r
92\r
93 Sock = SOCK_FROM_THIS (This);\r
94\r
95 TcpMode.Tcp4State = Tcp4State;\r
96 TcpMode.Tcp4ConfigData = Tcp4ConfigData;\r
97 TcpMode.Ip4ModeData = Ip4ModeData;\r
98 TcpMode.MnpConfigData = MnpConfigData;\r
99 TcpMode.SnpModeData = SnpModeData;\r
100\r
101 return SockGetMode (Sock, &TcpMode);\r
102}\r
103\r
104/**\r
105 Initialize or brutally reset the operational parameters for\r
106 this EFI TCPv4 instance.\r
107\r
108 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
109 @param[in] TcpConfigData Pointer to the configure data to configure the\r
110 instance. Optional parameter that may be NULL.\r
111\r
112 @retval EFI_SUCCESS The operational settings were set, changed, or\r
113 reset successfully.\r
114 @retval EFI_NO_MAPPING When using a default address, configuration\r
115 (through DHCP, BOOTP, RARP, etc.) is not\r
116 finished.\r
117 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
118 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already\r
119 configured.\r
120 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
121 @retval EFI_UNSUPPORTED One or more of the control options are not\r
122 supported in the implementation.\r
123 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
124\r
125**/\r
126EFI_STATUS\r
127EFIAPI\r
128Tcp4Configure (\r
129 IN EFI_TCP4_PROTOCOL * This,\r
130 IN EFI_TCP4_CONFIG_DATA * TcpConfigData OPTIONAL\r
131 )\r
132{\r
133 EFI_TCP4_OPTION *Option;\r
134 SOCKET *Sock;\r
135 EFI_STATUS Status;\r
136 IP4_ADDR Ip;\r
137 IP4_ADDR SubnetMask;\r
138\r
139 if (NULL == This) {\r
140 return EFI_INVALID_PARAMETER;\r
141 }\r
142\r
143 //\r
144 // Tcp protocol related parameter check will be conducted here\r
145 //\r
146 if (NULL != TcpConfigData) {\r
147\r
148 CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));\r
149 if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) {\r
150 return EFI_INVALID_PARAMETER;\r
151 }\r
152\r
153 if (TcpConfigData->AccessPoint.ActiveFlag && (0 == TcpConfigData->AccessPoint.RemotePort || (Ip == 0))) {\r
154 return EFI_INVALID_PARAMETER;\r
155 }\r
156\r
157 if (!TcpConfigData->AccessPoint.UseDefaultAddress) {\r
158\r
159 CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP4_ADDR));\r
160 CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof (IP4_ADDR));\r
161 if (!NetIp4IsUnicast (NTOHL (Ip), 0) || !IP4_IS_VALID_NETMASK (NTOHL (SubnetMask))) {\r
162 return EFI_INVALID_PARAMETER;\r
163 }\r
164 }\r
165\r
166 Option = TcpConfigData->ControlOption;\r
167 if ((NULL != Option) && (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {\r
168 return EFI_UNSUPPORTED;\r
169 }\r
170 }\r
171\r
172 Sock = SOCK_FROM_THIS (This);\r
173\r
174 if (NULL == TcpConfigData) {\r
175 return SockFlush (Sock);\r
176 }\r
177\r
178 Status = SockConfigure (Sock, TcpConfigData);\r
179\r
180 if (EFI_NO_MAPPING == Status) {\r
181 Sock->ConfigureState = SO_NO_MAPPING;\r
182 }\r
183\r
184 return Status;\r
185}\r
186\r
187/**\r
188 Add or delete routing entries.\r
189\r
190 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
191 @param[in] DeleteRoute If TRUE, delete the specified route from routing\r
192 table; if FALSE, add the specified route to\r
193 routing table.\r
194 @param[in] SubnetAddress The destination network.\r
195 @param[in] SubnetMask The subnet mask for the destination network.\r
196 @param[in] GatewayAddress The gateway address for this route.\r
197\r
198 @retval EFI_SUCCESS The operation completed successfully.\r
199 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been\r
200 configured.\r
201 @retval EFI_NO_MAPPING When using a default address, configuration\r
202 (through DHCP, BOOTP, RARP, etc.) is not\r
203 finished.\r
204 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
205 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the\r
206 entry to the routing table.\r
207 @retval EFI_NOT_FOUND This route is not in the routing table.\r
208 @retval EFI_ACCESS_DENIED This route is already in the routing table.\r
209 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.\r
210\r
211**/\r
212EFI_STATUS\r
213EFIAPI\r
214Tcp4Routes (\r
215 IN EFI_TCP4_PROTOCOL *This,\r
216 IN BOOLEAN DeleteRoute,\r
217 IN EFI_IPv4_ADDRESS *SubnetAddress,\r
218 IN EFI_IPv4_ADDRESS *SubnetMask,\r
219 IN EFI_IPv4_ADDRESS *GatewayAddress\r
220 )\r
221{\r
222 SOCKET *Sock;\r
223 TCP4_ROUTE_INFO RouteInfo;\r
224\r
225 if (NULL == This) {\r
226 return EFI_INVALID_PARAMETER;\r
227 }\r
228\r
229 Sock = SOCK_FROM_THIS (This);\r
230\r
231 RouteInfo.DeleteRoute = DeleteRoute;\r
232 RouteInfo.SubnetAddress = SubnetAddress;\r
233 RouteInfo.SubnetMask = SubnetMask;\r
234 RouteInfo.GatewayAddress = GatewayAddress;\r
235\r
236 return SockRoute (Sock, &RouteInfo);\r
237}\r
238\r
239/**\r
240 Initiate a non-blocking TCP connection request for an active TCP instance.\r
241\r
242 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
243 @param[in] ConnectionToken Pointer to the connection token to return when\r
244 the TCP three way handshake finishes.\r
245\r
246 @retval EFI_SUCCESS The connection request successfully\r
247 initiated.\r
248 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been\r
249 configured.\r
250 @retval EFI_ACCESS_DENIED The instance is not configured as an active one,\r
251 or it is not in Tcp4StateClosed state.\r
252 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
253 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resources to\r
254 initiate the active open.\r
255 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
256\r
257**/\r
258EFI_STATUS\r
259EFIAPI\r
260Tcp4Connect (\r
261 IN EFI_TCP4_PROTOCOL *This,\r
262 IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken\r
263 )\r
264{\r
265 SOCKET *Sock;\r
266\r
267 if (NULL == This || NULL == ConnectionToken || NULL == ConnectionToken->CompletionToken.Event) {\r
268 return EFI_INVALID_PARAMETER;\r
269 }\r
270\r
271 Sock = SOCK_FROM_THIS (This);\r
272\r
273 return SockConnect (Sock, ConnectionToken);\r
274}\r
275\r
276/**\r
277 Listen on the passive instance to accept an incoming connection request.\r
278\r
279 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
280 @param[in] ListenToken Pointer to the listen token to return when\r
281 operation finishes.\r
282\r
283 @retval EFI_SUCCESS The listen token was queued successfully.\r
284 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
285 configured.\r
286 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not\r
287 in Tcp4StateListen state or a same listen token\r
288 has already existed in the listen token queue of\r
289 this TCP instance.\r
290 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
291 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish\r
292 the operation.\r
293 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
294\r
295**/\r
296EFI_STATUS\r
297EFIAPI\r
298Tcp4Accept (\r
299 IN EFI_TCP4_PROTOCOL *This,\r
300 IN EFI_TCP4_LISTEN_TOKEN *ListenToken\r
301 )\r
302{\r
303 SOCKET *Sock;\r
304\r
305 if (NULL == This || NULL == ListenToken || NULL == ListenToken->CompletionToken.Event) {\r
306 return EFI_INVALID_PARAMETER;\r
307 }\r
308\r
309 Sock = SOCK_FROM_THIS (This);\r
310\r
311 return SockAccept (Sock, ListenToken);\r
312}\r
313\r
314/**\r
315 Queues outgoing data into the transmit queue\r
316\r
317 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
318 @param[in] Token Pointer to the completion token to queue to the\r
319 transmit queue.\r
320\r
321 @retval EFI_SUCCESS The data has been queued for transmission.\r
322 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
323 configured.\r
324 @retval EFI_NO_MAPPING When using a default address, configuration\r
325 (DHCP, BOOTP, RARP, etc.) is not finished yet.\r
326 @retval EFI_INVALID_PARAMETER One or more parameters are invalid\r
327 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:\r
328 * A transmit completion token with the same\r
329 Token-> CompletionToken.Event was already in the\r
330 transmission queue. * The current instance is in\r
331 Tcp4StateClosed state. * The current instance is\r
332 a passive one and it is in Tcp4StateListen\r
333 state. * User has called Close() to disconnect\r
334 this connection.\r
335 @retval EFI_NOT_READY The completion token could not be queued because\r
336 the transmit queue is full.\r
337 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of a\r
338 resource shortage.\r
339 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or\r
340 address.\r
341\r
342**/\r
343EFI_STATUS\r
344EFIAPI\r
345Tcp4Transmit (\r
346 IN EFI_TCP4_PROTOCOL *This,\r
347 IN EFI_TCP4_IO_TOKEN *Token\r
348 )\r
349{\r
350 SOCKET *Sock;\r
351 EFI_STATUS Status;\r
352\r
353 if (NULL == This ||\r
354 NULL == Token ||\r
355 NULL == Token->CompletionToken.Event ||\r
356 NULL == Token->Packet.TxData ||\r
357 0 == Token->Packet.TxData->FragmentCount ||\r
358 0 == Token->Packet.TxData->DataLength\r
359 ) {\r
360 return EFI_INVALID_PARAMETER;\r
361 }\r
362\r
363 Status = TcpChkDataBuf (\r
364 Token->Packet.TxData->DataLength,\r
365 Token->Packet.TxData->FragmentCount,\r
366 Token->Packet.TxData->FragmentTable\r
367 );\r
368 if (EFI_ERROR (Status)) {\r
369 return Status;\r
370 }\r
371\r
372 Sock = SOCK_FROM_THIS (This);\r
373\r
374 return SockSend (Sock, Token);\r
375}\r
376\r
377/**\r
378 Place an asynchronous receive request into the receiving queue.\r
379\r
380 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
381 @param[in] Token Pointer to a token that is associated with the\r
382 receive data descriptor.\r
383\r
384 @retval EFI_SUCCESS The receive completion token was cached\r
385 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
386 configured.\r
387 @retval EFI_NO_MAPPING When using a default address, configuration\r
388 (DHCP, BOOTP, RARP, etc.) is not finished yet.\r
389 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
390 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued\r
391 due to a lack of system resources.\r
392 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
393 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:\r
394 * A receive completion token with the same\r
395 Token->CompletionToken.Event was already in the\r
396 receive queue. * The current instance is in\r
397 Tcp4StateClosed state. * The current instance is\r
398 a passive one and it is in Tcp4StateListen\r
399 state. * User has called Close() to disconnect\r
400 this connection.\r
401 @retval EFI_CONNECTION_FIN The communication peer has closed the connection,\r
402 and there is no any buffered data in the receive\r
403 buffer of this instance.\r
404 @retval EFI_NOT_READY The receive request could not be queued because\r
405 the receive queue is full.\r
406\r
407**/\r
408EFI_STATUS\r
409EFIAPI\r
410Tcp4Receive (\r
411 IN EFI_TCP4_PROTOCOL *This,\r
412 IN EFI_TCP4_IO_TOKEN *Token\r
413 )\r
414{\r
415 SOCKET *Sock;\r
416 EFI_STATUS Status;\r
417\r
418 if (NULL == This ||\r
419 NULL == Token ||\r
420 NULL == Token->CompletionToken.Event ||\r
421 NULL == Token->Packet.RxData ||\r
422 0 == Token->Packet.RxData->FragmentCount ||\r
423 0 == Token->Packet.RxData->DataLength\r
424 ) {\r
425 return EFI_INVALID_PARAMETER;\r
426 }\r
427\r
428 Status = TcpChkDataBuf (\r
429 Token->Packet.RxData->DataLength,\r
430 Token->Packet.RxData->FragmentCount,\r
431 Token->Packet.RxData->FragmentTable\r
432 );\r
433 if (EFI_ERROR (Status)) {\r
434 return Status;\r
435 }\r
436\r
437 Sock = SOCK_FROM_THIS (This);\r
438\r
439 return SockRcv (Sock, Token);\r
440\r
441}\r
442\r
443/**\r
444 Disconnecting a TCP connection gracefully or reset a TCP connection.\r
445\r
446 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
447 @param[in] CloseToken Pointer to the close token to return when\r
448 operation finishes.\r
449\r
450 @retval EFI_SUCCESS The operation completed successfully.\r
451 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
452 configured.\r
453 @retval EFI_ACCESS_DENIED One or more of the following are TRUE: *\r
454 Configure() has been called with TcpConfigData\r
455 set to NULL, and this function has not returned.\r
456 * Previous Close() call on this instance has not\r
457 finished.\r
458 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid.\r
459 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish the\r
460 operation.\r
461 @retval EFI_DEVICE_ERROR Any unexpected category error not belonging to those\r
462 listed above.\r
463\r
464**/\r
465EFI_STATUS\r
466EFIAPI\r
467Tcp4Close (\r
468 IN EFI_TCP4_PROTOCOL *This,\r
469 IN EFI_TCP4_CLOSE_TOKEN *CloseToken\r
470 )\r
471{\r
472 SOCKET *Sock;\r
473\r
474 if (NULL == This || NULL == CloseToken || NULL == CloseToken->CompletionToken.Event) {\r
475 return EFI_INVALID_PARAMETER;\r
476 }\r
477\r
478 Sock = SOCK_FROM_THIS (This);\r
479\r
480 return SockClose (Sock, CloseToken, CloseToken->AbortOnClose);\r
481}\r
482\r
483/**\r
484 Abort an asynchronous connection, listen, transmission or receive request.\r
485\r
486 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
487 @param[in] Token Pointer to a token that has been issued by\r
488 Connect(), Accept(), Transmit() or Receive(). If\r
489 NULL, all pending tokens issued by the four\r
490 functions listed above will be aborted.\r
491\r
492 @retval EFI_UNSUPPORTED The operation is not supported in the current\r
493 implementation.\r
494\r
495**/\r
496EFI_STATUS\r
497EFIAPI\r
498Tcp4Cancel (\r
499 IN EFI_TCP4_PROTOCOL *This,\r
500 IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL\r
501 )\r
502{\r
503 return EFI_UNSUPPORTED;\r
504}\r
505\r
506/**\r
507 Poll to receive incoming data and transmit outgoing segments.\r
508\r
509 @param[in] This Pointer to the EFI_TCP4_PROTOCOL instance.\r
510\r
511 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
512 @retval EFI_INVALID_PARAMETER This is NULL.\r
513 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
514 @retval EFI_NOT_READY No incoming or outgoing data was processed.\r
515 @retval EFI_TIMEOUT Data was dropped out of the transmission or\r
516 receive queue. Consider increasing the polling\r
517 rate.\r
518\r
519**/\r
520EFI_STATUS\r
521EFIAPI\r
522Tcp4Poll (\r
523 IN EFI_TCP4_PROTOCOL *This\r
524 )\r
525{\r
526 SOCKET *Sock;\r
527 EFI_STATUS Status;\r
528\r
529 if (NULL == This) {\r
530 return EFI_INVALID_PARAMETER;\r
531 }\r
532\r
533 Sock = SOCK_FROM_THIS (This);\r
534\r
535 Status = Sock->ProtoHandler (Sock, SOCK_POLL, NULL);\r
536\r
537 return Status;\r
538}\r
539\r
540/**\r
541 Get the current operational status.\r
542\r
543 The GetModeData() function copies the current operational settings of this EFI TCPv6\r
544 Protocol instance into user-supplied buffers. This function can also be used to retrieve\r
545 the operational setting of underlying drivers such as IPv6, MNP, or SNP.\r
546\r
547 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
548 @param[out] Tcp6State The buffer in which the current TCP state is\r
549 returned. Optional parameter that may be NULL.\r
550 @param[out] Tcp6ConfigData The buffer in which the current TCP configuration\r
551 is returned. Optional parameter that may be NULL.\r
552 @param[out] Ip6ModeData The buffer in which the current IPv6 configuration\r
553 data used by the TCP instance is returned.\r
554 Optional parameter that may be NULL.\r
555 @param[out] MnpConfigData The buffer in which the current MNP configuration\r
556 data indirectly used by the TCP instance is returned.\r
557 Optional parameter that may be NULL.\r
558 @param[out] SnpModeData The buffer in which the current SNP mode data\r
559 indirectly used by the TCP instance is returned.\r
560 Optional parameter that may be NULL.\r
561\r
562 @retval EFI_SUCCESS The mode data was read.\r
563 @retval EFI_NOT_STARTED No configuration data is available because this instance hasn't\r
564 been started.\r
565 @retval EFI_INVALID_PARAMETER This is NULL.\r
566\r
567**/\r
568EFI_STATUS\r
569EFIAPI\r
570Tcp6GetModeData (\r
571 IN EFI_TCP6_PROTOCOL *This,\r
572 OUT EFI_TCP6_CONNECTION_STATE *Tcp6State OPTIONAL,\r
573 OUT EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL,\r
574 OUT EFI_IP6_MODE_DATA *Ip6ModeData OPTIONAL,\r
575 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,\r
576 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r
577 )\r
578{\r
579 TCP6_MODE_DATA TcpMode;\r
580 SOCKET *Sock;\r
581\r
582 if (NULL == This) {\r
583 return EFI_INVALID_PARAMETER;\r
584 }\r
585\r
586 Sock = SOCK_FROM_THIS (This);\r
587\r
588 TcpMode.Tcp6State = Tcp6State;\r
589 TcpMode.Tcp6ConfigData = Tcp6ConfigData;\r
590 TcpMode.Ip6ModeData = Ip6ModeData;\r
591 TcpMode.MnpConfigData = MnpConfigData;\r
592 TcpMode.SnpModeData = SnpModeData;\r
593\r
594 return SockGetMode (Sock, &TcpMode);\r
595}\r
596\r
597/**\r
598 Initialize or brutally reset the operational parameters for this EFI TCPv6 instance.\r
599\r
600 The Configure() function does the following:\r
601 - Initialize this TCP instance, i.e., initialize the communication end settings and\r
602 specify active open or passive open for an instance.\r
603 - Reset this TCP instance brutally, i.e., cancel all pending asynchronous tokens, flush\r
604 transmission and receiving buffer directly without informing the communication peer.\r
605\r
606 No other TCPv6 Protocol operation except Poll() can be executed by this instance until\r
607 it is configured properly. For an active TCP instance, after a proper configuration it\r
608 may call Connect() to initiate a three-way handshake. For a passive TCP instance,\r
609 its state transits to Tcp6StateListen after configuration, and Accept() may be\r
610 called to listen the incoming TCP connection requests. If Tcp6ConfigData is set to NULL,\r
611 the instance is reset. The resetting process will be done brutally, the state machine will\r
612 be set to Tcp6StateClosed directly, the receive queue and transmit queue will be flushed,\r
613 and no traffic is allowed through this instance.\r
614\r
615 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
616 @param[in] Tcp6ConfigData Pointer to the configure data to configure the instance.\r
617 If Tcp6ConfigData is set to NULL, the instance is reset.\r
618\r
619 @retval EFI_SUCCESS The operational settings were set, changed, or reset\r
620 successfully.\r
621 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source\r
622 address for this instance, but no source address was available for\r
623 use.\r
624 @retval EFI_INVALID_PARAMETER One or more of the following conditions are TRUE:\r
625 - This is NULL.\r
626 - Tcp6ConfigData->AccessPoint.StationAddress is neither zero nor\r
627 one of the configured IP addresses in the underlying IPv6 driver.\r
628 - Tcp6ConfigData->AccessPoint.RemoteAddress isn't a valid unicast\r
629 IPv6 address.\r
630 - Tcp6ConfigData->AccessPoint.RemoteAddress is zero or\r
631 Tcp6ConfigData->AccessPoint.RemotePort is zero when\r
632 Tcp6ConfigData->AccessPoint.ActiveFlag is TRUE.\r
633 - A same access point has been configured in other TCP\r
634 instance properly.\r
635 @retval EFI_ACCESS_DENIED Configuring a TCP instance when it is configured without\r
636 calling Configure() with NULL to reset it.\r
637 @retval EFI_UNSUPPORTED One or more of the control options are not supported in\r
638 the implementation.\r
639 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when\r
640 executing Configure().\r
641 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
642\r
643**/\r
644EFI_STATUS\r
645EFIAPI\r
646Tcp6Configure (\r
647 IN EFI_TCP6_PROTOCOL *This,\r
648 IN EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL\r
649 )\r
650{\r
651 EFI_TCP6_OPTION *Option;\r
652 SOCKET *Sock;\r
653 EFI_STATUS Status;\r
654 EFI_IPv6_ADDRESS *Ip;\r
655\r
656 if (NULL == This) {\r
657 return EFI_INVALID_PARAMETER;\r
658 }\r
659\r
660 //\r
661 // Tcp protocol related parameter check will be conducted here\r
662 //\r
663 if (NULL != Tcp6ConfigData) {\r
664\r
665 Ip = &Tcp6ConfigData->AccessPoint.RemoteAddress;\r
666 if (!NetIp6IsUnspecifiedAddr (Ip) && !NetIp6IsValidUnicast (Ip)) {\r
667 return EFI_INVALID_PARAMETER;\r
668 }\r
669\r
670 if (Tcp6ConfigData->AccessPoint.ActiveFlag &&\r
671 (0 == Tcp6ConfigData->AccessPoint.RemotePort || NetIp6IsUnspecifiedAddr (Ip))\r
672 ) {\r
673 return EFI_INVALID_PARAMETER;\r
674 }\r
675\r
676 Ip = &Tcp6ConfigData->AccessPoint.StationAddress;\r
677 if (!NetIp6IsUnspecifiedAddr (Ip) && !NetIp6IsValidUnicast (Ip)) {\r
678 return EFI_INVALID_PARAMETER;\r
679 }\r
680\r
681 Option = Tcp6ConfigData->ControlOption;\r
682 if ((NULL != Option) && (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {\r
683 return EFI_UNSUPPORTED;\r
684 }\r
685 }\r
686\r
687 Sock = SOCK_FROM_THIS (This);\r
688\r
689 if (NULL == Tcp6ConfigData) {\r
690 return SockFlush (Sock);\r
691 }\r
692\r
693 Status = SockConfigure (Sock, Tcp6ConfigData);\r
694\r
695 if (EFI_NO_MAPPING == Status) {\r
696 Sock->ConfigureState = SO_NO_MAPPING;\r
697 }\r
698\r
699 return Status;\r
700}\r
701\r
702/**\r
703 Initiate a nonblocking TCP connection request for an active TCP instance.\r
704\r
705 The Connect() function will initiate an active open to the remote peer configured\r
706 in a current TCP instance if it is configured active. If the connection succeeds or\r
707 fails due to any error, the ConnectionToken->CompletionToken.Event will be signaled\r
708 and ConnectionToken->CompletionToken.Status will be updated accordingly. This\r
709 function can only be called for the TCP instance in the Tcp6StateClosed state. The\r
710 instance will transfer into Tcp6StateSynSent if the function returns EFI_SUCCESS.\r
711 If a TCP three-way handshake succeeds, its state will become Tcp6StateEstablished.\r
712 Otherwise, the state will return to Tcp6StateClosed.\r
713\r
714 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
715 @param[in] ConnectionToken Pointer to the connection token to return when the TCP three\r
716 way handshake finishes.\r
717\r
718 @retval EFI_SUCCESS The connection request successfully initiated and the state of\r
719 this TCP instance has been changed to Tcp6StateSynSent.\r
720 @retval EFI_NOT_STARTED This EFI TCPv6 Protocol instance has not been configured.\r
721 @retval EFI_ACCESS_DENIED One or more of the following conditions are TRUE:\r
722 - This instance is not configured as an active one.\r
723 - This instance is not in Tcp6StateClosed state.\r
724 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r
725 - This is NULL.\r
726 - ConnectionToken is NULL.\r
727 - ConnectionToken->CompletionToken.Event is NULL.\r
728 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resources to initiate the active open.\r
729 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
730\r
731**/\r
732EFI_STATUS\r
733EFIAPI\r
734Tcp6Connect (\r
735 IN EFI_TCP6_PROTOCOL *This,\r
736 IN EFI_TCP6_CONNECTION_TOKEN *ConnectionToken\r
737 )\r
738{\r
739 SOCKET *Sock;\r
740\r
741 if (NULL == This || NULL == ConnectionToken || NULL == ConnectionToken->CompletionToken.Event) {\r
742 return EFI_INVALID_PARAMETER;\r
743 }\r
744\r
745 Sock = SOCK_FROM_THIS (This);\r
746\r
747 return SockConnect (Sock, ConnectionToken);\r
748}\r
749\r
750/**\r
751 Listen on the passive instance to accept an incoming connection request. This is a\r
752 nonblocking operation.\r
753\r
754 The Accept() function initiates an asynchronous accept request to wait for an incoming\r
755 connection on the passive TCP instance. If a remote peer successfully establishes a\r
756 connection with this instance, a new TCP instance will be created and its handle will\r
757 be returned in ListenToken->NewChildHandle. The newly created instance is configured\r
758 by inheriting the passive instance's configuration and is ready for use upon return.\r
759 The new instance is in the Tcp6StateEstablished state.\r
760\r
761 The ListenToken->CompletionToken.Event will be signaled when a new connection is\r
762 accepted, when a user aborts the listen or when a connection is reset.\r
763\r
764 This function only can be called when a current TCP instance is in Tcp6StateListen state.\r
765\r
766 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
767 @param[in] ListenToken Pointer to the listen token to return when operation finishes.\r
768\r
769\r
770 @retval EFI_SUCCESS The listen token queued successfully.\r
771 @retval EFI_NOT_STARTED This EFI TCPv6 Protocol instance has not been configured.\r
772 @retval EFI_ACCESS_DENIED One or more of the following are TRUE:\r
773 - This instance is not a passive instance.\r
774 - This instance is not in Tcp6StateListen state.\r
775 - The same listen token has already existed in the listen\r
776 token queue of this TCP instance.\r
777 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r
778 - This is NULL.\r
779 - ListenToken is NULL.\r
780 - ListentToken->CompletionToken.Event is NULL.\r
781 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the operation.\r
782 @retval EFI_DEVICE_ERROR Any unexpected error not belonging to a category listed above.\r
783\r
784**/\r
785EFI_STATUS\r
786EFIAPI\r
787Tcp6Accept (\r
788 IN EFI_TCP6_PROTOCOL *This,\r
789 IN EFI_TCP6_LISTEN_TOKEN *ListenToken\r
790 )\r
791{\r
792 SOCKET *Sock;\r
793\r
794 if (NULL == This || NULL == ListenToken || NULL == ListenToken->CompletionToken.Event) {\r
795 return EFI_INVALID_PARAMETER;\r
796 }\r
797\r
798 Sock = SOCK_FROM_THIS (This);\r
799\r
800 return SockAccept (Sock, ListenToken);\r
801}\r
802\r
803/**\r
804 Queues outgoing data into the transmit queue.\r
805\r
806 The Transmit() function queues a sending request to this TCP instance along with the\r
807 user data. The status of the token is updated and the event in the token will be\r
808 signaled once the data is sent out or an error occurs.\r
809\r
810 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
811 @param[in] Token Pointer to the completion token to queue to the transmit queue.\r
812\r
813 @retval EFI_SUCCESS The data has been queued for transmission.\r
814 @retval EFI_NOT_STARTED This EFI TCPv6 Protocol instance has not been configured.\r
815 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a\r
816 source address for this instance, but no source address was\r
817 available for use.\r
818 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r
819 - This is NULL.\r
820 - Token is NULL.\r
821 - Token->CompletionToken.Event is NULL.\r
822 - Token->Packet.TxData is NULL.\r
823 - Token->Packet.FragmentCount is zero.\r
824 - Token->Packet.DataLength is not equal to the sum of fragment lengths.\r
825 @retval EFI_ACCESS_DENIED One or more of the following conditions are TRUE:\r
826 - A transmit completion token with the same Token->\r
827 CompletionToken.Event was already in the\r
828 transmission queue.\r
829 - The current instance is in Tcp6StateClosed state.\r
830 - The current instance is a passive one and it is in\r
831 Tcp6StateListen state.\r
832 - User has called Close() to disconnect this connection.\r
833 @retval EFI_NOT_READY The completion token could not be queued because the\r
834 transmit queue is full.\r
835 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of resource\r
836 shortage.\r
837 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or address.\r
838\r
839**/\r
840EFI_STATUS\r
841EFIAPI\r
842Tcp6Transmit (\r
843 IN EFI_TCP6_PROTOCOL *This,\r
844 IN EFI_TCP6_IO_TOKEN *Token\r
845 )\r
846{\r
847 SOCKET *Sock;\r
848 EFI_STATUS Status;\r
849\r
850 if (NULL == This ||\r
851 NULL == Token ||\r
852 NULL == Token->CompletionToken.Event ||\r
853 NULL == Token->Packet.TxData ||\r
854 0 == Token->Packet.TxData->FragmentCount ||\r
855 0 == Token->Packet.TxData->DataLength\r
856 ) {\r
857 return EFI_INVALID_PARAMETER;\r
858 }\r
859\r
860 Status = TcpChkDataBuf (\r
861 Token->Packet.TxData->DataLength,\r
862 Token->Packet.TxData->FragmentCount,\r
863 (EFI_TCP4_FRAGMENT_DATA *) Token->Packet.TxData->FragmentTable\r
864 );\r
865 if (EFI_ERROR (Status)) {\r
866 return Status;\r
867 }\r
868\r
869 Sock = SOCK_FROM_THIS (This);\r
870\r
871 return SockSend (Sock, Token);\r
872}\r
873\r
874/**\r
875 Places an asynchronous receive request into the receiving queue.\r
876\r
877 The Receive() function places a completion token into the receive packet queue. This\r
878 function is always asynchronous. The caller must allocate the Token->CompletionToken.Event\r
879 and the FragmentBuffer used to receive data. The caller also must fill the DataLength that\r
880 represents the whole length of all FragmentBuffer. When the receive operation completes, the\r
881 EFI TCPv6 Protocol driver updates the Token->CompletionToken.Status and Token->Packet.RxData\r
882 fields, and the Token->CompletionToken.Event is signaled. If data obtained, the data and its length\r
883 will be copied into the FragmentTable; at the same time the full length of received data will\r
884 be recorded in the DataLength fields. Providing a proper notification function and context\r
885 for the event enables the user to receive the notification and receiving status. That\r
886 notification function is guaranteed to not be re-entered.\r
887\r
888 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
889 @param[in] Token Pointer to a token that is associated with the receive data\r
890 descriptor.\r
891\r
892 @retval EFI_SUCCESS The receive completion token was cached.\r
893 @retval EFI_NOT_STARTED This EFI TCPv6 Protocol instance has not been configured.\r
894 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source\r
895 address for this instance, but no source address was available for use.\r
896 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
897 - This is NULL.\r
898 - Token is NULL.\r
899 - Token->CompletionToken.Event is NULL.\r
900 - Token->Packet.RxData is NULL.\r
901 - Token->Packet.RxData->DataLength is 0.\r
902 - The Token->Packet.RxData->DataLength is not the\r
903 sum of all FragmentBuffer length in FragmentTable.\r
904 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of\r
905 system resources (usually memory).\r
906 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
907 The EFI TCPv6 Protocol instance has been reset to startup defaults.\r
908 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:\r
909 - A receive completion token with the same Token->CompletionToken.Event\r
910 was already in the receive queue.\r
911 - The current instance is in Tcp6StateClosed state.\r
912 - The current instance is a passive one and it is in\r
913 Tcp6StateListen state.\r
914 - User has called Close() to disconnect this connection.\r
915 @retval EFI_CONNECTION_FIN The communication peer has closed the connection and there is no\r
916 buffered data in the receive buffer of this instance.\r
917 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.\r
918\r
919**/\r
920EFI_STATUS\r
921EFIAPI\r
922Tcp6Receive (\r
923 IN EFI_TCP6_PROTOCOL *This,\r
924 IN EFI_TCP6_IO_TOKEN *Token\r
925 )\r
926{\r
927 SOCKET *Sock;\r
928 EFI_STATUS Status;\r
929\r
930 if (NULL == This ||\r
931 NULL == Token ||\r
932 NULL == Token->CompletionToken.Event ||\r
933 NULL == Token->Packet.RxData ||\r
934 0 == Token->Packet.RxData->FragmentCount ||\r
935 0 == Token->Packet.RxData->DataLength\r
936 ) {\r
937 return EFI_INVALID_PARAMETER;\r
938 }\r
939\r
940 Status = TcpChkDataBuf (\r
941 Token->Packet.RxData->DataLength,\r
942 Token->Packet.RxData->FragmentCount,\r
943 (EFI_TCP4_FRAGMENT_DATA *) Token->Packet.RxData->FragmentTable\r
944 );\r
945 if (EFI_ERROR (Status)) {\r
946 return Status;\r
947 }\r
948\r
949 Sock = SOCK_FROM_THIS (This);\r
950\r
951 return SockRcv (Sock, Token);\r
952}\r
953\r
954/**\r
955 Disconnecting a TCP connection gracefully or reset a TCP connection. This function is a\r
956 nonblocking operation.\r
957\r
958 Initiate an asynchronous close token to the TCP driver. After Close() is called, any buffered\r
959 transmission data will be sent by the TCP driver, and the current instance will have a graceful close\r
960 working flow described as RFC 793 if AbortOnClose is set to FALSE. Otherwise, a rest packet\r
961 will be sent by TCP driver to fast disconnect this connection. When the close operation completes\r
962 successfully the TCP instance is in Tcp6StateClosed state, all pending asynchronous\r
963 operations are signaled, and any buffers used for TCP network traffic are flushed.\r
964\r
965 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
966 @param[in] CloseToken Pointer to the close token to return when operation finishes.\r
967\r
968 @retval EFI_SUCCESS The Close() was called successfully.\r
969 @retval EFI_NOT_STARTED This EFI TCPv6 Protocol instance has not been configured.\r
970 @retval EFI_ACCESS_DENIED One or more of the following are TRUE:\r
971 - CloseToken or CloseToken->CompletionToken.Event is already in use.\r
972 - Previous Close() call on this instance has not finished.\r
973 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r
974 - This is NULL.\r
975 - CloseToken is NULL.\r
976 - CloseToken->CompletionToken.Event is NULL.\r
977 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the operation.\r
978 @retval EFI_DEVICE_ERROR Any unexpected error not belonging to error categories given above.\r
979\r
980**/\r
981EFI_STATUS\r
982EFIAPI\r
983Tcp6Close (\r
984 IN EFI_TCP6_PROTOCOL *This,\r
985 IN EFI_TCP6_CLOSE_TOKEN *CloseToken\r
986 )\r
987{\r
988 SOCKET *Sock;\r
989\r
990 if (NULL == This || NULL == CloseToken || NULL == CloseToken->CompletionToken.Event) {\r
991 return EFI_INVALID_PARAMETER;\r
992 }\r
993\r
994 Sock = SOCK_FROM_THIS (This);\r
995\r
996 return SockClose (Sock, CloseToken, CloseToken->AbortOnClose);\r
997}\r
998\r
999/**\r
1000 Abort an asynchronous connection, listen, transmission, or receive request.\r
1001\r
1002 The Cancel() function aborts a pending connection, listen, transmit, or\r
1003 receive request.\r
1004\r
1005 If Token is not NULL and the token is in the connection, listen, transmission,\r
1006 or receive queue when it is being cancelled, its Token->Status will be set\r
1007 to EFI_ABORTED, and then Token->Event will be signaled.\r
1008\r
1009 If the token is not in one of the queues, which usually means that the\r
1010 asynchronous operation has completed, EFI_NOT_FOUND is returned.\r
1011\r
1012 If Token is NULL all asynchronous token issued by Connect(), Accept(),\r
1013 Transmit(), and Receive() will be aborted.\r
1014\r
1015 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
1016 @param[in] Token Pointer to a token that has been issued by\r
1017 EFI_TCP6_PROTOCOL.Connect(),\r
1018 EFI_TCP6_PROTOCOL.Accept(),\r
1019 EFI_TCP6_PROTOCOL.Transmit() or\r
1020 EFI_TCP6_PROTOCOL.Receive(). If NULL, all pending\r
1021 tokens issued by above four functions will be aborted. Type\r
1022 EFI_TCP6_COMPLETION_TOKEN is defined in\r
1023 EFI_TCP_PROTOCOL.Connect().\r
1024\r
1025 @retval EFI_UNSUPPORTED The implementation does not support this function.\r
1026\r
1027**/\r
1028EFI_STATUS\r
1029EFIAPI\r
1030Tcp6Cancel (\r
1031 IN EFI_TCP6_PROTOCOL *This,\r
1032 IN EFI_TCP6_COMPLETION_TOKEN *Token OPTIONAL\r
1033 )\r
1034{\r
1035 return EFI_UNSUPPORTED;\r
1036}\r
1037\r
1038/**\r
1039 Poll to receive incoming data and transmit outgoing segments.\r
1040\r
1041 The Poll() function increases the rate that data is moved between the network\r
1042 and application, and can be called when the TCP instance is created successfully.\r
1043 Its use is optional.\r
1044\r
1045 @param[in] This Pointer to the EFI_TCP6_PROTOCOL instance.\r
1046\r
1047 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
1048 @retval EFI_INVALID_PARAMETER This is NULL.\r
1049 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
1050 @retval EFI_NOT_READY No incoming or outgoing data is processed.\r
1051 @retval EFI_TIMEOUT Data was dropped out of the transmission or receive queue.\r
1052 Consider increasing the polling rate.\r
1053\r
1054**/\r
1055EFI_STATUS\r
1056EFIAPI\r
1057Tcp6Poll (\r
1058 IN EFI_TCP6_PROTOCOL *This\r
1059 )\r
1060{\r
1061 SOCKET *Sock;\r
1062 EFI_STATUS Status;\r
1063\r
1064 if (NULL == This) {\r
1065 return EFI_INVALID_PARAMETER;\r
1066 }\r
1067\r
1068 Sock = SOCK_FROM_THIS (This);\r
1069\r
1070 Status = Sock->ProtoHandler (Sock, SOCK_POLL, NULL);\r
1071\r
1072 return Status;\r
1073}\r
1074\r