NetworkPkg: Convert the UNIX to DOS end of line format

Convert the UNIX to DOS end of line format.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18326 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jiaxin Wu
2015-08-27 01:07:31 +00:00
committed by jiaxinwu
parent 85d21c18fd
commit d933e70a97
18 changed files with 5602 additions and 5602 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,139 +1,139 @@
/** @file /** @file
Declaration of the boot file download function. Declaration of the boot file download function.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#ifndef __EFI_HTTP_BOOT_HTTP_H__ #ifndef __EFI_HTTP_BOOT_HTTP_H__
#define __EFI_HTTP_BOOT_HTTP_H__ #define __EFI_HTTP_BOOT_HTTP_H__
#define HTTP_BOOT_REQUEST_TIMEOUT 5000 // 5 seconds in uints of millisecond. #define HTTP_BOOT_REQUEST_TIMEOUT 5000 // 5 seconds in uints of millisecond.
#define HTTP_BOOT_BLOCK_SIZE 1024 #define HTTP_BOOT_BLOCK_SIZE 1024
#define HTTP_FIELD_NAME_USER_AGENT "User-Agent" #define HTTP_FIELD_NAME_USER_AGENT "User-Agent"
#define HTTP_FIELD_NAME_HOST "Host" #define HTTP_FIELD_NAME_HOST "Host"
#define HTTP_FIELD_NAME_ACCEPT "Accept" #define HTTP_FIELD_NAME_ACCEPT "Accept"
#define HTTP_USER_AGENT_EFI_HTTP_BOOT "UefiHttpBoot/1.0" #define HTTP_USER_AGENT_EFI_HTTP_BOOT "UefiHttpBoot/1.0"
// //
// Record the data length and start address of a data block. // Record the data length and start address of a data block.
// //
typedef struct { typedef struct {
LIST_ENTRY Link; // Link to the EntityDataList in HTTP_BOOT_CACHE_CONTENT LIST_ENTRY Link; // Link to the EntityDataList in HTTP_BOOT_CACHE_CONTENT
UINT8 *Block; // If NULL, the data is in previous data block. UINT8 *Block; // If NULL, the data is in previous data block.
UINT8 *DataStart; // Point to somewhere in the Block UINT8 *DataStart; // Point to somewhere in the Block
UINTN DataLength; UINTN DataLength;
} HTTP_BOOT_ENTITY_DATA; } HTTP_BOOT_ENTITY_DATA;
// //
// Structure for a cache item // Structure for a cache item
// //
typedef struct { typedef struct {
LIST_ENTRY Link; // Link to the CacheList in driver's private data. LIST_ENTRY Link; // Link to the CacheList in driver's private data.
EFI_HTTP_REQUEST_DATA *RequestData; EFI_HTTP_REQUEST_DATA *RequestData;
HTTP_IO_RESOPNSE_DATA *ResponseData; // Not include any message-body data. HTTP_IO_RESOPNSE_DATA *ResponseData; // Not include any message-body data.
UINTN EntityLength; UINTN EntityLength;
LIST_ENTRY EntityDataList; // Entity data (message-body) LIST_ENTRY EntityDataList; // Entity data (message-body)
} HTTP_BOOT_CACHE_CONTENT; } HTTP_BOOT_CACHE_CONTENT;
// //
// Callback data for HTTP_BODY_PARSER_CALLBACK() // Callback data for HTTP_BODY_PARSER_CALLBACK()
// //
typedef struct { typedef struct {
EFI_STATUS Status; EFI_STATUS Status;
// //
// Cache info. // Cache info.
// //
HTTP_BOOT_CACHE_CONTENT *Cache; HTTP_BOOT_CACHE_CONTENT *Cache;
BOOLEAN NewBlock; BOOLEAN NewBlock;
UINT8 *Block; UINT8 *Block;
// //
// Caller provided buffer to load the file in. // Caller provided buffer to load the file in.
// //
UINTN CopyedSize; UINTN CopyedSize;
UINTN BufferSize; UINTN BufferSize;
UINT8 *Buffer; UINT8 *Buffer;
} HTTP_BOOT_CALLBACK_DATA; } HTTP_BOOT_CALLBACK_DATA;
/** /**
Discover all the boot information for boot file. Discover all the boot information for boot file.
@param[in, out] Private The pointer to the driver's private data. @param[in, out] Private The pointer to the driver's private data.
@retval EFI_SUCCESS Successfully obtained all the boot information . @retval EFI_SUCCESS Successfully obtained all the boot information .
@retval Others Failed to retrieve the boot information. @retval Others Failed to retrieve the boot information.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootDiscoverBootInfo ( HttpBootDiscoverBootInfo (
IN OUT HTTP_BOOT_PRIVATE_DATA *Private IN OUT HTTP_BOOT_PRIVATE_DATA *Private
); );
/** /**
Create a HttpIo instance for the file download. Create a HttpIo instance for the file download.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@retval EFI_SUCCESS Successfully created. @retval EFI_SUCCESS Successfully created.
@retval Others Failed to create HttpIo. @retval Others Failed to create HttpIo.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootCreateHttpIo ( HttpBootCreateHttpIo (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
); );
/** /**
This function download the boot file by using UEFI HTTP protocol. This function download the boot file by using UEFI HTTP protocol.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@param[in] HeaderOnly Only request the response header, it could save a lot of time if @param[in] HeaderOnly Only request the response header, it could save a lot of time if
the caller only want to know the size of the requested file. the caller only want to know the size of the requested file.
@param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return
code of EFI_SUCCESS, the amount of data transferred to code of EFI_SUCCESS, the amount of data transferred to
Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
the size of Buffer required to retrieve the requested file. the size of Buffer required to retrieve the requested file.
@param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL, @param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
then the size of the requested file is returned in then the size of the requested file is returned in
BufferSize. BufferSize.
@retval EFI_SUCCESS The file was loaded. @retval EFI_SUCCESS The file was loaded.
@retval EFI_INVALID_PARAMETER BufferSize is NULL or Buffer Size is not NULL but Buffer is NULL. @retval EFI_INVALID_PARAMETER BufferSize is NULL or Buffer Size is not NULL but Buffer is NULL.
@retval EFI_OUT_OF_RESOURCES Could not allocate needed resources @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
@retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry. @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
BufferSize has been updated with the size needed to complete BufferSize has been updated with the size needed to complete
the request. the request.
@retval Others Unexpected error happened. @retval Others Unexpected error happened.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootGetBootFile ( HttpBootGetBootFile (
IN HTTP_BOOT_PRIVATE_DATA *Private, IN HTTP_BOOT_PRIVATE_DATA *Private,
IN BOOLEAN HeaderOnly, IN BOOLEAN HeaderOnly,
IN OUT UINTN *BufferSize, IN OUT UINTN *BufferSize,
OUT UINT8 *Buffer OUT UINT8 *Buffer
); );
/** /**
Clean up all cached data. Clean up all cached data.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
**/ **/
VOID VOID
HttpBootFreeCacheList ( HttpBootFreeCacheList (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
); );
#endif #endif

View File

@ -1,180 +1,180 @@
/** @file /** @file
Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol. Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "HttpBootDxe.h" #include "HttpBootDxe.h"
/// ///
/// Component Name Protocol instance /// Component Name Protocol instance
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED GLOBAL_REMOVE_IF_UNREFERENCED
EFI_COMPONENT_NAME_PROTOCOL gHttpBootDxeComponentName = { EFI_COMPONENT_NAME_PROTOCOL gHttpBootDxeComponentName = {
(EFI_COMPONENT_NAME_GET_DRIVER_NAME) HttpBootDxeComponentNameGetDriverName, (EFI_COMPONENT_NAME_GET_DRIVER_NAME) HttpBootDxeComponentNameGetDriverName,
(EFI_COMPONENT_NAME_GET_CONTROLLER_NAME)HttpBootDxeComponentNameGetControllerName, (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME)HttpBootDxeComponentNameGetControllerName,
"eng" "eng"
}; };
/// ///
/// Component Name 2 Protocol instance /// Component Name 2 Protocol instance
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED GLOBAL_REMOVE_IF_UNREFERENCED
EFI_COMPONENT_NAME2_PROTOCOL gHttpBootDxeComponentName2 = { EFI_COMPONENT_NAME2_PROTOCOL gHttpBootDxeComponentName2 = {
HttpBootDxeComponentNameGetDriverName, HttpBootDxeComponentNameGetDriverName,
HttpBootDxeComponentNameGetControllerName, HttpBootDxeComponentNameGetControllerName,
"en" "en"
}; };
/// ///
/// Table of driver names /// Table of driver names
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED GLOBAL_REMOVE_IF_UNREFERENCED
EFI_UNICODE_STRING_TABLE mHttpBootDxeDriverNameTable[] = { EFI_UNICODE_STRING_TABLE mHttpBootDxeDriverNameTable[] = {
{ "eng;en", (CHAR16 *)L"UEFI HTTP Boot Driver" }, { "eng;en", (CHAR16 *)L"UEFI HTTP Boot Driver" },
{ NULL, NULL } { NULL, NULL }
}; };
/// ///
/// Table of controller names /// Table of controller names
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED GLOBAL_REMOVE_IF_UNREFERENCED
EFI_UNICODE_STRING_TABLE mHttpBootDxeControllerNameTable[] = { EFI_UNICODE_STRING_TABLE mHttpBootDxeControllerNameTable[] = {
{ "eng;en", (CHAR16 *)L"UEFI Http Boot Controller" }, { "eng;en", (CHAR16 *)L"UEFI Http Boot Controller" },
{ NULL, NULL } { NULL, NULL }
}; };
/** /**
Retrieves a Unicode string that is the user-readable name of the EFI Driver. Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language A pointer to a three-character ISO 639-2 language identifier. @param Language A pointer to a three-character ISO 639-2 language identifier.
This is the language of the driver name that that the caller This is the language of the driver name that that the caller
is requesting, and it must match one of the languages specified is requesting, and it must match one of the languages specified
in SupportedLanguages. The number of languages supported by a in SupportedLanguages. The number of languages supported by a
driver is up to the driver writer. driver is up to the driver writer.
@param DriverName A pointer to the Unicode string to return. This Unicode string @param DriverName A pointer to the Unicode string to return. This Unicode string
is the name of the driver specified by This in the language is the name of the driver specified by This in the language
specified by Language. specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by This @retval EFI_SUCCESS The Unicode string for the Driver specified by This
and the language specified by Language was returned and the language specified by Language was returned
in DriverName. in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL. @retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support the @retval EFI_UNSUPPORTED The driver specified by This does not support the
language specified by Language. language specified by Language.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootDxeComponentNameGetDriverName ( HttpBootDxeComponentNameGetDriverName (
IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_COMPONENT_NAME2_PROTOCOL *This,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
) )
{ {
return LookupUnicodeString2 ( return LookupUnicodeString2 (
Language, Language,
This->SupportedLanguages, This->SupportedLanguages,
mHttpBootDxeDriverNameTable, mHttpBootDxeDriverNameTable,
DriverName, DriverName,
(BOOLEAN) (This != &gHttpBootDxeComponentName2) (BOOLEAN) (This != &gHttpBootDxeComponentName2)
); );
} }
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by an EFI Driver. that is being managed by an EFI Driver.
@param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle The handle of a controller that the driver specified by @param ControllerHandle The handle of a controller that the driver specified by
This is managing. This handle specifies the controller This is managing. This handle specifies the controller
whose name is to be returned. whose name is to be returned.
@param ChildHandle The handle of the child controller to retrieve the name @param ChildHandle The handle of the child controller to retrieve the name
of. This is an optional parameter that may be NULL. It of. This is an optional parameter that may be NULL. It
will be NULL for device drivers. It will also be NULL will be NULL for device drivers. It will also be NULL
for a bus drivers that wish to retrieve the name of the for a bus drivers that wish to retrieve the name of the
bus controller. It will not be NULL for a bus driver bus controller. It will not be NULL for a bus driver
that wishes to retrieve the name of a child controller. that wishes to retrieve the name of a child controller.
@param Language A pointer to a three character ISO 639-2 language @param Language A pointer to a three character ISO 639-2 language
identifier. This is the language of the controller name identifier. This is the language of the controller name
that the caller is requesting, and it must match one that the caller is requesting, and it must match one
of the languages specified in SupportedLanguages. The of the languages specified in SupportedLanguages. The
number of languages supported by a driver is up to the number of languages supported by a driver is up to the
driver writer. driver writer.
@param ControllerName A pointer to the Unicode string to return. This Unicode @param ControllerName A pointer to the Unicode string to return. This Unicode
string is the name of the controller specified by string is the name of the controller specified by
ControllerHandle and ChildHandle in the language specified ControllerHandle and ChildHandle in the language specified
by Language, from the point of view of the driver specified by Language, from the point of view of the driver specified
by This. by This.
@retval EFI_SUCCESS The Unicode string for the user-readable name in the @retval EFI_SUCCESS The Unicode string for the user-readable name in the
language specified by Language for the driver language specified by Language for the driver
specified by This was returned in DriverName. specified by This was returned in DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently managing @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
the controller specified by ControllerHandle and the controller specified by ControllerHandle and
ChildHandle. ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support the @retval EFI_UNSUPPORTED The driver specified by This does not support the
language specified by Language. language specified by Language.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootDxeComponentNameGetControllerName ( HttpBootDxeComponentNameGetControllerName (
IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_COMPONENT_NAME2_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_HANDLE NicHandle; EFI_HANDLE NicHandle;
UINT32 *Id; UINT32 *Id;
if (ControllerHandle == NULL || ChildHandle != NULL) { if (ControllerHandle == NULL || ChildHandle != NULL) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
NicHandle = HttpBootGetNicByIp4Children (ControllerHandle); NicHandle = HttpBootGetNicByIp4Children (ControllerHandle);
if (NicHandle == NULL) { if (NicHandle == NULL) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Try to retrieve the private data by caller ID GUID. // Try to retrieve the private data by caller ID GUID.
// //
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
NicHandle, NicHandle,
&gEfiCallerIdGuid, &gEfiCallerIdGuid,
(VOID **) &Id, (VOID **) &Id,
NULL, NULL,
NULL, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL EFI_OPEN_PROTOCOL_GET_PROTOCOL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
return LookupUnicodeString2 ( return LookupUnicodeString2 (
Language, Language,
This->SupportedLanguages, This->SupportedLanguages,
mHttpBootDxeControllerNameTable, mHttpBootDxeControllerNameTable,
ControllerName, ControllerName,
(BOOLEAN)(This != &gHttpBootDxeComponentName2) (BOOLEAN)(This != &gHttpBootDxeComponentName2)
); );
} }

View File

@ -1,99 +1,99 @@
/** @file /** @file
Declaration of HTTP boot driver's EFI_COMPONENT_NAME_PROTOCOL and Declaration of HTTP boot driver's EFI_COMPONENT_NAME_PROTOCOL and
EFI_COMPONENT_NAME2_PROTOCOL function. EFI_COMPONENT_NAME2_PROTOCOL function.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#ifndef __EFI_UEFI_HTTP_BOOT_COM_NAME_H__ #ifndef __EFI_UEFI_HTTP_BOOT_COM_NAME_H__
#define __EFI_UEFI_HTTP_BOOT_COM_NAME_H__ #define __EFI_UEFI_HTTP_BOOT_COM_NAME_H__
/** /**
Retrieves a Unicode string that is the user-readable name of the EFI Driver. Retrieves a Unicode string that is the user-readable name of the EFI Driver.
@param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language A pointer to a three-character ISO 639-2 language identifier. @param Language A pointer to a three-character ISO 639-2 language identifier.
This is the language of the driver name that that the caller This is the language of the driver name that that the caller
is requesting, and it must match one of the languages specified is requesting, and it must match one of the languages specified
in SupportedLanguages. The number of languages supported by a in SupportedLanguages. The number of languages supported by a
driver is up to the driver writer. driver is up to the driver writer.
@param DriverName A pointer to the Unicode string to return. This Unicode string @param DriverName A pointer to the Unicode string to return. This Unicode string
is the name of the driver specified by This in the language is the name of the driver specified by This in the language
specified by Language. specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by This @retval EFI_SUCCESS The Unicode string for the Driver specified by This
and the language specified by Language was returned and the language specified by Language was returned
in DriverName. in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL. @retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support the @retval EFI_UNSUPPORTED The driver specified by This does not support the
language specified by Language. language specified by Language.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootDxeComponentNameGetDriverName ( HttpBootDxeComponentNameGetDriverName (
IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_COMPONENT_NAME2_PROTOCOL *This,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by an EFI Driver. that is being managed by an EFI Driver.
@param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle The handle of a controller that the driver specified by @param ControllerHandle The handle of a controller that the driver specified by
This is managing. This handle specifies the controller This is managing. This handle specifies the controller
whose name is to be returned. whose name is to be returned.
@param ChildHandle The handle of the child controller to retrieve the name @param ChildHandle The handle of the child controller to retrieve the name
of. This is an optional parameter that may be NULL. It of. This is an optional parameter that may be NULL. It
will be NULL for device drivers. It will also be NULL will be NULL for device drivers. It will also be NULL
for a bus drivers that wish to retrieve the name of the for a bus drivers that wish to retrieve the name of the
bus controller. It will not be NULL for a bus driver bus controller. It will not be NULL for a bus driver
that wishes to retrieve the name of a child controller. that wishes to retrieve the name of a child controller.
@param Language A pointer to a three character ISO 639-2 language @param Language A pointer to a three character ISO 639-2 language
identifier. This is the language of the controller name identifier. This is the language of the controller name
that the caller is requesting, and it must match one that the caller is requesting, and it must match one
of the languages specified in SupportedLanguages. The of the languages specified in SupportedLanguages. The
number of languages supported by a driver is up to the number of languages supported by a driver is up to the
driver writer. driver writer.
@param ControllerName A pointer to the Unicode string to return. This Unicode @param ControllerName A pointer to the Unicode string to return. This Unicode
string is the name of the controller specified by string is the name of the controller specified by
ControllerHandle and ChildHandle in the language specified ControllerHandle and ChildHandle in the language specified
by Language, from the point of view of the driver specified by Language, from the point of view of the driver specified
by This. by This.
@retval EFI_SUCCESS The Unicode string for the user-readable name in the @retval EFI_SUCCESS The Unicode string for the user-readable name in the
language specified by Language for the driver language specified by Language for the driver
specified by This was returned in DriverName. specified by This was returned in DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently managing @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
the controller specified by ControllerHandle and the controller specified by ControllerHandle and
ChildHandle. ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support the @retval EFI_UNSUPPORTED The driver specified by This does not support the
language specified by Language. language specified by Language.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootDxeComponentNameGetControllerName ( HttpBootDxeComponentNameGetControllerName (
IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_COMPONENT_NAME2_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,281 +1,281 @@
/** @file /** @file
Functions declaration related with DHCPv4 for HTTP boot driver. Functions declaration related with DHCPv4 for HTTP boot driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#ifndef __EFI_UEFI_HTTP_BOOT_DHCP4_H__ #ifndef __EFI_UEFI_HTTP_BOOT_DHCP4_H__
#define __EFI_UEFI_HTTP_BOOT_DHCP4_H__ #define __EFI_UEFI_HTTP_BOOT_DHCP4_H__
#define HTTP_BOOT_DHCP4_OPTION_MAX_NUM 16 #define HTTP_BOOT_DHCP4_OPTION_MAX_NUM 16
#define HTTP_BOOT_DHCP4_OPTION_MAX_SIZE 312 #define HTTP_BOOT_DHCP4_OPTION_MAX_SIZE 312
#define HTTP_BOOT_DHCP4_PACKET_MAX_SIZE 1472 #define HTTP_BOOT_DHCP4_PACKET_MAX_SIZE 1472
#define HTTP_BOOT_DHCP4_OPCODE_REQUEST 1 #define HTTP_BOOT_DHCP4_OPCODE_REQUEST 1
#define HTTP_BOOT_DHCP4_OPCODE_REPLY 2 #define HTTP_BOOT_DHCP4_OPCODE_REPLY 2
#define HTTP_BOOT_DHCP4_MSG_TYPE_REQUEST 3 #define HTTP_BOOT_DHCP4_MSG_TYPE_REQUEST 3
#define HTTP_BOOT_DHCP4_MAGIC 0x63538263 // network byte order #define HTTP_BOOT_DHCP4_MAGIC 0x63538263 // network byte order
// //
// Dhcp Options // Dhcp Options
// //
#define HTTP_BOOT_DHCP4_TAG_PAD 0 // Pad Option #define HTTP_BOOT_DHCP4_TAG_PAD 0 // Pad Option
#define HTTP_BOOT_DHCP4_TAG_EOP 255 // End Option #define HTTP_BOOT_DHCP4_TAG_EOP 255 // End Option
#define HTTP_BOOT_DHCP4_TAG_NETMASK 1 // Subnet Mask #define HTTP_BOOT_DHCP4_TAG_NETMASK 1 // Subnet Mask
#define HTTP_BOOT_DHCP4_TAG_TIME_OFFSET 2 // Time Offset from UTC #define HTTP_BOOT_DHCP4_TAG_TIME_OFFSET 2 // Time Offset from UTC
#define HTTP_BOOT_DHCP4_TAG_ROUTER 3 // Router option, #define HTTP_BOOT_DHCP4_TAG_ROUTER 3 // Router option,
#define HTTP_BOOT_DHCP4_TAG_TIME_SERVER 4 // Time Server #define HTTP_BOOT_DHCP4_TAG_TIME_SERVER 4 // Time Server
#define HTTP_BOOT_DHCP4_TAG_NAME_SERVER 5 // Name Server #define HTTP_BOOT_DHCP4_TAG_NAME_SERVER 5 // Name Server
#define HTTP_BOOT_DHCP4_TAG_DNS_SERVER 6 // Domain Name Server #define HTTP_BOOT_DHCP4_TAG_DNS_SERVER 6 // Domain Name Server
#define HTTP_BOOT_DHCP4_TAG_HOSTNAME 12 // Host Name #define HTTP_BOOT_DHCP4_TAG_HOSTNAME 12 // Host Name
#define HTTP_BOOT_DHCP4_TAG_BOOTFILE_LEN 13 // Boot File Size #define HTTP_BOOT_DHCP4_TAG_BOOTFILE_LEN 13 // Boot File Size
#define HTTP_BOOT_DHCP4_TAG_DUMP 14 // Merit Dump File #define HTTP_BOOT_DHCP4_TAG_DUMP 14 // Merit Dump File
#define HTTP_BOOT_DHCP4_TAG_DOMAINNAME 15 // Domain Name #define HTTP_BOOT_DHCP4_TAG_DOMAINNAME 15 // Domain Name
#define HTTP_BOOT_DHCP4_TAG_ROOTPATH 17 // Root path #define HTTP_BOOT_DHCP4_TAG_ROOTPATH 17 // Root path
#define HTTP_BOOT_DHCP4_TAG_EXTEND_PATH 18 // Extensions Path #define HTTP_BOOT_DHCP4_TAG_EXTEND_PATH 18 // Extensions Path
#define HTTP_BOOT_DHCP4_TAG_EMTU 22 // Maximum Datagram Reassembly Size #define HTTP_BOOT_DHCP4_TAG_EMTU 22 // Maximum Datagram Reassembly Size
#define HTTP_BOOT_DHCP4_TAG_TTL 23 // Default IP Time-to-live #define HTTP_BOOT_DHCP4_TAG_TTL 23 // Default IP Time-to-live
#define HTTP_BOOT_DHCP4_TAG_BROADCAST 28 // Broadcast Address #define HTTP_BOOT_DHCP4_TAG_BROADCAST 28 // Broadcast Address
#define HTTP_BOOT_DHCP4_TAG_NIS_DOMAIN 40 // Network Information Service Domain #define HTTP_BOOT_DHCP4_TAG_NIS_DOMAIN 40 // Network Information Service Domain
#define HTTP_BOOT_DHCP4_TAG_NIS_SERVER 41 // Network Information Servers #define HTTP_BOOT_DHCP4_TAG_NIS_SERVER 41 // Network Information Servers
#define HTTP_BOOT_DHCP4_TAG_NTP_SERVER 42 // Network Time Protocol Servers #define HTTP_BOOT_DHCP4_TAG_NTP_SERVER 42 // Network Time Protocol Servers
#define HTTP_BOOT_DHCP4_TAG_VENDOR 43 // Vendor Specific Information #define HTTP_BOOT_DHCP4_TAG_VENDOR 43 // Vendor Specific Information
#define HTTP_BOOT_DHCP4_TAG_REQUEST_IP 50 // Requested IP Address #define HTTP_BOOT_DHCP4_TAG_REQUEST_IP 50 // Requested IP Address
#define HTTP_BOOT_DHCP4_TAG_LEASE 51 // IP Address Lease Time #define HTTP_BOOT_DHCP4_TAG_LEASE 51 // IP Address Lease Time
#define HTTP_BOOT_DHCP4_TAG_OVERLOAD 52 // Option Overload #define HTTP_BOOT_DHCP4_TAG_OVERLOAD 52 // Option Overload
#define HTTP_BOOT_DHCP4_TAG_MSG_TYPE 53 // DHCP Message Type #define HTTP_BOOT_DHCP4_TAG_MSG_TYPE 53 // DHCP Message Type
#define HTTP_BOOT_DHCP4_TAG_SERVER_ID 54 // Server Identifier #define HTTP_BOOT_DHCP4_TAG_SERVER_ID 54 // Server Identifier
#define HTTP_BOOT_DHCP4_TAG_PARA_LIST 55 // Parameter Request List #define HTTP_BOOT_DHCP4_TAG_PARA_LIST 55 // Parameter Request List
#define HTTP_BOOT_DHCP4_TAG_MAXMSG 57 // Maximum DHCP Message Size #define HTTP_BOOT_DHCP4_TAG_MAXMSG 57 // Maximum DHCP Message Size
#define HTTP_BOOT_DHCP4_TAG_T1 58 // Renewal (T1) Time Value #define HTTP_BOOT_DHCP4_TAG_T1 58 // Renewal (T1) Time Value
#define HTTP_BOOT_DHCP4_TAG_T2 59 // Rebinding (T2) Time Value #define HTTP_BOOT_DHCP4_TAG_T2 59 // Rebinding (T2) Time Value
#define HTTP_BOOT_DHCP4_TAG_CLASS_ID 60 // Vendor class identifier #define HTTP_BOOT_DHCP4_TAG_CLASS_ID 60 // Vendor class identifier
#define HTTP_BOOT_DHCP4_TAG_CLIENT_ID 61 // Client-identifier #define HTTP_BOOT_DHCP4_TAG_CLIENT_ID 61 // Client-identifier
#define HTTP_BOOT_DHCP4_TAG_TFTP 66 // TFTP server name #define HTTP_BOOT_DHCP4_TAG_TFTP 66 // TFTP server name
#define HTTP_BOOT_DHCP4_TAG_BOOTFILE 67 // Bootfile name #define HTTP_BOOT_DHCP4_TAG_BOOTFILE 67 // Bootfile name
#define HTTP_BOOT_DHCP4_TAG_ARCH 93 #define HTTP_BOOT_DHCP4_TAG_ARCH 93
#define HTTP_BOOT_DHCP4_TAG_UNDI 94 #define HTTP_BOOT_DHCP4_TAG_UNDI 94
#define HTTP_BOOT_DHCP4_TAG_UUID 97 #define HTTP_BOOT_DHCP4_TAG_UUID 97
#define HTTP_BOOT_DHCP4_OVERLOAD_FILE 1 #define HTTP_BOOT_DHCP4_OVERLOAD_FILE 1
#define HTTP_BOOT_DHCP4_OVERLOAD_SERVER_NAME 2 #define HTTP_BOOT_DHCP4_OVERLOAD_SERVER_NAME 2
/// ///
/// HTTP Tag definition that identifies the processor /// HTTP Tag definition that identifies the processor
/// and programming environment of the client system. /// and programming environment of the client system.
/// These identifiers are defined by IETF: /// These identifiers are defined by IETF:
/// http://www.ietf.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml /// http://www.ietf.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml
/// ///
#if defined (MDE_CPU_IA32) #if defined (MDE_CPU_IA32)
#define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x000F #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x000F
#elif defined (MDE_CPU_X64) #elif defined (MDE_CPU_X64)
#define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0010 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0010
#elif defined (MDE_CPU_ARM) #elif defined (MDE_CPU_ARM)
#define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0012 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0012
#elif defined (MDE_CPU_AARCH64) #elif defined (MDE_CPU_AARCH64)
#define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0013 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0013
#elif defined (MDE_CPU_EBC) #elif defined (MDE_CPU_EBC)
#define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0011 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE 0x0011
#endif #endif
/// DHCP offer types among HTTP boot. /// DHCP offer types among HTTP boot.
/// Dhcp4 and Dhcp6 share this definition, and corresponding /// Dhcp4 and Dhcp6 share this definition, and corresponding
/// relatioinship is as follows: /// relatioinship is as follows:
/// Dhcp4Discover <> Dhcp6Solicit /// Dhcp4Discover <> Dhcp6Solicit
/// Dhcp4Offer <> Dhcp6Advertise /// Dhcp4Offer <> Dhcp6Advertise
/// Dhcp4Request <> Dhcp6Request /// Dhcp4Request <> Dhcp6Request
/// Dhcp4Ack <> DHcp6Reply /// Dhcp4Ack <> DHcp6Reply
/// ///
typedef enum { typedef enum {
// //
// <IP address, IP expressed URI> or // <IP address, IP expressed URI> or
// <IP address, IP expressed URI, Name-server (will be ignored)> // <IP address, IP expressed URI, Name-server (will be ignored)>
// //
HttpOfferTypeDhcpIpUri, HttpOfferTypeDhcpIpUri,
// //
// <IP address, Domain-name expressed URI, Name-server> // <IP address, Domain-name expressed URI, Name-server>
// //
HttpOfferTypeDhcpNameUriDns, HttpOfferTypeDhcpNameUriDns,
// //
// <IP address, Name-server> // <IP address, Name-server>
// //
HttpOfferTypeDhcpDns, HttpOfferTypeDhcpDns,
// //
// <IP address> // <IP address>
// //
HttpOfferTypeDhcpOnly, HttpOfferTypeDhcpOnly,
// //
// <Domain-name expressed URI> or // <Domain-name expressed URI> or
// <Domain-name expressed URI, Name-server (will be ignored)> // <Domain-name expressed URI, Name-server (will be ignored)>
// //
HttpOfferTypeProxyNameUri, HttpOfferTypeProxyNameUri,
// //
// <IP expressed URI> or // <IP expressed URI> or
// <IP expressed URI, Name-server (will be ignored)> // <IP expressed URI, Name-server (will be ignored)>
// //
HttpOfferTypeProxyIpUri, HttpOfferTypeProxyIpUri,
// //
// <IP address, Domain-name expressed URI> // <IP address, Domain-name expressed URI>
// //
HttpOfferTypeDhcpNameUri, HttpOfferTypeDhcpNameUri,
HttpOfferTypeMax HttpOfferTypeMax
} HTTP_BOOT_OFFER_TYPE; } HTTP_BOOT_OFFER_TYPE;
#define HTTP_BOOT_DHCP_RETRIES 4 #define HTTP_BOOT_DHCP_RETRIES 4
#define HTTP_BOOT_OFFER_MAX_NUM 16 #define HTTP_BOOT_OFFER_MAX_NUM 16
// The array index of the DHCP4 option tag interested // The array index of the DHCP4 option tag interested
// //
#define HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE_LEN 0 #define HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE_LEN 0
#define HTTP_BOOT_DHCP4_TAG_INDEX_OVERLOAD 1 #define HTTP_BOOT_DHCP4_TAG_INDEX_OVERLOAD 1
#define HTTP_BOOT_DHCP4_TAG_INDEX_MSG_TYPE 2 #define HTTP_BOOT_DHCP4_TAG_INDEX_MSG_TYPE 2
#define HTTP_BOOT_DHCP4_TAG_INDEX_SERVER_ID 3 #define HTTP_BOOT_DHCP4_TAG_INDEX_SERVER_ID 3
#define HTTP_BOOT_DHCP4_TAG_INDEX_CLASS_ID 4 #define HTTP_BOOT_DHCP4_TAG_INDEX_CLASS_ID 4
#define HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE 5 #define HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE 5
#define HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER 6 #define HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER 6
#define HTTP_BOOT_DHCP4_TAG_INDEX_MAX 7 #define HTTP_BOOT_DHCP4_TAG_INDEX_MAX 7
#pragma pack(1) #pragma pack(1)
typedef struct { typedef struct {
UINT8 ParaList[135]; UINT8 ParaList[135];
} HTTP_BOOT_DHCP4_OPTION_PARA; } HTTP_BOOT_DHCP4_OPTION_PARA;
typedef struct { typedef struct {
UINT16 Size; UINT16 Size;
} HTTP_BOOT_DHCP4_OPTION_MAX_MESG_SIZE; } HTTP_BOOT_DHCP4_OPTION_MAX_MESG_SIZE;
typedef struct { typedef struct {
UINT8 Type; UINT8 Type;
UINT8 MajorVer; UINT8 MajorVer;
UINT8 MinorVer; UINT8 MinorVer;
} HTTP_BOOT_DHCP4_OPTION_UNDI; } HTTP_BOOT_DHCP4_OPTION_UNDI;
typedef struct { typedef struct {
UINT8 Type; UINT8 Type;
} HTTP_BOOT_DHCP4_OPTION_MESG; } HTTP_BOOT_DHCP4_OPTION_MESG;
typedef struct { typedef struct {
UINT16 Type; UINT16 Type;
} HTTP_BOOT_DHCP4_OPTION_ARCH; } HTTP_BOOT_DHCP4_OPTION_ARCH;
typedef struct { typedef struct {
UINT8 ClassIdentifier[11]; UINT8 ClassIdentifier[11];
UINT8 ArchitecturePrefix[5]; UINT8 ArchitecturePrefix[5];
UINT8 ArchitectureType[5]; UINT8 ArchitectureType[5];
UINT8 Lit3[1]; UINT8 Lit3[1];
UINT8 InterfaceName[4]; UINT8 InterfaceName[4];
UINT8 Lit4[1]; UINT8 Lit4[1];
UINT8 UndiMajor[3]; UINT8 UndiMajor[3];
UINT8 UndiMinor[3]; UINT8 UndiMinor[3];
} HTTP_BOOT_DHCP4_OPTION_CLID; } HTTP_BOOT_DHCP4_OPTION_CLID;
typedef struct { typedef struct {
UINT8 Type; UINT8 Type;
UINT8 Guid[16]; UINT8 Guid[16];
} HTTP_BOOT_DHCP4_OPTION_UUID; } HTTP_BOOT_DHCP4_OPTION_UUID;
typedef struct { typedef struct {
UINT16 Type; UINT16 Type;
UINT16 Layer; UINT16 Layer;
} HTTP_BOOT_OPTION_BOOT_ITEM; } HTTP_BOOT_OPTION_BOOT_ITEM;
#pragma pack() #pragma pack()
typedef union { typedef union {
HTTP_BOOT_DHCP4_OPTION_PARA *Para; HTTP_BOOT_DHCP4_OPTION_PARA *Para;
HTTP_BOOT_DHCP4_OPTION_UNDI *Undi; HTTP_BOOT_DHCP4_OPTION_UNDI *Undi;
HTTP_BOOT_DHCP4_OPTION_ARCH *Arch; HTTP_BOOT_DHCP4_OPTION_ARCH *Arch;
HTTP_BOOT_DHCP4_OPTION_CLID *Clid; HTTP_BOOT_DHCP4_OPTION_CLID *Clid;
HTTP_BOOT_DHCP4_OPTION_UUID *Uuid; HTTP_BOOT_DHCP4_OPTION_UUID *Uuid;
HTTP_BOOT_DHCP4_OPTION_MESG *Mesg; HTTP_BOOT_DHCP4_OPTION_MESG *Mesg;
HTTP_BOOT_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize; HTTP_BOOT_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize;
} HTTP_BOOT_DHCP4_OPTION_ENTRY; } HTTP_BOOT_DHCP4_OPTION_ENTRY;
#define GET_NEXT_DHCP_OPTION(Opt) \ #define GET_NEXT_DHCP_OPTION(Opt) \
(EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + \ (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + \
sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1) sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1)
#define GET_OPTION_BUFFER_LEN(Pkt) \ #define GET_OPTION_BUFFER_LEN(Pkt) \
((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4) ((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4)
#define DEFAULT_CLASS_ID_DATA "HTTPClient:Arch:xxxxx:UNDI:003000" #define DEFAULT_CLASS_ID_DATA "HTTPClient:Arch:xxxxx:UNDI:003000"
#define DEFAULT_UNDI_TYPE 1 #define DEFAULT_UNDI_TYPE 1
#define DEFAULT_UNDI_MAJOR 3 #define DEFAULT_UNDI_MAJOR 3
#define DEFAULT_UNDI_MINOR 0 #define DEFAULT_UNDI_MINOR 0
typedef struct { typedef struct {
UINT32 Reserved; UINT32 Reserved;
} HTTP_BOOT_VENDOR_OPTION; } HTTP_BOOT_VENDOR_OPTION;
typedef union { typedef union {
EFI_DHCP4_PACKET Offer; EFI_DHCP4_PACKET Offer;
EFI_DHCP4_PACKET Ack; EFI_DHCP4_PACKET Ack;
UINT8 Buffer[HTTP_BOOT_DHCP4_PACKET_MAX_SIZE]; UINT8 Buffer[HTTP_BOOT_DHCP4_PACKET_MAX_SIZE];
} HTTP_BOOT_DHCP4_PACKET; } HTTP_BOOT_DHCP4_PACKET;
typedef struct { typedef struct {
// //
// URI component // URI component
// //
CHAR8 *Scheme; CHAR8 *Scheme;
CHAR8 *Authority; CHAR8 *Authority;
CHAR8 *Path; CHAR8 *Path;
CHAR8 *Query; CHAR8 *Query;
CHAR8 *Fragment; /// TODO: may not required in HTTP URL CHAR8 *Fragment; /// TODO: may not required in HTTP URL
CHAR8 *RegName; /// Point to somewhere in Authority CHAR8 *RegName; /// Point to somewhere in Authority
BOOLEAN AddrIsOk; BOOLEAN AddrIsOk;
EFI_IP_ADDRESS Address; EFI_IP_ADDRESS Address;
UINT16 Port; UINT16 Port;
} HTTP_BOOT_URI_CONTENT; } HTTP_BOOT_URI_CONTENT;
typedef struct { typedef struct {
HTTP_BOOT_DHCP4_PACKET Packet; HTTP_BOOT_DHCP4_PACKET Packet;
HTTP_BOOT_OFFER_TYPE OfferType; HTTP_BOOT_OFFER_TYPE OfferType;
VOID *UriParser; VOID *UriParser;
EFI_DHCP4_PACKET_OPTION *OptList[HTTP_BOOT_DHCP4_TAG_INDEX_MAX]; EFI_DHCP4_PACKET_OPTION *OptList[HTTP_BOOT_DHCP4_TAG_INDEX_MAX];
} HTTP_BOOT_DHCP4_PACKET_CACHE; } HTTP_BOOT_DHCP4_PACKET_CACHE;
/** /**
Start the D.O.R.A DHCPv4 process to acquire the IPv4 address and other Http boot information. Start the D.O.R.A DHCPv4 process to acquire the IPv4 address and other Http boot information.
@param[in] Private Pointer to HTTP_BOOT private data. @param[in] Private Pointer to HTTP_BOOT private data.
@retval EFI_SUCCESS The D.O.R.A process successfully finished. @retval EFI_SUCCESS The D.O.R.A process successfully finished.
@retval Others Failed to finish the D.O.R.A process. @retval Others Failed to finish the D.O.R.A process.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootDhcp4Dora ( HttpBootDhcp4Dora (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
); );
/** /**
This function will register the default DNS addresses to the network device. This function will register the default DNS addresses to the network device.
@param[in] Private The pointer to HTTP_BOOT_PRIVATE_DATA. @param[in] Private The pointer to HTTP_BOOT_PRIVATE_DATA.
@param[in] DataLength Size of the buffer pointed to by DnsServerData in bytes. @param[in] DataLength Size of the buffer pointed to by DnsServerData in bytes.
@param[in] DnsServerData Point a list of DNS server address in an array @param[in] DnsServerData Point a list of DNS server address in an array
of EFI_IPv4_ADDRESS instances. of EFI_IPv4_ADDRESS instances.
@retval EFI_SUCCESS The DNS configuration has been configured successfully. @retval EFI_SUCCESS The DNS configuration has been configured successfully.
@retval Others Failed to configure the address. @retval Others Failed to configure the address.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootRegisterIp4Dns ( HttpBootRegisterIp4Dns (
IN HTTP_BOOT_PRIVATE_DATA *Private, IN HTTP_BOOT_PRIVATE_DATA *Private,
IN UINTN DataLength, IN UINTN DataLength,
IN VOID *DnsServerData IN VOID *DnsServerData
); );
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,303 +1,303 @@
/** @file /** @file
UEFI HTTP boot driver's private data structure and interfaces declaration. UEFI HTTP boot driver's private data structure and interfaces declaration.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#ifndef __EFI_HTTP_BOOT_DXE_H__ #ifndef __EFI_HTTP_BOOT_DXE_H__
#define __EFI_HTTP_BOOT_DXE_H__ #define __EFI_HTTP_BOOT_DXE_H__
#include <Uefi.h> #include <Uefi.h>
// //
// Libraries // Libraries
// //
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/NetLib.h> #include <Library/NetLib.h>
#include <Library/HttpLib.h> #include <Library/HttpLib.h>
// //
// UEFI Driver Model Protocols // UEFI Driver Model Protocols
// //
#include <Protocol/DriverBinding.h> #include <Protocol/DriverBinding.h>
#include <Protocol/ComponentName2.h> #include <Protocol/ComponentName2.h>
#include <Protocol/ComponentName.h> #include <Protocol/ComponentName.h>
// //
// Consumed Protocols // Consumed Protocols
// //
#include <Protocol/NetworkInterfaceIdentifier.h> #include <Protocol/NetworkInterfaceIdentifier.h>
#include <Protocol/Dhcp4.h> #include <Protocol/Dhcp4.h>
#include <Protocol/Http.h> #include <Protocol/Http.h>
#include <Protocol/Ip4Config2.h> #include <Protocol/Ip4Config2.h>
// //
// Produced Protocols // Produced Protocols
// //
#include <Protocol/LoadFile.h> #include <Protocol/LoadFile.h>
// //
// Driver Version // Driver Version
// //
#define HTTP_BOOT_DXE_VERSION 0xa #define HTTP_BOOT_DXE_VERSION 0xa
// //
// Protocol instances // Protocol instances
// //
extern EFI_DRIVER_BINDING_PROTOCOL gHttpBootDxeDriverBinding; extern EFI_DRIVER_BINDING_PROTOCOL gHttpBootDxeDriverBinding;
extern EFI_COMPONENT_NAME2_PROTOCOL gHttpBootDxeComponentName2; extern EFI_COMPONENT_NAME2_PROTOCOL gHttpBootDxeComponentName2;
extern EFI_COMPONENT_NAME_PROTOCOL gHttpBootDxeComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gHttpBootDxeComponentName;
// //
// Private data structure // Private data structure
// //
typedef struct _HTTP_BOOT_PRIVATE_DATA HTTP_BOOT_PRIVATE_DATA; typedef struct _HTTP_BOOT_PRIVATE_DATA HTTP_BOOT_PRIVATE_DATA;
// //
// Include files with internal function prototypes // Include files with internal function prototypes
// //
#include "HttpBootComponentName.h" #include "HttpBootComponentName.h"
#include "HttpBootDhcp4.h" #include "HttpBootDhcp4.h"
#include "HttpBootImpl.h" #include "HttpBootImpl.h"
#include "HttpBootSupport.h" #include "HttpBootSupport.h"
#include "HttpBootClient.h" #include "HttpBootClient.h"
typedef union { typedef union {
HTTP_BOOT_DHCP4_PACKET_CACHE Dhcp4; HTTP_BOOT_DHCP4_PACKET_CACHE Dhcp4;
} HTTP_BOOT_DHCP_PACKET_CACHE; } HTTP_BOOT_DHCP_PACKET_CACHE;
struct _HTTP_BOOT_PRIVATE_DATA { struct _HTTP_BOOT_PRIVATE_DATA {
UINT32 Signature; UINT32 Signature;
EFI_HANDLE Controller; EFI_HANDLE Controller;
EFI_HANDLE Image; EFI_HANDLE Image;
// //
// Cousumed children // Cousumed children
// //
EFI_HANDLE Dhcp4Child; EFI_HANDLE Dhcp4Child;
HTTP_IO HttpIo; HTTP_IO HttpIo;
BOOLEAN HttpCreated; BOOLEAN HttpCreated;
// //
// Consumed protocol // Consumed protocol
// //
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii; EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2; EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2;
EFI_DHCP4_PROTOCOL *Dhcp4; EFI_DHCP4_PROTOCOL *Dhcp4;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
// //
// Produced children // Produced children
// //
EFI_HANDLE ChildHandle; EFI_HANDLE ChildHandle;
// //
// Produced protocol // Produced protocol
// //
EFI_LOAD_FILE_PROTOCOL LoadFile; EFI_LOAD_FILE_PROTOCOL LoadFile;
EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *DevicePath;
UINT32 Id; UINT32 Id;
// //
// Mode data // Mode data
// //
BOOLEAN UsingIpv6; BOOLEAN UsingIpv6;
BOOLEAN Started; BOOLEAN Started;
EFI_IP_ADDRESS StationIp; EFI_IP_ADDRESS StationIp;
EFI_IP_ADDRESS SubnetMask; EFI_IP_ADDRESS SubnetMask;
EFI_IP_ADDRESS GatewayIp; EFI_IP_ADDRESS GatewayIp;
UINT16 Port; UINT16 Port;
CHAR8 *BootFileUri; CHAR8 *BootFileUri;
VOID *BootFileUriParser; VOID *BootFileUriParser;
UINTN BootFileSize; UINTN BootFileSize;
// //
// Cached HTTP data // Cached HTTP data
// //
LIST_ENTRY CacheList; LIST_ENTRY CacheList;
// //
// Cached DHCP offer // Cached DHCP offer
// //
// OfferIndex records the index of DhcpOffer[] buffer, and OfferCount records the num of each type of offer. // OfferIndex records the index of DhcpOffer[] buffer, and OfferCount records the num of each type of offer.
// //
// It supposed that // It supposed that
// //
// OfferNum: 8 // OfferNum: 8
// OfferBuffer: [ProxyNameUri, DhcpNameUri, DhcpIpUri, ProxyNameUri, ProxyIpUri, DhcpOnly, DhcpIpUri, DhcpNameUriDns] // OfferBuffer: [ProxyNameUri, DhcpNameUri, DhcpIpUri, ProxyNameUri, ProxyIpUri, DhcpOnly, DhcpIpUri, DhcpNameUriDns]
// (OfferBuffer is 0-based.) // (OfferBuffer is 0-based.)
// //
// And assume that (DhcpIpUri is the first priority actually.) // And assume that (DhcpIpUri is the first priority actually.)
// //
// SelectIndex: 5 // SelectIndex: 5
// SelectProxyType: HttpOfferTypeProxyIpUri // SelectProxyType: HttpOfferTypeProxyIpUri
// (SelectIndex is 1-based, and 0 means no one is selected.) // (SelectIndex is 1-based, and 0 means no one is selected.)
// //
// So it should be // So it should be
// //
// DhcpIpUri DhcpNameUriDns DhcpDns DhcpOnly ProxyNameUri ProxyIpUri DhcpNameUri // DhcpIpUri DhcpNameUriDns DhcpDns DhcpOnly ProxyNameUri ProxyIpUri DhcpNameUri
// OfferCount: [ 2, 1, 0, 1, 2, 1, 1] // OfferCount: [ 2, 1, 0, 1, 2, 1, 1]
// //
// OfferIndex: {[ 2, 7, 0, 5, 0, *4, 1] // OfferIndex: {[ 2, 7, 0, 5, 0, *4, 1]
// [ 6, 0, 0, 0, 3, 0, 0] // [ 6, 0, 0, 0, 3, 0, 0]
// [ 0, 0, 0, 0, 0, 0, 0] // [ 0, 0, 0, 0, 0, 0, 0]
// ... ]} // ... ]}
// (OfferIndex is 0-based.) // (OfferIndex is 0-based.)
// //
// //
UINT32 SelectIndex; UINT32 SelectIndex;
UINT32 SelectProxyType; UINT32 SelectProxyType;
HTTP_BOOT_DHCP_PACKET_CACHE OfferBuffer[HTTP_BOOT_OFFER_MAX_NUM]; HTTP_BOOT_DHCP_PACKET_CACHE OfferBuffer[HTTP_BOOT_OFFER_MAX_NUM];
UINT32 OfferNum; UINT32 OfferNum;
UINT32 OfferCount[HttpOfferTypeMax]; UINT32 OfferCount[HttpOfferTypeMax];
UINT32 OfferIndex[HttpOfferTypeMax][HTTP_BOOT_OFFER_MAX_NUM]; UINT32 OfferIndex[HttpOfferTypeMax][HTTP_BOOT_OFFER_MAX_NUM];
}; };
#define HTTP_BOOT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('H', 'B', 'P', 'D') #define HTTP_BOOT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('H', 'B', 'P', 'D')
#define HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, HTTP_BOOT_PRIVATE_DATA, LoadFile, HTTP_BOOT_PRIVATE_DATA_SIGNATURE) #define HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, HTTP_BOOT_PRIVATE_DATA, LoadFile, HTTP_BOOT_PRIVATE_DATA_SIGNATURE)
#define HTTP_BOOT_PRIVATE_DATA_FROM_ID(a) CR (a, HTTP_BOOT_PRIVATE_DATA, Id, HTTP_BOOT_PRIVATE_DATA_SIGNATURE) #define HTTP_BOOT_PRIVATE_DATA_FROM_ID(a) CR (a, HTTP_BOOT_PRIVATE_DATA, Id, HTTP_BOOT_PRIVATE_DATA_SIGNATURE)
extern EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile; extern EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile;
/** /**
Tests to see if this driver supports a given controller. If a child device is provided, Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device. it further tests to see if this driver supports creating a handle for the specified child device.
This function checks to see if the driver specified by This supports the device specified by This function checks to see if the driver specified by This supports the device specified by
ControllerHandle. Drivers will typically use the device path attached to ControllerHandle. Drivers will typically use the device path attached to
ControllerHandle and/or the services from the bus I/O abstraction attached to ControllerHandle and/or the services from the bus I/O abstraction attached to
ControllerHandle to determine if the driver supports ControllerHandle. This function ControllerHandle to determine if the driver supports ControllerHandle. This function
may be called many times during platform initialization. In order to reduce boot times, the tests may be called many times during platform initialization. In order to reduce boot times, the tests
performed by this function must be very small, and take as little time as possible to execute. This performed by this function must be very small, and take as little time as possible to execute. This
function must not change the state of any hardware devices, and this function must be aware that the function must not change the state of any hardware devices, and this function must be aware that the
device specified by ControllerHandle may already be managed by the same driver or a device specified by ControllerHandle may already be managed by the same driver or a
different driver. This function must match its calls to AllocatePages() with FreePages(), different driver. This function must match its calls to AllocatePages() with FreePages(),
AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
Because ControllerHandle may have been previously started by the same driver, if a protocol is Because ControllerHandle may have been previously started by the same driver, if a protocol is
already in the opened state, then it must not be closed with CloseProtocol(). This is required already in the opened state, then it must not be closed with CloseProtocol(). This is required
to guarantee the state of ControllerHandle is not modified by this function. to guarantee the state of ControllerHandle is not modified by this function.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to test. This handle @param[in] ControllerHandle The handle of the controller to test. This handle
must support a protocol interface that supplies must support a protocol interface that supplies
an I/O abstraction to the driver. an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus parameter is ignored by device drivers, and is optional for bus
drivers. For bus drivers, if this parameter is not NULL, then drivers. For bus drivers, if this parameter is not NULL, then
the bus driver must determine if the bus controller specified the bus driver must determine if the bus controller specified
by ControllerHandle and the child controller specified by ControllerHandle and the child controller specified
by RemainingDevicePath are both supported by this by RemainingDevicePath are both supported by this
bus driver. bus driver.
@retval EFI_SUCCESS The device specified by ControllerHandle and @retval EFI_SUCCESS The device specified by ControllerHandle and
RemainingDevicePath is supported by the driver specified by This. RemainingDevicePath is supported by the driver specified by This.
@retval EFI_ALREADY_STARTED The device specified by ControllerHandle and @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by the driver RemainingDevicePath is already being managed by the driver
specified by This. specified by This.
@retval EFI_ACCESS_DENIED The device specified by ControllerHandle and @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by a different RemainingDevicePath is already being managed by a different
driver or an application that requires exclusive access. driver or an application that requires exclusive access.
Currently not implemented. Currently not implemented.
@retval EFI_UNSUPPORTED The device specified by ControllerHandle and @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
RemainingDevicePath is not supported by the driver specified by This. RemainingDevicePath is not supported by the driver specified by This.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootIp4DxeDriverBindingSupported ( HttpBootIp4DxeDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
); );
/** /**
Starts a device controller or a bus controller. Starts a device controller or a bus controller.
The Start() function is designed to be invoked from the EFI boot service ConnectController(). The Start() function is designed to be invoked from the EFI boot service ConnectController().
As a result, much of the error checking on the parameters to Start() has been moved into this As a result, much of the error checking on the parameters to Start() has been moved into this
common boot service. It is legal to call Start() from other locations, common boot service. It is legal to call Start() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic. but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE. 1. ControllerHandle must be a valid EFI_HANDLE.
2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
EFI_DEVICE_PATH_PROTOCOL. EFI_DEVICE_PATH_PROTOCOL.
3. Prior to calling Start(), the Supported() function for the driver specified by This must 3. Prior to calling Start(), the Supported() function for the driver specified by This must
have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to start. This handle @param[in] ControllerHandle The handle of the controller to start. This handle
must support a protocol interface that supplies must support a protocol interface that supplies
an I/O abstraction to the driver. an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus parameter is ignored by device drivers, and is optional for bus
drivers. For a bus driver, if this parameter is NULL, then handles drivers. For a bus driver, if this parameter is NULL, then handles
for all the children of Controller are created by this driver. for all the children of Controller are created by this driver.
If this parameter is not NULL and the first Device Path Node is If this parameter is not NULL and the first Device Path Node is
not the End of Device Path Node, then only the handle for the not the End of Device Path Node, then only the handle for the
child device specified by the first Device Path Node of child device specified by the first Device Path Node of
RemainingDevicePath is created by this driver. RemainingDevicePath is created by this driver.
If the first Device Path Node of RemainingDevicePath is If the first Device Path Node of RemainingDevicePath is
the End of Device Path Node, no child handle is created by this the End of Device Path Node, no child handle is created by this
driver. driver.
@retval EFI_SUCCESS The device was started. @retval EFI_SUCCESS The device was started.
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented. @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval Others The driver failded to start the device. @retval Others The driver failded to start the device.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootIp4DxeDriverBindingStart ( HttpBootIp4DxeDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
); );
/** /**
Stops a device controller or a bus controller. Stops a device controller or a bus controller.
The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
As a result, much of the error checking on the parameters to Stop() has been moved As a result, much of the error checking on the parameters to Stop() has been moved
into this common boot service. It is legal to call Stop() from other locations, into this common boot service. It is legal to call Stop() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic. but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
same driver's Start() function. same driver's Start() function.
2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
EFI_HANDLE. In addition, all of these handles must have been created in this driver's EFI_HANDLE. In addition, all of these handles must have been created in this driver's
Start() function, and the Start() function must have called OpenProtocol() on Start() function, and the Start() function must have called OpenProtocol() on
ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must @param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver support a bus specific I/O protocol for the driver
to use to stop the device. to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer. @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0. if NumberOfChildren is 0.
@retval EFI_SUCCESS The device was stopped. @retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error. @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootIp4DxeDriverBindingStop ( HttpBootIp4DxeDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren, IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
); );
#endif #endif

View File

@ -1,68 +1,68 @@
## @file ## @file
# This modules produce the Load File Protocol for UEFI HTTP boot. # This modules produce the Load File Protocol for UEFI HTTP boot.
# #
# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials # This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License # are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at # which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php # http://opensource.org/licenses/bsd-license.php
# #
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
# #
## ##
[Defines] [Defines]
INF_VERSION = 0x00010005 INF_VERSION = 0x00010005
BASE_NAME = HttpBootDxe BASE_NAME = HttpBootDxe
FILE_GUID = ecebcb00-d9c8-11e4-af3d-8cdcd426c973 FILE_GUID = ecebcb00-d9c8-11e4-af3d-8cdcd426c973
MODULE_TYPE = UEFI_DRIVER MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0 VERSION_STRING = 1.0
ENTRY_POINT = HttpBootDxeDriverEntryPoint ENTRY_POINT = HttpBootDxeDriverEntryPoint
UNLOAD_IMAGE = NetLibDefaultUnload UNLOAD_IMAGE = NetLibDefaultUnload
MODULE_UNI_FILE = HttpBootDxe.uni MODULE_UNI_FILE = HttpBootDxe.uni
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec MdeModulePkg/MdeModulePkg.dec
[Sources] [Sources]
HttpBootDxe.h HttpBootDxe.h
HttpBootDxe.c HttpBootDxe.c
HttpBootComponentName.h HttpBootComponentName.h
HttpBootComponentName.c HttpBootComponentName.c
HttpBootImpl.h HttpBootImpl.h
HttpBootImpl.c HttpBootImpl.c
HttpBootDhcp4.h HttpBootDhcp4.h
HttpBootDhcp4.c HttpBootDhcp4.c
HttpBootSupport.h HttpBootSupport.h
HttpBootSupport.c HttpBootSupport.c
HttpBootClient.h HttpBootClient.h
HttpBootClient.c HttpBootClient.c
[LibraryClasses] [LibraryClasses]
UefiDriverEntryPoint UefiDriverEntryPoint
UefiBootServicesTableLib UefiBootServicesTableLib
MemoryAllocationLib MemoryAllocationLib
BaseLib BaseLib
UefiLib UefiLib
DevicePathLib DevicePathLib
DebugLib DebugLib
NetLib NetLib
HttpLib HttpLib
[Protocols] [Protocols]
## TO_START ## TO_START
## BY_START ## BY_START
gEfiDevicePathProtocolGuid gEfiDevicePathProtocolGuid
gEfiLoadFileProtocolGuid ## BY_START gEfiLoadFileProtocolGuid ## BY_START
gEfiHttpServiceBindingProtocolGuid ## CONSUMES gEfiHttpServiceBindingProtocolGuid ## CONSUMES
gEfiHttpProtocolGuid ## CONSUMES gEfiHttpProtocolGuid ## CONSUMES
gEfiDhcp4ServiceBindingProtocolGuid ## TO_START gEfiDhcp4ServiceBindingProtocolGuid ## TO_START
gEfiDhcp4ProtocolGuid ## TO_START gEfiDhcp4ProtocolGuid ## TO_START
gEfiIp4Config2ProtocolGuid ## TO_START gEfiIp4Config2ProtocolGuid ## TO_START
gEfiNetworkInterfaceIdentifierProtocolGuid_31 ## SOMETIMES_CONSUMES gEfiNetworkInterfaceIdentifierProtocolGuid_31 ## SOMETIMES_CONSUMES
[UserExtensions.TianoCore."ExtraFiles"] [UserExtensions.TianoCore."ExtraFiles"]
HttpBootDxeExtra.uni HttpBootDxeExtra.uni

View File

@ -1,364 +1,364 @@
/** @file /** @file
The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot. The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "HttpBootDxe.h" #include "HttpBootDxe.h"
/** /**
Enable the use of UEFI HTTP boot function. Enable the use of UEFI HTTP boot function.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@retval EFI_SUCCESS HTTP boot was successfully enabled. @retval EFI_SUCCESS HTTP boot was successfully enabled.
@retval EFI_INVALID_PARAMETER Private is NULL. @retval EFI_INVALID_PARAMETER Private is NULL.
@retval EFI_ALREADY_STARTED The driver is already in started state. @retval EFI_ALREADY_STARTED The driver is already in started state.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootStart ( HttpBootStart (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
) )
{ {
UINTN Index; UINTN Index;
if (Private == NULL) { if (Private == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (Private->Started) { if (Private->Started) {
return EFI_ALREADY_STARTED; return EFI_ALREADY_STARTED;
} }
if (!Private->UsingIpv6) { if (!Private->UsingIpv6) {
// //
// Init the content of cached DHCP offer list. // Init the content of cached DHCP offer list.
// //
ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer)); ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer));
for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) { for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {
Private->OfferBuffer[Index].Dhcp4.Packet.Offer.Size = HTTP_BOOT_DHCP4_PACKET_MAX_SIZE; Private->OfferBuffer[Index].Dhcp4.Packet.Offer.Size = HTTP_BOOT_DHCP4_PACKET_MAX_SIZE;
} }
} else { } else {
ASSERT (FALSE); ASSERT (FALSE);
} }
Private->Started = TRUE; Private->Started = TRUE;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Attempt to complete a DHCPv4 D.O.R.A sequence to retrieve the boot resource information. Attempt to complete a DHCPv4 D.O.R.A sequence to retrieve the boot resource information.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@retval EFI_SUCCESS Boot info was successfully retrieved. @retval EFI_SUCCESS Boot info was successfully retrieved.
@retval EFI_INVALID_PARAMETER Private is NULL. @retval EFI_INVALID_PARAMETER Private is NULL.
@retval EFI_NOT_STARTED The driver is in stopped state. @retval EFI_NOT_STARTED The driver is in stopped state.
@retval EFI_DEVICE_ERROR An unexpected network error occurred. @retval EFI_DEVICE_ERROR An unexpected network error occurred.
@retval Others Other errors as indicated. @retval Others Other errors as indicated.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootDhcp ( HttpBootDhcp (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
if (Private == NULL) { if (Private == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (!Private->Started) { if (!Private->Started) {
return EFI_NOT_STARTED; return EFI_NOT_STARTED;
} }
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
if (!Private->UsingIpv6) { if (!Private->UsingIpv6) {
Status = HttpBootDhcp4Dora (Private); Status = HttpBootDhcp4Dora (Private);
} else { } else {
ASSERT (FALSE); ASSERT (FALSE);
} }
return Status; return Status;
} }
/** /**
Attempt to download the boot file through HTTP message exchange. Attempt to download the boot file through HTTP message exchange.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return
code of EFI_SUCCESS, the amount of data transferred to code of EFI_SUCCESS, the amount of data transferred to
Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
the size of Buffer required to retrieve the requested file. the size of Buffer required to retrieve the requested file.
@param[in] Buffer The memory buffer to transfer the file to. If Buffer is NULL, @param[in] Buffer The memory buffer to transfer the file to. If Buffer is NULL,
then the size of the requested file is returned in then the size of the requested file is returned in
BufferSize. BufferSize.
@retval EFI_SUCCESS Boot file was loaded successfully. @retval EFI_SUCCESS Boot file was loaded successfully.
@retval EFI_INVALID_PARAMETER Private is NULL. @retval EFI_INVALID_PARAMETER Private is NULL.
@retval EFI_NOT_STARTED The driver is in stopped state. @retval EFI_NOT_STARTED The driver is in stopped state.
@retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the boot file. BufferSize has @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the boot file. BufferSize has
been updated with the size needed to complete the request. been updated with the size needed to complete the request.
@retval EFI_DEVICE_ERROR An unexpected network error occurred. @retval EFI_DEVICE_ERROR An unexpected network error occurred.
@retval Others Other errors as indicated. @retval Others Other errors as indicated.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootLoadFile ( HttpBootLoadFile (
IN HTTP_BOOT_PRIVATE_DATA *Private, IN HTTP_BOOT_PRIVATE_DATA *Private,
IN OUT UINTN *BufferSize, IN OUT UINTN *BufferSize,
IN VOID *Buffer OPTIONAL IN VOID *Buffer OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
if (Private == NULL) { if (Private == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (!Private->Started) { if (!Private->Started) {
return EFI_NOT_STARTED; return EFI_NOT_STARTED;
} }
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
if (Private->BootFileUri == NULL) { if (Private->BootFileUri == NULL) {
// //
// Parse the cached offer to get the boot file URL first. // Parse the cached offer to get the boot file URL first.
// //
Status = HttpBootDiscoverBootInfo (Private); Status = HttpBootDiscoverBootInfo (Private);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
} }
if (!Private->HttpCreated) { if (!Private->HttpCreated) {
// //
// Create HTTP child. // Create HTTP child.
// //
Status = HttpBootCreateHttpIo (Private); Status = HttpBootCreateHttpIo (Private);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
} }
if (Private->BootFileSize == 0) { if (Private->BootFileSize == 0) {
// //
// Discover the information about the bootfile if we haven't. // Discover the information about the bootfile if we haven't.
// //
// //
// Try to use HTTP HEAD method. // Try to use HTTP HEAD method.
// //
Status = HttpBootGetBootFile ( Status = HttpBootGetBootFile (
Private, Private,
TRUE, TRUE,
&Private->BootFileSize, &Private->BootFileSize,
NULL NULL
); );
if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) { if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
// //
// Failed to get file size by HEAD method, may be trunked encoding, try HTTP GET method. // Failed to get file size by HEAD method, may be trunked encoding, try HTTP GET method.
// //
ASSERT (Private->BootFileSize == 0); ASSERT (Private->BootFileSize == 0);
Status = HttpBootGetBootFile ( Status = HttpBootGetBootFile (
Private, Private,
FALSE, FALSE,
&Private->BootFileSize, &Private->BootFileSize,
NULL NULL
); );
if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) { if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
return Status; return Status;
} }
} }
} }
if (*BufferSize < Private->BootFileSize) { if (*BufferSize < Private->BootFileSize) {
*BufferSize = Private->BootFileSize; *BufferSize = Private->BootFileSize;
return EFI_BUFFER_TOO_SMALL; return EFI_BUFFER_TOO_SMALL;
} }
// //
// Load the boot file into Buffer // Load the boot file into Buffer
// //
return HttpBootGetBootFile ( return HttpBootGetBootFile (
Private, Private,
FALSE, FALSE,
BufferSize, BufferSize,
Buffer Buffer
); );
} }
/** /**
Disable the use of UEFI HTTP boot function. Disable the use of UEFI HTTP boot function.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@retval EFI_SUCCESS HTTP boot was successfully disabled. @retval EFI_SUCCESS HTTP boot was successfully disabled.
@retval EFI_NOT_STARTED The driver is already in stopped state. @retval EFI_NOT_STARTED The driver is already in stopped state.
@retval EFI_INVALID_PARAMETER Private is NULL. @retval EFI_INVALID_PARAMETER Private is NULL.
@retval Others Unexpected error when stop the function. @retval Others Unexpected error when stop the function.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootStop ( HttpBootStop (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
) )
{ {
UINTN Index; UINTN Index;
if (Private == NULL) { if (Private == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (!Private->Started) { if (!Private->Started) {
return EFI_NOT_STARTED; return EFI_NOT_STARTED;
} }
if (Private->HttpCreated) { if (Private->HttpCreated) {
HttpIoDestroyIo (&Private->HttpIo); HttpIoDestroyIo (&Private->HttpIo);
Private->HttpCreated = FALSE; Private->HttpCreated = FALSE;
} }
Private->Started = FALSE; Private->Started = FALSE;
ZeroMem (&Private->StationIp, sizeof (EFI_IP_ADDRESS)); ZeroMem (&Private->StationIp, sizeof (EFI_IP_ADDRESS));
ZeroMem (&Private->SubnetMask, sizeof (EFI_IP_ADDRESS)); ZeroMem (&Private->SubnetMask, sizeof (EFI_IP_ADDRESS));
ZeroMem (&Private->GatewayIp, sizeof (EFI_IP_ADDRESS)); ZeroMem (&Private->GatewayIp, sizeof (EFI_IP_ADDRESS));
Private->Port = 0; Private->Port = 0;
Private->BootFileUri = NULL; Private->BootFileUri = NULL;
Private->BootFileUriParser = NULL; Private->BootFileUriParser = NULL;
Private->BootFileSize = 0; Private->BootFileSize = 0;
Private->SelectIndex = 0; Private->SelectIndex = 0;
Private->SelectProxyType = HttpOfferTypeMax; Private->SelectProxyType = HttpOfferTypeMax;
if (!Private->UsingIpv6) { if (!Private->UsingIpv6) {
// //
// Stop and release the DHCP4 child. // Stop and release the DHCP4 child.
// //
Private->Dhcp4->Stop (Private->Dhcp4); Private->Dhcp4->Stop (Private->Dhcp4);
Private->Dhcp4->Configure (Private->Dhcp4, NULL); Private->Dhcp4->Configure (Private->Dhcp4, NULL);
for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) { for (Index = 0; Index < HTTP_BOOT_OFFER_MAX_NUM; Index++) {
if (Private->OfferBuffer[Index].Dhcp4.UriParser) { if (Private->OfferBuffer[Index].Dhcp4.UriParser) {
HttpUrlFreeParser (Private->OfferBuffer[Index].Dhcp4.UriParser); HttpUrlFreeParser (Private->OfferBuffer[Index].Dhcp4.UriParser);
} }
} }
} else { } else {
ASSERT (FALSE); ASSERT (FALSE);
} }
ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer)); ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer));
Private->OfferNum = 0; Private->OfferNum = 0;
ZeroMem (Private->OfferCount, sizeof (Private->OfferCount)); ZeroMem (Private->OfferCount, sizeof (Private->OfferCount));
ZeroMem (Private->OfferIndex, sizeof (Private->OfferIndex)); ZeroMem (Private->OfferIndex, sizeof (Private->OfferIndex));
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Causes the driver to load a specified file. Causes the driver to load a specified file.
@param This Protocol instance pointer. @param This Protocol instance pointer.
@param FilePath The device specific path of the file to load. @param FilePath The device specific path of the file to load.
@param BootPolicy If TRUE, indicates that the request originates from the @param BootPolicy If TRUE, indicates that the request originates from the
boot manager is attempting to load FilePath as a boot boot manager is attempting to load FilePath as a boot
selection. If FALSE, then FilePath must match as exact file selection. If FALSE, then FilePath must match as exact file
to be loaded. to be loaded.
@param BufferSize On input the size of Buffer in bytes. On output with a return @param BufferSize On input the size of Buffer in bytes. On output with a return
code of EFI_SUCCESS, the amount of data transferred to code of EFI_SUCCESS, the amount of data transferred to
Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
the size of Buffer required to retrieve the requested file. the size of Buffer required to retrieve the requested file.
@param Buffer The memory buffer to transfer the file to. IF Buffer is NULL, @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
then the size of the requested file is returned in then the size of the requested file is returned in
BufferSize. BufferSize.
@retval EFI_SUCCESS The file was loaded. @retval EFI_SUCCESS The file was loaded.
@retval EFI_UNSUPPORTED The device does not support the provided BootPolicy @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy
@retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
BufferSize is NULL. BufferSize is NULL.
@retval EFI_NO_MEDIA No medium was present to load the file. @retval EFI_NO_MEDIA No medium was present to load the file.
@retval EFI_DEVICE_ERROR The file was not loaded due to a device error. @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
@retval EFI_NO_RESPONSE The remote system did not respond. @retval EFI_NO_RESPONSE The remote system did not respond.
@retval EFI_NOT_FOUND The file was not found. @retval EFI_NOT_FOUND The file was not found.
@retval EFI_ABORTED The file load process was manually cancelled. @retval EFI_ABORTED The file load process was manually cancelled.
@retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry. @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
BufferSize has been updated with the size needed to complete BufferSize has been updated with the size needed to complete
the request. the request.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpBootDxeLoadFile ( HttpBootDxeLoadFile (
IN EFI_LOAD_FILE_PROTOCOL *This, IN EFI_LOAD_FILE_PROTOCOL *This,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
IN BOOLEAN BootPolicy, IN BOOLEAN BootPolicy,
IN OUT UINTN *BufferSize, IN OUT UINTN *BufferSize,
IN VOID *Buffer OPTIONAL IN VOID *Buffer OPTIONAL
) )
{ {
HTTP_BOOT_PRIVATE_DATA *Private; HTTP_BOOT_PRIVATE_DATA *Private;
BOOLEAN MediaPresent; BOOLEAN MediaPresent;
EFI_STATUS Status; EFI_STATUS Status;
if (This == NULL || BufferSize == NULL) { if (This == NULL || BufferSize == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Only support BootPolicy // Only support BootPolicy
// //
if (!BootPolicy) { if (!BootPolicy) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (This); Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (This);
// //
// Check media status before HTTP boot start // Check media status before HTTP boot start
// //
MediaPresent = TRUE; MediaPresent = TRUE;
NetLibDetectMedia (Private->Controller, &MediaPresent); NetLibDetectMedia (Private->Controller, &MediaPresent);
if (!MediaPresent) { if (!MediaPresent) {
return EFI_NO_MEDIA; return EFI_NO_MEDIA;
} }
// //
// Initialize HTTP boot and load the boot file. // Initialize HTTP boot and load the boot file.
// //
Status = HttpBootStart (Private); Status = HttpBootStart (Private);
if (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED) { if (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED) {
Status = HttpBootLoadFile (Private, BufferSize, Buffer); Status = HttpBootLoadFile (Private, BufferSize, Buffer);
} }
if (Status != EFI_SUCCESS && Status != EFI_BUFFER_TOO_SMALL) { if (Status != EFI_SUCCESS && Status != EFI_BUFFER_TOO_SMALL) {
HttpBootStop (Private); HttpBootStop (Private);
} else { } else {
// //
// Stop and release the DHCP4 child. // Stop and release the DHCP4 child.
// //
Private->Dhcp4->Stop (Private->Dhcp4); Private->Dhcp4->Stop (Private->Dhcp4);
Private->Dhcp4->Configure (Private->Dhcp4, NULL); Private->Dhcp4->Configure (Private->Dhcp4, NULL);
} }
return Status; return Status;
} }
/// ///
/// Load File Protocol instance /// Load File Protocol instance
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED GLOBAL_REMOVE_IF_UNREFERENCED
EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile = { EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile = {
HttpBootDxeLoadFile HttpBootDxeLoadFile
}; };

View File

@ -1,50 +1,50 @@
/** @file /** @file
The declaration of UEFI HTTP boot function. The declaration of UEFI HTTP boot function.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#ifndef __EFI_HTTP_BOOT_IMPL_H__ #ifndef __EFI_HTTP_BOOT_IMPL_H__
#define __EFI_HTTP_BOOT_IMPL_H__ #define __EFI_HTTP_BOOT_IMPL_H__
/** /**
Attempt to complete a DHCPv4 D.O.R.A sequence to retrieve the boot resource information. Attempt to complete a DHCPv4 D.O.R.A sequence to retrieve the boot resource information.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@retval EFI_SUCCESS Boot info was successfully retrieved. @retval EFI_SUCCESS Boot info was successfully retrieved.
@retval EFI_INVALID_PARAMETER Private is NULL. @retval EFI_INVALID_PARAMETER Private is NULL.
@retval EFI_NOT_STARTED The driver is in stopped state. @retval EFI_NOT_STARTED The driver is in stopped state.
@retval EFI_DEVICE_ERROR An unexpected network error occurred. @retval EFI_DEVICE_ERROR An unexpected network error occurred.
@retval Others Other errors as indicated. @retval Others Other errors as indicated.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootDhcp ( HttpBootDhcp (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
); );
/** /**
Disable the use of UEFI HTTP boot function. Disable the use of UEFI HTTP boot function.
@param[in] Private The pointer to the driver's private data. @param[in] Private The pointer to the driver's private data.
@retval EFI_SUCCESS HTTP boot was successfully disabled. @retval EFI_SUCCESS HTTP boot was successfully disabled.
@retval EFI_NOT_STARTED The driver is already in stopped state. @retval EFI_NOT_STARTED The driver is already in stopped state.
@retval EFI_INVALID_PARAMETER Private is NULL. @retval EFI_INVALID_PARAMETER Private is NULL.
@retval Others Unexpected error when stop the function. @retval Others Unexpected error when stop the function.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootStop ( HttpBootStop (
IN HTTP_BOOT_PRIVATE_DATA *Private IN HTTP_BOOT_PRIVATE_DATA *Private
); );
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,250 +1,250 @@
/** @file /** @file
Support functions declaration for UEFI HTTP boot driver. Support functions declaration for UEFI HTTP boot driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#ifndef __EFI_HTTP_BOOT_SUPPORT_H__ #ifndef __EFI_HTTP_BOOT_SUPPORT_H__
#define __EFI_HTTP_BOOT_SUPPORT_H__ #define __EFI_HTTP_BOOT_SUPPORT_H__
/** /**
Get the Nic handle using any child handle in the IPv4 stack. Get the Nic handle using any child handle in the IPv4 stack.
@param[in] ControllerHandle Pointer to child handle over IPv4. @param[in] ControllerHandle Pointer to child handle over IPv4.
@return NicHandle The pointer to the Nic handle. @return NicHandle The pointer to the Nic handle.
@return NULL Can't find the Nic handle. @return NULL Can't find the Nic handle.
**/ **/
EFI_HANDLE EFI_HANDLE
HttpBootGetNicByIp4Children ( HttpBootGetNicByIp4Children (
IN EFI_HANDLE ControllerHandle IN EFI_HANDLE ControllerHandle
); );
/** /**
This function is to convert UINTN to ASCII string with the required formatting. This function is to convert UINTN to ASCII string with the required formatting.
@param[in] Number Numeric value to be converted. @param[in] Number Numeric value to be converted.
@param[in] Buffer The pointer to the buffer for ASCII string. @param[in] Buffer The pointer to the buffer for ASCII string.
@param[in] Length The length of the required format. @param[in] Length The length of the required format.
**/ **/
VOID VOID
HttpBootUintnToAscDecWithFormat ( HttpBootUintnToAscDecWithFormat (
IN UINTN Number, IN UINTN Number,
IN UINT8 *Buffer, IN UINT8 *Buffer,
IN INTN Length IN INTN Length
); );
/** /**
This function is to display the IPv4 address. This function is to display the IPv4 address.
@param[in] Ip The pointer to the IPv4 address. @param[in] Ip The pointer to the IPv4 address.
**/ **/
VOID VOID
HttpBootShowIp4Addr ( HttpBootShowIp4Addr (
IN EFI_IPv4_ADDRESS *Ip IN EFI_IPv4_ADDRESS *Ip
); );
// //
// A wrapper structure to hold the HTTP headers. // A wrapper structure to hold the HTTP headers.
// //
typedef struct { typedef struct {
UINTN MaxHeaderCount; UINTN MaxHeaderCount;
UINTN HeaderCount; UINTN HeaderCount;
EFI_HTTP_HEADER *Headers; EFI_HTTP_HEADER *Headers;
} HTTP_IO_HEADER; } HTTP_IO_HEADER;
/** /**
Create a HTTP_IO_HEADER to hold the HTTP header items. Create a HTTP_IO_HEADER to hold the HTTP header items.
@param[in] MaxHeaderCount The maximun number of HTTP header in this holder. @param[in] MaxHeaderCount The maximun number of HTTP header in this holder.
@return A pointer of the HTTP header holder or NULL if failed. @return A pointer of the HTTP header holder or NULL if failed.
**/ **/
HTTP_IO_HEADER * HTTP_IO_HEADER *
HttpBootCreateHeader ( HttpBootCreateHeader (
IN UINTN MaxHeaderCount IN UINTN MaxHeaderCount
); );
/** /**
Destroy the HTTP_IO_HEADER and release the resouces. Destroy the HTTP_IO_HEADER and release the resouces.
@param[in] HttpIoHeader Point to the HTTP header holder to be destroyed. @param[in] HttpIoHeader Point to the HTTP header holder to be destroyed.
**/ **/
VOID VOID
HttpBootFreeHeader ( HttpBootFreeHeader (
IN HTTP_IO_HEADER *HttpIoHeader IN HTTP_IO_HEADER *HttpIoHeader
); );
/** /**
Set or update a HTTP header with the field name and corresponding value. Set or update a HTTP header with the field name and corresponding value.
@param[in] HttpIoHeader Point to the HTTP header holder. @param[in] HttpIoHeader Point to the HTTP header holder.
@param[in] FieldName Null terminated string which describes a field name. @param[in] FieldName Null terminated string which describes a field name.
@param[in] FieldValue Null terminated string which describes the corresponding field value. @param[in] FieldValue Null terminated string which describes the corresponding field value.
@retval EFI_SUCCESS The HTTP header has been set or updated. @retval EFI_SUCCESS The HTTP header has been set or updated.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Insufficient resource to complete the operation. @retval EFI_OUT_OF_RESOURCES Insufficient resource to complete the operation.
@retval Other Unexpected error happened. @retval Other Unexpected error happened.
**/ **/
EFI_STATUS EFI_STATUS
HttpBootSetHeader ( HttpBootSetHeader (
IN HTTP_IO_HEADER *HttpIoHeader, IN HTTP_IO_HEADER *HttpIoHeader,
IN CHAR8 *FieldName, IN CHAR8 *FieldName,
IN CHAR8 *FieldValue IN CHAR8 *FieldValue
); );
// //
// HTTP_IO configuration data for IPv4 // HTTP_IO configuration data for IPv4
// //
typedef struct { typedef struct {
EFI_HTTP_VERSION HttpVersion; EFI_HTTP_VERSION HttpVersion;
UINT32 RequestTimeOut; // In milliseconds. UINT32 RequestTimeOut; // In milliseconds.
UINT32 ResponseTimeOut; // In milliseconds. UINT32 ResponseTimeOut; // In milliseconds.
BOOLEAN UseDefaultAddress; BOOLEAN UseDefaultAddress;
EFI_IPv4_ADDRESS LocalIp; EFI_IPv4_ADDRESS LocalIp;
EFI_IPv4_ADDRESS SubnetMask; EFI_IPv4_ADDRESS SubnetMask;
UINT16 LocalPort; UINT16 LocalPort;
} HTTP4_IO_CONFIG_DATA; } HTTP4_IO_CONFIG_DATA;
// //
// HTTP_IO configuration // HTTP_IO configuration
// //
typedef union { typedef union {
HTTP4_IO_CONFIG_DATA Config4; HTTP4_IO_CONFIG_DATA Config4;
} HTTP_IO_CONFIG_DATA; } HTTP_IO_CONFIG_DATA;
// //
// HTTO_IO wrapper of the EFI HTTP service. // HTTO_IO wrapper of the EFI HTTP service.
// //
typedef struct { typedef struct {
UINT8 IpVersion; UINT8 IpVersion;
EFI_HANDLE Image; EFI_HANDLE Image;
EFI_HANDLE Controller; EFI_HANDLE Controller;
EFI_HANDLE Handle; EFI_HANDLE Handle;
EFI_HTTP_PROTOCOL *Http; EFI_HTTP_PROTOCOL *Http;
EFI_HTTP_TOKEN ReqToken; EFI_HTTP_TOKEN ReqToken;
EFI_HTTP_MESSAGE ReqMessage; EFI_HTTP_MESSAGE ReqMessage;
EFI_HTTP_TOKEN RspToken; EFI_HTTP_TOKEN RspToken;
EFI_HTTP_MESSAGE RspMessage; EFI_HTTP_MESSAGE RspMessage;
BOOLEAN IsTxDone; BOOLEAN IsTxDone;
BOOLEAN IsRxDone; BOOLEAN IsRxDone;
} HTTP_IO; } HTTP_IO;
// //
// A wrapper structure to hold the received HTTP response data. // A wrapper structure to hold the received HTTP response data.
// //
typedef struct { typedef struct {
EFI_HTTP_RESPONSE_DATA Response; EFI_HTTP_RESPONSE_DATA Response;
UINTN HeaderCount; UINTN HeaderCount;
EFI_HTTP_HEADER *Headers; EFI_HTTP_HEADER *Headers;
UINTN BodyLength; UINTN BodyLength;
CHAR8 *Body; CHAR8 *Body;
} HTTP_IO_RESOPNSE_DATA; } HTTP_IO_RESOPNSE_DATA;
/** /**
Create a HTTP_IO to access the HTTP service. It will create and configure Create a HTTP_IO to access the HTTP service. It will create and configure
a HTTP child handle. a HTTP child handle.
@param[in] Image The handle of the driver image. @param[in] Image The handle of the driver image.
@param[in] Controller The handle of the controller. @param[in] Controller The handle of the controller.
@param[in] IpVersion IP_VERSION_4 or IP_VERSION_6. @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
@param[in] ConfigData The HTTP_IO configuration data. @param[in] ConfigData The HTTP_IO configuration data.
@param[out] HttpIo The HTTP_IO. @param[out] HttpIo The HTTP_IO.
@retval EFI_SUCCESS The HTTP_IO is created and configured. @retval EFI_SUCCESS The HTTP_IO is created and configured.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_UNSUPPORTED One or more of the control options are not @retval EFI_UNSUPPORTED One or more of the control options are not
supported in the implementation. supported in the implementation.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
@retval Others Failed to create the HTTP_IO or configure it. @retval Others Failed to create the HTTP_IO or configure it.
**/ **/
EFI_STATUS EFI_STATUS
HttpIoCreateIo ( HttpIoCreateIo (
IN EFI_HANDLE Image, IN EFI_HANDLE Image,
IN EFI_HANDLE Controller, IN EFI_HANDLE Controller,
IN UINT8 IpVersion, IN UINT8 IpVersion,
IN HTTP_IO_CONFIG_DATA *ConfigData, IN HTTP_IO_CONFIG_DATA *ConfigData,
OUT HTTP_IO *HttpIo OUT HTTP_IO *HttpIo
); );
/** /**
Destroy the HTTP_IO and release the resouces. Destroy the HTTP_IO and release the resouces.
@param[in] HttpIo The HTTP_IO which wraps the HTTP service to be destroyed. @param[in] HttpIo The HTTP_IO which wraps the HTTP service to be destroyed.
**/ **/
VOID VOID
HttpIoDestroyIo ( HttpIoDestroyIo (
IN HTTP_IO *HttpIo IN HTTP_IO *HttpIo
); );
/** /**
Synchronously send a HTTP REQUEST message to the server. Synchronously send a HTTP REQUEST message to the server.
@param[in] HttpIo The HttpIo wrapping the HTTP service. @param[in] HttpIo The HttpIo wrapping the HTTP service.
@param[in] Request A pointer to storage such data as URL and HTTP method. @param[in] Request A pointer to storage such data as URL and HTTP method.
@param[in] HeaderCount Number of HTTP header structures in Headers list. @param[in] HeaderCount Number of HTTP header structures in Headers list.
@param[in] Headers Array containing list of HTTP headers. @param[in] Headers Array containing list of HTTP headers.
@param[in] BodyLength Length in bytes of the HTTP body. @param[in] BodyLength Length in bytes of the HTTP body.
@param[in] Body Body associated with the HTTP request. @param[in] Body Body associated with the HTTP request.
@retval EFI_SUCCESS The HTTP request is trasmitted. @retval EFI_SUCCESS The HTTP request is trasmitted.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
@retval EFI_DEVICE_ERROR An unexpected network or system error occurred. @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
@retval Others Other errors as indicated. @retval Others Other errors as indicated.
**/ **/
EFI_STATUS EFI_STATUS
HttpIoSendRequest ( HttpIoSendRequest (
IN HTTP_IO *HttpIo, IN HTTP_IO *HttpIo,
IN EFI_HTTP_REQUEST_DATA *Request, OPTIONAL IN EFI_HTTP_REQUEST_DATA *Request, OPTIONAL
IN UINTN HeaderCount, IN UINTN HeaderCount,
IN EFI_HTTP_HEADER *Headers, OPTIONAL IN EFI_HTTP_HEADER *Headers, OPTIONAL
IN UINTN BodyLength, IN UINTN BodyLength,
IN VOID *Body OPTIONAL IN VOID *Body OPTIONAL
); );
/** /**
Synchronously receive a HTTP RESPONSE message from the server. Synchronously receive a HTTP RESPONSE message from the server.
@param[in] HttpIo The HttpIo wrapping the HTTP service. @param[in] HttpIo The HttpIo wrapping the HTTP service.
@param[in] RecvMsgHeader TRUE to receive a new HTTP response (from message header). @param[in] RecvMsgHeader TRUE to receive a new HTTP response (from message header).
FALSE to continue receive the previous response message. FALSE to continue receive the previous response message.
@param[out] ResponseData Point to a wrapper of the received response data. @param[out] ResponseData Point to a wrapper of the received response data.
@retval EFI_SUCCESS The HTTP resopnse is received. @retval EFI_SUCCESS The HTTP resopnse is received.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
@retval EFI_DEVICE_ERROR An unexpected network or system error occurred. @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
@retval Others Other errors as indicated. @retval Others Other errors as indicated.
**/ **/
EFI_STATUS EFI_STATUS
HttpIoRecvResponse ( HttpIoRecvResponse (
IN HTTP_IO *HttpIo, IN HTTP_IO *HttpIo,
IN BOOLEAN RecvMsgHeader, IN BOOLEAN RecvMsgHeader,
OUT HTTP_IO_RESOPNSE_DATA *ResponseData OUT HTTP_IO_RESOPNSE_DATA *ResponseData
); );
#endif #endif

View File

@ -1,126 +1,126 @@
/** @file /** @file
The DriverEntryPoint and Unload for HttpUtilities driver. The DriverEntryPoint and Unload for HttpUtilities driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "HttpUtilitiesDxe.h" #include "HttpUtilitiesDxe.h"
/** /**
Unloads an image. Unloads an image.
@param ImageHandle Handle that identifies the image to be unloaded. @param ImageHandle Handle that identifies the image to be unloaded.
@retval EFI_SUCCESS The image has been unloaded. @retval EFI_SUCCESS The image has been unloaded.
@retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpUtilitiesDxeUnload ( HttpUtilitiesDxeUnload (
IN EFI_HANDLE ImageHandle IN EFI_HANDLE ImageHandle
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN HandleNum; UINTN HandleNum;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINT32 Index; UINT32 Index;
EFI_HTTP_UTILITIES_PROTOCOL *HttpUtilitiesProtocol; EFI_HTTP_UTILITIES_PROTOCOL *HttpUtilitiesProtocol;
HandleBuffer = NULL; HandleBuffer = NULL;
// //
// Locate all the handles with HttpUtilities protocol. // Locate all the handles with HttpUtilities protocol.
// //
Status = gBS->LocateHandleBuffer ( Status = gBS->LocateHandleBuffer (
ByProtocol, ByProtocol,
&gEfiHttpUtilitiesProtocolGuid, &gEfiHttpUtilitiesProtocolGuid,
NULL, NULL,
&HandleNum, &HandleNum,
&HandleBuffer &HandleBuffer
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
for (Index = 0; Index < HandleNum; Index++) { for (Index = 0; Index < HandleNum; Index++) {
// //
// Firstly, find HttpUtilitiesProtocol interface // Firstly, find HttpUtilitiesProtocol interface
// //
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiHttpUtilitiesProtocolGuid, &gEfiHttpUtilitiesProtocolGuid,
(VOID **) &HttpUtilitiesProtocol, (VOID **) &HttpUtilitiesProtocol,
ImageHandle, ImageHandle,
NULL, NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Then, uninstall HttpUtilities interface // Then, uninstall HttpUtilities interface
// //
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiHttpUtilitiesProtocolGuid, HttpUtilitiesProtocol, &gEfiHttpUtilitiesProtocolGuid, HttpUtilitiesProtocol,
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
This is the declaration of an EFI image entry point. This entry point is 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 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
both device drivers and bus drivers. both device drivers and bus drivers.
@param ImageHandle The firmware allocated handle for the UEFI image. @param ImageHandle The firmware allocated handle for the UEFI image.
@param SystemTable A pointer to the EFI System Table. @param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The operation completed successfully. @retval EFI_SUCCESS The operation completed successfully.
@retval Others An unexpected error occurred. @retval Others An unexpected error occurred.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpUtilitiesDxeDriverEntryPoint ( HttpUtilitiesDxeDriverEntryPoint (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_HANDLE Handle; EFI_HANDLE Handle;
Handle = NULL; Handle = NULL;
// //
// Install the HttpUtilities Protocol onto Handle // Install the HttpUtilities Protocol onto Handle
// //
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Handle, &Handle,
&gEfiHttpUtilitiesProtocolGuid, &gEfiHttpUtilitiesProtocolGuid,
&mHttpUtilitiesProtocol, &mHttpUtilitiesProtocol,
NULL NULL
); );
return Status; return Status;
} }

View File

@ -1,212 +1,212 @@
/** @file /** @file
The header files of Http Utilities functions for HttpUtilities driver. The header files of Http Utilities functions for HttpUtilities driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#ifndef __EFI_HTTP_UTILITIES_DXE_H__ #ifndef __EFI_HTTP_UTILITIES_DXE_H__
#define __EFI_HTTP_UTILITIES_DXE_H__ #define __EFI_HTTP_UTILITIES_DXE_H__
#include <Uefi.h> #include <Uefi.h>
// //
// Libraries // Libraries
// //
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
// //
// Consumed Protocols // Consumed Protocols
// //
#include <Protocol/HttpUtilities.h> #include <Protocol/HttpUtilities.h>
#include <Protocol/Http.h> #include <Protocol/Http.h>
// //
// Protocol instances // Protocol instances
// //
extern EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol; extern EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol;
/** /**
Free existing HeaderFields. Free existing HeaderFields.
@param[in] HeaderFields Pointer to array of key/value header pairs waitting for free. @param[in] HeaderFields Pointer to array of key/value header pairs waitting for free.
@param[in] FieldCount The number of header pairs in HeaderFields. @param[in] FieldCount The number of header pairs in HeaderFields.
**/ **/
VOID VOID
FreeHeaderFields ( FreeHeaderFields (
IN EFI_HTTP_HEADER *HeaderFields, IN EFI_HTTP_HEADER *HeaderFields,
IN UINTN FieldCount IN UINTN FieldCount
); );
/** /**
Find required header field in HeaderFields. Find required header field in HeaderFields.
@param[in] HeaderFields Pointer to array of key/value header pairs. @param[in] HeaderFields Pointer to array of key/value header pairs.
@param[in] FieldCount The number of header pairs. @param[in] FieldCount The number of header pairs.
@param[in] FieldName Pointer to header field's name. @param[in] FieldName Pointer to header field's name.
@return Pointer to the queried header field. @return Pointer to the queried header field.
@return NULL if not find this required header field. @return NULL if not find this required header field.
**/ **/
EFI_HTTP_HEADER * EFI_HTTP_HEADER *
FindHttpHeader ( FindHttpHeader (
IN EFI_HTTP_HEADER *HeaderFields, IN EFI_HTTP_HEADER *HeaderFields,
IN UINTN FieldCount, IN UINTN FieldCount,
IN CHAR8 *FieldName IN CHAR8 *FieldName
); );
/** /**
Check whether header field called FieldName is in DeleteList. Check whether header field called FieldName is in DeleteList.
@param[in] DeleteList Pointer to array of key/value header pairs. @param[in] DeleteList Pointer to array of key/value header pairs.
@param[in] DeleteCount The number of header pairs. @param[in] DeleteCount The number of header pairs.
@param[in] FieldName Pointer to header field's name. @param[in] FieldName Pointer to header field's name.
@return TRUE if FieldName is not in DeleteList, that means this header field is valid. @return TRUE if FieldName is not in DeleteList, that means this header field is valid.
@return FALSE if FieldName is in DeleteList, that means this header field is invalid. @return FALSE if FieldName is in DeleteList, that means this header field is invalid.
**/ **/
BOOLEAN BOOLEAN
IsValidHttpHeader ( IsValidHttpHeader (
IN CHAR8 *DeleteList[], IN CHAR8 *DeleteList[],
IN UINTN DeleteCount, IN UINTN DeleteCount,
IN CHAR8 *FieldName IN CHAR8 *FieldName
); );
/** /**
Set FieldName and FieldValue into specified HttpHeader. Set FieldName and FieldValue into specified HttpHeader.
@param[in] HttpHeader Specified HttpHeader. @param[in] HttpHeader Specified HttpHeader.
@param[in] FieldName FieldName of this HttpHeader. @param[in] FieldName FieldName of this HttpHeader.
@param[in] FieldValue FieldValue of this HttpHeader. @param[in] FieldValue FieldValue of this HttpHeader.
@retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully. @retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
**/ **/
EFI_STATUS EFI_STATUS
SetFieldNameAndValue ( SetFieldNameAndValue (
IN EFI_HTTP_HEADER *HttpHeader, IN EFI_HTTP_HEADER *HttpHeader,
IN CHAR8 *FieldName, IN CHAR8 *FieldName,
IN CHAR8 *FieldValue IN CHAR8 *FieldValue
); );
/** /**
Get one key/value header pair from the raw string. Get one key/value header pair from the raw string.
@param[in] String Pointer to the raw string. @param[in] String Pointer to the raw string.
@param[out] FieldName Pointer to header field's name. @param[out] FieldName Pointer to header field's name.
@param[out] FieldValue Pointer to header field's value. @param[out] FieldValue Pointer to header field's value.
@return Pointer to the next raw string. @return Pointer to the next raw string.
@return NULL if no key/value header pair from this raw string. @return NULL if no key/value header pair from this raw string.
**/ **/
CHAR8 * CHAR8 *
GetFieldNameAndValue ( GetFieldNameAndValue (
IN CHAR8 *String, IN CHAR8 *String,
OUT CHAR8 **FieldName, OUT CHAR8 **FieldName,
OUT CHAR8 **FieldValue OUT CHAR8 **FieldValue
); );
/** /**
Create HTTP header based on a combination of seed header, fields Create HTTP header based on a combination of seed header, fields
to delete, and fields to append. to delete, and fields to append.
The Build() function is used to manage the headers portion of an The Build() function is used to manage the headers portion of an
HTTP message by providing the ability to add, remove, or replace HTTP message by providing the ability to add, remove, or replace
HTTP headers. HTTP headers.
@param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance.
@param[in] SeedMessageSize Size of the initial HTTP header. This can be zero. @param[in] SeedMessageSize Size of the initial HTTP header. This can be zero.
@param[in] SeedMessage Initial HTTP header to be used as a base for @param[in] SeedMessage Initial HTTP header to be used as a base for
building a new HTTP header. If NULL, building a new HTTP header. If NULL,
SeedMessageSize is ignored. SeedMessageSize is ignored.
@param[in] DeleteCount Number of null-terminated HTTP header field names @param[in] DeleteCount Number of null-terminated HTTP header field names
in DeleteList. in DeleteList.
@param[in] DeleteList List of null-terminated HTTP header field names to @param[in] DeleteList List of null-terminated HTTP header field names to
remove from SeedMessage. Only the field names are remove from SeedMessage. Only the field names are
in this list because the field values are irrelevant in this list because the field values are irrelevant
to this operation. to this operation.
@param[in] AppendCount Number of header fields in AppendList. @param[in] AppendCount Number of header fields in AppendList.
@param[in] AppendList List of HTTP headers to populate NewMessage with. @param[in] AppendList List of HTTP headers to populate NewMessage with.
If SeedMessage is not NULL, AppendList will be If SeedMessage is not NULL, AppendList will be
appended to the existing list from SeedMessage in appended to the existing list from SeedMessage in
NewMessage. NewMessage.
@param[out] NewMessageSize Pointer to number of header fields in NewMessage. @param[out] NewMessageSize Pointer to number of header fields in NewMessage.
@param[out] NewMessage Pointer to a new list of HTTP headers based on. @param[out] NewMessage Pointer to a new list of HTTP headers based on.
@retval EFI_SUCCESS Add, remove, and replace operations succeeded. @retval EFI_SUCCESS Add, remove, and replace operations succeeded.
@retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage. @retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
This is NULL. This is NULL.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpUtilitiesBuild ( HttpUtilitiesBuild (
IN EFI_HTTP_UTILITIES_PROTOCOL *This, IN EFI_HTTP_UTILITIES_PROTOCOL *This,
IN UINTN SeedMessageSize, IN UINTN SeedMessageSize,
IN VOID *SeedMessage, OPTIONAL IN VOID *SeedMessage, OPTIONAL
IN UINTN DeleteCount, IN UINTN DeleteCount,
IN CHAR8 *DeleteList[], OPTIONAL IN CHAR8 *DeleteList[], OPTIONAL
IN UINTN AppendCount, IN UINTN AppendCount,
IN EFI_HTTP_HEADER *AppendList[], OPTIONAL IN EFI_HTTP_HEADER *AppendList[], OPTIONAL
OUT UINTN *NewMessageSize, OUT UINTN *NewMessageSize,
OUT VOID **NewMessage OUT VOID **NewMessage
); );
/** /**
Parses HTTP header and produces an array of key/value pairs. Parses HTTP header and produces an array of key/value pairs.
The Parse() function is used to transform data stored in HttpHeader The Parse() function is used to transform data stored in HttpHeader
into a list of fields paired with their corresponding values. into a list of fields paired with their corresponding values.
@param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance.
@param[in] HttpMessage Contains raw unformatted HTTP header string. @param[in] HttpMessage Contains raw unformatted HTTP header string.
@param[in] HttpMessageSize Size of HTTP header. @param[in] HttpMessageSize Size of HTTP header.
@param[out] HeaderFields Array of key/value header pairs. @param[out] HeaderFields Array of key/value header pairs.
@param[out] FieldCount Number of headers in HeaderFields. @param[out] FieldCount Number of headers in HeaderFields.
@retval EFI_SUCCESS Allocation succeeded. @retval EFI_SUCCESS Allocation succeeded.
@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
initialized. initialized.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
This is NULL. This is NULL.
HttpMessage is NULL. HttpMessage is NULL.
HeaderFields is NULL. HeaderFields is NULL.
FieldCount is NULL. FieldCount is NULL.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpUtilitiesParse ( HttpUtilitiesParse (
IN EFI_HTTP_UTILITIES_PROTOCOL *This, IN EFI_HTTP_UTILITIES_PROTOCOL *This,
IN CHAR8 *HttpMessage, IN CHAR8 *HttpMessage,
IN UINTN HttpMessageSize, IN UINTN HttpMessageSize,
OUT EFI_HTTP_HEADER **HeaderFields, OUT EFI_HTTP_HEADER **HeaderFields,
OUT UINTN *FieldCount OUT UINTN *FieldCount
); );
#endif #endif

View File

@ -1,51 +1,51 @@
## @file ## @file
# Implementation of EFI Http Utilities Protocol interfaces. # Implementation of EFI Http Utilities Protocol interfaces.
# #
# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
# #
# This program and the accompanying materials # This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License # are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at # which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php. # http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
# #
# #
## ##
[Defines] [Defines]
INF_VERSION = 0x00010005 INF_VERSION = 0x00010005
BASE_NAME = HttpUtilitiesDxe BASE_NAME = HttpUtilitiesDxe
FILE_GUID = 22ea234f-e72a-11e4-91f9-28d2447c4829 FILE_GUID = 22ea234f-e72a-11e4-91f9-28d2447c4829
MODULE_TYPE = DXE_DRIVER MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0 VERSION_STRING = 1.0
ENTRY_POINT = HttpUtilitiesDxeDriverEntryPoint ENTRY_POINT = HttpUtilitiesDxeDriverEntryPoint
UNLOAD_IMAGE = HttpUtilitiesDxeUnload UNLOAD_IMAGE = HttpUtilitiesDxeUnload
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec MdeModulePkg/MdeModulePkg.dec
[Sources] [Sources]
HttpUtilitiesDxe.h HttpUtilitiesDxe.h
HttpUtilitiesDxe.c HttpUtilitiesDxe.c
HttpUtilitiesImpl.c HttpUtilitiesImpl.c
HttpUtilitiesProtocol.c HttpUtilitiesProtocol.c
[LibraryClasses] [LibraryClasses]
UefiDriverEntryPoint UefiDriverEntryPoint
UefiBootServicesTableLib UefiBootServicesTableLib
MemoryAllocationLib MemoryAllocationLib
BaseMemoryLib BaseMemoryLib
BaseLib BaseLib
UefiLib UefiLib
DebugLib DebugLib
[Protocols] [Protocols]
gEfiHttpUtilitiesProtocolGuid ## PRODUCES gEfiHttpUtilitiesProtocolGuid ## PRODUCES
[Depex] [Depex]
TRUE TRUE
[Guids] [Guids]

View File

@ -1,279 +1,279 @@
/** @file /** @file
The functions for HttpUtilities driver. The functions for HttpUtilities driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php. http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "HttpUtilitiesDxe.h" #include "HttpUtilitiesDxe.h"
/** /**
Get the next string, which is distinguished by specified seperator. Get the next string, which is distinguished by specified seperator.
@param[in] String Pointer to the string. @param[in] String Pointer to the string.
@param[in] Seperator Specified seperator used to distinguish where is the beginning @param[in] Seperator Specified seperator used to distinguish where is the beginning
of next string. of next string.
@return Pointer to the next string. @return Pointer to the next string.
@return NULL if not find or String is NULL. @return NULL if not find or String is NULL.
**/ **/
CHAR8 * CHAR8 *
AsciiStrGetNextToken ( AsciiStrGetNextToken (
IN CONST CHAR8 *String, IN CONST CHAR8 *String,
IN CHAR8 Seperator IN CHAR8 Seperator
) )
{ {
CONST CHAR8 *Token; CONST CHAR8 *Token;
Token = String; Token = String;
while (TRUE) { while (TRUE) {
if (*Token == 0) { if (*Token == 0) {
return NULL; return NULL;
} }
if (*Token == Seperator) { if (*Token == Seperator) {
return (CHAR8 *)(Token + 1); return (CHAR8 *)(Token + 1);
} }
Token++; Token++;
} }
} }
/** /**
Free existing HeaderFields. Free existing HeaderFields.
@param[in] HeaderFields Pointer to array of key/value header pairs waitting for free. @param[in] HeaderFields Pointer to array of key/value header pairs waitting for free.
@param[in] FieldCount The number of header pairs in HeaderFields. @param[in] FieldCount The number of header pairs in HeaderFields.
**/ **/
VOID VOID
FreeHeaderFields ( FreeHeaderFields (
IN EFI_HTTP_HEADER *HeaderFields, IN EFI_HTTP_HEADER *HeaderFields,
IN UINTN FieldCount IN UINTN FieldCount
) )
{ {
UINTN Index; UINTN Index;
if (HeaderFields != NULL) { if (HeaderFields != NULL) {
for (Index = 0; Index < FieldCount; Index++) { for (Index = 0; Index < FieldCount; Index++) {
if (HeaderFields[Index].FieldName != NULL) { if (HeaderFields[Index].FieldName != NULL) {
FreePool (HeaderFields[Index].FieldName); FreePool (HeaderFields[Index].FieldName);
} }
if (HeaderFields[Index].FieldValue != NULL) { if (HeaderFields[Index].FieldValue != NULL) {
FreePool (HeaderFields[Index].FieldValue); FreePool (HeaderFields[Index].FieldValue);
} }
} }
FreePool (HeaderFields); FreePool (HeaderFields);
} }
} }
/** /**
Find required header field in HeaderFields. Find required header field in HeaderFields.
@param[in] HeaderFields Pointer to array of key/value header pairs. @param[in] HeaderFields Pointer to array of key/value header pairs.
@param[in] FieldCount The number of header pairs. @param[in] FieldCount The number of header pairs.
@param[in] FieldName Pointer to header field's name. @param[in] FieldName Pointer to header field's name.
@return Pointer to the queried header field. @return Pointer to the queried header field.
@return NULL if not find this required header field. @return NULL if not find this required header field.
**/ **/
EFI_HTTP_HEADER * EFI_HTTP_HEADER *
FindHttpHeader ( FindHttpHeader (
IN EFI_HTTP_HEADER *HeaderFields, IN EFI_HTTP_HEADER *HeaderFields,
IN UINTN FieldCount, IN UINTN FieldCount,
IN CHAR8 *FieldName IN CHAR8 *FieldName
) )
{ {
UINTN Index; UINTN Index;
for (Index = 0; Index < FieldCount; Index++) { for (Index = 0; Index < FieldCount; Index++) {
if (AsciiStrCmp (FieldName, HeaderFields[Index].FieldName) == 0) { if (AsciiStrCmp (FieldName, HeaderFields[Index].FieldName) == 0) {
// //
// Find the required header field. // Find the required header field.
// //
return &HeaderFields[Index]; return &HeaderFields[Index];
} }
} }
return NULL; return NULL;
} }
/** /**
Check whether header field called FieldName is in DeleteList. Check whether header field called FieldName is in DeleteList.
@param[in] DeleteList Pointer to array of key/value header pairs. @param[in] DeleteList Pointer to array of key/value header pairs.
@param[in] DeleteCount The number of header pairs. @param[in] DeleteCount The number of header pairs.
@param[in] FieldName Pointer to header field's name. @param[in] FieldName Pointer to header field's name.
@return TRUE if FieldName is not in DeleteList, that means this header field is valid. @return TRUE if FieldName is not in DeleteList, that means this header field is valid.
@return FALSE if FieldName is in DeleteList, that means this header field is invalid. @return FALSE if FieldName is in DeleteList, that means this header field is invalid.
**/ **/
BOOLEAN BOOLEAN
IsValidHttpHeader ( IsValidHttpHeader (
IN CHAR8 *DeleteList[], IN CHAR8 *DeleteList[],
IN UINTN DeleteCount, IN UINTN DeleteCount,
IN CHAR8 *FieldName IN CHAR8 *FieldName
) )
{ {
UINTN Index; UINTN Index;
for (Index = 0; Index < DeleteCount; Index++) { for (Index = 0; Index < DeleteCount; Index++) {
if (AsciiStrCmp (FieldName, DeleteList[Index]) == 0) { if (AsciiStrCmp (FieldName, DeleteList[Index]) == 0) {
return FALSE; return FALSE;
} }
} }
return TRUE; return TRUE;
} }
/** /**
Set FieldName and FieldValue into specified HttpHeader. Set FieldName and FieldValue into specified HttpHeader.
@param[in] HttpHeader Specified HttpHeader. @param[in] HttpHeader Specified HttpHeader.
@param[in] FieldName FieldName of this HttpHeader. @param[in] FieldName FieldName of this HttpHeader.
@param[in] FieldValue FieldValue of this HttpHeader. @param[in] FieldValue FieldValue of this HttpHeader.
@retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully. @retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
**/ **/
EFI_STATUS EFI_STATUS
SetFieldNameAndValue ( SetFieldNameAndValue (
IN EFI_HTTP_HEADER *HttpHeader, IN EFI_HTTP_HEADER *HttpHeader,
IN CHAR8 *FieldName, IN CHAR8 *FieldName,
IN CHAR8 *FieldValue IN CHAR8 *FieldValue
) )
{ {
UINTN FieldNameSize; UINTN FieldNameSize;
UINTN FieldValueSize; UINTN FieldValueSize;
if (HttpHeader->FieldName != NULL) { if (HttpHeader->FieldName != NULL) {
FreePool (HttpHeader->FieldName); FreePool (HttpHeader->FieldName);
} }
if (HttpHeader->FieldValue != NULL) { if (HttpHeader->FieldValue != NULL) {
FreePool (HttpHeader->FieldValue); FreePool (HttpHeader->FieldValue);
} }
FieldNameSize = AsciiStrSize (FieldName); FieldNameSize = AsciiStrSize (FieldName);
HttpHeader->FieldName = AllocateZeroPool (FieldNameSize); HttpHeader->FieldName = AllocateZeroPool (FieldNameSize);
if (HttpHeader->FieldName == NULL) { if (HttpHeader->FieldName == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (HttpHeader->FieldName, FieldName, FieldNameSize); CopyMem (HttpHeader->FieldName, FieldName, FieldNameSize);
HttpHeader->FieldName[FieldNameSize - 1] = 0; HttpHeader->FieldName[FieldNameSize - 1] = 0;
FieldValueSize = AsciiStrSize (FieldValue); FieldValueSize = AsciiStrSize (FieldValue);
HttpHeader->FieldValue = AllocateZeroPool (FieldValueSize); HttpHeader->FieldValue = AllocateZeroPool (FieldValueSize);
if (HttpHeader->FieldValue == NULL) { if (HttpHeader->FieldValue == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (HttpHeader->FieldValue, FieldValue, FieldValueSize); CopyMem (HttpHeader->FieldValue, FieldValue, FieldValueSize);
HttpHeader->FieldValue[FieldValueSize - 1] = 0; HttpHeader->FieldValue[FieldValueSize - 1] = 0;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Get one key/value header pair from the raw string. Get one key/value header pair from the raw string.
@param[in] String Pointer to the raw string. @param[in] String Pointer to the raw string.
@param[out] FieldName Pointer to header field's name. @param[out] FieldName Pointer to header field's name.
@param[out] FieldValue Pointer to header field's value. @param[out] FieldValue Pointer to header field's value.
@return Pointer to the next raw string. @return Pointer to the next raw string.
@return NULL if no key/value header pair from this raw string. @return NULL if no key/value header pair from this raw string.
**/ **/
CHAR8 * CHAR8 *
GetFieldNameAndValue ( GetFieldNameAndValue (
IN CHAR8 *String, IN CHAR8 *String,
OUT CHAR8 **FieldName, OUT CHAR8 **FieldName,
OUT CHAR8 **FieldValue OUT CHAR8 **FieldValue
) )
{ {
CHAR8 *FieldNameStr; CHAR8 *FieldNameStr;
CHAR8 *FieldValueStr; CHAR8 *FieldValueStr;
CHAR8 *StrPtr; CHAR8 *StrPtr;
if (String == NULL || FieldName == NULL || FieldValue == NULL) { if (String == NULL || FieldName == NULL || FieldValue == NULL) {
return NULL; return NULL;
} }
*FieldName = NULL; *FieldName = NULL;
*FieldValue = NULL; *FieldValue = NULL;
FieldNameStr = NULL; FieldNameStr = NULL;
FieldValueStr = NULL; FieldValueStr = NULL;
StrPtr = NULL; StrPtr = NULL;
// //
// Each header field consists of a name followed by a colon (":") and the field value. // Each header field consists of a name followed by a colon (":") and the field value.
// //
FieldNameStr = String; FieldNameStr = String;
FieldValueStr = AsciiStrGetNextToken (FieldNameStr, ':'); FieldValueStr = AsciiStrGetNextToken (FieldNameStr, ':');
if (FieldValueStr == NULL) { if (FieldValueStr == NULL) {
return NULL; return NULL;
} }
// //
// Replace ':' with 0 // Replace ':' with 0
// //
*(FieldValueStr - 1) = 0; *(FieldValueStr - 1) = 0;
// //
// The field value MAY be preceded by any amount of LWS, though a single SP is preferred. // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.
// //
while (TRUE) { while (TRUE) {
if (*FieldValueStr == ' ' || *FieldValueStr == '\t') { if (*FieldValueStr == ' ' || *FieldValueStr == '\t') {
FieldValueStr ++; FieldValueStr ++;
} else if (*FieldValueStr == '\r' && *(FieldValueStr + 1) == '\n' && } else if (*FieldValueStr == '\r' && *(FieldValueStr + 1) == '\n' &&
(*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t')) { (*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t')) {
FieldValueStr = FieldValueStr + 3; FieldValueStr = FieldValueStr + 3;
} else { } else {
break; break;
} }
} }
// //
// Header fields can be extended over multiple lines by preceding each extra // Header fields can be extended over multiple lines by preceding each extra
// line with at least one SP or HT. // line with at least one SP or HT.
// //
StrPtr = FieldValueStr; StrPtr = FieldValueStr;
do { do {
StrPtr = AsciiStrGetNextToken (StrPtr, '\r'); StrPtr = AsciiStrGetNextToken (StrPtr, '\r');
if (StrPtr == NULL || *StrPtr != '\n') { if (StrPtr == NULL || *StrPtr != '\n') {
return NULL; return NULL;
} }
StrPtr++; StrPtr++;
} while (*StrPtr == ' ' || *StrPtr == '\t'); } while (*StrPtr == ' ' || *StrPtr == '\t');
// //
// Replace '\r' with 0 // Replace '\r' with 0
// //
*(StrPtr - 2) = 0; *(StrPtr - 2) = 0;
// //
// Get FieldName and FieldValue. // Get FieldName and FieldValue.
// //
*FieldName = FieldNameStr; *FieldName = FieldNameStr;
*FieldValue = FieldValueStr; *FieldValue = FieldValueStr;
return StrPtr; return StrPtr;
} }

View File

@ -1,393 +1,393 @@
/** @file /** @file
Implementation of EFI_HTTP_PROTOCOL protocol interfaces. Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "HttpUtilitiesDxe.h" #include "HttpUtilitiesDxe.h"
EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol = { EFI_HTTP_UTILITIES_PROTOCOL mHttpUtilitiesProtocol = {
HttpUtilitiesBuild, HttpUtilitiesBuild,
HttpUtilitiesParse HttpUtilitiesParse
}; };
/** /**
Create HTTP header based on a combination of seed header, fields Create HTTP header based on a combination of seed header, fields
to delete, and fields to append. to delete, and fields to append.
The Build() function is used to manage the headers portion of an The Build() function is used to manage the headers portion of an
HTTP message by providing the ability to add, remove, or replace HTTP message by providing the ability to add, remove, or replace
HTTP headers. HTTP headers.
@param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance.
@param[in] SeedMessageSize Size of the initial HTTP header. This can be zero. @param[in] SeedMessageSize Size of the initial HTTP header. This can be zero.
@param[in] SeedMessage Initial HTTP header to be used as a base for @param[in] SeedMessage Initial HTTP header to be used as a base for
building a new HTTP header. If NULL, building a new HTTP header. If NULL,
SeedMessageSize is ignored. SeedMessageSize is ignored.
@param[in] DeleteCount Number of null-terminated HTTP header field names @param[in] DeleteCount Number of null-terminated HTTP header field names
in DeleteList. in DeleteList.
@param[in] DeleteList List of null-terminated HTTP header field names to @param[in] DeleteList List of null-terminated HTTP header field names to
remove from SeedMessage. Only the field names are remove from SeedMessage. Only the field names are
in this list because the field values are irrelevant in this list because the field values are irrelevant
to this operation. to this operation.
@param[in] AppendCount Number of header fields in AppendList. @param[in] AppendCount Number of header fields in AppendList.
@param[in] AppendList List of HTTP headers to populate NewMessage with. @param[in] AppendList List of HTTP headers to populate NewMessage with.
If SeedMessage is not NULL, AppendList will be If SeedMessage is not NULL, AppendList will be
appended to the existing list from SeedMessage in appended to the existing list from SeedMessage in
NewMessage. NewMessage.
@param[out] NewMessageSize Pointer to number of header fields in NewMessage. @param[out] NewMessageSize Pointer to number of header fields in NewMessage.
@param[out] NewMessage Pointer to a new list of HTTP headers based on. @param[out] NewMessage Pointer to a new list of HTTP headers based on.
@retval EFI_SUCCESS Add, remove, and replace operations succeeded. @retval EFI_SUCCESS Add, remove, and replace operations succeeded.
@retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage. @retval EFI_OUT_OF_RESOURCES Could not allocate memory for NewMessage.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
This is NULL. This is NULL.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpUtilitiesBuild ( HttpUtilitiesBuild (
IN EFI_HTTP_UTILITIES_PROTOCOL *This, IN EFI_HTTP_UTILITIES_PROTOCOL *This,
IN UINTN SeedMessageSize, IN UINTN SeedMessageSize,
IN VOID *SeedMessage, OPTIONAL IN VOID *SeedMessage, OPTIONAL
IN UINTN DeleteCount, IN UINTN DeleteCount,
IN CHAR8 *DeleteList[], OPTIONAL IN CHAR8 *DeleteList[], OPTIONAL
IN UINTN AppendCount, IN UINTN AppendCount,
IN EFI_HTTP_HEADER *AppendList[], OPTIONAL IN EFI_HTTP_HEADER *AppendList[], OPTIONAL
OUT UINTN *NewMessageSize, OUT UINTN *NewMessageSize,
OUT VOID **NewMessage OUT VOID **NewMessage
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_HTTP_HEADER *SeedHeaderFields; EFI_HTTP_HEADER *SeedHeaderFields;
UINTN SeedFieldCount; UINTN SeedFieldCount;
UINTN Index; UINTN Index;
EFI_HTTP_HEADER *TempHeaderFields; EFI_HTTP_HEADER *TempHeaderFields;
UINTN TempFieldCount; UINTN TempFieldCount;
EFI_HTTP_HEADER *NewHeaderFields; EFI_HTTP_HEADER *NewHeaderFields;
UINTN NewFieldCount; UINTN NewFieldCount;
EFI_HTTP_HEADER *HttpHeader; EFI_HTTP_HEADER *HttpHeader;
UINTN StrLength; UINTN StrLength;
UINT8 *NewMessagePtr; UINT8 *NewMessagePtr;
SeedHeaderFields = NULL; SeedHeaderFields = NULL;
SeedFieldCount = 0; SeedFieldCount = 0;
TempHeaderFields = NULL; TempHeaderFields = NULL;
TempFieldCount = 0; TempFieldCount = 0;
NewHeaderFields = NULL; NewHeaderFields = NULL;
NewFieldCount = 0; NewFieldCount = 0;
HttpHeader = NULL; HttpHeader = NULL;
StrLength = 0; StrLength = 0;
NewMessagePtr = NULL; NewMessagePtr = NULL;
*NewMessageSize = 0; *NewMessageSize = 0;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
if (This == NULL) { if (This == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (SeedMessage != NULL) { if (SeedMessage != NULL) {
Status = This->Parse ( Status = This->Parse (
This, This,
SeedMessage, SeedMessage,
SeedMessageSize, SeedMessageSize,
&SeedHeaderFields, &SeedHeaderFields,
&SeedFieldCount &SeedFieldCount
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ON_EXIT; goto ON_EXIT;
} }
} }
// //
// Handle DeleteList // Handle DeleteList
// //
if (SeedFieldCount != 0 && DeleteCount != 0) { if (SeedFieldCount != 0 && DeleteCount != 0) {
TempHeaderFields = AllocateZeroPool (SeedFieldCount * sizeof(EFI_HTTP_HEADER)); TempHeaderFields = AllocateZeroPool (SeedFieldCount * sizeof(EFI_HTTP_HEADER));
if (TempHeaderFields == NULL) { if (TempHeaderFields == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT; goto ON_EXIT;
} }
for (Index = 0, TempFieldCount = 0; Index < SeedFieldCount; Index++) { for (Index = 0, TempFieldCount = 0; Index < SeedFieldCount; Index++) {
// //
// Check whether each SeedHeaderFields member is in DeleteList // Check whether each SeedHeaderFields member is in DeleteList
// //
if (IsValidHttpHeader( DeleteList, DeleteCount, SeedHeaderFields[Index].FieldName)) { if (IsValidHttpHeader( DeleteList, DeleteCount, SeedHeaderFields[Index].FieldName)) {
Status = SetFieldNameAndValue ( Status = SetFieldNameAndValue (
&TempHeaderFields[TempFieldCount], &TempHeaderFields[TempFieldCount],
SeedHeaderFields[Index].FieldName, SeedHeaderFields[Index].FieldName,
SeedHeaderFields[Index].FieldValue SeedHeaderFields[Index].FieldValue
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ON_EXIT; goto ON_EXIT;
} }
TempFieldCount++; TempFieldCount++;
} }
} }
} else { } else {
TempHeaderFields = SeedHeaderFields; TempHeaderFields = SeedHeaderFields;
TempFieldCount = SeedFieldCount; TempFieldCount = SeedFieldCount;
} }
// //
// Handle AppendList // Handle AppendList
// //
NewHeaderFields = AllocateZeroPool ((TempFieldCount + AppendCount) * sizeof (EFI_HTTP_HEADER)); NewHeaderFields = AllocateZeroPool ((TempFieldCount + AppendCount) * sizeof (EFI_HTTP_HEADER));
if (NewHeaderFields == NULL) { if (NewHeaderFields == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT; goto ON_EXIT;
} }
for (Index = 0; Index < TempFieldCount; Index++) { for (Index = 0; Index < TempFieldCount; Index++) {
Status = SetFieldNameAndValue ( Status = SetFieldNameAndValue (
&NewHeaderFields[Index], &NewHeaderFields[Index],
TempHeaderFields[Index].FieldName, TempHeaderFields[Index].FieldName,
TempHeaderFields[Index].FieldValue TempHeaderFields[Index].FieldValue
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ON_EXIT; goto ON_EXIT;
} }
} }
NewFieldCount = TempFieldCount; NewFieldCount = TempFieldCount;
for (Index = 0; Index < AppendCount; Index++) { for (Index = 0; Index < AppendCount; Index++) {
HttpHeader = FindHttpHeader (NewHeaderFields, NewFieldCount, AppendList[Index]->FieldName); HttpHeader = FindHttpHeader (NewHeaderFields, NewFieldCount, AppendList[Index]->FieldName);
if (HttpHeader != NULL) { if (HttpHeader != NULL) {
Status = SetFieldNameAndValue ( Status = SetFieldNameAndValue (
HttpHeader, HttpHeader,
AppendList[Index]->FieldName, AppendList[Index]->FieldName,
AppendList[Index]->FieldValue AppendList[Index]->FieldValue
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ON_EXIT; goto ON_EXIT;
} }
} else { } else {
Status = SetFieldNameAndValue ( Status = SetFieldNameAndValue (
&NewHeaderFields[NewFieldCount], &NewHeaderFields[NewFieldCount],
AppendList[Index]->FieldName, AppendList[Index]->FieldName,
AppendList[Index]->FieldValue AppendList[Index]->FieldValue
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ON_EXIT; goto ON_EXIT;
} }
NewFieldCount++; NewFieldCount++;
} }
} }
// //
// Calculate NewMessageSize, then build NewMessage // Calculate NewMessageSize, then build NewMessage
// //
for (Index = 0; Index < NewFieldCount; Index++) { for (Index = 0; Index < NewFieldCount; Index++) {
HttpHeader = &NewHeaderFields[Index]; HttpHeader = &NewHeaderFields[Index];
StrLength = AsciiStrLen (HttpHeader->FieldName); StrLength = AsciiStrLen (HttpHeader->FieldName);
*NewMessageSize += StrLength; *NewMessageSize += StrLength;
StrLength = sizeof(": ") - 1; StrLength = sizeof(": ") - 1;
*NewMessageSize += StrLength; *NewMessageSize += StrLength;
StrLength = AsciiStrLen (HttpHeader->FieldValue); StrLength = AsciiStrLen (HttpHeader->FieldValue);
*NewMessageSize += StrLength; *NewMessageSize += StrLength;
StrLength = sizeof("\r\n") - 1; StrLength = sizeof("\r\n") - 1;
*NewMessageSize += StrLength; *NewMessageSize += StrLength;
} }
StrLength = sizeof("\r\n") - 1; StrLength = sizeof("\r\n") - 1;
*NewMessageSize += StrLength; *NewMessageSize += StrLength;
// //
// Final 0 for end flag // Final 0 for end flag
// //
*NewMessageSize += 1; *NewMessageSize += 1;
*NewMessage = AllocateZeroPool (*NewMessageSize); *NewMessage = AllocateZeroPool (*NewMessageSize);
if (*NewMessage == NULL) { if (*NewMessage == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT; goto ON_EXIT;
} }
NewMessagePtr = (UINT8 *)(*NewMessage); NewMessagePtr = (UINT8 *)(*NewMessage);
for (Index = 0; Index < NewFieldCount; Index++) { for (Index = 0; Index < NewFieldCount; Index++) {
HttpHeader = &NewHeaderFields[Index]; HttpHeader = &NewHeaderFields[Index];
StrLength = AsciiStrLen (HttpHeader->FieldName); StrLength = AsciiStrLen (HttpHeader->FieldName);
CopyMem (NewMessagePtr, HttpHeader->FieldName, StrLength); CopyMem (NewMessagePtr, HttpHeader->FieldName, StrLength);
NewMessagePtr += StrLength; NewMessagePtr += StrLength;
StrLength = sizeof(": ") - 1; StrLength = sizeof(": ") - 1;
CopyMem (NewMessagePtr, ": ", StrLength); CopyMem (NewMessagePtr, ": ", StrLength);
NewMessagePtr += StrLength; NewMessagePtr += StrLength;
StrLength = AsciiStrLen (HttpHeader->FieldValue); StrLength = AsciiStrLen (HttpHeader->FieldValue);
CopyMem (NewMessagePtr, HttpHeader->FieldValue, StrLength); CopyMem (NewMessagePtr, HttpHeader->FieldValue, StrLength);
NewMessagePtr += StrLength; NewMessagePtr += StrLength;
StrLength = sizeof("\r\n") - 1; StrLength = sizeof("\r\n") - 1;
CopyMem (NewMessagePtr, "\r\n", StrLength); CopyMem (NewMessagePtr, "\r\n", StrLength);
NewMessagePtr += StrLength; NewMessagePtr += StrLength;
} }
StrLength = sizeof("\r\n") - 1; StrLength = sizeof("\r\n") - 1;
CopyMem (NewMessagePtr, "\r\n", StrLength); CopyMem (NewMessagePtr, "\r\n", StrLength);
NewMessagePtr += StrLength; NewMessagePtr += StrLength;
*NewMessagePtr = 0; *NewMessagePtr = 0;
ASSERT (*NewMessageSize == (UINTN)NewMessagePtr - (UINTN)(*NewMessage) + 1); ASSERT (*NewMessageSize == (UINTN)NewMessagePtr - (UINTN)(*NewMessage) + 1);
// //
// Free allocated buffer // Free allocated buffer
// //
ON_EXIT: ON_EXIT:
if (SeedHeaderFields != NULL) { if (SeedHeaderFields != NULL) {
FreeHeaderFields(SeedHeaderFields, SeedFieldCount); FreeHeaderFields(SeedHeaderFields, SeedFieldCount);
} }
if (TempHeaderFields != NULL) { if (TempHeaderFields != NULL) {
FreeHeaderFields(TempHeaderFields, TempFieldCount); FreeHeaderFields(TempHeaderFields, TempFieldCount);
} }
if (NewHeaderFields != NULL) { if (NewHeaderFields != NULL) {
FreeHeaderFields(NewHeaderFields, NewFieldCount); FreeHeaderFields(NewHeaderFields, NewFieldCount);
} }
return Status; return Status;
} }
/** /**
Parses HTTP header and produces an array of key/value pairs. Parses HTTP header and produces an array of key/value pairs.
The Parse() function is used to transform data stored in HttpHeader The Parse() function is used to transform data stored in HttpHeader
into a list of fields paired with their corresponding values. into a list of fields paired with their corresponding values.
@param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance. @param[in] This Pointer to EFI_HTTP_UTILITIES_PROTOCOL instance.
@param[in] HttpMessage Contains raw unformatted HTTP header string. @param[in] HttpMessage Contains raw unformatted HTTP header string.
@param[in] HttpMessageSize Size of HTTP header. @param[in] HttpMessageSize Size of HTTP header.
@param[out] HeaderFields Array of key/value header pairs. @param[out] HeaderFields Array of key/value header pairs.
@param[out] FieldCount Number of headers in HeaderFields. @param[out] FieldCount Number of headers in HeaderFields.
@retval EFI_SUCCESS Allocation succeeded. @retval EFI_SUCCESS Allocation succeeded.
@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
initialized. initialized.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
This is NULL. This is NULL.
HttpMessage is NULL. HttpMessage is NULL.
HeaderFields is NULL. HeaderFields is NULL.
FieldCount is NULL. FieldCount is NULL.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
HttpUtilitiesParse ( HttpUtilitiesParse (
IN EFI_HTTP_UTILITIES_PROTOCOL *This, IN EFI_HTTP_UTILITIES_PROTOCOL *This,
IN CHAR8 *HttpMessage, IN CHAR8 *HttpMessage,
IN UINTN HttpMessageSize, IN UINTN HttpMessageSize,
OUT EFI_HTTP_HEADER **HeaderFields, OUT EFI_HTTP_HEADER **HeaderFields,
OUT UINTN *FieldCount OUT UINTN *FieldCount
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
CHAR8 *TempHttpMessage; CHAR8 *TempHttpMessage;
CHAR8 *Token; CHAR8 *Token;
CHAR8 *NextToken; CHAR8 *NextToken;
CHAR8 *FieldName; CHAR8 *FieldName;
CHAR8 *FieldValue; CHAR8 *FieldValue;
UINTN Index; UINTN Index;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
TempHttpMessage = NULL; TempHttpMessage = NULL;
*FieldCount = 0; *FieldCount = 0;
Token = NULL; Token = NULL;
NextToken = NULL; NextToken = NULL;
FieldName = NULL; FieldName = NULL;
FieldValue = NULL; FieldValue = NULL;
Index = 0; Index = 0;
if (This == NULL || HttpMessage == NULL || HeaderFields == NULL || FieldCount == NULL) { if (This == NULL || HttpMessage == NULL || HeaderFields == NULL || FieldCount == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
TempHttpMessage = AllocateZeroPool (HttpMessageSize); TempHttpMessage = AllocateZeroPool (HttpMessageSize);
if (TempHttpMessage == NULL) { if (TempHttpMessage == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize); CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize);
// //
// Get header number // Get header number
// //
Token = TempHttpMessage; Token = TempHttpMessage;
while (TRUE) { while (TRUE) {
FieldName = NULL; FieldName = NULL;
FieldValue = NULL; FieldValue = NULL;
NextToken = GetFieldNameAndValue (Token, &FieldName, &FieldValue); NextToken = GetFieldNameAndValue (Token, &FieldName, &FieldValue);
Token = NextToken; Token = NextToken;
if (FieldName == NULL || FieldValue == NULL) { if (FieldName == NULL || FieldValue == NULL) {
break; break;
} }
(*FieldCount)++; (*FieldCount)++;
} }
if (*FieldCount == 0) { if (*FieldCount == 0) {
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto ON_EXIT; goto ON_EXIT;
} }
// //
// Allocate buffer for header // Allocate buffer for header
// //
*HeaderFields = AllocateZeroPool ((*FieldCount) * sizeof(EFI_HTTP_HEADER)); *HeaderFields = AllocateZeroPool ((*FieldCount) * sizeof(EFI_HTTP_HEADER));
if (*HeaderFields == NULL) { if (*HeaderFields == NULL) {
*FieldCount = 0; *FieldCount = 0;
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT; goto ON_EXIT;
} }
CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize); CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize);
// //
// Set Field and Value to each header // Set Field and Value to each header
// //
Token = TempHttpMessage; Token = TempHttpMessage;
while (Index < *FieldCount) { while (Index < *FieldCount) {
FieldName = NULL; FieldName = NULL;
FieldValue = NULL; FieldValue = NULL;
NextToken = GetFieldNameAndValue (Token, &FieldName, &FieldValue); NextToken = GetFieldNameAndValue (Token, &FieldName, &FieldValue);
Token = NextToken; Token = NextToken;
if (FieldName == NULL || FieldValue == NULL) { if (FieldName == NULL || FieldValue == NULL) {
break; break;
} }
Status = SetFieldNameAndValue (&(*HeaderFields)[Index], FieldName, FieldValue); Status = SetFieldNameAndValue (&(*HeaderFields)[Index], FieldName, FieldValue);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
*FieldCount = 0; *FieldCount = 0;
FreeHeaderFields (*HeaderFields, Index); FreeHeaderFields (*HeaderFields, Index);
goto ON_EXIT; goto ON_EXIT;
} }
Index++; Index++;
} }
// //
// Free allocated buffer // Free allocated buffer
// //
ON_EXIT: ON_EXIT:
if (TempHttpMessage != NULL) { if (TempHttpMessage != NULL) {
FreePool (TempHttpMessage); FreePool (TempHttpMessage);
} }
return Status; return Status;
} }