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