TianoCore EDK2 master
Loading...
Searching...
No Matches
TcpMain.c
Go to the documentation of this file.
1
11#include "TcpMain.h"
12
27 IN UINT32 DataLen,
28 IN UINT32 FragmentCount,
29 IN EFI_TCP4_FRAGMENT_DATA *FragmentTable
30 )
31{
32 UINT32 Index;
33
34 UINT32 Len;
35
36 for (Index = 0, Len = 0; Index < FragmentCount; Index++) {
37 if (FragmentTable[Index].FragmentBuffer == NULL) {
38 return EFI_INVALID_PARAMETER;
39 }
40
41 Len = Len + FragmentTable[Index].FragmentLength;
42 }
43
44 if (DataLen != Len) {
45 return EFI_INVALID_PARAMETER;
46 }
47
48 return EFI_SUCCESS;
49}
50
75EFIAPI
78 OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL,
79 OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL,
80 OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,
81 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
82 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
83 )
84{
85 TCP4_MODE_DATA TcpMode;
86 SOCKET *Sock;
87
88 if (NULL == This) {
89 return EFI_INVALID_PARAMETER;
90 }
91
92 Sock = SOCK_FROM_THIS (This);
93
94 TcpMode.Tcp4State = Tcp4State;
95 TcpMode.Tcp4ConfigData = Tcp4ConfigData;
96 TcpMode.Ip4ModeData = Ip4ModeData;
97 TcpMode.MnpConfigData = MnpConfigData;
98 TcpMode.SnpModeData = SnpModeData;
99
100 return SockGetMode (Sock, &TcpMode);
101}
102
126EFIAPI
128 IN EFI_TCP4_PROTOCOL *This,
129 IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL
130 )
131{
132 EFI_TCP4_OPTION *Option;
133 SOCKET *Sock;
134 EFI_STATUS Status;
135 IP4_ADDR Ip;
136 IP4_ADDR SubnetMask;
137
138 if (NULL == This) {
139 return EFI_INVALID_PARAMETER;
140 }
141
142 //
143 // Tcp protocol related parameter check will be conducted here
144 //
145 if (NULL != TcpConfigData) {
146 CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));
147 if (IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
148 return EFI_INVALID_PARAMETER;
149 }
150
151 if (TcpConfigData->AccessPoint.ActiveFlag && ((0 == TcpConfigData->AccessPoint.RemotePort) || (Ip == 0))) {
152 return EFI_INVALID_PARAMETER;
153 }
154
155 if (!TcpConfigData->AccessPoint.UseDefaultAddress) {
156 CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP4_ADDR));
157 CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof (IP4_ADDR));
158 if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) ||
159 ((SubnetMask != 0) && !NetIp4IsUnicast (NTOHL (Ip), NTOHL (SubnetMask))))
160 {
161 return EFI_INVALID_PARAMETER;
162 }
163 }
164
165 Option = TcpConfigData->ControlOption;
166 if ((NULL != Option) && (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {
167 return EFI_UNSUPPORTED;
168 }
169 }
170
171 Sock = SOCK_FROM_THIS (This);
172
173 if (NULL == TcpConfigData) {
174 return SockFlush (Sock);
175 }
176
177 Status = SockConfigure (Sock, TcpConfigData);
178
179 if (EFI_NO_MAPPING == Status) {
180 Sock->ConfigureState = SO_NO_MAPPING;
181 }
182
183 return Status;
184}
185
212EFIAPI
214 IN EFI_TCP4_PROTOCOL *This,
215 IN BOOLEAN DeleteRoute,
216 IN EFI_IPv4_ADDRESS *SubnetAddress,
217 IN EFI_IPv4_ADDRESS *SubnetMask,
218 IN EFI_IPv4_ADDRESS *GatewayAddress
219 )
220{
221 SOCKET *Sock;
222 TCP4_ROUTE_INFO RouteInfo;
223
224 if (NULL == This) {
225 return EFI_INVALID_PARAMETER;
226 }
227
228 Sock = SOCK_FROM_THIS (This);
229
230 RouteInfo.DeleteRoute = DeleteRoute;
231 RouteInfo.SubnetAddress = SubnetAddress;
232 RouteInfo.SubnetMask = SubnetMask;
233 RouteInfo.GatewayAddress = GatewayAddress;
234
235 return SockRoute (Sock, &RouteInfo);
236}
237
258EFIAPI
260 IN EFI_TCP4_PROTOCOL *This,
261 IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken
262 )
263{
264 SOCKET *Sock;
265
266 if ((NULL == This) || (NULL == ConnectionToken) || (NULL == ConnectionToken->CompletionToken.Event)) {
267 return EFI_INVALID_PARAMETER;
268 }
269
270 Sock = SOCK_FROM_THIS (This);
271
272 return SockConnect (Sock, ConnectionToken);
273}
274
296EFIAPI
298 IN EFI_TCP4_PROTOCOL *This,
299 IN EFI_TCP4_LISTEN_TOKEN *ListenToken
300 )
301{
302 SOCKET *Sock;
303
304 if ((NULL == This) || (NULL == ListenToken) || (NULL == ListenToken->CompletionToken.Event)) {
305 return EFI_INVALID_PARAMETER;
306 }
307
308 Sock = SOCK_FROM_THIS (This);
309
310 return SockAccept (Sock, ListenToken);
311}
312
343EFIAPI
345 IN EFI_TCP4_PROTOCOL *This,
346 IN EFI_TCP4_IO_TOKEN *Token
347 )
348{
349 SOCKET *Sock;
350 EFI_STATUS Status;
351
352 if ((NULL == This) ||
353 (NULL == Token) ||
354 (NULL == Token->CompletionToken.Event) ||
355 (NULL == Token->Packet.TxData) ||
356 (0 == Token->Packet.TxData->FragmentCount) ||
357 (0 == Token->Packet.TxData->DataLength)
358 )
359 {
360 return EFI_INVALID_PARAMETER;
361 }
362
363 Status = TcpChkDataBuf (
364 Token->Packet.TxData->DataLength,
365 Token->Packet.TxData->FragmentCount,
366 Token->Packet.TxData->FragmentTable
367 );
368 if (EFI_ERROR (Status)) {
369 return Status;
370 }
371
372 Sock = SOCK_FROM_THIS (This);
373
374 return SockSend (Sock, Token);
375}
376
409EFIAPI
411 IN EFI_TCP4_PROTOCOL *This,
412 IN EFI_TCP4_IO_TOKEN *Token
413 )
414{
415 SOCKET *Sock;
416 EFI_STATUS Status;
417
418 if ((NULL == This) ||
419 (NULL == Token) ||
420 (NULL == Token->CompletionToken.Event) ||
421 (NULL == Token->Packet.RxData) ||
422 (0 == Token->Packet.RxData->FragmentCount) ||
423 (0 == Token->Packet.RxData->DataLength)
424 )
425 {
426 return EFI_INVALID_PARAMETER;
427 }
428
429 Status = TcpChkDataBuf (
430 Token->Packet.RxData->DataLength,
431 Token->Packet.RxData->FragmentCount,
432 Token->Packet.RxData->FragmentTable
433 );
434 if (EFI_ERROR (Status)) {
435 return Status;
436 }
437
438 Sock = SOCK_FROM_THIS (This);
439
440 return SockRcv (Sock, Token);
441}
442
466EFIAPI
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
508EFIAPI
510 IN EFI_TCP4_PROTOCOL *This,
511 IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL
512 )
513{
514 SOCKET *Sock;
515
516 if (NULL == This) {
517 return EFI_INVALID_PARAMETER;
518 }
519
520 Sock = SOCK_FROM_THIS (This);
521
522 return SockCancel (Sock, Token);
523}
524
540EFIAPI
543 )
544{
545 SOCKET *Sock;
546 EFI_STATUS Status;
547
548 if (NULL == This) {
549 return EFI_INVALID_PARAMETER;
550 }
551
552 Sock = SOCK_FROM_THIS (This);
553
554 Status = Sock->ProtoHandler (Sock, SOCK_POLL, NULL);
555
556 return Status;
557}
558
588EFIAPI
590 IN EFI_TCP6_PROTOCOL *This,
591 OUT EFI_TCP6_CONNECTION_STATE *Tcp6State OPTIONAL,
592 OUT EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL,
593 OUT EFI_IP6_MODE_DATA *Ip6ModeData OPTIONAL,
594 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
595 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
596 )
597{
598 TCP6_MODE_DATA TcpMode;
599 SOCKET *Sock;
600
601 if (NULL == This) {
602 return EFI_INVALID_PARAMETER;
603 }
604
605 Sock = SOCK_FROM_THIS (This);
606
607 TcpMode.Tcp6State = Tcp6State;
608 TcpMode.Tcp6ConfigData = Tcp6ConfigData;
609 TcpMode.Ip6ModeData = Ip6ModeData;
610 TcpMode.MnpConfigData = MnpConfigData;
611 TcpMode.SnpModeData = SnpModeData;
612
613 return SockGetMode (Sock, &TcpMode);
614}
615
664EFIAPI
666 IN EFI_TCP6_PROTOCOL *This,
667 IN EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL
668 )
669{
670 EFI_TCP6_OPTION *Option;
671 SOCKET *Sock;
672 EFI_STATUS Status;
674
675 if (NULL == This) {
676 return EFI_INVALID_PARAMETER;
677 }
678
679 //
680 // Tcp protocol related parameter check will be conducted here
681 //
682 if (NULL != Tcp6ConfigData) {
683 Ip = &Tcp6ConfigData->AccessPoint.RemoteAddress;
685 return EFI_INVALID_PARAMETER;
686 }
687
688 if (Tcp6ConfigData->AccessPoint.ActiveFlag &&
689 ((0 == Tcp6ConfigData->AccessPoint.RemotePort) || NetIp6IsUnspecifiedAddr (Ip))
690 )
691 {
692 return EFI_INVALID_PARAMETER;
693 }
694
695 Ip = &Tcp6ConfigData->AccessPoint.StationAddress;
697 return EFI_INVALID_PARAMETER;
698 }
699
700 Option = Tcp6ConfigData->ControlOption;
701 if ((NULL != Option) && (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {
702 return EFI_UNSUPPORTED;
703 }
704 }
705
706 Sock = SOCK_FROM_THIS (This);
707
708 if (NULL == Tcp6ConfigData) {
709 return SockFlush (Sock);
710 }
711
712 Status = SockConfigure (Sock, Tcp6ConfigData);
713
714 if (EFI_NO_MAPPING == Status) {
715 Sock->ConfigureState = SO_NO_MAPPING;
716 }
717
718 return Status;
719}
720
752EFIAPI
754 IN EFI_TCP6_PROTOCOL *This,
755 IN EFI_TCP6_CONNECTION_TOKEN *ConnectionToken
756 )
757{
758 SOCKET *Sock;
759
760 if ((NULL == This) || (NULL == ConnectionToken) || (NULL == ConnectionToken->CompletionToken.Event)) {
761 return EFI_INVALID_PARAMETER;
762 }
763
764 Sock = SOCK_FROM_THIS (This);
765
766 return SockConnect (Sock, ConnectionToken);
767}
768
805EFIAPI
807 IN EFI_TCP6_PROTOCOL *This,
808 IN EFI_TCP6_LISTEN_TOKEN *ListenToken
809 )
810{
811 SOCKET *Sock;
812
813 if ((NULL == This) || (NULL == ListenToken) || (NULL == ListenToken->CompletionToken.Event)) {
814 return EFI_INVALID_PARAMETER;
815 }
816
817 Sock = SOCK_FROM_THIS (This);
818
819 return SockAccept (Sock, ListenToken);
820}
821
860EFIAPI
862 IN EFI_TCP6_PROTOCOL *This,
863 IN EFI_TCP6_IO_TOKEN *Token
864 )
865{
866 SOCKET *Sock;
867 EFI_STATUS Status;
868
869 if ((NULL == This) ||
870 (NULL == Token) ||
871 (NULL == Token->CompletionToken.Event) ||
872 (NULL == Token->Packet.TxData) ||
873 (0 == Token->Packet.TxData->FragmentCount) ||
874 (0 == Token->Packet.TxData->DataLength)
875 )
876 {
877 return EFI_INVALID_PARAMETER;
878 }
879
880 Status = TcpChkDataBuf (
881 Token->Packet.TxData->DataLength,
882 Token->Packet.TxData->FragmentCount,
883 (EFI_TCP4_FRAGMENT_DATA *)Token->Packet.TxData->FragmentTable
884 );
885 if (EFI_ERROR (Status)) {
886 return Status;
887 }
888
889 Sock = SOCK_FROM_THIS (This);
890
891 return SockSend (Sock, Token);
892}
893
941EFIAPI
943 IN EFI_TCP6_PROTOCOL *This,
944 IN EFI_TCP6_IO_TOKEN *Token
945 )
946{
947 SOCKET *Sock;
948 EFI_STATUS Status;
949
950 if ((NULL == This) ||
951 (NULL == Token) ||
952 (NULL == Token->CompletionToken.Event) ||
953 (NULL == Token->Packet.RxData) ||
954 (0 == Token->Packet.RxData->FragmentCount) ||
955 (0 == Token->Packet.RxData->DataLength)
956 )
957 {
958 return EFI_INVALID_PARAMETER;
959 }
960
961 Status = TcpChkDataBuf (
962 Token->Packet.RxData->DataLength,
963 Token->Packet.RxData->FragmentCount,
964 (EFI_TCP4_FRAGMENT_DATA *)Token->Packet.RxData->FragmentTable
965 );
966 if (EFI_ERROR (Status)) {
967 return Status;
968 }
969
970 Sock = SOCK_FROM_THIS (This);
971
972 return SockRcv (Sock, Token);
973}
974
1003EFIAPI
1005 IN EFI_TCP6_PROTOCOL *This,
1006 IN EFI_TCP6_CLOSE_TOKEN *CloseToken
1007 )
1008{
1009 SOCKET *Sock;
1010
1011 if ((NULL == This) || (NULL == CloseToken) || (NULL == CloseToken->CompletionToken.Event)) {
1012 return EFI_INVALID_PARAMETER;
1013 }
1014
1015 Sock = SOCK_FROM_THIS (This);
1016
1017 return SockClose (Sock, CloseToken, CloseToken->AbortOnClose);
1018}
1019
1056EFIAPI
1058 IN EFI_TCP6_PROTOCOL *This,
1059 IN EFI_TCP6_COMPLETION_TOKEN *Token OPTIONAL
1060 )
1061{
1062 SOCKET *Sock;
1063
1064 if (NULL == This) {
1065 return EFI_INVALID_PARAMETER;
1066 }
1067
1068 Sock = SOCK_FROM_THIS (This);
1069
1070 return SockCancel (Sock, Token);
1071}
1072
1091EFIAPI
1093 IN EFI_TCP6_PROTOCOL *This
1094 )
1095{
1096 SOCKET *Sock;
1097 EFI_STATUS Status;
1098
1099 if (NULL == This) {
1100 return EFI_INVALID_PARAMETER;
1101 }
1102
1103 Sock = SOCK_FROM_THIS (This);
1104
1105 Status = Sock->ProtoHandler (Sock, SOCK_POLL, NULL);
1106
1107 return Status;
1108}
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI NetIp4IsUnicast(IN IP4_ADDR Ip, IN IP4_ADDR NetMask)
Definition: DxeNetLib.c:683
BOOLEAN EFIAPI NetIp6IsValidUnicast(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:725
BOOLEAN EFIAPI NetIp6IsUnspecifiedAddr(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:766
EFI_STATUS SockFlush(IN OUT SOCKET *Sock)
EFI_STATUS SockClose(IN OUT SOCKET *Sock, IN VOID *Token, IN BOOLEAN OnAbort)
EFI_STATUS SockConnect(IN SOCKET *Sock, IN VOID *Token)
EFI_STATUS SockRcv(IN SOCKET *Sock, IN VOID *Token)
#define SOCK_POLL
Need to poll to the protocol layer.
Definition: Socket.h:92
EFI_STATUS SockRoute(IN SOCKET *Sock, IN VOID *RouteInfo)
EFI_STATUS SockSend(IN SOCKET *Sock, IN VOID *Token)
EFI_STATUS SockAccept(IN SOCKET *Sock, IN VOID *Token)
EFI_STATUS SockGetMode(IN SOCKET *Sock, IN OUT VOID *Mode)
EFI_STATUS SockCancel(IN OUT SOCKET *Sock, IN VOID *Token)
EFI_STATUS SockConfigure(IN SOCKET *Sock, IN VOID *ConfigData)
EFI_TCP4_CONNECTION_STATE
Definition: Tcp4.h:103
EFI_TCP6_CONNECTION_STATE
Definition: Tcp6.h:243
EFI_STATUS 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)
Definition: TcpMain.c:76
EFI_STATUS EFIAPI Tcp4Accept(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_LISTEN_TOKEN *ListenToken)
Definition: TcpMain.c:297
EFI_STATUS EFIAPI Tcp4Cancel(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL)
Definition: TcpMain.c:509
EFI_STATUS EFIAPI Tcp4Receive(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_IO_TOKEN *Token)
Definition: TcpMain.c:410
EFI_STATUS EFIAPI Tcp6Close(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CLOSE_TOKEN *CloseToken)
Definition: TcpMain.c:1004
EFI_STATUS EFIAPI Tcp6Connect(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CONNECTION_TOKEN *ConnectionToken)
Definition: TcpMain.c:753
EFI_STATUS 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)
Definition: TcpMain.c:589
EFI_STATUS EFIAPI Tcp6Configure(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL)
Definition: TcpMain.c:665
EFI_STATUS EFIAPI Tcp6Receive(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_IO_TOKEN *Token)
Definition: TcpMain.c:942
EFI_STATUS EFIAPI Tcp4Transmit(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_IO_TOKEN *Token)
Definition: TcpMain.c:344
EFI_STATUS EFIAPI Tcp4Close(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CLOSE_TOKEN *CloseToken)
Definition: TcpMain.c:467
EFI_STATUS EFIAPI Tcp6Poll(IN EFI_TCP6_PROTOCOL *This)
Definition: TcpMain.c:1092
EFI_STATUS EFIAPI Tcp4Poll(IN EFI_TCP4_PROTOCOL *This)
Definition: TcpMain.c:541
EFI_STATUS EFIAPI Tcp6Transmit(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_IO_TOKEN *Token)
Definition: TcpMain.c:861
EFI_STATUS EFIAPI Tcp6Cancel(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_COMPLETION_TOKEN *Token OPTIONAL)
Definition: TcpMain.c:1057
EFI_STATUS TcpChkDataBuf(IN UINT32 DataLen, IN UINT32 FragmentCount, IN EFI_TCP4_FRAGMENT_DATA *FragmentTable)
Definition: TcpMain.c:26
EFI_STATUS 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)
Definition: TcpMain.c:213
EFI_STATUS EFIAPI Tcp6Accept(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_LISTEN_TOKEN *ListenToken)
Definition: TcpMain.c:806
EFI_STATUS EFIAPI Tcp4Connect(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken)
Definition: TcpMain.c:259
EFI_STATUS EFIAPI Tcp4Configure(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL)
Definition: TcpMain.c:127
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
SOCK_PROTO_HANDLER ProtoHandler
The request handler of protocol.
Definition: Socket.h:496
BOOLEAN EnablePathMtuDiscovery
Definition: Tcp6.h:214
BOOLEAN EnableSelectiveAck
Definition: Tcp6.h:209