Exemple #1
0
/* Stop a PPPoE session. */
static BOOL StopPPPoE(__PPPOE_INSTANCE* pInstance)
{
	BOOL bResult = FALSE;

	BUG_ON(NULL == pInstance);
	if (pInstance->status == SESSION_IDLE)
	{
		goto __TERMINAL;
	}
	/* 
	 * Just close PPP session here.
	 * The callback of PPPoE will destroy
	 * PPPoE control block,i.e,pppoe_soft_c.
	 */
	pppClose(pInstance->ppp_session_id);

	/* Reset DNS server to default. */
	NetworkGlobal.ResetDNSServer();

	pInstance->status = SESSION_IDLE;

__TERMINAL:
	return bResult;
}
Exemple #2
0
/* This is somewhat different to other ports: we have a main loop here:
 * a dedicated task that waits for packets to arrive. This would normally be
 * done from interrupt context with embedded hardware, but we don't get an
 * interrupt in windows for that :-) */
void main_loop()
{
#if !NO_SYS
  err_t err;
  sys_sem_t init_sem;
#endif /* NO_SYS */
#if PPP_SUPPORT
#if !USE_ETHERNET
  int count;
  u8_t rxbuf[1024];
#endif
  volatile int callClosePpp = 0;
#endif /* PPP_SUPPORT */

  /* initialize lwIP stack, network interfaces and applications */
#if NO_SYS
  lwip_init();
  test_init(NULL);
#else /* NO_SYS */
  err = sys_sem_new(&init_sem, 0);
  tcpip_init(test_init, &init_sem);
  /* we have to wait for initialization to finish before
   * calling update_adapter()! */
  sys_sem_wait(&init_sem);
  sys_sem_free(&init_sem);
#endif /* NO_SYS */

  /* MAIN LOOP for driver update (and timers if NO_SYS) */
  while (!_kbhit()) {
#if NO_SYS
    /* handle timers (already done in tcpip.c when NO_SYS=0) */
    sys_check_timeouts();
#endif /* NO_SYS */

#if USE_ETHERNET
#if !PCAPIF_RX_USE_THREAD
    /* check for packets and link status*/
    pcapif_poll(&netif);
    /* When pcapif_poll comes back, there are not packets, so sleep to
       prevent 100% CPU load. Don't do this in an embedded system since it
       increases latency! */
    sys_msleep(1);
#else /* !PCAPIF_RX_USE_THREAD */
    sys_msleep(50);
#endif /* !PCAPIF_RX_USE_THREAD */
#else /* USE_ETHERNET */
#if 0 /* set this to 1 if PPP_INPROC_OWNTHREAD==0 or not defined (see ppp.c) */
    /* try to read characters from serial line and pass them to PPPoS */
    count = sio_read(ppp_sio, (u8_t*)rxbuf, 1024);
    if(count > 0) {
      pppos_input(ppp_desc, rxbuf, count);
    } else
#endif
    {
      /* nothing received, give other tasks a chance to run */
      sys_msleep(1);
    }

#endif /* USE_ETHERNET */
#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
    /* check for loopback packets on all netifs */
    netif_poll_all();
#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
#if PPP_SUPPORT
    {
    int do_hup = 0;
    if(do_hup) {
      pppSigHUP(ppp_desc);
      do_hup = 0;
    }
    }
    if(callClosePpp && (ppp_desc >= 0)) {
      /* make sure to disconnect PPP before stopping the program... */
      callClosePpp = 0;
#if NO_SYS
      pppClose(ppp_desc);
#else
      tcpip_callback_with_block(pppCloseCallback, (void*)ppp_desc, 0);
#endif
      ppp_desc = -1;
    }
#endif /* PPP_SUPPORT */
  }

#if PPP_SUPPORT
    if(ppp_desc >= 0) {
      u32_t started;
      printf("Closing PPP connection...\n");
      /* make sure to disconnect PPP before stopping the program... */
#if NO_SYS
      pppClose(ppp_desc);
#else
      tcpip_callback_with_block(pppCloseCallback, (void*)ppp_desc, 0);
#endif
      ppp_desc = -1;
      /* Wait for some time to let PPP finish... */
      started = sys_now();
      do
      {
#if USE_ETHERNET && !PCAPIF_RX_USE_THREAD
        pcapif_poll(&netif);
#else /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */
        sys_msleep(50);
#endif /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */
        /* @todo: need a better check here: only wait until PPP is down */
      } while(sys_now() - started < 5000);
    }
#endif /* PPP_SUPPORT */
#if USE_ETHERNET
  /* release the pcap library... */
  pcapif_shutdown(&netif);
#endif /* USE_ETHERNET */
}
Exemple #3
0
static void pppCloseCallback(void *arg)
{
  int pd = (int)arg;
  pppClose(pd);
}
Exemple #4
0
/* 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;
}