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