33 Token = Instance->Token;
42 Instance->Token =
NULL;
45 ASSERT (Instance->UnicastPort !=
NULL);
48 if (Instance->LastPacket !=
NULL) {
50 Instance->LastPacket =
NULL;
53 if (Instance->McastUdpPort !=
NULL) {
55 Instance->McastUdpPort->UdpHandle,
56 &gEfiUdp4ProtocolGuid,
61 Instance->McastUdpPort =
NULL;
64 NET_LIST_FOR_EACH_SAFE (Entry, Next, &Instance->Blocks) {
72 Instance->Operation = 0;
74 Instance->BlkSize = MTFTP4_DEFAULT_BLKSIZE;
75 Instance->WindowSize = 1;
76 Instance->TotalBlock = 0;
77 Instance->AckedBlock = 0;
78 Instance->LastBlock = 0;
79 Instance->ServerIp = 0;
80 Instance->ListeningPort = 0;
81 Instance->ConnectedPort = 0;
82 Instance->Gateway = 0;
83 Instance->PacketToLive = 0;
84 Instance->MaxRetry = 0;
85 Instance->CurRetry = 0;
86 Instance->Timeout = 0;
87 Instance->McastIp = 0;
88 Instance->McastPort = 0;
89 Instance->Master =
TRUE;
121 OpCode = NTOHS (Packet->OpCode);
127 case EFI_MTFTP4_OPCODE_ERROR:
129 if (ErrorHeader->ErrorCode == EFI_MTFTP4_ERRORCODE_FILE_NOT_FOUND) {
130 DEBUG ((DEBUG_ERROR,
"TFTP error code 1 (File Not Found)\n"));
132 DEBUG ((DEBUG_ERROR,
"TFTP error code %d\n", ErrorHeader->ErrorCode));
135 State->Status = EFI_TFTP_ERROR;
138 case EFI_MTFTP4_OPCODE_OACK:
143 State->Status = EFI_PROTOCOL_ERROR;
152 if (EFI_ERROR (Status)) {
153 State->Status = EFI_OUT_OF_RESOURCES;
157 *(State->PacketLen) = PacketLen;
158 CopyMem (*(State->Packet), Packet, PacketLen);
188 CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR));
189 if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
193 Config = &Instance->Config;
195 CopyMem (&Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));
196 Gateway = NTOHL (Gateway);
198 if (!Config->UseDefaultSetting && (Gateway != 0)) {
199 CopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR));
200 CopyMem (&Ip, &Config->StationIp, sizeof (IP4_ADDR));
202 Netmask = NTOHL (Netmask);
205 if (((Netmask != 0) && !
NetIp4IsUnicast (Gateway, Netmask)) || !IP4_NET_EQUAL (Gateway, Ip, Netmask)) {
240 ASSERT (Instance->Config.UseDefaultSetting);
242 Service = Instance->Service;
243 Udp = UdpIo->Protocol.Udp4;
245 Status =
gBS->SetTimer (
246 Service->TimerToGetMap,
248 MTFTP4_TIME_TO_GETMAP * TICKS_PER_SECOND
250 if (EFI_ERROR (Status)) {
254 while (EFI_ERROR (
gBS->CheckEvent (Service->TimerToGetMap))) {
257 if (!EFI_ERROR (Udp->GetModeData (Udp,
NULL, &Ip4Mode,
NULL,
NULL)) &&
260 Udp->Configure (Udp,
NULL);
261 return (BOOLEAN)(Udp->Configure (Udp, UdpCfgData) ==
EFI_SUCCESS);
289 Config = &Instance->Config;
291 UdpConfig.AcceptBroadcast =
FALSE;
292 UdpConfig.AcceptPromiscuous =
FALSE;
293 UdpConfig.AcceptAnyPort =
FALSE;
294 UdpConfig.AllowDuplicatePort =
FALSE;
295 UdpConfig.TypeOfService = 0;
296 UdpConfig.TimeToLive = 64;
297 UdpConfig.DoNotFragment =
FALSE;
298 UdpConfig.ReceiveTimeout = 0;
299 UdpConfig.TransmitTimeout = 0;
300 UdpConfig.UseDefaultAddress = Config->UseDefaultSetting;
301 IP4_COPY_ADDRESS (&UdpConfig.StationAddress, &Config->StationIp);
302 IP4_COPY_ADDRESS (&UdpConfig.SubnetMask, &Config->SubnetMask);
303 UdpConfig.StationPort = Config->LocalPort;
304 UdpConfig.RemotePort = 0;
306 Ip = HTONL (Instance->ServerIp);
307 IP4_COPY_ADDRESS (&UdpConfig.RemoteAddress, &Ip);
309 Status = UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfig);
311 if ((Status == EFI_NO_MAPPING) &&
Mtftp4GetMapping (Instance, UdpIo, &UdpConfig)) {
315 if (!Config->UseDefaultSetting && !EFI_IP4_EQUAL (&mZeroIp4Addr, &Config->GatewayIp)) {
320 Status = UdpIo->Protocol.Udp4->Routes (
321 UdpIo->Protocol.Udp4,
327 if (EFI_ERROR (Status)) {
328 UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4,
NULL);
366 if ((This ==
NULL) || (Token ==
NULL) || (Token->Filename ==
NULL) ||
367 ((Token->OptionCount != 0) && (Token->OptionList ==
NULL)))
369 return EFI_INVALID_PARAMETER;
375 if (((Operation == EFI_MTFTP4_OPCODE_RRQ) || (Operation == EFI_MTFTP4_OPCODE_DIR)) &&
376 ((Token->Buffer ==
NULL) && (Token->CheckPacket ==
NULL)))
378 return EFI_INVALID_PARAMETER;
384 if ((Operation == EFI_MTFTP4_OPCODE_WRQ) &&
385 ((Token->Buffer ==
NULL) && (Token->PacketNeeded ==
NULL)))
387 return EFI_INVALID_PARAMETER;
390 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);
395 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
397 if (Instance->State != MTFTP4_STATE_CONFIGED) {
398 Status = EFI_NOT_STARTED;
401 if (Instance->Operation != 0) {
402 Status = EFI_ACCESS_DENIED;
406 Status = EFI_INVALID_PARAMETER;
409 if (EFI_ERROR (Status)) {
410 gBS->RestoreTPL (OldTpl);
418 Instance->Operation = Operation;
419 Override = Token->OverrideData;
421 if (Token->OptionCount != 0) {
427 &Instance->RequestOption
430 if (EFI_ERROR (Status)) {
431 TokenStatus = EFI_DEVICE_ERROR;
439 Config = &Instance->Config;
440 Instance->Token = Token;
441 Instance->BlkSize = MTFTP4_DEFAULT_BLKSIZE;
442 Instance->WindowSize = MTFTP4_DEFAULT_WINDOWSIZE;
444 CopyMem (&Instance->ServerIp, &Config->ServerIp, sizeof (IP4_ADDR));
445 Instance->ServerIp = NTOHL (Instance->ServerIp);
447 Instance->ListeningPort = Config->InitialServerPort;
448 Instance->ConnectedPort = 0;
450 CopyMem (&Instance->Gateway, &Config->GatewayIp, sizeof (IP4_ADDR));
451 Instance->Gateway = NTOHL (Instance->Gateway);
453 Instance->MaxRetry = Config->TryCount;
454 Instance->Timeout = Config->TimeoutValue;
455 Instance->Master =
TRUE;
457 if (Override !=
NULL) {
458 CopyMem (&Instance->ServerIp, &Override->ServerIp, sizeof (IP4_ADDR));
459 CopyMem (&Instance->Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));
461 Instance->ServerIp = NTOHL (Instance->ServerIp);
462 Instance->Gateway = NTOHL (Instance->Gateway);
464 Instance->ListeningPort = Override->ServerPort;
465 Instance->MaxRetry = Override->TryCount;
466 Instance->Timeout = Override->TimeoutValue;
469 if (Instance->ListeningPort == 0) {
470 Instance->ListeningPort = MTFTP4_DEFAULT_SERVER_PORT;
473 if (Instance->MaxRetry == 0) {
474 Instance->MaxRetry = MTFTP4_DEFAULT_RETRY;
477 if (Instance->Timeout == 0) {
478 Instance->Timeout = MTFTP4_DEFAULT_TIMEOUT;
485 if (EFI_ERROR (Status)) {
486 TokenStatus = EFI_DEVICE_ERROR;
493 Token->Status = EFI_NOT_READY;
498 if (Operation == EFI_MTFTP4_OPCODE_WRQ) {
504 if (EFI_ERROR (Status)) {
505 TokenStatus = EFI_DEVICE_ERROR;
509 gBS->RestoreTPL (OldTpl);
511 if (Token->Event !=
NULL) {
519 while (Token->Status == EFI_NOT_READY) {
523 return Token->Status;
527 gBS->RestoreTPL (OldTpl);
557 if ((This ==
NULL) || (ModeData ==
NULL)) {
558 return EFI_INVALID_PARAMETER;
561 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
563 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);
564 CopyMem (&ModeData->ConfigData, &Instance->Config, sizeof (Instance->Config));
565 ModeData->SupportedOptionCount = MTFTP4_SUPPORTED_OPTIONS;
566 ModeData->SupportedOptoins = (UINT8 **)mMtftp4SupportedOptions;
567 ModeData->UnsupportedOptionCount = 0;
568 ModeData->UnsupportedOptoins =
NULL;
570 gBS->RestoreTPL (OldTpl);
637 return EFI_INVALID_PARAMETER;
640 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);
642 if (ConfigData ==
NULL) {
646 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
650 Instance->State = MTFTP4_STATE_UNCONFIGED;
652 gBS->RestoreTPL (OldTpl);
657 CopyMem (&Ip, &ConfigData->StationIp, sizeof (IP4_ADDR));
658 CopyMem (&Netmask, &ConfigData->SubnetMask, sizeof (IP4_ADDR));
659 CopyMem (&Gateway, &ConfigData->GatewayIp, sizeof (IP4_ADDR));
660 CopyMem (&ServerIp, &ConfigData->ServerIp, sizeof (IP4_ADDR));
663 Netmask = NTOHL (Netmask);
664 Gateway = NTOHL (Gateway);
665 ServerIp = NTOHL (ServerIp);
667 if ((ServerIp == 0) || IP4_IS_LOCAL_BROADCAST (ServerIp)) {
668 return EFI_INVALID_PARAMETER;
671 if (!ConfigData->UseDefaultSetting &&
672 ((!IP4_IS_VALID_NETMASK (Netmask) || ((Netmask != 0) && !
NetIp4IsUnicast (Ip, Netmask)))))
674 return EFI_INVALID_PARAMETER;
677 if ((Gateway != 0) &&
678 (((Netmask != 0xFFFFFFFF) && !IP4_NET_EQUAL (Gateway, Ip, Netmask)) || ((Netmask != 0) && !
NetIp4IsUnicast (Gateway, Netmask))))
680 return EFI_INVALID_PARAMETER;
683 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
685 if ((Instance->State == MTFTP4_STATE_CONFIGED) && (Instance->Operation != 0)) {
686 gBS->RestoreTPL (OldTpl);
687 return EFI_ACCESS_DENIED;
690 CopyMem (&Instance->Config, ConfigData, sizeof (*ConfigData));
691 Instance->State = MTFTP4_STATE_CONFIGED;
693 gBS->RestoreTPL (OldTpl);
735 OUT UINT32 *OptionCount,
741 if ((This ==
NULL) || (PacketLen < MTFTP4_OPCODE_LEN) ||
742 (Packet ==
NULL) || (OptionCount ==
NULL))
744 return EFI_INVALID_PARAMETER;
749 if (EFI_ERROR (Status)) {
753 if (*OptionCount == 0) {
754 return EFI_NOT_FOUND;
797 return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_RRQ);
857 return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_WRQ);
926 return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_DIR);
989 IN UINT8 *ModeStr OPTIONAL,
990 IN UINT8 OptionCount,
992 OUT UINT32 *PacketLength,
1000 if ((This ==
NULL) || (Filename ==
NULL) || (PacketLength ==
NULL) ||
1001 ((OptionCount != 0) && (OptionList ==
NULL)))
1003 return EFI_INVALID_PARAMETER;
1006 if (Packet !=
NULL) {
1011 State.Packet = Packet;
1012 State.PacketLen = PacketLength;
1034 if (EFI_ABORTED == Status) {
1035 return State.Status;
1076 return EFI_INVALID_PARAMETER;
1079 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);
1081 if (Instance->State == MTFTP4_STATE_UNCONFIGED) {
1082 return EFI_NOT_STARTED;
1083 }
else if (Instance->State == MTFTP4_STATE_DESTROY) {
1084 return EFI_DEVICE_ERROR;
1087 Udp = Instance->UnicastPort->Protocol.Udp4;
1088 Status = Udp->Poll (Udp);
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
EFI_STATUS EFIAPI EfiMtftp4ReadDirectory(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_TOKEN *Token)
EFI_STATUS EFIAPI EfiMtftp4ParseOptions(IN EFI_MTFTP4_PROTOCOL *This, IN UINT32 PacketLen, IN EFI_MTFTP4_PACKET *Packet, OUT UINT32 *OptionCount, OUT EFI_MTFTP4_OPTION **OptionList OPTIONAL)
EFI_STATUS EFIAPI EfiMtftp4WriteFile(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_TOKEN *Token)
EFI_STATUS EFIAPI EfiMtftp4Poll(IN EFI_MTFTP4_PROTOCOL *This)
EFI_STATUS EFIAPI EfiMtftp4ReadFile(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_TOKEN *Token)
BOOLEAN Mtftp4GetMapping(IN MTFTP4_PROTOCOL *Instance, IN UDP_IO *UdpIo, IN EFI_UDP4_CONFIG_DATA *UdpCfgData)
EFI_STATUS EFIAPI EfiMtftp4GetModeData(IN EFI_MTFTP4_PROTOCOL *This, OUT EFI_MTFTP4_MODE_DATA *ModeData)
EFI_STATUS EFIAPI EfiMtftp4GetInfo(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_OVERRIDE_DATA *OverrideData OPTIONAL, IN UINT8 *Filename, IN UINT8 *ModeStr OPTIONAL, IN UINT8 OptionCount, IN EFI_MTFTP4_OPTION *OptionList OPTIONAL, OUT UINT32 *PacketLength, OUT EFI_MTFTP4_PACKET **Packet OPTIONAL)
EFI_STATUS Mtftp4Start(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_TOKEN *Token, IN UINT16 Operation)
EFI_STATUS Mtftp4ConfigUnicastPort(IN UDP_IO *UdpIo, IN MTFTP4_PROTOCOL *Instance)
EFI_STATUS EFIAPI EfiMtftp4Configure(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_CONFIG_DATA *ConfigData)
BOOLEAN Mtftp4OverrideValid(IN MTFTP4_PROTOCOL *Instance, IN EFI_MTFTP4_OVERRIDE_DATA *Override)
EFI_STATUS EFIAPI Mtftp4GetInfoCheckPacket(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_TOKEN *Token, IN UINT16 PacketLen, IN EFI_MTFTP4_PACKET *Packet)
VOID Mtftp4CleanOperation(IN OUT MTFTP4_PROTOCOL *Instance, IN EFI_STATUS Result)
EFI_STATUS Mtftp4RrqStart(IN MTFTP4_PROTOCOL *Instance, IN UINT16 Operation)
EFI_STATUS Mtftp4WrqStart(IN MTFTP4_PROTOCOL *Instance, IN UINT16 Operation)
EFI_STATUS Mtftp4ExtractOptions(IN EFI_MTFTP4_PACKET *Packet, IN UINT32 PacketLen, OUT UINT32 *OptionCount, OUT EFI_MTFTP4_OPTION **OptionList OPTIONAL)
EFI_STATUS Mtftp4ParseOption(IN EFI_MTFTP4_OPTION *Options, IN UINT32 Count, IN BOOLEAN Request, IN UINT16 Operation, OUT MTFTP4_OPTION *MtftpOption)
VOID EFIAPI Mtftp4OnTimerTick(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI NetbufFree(IN NET_BUF *Nbuf)
BOOLEAN EFIAPI NetIp4IsUnicast(IN IP4_ADDR Ip, IN IP4_ADDR NetMask)
VOID EFIAPI UdpIoCleanIo(IN UDP_IO *UdpIo)
EFI_STATUS EFIAPI UdpIoFreeIo(IN UDP_IO *UdpIo)
EFI_HANDLE DriverBindingHandle
EFI_MTFTP4_CHECK_PACKET CheckPacket
EFI_MTFTP4_PACKET_NEEDED PacketNeeded
EFI_MTFTP4_TIMEOUT_CALLBACK TimeoutCallback
EFI_MTFTP4_OVERRIDE_DATA * OverrideData
EFI_MTFTP4_OPTION * OptionList