]>
Commit | Line | Data |
---|---|---|
8a67d61d | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2005 - 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Tcp4Main.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Implementation of TCP4 protocol services.\r | |
19 | \r | |
20 | \r | |
21 | **/\r | |
22 | \r | |
23 | #include "Tcp4Main.h"\r | |
24 | \r | |
25 | \r | |
26 | /**\r | |
27 | Check the integrity of the data buffer.\r | |
28 | \r | |
29 | @param DataLen The total length of the data buffer.\r | |
30 | @param FragmentCount The fragment count of the fragment table.\r | |
31 | @param FragmentTable Pointer to the fragment table of the data\r | |
32 | buffer.\r | |
33 | \r | |
34 | @retval EFI_SUCCESS The integrity check is passed.\r | |
35 | @retval EFI_INVALID_PARAMETER The integrity check is failed.\r | |
36 | \r | |
37 | **/\r | |
8a67d61d | 38 | EFI_STATUS\r |
39 | Tcp4ChkDataBuf (\r | |
40 | IN UINT32 DataLen,\r | |
41 | IN UINT32 FragmentCount,\r | |
42 | IN EFI_TCP4_FRAGMENT_DATA *FragmentTable\r | |
43 | )\r | |
44 | {\r | |
45 | UINT32 Index;\r | |
46 | \r | |
47 | UINT32 Len;\r | |
48 | \r | |
49 | for (Index = 0, Len = 0; Index < FragmentCount; Index++) {\r | |
4eb65aff | 50 | Len = Len + (UINT32) FragmentTable[Index].FragmentLength;\r |
8a67d61d | 51 | }\r |
52 | \r | |
53 | if (DataLen != Len) {\r | |
54 | return EFI_INVALID_PARAMETER;\r | |
55 | }\r | |
56 | \r | |
57 | return EFI_SUCCESS;\r | |
58 | }\r | |
59 | \r | |
60 | \r | |
61 | /**\r | |
62 | Get the current operational status.\r | |
85511ddf | 63 | \r |
64 | The GetModeData() function copies the current operational settings of this \r | |
65 | EFI TCPv4 Protocol instance into user-supplied buffers. This function can \r | |
66 | also be used to retrieve the operational setting of underlying drivers \r | |
67 | such as IPv4, MNP, or SNP.\r | |
8a67d61d | 68 | \r |
69 | @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r | |
70 | @param Tcp4State Pointer to the buffer to receive the current TCP\r | |
71 | state.\r | |
72 | @param Tcp4ConfigData Pointer to the buffer to receive the current TCP\r | |
73 | configuration.\r | |
85511ddf | 74 | @param Ip4ModeData Pointer to the buffer to receive the current IPv4 \r |
75 | configuration data used by the TCPv4 instance.\r | |
8a67d61d | 76 | @param MnpConfigData Pointer to the buffer to receive the current MNP\r |
77 | configuration data indirectly used by the TCPv4\r | |
78 | Instance.\r | |
79 | @param SnpModeData Pointer to the buffer to receive the current SNP\r | |
80 | configuration data indirectly used by the TCPv4\r | |
81 | Instance.\r | |
82 | \r | |
83 | @retval EFI_SUCCESS The mode data was read.\r | |
84 | @retval EFI_NOT_STARTED No configuration data is available because this\r | |
85 | instance hasn't been started.\r | |
86 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
87 | \r | |
88 | **/\r | |
89 | EFI_STATUS\r | |
90 | EFIAPI\r | |
91 | Tcp4GetModeData (\r | |
85511ddf | 92 | IN CONST EFI_TCP4_PROTOCOL *This,\r |
93 | OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL,\r | |
94 | OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL,\r | |
95 | OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,\r | |
96 | OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,\r | |
97 | OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r | |
8a67d61d | 98 | )\r |
99 | {\r | |
100 | TCP4_MODE_DATA TcpMode;\r | |
101 | SOCKET *Sock;\r | |
102 | \r | |
103 | if (NULL == This) {\r | |
104 | return EFI_INVALID_PARAMETER;\r | |
105 | }\r | |
106 | \r | |
107 | Sock = SOCK_FROM_THIS (This);\r | |
108 | \r | |
109 | TcpMode.Tcp4State = Tcp4State;\r | |
110 | TcpMode.Tcp4ConfigData = Tcp4ConfigData;\r | |
111 | TcpMode.Ip4ModeData = Ip4ModeData;\r | |
112 | TcpMode.MnpConfigData = MnpConfigData;\r | |
113 | TcpMode.SnpModeData = SnpModeData;\r | |
114 | \r | |
115 | return SockGetMode (Sock, &TcpMode);\r | |
116 | }\r | |
117 | \r | |
118 | \r | |
119 | /**\r | |
120 | Initialize or brutally reset the operational parameters for\r | |
121 | this EFI TCPv4 instance.\r | |
85511ddf | 122 | \r |
123 | The Configure() function does the following:\r | |
124 | * Initialize this EFI TCPv4 instance, i.e., initialize the communication end \r | |
125 | setting, specify active open or passive open for an instance.\r | |
126 | * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchronous \r | |
127 | tokens, flush transmission and receiving buffer directly without informing \r | |
128 | the communication peer.\r | |
129 | No other TCPv4 Protocol operation can be executed by this instance \r | |
130 | until it is configured properly. For an active TCP4 instance, after a proper \r | |
131 | configuration it may call Connect() to initiates the three-way handshake. \r | |
132 | For a passive TCP4 instance, its state will transit to Tcp4StateListen after \r | |
133 | configuration, and Accept() may be called to listen the incoming TCP connection \r | |
134 | request. If TcpConfigData is set to NULL, the instance is reset. Resetting \r | |
135 | process will be done brutally, the state machine will be set to Tcp4StateClosed \r | |
136 | directly, the receive queue and transmit queue will be flushed, and no traffic is \r | |
137 | allowed through this instance.\r | |
8a67d61d | 138 | \r |
139 | @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r | |
140 | @param TcpConfigData Pointer to the configure data to configure the\r | |
141 | instance.\r | |
142 | \r | |
143 | @retval EFI_SUCCESS The operational settings are set, changed, or\r | |
144 | reset successfully.\r | |
145 | @retval EFI_NO_MAPPING When using a default address, configuration\r | |
146 | (through DHCP, BOOTP, RARP, etc.) is not\r | |
147 | finished.\r | |
148 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
149 | @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already\r | |
150 | configured.\r | |
151 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r | |
152 | @retval EFI_UNSUPPORTED One or more of the control options are not\r | |
153 | supported in the implementation.\r | |
154 | @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r | |
155 | \r | |
156 | **/\r | |
157 | EFI_STATUS\r | |
158 | EFIAPI\r | |
159 | Tcp4Configure (\r | |
85511ddf | 160 | IN EFI_TCP4_PROTOCOL *This,\r |
161 | IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL\r | |
8a67d61d | 162 | )\r |
163 | {\r | |
164 | EFI_TCP4_OPTION *Option;\r | |
165 | SOCKET *Sock;\r | |
166 | EFI_STATUS Status;\r | |
772db4bb | 167 | IP4_ADDR Ip;\r |
687a2e5f | 168 | IP4_ADDR SubnetMask;\r |
8a67d61d | 169 | \r |
170 | if (NULL == This) {\r | |
171 | return EFI_INVALID_PARAMETER;\r | |
172 | }\r | |
173 | \r | |
174 | //\r | |
175 | // Tcp protocol related parameter check will be conducted here\r | |
176 | //\r | |
177 | if (NULL != TcpConfigData) {\r | |
772db4bb | 178 | \r |
e48e37fc | 179 | CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));\r |
772db4bb | 180 | if ((Ip != 0) && !Ip4IsUnicast (NTOHL (Ip), 0)) {\r |
181 | return EFI_INVALID_PARAMETER;\r | |
182 | }\r | |
183 | \r | |
184 | if (TcpConfigData->AccessPoint.ActiveFlag &&\r | |
185 | (0 == TcpConfigData->AccessPoint.RemotePort || (Ip == 0))) {\r | |
8a67d61d | 186 | return EFI_INVALID_PARAMETER;\r |
187 | }\r | |
188 | \r | |
189 | if (!TcpConfigData->AccessPoint.UseDefaultAddress) {\r | |
772db4bb | 190 | \r |
e48e37fc | 191 | CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP4_ADDR));\r |
192 | CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof (IP4_ADDR));\r | |
687a2e5f | 193 | if (!Ip4IsUnicast (NTOHL (Ip), 0) || !IP4_IS_VALID_NETMASK (NTOHL (SubnetMask))) {\r |
8a67d61d | 194 | return EFI_INVALID_PARAMETER;\r |
195 | }\r | |
196 | }\r | |
197 | \r | |
8a67d61d | 198 | Option = TcpConfigData->ControlOption;\r |
199 | if ((NULL != Option) &&\r | |
200 | (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {\r | |
201 | return EFI_UNSUPPORTED;\r | |
202 | }\r | |
203 | }\r | |
204 | \r | |
205 | Sock = SOCK_FROM_THIS (This);\r | |
206 | \r | |
207 | if (NULL == TcpConfigData) {\r | |
208 | return SockFlush (Sock);\r | |
209 | }\r | |
210 | \r | |
211 | Status = SockConfigure (Sock, TcpConfigData);\r | |
212 | \r | |
213 | if (EFI_NO_MAPPING == Status) {\r | |
214 | Sock->ConfigureState = SO_NO_MAPPING;\r | |
215 | }\r | |
216 | \r | |
217 | return Status;\r | |
218 | }\r | |
219 | \r | |
220 | \r | |
221 | /**\r | |
222 | Add or delete routing entries.\r | |
85511ddf | 223 | \r |
224 | Content-type: text/html ]>