/*====================================================================*
*
* signed pibfile (struct _file_ * pib);
*
* pib.h
*
* open an PIB file and validate it by checking things like file
* size, checksum and selected internal parameters; return a file
* descriptor on success; terminate the program on error;
*
* This software and documentation is the property of Atheros
* Corporation, Ocala, Florida. It is provided 'as is' without
* expressed or implied warranty of any kind to anyone for any
* reason. Atheros assumes no responsibility or liability for
* errors or omissions in the software or documentation and
* reserves the right to make changes without notification.
*
* Atheros customers may modify and distribute the software
* without obligation to Atheros. Since use of this software
* is optional, users shall bear sole responsibility and
* liability for any consequences of it's use.
*
*. Atheros Powerline Toolkit for HomePlug AV;
*: Published 2006-2008 by Intellon Corp. ALL RIGHTS RESERVED;
*; For demonstration; Not for production use;
*
* Contributor(s):
* Charles Maier <charles.maier@atheros.com>
*
*--------------------------------------------------------------------*/
#ifndef PIBFILE_SOURCE
#define PIBFILE_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <memory.h>
#include <errno.h>
#include "../tools/memory.h"
#include "../tools/files.h"
#include "../tools/error.h"
#include "../crypt/HPAVKey.h"
#include "../pib/pib.h"
signed pibfile (struct _file_ * pib)
{
struct simple_pib simple_pib;
if (lseek (pib->file, 0, SEEK_SET))
{
error (1, errno, "Can't rewind %s", pib->name);
}
if (read (pib->file, &simple_pib, sizeof (simple_pib)) < sizeof (simple_pib))
{
error (1, errno, "Can't read header: %s", pib->name);
}
if (lseek (pib->file, 0, SEEK_END) != LE16TOH (simple_pib.PIBLENGTH))
{
error (1, errno, "Bad PIB length: %s", pib->name);
}
if (lseek (pib->file, 0, SEEK_SET))
{
error (1, errno, "Can't rewind %s", pib->name);
}
if (fdchecksum_32 (pib->file, LE16TOH (simple_pib.PIBLENGTH), 0))
{
error (1, errno, "Bad PIB checksum: %s", pib->name);
}
if (lseek (pib->file, 0, SEEK_SET))
{
error (1, errno, "Can't rewind %s", pib->name);
}
return (0);
}
#endif