⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppplcp.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
  {#if PPP_TRACE    pppLog("LCP REJ: wrong ID");#endif    return -1;  }  /*-------------------------------------------------------------------*/  /* Process in order, checking for errors.                            */  /*-------------------------------------------------------------------*/  while ((signed_length > 0) && (pppRdOpt(&option) != -1))  {    int i;    /*-----------------------------------------------------------------*/    /* Ensure configuraton length is long enough to hold next option.  */    /*-----------------------------------------------------------------*/    if ((signed_length -= option.len) < 0)    {#if PPP_TRACE      pppLog("LCP REJ: bad header length");#endif      return -1;    }    /*-----------------------------------------------------------------*/    /* Ensure option order and type is legal.                          */    /*-----------------------------------------------------------------*/    if (option.type > LCP_OPT_LIMIT)    {#if PPP_TRACE      pppLog("LCP REJ: option out of range");#endif    }    else if ((option.type < last_option) ||             !(local->options & (1 << option.type)))    {#if PPP_TRACE      pppLog("LCP REJ: option out of order");#endif      return -1;    }    /*-----------------------------------------------------------------*/    /* Strip option from receive buffer.                               */    /*-----------------------------------------------------------------*/    for (i = option.len - OPTION_HDR_LEN; i > 0; --i)    {      if (pullchar(pppRcvBuf) == -1)      {#if PPP_TRACE        pppLog("LCP REJ: ran out of data");#endif        return -1;      }    }    last_option = option.type;    /*-----------------------------------------------------------------*/    /* Remove rejected option from list of options being negotiated.   */    /*-----------------------------------------------------------------*/    if (option.type <= LCP_OPT_LIMIT)      local->options &= ~(1 << option.type);  }#if PPP_TRACE  pppLog("LCP REJ: valid");#endif  return 0;}/***********************************************************************//* lcp_down: Left LCP Opened state                                     *//*                                                                     *//***********************************************************************/static void lcp_down(FSM *fsm){  Ppp->phase = pppTERMINATE;  if (Ppp->fsm[kIPCP].state > fsmSTARTING)    pppFsmDown(&Ppp->fsm[kIPCP]);  if (Ppp->public.flags & (PPPF_CHAP_LOCAL | PPPF_CHAP_REMOTE))    chapDown();  if (Ppp->public.flags & (PPPF_PAP_LOCAL | PPPF_PAP_REMOTE))    papDown();}/***********************************************************************//* lcp_finished: After termination                                     *//*                                                                     *//***********************************************************************/static void lcp_finished(FSM *fsm){  /*-------------------------------------------------------------------*/  /* If interface has a modem with a hangup string, call Chat.         */  /*-------------------------------------------------------------------*/  if (Ppp->public.chat.hangup)    pppAttnReq(chatClose, Ppp);  /*-------------------------------------------------------------------*/  /* Otherwise, disconnect the serial interface and report Down event. */  /*-------------------------------------------------------------------*/  else    pppFinish();}/***********************************************************************//*      lcp_up: Configuration negotiation complete                     *//*                                                                     *//***********************************************************************/static void lcp_up(FSM *fsm){  LcpCB *lcp = &Ppp->lcp;  /*-------------------------------------------------------------------*/  /* If remote ACCM negotiated, use agreed value. Else use default.    */  /*-------------------------------------------------------------------*/  if (lcp->remote.options & LCP_N_ACCM)    Ppp->tx_accm[0] = Ppp->lcp.remote.accm;  else    Ppp->tx_accm[0] = LCP_ACCM_DEFAULT;  /*-------------------------------------------------------------------*/  /* If MRU option was refused or not requested, use default size.     */  /* Else ensure MRU is atleast as big as the default value.           */  /*-------------------------------------------------------------------*/  if ((lcp->local.options & LCP_N_MRU) == FALSE)    lcp->local.mru = LCP_MRU_DEFAULT;  else    lcp->local.mru = max(lcp->local.mru, LCP_MRU_DEFAULT);  /*-------------------------------------------------------------------*/  /* Update PPP receive buffer size based on the final local MRU.      */  /*-------------------------------------------------------------------*/  Ppp->rbuf_size = NIMHLEN + lcp->local.mru + CRC16_LEN;  /*-------------------------------------------------------------------*/  /* If our authentication request was rejected, shutdown.             */  /*-------------------------------------------------------------------*/  if ((Ppp->lcp_request_opts & LCP_N_AUTHENT) &&      ((lcp->local.options & LCP_N_AUTHENT) == FALSE))  {    fsmLcpClose();    return;  }  /*-------------------------------------------------------------------*/  /* Set local authentication protocol flag if authenticator.          */  /*-------------------------------------------------------------------*/  if (lcp->local.options & LCP_N_AUTHENT)  {    switch (lcp->local.auth_proto)    {      case PPP_CHAP_PROTO:        /*-------------------------------------------------------------*/        /* Ensure a user name has been provided.                       */        /*-------------------------------------------------------------*/        if (Ppp->public.username == NULL)        {#if PPP_TRACE          pppFsmLog(fsm, "NULL username");#endif          fsmLcpClose();          return;        }        Ppp->public.flags |= PPPF_CHAP_LOCAL;        break;      case PPP_PAP_PROTO:        Ppp->public.flags |= PPPF_PAP_LOCAL;        break;    }  }  /*-------------------------------------------------------------------*/  /* Set remote authentication protocol flag if authenticatee.         */  /*-------------------------------------------------------------------*/  if (lcp->remote.options & LCP_N_AUTHENT)  {    /*-----------------------------------------------------------------*/    /* Ensure a user name and password have been provided.             */    /*-----------------------------------------------------------------*/    if ((Ppp->public.username == NULL) || (Ppp->public.password == NULL))    {#if PPP_TRACE      pppFsmLog(fsm, "NULL username or password");#endif      fsmLcpClose();      return;    }    switch (lcp->remote.auth_proto)    {      case PPP_CHAP_PROTO:        Ppp->public.flags |= PPPF_CHAP_REMOTE;        break;      case PPP_PAP_PROTO:        Ppp->public.flags |= PPPF_PAP_REMOTE;        break;    }  }  /*-------------------------------------------------------------------*/  /* Check if any authentication flags were set.                       */  /*-------------------------------------------------------------------*/  if (Ppp->public.flags & PPPF_AUTHENTICATION)  {    /*-----------------------------------------------------------------*/    /* Set phase to "authenticate" and begin authentication.           */    /*-----------------------------------------------------------------*/    Ppp->phase = pppAUTHEN;    if (Ppp->public.flags & (PPPF_CHAP_LOCAL | PPPF_CHAP_REMOTE))      chapOpen();    if (Ppp->public.flags & (PPPF_PAP_LOCAL | PPPF_PAP_REMOTE))      papOpen();  }  /*-------------------------------------------------------------------*/  /* Else skipping authentication phase.                               */  /*-------------------------------------------------------------------*/  else  {    /*-----------------------------------------------------------------*/    /* Set phase to "network" and start IPCP layer.                    */    /*-----------------------------------------------------------------*/    Ppp->phase = pppNETWORK;    pppFsmUp(&Ppp->fsm[kIPCP]);  }}/***********************************************************************//* lcp_starting: Prepare to begin configuration exchange               *//*                                                                     *//***********************************************************************/static void lcp_starting(FSM *fsm){  LcpCB *lcp = &Ppp->lcp;  /*-------------------------------------------------------------------*/  /* Initialize local options.                                         */  /*-------------------------------------------------------------------*/  lcp->local.options = Ppp->lcp_request_opts;  if (lcp->local.options & LCP_N_MAGIC)    lcp->local.magic = lcp_rand();  else    lcp->local.magic = 0;  lcp->local.mru = Ppp->public.mru;  lcp->local.accm = Ppp->public.asyncmap;  if (Ppp->public.request_opts & OPT_PAP)    lcp->local.auth_proto = PPP_PAP_PROTO;  else    lcp->local.auth_proto = PPP_CHAP_PROTO;  /*-------------------------------------------------------------------*/  /* Initialize remote values (others initialized in check_req()).     */  /*-------------------------------------------------------------------*/  lcp->remote.magic = 0;}/***********************************************************************//* Global Function Definitions                                         *//***********************************************************************//***********************************************************************//*    pppReady: Check for PPP Network-Layer Protocol Phase             *//*                                                                     *//***********************************************************************/void pppReady(void){  /*-------------------------------------------------------------------*/  /* Determine if there is no pending authentication.                  */  /*-------------------------------------------------------------------*/  if ((Ppp->public.flags & PPPF_AUTHENTICATION) == 0)  {    /*-----------------------------------------------------------------*/    /* Set phase to "network" and start IPCP layer.                    */    /*-----------------------------------------------------------------*/    Ppp->phase = pppNETWORK;    pppFsmUp(&Ppp->fsm[kIPCP]);  }}/***********************************************************************//*     lcpInit: Initialize configuration structure                     *//*                                                                     *//***********************************************************************/void lcpInit(PPP ppp){  FSM *fsm = &ppp->fsm[kLCP];  /*-------------------------------------------------------------------*/  /* Supply LCP finite state machine constants.                        */  /*-------------------------------------------------------------------*/  fsm->pdc = &LcpConstants;  /*-------------------------------------------------------------------*/  /* Initialize state machine.                                         */  /*-------------------------------------------------------------------*/  pppFsmInit(fsm);}#endif /* MAX_PPP_INTF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -