int ppp_start(int ttyfd) { //ppp_debug(PPPLVL_NOTE, "start ppp...\n"); printf("start ppp1...\n"); printf("start ppp ttyfd = %d\n",ttyfd); ppp_isup = 0; tty_fd = ttyfd; //printf("establish_ppp succ\n"); printf("start ppp ttyfd = %d\n",ttyfd); if(establish_ppp(ttyfd)) { printf("establish_ppp_fail\n"); return 1; } else { printf("establish_ppp succ\n"); } printf("start ppp2...\n"); lcp_init(); printf("start ppp3...\n"); if(lcp_start()) { ppp_debug(PPPLVL_NOTE, "lcp start fail\n"); goto err_close; } printf("lcp start succ\n"); ppp_debug(PPPLVL_NOTE, "lcp start OK\n"); printf("start ppp4...\n"); if(chap_start()) { ppp_debug(PPPLVL_NOTE, "chap start fail\n"); goto err_close; } ppp_debug(PPPLVL_NOTE, "chap start OK\n"); printf("start ppp5...\n"); ipcp_init(); if(ipcp_start()) { ppp_debug(PPPLVL_NOTE, "ipcp start fail\n"); goto err_close; } printf("start ppp6...\n"); ppp_debug(PPPLVL_NOTE, "ipcp start OK\n"); if(ppp_netup()) { ppp_debug(PPPLVL_NOTE, "ppp up failed!\n"); goto err_close; } ppp_debug(PPPLVL_ALM, "ppp up!\n"); printf("start ppp7...\n"); ppp_isup = 1; return 0; err_close: ppp_end(ttyfd); return 1; }
/*---------------------------------------------------------------------------*/ void ppp_connect(void) { /* Initialize PPP engine */ /* init_ppp(); */ pap_init(); ipcp_init(); lcp_init(); /* Enable PPP */ ppp_flags = PPP_RX_READY; }
/*---------------------------------------------------------------------------*/ void ppp_init() { #if PACKET_RX_DEBUG ppp_rx_frame_count = 0; done = 0; #endif ppp_flags = 0; pap_init(); ipcp_init(); lcp_init(); ppp_flags = 0; ahdlc_init(ppp_rx_buffer, PPP_RX_BUFFER_SIZE); ahdlc_rx_ready(); }
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 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; }
/*---------------------------------------------------------------------------*/ void ppp_init() { ppp_rx_frame_count = 0; #if PACKET_RX_DEBUG done = 0; #endif ppp_flags = 0; pap_init(); // #if UIP_CONF_IPV6 ipv6cp_init(); #else ipcp_init(); #endif // lcp_init(); ppp_flags = 0; ahdlc_init(ppp_rx_buffer, PPP_RX_BUFFER_SIZE); ahdlc_rx_ready(); }
/* Open a new PPP connection using the given I/O device. * This initializes the PPP control block but does not * attempt to negotiate the LCP session. If this port * connects to a modem, the modem connection must be * established before calling this. * Return a new PPP connection descriptor on success or * an error code (negative) on failure. */ int pppOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx) { PPPControl *pc; int pd; /* Find a free PPP session descriptor. Critical region? */ for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++); if (pd >= NUM_PPP) pd = PPPERR_OPEN; else pppControl[pd].openFlag = !0; /* Launch a deamon thread. */ if (pd >= 0) { pppControl[pd].openFlag = 1; lcp_init(pd); pc = &pppControl[pd]; pc->fd = fd; pc->kill_link = 0; pc->sig_hup = 0; pc->if_up = 0; pc->errCode = 0; pc->inState = PDIDLE; pc->inHead = NULL; pc->inTail = NULL; pc->inEscaped = 0; pc->lastXMit = 0; #if VJ_SUPPORT > 0 pc->vjEnabled = 0; vj_compress_init(&pc->vjComp); #endif /* * Default the in and out accm so that escape and flag characters * are always escaped. */ memset(pc->inACCM, 0, sizeof(ext_accm)); pc->inACCM[15] = 0x60; memset(pc->outACCM, 0, sizeof(ext_accm)); pc->outACCM[15] = 0x60; pc->linkStatusCB = linkStatusCB; pc->linkStatusCtx = linkStatusCtx; sys_thread_new(pppMain, (void*)pd, PPP_THREAD_PRIO); if(!linkStatusCB) { while(pd >= 0 && !pc->if_up) { sys_msleep(500); if (lcp_phase[pd] == PHASE_DEAD) { pppClose(pd); if (pc->errCode) pd = pc->errCode; else pd = PPPERR_CONNECT; } } } } return pd; }
/** * Initialize the npppd_ppp instance * Set npppd_ppp#mru and npppd_ppp#phy_label before call this function. */ int ppp_init(npppd *pppd, npppd_ppp *_this) { PPP_ASSERT(_this != NULL); PPP_ASSERT(strlen(_this->phy_label) > 0); _this->id = -1; _this->ifidx = -1; _this->has_acf = 1; _this->recv_packet = ppp_recv_packet; _this->id = ppp_seq++; _this->pppd = pppd; lcp_init(&_this->lcp, _this); _this->mru = ppp_config_int(_this, "lcp.mru", DEFAULT_MRU); if (_this->outpacket_buf == NULL) { _this->outpacket_buf = malloc(_this->mru + 64); if (_this->outpacket_buf == NULL){ log_printf(LOG_ERR, "malloc() failed in %s(): %m", __func__); return -1; } } _this->adjust_mss = ppp_config_str_equal(_this, "ip.adjust_mss", "true", 0); #ifdef USE_NPPPD_PIPEX _this->use_pipex = ppp_config_str_equal(_this, "pipex.enabled", "true", 1); #endif /* load the logging configuration */ _this->log_dump_in = ppp_config_str_equal(_this, "log.in.pktdump", "true", 0); _this->log_dump_out = ppp_config_str_equal(_this, "log.out.pktdump", "true", 0); _this->ingress_filter = ppp_config_str_equal(_this, "ingress_filter", "true", 0); #ifdef USE_NPPPD_MPPE mppe_init(&_this->mppe, _this); #endif ccp_init(&_this->ccp, _this); ipcp_init(&_this->ipcp, _this); pap_init(&_this->pap, _this); chap_init(&_this->chap, _this); /* load the idle timer configuration */ _this->timeout_sec = ppp_config_int(_this, "idle_timeout", 0); if (!evtimer_initialized(&_this->idle_event)) evtimer_set(&_this->idle_event, ppp_idle_timeout, _this); _this->auth_timeout = ppp_config_int(_this, "auth.timeout", DEFAULT_AUTH_TIMEOUT); _this->lcp.echo_interval = ppp_config_int(_this, "lcp.echo_interval", DEFAULT_LCP_ECHO_INTERVAL); _this->lcp.echo_max_retries = ppp_config_int(_this, "lcp.echo_max_retries", DEFAULT_LCP_ECHO_MAX_RETRIES); _this->lcp.echo_retry_interval = ppp_config_int(_this, "lcp.echo_retry_interval", DEFAULT_LCP_ECHO_RETRY_INTERVAL); return 0; }