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