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