/*====================================================================*
 *
 *   signed FirmwarePacket (const void * memory);
 *
 *   int6k.h
 *
 *   intercept and print VS_ARPC messages; return 0 if the int6k struct
 *   message buffer contains a VS_ARPC message or -1 if not;
 *
 *   call ARPCPrint () to display or log intercepted ARPC messages;
 *
 *   VS_ARPC is an indication message that requires no response; it is
 *   used for diagnostic reporting;
 *
 *   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 its use. 
 *   
 *.  Atheros Powerline Toolkit for HomePlug AV; 
 *:  Published 2007 by Intellon Corp. ALL RIGHTS RESERVED;
 *;  For demonstration; Not for production use;
 *
 *   Contributor(s):
 *      Charles Maier <charles.maier@atheros.com>
 *
 *--------------------------------------------------------------------*/

#ifndef FIRMWAREPACKET_SOURCE
#define FIRMWAREPACKET_SOURCE

#include <stdint.h>
#include <memory.h>

#include "../int6k/int6k.h"
#include "../int6k/message.h"
#include "../tools/memory.h" 
#include "../mme/mme.h"

signed FirmwarePacket (const void * memory) 

{

	const struct message * message = (const struct message *)(memory);

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	static struct __packed header_int header_arpc = 
	{
		INTELLON_MMV,
		HTOLE16 (VS_ARPC | MMTYPE_IND),
		{
			0x00,
			0xB0,
			0x52 
		}
	};
	struct __packed vs_arpc_ind 
	{
		struct header_eth ethernet;
		struct header_int intellon;
		uint16_t RDATALENGTH;
		uint8_t RDATAOFFSET;
		uint8_t RDATA [1];
	}
	* indicate = (struct vs_arpc_ind *)(message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	if (!memcmp (&indicate->intellon, &header_arpc, sizeof (header_arpc))) 
	{
		ARPCPrint (stdout, &indicate->RDATA [indicate->RDATAOFFSET], LE16TOH (indicate->RDATALENGTH));
		return (-1);
	}
	return (0);
}

#endif