]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Io.c
3adf356e0b9e4ebf31ecde7617ebcd9d5b5dd1c2
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Io.c
1 /** @file
2 I/O interfaces between TCP and IpIo.
3
4 Copyright (c) 2005 - 2009, Intel Corporation<BR>
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<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 Tcp4RxCallback (
32 IN EFI_STATUS Status,
33 IN UINT8 IcmpErr,
34 IN EFI_NET_SESSION_DATA *NetSession,
35 IN NET_BUF *Pkt,
36 IN VOID *Context OPTIONAL
37 )
38 {
39 if (EFI_SUCCESS == Status) {
40 TcpInput (Pkt, NetSession->Source.Addr[0], NetSession->Dest.Addr[0]);
41 } else {
42 TcpIcmpInput (Pkt, IcmpErr, NetSession->Source.Addr[0], NetSession->Dest.Addr[0]);
43 }
44 }
45
46
47 /**
48 Send the segment to IP via IpIo function.
49
50 @param Tcb Pointer to the TCP_CB of this TCP instance.
51 @param Nbuf Pointer to the TCP segment to be sent.
52 @param Src Source address of the TCP segment.
53 @param Dest Destination address of the TCP segment.
54
55 @retval 0 The segment was sent out successfully.
56 @retval -1 The segment was failed to send.
57
58 **/
59 INTN
60 TcpSendIpPacket (
61 IN TCP_CB *Tcb,
62 IN NET_BUF *Nbuf,
63 IN UINT32 Src,
64 IN UINT32 Dest
65 )
66 {
67 EFI_STATUS Status;
68 IP_IO *IpIo;
69 IP_IO_OVERRIDE Override;
70 SOCKET *Sock;
71 VOID *IpSender;
72 TCP4_PROTO_DATA *TcpProto;
73 EFI_IP_ADDRESS Source;
74 EFI_IP_ADDRESS Destination;
75
76 Source.Addr[0] = Src;
77 Destination.Addr[0] = Dest;
78
79 if (NULL == Tcb) {
80
81 IpIo = NULL;
82 IpSender = IpIoFindSender (&IpIo, IP_VERSION_4, &Source);
83
84 if (IpSender == NULL) {
85 DEBUG ((EFI_D_WARN, "TcpSendIpPacket: No appropriate IpSender.\n"));
86 return -1;
87 }
88 } else {
89
90 Sock = Tcb->Sk;
91 TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
92 IpIo = TcpProto->TcpService->IpIo;
93 IpSender = Tcb->IpInfo;
94 }
95
96 Override.Ip4OverrideData.TypeOfService = 0;
97 Override.Ip4OverrideData.TimeToLive = 255;
98 Override.Ip4OverrideData.DoNotFragment = FALSE;
99 Override.Ip4OverrideData.Protocol = EFI_IP_PROTO_TCP;
100 ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
101 CopyMem (&Override.Ip4OverrideData.SourceAddress, &Src, sizeof (EFI_IPv4_ADDRESS));
102
103 Status = IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, &Destination, &Override);
104
105 if (EFI_ERROR (Status)) {
106 DEBUG ((EFI_D_ERROR, "TcpSendIpPacket: return %r error\n", Status));
107 return -1;
108 }
109
110 return 0;
111 }