/** @file
Mtftp6 option parse functions implementation.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Mtftp6Impl.h"
"blksize",
"timeout",
"tsize",
"multicast"
};
/**
Parse the NULL terminated ASCII string of multicast option.
@param[in] Str The pointer to the Ascii string of multicast option.
@param[in] ExtInfo The pointer to the option information to be filled.
@retval EFI_SUCCESS Parse the multicast option successfully.
@retval EFI_INVALID_PARAMETER The string is malformatted.
@retval EFI_OUT_OF_RESOURCES Failed to perform the operation due to lack of
resources.
**/
)
{
//
// The multicast option is formated like "addr,port,mc"
// The server can also omit the ip and port, use ",,1"
//
if (*Str == ',') {
} else {
return EFI_OUT_OF_RESOURCES;
}
//
// The IPv6 address locates before comma in the input Str.
//
TempStr++;
}
*TempStr = '\0';
return Status;
}
Str++;
}
}
if (*Str != ',') {
return EFI_INVALID_PARAMETER;
}
Str++;
//
// Convert the port setting. the server can send us a port number or
// empty string. such as the port in ",,1"
//
if (*Str == ',') {
} else {
if (Num > 65535) {
return EFI_INVALID_PARAMETER;
}
while (NET_IS_DIGIT (*Str)) {
Str++;
}
}
if (*Str != ',') {
return EFI_INVALID_PARAMETER;
}
Str++;
//
//
return EFI_INVALID_PARAMETER;
}
while (NET_IS_DIGIT (*Str)) {
Str++;
}
if (*Str != '\0') {
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/**
Parse the MTFTP6 extesion options.
@param[in] Options The pointer to the extension options list.
@param[in] Count The num of the extension options.
@param[in] IsRequest If FALSE, the extension options is included
by a request packet.
@param[in] ExtInfo The pointer to the option information to be filled.
@retval EFI_SUCCESS Parse the multicast option successfully.
@retval EFI_INVALID_PARAMETER There is one option is malformatted at least.
@retval EFI_UNSUPPORTED There is one option is not supported at least.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// block size option, valid value is between [8, 65464]
//
return EFI_INVALID_PARAMETER;
}
//
// timeout option, valid value is between [1, 255]
//
return EFI_INVALID_PARAMETER;
}
//
// tsize option, the biggest transfer supported is 4GB with block size option
//
//
// Multicast option, if it is a request, the value must be a zero string,
// otherwise, it must be like "addr,port,mc" string, mc indicates master.
//
if (!IsRequest) {
return Status;
}
return EFI_INVALID_PARAMETER;
}
} else if (IsRequest) {
//
// If it's a request, unsupported; else if it's a reply, ignore.
//
return EFI_UNSUPPORTED;
}
}
return EFI_SUCCESS;
}
/**
Go through the packet to fill the options array with the start
@param[in] Packet The packet to be checked.
@param[in] PacketLen The length of the packet.
@param[in, out] Count The num of the Options on input.
The actual one on output.
@param[in] Options The option array to be filled.
It is optional.
@retval EFI_SUCCESS The packet has been parsed successfully.
@retval EFI_INVALID_PARAMETER The packet is malformatted.
@retval EFI_BUFFER_TOO_SMALL The Options array is too small.
@retval EFI_PROTOCOL_ERROR An unexpected MTFTPv6 packet was received.
**/
)
{
Num = 0;
//
// process option name and value pairs.
// The last byte is always zero.
//
while (*Cur != 0) {
Cur++;
}
return EFI_PROTOCOL_ERROR;
}
while (*Cur != 0) {
Cur++;
}
Num++;
}
Cur++;
}
//
// Return buffer too small if the buffer passed-in isn't enough.
//
return EFI_BUFFER_TOO_SMALL;
}
return EFI_SUCCESS;
}
/**
Go through the packet, generate option list array and fill it
by the result of parse options.
@param[in] Packet The packet to be checked.
@param[in] PacketLen The length of the packet.
@param[in, out] OptionCount The num of the Options on input.
The actual one on output.
@param[out] OptionList The option list array to be generated
and filled. It is optional.
@retval EFI_SUCCESS The packet has been parsed successfully.
@retval EFI_INVALID_PARAMETER The packet is malformatted.
@retval EFI_PROTOCOL_ERROR There is one option is malformatted at least.
@retval EFI_NOT_FOUND The packet has no options.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the array.
@retval EFI_BUFFER_TOO_SMALL The size of option list array is too small.
**/
)
{
return EFI_INVALID_PARAMETER;
}
*OptionCount = 0;
if (OptionList != NULL) {
*OptionList = NULL;
}
return EFI_INVALID_PARAMETER;
}
//
// The last byte must be zero to terminate the options.
//
return EFI_PROTOCOL_ERROR;
}
//
// Parse packet with NULL buffer for the first time to get the number
// of options in the packet.
//
if (Status != EFI_BUFFER_TOO_SMALL) {
return Status;
}
//
// Return not found if there is no option parsed.
//
if (*OptionCount == 0) {
return EFI_NOT_FOUND;
}
//
// Only need parse out the number of options.
//
if (OptionList == NULL) {
return EFI_SUCCESS;
}
//
// Allocate the buffer according to the option number parsed before.
//
if (*OptionList == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Parse packet with allocated buffer for the second time to fill the pointer array
// of the options in the packet.
//
return Status;
}
return EFI_SUCCESS;
}