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

📄 ppp.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
📖 第 1 页 / 共 3 页
字号:
  /* If installed, pass buffer to synchronous transmit routine.        */  /*-------------------------------------------------------------------*/  if (Ppp->public.transmit)    Ppp->public.transmit(buf);  /*-------------------------------------------------------------------*/  /* Else send buffer using UART framer module.                        */  /*-------------------------------------------------------------------*/  else  {    /*-----------------------------------------------------------------*/    /* Flag buffer type for transmitter's application of the ACCM.     */    /*-----------------------------------------------------------------*/    if (is_lcp)      buf->type = kLCP;    else      buf->type = ~kLCP;    /*-----------------------------------------------------------------*/    /* Convert "length" to just length of first data region.           */    /*-----------------------------------------------------------------*/    buf->length -= (buf->app_len + buf->app_len2);    /*-----------------------------------------------------------------*/    /* Add buffer to end of framer's outbound list.                    */    /*-----------------------------------------------------------------*/    buf->next = NULL;    isrMask();    if (Ppp->uart.tx_head == NULL)      Ppp->uart.tx_head = buf;    else      Ppp->uart.tx_tail->next = buf;    Ppp->uart.tx_tail = buf;    /*-----------------------------------------------------------------*/    /* Start transmitter if idle.                                      */    /*-----------------------------------------------------------------*/    if (Ppp->uart.idle)    {      Ppp->uart.idle = FALSE;      Ppp->uart.next_char = PPP_FLAG;  /* first character will be flag */      isrUnmask();      Ppp->public.start_tx();    }    else      isrUnmask();  }}/***********************************************************************//*  pppDataInd: Called by framer to process incoming packets           *//*                                                                     *//*       Input: handle = pointer to PPP receive buffer                 *//*                                                                     *//***********************************************************************/void pppDataInd(void *handle){  uint negotiated;  uint protocol;  NetBuf *buf = handle;  ui8 *cp = buf->ip_pkt;  /*-------------------------------------------------------------------*/  /* Set global PPP and buffer pointers before calling other routines. */  /*-------------------------------------------------------------------*/  Ppp = buf->ip_data;  pppRcvBuf = buf;  /*-------------------------------------------------------------------*/  /* Initialize the buffer's "ni" and "type" fields.                   */  /*-------------------------------------------------------------------*/  pppRcvBuf->ni = &Ppp->public.ni;  pppRcvBuf->type = htons(IP_TYPE);  /*-------------------------------------------------------------------*/  /* Update count of received octets.                                  */  /*-------------------------------------------------------------------*/  Ppp->rxOctetCount += buf->length;  /*-------------------------------------------------------------------*/  /* Use negotiated values if LCP finished.                            */  /*-------------------------------------------------------------------*/  if (Ppp->fsm[kLCP].state == fsmOPENED)    negotiated = Ppp->lcp.local.options;  else    negotiated = 0;  /*-------------------------------------------------------------------*/  /* HDLC address and control fields may be compressed out.            */  /*-------------------------------------------------------------------*/  if ((cp[0] != HDLC_ALL_ADDR) || (cp[1] != HDLC_UI))  {    /*-----------------------------------------------------------------*/    /* Error if address and control field compression not enabled.     */    /*-----------------------------------------------------------------*/    if ((negotiated & LCP_N_ACFC) == FALSE)    {#if PPP_TRACE      ppp_log("missing address and control fields");#endif      ++Ppp->rxFrame;      goto proc_err;    }  }  else  {    /*-----------------------------------------------------------------*/    /* Skip address and control fields.                                */    /*-----------------------------------------------------------------*/    cp += 2;  }  /*-------------------------------------------------------------------*/  /* First byte of PPP protocol field may be compressed out.           */  /*-------------------------------------------------------------------*/  protocol = *cp++;  if (protocol & 1)  {    /*-----------------------------------------------------------------*/    /* Check if protocol field compression not enabled.                */    /*-----------------------------------------------------------------*/    if ((negotiated & LCP_N_PFC) == FALSE)    {#if PPP_TRACE      ppp_log("missing upper protocol byte");#endif      ++Ppp->rxFrame;      goto proc_err;    }  }  else  {    /*-----------------------------------------------------------------*/    /* Extract second protocol byte and check that it is odd.          */    /*-----------------------------------------------------------------*/    protocol = (protocol << 8) | *cp++;    if ((protocol & 1) == 0)    {#if PPP_TRACE      ppp_log("missing lower protocol byte");#endif      ++Ppp->rxFrame;      goto proc_err;    }  }  /*-------------------------------------------------------------------*/  /* Adjust buffer length and pointer to refer to just frame data.     */  /*-------------------------------------------------------------------*/  buf->length -= (cp - buf->ip_pkt) + CRC16_LEN;  buf->ip_pkt = cp;  /*-------------------------------------------------------------------*/  /* Route packet according to protocol value.                         */  /*-------------------------------------------------------------------*/  switch (protocol)  {    /*-----------------------------------------------------------------*/    /* Regular IP packet                                               */    /*-----------------------------------------------------------------*/    case PPP_IP_PROTO:      /*---------------------------------------------------------------*/      /* If IPCP layer is open, pass up IP packets, else error.        */      /*---------------------------------------------------------------*/      if (Ppp->fsm[kIPCP].state == fsmOPENED)      {        tcpDataInd(pppRcvBuf);        pppRcvBuf = NULL;      }      else      {#if PPP_TRACE        ppp_log("not open for IP traffic");#endif        ++Ppp->rxError;        goto proc_err;      }      break;    /*-----------------------------------------------------------------*/    /* Van Jacobson Compressed TCP/IP                                  */    /*-----------------------------------------------------------------*/    case PPP_COMP_PROTO:      if (Ppp->fsm[kIPCP].state != fsmOPENED)      {#if PPP_TRACE        ppp_log("not open for Compressed TCP/IP traffic");#endif        ++Ppp->rxError;        goto proc_err;      }      if ((Ppp->ipcp.local.options & IPCP_N_COMPRESS) == FALSE)      {#if PPP_TRACE        ppp_log("compressed TCP/IP not enabled");#endif        ++Ppp->rxError;        goto proc_err;      }      if (vjhc_uncompress(&Ppp->comp, pppRcvBuf))      {#if PPP_TRACE        ppp_log("compressed TCP/IP packet error");#endif        ++Ppp->rxError;        goto proc_err;      }      tcpDataInd(pppRcvBuf);      pppRcvBuf = NULL;      break;    /*-----------------------------------------------------------------*/    /* Van Jacobson Uncompressed TCP/IP                                */    /*-----------------------------------------------------------------*/    case PPP_UNCOMP_PROTO:      if (Ppp->fsm[kIPCP].state != fsmOPENED)      {#if PPP_TRACE        ppp_log("closed for Uncompressed TCP/IP traffic");#endif        ++Ppp->rxError;        goto proc_err;      }      if ((Ppp->ipcp.local.options & IPCP_N_COMPRESS) == FALSE)      {#if PPP_TRACE        ppp_log("uncompressed TCP/IP not enabled");#endif        ++Ppp->rxError;        goto proc_err;      }      if (vjhc_remember(&Ppp->comp, pppRcvBuf))      {#if PPP_TRACE        ppp_log("uncompressed TCP/IP packet error");#endif        ++Ppp->rxError;        goto proc_err;      }      tcpDataInd(pppRcvBuf);      pppRcvBuf = NULL;      break;    /*-----------------------------------------------------------------*/    /* Link Control Protocol                                           */    /*-----------------------------------------------------------------*/    case PPP_LCP_PROTO:      ++Ppp->rxOctet[kLCP];      PppFsmProc(&Ppp->fsm[kLCP]);      break;    /*-----------------------------------------------------------------*/    /* Password Authentication Protocol                                */    /*-----------------------------------------------------------------*/    case PPP_PAP_PROTO:      if ((Ppp->phase == pppAUTHEN) || (Ppp->phase == pppNETWORK))      {        ++Ppp->rxOctet[kPAP];        papProc(&Ppp->fsm[kPAP], buf);        break;      }      else      {#if PPP_TRACE        ppp_log("not ready for authentication");#endif        ++Ppp->rxError;        goto proc_err;      }    /*-----------------------------------------------------------------*/    /* Challenge Handshake Authentication Protocol                     */    /*-----------------------------------------------------------------*/    case PPP_CHAP_PROTO:      if ((Ppp->phase == pppAUTHEN) || (Ppp->phase == pppNETWORK))      {        ++Ppp->rxOctet[kCHAP];        chapProc(&Ppp->fsm[kCHAP], buf);        break;      }      else      {#if PPP_TRACE        ppp_log("not ready for authentication");#endif        ++Ppp->rxError;        goto proc_err;      }    /*-----------------------------------------------------------------*/    /* IP Control Protocol                                             */    /*-----------------------------------------------------------------*/    case PPP_IPCP_PROTO:      /*---------------------------------------------------------------*/      /* Check if a success or authentication-ack message was lost.    */      /*---------------------------------------------------------------*/      if ((Ppp->phase == pppAUTHEN) &&          (Ppp->lcp.remote.options & LCP_N_AUTHENT))      {        switch (Ppp->lcp.remote.auth_proto)        {          case PPP_CHAP_PROTO:            chapNcpMsg();

⌨️ 快捷键说明

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