/*====================================================================*
 *   
 *   signed OptionSecurity (signed margin, const char * style);
 *
 *   page.h
 * 
 *   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-2009 by Intellon Corp. ALL RIGHTS RESERVED;
 *;  For demonstration; Not for production use;
 *
 *   Contributor(s):
 *      Charles Maier <charles.maier@atheros.com>
 *
 *--------------------------------------------------------------------*/

#ifndef OPTIONSECURITY_SOURCE
#define OPTIONSECURITY_SOURCE

#include "../cgi/page.h"
#include "../cgi/session.h"
#include "../tools/memory.h"
#include "../crypt/HPAVKey.h"
#include "../tools/format.h"

#define PASSWORD "HomePlugAV"
#define DISABLED "disabled value='not required'"

static signed passwords (signed margin, const char * style) 

{
	extern struct session session;

#ifdef STYLE_KEY

	char string [HPAVKEY_DAK_LEN * 3];

#endif

	unsigned bridge;
	for (bridge = 0; bridge < session.bridges; bridge++) 
	{
		if (!memcmp (session.device.MAC, session.bridge [bridge].MAC, ETHER_ADDR_LEN)) 
		{
			break;
		}
	}
	output (margin++, "<fieldset class='%s'>", style);
	output (margin++, "<legend class='%s'>", style);
	output (margin, "%s", "Passwords");
	output (margin--, "</legend>");
	output (margin++, "<table class='%s'>", style);
	if (bridge == session.bridges) 
	{
		output (margin++, "<tr class='%s'>", style);
		output (margin++, "<th class='%s'>", style);
		output (margin, "%s", "Station");
		output (margin--, "</th>");
		output (margin++, "<td class='%s'>", style);
		output (margin, "<input type='text' maxlength='64' class='%s' name='%s'>", STYLE_PWD, FIELD_DPW);
		output (margin--, "</td>");

#ifdef STYLE_KEY

		output (margin++, "<td class='%s'>", style);
		output (margin, "<input type='text' class='%s' name='%s' value='%s' readonly>", STYLE_KEY, FIELD_DAK, hexstring (string, sizeof (string), session.device.DAK, sizeof (session.device.DAK)));
		output (margin--, "</td>");

#endif

		output (margin--, "</tr>");
	}
	output (margin++, "<tr class='%s'>", style);
	output (margin++, "<th class='%s'>", style);
	output (margin, "%s", "Network");
	output (margin--, "</th>");
	output (margin++, "<td class='%s'>", style);
	output (margin, "<input type='text' maxlength='64' class='%s' name='%s'>", STYLE_PWD, FIELD_NPW);
	output (margin--, "</td>");

#ifdef STYLE_KEY

	output (margin++, "<td class='%s'>", style);
	output (margin, "<input type='text' class='%s' name='%s' value='%s' readonly>", STYLE_KEY, FIELD_NMK, hexstring (string, sizeof (string), session.device.NMK, sizeof (session.device.NMK)));
	output (margin--, "</td>");

#endif

	output (margin--, "</tr>");
	output (margin--, "</table>");
	output (margin--, "</fieldset>");
	return (margin);
}

/*====================================================================*
 *   
 *   signed OptionSecurity (signed margin, const char * style);
 *   
 *   
 *.  Atheros Powerline Toolkit for HomePlug AV;
 *:  Published 2006-2009 by Intellon Corp. ALL RIGHTS RESERVED;
 *;  For demonstration; Not for production use;
 *
 *--------------------------------------------------------------------*/

signed OptionSecurity (signed margin, const char * style) 

{
	output (margin++, "<div class='%s'>", style);
	output (margin++, "<table class='%s'>", style);
	output (margin++, "<tr class='%s'>", style);
	output (margin++, "<td class='%s'>", style);
	margin = passwords (margin, FIELD_KEY);
	output (margin--, "</td>");
	output (margin--, "</tr>");
	output (margin++, "<tr class='%s'>", style);
	output (margin++, "<td class='%s'>", style);
	output (margin, "<input type='submit' class='%s' name='%s' value='%s' title=' Change Network Membership '>", style, SUBMIT_ACTION, ACTION_NETWORK);
	output (margin--, "</td>");
	output (margin++, "<td class='%s'>", style);
	output (margin, "%s", "&nbsp;");
	output (margin--, "</td>");
	output (margin--, "</tr>");
	output (margin--, "</table>");
	output (margin--, "</div>");
	return (margin);
}

#endif