/************************************************************************
*
* Copyright (c) 1997-2001 by Accelerated Technology, Inc.
*
* PROPRIETARY RIGHTS of Accelerated Technology are involved in
* the subject matter of this material. All manufacturing,
* reproduction, use, and sales rights pertaining to this subject
* matter are governed by the license agreement. The recipient of
* this software implicitly accepts the terms of the license.
*
*
*************************************************************************
*************************************************************************
* FILE NAME VERSION
*
* ncp.c 2.4
*
* COMPONENT
*
* The Network Control Protocol for PPP. Specifically the
* Internet Protocol Control Protocol (IPCP).
*
* DESCRIPTION
*
* This file contains the network control protocols used by PPP to
* negotiate network settings to be used over the link. This
* implementation only contains the internet protocol control protocol
* (IPCP). No other network protocols are suppported.
*
* DATA STRUCTURES
*
* none
*
* FUNCTIONS
*
* NCP_Init
* PPP_NCP_IP_Interpret
* NCP_IP_Send_Config_Req
* NCP_IP_Req_Sent_State
* NCP_IP_Ack_Rcvd_State
* NCP_Timer_Expire
* NCP_SnmpTimer_Expire
* NCP_Change_IP_Mode
* NCP_Configure_Req_Check
* NCP_Configure_Nak_Check
* NCP_IP_Ack_Sent_State
* NCP_IP_Opened_State
* NCP_IP_Code_Reject_Check
* NCP_IP_Stopping_State
* NCP_Set_Client_IP_Address
*
* DEPENDENCIES
*
* nucleus.h
* externs.h
* tcp_errs.h
* netevent.h
* protocol.h
* target.h
* ppp.h
*
*
************************************************************************/
#include "plus/nucleus.h"
#include "net/inc/externs.h"
#include "net/inc/tcp_errs.h"
#include "net/inc/netevent.h"
#include "net/inc/ncl.h"
#include "net/target.h" /* Compiler typedefs for data type sizes */
#include "ppp/inc/nu_ppp.h"
#if (INCLUDE_PPP_MIB == NU_TRUE)
#include SNMP_GLUE
#endif
/************************************************************************
* FUNCTION
*
* NCP_Init
*
* DESCRIPTION
*
* This function initializes the NCP layer of PPP. It creates the needed
* timers and initializes the NCP structure for the passed in device.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* DV_DEVICE_ENTRY *dev_ptr Pointer to the device that this
* LCP layer belongs to.
*
* OUTPUTS
*
* STATUS NU_SUCCESS will be returned on if NCP is
* correctly initialized otherwise -1 will be
* returned or a Nucleus PLUS status will be
* returned.
*
************************************************************************/
STATUS NCP_Init (DV_DEVICE_ENTRY *dev_ptr)
{
STATUS ret_status;
IPCP_LAYER *ipcp;
CHAR timer_name[9]; /* max length for a PLUS timer name is 8 */
CHAR temp[5]; /* temp string to store the com port */
#if (INCLUDE_PPP_MIB == NU_TRUE)
INT32 retcode;
#endif
/* Get a pointer to the lcp stucture for this device. */
ipcp = &((LINK_LAYER *) dev_ptr->link_layer)->ipcp;
/* Zero out the name */
UTL_Zero (timer_name, 9);
/* Build the NCP IPCP restart timer name */
timer_name[0] = 'i';
timer_name[1] = 'p';
timer_name[2] = 'c';
timer_name[3] = 'p';
strcat (timer_name, (CHAR *)NU_ITOA ((INT)dev_ptr->dev_index, temp, 10));
/* Create the restart timer, it will be used for NCP. */
ret_status = NU_Create_Timer (&ipcp->restart_timer, timer_name,
NCP_Timer_Expire, (UNSIGNED) dev_ptr, LCP_TIMEOUT_VALUE,
LCP_TIMEOUT_VALUE, NU_DISABLE_TIMER);
if (ret_status != NU_SUCCESS)
{
NERRS_Log_Error (NERR_RECOVERABLE, __FILE__, __LINE__);
return(-1);
}
ipcp->network_options.use_primary_dns_server = NCP_DEFAULT_PRI_DNS;
ipcp->network_options.use_secondary_dns_server = NCP_DEFAULT_SEC_DNS;
ipcp->network_options.use_IpVanJacobsonCompression = NU_FALSE;
#if (INCLUDE_PPP_MIB == NU_TRUE) /* setup the values for this link from the PPP MIB */
/* Create the SNMP periodic timer to report IPCP state to SNMP */
ret_status = NU_Create_Timer (&ipcp->snmp_timer, "ipcpSNMP",
NCP_SnmpTimer_Expire, (UNSIGNED) dev_ptr,IPCP_SNMP_TIMEOUT_VALUE,
IPCP_SNMP_TIMEOUT_VALUE,NU_ENABLE_TIMER);
if (ret_status != NU_SUCCESS)
{
NERRS_Log_Error (NERR_RECOVERABLE, __FILE__, __LINE__);
return(-1);
}
/* create ppp status table entries first for PPP Mib */
retcode = pppIpEntry_Add_Table_Entry (dev_ptr->dev_index);
if (retcode == -2)
{
/* unable to create the table - no memory */
NERRS_Log_Error (TCP_FATAL, __FILE__, __LINE__);
return(-1);
}
SNMP_SetpppIpStatusValues(dev_ptr->dev_index,
PPP_IP_OPER_STATUS_DOWN, NU_FALSE, NU_FALSE,
NU_FALSE, NU_FALSE);
/* create ppp config table entries first for PPP Mib */
retcode = pppIpConfigEntry_Add_Table_Entry (dev_ptr->dev_index);
if (!retcode) /* entry was created, so initialize everything */
{
retcode = SNMP_SetpppIpConfigValues (dev_ptr->dev_index,
ipcp->network_options.use_IpVanJacobsonCompression);
if (retcode == -2)
{
NERRS_Log_Error (TCP_FATAL, __FILE__, __LINE__);
return(-1);
}
}
else if (retcode == -1)
{
/* entry found, so use values from MIB table for this link */
retcode = SNMP_GetpppIpConfigValues(dev_ptr->dev_index,
&ipcp->network_options.use_IpVanJacobsonCompression);
if (retcode == -2)
{
NERRS_Log_Error (TCP_FATAL, __FILE__, __LINE__);
return(-1);
}
}
else
{
/* unable to create the table - no memory */
NERRS_Log_Error (TCP_FATAL, __FILE__, __LINE__);
return(-1);
}
#endif
return (NU_SUCCESS);
} /* NCP_Init */
/************************************************************************
* FUNCTION
*
* NCP_Reset
*
* DESCRIPTION
*
* Resets the NCP DNS server addresses. This is done in preparation
* for a new PPP session.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* IPCP_LAYER *ipcp_ptr Pointer to the IPCP structure to
* be reset.
*
* OUTPUTS
*
* none
*
************************************************************************/
VOID NCP_Reset (IPCP_LAYER *ipcp_ptr)
{
/* Zero out the primary and secondary DNS servers. */
UTL_Zero (ipcp_ptr->primary_dns_server, IP_ADDRESS_LENGTH);
UTL_Zero (ipcp_ptr->secondary_dns_server, IP_ADDRESS_LENGTH);
}
/************************************************************************
* FUNCTION
*
* NCP_InjectSnmpEvent