/*
* Copyright (c) 2009-2015 Solarflare Communications Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the FreeBSD Project.
*/
#include "efx.h"
#include "efx_impl.h"
/*
* Maximum size of BOOTCFG block across all nics as understood by SFCgPXE.
* A multiple of 0x100 so trailing 0xff characters don't contrinbute to the
* checksum.
*/
static __checkReturn uint8_t
{
unsigned int pos;
return (checksum);
}
static __checkReturn efx_rc_t
{
/* Start parsing tags immediatly after the checksum */
/* Consume tag */
offset++;
break;
}
offset++;
continue;
}
/* Consume length */
goto fail1;
}
/* Consume *length */
goto fail2;
}
}
/* Checksum the entire sector, including bytes after any DHCP_END */
goto fail3;
}
return (0);
return (rc);
}
{
if (rc != 0)
goto fail1;
/*
* We need to read the entire BOOTCFG area to ensure we read all the
* tags, because legacy bootcfg sectors are not guaranteed to end with
* a DHCP_END character. If the user hasn't supplied a sufficiently
* large buffer then use our own buffer.
*/
if (sector_length > BOOTCFG_MAX_SIZE)
if (sector_length > size) {
goto fail2;
}
} else
goto fail3;
if (rc != 0)
goto fail4;
/* Verify that the area is correctly formatted and checksummed */
&used_bytes);
if (rc != 0 || used_bytes == 0) {
used_bytes = 2;
}
/*
* Legacy bootcfg sectors don't terminate with a DHCP_END character.
* Modify the returned payload so it does. BOOTCFG_MAX_SIZE is by
* definition large enough for any valid (per-port) bootcfg sector,
* so reinitialise the sector if there isn't room for the character.
*/
payload[0] = 0;
used_bytes = 1;
}
++used_bytes;
}
/*
* Verify that the user supplied buffer is large enough for the
* entire used bootcfg area, then copy into the user supplied buffer.
*/
if (used_bytes > size) {
goto fail5;
}
if (sector_length > size) {
}
/* Zero out the unused portion of the user buffer */
if (used_bytes < size)
/*
* The checksum includes trailing data after any DHCP_END character,
* which we've just modified (by truncation or appending DHCP_END).
*/
return (0);
if (sector_length > size)
return (rc);
}
{
if (rc != 0)
goto fail1;
if (sector_length > BOOTCFG_MAX_SIZE)
goto fail2;
/* The caller *must* terminate their block with a DHCP_END character */
goto fail3;
}
/* Check that the hardware has support for this much data */
goto fail4;
}
if (rc != 0)
goto fail5;
goto fail6;
}
goto fail7;
/*
* Write the entire sector_length bytes of data in chunks. Zero out
* all data following the DHCP_END, and adjust the checksum
*/
/* Fill chunk */
if (offset < used_bytes)
/* Adjust checksum */
if (offset == 0)
goto fail8;
}
return (0);
return (rc);
}
#endif /* EFSYS_OPT_BOOTCFG */