/*****************************************************************************
* Copyright (c) 2005 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/

#ifndef IAM_PARAMS_H
#define IAM_PARAMS_H

#include "iam.hh"

#ifdef __cplusplus
extern "C" {
#endif

/*ad*
 * Bitmask to enable Static IPv6 address in ipv6IsEnabled of @link NaIamStaticParams_t.
 *
 * @external
 * @include  "iam.hh"
 * @category Networking:IAM:iam_params
 * @since 7.5
*ad*/
#define		NA_IAM_STATICV6_ENABLED		0x1

/*ad*
 * Bitmask to enable DHCPv6 address in ipv6IsEnabled of @link NaIamStaticParams_t.
 *
 * @external
 * @include  "iam.hh"
 * @category Networking:IAM:iam_params
 * @since 7.5
*ad*/
#define		NA_IAM_DHCPV6_ENABLED		0x2

/*ad*
 * Static method NVRAM settings structure for a particular interface/multihome pair.
 *
 * @external
 * @include "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.0
 *
 * @param isEnabled     TRUE if this method is enabled on the interface/multihome.
 * @param ipAddress     IPv4 address in network byte order.
 * @param ipv6Address   Static IPv6 address (manually configured). 
 * @param subnetMask    IPv4 address subnet mask.
 * @param ipv6PrefixLen Network prefix lenght of Static IPv6 address.
 * @param ipv6IsEnabled Bit mask to enable DHCPv6 and Static IPv6 address:
 *          <list type="unordered">
 *              <item> NA_IAM_STATICV6_ENABLED  (1) Static IPv6 is enabled </item>
 *              <item> NA_IAM_DHCPV6_ENABLED    (2) DHCPv6 is enabled </item>
 *          </list>
 * @param gateway       Default gateway IPv4 address in network byte order.	
 * @param primaryDns    Primary DNS server IP address in network byte order.
 * @param secondaryDns 	Secondary DNS server IP address in network byte order.
 * @param gatewayTunnel Default gateway tunnel for running IPv6 over IPv4.
*ad*/
typedef struct 
{
    BOOLEAN isEnabled; 
    struct  sockaddr_storage ipAddress;
    struct  sockaddr_storage ipv6Address; 
    WORD32  subnetMask;
    WORD8   ipv6PrefixLen;
	WORD8	ipv6IsEnabled;
    struct  sockaddr_storage gateway;
    struct  sockaddr_storage primaryDns;
    struct  sockaddr_storage secondaryDns;
    struct  sockaddr_storage gatewayTunnel;
} NaIamStaticParams_t;

/*ad*
 * DHCP method NVRAM settings structure for a particular interface/multihome pair. 
 *
 * @external
 * @include "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.0
 *
 * @param isEnabled      TRUE if this method is enabled on the interface/multihome.
 * @param optionsBuffer  Pointer to the formatted options buffer in network byte order.
 * @param optionsLength  Length of options buffer in bytes.
*ad*/
typedef struct 
{
    BOOLEAN  isEnabled; 
    char    optionsBuffer[NA_IAM_DHCP_OPTIONS_BUFFER_LEN];
    WORD32  optionsLength; 
} NaIamDhcpParams_t;


/*ad*
 * Auto IP method NVRAM settings structure for a particular interface/multihome pair. 
 *
 * @external
 * @include "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.0
 *
 * @param isEnabled      TRUE if this method is enabled on the interface/multihome.
*ad*/
typedef struct 
{
    BOOLEAN isEnabled; 
} NaIamAutoipParams_t;


/*ad*
 * IAM NVRAM settings structure structure for a specific interface/multihome pair.
 *
 * @external
 * @include "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.0
 *
 * @param  isEnabled       TRUE if IAM is to be used for this interface/multihome.
 * @param  isConfigValid   TRUE if record has been previously configured. 
 * @param  ifname          nul-terminated name of the interface/multihome in the "ethx:x/wlnx:x" format. 
 * @param  staticParams    Static method configuration.
 * @param  dhcpParams      DHCP method configuration.
 * @param  autoipParams    AutoIP method configuration.
 *
*ad*/
typedef struct
{
    BOOLEAN isEnabled;
    BOOLEAN isConfigValid;
    char ifname[MAX_IF_NAMELEN + 1];
    NaIamStaticParams_t     staticParams;
    NaIamDhcpParams_t       dhcpParams;
    NaIamAutoipParams_t     autoipParams;
} NaIamParams_t;

/*ad*
 * The main NVRAM IAM structure. 
 *
 * @external
 * @include "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.0
 *
 * @param	version	   IAM NVRAM record version number.
 * @param	iamParams  IAM NVRAM record.
 *
*ad*/
typedef struct
{
    int version;
    NaIamParams_t    iamParams[NA_IAM_INTERFACE_MAX];
} NaIamParamsInfo_t;


#define NaIpv6IsStaticEnabled(ifparams) ((ifparams)->staticParams.ipv6IsEnabled & NA_IAM_STATICV6_ENABLED)
#define NaIpv6IsDhcpEnabled(ifparams) ((ifparams)->staticParams.ipv6IsEnabled & NA_IAM_DHCPV6_ENABLED)

#define NaIpv6SetStaticEnabled(ifparams, state) \
{ \
  if (state) \
	 (ifparams)->staticParams.ipv6IsEnabled |= NA_IAM_STATICV6_ENABLED; \
  else \
	 (ifparams)->staticParams.ipv6IsEnabled &= ~NA_IAM_STATICV6_ENABLED; \
}

#define NaIpv6SetDhcpEnabled(ifparams, state) \
{ \
  if (state) \
	 (ifparams)->staticParams.ipv6IsEnabled |= NA_IAM_DHCPV6_ENABLED; \
  else \
	 (ifparams)->staticParams.ipv6IsEnabled &= ~NA_IAM_DHCPV6_ENABLED; \
}

/*ad*
 * Number of entries in @link NaIamExParams_t.
 *
 * @external
 * @include  "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.6
*ad*/
#define NA_IAM_EX_ENTRIES        4


/*ad*
 * Number reserved bytes in @link NaIamExParams_t.
 *
 * @external
 * @include  "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.6
*ad*/
#define NA_IAM_EX_PARAMS_RESERVED   256


/*ad*
 * The NVRAM structure for extra IAM parameters. 
 *
 * First two entries are reserved for "eth0" and "wln0". The rest can be used for additional network
 * devices, with some BSP customization.
 *
 * @external
 * @include "iam_params.h"
 * @category Networking:IAM:iam_params
 * @since 7.6
 *
 * @param	ifname	        Array of interface names. 
 *                          <list type="ordered">
 *                              <item> First entry: "eth0", if @link BSP_WANT_ETHERNET is TRUE </item>
 *                              <item> Second entry: "wln0", if @link BSP_WANT_WIRELESS is TRUE </item>
 *                          </list>
 * @param	ipv6gateway     Array of static IPv6 gateway addresses, indexed the same way as ifname array.
 * @param   reserved        Not used.
 *
*ad*/
typedef struct
{
    char   ifname[NA_IAM_EX_ENTRIES][MAX_IF_NAMELEN + 1];
    struct sockaddr_storage ipv6gateway[NA_IAM_EX_ENTRIES];
    char   reserved[NA_IAM_EX_PARAMS_RESERVED];

} NaIamExParams_t;

#ifdef __cplusplus
}
#endif

#endif


