1 /** @file
2   iSCSI Tcp4 IO related definitions.
3 
4 Copyright (c) 2004 - 2008, 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
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 #ifndef _ISCSI_TCP4_IO_H_
16 #define _ISCSI_TCP4_IO_H_
17 
18 #include <Library/NetLib.h>
19 #include <Protocol/Tcp4.h>
20 
21 typedef struct _TCP4_IO_CONFIG_DATA {
22   EFI_IPv4_ADDRESS  LocalIp;
23   EFI_IPv4_ADDRESS  SubnetMask;
24   EFI_IPv4_ADDRESS  Gateway;
25 
26   EFI_IPv4_ADDRESS  RemoteIp;
27   UINT16            RemotePort;
28 } TCP4_IO_CONFIG_DATA;
29 
30 typedef struct _TCP4_IO {
31   EFI_HANDLE                Image;
32   EFI_HANDLE                Controller;
33 
34   EFI_HANDLE                Handle;
35   EFI_TCP4_PROTOCOL         *Tcp4;
36 
37   EFI_TCP4_CONNECTION_TOKEN ConnToken;
38   EFI_TCP4_IO_TOKEN         TxToken;
39   EFI_TCP4_IO_TOKEN         RxToken;
40   EFI_TCP4_CLOSE_TOKEN      CloseToken;
41 
42   BOOLEAN                   IsConnDone;
43   BOOLEAN                   IsTxDone;
44   BOOLEAN                   IsRxDone;
45   BOOLEAN                   IsCloseDone;
46 } TCP4_IO;
47 
48 /**
49   Create a TCP socket with the specified configuration data.
50 
51   @param[in]  Image      The handle of the driver image.
52   @param[in]  Controller The handle of the controller.
53   @param[in]  ConfigData The Tcp4 configuration data.
54   @param[in]  Tcp4Io     The Tcp4Io.
55 
56   @retval EFI_SUCCESS    The TCP socket is created and configured.
57   @retval Others         Failed to create the TCP socket or configure it.
58 **/
59 EFI_STATUS
60 Tcp4IoCreateSocket (
61   IN EFI_HANDLE           Image,
62   IN EFI_HANDLE           Controller,
63   IN TCP4_IO_CONFIG_DATA  *ConfigData,
64   IN TCP4_IO              *Tcp4Io
65   );
66 
67 /**
68   Destroy the socket.
69 
70   @param[in]  Tcp4Io The Tcp4Io which wraps the socket to be destroyeds.
71 **/
72 VOID
73 Tcp4IoDestroySocket (
74   IN TCP4_IO  *Tcp4Io
75   );
76 
77 /**
78   Connect to the other endpoint of the TCP socket.
79 
80   @param[in, out]  Tcp4Io    The Tcp4Io wrapping the TCP socket.
81   @param[in]       Timeout   The time to wait for connection done.
82 
83   @retval EFI_SUCCESS          Connect to the other endpoint of the TCP socket successfully.
84   @retval EFI_TIMEOUT          Failed to connect to the other endpoint of the TCP socket in the                               specified time period.
85   @retval Others               Other errors as indicated.
86 **/
87 EFI_STATUS
88 Tcp4IoConnect (
89   IN OUT TCP4_IO    *Tcp4Io,
90   IN EFI_EVENT      Timeout
91   );
92 
93 /**
94   Reset the socket.
95 
96   @param[in, out]  Tcp4Io The Tcp4Io wrapping the TCP socket.
97 **/
98 VOID
99 Tcp4IoReset (
100   IN OUT TCP4_IO  *Tcp4Io
101   );
102 
103 /**
104   Transmit the Packet to the other endpoint of the socket.
105 
106   @param[in]   Tcp4Io          The Tcp4Io wrapping the TCP socket.
107   @param[in]   Packet          The packet to transmit.
108 
109   @retval EFI_SUCCESS          The packet is trasmitted.
110   @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
111   @retval Others               Other errors as indicated.
112 **/
113 EFI_STATUS
114 Tcp4IoTransmit (
115   IN TCP4_IO  *Tcp4Io,
116   IN NET_BUF  *Packet
117   );
118 
119 /**
120   Receive data from the socket.
121 
122   @param[in]  Tcp4Io           The Tcp4Io which wraps the socket to be destroyed.
123   @param[in]  Packet           The buffer to hold the data copy from the soket rx buffer.
124   @param[in]  AsyncMode        Is this receive asyncronous or not.
125   @param[in]  Timeout          The time to wait for receiving the amount of data the Packet
126                                can hold.
127 
128   @retval EFI_SUCCESS          The required amount of data is received from the socket.
129   @retval EFI_OUT_OF_RESOURCES Failed to allocate momery.
130   @retval EFI_TIMEOUT          Failed to receive the required amount of data in the
131                                specified time period.
132   @retval Others               Other errors as indicated.
133 **/
134 EFI_STATUS
135 Tcp4IoReceive (
136   IN TCP4_IO    *Tcp4Io,
137   IN NET_BUF    *Packet,
138   IN BOOLEAN    AsyncMode,
139   IN EFI_EVENT  Timeout
140   );
141 
142 #endif
143