1 | /** @file
|
---|
2 | Implement the IP4 driver support for the socket layer.
|
---|
3 |
|
---|
4 | Copyright (c) 2011, Intel Corporation
|
---|
5 | All rights reserved. This program and the accompanying materials
|
---|
6 | are licensed and made available under the terms and conditions of the BSD License
|
---|
7 | which accompanies this distribution. The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | #include "Socket.h"
|
---|
16 |
|
---|
17 |
|
---|
18 | /**
|
---|
19 | Get the local socket address
|
---|
20 |
|
---|
21 | This routine returns the IPv4 address associated with the local
|
---|
22 | socket.
|
---|
23 |
|
---|
24 | This routine is called by ::EslSocketGetLocalAddress to determine the
|
---|
25 | network address for the SOCK_RAW socket.
|
---|
26 |
|
---|
27 | @param [in] pPort Address of an ::ESL_PORT structure.
|
---|
28 |
|
---|
29 | @param [out] pAddress Network address to receive the local system address
|
---|
30 |
|
---|
31 | **/
|
---|
32 | VOID
|
---|
33 | EslIp4LocalAddressGet (
|
---|
34 | IN ESL_PORT * pPort,
|
---|
35 | OUT struct sockaddr * pAddress
|
---|
36 | )
|
---|
37 | {
|
---|
38 | struct sockaddr_in * pLocalAddress;
|
---|
39 | ESL_IP4_CONTEXT * pIp4;
|
---|
40 |
|
---|
41 | DBG_ENTER ( );
|
---|
42 |
|
---|
43 | //
|
---|
44 | // Return the local address
|
---|
45 | //
|
---|
46 | pIp4 = &pPort->Context.Ip4;
|
---|
47 | pLocalAddress = (struct sockaddr_in *)pAddress;
|
---|
48 | pLocalAddress->sin_family = AF_INET;
|
---|
49 | CopyMem ( &pLocalAddress->sin_addr,
|
---|
50 | &pIp4->ModeData.ConfigData.StationAddress.Addr[0],
|
---|
51 | sizeof ( pLocalAddress->sin_addr ));
|
---|
52 |
|
---|
53 | DBG_EXIT ( );
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | /**
|
---|
58 | Set the local port address.
|
---|
59 |
|
---|
60 | This routine sets the local port address.
|
---|
61 |
|
---|
62 | This support routine is called by ::EslSocketPortAllocate.
|
---|
63 |
|
---|
64 | @param [in] pPort Address of an ESL_PORT structure
|
---|
65 | @param [in] pSockAddr Address of a sockaddr structure that contains the
|
---|
66 | connection point on the local machine. An IPv4 address
|
---|
67 | of INADDR_ANY specifies that the connection is made to
|
---|
68 | all of the network stacks on the platform. Specifying a
|
---|
69 | specific IPv4 address restricts the connection to the
|
---|
70 | network stack supporting that address. Specifying zero
|
---|
71 | for the port causes the network layer to assign a port
|
---|
72 | number from the dynamic range. Specifying a specific
|
---|
73 | port number causes the network layer to use that port.
|
---|
74 |
|
---|
75 | @param [in] bBindTest TRUE = run bind testing
|
---|
76 |
|
---|
77 | @retval EFI_SUCCESS The operation was successful
|
---|
78 |
|
---|
79 | **/
|
---|
80 | EFI_STATUS
|
---|
81 | EslIp4LocalAddressSet (
|
---|
82 | IN ESL_PORT * pPort,
|
---|
83 | IN CONST struct sockaddr * pSockAddr,
|
---|
84 | IN BOOLEAN bBindTest
|
---|
85 | )
|
---|
86 | {
|
---|
87 | EFI_IP4_CONFIG_DATA * pConfig;
|
---|
88 | CONST struct sockaddr_in * pIpAddress;
|
---|
89 | CONST UINT8 * pIpv4Address;
|
---|
90 | EFI_STATUS Status;
|
---|
91 |
|
---|
92 | DBG_ENTER ( );
|
---|
93 |
|
---|
94 | //
|
---|
95 | // Validate the address
|
---|
96 | //
|
---|
97 | pIpAddress = (struct sockaddr_in *)pSockAddr;
|
---|
98 | if ( INADDR_BROADCAST == pIpAddress->sin_addr.s_addr ) {
|
---|
99 | //
|
---|
100 | // The local address must not be the broadcast address
|
---|
101 | //
|
---|
102 | Status = EFI_INVALID_PARAMETER;
|
---|
103 | pPort->pSocket->errno = EADDRNOTAVAIL;
|
---|
104 | }
|
---|
105 | else {
|
---|
106 | Status = EFI_SUCCESS;
|
---|
107 |
|
---|
108 | //
|
---|
109 | // Set the local address
|
---|
110 | //
|
---|
111 | pIpAddress = (struct sockaddr_in *)pSockAddr;
|
---|
112 | pIpv4Address = (UINT8 *)&pIpAddress->sin_addr.s_addr;
|
---|
113 | pConfig = &pPort->Context.Ip4.ModeData.ConfigData;
|
---|
114 | pConfig->StationAddress.Addr[0] = pIpv4Address[0];
|
---|
115 | pConfig->StationAddress.Addr[1] = pIpv4Address[1];
|
---|
116 | pConfig->StationAddress.Addr[2] = pIpv4Address[2];
|
---|
117 | pConfig->StationAddress.Addr[3] = pIpv4Address[3];
|
---|
118 |
|
---|
119 | //
|
---|
120 | // Determine if the default address is used
|
---|
121 | //
|
---|
122 | pConfig->UseDefaultAddress = (BOOLEAN)( 0 == pIpAddress->sin_addr.s_addr );
|
---|
123 |
|
---|
124 | //
|
---|
125 | // Display the local address
|
---|
126 | //
|
---|
127 | DEBUG (( DEBUG_BIND,
|
---|
128 | "0x%08x: Port, Local IP4 Address: %d.%d.%d.%d\r\n",
|
---|
129 | pPort,
|
---|
130 | pConfig->StationAddress.Addr[0],
|
---|
131 | pConfig->StationAddress.Addr[1],
|
---|
132 | pConfig->StationAddress.Addr[2],
|
---|
133 | pConfig->StationAddress.Addr[3]));
|
---|
134 |
|
---|
135 | //
|
---|
136 | // Set the subnet mask
|
---|
137 | //
|
---|
138 | if ( pConfig->UseDefaultAddress ) {
|
---|
139 | pConfig->SubnetMask.Addr[0] = 0;
|
---|
140 | pConfig->SubnetMask.Addr[1] = 0;
|
---|
141 | pConfig->SubnetMask.Addr[2] = 0;
|
---|
142 | pConfig->SubnetMask.Addr[3] = 0;
|
---|
143 | }
|
---|
144 | else {
|
---|
145 | pConfig->SubnetMask.Addr[0] = 0xff;
|
---|
146 | pConfig->SubnetMask.Addr[1] = ( 128 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
|
---|
147 | pConfig->SubnetMask.Addr[2] = ( 192 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
|
---|
148 | pConfig->SubnetMask.Addr[3] = ( 224 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | //
|
---|
153 | // Return the operation status
|
---|
154 | //
|
---|
155 | DBG_EXIT_STATUS ( Status );
|
---|
156 | return Status;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | /**
|
---|
161 | Get the option value
|
---|
162 |
|
---|
163 | This routine handles the IPv4 level options.
|
---|
164 |
|
---|
165 | The ::EslSocketOptionGet routine calls this routine to retrieve
|
---|
166 | the IPv4 options one at a time by name.
|
---|
167 |
|
---|
168 | @param [in] pSocket Address of an ::ESL_SOCKET structure
|
---|
169 | @param [in] OptionName Name of the option
|
---|
170 | @param [out] ppOptionData Buffer to receive address of option value
|
---|
171 | @param [out] pOptionLength Buffer to receive the option length
|
---|
172 |
|
---|
173 | @retval EFI_SUCCESS - Socket data successfully received
|
---|
174 |
|
---|
175 | **/
|
---|
176 | EFI_STATUS
|
---|
177 | EslIp4OptionGet (
|
---|
178 | IN ESL_SOCKET * pSocket,
|
---|
179 | IN int OptionName,
|
---|
180 | OUT CONST void ** __restrict ppOptionData,
|
---|
181 | OUT socklen_t * __restrict pOptionLength
|
---|
182 | )
|
---|
183 | {
|
---|
184 | EFI_STATUS Status;
|
---|
185 |
|
---|
186 | DBG_ENTER ( );
|
---|
187 |
|
---|
188 | //
|
---|
189 | // Assume success
|
---|
190 | //
|
---|
191 | pSocket->errno = 0;
|
---|
192 | Status = EFI_SUCCESS;
|
---|
193 |
|
---|
194 | //
|
---|
195 | // Attempt to get the option
|
---|
196 | //
|
---|
197 | switch ( OptionName ) {
|
---|
198 | default:
|
---|
199 | //
|
---|
200 | // Option not supported
|
---|
201 | //
|
---|
202 | pSocket->errno = ENOPROTOOPT;
|
---|
203 | Status = EFI_INVALID_PARAMETER;
|
---|
204 | break;
|
---|
205 |
|
---|
206 | case IP_HDRINCL:
|
---|
207 | *ppOptionData = (void *)&pSocket->bIncludeHeader;
|
---|
208 | *pOptionLength = sizeof ( pSocket->bIncludeHeader );
|
---|
209 | break;
|
---|
210 | }
|
---|
211 |
|
---|
212 | //
|
---|
213 | // Return the operation status
|
---|
214 | //
|
---|
215 | DBG_EXIT_STATUS ( Status );
|
---|
216 | return Status;
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 | /**
|
---|
221 | Set the option value
|
---|
222 |
|
---|
223 | This routine handles the IPv4 level options.
|
---|
224 |
|
---|
225 | The ::EslSocketOptionSet routine calls this routine to adjust
|
---|
226 | the IPv4 options one at a time by name.
|
---|
227 |
|
---|
228 | @param [in] pSocket Address of an ::ESL_SOCKET structure
|
---|
229 | @param [in] OptionName Name of the option
|
---|
230 | @param [in] pOptionValue Buffer containing the option value
|
---|
231 | @param [in] OptionLength Length of the buffer in bytes
|
---|
232 |
|
---|
233 | @retval EFI_SUCCESS - Option successfully set
|
---|
234 |
|
---|
235 | **/
|
---|
236 | EFI_STATUS
|
---|
237 | EslIp4OptionSet (
|
---|
238 | IN ESL_SOCKET * pSocket,
|
---|
239 | IN int OptionName,
|
---|
240 | IN CONST void * pOptionValue,
|
---|
241 | IN socklen_t OptionLength
|
---|
242 | )
|
---|
243 | {
|
---|
244 | BOOLEAN bTrueFalse;
|
---|
245 | socklen_t LengthInBytes;
|
---|
246 | UINT8 * pOptionData;
|
---|
247 | EFI_STATUS Status;
|
---|
248 |
|
---|
249 | DBG_ENTER ( );
|
---|
250 |
|
---|
251 | //
|
---|
252 | // Assume success
|
---|
253 | //
|
---|
254 | pSocket->errno = 0;
|
---|
255 | Status = EFI_SUCCESS;
|
---|
256 |
|
---|
257 | //
|
---|
258 | // Determine if the option protocol matches
|
---|
259 | //
|
---|
260 | LengthInBytes = 0;
|
---|
261 | pOptionData = NULL;
|
---|
262 | switch ( OptionName ) {
|
---|
263 | default:
|
---|
264 | //
|
---|
265 | // Protocol level not supported
|
---|
266 | //
|
---|
267 | DEBUG (( DEBUG_INFO | DEBUG_OPTION, "ERROR - Invalid protocol option\r\n" ));
|
---|
268 | pSocket->errno = ENOTSUP;
|
---|
269 | Status = EFI_UNSUPPORTED;
|
---|
270 | break;
|
---|
271 |
|
---|
272 | case IP_HDRINCL:
|
---|
273 |
|
---|
274 | //
|
---|
275 | // Validate the option length
|
---|
276 | //
|
---|
277 | if ( sizeof ( UINT32 ) == OptionLength ) {
|
---|
278 | //
|
---|
279 | // Restrict the input to TRUE or FALSE
|
---|
280 | //
|
---|
281 | bTrueFalse = TRUE;
|
---|
282 | if ( 0 == *(UINT32 *)pOptionValue ) {
|
---|
283 | bTrueFalse = FALSE;
|
---|
284 | }
|
---|
285 | pOptionValue = &bTrueFalse;
|
---|
286 |
|
---|
287 | //
|
---|
288 | // Set the option value
|
---|
289 | //
|
---|
290 | pOptionData = (UINT8 *)&pSocket->bIncludeHeader;
|
---|
291 | LengthInBytes = sizeof ( pSocket->bIncludeHeader );
|
---|
292 | }
|
---|
293 | break;
|
---|
294 | }
|
---|
295 |
|
---|
296 | //
|
---|
297 | // Return the operation status
|
---|
298 | //
|
---|
299 | DBG_EXIT_STATUS ( Status );
|
---|
300 | return Status;
|
---|
301 | }
|
---|
302 |
|
---|
303 |
|
---|
304 | /**
|
---|
305 | Free a receive packet
|
---|
306 |
|
---|
307 | This routine performs the network specific operations necessary
|
---|
308 | to free a receive packet.
|
---|
309 |
|
---|
310 | This routine is called by ::EslSocketPortCloseTxDone to free a
|
---|
311 | receive packet.
|
---|
312 |
|
---|
313 | @param [in] pPacket Address of an ::ESL_PACKET structure.
|
---|
314 | @param [in, out] pRxBytes Address of the count of RX bytes
|
---|
315 |
|
---|
316 | **/
|
---|
317 | VOID
|
---|
318 | EslIp4PacketFree (
|
---|
319 | IN ESL_PACKET * pPacket,
|
---|
320 | IN OUT size_t * pRxBytes
|
---|
321 | )
|
---|
322 | {
|
---|
323 | EFI_IP4_RECEIVE_DATA * pRxData;
|
---|
324 | DBG_ENTER ( );
|
---|
325 |
|
---|
326 | //
|
---|
327 | // Account for the receive bytes
|
---|
328 | //
|
---|
329 | pRxData = pPacket->Op.Ip4Rx.pRxData;
|
---|
330 | *pRxBytes -= pRxData->HeaderLength + pRxData->DataLength;
|
---|
331 |
|
---|
332 | //
|
---|
333 | // Disconnect the buffer from the packet
|
---|
334 | //
|
---|
335 | pPacket->Op.Ip4Rx.pRxData = NULL;
|
---|
336 |
|
---|
337 | //
|
---|
338 | // Return the buffer to the IP4 driver
|
---|
339 | //
|
---|
340 | gBS->SignalEvent ( pRxData->RecycleSignal );
|
---|
341 | DBG_EXIT ( );
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | /**
|
---|
346 | Initialize the network specific portions of an ::ESL_PORT structure.
|
---|
347 |
|
---|
348 | This routine initializes the network specific portions of an
|
---|
349 | ::ESL_PORT structure for use by the socket.
|
---|
350 |
|
---|
351 | This support routine is called by ::EslSocketPortAllocate
|
---|
352 | to connect the socket with the underlying network adapter
|
---|
353 | running the IPv4 protocol.
|
---|
354 |
|
---|
355 | @param [in] pPort Address of an ESL_PORT structure
|
---|
356 | @param [in] DebugFlags Flags for debug messages
|
---|
357 |
|
---|
358 | @retval EFI_SUCCESS - Socket successfully created
|
---|
359 |
|
---|
360 | **/
|
---|
361 | EFI_STATUS
|
---|
362 | EslIp4PortAllocate (
|
---|
363 | IN ESL_PORT * pPort,
|
---|
364 | IN UINTN DebugFlags
|
---|
365 | )
|
---|
366 | {
|
---|
367 | EFI_IP4_CONFIG_DATA * pConfig;
|
---|
368 | ESL_SOCKET * pSocket;
|
---|
369 | EFI_STATUS Status;
|
---|
370 |
|
---|
371 | DBG_ENTER ( );
|
---|
372 |
|
---|
373 | //
|
---|
374 | // Initialize the port
|
---|
375 | //
|
---|
376 | pSocket = pPort->pSocket;
|
---|
377 | pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Ip4Tx.TxData );
|
---|
378 | pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Ip4Tx.Event );
|
---|
379 | pSocket->TxTokenOffset = OFFSET_OF ( EFI_IP4_COMPLETION_TOKEN, Packet.TxData );
|
---|
380 |
|
---|
381 | //
|
---|
382 | // Save the cancel, receive and transmit addresses
|
---|
383 | //
|
---|
384 | pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.IPv4->Configure;
|
---|
385 | pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Cancel;
|
---|
386 | pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.IPv4->Poll;
|
---|
387 | pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Receive;
|
---|
388 | pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Transmit;
|
---|
389 |
|
---|
390 | //
|
---|
391 | // Set the configuration flags
|
---|
392 | //
|
---|
393 | pConfig = &pPort->Context.Ip4.ModeData.ConfigData;
|
---|
394 | pConfig->AcceptIcmpErrors = FALSE;
|
---|
395 | pConfig->AcceptBroadcast = FALSE;
|
---|
396 | pConfig->AcceptPromiscuous = FALSE;
|
---|
397 | pConfig->TypeOfService = 0;
|
---|
398 | pConfig->TimeToLive = 255;
|
---|
399 | pConfig->DoNotFragment = FALSE;
|
---|
400 | pConfig->RawData = FALSE;
|
---|
401 | pConfig->ReceiveTimeout = 0;
|
---|
402 | pConfig->TransmitTimeout = 0;
|
---|
403 |
|
---|
404 | //
|
---|
405 | // Set the default protocol
|
---|
406 | //
|
---|
407 | pConfig->DefaultProtocol = (UINT8)pSocket->Protocol;
|
---|
408 | pConfig->AcceptAnyProtocol = (BOOLEAN)( 0 == pConfig->DefaultProtocol );
|
---|
409 | Status = EFI_SUCCESS;
|
---|
410 |
|
---|
411 | //
|
---|
412 | // Return the operation status
|
---|
413 | //
|
---|
414 | DBG_EXIT_STATUS ( Status );
|
---|
415 | return Status;
|
---|
416 | }
|
---|
417 |
|
---|
418 |
|
---|
419 | /**
|
---|
420 | Receive data from a network connection.
|
---|
421 |
|
---|
422 | This routine attempts to return buffered data to the caller. The
|
---|
423 | data is removed from the urgent queue if the message flag MSG_OOB
|
---|
424 | is specified, otherwise data is removed from the normal queue.
|
---|
425 | See the \ref ReceiveEngine section.
|
---|
426 |
|
---|
427 | This routine is called by ::EslSocketReceive to handle the network
|
---|
428 | specific receive operation to support SOCK_RAW sockets.
|
---|
429 |
|
---|
430 | @param [in] pPort Address of an ::ESL_PORT structure.
|
---|
431 |
|
---|
432 | @param [in] pPacket Address of an ::ESL_PACKET structure.
|
---|
433 |
|
---|
434 | @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
|
---|
435 |
|
---|
436 | @param [in] BufferLength Length of the the buffer
|
---|
437 |
|
---|
438 | @param [in] pBuffer Address of a buffer to receive the data.
|
---|
439 |
|
---|
440 | @param [in] pDataLength Number of received data bytes in the buffer.
|
---|
441 |
|
---|
442 | @param [out] pAddress Network address to receive the remote system address
|
---|
443 |
|
---|
444 | @param [out] pSkipBytes Address to receive the number of bytes skipped
|
---|
445 |
|
---|
446 | @return Returns the address of the next free byte in the buffer.
|
---|
447 |
|
---|
448 | **/
|
---|
449 | UINT8 *
|
---|
450 | EslIp4Receive (
|
---|
451 | IN ESL_PORT * pPort,
|
---|
452 | IN ESL_PACKET * pPacket,
|
---|
453 | IN BOOLEAN * pbConsumePacket,
|
---|
454 | IN size_t BufferLength,
|
---|
455 | IN UINT8 * pBuffer,
|
---|
456 | OUT size_t * pDataLength,
|
---|
457 | OUT struct sockaddr * pAddress,
|
---|
458 | OUT size_t * pSkipBytes
|
---|
459 | )
|
---|
460 | {
|
---|
461 | size_t DataBytes;
|
---|
462 | size_t HeaderBytes;
|
---|
463 | size_t LengthInBytes;
|
---|
464 | struct sockaddr_in * pRemoteAddress;
|
---|
465 | EFI_IP4_RECEIVE_DATA * pRxData;
|
---|
466 |
|
---|
467 | DBG_ENTER ( );
|
---|
468 |
|
---|
469 | //
|
---|
470 | // Return the remote system address if requested
|
---|
471 | //
|
---|
472 | pRxData = pPacket->Op.Ip4Rx.pRxData;
|
---|
473 | if ( NULL != pAddress ) {
|
---|
474 | //
|
---|
475 | // Build the remote address
|
---|
476 | //
|
---|
477 | DEBUG (( DEBUG_RX,
|
---|
478 | "Getting packet remote address: %d.%d.%d.%d\r\n",
|
---|
479 | pRxData->Header->SourceAddress.Addr[0],
|
---|
480 | pRxData->Header->SourceAddress.Addr[1],
|
---|
481 | pRxData->Header->SourceAddress.Addr[2],
|
---|
482 | pRxData->Header->SourceAddress.Addr[3]));
|
---|
483 | pRemoteAddress = (struct sockaddr_in *)pAddress;
|
---|
484 | CopyMem ( &pRemoteAddress->sin_addr,
|
---|
485 | &pRxData->Header->SourceAddress.Addr[0],
|
---|
486 | sizeof ( pRemoteAddress->sin_addr ));
|
---|
487 | }
|
---|
488 |
|
---|
489 | //
|
---|
490 | // Copy the IP header
|
---|
491 | //
|
---|
492 | HeaderBytes = pRxData->HeaderLength;
|
---|
493 | if ( HeaderBytes > BufferLength ) {
|
---|
494 | HeaderBytes = BufferLength;
|
---|
495 | }
|
---|
496 | DEBUG (( DEBUG_RX,
|
---|
497 | "0x%08x --> 0x%08x: Copy header 0x%08x bytes\r\n",
|
---|
498 | pRxData->Header,
|
---|
499 | pBuffer,
|
---|
500 | HeaderBytes ));
|
---|
501 | CopyMem ( pBuffer, pRxData->Header, HeaderBytes );
|
---|
502 | pBuffer += HeaderBytes;
|
---|
503 | LengthInBytes = HeaderBytes;
|
---|
504 |
|
---|
505 | //
|
---|
506 | // Copy the received data
|
---|
507 | //
|
---|
508 | if ( 0 < ( BufferLength - LengthInBytes )) {
|
---|
509 | pBuffer = EslSocketCopyFragmentedBuffer ( pRxData->FragmentCount,
|
---|
510 | &pRxData->FragmentTable[0],
|
---|
511 | BufferLength - LengthInBytes,
|
---|
512 | pBuffer,
|
---|
513 | &DataBytes );
|
---|
514 | LengthInBytes += DataBytes;
|
---|
515 | }
|
---|
516 |
|
---|
517 | //
|
---|
518 | // Determine if the data is being read
|
---|
519 | //
|
---|
520 | if ( *pbConsumePacket ) {
|
---|
521 | //
|
---|
522 | // Display for the bytes consumed
|
---|
523 | //
|
---|
524 | DEBUG (( DEBUG_RX,
|
---|
525 | "0x%08x: Port account for 0x%08x bytes\r\n",
|
---|
526 | pPort,
|
---|
527 | LengthInBytes ));
|
---|
528 |
|
---|
529 | //
|
---|
530 | // Account for any discarded data
|
---|
531 | //
|
---|
532 | *pSkipBytes = pRxData->HeaderLength + pRxData->DataLength - LengthInBytes;
|
---|
533 | }
|
---|
534 |
|
---|
535 | //
|
---|
536 | // Return the data length and the buffer address
|
---|
537 | //
|
---|
538 | *pDataLength = LengthInBytes;
|
---|
539 | DBG_EXIT_HEX ( pBuffer );
|
---|
540 | return pBuffer;
|
---|
541 | }
|
---|
542 |
|
---|
543 |
|
---|
544 | /**
|
---|
545 | Get the remote socket address
|
---|
546 |
|
---|
547 | This routine returns the address of the remote connection point
|
---|
548 | associated with the SOCK_RAW socket.
|
---|
549 |
|
---|
550 | This routine is called by ::EslSocketGetPeerAddress to detemine
|
---|
551 | the IPv4 address associated with the network adapter.
|
---|
552 |
|
---|
553 | @param [in] pPort Address of an ::ESL_PORT structure.
|
---|
554 |
|
---|
555 | @param [out] pAddress Network address to receive the remote system address
|
---|
556 |
|
---|
557 | **/
|
---|
558 | VOID
|
---|
559 | EslIp4RemoteAddressGet (
|
---|
560 | IN ESL_PORT * pPort,
|
---|
561 | OUT struct sockaddr * pAddress
|
---|
562 | )
|
---|
563 | {
|
---|
564 | struct sockaddr_in * pRemoteAddress;
|
---|
565 | ESL_IP4_CONTEXT * pIp4;
|
---|
566 |
|
---|
567 | DBG_ENTER ( );
|
---|
568 |
|
---|
569 | //
|
---|
570 | // Return the remote address
|
---|
571 | //
|
---|
572 | pIp4 = &pPort->Context.Ip4;
|
---|
573 | pRemoteAddress = (struct sockaddr_in *)pAddress;
|
---|
574 | pRemoteAddress->sin_family = AF_INET;
|
---|
575 | CopyMem ( &pRemoteAddress->sin_addr,
|
---|
576 | &pIp4->DestinationAddress.Addr[0],
|
---|
577 | sizeof ( pRemoteAddress->sin_addr ));
|
---|
578 |
|
---|
579 | DBG_EXIT ( );
|
---|
580 | }
|
---|
581 |
|
---|
582 |
|
---|
583 | /**
|
---|
584 | Set the remote address
|
---|
585 |
|
---|
586 | This routine sets the remote address in the port.
|
---|
587 |
|
---|
588 | This routine is called by ::EslSocketConnect to specify the
|
---|
589 | remote network address.
|
---|
590 |
|
---|
591 | @param [in] pPort Address of an ::ESL_PORT structure.
|
---|
592 |
|
---|
593 | @param [in] pSockAddr Network address of the remote system.
|
---|
594 |
|
---|
595 | @param [in] SockAddrLength Length in bytes of the network address.
|
---|
596 |
|
---|
597 | @retval EFI_SUCCESS The operation was successful
|
---|
598 |
|
---|
599 | **/
|
---|
600 | EFI_STATUS
|
---|
601 | EslIp4RemoteAddressSet (
|
---|
602 | IN ESL_PORT * pPort,
|
---|
603 | IN CONST struct sockaddr * pSockAddr,
|
---|
604 | IN socklen_t SockAddrLength
|
---|
605 | )
|
---|
606 | {
|
---|
607 | ESL_IP4_CONTEXT * pIp4;
|
---|
608 | CONST struct sockaddr_in * pRemoteAddress;
|
---|
609 | EFI_STATUS Status;
|
---|
610 |
|
---|
611 | DBG_ENTER ( );
|
---|
612 |
|
---|
613 | //
|
---|
614 | // Set the remote address
|
---|
615 | //
|
---|
616 | pIp4 = &pPort->Context.Ip4;
|
---|
617 | pRemoteAddress = (struct sockaddr_in *)pSockAddr;
|
---|
618 | pIp4->DestinationAddress.Addr[0] = (UINT8)( pRemoteAddress->sin_addr.s_addr );
|
---|
619 | pIp4->DestinationAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );
|
---|
620 | pIp4->DestinationAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );
|
---|
621 | pIp4->DestinationAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );
|
---|
622 | pPort->pSocket->bAddressSet = TRUE;
|
---|
623 | Status = EFI_SUCCESS;
|
---|
624 |
|
---|
625 | //
|
---|
626 | // Return the operation status
|
---|
627 | //
|
---|
628 | DBG_EXIT_STATUS ( Status );
|
---|
629 | return Status;
|
---|
630 | }
|
---|
631 |
|
---|
632 |
|
---|
633 | /**
|
---|
634 | Process the receive completion
|
---|
635 |
|
---|
636 | This routine keeps the IPv4 driver's buffer and queues it in
|
---|
637 | in FIFO order to the data queue. The IP4 driver's buffer will
|
---|
638 | be returned by either ::EslIp4Receive or ::EslSocketPortCloseTxDone.
|
---|
639 | See the \ref ReceiveEngine section.
|
---|
640 |
|
---|
641 | This routine is called by the IPv4 driver when data is
|
---|
642 | received.
|
---|
643 |
|
---|
644 | @param [in] Event The receive completion event
|
---|
645 |
|
---|
646 | @param [in] pIo The address of an ::ESL_IO_MGMT structure
|
---|
647 |
|
---|
648 | **/
|
---|
649 | VOID
|
---|
650 | EslIp4RxComplete (
|
---|
651 | IN EFI_EVENT Event,
|
---|
652 | IN ESL_IO_MGMT * pIo
|
---|
653 | )
|
---|
654 | {
|
---|
655 | size_t LengthInBytes;
|
---|
656 | ESL_PORT * pPort;
|
---|
657 | ESL_PACKET * pPacket;
|
---|
658 | EFI_IP4_RECEIVE_DATA * pRxData;
|
---|
659 | EFI_STATUS Status;
|
---|
660 |
|
---|
661 | DBG_ENTER ( );
|
---|
662 |
|
---|
663 | //
|
---|
664 | // Get the operation status.
|
---|
665 | //
|
---|
666 | pPort = pIo->pPort;
|
---|
667 | Status = pIo->Token.Ip4Rx.Status;
|
---|
668 |
|
---|
669 | //
|
---|
670 | // Get the packet length
|
---|
671 | //
|
---|
672 | pRxData = pIo->Token.Ip4Rx.Packet.RxData;
|
---|
673 | LengthInBytes = pRxData->HeaderLength + pRxData->DataLength;
|
---|
674 |
|
---|
675 | //
|
---|
676 | // +--------------------+ +----------------------+
|
---|
677 | // | ESL_IO_MGMT | | Data Buffer |
|
---|
678 | // | | | (Driver owned) |
|
---|
679 | // | +---------------+ +----------------------+
|
---|
680 | // | | Token | ^
|
---|
681 | // | | Rx Event | |
|
---|
682 | // | | | +----------------------+
|
---|
683 | // | | RxData --> | EFI_IP4_RECEIVE_DATA |
|
---|
684 | // +----+---------------+ | (Driver owned) |
|
---|
685 | // +----------------------+
|
---|
686 | // +--------------------+ ^
|
---|
687 | // | ESL_PACKET | .
|
---|
688 | // | | .
|
---|
689 | // | +---------------+ .
|
---|
690 | // | | pRxData --> NULL .......
|
---|
691 | // +----+---------------+
|
---|
692 | //
|
---|
693 | //
|
---|
694 | // Save the data in the packet
|
---|
695 | //
|
---|
696 | pPacket = pIo->pPacket;
|
---|
697 | pPacket->Op.Ip4Rx.pRxData = pRxData;
|
---|
698 |
|
---|
699 | //
|
---|
700 | // Complete this request
|
---|
701 | //
|
---|
702 | EslSocketRxComplete ( pIo, Status, LengthInBytes, FALSE );
|
---|
703 | DBG_EXIT ( );
|
---|
704 | }
|
---|
705 |
|
---|
706 |
|
---|
707 | /**
|
---|
708 | Determine if the socket is configured.
|
---|
709 |
|
---|
710 | This routine uses the flag ESL_SOCKET::bConfigured to determine
|
---|
711 | if the network layer's configuration routine has been called.
|
---|
712 | This routine calls the ::EslSocketBind and configuration routines
|
---|
713 | if they were not already called. After the port is configured,
|
---|
714 | the \ref ReceiveEngine is started.
|
---|
715 |
|
---|
716 | This routine is called by EslSocketIsConfigured to verify
|
---|
717 | that the socket is configured.
|
---|
718 |
|
---|
719 | @param [in] pSocket Address of an ::ESL_SOCKET structure
|
---|
720 |
|
---|
721 | @retval EFI_SUCCESS - The port is connected
|
---|
722 | @retval EFI_NOT_STARTED - The port is not connected
|
---|
723 |
|
---|
724 | **/
|
---|
725 | EFI_STATUS
|
---|
726 | EslIp4SocketIsConfigured (
|
---|
727 | IN ESL_SOCKET * pSocket
|
---|
728 | )
|
---|
729 | {
|
---|
730 | UINTN Index;
|
---|
731 | ESL_PORT * pPort;
|
---|
732 | ESL_PORT * pNextPort;
|
---|
733 | ESL_IP4_CONTEXT * pIp4;
|
---|
734 | EFI_IP4_PROTOCOL * pIp4Protocol;
|
---|
735 | EFI_STATUS Status;
|
---|
736 | struct sockaddr_in LocalAddress;
|
---|
737 |
|
---|
738 | DBG_ENTER ( );
|
---|
739 |
|
---|
740 | //
|
---|
741 | // Assume success
|
---|
742 | //
|
---|
743 | Status = EFI_SUCCESS;
|
---|
744 |
|
---|
745 | //
|
---|
746 | // Configure the port if necessary
|
---|
747 | //
|
---|
748 | if ( !pSocket->bConfigured ) {
|
---|
749 | //
|
---|
750 | // Fill in the port list if necessary
|
---|
751 | //
|
---|
752 | pSocket->errno = ENETDOWN;
|
---|
753 | if ( NULL == pSocket->pPortList ) {
|
---|
754 | LocalAddress.sin_len = sizeof ( LocalAddress );
|
---|
755 | LocalAddress.sin_family = AF_INET;
|
---|
756 | LocalAddress.sin_addr.s_addr = 0;
|
---|
757 | LocalAddress.sin_port = 0;
|
---|
758 | Status = EslSocketBind ( &pSocket->SocketProtocol,
|
---|
759 | (struct sockaddr *)&LocalAddress,
|
---|
760 | LocalAddress.sin_len,
|
---|
761 | &pSocket->errno );
|
---|
762 | }
|
---|
763 |
|
---|
764 | //
|
---|
765 | // Walk the port list
|
---|
766 | //
|
---|
767 | pPort = pSocket->pPortList;
|
---|
768 | while ( NULL != pPort ) {
|
---|
769 | //
|
---|
770 | // Update the raw setting
|
---|
771 | //
|
---|
772 | pIp4 = &pPort->Context.Ip4;
|
---|
773 | if ( pSocket->bIncludeHeader ) {
|
---|
774 | //
|
---|
775 | // IP header will be included with the data on transmit
|
---|
776 | //
|
---|
777 | pIp4->ModeData.ConfigData.RawData = TRUE;
|
---|
778 | }
|
---|
779 |
|
---|
780 | //
|
---|
781 | // Attempt to configure the port
|
---|
782 | //
|
---|
783 | pNextPort = pPort->pLinkSocket;
|
---|
784 | pIp4Protocol = pPort->pProtocol.IPv4;
|
---|
785 | DEBUG (( DEBUG_TX,
|
---|
786 | "0x%08x: pPort Configuring for %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
|
---|
787 | pPort,
|
---|
788 | pIp4->ModeData.ConfigData.StationAddress.Addr[0],
|
---|
789 | pIp4->ModeData.ConfigData.StationAddress.Addr[1],
|
---|
790 | pIp4->ModeData.ConfigData.StationAddress.Addr[2],
|
---|
791 | pIp4->ModeData.ConfigData.StationAddress.Addr[3],
|
---|
792 | pIp4->DestinationAddress.Addr[0],
|
---|
793 | pIp4->DestinationAddress.Addr[1],
|
---|
794 | pIp4->DestinationAddress.Addr[2],
|
---|
795 | pIp4->DestinationAddress.Addr[3]));
|
---|
796 | Status = pIp4Protocol->Configure ( pIp4Protocol,
|
---|
797 | &pIp4->ModeData.ConfigData );
|
---|
798 | if ( !EFI_ERROR ( Status )) {
|
---|
799 | //
|
---|
800 | // Update the configuration data
|
---|
801 | //
|
---|
802 | Status = pIp4Protocol->GetModeData ( pIp4Protocol,
|
---|
803 | &pIp4->ModeData,
|
---|
804 | NULL,
|
---|
805 | NULL );
|
---|
806 | }
|
---|
807 | if ( EFI_ERROR ( Status )) {
|
---|
808 | if ( !pSocket->bConfigured ) {
|
---|
809 | DEBUG (( DEBUG_LISTEN,
|
---|
810 | "ERROR - Failed to configure the Ip4 port, Status: %r\r\n",
|
---|
811 | Status ));
|
---|
812 | switch ( Status ) {
|
---|
813 | case EFI_ACCESS_DENIED:
|
---|
814 | pSocket->errno = EACCES;
|
---|
815 | break;
|
---|
816 |
|
---|
817 | default:
|
---|
818 | case EFI_DEVICE_ERROR:
|
---|
819 | pSocket->errno = EIO;
|
---|
820 | break;
|
---|
821 |
|
---|
822 | case EFI_INVALID_PARAMETER:
|
---|
823 | pSocket->errno = EADDRNOTAVAIL;
|
---|
824 | break;
|
---|
825 |
|
---|
826 | case EFI_NO_MAPPING:
|
---|
827 | pSocket->errno = EAFNOSUPPORT;
|
---|
828 | break;
|
---|
829 |
|
---|
830 | case EFI_OUT_OF_RESOURCES:
|
---|
831 | pSocket->errno = ENOBUFS;
|
---|
832 | break;
|
---|
833 |
|
---|
834 | case EFI_UNSUPPORTED:
|
---|
835 | pSocket->errno = EOPNOTSUPP;
|
---|
836 | break;
|
---|
837 | }
|
---|
838 | }
|
---|
839 | }
|
---|
840 | else {
|
---|
841 | DEBUG (( DEBUG_TX,
|
---|
842 | "0x%08x: pPort Configured for %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
|
---|
843 | pPort,
|
---|
844 | pIp4->ModeData.ConfigData.StationAddress.Addr[0],
|
---|
845 | pIp4->ModeData.ConfigData.StationAddress.Addr[1],
|
---|
846 | pIp4->ModeData.ConfigData.StationAddress.Addr[2],
|
---|
847 | pIp4->ModeData.ConfigData.StationAddress.Addr[3],
|
---|
848 | pIp4->DestinationAddress.Addr[0],
|
---|
849 | pIp4->DestinationAddress.Addr[1],
|
---|
850 | pIp4->DestinationAddress.Addr[2],
|
---|
851 | pIp4->DestinationAddress.Addr[3]));
|
---|
852 | DEBUG (( DEBUG_TX,
|
---|
853 | "Subnet Mask: %d.%d.%d.%d\r\n",
|
---|
854 | pIp4->ModeData.ConfigData.SubnetMask.Addr[0],
|
---|
855 | pIp4->ModeData.ConfigData.SubnetMask.Addr[1],
|
---|
856 | pIp4->ModeData.ConfigData.SubnetMask.Addr[2],
|
---|
857 | pIp4->ModeData.ConfigData.SubnetMask.Addr[3]));
|
---|
858 | DEBUG (( DEBUG_TX,
|
---|
859 | "Route Count: %d\r\n",
|
---|
860 | pIp4->ModeData.RouteCount ));
|
---|
861 | for ( Index = 0; pIp4->ModeData.RouteCount > Index; Index++ ) {
|
---|
862 | if ( 0 == Index ) {
|
---|
863 | DEBUG (( DEBUG_TX, "Route Table:\r\n" ));
|
---|
864 | }
|
---|
865 | DEBUG (( DEBUG_TX,
|
---|
866 | "%5d: %d.%d.%d.%d, %d.%d.%d.%d ==> %d.%d.%d.%d\r\n",
|
---|
867 | Index,
|
---|
868 | pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[0],
|
---|
869 | pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[1],
|
---|
870 | pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[2],
|
---|
871 | pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[3],
|
---|
872 | pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[0],
|
---|
873 | pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[1],
|
---|
874 | pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[2],
|
---|
875 | pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[3],
|
---|
876 | pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[0],
|
---|
877 | pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[1],
|
---|
878 | pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[2],
|
---|
879 | pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[3]));
|
---|
880 | }
|
---|
881 | pPort->bConfigured = TRUE;
|
---|
882 | pSocket->bConfigured = TRUE;
|
---|
883 |
|
---|
884 | //
|
---|
885 | // Start the first read on the port
|
---|
886 | //
|
---|
887 | EslSocketRxStart ( pPort );
|
---|
888 |
|
---|
889 | //
|
---|
890 | // The socket is connected
|
---|
891 | //
|
---|
892 | pSocket->State = SOCKET_STATE_CONNECTED;
|
---|
893 | pSocket->errno = 0;
|
---|
894 | }
|
---|
895 |
|
---|
896 | //
|
---|
897 | // Set the next port
|
---|
898 | //
|
---|
899 | pPort = pNextPort;
|
---|
900 | }
|
---|
901 | }
|
---|
902 |
|
---|
903 | //
|
---|
904 | // Determine the socket configuration status
|
---|
905 | //
|
---|
906 | Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;
|
---|
907 |
|
---|
908 | //
|
---|
909 | // Return the port connected state.
|
---|
910 | //
|
---|
911 | DBG_EXIT_STATUS ( Status );
|
---|
912 | return Status;
|
---|
913 | }
|
---|
914 |
|
---|
915 |
|
---|
916 | /**
|
---|
917 | Buffer data for transmission over a network connection.
|
---|
918 |
|
---|
919 | This routine buffers data for the transmit engine in the normal
|
---|
920 | data queue. When the \ref TransmitEngine has resources, this
|
---|
921 | routine will start the transmission of the next buffer on the
|
---|
922 | network connection.
|
---|
923 |
|
---|
924 | This routine is called by ::EslSocketTransmit to buffer
|
---|
925 | data for transmission. The data is copied into a local buffer
|
---|
926 | freeing the application buffer for reuse upon return. When
|
---|
927 | necessary, this routine starts the transmit engine that
|
---|
928 | performs the data transmission on the network connection. The
|
---|
929 | transmit engine transmits the data a packet at a time over the
|
---|
930 | network connection.
|
---|
931 |
|
---|
932 | Transmission errors are returned during the next transmission or
|
---|
933 | during the close operation. Only buffering errors are returned
|
---|
934 | during the current transmission attempt.
|
---|
935 |
|
---|
936 | @param [in] pSocket Address of an ::ESL_SOCKET structure
|
---|
937 |
|
---|
938 | @param [in] Flags Message control flags
|
---|
939 |
|
---|
940 | @param [in] BufferLength Length of the the buffer
|
---|
941 |
|
---|
942 | @param [in] pBuffer Address of a buffer to receive the data.
|
---|
943 |
|
---|
944 | @param [in] pDataLength Number of received data bytes in the buffer.
|
---|
945 |
|
---|
946 | @param [in] pAddress Network address of the remote system address
|
---|
947 |
|
---|
948 | @param [in] AddressLength Length of the remote network address structure
|
---|
949 |
|
---|
950 | @retval EFI_SUCCESS - Socket data successfully buffered
|
---|
951 |
|
---|
952 | **/
|
---|
953 | EFI_STATUS
|
---|
954 | EslIp4TxBuffer (
|
---|
955 | IN ESL_SOCKET * pSocket,
|
---|
956 | IN int Flags,
|
---|
957 | IN size_t BufferLength,
|
---|
958 | IN CONST UINT8 * pBuffer,
|
---|
959 | OUT size_t * pDataLength,
|
---|
960 | IN const struct sockaddr * pAddress,
|
---|
961 | IN socklen_t AddressLength
|
---|
962 | )
|
---|
963 | {
|
---|
964 | ESL_PACKET * pPacket;
|
---|
965 | ESL_PACKET * pPreviousPacket;
|
---|
966 | ESL_PORT * pPort;
|
---|
967 | const struct sockaddr_in * pRemoteAddress;
|
---|
968 | ESL_IP4_CONTEXT * pIp4;
|
---|
969 | size_t * pTxBytes;
|
---|
970 | ESL_IP4_TX_DATA * pTxData;
|
---|
971 | EFI_STATUS Status;
|
---|
972 | EFI_TPL TplPrevious;
|
---|
973 |
|
---|
974 | DBG_ENTER ( );
|
---|
975 |
|
---|
976 | //
|
---|
977 | // Assume failure
|
---|
978 | //
|
---|
979 | Status = EFI_UNSUPPORTED;
|
---|
980 | pSocket->errno = ENOTCONN;
|
---|
981 | *pDataLength = 0;
|
---|
982 |
|
---|
983 | //
|
---|
984 | // Verify that the socket is connected
|
---|
985 | //
|
---|
986 | if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
|
---|
987 | //
|
---|
988 | // Verify that there is enough room to buffer another
|
---|
989 | // transmit operation
|
---|
990 | //
|
---|
991 | pTxBytes = &pSocket->TxBytes;
|
---|
992 | if ( pSocket->MaxTxBuf > *pTxBytes ) {
|
---|
993 | //
|
---|
994 | // Locate the port
|
---|
995 | //
|
---|
996 | pPort = pSocket->pPortList;
|
---|
997 | while ( NULL != pPort ) {
|
---|
998 | //
|
---|
999 | // Determine the queue head
|
---|
1000 | //
|
---|
1001 | pIp4 = &pPort->Context.Ip4;
|
---|
1002 |
|
---|
1003 | //
|
---|
1004 | // Attempt to allocate the packet
|
---|
1005 | //
|
---|
1006 | Status = EslSocketPacketAllocate ( &pPacket,
|
---|
1007 | sizeof ( pPacket->Op.Ip4Tx )
|
---|
1008 | - sizeof ( pPacket->Op.Ip4Tx.Buffer )
|
---|
1009 | + BufferLength,
|
---|
1010 | 0,
|
---|
1011 | DEBUG_TX );
|
---|
1012 | if ( !EFI_ERROR ( Status )) {
|
---|
1013 | //
|
---|
1014 | // Initialize the transmit operation
|
---|
1015 | //
|
---|
1016 | pTxData = &pPacket->Op.Ip4Tx;
|
---|
1017 | pTxData->TxData.DestinationAddress.Addr[0] = pIp4->DestinationAddress.Addr[0];
|
---|
1018 | pTxData->TxData.DestinationAddress.Addr[1] = pIp4->DestinationAddress.Addr[1];
|
---|
1019 | pTxData->TxData.DestinationAddress.Addr[2] = pIp4->DestinationAddress.Addr[2];
|
---|
1020 | pTxData->TxData.DestinationAddress.Addr[3] = pIp4->DestinationAddress.Addr[3];
|
---|
1021 | pTxData->TxData.OverrideData = NULL;
|
---|
1022 | pTxData->TxData.OptionsLength = 0;
|
---|
1023 | pTxData->TxData.OptionsBuffer = NULL;
|
---|
1024 | pTxData->TxData.TotalDataLength = (UINT32) BufferLength;
|
---|
1025 | pTxData->TxData.FragmentCount = 1;
|
---|
1026 | pTxData->TxData.FragmentTable[0].FragmentLength = (UINT32) BufferLength;
|
---|
1027 | pTxData->TxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Ip4Tx.Buffer[0];
|
---|
1028 |
|
---|
1029 | //
|
---|
1030 | // Set the remote system address if necessary
|
---|
1031 | //
|
---|
1032 | if ( NULL != pAddress ) {
|
---|
1033 | pRemoteAddress = (const struct sockaddr_in *)pAddress;
|
---|
1034 | pTxData->Override.SourceAddress.Addr[0] = pIp4->ModeData.ConfigData.StationAddress.Addr[0];
|
---|
1035 | pTxData->Override.SourceAddress.Addr[1] = pIp4->ModeData.ConfigData.StationAddress.Addr[1];
|
---|
1036 | pTxData->Override.SourceAddress.Addr[2] = pIp4->ModeData.ConfigData.StationAddress.Addr[2];
|
---|
1037 | pTxData->Override.SourceAddress.Addr[3] = pIp4->ModeData.ConfigData.StationAddress.Addr[3];
|
---|
1038 | pTxData->TxData.DestinationAddress.Addr[0] = (UINT8)pRemoteAddress->sin_addr.s_addr;
|
---|
1039 | pTxData->TxData.DestinationAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );
|
---|
1040 | pTxData->TxData.DestinationAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );
|
---|
1041 | pTxData->TxData.DestinationAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );
|
---|
1042 | pTxData->Override.GatewayAddress.Addr[0] = 0;
|
---|
1043 | pTxData->Override.GatewayAddress.Addr[1] = 0;
|
---|
1044 | pTxData->Override.GatewayAddress.Addr[2] = 0;
|
---|
1045 | pTxData->Override.GatewayAddress.Addr[3] = 0;
|
---|
1046 | pTxData->Override.Protocol = (UINT8)pSocket->Protocol;
|
---|
1047 | pTxData->Override.TypeOfService = 0;
|
---|
1048 | pTxData->Override.TimeToLive = 255;
|
---|
1049 | pTxData->Override.DoNotFragment = FALSE;
|
---|
1050 |
|
---|
1051 | //
|
---|
1052 | // Use the remote system address when sending this packet
|
---|
1053 | //
|
---|
1054 | pTxData->TxData.OverrideData = &pTxData->Override;
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | //
|
---|
1058 | // Copy the data into the buffer
|
---|
1059 | //
|
---|
1060 | CopyMem ( &pPacket->Op.Ip4Tx.Buffer[0],
|
---|
1061 | pBuffer,
|
---|
1062 | BufferLength );
|
---|
1063 |
|
---|
1064 | //
|
---|
1065 | // Synchronize with the socket layer
|
---|
1066 | //
|
---|
1067 | RAISE_TPL ( TplPrevious, TPL_SOCKETS );
|
---|
1068 |
|
---|
1069 | //
|
---|
1070 | // Display the request
|
---|
1071 | //
|
---|
1072 | DEBUG (( DEBUG_TX,
|
---|
1073 | "Send %d bytes from 0x%08x, %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
|
---|
1074 | BufferLength,
|
---|
1075 | pBuffer,
|
---|
1076 | pIp4->ModeData.ConfigData.StationAddress.Addr[0],
|
---|
1077 | pIp4->ModeData.ConfigData.StationAddress.Addr[1],
|
---|
1078 | pIp4->ModeData.ConfigData.StationAddress.Addr[2],
|
---|
1079 | pIp4->ModeData.ConfigData.StationAddress.Addr[3],
|
---|
1080 | pTxData->TxData.DestinationAddress.Addr[0],
|
---|
1081 | pTxData->TxData.DestinationAddress.Addr[1],
|
---|
1082 | pTxData->TxData.DestinationAddress.Addr[2],
|
---|
1083 | pTxData->TxData.DestinationAddress.Addr[3]));
|
---|
1084 |
|
---|
1085 | //
|
---|
1086 | // Queue the data for transmission
|
---|
1087 | //
|
---|
1088 | pPacket->pNext = NULL;
|
---|
1089 | pPreviousPacket = pSocket->pTxPacketListTail;
|
---|
1090 | if ( NULL == pPreviousPacket ) {
|
---|
1091 | pSocket->pTxPacketListHead = pPacket;
|
---|
1092 | }
|
---|
1093 | else {
|
---|
1094 | pPreviousPacket->pNext = pPacket;
|
---|
1095 | }
|
---|
1096 | pSocket->pTxPacketListTail = pPacket;
|
---|
1097 | DEBUG (( DEBUG_TX,
|
---|
1098 | "0x%08x: Packet on transmit list\r\n",
|
---|
1099 | pPacket ));
|
---|
1100 |
|
---|
1101 | //
|
---|
1102 | // Account for the buffered data
|
---|
1103 | //
|
---|
1104 | *pTxBytes += BufferLength;
|
---|
1105 | *pDataLength = BufferLength;
|
---|
1106 |
|
---|
1107 | //
|
---|
1108 | // Start the transmit engine if it is idle
|
---|
1109 | //
|
---|
1110 | if ( NULL != pPort->pTxFree ) {
|
---|
1111 | EslSocketTxStart ( pPort,
|
---|
1112 | &pSocket->pTxPacketListHead,
|
---|
1113 | &pSocket->pTxPacketListTail,
|
---|
1114 | &pPort->pTxActive,
|
---|
1115 | &pPort->pTxFree );
|
---|
1116 |
|
---|
1117 | //
|
---|
1118 | // Ignore any transmit error
|
---|
1119 | //
|
---|
1120 | if ( EFI_ERROR ( pSocket->TxError )) {
|
---|
1121 | DEBUG (( DEBUG_TX,
|
---|
1122 | "0x%08x: Transmit error, Packet: 0x%08x, Status: %r\r\n",
|
---|
1123 | pPort,
|
---|
1124 | pPacket,
|
---|
1125 | pSocket->TxError ));
|
---|
1126 | }
|
---|
1127 | pSocket->TxError = EFI_SUCCESS;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | //
|
---|
1131 | // Release the socket layer synchronization
|
---|
1132 | //
|
---|
1133 | RESTORE_TPL ( TplPrevious );
|
---|
1134 | }
|
---|
1135 | else {
|
---|
1136 | //
|
---|
1137 | // Packet allocation failed
|
---|
1138 | //
|
---|
1139 | pSocket->errno = ENOMEM;
|
---|
1140 | break;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | //
|
---|
1144 | // Set the next port
|
---|
1145 | //
|
---|
1146 | pPort = pPort->pLinkSocket;
|
---|
1147 | }
|
---|
1148 | }
|
---|
1149 | else {
|
---|
1150 | //
|
---|
1151 | // Not enough buffer space available
|
---|
1152 | //
|
---|
1153 | pSocket->errno = EAGAIN;
|
---|
1154 | Status = EFI_NOT_READY;
|
---|
1155 | }
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | //
|
---|
1159 | // Return the operation status
|
---|
1160 | //
|
---|
1161 | DBG_EXIT_STATUS ( Status );
|
---|
1162 | return Status;
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 |
|
---|
1166 | /**
|
---|
1167 | Process the transmit completion
|
---|
1168 |
|
---|
1169 | This routine use ::EslSocketTxComplete to perform the transmit
|
---|
1170 | completion processing for data packets.
|
---|
1171 |
|
---|
1172 | This routine is called by the IPv4 network layer when a data
|
---|
1173 | transmit request completes.
|
---|
1174 |
|
---|
1175 | @param [in] Event The normal transmit completion event
|
---|
1176 |
|
---|
1177 | @param [in] pIo The address of an ::ESL_IO_MGMT structure
|
---|
1178 |
|
---|
1179 | **/
|
---|
1180 | VOID
|
---|
1181 | EslIp4TxComplete (
|
---|
1182 | IN EFI_EVENT Event,
|
---|
1183 | IN ESL_IO_MGMT * pIo
|
---|
1184 | )
|
---|
1185 | {
|
---|
1186 | UINT32 LengthInBytes;
|
---|
1187 | ESL_PORT * pPort;
|
---|
1188 | ESL_PACKET * pPacket;
|
---|
1189 | ESL_SOCKET * pSocket;
|
---|
1190 | EFI_STATUS Status;
|
---|
1191 |
|
---|
1192 | DBG_ENTER ( );
|
---|
1193 |
|
---|
1194 | //
|
---|
1195 | // Locate the active transmit packet
|
---|
1196 | //
|
---|
1197 | pPacket = pIo->pPacket;
|
---|
1198 | pPort = pIo->pPort;
|
---|
1199 | pSocket = pPort->pSocket;
|
---|
1200 |
|
---|
1201 | //
|
---|
1202 | // Get the transmit length and status
|
---|
1203 | //
|
---|
1204 | LengthInBytes = pPacket->Op.Ip4Tx.TxData.TotalDataLength;
|
---|
1205 | pSocket->TxBytes -= LengthInBytes;
|
---|
1206 | Status = pIo->Token.Ip4Tx.Status;
|
---|
1207 |
|
---|
1208 | //
|
---|
1209 | // Ignore the transmit error
|
---|
1210 | //
|
---|
1211 | if ( EFI_ERROR ( Status )) {
|
---|
1212 | DEBUG (( DEBUG_TX,
|
---|
1213 | "0x%08x: Transmit completion error, Packet: 0x%08x, Status: %r\r\n",
|
---|
1214 | pPort,
|
---|
1215 | pPacket,
|
---|
1216 | Status ));
|
---|
1217 | Status = EFI_SUCCESS;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | //
|
---|
1221 | // Complete the transmit operation
|
---|
1222 | //
|
---|
1223 | EslSocketTxComplete ( pIo,
|
---|
1224 | LengthInBytes,
|
---|
1225 | Status,
|
---|
1226 | "Raw ",
|
---|
1227 | &pSocket->pTxPacketListHead,
|
---|
1228 | &pSocket->pTxPacketListTail,
|
---|
1229 | &pPort->pTxActive,
|
---|
1230 | &pPort->pTxFree );
|
---|
1231 | DBG_EXIT ( );
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 |
|
---|
1235 | /**
|
---|
1236 | Verify the adapter's IP address
|
---|
1237 |
|
---|
1238 | This support routine is called by EslSocketBindTest.
|
---|
1239 |
|
---|
1240 | @param [in] pPort Address of an ::ESL_PORT structure.
|
---|
1241 | @param [in] pConfigData Address of the configuration data
|
---|
1242 |
|
---|
1243 | @retval EFI_SUCCESS - The IP address is valid
|
---|
1244 | @retval EFI_NOT_STARTED - The IP address is invalid
|
---|
1245 |
|
---|
1246 | **/
|
---|
1247 | EFI_STATUS
|
---|
1248 | EslIp4VerifyLocalIpAddress (
|
---|
1249 | IN ESL_PORT * pPort,
|
---|
1250 | IN EFI_IP4_CONFIG_DATA * pConfigData
|
---|
1251 | )
|
---|
1252 | {
|
---|
1253 | UINTN DataSize;
|
---|
1254 | EFI_IP4_IPCONFIG_DATA * pIpConfigData;
|
---|
1255 | EFI_IP4_CONFIG_PROTOCOL * pIpConfigProtocol;
|
---|
1256 | ESL_SERVICE * pService;
|
---|
1257 | EFI_STATUS Status;
|
---|
1258 |
|
---|
1259 | DBG_ENTER ( );
|
---|
1260 |
|
---|
1261 | //
|
---|
1262 | // Use break instead of goto
|
---|
1263 | //
|
---|
1264 | pIpConfigData = NULL;
|
---|
1265 | for ( ; ; ) {
|
---|
1266 | //
|
---|
1267 | // Determine if the IP address is specified
|
---|
1268 | //
|
---|
1269 | DEBUG (( DEBUG_BIND,
|
---|
1270 | "UseDefaultAddress: %s\r\n",
|
---|
1271 | pConfigData->UseDefaultAddress ? L"TRUE" : L"FALSE" ));
|
---|
1272 | DEBUG (( DEBUG_BIND,
|
---|
1273 | "Requested IP address: %d.%d.%d.%d\r\n",
|
---|
1274 | pConfigData->StationAddress.Addr [ 0 ],
|
---|
1275 | pConfigData->StationAddress.Addr [ 1 ],
|
---|
1276 | pConfigData->StationAddress.Addr [ 2 ],
|
---|
1277 | pConfigData->StationAddress.Addr [ 3 ]));
|
---|
1278 | if ( pConfigData->UseDefaultAddress
|
---|
1279 | || (( 0 == pConfigData->StationAddress.Addr [ 0 ])
|
---|
1280 | && ( 0 == pConfigData->StationAddress.Addr [ 1 ])
|
---|
1281 | && ( 0 == pConfigData->StationAddress.Addr [ 2 ])
|
---|
1282 | && ( 0 == pConfigData->StationAddress.Addr [ 3 ])))
|
---|
1283 | {
|
---|
1284 | Status = EFI_SUCCESS;
|
---|
1285 | break;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 | //
|
---|
1289 | // Open the configuration protocol
|
---|
1290 | //
|
---|
1291 | pService = pPort->pService;
|
---|
1292 | Status = gBS->OpenProtocol ( pService->Controller,
|
---|
1293 | &gEfiIp4ConfigProtocolGuid,
|
---|
1294 | (VOID **)&pIpConfigProtocol,
|
---|
1295 | NULL,
|
---|
1296 | NULL,
|
---|
1297 | EFI_OPEN_PROTOCOL_GET_PROTOCOL );
|
---|
1298 | if ( EFI_ERROR ( Status )) {
|
---|
1299 | DEBUG (( DEBUG_ERROR,
|
---|
1300 | "ERROR - IP Configuration Protocol not available, Status: %r\r\n",
|
---|
1301 | Status ));
|
---|
1302 | break;
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | //
|
---|
1306 | // Get the IP configuration data size
|
---|
1307 | //
|
---|
1308 | DataSize = 0;
|
---|
1309 | Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
|
---|
1310 | &DataSize,
|
---|
1311 | NULL );
|
---|
1312 | if ( EFI_BUFFER_TOO_SMALL != Status ) {
|
---|
1313 | DEBUG (( DEBUG_ERROR,
|
---|
1314 | "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",
|
---|
1315 | Status ));
|
---|
1316 | break;
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | //
|
---|
1320 | // Allocate the configuration data buffer
|
---|
1321 | //
|
---|
1322 | pIpConfigData = AllocatePool ( DataSize );
|
---|
1323 | if ( NULL == pIpConfigData ) {
|
---|
1324 | DEBUG (( DEBUG_ERROR,
|
---|
1325 | "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));
|
---|
1326 | Status = EFI_OUT_OF_RESOURCES;
|
---|
1327 | break;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | //
|
---|
1331 | // Get the IP configuration
|
---|
1332 | //
|
---|
1333 | Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
|
---|
1334 | &DataSize,
|
---|
1335 | pIpConfigData );
|
---|
1336 | if ( EFI_ERROR ( Status )) {
|
---|
1337 | DEBUG (( DEBUG_ERROR,
|
---|
1338 | "ERROR - Failed to return IP Configuration data, Status: %r\r\n",
|
---|
1339 | Status ));
|
---|
1340 | break;
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 | //
|
---|
1344 | // Display the current configuration
|
---|
1345 | //
|
---|
1346 | DEBUG (( DEBUG_BIND,
|
---|
1347 | "Actual adapter IP address: %d.%d.%d.%d\r\n",
|
---|
1348 | pIpConfigData->StationAddress.Addr [ 0 ],
|
---|
1349 | pIpConfigData->StationAddress.Addr [ 1 ],
|
---|
1350 | pIpConfigData->StationAddress.Addr [ 2 ],
|
---|
1351 | pIpConfigData->StationAddress.Addr [ 3 ]));
|
---|
1352 |
|
---|
1353 | //
|
---|
1354 | // Assume the port is not configured
|
---|
1355 | //
|
---|
1356 | Status = EFI_SUCCESS;
|
---|
1357 | if (( pConfigData->StationAddress.Addr [ 0 ] == pIpConfigData->StationAddress.Addr [ 0 ])
|
---|
1358 | && ( pConfigData->StationAddress.Addr [ 1 ] == pIpConfigData->StationAddress.Addr [ 1 ])
|
---|
1359 | && ( pConfigData->StationAddress.Addr [ 2 ] == pIpConfigData->StationAddress.Addr [ 2 ])
|
---|
1360 | && ( pConfigData->StationAddress.Addr [ 3 ] == pIpConfigData->StationAddress.Addr [ 3 ])) {
|
---|
1361 | break;
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 | //
|
---|
1365 | // The IP address did not match
|
---|
1366 | //
|
---|
1367 | Status = EFI_NOT_STARTED;
|
---|
1368 | break;
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | //
|
---|
1372 | // Free the buffer if necessary
|
---|
1373 | //
|
---|
1374 | if ( NULL != pIpConfigData ) {
|
---|
1375 | FreePool ( pIpConfigData );
|
---|
1376 | }
|
---|
1377 |
|
---|
1378 | //
|
---|
1379 | // Return the IP address status
|
---|
1380 | //
|
---|
1381 | DBG_EXIT_STATUS ( Status );
|
---|
1382 | return Status;
|
---|
1383 | }
|
---|
1384 |
|
---|
1385 |
|
---|
1386 | /**
|
---|
1387 | Interface between the socket layer and the network specific
|
---|
1388 | code that supports SOCK_RAW sockets over IPv4.
|
---|
1389 | **/
|
---|
1390 | CONST ESL_PROTOCOL_API cEslIp4Api = {
|
---|
1391 | "IPv4",
|
---|
1392 | IPPROTO_IP,
|
---|
1393 | OFFSET_OF ( ESL_PORT, Context.Ip4.ModeData.ConfigData ),
|
---|
1394 | OFFSET_OF ( ESL_LAYER, pIp4List ),
|
---|
1395 | OFFSET_OF ( struct sockaddr_in, sin_zero ),
|
---|
1396 | sizeof ( struct sockaddr_in ),
|
---|
1397 | AF_INET,
|
---|
1398 | sizeof (((ESL_PACKET *)0 )->Op.Ip4Rx ),
|
---|
1399 | sizeof (((ESL_PACKET *)0 )->Op.Ip4Rx ),
|
---|
1400 | OFFSET_OF ( ESL_IO_MGMT, Token.Ip4Rx.Packet.RxData ),
|
---|
1401 | FALSE,
|
---|
1402 | EADDRNOTAVAIL,
|
---|
1403 | NULL, // Accept
|
---|
1404 | NULL, // ConnectPoll
|
---|
1405 | NULL, // ConnectStart
|
---|
1406 | EslIp4SocketIsConfigured,
|
---|
1407 | EslIp4LocalAddressGet,
|
---|
1408 | EslIp4LocalAddressSet,
|
---|
1409 | NULL, // Listen
|
---|
1410 | EslIp4OptionGet,
|
---|
1411 | EslIp4OptionSet,
|
---|
1412 | EslIp4PacketFree,
|
---|
1413 | EslIp4PortAllocate,
|
---|
1414 | NULL, // PortClose
|
---|
1415 | NULL, // PortCloseOp
|
---|
1416 | TRUE,
|
---|
1417 | EslIp4Receive,
|
---|
1418 | EslIp4RemoteAddressGet,
|
---|
1419 | EslIp4RemoteAddressSet,
|
---|
1420 | EslIp4RxComplete,
|
---|
1421 | NULL, // RxStart
|
---|
1422 | EslIp4TxBuffer,
|
---|
1423 | EslIp4TxComplete,
|
---|
1424 | NULL, // TxOobComplete
|
---|
1425 | (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslIp4VerifyLocalIpAddress
|
---|
1426 | };
|
---|