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

📄 pppchat.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
  /* Return the number of characters transferred to the driver.        */  /*-------------------------------------------------------------------*/  return initial_room - room;}/***********************************************************************//*    data_ind: Called by serial driver to report incoming data        *//*                                                                     *//*      Inputs: handle = pointer to PPP control block                  *//*              src = pointer to driver data                           *//*              length = amount of driver data                         *//*              increment = 0 if from FIFO, 1 if from buffer           *//*                                                                     *//*    Note (1): May be called by either the TCP/IP task or an ISR      *//*    Note (2): If overrun occurs, earlier data is lost. CHAT may not  *//*              miss it. Otherwise, it must retry to recover.          *//*                                                                     *//***********************************************************************/static void data_ind(void *handle, ui8 *src, int length, int increment){  PPP ppp = handle;  /*-------------------------------------------------------------------*/  /* Loop until out of data.                                           */  /*-------------------------------------------------------------------*/  do  {    /*-----------------------------------------------------------------*/    /* Copy driver character and update source pointer.                */    /*-----------------------------------------------------------------*/    *ppp->chat.uart_put = *src;    src += increment;    /*-----------------------------------------------------------------*/    /* Advance driver's "put" pointer, wrapping around as necessary.   */    /*-----------------------------------------------------------------*/    if (ppp->chat.uart_put == &ppp->chat.rcv_buf[RBUF_LEN - 1])      ppp->chat.uart_put = ppp->chat.rcv_buf;    else      ++ppp->chat.uart_put;  }  while (--length);  /*-------------------------------------------------------------------*/  /* If interpreter is waiting for a receive character, release it.    */  /*-------------------------------------------------------------------*/  if (ppp->chat.minor_state == WAIT_FOR_CHAR)  {    ppp->chat.minor_state = EXPECTING;    pppAttnReq(do_chat, ppp);  }}/***********************************************************************//*  next_state: Set the next CHAT state                                *//*                                                                     *//***********************************************************************/static void next_state(void){  int i, state = Ppp->chat.major_state;  ChatCfg *cfg = &Ppp->public.chat;  /*-------------------------------------------------------------------*/  /* Clear abort strings from previous script.                         */  /*-------------------------------------------------------------------*/  for (i = 0; i < CHAT_ABORTS; ++i)    Ppp->chat.abort[i].string = NULL;  /*-------------------------------------------------------------------*/  /* If an init script is present, run it.                             */  /*-------------------------------------------------------------------*/  if ((state < INITIALIZING) && cfg->init)  {    Ppp->chat.major_state = INITIALIZING;    Ppp->chat.script = cfg->init;    pppAttnReq(do_chat, Ppp);  }  /*-------------------------------------------------------------------*/  /* Else if dial script is present, run it.                           */  /*-------------------------------------------------------------------*/  else if ((state < DIALING) && cfg->dial)  {    Ppp->chat.major_state = DIALING;    Ppp->chat.script = cfg->dial;    pppAttnReq(do_chat, Ppp);  }  /*-------------------------------------------------------------------*/  /* Else if login script is present, run it.                          */  /*-------------------------------------------------------------------*/  else if ((state < LOGGING_IN) && cfg->login)  {    Ppp->chat.major_state = LOGGING_IN;    Ppp->chat.script = cfg->login;    pppAttnReq(do_chat, Ppp);  }  /*-------------------------------------------------------------------*/  /* Else if finishing, post event and disconnect serial interface.    */  /*-------------------------------------------------------------------*/  else if (state == FINISHING)  {    /*-----------------------------------------------------------------*/    /* If transmitter is idle, complete shutdown, else wait for idle.  */    /*-----------------------------------------------------------------*/    isrMask();    if (Ppp->uart.idle)    {      isrUnmask();      pppFinish();    }    else    {      Ppp->chat.minor_state = WAIT_FOR_IDLE;      isrUnmask();    }  }  /*-------------------------------------------------------------------*/  /* Else, CHAT has successfully processed all scripts.                */  /*-------------------------------------------------------------------*/  else  {    /*-----------------------------------------------------------------*/    /* Install the PPP receive data handler.                           */    /*-----------------------------------------------------------------*/    Ppp->public.data_ind = uartDataInd;    /*-----------------------------------------------------------------*/    /* If transmitter is idle, complete bring up, else wait for idle.  */    /*-----------------------------------------------------------------*/    isrMask();    if (Ppp->uart.idle)    {      isrUnmask();      chat_up();    }    else    {      Ppp->chat.minor_state = WAIT_FOR_IDLE;      isrUnmask();    }  }}/***********************************************************************//*     chat_up: CHAT is up, send notification to upper layer           *//*                                                                     *//***********************************************************************/static void chat_up(void){  /*-------------------------------------------------------------------*/  /* Install the PPP transmit data handler.                            */  /*-------------------------------------------------------------------*/  Ppp->public.data_req = uartDataReq;  /*-------------------------------------------------------------------*/  /* Free buffer allocated for CHAT send and receive use.              */  /*-------------------------------------------------------------------*/  tcpRetBuf(&Ppp->chat.buf);  Ppp->chat.rcv_buf = Ppp->chat.snd_buf = NULL;  /*-------------------------------------------------------------------*/  /* Report "up" event.                                                */  /*-------------------------------------------------------------------*/#if PPP_TRACE  pppLogn("CHAT layer up");#endif  Ppp->phase = pppLCP;  pppFsmUp(&Ppp->fsm[kLCP]);}/***********************************************************************//* Global Function Definitions                                         *//***********************************************************************//***********************************************************************//*    chatInit: Perform CHAT one-time initialization                   *//*                                                                     *//***********************************************************************/void chatInit(PPP ppp){  ppp->chat.timer.object = ppp;  INIT_TMR(ppp->chat.timer);  ppp->chat.num_trys = 0;}/***********************************************************************//*   chatStart: Starts CHAT processing                                 *//*                                                                     *//***********************************************************************/void chatStart(void *handle){  Ppp = handle;  /*-------------------------------------------------------------------*/  /* Allocate a buffer for send and receive use.                       */  /*-------------------------------------------------------------------*/  Ppp->chat.buf = tcpGetBuf(STR_LEN + RBUF_LEN + SBUF_LEN);  if (Ppp->chat.buf == NULL)  {#if PPP_TRACE    pppLogn("CHAT unable to allocate buffer");#endif    pppFinish();    return;  }  Ppp->chat.rcv_buf = (char *)&Ppp->chat.buf->data[RBUF_START];  Ppp->chat.snd_buf = (char *)&Ppp->chat.buf->data[SBUF_START];  /*-------------------------------------------------------------------*/  /* Take over the serial interface.                                   */  /*-------------------------------------------------------------------*/  Ppp->public.data_ind = data_ind;  Ppp->public.data_req = data_req;  Ppp->chat.uart_get = Ppp->chat.output = Ppp->chat.snd_buf;  Ppp->chat.uart_put = Ppp->chat.match.compare = Ppp->chat.rcv_buf;  Ppp->chat.sb_count = 0;  /*-------------------------------------------------------------------*/  /* Perform initialization required for each CHAT retry.              */  /*-------------------------------------------------------------------*/  Ppp->chat.minor_state = INTERPRETING;  Ppp->chat.major_state = STARTING;  Ppp->chat.timeout = TICKS_PER_SEC * DEFAULT_TIMEOUT;  Ppp->uart.idle = TRUE;  /*-------------------------------------------------------------------*/  /* Start the serial controller.                                      */  /*-------------------------------------------------------------------*/  if (Ppp->public.connect())  {    pppFinish();    return;  }  /*-------------------------------------------------------------------*/  /* Set the CHAT state and start the interpretor.                     */  /*-------------------------------------------------------------------*/  next_state();}/***********************************************************************//*    chatDown: CHAT is going down, free resources and stop timer      *//*                                                                     *//***********************************************************************/void chatDown(void){  /*-------------------------------------------------------------------*/  /* Ensure CHAT send and receive buffer is free.                      */  /*-------------------------------------------------------------------*/  if (Ppp->chat.buf)    tcpRetBuf(&Ppp->chat.buf);  Ppp->chat.rcv_buf = Ppp->chat.snd_buf = NULL;  /*-------------------------------------------------------------------*/  /* Ensure CHAT timer is stopped.                                     */  /*-------------------------------------------------------------------*/  NetTimerStop(&Ppp->chat.timer);}/***********************************************************************//*   chatClose: Take over serial interface and run "hangup" script     *//*                                                                     *//***********************************************************************/void chatClose(void *handle){  Ppp = handle;  /*-------------------------------------------------------------------*/  /* Allocate a buffer for send and receive use.                       */  /*-------------------------------------------------------------------*/  Ppp->chat.buf = tcpGetBuf(STR_LEN + RBUF_LEN + SBUF_LEN);  if (Ppp->chat.buf == NULL)  {#if PPP_TRACE    pppLogn("CHAT unable to allocate buffer");#endif    pppFinish();    return;  }  Ppp->chat.rcv_buf = (char *)&Ppp->chat.buf->data[RBUF_START];  Ppp->chat.snd_buf = (char *)&Ppp->chat.buf->data[SBUF_START];  /*-------------------------------------------------------------------*/  /* Take over the serial interface.                                   */  /*-------------------------------------------------------------------*/  isrMask();  Ppp->public.data_ind = data_ind;  Ppp->public.data_req = data_req;  Ppp->chat.uart_get = Ppp->chat.output = Ppp->chat.snd_buf;  Ppp->chat.uart_put = Ppp->chat.match.compare = Ppp->chat.rcv_buf;  Ppp->chat.sb_count = 0;  isrUnmask();  /*-------------------------------------------------------------------*/  /* Run hangup script.                                                */  /*-------------------------------------------------------------------*/  Ppp->chat.minor_state = INTERPRETING;  Ppp->chat.major_state = FINISHING;  Ppp->chat.script = Ppp->public.chat.hangup;  pppAttnReq(do_chat, Ppp);}#endif

⌨️ 快捷键说明

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