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