diff --git a/examples/pppd/Kconfig b/examples/pppd/Kconfig index a41625877..bceb7e8bf 100644 --- a/examples/pppd/Kconfig +++ b/examples/pppd/Kconfig @@ -5,10 +5,15 @@ config EXAMPLES_PPPD tristate "pppd client example" + select NETUTILS_PPPD default n ---help--- Enable the pppd client example if EXAMPLES_PPPD +config EXAMPLES_PPPD_STACKSIZE + int "pppd example stack stack size" + default 2048 + endif diff --git a/examples/pppd/Makefile b/examples/pppd/Makefile index 96990751d..b9101d252 100644 --- a/examples/pppd/Makefile +++ b/examples/pppd/Makefile @@ -48,7 +48,7 @@ PROGNAME = $(CONFIG_EXAMPLES_PPPD_PROGNAME) APPNAME = pppd PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 +STACKSIZE = CONFIG_EXAMPLES_PPPD_STACKSIZE MODULE = CONFIG_EXAMPLES_PPPD diff --git a/examples/pppd/pppd_main.c b/examples/pppd/pppd_main.c index e348fca9b..ac081e00d 100644 --- a/examples/pppd/pppd_main.c +++ b/examples/pppd/pppd_main.c @@ -50,7 +50,7 @@ * Private Data ****************************************************************************/ -static FAR char connect_script[] = +static FAR const char connect_script[] = "ECHO ON " "TIMEOUT 30 " "\"\" ATE1 " @@ -58,7 +58,7 @@ static FAR char connect_script[] = "OK ATD*99***1# " "CONNECT \\c"; -static FAR char disconnect_script[] = +static FAR const char disconnect_script[] = "\"\" ATZ " "OK \\c"; @@ -72,7 +72,7 @@ static FAR char disconnect_script[] = int pppd_main(int argc, char *argv[]) { - struct pppd_settings_s pppd_settings = + const struct pppd_settings_s pppd_settings = { .disconnect_script = disconnect_script, .connect_script = connect_script, diff --git a/include/netutils/pppd.h b/include/netutils/pppd.h index 56ae7cb83..0e894ca55 100644 --- a/include/netutils/pppd.h +++ b/include/netutils/pppd.h @@ -76,8 +76,8 @@ struct pppd_settings_s /* Chat Scripts */ - FAR char* connect_script; - FAR char* disconnect_script; + FAR const char* connect_script; + FAR const char* disconnect_script; }; /**************************************************************************** @@ -110,7 +110,7 @@ extern "C" * ****************************************************************************/ -int pppd(struct pppd_settings_s *ppp_settings); +int pppd(const struct pppd_settings_s *ppp_settings); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/pppd/Kconfig b/netutils/pppd/Kconfig index 8533ae304..ac204ed0d 100755 --- a/netutils/pppd/Kconfig +++ b/netutils/pppd/Kconfig @@ -4,7 +4,7 @@ # config NETUTILS_PPPD - bool "PPP daemon" + bool "PPP server" default n select NETUTILS_CHAT select NET_TUN @@ -14,10 +14,6 @@ config NETUTILS_PPPD if NETUTILS_PPPD -config NETUTILS_PPPD_STACKSIZE - int "PPP daemon stack stack size" - default 2048 - config NETUTILS_PPPD_PAP bool "PPP PAP Authentication Support" default n diff --git a/netutils/pppd/ahdlc.c b/netutils/pppd/ahdlc.c index 06cdb814c..c4cbf981a 100644 --- a/netutils/pppd/ahdlc.c +++ b/netutils/pppd/ahdlc.c @@ -54,23 +54,9 @@ # define PACKET_TX_DEBUG 1 #else # define DEBUG1(x) -# undef PACKET_TX_DEBUG +# define PACKET_TX_DEBUG 0 #endif -/* ahdlc flags bit defins, for ahdlc_flags variable */ - -/* Escaped mode bit */ - -#define AHDLC_ESCAPED 0x1 - -/* Frame is ready bit */ - -#define AHDLC_RX_READY 0x2 -#define AHDLC_RX_ASYNC_MAP 0x4 -#define AHDLC_TX_ASYNC_MAP 0x8 -#define AHDLC_PFC 0x10 -#define AHDLC_ACFC 0x20 - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -89,9 +75,9 @@ * ****************************************************************************/ -static u16_t crcadd(u16_t crcvalue, u8_t c) +static uint16_t crcadd(uint16_t crcvalue, uint8_t c) { - u16_t b; + uint16_t b; b = (crcvalue ^ c) & 0xFF; b = (b ^ (b << 4)) & 0xFF; @@ -112,11 +98,12 @@ static u16_t crcadd(u16_t crcvalue, u8_t c) void ahdlc_init(struct ppp_context_s *ctx) { - ctx->ahdlc_flags = 0 | AHDLC_RX_ASYNC_MAP; - ctx->ahdlc_rx_count = 0; + ctx->ahdlc_flags = PPP_RX_ASYNC_MAP; + ctx->ahdlc_rx_count = 0; ctx->ahdlc_tx_offline = 0; #ifdef PPP_STATISTICS + ctx->ahdlc_crc_error = 0; ctx->ahdlc_rx_tobig_error = 0; #endif } @@ -131,7 +118,7 @@ void ahdlc_rx_ready(struct ppp_context_s *ctx) { ctx->ahdlc_rx_count = 0; ctx->ahdlc_rx_crc = 0xffff; - ctx->ahdlc_flags |= AHDLC_RX_READY; + ctx->ahdlc_flags |= PPP_RX_READY; } /**************************************************************************** @@ -144,21 +131,21 @@ void ahdlc_rx_ready(struct ppp_context_s *ctx) * ****************************************************************************/ -u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) +uint8_t ahdlc_rx(FAR struct ppp_context_s *ctx, uint8_t c) { - //static u16_t protocol; + /* Check to see if PPP packet is useable, we should have hardware flow + * control set, but if host ignores it and sends us a char when the PPP + * Receive packet is in use, discard the character. + */ - /* Check to see if PPP packet is useable, we should have hardware - flow control set, but if host ignores it and sends us a char when - the PPP Receive packet is in use, discard the character. */ - - if (ctx->ahdlc_flags & AHDLC_RX_READY) + if ((ctx->ahdlc_flags & PPP_RX_READY) != 0) { - /* Check to see if character is less than 0x20 hex we really - should set AHDLC_RX_ASYNC_MAP on by default and only turn it - off when it is negotiated off to handle some buggy stacks. */ + /* Check to see if character is less than 0x20 hex we really should set + * AHDLC_RX_ASYNC_MAP on by default and only turn it off when it is + * negotiated off to handle some buggy stacks. + */ - if ((c < 0x20) && ((ctx->ahdlc_flags & AHDLC_RX_ASYNC_MAP) == 0)) + if ((c < 0x20) && ((ctx->ahdlc_flags & PPP_RX_ASYNC_MAP) == 0)) { /* Discard character */ @@ -168,11 +155,11 @@ u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) /* Are we in escaped mode? */ - if (ctx->ahdlc_flags & AHDLC_ESCAPED) + if ((ctx->ahdlc_flags & PPP_ESCAPED) != 0) { /* Set escaped to FALSE */ - ctx->ahdlc_flags &= ~AHDLC_ESCAPED; + ctx->ahdlc_flags &= ~PPP_ESCAPED; /* If value is 0x7e then silently discard and reset receive packet */ @@ -193,11 +180,13 @@ u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) if (ctx->ahdlc_rx_crc == CRC_GOOD_VALUE) { DEBUG1(("\nReceiving packet with good crc value, len %d\n", - ctx->ahdlc_rx_count)); + ctx->ahdlc_rx_count)); - /* we hae a good packet, turn off CTS until we are done with - this packet */ - /*CTS_OFF();*/ + /* we have a good packet, turn off CTS until we are done with this + * packet + */ + + /* CTS_OFF(); */ #if PPP_STATISTICS /* Update statistics */ @@ -205,35 +194,39 @@ u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) ++ctx->ppp_rx_frame_count; #endif - /* Femove CRC bytes from packet */ + /* Remove CRC bytes from packet */ ctx->ahdlc_rx_count -= 2; /* Lock PPP buffer */ - ctx->ahdlc_flags &= ~AHDLC_RX_READY; + ctx->ahdlc_flags &= ~PPP_RX_READY; - /*upcall routine must fully process frame before return - * as returning signifies that buffer belongs to AHDLC again. - */ + /* upcall routine must fully process frame before return as + * returning signifies that buffer belongs to AHDLC again. + */ - if ((c & 0x1) && (ctx->ahdlc_flags & PPP_PFC)) + if ((ctx->ahdlc_rx_buffer[0] & 0x1) != 0 && + (ctx->ahdlc_flags & PPP_PFC) != 0) { /* Send up packet */ - ppp_upcall(ctx, (u16_t)ctx->ahdlc_rx_buffer[0], - (u8_t *)&ctx->ahdlc_rx_buffer[1], - (u16_t)(ctx->ahdlc_rx_count - 1)); + ppp_upcall(ctx, (uint16_t) ctx->ahdlc_rx_buffer[0], + (FAR uint8_t *) & ctx->ahdlc_rx_buffer[1], + (uint16_t) (ctx->ahdlc_rx_count - 1)); } else { /* Send up packet */ - ppp_upcall(ctx, (u16_t)(ctx->ahdlc_rx_buffer[0] << 8 | ctx->ahdlc_rx_buffer[1]), - (u8_t *)&ctx->ahdlc_rx_buffer[2], (u16_t)(ctx->ahdlc_rx_count - 2)); + ppp_upcall(ctx, + (uint16_t) (ctx->ahdlc_rx_buffer[0] << 8 | ctx-> + ahdlc_rx_buffer[1]), + (FAR uint8_t *) & ctx->ahdlc_rx_buffer[2], + (uint16_t) (ctx->ahdlc_rx_count - 2)); } - ctx->ahdlc_tx_offline = 0; /* The remote side is alive */ + ctx->ahdlc_tx_offline = 0; /* The remote side is alive */ ahdlc_rx_ready(ctx); return 0; } @@ -246,9 +239,10 @@ u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) #endif /* Shouldn't we dump the packet and not pass it up? */ - /*ppp_upcall((u16_t)ahdlc_rx_buffer[0], - (u8_t *)&ahdlc_rx_buffer[0], (u16_t)(ahdlc_rx_count+2)); - dump_ppp_packet(&ahdlc_rx_buffer[0],ahdlc_rx_count);*/ + /* ppp_upcall((uint16_t)ahdlc_rx_buffer[0], (FAR uint8_t + * *)&ahdlc_rx_buffer[0], (uint16_t)(ahdlc_rx_count+2)); + * dump_ppp_packet(&ahdlc_rx_buffer[0],ahdlc_rx_count); + */ } ahdlc_rx_ready(ctx); @@ -256,13 +250,13 @@ u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) } else if (c == 0x7d) { - /* Handle escaped chars*/ + /* Handle escaped chars */ ctx->ahdlc_flags |= PPP_ESCAPED; return 0; } - /* Rry to store char if not too big */ + /* Try to store char if not too big */ if (ctx->ahdlc_rx_count >= PPP_RX_BUFFER_SIZE) { @@ -295,6 +289,7 @@ u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) else { /* we are busy and didn't process the character. */ + DEBUG1(("Busy/not active\n")); return 1; } @@ -311,7 +306,7 @@ u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t c) * ****************************************************************************/ -void ahdlc_tx_char(struct ppp_context_s *ctx, u16_t protocol, u8_t c) +void ahdlc_tx_char(struct ppp_context_s *ctx, uint16_t protocol, uint8_t c) { /* Add in crc */ @@ -324,7 +319,9 @@ void ahdlc_tx_char(struct ppp_context_s *ctx, u16_t protocol, u8_t c) */ if ((c == 0x7d) || (c == 0x7e) || ((c < 0x20) && ((protocol == LCP) || - (ctx->ahdlc_flags & PPP_TX_ASYNC_MAP) == 0))) + (ctx-> + ahdlc_flags & + PPP_TX_ASYNC_MAP) == 0))) { /* Send escape char and xor byte by 0x20 */ @@ -346,14 +343,15 @@ void ahdlc_tx_char(struct ppp_context_s *ctx, u16_t protocol, u8_t c) * ****************************************************************************/ -u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, - u8_t *buffer, u16_t headerlen, u16_t datalen) +uint8_t ahdlc_tx(struct ppp_context_s *ctx, uint16_t protocol, + FAR uint8_t * header, FAR uint8_t * buffer, uint16_t headerlen, + uint16_t datalen) { - u16_t i; - u8_t c; + uint16_t i; + uint8_t c; DEBUG1(("\nAHDLC_TX - transmit frame, protocol 0x%04x, length %d offline %d\n", - protocol, datalen + headerlen, ctx->ahdlc_tx_offline)); + protocol, datalen + headerlen, ctx->ahdlc_tx_offline)); if (AHDLC_TX_OFFLINE && (ctx->ahdlc_tx_offline++ > AHDLC_TX_OFFLINE)) { @@ -378,8 +376,7 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, DEBUG1(("\n\n")); #endif - /* Check to see that physical layer is up, we can assume is some - cases */ + /* Check to see that physical layer is up, we can assume is some cases */ /* Write leading 0x7e */ @@ -391,7 +388,10 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, /* send HDLC control and address if not disabled or of LCP frame type */ - /*if ((0==(ahdlc_flags & PPP_ACFC)) || ((0xc0==buffer[0]) && (0x21==buffer[1]))) */ + /* if ((0==(ahdlc_flags & PPP_ACFC)) || ((0xc0==buffer[0]) && + * (0x21==buffer[1]))) + */ + if ((0 == (ctx->ahdlc_flags & PPP_ACFC)) || (protocol == LCP)) { ahdlc_tx_char(ctx, protocol, 0xff); @@ -400,8 +400,8 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, /* Write Protocol */ - ahdlc_tx_char(ctx, protocol,(u8_t)(protocol >> 8)); - ahdlc_tx_char(ctx, protocol,(u8_t)(protocol & 0xff)); + ahdlc_tx_char(ctx, protocol, (uint8_t) (protocol >> 8)); + ahdlc_tx_char(ctx, protocol, (uint8_t) (protocol & 0xff)); /* Write header if it exists */ @@ -411,7 +411,7 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, c = header[i]; - /* Write it...*/ + /* Write it... */ ahdlc_tx_char(ctx, protocol, c); } @@ -424,7 +424,7 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, c = buffer[i]; - /* Write it...*/ + /* Write it... */ ahdlc_tx_char(ctx, protocol, c); } @@ -432,8 +432,8 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, /* Send crc, lsb then msb */ i = ctx->ahdlc_tx_crc ^ 0xffff; - ahdlc_tx_char(ctx, protocol, (u8_t)(i & 0xff)); - ahdlc_tx_char(ctx, protocol, (u8_t)((i >> 8) & 0xff)); + ahdlc_tx_char(ctx, protocol, (uint8_t) (i & 0xff)); + ahdlc_tx_char(ctx, protocol, (uint8_t) ((i >> 8) & 0xff)); /* Write trailing 0x7e, probably not needed but it doesn't hurt */ diff --git a/netutils/pppd/ahdlc.h b/netutils/pppd/ahdlc.h index c6cddcd84..8ed51ff5d 100644 --- a/netutils/pppd/ahdlc.h +++ b/netutils/pppd/ahdlc.h @@ -62,13 +62,14 @@ extern "C" #define EXTERN extern #endif -void ahdlc_init(struct ppp_context_s *ctx); +void ahdlc_init(FAR struct ppp_context_s *ctx); -void ahdlc_rx_ready(struct ppp_context_s *ctx); +void ahdlc_rx_ready(FAR struct ppp_context_s *ctx); -u8_t ahdlc_rx(struct ppp_context_s *ctx, u8_t); -u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, - u8_t *buffer, u16_t headerlen, u16_t datalen); +uint8_t ahdlc_rx(FAR struct ppp_context_s *ctx, uint8_t); +uint8_t ahdlc_tx(FAR struct ppp_context_s *ctx, uint16_t protocol, + FAR uint8_t *header, FAR uint8_t *buffer, uint16_t headerlen, + uint16_t datalen); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/pppd/ipcp.c b/netutils/pppd/ipcp.c index 16133bd88..489c13cc7 100644 --- a/netutils/pppd/ipcp.c +++ b/netutils/pppd/ipcp.c @@ -66,9 +66,9 @@ * only) */ -static const u8_t ipcplist[] = +static const uint8_t ipcplist[] = { - 0x3, + IPCP_IPADDRESS, 0 }; @@ -84,11 +84,11 @@ static const u8_t ipcplist[] = * Name: printip ****************************************************************************/ -#if 0 -void printip(uip_ipaddr_t ip2) +#if PPP_DEBUG +void printip(struct in_addr ip2) { - char *ip = (u8_t*)ip2; - DEBUG1((" %d.%d.%d.%d ",ip[0],ip[1],ip[2],ip[3])); + char *ip = (FAR uint8_t *) & ip2.s_addr; + DEBUG1((" %d.%d.%d.%d ", ip[0], ip[1], ip[2], ip[3])); } #else # define printip(x) @@ -98,7 +98,7 @@ void printip(uip_ipaddr_t ip2) * Name: ipcp_init ****************************************************************************/ -void ipcp_init(struct ppp_context_s *ctx) +void ipcp_init(FAR struct ppp_context_s *ctx) { DEBUG1(("ipcp init\n")); @@ -126,317 +126,335 @@ void ipcp_init(struct ppp_context_s *ctx) * ****************************************************************************/ -void ipcp_rx(struct ppp_context_s *ctx, u8_t *buffer, u16_t count) +void ipcp_rx(FAR struct ppp_context_s *ctx, FAR uint8_t * buffer, + uint16_t count) { - u8_t *bptr = buffer; - //IPCPPKT *pkt=(IPCPPKT *)buffer; - u16_t len; + FAR uint8_t *bptr = buffer; + uint16_t len; - DEBUG1(("IPCP len %d\n",count)); + DEBUG1(("IPCP len %d\n", count)); switch (*bptr++) - { - case CONF_REQ: - /* Parse request and see if we can ACK it */ + { + case CONF_REQ: + /* Parse request and see if we can ACK it */ - ++bptr; - len = (*bptr++ << 8); - len |= *bptr++; - /* len-=2; */ + ++bptr; + len = (*bptr++ << 8); + len |= *bptr++; - DEBUG1(("check lcplist\n")); - if (scan_packet(ctx, IPCP, ipcplist, buffer, bptr, (u16_t)(len - 4))) - { - DEBUG1(("option was bad\n")); - } - else - { - DEBUG1(("IPCP options are good\n")); + /* len-=2; */ - /* Parse out the results */ - /* lets try to implement what peer wants */ - /* Reject any protocol not */ - /* Error? if we we need to send a config Reject ++++ this is good for a subroutine*/ - /* All we should get is the peer IP address */ + DEBUG1(("check lcplist\n")); + if (scan_packet(ctx, IPCP, ipcplist, buffer, bptr, (uint16_t) (len - 4))) + { + DEBUG1(("option was bad\n")); + } + else + { + DEBUG1(("IPCP options are good\n")); - if (IPCP_IPADDRESS == *bptr++) - { - /* Dump length */ + /* Parse out the results */ - ++bptr; + /* lets try to implement what peer wants */ + + /* Reject any protocol not */ + + /* Error? if we we need to send a config Reject ++++ this is good for + * a subroutine. + */ + + /* All we should get is the peer IP address */ + + if (IPCP_IPADDRESS == *bptr++) + { + /* Dump length */ + + ++bptr; #ifdef IPCP_GET_PEER_IP - ((u8_t*)&ctx->peer_ip)[0] = *bptr++; - ((u8_t*)&ctx->peer_ip)[1] = *bptr++; - ((u8_t*)&ctx->peer_ip)[2] = *bptr++; - ((u8_t*)&ctx->peer_ip)[3] = *bptr++; + ((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++; - DEBUG1(("Peer IP ")); - /* printip(peer_ip_addr); */ - DEBUG1(("\n")); + DEBUG1(("Peer IP ")); + printip(ctx->peer_ip); + DEBUG1(("\n")); - netlib_set_dripv4addr((char*)ctx->ifname, &ctx->peer_ip); + netlib_set_dripv4addr((char *)ctx->ifname, &ctx->peer_ip); #else - bptr += 4; + bptr += 4; #endif - } - else - { - DEBUG1(("HMMMM this shouldn't happen IPCP1\n")); - } + } + else + { + DEBUG1(("HMMMM this shouldn't happen IPCP1\n")); + } #if 0 - if (error) - { - /* Write the config NAK packet we've built above, take on the header */ + if (error) + { + /* Write the config NAK packet we've built above, take on the + * header + */ - bptr = buffer; - *bptr++ = CONF_NAK; /* Write Conf_rej */ - *bptr++; - /*tptr++;*/ /* skip over ID */ + bptr = buffer; + *bptr++ = CONF_NAK; /* Write Conf_rej */ + *bptr++; - /* Write new length */ + /* tptr++; *//* skip over ID */ - *bptr++ = 0; - *bptr = tptr - buffer; + /* Write new length */ - /* Write the reject frame */ + *bptr++ = 0; + *bptr = tptr - buffer; - DEBUG1(("Writing NAK frame \n")); - ahdlc_tx(IPCP, buffer, (u16_t)(tptr - buffer)); - DEBUG1(("- End NAK Write frame\n")); - } - else - { - } + /* Write the reject frame */ + + DEBUG1(("Writing NAK frame \n")); + ahdlc_tx(IPCP, buffer, (uint16_t) (tptr - buffer)); + DEBUG1(("- End NAK Write frame\n")); + } + else + { + } #endif - /* If we get here then we are OK, lets send an ACK and tell the rest - * of our modules our negotiated config. - */ + /* If we get here then we are OK, lets send an ACK and tell the rest + * of our modules our negotiated config. + */ - 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) */ + 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) */ - /* Set stuff */ + /* Set stuff */ - /* ppp_flags |= tflag; */ - DEBUG1(("SET- stuff -- are we up? c=%d dif=%d \n", count, (u16_t)(bptr - buffer))); + /* ppp_flags |= tflag; */ - /* Write the ACK frame */ + DEBUG1(("SET- stuff -- are we up? c=%d dif=%d \n", + count, (uint16_t) (bptr - buffer))); - DEBUG1(("Writing ACK frame \n")); + /* Write the ACK frame */ - /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ + DEBUG1(("Writing ACK frame \n")); - ahdlc_tx(ctx, IPCP, 0, buffer, 0, count /*bptr-buffer*/); - DEBUG1(("- End ACK Write frame\n")); - } - break; + /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ - case CONF_ACK: /* config Ack */ - DEBUG1(("CONF ACK\n")); - /* Parse out the results - * - * Dump the ID and get the length. - */ - - /* Dump the ID */ - - bptr++; - - /* Get the length */ - - len = (*bptr++ << 8); - len |= *bptr++; - -#if 0 - /* Parse ACK and set data */ - - while (bptr < buffer + len) - { - switch (*bptr++) - { - case IPCP_IPADDRESS: - /* Dump length */ - - bptr++; - ((u8_t*)ipaddr)[0] = *bptr++; - ((u8_t*)ipaddr)[1] = *bptr++; - ((u8_t*)ipaddr)[2] = *bptr++; - ((u8_t*)ipaddr)[3] = *bptr++; - break; - - case IPCP_PRIMARY_DNS: - bptr++; - ((u8_t*)pri_dns_addr)[0] = *bptr++; - ((u8_t*)pri_dns_addr)[1] = *bptr++; - ((u8_t*)pri_dns_addr)[2] = *bptr++; - ((u8_t*)pri_dns_addr)[3] = *bptr++; - break; - - case IPCP_SECONDARY_DNS: - bptr++; - ((u8_t*)sec_dns_addr)[0] = *bptr++; - ((u8_t*)sec_dns_addr)[1] = *bptr++; - ((u8_t*)sec_dns_addr)[2] = *bptr++; - ((u8_t*)sec_dns_addr)[3] = *bptr++; - break; - - default: - DEBUG1(("IPCP CONFIG_ACK problem1\n")); + ahdlc_tx(ctx, IPCP, 0, buffer, 0, count /* bptr-buffer */); + DEBUG1(("- End ACK Write frame\n")); + } + break; + + case CONF_ACK: /* config Ack */ + DEBUG1(("CONF ACK\n")); + + /* Parse out the results Dump the ID and get the length. */ + + /* Dump the ID */ + + bptr++; + + /* Get the length */ + + len = (*bptr++ << 8); + len |= *bptr++; + +#if 0 + /* Parse ACK and set data */ + + while (bptr < buffer + len) + { + switch (*bptr++) + { + case IPCP_IPADDRESS: + /* Dump length */ + + bptr++; + ((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++; + break; + +# ifdef IPCP_GET_PRI_DNS + case IPCP_PRIMARY_DNS: + 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] = *bptr++; + break; +# endif + +# ifdef IPCP_GET_SEC_DNS + case IPCP_SECONDARY_DNS: + 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] = *bptr++; + break; +# endif + + default: + DEBUG1(("IPCP CONFIG_ACK problem1\n")); + } } - } #endif - ctx->ipcp_state |= IPCP_TX_UP; - /*ppp_ipcp_state &= ~IPCP_RX_UP;*/ + ctx->ipcp_state |= IPCP_TX_UP; - DEBUG1(("were up! \n")); - //printip(pppif.ipaddr); + /* ppp_ipcp_state &= ~IPCP_RX_UP; */ + + DEBUG1(("were up! \n")); + printip(ctx->local_ip); #ifdef IPCP_GET_PRI_DNS - printip(pri_dns_addr); + printip(ctx->pri_dns_addr); #endif #ifdef IPCP_GET_SEC_DNS - printip(sec_dns_addr); + printip(ctx->sec_dns_addr); #endif - DEBUG1(("\n")); - break; + DEBUG1(("\n")); + break; - case CONF_NAK: /* Config Nack */ - DEBUG1(("CONF NAK\n")); + case CONF_NAK: /* Config Nack */ + DEBUG1(("CONF NAK\n")); - /* Dump the ID */ + /* Dump the ID */ - bptr++; + bptr++; - /* Get the length */ + /* Get the length */ - len = (*bptr++ << 8); - len |= *bptr++; + len = (*bptr++ << 8); + len |= *bptr++; - /* Parse ACK and set data */ + /* Parse ACK and set data */ - while (bptr < buffer + len) - { - switch (*bptr++) + while (bptr < buffer + len) { - case IPCP_IPADDRESS: - /* dump length */ - bptr++; + switch (*bptr++) + { + case IPCP_IPADDRESS: + /* Dump length */ - ((u8_t*)&ctx->local_ip)[0] = (char)*bptr++; - ((u8_t*)&ctx->local_ip)[1] = (char)*bptr++; - ((u8_t*)&ctx->local_ip)[2] = (char)*bptr++; - ((u8_t*)&ctx->local_ip)[3] = (char)*bptr++; + bptr++; - netlib_ifup((char*)ctx->ifname); - netlib_set_ipv4addr((char*)ctx->ifname, &ctx->local_ip); - //DEBUG1(("My PPP-ipno: (%d.%d.%d.%d)\n", ((u8_t*)pppif.ipaddr)[0], ((u8_t*)pppif.ipaddr)[1], ((u8_t*)pppif.ipaddr)[2], ((u8_t*)pppif.ipaddr)[3])); - break; + ((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++; + + netlib_ifup((char *)ctx->ifname); + netlib_set_ipv4addr((char *)ctx->ifname, &ctx->local_ip); + break; #ifdef IPCP_GET_PRI_DNS - case IPCP_PRIMARY_DNS: - bptr++; - ((u8_t*)&ctx->pri_dns_addr)[0] = *bptr++; - ((u8_t*)&ctx->pri_dns_addr)[1] = *bptr++; - ((u8_t*)&ctx->pri_dns_addr)[2] = *bptr++; - ((u8_t*)&ctx->pri_dns_addr)[3] = *bptr++; - break; + case IPCP_PRIMARY_DNS: + 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] = *bptr++; + netlib_set_ipv4dnsaddr(&ctx->pri_dns_addr); + break; #endif #ifdef IPCP_GET_SEC_DNS - case IPCP_SECONDARY_DNS: - bptr++; - ((u8_t*)&ctx->sec_dns_addr)[0] = *bptr++; - ((u8_t*)&ctx->sec_dns_addr)[1] = *bptr++; - ((u8_t*)&ctx->sec_dns_addr)[2] = *bptr++; - ((u8_t*)&ctx->sec_dns_addr)[3] = *bptr++; - break; + case IPCP_SECONDARY_DNS: + 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] = *bptr++; + netlib_set_ipv4dnsaddr(&ctx->sec_dns_addr); + break; #endif - default: - DEBUG1(("IPCP CONFIG_ACK problem 2\n")); + default: + DEBUG1(("IPCP CONFIG_ACK problem 2\n")); + } } - } - ctx->ppp_id++; + ctx->ppp_id++; - printip(pppif.ipaddr); + printip(ctx->local_ip); #ifdef IPCP_GET_PRI_DNS - printip(pri_dns_addr); + printip(ctx->pri_dns_addr); #endif #ifdef IPCP_GET_PRI_DNS - printip(sec_dns_addr); + printip(ctx->sec_dns_addr); #endif - DEBUG1(("\n")); - break; + DEBUG1(("\n")); + break; - case CONF_REJ: /* Config Reject */ - DEBUG1(("CONF REJ\n")); + case CONF_REJ: /* Config Reject */ + DEBUG1(("CONF REJ\n")); - /* Remove the offending options*/ + /* Remove the offending options */ - ctx->ppp_id++; + ctx->ppp_id++; - /* Dump the ID */ + /* Dump the ID */ - bptr++; + bptr++; - /* Get the length */ + /* Get the length */ - len = (*bptr++ << 8); - len |= *bptr++; + len = (*bptr++ << 8); + len |= *bptr++; - /* Parse ACK and set data */ + /* Parse ACK and set data */ - while (bptr < buffer + len) - { - switch (*bptr++) + while (bptr < buffer + len) { - case IPCP_IPADDRESS: - ctx->ipcp_state |= IPCP_IP_BIT; - bptr += 5; - break; + switch (*bptr++) + { + case IPCP_IPADDRESS: + ctx->ipcp_state |= IPCP_IP_BIT; + bptr += 5; + break; #ifdef IPCP_GET_PRI_DNS - case IPCP_PRIMARY_DNS: - ctx->ipcp_state |= IPCP_PRI_DNS_BIT; - bptr += 5; - break; + case IPCP_PRIMARY_DNS: + ctx->ipcp_state |= IPCP_PRI_DNS_BIT; + bptr += 5; + break; #endif #ifdef IPCP_GET_PRI_DNS - case IPCP_SECONDARY_DNS: - ctx->ipcp_state |= IPCP_SEC_DNS_BIT; - bptr += 5; - break; + case IPCP_SECONDARY_DNS: + ctx->ipcp_state |= IPCP_SEC_DNS_BIT; + bptr += 5; + break; #endif - default: - DEBUG1(("IPCP this shoudln't happen 3\n")); + default: + DEBUG1(("IPCP this shoudln't happen 3\n")); + } } - } - break; + break; - default: - DEBUG1(("-Unknown 4\n")); - } + default: + DEBUG1(("-Unknown 4\n")); + } } /**************************************************************************** * Name: ipcp_task ****************************************************************************/ -void ipcp_task(struct ppp_context_s *ctx, u8_t *buffer) +void ipcp_task(FAR struct ppp_context_s *ctx, FAR uint8_t * buffer) { - u8_t *bptr; - u16_t t; + FAR uint8_t *bptr; + uint16_t t; IPCPPKT *pkt; - /* IPCP tx not up and hasn't timed out then lets see if we need to - send a request */ + /* IPCP tx not up and hasn't timed out then lets see if we need to send a + * request + */ if (!(ctx->ipcp_state & IPCP_TX_UP) && !(ctx->ipcp_state & IPCP_TX_TIMEOUT)) { @@ -448,7 +466,7 @@ void ipcp_task(struct ppp_context_s *ctx, u8_t *buffer) /* No pending request, lets build one */ - pkt=(IPCPPKT *)buffer; + pkt = (IPCPPKT *) buffer; /* Configure-Request only here, write id */ @@ -457,41 +475,42 @@ void ipcp_task(struct ppp_context_s *ctx, u8_t *buffer) bptr = pkt->data; - /* Write options, we want IP address, and DNS addresses if set. */ - /* Write zeros for IP address the first time */ + /* Write options, we want IP address, and DNS addresses if set. + * Write zeros for IP address the first time + */ *bptr++ = IPCP_IPADDRESS; *bptr++ = 0x6; - *bptr++ = (u8_t)((u8_t*)&ctx->local_ip)[0]; - *bptr++ = (u8_t)((u8_t*)&ctx->local_ip)[1]; - *bptr++ = (u8_t)((u8_t*)&ctx->local_ip)[2]; - *bptr++ = (u8_t)((u8_t*)&ctx->local_ip)[3]; + *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]; #ifdef IPCP_GET_PRI_DNS - if (!(ppp_ipcp_state & IPCP_PRI_DNS_BIT)) + if ((ctx->ipcp_state & IPCP_PRI_DNS_BIT) == 0) { /* Write zeros for IP address the first time */ *bptr++ = IPCP_PRIMARY_DNS; *bptr++ = 0x6; - *bptr++ = ((u8_t*)&ctx->pri_dns_addr)[0]; - *bptr++ = ((u8_t*)&ctx->pri_dns_addr)[1]; - *bptr++ = ((u8_t*)&ctx->pri_dns_addr)[2]; - *bptr++ = ((u8_t*)&ctx->pri_dns_addr)[3]; + *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]; } #endif #ifdef IPCP_GET_SEC_DNS - if (!(ppp_ipcp_state & IPCP_SEC_DNS_BIT)) + if ((ctx->ipcp_state & IPCP_SEC_DNS_BIT) == 0) { /* Write zeros for IP address the first time */ *bptr++ = IPCP_SECONDARY_DNS; *bptr++ = 0x6; - *bptr++ = ((u8_t*)&ctx->sec_dns_addr)[0]; - *bptr++ = ((u8_t*)&ctx->sec_dns_addr)[1]; - *bptr++ = ((u8_t*)&ctx->sec_dns_addr)[2]; - *bptr++ = ((u8_t*)&ctx->sec_dns_addr)[3]; + *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]; } #endif @@ -499,7 +518,7 @@ void ipcp_task(struct ppp_context_s *ctx, u8_t *buffer) t = bptr - buffer; - /* length here - code and ID + */ + /* length here - code and ID + */ pkt->len = htons(t); @@ -517,7 +536,7 @@ void ipcp_task(struct ppp_context_s *ctx, u8_t *buffer) if (ctx->ipcp_retry > IPCP_RETRY_COUNT) { - ctx->ipcp_state &= IPCP_TX_TIMEOUT; + ctx->ipcp_state |= IPCP_TX_TIMEOUT; } } } diff --git a/netutils/pppd/ipcp.h b/netutils/pppd/ipcp.h index 8f2772bbf..584f1df69 100644 --- a/netutils/pppd/ipcp.h +++ b/netutils/pppd/ipcp.h @@ -1,5 +1,5 @@ /**************************************************************************** - * netutils/pppd/ipcp.c + * netutils/pppd/ipcp.h * Internet Protocol Control Protocol header file * * Version: 0.1 Original Version June 3, 2000 @@ -51,11 +51,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Config options (move to pppconfig) - #define IPCP_RETRY_COUNT 5 - #define IPCP_TIMEOUT 5 -*/ - /* IPCP Option Types */ #define IPCP_IPADDRESS 0x03 @@ -68,8 +63,8 @@ #define IPCP_RX_UP 0x02 #define IPCP_IP_BIT 0x04 #define IPCP_TX_TIMEOUT 0x08 -#define IPCP_PRI_DNS_BIT 0x08 -#define IPCP_SEC_DNS_BIT 0x10 +#define IPCP_PRI_DNS_BIT 0x10 +#define IPCP_SEC_DNS_BIT 0x20 /**************************************************************************** * Public Types @@ -79,10 +74,10 @@ struct ppp_context_s; typedef struct _ipcp { - u8_t code; - u8_t id; - u16_t len; - u8_t data[0]; + uint8_t code; + uint8_t id; + uint16_t len; + uint8_t data[0]; } IPCPPKT; /**************************************************************************** @@ -98,9 +93,9 @@ extern "C" #define EXTERN extern #endif -void ipcp_init(struct ppp_context_s *ctx); -void ipcp_task(struct ppp_context_s *ctx, u8_t *buffer); -void ipcp_rx(struct ppp_context_s *ctx, u8_t *, u16_t); +void ipcp_init(FAR struct ppp_context_s *ctx); +void ipcp_task(FAR struct ppp_context_s *ctx, FAR uint8_t *buffer); +void ipcp_rx(FAR struct ppp_context_s *ctx, FAR uint8_t *, uint16_t); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/pppd/lcp.c b/netutils/pppd/lcp.c index b09c60feb..fe6943789 100644 --- a/netutils/pppd/lcp.c +++ b/netutils/pppd/lcp.c @@ -69,16 +69,18 @@ ****************************************************************************/ /* We need this when we neg our direction. - u8_t lcp_tx_options; */ + * uint8_t lcp_tx_options; + */ /* Define the supported parameters for this module here. */ -static const u8_t lcplist[] = -{ +static const uint8_t lcplist[] = { LPC_MAGICNUMBER, LPC_PFC, LPC_ACFC, +#ifdef CONFIG_NETUTILS_PPPD_PAP LPC_AUTH, +#endif LPC_ACCM, LPC_MRU, 0 @@ -107,318 +109,313 @@ void lcp_init(struct ppp_context_s *ctx) * ****************************************************************************/ -void lcp_rx(struct ppp_context_s *ctx, u8_t *buffer, u16_t count) +void lcp_rx(struct ppp_context_s *ctx, uint8_t * buffer, uint16_t count) { - u8_t *bptr = buffer, *tptr; - u8_t error = 0; - u8_t id; - u16_t len, j; - struct pppd_settings_s *pppd_settings = ctx->settings; + FAR uint8_t *bptr = buffer; + FAR uint8_t *tptr; + uint8_t error = 0; + uint8_t id; + uint16_t len; + uint16_t j; switch (*bptr++) - { - case CONF_REQ: /* config request */ - /* Parse request and see if we can ACK it */ + { + case CONF_REQ: /* config request */ + /* Parse request and see if we can ACK it */ - id = *bptr++; - len = (*bptr++ << 8); - len |= *bptr++; - /*len -= 2;*/ + id = *bptr++; + UNUSED(id); + len = (*bptr++ << 8); + len |= *bptr++; - /* In case of new peer connection */ + /* len -= 2; */ - ipcp_init(ctx); - ctx->lcp_state &= ~LCP_TX_UP; + /* In case of new peer connection */ - DEBUG1(("received [LCP Config Request id %u\n", id)); - if (scan_packet(ctx, (u16_t)LCP, lcplist, buffer, bptr, (u16_t)(len-4))) - { - /* Must do the -4 here, !scan packet */ + ipcp_init(ctx); + ctx->lcp_state &= ~LCP_RX_UP; - DEBUG1((" options were rejected\n")); - } - else - { - /* Lets try to implement what peer wants */ + DEBUG1(("received [LCP Config Request id %u\n", id)); + if (scan_packet + (ctx, (uint16_t) LCP, lcplist, buffer, bptr, (uint16_t) (len - 4))) + { + /* Must do the -4 here, !scan packet */ - tptr = bptr = buffer; - bptr += 4; /* skip code, id, len */ - error = 0; + DEBUG1((" options were rejected\n")); + } + else + { + /* Lets try to implement what peer wants */ - /* First scan for unknown values */ + tptr = bptr; + error = 0; - while(bptr < (buffer + len)) - { - switch (*bptr++) + /* First scan for unknown values */ + + while (bptr < (buffer + len)) { - case LPC_MRU: /* mru */ - j = *bptr++; - j -= 2; + switch (*bptr++) + { + case LPC_MRU: /* mru */ + j = *bptr++; + j -= 2; - if (j == 2) - { - ctx->ppp_tx_mru = ((int)*bptr++) << 8; - ctx->ppp_tx_mru |= *bptr++; - DEBUG1((" ", ctx->ppp_tx_mru)); - } - else - { - DEBUG1((" ")); - } - break; + if (j == 2) + { + ctx->ppp_tx_mru = ((int)*bptr++) << 8; + ctx->ppp_tx_mru |= *bptr++; + DEBUG1((" ", ctx->ppp_tx_mru)); + } + else + { + DEBUG1((" ")); + } + break; - case LPC_ACCM: - bptr++; /* skip length */ - j = *bptr++; - j += *bptr++; - j += *bptr++; - j += *bptr++; + case LPC_ACCM: + bptr++; /* skip length */ + j = *bptr++; + j += *bptr++; + j += *bptr++; + j += *bptr++; - if (j==0) - { - // ok - DEBUG1(("",j)); - //ahdlc_flags |= PPP_TX_ASYNC_MAP; - } - else if (j!=0) - { - // ok - DEBUG1((", assume 0xffffffff",j)); - } - else - { - /* Fail. We only support default or all zeros */ + if (j == 0) + { + /* OK */ - DEBUG1(("We only support default or all zeros for ACCM ")); - error = 1; - *tptr++ = LPC_ACCM; - *tptr++ = 0x6; - *tptr++ = 0; - *tptr++ = 0; - *tptr++ = 0; - *tptr++ = 0; - } - break; + DEBUG1(("", j)); + ctx->ahdlc_flags |= PPP_TX_ASYNC_MAP; + } + else if (j == 0x3fc) + { + /* OK */ + + DEBUG1((", assume 0xffffffff", j)); + ctx->ahdlc_flags &= ~PPP_TX_ASYNC_MAP; + } + else + { + /* Fail. We only support default or all zeros */ + + DEBUG1(("We only support default or all zeros for ACCM ")); + error = 1; + *tptr++ = LPC_ACCM; + *tptr++ = 0x6; + *tptr++ = 0; + *tptr++ = 0; + *tptr++ = 0; + *tptr++ = 0; + } + break; #ifdef CONFIG_NETUTILS_PPPD_PAP - case LPC_AUTH: - bptr++; - if ((*bptr++ == 0xc0) && (*bptr++ == 0x23)) - { - /* Negotiate PAP */ - - if (strlen(pppd_settings->pap_username) > 0) + case LPC_AUTH: + bptr++; + if ((*bptr++ == 0xc0) && (*bptr++ == 0x23)) { + /* Negotiate PAP */ + DEBUG1((" ")); ctx->lcp_state |= LCP_RX_AUTH; } else { - DEBUG1((" ")); + /* We only support PAP */ - *tptr++ = CONF_REJ; - tptr++; // Keep ID - *tptr++ = 0; - *tptr++ = 8; + DEBUG1(("")); + error = 1; *tptr++ = LPC_AUTH; *tptr++ = 0x4; *tptr++ = 0xc0; *tptr++ = 0x23; - ahdlc_tx(ctx, LCP, 0, buffer, 0, (u16_t)(tptr-buffer)); - return; } + break; +#endif /* CONFIG_NETUTILS_PPPD_PAP */ + + case LPC_MAGICNUMBER: + DEBUG1((" ")); + + /* Compare incoming number to our number (not implemented) */ + + bptr++; /* For now just dump */ + bptr++; + bptr++; + bptr++; + bptr++; + break; + + case LPC_PFC: + bptr++; + DEBUG1((" ")); + ctx->ahdlc_flags |= PPP_PFC; + break; + + case LPC_ACFC: + bptr++; + DEBUG1((" ")); + ctx->ahdlc_flags |= PPP_ACFC; + break; } - else - { - /* We only support PAP */ - - DEBUG1(("")); - error = 1; - *tptr++ = LPC_AUTH; - *tptr++ = 0x4; - *tptr++ = 0xc0; - *tptr++ = 0x23; - } - break; -#endif /* CONFIG_NETUTILS_PPPD_PAP */ - - case LPC_MAGICNUMBER: - DEBUG1((" ")); - - /* Compare incoming number to our number (not implemented) */ - - bptr++; /* For now just dump */ - bptr++; - bptr++; - bptr++; - bptr++; - break; - - case LPC_PFC: - bptr++; - DEBUG1((" ")); - /*tflag|=PPP_PFC;*/ - break; - - case LPC_ACFC: - bptr++; - DEBUG1((" ")); - /*tflag|=PPP_ACFC;*/ - break; } - } - /* Error? if we we need to send a config Reject ++++ this is good - * for a subroutine. - */ + /* Error? if we we need to send a config Reject ++++ this is good for + * a subroutine. + */ - if (error) - { - /* Write the config NAK packet we've built above, take on the - * header - */ + if (error) + { + /* Write the config NAK packet we've built above, take on the + * header + */ - bptr = buffer; - *bptr++ = CONF_NAK; /* Write Conf_rej */ - bptr++;/*tptr++;*/ /* skip over ID */ + bptr = buffer; + *bptr++ = CONF_NAK; /* Write Conf_rej */ + bptr++; /* tptr++; skip over ID */ - /* Write new length */ + /* Write new length */ - *bptr++ = 0; - *bptr = tptr - buffer; + *bptr++ = 0; + *bptr = tptr - buffer; - /* Write the reject frame */ + /* Write the reject frame */ - DEBUG1(("\nWriting NAK frame \n")); - // Send packet ahdlc_txz(procol,header,data,headerlen,datalen); - ahdlc_tx(ctx, LCP, 0, buffer, 0, (u16_t)(tptr-buffer)); - DEBUG1(("- end NAK Write frame\n")); - } - else - { - /* If we get here then we are OK, lets send an ACK and tell the rest - * of our modules our negotiated config. - */ + DEBUG1(("\nWriting NAK frame \n")); - DEBUG1(("\nSend ACK!\n")); - bptr = buffer; - *bptr++ = CONF_ACK; /* Write Conf_ACK */ - bptr++; /* Skip ID (send same one) */ + /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ - /* Set stuff */ + ahdlc_tx(ctx, LCP, 0, buffer, 0, (uint16_t) (tptr - buffer)); + DEBUG1(("- end NAK Write frame\n")); + } + else + { + /* If we get here then we are OK, lets send an ACK and tell the + * rest of our modules our negotiated config. + */ - /*ppp_flags|=tflag;*/ - /* DEBUG2("SET- stuff -- are we up? c=%d dif=%d \n", count, (u16_t)(bptr-buffer)); */ + DEBUG1(("\nSend ACK!\n")); + bptr = buffer; + *bptr++ = CONF_ACK; /* Write Conf_ACK */ + bptr++; /* Skip ID (send same one) */ - /* Write the ACK frame */ + /* Set stuff */ - DEBUG2(("Writing ACK frame \n")); + /* ppp_flags |= tflag; + * DEBUG2("SET- stuff -- are we up? c=%d dif=%d \n", count, + * (uint16_t)(bptr-buffer)); + */ - /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ + /* Write the ACK frame */ - ahdlc_tx(ctx, LCP, 0, buffer, 0, count /*bptr-buffer*/); - DEBUG2(("- end ACK Write frame\n")); - ctx->lcp_state |= LCP_RX_UP; - } - } - break; + DEBUG2(("Writing ACK frame \n")); - case CONF_ACK: /* config Ack Anytime we do an ack reset the timer to force send. */ - DEBUG1(("LCP-ACK - ")); + /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ - /* Check that ID matches one sent */ + ahdlc_tx(ctx, LCP, 0, buffer, 0, count /* bptr-buffer */); + DEBUG2(("- end ACK Write frame\n")); + ctx->lcp_state |= LCP_RX_UP; + } + } + break; - if (*bptr++ == ctx->ppp_id) - { - /* Change state to PPP up. */ + case CONF_ACK: /* config Ack Anytime we do an ack reset the + * timer to force send. */ + DEBUG1(("LCP-ACK - ")); - DEBUG1((">>>>>>>> good ACK id up! %d\n", ctx->ppp_id)); + /* Check that ID matches one sent */ - /* Copy negotiated values over */ + if (*bptr++ == ctx->ppp_id) + { + /* Change state to PPP up. */ - ctx->lcp_state |= LCP_TX_UP; - } - else - { - DEBUG1(("*************++++++++++ bad id %d\n", ctx->ppp_id)); - } - break; + DEBUG1((">>>>>>>> good ACK id up! %d\n", ctx->ppp_id)); - case CONF_NAK: /* Config Nack */ - DEBUG1(("LCP-CONF NAK\n")); - ctx->ppp_id++; - break; + /* Copy negotiated values over */ - case CONF_REJ: /* Config Reject */ - DEBUG1(("LCP-CONF REJ\n")); - ctx->ppp_id++; - break; + ctx->lcp_state |= LCP_TX_UP; + } + else + { + DEBUG1(("*************++++++++++ bad id %d\n", ctx->ppp_id)); + } + break; - case TERM_REQ: /* Terminate Request */ - DEBUG1(("LCP-TERM-REQ -")); - bptr = buffer; - *bptr++ = TERM_ACK; /* Write TERM_ACK */ + case CONF_NAK: /* Config Nack */ + DEBUG1(("LCP-CONF NAK\n")); + ctx->ppp_id++; + break; - /* Write the reject frame */ + case CONF_REJ: /* Config Reject */ + DEBUG1(("LCP-CONF REJ\n")); + ctx->ppp_id++; + break; - DEBUG1(("Writing TERM_ACK frame \n")); + case TERM_REQ: /* Terminate Request */ + DEBUG1(("LCP-TERM-REQ -")); + bptr = buffer; + *bptr++ = TERM_ACK; /* Write TERM_ACK */ - /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ + /* Write the reject frame */ - ahdlc_tx(ctx, LCP, 0, buffer, 0, count); + DEBUG1(("Writing TERM_ACK frame \n")); - ctx->lcp_state &= ~LCP_TX_UP; - ctx->lcp_state |= LCP_TERM_PEER; - break; + /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ - case TERM_ACK: - DEBUG1(("LCP-TERM ACK\n")); - break; + ahdlc_tx(ctx, LCP, 0, buffer, 0, count); - case ECHO_REQ: - if ((ctx->lcp_state & LCP_TX_UP) && (ctx->lcp_state & LCP_RX_UP)) - { - bptr = buffer; - *bptr++ = ECHO_REP; /* Write ECHO-REPLY */ + ctx->lcp_state &= ~LCP_TX_UP; + ctx->lcp_state |= LCP_TERM_PEER; + break; - bptr += 3; /* Skip id and length */ + case TERM_ACK: + DEBUG1(("LCP-TERM ACK\n")); + break; - *bptr++ = 0; /* Zero Magic */ - *bptr++ = 0; - *bptr++ = 0; - *bptr++ = 0; + case ECHO_REQ: + if ((ctx->lcp_state & LCP_TX_UP) && (ctx->lcp_state & LCP_RX_UP)) + { + bptr = buffer; + *bptr++ = ECHO_REP; /* Write ECHO-REPLY */ - /* Write the echo reply frame */ + bptr += 3; /* Skip id and length */ - DEBUG1(("\nWriting ECHO-REPLY frame \n")); - // Send packet ahdlc_txz(procol,header,data,headerlen,datalen); - ahdlc_tx(ctx, LCP, 0, buffer, 0, count); - DEBUG1(("- end ECHO-REPLY Write frame\n")); - } - break; + *bptr++ = 0; /* Zero Magic */ + *bptr++ = 0; + *bptr++ = 0; + *bptr++ = 0; - case ECHO_REP: - DEBUG1(("LCP-ECHO REPLY\n")); - if ((ctx->lcp_state & LCP_TX_UP) && (ctx->lcp_state & LCP_RX_UP)) - { - ctx->ppp_id++; - } - break; + /* Write the echo reply frame */ - default: - DEBUG1(("LCP unknown packet: %02x", *(bptr-1))); - break; - } + DEBUG1(("\nWriting ECHO-REPLY frame \n")); + + /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ + + ahdlc_tx(ctx, LCP, 0, buffer, 0, count); + DEBUG1(("- end ECHO-REPLY Write frame\n")); + } + break; + + case ECHO_REP: + DEBUG1(("LCP-ECHO REPLY\n")); + if ((ctx->lcp_state & LCP_TX_UP) && (ctx->lcp_state & LCP_RX_UP)) + { + ctx->ppp_id++; + } + break; + + default: + DEBUG1(("LCP unknown packet: %02x", *(bptr - 1))); + break; + } } /**************************************************************************** * Name: lcp_disconnect ****************************************************************************/ -void lcp_disconnect(struct ppp_context_s *ctx, u8_t id) +void lcp_disconnect(struct ppp_context_s *ctx, uint8_t id) { - u8_t buffer[4]; - u8_t *bptr = buffer; + uint8_t buffer[4]; + FAR uint8_t *bptr = buffer; *bptr++ = TERM_REQ; *bptr++ = id; @@ -432,47 +429,50 @@ void lcp_disconnect(struct ppp_context_s *ctx, u8_t id) * Name: lcp_echo_request ****************************************************************************/ -void lcp_echo_request(struct ppp_context_s *ctx, u8_t *buffer) +void lcp_echo_request(struct ppp_context_s *ctx) { - u8_t *bptr; - u16_t t; + uint8_t buffer[8]; + FAR uint8_t *bptr; + uint16_t t; LCPPKT *pkt; if ((ctx->lcp_state & LCP_TX_UP) && (ctx->lcp_state & LCP_RX_UP)) - { - if ((ppp_arch_clock_seconds() - ctx->lcp_prev_seconds) > LCP_ECHO_INTERVAL) - { - ctx->lcp_prev_seconds = ppp_arch_clock_seconds(); + { + if ((ppp_arch_clock_seconds() - ctx->lcp_prev_seconds) > + LCP_ECHO_INTERVAL) + { + ctx->lcp_prev_seconds = ppp_arch_clock_seconds(); - pkt = (LCPPKT *)buffer; + pkt = (LCPPKT *) buffer; - /* Configure-Request only here, write id */ + /* Configure-Request only here, write id */ - pkt->code = ECHO_REQ; - pkt->id = ctx->ppp_id; + pkt->code = ECHO_REQ; + pkt->id = ctx->ppp_id; - bptr = pkt->data; + bptr = pkt->data; - *bptr++ = 0; - *bptr++ = 0; - *bptr++ = 0; - *bptr++ = 0; + *bptr++ = 0; + *bptr++ = 0; + *bptr++ = 0; + *bptr++ = 0; - /* Write length */ + /* Write length */ - t = bptr - buffer; - pkt->len = htons(t); /* length here - code and ID + */ + t = bptr - buffer; + pkt->len = htons(t); /* length here - code and ID + */ - DEBUG1((" len %d\n",t)); + DEBUG1((" len %d\n", t)); - /* Send packet */ - /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ + /* Send packet + * Send packet ahdlc_txz(procol,header,data,headerlen,datalen); + */ - DEBUG1(("\nWriting ECHO-REQUEST frame \n")); - ahdlc_tx(ctx, LCP, 0, buffer, 0, t); - DEBUG1(("- end ECHO-REQUEST Write frame\n")); - } - } + DEBUG1(("\nWriting ECHO-REQUEST frame \n")); + ahdlc_tx(ctx, LCP, 0, buffer, 0, t); + DEBUG1(("- end ECHO-REQUEST Write frame\n")); + } + } } /**************************************************************************** @@ -484,10 +484,10 @@ void lcp_echo_request(struct ppp_context_s *ctx, u8_t *buffer) * ****************************************************************************/ -void lcp_task(struct ppp_context_s *ctx, u8_t *buffer) +void lcp_task(FAR struct ppp_context_s *ctx, FAR uint8_t * buffer) { - u8_t *bptr; - u16_t t; + FAR uint8_t *bptr; + uint16_t t; LCPPKT *pkt; /* lcp tx not up and hasn't timed out then lets see if we need to send a @@ -506,7 +506,7 @@ void lcp_task(struct ppp_context_s *ctx, u8_t *buffer) /* No pending request, lets build one */ - pkt = (LCPPKT *)buffer; + pkt = (LCPPKT *) buffer; /* Configure-Request only here, write id */ @@ -531,12 +531,11 @@ void lcp_task(struct ppp_context_s *ctx, u8_t *buffer) *bptr++ = LPC_MAGICNUMBER; *bptr++ = 0x6; - /* - *bptr++ = random_rand() & 0xff; - *bptr++ = random_rand() & 0xff; - *bptr++ = random_rand() & 0xff; - *bptr++ = random_rand() & 0xff; - */ + /* bptr++ = random_rand() & 0xff; + * bptr++ = random_rand() & 0xff; + * bptr++ = random_rand() & 0xff; + * bptr++ = random_rand() & 0xff; + */ *bptr++ = 0x11; *bptr++ = 0x11; @@ -581,12 +580,13 @@ void lcp_task(struct ppp_context_s *ctx, u8_t *buffer) /* Write length */ t = bptr - buffer; - pkt->len = htons(t); /* length here - code and ID + */ + pkt->len = htons(t); /* length here - code and ID + */ - DEBUG1((" len %d\n",t)); + DEBUG1((" len %d\n", t)); - /* Send packet */ - /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ + /* Send packet + * Send packet ahdlc_txz(procol,header,data,headerlen,datalen); + */ ahdlc_tx(ctx, LCP, 0, buffer, 0, t); @@ -598,7 +598,7 @@ void lcp_task(struct ppp_context_s *ctx, u8_t *buffer) if (ctx->lcp_retry > LCP_RETRY_COUNT) { - ctx->lcp_state &= LCP_TX_TIMEOUT; + ctx->lcp_state |= LCP_TX_TIMEOUT; } } } diff --git a/netutils/pppd/lcp.h b/netutils/pppd/lcp.h index 8344c4363..d2236ecc8 100644 --- a/netutils/pppd/lcp.h +++ b/netutils/pppd/lcp.h @@ -62,13 +62,6 @@ #define LPC_PFC 0x7 #define LPC_ACFC 0x8 -/* LCP Negotiated options flag equates */ - -#define LCP_OPT_ACCM 0x1 -#define LCP_OPT_AUTH 0x2 -#define LCP_OPT_PFC 0x4 -#define LCP_OPT_ACFC 0x4 - /* LCP state machine flags */ #define LCP_TX_UP 0x1 @@ -93,10 +86,10 @@ struct ppp_context_s; typedef struct _lcppkt { - u8_t code; - u8_t id; - u16_t len; - u8_t data[0]; + uint8_t code; + uint8_t id; + uint16_t len; + uint8_t data[0]; } LCPPKT; /**************************************************************************** @@ -112,11 +105,11 @@ extern "C" #define EXTERN extern #endif -void lcp_init(struct ppp_context_s *ctx); -void lcp_rx(struct ppp_context_s *ctx, u8_t *, u16_t); -void lcp_task(struct ppp_context_s *ctx, u8_t *buffer); -void lcp_disconnect(struct ppp_context_s *ctx, u8_t id); -void lcp_echo_request(struct ppp_context_s *ctx, u8_t *buffer); +void lcp_init(FAR struct ppp_context_s *ctx); +void lcp_rx(FAR struct ppp_context_s *ctx, FAR uint8_t *, uint16_t); +void lcp_task(FAR struct ppp_context_s *ctx, FAR uint8_t *buffer); +void lcp_disconnect(FAR struct ppp_context_s *ctx, uint8_t id); +void lcp_echo_request(FAR struct ppp_context_s *ctx); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/pppd/pap.c b/netutils/pppd/pap.c index 7ac457f12..04c7bf613 100644 --- a/netutils/pppd/pap.c +++ b/netutils/pppd/pap.c @@ -83,39 +83,41 @@ void pap_init(struct ppp_context_s *ctx) * ****************************************************************************/ -void pap_rx(struct ppp_context_s *ctx, u8_t *buffer, u16_t count) +void pap_rx(struct ppp_context_s *ctx, FAR uint8_t * buffer, uint16_t count) { - u8_t *bptr=buffer; - u8_t len; + FAR uint8_t *bptr = buffer; + uint8_t len; switch (*bptr++) - { - case CONF_REQ: - DEBUG1(("CONF REQ - only for server, no support\n")); - break; + { + case CONF_REQ: + DEBUG1(("CONF REQ - only for server, no support\n")); + break; - case CONF_ACK: /* config Ack */ - DEBUG1(("CONF ACK - PAP good - ")); + case CONF_ACK: /* config Ack */ + DEBUG1(("CONF ACK - PAP good - ")); - /* Display message if debug */ + /* Display message if debug */ - len = *bptr++; - *(bptr + len) = 0; - DEBUG1((" %s \n",bptr)); - ctx->pap_state |= PAP_TX_UP; - break; + bptr += 3; + len = *bptr++; + *(bptr + len) = 0; + DEBUG1((" %s \n", bptr)); + ctx->pap_state |= PAP_TX_UP; + break; - case CONF_NAK: - DEBUG1(("CONF NAK - Failed Auth - ")); - ctx->pap_state |= PAP_TX_AUTH_FAIL; + case CONF_NAK: + DEBUG1(("CONF NAK - Failed Auth - ")); + ctx->pap_state |= PAP_TX_AUTH_FAIL; - /* Display message if debug */ + /* Display message if debug */ - len = *bptr++; - *(bptr + len)=0; - DEBUG1((" %s \n",bptr)); - break; - } + bptr += 3; + len = *bptr++; + *(bptr + len) = 0; + DEBUG1((" %s \n", bptr)); + break; + } } /**************************************************************************** @@ -124,18 +126,18 @@ void pap_rx(struct ppp_context_s *ctx, u8_t *buffer, u16_t count) * ****************************************************************************/ -void pap_task(struct ppp_context_s *ctx, u8_t *buffer) +void pap_task(FAR struct ppp_context_s *ctx, FAR uint8_t * buffer) { - u8_t *bptr; - u16_t t; + FAR uint8_t *bptr; + uint16_t t; PAPPKT *pkt; /* If LCP is up and PAP negotiated, try to bring up PAP */ if (!(ctx->pap_state & PAP_TX_UP) && !(ctx->pap_state & PAP_TX_TIMEOUT)) { - /* Do we need to send a PAP auth packet? - Check if we have a request pending*/ + /* Do we need to send a PAP auth packet? Check if we have a request + * pending */ if ((ppp_arch_clock_seconds() - ctx->pap_prev_seconds) > PAP_TIMEOUT) { @@ -147,7 +149,7 @@ void pap_task(struct ppp_context_s *ctx, u8_t *buffer) /* Build a PAP request packet */ - pkt = (PAPPKT *)buffer; + pkt = (PAPPKT *) buffer; /* Configure-Request only here, write id */ @@ -157,26 +159,26 @@ void pap_task(struct ppp_context_s *ctx, u8_t *buffer) /* Write options */ - t = strlen((char*)ctx->settings->pap_username); + t = strlen((char *)ctx->settings->pap_username); /* Write peer length */ - *bptr++ = (u8_t)t; + *bptr++ = (uint8_t) t; bptr = memcpy(bptr, ctx->settings->pap_username, t); - t = strlen((char*)ctx->settings->pap_password); - *bptr++ = (u8_t)t; + t = strlen((char *)ctx->settings->pap_password); + *bptr++ = (uint8_t) t; bptr = memcpy(bptr, ctx->settings->pap_password, t); /* Write length */ t = bptr - buffer; - /* length here - code and ID + */ + /* length here - code and ID + */ pkt->len = htons(t); - DEBUG1((" Len %d\n",t)); + DEBUG1((" Len %d\n", t)); /* Send packet */ @@ -189,7 +191,7 @@ void pap_task(struct ppp_context_s *ctx, u8_t *buffer) if (ctx->pap_retry > PAP_RETRY_COUNT) { DEBUG1(("PAP - timout\n")); - ctx->pap_state &= PAP_TX_TIMEOUT; + ctx->pap_state |= PAP_TX_TIMEOUT; } } } diff --git a/netutils/pppd/pap.h b/netutils/pppd/pap.h index 918d1b86d..ce8ac73aa 100644 --- a/netutils/pppd/pap.h +++ b/netutils/pppd/pap.h @@ -66,7 +66,7 @@ #define PAP_RX_AUTH_FAIL 0x10 #define PAP_TX_AUTH_FAIL 0x20 -#define PAP_RX_TIMEOUT 0x80 +#define PAP_RX_TIMEOUT 0x40 #define PAP_TX_TIMEOUT 0x80 /**************************************************************************** @@ -77,10 +77,10 @@ struct ppp_context_s; typedef struct _pappkt { - u8_t code; - u8_t id; - u16_t len; - u8_t data[0]; + uint8_t code; + uint8_t id; + uint16_t len; + uint8_t data[0]; } PAPPKT; /**************************************************************************** @@ -97,9 +97,10 @@ extern "C" #endif /* Function prototypes */ -void pap_init(struct ppp_context_s *ctx); -void pap_rx(struct ppp_context_s *ctx, u8_t *, u16_t); -void pap_task(struct ppp_context_s *ctx, u8_t *buffer); + +void pap_init(FAR struct ppp_context_s *ctx); +void pap_rx(FAR struct ppp_context_s *ctx, FAR uint8_t *, uint16_t); +void pap_task(FAR struct ppp_context_s *ctx, FAR uint8_t *buffer); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/pppd/ppp.c b/netutils/pppd/ppp.c index 3b3ce2afc..8f6dc1d52 100644 --- a/netutils/pppd/ppp.c +++ b/netutils/pppd/ppp.c @@ -51,8 +51,8 @@ #include "lcp.h" #ifdef CONFIG_NETUTILS_PPPD_PAP -#include "pap.h" -#endif /* CONFIG_NETUTILS_PPPD_PAP */ +# include "pap.h" +#endif /**************************************************************************** * Pre-processor Definitions @@ -66,7 +66,7 @@ /* Set the debug message level */ -#define PACKET_RX_DEBUG 1 +#define PACKET_RX_DEBUG PPP_DEBUG /**************************************************************************** * Private Functions @@ -77,16 +77,18 @@ * ****************************************************************************/ -static void ppp_reject_protocol(struct ppp_context_s *ctx, u16_t protocol, - u8_t *buffer, u16_t count) +static void ppp_reject_protocol(FAR struct ppp_context_s *ctx, + uint16_t protocol, FAR uint8_t * buffer, + uint16_t count) { - u16_t i; - u8_t *dptr, *sptr; - LCPPKT *pkt; + uint16_t i; + FAR uint8_t *dptr; + FAR uint8_t *sptr; + FAR LCPPKT *pkt; - /* first copy rejected packet back, start from end and work forward, - +++ Pay attention to buffer management when updated. Assumes fixed - PPP blocks. */ + /* First copy rejected packet back, start from end and work forward, +++ Pay + * attention to buffer management when updated. Assumes fixed PPP blocks. + */ DEBUG1(("Rejecting Protocol\n")); if ((count + 6) > PPP_RX_BUFFER_SIZE) @@ -101,16 +103,18 @@ static void ppp_reject_protocol(struct ppp_context_s *ctx, u16_t protocol, sptr = buffer + count; for (i = 0; i < count; ++i) { - *dptr-- = *sptr--; + *--dptr = *--sptr; } - pkt = (LCPPKT *)buffer; - pkt->code = PROT_REJ; /* Write Conf_rej */ - /*pkt->id = tid++;*/ /* write tid */ - pkt->len = htons(count + 6); - *((u16_t *)(&pkt->data[0])) = htons(protocol); + pkt = (LCPPKT *) buffer; + pkt->code = PROT_REJ; /* Write Conf_rej */ - ahdlc_tx(ctx, LCP, buffer, 0, (u16_t)(count + 6), 0); + /* pkt->id = tid++; write tid */ + + pkt->len = htons(count + 6); + *((FAR uint16_t *) (&pkt->data[0])) = htons(protocol); + + ahdlc_tx(ctx, LCP, buffer, 0, (uint16_t) (count + 6), 0); } /**************************************************************************** @@ -122,19 +126,19 @@ static void ppp_reject_protocol(struct ppp_context_s *ctx, u16_t protocol, ****************************************************************************/ #if PACKET_RX_DEBUG -void dump_ppp_packet(u8_t *buffer, u16_t len) +void dump_ppp_packet(FAR uint8_t * buffer, uint16_t len) { int i; DEBUG1(("\n")); - for (i = 0;i < len; ++i) + for (i = 0; i < len; ++i) { if ((i & 0x1f) == 0x10) { DEBUG1(("\n")); } - DEBUG1(("0x%02x ",buffer[i])); + DEBUG1(("0x%02x ", buffer[i])); } DEBUG1(("\n\n")); @@ -147,18 +151,20 @@ void dump_ppp_packet(u8_t *buffer, u16_t len) * ****************************************************************************/ -void ppp_init(struct ppp_context_s *ctx) +void ppp_init(FAR struct ppp_context_s *ctx) { #ifdef PPP_STATISTICS ctx->ppp_rx_frame_count = 0; + ctx->ppp_tx_frame_count = 0; #endif ctx->ppp_flags = 0; + ctx->ppp_tx_mru = PPP_RX_BUFFER_SIZE; ctx->ip_no_data_time = 0; ctx->ppp_id = 0; #ifdef CONFIG_NETUTILS_PPPD_PAP pap_init(ctx); -#endif /* CONFIG_NETUTILS_PPPD_PAP */ +#endif ipcp_init(ctx); lcp_init(ctx); @@ -166,82 +172,11 @@ void ppp_init(struct ppp_context_s *ctx) ahdlc_rx_ready(ctx); } -/**************************************************************************** - * raise_ppp() - This routine will try to bring up a PPP connection, - * It is blocking. In the future we probably want to pass a - * structure with all the options on bringing up a PPP link, like - * server/client, DSN server, username password for PAP... +++ for - * now just use config and bit defines - * - ****************************************************************************/ - -#if 0 -u16_t ppp_raise(u8_t config, u8_t *username, u8_t *password) -{ - u16_t status = 0; - - /* Initialize PPP engine */ - /* init_ppp(); */ - - pap_init(); - ipcp_init(); - lcp_init(); - - /* Enable PPP */ - - ppp_flags = PPP_RX_READY; - - /* Try to bring up the layers */ - - while (status == 0) - { -#ifdef SYSTEM_POLLER - /* If the serial interrupt is not hooked to ahdlc_rx, or the - system needs to handle other stuff while were blocking, call - the system poller.*/ - - system_poller(); -#endif - - /* Call the lcp task to bring up the LCP layer */ - - lcp_task(ppp_tx_buffer); - - /* If LCP is up, neg next layer */ - - if (lcp_state & LCP_TX_UP) - { - /* If LCP wants PAP, try to authenticate, else bring up IPCP */ - - if ((lcp_state & LCP_RX_AUTH) && (!(pap_state & PAP_TX_UP))) - { - pap_task(ppp_tx_buffer,username,password); - } - else - { - ipcp_task(ppp_tx_buffer); - } - } - - /* If IPCP came up then our link should be up. */ - - if ((ipcp_state & IPCP_TX_UP) && (ipcp_state & IPCP_RX_UP)) - { - break; - } - - status = check_ppp_errors(); - } - - return status; -} -#endif - /**************************************************************************** * Name: ppp_connect ****************************************************************************/ -void ppp_connect(struct ppp_context_s *ctx) +void ppp_connect(FAR struct ppp_context_s *ctx) { /* Initialize PPP engine */ @@ -249,7 +184,7 @@ void ppp_connect(struct ppp_context_s *ctx) #ifdef CONFIG_NETUTILS_PPPD_PAP pap_init(ctx); -#endif /* CONFIG_NETUTILS_PPPD_PAP */ +#endif ipcp_init(ctx); lcp_init(ctx); @@ -262,7 +197,7 @@ void ppp_connect(struct ppp_context_s *ctx) * Name: ppp_send ****************************************************************************/ -void ppp_send(struct ppp_context_s *ctx) +void ppp_send(FAR struct ppp_context_s *ctx) { /* If IPCP came up then our link should be up. */ @@ -276,9 +211,9 @@ void ppp_send(struct ppp_context_s *ctx) * Name: ppp_poll ****************************************************************************/ -void ppp_poll(struct ppp_context_s *ctx) +void ppp_poll(FAR struct ppp_context_s *ctx) { - u8_t c; + uint8_t c; ctx->ip_len = 0; @@ -303,7 +238,7 @@ void ppp_poll(struct ppp_context_s *ctx) if ((ctx->ipcp_state & IPCP_TX_UP) && (ctx->ipcp_state & IPCP_RX_UP)) { - lcp_echo_request(ctx, ctx->ip_buf); + lcp_echo_request(ctx); return; } @@ -316,6 +251,7 @@ void ppp_poll(struct ppp_context_s *ctx) if ((ctx->lcp_state & LCP_TX_UP) && (ctx->lcp_state & LCP_RX_UP)) { /* If LCP wants PAP, try to authenticate, else bring up IPCP */ + #ifdef CONFIG_NETUTILS_PPPD_PAP if ((ctx->lcp_state & LCP_RX_AUTH) && (!(ctx->pap_state & PAP_TX_UP))) { @@ -328,11 +264,11 @@ void ppp_poll(struct ppp_context_s *ctx) #else if (ctx->lcp_state & LCP_RX_AUTH) { - /* lcp is asking for authentication but we do not support this. - * This should be communicated upstream but we do not have an - * interface for that right now, so just ignore it; nothing can be - * done. This also should not have been hit because upcall does - * not know about the pap message type. + /* lcp is asking for authentication but we do not support this. This + * should be communicated upstream but we do not have an interface + * for that right now, so just ignore it; nothing can be done. This + * also should not have been hit because upcall does not know about + * the pap message type. */ DEBUG1(("Asking for PAP, but we do not know PAP\n")); @@ -341,7 +277,7 @@ void ppp_poll(struct ppp_context_s *ctx) { ipcp_task(ctx, ctx->ip_buf); } -#endif /* CONFIG_NETUTILS_PPPD_PAP */ +#endif } } @@ -354,17 +290,13 @@ void ppp_poll(struct ppp_context_s *ctx) * ****************************************************************************/ -void ppp_upcall(struct ppp_context_s *ctx, u16_t protocol, u8_t *buffer, u16_t len) +void ppp_upcall(FAR struct ppp_context_s *ctx, uint16_t protocol, + FAR uint8_t * buffer, uint16_t len) { -#ifdef PPP_STATISTICS - ++ctx->ppp_rx_frame_count; - -#ifdef PPP_DEBUG +#if PPP_DEBUG dump_ppp_packet(buffer, len); #endif -#endif /* PPP_STATISTICS */ - /* Check to see if we have a packet waiting to be processed */ if (ctx->ppp_flags & PPP_RX_READY) @@ -373,27 +305,27 @@ void ppp_upcall(struct ppp_context_s *ctx, u16_t protocol, u8_t *buffer, u16_t l switch (protocol) { - case LCP: /* We must support some level of LCP */ + case LCP: /* We must support some level of LCP */ DEBUG1(("LCP Packet - ")); lcp_rx(ctx, buffer, len); DEBUG1(("\n")); break; #ifdef CONFIG_NETUTILS_PPPD_PAP - case PAP: /* PAP should be compile in optional */ + case PAP: /* PAP should be compile in optional */ DEBUG1(("PAP Packet - ")); pap_rx(ctx, buffer, len); DEBUG1(("\n")); break; -#endif /* CONFIG_NETUTILS_PPPD_PAP */ +#endif - case IPCP: /* IPCP should be compile in optional. */ + case IPCP: /* IPCP should be compile in optional. */ DEBUG1(("IPCP Packet - ")); ipcp_rx(ctx, buffer, len); DEBUG1(("\n")); break; - case IPV4: /* We must support IPV4 */ + case IPV4: /* We must support IPV4 */ DEBUG1(("IPV4 Packet---\n")); memcpy(ctx->ip_buf, buffer, len); ctx->ip_len = len; @@ -402,7 +334,7 @@ void ppp_upcall(struct ppp_context_s *ctx, u16_t protocol, u8_t *buffer, u16_t l break; default: - DEBUG1(("Unknown PPP Packet Type 0x%04x - ",protocol)); + DEBUG1(("Unknown PPP Packet Type 0x%04x - ", protocol)); ppp_reject_protocol(ctx, protocol, buffer, len); DEBUG1(("\n")); break; @@ -419,14 +351,17 @@ void ppp_upcall(struct ppp_context_s *ctx, u16_t protocol, u8_t *buffer, u16_t l * ****************************************************************************/ -u16_t scan_packet(struct ppp_context_s *ctx, u16_t protocol, const u8_t *list, - u8_t *buffer, u8_t *options, u16_t len) +uint16_t scan_packet(FAR struct ppp_context_s *ctx, uint16_t protocol, + FAR const FAR uint8_t * list, FAR uint8_t * buffer, + FAR uint8_t * options, uint16_t len) { - const u8_t *tlist; - u8_t *bptr; - u8_t *tptr; - u8_t bad = 0; - u8_t i, j, good; + FAR const FAR uint8_t *tlist; + FAR uint8_t *bptr; + FAR uint8_t *tptr; + uint8_t bad = 0; + uint8_t good; + uint8_t i; + uint8_t j; bptr = tptr = options; @@ -434,8 +369,9 @@ u16_t scan_packet(struct ppp_context_s *ctx, u16_t protocol, const u8_t *list, while (bptr < options + len) { - /* Get code and see if it matches somwhere in the list, if not - we don't support it */ + /* Get code and see if it matches somwhere in the list, if not we don't + * support it. + */ i = *bptr++; @@ -446,6 +382,7 @@ u16_t scan_packet(struct ppp_context_s *ctx, u16_t protocol, const u8_t *list, while (*tlist) { /* DEBUG2("%x ",*tlist); */ + if (i == *tlist++) { good = 1; @@ -457,7 +394,7 @@ u16_t scan_packet(struct ppp_context_s *ctx, u16_t protocol, const u8_t *list, { /* We don't understand it, write it back */ - DEBUG1(("We don't understand option 0x%02x\n",i)); + DEBUG1(("We don't understand option 0x%02x\n", i)); bad = 1; *tptr++ = i; j = *tptr++ = *bptr++; @@ -472,7 +409,7 @@ u16_t scan_packet(struct ppp_context_s *ctx, u16_t protocol, const u8_t *list, bptr += *bptr - 1; } - } + } /* Bad? if we we need to send a config Reject */ @@ -481,8 +418,8 @@ u16_t scan_packet(struct ppp_context_s *ctx, u16_t protocol, const u8_t *list, /* Write the config Rej packet we've built above, take on the header */ bptr = buffer; - *bptr++ = CONF_REJ; /* Write Conf_rej */ - bptr++; /* skip over ID */ + *bptr++ = CONF_REJ; /* Write Conf_rej */ + bptr++; /* skip over ID */ *bptr++ = 0; *bptr = tptr - buffer; @@ -491,7 +428,7 @@ u16_t scan_packet(struct ppp_context_s *ctx, u16_t protocol, const u8_t *list, /* Write the reject frame */ DEBUG1(("Writing Reject frame --\n")); - ahdlc_tx(ctx, protocol, buffer, 0, (u16_t)(tptr - buffer), 0); + ahdlc_tx(ctx, protocol, buffer, 0, (uint16_t) (tptr - buffer), 0); DEBUG1(("\nEnd writing reject \n")); } diff --git a/netutils/pppd/ppp.h b/netutils/pppd/ppp.h index 94101cd2a..d00a2859c 100644 --- a/netutils/pppd/ppp.h +++ b/netutils/pppd/ppp.h @@ -47,6 +47,8 @@ #include +#include + #include "netutils/chat.h" #include "ppp_conf.h" @@ -57,7 +59,7 @@ #ifdef CONFIG_NETUTILS_PPPD_PAP # include "pap.h" -#endif /* CONFIG_NETUTILS_PPPD_PAP */ +#endif /**************************************************************************** * Pre-processor Definitions @@ -74,7 +76,7 @@ #define PPP_ESCAPED 0x1 #define PPP_RX_READY 0x2 -#define PPP_RX_ASYNC_MAP 0x8 +#define PPP_RX_ASYNC_MAP 0x4 #define PPP_TX_ASYNC_MAP 0x8 #define PPP_PFC 0x10 #define PPP_ACFC 0x20 @@ -98,12 +100,6 @@ #define ECHO_REQ 0x9 #define ECHO_REP 0xa -/* Raise PPP config bits */ - -#define USE_PAP 0x1 -#define USE_NOACCMBUG 0x2 -#define USE_GETDNS 0x4 - /**************************************************************************** * Public Types ****************************************************************************/ @@ -114,24 +110,23 @@ struct ppp_context_s { /* IP Buffer */ - u8_t ip_buf[PPP_RX_BUFFER_SIZE]; - u16_t ip_len; + uint8_t ip_buf[PPP_RX_BUFFER_SIZE]; + uint16_t ip_len; /* Main status */ - u8_t ppp_flags; - u8_t ppp_status; - u16_t ppp_tx_mru; - u8_t ppp_id; + uint8_t ppp_flags; + uint16_t ppp_tx_mru; + uint8_t ppp_id; /* IP timeout */ - u16_t ip_no_data_time; + uint16_t ip_no_data_time; /* Interfaces */ int if_fd; - u8_t ifname[IFNAMSIZ]; + uint8_t ifname[IFNAMSIZ]; /* Addresses */ @@ -148,41 +143,40 @@ struct ppp_context_s /* LCP */ - u8_t lcp_state; - u16_t lcp_tx_mru; - u8_t lcp_retry; + uint8_t lcp_state; + uint8_t lcp_retry; time_t lcp_prev_seconds; #ifdef CONFIG_NETUTILS_PPPD_PAP /* PAP */ - u8_t pap_state; - u8_t pap_retry; + uint8_t pap_state; + uint8_t pap_retry; time_t pap_prev_seconds; #endif /* CONFIG_NETUTILS_PPPD_PAP */ /* IPCP */ - u8_t ipcp_state; - u8_t ipcp_retry; + uint8_t ipcp_state; + uint8_t ipcp_retry; time_t ipcp_prev_seconds; /* AHDLC */ - u8_t ahdlc_rx_buffer[PPP_RX_BUFFER_SIZE]; - u16_t ahdlc_tx_crc; /* Running tx CRC */ - u16_t ahdlc_rx_crc; /* Running rx CRC */ - u16_t ahdlc_rx_count; /* Number of rx bytes processed, cur frame */ - u8_t ahdlc_flags; /* ahdlc state flags, see above */ - u8_t ahdlc_tx_offline; + uint8_t ahdlc_rx_buffer[PPP_RX_BUFFER_SIZE]; + uint16_t ahdlc_tx_crc; /* Running tx CRC */ + uint16_t ahdlc_rx_crc; /* Running rx CRC */ + uint16_t ahdlc_rx_count; /* Number of rx bytes processed, cur frame */ + uint8_t ahdlc_flags; /* ahdlc state flags, see above */ + uint8_t ahdlc_tx_offline; /* Statistics counters */ #ifdef PPP_STATISTICS - u16_t ahdlc_crc_error; - u16_t ahdlc_rx_tobig_error; - u32_t ppp_rx_frame_count; - u32_t ppp_tx_frame_count; + uint16_t ahdlc_crc_error; + uint16_t ahdlc_rx_tobig_error; + uint32_t ppp_rx_frame_count; + uint32_t ppp_tx_frame_count; #endif /* Chat controls */ @@ -191,7 +185,7 @@ struct ppp_context_s /* PPPD Settings */ - struct pppd_settings_s *settings; + const struct pppd_settings_s *settings; }; /**************************************************************************** @@ -207,20 +201,19 @@ extern "C" #define EXTERN extern #endif -/* - * Function Prototypes - */ -void ppp_init(struct ppp_context_s *ctx); -void ppp_connect(struct ppp_context_s *ctx); +void ppp_init(FAR struct ppp_context_s *ctx); +void ppp_connect(FAR struct ppp_context_s *ctx); -extern void ppp_reconnect(struct ppp_context_s *ctx); +extern void ppp_reconnect(FAR struct ppp_context_s *ctx); -void ppp_send(struct ppp_context_s *ctx); -void ppp_poll(struct ppp_context_s *ctx); +void ppp_send(FAR struct ppp_context_s *ctx); +void ppp_poll(FAR struct ppp_context_s *ctx); -void ppp_upcall(struct ppp_context_s *ctx, u16_t, u8_t *, u16_t); -u16_t scan_packet(struct ppp_context_s *ctx, u16_t, const u8_t *list, - u8_t *buffer, u8_t *options, u16_t len); +void ppp_upcall(FAR struct ppp_context_s *ctx, uint16_t, + FAR uint8_t *, uint16_t); +uint16_t scan_packet(FAR struct ppp_context_s *ctx, uint16_t, + FAR const uint8_t *list, FAR uint8_t *buffer, + FAR uint8_t *options, uint16_t len); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/pppd/ppp_arch.h b/netutils/pppd/ppp_arch.h index 55e075d99..8f83efe68 100644 --- a/netutils/pppd/ppp_arch.h +++ b/netutils/pppd/ppp_arch.h @@ -1,5 +1,5 @@ /**************************************************************************** - * netutils/pppd/pppd.c + * netutils/pppd/ppp_arch.h * * Copyright (C) 2015 Max Nekludov. All rights reserved. * Author: Max Nekludov @@ -62,10 +62,6 @@ struct ppp_context_s; -typedef uint8_t u8_t; -typedef uint16_t u16_t; -typedef uint32_t u32_t; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -81,8 +77,8 @@ extern "C" time_t ppp_arch_clock_seconds(void); -int ppp_arch_getchar(struct ppp_context_s *ctx, u8_t *p); -int ppp_arch_putchar(struct ppp_context_s *ctx, u8_t c); +int ppp_arch_getchar(FAR struct ppp_context_s *ctx, FAR uint8_t *p); +int ppp_arch_putchar(FAR struct ppp_context_s *ctx, uint8_t c); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/pppd/ppp_conf.h b/netutils/pppd/ppp_conf.h index 27f646772..842d33f97 100644 --- a/netutils/pppd/ppp_conf.h +++ b/netutils/pppd/ppp_conf.h @@ -1,5 +1,5 @@ /**************************************************************************** - * netutils/pppd/ppp-conf.c + * netutils/pppd/ppp_conf.h * * Copyright (C) 2015 Max Nekludov. All rights reserved. * Author: Max Nekludov @@ -53,21 +53,16 @@ #define PPP_IP_TIMEOUT (6*3600) #define PPP_MAX_CONNECT 15 -#define PAP_USERNAME_SIZE 16 -#define PAP_PASSWORD_SIZE 16 - -#define xxdebug_printf printf -#define debug_printf printf +#define xxdebug_printf ninfo +#define debug_printf ninfo #define PPP_RX_BUFFER_SIZE 1024 //1024 //GD 2048 for 1280 IPv6 MTU -#define PPP_TX_BUFFER_SIZE 64 #define AHDLC_TX_OFFLINE 5 -//#define AHDLC_COUNTERS 1 //defined for AHDLC stats support, Guillaume Descamps, September 19th, 2011 #define IPCP_GET_PEER_IP 1 #define PPP_STATISTICS 1 -#define PPP_DEBUG 1 +#define PPP_DEBUG defined(CONFIG_DEBUG_NET_INFO) #endif /* __APPS_NETUTILS_PPPD_PPP_CONF_H */ diff --git a/netutils/pppd/pppd.c b/netutils/pppd/pppd.c index 97456711d..b9e5d9415 100644 --- a/netutils/pppd/pppd.c +++ b/netutils/pppd/pppd.c @@ -63,7 +63,7 @@ #include "netutils/pppd.h" /**************************************************************************** - * Extenal Functions + * External Functions ****************************************************************************/ #ifdef PPP_ARCH_HAVE_MODEM_RESET @@ -110,7 +110,7 @@ static int tun_alloc(char *dev) return fd; } - printf("tun fd:%i\n", fd); + debug_printf("tun fd:%i\n", fd); if ((errcode = make_nonblock(fd)) < 0) { @@ -140,7 +140,7 @@ static int tun_alloc(char *dev) * Name: open_tty ****************************************************************************/ -static int open_tty(char *dev) +static int open_tty(const char *dev) { int fd; int errcode; @@ -156,7 +156,7 @@ static int open_tty(char *dev) return errcode; } - printf("tty fd:%i\n", fd); + debug_printf("tty fd:%i\n", fd); return fd; } @@ -165,9 +165,9 @@ static int open_tty(char *dev) * Name: ppp_check_errors ****************************************************************************/ -static u8_t ppp_check_errors(struct ppp_context_s *ctx) +static uint8_t ppp_check_errors(FAR struct ppp_context_s *ctx) { - u8_t ret = 0; + uint8_t ret = 0; /* Check Errors */ @@ -182,7 +182,7 @@ static u8_t ppp_check_errors(struct ppp_context_s *ctx) { ret = 2; } -#endif /* CONFIG_NETUTILS_PPPD_PAP */ +#endif if (ctx->ipcp_state & (IPCP_TX_TIMEOUT)) { @@ -200,12 +200,12 @@ static u8_t ppp_check_errors(struct ppp_context_s *ctx) * Name: ppp_reconnect ****************************************************************************/ -void ppp_reconnect(struct ppp_context_s *ctx) +void ppp_reconnect(FAR struct ppp_context_s *ctx) { int ret; int retry = PPP_MAX_CONNECT; - struct pppd_settings_s *pppd_settings = ctx->settings; - netlib_ifdown((char*)ctx->ifname); + const struct pppd_settings_s *pppd_settings = ctx->settings; + netlib_ifdown((char *)ctx->ifname); lcp_disconnect(ctx, ++ctx->ppp_id); sleep(1); @@ -220,7 +220,7 @@ void ppp_reconnect(struct ppp_context_s *ctx) ret = chat(&ctx->ctl, pppd_settings->disconnect_script); if (ret < 0) { - printf("ppp: disconnect script failed\n"); + debug_printf("ppp: disconnect script failed\n"); } } @@ -231,7 +231,7 @@ void ppp_reconnect(struct ppp_context_s *ctx) ret = chat(&ctx->ctl, pppd_settings->connect_script); if (ret < 0) { - printf("ppp: connect script failed\n"); + debug_printf("ppp: connect script failed\n"); --retry; if (retry == 0) { @@ -276,7 +276,7 @@ time_t ppp_arch_clock_seconds(void) * Name: ppp_arch_getchar ****************************************************************************/ -int ppp_arch_getchar(struct ppp_context_s *ctx, u8_t *c) +int ppp_arch_getchar(FAR struct ppp_context_s *ctx, FAR uint8_t * c) { int ret; @@ -288,7 +288,7 @@ int ppp_arch_getchar(struct ppp_context_s *ctx, u8_t *c) * Name: ppp_arch_putchar ****************************************************************************/ -int ppp_arch_putchar(struct ppp_context_s *ctx, u8_t c) +int ppp_arch_putchar(FAR struct ppp_context_s *ctx, uint8_t c) { int ret; struct pollfd fds; @@ -314,18 +314,18 @@ int ppp_arch_putchar(struct ppp_context_s *ctx, u8_t c) * Name: pppd ****************************************************************************/ -int pppd(struct pppd_settings_s *pppd_settings) +int pppd(const struct pppd_settings_s *pppd_settings) { struct pollfd fds[2]; int ret; - struct ppp_context_s *ctx; + FAR struct ppp_context_s *ctx; - ctx = (struct ppp_context_s*)malloc(sizeof(struct ppp_context_s)); + ctx = (struct ppp_context_s *)malloc(sizeof(struct ppp_context_s)); memset(ctx, 0, sizeof(struct ppp_context_s)); - strcpy((char*)ctx->ifname, "ppp%d"); + strcpy((char *)ctx->ifname, "ppp%d"); ctx->settings = pppd_settings; - ctx->if_fd = tun_alloc((char*)ctx->ifname); + ctx->if_fd = tun_alloc((char *)ctx->ifname); if (ctx->if_fd < 0) { free(ctx); @@ -335,12 +335,12 @@ int pppd(struct pppd_settings_s *pppd_settings) ctx->ctl.fd = open_tty(pppd_settings->ttyname); if (ctx->ctl.fd < 0) { - close(ctx->ctl.fd); + close(ctx->if_fd); free(ctx); return 2; } - ctx->ctl.echo = true; + ctx->ctl.echo = true; ctx->ctl.verbose = true; ctx->ctl.timeout = 30; @@ -362,7 +362,7 @@ int pppd(struct pppd_settings_s *pppd_settings) if (ret > 0 && fds[0].revents & POLLIN) { ret = read(ctx->if_fd, ctx->ip_buf, PPP_RX_BUFFER_SIZE); - printf("read from tun :%i\n", ret); + debug_printf("read from tun :%i\n", ret); if (ret > 0) { ctx->ip_len = ret;