/*
 *            Copyright (c) 1998-2003 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of 
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,  
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 304                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************
 *
 *  Description
 *  ====================================================================
 *  
 *
 */

#ifndef ace_params_h
#define ace_params_h

#include <limits.h>
#include <time.h>
#include "npttypes.h"
#include "naifconfig.h"
#include "naip_global.h"
#include "ace.h"


#ifdef __cplusplus
extern "C"
{
#endif


/**
 * Size of DHCP options buffer. 
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define CONFIG_ACE_MAX_DHCP_PARAMS		256 /* maximum number of requested DHCP options */
/**
 * Maximum number of characters in a boot file name. 
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define CONFIG_MAX_BOOT_FILE_NAME       128 /* maximum number of characters in a filename */
/**
 * Maximum number of characters in a server host name. 
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define CONFIG_MAX_SERVER_HOST_NAME     64
/**
 * Maximum number of network interfaces running ACE. 
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define CONFIG_ACE_MAX_INTERFACES       2   /* maximum number of ACE contexts */


/* Supported Protocols */ 

/**
 * Code for no protocol. 
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 * @name AceProtocols "Protocols used by ACE"
 *
 * @param ACE_NO_PROTOCOL       Protocol not defined 
 * @param ACE_PROT_BOOTP        BOOTP
 * @param ACE_PROT_DHCP         DHCP
 * @param ACE_PROT_AUTOIP       Auto IP
 * @param ACE_PROT_PING_ARP     Ping ARP
 * @param ACE_PROT_RARP         RARP
 * @param ACE_PROT_STATIC       Static IP address assignment
 * @param ACE_PROT_CUSTOM       Custom-defined protocol
 *
 */   
#define	ACE_NO_PROTOCOL		0     
#define	ACE_PROT_BOOTP		1
#define	ACE_PROT_DHCP		2
#define	ACE_PROT_AUTOIP		3
#define	ACE_PROT_PING_ARP	4
#define	ACE_PROT_RARP		5
#define	ACE_PROT_STATIC		6
#define	ACE_PROT_CUSTOM		7



/**
 * Current ACE Configuration Version. 
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define ACE_CONFIG_VERSION      0

/**
 * Value to use for IP address fields when the IP address is not known.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define ACE_UNKNOWN_IP_ADDRESS  0

/**
 * Value for domain name if domain name is unknown.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define ACE_UNKNOWN_DOMAIN_NAME     ""


/**
 * Value to use for very large values.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define ACE_INFINITE            INT_MAX

/**
 * Value to use if we want DHCP to keep trying forever.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define ACE_DHCP_RETRY_FOREVER  -1

/**
 * Value to use for unknown DHCP lease start time.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 */   
#define ACE_DONT_KNOW_START_TIME    LONG_MAX




/**
 * Specifies how the DHCP client will start if a suggested IP address is defined.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param ACE_RESTART_DHCP_DISCOVER  Start DHCP client to allocate a network address,
 *                                   sending DHCPDISCOVER message 
 * @param ACE_RESTART_DHCP_REUSE     Not supported.
 */   
typedef enum 
{ 
	ACE_RESTART_DHCP_DISCOVER = 1, 
 	ACE_RESTART_DHCP_REUSE    = 2    

} configAceDhcpRestartType;

#define BP_AUTOIP_START_WITH_RANDOM_IP_ADDRESS  0

/**
 * Information specific to start AutoIp.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param isConfigValid         Set if this configuration record is valid
 * @param isEnabled             Set if this protocol is enabled on this interface
 * @param autoip_local_addr     IP address which AutoIP should initially use when trying
 *					            to configure an address. If 0, will use random number
 *						        to generate one. Must begin with 169.254.
 * @param startInfo				Startup parameters
 */   
typedef struct 
{
    BOOLEAN isConfigValid;          
    BOOLEAN isEnabled;              
	WORD32 autoip_local_addr;	    
						            
							        
    aceProtoStartInfo startInfo;    
} configAceAutoipInfo;

/**
 * Information specific to start RARP.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param isConfigValid         Set if this configuration record is valid
 * @param isEnabled             Set if this protocol is enabled on this interface
 * @param rarp_rexint		    Retransmit interval that RARP should use, default is 2 seconds
 * @param startInfo		        Startup parameters
 */   
typedef struct 
{
    BOOLEAN isConfigValid;          
    BOOLEAN isEnabled;              
	WORD8 rarp_rexint;			    
    aceProtoStartInfo startInfo;    
} configAceRarpInfo;


/**
 * Information specific to start DHCP client.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param isConfigValid         Set if this configuration record is valid
 * @param isEnabled             Set if this protocol is enabled on this interface
 * @param suggested_ip_address	Suggested IP address in network byte order
 * @param server_ip_address	    Server IP address for ACE_RESTART_DHCP_REUSE in network byte order
 * @param gateway		        Default gateway IP address in network byte order
 * @param suggested_lease_time	Seggested lease time in seconds
 * @param number_of_retries	    Number of retries, -1 = infinite
 * @param lease_start_time	    Time recorded when lease has started
 * @param dhcp_restart_type	    DHCP restart type
 * @param need_bcast_response	Set the BROADCAST flag in the DHCP message default is TRUE
 * @param do_init_delay			Enable initial random delay before sending DISCOVER message, 
 *                              default is TRUE.
 * @param arp_reply_timeout		ARP probe reply timeout, default is 15 seconds 
 * @param desired_params	    Requested option codes
 * @param num_desired_params	Number of requested option codes
 * @param startInfo		        Startup parameters
 */      
typedef struct 
{
    BOOLEAN isConfigValid;        
    BOOLEAN isEnabled;            
	WORD32	suggested_ip_address; 
	WORD32	server_ip_address;    
    WORD32  gateway;
	time_t  suggested_lease_time; 
	int		number_of_retries;    
    time_t  lease_start_time;     
	configAceDhcpRestartType dhcp_restart_type; 
    BOOLEAN need_bcast_response;
    BOOLEAN do_init_delay;
    time_t  arp_reply_timeout;
    WORD8	desired_params[CONFIG_ACE_MAX_DHCP_PARAMS]; 
	int		num_desired_params;                         
    aceProtoStartInfo startInfo;    
} configAceDhcpInfo;

/**
 * Information specific to start BOOTP client.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param isConfigValid         Set if this configuration record is valid
 * @param isEnabled             Set if this protocol is enabled on this interface
 * @param client_ip_address	    Client IP address, if alrready known, in network byte order
 * @param server_ip_address		Server IP address, if alrready known, in network byte order
 * @param number_of_retries		Number of retries, -1 = infinite
 * @param gateway		        Dfault gateway IP address in network byte order
 * @param bootfile_name		    Generic or fully qualified pathname of the boot image file 
 * @param server_host_name      A string containing the server name, if booting is to be 
 *                              restricted to a particular server
 * @param startInfo		        Startup parameters
 */   
typedef struct 
{
    BOOLEAN isConfigValid;         
    BOOLEAN isEnabled;             
	WORD32	client_ip_address;
	WORD32  server_ip_address;
	INT32	number_of_retries;
    WORD32  gateway;
	char    bootfile_name[CONFIG_MAX_BOOT_FILE_NAME + 1];
	char	server_host_name[CONFIG_MAX_SERVER_HOST_NAME + 1];
    aceProtoStartInfo startInfo;    
} configAceBootpInfo;

/**
 * Information specific to start static address assignment.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param isConfigValid         Set if this configuration record is valid
 * @param isEnabled             Set if this protocol is enabled on this interface
 * @param ip_address		    IP address in network byte order
 * @param subnet_mask			Subnet mask in network byte order
 * @param gateway		        Default gateway in network byte order
 * @param auto_assign		    TRUE - assign static IP address and ignore other protocols
 *				                FALSE - assign static IP address after other protocols failed
 * @param domain_name			Not supported
 * @param name_server_address	IP addresses of DNS servers
 * @param startInfo				Startup parameters
 */   
typedef struct 
{
    BOOLEAN isConfigValid;          
    BOOLEAN isEnabled;              
	WORD32	ip_address;     
	WORD32  subnet_mask;
	WORD32	gateway;       
	int     auto_assign;   
                           
    char    domain_name[ACE_MAX_DOMAIN_NAME];
    WORD32  name_server_address[ACE_MAX_DNS_SERVERS];
    aceProtoStartInfo startInfo;    
} configAceStaticInfo;


/**
 * Information specific to start Ping ARP.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param isConfigValid         Set if this configuration record is valid
 * @param isEnabled             Set if this protocol is enabled on this interface
 * @param startInfo		        Startup parameters
 */   
typedef struct 
{
    BOOLEAN isConfigValid;          
    BOOLEAN isEnabled;              
    aceProtoStartInfo startInfo;

} configAcePingArpInfo;

/**
 * ACE configuration record for an interface. An entry of protocols is not 
 * used if protocols[i].protocol == 0.
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param isConfigValid     Set if this configuration record is valid
 * @param isEnabled         Set if this interface is enabled
 * @param ifname		    Interface name, e.g., "eth0", "eth0:0", etc.
 * @param static_config		Static address assignment specific information		
 * @param dhcp_config		DHCP-specific information		
 * @param bootp_config		BOOTP-specific information
 * @param autoip_config		AutoIP-specific information			
 * @param rarp_config		RARP-specific information
 * @param ping_arp_config	Ping ARP-specific information
 */   
typedef struct 
{   
    BOOLEAN isConfigValid;          
    BOOLEAN isEnabled;              
	char					ifname[NETOS_MAX_IF_NAMELEN + 1]; 
    configAceStaticInfo		static_config;
	configAceDhcpInfo		dhcp_config;
	configAceBootpInfo		bootp_config;
	configAceAutoipInfo		autoip_config;
	configAceRarpInfo		rarp_config;   
    configAcePingArpInfo    ping_arp_config;
} aceConfigInterfaceInfo;

/**
 * ACE configuration record.  Version number will change if the definition of this structure 
 * (and any included structures) changes. 
 *
 * @external
 * @category ACE:ace_params
 * @since 6.0
 *
 * @param version				Version number for this record
 * @param ace_interface_info    One ACE configuration record for each interface up to the maximum
 */   
typedef struct 
{
    int  version;           
    aceConfigInterfaceInfo ace_interface_info[CONFIG_ACE_MAX_INTERFACES];
} aceConfigInfo;


BOOLEAN ace_start_static(char *ifname, void *handle, const void *proto_spec_info, size_t proto_spec_info_size);
BOOLEAN ace_stop_static(char *ifname);
BOOLEAN ace_get_static_addr_info(void *handle, const void  *event_info, size_t event_info_size, aceAddrInfo *addr_info);

BOOLEAN ace_start_dhcp(char *ifname,  void *handle, const void *proto_spec_info, size_t proto_spec_info_size);
BOOLEAN ace_stop_dhcp(char *ifname);
BOOLEAN ace_get_dhcp_addr_info(void *handle, const void  *event_info, size_t event_info_size, aceAddrInfo *addr_info);
void    ace_release_dhcp_addr(char *ifname);

BOOLEAN ace_start_autoip(char *ifname, void *handle, const void *proto_spec_info, size_t proto_spec_info_size);
BOOLEAN ace_stop_autoip(char *ifname);
BOOLEAN ace_get_autoip_addr_info(void *handle, const void  *event_info, size_t event_info_size, aceAddrInfo *addr_info);

BOOLEAN ace_start_rarp(char *ifname, void *handle, const void *proto_spec_info, size_t proto_spec_info_size);
BOOLEAN ace_stop_rarp(char *ifname);
BOOLEAN ace_get_rarp_addr_info(void *handle, const void  *event_info, size_t event_info_size, aceAddrInfo *addr_info);

BOOLEAN ace_start_ping_arp(char *ifname, void *handle, const void *proto_spec_info, size_t proto_spec_info_size);
BOOLEAN ace_stop_ping_arp(char *ifname);
BOOLEAN ace_get_ping_arp_addr_info(void *handle, const void  *event_info, size_t event_info_size, aceAddrInfo *addr_info);

BOOLEAN ace_start_bootp(char *ifname, void *handle, const void   *proto_spec_info, size_t proto_spec_info_size);
BOOLEAN ace_stop_bootp(char *ifname);
BOOLEAN ace_get_bootp_addr_info(void *handle, const void  *event_info, size_t event_info_size, aceAddrInfo *addr_info);


/* 
 * globalIpConfig is returned by ace_get_bootp_dhcp_ip_options
 * 
 * GBL_SET_... defines are ORed together and set in set_mask to show which 
 * fields of globalIpConfig are used.
 */

/**
 * These constants, when ORed with the set_mask field of the globalIpConfig structure,
 * define which IP paremeter must be configured.
 *
 * @external
 * @category ACE:ace_callbacks
 * @since 6.0
 * @name GlobalIpMasks "Global IP Parameters to Configure"
 *
 * @param GBL_SET_DEF_IP_TTL     Change default TTL value
 * @param GBL_SET_DEF_TCP_TTL    Change default TCP TTL value           
 * @param GBL_SET_KA_INTERVAL    Change keep alive interval     
 * @param GBL_SET_KA_GARBAGE     Change keep alive garbage type     
 * @param GBL_SET_IP_FORWARDING  Change IP forwarding  
 * @param GBL_IP_SET_ALL         Change all paremeters    
 *
 * @see @link globalIpConfig
 *
 */   
#define GBL_SET_DEF_IP_TTL      0x01
#define GBL_SET_DEF_TCP_TTL     0x02
#define GBL_SET_KA_INTERVAL     0x04
#define GBL_SET_KA_GARBAGE      0x08
#define GBL_SET_IP_FORWARDING   0x10
#define GBL_IP_SET_ALL          0xFF


/**
 * The structure of this type is used by customizeAceConfigureInterface function to 
 * change the global (per system) IP setting, defined as fields of this structure 
 *
 * @external
 * @category ACE:ace_callbacks
 * @since 6.0
 *
 * @param default_ttl       Default TTL              
 * @param default_tcp_ttl   Default TTL used in TCP sockets               
 * @param ka_interval       Keep alive interval              
 * @param ka_garbage        Keep alive garbage type           
 * @param ip_forwarding     Do IP forwarding                   
 * @param set_mask          Bit mask, identifying which IP parameter must be 
 *                          configured. 
 *
 * @see @link GlobalIpMasks
 * @see @link NaIpKaGarbageType
 * @see @link customizeAceConfigureInterface
 */
typedef struct
{
    WORD8               default_ttl;			
    WORD8               default_tcp_ttl;		
    WORD16              ka_interval;		    
    NaIpKaGarbageType   ka_garbage;			    
    BOOLEAN             ip_forwarding;			
    WORD32              set_mask;

} globalIpConfig;

/*
 * Get global IP configurations returned via DHCP or BOOTP options
 */
BOOLEAN ace_get_bootp_dhcp_ip_options(int protocol, const void *p_event_info, globalIpConfig *ip_config);

/*
 * The following structures are used to define protocol specific event information,
 * for Auto IP and RARP, when they return an IP address to the application. 
 */
typedef struct 
{
	WORD32 address;
	WORD32 mask;

} aceAutoIpEventInfo, aceRarpEventInfo;

/*
 * The following structures are used to define protocol specific event information,
 * for Ping ARP, when it returns an IP address to the application. 
 */
typedef struct 
{
	WORD32 address;
	WORD32 mask;
    WORD32 servaddr;

} acePingArpEventInfo;

extern size_t ace_dhcp_event_info_size;
extern size_t ace_bootp_event_info_size;

/* Retrieves the configuration for the IP address conflict detection for the network interface.*/
int customizeAceGetAddrConflictData(char const * ifname, NAAddrConflictConfigType * data);


#ifdef __cplusplus
}
#endif

#endif

