📄 ppp.c
字号:
/************************************************************************
*
* 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
*
* ppp.c 2.4
*
* COMPONENT
*
* The Point -to-Point Protocol. This is the main component of PPP.
*
* DESCRIPTION
*
* This file contains the main PPP services and controls negotiation
* of a PPP link with a peer.
*
* DATA STRUCTURES
*
*
*
* FUNCTIONS
*
* PPP_Initialize
* PPP_Lower_Layer_Up
* PPP_Set_Login
* PPP_Hangup
* PPP_Safe_To_Hangup
* PPP_Still_Connected
* PPP_Two_To_Power
* PPP_Output
* PPP_Input
* PPP_Dial
* PPP_Wait_For_Client
* PPP_Clean_Up_Link
* PPP_Event_Handler
* PPP_Obtain_Connection_Status
* PPP_Abort_Wait_For_Client
* PPP_Stop_All_Timers
* PPP_Last_Activity_Time
* PPP_Init_State
* PPP_Terminate_Link
*
* DEPENDENCIES
*
* nucleus.h
* externs.h
* tcp_errs.h
* target.h
* rtab.h
* rip2.h
* ppp.h
*
************************************************************************/
#include "plus/nucleus.h"
#include "net/target.h" /* Compiler typedefs for data type sizes */
#include "net/inc/externs.h"
#include "net/inc/tcp_errs.h"
#include "net/inc/rtab.h"
#include "net/inc/rip2.h"
#include "net/inc/netevent.h"
#include "net/inc/ncl.h"
#include "net/inc/tcp.h"
#include "net/inc/udp.h"
#include "ppp/inc/nu_ppp.h"
#include "net/inc/net_extr.h"
#if (INCLUDE_PPP_MIB == NU_TRUE)
#include SNMP_GLUE
#endif
extern VOID print(CHAR *s);
extern VOID light_open(VOID);
extern VOID light_close(VOID);
/************************************************************************
* FUNCTION
*
* PPP_Initialize
*
* DESCRIPTION
*
* This function initializes the LCP and NCP layers of the protocol stack.
* After exiting from this function PPP will be in a state to begin
* link negotiation.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* DV_DEVICE_ENTRY *dev_ptr Pointer to the device structure
* for this device.
*
* OUTPUTS
*
* STATUS Returns NU_SUCCESS if
* initialization is successful,
* else a value less than 0 is
* returned.
*
************************************************************************/
STATUS PPP_Initialize (DV_DEVICE_ENTRY *dev_ptr)
{
STATUS status;
PPP_LAYER *ppp_layer_ptr;
CHAR timer_name[9]; /* max length for a PLUS timer name is 8 */
CHAR temp[5]; /* temp string to store the com port */
ppp_layer_ptr = (PPP_LAYER*)(dev_ptr->dev_ppp_layer);
/* Set the MTU if it hasn't been set yet, or it is set to
a higher value. */
if (dev_ptr->dev_mtu == 0 || dev_ptr->dev_mtu > PPP_MTU)
dev_ptr->dev_mtu = PPP_MTU;
#if (INCLUDE_PPP_MIB == NU_TRUE)
/* let PPP mib know our capabilities */
ppp_set_init_value (dev_ptr->dev_mtu, PPP_FCS_SIZE_BYTE2, LCP_DEFAULT_AUTH_PROTOCOL);
#endif
dev_ptr->dev_event = PPP_Event_Handler;
dev_ptr->dev_type = DVT_PPP;
/* Each link protocol adds a header size to a total for Net to use. */
dev_ptr->dev_hdrlen += PPP_HEADER_SIZE;
/* Set the default timeout for link negotiation */
ppp_layer_ptr->negotiation_timeout = PPP_DEFAULT_NEG_TIMEOUT;
/* Initialize the LCP layer. */
if (LCP_Init (dev_ptr) != NU_SUCCESS)
return (NU_PPP_INIT_FAILURE);
/* Initialize the NCP layer. */
if (NCP_Init (dev_ptr) != NU_SUCCESS)
return (NU_PPP_INIT_FAILURE);
/* Zero out the name */
UTL_Zero (timer_name, 9);
/* Build the authentication restart timer name */
timer_name[0] = 'a';
timer_name[1] = 'u';
timer_name[2] = 't';
timer_name[3] = 'h';
strcat (timer_name, (CHAR *)NU_ITOA ((INT)dev_ptr->dev_index, temp, 10));
/* Create the restart timer, it will be used for authentication. */
status = NU_Create_Timer (&ppp_layer_ptr->authentication.authentication_timer,
timer_name, PAP_Timer_Expire, (UNSIGNED) dev_ptr,
LCP_TIMEOUT_VALUE, LCP_TIMEOUT_VALUE, NU_DISABLE_TIMER);
if (status != NU_SUCCESS)
{
NERRS_Log_Error (TCP_FATAL, __FILE__, __LINE__);
return(NU_PPP_INIT_FAILURE);
}
/* Zero out the name */
UTL_Zero (timer_name, 9);
/* Build the PPP negotiation event group timer name */
timer_name[0] = 'p';
timer_name[1] = 'p';
timer_name[2] = 'p';
strcat (timer_name, (CHAR *)NU_ITOA ((INT)dev_ptr->dev_index, temp, 10));
status = NU_Create_Event_Group (&ppp_layer_ptr->negotiation_progression,
timer_name);
if (status != NU_SUCCESS)
{
NERRS_Log_Error (TCP_FATAL, __FILE__, __LINE__);
return(NU_PPP_INIT_FAILURE);
}
return (NU_SUCCESS);
} /* end NU_Etopen routine */
/************************************************************************
* FUNCTION
*
* PPP_Lower_Layer_Up
*
* DESCRIPTION
*
* This function is responsible for controlling the movement of PPP
* through each phase of the link negotiation.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* UINT8 *ip_address Pointer to the IP address to be
* used during IPCP negotiation.
* This address will either be the
* address to assign to a calling
* client or will be the address
* to suggest to a PPP server
* depending on if the local side
* is functioning as a PPP server
* or a PPP client respectively.
* DV_DEVICE_ENTRY *dev_ptr Pointer to device structure.
*
* OUTPUTS
*
* STATUS How the link negotiation ended
*
************************************************************************/
STATUS PPP_Lower_Layer_Up(UINT8 *ip_address, DV_DEVICE_ENTRY *dev_ptr)
{
STATUS status;
UNSIGNED bufs_ava;
LCP_LAYER *lcp;
IPCP_LAYER *ipcp;
AUTHENTICATION_LAYER *auth;
LINK_LAYER *link;
#if (INCLUDE_PPP_MIB == NU_TRUE)
INT32 retcode;
#endif
/* Grab a pointer to the ppp link layer stucture. */
link = (LINK_LAYER *)dev_ptr->link_layer;
/* Grab a pointer to the LCP layer stucture. */
lcp = &((LINK_LAYER *)dev_ptr->link_layer)->lcp;
/* Grab a pointer to the IPCP layer stucture. */
ipcp = &((LINK_LAYER *)dev_ptr->link_layer)->ipcp;
/* Grab a pointer to the authentication layer stucture. */
auth = &((LINK_LAYER *)dev_ptr->link_layer)->authentication;
/* Eat any events that may be around from the last session. */
NU_Retrieve_Events(&link->negotiation_progression, (LCP_CONFIG_DONE |
NCP_CONFIG_DONE | AUTHENTICATION_DONE |
LCP_CONFIG_FAIL | PPP_NEG_TIMEOUT),
NU_OR_CONSUME, &bufs_ava, NU_NO_SUSPEND);
/* Reset the restart timer */
NU_Control_Timer (&lcp->restart_timer, NU_DISABLE_TIMER);
/* Set the status of the PPP connection attempt. */
((PPP_LAYER *)dev_ptr->link_layer)->connection_status = NU_PPP_LINK_NEGOTIATION;
/* Start the LCP state automaton. */
LCP_Send_Config_Req(dev_ptr);
/* Start the timer */
NU_Reset_Timer (&lcp->restart_timer, LCP_Timer_Expire,
LCP_TIMEOUT_VALUE, LCP_TIMEOUT_VALUE, NU_ENABLE_TIMER);
/* Set the negotiation timeout event. If this event goes off
before the link is up we will abort the attempt. */
UTL_Timerset (PPP_STOP_NEGOTIATION, (UNSIGNED)dev_ptr,
(link->negotiation_timeout * SCK_Ticks_Per_Second), NU_NULL);
/* We wait for the event to tell us that LCP is done. */
status = NU_Retrieve_Events(&link->negotiation_progression,
(LCP_CONFIG_DONE | PPP_NEG_TIMEOUT),
NU_OR_CONSUME, &bufs_ava, NU_SUSPEND);
/* update the PP MIB database */
#if (INCLUDE_PPP_MIB == NU_TRUE)
retcode = SNMP_SetpppLinkStatusValues(dev_ptr->dev_index,
lcp->local_options.max_rx_unit,
lcp->foreign_options.max_rx_unit,
lcp->local_options.accm,
lcp->foreign_options.accm,
lcp->local_options.protocol_field_compression,
lcp->foreign_options.protocol_field_compression,
lcp->local_options.address_field_compression,
lcp->foreign_options.address_field_compression,
lcp->local_options.fcs_size,
lcp->foreign_options.fcs_size);
if (retcode == -2)
{
NERRS_Log_Error (TCP_FATAL, __FILE__, __LINE__);
return(-1);
}
#endif
/* Reset the restart timer */
NU_Control_Timer (&lcp->restart_timer, NU_DISABLE_TIMER);
if (bufs_ava & PPP_NEG_TIMEOUT)
status = NU_NEGOTIATION_TIMEOUT;
/* Check to see if it completed succcessfully. */
else if (!(!(bufs_ava & LCP_CONFIG_SUCCESS) || (status != NU_SUCCESS)))
{
/* LCP is done so start authentication if it is used */
if (1)
(&((LINK_LAYER *)dev_ptr->link_layer)->lcp)->state = OPENED;//****************************************************************************************************************************************************************8
if (lcp->local_options.authentication_protocol)
{
#ifdef NU_DEBUG_PPP
_PRINT ("\ndone with LCP, starting authentication. \n");
#endif
/* Set the status of the PPP connection attempt. */
((PPP_LAYER *)dev_ptr->link_layer)->connection_status = NU_PPP_AUTHENTICATION;
/* If we are are using PAP then we must start the timer and
initiate the authentication */
if (lcp->local_options.authentication_protocol == PPP_PAP_PROTOCOL)
{
#ifdef NU_DEBUG_PPP
_PRINT ("using PAP ");
#endif
/* We will only send a PAP packet if we are a CLIENT */
if (ipcp->mode == NCP_CLIENT)
{
/* Send our ID and PW */
PAP_Send_Authentication(dev_ptr);
}
else
{
/* Don't need to do anything, the client will send
us an authentication pkt. */
}
/* Start the timer */
NU_Reset_Timer (&auth->authentication_timer, PAP_Timer_Expire,
LCP_TIMEOUT_VALUE, LCP_TIMEOUT_VALUE, NU_ENABLE_TIMER);
}
else
{
#ifdef NU_DEBUG_PPP
_PRINT ("using CHAP-MD5 ");
#endif
/* If we in SERVER mode then we need to challenge the
peer for a PW. */
if (ipcp->mode == NCP_SERVER)
{
/* Send a challenge pkt. */
CHAP_Send_Challenge(dev_ptr);
}
else
{
/* Don't need to do anything, the server will challenge
us. */
}
/* Start the timer */
NU_Reset_Timer (&auth->authentication_timer, CHAP_Timer_Expire,
LCP_TIMEOUT_VALUE, LCP_TIMEOUT_VALUE, NU_ENABLE_TIMER);
}
auth->num_timeouts = LCP_MAX_AUTHENTICATE;
/* We wait for the event to tell us that authentication is done. */
status = NU_Retrieve_Events(&link->negotiation_progression, AUTHENTICATION_DONE,
NU_OR_CONSUME, &bufs_ava, NU_SUSPEND);
/* Reset the restart timer */
NU_Control_Timer (&auth->authentication_timer, NU_DISABLE_TIMER);
/* See if we were successful at logging in */
if (!(!(bufs_ava & AUTHENTICATION_SUCCESS) || (status != NU_SUCCESS)))
status = PPP_SUCCESS;
else
status = NU_LOGIN_FAILED;
} /* if we are using authentication */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -