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