NetworkPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the NetworkPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:07 -08:00
committed by mergify[bot]
parent 2f88bd3a12
commit d1050b9dff
294 changed files with 29888 additions and 30440 deletions

View File

@@ -9,7 +9,6 @@
#include "Mtftp6Impl.h"
/**
Retrieves a Unicode string that is the user-readable name of the driver.
@@ -128,17 +127,17 @@ Mtftp6ComponentNameGetDriverName (
EFI_STATUS
EFIAPI
Mtftp6ComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp6ComponentName = {
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp6ComponentName = {
Mtftp6ComponentNameGetDriverName,
Mtftp6ComponentNameGetControllerName,
"eng"
@@ -147,13 +146,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp6ComponentNa
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMtftp6ComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Mtftp6ComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Mtftp6ComponentNameGetControllerName,
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMtftp6ComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)Mtftp6ComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)Mtftp6ComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp6DriverNameTable[] = {
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp6DriverNameTable[] = {
{
"eng;en",
L"MTFTP6 Network Service Driver"
@@ -164,7 +163,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp6DriverNameT
}
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMtftp6ControllerNameTable = NULL;
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMtftp6ControllerNameTable = NULL;
/**
Retrieves a Unicode string that is the user-readable name of the driver.
@@ -214,12 +213,12 @@ Mtftp6ComponentNameGetDriverName (
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mMtftp6DriverNameTable,
DriverName,
(BOOLEAN)(This == &gMtftp6ComponentName)
);
Language,
This->SupportedLanguages,
mMtftp6DriverNameTable,
DriverName,
(BOOLEAN)(This == &gMtftp6ComponentName)
);
}
/**
@@ -234,13 +233,13 @@ Mtftp6ComponentNameGetDriverName (
**/
EFI_STATUS
UpdateName (
IN EFI_MTFTP6_PROTOCOL *Mtftp6
IN EFI_MTFTP6_PROTOCOL *Mtftp6
)
{
EFI_STATUS Status;
CHAR16 HandleName[128];
EFI_MTFTP6_MODE_DATA Mtftp6ModeData;
CHAR16 Address[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
EFI_STATUS Status;
CHAR16 HandleName[128];
EFI_MTFTP6_MODE_DATA Mtftp6ModeData;
CHAR16 Address[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
if (Mtftp6 == NULL) {
return EFI_INVALID_PARAMETER;
@@ -251,11 +250,14 @@ UpdateName (
//
Status = Mtftp6->GetModeData (Mtftp6, &Mtftp6ModeData);
if (!EFI_ERROR (Status)) {
Status = NetLibIp6ToStr (&Mtftp6ModeData.ConfigData.ServerIp, Address, sizeof(Address));
Status = NetLibIp6ToStr (&Mtftp6ModeData.ConfigData.ServerIp, Address, sizeof (Address));
if (EFI_ERROR (Status)) {
return Status;
}
UnicodeSPrint (HandleName, sizeof (HandleName),
UnicodeSPrint (
HandleName,
sizeof (HandleName),
L"MTFTPv6(ServerIp=%s, InitialServerPort=%d)",
Address,
Mtftp6ModeData.ConfigData.InitialServerPort
@@ -289,7 +291,6 @@ UpdateName (
);
}
/**
Retrieves a Unicode string that is the user-readable name of the controller
that is being managed by a driver.
@@ -361,15 +362,15 @@ UpdateName (
EFI_STATUS
EFIAPI
Mtftp6ComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_MTFTP6_PROTOCOL *Mtftp6;
EFI_STATUS Status;
EFI_MTFTP6_PROTOCOL *Mtftp6;
//
// Only provide names for child handles.
@@ -421,4 +422,3 @@ Mtftp6ComponentNameGetControllerName (
(BOOLEAN)(This == &gMtftp6ComponentName)
);
}

View File

@@ -10,8 +10,7 @@
#include "Mtftp6Impl.h"
EFI_DRIVER_BINDING_PROTOCOL gMtftp6DriverBinding = {
EFI_DRIVER_BINDING_PROTOCOL gMtftp6DriverBinding = {
Mtftp6DriverBindingSupported,
Mtftp6DriverBindingStart,
Mtftp6DriverBindingStop,
@@ -25,7 +24,6 @@ EFI_SERVICE_BINDING_PROTOCOL gMtftp6ServiceBindingTemplate = {
Mtftp6ServiceBindingDestroyChild
};
/**
Destroy the MTFTP6 service. The MTFTP6 service may be partly initialized,
or partly destroyed. If a resource is destroyed, it is marked as such in
@@ -36,7 +34,7 @@ EFI_SERVICE_BINDING_PROTOCOL gMtftp6ServiceBindingTemplate = {
**/
VOID
Mtftp6DestroyService (
IN MTFTP6_SERVICE *Service
IN MTFTP6_SERVICE *Service
)
{
//
@@ -55,7 +53,6 @@ Mtftp6DestroyService (
FreePool (Service);
}
/**
Create then initialize a MTFTP6 service binding instance.
@@ -72,13 +69,13 @@ Mtftp6DestroyService (
**/
EFI_STATUS
Mtftp6CreateService (
IN EFI_HANDLE Controller,
IN EFI_HANDLE Image,
OUT MTFTP6_SERVICE **Service
IN EFI_HANDLE Controller,
IN EFI_HANDLE Image,
OUT MTFTP6_SERVICE **Service
)
{
MTFTP6_SERVICE *Mtftp6Srv;
EFI_STATUS Status;
MTFTP6_SERVICE *Mtftp6Srv;
EFI_STATUS Status;
ASSERT (Service != NULL);
@@ -89,10 +86,10 @@ Mtftp6CreateService (
return EFI_OUT_OF_RESOURCES;
}
Mtftp6Srv->Signature = MTFTP6_SERVICE_SIGNATURE;
Mtftp6Srv->Controller = Controller;
Mtftp6Srv->Image = Image;
Mtftp6Srv->ChildrenNum = 0;
Mtftp6Srv->Signature = MTFTP6_SERVICE_SIGNATURE;
Mtftp6Srv->Controller = Controller;
Mtftp6Srv->Image = Image;
Mtftp6Srv->ChildrenNum = 0;
CopyMem (
&Mtftp6Srv->ServiceBinding,
@@ -140,7 +137,6 @@ Mtftp6CreateService (
return EFI_SUCCESS;
}
/**
Destroy the MTFTP6 instance and recycle the resources.
@@ -149,18 +145,18 @@ Mtftp6CreateService (
**/
VOID
Mtftp6DestroyInstance (
IN MTFTP6_INSTANCE *Instance
IN MTFTP6_INSTANCE *Instance
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
MTFTP6_BLOCK_RANGE *Block;
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
MTFTP6_BLOCK_RANGE *Block;
if (Instance->Config != NULL) {
FreePool (Instance->Config);
}
if (Instance->Token != NULL && Instance->Token->Event != NULL) {
if ((Instance->Token != NULL) && (Instance->Token->Event != NULL)) {
gBS->SignalEvent (Instance->Token->Event);
}
@@ -168,7 +164,7 @@ Mtftp6DestroyInstance (
NetbufFree (Instance->LastPacket);
}
if (Instance->UdpIo!= NULL) {
if (Instance->UdpIo != NULL) {
UdpIoFreeIo (Instance->UdpIo);
}
@@ -185,7 +181,6 @@ Mtftp6DestroyInstance (
FreePool (Instance);
}
/**
Create the MTFTP6 instance and initialize it.
@@ -198,11 +193,11 @@ Mtftp6DestroyInstance (
**/
EFI_STATUS
Mtftp6CreateInstance (
IN MTFTP6_SERVICE *Service,
OUT MTFTP6_INSTANCE **Instance
IN MTFTP6_SERVICE *Service,
OUT MTFTP6_INSTANCE **Instance
)
{
MTFTP6_INSTANCE *Mtftp6Ins;
MTFTP6_INSTANCE *Mtftp6Ins;
*Instance = NULL;
Mtftp6Ins = AllocateZeroPool (sizeof (MTFTP6_INSTANCE));
@@ -229,7 +224,6 @@ Mtftp6CreateInstance (
return EFI_SUCCESS;
}
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@@ -243,8 +237,8 @@ Mtftp6CreateInstance (
EFI_STATUS
EFIAPI
Mtftp6DestroyChildEntryInHandleBuffer (
IN LIST_ENTRY *Entry,
IN VOID *Context
IN LIST_ENTRY *Entry,
IN VOID *Context
)
{
MTFTP6_INSTANCE *Instance;
@@ -252,14 +246,14 @@ Mtftp6DestroyChildEntryInHandleBuffer (
UINTN NumberOfChildren;
EFI_HANDLE *ChildHandleBuffer;
if (Entry == NULL || Context == NULL) {
if ((Entry == NULL) || (Context == NULL)) {
return EFI_INVALID_PARAMETER;
}
Instance = NET_LIST_USER_STRUCT_S (Entry, MTFTP6_INSTANCE, Link, MTFTP6_INSTANCE_SIGNATURE);
ServiceBinding = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;
NumberOfChildren = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;
ChildHandleBuffer = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;
Instance = NET_LIST_USER_STRUCT_S (Entry, MTFTP6_INSTANCE, Link, MTFTP6_INSTANCE_SIGNATURE);
ServiceBinding = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ServiceBinding;
NumberOfChildren = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->NumberOfChildren;
ChildHandleBuffer = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ChildHandleBuffer;
if (!NetIsInHandleBuffer (Instance->Handle, NumberOfChildren, ChildHandleBuffer)) {
return EFI_SUCCESS;
@@ -268,7 +262,6 @@ Mtftp6DestroyChildEntryInHandleBuffer (
return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
}
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including
@@ -286,8 +279,8 @@ Mtftp6DestroyChildEntryInHandleBuffer (
EFI_STATUS
EFIAPI
Mtftp6DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
@@ -300,7 +293,6 @@ Mtftp6DriverEntryPoint (
);
}
/**
Test to see if this driver supports Controller. This service
is called by the EFI boot service ConnectController(). In
@@ -321,9 +313,9 @@ Mtftp6DriverEntryPoint (
EFI_STATUS
EFIAPI
Mtftp6DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
return gBS->OpenProtocol (
@@ -336,7 +328,6 @@ Mtftp6DriverBindingSupported (
);
}
/**
Start this driver on Controller. This service is called by the
EFI boot service ConnectController(). In order to make
@@ -363,8 +354,8 @@ Mtftp6DriverBindingStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
MTFTP6_SERVICE *Service;
EFI_STATUS Status;
MTFTP6_SERVICE *Service;
EFI_STATUS Status;
//
// Directly return if driver is already running on this Nic handle.
@@ -432,7 +423,6 @@ ON_ERROR:
return Status;
}
/**
Stop this driver on Controller. This service is called by the
EFI boot service DisconnectController(). In order to
@@ -455,18 +445,18 @@ ON_ERROR:
EFI_STATUS
EFIAPI
Mtftp6DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
MTFTP6_SERVICE *Service;
EFI_HANDLE NicHandle;
EFI_STATUS Status;
LIST_ENTRY *List;
MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
MTFTP6_SERVICE *Service;
EFI_HANDLE NicHandle;
EFI_STATUS Status;
LIST_ENTRY *List;
MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
//
// Locate the Nic handle to retrieve the Mtftp6 private data.
@@ -480,7 +470,7 @@ Mtftp6DriverBindingStop (
Status = gBS->OpenProtocol (
NicHandle,
&gEfiMtftp6ServiceBindingProtocolGuid,
(VOID **) &ServiceBinding,
(VOID **)&ServiceBinding,
This->DriverBindingHandle,
NicHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -496,19 +486,19 @@ Mtftp6DriverBindingStop (
//
// Destroy the Mtftp6 child instance in ChildHandleBuffer.
//
List = &Service->Children;
List = &Service->Children;
Context.ServiceBinding = ServiceBinding;
Context.NumberOfChildren = NumberOfChildren;
Context.ChildHandleBuffer = ChildHandleBuffer;
Status = NetDestroyLinkList (
List,
Mtftp6DestroyChildEntryInHandleBuffer,
&Context,
NULL
);
Status = NetDestroyLinkList (
List,
Mtftp6DestroyChildEntryInHandleBuffer,
&Context,
NULL
);
}
if (NumberOfChildren == 0 && IsListEmpty (&Service->Children)) {
if ((NumberOfChildren == 0) && IsListEmpty (&Service->Children)) {
//
// Destroy the Mtftp6 service if there is no Mtftp6 child instance left.
//
@@ -525,7 +515,6 @@ Mtftp6DriverBindingStop (
return Status;
}
/**
Creates a child handle and installs a protocol.
@@ -550,13 +539,13 @@ Mtftp6ServiceBindingCreateChild (
IN OUT EFI_HANDLE *ChildHandle
)
{
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
EFI_STATUS Status;
EFI_TPL OldTpl;
VOID *Udp6;
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
EFI_STATUS Status;
EFI_TPL OldTpl;
VOID *Udp6;
if (This == NULL || ChildHandle == NULL) {
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -592,7 +581,7 @@ Mtftp6ServiceBindingCreateChild (
Status = gBS->OpenProtocol (
Service->DummyUdpIo->UdpHandle,
&gEfiUdp6ProtocolGuid,
(VOID **) &Udp6,
(VOID **)&Udp6,
gMtftp6DriverBinding.DriverBindingHandle,
Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@@ -626,7 +615,6 @@ ON_ERROR:
return Status;
}
/**
Destroys a child handle with a protocol installed on it.
@@ -646,17 +634,17 @@ ON_ERROR:
EFI_STATUS
EFIAPI
Mtftp6ServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
)
{
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
EFI_MTFTP6_PROTOCOL *Mtftp6;
EFI_STATUS Status;
EFI_TPL OldTpl;
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
EFI_MTFTP6_PROTOCOL *Mtftp6;
EFI_STATUS Status;
EFI_TPL OldTpl;
if (This == NULL || ChildHandle == NULL) {
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -666,7 +654,7 @@ Mtftp6ServiceBindingDestroyChild (
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiMtftp6ProtocolGuid,
(VOID **) &Mtftp6,
(VOID **)&Mtftp6,
gMtftp6DriverBinding.DriverBindingHandle,
ChildHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -703,11 +691,11 @@ Mtftp6ServiceBindingDestroyChild (
if (Instance->UdpIo != NULL) {
gBS->CloseProtocol (
Instance->UdpIo->UdpHandle,
&gEfiUdp6ProtocolGuid,
gMtftp6DriverBinding.DriverBindingHandle,
Instance->Handle
);
Instance->UdpIo->UdpHandle,
&gEfiUdp6ProtocolGuid,
gMtftp6DriverBinding.DriverBindingHandle,
Instance->Handle
);
}
if (Instance->McastUdpIo != NULL) {
@@ -739,7 +727,7 @@ Mtftp6ServiceBindingDestroyChild (
// Remove the Mtftp6 instance from the children list of Mtftp6 service.
//
RemoveEntryList (&Instance->Link);
Service->ChildrenNum --;
Service->ChildrenNum--;
gBS->RestoreTPL (OldTpl);

View File

@@ -13,9 +13,9 @@
#include <Protocol/ServiceBinding.h>
extern EFI_COMPONENT_NAME_PROTOCOL gMtftp6ComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gMtftp6ComponentName2;
extern EFI_UNICODE_STRING_TABLE *gMtftp6ControllerNameTable;
extern EFI_COMPONENT_NAME_PROTOCOL gMtftp6ComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gMtftp6ComponentName2;
extern EFI_UNICODE_STRING_TABLE *gMtftp6ControllerNameTable;
/**
Test to see if this driver supports Controller. This service
@@ -90,10 +90,10 @@ Mtftp6DriverBindingStart (
EFI_STATUS
EFIAPI
Mtftp6DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
/**
@@ -116,8 +116,8 @@ Mtftp6DriverBindingStop (
EFI_STATUS
EFIAPI
Mtftp6ServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle
);
/**
@@ -139,8 +139,8 @@ Mtftp6ServiceBindingCreateChild (
EFI_STATUS
EFIAPI
Mtftp6ServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif

View File

@@ -16,7 +16,7 @@
#include "Mtftp6Impl.h"
EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate = {
EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate = {
EfiMtftp6GetModeData,
EfiMtftp6Configure,
EfiMtftp6GetInfo,
@@ -25,7 +25,7 @@ EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate = {
EfiMtftp6WriteFile,
EfiMtftp6ReadDirectory,
EfiMtftp6Poll
};
};
/**
Returns the current operating mode data for the MTFTP6 instance.
@@ -45,14 +45,14 @@ EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate = {
EFI_STATUS
EFIAPI
EfiMtftp6GetModeData (
IN EFI_MTFTP6_PROTOCOL *This,
OUT EFI_MTFTP6_MODE_DATA *ModeData
IN EFI_MTFTP6_PROTOCOL *This,
OUT EFI_MTFTP6_MODE_DATA *ModeData
)
{
MTFTP6_INSTANCE *Instance;
EFI_TPL OldTpl;
if (This == NULL || ModeData == NULL) {
if ((This == NULL) || (ModeData == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -79,14 +79,13 @@ EfiMtftp6GetModeData (
// Set the current support options in mode data.
//
ModeData->SupportedOptionCount = MTFTP6_SUPPORTED_OPTIONS_NUM;
ModeData->SupportedOptions = (UINT8 **) mMtftp6SupportedOptions;
ModeData->SupportedOptions = (UINT8 **)mMtftp6SupportedOptions;
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
}
/**
Initializes, changes, or resets the default operational setting for
this EFI MTFTPv6 Protocol driver instance.
@@ -128,22 +127,22 @@ EfiMtftp6GetModeData (
EFI_STATUS
EFIAPI
EfiMtftp6Configure (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL
)
{
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA Udp6Cfg;
EFI_STATUS Status;
EFI_TPL OldTpl;
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA Udp6Cfg;
EFI_STATUS Status;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
if (MtftpConfigData != NULL && !NetIp6IsValidUnicast (&MtftpConfigData->ServerIp)) {
if ((MtftpConfigData != NULL) && !NetIp6IsValidUnicast (&MtftpConfigData->ServerIp)) {
return EFI_INVALID_PARAMETER;
}
@@ -167,6 +166,7 @@ EfiMtftp6Configure (
Status = EFI_ACCESS_DENIED;
goto ON_EXIT;
}
//
// Allocate the configure buffer of the instance and store the user's data.
//
@@ -195,7 +195,7 @@ EfiMtftp6Configure (
Status = gBS->OpenProtocol (
Instance->UdpIo->UdpHandle,
&gEfiUdp6ProtocolGuid,
(VOID **) &Udp6,
(VOID **)&Udp6,
Service->Image,
Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@@ -229,7 +229,7 @@ EfiMtftp6Configure (
CopyMem (
&Udp6Cfg.StationAddress,
&Instance->Config->StationIp,
sizeof(EFI_IPv6_ADDRESS)
sizeof (EFI_IPv6_ADDRESS)
);
CopyMem (
@@ -252,16 +252,17 @@ ON_EXIT:
FreePool (Instance->Config);
Instance->Config = NULL;
}
if (Instance->UdpIo != NULL) {
UdpIoFreeIo (Instance->UdpIo);
Instance->UdpIo = NULL;
}
}
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Get the information of the download from the server.
@@ -319,26 +320,27 @@ ON_EXIT:
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
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
)
{
EFI_STATUS Status;
EFI_MTFTP6_TOKEN Token;
MTFTP6_GETINFO_CONTEXT Context;
EFI_STATUS Status;
EFI_MTFTP6_TOKEN Token;
MTFTP6_GETINFO_CONTEXT Context;
if (This == NULL ||
Filename == NULL ||
PacketLength == NULL ||
(OptionCount != 0 && OptionList == NULL) ||
(OverrideData != NULL && !NetIp6IsValidUnicast (&OverrideData->ServerIp))
) {
if ((This == NULL) ||
(Filename == NULL) ||
(PacketLength == NULL) ||
((OptionCount != 0) && (OptionList == NULL)) ||
((OverrideData != NULL) && !NetIp6IsValidUnicast (&OverrideData->ServerIp))
)
{
return EFI_INVALID_PARAMETER;
}
@@ -346,11 +348,11 @@ EfiMtftp6GetInfo (
*Packet = NULL;
}
*PacketLength = 0;
*PacketLength = 0;
Context.Packet = Packet;
Context.PacketLen = PacketLength;
Context.Status = EFI_SUCCESS;
Context.Packet = Packet;
Context.PacketLen = PacketLength;
Context.Status = EFI_SUCCESS;
//
// Fill fields of the Token for GetInfo operation.
@@ -384,7 +386,6 @@ EfiMtftp6GetInfo (
return Status;
}
/**
Parse the options in an MTFTPv6 OACK packet.
@@ -418,11 +419,11 @@ EfiMtftp6GetInfo (
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
IN EFI_MTFTP6_PROTOCOL *This,
IN UINT32 PacketLen,
IN EFI_MTFTP6_PACKET *Packet,
OUT UINT32 *OptionCount,
OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
)
{
if (This == NULL) {
@@ -432,7 +433,6 @@ EfiMtftp6ParseOptions (
return Mtftp6ParseStart (Packet, PacketLen, OptionCount, OptionList);
}
/**
Download a file from an MTFTPv6 server.
@@ -477,14 +477,13 @@ EfiMtftp6ParseOptions (
EFI_STATUS
EFIAPI
EfiMtftp6ReadFile (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
)
{
return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_RRQ);
}
/**
Send a file to an MTFTPv6 server.
@@ -530,14 +529,13 @@ EfiMtftp6ReadFile (
EFI_STATUS
EFIAPI
EfiMtftp6WriteFile (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
)
{
return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_WRQ);
}
/**
Download a data file directory from an MTFTPv6 server.
@@ -581,14 +579,13 @@ EfiMtftp6WriteFile (
EFI_STATUS
EFIAPI
EfiMtftp6ReadDirectory (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
)
{
return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_DIR);
}
/**
Polls for incoming data packets and processes outgoing data packets.
@@ -616,11 +613,11 @@ EfiMtftp6ReadDirectory (
EFI_STATUS
EFIAPI
EfiMtftp6Poll (
IN EFI_MTFTP6_PROTOCOL *This
IN EFI_MTFTP6_PROTOCOL *This
)
{
MTFTP6_INSTANCE *Instance;
EFI_UDP6_PROTOCOL *Udp6;
MTFTP6_INSTANCE *Instance;
EFI_UDP6_PROTOCOL *Udp6;
if (This == NULL) {
return EFI_INVALID_PARAMETER;

View File

@@ -25,114 +25,114 @@
#include <Library/NetLib.h>
#include <Library/PrintLib.h>
typedef struct _MTFTP6_SERVICE MTFTP6_SERVICE;
typedef struct _MTFTP6_INSTANCE MTFTP6_INSTANCE;
typedef struct _MTFTP6_SERVICE MTFTP6_SERVICE;
typedef struct _MTFTP6_INSTANCE MTFTP6_INSTANCE;
#include "Mtftp6Driver.h"
#include "Mtftp6Option.h"
#include "Mtftp6Support.h"
#define MTFTP6_SERVICE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'S')
#define MTFTP6_INSTANCE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'I')
#define MTFTP6_SERVICE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'S')
#define MTFTP6_INSTANCE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'I')
#define MTFTP6_DEFAULT_SERVER_CMD_PORT 69
#define MTFTP6_DEFAULT_TIMEOUT 3
#define MTFTP6_GET_MAPPING_TIMEOUT 3
#define MTFTP6_DEFAULT_MAX_RETRY 5
#define MTFTP6_DEFAULT_BLK_SIZE 512
#define MTFTP6_DEFAULT_WINDOWSIZE 1
#define MTFTP6_TICK_PER_SECOND 10000000U
#define MTFTP6_DEFAULT_SERVER_CMD_PORT 69
#define MTFTP6_DEFAULT_TIMEOUT 3
#define MTFTP6_GET_MAPPING_TIMEOUT 3
#define MTFTP6_DEFAULT_MAX_RETRY 5
#define MTFTP6_DEFAULT_BLK_SIZE 512
#define MTFTP6_DEFAULT_WINDOWSIZE 1
#define MTFTP6_TICK_PER_SECOND 10000000U
#define MTFTP6_SERVICE_FROM_THIS(a) CR (a, MTFTP6_SERVICE, ServiceBinding, MTFTP6_SERVICE_SIGNATURE)
#define MTFTP6_INSTANCE_FROM_THIS(a) CR (a, MTFTP6_INSTANCE, Mtftp6, MTFTP6_INSTANCE_SIGNATURE)
#define MTFTP6_SERVICE_FROM_THIS(a) CR (a, MTFTP6_SERVICE, ServiceBinding, MTFTP6_SERVICE_SIGNATURE)
#define MTFTP6_INSTANCE_FROM_THIS(a) CR (a, MTFTP6_INSTANCE, Mtftp6, MTFTP6_INSTANCE_SIGNATURE)
extern EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate;
extern EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate;
typedef struct _MTFTP6_GETINFO_CONTEXT{
EFI_MTFTP6_PACKET **Packet;
UINT32 *PacketLen;
EFI_STATUS Status;
typedef struct _MTFTP6_GETINFO_CONTEXT {
EFI_MTFTP6_PACKET **Packet;
UINT32 *PacketLen;
EFI_STATUS Status;
} MTFTP6_GETINFO_CONTEXT;
//
// Control block for MTFTP6 instance, it's per configuration data.
//
struct _MTFTP6_INSTANCE {
UINT32 Signature;
EFI_HANDLE Handle;
LIST_ENTRY Link;
EFI_MTFTP6_PROTOCOL Mtftp6;
MTFTP6_SERVICE *Service;
EFI_MTFTP6_CONFIG_DATA *Config;
UINT32 Signature;
EFI_HANDLE Handle;
LIST_ENTRY Link;
EFI_MTFTP6_PROTOCOL Mtftp6;
MTFTP6_SERVICE *Service;
EFI_MTFTP6_CONFIG_DATA *Config;
EFI_MTFTP6_TOKEN *Token;
MTFTP6_EXT_OPTION_INFO ExtInfo;
EFI_MTFTP6_TOKEN *Token;
MTFTP6_EXT_OPTION_INFO ExtInfo;
UINT16 BlkSize;
UINT16 LastBlk;
LIST_ENTRY BlkList;
UINT16 BlkSize;
UINT16 LastBlk;
LIST_ENTRY BlkList;
UINT16 Operation;
UINT16 Operation;
UINT16 WindowSize;
UINT16 WindowSize;
//
// Record the total received and saved block number.
//
UINT64 TotalBlock;
UINT64 TotalBlock;
//
// Record the acked block number.
//
UINT64 AckedBlock;
UINT64 AckedBlock;
EFI_IPv6_ADDRESS ServerIp;
UINT16 ServerCmdPort;
UINT16 ServerDataPort;
UDP_IO *UdpIo;
EFI_IPv6_ADDRESS ServerIp;
UINT16 ServerCmdPort;
UINT16 ServerDataPort;
UDP_IO *UdpIo;
EFI_IPv6_ADDRESS McastIp;
UINT16 McastPort;
UDP_IO *McastUdpIo;
EFI_IPv6_ADDRESS McastIp;
UINT16 McastPort;
UDP_IO *McastUdpIo;
NET_BUF *LastPacket;
UINT32 CurRetry;
UINT32 MaxRetry;
UINT32 PacketToLive;
UINT32 Timeout;
NET_BUF *LastPacket;
UINT32 CurRetry;
UINT32 MaxRetry;
UINT32 PacketToLive;
UINT32 Timeout;
EFI_TPL OldTpl;
BOOLEAN IsTransmitted;
BOOLEAN IsMaster;
BOOLEAN InDestroy;
EFI_TPL OldTpl;
BOOLEAN IsTransmitted;
BOOLEAN IsMaster;
BOOLEAN InDestroy;
};
//
// Control block for MTFTP6 service, it's per Nic handle.
//
struct _MTFTP6_SERVICE {
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
EFI_HANDLE Controller;
EFI_HANDLE Image;
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
EFI_HANDLE Controller;
EFI_HANDLE Image;
UINT16 ChildrenNum;
LIST_ENTRY Children;
UINT16 ChildrenNum;
LIST_ENTRY Children;
//
// It is used to be as internal calculagraph for all instances.
//
EFI_EVENT Timer;
EFI_EVENT Timer;
//
// It is used to maintain the parent-child relationship between
// mtftp driver and udp driver.
//
UDP_IO *DummyUdpIo;
UDP_IO *DummyUdpIo;
};
typedef struct {
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
UINTN NumberOfChildren;
EFI_HANDLE *ChildHandleBuffer;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
UINTN NumberOfChildren;
EFI_HANDLE *ChildHandleBuffer;
} MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
/**
@@ -153,8 +153,8 @@ typedef struct {
EFI_STATUS
EFIAPI
EfiMtftp6GetModeData (
IN EFI_MTFTP6_PROTOCOL *This,
OUT EFI_MTFTP6_MODE_DATA *ModeData
IN EFI_MTFTP6_PROTOCOL *This,
OUT EFI_MTFTP6_MODE_DATA *ModeData
);
/**
@@ -198,8 +198,8 @@ EfiMtftp6GetModeData (
EFI_STATUS
EFIAPI
EfiMtftp6Configure (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL
);
/**
@@ -258,14 +258,14 @@ EfiMtftp6Configure (
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
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
);
/**
@@ -301,11 +301,11 @@ EfiMtftp6GetInfo (
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
IN EFI_MTFTP6_PROTOCOL *This,
IN UINT32 PacketLen,
IN EFI_MTFTP6_PACKET *Packet,
OUT UINT32 *OptionCount,
OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
);
/**
@@ -351,8 +351,8 @@ EfiMtftp6ParseOptions (
EFI_STATUS
EFIAPI
EfiMtftp6ReadFile (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
);
/**
@@ -400,8 +400,8 @@ EfiMtftp6ReadFile (
EFI_STATUS
EFIAPI
EfiMtftp6WriteFile (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
);
/**
@@ -447,8 +447,8 @@ EfiMtftp6WriteFile (
EFI_STATUS
EFIAPI
EfiMtftp6ReadDirectory (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token
);
/**
@@ -478,7 +478,7 @@ EfiMtftp6ReadDirectory (
EFI_STATUS
EFIAPI
EfiMtftp6Poll (
IN EFI_MTFTP6_PROTOCOL *This
IN EFI_MTFTP6_PROTOCOL *This
);
#endif

View File

@@ -9,7 +9,7 @@
#include "Mtftp6Impl.h"
CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM] = {
CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM] = {
"blksize",
"windowsize",
"timeout",
@@ -17,7 +17,6 @@ CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM] = {
"multicast"
};
/**
Parse the NULL terminated ASCII string of multicast option.
@@ -32,25 +31,23 @@ CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM] = {
**/
EFI_STATUS
Mtftp6ParseMcastOption (
IN UINT8 *Str,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
IN UINT8 *Str,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
)
{
EFI_STATUS Status;
UINT32 Num;
CHAR8 *Ip6Str;
CHAR8 *TempStr;
EFI_STATUS Status;
UINT32 Num;
CHAR8 *Ip6Str;
CHAR8 *TempStr;
//
// The multicast option is formatted like "addr,port,mc"
// The server can also omit the ip and port, use ",,1"
//
if (*Str == ',') {
ZeroMem (&ExtInfo->McastIp, sizeof (EFI_IPv6_ADDRESS));
} else {
Ip6Str = (CHAR8 *) AllocateCopyPool (AsciiStrSize ((CHAR8 *) Str), Str);
Ip6Str = (CHAR8 *)AllocateCopyPool (AsciiStrSize ((CHAR8 *)Str), Str);
if (Ip6Str == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -88,17 +85,15 @@ Mtftp6ParseMcastOption (
// empty string. such as the port in ",,1"
//
if (*Str == ',') {
ExtInfo->McastPort = 0;
} else {
Num = (UINT32) AsciiStrDecimalToUintn ((CHAR8 *) Str);
Num = (UINT32)AsciiStrDecimalToUintn ((CHAR8 *)Str);
if (Num > 65535) {
return EFI_INVALID_PARAMETER;
}
ExtInfo->McastPort = (UINT16) Num;
ExtInfo->McastPort = (UINT16)Num;
while (NET_IS_DIGIT (*Str)) {
Str++;
@@ -114,13 +109,13 @@ Mtftp6ParseMcastOption (
//
// Check the master/slave setting, 1 for master, 0 for slave.
//
Num = (UINT32) AsciiStrDecimalToUintn ((CHAR8 *) Str);
Num = (UINT32)AsciiStrDecimalToUintn ((CHAR8 *)Str);
if (Num != 0 && Num != 1) {
if ((Num != 0) && (Num != 1)) {
return EFI_INVALID_PARAMETER;
}
ExtInfo->IsMaster = (BOOLEAN) (Num == 1);
ExtInfo->IsMaster = (BOOLEAN)(Num == 1);
while (NET_IS_DIGIT (*Str)) {
Str++;
@@ -133,7 +128,6 @@ Mtftp6ParseMcastOption (
return EFI_SUCCESS;
}
/**
Parse the MTFTP6 extension options.
@@ -151,81 +145,74 @@ Mtftp6ParseMcastOption (
**/
EFI_STATUS
Mtftp6ParseExtensionOption (
IN EFI_MTFTP6_OPTION *Options,
IN UINT32 Count,
IN BOOLEAN IsRequest,
IN UINT16 Operation,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
IN EFI_MTFTP6_OPTION *Options,
IN UINT32 Count,
IN BOOLEAN IsRequest,
IN UINT16 Operation,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
)
{
EFI_STATUS Status;
EFI_MTFTP6_OPTION *Opt;
UINT32 Index;
UINT32 Value;
EFI_STATUS Status;
EFI_MTFTP6_OPTION *Opt;
UINT32 Index;
UINT32 Value;
ExtInfo->BitMap = 0;
for (Index = 0; Index < Count; Index++) {
Opt = Options + Index;
if (Opt->OptionStr == NULL || Opt->ValueStr == NULL) {
if ((Opt->OptionStr == NULL) || (Opt->ValueStr == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (AsciiStriCmp ((CHAR8 *) Opt->OptionStr, "blksize") == 0) {
if (AsciiStriCmp ((CHAR8 *)Opt->OptionStr, "blksize") == 0) {
//
// block size option, valid value is between [8, 65464]
//
Value = (UINT32) AsciiStrDecimalToUintn ((CHAR8 *) Opt->ValueStr);
Value = (UINT32)AsciiStrDecimalToUintn ((CHAR8 *)Opt->ValueStr);
if ((Value < 8) || (Value > 65464)) {
return EFI_INVALID_PARAMETER;
}
ExtInfo->BlkSize = (UINT16) Value;
ExtInfo->BlkSize = (UINT16)Value;
ExtInfo->BitMap |= MTFTP6_OPT_BLKSIZE_BIT;
} else if (AsciiStriCmp ((CHAR8 *) Opt->OptionStr, "timeout") == 0) {
} else if (AsciiStriCmp ((CHAR8 *)Opt->OptionStr, "timeout") == 0) {
//
// timeout option, valid value is between [1, 255]
//
Value = (UINT32) AsciiStrDecimalToUintn ((CHAR8 *) Opt->ValueStr);
Value = (UINT32)AsciiStrDecimalToUintn ((CHAR8 *)Opt->ValueStr);
if (Value < 1 || Value > 255) {
if ((Value < 1) || (Value > 255)) {
return EFI_INVALID_PARAMETER;
}
ExtInfo->Timeout = (UINT8) Value;
ExtInfo->Timeout = (UINT8)Value;
ExtInfo->BitMap |= MTFTP6_OPT_TIMEOUT_BIT;
} else if (AsciiStriCmp ((CHAR8 *) Opt->OptionStr, "tsize") == 0) {
} else if (AsciiStriCmp ((CHAR8 *)Opt->OptionStr, "tsize") == 0) {
//
// tsize option, the biggest transfer supported is 4GB with block size option
//
ExtInfo->Tsize = (UINT32) AsciiStrDecimalToUintn ((CHAR8 *) Opt->ValueStr);
ExtInfo->Tsize = (UINT32)AsciiStrDecimalToUintn ((CHAR8 *)Opt->ValueStr);
ExtInfo->BitMap |= MTFTP6_OPT_TSIZE_BIT;
} else if (AsciiStriCmp ((CHAR8 *) Opt->OptionStr, "multicast") == 0) {
} else if (AsciiStriCmp ((CHAR8 *)Opt->OptionStr, "multicast") == 0) {
//
// Multicast option, if it is a request, the value must be a zero string,
// otherwise, it must be like "addr,port,mc" string, mc indicates master.
//
if (!IsRequest) {
Status = Mtftp6ParseMcastOption (Opt->ValueStr, ExtInfo);
if (EFI_ERROR (Status)) {
return Status;
}
} else if (*(Opt->ValueStr) != '\0') {
return EFI_INVALID_PARAMETER;
}
ExtInfo->BitMap |= MTFTP6_OPT_MCAST_BIT;
} else if (AsciiStriCmp ((CHAR8 *) Opt->OptionStr, "windowsize") == 0) {
} else if (AsciiStriCmp ((CHAR8 *)Opt->OptionStr, "windowsize") == 0) {
if (Operation == EFI_MTFTP6_OPCODE_WRQ) {
//
// Currently, windowsize is not supported in the write operation.
@@ -233,15 +220,14 @@ Mtftp6ParseExtensionOption (
return EFI_UNSUPPORTED;
}
Value = (UINT32) AsciiStrDecimalToUintn ((CHAR8 *) Opt->ValueStr);
Value = (UINT32)AsciiStrDecimalToUintn ((CHAR8 *)Opt->ValueStr);
if ((Value < 1)) {
return EFI_INVALID_PARAMETER;
}
ExtInfo->WindowSize = (UINT16) Value;
ExtInfo->BitMap |= MTFTP6_OPT_WINDOWSIZE_BIT;
ExtInfo->WindowSize = (UINT16)Value;
ExtInfo->BitMap |= MTFTP6_OPT_WINDOWSIZE_BIT;
} else if (IsRequest) {
//
// If it's a request, unsupported; else if it's a reply, ignore.
@@ -253,7 +239,6 @@ Mtftp6ParseExtensionOption (
return EFI_SUCCESS;
}
/**
Go through the packet to fill the options array with the start
addresses of each MTFTP option name/value pair.
@@ -273,21 +258,21 @@ Mtftp6ParseExtensionOption (
**/
EFI_STATUS
Mtftp6ParsePacketOption (
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *Count,
IN EFI_MTFTP6_OPTION *Options OPTIONAL
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *Count,
IN EFI_MTFTP6_OPTION *Options OPTIONAL
)
{
UINT8 *Cur;
UINT8 *Last;
UINT8 Num;
UINT8 *Name;
UINT8 *Value;
UINT8 *Cur;
UINT8 *Last;
UINT8 Num;
UINT8 *Name;
UINT8 *Value;
Num = 0;
Cur = (UINT8 *) Packet + MTFTP6_OPCODE_LEN;
Last = (UINT8 *) Packet + PacketLen - 1;
Num = 0;
Cur = (UINT8 *)Packet + MTFTP6_OPCODE_LEN;
Last = (UINT8 *)Packet + PacketLen - 1;
//
// process option name and value pairs.
@@ -312,9 +297,9 @@ Mtftp6ParsePacketOption (
Num++;
if (Options != NULL && Num <= *Count) {
Options[Num - 1].OptionStr = Name;
Options[Num - 1].ValueStr = Value;
if ((Options != NULL) && (Num <= *Count)) {
Options[Num - 1].OptionStr = Name;
Options[Num - 1].ValueStr = Value;
}
Cur++;
@@ -323,7 +308,7 @@ Mtftp6ParsePacketOption (
//
// Return buffer too small if the buffer passed-in isn't enough.
//
if (*Count < Num || Options == NULL) {
if ((*Count < Num) || (Options == NULL)) {
*Count = Num;
return EFI_BUFFER_TOO_SMALL;
}
@@ -332,7 +317,6 @@ Mtftp6ParsePacketOption (
return EFI_SUCCESS;
}
/**
Go through the packet, generate option list array and fill it
by the result of parse options.
@@ -354,15 +338,15 @@ Mtftp6ParsePacketOption (
**/
EFI_STATUS
Mtftp6ParseStart (
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *OptionCount,
OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *OptionCount,
OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
)
{
EFI_STATUS Status;
EFI_STATUS Status;
if (PacketLen == 0 || Packet == NULL || OptionCount == NULL) {
if ((PacketLen == 0) || (Packet == NULL) || (OptionCount == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -379,7 +363,7 @@ Mtftp6ParseStart (
//
// The last byte must be zero to terminate the options.
//
if (*((UINT8 *) Packet + PacketLen - 1) != 0) {
if (*((UINT8 *)Packet + PacketLen - 1) != 0) {
return EFI_PROTOCOL_ERROR;
}

View File

@@ -29,23 +29,23 @@
//
// The bit map definition for Mtftp6 extension options.
//
#define MTFTP6_OPT_BLKSIZE_BIT 0x01
#define MTFTP6_OPT_TIMEOUT_BIT 0x02
#define MTFTP6_OPT_TSIZE_BIT 0x04
#define MTFTP6_OPT_MCAST_BIT 0x08
#define MTFTP6_OPT_WINDOWSIZE_BIT 0X10
#define MTFTP6_OPT_BLKSIZE_BIT 0x01
#define MTFTP6_OPT_TIMEOUT_BIT 0x02
#define MTFTP6_OPT_TSIZE_BIT 0x04
#define MTFTP6_OPT_MCAST_BIT 0x08
#define MTFTP6_OPT_WINDOWSIZE_BIT 0X10
extern CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM];
extern CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM];
typedef struct {
UINT16 BlkSize;
UINT16 WindowSize;
UINT8 Timeout;
UINT32 Tsize;
EFI_IPv6_ADDRESS McastIp;
UINT16 McastPort;
BOOLEAN IsMaster;
UINT32 BitMap;
UINT16 BlkSize;
UINT16 WindowSize;
UINT8 Timeout;
UINT32 Tsize;
EFI_IPv6_ADDRESS McastIp;
UINT16 McastPort;
BOOLEAN IsMaster;
UINT32 BitMap;
} MTFTP6_EXT_OPTION_INFO;
/**
@@ -60,11 +60,10 @@ typedef struct {
**/
EFI_STATUS
Mtftp6ParseMcastOption (
IN UINT8 *Str,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
IN UINT8 *Str,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
);
/**
Parse the MTFTP6 extension options.
@@ -82,14 +81,13 @@ Mtftp6ParseMcastOption (
**/
EFI_STATUS
Mtftp6ParseExtensionOption (
IN EFI_MTFTP6_OPTION *Options,
IN UINT32 Count,
IN BOOLEAN IsRequest,
IN UINT16 Operation,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
IN EFI_MTFTP6_OPTION *Options,
IN UINT32 Count,
IN BOOLEAN IsRequest,
IN UINT16 Operation,
IN MTFTP6_EXT_OPTION_INFO *ExtInfo
);
/**
Go through the packet to fill the options array with the start
addresses of each MTFTP option name/value pair.
@@ -109,13 +107,12 @@ Mtftp6ParseExtensionOption (
**/
EFI_STATUS
Mtftp6ParsePacketOption (
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *Count,
IN EFI_MTFTP6_OPTION *Options OPTIONAL
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *Count,
IN EFI_MTFTP6_OPTION *Options OPTIONAL
);
/**
Go through the packet, generate option list array and fill it
by the result of parse options.
@@ -137,10 +134,10 @@ Mtftp6ParsePacketOption (
**/
EFI_STATUS
Mtftp6ParseStart (
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *OptionCount,
OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *OptionCount,
OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
);
#endif

View File

@@ -9,7 +9,6 @@
#include "Mtftp6Impl.h"
/**
Build and send a ACK packet for download.
@@ -23,13 +22,13 @@
**/
EFI_STATUS
Mtftp6RrqSendAck (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 BlockNum
IN MTFTP6_INSTANCE *Instance,
IN UINT16 BlockNum
)
{
EFI_MTFTP6_PACKET *Ack;
NET_BUF *Packet;
EFI_STATUS Status;
EFI_MTFTP6_PACKET *Ack;
NET_BUF *Packet;
EFI_STATUS Status;
Status = EFI_SUCCESS;
@@ -42,20 +41,20 @@ Mtftp6RrqSendAck (
return EFI_OUT_OF_RESOURCES;
}
Ack = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (
Packet,
sizeof (EFI_MTFTP6_ACK_HEADER),
FALSE
);
Ack = (EFI_MTFTP6_PACKET *)NetbufAllocSpace (
Packet,
sizeof (EFI_MTFTP6_ACK_HEADER),
FALSE
);
ASSERT (Ack != NULL);
Ack->Ack.OpCode = HTONS (EFI_MTFTP6_OPCODE_ACK);
Ack->Ack.Block[0] = HTONS (BlockNum);
Ack->Ack.OpCode = HTONS (EFI_MTFTP6_OPCODE_ACK);
Ack->Ack.Block[0] = HTONS (BlockNum);
//
// Reset current retry count of the instance.
//
Instance->CurRetry = 0;
Instance->CurRetry = 0;
Instance->LastPacket = Packet;
Status = Mtftp6TransmitPacket (Instance, Packet);
@@ -66,7 +65,6 @@ Mtftp6RrqSendAck (
return Status;
}
/**
Deliver the received data block to the user, which can be saved
in the user provide buffer or through the CheckPacket callback.
@@ -85,19 +83,19 @@ Mtftp6RrqSendAck (
**/
EFI_STATUS
Mtftp6RrqSaveBlock (
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket
)
{
EFI_MTFTP6_TOKEN *Token;
EFI_STATUS Status;
UINT16 Block;
UINT64 Start;
UINT32 DataLen;
UINT64 BlockCounter;
BOOLEAN Completed;
EFI_MTFTP6_TOKEN *Token;
EFI_STATUS Status;
UINT16 Block;
UINT64 Start;
UINT32 DataLen;
UINT64 BlockCounter;
BOOLEAN Completed;
Completed = FALSE;
Token = Instance->Token;
@@ -108,7 +106,7 @@ Mtftp6RrqSaveBlock (
// This is the last block, save the block num
//
if (DataLen < Instance->BlkSize) {
Completed = TRUE;
Completed = TRUE;
Instance->LastBlk = Block;
Mtftp6SetLastBlockNum (&Instance->BlkList, Block);
}
@@ -132,7 +130,7 @@ Mtftp6RrqSaveBlock (
//
// Callback to the check packet routine with the received packet.
//
Status = Token->CheckPacket (&Instance->Mtftp6, Token, (UINT16) Len, Packet);
Status = Token->CheckPacket (&Instance->Mtftp6, Token, (UINT16)Len, Packet);
if (EFI_ERROR (Status)) {
//
@@ -147,7 +145,7 @@ Mtftp6RrqSaveBlock (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_ILLEGAL_OPERATION,
(UINT8 *) "User aborted download"
(UINT8 *)"User aborted download"
);
return EFI_ABORTED;
@@ -155,10 +153,9 @@ Mtftp6RrqSaveBlock (
}
if (Token->Buffer != NULL) {
Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize);
if (Start + DataLen <= Token->BufferSize) {
CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);
CopyMem ((UINT8 *)Token->Buffer + Start, Packet->Data.Data, DataLen);
//
// Update the file size when received the last block
//
@@ -185,7 +182,7 @@ Mtftp6RrqSaveBlock (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_DISK_FULL,
(UINT8 *) "User provided memory block is too small"
(UINT8 *)"User provided memory block is too small"
);
return EFI_BUFFER_TOO_SMALL;
@@ -195,7 +192,6 @@ Mtftp6RrqSaveBlock (
return EFI_SUCCESS;
}
/**
Process the received data packets. It will save the block
then send back an ACK if it is active.
@@ -214,16 +210,16 @@ Mtftp6RrqSaveBlock (
**/
EFI_STATUS
Mtftp6RrqHandleData (
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
)
{
EFI_STATUS Status;
UINT16 BlockNum;
INTN Expected;
EFI_STATUS Status;
UINT16 BlockNum;
INTN Expected;
*IsCompleted = FALSE;
Status = EFI_SUCCESS;
@@ -248,7 +244,7 @@ Mtftp6RrqHandleData (
//
// If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535).
//
return Mtftp6RrqSendAck (Instance, (UINT16) (Expected - 1));
return Mtftp6RrqSendAck (Instance, (UINT16)(Expected - 1));
}
Status = Mtftp6RrqSaveBlock (Instance, Packet, Len, UdpPacket);
@@ -260,7 +256,7 @@ Mtftp6RrqHandleData (
//
// Record the total received and saved block number.
//
Instance->TotalBlock ++;
Instance->TotalBlock++;
//
// Reset the passive client's timer whenever it received a valid data packet.
@@ -277,7 +273,7 @@ Mtftp6RrqHandleData (
//
Expected = Mtftp6GetNextBlockNum (&Instance->BlkList);
if (Instance->IsMaster || Expected < 0) {
if (Instance->IsMaster || (Expected < 0)) {
if (Expected < 0) {
//
// If we are passive client, then the just received Block maybe
@@ -287,10 +283,10 @@ Mtftp6RrqHandleData (
//
BlockNum = Instance->LastBlk;
*IsCompleted = TRUE;
} else {
BlockNum = (UINT16) (Expected - 1);
BlockNum = (UINT16)(Expected - 1);
}
//
// Free the received packet before send new packet in ReceiveNotify,
// since the udpio might need to be reconfigured.
@@ -298,7 +294,7 @@ Mtftp6RrqHandleData (
NetbufFree (*UdpPacket);
*UdpPacket = NULL;
if (Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock) || Expected < 0) {
if ((Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock)) || (Expected < 0)) {
Status = Mtftp6RrqSendAck (Instance, BlockNum);
}
}
@@ -306,7 +302,6 @@ Mtftp6RrqHandleData (
return Status;
}
/**
Validate whether the options received in the server's OACK packet is valid.
The options are valid only if:
@@ -325,9 +320,9 @@ Mtftp6RrqHandleData (
**/
BOOLEAN
Mtftp6RrqOackValid (
IN MTFTP6_INSTANCE *Instance,
IN MTFTP6_EXT_OPTION_INFO *ReplyInfo,
IN MTFTP6_EXT_OPTION_INFO *RequestInfo
IN MTFTP6_INSTANCE *Instance,
IN MTFTP6_EXT_OPTION_INFO *ReplyInfo,
IN MTFTP6_EXT_OPTION_INFO *RequestInfo
)
{
//
@@ -344,7 +339,8 @@ Mtftp6RrqOackValid (
if ((((ReplyInfo->BitMap & MTFTP6_OPT_BLKSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||
(((ReplyInfo->BitMap & MTFTP6_OPT_WINDOWSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||
(((ReplyInfo->BitMap & MTFTP6_OPT_TIMEOUT_BIT) != 0) && (ReplyInfo->Timeout != RequestInfo->Timeout))
) {
)
{
return FALSE;
}
@@ -354,12 +350,12 @@ Mtftp6RrqOackValid (
// change the setting.
//
if (((ReplyInfo->BitMap & MTFTP6_OPT_MCAST_BIT) != 0) && !NetIp6IsUnspecifiedAddr (&Instance->McastIp)) {
if (!NetIp6IsUnspecifiedAddr (&ReplyInfo->McastIp) && CompareMem (
&ReplyInfo->McastIp,
&Instance->McastIp,
sizeof (EFI_IPv6_ADDRESS)
) != 0) {
if (!NetIp6IsUnspecifiedAddr (&ReplyInfo->McastIp) && (CompareMem (
&ReplyInfo->McastIp,
&Instance->McastIp,
sizeof (EFI_IPv6_ADDRESS)
) != 0))
{
return FALSE;
}
@@ -371,7 +367,6 @@ Mtftp6RrqOackValid (
return TRUE;
}
/**
Configure Udp6Io to receive a packet from a multicast address.
@@ -385,19 +380,19 @@ Mtftp6RrqOackValid (
EFI_STATUS
EFIAPI
Mtftp6RrqConfigMcastUdpIo (
IN UDP_IO *McastIo,
IN VOID *Context
IN UDP_IO *McastIo,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA *Udp6Cfg;
EFI_IPv6_ADDRESS Group;
MTFTP6_INSTANCE *Instance;
EFI_STATUS Status;
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA *Udp6Cfg;
EFI_IPv6_ADDRESS Group;
MTFTP6_INSTANCE *Instance;
Udp6 = McastIo->Protocol.Udp6;
Udp6Cfg = &(McastIo->Config.Udp6);
Instance = (MTFTP6_INSTANCE *) Context;
Instance = (MTFTP6_INSTANCE *)Context;
//
// Set the configure data for the mcast Udp6Io.
@@ -437,7 +432,6 @@ Mtftp6RrqConfigMcastUdpIo (
return Udp6->Groups (Udp6, TRUE, &Group);
}
/**
Process the OACK packet for Rrq.
@@ -455,22 +449,22 @@ Mtftp6RrqConfigMcastUdpIo (
**/
EFI_STATUS
Mtftp6RrqHandleOack (
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
)
{
EFI_MTFTP6_OPTION *Options;
UINT32 Count;
MTFTP6_EXT_OPTION_INFO ExtInfo;
EFI_STATUS Status;
INTN Expected;
EFI_UDP6_PROTOCOL *Udp6;
EFI_MTFTP6_OPTION *Options;
UINT32 Count;
MTFTP6_EXT_OPTION_INFO ExtInfo;
EFI_STATUS Status;
INTN Expected;
EFI_UDP6_PROTOCOL *Udp6;
*IsCompleted = FALSE;
Options = NULL;
Options = NULL;
//
// If already started the master download, don't change the
@@ -479,7 +473,7 @@ Mtftp6RrqHandleOack (
Expected = Mtftp6GetNextBlockNum (&Instance->BlkList);
ASSERT (Expected != -1);
if (Instance->IsMaster && Expected != 1) {
if (Instance->IsMaster && (Expected != 1)) {
return EFI_SUCCESS;
}
@@ -493,6 +487,7 @@ Mtftp6RrqHandleOack (
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (Options != NULL);
//
@@ -517,7 +512,7 @@ Mtftp6RrqHandleOack (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_ILLEGAL_OPERATION,
(UINT8 *) "Malformatted OACK packet"
(UINT8 *)"Malformatted OACK packet"
);
}
@@ -525,7 +520,6 @@ Mtftp6RrqHandleOack (
}
if ((ExtInfo.BitMap & MTFTP6_OPT_MCAST_BIT) != 0) {
//
// Save the multicast info. Always update the Master, only update the
// multicast IP address, block size, window size, timeoute at the first time. If IP
@@ -534,7 +528,7 @@ Mtftp6RrqHandleOack (
Instance->IsMaster = ExtInfo.IsMaster;
if (NetIp6IsUnspecifiedAddr (&Instance->McastIp)) {
if (NetIp6IsUnspecifiedAddr (&ExtInfo.McastIp) || ExtInfo.McastPort == 0) {
if (NetIp6IsUnspecifiedAddr (&ExtInfo.McastIp) || (ExtInfo.McastPort == 0)) {
//
// Free the received packet before send new packet in ReceiveNotify,
// since the udpio might need to be reconfigured.
@@ -547,7 +541,7 @@ Mtftp6RrqHandleOack (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_ILLEGAL_OPERATION,
(UINT8 *) "Illegal multicast setting"
(UINT8 *)"Illegal multicast setting"
);
return EFI_TFTP_ERROR;
@@ -562,7 +556,7 @@ Mtftp6RrqHandleOack (
sizeof (EFI_IP_ADDRESS)
);
Instance->McastPort = ExtInfo.McastPort;
Instance->McastPort = ExtInfo.McastPort;
if (Instance->McastUdpIo == NULL) {
Instance->McastUdpIo = UdpIoCreateIo (
Instance->Service->Controller,
@@ -575,7 +569,7 @@ Mtftp6RrqHandleOack (
Status = gBS->OpenProtocol (
Instance->McastUdpIo->UdpHandle,
&gEfiUdp6ProtocolGuid,
(VOID **) &Udp6,
(VOID **)&Udp6,
Instance->Service->Image,
Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@@ -612,7 +606,7 @@ Mtftp6RrqHandleOack (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_ACCESS_VIOLATION,
(UINT8 *) "Failed to create socket to receive multicast packet"
(UINT8 *)"Failed to create socket to receive multicast packet"
);
return Status;
@@ -633,9 +627,7 @@ Mtftp6RrqHandleOack (
Instance->Timeout = ExtInfo.Timeout;
}
}
} else {
Instance->IsMaster = TRUE;
if (ExtInfo.BlkSize != 0) {
@@ -661,10 +653,9 @@ Mtftp6RrqHandleOack (
// Send an ACK to (Expected - 1) which is 0 for unicast download,
// or tell the server we want to receive the Expected block.
//
return Mtftp6RrqSendAck (Instance, (UINT16) (Expected - 1));
return Mtftp6RrqSendAck (Instance, (UINT16)(Expected - 1));
}
/**
The packet process callback for Mtftp6 download.
@@ -677,22 +668,22 @@ Mtftp6RrqHandleOack (
VOID
EFIAPI
Mtftp6RrqInput (
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
)
{
MTFTP6_INSTANCE *Instance;
EFI_MTFTP6_PACKET *Packet;
BOOLEAN IsCompleted;
BOOLEAN IsMcast;
EFI_STATUS Status;
UINT16 Opcode;
UINT32 TotalNum;
UINT32 Len;
MTFTP6_INSTANCE *Instance;
EFI_MTFTP6_PACKET *Packet;
BOOLEAN IsCompleted;
BOOLEAN IsMcast;
EFI_STATUS Status;
UINT16 Opcode;
UINT32 TotalNum;
UINT32 Len;
Instance = (MTFTP6_INSTANCE *) Context;
Instance = (MTFTP6_INSTANCE *)Context;
NET_CHECK_SIGNATURE (Instance, MTFTP6_INSTANCE_SIGNATURE);
@@ -723,7 +714,8 @@ Mtftp6RrqInput (
Ip6Swap128 (&UdpEpt->LocalAddr.v6),
&Instance->McastIp,
sizeof (EFI_IPv6_ADDRESS)
) == 0) {
) == 0)
{
IsMcast = TRUE;
} else {
IsMcast = FALSE;
@@ -763,10 +755,9 @@ Mtftp6RrqInput (
goto ON_EXIT;
}
NetbufCopy (UdpPacket, 0, Len, (UINT8 *) Packet);
NetbufCopy (UdpPacket, 0, Len, (UINT8 *)Packet);
} else {
Packet = (EFI_MTFTP6_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);
Packet = (EFI_MTFTP6_PACKET *)NetbufGetByte (UdpPacket, 0, NULL);
ASSERT (Packet != NULL);
}
@@ -777,13 +768,13 @@ Mtftp6RrqInput (
// if CheckPacket returns an EFI_ERROR code.
//
if ((Instance->Token->CheckPacket != NULL) &&
(Opcode == EFI_MTFTP6_OPCODE_OACK || Opcode == EFI_MTFTP6_OPCODE_ERROR)
) {
((Opcode == EFI_MTFTP6_OPCODE_OACK) || (Opcode == EFI_MTFTP6_OPCODE_ERROR))
)
{
Status = Instance->Token->CheckPacket (
&Instance->Mtftp6,
Instance->Token,
(UINT16) Len,
(UINT16)Len,
Packet
);
@@ -804,7 +795,7 @@ Mtftp6RrqInput (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,
(UINT8 *) "User aborted the transfer"
(UINT8 *)"User aborted the transfer"
);
}
@@ -817,44 +808,46 @@ Mtftp6RrqInput (
// Switch the process routines by the operation code.
//
switch (Opcode) {
case EFI_MTFTP6_OPCODE_DATA:
if ((Len > (UINT32) (MTFTP6_DATA_HEAD_LEN + Instance->BlkSize)) || (Len < (UINT32) MTFTP6_DATA_HEAD_LEN)) {
goto ON_EXIT;
}
//
// Handle the data packet of Rrq.
//
Status = Mtftp6RrqHandleData (
Instance,
Packet,
Len,
&UdpPacket,
&IsCompleted
);
break;
case EFI_MTFTP6_OPCODE_DATA:
if ((Len > (UINT32)(MTFTP6_DATA_HEAD_LEN + Instance->BlkSize)) || (Len < (UINT32)MTFTP6_DATA_HEAD_LEN)) {
goto ON_EXIT;
}
case EFI_MTFTP6_OPCODE_OACK:
if (IsMcast || Len <= MTFTP6_OPCODE_LEN) {
goto ON_EXIT;
}
//
// Handle the Oack packet of Rrq.
//
Status = Mtftp6RrqHandleOack (
Instance,
Packet,
Len,
&UdpPacket,
&IsCompleted
);
break;
//
// Handle the data packet of Rrq.
//
Status = Mtftp6RrqHandleData (
Instance,
Packet,
Len,
&UdpPacket,
&IsCompleted
);
break;
default:
//
// Drop and return error if received error message.
//
Status = EFI_TFTP_ERROR;
break;
case EFI_MTFTP6_OPCODE_OACK:
if (IsMcast || (Len <= MTFTP6_OPCODE_LEN)) {
goto ON_EXIT;
}
//
// Handle the Oack packet of Rrq.
//
Status = Mtftp6RrqHandleOack (
Instance,
Packet,
Len,
&UdpPacket,
&IsCompleted
);
break;
default:
//
// Drop and return error if received error message.
//
Status = EFI_TFTP_ERROR;
break;
}
ON_EXIT:
@@ -862,12 +855,14 @@ ON_EXIT:
// Free the resources, then if !EFI_ERROR (Status), restart the
// receive, otherwise end the session.
//
if (Packet != NULL && TotalNum > 1) {
if ((Packet != NULL) && (TotalNum > 1)) {
FreePool (Packet);
}
if (UdpPacket != NULL) {
NetbufFree (UdpPacket);
}
if (!EFI_ERROR (Status) && !IsCompleted) {
if (IsMcast) {
Status = UdpIoRecvDatagram (
@@ -885,6 +880,7 @@ ON_EXIT:
);
}
}
//
// Clean up the current session if failed to continue.
//
@@ -893,7 +889,6 @@ ON_EXIT:
}
}
/**
Start the Mtftp6 instance to download. It first initializes some
of the internal states, then builds and sends an RRQ request packet.
@@ -908,11 +903,11 @@ ON_EXIT:
**/
EFI_STATUS
Mtftp6RrqStart (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// The valid block number range are [1, 0xffff]. For example:
@@ -939,4 +934,3 @@ Mtftp6RrqStart (
0
);
}

View File

@@ -9,7 +9,6 @@
#include "Mtftp6Impl.h"
/**
Allocate a MTFTP block range, then init it to the range of [Start, End].
@@ -21,11 +20,11 @@
**/
MTFTP6_BLOCK_RANGE *
Mtftp6AllocateRange (
IN UINT16 Start,
IN UINT16 End
IN UINT16 Start,
IN UINT16 End
)
{
MTFTP6_BLOCK_RANGE *Range;
MTFTP6_BLOCK_RANGE *Range;
Range = AllocateZeroPool (sizeof (MTFTP6_BLOCK_RANGE));
@@ -34,14 +33,13 @@ Mtftp6AllocateRange (
}
InitializeListHead (&Range->Link);
Range->Start = Start;
Range->End = End;
Range->Bound = End;
Range->Start = Start;
Range->End = End;
Range->Bound = End;
return Range;
}
/**
Initialize the block range for either RRQ or WRQ. RRQ and WRQ have
different requirements for Start and End. For example, during startup,
@@ -64,12 +62,12 @@ Mtftp6AllocateRange (
**/
EFI_STATUS
Mtftp6InitBlockRange (
IN LIST_ENTRY *Head,
IN UINT16 Start,
IN UINT16 End
IN LIST_ENTRY *Head,
IN UINT16 Start,
IN UINT16 End
)
{
MTFTP6_BLOCK_RANGE *Range;
MTFTP6_BLOCK_RANGE *Range;
Range = Mtftp6AllocateRange (Start, End);
@@ -81,7 +79,6 @@ Mtftp6InitBlockRange (
return EFI_SUCCESS;
}
/**
Get the first valid block number on the range list.
@@ -93,7 +90,7 @@ Mtftp6InitBlockRange (
**/
INTN
Mtftp6GetNextBlockNum (
IN LIST_ENTRY *Head
IN LIST_ENTRY *Head
)
{
MTFTP6_BLOCK_RANGE *Range;
@@ -106,7 +103,6 @@ Mtftp6GetNextBlockNum (
return Range->Start;
}
/**
Set the last block number of the block range list. It
removes all the blocks after the Last. MTFTP initialize the
@@ -120,11 +116,11 @@ Mtftp6GetNextBlockNum (
**/
VOID
Mtftp6SetLastBlockNum (
IN LIST_ENTRY *Head,
IN UINT16 Last
IN LIST_ENTRY *Head,
IN UINT16 Last
)
{
MTFTP6_BLOCK_RANGE *Range;
MTFTP6_BLOCK_RANGE *Range;
//
// Iterate from the tail to head to remove the block number
@@ -142,11 +138,11 @@ Mtftp6SetLastBlockNum (
if (Range->End > Last) {
Range->End = Last;
}
return ;
return;
}
}
/**
Remove the block number from the block range list.
@@ -162,18 +158,17 @@ Mtftp6SetLastBlockNum (
**/
EFI_STATUS
Mtftp6RemoveBlockNum (
IN LIST_ENTRY *Head,
IN UINT16 Num,
IN BOOLEAN Completed,
OUT UINT64 *BlockCounter
IN LIST_ENTRY *Head,
IN UINT16 Num,
IN BOOLEAN Completed,
OUT UINT64 *BlockCounter
)
{
MTFTP6_BLOCK_RANGE *Range;
MTFTP6_BLOCK_RANGE *NewRange;
LIST_ENTRY *Entry;
MTFTP6_BLOCK_RANGE *Range;
MTFTP6_BLOCK_RANGE *NewRange;
LIST_ENTRY *Entry;
NET_LIST_FOR_EACH (Entry, Head) {
//
// Each block represents a hole [Start, End] in the file,
// skip to the first range with End >= Num
@@ -202,7 +197,6 @@ Mtftp6RemoveBlockNum (
//
if (Range->Start > Num) {
return EFI_NOT_FOUND;
} else if (Range->Start == Num) {
Range->Start++;
@@ -214,7 +208,7 @@ Mtftp6RemoveBlockNum (
// wrap to zero, because this is the simplest to implement. Here we choose
// this solution.
//
*BlockCounter = Num;
*BlockCounter = Num;
if (Range->Round > 0) {
*BlockCounter += Range->Bound + MultU64x32 (Range->Round - 1, (UINT32)(Range->Bound + 1)) + 1;
@@ -222,7 +216,7 @@ Mtftp6RemoveBlockNum (
if (Range->Start > Range->Bound) {
Range->Start = 0;
Range->Round ++;
Range->Round++;
}
if ((Range->Start > Range->End) || Completed) {
@@ -231,12 +225,11 @@ Mtftp6RemoveBlockNum (
}
return EFI_SUCCESS;
} else {
if (Range->End == Num) {
Range->End--;
} else {
NewRange = Mtftp6AllocateRange ((UINT16) (Num + 1), (UINT16) Range->End);
NewRange = Mtftp6AllocateRange ((UINT16)(Num + 1), (UINT16)Range->End);
if (NewRange == NULL) {
return EFI_OUT_OF_RESOURCES;
@@ -253,7 +246,6 @@ Mtftp6RemoveBlockNum (
return EFI_NOT_FOUND;
}
/**
Configure the opened Udp6 instance until the corresponding Ip6 instance
has been configured.
@@ -268,17 +260,17 @@ Mtftp6RemoveBlockNum (
**/
EFI_STATUS
Mtftp6GetMapping (
IN UDP_IO *UdpIo,
IN EFI_UDP6_CONFIG_DATA *UdpCfgData
IN UDP_IO *UdpIo,
IN EFI_UDP6_CONFIG_DATA *UdpCfgData
)
{
EFI_IP6_MODE_DATA Ip6Mode;
EFI_UDP6_PROTOCOL *Udp6;
EFI_STATUS Status;
EFI_EVENT Event;
EFI_IP6_MODE_DATA Ip6Mode;
EFI_UDP6_PROTOCOL *Udp6;
EFI_STATUS Status;
EFI_EVENT Event;
Event = NULL;
Udp6 = UdpIo->Protocol.Udp6;
Event = NULL;
Udp6 = UdpIo->Protocol.Udp6;
//
// Create a timer to check whether the Ip6 instance configured or not.
@@ -307,7 +299,6 @@ Mtftp6GetMapping (
// Check the Ip6 mode data till timeout.
//
while (EFI_ERROR (gBS->CheckEvent (Event))) {
Udp6->Poll (Udp6);
Status = Udp6->GetModeData (Udp6, NULL, &Ip6Mode, NULL, NULL);
@@ -337,7 +328,7 @@ Mtftp6GetMapping (
FreePool (Ip6Mode.IcmpTypeList);
}
if (Ip6Mode.IsConfigured) {
if (Ip6Mode.IsConfigured) {
//
// Continue to configure the Udp6 instance.
//
@@ -357,7 +348,6 @@ ON_EXIT:
return Status;
}
/**
The dummy configure routine for create a new Udp6 Io.
@@ -370,14 +360,13 @@ ON_EXIT:
EFI_STATUS
EFIAPI
Mtftp6ConfigDummyUdpIo (
IN UDP_IO *UdpIo,
IN VOID *Context
IN UDP_IO *UdpIo,
IN VOID *Context
)
{
return EFI_SUCCESS;
}
/**
The configure routine for Mtftp6 instance to transmit/receive.
@@ -394,16 +383,16 @@ Mtftp6ConfigDummyUdpIo (
**/
EFI_STATUS
Mtftp6ConfigUdpIo (
IN UDP_IO *UdpIo,
IN EFI_IPv6_ADDRESS *ServerIp,
IN UINT16 ServerPort,
IN EFI_IPv6_ADDRESS *LocalIp,
IN UINT16 LocalPort
IN UDP_IO *UdpIo,
IN EFI_IPv6_ADDRESS *ServerIp,
IN UINT16 ServerPort,
IN EFI_IPv6_ADDRESS *LocalIp,
IN UINT16 LocalPort
)
{
EFI_STATUS Status;
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA *Udp6Cfg;
EFI_STATUS Status;
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA *Udp6Cfg;
Udp6 = UdpIo->Protocol.Udp6;
Udp6Cfg = &(UdpIo->Config.Udp6);
@@ -441,14 +430,12 @@ Mtftp6ConfigUdpIo (
Status = Udp6->Configure (Udp6, Udp6Cfg);
if (Status == EFI_NO_MAPPING) {
return Mtftp6GetMapping (UdpIo, Udp6Cfg);
}
return Status;
}
/**
Build and transmit the request packet for the Mtftp6 instance.
@@ -462,30 +449,30 @@ Mtftp6ConfigUdpIo (
**/
EFI_STATUS
Mtftp6SendRequest (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
)
{
EFI_MTFTP6_PACKET *Packet;
EFI_MTFTP6_OPTION *Options;
EFI_MTFTP6_TOKEN *Token;
RETURN_STATUS Status;
NET_BUF *Nbuf;
UINT8 *Mode;
UINT8 *Cur;
UINTN Index;
UINT32 BufferLength;
UINTN FileNameLength;
UINTN ModeLength;
UINTN OptionStrLength;
UINTN ValueStrLength;
EFI_MTFTP6_PACKET *Packet;
EFI_MTFTP6_OPTION *Options;
EFI_MTFTP6_TOKEN *Token;
RETURN_STATUS Status;
NET_BUF *Nbuf;
UINT8 *Mode;
UINT8 *Cur;
UINTN Index;
UINT32 BufferLength;
UINTN FileNameLength;
UINTN ModeLength;
UINTN OptionStrLength;
UINTN ValueStrLength;
Token = Instance->Token;
Options = Token->OptionList;
Mode = Token->ModeStr;
if (Mode == NULL) {
Mode = (UINT8 *) "octet";
Mode = (UINT8 *)"octet";
}
//
@@ -507,14 +494,14 @@ Mtftp6SendRequest (
//
// Compute the size of new Mtftp6 packet.
//
FileNameLength = AsciiStrLen ((CHAR8 *) Token->Filename);
ModeLength = AsciiStrLen ((CHAR8 *) Mode);
BufferLength = (UINT32) FileNameLength + (UINT32) ModeLength + 4;
FileNameLength = AsciiStrLen ((CHAR8 *)Token->Filename);
ModeLength = AsciiStrLen ((CHAR8 *)Mode);
BufferLength = (UINT32)FileNameLength + (UINT32)ModeLength + 4;
for (Index = 0; Index < Token->OptionCount; Index++) {
OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr);
ValueStrLength = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr);
BufferLength += (UINT32) OptionStrLength + (UINT32) ValueStrLength + 2;
OptionStrLength = AsciiStrLen ((CHAR8 *)Options[Index].OptionStr);
ValueStrLength = AsciiStrLen ((CHAR8 *)Options[Index].ValueStr);
BufferLength += (UINT32)OptionStrLength + (UINT32)ValueStrLength + 2;
}
//
@@ -527,39 +514,38 @@ Mtftp6SendRequest (
//
// Copy the opcode, filename and mode into packet.
//
Packet = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, BufferLength, FALSE);
Packet = (EFI_MTFTP6_PACKET *)NetbufAllocSpace (Nbuf, BufferLength, FALSE);
ASSERT (Packet != NULL);
Packet->OpCode = HTONS (Operation);
BufferLength -= sizeof (Packet->OpCode);
Cur = Packet->Rrq.Filename;
Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Token->Filename);
Cur = Packet->Rrq.Filename;
Status = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Token->Filename);
ASSERT_EFI_ERROR (Status);
BufferLength -= (UINT32) (FileNameLength + 1);
Cur += FileNameLength + 1;
Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Mode);
BufferLength -= (UINT32)(FileNameLength + 1);
Cur += FileNameLength + 1;
Status = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Mode);
ASSERT_EFI_ERROR (Status);
BufferLength -= (UINT32) (ModeLength + 1);
Cur += ModeLength + 1;
BufferLength -= (UINT32)(ModeLength + 1);
Cur += ModeLength + 1;
//
// Copy all the extension options into the packet.
//
for (Index = 0; Index < Token->OptionCount; ++Index) {
OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr);
ValueStrLength = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr);
OptionStrLength = AsciiStrLen ((CHAR8 *)Options[Index].OptionStr);
ValueStrLength = AsciiStrLen ((CHAR8 *)Options[Index].ValueStr);
Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].OptionStr);
Status = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Options[Index].OptionStr);
ASSERT_EFI_ERROR (Status);
BufferLength -= (UINT32) (OptionStrLength + 1);
Cur += OptionStrLength + 1;
BufferLength -= (UINT32)(OptionStrLength + 1);
Cur += OptionStrLength + 1;
Status = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].ValueStr);
Status = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Options[Index].ValueStr);
ASSERT_EFI_ERROR (Status);
BufferLength -= (UINT32) (ValueStrLength + 1);
Cur += ValueStrLength + 1;
BufferLength -= (UINT32)(ValueStrLength + 1);
Cur += ValueStrLength + 1;
}
//
@@ -575,7 +561,6 @@ Mtftp6SendRequest (
return Mtftp6TransmitPacket (Instance, Nbuf);
}
/**
Build and send an error packet.
@@ -590,26 +575,26 @@ Mtftp6SendRequest (
**/
EFI_STATUS
Mtftp6SendError (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 ErrCode,
IN UINT8* ErrInfo
IN MTFTP6_INSTANCE *Instance,
IN UINT16 ErrCode,
IN UINT8 *ErrInfo
)
{
NET_BUF *Nbuf;
EFI_MTFTP6_PACKET *TftpError;
UINT32 Len;
NET_BUF *Nbuf;
EFI_MTFTP6_PACKET *TftpError;
UINT32 Len;
//
// Allocate a packet then copy the data.
//
Len = (UINT32) (AsciiStrLen ((CHAR8 *) ErrInfo) + sizeof (EFI_MTFTP6_ERROR_HEADER));
Len = (UINT32)(AsciiStrLen ((CHAR8 *)ErrInfo) + sizeof (EFI_MTFTP6_ERROR_HEADER));
Nbuf = NetbufAlloc (Len);
if (Nbuf == NULL) {
return EFI_OUT_OF_RESOURCES;
}
TftpError = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, Len, FALSE);
TftpError = (EFI_MTFTP6_PACKET *)NetbufAllocSpace (Nbuf, Len, FALSE);
if (TftpError == NULL) {
NetbufFree (Nbuf);
@@ -619,7 +604,7 @@ Mtftp6SendError (
TftpError->OpCode = HTONS (EFI_MTFTP6_OPCODE_ERROR);
TftpError->Error.ErrorCode = HTONS (ErrCode);
AsciiStrCpyS ((CHAR8 *) TftpError->Error.ErrorMessage, AsciiStrLen ((CHAR8 *) ErrInfo) + 1 , (CHAR8 *) ErrInfo);
AsciiStrCpyS ((CHAR8 *)TftpError->Error.ErrorMessage, AsciiStrLen ((CHAR8 *)ErrInfo) + 1, (CHAR8 *)ErrInfo);
//
// Save the packet buf for retransmit
@@ -634,7 +619,6 @@ Mtftp6SendError (
return Mtftp6TransmitPacket (Instance, Nbuf);
}
/**
The callback function called when the packet is transmitted.
@@ -647,17 +631,16 @@ Mtftp6SendError (
VOID
EFIAPI
Mtftp6OnPacketSent (
IN NET_BUF *Packet,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
IN NET_BUF *Packet,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
)
{
NetbufFree (Packet);
*(BOOLEAN *) Context = TRUE;
*(BOOLEAN *)Context = TRUE;
}
/**
Send the packet for the Mtftp6 instance.
@@ -670,18 +653,18 @@ Mtftp6OnPacketSent (
**/
EFI_STATUS
Mtftp6TransmitPacket (
IN MTFTP6_INSTANCE *Instance,
IN NET_BUF *Packet
IN MTFTP6_INSTANCE *Instance,
IN NET_BUF *Packet
)
{
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA Udp6CfgData;
EFI_STATUS Status;
UINT16 *Temp;
UINT16 Value;
UINT16 OpCode;
EFI_UDP6_PROTOCOL *Udp6;
EFI_UDP6_CONFIG_DATA Udp6CfgData;
EFI_STATUS Status;
UINT16 *Temp;
UINT16 Value;
UINT16 OpCode;
ZeroMem (&Udp6CfgData, sizeof(EFI_UDP6_CONFIG_DATA));
ZeroMem (&Udp6CfgData, sizeof (EFI_UDP6_CONFIG_DATA));
Udp6 = Instance->UdpIo->Protocol.Udp6;
//
@@ -689,13 +672,13 @@ Mtftp6TransmitPacket (
//
Instance->PacketToLive = Instance->IsMaster ? Instance->Timeout : (Instance->Timeout * 2);
Temp = (UINT16 *) NetbufGetByte (Packet, 0, NULL);
Temp = (UINT16 *)NetbufGetByte (Packet, 0, NULL);
ASSERT (Temp != NULL);
Value = *Temp;
OpCode = NTOHS (Value);
if (OpCode == EFI_MTFTP6_OPCODE_RRQ || OpCode == EFI_MTFTP6_OPCODE_DIR || OpCode == EFI_MTFTP6_OPCODE_WRQ) {
if ((OpCode == EFI_MTFTP6_OPCODE_RRQ) || (OpCode == EFI_MTFTP6_OPCODE_DIR) || (OpCode == EFI_MTFTP6_OPCODE_WRQ)) {
//
// For the Rrq, Dir, Wrq requests of the operation, configure the Udp6Io as
// (serverip, 69, localip, localport) to send.
@@ -786,7 +769,6 @@ Mtftp6TransmitPacket (
}
if (Udp6CfgData.RemotePort != Instance->ServerDataPort) {
Status = Udp6->Configure (Udp6, NULL);
if (EFI_ERROR (Status)) {
@@ -838,7 +820,6 @@ Mtftp6TransmitPacket (
return Status;
}
/**
Check packet for GetInfo callback routine.
@@ -856,32 +837,32 @@ Mtftp6TransmitPacket (
EFI_STATUS
EFIAPI
Mtftp6CheckPacket (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 PacketLen,
IN EFI_MTFTP6_PACKET *Packet
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 PacketLen,
IN EFI_MTFTP6_PACKET *Packet
)
{
MTFTP6_GETINFO_CONTEXT *Context;
UINT16 OpCode;
MTFTP6_GETINFO_CONTEXT *Context;
UINT16 OpCode;
Context = (MTFTP6_GETINFO_CONTEXT *) Token->Context;
Context = (MTFTP6_GETINFO_CONTEXT *)Token->Context;
OpCode = NTOHS (Packet->OpCode);
//
// Set the GetInfo's return status according to the OpCode.
//
switch (OpCode) {
case EFI_MTFTP6_OPCODE_ERROR:
Context->Status = EFI_TFTP_ERROR;
break;
case EFI_MTFTP6_OPCODE_ERROR:
Context->Status = EFI_TFTP_ERROR;
break;
case EFI_MTFTP6_OPCODE_OACK:
Context->Status = EFI_SUCCESS;
break;
case EFI_MTFTP6_OPCODE_OACK:
Context->Status = EFI_SUCCESS;
break;
default:
Context->Status = EFI_PROTOCOL_ERROR;
default:
Context->Status = EFI_PROTOCOL_ERROR;
}
//
@@ -901,7 +882,6 @@ Mtftp6CheckPacket (
return EFI_ABORTED;
}
/**
Clean up the current Mtftp6 operation.
@@ -911,13 +891,13 @@ Mtftp6CheckPacket (
**/
VOID
Mtftp6OperationClean (
IN MTFTP6_INSTANCE *Instance,
IN EFI_STATUS Result
IN MTFTP6_INSTANCE *Instance,
IN EFI_STATUS Result
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
MTFTP6_BLOCK_RANGE *Block;
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
MTFTP6_BLOCK_RANGE *Block;
//
// Clean up the current token and event.
@@ -927,6 +907,7 @@ Mtftp6OperationClean (
if (Instance->Token->Event != NULL) {
gBS->SignalEvent (Instance->Token->Event);
}
Instance->Token = NULL;
}
@@ -985,7 +966,6 @@ Mtftp6OperationClean (
Instance->IsMaster = TRUE;
}
/**
Start the Mtftp6 instance to perform the operation, such as read file,
write file, and read directory.
@@ -1002,37 +982,39 @@ Mtftp6OperationClean (
**/
EFI_STATUS
Mtftp6OperationStart (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 OpCode
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 OpCode
)
{
MTFTP6_INSTANCE *Instance;
EFI_STATUS Status;
MTFTP6_INSTANCE *Instance;
EFI_STATUS Status;
if (This == NULL ||
Token == NULL ||
Token->Filename == NULL ||
(Token->OptionCount != 0 && Token->OptionList == NULL) ||
(Token->OverrideData != NULL && !NetIp6IsValidUnicast (&Token->OverrideData->ServerIp))
) {
if ((This == NULL) ||
(Token == NULL) ||
(Token->Filename == NULL) ||
((Token->OptionCount != 0) && (Token->OptionList == NULL)) ||
((Token->OverrideData != NULL) && !NetIp6IsValidUnicast (&Token->OverrideData->ServerIp))
)
{
return EFI_INVALID_PARAMETER;
}
//
// At least define one method to collect the data for download.
//
if ((OpCode == EFI_MTFTP6_OPCODE_RRQ || OpCode == EFI_MTFTP6_OPCODE_DIR) &&
Token->Buffer == NULL &&
Token->CheckPacket == NULL
) {
if (((OpCode == EFI_MTFTP6_OPCODE_RRQ) || (OpCode == EFI_MTFTP6_OPCODE_DIR)) &&
(Token->Buffer == NULL) &&
(Token->CheckPacket == NULL)
)
{
return EFI_INVALID_PARAMETER;
}
//
// At least define one method to provide the data for upload.
//
if (OpCode == EFI_MTFTP6_OPCODE_WRQ && Token->Buffer == NULL && Token->PacketNeeded == NULL) {
if ((OpCode == EFI_MTFTP6_OPCODE_WRQ) && (Token->Buffer == NULL) && (Token->PacketNeeded == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -1055,7 +1037,6 @@ Mtftp6OperationStart (
// Parse the extension options in the request packet.
//
if (Token->OptionCount != 0) {
Status = Mtftp6ParseExtensionOption (
Token->OptionList,
Token->OptionCount,
@@ -1072,12 +1053,12 @@ Mtftp6OperationStart (
//
// Initialize runtime data from config data or override data.
//
Instance->Token = Token;
Instance->ServerCmdPort = Instance->Config->InitialServerPort;
Instance->ServerDataPort = 0;
Instance->MaxRetry = Instance->Config->TryCount;
Instance->Timeout = Instance->Config->TimeoutValue;
Instance->IsMaster = TRUE;
Instance->Token = Token;
Instance->ServerCmdPort = Instance->Config->InitialServerPort;
Instance->ServerDataPort = 0;
Instance->MaxRetry = Instance->Config->TryCount;
Instance->Timeout = Instance->Config->TimeoutValue;
Instance->IsMaster = TRUE;
CopyMem (
&Instance->ServerIp,
@@ -1103,15 +1084,19 @@ Mtftp6OperationStart (
if (Instance->ServerCmdPort == 0) {
Instance->ServerCmdPort = MTFTP6_DEFAULT_SERVER_CMD_PORT;
}
if (Instance->BlkSize == 0) {
Instance->BlkSize = MTFTP6_DEFAULT_BLK_SIZE;
}
if (Instance->WindowSize == 0) {
Instance->WindowSize = MTFTP6_DEFAULT_WINDOWSIZE;
}
if (Instance->MaxRetry == 0) {
Instance->MaxRetry = MTFTP6_DEFAULT_MAX_RETRY;
}
if (Instance->Timeout == 0) {
Instance->Timeout = MTFTP6_DEFAULT_TIMEOUT;
}
@@ -1122,21 +1107,21 @@ Mtftp6OperationStart (
// Switch the routines by the operation code.
//
switch (OpCode) {
case EFI_MTFTP6_OPCODE_RRQ:
Status = Mtftp6RrqStart (Instance, OpCode);
break;
case EFI_MTFTP6_OPCODE_RRQ:
Status = Mtftp6RrqStart (Instance, OpCode);
break;
case EFI_MTFTP6_OPCODE_DIR:
Status = Mtftp6RrqStart (Instance, OpCode);
break;
case EFI_MTFTP6_OPCODE_DIR:
Status = Mtftp6RrqStart (Instance, OpCode);
break;
case EFI_MTFTP6_OPCODE_WRQ:
Status = Mtftp6WrqStart (Instance, OpCode);
break;
case EFI_MTFTP6_OPCODE_WRQ:
Status = Mtftp6WrqStart (Instance, OpCode);
break;
default:
Status = EFI_DEVICE_ERROR;
goto ON_ERROR;
default:
Status = EFI_DEVICE_ERROR;
goto ON_ERROR;
}
if (EFI_ERROR (Status)) {
@@ -1152,6 +1137,7 @@ Mtftp6OperationStart (
while (Token->Status == EFI_NOT_READY) {
This->Poll (This);
}
return Token->Status;
}
@@ -1165,7 +1151,6 @@ ON_ERROR:
return Status;
}
/**
The timer ticking routine for the Mtftp6 instance.
@@ -1176,25 +1161,24 @@ ON_ERROR:
VOID
EFIAPI
Mtftp6OnTimerTick (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
EFI_MTFTP6_TOKEN *Token;
EFI_STATUS Status;
MTFTP6_SERVICE *Service;
MTFTP6_INSTANCE *Instance;
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
EFI_MTFTP6_TOKEN *Token;
EFI_STATUS Status;
Service = (MTFTP6_SERVICE *) Context;
Service = (MTFTP6_SERVICE *)Context;
//
// Iterate through all the children of the Mtftp service instance. Time
// out the packet. If maximum retries reached, clean the session up.
//
NET_LIST_FOR_EACH_SAFE (Entry, Next, &Service->Children) {
Instance = NET_LIST_USER_STRUCT (Entry, MTFTP6_INSTANCE, Link);
if (Instance->Token == NULL) {
@@ -1217,10 +1201,10 @@ Mtftp6OnTimerTick (
if (EFI_ERROR (Status)) {
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,
(UINT8 *) "User aborted the transfer in time out"
);
Instance,
EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,
(UINT8 *)"User aborted the transfer in time out"
);
Mtftp6OperationClean (Instance, EFI_ABORTED);
continue;
}

View File

@@ -16,14 +16,13 @@
// the holes are filled in, then the download or upload has completed.
//
typedef struct {
LIST_ENTRY Link;
INTN Start;
INTN End;
INTN Round;
INTN Bound;
LIST_ENTRY Link;
INTN Start;
INTN End;
INTN Round;
INTN Bound;
} MTFTP6_BLOCK_RANGE;
/**
Initialize the block range for either RRQ or WRQ. RRQ and WRQ have
different requirements for Start and End. For example, during startup,
@@ -46,12 +45,11 @@ typedef struct {
**/
EFI_STATUS
Mtftp6InitBlockRange (
IN LIST_ENTRY *Head,
IN UINT16 Start,
IN UINT16 End
IN LIST_ENTRY *Head,
IN UINT16 Start,
IN UINT16 End
);
/**
Get the first valid block number on the range list.
@@ -63,10 +61,9 @@ Mtftp6InitBlockRange (
**/
INTN
Mtftp6GetNextBlockNum (
IN LIST_ENTRY *Head
IN LIST_ENTRY *Head
);
/**
Set the last block number of the block range list. It
removes all the blocks after the Last. MTFTP initialize the
@@ -80,11 +77,10 @@ Mtftp6GetNextBlockNum (
**/
VOID
Mtftp6SetLastBlockNum (
IN LIST_ENTRY *Head,
IN UINT16 Last
IN LIST_ENTRY *Head,
IN UINT16 Last
);
/**
Remove the block number from the block range list.
@@ -100,13 +96,12 @@ Mtftp6SetLastBlockNum (
**/
EFI_STATUS
Mtftp6RemoveBlockNum (
IN LIST_ENTRY *Head,
IN UINT16 Num,
IN BOOLEAN Completed,
OUT UINT64 *BlockCounter
IN LIST_ENTRY *Head,
IN UINT16 Num,
IN BOOLEAN Completed,
OUT UINT64 *BlockCounter
);
/**
Build and transmit the request packet for the Mtftp6 instance.
@@ -120,11 +115,10 @@ Mtftp6RemoveBlockNum (
**/
EFI_STATUS
Mtftp6SendRequest (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
);
/**
Build and send an error packet.
@@ -139,12 +133,11 @@ Mtftp6SendRequest (
**/
EFI_STATUS
Mtftp6SendError (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 ErrCode,
IN UINT8* ErrInfo
IN MTFTP6_INSTANCE *Instance,
IN UINT16 ErrCode,
IN UINT8 *ErrInfo
);
/**
Send the packet for the Mtftp6 instance.
@@ -157,11 +150,10 @@ Mtftp6SendError (
**/
EFI_STATUS
Mtftp6TransmitPacket (
IN MTFTP6_INSTANCE *Instance,
IN NET_BUF *Packet
IN MTFTP6_INSTANCE *Instance,
IN NET_BUF *Packet
);
/**
Check packet for GetInfo callback routine.
@@ -177,13 +169,12 @@ Mtftp6TransmitPacket (
EFI_STATUS
EFIAPI
Mtftp6CheckPacket (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 PacketLen,
IN EFI_MTFTP6_PACKET *Packet
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 PacketLen,
IN EFI_MTFTP6_PACKET *Packet
);
/**
The dummy configure routine for create a new Udp6 Io.
@@ -196,11 +187,10 @@ Mtftp6CheckPacket (
EFI_STATUS
EFIAPI
Mtftp6ConfigDummyUdpIo (
IN UDP_IO *UdpIo,
IN VOID *Context
IN UDP_IO *UdpIo,
IN VOID *Context
);
/**
The configure routine for the Mtftp6 instance to transmit/receive.
@@ -217,14 +207,13 @@ Mtftp6ConfigDummyUdpIo (
**/
EFI_STATUS
Mtftp6ConfigUdpIo (
IN UDP_IO *UdpIo,
IN EFI_IPv6_ADDRESS *ServerIp,
IN UINT16 ServerPort,
IN EFI_IPv6_ADDRESS *LocalIp,
IN UINT16 LocalPort
IN UDP_IO *UdpIo,
IN EFI_IPv6_ADDRESS *ServerIp,
IN UINT16 ServerPort,
IN EFI_IPv6_ADDRESS *LocalIp,
IN UINT16 LocalPort
);
/**
Clean up the current Mtftp6 operation.
@@ -234,11 +223,10 @@ Mtftp6ConfigUdpIo (
**/
VOID
Mtftp6OperationClean (
IN MTFTP6_INSTANCE *Instance,
IN EFI_STATUS Result
IN MTFTP6_INSTANCE *Instance,
IN EFI_STATUS Result
);
/**
Start the Mtftp6 instance to perform the operation, such as read file,
write file, and read directory.
@@ -255,12 +243,11 @@ Mtftp6OperationClean (
**/
EFI_STATUS
Mtftp6OperationStart (
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 OpCode
IN EFI_MTFTP6_PROTOCOL *This,
IN EFI_MTFTP6_TOKEN *Token,
IN UINT16 OpCode
);
/**
The timer ticking routine for the Mtftp6 instance.
@@ -271,11 +258,10 @@ Mtftp6OperationStart (
VOID
EFIAPI
Mtftp6OnTimerTick (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
);
/**
The packet process callback for Mtftp6 upload.
@@ -288,13 +274,12 @@ Mtftp6OnTimerTick (
VOID
EFIAPI
Mtftp6WrqInput (
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
);
/**
Start the Mtftp6 instance to upload. It will first init some states,
then send the WRQ request packet, and start to receive the packet.
@@ -308,11 +293,10 @@ Mtftp6WrqInput (
**/
EFI_STATUS
Mtftp6WrqStart (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
);
/**
The packet process callback for Mtftp6 download.
@@ -325,13 +309,12 @@ Mtftp6WrqStart (
VOID
EFIAPI
Mtftp6RrqInput (
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
);
/**
Start the Mtftp6 instance to download. It first initializes some
of the internal states then builds and sends an RRQ request packet.
@@ -346,8 +329,8 @@ Mtftp6RrqInput (
**/
EFI_STATUS
Mtftp6RrqStart (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
);
#endif

View File

@@ -9,8 +9,6 @@
#include "Mtftp6Impl.h"
/**
Build and send a Mtftp6 data packet for upload.
@@ -24,17 +22,17 @@
**/
EFI_STATUS
Mtftp6WrqSendBlock (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 BlockNum
IN MTFTP6_INSTANCE *Instance,
IN UINT16 BlockNum
)
{
EFI_MTFTP6_PACKET *Packet;
EFI_MTFTP6_TOKEN *Token;
NET_BUF *UdpPacket;
EFI_STATUS Status;
UINT16 DataLen;
UINT8 *DataBuf;
UINT64 Start;
EFI_MTFTP6_PACKET *Packet;
EFI_MTFTP6_TOKEN *Token;
NET_BUF *UdpPacket;
EFI_STATUS Status;
UINT16 DataLen;
UINT8 *DataBuf;
UINT64 Start;
//
// Allocate net buffer to create data packet.
@@ -45,11 +43,11 @@ Mtftp6WrqSendBlock (
return EFI_OUT_OF_RESOURCES;
}
Packet = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (
UdpPacket,
MTFTP6_DATA_HEAD_LEN,
FALSE
);
Packet = (EFI_MTFTP6_PACKET *)NetbufAllocSpace (
UdpPacket,
MTFTP6_DATA_HEAD_LEN,
FALSE
);
ASSERT (Packet != NULL);
Packet->Data.OpCode = HTONS (EFI_MTFTP6_OPCODE_DATA);
@@ -65,34 +63,34 @@ Mtftp6WrqSendBlock (
Start = MultU64x32 (BlockNum - 1, Instance->BlkSize);
if (Token->BufferSize < Start + Instance->BlkSize) {
DataLen = (UINT16) (Token->BufferSize - Start);
DataLen = (UINT16)(Token->BufferSize - Start);
Instance->LastBlk = BlockNum;
Mtftp6SetLastBlockNum (&Instance->BlkList, BlockNum);
}
if (DataLen > 0) {
NetbufAllocSpace (UdpPacket, DataLen, FALSE);
CopyMem (Packet->Data.Data, (UINT8 *) Token->Buffer + Start, DataLen);
CopyMem (Packet->Data.Data, (UINT8 *)Token->Buffer + Start, DataLen);
}
} else {
//
// Get data from PacketNeeded
//
DataBuf = NULL;
Status = Token->PacketNeeded (&Instance->Mtftp6, Token, &DataLen, (VOID*) &DataBuf);
Status = Token->PacketNeeded (&Instance->Mtftp6, Token, &DataLen, (VOID *)&DataBuf);
if (EFI_ERROR (Status) || (DataLen > Instance->BlkSize)) {
if (DataBuf != NULL) {
gBS->FreePool (DataBuf);
}
//
// The received packet has already been freed.
//
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,
(UINT8 *) "User aborted the transfer"
(UINT8 *)"User aborted the transfer"
);
return EFI_ABORTED;
@@ -118,7 +116,6 @@ Mtftp6WrqSendBlock (
return Mtftp6TransmitPacket (Instance, UdpPacket);
}
/**
Function to handle received ACK packet. If the ACK number matches the
expected block number, with more data pending, send the next
@@ -138,16 +135,16 @@ Mtftp6WrqSendBlock (
**/
EFI_STATUS
Mtftp6WrqHandleAck (
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
)
{
UINT16 AckNum;
INTN Expected;
UINT64 BlockCounter;
UINT16 AckNum;
INTN Expected;
UINT64 BlockCounter;
*IsCompleted = FALSE;
AckNum = NTOHS (Packet->Ack.Block[0]);
@@ -182,7 +179,6 @@ Mtftp6WrqHandleAck (
ASSERT (Instance->LastBlk >= 1);
*IsCompleted = TRUE;
return EFI_SUCCESS;
} else {
//
// Free the received packet before send new packet in ReceiveNotify,
@@ -196,7 +192,7 @@ Mtftp6WrqHandleAck (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,
(UINT8 *) "Block number rolls back, not supported, try blksize option"
(UINT8 *)"Block number rolls back, not supported, try blksize option"
);
return EFI_TFTP_ERROR;
@@ -210,10 +206,9 @@ Mtftp6WrqHandleAck (
NetbufFree (*UdpPacket);
*UdpPacket = NULL;
return Mtftp6WrqSendBlock (Instance, (UINT16) Expected);
return Mtftp6WrqSendBlock (Instance, (UINT16)Expected);
}
/**
Check whether the received OACK is valid. The OACK is valid
only if:
@@ -231,8 +226,8 @@ Mtftp6WrqHandleAck (
**/
BOOLEAN
Mtftp6WrqOackValid (
IN MTFTP6_EXT_OPTION_INFO *ReplyInfo,
IN MTFTP6_EXT_OPTION_INFO *RequestInfo
IN MTFTP6_EXT_OPTION_INFO *ReplyInfo,
IN MTFTP6_EXT_OPTION_INFO *RequestInfo
)
{
//
@@ -248,15 +243,14 @@ Mtftp6WrqOackValid (
//
if ((((ReplyInfo->BitMap & MTFTP6_OPT_BLKSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||
(((ReplyInfo->BitMap & MTFTP6_OPT_TIMEOUT_BIT) != 0) && (ReplyInfo->Timeout != RequestInfo->Timeout))
) {
)
{
return FALSE;
}
return TRUE;
}
/**
Process the OACK packet for Wrq.
@@ -274,22 +268,22 @@ Mtftp6WrqOackValid (
**/
EFI_STATUS
Mtftp6WrqHandleOack (
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
IN MTFTP6_INSTANCE *Instance,
IN EFI_MTFTP6_PACKET *Packet,
IN UINT32 Len,
OUT NET_BUF **UdpPacket,
OUT BOOLEAN *IsCompleted
)
{
EFI_MTFTP6_OPTION *Options;
UINT32 Count;
MTFTP6_EXT_OPTION_INFO ExtInfo;
EFI_MTFTP6_PACKET Dummy;
EFI_STATUS Status;
INTN Expected;
EFI_MTFTP6_OPTION *Options;
UINT32 Count;
MTFTP6_EXT_OPTION_INFO ExtInfo;
EFI_MTFTP6_PACKET Dummy;
EFI_STATUS Status;
INTN Expected;
*IsCompleted = FALSE;
Options = NULL;
Options = NULL;
//
// Ignore the OACK if already started the upload
@@ -310,11 +304,12 @@ Mtftp6WrqHandleOack (
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (Options != NULL);
Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, Instance->Operation, &ExtInfo);
if (EFI_ERROR(Status) || !Mtftp6WrqOackValid (&ExtInfo, &Instance->ExtInfo)) {
if (EFI_ERROR (Status) || !Mtftp6WrqOackValid (&ExtInfo, &Instance->ExtInfo)) {
//
// Don't send a MTFTP error packet when out of resource, it can
// only make it worse.
@@ -332,7 +327,7 @@ Mtftp6WrqHandleOack (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_ILLEGAL_OPERATION,
(UINT8 *) "Malformatted OACK packet"
(UINT8 *)"Malformatted OACK packet"
);
}
@@ -363,7 +358,6 @@ Mtftp6WrqHandleOack (
);
}
/**
The packet process callback for Mtftp6 upload.
@@ -376,21 +370,21 @@ Mtftp6WrqHandleOack (
VOID
EFIAPI
Mtftp6WrqInput (
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
IN NET_BUF *UdpPacket,
IN UDP_END_POINT *UdpEpt,
IN EFI_STATUS IoStatus,
IN VOID *Context
)
{
MTFTP6_INSTANCE *Instance;
EFI_MTFTP6_PACKET *Packet;
BOOLEAN IsCompleted;
EFI_STATUS Status;
UINT32 TotalNum;
UINT32 Len;
UINT16 Opcode;
MTFTP6_INSTANCE *Instance;
EFI_MTFTP6_PACKET *Packet;
BOOLEAN IsCompleted;
EFI_STATUS Status;
UINT32 TotalNum;
UINT32 Len;
UINT16 Opcode;
Instance = (MTFTP6_INSTANCE *) Context;
Instance = (MTFTP6_INSTANCE *)Context;
NET_CHECK_SIGNATURE (Instance, MTFTP6_INSTANCE_SIGNATURE);
@@ -439,10 +433,9 @@ Mtftp6WrqInput (
goto ON_EXIT;
}
NetbufCopy (UdpPacket, 0, Len, (UINT8 *) Packet);
NetbufCopy (UdpPacket, 0, Len, (UINT8 *)Packet);
} else {
Packet = (EFI_MTFTP6_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);
Packet = (EFI_MTFTP6_PACKET *)NetbufGetByte (UdpPacket, 0, NULL);
ASSERT (Packet != NULL);
}
@@ -452,14 +445,14 @@ Mtftp6WrqInput (
// Callback to the user's CheckPacket if provided. Abort the transmission
// if CheckPacket returns an EFI_ERROR code.
//
if (Instance->Token->CheckPacket != NULL &&
(Opcode == EFI_MTFTP6_OPCODE_OACK || Opcode == EFI_MTFTP6_OPCODE_ERROR)
) {
if ((Instance->Token->CheckPacket != NULL) &&
((Opcode == EFI_MTFTP6_OPCODE_OACK) || (Opcode == EFI_MTFTP6_OPCODE_ERROR))
)
{
Status = Instance->Token->CheckPacket (
&Instance->Mtftp6,
Instance->Token,
(UINT16) Len,
(UINT16)Len,
Packet
);
@@ -480,7 +473,7 @@ Mtftp6WrqInput (
Mtftp6SendError (
Instance,
EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,
(UINT8 *) "User aborted the transfer"
(UINT8 *)"User aborted the transfer"
);
}
@@ -493,32 +486,34 @@ Mtftp6WrqInput (
// Switch the process routines by the operation code.
//
switch (Opcode) {
case EFI_MTFTP6_OPCODE_ACK:
if (Len != MTFTP6_OPCODE_LEN + MTFTP6_BLKNO_LEN) {
goto ON_EXIT;
}
//
// Handle the Ack packet of Wrq.
//
Status = Mtftp6WrqHandleAck (Instance, Packet, Len, &UdpPacket, &IsCompleted);
break;
case EFI_MTFTP6_OPCODE_ACK:
if (Len != MTFTP6_OPCODE_LEN + MTFTP6_BLKNO_LEN) {
goto ON_EXIT;
}
case EFI_MTFTP6_OPCODE_OACK:
if (Len <= MTFTP6_OPCODE_LEN) {
goto ON_EXIT;
}
//
// Handle the Oack packet of Wrq.
//
Status = Mtftp6WrqHandleOack (Instance, Packet, Len, &UdpPacket, &IsCompleted);
break;
//
// Handle the Ack packet of Wrq.
//
Status = Mtftp6WrqHandleAck (Instance, Packet, Len, &UdpPacket, &IsCompleted);
break;
default:
//
// Drop and return eror if received error message.
//
Status = EFI_TFTP_ERROR;
break;
case EFI_MTFTP6_OPCODE_OACK:
if (Len <= MTFTP6_OPCODE_LEN) {
goto ON_EXIT;
}
//
// Handle the Oack packet of Wrq.
//
Status = Mtftp6WrqHandleOack (Instance, Packet, Len, &UdpPacket, &IsCompleted);
break;
default:
//
// Drop and return eror if received error message.
//
Status = EFI_TFTP_ERROR;
break;
}
ON_EXIT:
@@ -526,7 +521,7 @@ ON_EXIT:
// Free the resources, then if !EFI_ERROR (Status) and not completed,
// restart the receive, otherwise end the session.
//
if (Packet != NULL && TotalNum > 1) {
if ((Packet != NULL) && (TotalNum > 1)) {
FreePool (Packet);
}
@@ -542,6 +537,7 @@ ON_EXIT:
0
);
}
//
// Clean up the current session if failed to continue.
//
@@ -550,7 +546,6 @@ ON_EXIT:
}
}
/**
Start the Mtftp6 instance to upload. It will first init some states,
then send the WRQ request packet, and start to receive the packet.
@@ -564,11 +559,11 @@ ON_EXIT:
**/
EFI_STATUS
Mtftp6WrqStart (
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
IN MTFTP6_INSTANCE *Instance,
IN UINT16 Operation
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// The valid block number range are [0, 0xffff]. For example:
@@ -595,4 +590,3 @@ Mtftp6WrqStart (
0
);
}