]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Impl.h
CommitLineData
83cbd279 1/** @file\r
d1102dba 2\r
dab714aa 3 Mtftp4 Implementation.\r
d1102dba 4\r
dab714aa 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
6c047cfa 11 RFC7440 - TFTP Windowsize Option\r
d1102dba 12\r
0e2a5749 13Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 14SPDX-License-Identifier: BSD-2-Clause-Patent\r
83cbd279 15\r
83cbd279 16**/\r
17\r
dab714aa 18\r
83cbd279 19#ifndef __EFI_MTFTP4_IMPL_H__\r
20#define __EFI_MTFTP4_IMPL_H__\r
21\r
dab714aa 22#include <Uefi.h>\r
772db4bb 23\r
24#include <Protocol/Udp4.h>\r
25#include <Protocol/Mtftp4.h>\r
26\r
27#include <Library/DebugLib.h>\r
cfb1461b 28#include <Library/BaseMemoryLib.h>\r
29#include <Library/MemoryAllocationLib.h>\r
772db4bb 30#include <Library/UefiBootServicesTableLib.h>\r
83cbd279 31#include <Library/UdpIoLib.h>\r
1f7eb561 32#include <Library/PrintLib.h>\r
dab714aa 33\r
34extern EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate;\r
83cbd279 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
dab714aa 43\r
44///\r
45/// Some constant value of Mtftp service.\r
46///\r
f6b7393c 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
6c047cfa 54#define MTFTP4_DEFAULT_WINDOWSIZE 1\r
f6b7393c 55#define MTFTP4_TIME_TO_GETMAP 5\r
56\r
57#define MTFTP4_STATE_UNCONFIGED 0\r
58#define MTFTP4_STATE_CONFIGED 1\r
75dce340 59#define MTFTP4_STATE_DESTROY 2\r
83cbd279 60\r
dab714aa 61///\r
62/// Mtftp service block\r
63///\r
83cbd279 64struct _MTFTP4_SERVICE {\r
65 UINT32 Signature;\r
66 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r
67\r
83cbd279 68 UINT16 ChildrenNum;\r
e48e37fc 69 LIST_ENTRY Children;\r
83cbd279 70\r
0e2a5749
FS
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
83cbd279 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
b45b45b2 82 UDP_IO *ConnectUdp;\r
83cbd279 83};\r
84\r
dab714aa 85\r
61066b8d 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
83cbd279 92struct _MTFTP4_PROTOCOL {\r
93 UINT32 Signature;\r
e48e37fc 94 LIST_ENTRY Link;\r
83cbd279 95 EFI_MTFTP4_PROTOCOL Mtftp4;\r
96\r
97 INTN State;\r
75dce340 98 BOOLEAN InDestroy;\r
83cbd279 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
e48e37fc 118 LIST_ENTRY Blocks;\r
83cbd279 119\r
6c047cfa
JW
120 UINT16 WindowSize;\r
121\r
122 //\r
9202304c 123 // Record the total received and saved block number.\r
6c047cfa
JW
124 //\r
125 UINT64 TotalBlock;\r
dbeaf585 126\r
9202304c
JW
127 //\r
128 // Record the acked block number.\r
129 //\r
6c047cfa
JW
130 UINT64 AckedBlock;\r
131\r
83cbd279 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
b45b45b2 140 UDP_IO *UnicastPort;\r
83cbd279 141\r
142 //\r
143 // Timeout and retransmit status\r
144 //\r
145 NET_BUF *LastPacket;\r
146 UINT32 PacketToLive;\r
0e2a5749 147 BOOLEAN HasTimeout;\r
83cbd279 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
b45b45b2 158 UDP_IO *McastUdpPort;\r
61066b8d 159};\r
36ee91ca 160\r
216f7970 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
dab714aa 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
83cbd279 174VOID\r
175Mtftp4CleanOperation (\r
dab714aa 176 IN OUT MTFTP4_PROTOCOL *Instance,\r
177 IN EFI_STATUS Result\r
83cbd279 178 );\r
179\r
dab714aa 180/**\r
181 Start the MTFTP session for upload.\r
d1102dba
LG
182\r
183 It will first init some states, then send the WRQ request packet,\r
dab714aa 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
83cbd279 194EFI_STATUS\r
195Mtftp4WrqStart (\r
dab714aa 196 IN MTFTP4_PROTOCOL *Instance,\r
197 IN UINT16 Operation\r
83cbd279 198 );\r
199\r
dab714aa 200/**\r
d1102dba
LG
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
dab714aa 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
83cbd279 214EFI_STATUS\r
215Mtftp4RrqStart (\r
dab714aa 216 IN MTFTP4_PROTOCOL *Instance,\r
217 IN UINT16 Operation\r
83cbd279 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
83cbd279 226#endif\r