VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/TcpDxe/TcpMain.c

Last change on this file was 99404, checked in by vboxsync, 22 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette