]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h
Update modules to show real dependencies on the BaseMemoryLib and MemoryAllocationLib
[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 - 2007, Intel Corporation<BR>
13 All rights reserved. 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 typedef enum {
52 MTFTP4_SERVICE_SIGNATURE = SIGNATURE_32 ('T', 'F', 'T', 'P'),
53 MTFTP4_PROTOCOL_SIGNATURE = SIGNATURE_32 ('t', 'f', 't', 'p'),
54
55 MTFTP4_DEFAULT_SERVER_PORT = 69,
56 MTFTP4_DEFAULT_TIMEOUT = 3,
57 MTFTP4_DEFAULT_RETRY = 5,
58 MTFTP4_DEFAULT_BLKSIZE = 512,
59 MTFTP4_TIME_TO_GETMAP = 5,
60
61 MTFTP4_STATE_UNCONFIGED = 0,
62 MTFTP4_STATE_CONFIGED,
63 MTFTP4_STATE_DESTORY
64 } MTFTP4_SERVICE_CONST_VALUE;
65
66 ///
67 /// Mtftp service block
68 ///
69 struct _MTFTP4_SERVICE {
70 UINT32 Signature;
71 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
72
73 BOOLEAN InDestory;
74
75 UINT16 ChildrenNum;
76 LIST_ENTRY Children;
77
78 EFI_EVENT Timer; ///< Ticking timer for all the MTFTP clients
79 EFI_EVENT TimerToGetMap;
80
81 EFI_HANDLE Controller;
82 EFI_HANDLE Image;
83
84 //
85 // This UDP child is used to keep the connection between the UDP
86 // and MTFTP, so MTFTP will be notified when UDP is uninstalled.
87 //
88 UDP_IO_PORT *ConnectUdp;
89 };
90
91
92 typedef struct {
93 EFI_MTFTP4_PACKET **Packet;
94 UINT32 *PacketLen;
95 EFI_STATUS Status;
96 } MTFTP4_GETINFO_STATE;
97
98 struct _MTFTP4_PROTOCOL {
99 UINT32 Signature;
100 LIST_ENTRY Link;
101 EFI_MTFTP4_PROTOCOL Mtftp4;
102
103 INTN State;
104 BOOLEAN InDestory;
105
106 MTFTP4_SERVICE *Service;
107 EFI_HANDLE Handle;
108
109 EFI_MTFTP4_CONFIG_DATA Config;
110
111 //
112 // Operation parameters: token and requested options.
113 //
114 EFI_MTFTP4_TOKEN *Token;
115 MTFTP4_OPTION RequestOption;
116 UINT16 Operation;
117
118 //
119 // Blocks is a list of MTFTP4_BLOCK_RANGE which contains
120 // holes in the file
121 //
122 UINT16 BlkSize;
123 UINT16 LastBlock;
124 LIST_ENTRY Blocks;
125
126 //
127 // The server's communication end point: IP and two ports. one for
128 // initial request, one for its selected port.
129 //
130 IP4_ADDR ServerIp;
131 UINT16 ListeningPort;
132 UINT16 ConnectedPort;
133 IP4_ADDR Gateway;
134 UDP_IO_PORT *UnicastPort;
135
136 //
137 // Timeout and retransmit status
138 //
139 NET_BUF *LastPacket;
140 UINT32 PacketToLive;
141 UINT32 CurRetry;
142 UINT32 MaxRetry;
143 UINT32 Timeout;
144
145 //
146 // Parameter used by RRQ's multicast download.
147 //
148 IP4_ADDR McastIp;
149 UINT16 McastPort;
150 BOOLEAN Master;
151 UDP_IO_PORT *McastUdpPort;
152
153 MTFTP4_GETINFO_STATE GetInfoState;
154 };
155
156 /**
157 Clean up the MTFTP session to get ready for new operation.
158
159 @param Instance The MTFTP session to clean up
160 @param Result The result to return to the caller who initiated
161 the operation.
162 **/
163 VOID
164 Mtftp4CleanOperation (
165 IN OUT MTFTP4_PROTOCOL *Instance,
166 IN EFI_STATUS Result
167 );
168
169 /**
170 Start the MTFTP session for upload.
171
172 It will first init some states, then send the WRQ request packet,
173 and start receiving the packet.
174
175 @param Instance The MTFTP session
176 @param Operation Redundant parameter, which is always
177 EFI_MTFTP4_OPCODE_WRQ here.
178
179 @retval EFI_SUCCESS The upload process has been started.
180 @retval Others Failed to start the upload.
181
182 **/
183 EFI_STATUS
184 Mtftp4WrqStart (
185 IN MTFTP4_PROTOCOL *Instance,
186 IN UINT16 Operation
187 );
188
189 /**
190 Start the MTFTP session to download.
191
192 It will first initialize some of the internal states then build and send a RRQ
193 reqeuest packet, at last, it will start receive for the downloading.
194
195 @param Instance The Mtftp session
196 @param Operation The MTFTP opcode, it may be a EFI_MTFTP4_OPCODE_RRQ
197 or EFI_MTFTP4_OPCODE_DIR.
198
199 @retval EFI_SUCCESS The mtftp download session is started.
200 @retval Others Failed to start downloading.
201
202 **/
203 EFI_STATUS
204 Mtftp4RrqStart (
205 IN MTFTP4_PROTOCOL *Instance,
206 IN UINT16 Operation
207 );
208
209 #define MTFTP4_SERVICE_FROM_THIS(a) \
210 CR (a, MTFTP4_SERVICE, ServiceBinding, MTFTP4_SERVICE_SIGNATURE)
211
212 #define MTFTP4_PROTOCOL_FROM_THIS(a) \
213 CR (a, MTFTP4_PROTOCOL, Mtftp4, MTFTP4_PROTOCOL_SIGNATURE)
214
215 #endif