apps/netutils: Separated out apps/examples/pppd; split up pppd utils. From Brennan Ashton

This commit is contained in:
Gregory Nutt 2015-04-14 07:02:12 -06:00
parent 9e95454f34
commit af29ca3819
10 changed files with 33 additions and 90 deletions

View File

@ -40,7 +40,7 @@
SUBDIRS = json codecs SUBDIRS = json codecs
ifeq ($(CONFIG_NET),y) ifeq ($(CONFIG_NET),y)
SUBDIRS += netlib dhcpc dhcpd discover dnsclient ftpc ftpd smtp telnetd SUBDIRS += netlib dhcpc dhcpd discover dnsclient ftpc ftpd smtp telnetd
SUBDIRS += webclient webserver tftpc thttpd xmlrpc SUBDIRS += webclient webserver tftpc thttpd xmlrpc pppd
endif endif
all: nothing all: nothing

View File

@ -37,10 +37,6 @@
-include $(TOPDIR)/Make.defs -include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs include $(APPDIR)/Make.defs
APPNAME = pppd
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_NETUTILS_PPPD_STACKSIZE)
ASRCS = ASRCS =
CSRCS = CSRCS =
@ -86,16 +82,7 @@ $(COBJS): %$(OBJEXT): %.c
install: 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: context:
endif
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep

View File

@ -444,6 +444,6 @@ u8_t ahdlc_tx(struct ppp_context_s *ctx, u16_t protocol, u8_t *header,
++ctx->ppp_tx_frame_count; ++ctx->ppp_tx_frame_count;
#endif #endif
O
return 0; return 0;
} }

View File

@ -37,12 +37,16 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include "ppp_conf.h" #include "ppp_conf.h"
#include "ppp_arch.h" #include "ppp_arch.h"
#include "chat.h" #include "chat.h"
#include <poll.h> #include <poll.h>
#include <apps/netutils/pppd.h>
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
@ -200,4 +204,4 @@ int ppp_chat(int fd, struct chat_script_s *script, int echo)
} }
return 0; return 0;
} }

View File

@ -40,24 +40,12 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <time.h> #include <apps/netutils/pppd.h>
/**************************************************************************** /****************************************************************************
* Public Types * 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 * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
@ -78,4 +66,4 @@ int ppp_chat(int fd, struct chat_script_s *script, int echo);
} }
#endif #endif
#endif /* __APPS_NETUTILS_PPPD_CHAT_H */ #endif /* __APPS_NETUTILS_PPPD_CHAT_H */

View File

@ -42,12 +42,16 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include "ppp_conf.h" #include "ppp_conf.h"
#include "ppp_arch.h" #include "ppp_arch.h"
#include "ppp.h" #include "ppp.h"
#include "ahdlc.h" #include "ahdlc.h"
#include "lcp.h" #include "lcp.h"
#include <apps/netutils/pppd.h>
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * 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 error = 0;
u8_t id; u8_t id;
u16_t len, j; u16_t len, j;
struct pppd_settings_s *pppd_settings = ctx->settings;
switch (*bptr++) switch (*bptr++)
{ {
@ -202,7 +207,7 @@ void lcp_rx(struct ppp_context_s *ctx, u8_t *buffer, u16_t count)
{ {
/* Negotiate PAP */ /* Negotiate PAP */
if (strlen((char*)ctx->pap_username) > 0) if (strlen(pppd_settings->pap_username) > 0)
{ {
DEBUG1(("<auth pap> ")); DEBUG1(("<auth pap> "));
ctx->lcp_state |= LCP_RX_AUTH; ctx->lcp_state |= LCP_RX_AUTH;

View File

@ -102,17 +102,10 @@
#define USE_NOACCMBUG 0x2 #define USE_NOACCMBUG 0x2
#define USE_GETDNS 0x4 #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 * Public Types
****************************************************************************/ ****************************************************************************/
struct chat_script_s;
/* PPP context definition */ /* PPP context definition */
struct ppp_context_s struct ppp_context_s
@ -136,7 +129,6 @@ struct ppp_context_s
/* Interfaces */ /* Interfaces */
int tty_fd; int tty_fd;
u8_t ttyname[TTYNAMSIZ];
int if_fd; int if_fd;
u8_t ifname[IFNAMSIZ]; u8_t ifname[IFNAMSIZ];
@ -163,8 +155,6 @@ struct ppp_context_s
#ifdef CONFIG_NETUTILS_PPPD_PAP #ifdef CONFIG_NETUTILS_PPPD_PAP
/* PAP */ /* PAP */
u8_t pap_username[PAP_USERNAME_SIZE];
u8_t pap_password[PAP_PASSWORD_SIZE];
u8_t pap_state; u8_t pap_state;
u8_t pap_retry; u8_t pap_retry;
time_t pap_prev_seconds; time_t pap_prev_seconds;
@ -198,6 +188,10 @@ struct ppp_context_s
u32_t ppp_rx_frame_count; u32_t ppp_rx_frame_count;
u32_t ppp_tx_frame_count; u32_t ppp_tx_frame_count;
#endif #endif
/* PPPD Settings */
struct pppd_settings_s *settings;
}; };
/**************************************************************************** /****************************************************************************

View File

@ -56,8 +56,6 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define TTYNAMSIZ 16
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
@ -91,4 +89,4 @@ int ppp_arch_putchar(struct ppp_context_s *ctx, u8_t c);
} }
#endif #endif
#endif /* __APPS_NETUTILS_PPPD_PPP_ARCH_H */ #endif /* __APPS_NETUTILS_PPPD_PPP_ARCH_H */

View File

@ -55,8 +55,6 @@
#define PAP_USERNAME_SIZE 16 #define PAP_USERNAME_SIZE 16
#define PAP_PASSWORD_SIZE 16 #define PAP_PASSWORD_SIZE 16
#define PAP_USERNAME "user"
#define PAP_PASSWORD "pass"
#define xxdebug_printf printf #define xxdebug_printf printf
#define debug_printf printf #define debug_printf printf
@ -72,4 +70,4 @@
#define PPP_STATISTICS 1 #define PPP_STATISTICS 1
#define PPP_DEBUG 1 #define PPP_DEBUG 1
#endif /* __APPS_NETUTILS_PPPD_PPP_CONF_H */ #endif /* __APPS_NETUTILS_PPPD_PPP_CONF_H */

View File

@ -60,6 +60,8 @@
#include "ppp.h" #include "ppp.h"
#include "chat.h" #include "chat.h"
#include <apps/netutils/pppd.h>
#if PPP_ARCH_HAVE_MODEM_RESET #if PPP_ARCH_HAVE_MODEM_RESET
extern void ppp_arch_modem_reset(const char *tty); extern void ppp_arch_modem_reset(const char *tty);
#endif #endif
@ -76,28 +78,6 @@ extern void ppp_arch_modem_reset(const char *tty);
* Private Data * 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 * Private Functions
****************************************************************************/ ****************************************************************************/
@ -227,7 +207,7 @@ void ppp_reconnect(struct ppp_context_s *ctx)
{ {
int ret; int ret;
int retry = PPP_MAX_CONNECT; int retry = PPP_MAX_CONNECT;
struct pppd_settings_s *pppd_settings = ctx->settings;
netlib_ifdown((char*)ctx->ifname); netlib_ifdown((char*)ctx->ifname);
lcp_disconnect(ctx, ++ctx->ppp_id); lcp_disconnect(ctx, ++ctx->ppp_id);
@ -238,20 +218,20 @@ void ppp_reconnect(struct ppp_context_s *ctx)
sleep(2); sleep(2);
write(ctx->tty_fd, "ATE1\r\n", 6); 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) if (ret < 0)
{ {
printf("ppp: disconnect script failed\n"); printf("ppp: disconnect script failed\n");
} }
} }
if (ctx->connect_script) if (pppd_settings->connect_script)
{ {
do 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) if (ret < 0)
{ {
printf("ppp: connect script failed\n"); printf("ppp: connect script failed\n");
@ -260,7 +240,7 @@ void ppp_reconnect(struct ppp_context_s *ctx)
{ {
retry = PPP_MAX_CONNECT; retry = PPP_MAX_CONNECT;
#if PPP_ARCH_HAVE_MODEM_RESET #if PPP_ARCH_HAVE_MODEM_RESET
ppp_arch_modem_reset((char*)ctx->ttyname); ppp_arch_modem_reset(pppd_settings->ttyname);
#endif #endif
sleep(45); 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]; struct pollfd fds[2];
int ret; int ret;
@ -344,18 +324,9 @@ int pppd_main(int argc, char **argv)
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)); 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->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); ctx->if_fd = tun_alloc((char*)ctx->ifname);
if (ctx->if_fd < 0) if (ctx->if_fd < 0)
{ {
@ -363,7 +334,7 @@ int pppd_main(int argc, char **argv)
return 2; return 2;
} }
ctx->tty_fd = open_tty((char*)ctx->ttyname); ctx->tty_fd = open_tty(pppd_settings->ttyname);
if (ctx->tty_fd < 0) if (ctx->tty_fd < 0)
{ {
close(ctx->tty_fd); close(ctx->tty_fd);
@ -409,11 +380,9 @@ int pppd_main(int argc, char **argv)
if (ctx->ip_len > 0) if (ctx->ip_len > 0)
{ {
ret = write(ctx->if_fd, ctx->ip_buf, ctx->ip_len); ret = write(ctx->if_fd, ctx->ip_buf, ctx->ip_len);
//printf("write to tun :%i\n", ret);
ctx->ip_len = 0; ctx->ip_len = 0;
ret = read(ctx->if_fd, ctx->ip_buf, PPP_RX_BUFFER_SIZE); ret = read(ctx->if_fd, ctx->ip_buf, PPP_RX_BUFFER_SIZE);
//printf("read (after write) from tun :%i\n", ret);
if (ret > 0) if (ret > 0)
{ {
ctx->ip_len = ret; ctx->ip_len = ret;