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

📄 ppplcp.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
  if (rbuf == NULL)    return -1;  /*-------------------------------------------------------------------*/  /* Overall buffer length should match.                               */  /*-------------------------------------------------------------------*/  if (config->len != rbuf->length)  {#if PPP_TRACE    pppLog("LCP ACK: buffer length mismatch");#endif    error = TRUE;  }  /*-------------------------------------------------------------------*/  /* Each byte should match.                                           */  /*-------------------------------------------------------------------*/  else  {    int req_char;    int ack_char;    while ((req_char = pullchar(rbuf)) != -1)    {      ack_char = pullchar(pppRcvBuf);      if (ack_char != req_char)      {#if PPP_TRACE        pppLog("LCP ACK: data mismatch");#endif        error = TRUE;        break;      }    }  }  /*-------------------------------------------------------------------*/  /* Free temporarily allocated request buffer.                        */  /*-------------------------------------------------------------------*/  tcpRetBuf(&rbuf);  /*-------------------------------------------------------------------*/  /* Return success or failure code.                                   */  /*-------------------------------------------------------------------*/  if (error)    return -1;  else  {    /*-----------------------------------------------------------------*/    /* If ACCM option was accepted, set serial driver's receive ACMM.  */    /*-----------------------------------------------------------------*/    if (Ppp->lcp.local.options & LCP_N_ACCM)      Ppp->rx_accm = Ppp->lcp.local.accm;#if PPP_TRACE    pppLog("LCP ACK: valid");#endif    return 0;  }}/***********************************************************************//* check_nak_opt: Check a NAKed option, updating its local value       *//*                                                                     *//*     Returns: -1 if ran out of data, else 0                          *//*                                                                     *//*        Note: Called by nak_check() to update our local values       *//*                                                                     *//***********************************************************************/static int check_nak_opt(LcpOpts *local, OptHdr *opt){  int toss = opt->len - OPTION_HDR_LEN;  /*-------------------------------------------------------------------*/  /* Parse option type.                                                */  /*-------------------------------------------------------------------*/  switch (opt->type)  {    case LCP_MRU:      /*---------------------------------------------------------------*/      /* Read the peer's suggested MRU.                                */      /*---------------------------------------------------------------*/      local->mru = pull16(pppRcvBuf);      toss -= 2;#if PPP_TRACE      pppLog("   checking MRU: %u", local->mru);#endif      /*---------------------------------------------------------------*/      /* Ensure the suggested MRU is not too small.                    */      /*---------------------------------------------------------------*/      if (local->mru < LCP_MRU_LO)        local->mru = LCP_MRU_LO;      /*---------------------------------------------------------------*/      /* Ensure the suggested MRU is not too large.                    */      /*---------------------------------------------------------------*/      else if (local->mru > LCP_MRU_HI)        local->mru = LCP_MRU_HI;      break;    case LCP_ACCM:      /*---------------------------------------------------------------*/      /* Read the peer's suggested ACCM.                               */      /*---------------------------------------------------------------*/      local->accm = pull32(pppRcvBuf);      toss -= 4;#if PPP_TRACE      pppLog("   checking ACCM: 0x%08X", local->accm);#endif      /*---------------------------------------------------------------*/      /* Add those we are escaping to the suggested escape characters. */      /*---------------------------------------------------------------*/      local->accm |= Ppp->public.asyncmap;      /*---------------------------------------------------------------*/      /* On receipt of peer's NAK, set serial driver's receive ACCM.   */      /*---------------------------------------------------------------*/      Ppp->rx_accm = local->accm;      break;    case LCP_AUTHENT:    {      int suggested_proto;      /*---------------------------------------------------------------*/      /* Read peer's suggested authentication option.                  */      /*---------------------------------------------------------------*/      suggested_proto = pull16(pppRcvBuf);      toss -= 2;#if PPP_TRACE      pppLog("   checking Auth Protocol: 0x%04x", suggested_proto);#endif      /*---------------------------------------------------------------*/      /* Check suggested option.                                       */      /*---------------------------------------------------------------*/      switch (suggested_proto)      {        case PPP_CHAP_PROTO:          /*-----------------------------------------------------------*/          /* Ensure MD5 selected, length correct, and CHAP request.    */          /*-----------------------------------------------------------*/          --toss;          if ((pullchar(pppRcvBuf) == MD5_ALG) && (opt->len == 5) &&              (Ppp->public.request_opts & OPT_CHAP))            local->auth_proto = suggested_proto;          break;        case PPP_PAP_PROTO:          /*-----------------------------------------------------------*/          /* Ensure PAP is requested and length correct.               */          /*-----------------------------------------------------------*/          if ((Ppp->public.accept_opts & OPT_PAP) && (opt->len == 4))            local->auth_proto = suggested_proto;          break;      }      break;    }    case LCP_MAGIC:      /*---------------------------------------------------------------*/      /* Read the peer's suggested Magic Number option.                */      /*---------------------------------------------------------------*/      local->magic = pull32(pppRcvBuf);      toss -= 4;#if PPP_TRACE      pppLog("   checking Magic Number: 0x%08X", local->magic);#endif      /*---------------------------------------------------------------*/      /* Ensure the magic numbers are different.                       */      /*---------------------------------------------------------------*/      if (Ppp->lcp.remote.magic == local->magic)        local->magic = lcp_rand();      break;    case LCP_PFC:#if PPP_TRACE      pppLog("   checking Protocol compression");#endif      break;    case LCP_ACFC:#if PPP_TRACE      pppLog("   checking Addr/Ctrl compression");#endif      break;    default:#if PPP_TRACE      pppLog("LCP NAK: unknown option");#endif      break;  }  /*-------------------------------------------------------------------*/  /* Return error if buffer ran out of data.                           */  /*-------------------------------------------------------------------*/  if (toss < 0)    return -1;  /*-------------------------------------------------------------------*/  /* Toss remaining bytes in option.                                   */  /*-------------------------------------------------------------------*/  while (toss-- > 0)  {    if (pullchar(pppRcvBuf) == -1)      return -1;  }  return 0;}/***********************************************************************//*   nak_check: Process configuration NAK sent by peer                 *//*                                                                     *//*        Note: Update our config request to reflect NAKed options     *//*                                                                     *//***********************************************************************/static int nak_check(FSM *fsm, ConfigHdr *config){  LcpCB *lcp = &Ppp->lcp;  int signed_length = config->len;  OptHdr option;  int result;  /*-------------------------------------------------------------------*/  /* The ID field must match the last request we sent.                 */  /*-------------------------------------------------------------------*/  if (config->id != fsm->lastid)  {#if PPP_TRACE    pppLog("LCP NAK: wrong ID");#endif    return -1;  }  /*-------------------------------------------------------------------*/  /* Process options in the order received.                            */  /*-------------------------------------------------------------------*/  while ((signed_length > 0) && (pppRdOpt(&option) != -1))  {    /*-----------------------------------------------------------------*/    /* Verify configuration header length is not too short.            */    /*-----------------------------------------------------------------*/    if ((signed_length -= option.len) < 0)    {#if PPP_TRACE      pppLog("LCP NAK: bad header length");#endif      return -1;    }    /*-----------------------------------------------------------------*/    /* Check if option is an unsolicited NAK suggestion.               */    /*-----------------------------------------------------------------*/    if ((Ppp->lcp_request_opts & (1 << option.type)) == FALSE)    {#if PPP_TRACE      pppLog("   unsolicated NAK");#endif      /*---------------------------------------------------------------*/      /* If option is allowed, add it to our request list.             */      /*---------------------------------------------------------------*/      if (Ppp->lcp_accept_opts & (1 << option.type))        lcp->local.options |= (1 << option.type);    }    /*-----------------------------------------------------------------*/    /* Check option and update its working value.                      */    /*-----------------------------------------------------------------*/    result = check_nak_opt(&lcp->local, &option);    /*-----------------------------------------------------------------*/    /* Discard packet if it was too short.                             */    /*-----------------------------------------------------------------*/    if (result == -1)    {#if PPP_TRACE      pppLog("LCP NAK: ran out of data");#endif      return -1;    }  }#if PPP_TRACE  pppLog("LCP NAK: valid");#endif  return 0;}/***********************************************************************//*   check_rej: Process configuration reject sent by the peer          *//*                                                                     *//***********************************************************************/static int check_rej(FSM *fsm, ConfigHdr *config){  LcpOpts *local = &Ppp->lcp.local;  int signed_length = config->len;  OptHdr option;  int last_option = 0;  /*-------------------------------------------------------------------*/  /* The ID field must match the last request we sent.                 */  /*-------------------------------------------------------------------*/  if (config->id != fsm->lastid)

⌨️ 快捷键说明

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