TianoCore EDK2 master
Loading...
Searching...
No Matches
Mtftp6Impl.c
Go to the documentation of this file.
1
17#include "Mtftp6Impl.h"
18
19EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate = {
28};
29
46EFIAPI
50 )
51{
52 MTFTP6_INSTANCE *Instance;
53 EFI_TPL OldTpl;
54
55 if ((This == NULL) || (ModeData == NULL)) {
56 return EFI_INVALID_PARAMETER;
57 }
58
59 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
60 Instance = MTFTP6_INSTANCE_FROM_THIS (This);
61
62 //
63 // Copy back the configure data if the instance already configured.
64 //
65 if (Instance->Config != NULL) {
66 CopyMem (
67 &ModeData->ConfigData,
68 Instance->Config,
70 );
71 } else {
72 ZeroMem (
73 &ModeData->ConfigData,
75 );
76 }
77
78 //
79 // Set the current support options in mode data.
80 //
81 ModeData->SupportedOptionCount = MTFTP6_SUPPORTED_OPTIONS_NUM;
82 ModeData->SupportedOptions = (UINT8 **)mMtftp6SupportedOptions;
83
84 gBS->RestoreTPL (OldTpl);
85
86 return EFI_SUCCESS;
87}
88
128EFIAPI
131 IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL
132 )
133{
134 MTFTP6_SERVICE *Service;
135 MTFTP6_INSTANCE *Instance;
136 EFI_UDP6_PROTOCOL *Udp6;
137 EFI_UDP6_CONFIG_DATA Udp6Cfg;
138 EFI_STATUS Status;
139 EFI_TPL OldTpl;
140
141 if (This == NULL) {
142 return EFI_INVALID_PARAMETER;
143 }
144
145 if ((MtftpConfigData != NULL) && !NetIp6IsValidUnicast (&MtftpConfigData->ServerIp)) {
146 return EFI_INVALID_PARAMETER;
147 }
148
149 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
150 Instance = MTFTP6_INSTANCE_FROM_THIS (This);
151 Service = Instance->Service;
152 Status = EFI_SUCCESS;
153
154 if (MtftpConfigData == NULL) {
155 //
156 // Configure the instance as NULL to abort the current session.
157 //
158 Mtftp6OperationClean (Instance, EFI_ABORTED);
159 FreePool (Instance->Config);
160 Instance->Config = NULL;
161 } else {
162 //
163 // It's not allowed to configure one instance twice without configure null.
164 //
165 if (Instance->Config != NULL) {
166 Status = EFI_ACCESS_DENIED;
167 goto ON_EXIT;
168 }
169
170 //
171 // Allocate the configure buffer of the instance and store the user's data.
172 //
173 Instance->Config = AllocateZeroPool (sizeof (EFI_MTFTP6_CONFIG_DATA));
174
175 if (Instance->Config == NULL) {
176 Status = EFI_OUT_OF_RESOURCES;
177 goto ON_EXIT;
178 }
179
180 CopyMem (Instance->Config, MtftpConfigData, sizeof (EFI_MTFTP6_CONFIG_DATA));
181
182 //
183 // Don't configure the udpio here because each operation might override
184 // the configuration, so delay udpio configuration in each operation.
185 //
186 if (Instance->UdpIo == NULL) {
187 Instance->UdpIo = UdpIoCreateIo (
188 Service->Controller,
189 Service->Image,
191 UDP_IO_UDP6_VERSION,
192 NULL
193 );
194 if (Instance->UdpIo != NULL) {
195 Status = gBS->OpenProtocol (
196 Instance->UdpIo->UdpHandle,
197 &gEfiUdp6ProtocolGuid,
198 (VOID **)&Udp6,
199 Service->Image,
200 Instance->Handle,
201 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
202 );
203 if (EFI_ERROR (Status)) {
204 goto ON_EXIT;
205 }
206 }
207 }
208
209 if (Instance->UdpIo == NULL) {
210 Status = EFI_OUT_OF_RESOURCES;
211 goto ON_EXIT;
212 }
213
214 //
215 // Continue to configure the downside Udp6 instance by user's data.
216 //
217 ZeroMem (&Udp6Cfg, sizeof (EFI_UDP6_CONFIG_DATA));
218
219 Udp6Cfg.AcceptPromiscuous = FALSE;
220 Udp6Cfg.AcceptAnyPort = FALSE;
221 Udp6Cfg.AllowDuplicatePort = FALSE;
222 Udp6Cfg.TrafficClass = 0;
223 Udp6Cfg.HopLimit = 128;
224 Udp6Cfg.ReceiveTimeout = 0;
225 Udp6Cfg.TransmitTimeout = 0;
226 Udp6Cfg.StationPort = Instance->Config->LocalPort;
227 Udp6Cfg.RemotePort = Instance->Config->InitialServerPort;
228
229 CopyMem (
230 &Udp6Cfg.StationAddress,
231 &Instance->Config->StationIp,
232 sizeof (EFI_IPv6_ADDRESS)
233 );
234
235 CopyMem (
236 &Udp6Cfg.RemoteAddress,
237 &Instance->Config->ServerIp,
238 sizeof (EFI_IPv6_ADDRESS)
239 );
240
241 Udp6 = Instance->UdpIo->Protocol.Udp6;
242 Status = Udp6->Configure (Udp6, &Udp6Cfg);
243
244 if (EFI_ERROR (Status)) {
245 goto ON_EXIT;
246 }
247 }
248
249ON_EXIT:
250 if (EFI_ERROR (Status)) {
251 if (Instance->Config != NULL) {
252 FreePool (Instance->Config);
253 Instance->Config = NULL;
254 }
255
256 if (Instance->UdpIo != NULL) {
257 UdpIoFreeIo (Instance->UdpIo);
258 Instance->UdpIo = NULL;
259 }
260 }
261
262 gBS->RestoreTPL (OldTpl);
263 return Status;
264}
265
321EFIAPI
324 IN EFI_MTFTP6_OVERRIDE_DATA *OverrideData OPTIONAL,
325 IN UINT8 *Filename,
326 IN UINT8 *ModeStr OPTIONAL,
327 IN UINT8 OptionCount,
328 IN EFI_MTFTP6_OPTION *OptionList OPTIONAL,
329 OUT UINT32 *PacketLength,
330 OUT EFI_MTFTP6_PACKET **Packet OPTIONAL
331 )
332{
333 EFI_STATUS Status;
334 EFI_MTFTP6_TOKEN Token;
336
337 if ((This == NULL) ||
338 (Filename == NULL) ||
339 (PacketLength == NULL) ||
340 ((OptionCount != 0) && (OptionList == NULL)) ||
341 ((OverrideData != NULL) && !NetIp6IsValidUnicast (&OverrideData->ServerIp))
342 )
343 {
344 return EFI_INVALID_PARAMETER;
345 }
346
347 if (Packet != NULL) {
348 *Packet = NULL;
349 }
350
351 *PacketLength = 0;
352
353 Context.Packet = Packet;
354 Context.PacketLen = PacketLength;
355 Context.Status = EFI_SUCCESS;
356
357 //
358 // Fill fields of the Token for GetInfo operation.
359 //
360 Token.Status = EFI_SUCCESS;
361 Token.Event = NULL;
362 Token.OverrideData = OverrideData;
363 Token.Filename = Filename;
364 Token.ModeStr = ModeStr;
365 Token.OptionCount = OptionCount;
366 Token.OptionList = OptionList;
367 Token.BufferSize = 0;
368 Token.Buffer = NULL;
369 Token.Context = &Context;
371 Token.TimeoutCallback = NULL;
372 Token.PacketNeeded = NULL;
373
374 //
375 // Start the GetInfo operation by issue the Token.
376 //
377 Status = Mtftp6OperationStart (This, &Token, EFI_MTFTP6_OPCODE_RRQ);
378
379 if (Status == EFI_ABORTED) {
380 //
381 // Return the status if failed to issue.
382 //
383 return Context.Status;
384 }
385
386 return Status;
387}
388
420EFIAPI
423 IN UINT32 PacketLen,
424 IN EFI_MTFTP6_PACKET *Packet,
425 OUT UINT32 *OptionCount,
426 OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
427 )
428{
429 if (This == NULL) {
430 return EFI_INVALID_PARAMETER;
431 }
432
433 return Mtftp6ParseStart (Packet, PacketLen, OptionCount, OptionList);
434}
435
478EFIAPI
481 IN EFI_MTFTP6_TOKEN *Token
482 )
483{
484 return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_RRQ);
485}
486
530EFIAPI
533 IN EFI_MTFTP6_TOKEN *Token
534 )
535{
536 return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_WRQ);
537}
538
580EFIAPI
583 IN EFI_MTFTP6_TOKEN *Token
584 )
585{
586 return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_DIR);
587}
588
614EFIAPI
617 )
618{
619 MTFTP6_INSTANCE *Instance;
620 EFI_UDP6_PROTOCOL *Udp6;
621
622 if (This == NULL) {
623 return EFI_INVALID_PARAMETER;
624 }
625
626 Instance = MTFTP6_INSTANCE_FROM_THIS (This);
627
628 //
629 // Check the instance whether configured or in destroy.
630 //
631 if (Instance->Config == NULL) {
632 return EFI_NOT_STARTED;
633 }
634
635 Udp6 = Instance->UdpIo->Protocol.Udp6;
636
637 return Udp6->Poll (Udp6);
638}
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define EFI_MTFTP6_OPCODE_WRQ
The MTFTPv6 packet is a write request.
Definition: Mtftp6.h:36
#define EFI_MTFTP6_OPCODE_RRQ
The MTFTPv6 packet is a read request.
Definition: Mtftp6.h:35
#define EFI_MTFTP6_OPCODE_DIR
The MTFTPv6 packet is a directory query packet.
Definition: Mtftp6.h:41
EFI_STATUS EFIAPI EfiMtftp6GetModeData(IN EFI_MTFTP6_PROTOCOL *This, OUT EFI_MTFTP6_MODE_DATA *ModeData)
Definition: Mtftp6Impl.c:47
EFI_STATUS EFIAPI EfiMtftp6WriteFile(IN EFI_MTFTP6_PROTOCOL *This, IN EFI_MTFTP6_TOKEN *Token)
Definition: Mtftp6Impl.c:531
EFI_STATUS EFIAPI EfiMtftp6GetInfo(IN EFI_MTFTP6_PROTOCOL *This, IN EFI_MTFTP6_OVERRIDE_DATA *OverrideData OPTIONAL, IN UINT8 *Filename, IN UINT8 *ModeStr OPTIONAL, IN UINT8 OptionCount, IN EFI_MTFTP6_OPTION *OptionList OPTIONAL, OUT UINT32 *PacketLength, OUT EFI_MTFTP6_PACKET **Packet OPTIONAL)
Definition: Mtftp6Impl.c:322
EFI_STATUS EFIAPI EfiMtftp6ReadDirectory(IN EFI_MTFTP6_PROTOCOL *This, IN EFI_MTFTP6_TOKEN *Token)
Definition: Mtftp6Impl.c:581
EFI_STATUS EFIAPI EfiMtftp6Configure(IN EFI_MTFTP6_PROTOCOL *This, IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL)
Definition: Mtftp6Impl.c:129
EFI_STATUS EFIAPI EfiMtftp6ParseOptions(IN EFI_MTFTP6_PROTOCOL *This, IN UINT32 PacketLen, IN EFI_MTFTP6_PACKET *Packet, OUT UINT32 *OptionCount, OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL)
Definition: Mtftp6Impl.c:421
EFI_STATUS EFIAPI EfiMtftp6Poll(IN EFI_MTFTP6_PROTOCOL *This)
Definition: Mtftp6Impl.c:615
EFI_STATUS EFIAPI EfiMtftp6ReadFile(IN EFI_MTFTP6_PROTOCOL *This, IN EFI_MTFTP6_TOKEN *Token)
Definition: Mtftp6Impl.c:479
EFI_STATUS Mtftp6ParseStart(IN EFI_MTFTP6_PACKET *Packet, IN UINT32 PacketLen, IN OUT UINT32 *OptionCount, OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL)
Definition: Mtftp6Option.c:340
EFI_STATUS EFIAPI Mtftp6CheckPacket(IN EFI_MTFTP6_PROTOCOL *This, IN EFI_MTFTP6_TOKEN *Token, IN UINT16 PacketLen, IN EFI_MTFTP6_PACKET *Packet)
EFI_STATUS EFIAPI Mtftp6ConfigDummyUdpIo(IN UDP_IO *UdpIo, IN VOID *Context)
EFI_STATUS Mtftp6OperationStart(IN EFI_MTFTP6_PROTOCOL *This, IN EFI_MTFTP6_TOKEN *Token, IN UINT16 OpCode)
VOID Mtftp6OperationClean(IN MTFTP6_INSTANCE *Instance, IN EFI_STATUS Result)
BOOLEAN EFIAPI NetIp6IsValidUnicast(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:725
EFI_STATUS EFIAPI UdpIoFreeIo(IN UDP_IO *UdpIo)
Definition: DxeUdpIoLib.c:809
UDP_IO *EFIAPI UdpIoCreateIo(IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle, IN UDP_IO_CONFIG Configure, IN UINT8 UdpVersion, IN VOID *Context)
Definition: DxeUdpIoLib.c:602
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
UINT8 * ModeStr
Definition: Mtftp6.h:413
UINT64 BufferSize
Definition: Mtftp6.h:430
EFI_MTFTP6_PACKET_NEEDED PacketNeeded
Definition: Mtftp6.h:455
VOID * Context
Definition: Mtftp6.h:441
EFI_MTFTP6_TIMEOUT_CALLBACK TimeoutCallback
Definition: Mtftp6.h:450
EFI_MTFTP6_OPTION * OptionList
Definition: Mtftp6.h:425
EFI_MTFTP6_OVERRIDE_DATA * OverrideData
Definition: Mtftp6.h:405
VOID * Buffer
Definition: Mtftp6.h:436
UINT8 * Filename
Definition: Mtftp6.h:409
EFI_MTFTP6_CHECK_PACKET CheckPacket
Definition: Mtftp6.h:446
EFI_STATUS Status
Definition: Mtftp6.h:394
EFI_EVENT Event
Definition: Mtftp6.h:400
UINT32 OptionCount
Definition: Mtftp6.h:417
UINT16 InitialServerPort
Definition: Mtftp6.h:239
EFI_IPv6_ADDRESS StationIp
Definition: Mtftp6.h:226
EFI_IPv6_ADDRESS ServerIp
Definition: Mtftp6.h:234
UINT16 StationPort
Definition: Udp6.h:168
BOOLEAN AcceptAnyPort
Definition: Udp6.h:126
UINT16 RemotePort
Definition: Udp6.h:182
BOOLEAN AcceptPromiscuous
Definition: Udp6.h:122
BOOLEAN AllowDuplicatePort
Definition: Udp6.h:131
EFI_IPv6_ADDRESS RemoteAddress
Definition: Udp6.h:175
UINT32 ReceiveTimeout
Definition: Udp6.h:144
UINT32 TransmitTimeout
Definition: Udp6.h:149
UINT8 TrafficClass
Definition: Udp6.h:135
EFI_IPv6_ADDRESS StationAddress
Definition: Udp6.h:161