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