mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-06-11 09:29:40 +00:00
Added PPP support to unix port. Works over serial or pseudo-tty, talking
to the host's pppd.
This commit is contained in:
parent
01c8eeed90
commit
751297c61b
|
@ -28,6 +28,10 @@
|
|||
#include <sys/signal.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if PPP_SUPPORT
|
||||
#include <pty.h>
|
||||
#endif
|
||||
|
||||
/*#define BAUDRATE B19200 */
|
||||
/*#define BAUDRATE B57600 */
|
||||
#define BAUDRATE B115200
|
||||
|
@ -51,8 +55,9 @@
|
|||
/* } siostruct_t; */
|
||||
|
||||
/** array of ((siostruct*)netif->state)->sio structs */
|
||||
static sio_status_t statusar[2];
|
||||
static sio_status_t statusar[3];
|
||||
|
||||
#if ! PPP_SUPPORT
|
||||
/* --private-functions----------------------------------------------------------------- */
|
||||
/**
|
||||
* Signal handler for ttyXX0 to indicate bytes received
|
||||
|
@ -60,7 +65,7 @@ static sio_status_t statusar[2];
|
|||
*/
|
||||
static void signal_handler_IO_0( int status )
|
||||
{
|
||||
LWIP_DEBUGF(SIO_DEBUG, ("SigHand: rxSignal chanel 0"));
|
||||
LWIP_DEBUGF(SIO_DEBUG, ("SigHand: rxSignal channel 0\n"));
|
||||
fifoPut( &statusar[0].myfifo, statusar[0].fd );
|
||||
}
|
||||
|
||||
|
@ -70,9 +75,10 @@ static void signal_handler_IO_0( int status )
|
|||
*/
|
||||
static void signal_handler_IO_1( int status )
|
||||
{
|
||||
LWIP_DEBUGF(SIO_DEBUG, ("SigHand: rxSignal channel 1"));
|
||||
LWIP_DEBUGF(SIO_DEBUG, ("SigHand: rxSignal channel 1\n"));
|
||||
fifoPut( &statusar[1].myfifo, statusar[1].fd );
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initiation of serial device
|
||||
|
@ -83,10 +89,12 @@ static void signal_handler_IO_1( int status )
|
|||
static int sio_init( char * device, int devnum, sio_status_t * siostat )
|
||||
{
|
||||
struct termios oldtio,newtio;
|
||||
#if ! PPP_SUPPORT
|
||||
struct sigaction saio; /* definition of signal action */
|
||||
#endif
|
||||
int fd;
|
||||
|
||||
/* open the device to be non-blocking (read will return immediatly) */
|
||||
/* open the device to be non-blocking (read will return immediately) */
|
||||
fd = open( device, O_RDWR | O_NOCTTY | O_NONBLOCK );
|
||||
if ( fd < 0 )
|
||||
{
|
||||
|
@ -94,19 +102,20 @@ static int sio_init( char * device, int devnum, sio_status_t * siostat )
|
|||
exit( -1 );
|
||||
}
|
||||
|
||||
#if ! PPP_SUPPORT
|
||||
/* install the signal handler before making the device asynchronous */
|
||||
switch ( devnum )
|
||||
{
|
||||
case 0:
|
||||
LWIP_DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_0\r\n") );
|
||||
LWIP_DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_0\n") );
|
||||
saio.sa_handler = signal_handler_IO_0;
|
||||
break;
|
||||
case 1:
|
||||
LWIP_DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_1\r\n") );
|
||||
LWIP_DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_1\n") );
|
||||
saio.sa_handler = signal_handler_IO_1;
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF( SIO_DEBUG,("sioinit, devnum not allowed\r\n") );
|
||||
LWIP_DEBUGF( SIO_DEBUG,("sioinit, devnum not allowed\n") );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -121,11 +130,14 @@ static int sio_init( char * device, int devnum, sio_status_t * siostat )
|
|||
/* Make the file descriptor asynchronous (the manual page says only
|
||||
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
|
||||
fcntl( fd, F_SETFL, FASYNC );
|
||||
#else
|
||||
fcntl( fd, F_SETFL, 0 );
|
||||
#endif /* ! PPP_SUPPORT */
|
||||
|
||||
tcgetattr( fd,&oldtio ); /* save current port settings */
|
||||
/* set new port settings */
|
||||
/* see 'man termios' for further settings */
|
||||
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD; /* | CRTSCTS; */
|
||||
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD | CRTSCTS;
|
||||
newtio.c_iflag = 0;
|
||||
newtio.c_oflag = 0;
|
||||
newtio.c_lflag = 0; /*ECHO; */
|
||||
|
@ -178,7 +190,7 @@ void sio_send( u8_t c, sio_status_t * siostat )
|
|||
|
||||
if ( write( siostat->fd, &c, 1 ) <= 0 )
|
||||
{
|
||||
LWIP_DEBUGF( SIO_DEBUG,("sio_send: write refused") );
|
||||
LWIP_DEBUGF( SIO_DEBUG,("sio_send: write refused\n") );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,9 +201,9 @@ void sio_send_string( u8_t *str, sio_status_t * siostat )
|
|||
|
||||
if ( write( siostat->fd, str, len ) <= 0 )
|
||||
{
|
||||
LWIP_DEBUGF( SIO_DEBUG,("sio_send_string: write refused") );
|
||||
LWIP_DEBUGF( SIO_DEBUG,("sio_send_string: write refused\n") );
|
||||
}
|
||||
LWIP_DEBUGF( (PPP_DEBUG | SIO_DEBUG),("sent:%s",str ) );
|
||||
LWIP_DEBUGF( (PPP_DEBUG | SIO_DEBUG),("sent:%s\n",str ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,6 +214,7 @@ void sio_flush( sio_status_t * siostat )
|
|||
}
|
||||
|
||||
|
||||
#if ! PPP_SUPPORT
|
||||
/*u8_t sio_recv( struct netif * netif )*/
|
||||
u8_t sio_recv( sio_status_t * siostat )
|
||||
{
|
||||
|
@ -243,7 +256,24 @@ void sio_expect_string( u8_t *str, sio_status_t * siostat )
|
|||
}
|
||||
LWIP_DEBUGF( (PPP_DEBUG | SIO_DEBUG), ("[match]\n") );
|
||||
}
|
||||
#endif /* ! PPP_SUPPORT */
|
||||
|
||||
#if PPP_SUPPORT
|
||||
u32_t sio_write(sio_status_t * siostat, u8_t *buf, u32_t size)
|
||||
{
|
||||
return write( siostat->fd, buf, size );
|
||||
}
|
||||
|
||||
u32_t sio_read(sio_status_t * siostat, u8_t *buf, u32_t size)
|
||||
{
|
||||
return read( siostat->fd, buf, size );
|
||||
}
|
||||
|
||||
void sio_read_abort(sio_status_t * siostat)
|
||||
{
|
||||
printf("sio_read_abort: not yet implemented for unix\n");
|
||||
}
|
||||
#endif /* PPP_SUPPORT */
|
||||
|
||||
sio_status_t * sio_open( int devnum )
|
||||
{
|
||||
|
@ -261,7 +291,9 @@ sio_status_t * sio_open( int devnum )
|
|||
|
||||
/* ((sio_status_t*)(tmp->sio))->fd = 0; */
|
||||
|
||||
#if ! PPP_SUPPORT
|
||||
fifoInit( &siostate->myfifo );
|
||||
#endif /* ! PPP_SUPPORT */
|
||||
|
||||
sprintf( dev, "/dev/ttyS%d", devnum );
|
||||
|
||||
|
@ -269,14 +301,39 @@ sio_status_t * sio_open( int devnum )
|
|||
{
|
||||
if ( ( siostate->fd = sio_init( dev, devnum, siostate ) ) == 0 )
|
||||
{
|
||||
LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: ERROR opening serial device" ));
|
||||
LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: ERROR opening serial device\n" ));
|
||||
abort( );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#if PPP_SUPPORT
|
||||
else if (devnum == 2) {
|
||||
pid_t childpid;
|
||||
childpid = forkpty(&siostate->fd, NULL, NULL, NULL);
|
||||
if(childpid < 0) {
|
||||
perror("forkpty");
|
||||
exit (1);
|
||||
}
|
||||
if(childpid == 0) {
|
||||
execl("/usr/sbin/pppd", "pppd",
|
||||
"ms-dns", "198.168.100.7",
|
||||
"local", "silent", "crtscts",
|
||||
"noauth", "nodetach",
|
||||
"mru", "1524",
|
||||
"mtu", "1500",
|
||||
"192.168.1.1:192.168.1.2",
|
||||
NULL);
|
||||
perror("execl pppd");
|
||||
exit (1);
|
||||
} else {
|
||||
LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: spawned pppd pid %d\n", childpid));
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: device %s (%d) is not supported", dev, devnum ));
|
||||
LWIP_DEBUGF(SIO_DEBUG, ( "sio_open: device %s (%d) is not supported\n", dev, devnum ));
|
||||
return NULL;
|
||||
}
|
||||
LWIP_DEBUGF( 1,("sio_open: dev=%s open.\n", dev ));
|
||||
|
@ -312,7 +369,7 @@ void sio_change_baud( sioBaudrates baud, sio_status_t * siostat )
|
|||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF( 1,("sio_change_baud: Unknown baudrate, code:%d", baud ));
|
||||
LWIP_DEBUGF( 1,("sio_change_baud: Unknown baudrate, code:%d\n", baud ));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ CC=gcc
|
|||
#To compile for cygwin: make ARCH=cygwin
|
||||
ARCH=unix
|
||||
CFLAGS=-g -Wall -D$(ARCH) -DIPv4 -DLWIP_DEBUG -pedantic
|
||||
LDFLAGS=-lpcap
|
||||
LDFLAGS=-lpcap -lutil
|
||||
CONTRIBDIR=../../../..
|
||||
LWIPARCH=$(CONTRIBDIR)/ports/unix
|
||||
ARFLAGS=rs
|
||||
|
@ -46,8 +46,9 @@ ARFLAGS=rs
|
|||
LWIPDIR=$(CONTRIBDIR)/../lwip/src
|
||||
|
||||
CFLAGS:=$(CFLAGS) \
|
||||
-Iapps -I. \
|
||||
-I$(LWIPDIR)/include -I$(LWIPARCH)/include -I$(LWIPDIR)/include/ipv4 \
|
||||
-Iapps -I.
|
||||
-I$(LWIPDIR)
|
||||
|
||||
# COREFILES, CORE4FILES: The minimum set of files needed for lwIP.
|
||||
COREFILES=$(LWIPDIR)/core/mem.c $(LWIPDIR)/core/memp.c $(LWIPDIR)/core/netif.c \
|
||||
|
@ -65,6 +66,15 @@ APIFILES=$(LWIPDIR)/api/api_lib.c $(LWIPDIR)/api/api_msg.c $(LWIPDIR)/api/tcpip.
|
|||
NETIFFILES=$(LWIPDIR)/netif/loopif.c \
|
||||
$(LWIPDIR)/netif/etharp.c $(LWIPDIR)/netif/slipif.c
|
||||
|
||||
# NETIFFILES: Add PPP netif
|
||||
NETIFFILES+=$(LWIPDIR)/netif/ppp/auth.c $(LWIPDIR)/netif/ppp/chap.c \
|
||||
$(LWIPDIR)/netif/ppp/chpms.c $(LWIPDIR)/netif/ppp/fsm.c \
|
||||
$(LWIPDIR)/netif/ppp/ipcp.c $(LWIPDIR)/netif/ppp/lcp.c \
|
||||
$(LWIPDIR)/netif/ppp/magic.c $(LWIPDIR)/netif/ppp/md5.c \
|
||||
$(LWIPDIR)/netif/ppp/pap.c $(LWIPDIR)/netif/ppp/ppp.c \
|
||||
$(LWIPDIR)/netif/ppp/randm.c $(LWIPDIR)/netif/ppp/vj.c \
|
||||
$(LWIPARCH)/netif/sio.c
|
||||
|
||||
# ARCHFILES: Architecture specific files.
|
||||
ARCHFILES=$(wildcard $(LWIPARCH)/*.c $(LWIPARCH)/netif/tapif.c $(LWIPARCH)/netif/tcpdump.c)
|
||||
|
||||
|
|
|
@ -33,13 +33,41 @@
|
|||
#define __LWIPOPTS_H__
|
||||
#define DBG_MIN_LEVEL 0
|
||||
#define LWIP_COMPAT_SOCKETS 1
|
||||
#define TAPIF_DEBUG 0
|
||||
#define TUNIF_DEBUG 0
|
||||
#define UNIXIF_DEBUG 0
|
||||
#define DELIF_DEBUG 0
|
||||
#define SIO_FIFO_DEBUG 0
|
||||
#define PPP_DEBUG 0
|
||||
#define TCPDUMP_DEBUG 0
|
||||
#define TAPIF_DEBUG DBG_ON
|
||||
#define TUNIF_DEBUG DBG_OFF
|
||||
#define UNIXIF_DEBUG DBG_OFF
|
||||
#define DELIF_DEBUG DBG_OFF
|
||||
#define SIO_FIFO_DEBUG DBG_OFF
|
||||
#define TCPDUMP_DEBUG DBG_ON
|
||||
|
||||
#define PPP_DEBUG DBG_ON
|
||||
|
||||
#if 0
|
||||
/*#define MEM_DEBUG DBG_ON
|
||||
#define MEMP_DEBUG DBG_ON
|
||||
#define PBUF_DEBUG DBG_ON
|
||||
#define API_LIB_DEBUG DBG_ON
|
||||
#define API_MSG_DEBUG DBG_ON */
|
||||
#define TCPIP_DEBUG DBG_ON
|
||||
#define NETIF_DEBUG DBG_ON
|
||||
#define SOCKETS_DEBUG DBG_ON
|
||||
#define DEMO_DEBUG DBG_ON
|
||||
#define IP_DEBUG DBG_ON
|
||||
#define IP_REASS_DEBUG DBG_ON
|
||||
#define ICMP_DEBUG DBG_ON
|
||||
#define UDP_DEBUG DBG_ON
|
||||
#define TCP_DEBUG DBG_ON
|
||||
#define TCP_RTO_DEBUG DBG_ON
|
||||
#define TCP_CWND_DEBUG DBG_ON
|
||||
#define TCP_WND_DEBUG DBG_ON
|
||||
#define TCP_FR_DEBUG DBG_ON
|
||||
#define TCP_QLEN_DEBUG DBG_ON
|
||||
#define TCP_RST_DEBUG DBG_ON
|
||||
#endif
|
||||
|
||||
#define DBG_TYPES_ON (DBG_ON|DBG_TRACE|DBG_STATE|DBG_FRESH|DBG_HALT)
|
||||
|
||||
|
||||
/* ---------- Memory options ---------- */
|
||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
||||
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
|
||||
|
@ -48,7 +76,7 @@
|
|||
|
||||
/* MEM_SIZE: the size of the heap memory. If the application will send
|
||||
a lot of data that needs to be copied, this should be set high. */
|
||||
#define MEM_SIZE 1600
|
||||
#define MEM_SIZE 10240
|
||||
|
||||
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
|
||||
sends a lot of data out of ROM (or other static memory), this
|
||||
|
@ -75,15 +103,15 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
/* MEMP_NUM_NETBUF: the number of struct netbufs. */
|
||||
#define MEMP_NUM_NETBUF 2
|
||||
/* MEMP_NUM_NETCONN: the number of struct netconns. */
|
||||
#define MEMP_NUM_NETCONN 4
|
||||
#define MEMP_NUM_NETCONN 10
|
||||
/* MEMP_NUM_APIMSG: the number of struct api_msg, used for
|
||||
communication between the TCP/IP stack and the sequential
|
||||
programs. */
|
||||
#define MEMP_NUM_API_MSG 8
|
||||
#define MEMP_NUM_API_MSG 16
|
||||
/* MEMP_NUM_TCPIPMSG: the number of struct tcpip_msg, which is used
|
||||
for sequential API communication and incoming packets. Used in
|
||||
src/api/tcpip.c. */
|
||||
#define MEMP_NUM_TCPIP_MSG 8
|
||||
#define MEMP_NUM_TCPIP_MSG 16
|
||||
|
||||
|
||||
/* ---------- Pbuf options ---------- */
|
||||
|
@ -113,17 +141,22 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
#define TCP_QUEUE_OOSEQ 1
|
||||
|
||||
/* TCP Maximum segment size. */
|
||||
#define TCP_MSS 128
|
||||
#define TCP_MSS 1024
|
||||
|
||||
/* TCP sender buffer space (bytes). */
|
||||
#define TCP_SND_BUF 256
|
||||
#define TCP_SND_BUF 2048
|
||||
|
||||
/* TCP sender buffer space (pbufs). This must be at least = 2 *
|
||||
TCP_SND_BUF/TCP_MSS for things to work. */
|
||||
#define TCP_SND_QUEUELEN 4 * TCP_SND_BUF/TCP_MSS
|
||||
|
||||
/* TCP writable space (bytes). This must be less than or equal
|
||||
to TCP_SND_BUF. It is the amount of space which must be
|
||||
available in the tcp snd_buf for select to return writable */
|
||||
#define TCP_SNDLOWAT (TCP_SND_BUF/2)
|
||||
|
||||
/* TCP receive window. */
|
||||
#define TCP_WND 1024
|
||||
#define TCP_WND 8096
|
||||
|
||||
/* Maximum number of retransmissions of data segments. */
|
||||
#define TCP_MAXRTX 12
|
||||
|
@ -131,11 +164,6 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
/* Maximum number of retransmissions of SYN segments. */
|
||||
#define TCP_SYNMAXRTX 4
|
||||
|
||||
/* TCP writable space (bytes). This must be less than or equal
|
||||
to TCP_SND_BUF. It is the amount of space which must be
|
||||
available in the tcp snd_buf for select to return writable */
|
||||
#define TCP_SNDLOWAT TCP_SND_BUF/2
|
||||
|
||||
/* ---------- ARP options ---------- */
|
||||
#define ARP_TABLE_SIZE 10
|
||||
#define ARP_QUEUEING 1
|
||||
|
@ -182,7 +210,7 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
|
||||
/* ---------- Statistics options ---------- */
|
||||
|
||||
#if LWIP_STATS
|
||||
#ifdef LWIP_STATS
|
||||
#define LINK_STATS
|
||||
#define IP_STATS
|
||||
#define ICMP_STATS
|
||||
|
@ -194,4 +222,80 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
#define SYS_STATS
|
||||
#endif /* LWIP_STATS */
|
||||
|
||||
/* ---------- PPP options ---------- */
|
||||
|
||||
#define PPP_SUPPORT 1 /* Set > 0 for PPP */
|
||||
|
||||
#if PPP_SUPPORT > 0
|
||||
|
||||
#define NUM_PPP 1 /* Max PPP sessions. */
|
||||
|
||||
|
||||
/* Select modules to enable. Ideally these would be set in the makefile but
|
||||
* we're limited by the command line length so you need to modify the settings
|
||||
* in this file.
|
||||
*/
|
||||
#define PAP_SUPPORT 1 /* Set > 0 for PAP. */
|
||||
#define CHAP_SUPPORT 0 /* Set > 0 for CHAP. */
|
||||
#define MSCHAP_SUPPORT 0 /* Set > 0 for MSCHAP (NOT FUNCTIONAL!) */
|
||||
#define CBCP_SUPPORT 0 /* Set > 0 for CBCP (NOT FUNCTIONAL!) */
|
||||
#define CCP_SUPPORT 0 /* Set > 0 for CCP (NOT FUNCTIONAL!) */
|
||||
#define VJ_SUPPORT 1 /* Set > 0 for VJ header compression. */
|
||||
#define MD5_SUPPORT 1 /* Set > 0 for MD5 (see also CHAP) */
|
||||
|
||||
|
||||
/*
|
||||
* Timeouts.
|
||||
*/
|
||||
#define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */
|
||||
#define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
|
||||
#define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
|
||||
#define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
|
||||
|
||||
#define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */
|
||||
#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */
|
||||
|
||||
#define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */
|
||||
#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */
|
||||
|
||||
|
||||
/* Interval in seconds between keepalive echo requests, 0 to disable. */
|
||||
#if 1
|
||||
#define LCP_ECHOINTERVAL 0
|
||||
#else
|
||||
#define LCP_ECHOINTERVAL 10
|
||||
#endif
|
||||
|
||||
/* Number of unanswered echo requests before failure. */
|
||||
#define LCP_MAXECHOFAILS 3
|
||||
|
||||
/* Max Xmit idle time (in jiffies) before resend flag char. */
|
||||
#define PPP_MAXIDLEFLAG 100
|
||||
|
||||
/*
|
||||
* Packet sizes
|
||||
*
|
||||
* Note - lcp shouldn't be allowed to negotiate stuff outside these
|
||||
* limits. See lcp.h in the pppd directory.
|
||||
* (XXX - these constants should simply be shared by lcp.c instead
|
||||
* of living in lcp.h)
|
||||
*/
|
||||
#define PPP_MTU 1500 /* Default MTU (size of Info field) */
|
||||
#if 0
|
||||
#define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN)
|
||||
#else
|
||||
#define PPP_MAXMTU 1500 /* Largest MTU we allow */
|
||||
#endif
|
||||
#define PPP_MINMTU 64
|
||||
#define PPP_MRU 1500 /* default MRU = max length of info field */
|
||||
#define PPP_MAXMRU 1500 /* Largest MRU we allow */
|
||||
#define PPP_DEFMRU 296 /* Try for this */
|
||||
#define PPP_MINMRU 128 /* No MRUs below this */
|
||||
|
||||
|
||||
#define MAXNAMELEN 256 /* max length of hostname or name for auth */
|
||||
#define MAXSECRETLEN 256 /* max length of password or secret */
|
||||
|
||||
#endif /* PPP_SUPPORT > 0 */
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
|
|
|
@ -30,9 +30,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "lwip/debug.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
|
@ -55,8 +54,12 @@
|
|||
|
||||
#include "netif/tcpdump.h"
|
||||
|
||||
#if PPP_SUPPORT
|
||||
#include "netif/ppp/ppp.h"
|
||||
#define PPP_PTY_TEST 1
|
||||
#endif
|
||||
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
|
@ -84,12 +87,74 @@ tcpip_init_done(void *arg)
|
|||
sem = arg;
|
||||
sys_sem_signal(*sem);
|
||||
}
|
||||
|
||||
#if PPP_SUPPORT
|
||||
void
|
||||
pppLinkStatusCallback(void *ctx, int errCode, void *arg)
|
||||
{
|
||||
switch(errCode) {
|
||||
case PPPERR_NONE: /* No error. */
|
||||
{
|
||||
struct ppp_addrs *ppp_addrs = arg;
|
||||
|
||||
printf("pppLinkStatusCallback: PPPERR_NONE");
|
||||
printf(" our_ipaddr=%s", inet_ntoa(ppp_addrs->our_ipaddr.addr));
|
||||
printf(" his_ipaddr=%s", inet_ntoa(ppp_addrs->his_ipaddr.addr));
|
||||
printf(" netmask=%s", inet_ntoa(ppp_addrs->netmask.addr));
|
||||
printf(" dns1=%s", inet_ntoa(ppp_addrs->dns1.addr));
|
||||
printf(" dns2=%s\n", inet_ntoa(ppp_addrs->dns2.addr));
|
||||
}
|
||||
break;
|
||||
|
||||
case PPPERR_PARAM: /* Invalid parameter. */
|
||||
printf("pppLinkStatusCallback: PPPERR_PARAM\n");
|
||||
break;
|
||||
|
||||
case PPPERR_OPEN: /* Unable to open PPP session. */
|
||||
printf("pppLinkStatusCallback: PPPERR_OPEN\n");
|
||||
break;
|
||||
|
||||
case PPPERR_DEVICE: /* Invalid I/O device for PPP. */
|
||||
printf("pppLinkStatusCallback: PPPERR_DEVICE\n");
|
||||
break;
|
||||
|
||||
case PPPERR_ALLOC: /* Unable to allocate resources. */
|
||||
printf("pppLinkStatusCallback: PPPERR_ALLOC\n");
|
||||
break;
|
||||
|
||||
case PPPERR_USER: /* User interrupt. */
|
||||
printf("pppLinkStatusCallback: PPPERR_USER\n");
|
||||
break;
|
||||
|
||||
case PPPERR_CONNECT: /* Connection lost. */
|
||||
printf("pppLinkStatusCallback: PPPERR_CONNECT\n");
|
||||
break;
|
||||
|
||||
case PPPERR_AUTHFAIL: /* Failed authentication challenge. */
|
||||
printf("pppLinkStatusCallback: PPPERR_AUTHFAIL\n");
|
||||
break;
|
||||
|
||||
case PPPERR_PROTOCOL: /* Failed to meet protocol. */
|
||||
printf("pppLinkStatusCallback: PPPERR_PROTOCOL\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("pppLinkStatusCallback: unknown errCode %d\n", errCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
main_thread(void *arg)
|
||||
{
|
||||
struct ip_addr ipaddr, netmask, gw;
|
||||
sys_sem_t sem;
|
||||
#if PPP_SUPPORT
|
||||
sio_fd_t ppp_sio;
|
||||
#endif
|
||||
|
||||
netif_init();
|
||||
|
||||
|
@ -98,6 +163,21 @@ main_thread(void *arg)
|
|||
sys_sem_wait(sem);
|
||||
sys_sem_free(sem);
|
||||
printf("TCP/IP initialized.\n");
|
||||
#if PPP_SUPPORT
|
||||
pppInit();
|
||||
#if PPP_PTY_TEST
|
||||
ppp_sio = sio_open(2);
|
||||
#else
|
||||
ppp_sio = sio_open(0);
|
||||
#endif
|
||||
if(!ppp_sio)
|
||||
{
|
||||
perror("Error opening device: ");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pppOpen(ppp_sio, pppLinkStatusCallback, NULL);
|
||||
#endif /* PPP_SUPPORT */
|
||||
|
||||
#if LWIP_DHCP
|
||||
{
|
||||
|
@ -177,7 +257,7 @@ main(int argc, char **argv)
|
|||
|
||||
printf("System initialized.\n");
|
||||
|
||||
sys_thread_new((void *)(main_thread), NULL, DEFAULT_THREAD_PRIO);
|
||||
sys_thread_new(main_thread, NULL, DEFAULT_THREAD_PRIO);
|
||||
pause();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -509,3 +509,42 @@ sys_arch_unprotect(sys_prot_t pval)
|
|||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef MAX_JIFFY_OFFSET
|
||||
#define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
|
||||
#endif
|
||||
|
||||
#ifndef HZ
|
||||
#define HZ 100
|
||||
#endif
|
||||
|
||||
unsigned long
|
||||
sys_jiffies(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
unsigned long sec = tv.tv_sec;
|
||||
long usec = tv.tv_usec;
|
||||
|
||||
gettimeofday(&tv,NULL);
|
||||
|
||||
if (sec >= (MAX_JIFFY_OFFSET / HZ))
|
||||
return MAX_JIFFY_OFFSET;
|
||||
usec += 1000000L / HZ - 1;
|
||||
usec /= 1000000L / HZ;
|
||||
return HZ * sec + usec;
|
||||
}
|
||||
|
||||
#if PPP_DEBUG
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
void ppp_trace(int level, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
(void)level;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user