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