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