]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Io.c
1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Io.c
1 /** @file
2
3 Copyright (c) 2005 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 Tcp4Io.c
15
16 Abstract:
17
18 I/O interfaces between TCP and IpIo.
19
20
21 **/
22
23
24 #include "Tcp4Main.h"
25
26
27 /**
28 Packet receive callback function provided to IP_IO, used to call
29 the proper function to handle the packet received by IP.
30
31 @param Status Status of the received packet.
32 @param IcmpErr ICMP error number.
33 @param NetSession Pointer to the net session of this packet.
34 @param Pkt Pointer to the recieved packet.
35 @param Context Pointer to the context configured in IpIoOpen(), not used
36 now.
37
38 @return None
39
40 **/
41 VOID
42 Tcp4RxCallback (
43 IN EFI_STATUS Status,
44 IN ICMP_ERROR IcmpErr,
45 IN EFI_NET_SESSION_DATA *NetSession,
46 IN NET_BUF *Pkt,
47 IN VOID *Context OPTIONAL
48 )
49 {
50 if (EFI_SUCCESS == Status) {
51 TcpInput (Pkt, NetSession->Source, NetSession->Dest);
52 } else {
53 TcpIcmpInput (Pkt, IcmpErr, NetSession->Source, NetSession->Dest);
54 }
55 }
56
57
58 /**
59 Send the segment to IP via IpIo function.
60
61 @param Tcb Pointer to the TCP_CB of this TCP instance.
62 @param Nbuf Pointer to the TCP segment to be sent.
63 @param Src Source address of the TCP segment.
64 @param Dest Destination address of the TCP segment.
65
66 @retval 0 The segment was sent out successfully.
67 @retval -1 The segment was failed to send.
68
69 **/
70 INTN
71 TcpSendIpPacket (
72 IN TCP_CB *Tcb,
73 IN NET_BUF *Nbuf,
74 IN UINT32 Src,
75 IN UINT32 Dest
76 )
77 {
78 EFI_STATUS Status;
79 IP_IO *IpIo;
80 IP_IO_OVERRIDE Override;
81 SOCKET *Sock;
82 VOID *IpSender;
83 TCP4_PROTO_DATA *TcpProto;
84
85 if (NULL == Tcb) {
86
87 IpIo = NULL;
88 IpSender = IpIoFindSender (&IpIo, Src);
89
90 if (IpSender == NULL) {
91 TCP4_DEBUG_WARN (("TcpSendIpPacket: No appropriate IpSender.\n"));
92 return -1;
93 }
94 } else {
95
96 Sock = Tcb->Sk;
97 TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
98 IpIo = TcpProto->TcpService->IpIo;
99 IpSender = Tcb->IpInfo;
100 }
101
102 Override.TypeOfService = 0;
103 Override.TimeToLive = 255;
104 Override.DoNotFragment = FALSE;
105 Override.Protocol = EFI_IP_PROTO_TCP;
106 NetZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
107 NetCopyMem (&Override.SourceAddress, &Src, sizeof (EFI_IPv4_ADDRESS));
108
109 Status = IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, Dest, &Override);
110
111 if (EFI_ERROR (Status)) {
112 TCP4_DEBUG_ERROR (("TcpSendIpPacket: return %r error\n", Status));
113 return -1;
114 }
115
116 return 0;
117 }