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