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