📄 ppp.c
字号:
break;
case PPP_PAP_PROTOCOL :
PPP_PAP_Interpret (MEM_Buffer_List.head);
break;
case PPP_LINK_CONTROL_PROTOCOL :
PPP_LCP_Interpret (MEM_Buffer_List.head);
break;
default :
/* This packet is for a protocol
unknown to this implementation.
Reject the protocol and remove
the buffer from the buffer list. */
/* Restore the header. */
MEM_Buffer_List.head->data_ptr -= PPP_PROTOCOL_HEADER_2BYTES;
MEM_Buffer_List.head->data_len += PPP_PROTOCOL_HEADER_2BYTES;
MEM_Buffer_List.head->mem_total_data_len += PPP_PROTOCOL_HEADER_2BYTES;
LCP_Send_Protocol_Reject (MEM_Buffer_Dequeue (&MEM_Buffer_List));
/* Note: this buffer does not need to be deallocated
here. The function LCP_Send_Protocol_Reject reuses
this buffer, therefore it will be deallocated by
the transmit code. */
break;
} /* switch - no compresssion */
} /* switch - protocol compression */
return (NU_SUCCESS);
}
/************************************************************************
* FUNCTION
*
* PPP_Dial
*
* DESCRIPTION
*
* Dials a PPP server and attempts to establish a connection.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* CHAR *number Pointer to the number to dial.
* CHAR *link_name Pointer to the PPP link name.
* UINT8 *ip_addr Pointer to the IP address to
* suggest for use on this end
* of the PPP link.Normally this
* address is 0.0.0.0 which
* corresponds to a request of the
* PPP server to assign to the PPP
* client an IP address.
*
* OUTPUTS
*
* STATUS Was the connection made. If not
* which protocol failed.
*
************************************************************************/
STATUS PPP_Dial (CHAR *number, CHAR *link_name, UINT8 *ip_addr)
{
STATUS ret_status;
DV_DEVICE_ENTRY *dev_ptr;
CHAR subnet_mask [] = {(CHAR)255, (CHAR)255, (CHAR)255, (CHAR)255};
LINK_LAYER *link_layer;
/* Find the device for the link name. */
dev_ptr = DEV_Get_Dev_By_Name (link_name);
/* Make sure the device was found and that it is a PPP device. */
if ((dev_ptr) && (dev_ptr->dev_type == DVT_PPP))
{
/* Get pointers to the lower layers */
link_layer = (LINK_LAYER*)dev_ptr->dev_ppp_layer;
/* Make sure all PPP related timers are disabled */
PPP_Stop_All_Timers(dev_ptr);
/* Clear out any messages left in the transmit queue before dialing. */
MEM_Buffer_Cleanup(&dev_ptr->dev_transq);
dev_ptr->dev_transq_length = 0;
/* Set the status of the PPP connection attempt. */
link_layer->connection_status = NU_PPP_DIALING;
/* Initialize the state of the LCP and NCP structures. */
PPP_Init_State(dev_ptr);
/* Dial the number. */
ret_status = link_layer->connect(number, dev_ptr);
/* Check to see if we connected. */
if (ret_status == NU_SUCCESS)
{
/* Change to CLIENT mode, we must be a client if we are dialing. */
NCP_Change_IP_Mode (NCP_CLIENT, dev_ptr);
/* Start the PPP negotiation */
ret_status = PPP_Lower_Layer_Up(ip_addr, dev_ptr);
/* If we failed to connect correctly then we need to hangup */
if (ret_status != NU_SUCCESS)
/* Hangup the modem */
//link_layer->disconnect(link_layer, NU_TRUE);//*******************************************************************************************************************************************************
;
else
{
//*****************************************************************************************************************************************************************************************************
print("PPP success \r\n\r\n ");
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
light_open();
NU_Sleep(150);
light_close();
NU_Sleep(150);
//******************************************************************************************************************************************************************************************************
/* Initialize the last activity time to the current system clock
* when the link is established.
*/
link_layer->last_activity_time = NU_Retrieve_Clock();
/* Grab the stack semaphore before playing with stack
globals. */
NU_Obtain_Semaphore (&TCP_Resource, NU_SUSPEND);
/* Attach the IP address to this device. */
DEV_Attach_IP_To_Device (dev_ptr->dev_net_if_name,
link_layer->ipcp.local_ip_address,
(UINT8 *)subnet_mask);
/* Add a route to the server. The server will play the role
of a gateway. */
//********************************************************************************************************************************************************************************
RTAB_Add_Route (dev_ptr,
0x0A0000ACUL,
IP_ADDR ((unsigned char *)subnet_mask),
dev_ptr->dev_addr.dev_ip_addr,
(RT_UP | RT_STATIC | RT_GATEWAY | RT_HOST));
//********************************************************************************************************************************************************************************
RTAB_Add_Route (dev_ptr,
dev_ptr->dev_addr.dev_dst_ip_addr,
IP_ADDR ((unsigned char *)subnet_mask),
dev_ptr->dev_addr.dev_ip_addr,
(RT_UP | RT_GATEWAY | RT_HOST));
NU_Release_Semaphore(&TCP_Resource);
/* If we have been assigned DNS servers add
routes to them also. */
/* Did we get a primary DNS server? */
if (IP_ADDR (link_layer->ipcp.primary_dns_server) != NU_NULL)
{
NU_Obtain_Semaphore (&TCP_Resource, NU_SUSPEND);
/* Add route to DNS server. */
RTAB_Add_Route (dev_ptr,
IP_ADDR (link_layer->ipcp.primary_dns_server),
IP_ADDR ((unsigned char *)subnet_mask),
dev_ptr->dev_addr.dev_dst_ip_addr,
(RT_UP | RT_HOST));
NU_Release_Semaphore(&TCP_Resource);
/* Avoid multiple entries of the same DNS server. */
NU_Delete_DNS_Server (link_layer->ipcp.primary_dns_server);
/* Now add the DNS server to our DNS server
search list. */
NU_Add_DNS_Server (link_layer->ipcp.primary_dns_server,
DNS_ADD_TO_END);
}
/* Did we get a secondary DNS server. */
if (IP_ADDR (link_layer->ipcp.secondary_dns_server) != NU_NULL)
{
NU_Obtain_Semaphore (&TCP_Resource, NU_SUSPEND);
/* Add route to DNS server. */
RTAB_Add_Route (dev_ptr,
IP_ADDR (link_layer->ipcp.secondary_dns_server),
IP_ADDR ((unsigned char *)subnet_mask),
dev_ptr->dev_addr.dev_dst_ip_addr,
(RT_UP | RT_HOST));
NU_Release_Semaphore(&TCP_Resource);
/* Avoid multiple entries of the same DNS server. */
NU_Delete_DNS_Server (link_layer->ipcp.secondary_dns_server);
/* Now add the DNS server to our DNS server
search list. */
NU_Add_DNS_Server (link_layer->ipcp.secondary_dns_server,
DNS_ADD_TO_END);
}
}
}
else
{
/* If we failed to connect correctly then we need to hangup,
but do not try to hangup if the modem was not found. */
if (ret_status != NU_NO_MODEM)
/* Hangup the modem */
//link_layer->disconnect(ppp_layer, NU_TRUE);//*******************************************************************************************************************************************
;
}
} /* end the device was found and is PPP */
else
ret_status = NU_INVALID_LINK;
return (ret_status);
}
/************************************************************************
* FUNCTION
*
* PPP_Wait_For_Client
*
* DESCRIPTION
*
* Puts the modem in answer mode and waits for a caller. When the
* modem has connected with another modem a PPP session is attempted
* to be established.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* UINT8 *server_ip_address IP Address to assume when acting
* as a server for the incoming
* caller.
* CHAR *link_name Pointer to the PPP link name.
*
* OUTPUTS
*
* STATUS NU_SUCCESS
*
************************************************************************/
STATUS PPP_Wait_For_Client (UINT8 *server_ip_addr, CHAR *link_name)
{
STATUS ret_status;
CHAR subnet_mask [] = {(CHAR)255, (CHAR)255, (CHAR)255, (CHAR)255};
DV_DEVICE_ENTRY *dev_ptr;
LINK_LAYER *link_layer;
/* Assume that there is not a client connected. */
ret_status = ~NU_SUCCESS;
/* Get the device for the link name. */
dev_ptr = DEV_Get_Dev_By_Name(link_name);
/* Make sure we got a device and that it is a PPP device. */
if ((dev_ptr) && (dev_ptr->dev_type == DVT_PPP))
{
/* Get a pointer to the PPP structure. */
link_layer = (LINK_LAYER*)dev_ptr->dev_ppp_layer;
while ((ret_status != NU_SUCCESS) &&
(ret_status != NU_PPP_ATTEMPT_ABORTED))
{
/* Set the status of the PPP connection attempt. */
link_layer->connection_status = NU_PPP_WAITING;
/* Initialize the state of the LCP and NCP structures. */
PPP_Init_State(dev_ptr);
/* Clear out any messages left in the transmit queue. */
MEM_Buffer_Cleanup(&dev_ptr->dev_transq);
dev_ptr->dev_transq_length = 0;
/* Start waiting for a client to call. */
ret_status = link_layer->passive(dev_ptr);
if (ret_status == NU_SUCCESS)
{
/* Change to SERVER mode */
NCP_Change_IP_Mode (NCP_SERVER, dev_ptr);
#ifdef NU_DEBUG_PPP
_PRINT ("starting PPP negotiation\n");
#endif
/* Start the PPP negotiation */
ret_status = PPP_Lower_Layer_Up(server_ip_addr, dev_ptr);
/* If we connected then attach the server's IP address
to this device. */
if (ret_status == NU_SUCCESS)
{
/* Initialize the last activity time to the current system clock
* when the link is established.
*/
link_layer->last_activity_time = NU_Retrieve_Clock();
/* Grab the stack semaphore before playing with stack
globals. */
NU_Obtain_Semaphore (&TCP_Resource, NU_SUSPEND);
/* Set our new address */
DEV_Attach_IP_To_Device (dev_ptr->dev_net_if_name,
server_ip_addr, (UINT8 *) subnet_mask);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -