diff --git a/netutils/Makefile b/netutils/Makefile index 4d30700f8..875000533 100644 --- a/netutils/Makefile +++ b/netutils/Makefile @@ -40,7 +40,7 @@ SUBDIRS = json codecs ifeq ($(CONFIG_NET),y) SUBDIRS += netlib dhcpc dhcpd discover dnsclient ftpc ftpd smtp telnetd -SUBDIRS += webclient webserver tftpc thttpd xmlrpc +SUBDIRS += webclient webserver tftpc thttpd xmlrpc pppd endif all: nothing diff --git a/netutils/pppd/Makefile b/netutils/pppd/Makefile index b3ea837ff..d1cc3ee51 100644 --- a/netutils/pppd/Makefile +++ b/netutils/pppd/Makefile @@ -37,10 +37,6 @@ -include $(TOPDIR)/Make.defs include $(APPDIR)/Make.defs -APPNAME = pppd -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_NETUTILS_PPPD_STACKSIZE) - ASRCS = CSRCS = @@ -86,16 +82,7 @@ $(COBJS): %$(OBJEXT): %.c install: -# Register application - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else context: -endif .depend: Makefile $(SRCS) $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep diff --git a/netutils/pppd/ahdlc.c b/netutils/pppd/ahdlc.c index de593a8bb..0245a6a1b 100644 --- a/netutils/pppd/ahdlc.c +++ b/netutils/pppd/ahdlc.c @@ -444,6 +444,6 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header, ++ctx->ppp_tx_frame_count; #endif -O + return 0; } diff --git a/netutils/pppd/chat.c b/netutils/pppd/chat.c index e3120f647..35ab4c23a 100644 --- a/netutils/pppd/chat.c +++ b/netutils/pppd/chat.c @@ -37,12 +37,16 @@ * Included Files ****************************************************************************/ +#include + #include "ppp_conf.h" #include "ppp_arch.h" #include "chat.h" #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -200,4 +204,4 @@ int ppp_chat(int fd, struct chat_script_s *script, int echo) } return 0; -} \ No newline at end of file +} diff --git a/netutils/pppd/chat.h b/netutils/pppd/chat.h index 7246b6812..63c707434 100644 --- a/netutils/pppd/chat.h +++ b/netutils/pppd/chat.h @@ -40,24 +40,12 @@ * Included Files ****************************************************************************/ -#include +#include /**************************************************************************** * Public Types ****************************************************************************/ -struct chat_line_s -{ - const char *request; - const char *response; -}; - -struct chat_script_s -{ - time_t timeout; - struct chat_line_s lines[]; -}; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -78,4 +66,4 @@ int ppp_chat(int fd, struct chat_script_s *script, int echo); } #endif -#endif /* __APPS_NETUTILS_PPPD_CHAT_H */ \ No newline at end of file +#endif /* __APPS_NETUTILS_PPPD_CHAT_H */ diff --git a/netutils/pppd/lcp.c b/netutils/pppd/lcp.c index cf0137387..e6cd7847d 100644 --- a/netutils/pppd/lcp.c +++ b/netutils/pppd/lcp.c @@ -42,12 +42,16 @@ * Included Files ****************************************************************************/ +#include + #include "ppp_conf.h" #include "ppp_arch.h" #include "ppp.h" #include "ahdlc.h" #include "lcp.h" +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -109,6 +113,7 @@ void lcp_rx(struct ppp_context_s *ctx, u8_t *buffer, u16_t count) u8_t error = 0; u8_t id; u16_t len, j; + struct pppd_settings_s *pppd_settings = ctx->settings; switch (*bptr++) { @@ -202,7 +207,7 @@ void lcp_rx(struct ppp_context_s *ctx, u8_t *buffer, u16_t count) { /* Negotiate PAP */ - if (strlen((char*)ctx->pap_username) > 0) + if (strlen(pppd_settings->pap_username) > 0) { DEBUG1((" ")); ctx->lcp_state |= LCP_RX_AUTH; diff --git a/netutils/pppd/ppp.h b/netutils/pppd/ppp.h index 85a7bd6b3..1252a386a 100644 --- a/netutils/pppd/ppp.h +++ b/netutils/pppd/ppp.h @@ -102,17 +102,10 @@ #define USE_NOACCMBUG 0x2 #define USE_GETDNS 0x4 -#ifdef CONFIG_NETUTILS_PPPD_PAP -#define ppp_setusername(un) strncpy(pap_username, (un), PAP_USERNAME_SIZE) -#define ppp_setpassword(pw) strncpy(pap_password, (pw), PAP_PASSWORD_SIZE) -#endif /* CONFIG_NETUTILS_PPPD_PAP */ - /**************************************************************************** * Public Types ****************************************************************************/ -struct chat_script_s; - /* PPP context definition */ struct ppp_context_s @@ -136,7 +129,6 @@ struct ppp_context_s /* Interfaces */ int tty_fd; - u8_t ttyname[TTYNAMSIZ]; int if_fd; u8_t ifname[IFNAMSIZ]; @@ -163,8 +155,6 @@ struct ppp_context_s #ifdef CONFIG_NETUTILS_PPPD_PAP /* PAP */ - u8_t pap_username[PAP_USERNAME_SIZE]; - u8_t pap_password[PAP_PASSWORD_SIZE]; u8_t pap_state; u8_t pap_retry; time_t pap_prev_seconds; @@ -198,6 +188,10 @@ struct ppp_context_s u32_t ppp_rx_frame_count; u32_t ppp_tx_frame_count; #endif + + /* PPPD Settings */ + + struct pppd_settings_s *settings; }; /**************************************************************************** diff --git a/netutils/pppd/ppp_arch.h b/netutils/pppd/ppp_arch.h index b1c6be83b..62804acc7 100644 --- a/netutils/pppd/ppp_arch.h +++ b/netutils/pppd/ppp_arch.h @@ -56,8 +56,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define TTYNAMSIZ 16 - /**************************************************************************** * Public Types ****************************************************************************/ @@ -91,4 +89,4 @@ int ppp_arch_putchar(struct ppp_context_s *ctx, u8_t c); } #endif -#endif /* __APPS_NETUTILS_PPPD_PPP_ARCH_H */ \ No newline at end of file +#endif /* __APPS_NETUTILS_PPPD_PPP_ARCH_H */ diff --git a/netutils/pppd/ppp_conf.h b/netutils/pppd/ppp_conf.h index d092f2b81..27f646772 100644 --- a/netutils/pppd/ppp_conf.h +++ b/netutils/pppd/ppp_conf.h @@ -55,8 +55,6 @@ #define PAP_USERNAME_SIZE 16 #define PAP_PASSWORD_SIZE 16 -#define PAP_USERNAME "user" -#define PAP_PASSWORD "pass" #define xxdebug_printf printf #define debug_printf printf @@ -72,4 +70,4 @@ #define PPP_STATISTICS 1 #define PPP_DEBUG 1 -#endif /* __APPS_NETUTILS_PPPD_PPP_CONF_H */ \ No newline at end of file +#endif /* __APPS_NETUTILS_PPPD_PPP_CONF_H */ diff --git a/netutils/pppd/pppd.c b/netutils/pppd/pppd.c index 8bac59b2e..3a51a4f45 100644 --- a/netutils/pppd/pppd.c +++ b/netutils/pppd/pppd.c @@ -60,6 +60,8 @@ #include "ppp.h" #include "chat.h" +#include + #if PPP_ARCH_HAVE_MODEM_RESET extern void ppp_arch_modem_reset(const char *tty); #endif @@ -76,28 +78,6 @@ extern void ppp_arch_modem_reset(const char *tty); * Private Data ****************************************************************************/ -static struct chat_script_s connect_script = -{ - .timeout = 30, - .lines = - { - {"AT", "OK"}, - {"AT+CGDCONT = 1,\"IP\",\"internet\"", "OK"}, - {"ATD*99***1#", "CONNECT"}, - {0, 0} - }, -}; - -static struct chat_script_s disconnect_script = -{ - .timeout = 30, - .lines = - { - {"ATZ", "OK"}, - {0, 0} - }, -}; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -227,7 +207,7 @@ void ppp_reconnect(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); lcp_disconnect(ctx, ++ctx->ppp_id); @@ -238,20 +218,20 @@ void ppp_reconnect(struct ppp_context_s *ctx) sleep(2); write(ctx->tty_fd, "ATE1\r\n", 6); - if (ctx->disconnect_script) + if (pppd_settings->disconnect_script) { - ret = ppp_chat(ctx->tty_fd, ctx->disconnect_script, 1 /*echo on*/); + ret = ppp_chat(ctx->tty_fd, pppd_settings->disconnect_script, 1 /*echo on*/); if (ret < 0) { printf("ppp: disconnect script failed\n"); } } - if (ctx->connect_script) + if (pppd_settings->connect_script) { do { - ret = ppp_chat(ctx->tty_fd, ctx->connect_script, 1 /*echo on*/); + ret = ppp_chat(ctx->tty_fd, pppd_settings->connect_script, 1 /*echo on*/); if (ret < 0) { printf("ppp: connect script failed\n"); @@ -260,7 +240,7 @@ void ppp_reconnect(struct ppp_context_s *ctx) { retry = PPP_MAX_CONNECT; #if PPP_ARCH_HAVE_MODEM_RESET - ppp_arch_modem_reset((char*)ctx->ttyname); + ppp_arch_modem_reset(pppd_settings->ttyname); #endif sleep(45); } @@ -333,10 +313,10 @@ int ppp_arch_putchar(struct ppp_context_s *ctx, u8_t c) } /**************************************************************************** - * Name: pppd_main + * Name: pppd ****************************************************************************/ -int pppd_main(int argc, char **argv) +int pppd(struct pppd_settings_s *pppd_settings) { struct pollfd fds[2]; int ret; @@ -344,18 +324,9 @@ int pppd_main(int argc, char **argv) ctx = (struct ppp_context_s*)malloc(sizeof(struct ppp_context_s)); memset(ctx, 0, sizeof(struct ppp_context_s)); - -#ifdef CONFIG_NETUTILS_PPPD_PAP - strcpy((char*)ctx->pap_username, PAP_USERNAME); - strcpy((char*)ctx->pap_password, PAP_PASSWORD); -#endif /* CONFIG_NETUTILS_PPPD_PAP */ - strcpy((char*)ctx->ifname, "ppp%d"); - strcpy((char*)ctx->ttyname, "/dev/ttyS2"); - - ctx->connect_script = &connect_script; - ctx->disconnect_script = &disconnect_script; + ctx->settings = pppd_settings; ctx->if_fd = tun_alloc((char*)ctx->ifname); if (ctx->if_fd < 0) { @@ -363,7 +334,7 @@ int pppd_main(int argc, char **argv) return 2; } - ctx->tty_fd = open_tty((char*)ctx->ttyname); + ctx->tty_fd = open_tty(pppd_settings->ttyname); if (ctx->tty_fd < 0) { close(ctx->tty_fd); @@ -409,11 +380,9 @@ int pppd_main(int argc, char **argv) if (ctx->ip_len > 0) { ret = write(ctx->if_fd, ctx->ip_buf, ctx->ip_len); - //printf("write to tun :%i\n", ret); ctx->ip_len = 0; ret = read(ctx->if_fd, ctx->ip_buf, PPP_RX_BUFFER_SIZE); - //printf("read (after write) from tun :%i\n", ret); if (ret > 0) { ctx->ip_len = ret;