1 /** @file
2 I/O interfaces between TCP and IpIo.
3
4 Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>
5 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<BR>
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 "Tcp4Main.h"
16
17
18 /**
19 Packet receive callback function provided to IP_IO, used to call
20 the proper function to handle the packet received by IP.
21
22 @param Status Status of the received packet.
23 @param IcmpErr ICMP error number.
24 @param NetSession Pointer to the net session of this packet.
25 @param Pkt Pointer to the recieved packet.
26 @param Context Pointer to the context configured in IpIoOpen(), not used
27 now.
28
29 **/
30 VOID
31 EFIAPI
Tcp4RxCallback(IN EFI_STATUS Status,IN UINT8 IcmpErr,IN EFI_NET_SESSION_DATA * NetSession,IN NET_BUF * Pkt,IN VOID * Context OPTIONAL)32 Tcp4RxCallback (
33 IN EFI_STATUS Status,
34 IN UINT8 IcmpErr,
35 IN EFI_NET_SESSION_DATA *NetSession,
36 IN NET_BUF *Pkt,
37 IN VOID *Context OPTIONAL
38 )
39 {
40 if (EFI_SUCCESS == Status) {
41 TcpInput (Pkt, NetSession->Source.Addr[0], NetSession->Dest.Addr[0]);
42 } else {
43 TcpIcmpInput (Pkt, IcmpErr, NetSession->Source.Addr[0], NetSession->Dest.Addr[0]);
44 }
45 }
46
47
48 /**
49 Send the segment to IP via IpIo function.
50
51 @param Tcb Pointer to the TCP_CB of this TCP instance.
52 @param Nbuf Pointer to the TCP segment to be sent.
53 @param Src Source address of the TCP segment.
54 @param Dest Destination address of the TCP segment.
55
56 @retval 0 The segment was sent out successfully.
57 @retval -1 The segment was failed to send.
58
59 **/
60 INTN
TcpSendIpPacket(IN TCP_CB * Tcb,IN NET_BUF * Nbuf,IN UINT32 Src,IN UINT32 Dest)61 TcpSendIpPacket (
62 IN TCP_CB *Tcb,
63 IN NET_BUF *Nbuf,
64 IN UINT32 Src,
65 IN UINT32 Dest
66 )
67 {
68 EFI_STATUS Status;
69 IP_IO *IpIo;
70 IP_IO_OVERRIDE Override;
71 SOCKET *Sock;
72 VOID *IpSender;
73 TCP4_PROTO_DATA *TcpProto;
74 EFI_IP_ADDRESS Source;
75 EFI_IP_ADDRESS Destination;
76
77 Source.Addr[0] = Src;
78 Destination.Addr[0] = Dest;
79
80 if (NULL == Tcb) {
81
82 IpIo = NULL;
83 IpSender = IpIoFindSender (&IpIo, IP_VERSION_4, &Source);
84
85 if (IpSender == NULL) {
86 DEBUG ((EFI_D_WARN, "TcpSendIpPacket: No appropriate IpSender.\n"));
87 return -1;
88 }
89 } else {
90
91 Sock = Tcb->Sk;
92 TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
93 IpIo = TcpProto->TcpService->IpIo;
94 IpSender = Tcb->IpInfo;
95 }
96
97 Override.Ip4OverrideData.TypeOfService = 0;
98 Override.Ip4OverrideData.TimeToLive = 255;
99 Override.Ip4OverrideData.DoNotFragment = FALSE;
100 Override.Ip4OverrideData.Protocol = EFI_IP_PROTO_TCP;
101 ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
102 CopyMem (&Override.Ip4OverrideData.SourceAddress, &Src, sizeof (EFI_IPv4_ADDRESS));
103
104 Status = IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, &Destination, &Override);
105
106 if (EFI_ERROR (Status)) {
107 DEBUG ((EFI_D_ERROR, "TcpSendIpPacket: return %r error\n", Status));
108 return -1;
109 }
110
111 return 0;
112 }
113