2015-03-11 15:33:57 +01:00
|
|
|
/****************************************************************************
|
2021-06-16 10:26:22 +02:00
|
|
|
* apps/netutils/pppd/ipcp.c
|
2015-03-11 15:33:57 +01:00
|
|
|
* PPP IPCP (intrnet protocol) Processor/Handler
|
2015-03-11 14:53:04 +01:00
|
|
|
*
|
2015-03-11 15:33:57 +01:00
|
|
|
* Version: 0.1 Original Version Jun 3, 2000
|
|
|
|
* Copyright (C) 2000, Mycal Labs www.mycal.com
|
|
|
|
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
|
|
|
* All rights reserved.
|
2015-03-11 14:53:04 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2015-03-11 15:33:57 +01:00
|
|
|
*
|
2015-03-11 14:53:04 +01:00
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Mike Johnson/Mycal Labs
|
|
|
|
* www.mycal.net.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2015-03-11 15:33:57 +01:00
|
|
|
****************************************************************************/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-11 15:33:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
|
|
|
#include "ppp_conf.h"
|
|
|
|
#include "ppp_arch.h"
|
|
|
|
#include "ipcp.h"
|
|
|
|
#include "ppp.h"
|
|
|
|
#include "ahdlc.h"
|
|
|
|
|
2015-03-11 15:33:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-11 14:53:04 +01:00
|
|
|
#if PPP_DEBUG
|
|
|
|
# define DEBUG1(x) debug_printf x
|
|
|
|
#else
|
|
|
|
# define DEBUG1(x)
|
|
|
|
#endif
|
|
|
|
|
2015-03-11 15:33:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-10-03 19:48:15 +02:00
|
|
|
/* In the future add compression protocol and name servers (possibly for
|
|
|
|
* servers only)
|
2015-03-11 14:53:04 +01:00
|
|
|
*/
|
|
|
|
|
2018-11-07 20:37:37 +01:00
|
|
|
static const uint8_t g_ipcplist[] =
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
2018-11-07 19:43:42 +01:00
|
|
|
IPCP_IPADDRESS,
|
2015-03-11 14:53:04 +01:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2015-03-11 15:33:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: printip
|
|
|
|
****************************************************************************/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
#if PPP_DEBUG
|
|
|
|
void printip(struct in_addr ip2)
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
FAR unt8_t *ip = (FAR uint8_t *)&ip2.s_addr;
|
2018-11-07 19:43:42 +01:00
|
|
|
DEBUG1((" %d.%d.%d.%d ", ip[0], ip[1], ip[2], ip[3]));
|
2015-03-11 14:53:04 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define printip(x)
|
|
|
|
#endif
|
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: ipcp_init
|
|
|
|
****************************************************************************/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
void ipcp_init(FAR struct ppp_context_s *ctx)
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
|
|
|
DEBUG1(("ipcp init\n"));
|
|
|
|
|
|
|
|
ctx->ipcp_state = 0;
|
|
|
|
ctx->ipcp_retry = 0;
|
|
|
|
ctx->ipcp_prev_seconds = 0;
|
|
|
|
|
|
|
|
memset(&ctx->local_ip, 0, sizeof(struct in_addr));
|
|
|
|
#ifdef IPCP_GET_PEER_IP
|
|
|
|
memset(&ctx->peer_ip, 0, sizeof(struct in_addr));
|
|
|
|
#endif
|
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
|
|
|
memset(&ctx->pri_dns_addr, 0, sizeof(struct in_addr));
|
|
|
|
#endif
|
|
|
|
#ifdef IPCP_GET_SEC_DNS
|
|
|
|
memset(&ctx->sec_dns_addr, 0, sizeof(struct in_addr));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: ipcp_rx
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* IPCP RX protocol Handler
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
void ipcp_rx(FAR struct ppp_context_s *ctx, FAR uint8_t * buffer,
|
|
|
|
uint16_t count)
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
2018-11-07 19:43:42 +01:00
|
|
|
FAR uint8_t *bptr = buffer;
|
|
|
|
uint16_t len;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
DEBUG1(("IPCP len %d\n", count));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
|
|
|
switch (*bptr++)
|
2018-11-07 19:43:42 +01:00
|
|
|
{
|
|
|
|
case CONF_REQ:
|
2022-10-03 19:48:15 +02:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Parse request and see if we can ACK it */
|
|
|
|
|
|
|
|
++bptr;
|
|
|
|
len = (*bptr++ << 8);
|
|
|
|
len |= *bptr++;
|
|
|
|
|
|
|
|
/* len-=2; */
|
|
|
|
|
|
|
|
DEBUG1(("check lcplist\n"));
|
2022-10-03 19:48:15 +02:00
|
|
|
if (scan_packet(ctx, IPCP, g_ipcplist, buffer, bptr, len - 4))
|
2018-11-07 19:43:42 +01:00
|
|
|
{
|
|
|
|
DEBUG1(("option was bad\n"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG1(("IPCP options are good\n"));
|
|
|
|
|
|
|
|
/* Parse out the results */
|
|
|
|
|
|
|
|
/* lets try to implement what peer wants */
|
|
|
|
|
|
|
|
/* Reject any protocol not */
|
|
|
|
|
2022-10-03 19:48:15 +02:00
|
|
|
/* Error? if we we need to send a config Reject ++++ this is good
|
|
|
|
* for a subroutine.
|
2018-11-07 19:43:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* All we should get is the peer IP address */
|
|
|
|
|
|
|
|
if (IPCP_IPADDRESS == *bptr++)
|
|
|
|
{
|
|
|
|
/* Dump length */
|
|
|
|
|
|
|
|
++bptr;
|
2015-03-11 14:53:04 +01:00
|
|
|
#ifdef IPCP_GET_PEER_IP
|
2022-10-08 10:31:21 +02:00
|
|
|
((FAR uint8_t *)&ctx->peer_ip)[0] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->peer_ip)[1] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->peer_ip)[2] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->peer_ip)[3] = *bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
DEBUG1(("Peer IP "));
|
|
|
|
printip(ctx->peer_ip);
|
|
|
|
DEBUG1(("\n"));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
netlib_set_dripv4addr((char *)ctx->ifname, &ctx->peer_ip);
|
2015-03-11 14:53:04 +01:00
|
|
|
#else
|
2018-11-07 19:43:42 +01:00
|
|
|
bptr += 4;
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
2018-11-07 19:43:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG1(("HMMMM this shouldn't happen IPCP1\n"));
|
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
|
|
|
|
#if 0
|
2018-11-07 19:43:42 +01:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
/* Write the config NAK packet we've built above, take on the
|
|
|
|
* header
|
|
|
|
*/
|
|
|
|
|
|
|
|
bptr = buffer;
|
|
|
|
*bptr++ = CONF_NAK; /* Write Conf_rej */
|
|
|
|
*bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2022-10-03 19:48:15 +02:00
|
|
|
/* tptr++; */ /* skip over ID */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Write new length */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
*bptr++ = 0;
|
|
|
|
*bptr = tptr - buffer;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Write the reject frame */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2021-12-26 23:10:48 +01:00
|
|
|
DEBUG1(("Writing NAK frame\n"));
|
2018-11-07 20:43:51 +01:00
|
|
|
ahdlc_tx(IPCP, buffer, (uint16_t)(tptr - buffer));
|
2018-11-07 19:43:42 +01:00
|
|
|
DEBUG1(("- End NAK Write frame\n"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
2022-10-03 19:48:15 +02:00
|
|
|
|
|
|
|
/* If we get here then we are OK, lets send an ACK and tell the
|
|
|
|
* rest of our modules our negotiated config.
|
2018-11-07 19:43:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
ctx->ipcp_state |= IPCP_RX_UP;
|
|
|
|
DEBUG1(("Send IPCP ACK!\n"));
|
|
|
|
bptr = buffer;
|
|
|
|
*bptr++ = CONF_ACK; /* Write Conf_ACK */
|
|
|
|
bptr++; /* Skip ID (send same one) */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Set stuff */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* ppp_flags |= tflag; */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2021-12-26 23:10:48 +01:00
|
|
|
DEBUG1(("SET- stuff -- are we up? c=%d dif=%d\n",
|
2018-11-07 20:43:51 +01:00
|
|
|
count, (uint16_t)(bptr - buffer)));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Write the ACK frame */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2021-12-26 23:10:48 +01:00
|
|
|
DEBUG1(("Writing ACK frame\n"));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */
|
|
|
|
|
|
|
|
ahdlc_tx(ctx, IPCP, 0, buffer, 0, count /* bptr-buffer */);
|
|
|
|
DEBUG1(("- End ACK Write frame\n"));
|
|
|
|
}
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
case CONF_ACK: /* config Ack */
|
|
|
|
DEBUG1(("CONF ACK\n"));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Parse out the results Dump the ID and get the length. */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Dump the ID */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Get the length */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
len = (*bptr++ << 8);
|
|
|
|
len |= *bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
|
|
|
#if 0
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Parse ACK and set data */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
while (bptr < buffer + len)
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
2018-11-07 19:43:42 +01:00
|
|
|
switch (*bptr++)
|
|
|
|
{
|
|
|
|
case IPCP_IPADDRESS:
|
2022-10-03 19:48:15 +02:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Dump length */
|
|
|
|
|
|
|
|
bptr++;
|
2022-10-08 10:31:21 +02:00
|
|
|
((FAR uint8_t *)&ctx->local_ip)[0] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->local_ip)[1] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->local_ip)[2] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->local_ip)[3] = *bptr++;
|
2018-11-07 19:43:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
# ifdef IPCP_GET_PRI_DNS
|
|
|
|
case IPCP_PRIMARY_DNS:
|
|
|
|
bptr++;
|
2022-10-08 10:31:21 +02:00
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[0] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[1] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[2] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[3] = *bptr++;
|
2018-11-07 19:43:42 +01:00
|
|
|
break;
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifdef IPCP_GET_SEC_DNS
|
|
|
|
case IPCP_SECONDARY_DNS:
|
|
|
|
bptr++;
|
2022-10-08 10:31:21 +02:00
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[0] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[1] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[2] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[3] = *bptr++;
|
2018-11-07 19:43:42 +01:00
|
|
|
break;
|
|
|
|
# endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG1(("IPCP CONFIG_ACK problem1\n"));
|
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
ctx->ipcp_state |= IPCP_TX_UP;
|
|
|
|
|
|
|
|
/* ppp_ipcp_state &= ~IPCP_RX_UP; */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2021-12-26 23:10:48 +01:00
|
|
|
DEBUG1(("were up!\n"));
|
2018-11-07 19:43:42 +01:00
|
|
|
printip(ctx->local_ip);
|
2015-03-11 14:53:04 +01:00
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
printip(ctx->pri_dns_addr);
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
#ifdef IPCP_GET_SEC_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
printip(ctx->sec_dns_addr);
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
2018-11-07 19:43:42 +01:00
|
|
|
DEBUG1(("\n"));
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
case CONF_NAK: /* Config Nack */
|
|
|
|
DEBUG1(("CONF NAK\n"));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Dump the ID */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Get the length */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
len = (*bptr++ << 8);
|
|
|
|
len |= *bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Parse ACK and set data */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
while (bptr < buffer + len)
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
2018-11-07 19:43:42 +01:00
|
|
|
switch (*bptr++)
|
|
|
|
{
|
|
|
|
case IPCP_IPADDRESS:
|
2022-10-03 19:48:15 +02:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Dump length */
|
|
|
|
|
|
|
|
bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2022-10-08 10:31:21 +02:00
|
|
|
((FAR uint8_t *)&ctx->local_ip)[0] = (char)*bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->local_ip)[1] = (char)*bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->local_ip)[2] = (char)*bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->local_ip)[3] = (char)*bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2022-10-08 10:31:21 +02:00
|
|
|
netlib_ifup((FAR char *)ctx->ifname);
|
|
|
|
netlib_set_ipv4addr((FAR char *)ctx->ifname, &ctx->local_ip);
|
2018-11-07 19:43:42 +01:00
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
case IPCP_PRIMARY_DNS:
|
|
|
|
bptr++;
|
2022-10-08 10:31:21 +02:00
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[0] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[1] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[2] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->pri_dns_addr)[3] = *bptr++;
|
2018-11-07 19:43:42 +01:00
|
|
|
netlib_set_ipv4dnsaddr(&ctx->pri_dns_addr);
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPCP_GET_SEC_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
case IPCP_SECONDARY_DNS:
|
|
|
|
bptr++;
|
2022-10-08 10:31:21 +02:00
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[0] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[1] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[2] = *bptr++;
|
|
|
|
((FAR uint8_t *)&ctx->sec_dns_addr)[3] = *bptr++;
|
2018-11-07 19:43:42 +01:00
|
|
|
netlib_set_ipv4dnsaddr(&ctx->sec_dns_addr);
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
default:
|
|
|
|
DEBUG1(("IPCP CONFIG_ACK problem 2\n"));
|
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
ctx->ppp_id++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
printip(ctx->local_ip);
|
2015-03-11 14:53:04 +01:00
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
printip(ctx->pri_dns_addr);
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
printip(ctx->sec_dns_addr);
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
2018-11-07 19:43:42 +01:00
|
|
|
DEBUG1(("\n"));
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
case CONF_REJ: /* Config Reject */
|
|
|
|
DEBUG1(("CONF REJ\n"));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Remove the offending options */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
ctx->ppp_id++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Dump the ID */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Get the length */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
len = (*bptr++ << 8);
|
|
|
|
len |= *bptr++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Parse ACK and set data */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
while (bptr < buffer + len)
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
2018-11-07 19:43:42 +01:00
|
|
|
switch (*bptr++)
|
|
|
|
{
|
|
|
|
case IPCP_IPADDRESS:
|
|
|
|
ctx->ipcp_state |= IPCP_IP_BIT;
|
|
|
|
bptr += 5;
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
case IPCP_PRIMARY_DNS:
|
|
|
|
ctx->ipcp_state |= IPCP_PRI_DNS_BIT;
|
|
|
|
bptr += 5;
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
case IPCP_SECONDARY_DNS:
|
|
|
|
ctx->ipcp_state |= IPCP_SEC_DNS_BIT;
|
|
|
|
bptr += 5;
|
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
default:
|
2020-02-23 05:51:44 +01:00
|
|
|
DEBUG1(("IPCP this shouldn't happen 3\n"));
|
2018-11-07 19:43:42 +01:00
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
}
|
2018-11-07 19:43:42 +01:00
|
|
|
break;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
default:
|
|
|
|
DEBUG1(("-Unknown 4\n"));
|
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
}
|
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: ipcp_task
|
|
|
|
****************************************************************************/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
void ipcp_task(FAR struct ppp_context_s *ctx, FAR uint8_t * buffer)
|
2015-03-11 14:53:04 +01:00
|
|
|
{
|
2018-11-07 19:43:42 +01:00
|
|
|
FAR uint8_t *bptr;
|
|
|
|
uint16_t t;
|
2015-03-11 14:53:04 +01:00
|
|
|
IPCPPKT *pkt;
|
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* IPCP tx not up and hasn't timed out then lets see if we need to send a
|
|
|
|
* request
|
|
|
|
*/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2022-10-03 19:48:15 +02:00
|
|
|
if (!(ctx->ipcp_state & IPCP_TX_UP) &&
|
|
|
|
!(ctx->ipcp_state & IPCP_TX_TIMEOUT))
|
2015-03-12 01:47:04 +01:00
|
|
|
{
|
|
|
|
/* Check if we have a request pending */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
if ((ppp_arch_clock_seconds() - ctx->ipcp_prev_seconds) > IPCP_TIMEOUT)
|
|
|
|
{
|
|
|
|
ctx->ipcp_prev_seconds = ppp_arch_clock_seconds();
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/* No pending request, lets build one */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2022-10-03 19:48:15 +02:00
|
|
|
pkt = (IPCPPKT *)buffer;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/* Configure-Request only here, write id */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
pkt->code = CONF_REQ;
|
|
|
|
pkt->id = ctx->ppp_id;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
bptr = pkt->data;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* Write options, we want IP address, and DNS addresses if set.
|
|
|
|
* Write zeros for IP address the first time
|
|
|
|
*/
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
*bptr++ = IPCP_IPADDRESS;
|
|
|
|
*bptr++ = 0x6;
|
2022-10-08 10:31:21 +02:00
|
|
|
*bptr++ = (uint8_t)((FAR uint8_t *)&ctx->local_ip)[0];
|
|
|
|
*bptr++ = (uint8_t)((FAR uint8_t *)&ctx->local_ip)[1];
|
|
|
|
*bptr++ = (uint8_t)((FAR uint8_t *)&ctx->local_ip)[2];
|
|
|
|
*bptr++ = (uint8_t)((FAR uint8_t *)&ctx->local_ip)[3];
|
2015-03-11 14:53:04 +01:00
|
|
|
|
|
|
|
#ifdef IPCP_GET_PRI_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
if ((ctx->ipcp_state & IPCP_PRI_DNS_BIT) == 0)
|
2015-03-12 01:47:04 +01:00
|
|
|
{
|
|
|
|
/* Write zeros for IP address the first time */
|
|
|
|
|
|
|
|
*bptr++ = IPCP_PRIMARY_DNS;
|
|
|
|
*bptr++ = 0x6;
|
2022-10-08 10:31:21 +02:00
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->pri_dns_addr)[0];
|
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->pri_dns_addr)[1];
|
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->pri_dns_addr)[2];
|
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->pri_dns_addr)[3];
|
2015-03-12 01:47:04 +01:00
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPCP_GET_SEC_DNS
|
2018-11-07 19:43:42 +01:00
|
|
|
if ((ctx->ipcp_state & IPCP_SEC_DNS_BIT) == 0)
|
2015-03-12 01:47:04 +01:00
|
|
|
{
|
|
|
|
/* Write zeros for IP address the first time */
|
|
|
|
|
|
|
|
*bptr++ = IPCP_SECONDARY_DNS;
|
|
|
|
*bptr++ = 0x6;
|
2022-10-08 10:31:21 +02:00
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->sec_dns_addr)[0];
|
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->sec_dns_addr)[1];
|
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->sec_dns_addr)[2];
|
|
|
|
*bptr++ = ((FAR uint8_t *)&ctx->sec_dns_addr)[3];
|
2015-03-12 01:47:04 +01:00
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
#endif
|
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/* Write length */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
t = bptr - buffer;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2018-11-07 19:43:42 +01:00
|
|
|
/* length here - code and ID + */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
pkt->len = htons(t);
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
DEBUG1(("\n**Sending IPCP Request packet\n"));
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
ahdlc_tx(ctx, IPCP, 0, buffer, 0, t);
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/* Inc retry */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
ctx->ipcp_retry++;
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
/* Have we timed out? (combine the timers?) */
|
2015-03-11 14:53:04 +01:00
|
|
|
|
2015-03-12 01:47:04 +01:00
|
|
|
if (ctx->ipcp_retry > IPCP_RETRY_COUNT)
|
|
|
|
{
|
2018-11-07 19:43:42 +01:00
|
|
|
ctx->ipcp_state |= IPCP_TX_TIMEOUT;
|
2015-03-12 01:47:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-11 14:53:04 +01:00
|
|
|
}
|