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