]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c
BaseTools/tools_def ARM: use softfloat target for CLANG3x
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Main.c
CommitLineData
8a67d61d 1/** @file\r
dfc1f033 2 Implementation of TCP4 protocol services.\r
8a67d61d 3\r
d1102dba 4Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
8a67d61d 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
dfc1f033 8http://opensource.org/licenses/bsd-license.php<BR>\r
8a67d61d 9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
8a67d61d 13**/\r
14\r
dfc1f033 15\r
8a67d61d 16#include "Tcp4Main.h"\r
17\r
18\r
19/**\r
20 Check the integrity of the data buffer.\r
21\r
22 @param DataLen The total length of the data buffer.\r
23 @param FragmentCount The fragment count of the fragment table.\r
24 @param FragmentTable Pointer to the fragment table of the data\r
25 buffer.\r
26\r
27 @retval EFI_SUCCESS The integrity check is passed.\r
28 @retval EFI_INVALID_PARAMETER The integrity check is failed.\r
29\r
30**/\r
8a67d61d 31EFI_STATUS\r
32Tcp4ChkDataBuf (\r
33 IN UINT32 DataLen,\r
34 IN UINT32 FragmentCount,\r
35 IN EFI_TCP4_FRAGMENT_DATA *FragmentTable\r
36 )\r
37{\r
38 UINT32 Index;\r
39\r
40 UINT32 Len;\r
41\r
42 for (Index = 0, Len = 0; Index < FragmentCount; Index++) {\r
4eb65aff 43 Len = Len + (UINT32) FragmentTable[Index].FragmentLength;\r
8a67d61d 44 }\r
45\r
46 if (DataLen != Len) {\r
47 return EFI_INVALID_PARAMETER;\r
48 }\r
49\r
50 return EFI_SUCCESS;\r
51}\r
52\r
53\r
54/**\r
55 Get the current operational status.\r
d1102dba
LG
56\r
57 The GetModeData() function copies the current operational settings of this\r
58 EFI TCPv4 Protocol instance into user-supplied buffers. This function can\r
59 also be used to retrieve the operational setting of underlying drivers\r
85511ddf 60 such as IPv4, MNP, or SNP.\r
8a67d61d 61\r
62 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
63 @param Tcp4State Pointer to the buffer to receive the current TCP\r
64 state.\r
65 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP\r
66 configuration.\r
d1102dba 67 @param Ip4ModeData Pointer to the buffer to receive the current IPv4\r
85511ddf 68 configuration data used by the TCPv4 instance.\r
8a67d61d 69 @param MnpConfigData Pointer to the buffer to receive the current MNP\r
70 configuration data indirectly used by the TCPv4\r
71 Instance.\r
72 @param SnpModeData Pointer to the buffer to receive the current SNP\r
73 configuration data indirectly used by the TCPv4\r
74 Instance.\r
75\r
76 @retval EFI_SUCCESS The mode data was read.\r
77 @retval EFI_NOT_STARTED No configuration data is available because this\r
78 instance hasn't been started.\r
79 @retval EFI_INVALID_PARAMETER This is NULL.\r
80\r
81**/\r
82EFI_STATUS\r
83EFIAPI\r
84Tcp4GetModeData (\r
db0f0d3c 85 IN EFI_TCP4_PROTOCOL *This,\r
86 OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL,\r
87 OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL,\r
88 OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,\r
89 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,\r
90 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r
8a67d61d 91 )\r
92{\r
93 TCP4_MODE_DATA TcpMode;\r
94 SOCKET *Sock;\r
95\r
96 if (NULL == This) {\r
97 return EFI_INVALID_PARAMETER;\r
98 }\r
99\r
100 Sock = SOCK_FROM_THIS (This);\r
101\r
102 TcpMode.Tcp4State = Tcp4State;\r
103 TcpMode.Tcp4ConfigData = Tcp4ConfigData;\r
104 TcpMode.Ip4ModeData = Ip4ModeData;\r
105 TcpMode.MnpConfigData = MnpConfigData;\r
106 TcpMode.SnpModeData = SnpModeData;\r
107\r
108 return SockGetMode (Sock, &TcpMode);\r
109}\r
110\r
111\r
112/**\r
113 Initialize or brutally reset the operational parameters for\r
114 this EFI TCPv4 instance.\r
d1102dba 115\r
85511ddf 116 The Configure() function does the following:\r
d1102dba 117 * Initialize this EFI TCPv4 instance, i.e., initialize the communication end\r
85511ddf 118 setting, specify active open or passive open for an instance.\r
d1102dba
LG
119 * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchronous\r
120 tokens, flush transmission and receiving buffer directly without informing\r
85511ddf 121 the communication peer.\r
d1102dba
LG
122 No other TCPv4 Protocol operation can be executed by this instance\r
123 until it is configured properly. For an active TCP4 instance, after a proper\r
124 configuration it may call Connect() to initiates the three-way handshake.\r
125 For a passive TCP4 instance, its state will transit to Tcp4StateListen after\r
126 configuration, and Accept() may be called to listen the incoming TCP connection\r
127 request. If TcpConfigData is set to NULL, the instance is reset. Resetting\r
128 process will be done brutally, the state machine will be set to Tcp4StateClosed\r
129 directly, the receive queue and transmit queue will be flushed, and no traffic is\r
85511ddf 130 allowed through this instance.\r
8a67d61d 131\r
132 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
133 @param TcpConfigData Pointer to the configure data to configure the\r
134 instance.\r
135\r
136 @retval EFI_SUCCESS The operational settings are set, changed, or\r
137 reset successfully.\r
138 @retval EFI_NO_MAPPING When using a default address, configuration\r
139 (through DHCP, BOOTP, RARP, etc.) is not\r
140 finished.\r
141 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
142 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already\r
143 configured.\r
144 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
145 @retval EFI_UNSUPPORTED One or more of the control options are not\r
146 supported in the implementation.\r
147 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
148\r
149**/\r
150EFI_STATUS\r
151EFIAPI\r
152Tcp4Configure (\r
85511ddf 153 IN EFI_TCP4_PROTOCOL *This,\r
154 IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL\r
8a67d61d 155 )\r
156{\r
157 EFI_TCP4_OPTION *Option;\r
158 SOCKET *Sock;\r
159 EFI_STATUS Status;\r
772db4bb 160 IP4_ADDR Ip;\r
687a2e5f 161 IP4_ADDR SubnetMask;\r
8a67d61d 162\r
163 if (NULL == This) {\r
164 return EFI_INVALID_PARAMETER;\r
165 }\r
166\r
167 //\r
168 // Tcp protocol related parameter check will be conducted here\r
169 //\r
170 if (NULL != TcpConfigData) {\r
772db4bb 171\r
e48e37fc 172 CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));\r
01b5ac88 173 if (IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
772db4bb 174 return EFI_INVALID_PARAMETER;\r
175 }\r
176\r
177 if (TcpConfigData->AccessPoint.ActiveFlag &&\r
178 (0 == TcpConfigData->AccessPoint.RemotePort || (Ip == 0))) {\r
8a67d61d 179 return EFI_INVALID_PARAMETER;\r
180 }\r
181\r
182 if (!TcpConfigData->AccessPoint.UseDefaultAddress) {\r
772db4bb 183\r
e48e37fc 184 CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP4_ADDR));\r
185 CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof (IP4_ADDR));\r
d1102dba 186 if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) ||\r
d0e76ac5 187 (SubnetMask != 0 && !NetIp4IsUnicast (NTOHL (Ip), NTOHL (SubnetMask)))) {\r
8a67d61d 188 return EFI_INVALID_PARAMETER;\r
189 }\r
190 }\r
191\r
8a67d61d 192 Option = TcpConfigData->ControlOption;\r
193 if ((NULL != Option) &&\r
194 (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {\r
195 return EFI_UNSUPPORTED;\r
196 }\r
197 }\r
198\r
199 Sock = SOCK_FROM_THIS (This);\r
200\r
201 if (NULL == TcpConfigData) {\r
202 return SockFlush (Sock);\r
203 }\r
204\r
205 Status = SockConfigure (Sock, TcpConfigData);\r
206\r
207 if (EFI_NO_MAPPING == Status) {\r
208 Sock->ConfigureState = SO_NO_MAPPING;\r
209 }\r
210\r
211 return Status;\r
212}\r
213\r
214\r
215/**\r
216 Add or delete routing entries.\r
d1102dba 217\r
dfc1f033 218 The Routes() function adds or deletes a route from the instance's routing table.\r
d1102dba 219 The most specific route is selected by comparing the SubnetAddress with the\r
dfc1f033 220 destination IP address's arithmetical AND to the SubnetMask.\r
d1102dba 221 The default route is added with both SubnetAddress and SubnetMask set to 0.0.0.0.\r
85511ddf 222 The default route matches all destination IP addresses if there is no more specific route.\r
d1102dba
LG
223 Direct route is added with GatewayAddress set to 0.0.0.0. Packets are sent to\r
224 the destination host if its address can be found in the Address Resolution Protocol (ARP)\r
225 cache or it is on the local subnet. If the instance is configured to use default\r
85511ddf 226 address, a direct route to the local network will be added automatically.\r
d1102dba
LG
227 Each TCP instance has its own independent routing table. Instance that uses the\r
228 default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's routing table.\r
229 The copy will be updated automatically whenever the IP driver reconfigures its\r
230 instance. As a result, the previous modification to the instance's local copy\r
231 will be lost. The priority of checking the route table is specific with IP\r
85511ddf 232 implementation and every IP implementation must comply with RFC 1122.\r
8a67d61d 233\r
234 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
235 @param DeleteRoute If TRUE, delete the specified route from routing\r
236 table; if FALSE, add the specified route to\r
237 routing table.\r
d1102dba 238 DestinationAddress and SubnetMask are used as\r
85511ddf 239 the keywords to search route entry.\r
8a67d61d 240 @param SubnetAddress The destination network.\r
241 @param SubnetMask The subnet mask for the destination network.\r
d1102dba
LG
242 @param GatewayAddress The gateway address for this route.\r
243 It must be on the same subnet with the station\r
85511ddf 244 address unless a direct route is specified.\r
d1102dba 245\r
8a67d61d 246 @retval EFI_SUCCESS The operation completed successfully.\r
247 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been\r
248 configured.\r
249 @retval EFI_NO_MAPPING When using a default address, configuration\r
250 (through DHCP, BOOTP, RARP, etc.) is not\r
251 finished.\r
252 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
253 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the\r
254 entry to the routing table.\r
255 @retval EFI_NOT_FOUND This route is not in the routing table.\r
256 @retval EFI_ACCESS_DENIED This route is already in the routing table.\r
257 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.\r
258\r
259**/\r
260EFI_STATUS\r
261EFIAPI\r
262Tcp4Routes (\r
263 IN EFI_TCP4_PROTOCOL *This,\r
264 IN BOOLEAN DeleteRoute,\r
265 IN EFI_IPv4_ADDRESS *SubnetAddress,\r
266 IN EFI_IPv4_ADDRESS *SubnetMask,\r
267 IN EFI_IPv4_ADDRESS *GatewayAddress\r
268 )\r
269{\r
270 SOCKET *Sock;\r
271 TCP4_ROUTE_INFO RouteInfo;\r
272\r
273 if (NULL == This) {\r
274 return EFI_INVALID_PARAMETER;\r
275 }\r
276\r
277 Sock = SOCK_FROM_THIS (This);\r
278\r
279 RouteInfo.DeleteRoute = DeleteRoute;\r
280 RouteInfo.SubnetAddress = SubnetAddress;\r
281 RouteInfo.SubnetMask = SubnetMask;\r
282 RouteInfo.GatewayAddress = GatewayAddress;\r
283\r
284 return SockRoute (Sock, &RouteInfo);\r
285}\r
286\r
287\r
288/**\r
289 Initiate a nonblocking TCP connection request for an active TCP instance.\r
290\r
d1102dba
LG
291 The Connect() function will initiate an active open to the remote peer configured\r
292 in current TCP instance if it is configured active. If the connection succeeds\r
293 or fails due to any error, the ConnectionToken->CompletionToken.Event will be\r
294 signaled and ConnectionToken->CompletionToken.Status will be updated accordingly.\r
295 This function can only be called for the TCP instance in Tcp4StateClosed state.\r
296 The instance will transfer into Tcp4StateSynSent if the function returns EFI_SUCCESS.\r
297 If TCP three way handshake succeeds, its state will become Tcp4StateEstablished,\r
85511ddf 298 otherwise, the state will return to Tcp4StateClosed.\r
d1102dba 299\r
8a67d61d 300 @param This Pointer to the EFI_TCP4_PROTOCOL instance\r
301 @param ConnectionToken Pointer to the connection token to return when\r
302 the TCP three way handshake finishes.\r
303\r
d1102dba
LG
304 @retval EFI_SUCCESS The connection request is successfully initiated\r
305 and the state of this TCPv4 instance has\r
85511ddf 306 been changed to Tcp4StateSynSent.\r
8a67d61d 307 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been\r
308 configured.\r
309 @retval EFI_ACCESS_DENIED The instance is not configured as an active one\r
310 or it is not in Tcp4StateClosed state.\r
311 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
312 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to\r
313 initiate the active open.\r
314 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
315\r
316**/\r
317EFI_STATUS\r
318EFIAPI\r
319Tcp4Connect (\r
320 IN EFI_TCP4_PROTOCOL *This,\r
321 IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken\r
322 )\r
323{\r
324 SOCKET *Sock;\r
325\r
326 if (NULL == This ||\r
327 NULL == ConnectionToken ||\r
328 NULL == ConnectionToken->CompletionToken.Event) {\r
329 return EFI_INVALID_PARAMETER;\r
330 }\r
331\r
332 Sock = SOCK_FROM_THIS (This);\r
333\r
334 return SockConnect (Sock, ConnectionToken);\r
335}\r
336\r
337\r
338/**\r
339 Listen on the passive instance to accept an incoming connection request.\r
340\r
d1102dba
LG
341 The Accept() function initiates an asynchronous accept request to wait for an\r
342 incoming connection on the passive TCP instance. If a remote peer successfully\r
343 establishes a connection with this instance, a new TCP instance will be created\r
344 and its handle will be returned in ListenToken->NewChildHandle. The newly created\r
345 instance is configured by inheriting the passive instance's configuration and is\r
85511ddf 346 ready for use upon return. The instance is in the Tcp4StateEstablished state.\r
d1102dba
LG
347 The ListenToken->CompletionToken.Event will be signaled when a new connection\r
348 is accepted, user aborts the listen or connection is reset. This function only\r
85511ddf 349 can be called when current TCP instance is in Tcp4StateListen state.\r
350\r
8a67d61d 351 @param This Pointer to the EFI_TCP4_PROTOCOL instance\r
352 @param ListenToken Pointer to the listen token to return when\r
353 operation finishes.\r
354\r
355 @retval EFI_SUCCESS The listen token has been queued successfully.\r
356 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
357 configured.\r
358 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not\r
359 in Tcp4StateListen state or a same listen token\r
360 has already existed in the listen token queue of\r
361 this TCP instance.\r
362 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
363 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish\r
364 the operation.\r
85511ddf 365 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above category error.\r
8a67d61d 366\r
367**/\r
368EFI_STATUS\r
369EFIAPI\r
370Tcp4Accept (\r
371 IN EFI_TCP4_PROTOCOL *This,\r
372 IN EFI_TCP4_LISTEN_TOKEN *ListenToken\r
373 )\r
374{\r
375 SOCKET *Sock;\r
376\r
377 if (NULL == This ||\r
378 NULL == ListenToken ||\r
379 NULL == ListenToken->CompletionToken.Event) {\r
380 return EFI_INVALID_PARAMETER;\r
381 }\r
382\r
383 Sock = SOCK_FROM_THIS (This);\r
384\r
385 return SockAccept (Sock, ListenToken);\r
386}\r
387\r
388\r
389/**\r
120db52c 390 Queues outgoing data into the transmit queue.\r
8a67d61d 391\r
d1102dba
LG
392 The Transmit() function queues a sending request to this TCPv4 instance along\r
393 with the user data. The status of the token is updated and the event in the token\r
85511ddf 394 will be signaled once the data is sent out or some error occurs.\r
395\r
8a67d61d 396 @param This Pointer to the EFI_TCP4_PROTOCOL instance\r
397 @param Token Pointer to the completion token to queue to the\r
398 transmit queue\r
399\r
120db52c 400 @retval EFI_SUCCESS The data has been queued for transmission.\r
8a67d61d 401 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
402 configured.\r
403 @retval EFI_NO_MAPPING When using a default address, configuration\r
404 (DHCP, BOOTP, RARP, etc.) is not finished yet.\r
120db52c 405 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
8a67d61d 406 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:\r
407 * A transmit completion token with the same\r
85511ddf 408 Token-> CompletionToken.Event was already in the\r
d1102dba
LG
409 transmission queue.\r
410 * The current instance is in Tcp4StateClosed state\r
411 * The current instance is a passive one and\r
412 it is in Tcp4StateListen state.\r
413 * User has called Close() to disconnect this\r
85511ddf 414 connection.\r
8a67d61d 415 @retval EFI_NOT_READY The completion token could not be queued because\r
416 the transmit queue is full.\r
417 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of\r
418 resource shortage.\r
419 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or\r
420 address.\r
421\r
422**/\r
423EFI_STATUS\r
424EFIAPI\r
425Tcp4Transmit (\r
426 IN EFI_TCP4_PROTOCOL *This,\r
427 IN EFI_TCP4_IO_TOKEN *Token\r
428 )\r
429{\r
430 SOCKET *Sock;\r
431 EFI_STATUS Status;\r
432\r
433 if (NULL == This ||\r
434 NULL == Token ||\r
435 NULL == Token->CompletionToken.Event ||\r
436 NULL == Token->Packet.TxData ||\r
437 0 == Token->Packet.TxData->FragmentCount ||\r
438 0 == Token->Packet.TxData->DataLength\r
439 ) {\r
440 return EFI_INVALID_PARAMETER;\r
441 }\r
442\r
443 Status = Tcp4ChkDataBuf (\r
4eb65aff 444 (UINT32) Token->Packet.TxData->DataLength,\r
445 (UINT32) Token->Packet.TxData->FragmentCount,\r
8a67d61d 446 Token->Packet.TxData->FragmentTable\r
447 );\r
448 if (EFI_ERROR (Status)) {\r
449 return Status;\r
450 }\r
451\r
452 Sock = SOCK_FROM_THIS (This);\r
453\r
454 return SockSend (Sock, Token);\r
455\r
456}\r
457\r
458\r
459/**\r
460 Place an asynchronous receive request into the receiving queue.\r
461\r
d1102dba
LG
462 The Receive() function places a completion token into the receive packet queue.\r
463 This function is always asynchronous. The caller must allocate the\r
464 Token->CompletionToken.Event and the FragmentBuffer used to receive data. He also\r
465 must fill the DataLength which represents the whole length of all FragmentBuffer.\r
466 When the receive operation completes, the EFI TCPv4 Protocol driver updates the\r
467 Token->CompletionToken.Status and Token->Packet.RxData fields and the\r
468 Token->CompletionToken.Event is signaled. If got data the data and its length\r
469 will be copy into the FragmentTable, in the same time the full length of received\r
470 data will be recorded in the DataLength fields. Providing a proper notification\r
471 function and context for the event will enable the user to receive the notification\r
85511ddf 472 and receiving status. That notification function is guaranteed to not be re-entered.\r
473\r
8a67d61d 474 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
475 @param Token Pointer to a token that is associated with the\r
476 receive data descriptor.\r
477\r
120db52c 478 @retval EFI_SUCCESS The receive completion token was cached.\r
8a67d61d 479 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
480 configured.\r
481 @retval EFI_NO_MAPPING When using a default address, configuration\r
482 (DHCP, BOOTP, RARP, etc.) is not finished yet.\r
483 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
484 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued\r
485 due to a lack of system resources.\r
486 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
d1102dba 487 The EFI TCPv4 Protocol instance has been reset\r
85511ddf 488 to startup defaults.\r
8a67d61d 489 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:\r
490 * A receive completion token with the same\r
d1102dba
LG
491 Token->CompletionToken.Event was already in\r
492 the receive queue.\r
493 * The current instance is in Tcp4StateClosed state.\r
494 * The current instance is a passive one and it\r
495 is in Tcp4StateListen state.\r
496 * User has called Close() to disconnect this\r
85511ddf 497 connection.\r
8a67d61d 498 @retval EFI_CONNECTION_FIN The communication peer has closed the connection\r
499 and there is no any buffered data in the receive\r
500 buffer of this instance.\r
501 @retval EFI_NOT_READY The receive request could not be queued because\r
502 the receive queue is full.\r
503\r
504**/\r
505EFI_STATUS\r
506EFIAPI\r
507Tcp4Receive (\r
508 IN EFI_TCP4_PROTOCOL *This,\r
509 IN EFI_TCP4_IO_TOKEN *Token\r
510 )\r
511{\r
512 SOCKET *Sock;\r
513 EFI_STATUS Status;\r
514\r
515 if (NULL == This ||\r
516 NULL == Token ||\r
517 NULL == Token->CompletionToken.Event ||\r
518 NULL == Token->Packet.RxData ||\r
519 0 == Token->Packet.RxData->FragmentCount ||\r
520 0 == Token->Packet.RxData->DataLength\r
521 ) {\r
522 return EFI_INVALID_PARAMETER;\r
523 }\r
524\r
525 Status = Tcp4ChkDataBuf (\r
4eb65aff 526 (UINT32) Token->Packet.RxData->DataLength,\r
527 (UINT32) Token->Packet.RxData->FragmentCount,\r
8a67d61d 528 Token->Packet.RxData->FragmentTable\r
529 );\r
530 if (EFI_ERROR (Status)) {\r
531 return Status;\r
532 }\r
533\r
534 Sock = SOCK_FROM_THIS (This);\r
535\r
536 return SockRcv (Sock, Token);\r
537\r
538}\r
539\r
540\r
541/**\r
542 Disconnecting a TCP connection gracefully or reset a TCP connection.\r
543\r
d1102dba
LG
544 Initiate an asynchronous close token to TCP driver. After Close() is called,\r
545 any buffered transmission data will be sent by TCP driver and the current\r
546 instance will have a graceful close working flow described as RFC 793 if\r
547 AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by TCP\r
548 driver to fast disconnect this connection. When the close operation completes\r
549 successfully the TCP instance is in Tcp4StateClosed state, all pending\r
550 asynchronous operation is signaled and any buffers used for TCP network traffic\r
85511ddf 551 is flushed.\r
552\r
120db52c 553 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
8a67d61d 554 @param CloseToken Pointer to the close token to return when\r
555 operation finishes.\r
556\r
120db52c 557 @retval EFI_SUCCESS The operation completed successfully.\r
8a67d61d 558 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
559 configured.\r
d1102dba 560 @retval EFI_ACCESS_DENIED One or more of the following are TRUE:\r
85511ddf 561 * Configure() has been called with TcpConfigData\r
562 set to NULL and this function has not returned.\r
8a67d61d 563 * Previous Close() call on this instance has not\r
85511ddf 564 finished.\r
120db52c 565 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid.\r
8a67d61d 566 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the\r
120db52c 567 operation.\r
8a67d61d 568 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above\r
569 category error.\r
570\r
571**/\r
572EFI_STATUS\r
573EFIAPI\r
574Tcp4Close (\r
575 IN EFI_TCP4_PROTOCOL *This,\r
576 IN EFI_TCP4_CLOSE_TOKEN *CloseToken\r
577 )\r
578{\r
579 SOCKET *Sock;\r
580\r
581 if (NULL == This ||\r
582 NULL == CloseToken ||\r
583 NULL == CloseToken->CompletionToken.Event) {\r
584 return EFI_INVALID_PARAMETER;\r
585 }\r
586\r
587 Sock = SOCK_FROM_THIS (This);\r
588\r
589 return SockClose (Sock, CloseToken, CloseToken->AbortOnClose);\r
590}\r
591\r
592\r
593/**\r
594 Abort an asynchronous connection, listen, transmission or receive request.\r
595\r
d1102dba
LG
596 The Cancel() function aborts a pending connection, listen, transmit or receive\r
597 request. If Token is not NULL and the token is in the connection, listen,\r
598 transmission or receive queue when it is being cancelled, its Token->Status\r
599 will be set to EFI_ABORTED and then Token->Event will be signaled. If the token\r
600 is not in one of the queues, which usually means that the asynchronous operation\r
601 has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchronous token\r
85511ddf 602 issued by Connect(), Accept(), Transmit() and Receive()will be aborted.\r
120db52c 603 NOTE: It has not been implemented currently.\r
d1102dba 604\r
8a67d61d 605 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
606 @param Token Pointer to a token that has been issued by\r
607 Connect(), Accept(), Transmit() or Receive(). If\r
608 NULL, all pending tokens issued by above four\r
609 functions will be aborted.\r
d1102dba 610\r
85511ddf 611 @retval EFI_SUCCESS The asynchronous I/O request is aborted and Token->Event\r
612 is signaled.\r
613 @retval EFI_INVALID_PARAMETER This is NULL.\r
dfc1f033 614 @retval EFI_NOT_STARTED This instance hasn's been configured.\r
85511ddf 615 @retval EFI_NO_MAPPING When using the default address, configuration\r
dfc1f033 616 (DHCP, BOOTP,RARP, etc.) hasn's finished yet.\r
d1102dba
LG
617 @retval EFI_NOT_FOUND The asynchronous I/O request isn's found in the\r
618 transmission or receive queue. It has either\r
dfc1f033 619 completed or wasn's issued by Transmit() and Receive().\r
85511ddf 620 @retval EFI_UNSUPPORTED The operation is not supported in current\r
8a67d61d 621 implementation.\r
d1102dba 622\r
8a67d61d 623**/\r
624EFI_STATUS\r
625EFIAPI\r
626Tcp4Cancel (\r
85511ddf 627 IN EFI_TCP4_PROTOCOL *This,\r
628 IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL\r
8a67d61d 629 )\r
630{\r
631 return EFI_UNSUPPORTED;\r
632}\r
633\r
634\r
635/**\r
636 Poll to receive incoming data and transmit outgoing segments.\r
637\r
d1102dba
LG
638 The Poll() function increases the rate that data is moved between the network\r
639 and application and can be called when the TCP instance is created successfully.\r
640 Its use is optional. In some implementations, the periodical timer in the MNP\r
641 driver may not poll the underlying communications device fast enough to avoid\r
642 drop packets. Drivers and applications that are experiencing packet loss should\r
85511ddf 643 try calling the Poll() function in a high frequency.\r
644\r
8a67d61d 645 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
646\r
647 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
648 @retval EFI_INVALID_PARAMETER This is NULL.\r
649 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
650 @retval EFI_NOT_READY No incoming or outgoing data was processed.\r
651 @retval EFI_TIMEOUT Data was dropped out of the transmission or\r
652 receive queue. Consider increasing the polling\r
653 rate.\r
654\r
655**/\r
656EFI_STATUS\r
657EFIAPI\r
658Tcp4Poll (\r
659 IN EFI_TCP4_PROTOCOL *This\r
660 )\r
661{\r
662 SOCKET *Sock;\r
663 EFI_STATUS Status;\r
664\r
665 if (NULL == This) {\r
666 return EFI_INVALID_PARAMETER;\r
667 }\r
668\r
669 Sock = SOCK_FROM_THIS (This);\r
670\r
671 Status = Sock->ProtoHandler (Sock, SOCK_POLL, NULL);\r
672\r
673 return Status;\r
674}\r