]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h
MdeModulePke/Mtftp4Dxe: Support windowsize in read request operation.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Impl.h
1 /** @file
2
3 Mtftp4 Implementation.
4
5 Mtftp4 Implementation, it supports the following RFCs:
6 RFC1350 - THE TFTP PROTOCOL (REVISION 2)
7 RFC2090 - TFTP Multicast Option
8 RFC2347 - TFTP Option Extension
9 RFC2348 - TFTP Blocksize Option
10 RFC2349 - TFTP Timeout Interval and Transfer Size Options
11 RFC7440 - TFTP Windowsize Option
12
13 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
14 This program and the accompanying materials
15 are licensed and made available under the terms and conditions of the BSD License
16 which accompanies this distribution. The full text of the license may be found at
17 http://opensource.org/licenses/bsd-license.php<BR>
18
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21
22 **/
23
24
25 #ifndef __EFI_MTFTP4_IMPL_H__
26 #define __EFI_MTFTP4_IMPL_H__
27
28 #include <Uefi.h>
29
30 #include <Protocol/Udp4.h>
31 #include <Protocol/Mtftp4.h>
32
33 #include <Library/DebugLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UdpIoLib.h>
38 #include <Library/PrintLib.h>
39
40 extern EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate;
41
42 typedef struct _MTFTP4_SERVICE MTFTP4_SERVICE;
43 typedef struct _MTFTP4_PROTOCOL MTFTP4_PROTOCOL;
44
45 #include "Mtftp4Driver.h"
46 #include "Mtftp4Option.h"
47 #include "Mtftp4Support.h"
48
49
50 ///
51 /// Some constant value of Mtftp service.
52 ///
53 #define MTFTP4_SERVICE_SIGNATURE SIGNATURE_32 ('T', 'F', 'T', 'P')
54 #define MTFTP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('t', 'f', 't', 'p')
55
56 #define MTFTP4_DEFAULT_SERVER_PORT 69
57 #define MTFTP4_DEFAULT_TIMEOUT 3
58 #define MTFTP4_DEFAULT_RETRY 5
59 #define MTFTP4_DEFAULT_BLKSIZE 512
60 #define MTFTP4_DEFAULT_WINDOWSIZE 1
61 #define MTFTP4_TIME_TO_GETMAP 5
62
63 #define MTFTP4_STATE_UNCONFIGED 0
64 #define MTFTP4_STATE_CONFIGED 1
65 #define MTFTP4_STATE_DESTROY 2
66
67 ///
68 /// Mtftp service block
69 ///
70 struct _MTFTP4_SERVICE {
71 UINT32 Signature;
72 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
73
74 UINT16 ChildrenNum;
75 LIST_ENTRY Children;
76
77 EFI_EVENT Timer; ///< Ticking timer for all the MTFTP clients to handle the packet timeout case.
78 EFI_EVENT TimerNotifyLevel; ///< Ticking timer for all the MTFTP clients to calculate the packet live time.
79 EFI_EVENT TimerToGetMap;
80
81 EFI_HANDLE Controller;
82 EFI_HANDLE Image;
83
84 //
85 // This UDP child is used to keep the connection between the UDP
86 // and MTFTP, so MTFTP will be notified when UDP is uninstalled.
87 //
88 UDP_IO *ConnectUdp;
89 };
90
91
92 typedef struct {
93 EFI_MTFTP4_PACKET **Packet;
94 UINT32 *PacketLen;
95 EFI_STATUS Status;
96 } MTFTP4_GETINFO_STATE;
97
98 struct _MTFTP4_PROTOCOL {
99 UINT32 Signature;
100 LIST_ENTRY Link;
101 EFI_MTFTP4_PROTOCOL Mtftp4;
102
103 INTN State;
104 BOOLEAN InDestroy;
105
106 MTFTP4_SERVICE *Service;
107 EFI_HANDLE Handle;
108
109 EFI_MTFTP4_CONFIG_DATA Config;
110
111 //
112 // Operation parameters: token and requested options.
113 //
114 EFI_MTFTP4_TOKEN *Token;
115 MTFTP4_OPTION RequestOption;
116 UINT16 Operation;
117
118 //
119 // Blocks is a list of MTFTP4_BLOCK_RANGE which contains
120 // holes in the file
121 //
122 UINT16 BlkSize;
123 UINT16 LastBlock;
124 LIST_ENTRY Blocks;
125
126 UINT16 WindowSize;
127
128 //
129 // Record the total received block number and the already acked block number.
130 //
131 UINT64 TotalBlock;
132 UINT64 AckedBlock;
133
134 //
135 // The server's communication end point: IP and two ports. one for
136 // initial request, one for its selected port.
137 //
138 IP4_ADDR ServerIp;
139 UINT16 ListeningPort;
140 UINT16 ConnectedPort;
141 IP4_ADDR Gateway;
142 UDP_IO *UnicastPort;
143
144 //
145 // Timeout and retransmit status
146 //
147 NET_BUF *LastPacket;
148 UINT32 PacketToLive;
149 BOOLEAN HasTimeout;
150 UINT32 CurRetry;
151 UINT32 MaxRetry;
152 UINT32 Timeout;
153
154 //
155 // Parameter used by RRQ's multicast download.
156 //
157 IP4_ADDR McastIp;
158 UINT16 McastPort;
159 BOOLEAN Master;
160 UDP_IO *McastUdpPort;
161 };
162
163 typedef struct {
164 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
165 UINTN NumberOfChildren;
166 EFI_HANDLE *ChildHandleBuffer;
167 } MTFTP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
168
169 /**
170 Clean up the MTFTP session to get ready for new operation.
171
172 @param Instance The MTFTP session to clean up
173 @param Result The result to return to the caller who initiated
174 the operation.
175 **/
176 VOID
177 Mtftp4CleanOperation (
178 IN OUT MTFTP4_PROTOCOL *Instance,
179 IN EFI_STATUS Result
180 );
181
182 /**
183 Start the MTFTP session for upload.
184
185 It will first init some states, then send the WRQ request packet,
186 and start receiving the packet.
187
188 @param Instance The MTFTP session
189 @param Operation Redundant parameter, which is always
190 EFI_MTFTP4_OPCODE_WRQ here.
191
192 @retval EFI_SUCCESS The upload process has been started.
193 @retval Others Failed to start the upload.
194
195 **/
196 EFI_STATUS
197 Mtftp4WrqStart (
198 IN MTFTP4_PROTOCOL *Instance,
199 IN UINT16 Operation
200 );
201
202 /**
203 Start the MTFTP session to download.
204
205 It will first initialize some of the internal states then build and send a RRQ
206 reqeuest packet, at last, it will start receive for the downloading.
207
208 @param Instance The Mtftp session
209 @param Operation The MTFTP opcode, it may be a EFI_MTFTP4_OPCODE_RRQ
210 or EFI_MTFTP4_OPCODE_DIR.
211
212 @retval EFI_SUCCESS The mtftp download session is started.
213 @retval Others Failed to start downloading.
214
215 **/
216 EFI_STATUS
217 Mtftp4RrqStart (
218 IN MTFTP4_PROTOCOL *Instance,
219 IN UINT16 Operation
220 );
221
222 #define MTFTP4_SERVICE_FROM_THIS(a) \
223 CR (a, MTFTP4_SERVICE, ServiceBinding, MTFTP4_SERVICE_SIGNATURE)
224
225 #define MTFTP4_PROTOCOL_FROM_THIS(a) \
226 CR (a, MTFTP4_PROTOCOL, Mtftp4, MTFTP4_PROTOCOL_SIGNATURE)
227
228 #endif