Mercurial > ecos-v3_0-branch
changeset 1694:5629b7c30ed2
Various patches from Matt Jerdonek and Oyvind Harboe:
* cdl/ppp.cdl:
* src/ipcp.c:
Add option to disallow negotiation of old-style VJ compression
* include/ppp.h:
Add structure to track ppp failure reasons
* include/pppd.h:
Fix compiler warning
* src/auth.c:
* src/lcp.c:
* src/pppd.c:
Add code to track ppp failure reasons
* src/chat.c:
Fixes to clear out buffer space to allow chat script to run
multiple times. Note: function is still not thread-safe
* src/sys-ecos.c:
Reset carrier detected bit when carrier lost
Reset ppp_tty control block when PPP started
* tests/windows_telnet.c:
* cdl/ppp.cdl:
Added windows_telnet example application. Connects to Windows PPP
server and waits for a telnet session.
| author | nickg |
|---|---|
| date | Fri, 23 Jul 2004 11:00:40 +0000 |
| parents | 9f18943c887e |
| children | 9cfc85f8523f |
| files | packages/net/ppp/current/ChangeLog packages/net/ppp/current/cdl/ppp.cdl packages/net/ppp/current/include/ppp.h packages/net/ppp/current/include/pppd.h packages/net/ppp/current/src/auth.c packages/net/ppp/current/src/chat.c packages/net/ppp/current/src/ipcp.c packages/net/ppp/current/src/lcp.c packages/net/ppp/current/src/pppd.c packages/net/ppp/current/src/sys-ecos.c packages/net/ppp/current/tests/windows_telnet.c |
| diffstat | 11 files changed, 265 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/net/ppp/current/ChangeLog +++ b/packages/net/ppp/current/ChangeLog @@ -1,3 +1,30 @@ +2004-06-29 Matt Jerdonek <maj1224@yahoo.com> + + * cdl/ppp.cdl: + * src/ipcp.c: + Add option to disallow negotiation of old-style VJ compression + * include/ppp.h: + Add structure to track ppp failure reasons + * include/pppd.h: + Fix compiler warning + * src/auth.c: + * src/lcp.c: + * src/pppd.c: + Add code to track ppp failure reasons + * src/chat.c: + Fixes to clear out buffer space to allow chat script to run + multiple times. Note: function is still not thread-safe + * src/sys-ecos.c: + Reset carrier detected bit when carrier lost + Reset ppp_tty control block when PPP started + +2004-06-24 Oyvind Harboe <oyvind.harboe@zylin.com> + + * tests/windows_telnet.c: + * cdl/ppp.cdl: + Added windows_telnet example application. Connects to Windows PPP + server and waits for a telnet session. + 2004-05-06 Mark Retallack <mark.retallack@siemens.com> * src/ppp_io.c:
--- a/packages/net/ppp/current/cdl/ppp.cdl +++ b/packages/net/ppp/current/cdl/ppp.cdl @@ -162,8 +162,8 @@ cdl_package CYGPKG_PPP { default_value 0 description "This component provides control over PPP compression features. WARNING: at - present there are problems with this, and - the compression code needs to allocate large + present there are problems with BSD and ZLIB, + and the compression code needs to allocate large amounts of memory. Hence this is all currently disabled." @@ -183,6 +183,16 @@ cdl_package CYGPKG_PPP { compression into the PPP protocol." } + cdl_option PPP_INHIBIT_OLD_VJ_COMPRESSION { + display "Inhibit older-style VJ compression" + flavor bool + default_value 0 + description "This option prevents the IPCP state machine + from negotiating the pre-RFC1332 Van Jacobson + compression. Checking this option could + improve IPCP negotiation time at the expense + of compatibility." + } } cdl_component CYGPKG_PPP_CHAT { @@ -310,6 +320,19 @@ cdl_package CYGPKG_PPP { tests will execute." } } + cdl_option CYGBLD_PPP_WINDOWS_TELNET_APP { + display "Build complete eCos PPP client interfacing to Windows PPP server" + default_value 0 + make -priority 320 { + <PREFIX>/bin/windows_telnet.elf : $(PREFIX)/lib/target.ld $(PREFIX)/lib/vectors.o $(PREFIX)/lib/libtarget.a $(PREFIX)/lib/libextras.a $(REPOSITORY)/$(PACKAGE)/tests/windows_telnet.c + @sh -c "mkdir -p $(dir $@)" + $(CC) -c $(INCLUDE_PATH) $(CFLAGS) -o $(PREFIX)/lib/windows_telnet.o $(REPOSITORY)/$(PACKAGE)/tests/windows_telnet.c + $(CC) $(LDFLAGS) -L$(PREFIX)/lib -Ttarget.ld -o $@ $(PREFIX)/lib/windows_telnet.o + $(OBJCOPY) -O binary $@ $(PREFIX)/bin/windows_telnet.bin + } + + } + } # EOF ppp.cdl
--- a/packages/net/ppp/current/include/ppp.h +++ b/packages/net/ppp/current/include/ppp.h @@ -71,6 +71,20 @@ typedef CYG_ADDRWORD cyg_ppp_handle_t; // ------------------------------------------------------------------------- +/* PPP statistics */ + +typedef struct { + int auth_failures; /* PAP or CHAP failures */ + int no_proto; /* No network protocol running */ + int idle_timeout; /* Idle timer expired */ + int connect_time_expired; /* Max connect time expired */ + int loopback; /* Loopback detected */ + int no_response; /* Peer not responding */ +} cyg_ppp_stats_t; + +extern cyg_ppp_stats_t cyg_ppp_stats; /* PPP statistics */ + +// ------------------------------------------------------------------------- typedef struct {
--- a/packages/net/ppp/current/include/pppd.h +++ b/packages/net/ppp/current/include/pppd.h @@ -85,6 +85,7 @@ #include <sys/types.h> /* for u_int32_t, if defined */ #include <sys/time.h> /* for struct timeval */ #include <cyg/ppp/net/ppp_defs.h> +#include <cyg/ppp/ppp.h> #if __STDC__ #include <stdarg.h> @@ -376,6 +377,7 @@ int getword __P((FILE *f, char *word, i void option_error __P((char *fmt, ...)); /* Print an error message about an option */ int setipaddr __P((char *)); /* set IP addresses */ +int gettimeofday __P((struct timeval *tv, struct timezone *tz)); /*
--- a/packages/net/ppp/current/src/auth.c +++ b/packages/net/ppp/current/src/auth.c @@ -283,6 +283,7 @@ link_established(unit) if (!wo->neg_upap || !null_login(unit)) { syslog(LOG_WARNING, "peer refused to authenticate"); lcp_close(unit, "peer refused to authenticate"); + cyg_ppp_stats.auth_failures++; return; } } @@ -344,9 +345,11 @@ network_phase(unit) ++num_np_open; } - if (num_np_open == 0) + if (num_np_open == 0) { /* nothing to do */ lcp_close(0, "No network protocols running"); + cyg_ppp_stats.no_proto++; + } } /* @@ -360,6 +363,7 @@ auth_peer_fail(unit, protocol) * Authentication failure: take the link down */ lcp_close(unit, "Authentication failed"); + cyg_ppp_stats.auth_failures++; } /* @@ -422,6 +426,7 @@ auth_withpeer_fail(unit, protocol) * He'll probably take the link down, and there's not much * we can do except wait for that. */ + cyg_ppp_stats.auth_failures++; } /* @@ -512,6 +517,7 @@ np_finished(unit, proto) if (--num_np_open <= 0) { /* no further use for the link: shut up shop. */ lcp_close(0, "No network protocols running"); + cyg_ppp_stats.no_proto++; } } @@ -533,6 +539,7 @@ check_idle(arg) /* link is idle: shut it down. */ syslog(LOG_INFO, "Terminating connection due to lack of activity."); lcp_close(0, "Link inactive"); + cyg_ppp_stats.idle_timeout++; } else { TIMEOUT(check_idle, NULL, idle_time_limit - itime); } @@ -547,6 +554,7 @@ connect_time_expired(arg) { syslog(LOG_INFO, "Connect time expired"); lcp_close(0, "Connect time expired"); /* Close connection */ + cyg_ppp_stats.connect_time_expired++; } /*
--- a/packages/net/ppp/current/src/chat.c +++ b/packages/net/ppp/current/src/chat.c @@ -111,7 +111,7 @@ static cyg_handle_t cyg_ppp_chat_thread; static cyg_io_handle_t cyg_ppp_chat_handle; // String buffers -static char cyg_ppp_chat_buffer[CHAT_STRING_LENGTH]; +char cyg_ppp_chat_buffer[CHAT_STRING_LENGTH]; static char cyg_ppp_chat_expect_buffer[CHAT_STRING_LENGTH]; //===================================================================== @@ -365,16 +365,26 @@ externC cyg_int32 cyg_ppp_chat( const ch const char *s; Cyg_ErrNo err; cyg_int32 result = 1; + cyg_uint32 zero = 0; + cyg_uint32 len = sizeof(zero); cyg_ppp_chat_thread = cyg_thread_self(); cyg_ppp_chat_abort_count = 0; cyg_ppp_chat_timeout = 45; + // Clear the result area + memset(cyg_ppp_chat_buffer, 0, CHAT_STRING_LENGTH); + while ((err = cyg_io_lookup(devname, &cyg_ppp_chat_handle)) < 0) { if (err != 0) syslog(LOG_ERR, "Failed to open %s: %d", devname,err); } + // Flush the serial input before starting + cyg_io_get_config( cyg_ppp_chat_handle, + CYG_IO_GET_CONFIG_SERIAL_INPUT_FLUSH, + &zero, &len); + // Set up timeout alarm. cyg_alarm_create( cyg_real_time_clock(), chat_alarm, @@ -433,16 +443,10 @@ externC cyg_int32 cyg_ppp_chat( const ch } // Finally, wait for the serial device to drain - { - cyg_uint32 zero = 0; - cyg_uint32 len = sizeof(zero); - cyg_io_get_config( cyg_ppp_chat_handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, &zero, &len); - } - return result; }
--- a/packages/net/ppp/current/src/ipcp.c +++ b/packages/net/ppp/current/src/ipcp.c @@ -83,6 +83,7 @@ #include <sys/socket.h> #include <netinet/in.h> +#include <pkgconf/ppp.h> #include "cyg/ppp/pppd.h" #include "cyg/ppp/fsm.h" #include "cyg/ppp/ipcp.h" @@ -363,8 +364,10 @@ ipcp_cilen(f) if (wo->neg_vj && !go->neg_vj && !go->old_vj) { /* try an older style of VJ negotiation */ if (cis_received[f->unit] == 0) { +#ifndef PPP_INHIBIT_OLD_VJ_COMPRESSION /* keep trying the new style until we see some CI from the peer */ go->neg_vj = 1; +#endif } else { /* use the old style only if the peer did */ if (ho->neg_vj && ho->old_vj) {
--- a/packages/net/ppp/current/src/lcp.c +++ b/packages/net/ppp/current/src/lcp.c @@ -1018,6 +1018,7 @@ lcp_nakci(f, p, len) if (++try.numloops >= lcp_loopbackfail) { syslog(LOG_NOTICE, "Serial line is looped back."); lcp_close(f->unit, "Loopback detected"); + cyg_ppp_stats.loopback++; } } else try.numloops = 0; @@ -1778,6 +1779,7 @@ void LcpLinkFailure (f) syslog(LOG_INFO, "No response to %d echo-requests", lcp_echos_pending); syslog(LOG_NOTICE, "Serial link appears to be disconnected."); lcp_close(f->unit, "Peer not responding"); + cyg_ppp_stats.no_response++; } }
--- a/packages/net/ppp/current/src/pppd.c +++ b/packages/net/ppp/current/src/pppd.c @@ -193,6 +193,7 @@ u_char outpacket_buf[PPP_MRU+PPP_HDRLEN] u_char inpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for incoming packet */ char *no_ppp_msg = "Sorry - this system lacks PPP kernel support\n"; +cyg_ppp_stats_t cyg_ppp_stats; /* Prototypes for procedures local to this file. */
--- a/packages/net/ppp/current/src/sys-ecos.c +++ b/packages/net/ppp/current/src/sys-ecos.c @@ -538,6 +538,7 @@ void cyg_ppp_serial_callback( cyg_serial if( s->value == 0 ) { // CD lost + ppp_tty.carrier_detected = 0; kill_link = 1; cyg_thread_release( ppp_tty.pppd_thread ); ppp_tty.pppd_wakeup = 1; @@ -1692,6 +1693,9 @@ externC cyg_ppp_handle_t cyg_ppp_up( con if( options == NULL || phase != PHASE_DEAD ) return 0; + // Initialize control block + memset(&ppp_tty, 0, sizeof(struct tty)); + strncpy( devnam, devnam_arg, PATH_MAX ); ppp_tty.options = options;
new file mode 100644 --- /dev/null +++ b/packages/net/ppp/current/tests/windows_telnet.c @@ -0,0 +1,167 @@ +//========================================================================== +// +// tests/windows_telnet.c +// +// Test program showing how to create a client that dials into +// a Windows PPP server and waits for a telnet session. +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Portions created by Nick Garnett are +// Copyright (C) 2003 eCosCentric Ltd. +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//####BSDCOPYRIGHTBEGIN#### +// +// ------------------------------------------- +// +// Portions of this software may have been derived from OpenBSD, +// FreeBSD or other sources, and are covered by the appropriate +// copyright disclaimers included herein. +// +// ------------------------------------------- +// +//####BSDCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): oyvind +// Contributors: oyvind harboe +// Date: 2004-06-24 +// Purpose: +// Description: Example/test on how to connect to a Windows PPP server +// +// +//####DESCRIPTIONEND#### +// +//========================================================================== + + +#include <pkgconf/system.h> +#include <pkgconf/net.h> +#include <network.h> +#include <cyg/ppp/ppp.h> + +static char *windows_script[] = +{ + "", "CLIENTCLIENT\\c", + "CLIENTSERVER", "\\c", + 0 +}; + +void telnet(void) +{ + struct sockaddr_in sin; + struct sockaddr_in pin; + + /* get an internet domain socket */ + int sd; + if ((sd = socket(AF_INET, SOCK_STREAM, 0)) != -1) + { + /* complete the socket structure */ + memset(&sin, 0, sizeof(sin)); + sin.sin_len = sizeof(sin); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + sin.sin_port = htons(23); + + /* bind the socket to the port number */ + if (bind(sd, (struct sockaddr *) &sin, sizeof(sin)) != -1) + { + /* show that we are willing to listen */ + if (listen(sd, SOMAXCONN) != -1) + { + int sd_current; + /* wait for a client to talk to us */ + socklen_t addrlen = sizeof(pin); + if ((sd_current = accept(sd, (struct sockaddr *) &pin, &addrlen)) != -1) + { + for (;;) + { + /* get a message from the client */ + + char t[256]; + int len; + len=recv(sd_current, t, sizeof(t)-1, 0); + if (len == -1) + { + break; + } + + if (send(sd_current, t, len, 0)!=len) + { + break; + } + } + /* close up both sockets */ + close(sd_current); + } + } + } + close(sd); + } +} + + +int main(int argc, char **argv) +{ + cyg_ppp_options_t options; + cyg_ppp_handle_t ppp_handle; + + // Bring up the TCP/IP network + init_all_network_interfaces(); + + // Initialize the options + cyg_ppp_options_init( &options ); + + options.script=windows_script; + options.baud = CYGNUM_SERIAL_BAUD_38400; + options.flowctl = CYG_PPP_FLOWCTL_NONE; + + // Start up PPP + ppp_handle = cyg_ppp_up( "/dev/ser0", &options ); + + // Wait for it to get running + if( cyg_ppp_wait_up( ppp_handle ) == 0 ) + { + // Make use of PPP + for (;;) + { + telnet(); + } + + // never reached, but for illustration: + + // Bring PPP link down + cyg_ppp_down( ppp_handle ); + + // Wait for connection to go down. + cyg_ppp_wait_down( ppp_handle ); + } +}
