📄 ppp.c
字号:
break; case PPP_PAP_PROTO: break; } } /*---------------------------------------------------------------*/ /* If in network phase, accept IPCP packet, else error. */ /*---------------------------------------------------------------*/ if (Ppp->phase == pppNETWORK) { ++Ppp->rxOctet[kIPCP]; PppFsmProc(&Ppp->fsm[kIPCP]); } else {#if PPP_TRACE ppp_log("not ready for IPCP traffic");#endif ++Ppp->rxError; goto proc_err; } break; /*-----------------------------------------------------------------*/ /* Unknown Protocol */ /*-----------------------------------------------------------------*/ default:#if PPP_TRACE pppLogn("PPP Unknown protocol: 0x%x", protocol);#endif ++Ppp->rxUnknown; /*---------------------------------------------------------------*/ /* Unknown protocol. Check if LCP layer is open. */ /*---------------------------------------------------------------*/ if (Ppp->fsm[kLCP].state == fsmOPENED) { /*-------------------------------------------------------------*/ /* Prepend 16 bit protocol field. */ /*-------------------------------------------------------------*/ pppRcvBuf->ip_pkt -= 2; pppRcvBuf->length += 2; put16(buf->ip_pkt, protocol); /*-------------------------------------------------------------*/ /* Send protocol reject packet. */ /*-------------------------------------------------------------*/ pppFsmSend(&Ppp->fsm[kLCP], PROT_REJ, 0, pppRcvBuf); pppRcvBuf = NULL; } break; } /*-------------------------------------------------------------------*/ /* Unless passed on to the TCP/IP stack, free the receive buffer. */ /*-------------------------------------------------------------------*/ if (pppRcvBuf) tcpRetBuf(&pppRcvBuf); return; /*-------------------------------------------------------------------*/ /* An error was found in the incoming packet. */ /*-------------------------------------------------------------------*/proc_err: vjhc_toss(&Ppp->comp); tcpRetBuf(&pppRcvBuf);}/***********************************************************************//* pppStart: PPP channel initialization and bringup *//* *//***********************************************************************/void pppStart(void *handle){ /*-------------------------------------------------------------------*/ /* Set global PPP channel identifier before calling other routines. */ /*-------------------------------------------------------------------*/ Ppp = handle; /*-------------------------------------------------------------------*/ /* Send Open event to IPCP and LCP layers. */ /*-------------------------------------------------------------------*/ pppFsmOpen(&Ppp->fsm[kIPCP]); pppFsmOpen(&Ppp->fsm[kLCP]); /*-------------------------------------------------------------------*/ /* If CHAT scripts will be used, pass control to CHAT interpreter. */ /*-------------------------------------------------------------------*/ if (Ppp->public.chat.init || Ppp->public.chat.dial || Ppp->public.chat.hangup) { Ppp->phase = pppCHAT; chatStart(Ppp); } /*-------------------------------------------------------------------*/ /* Otherwise, start the serial controller and report "up" event. */ /*-------------------------------------------------------------------*/ else { Ppp->phase = pppLCP; if (Ppp->public.connect()) { pppFinish(); return; }#if PPP_TRACE pppLogn("serial controller up");#endif pppFsmUp(&Ppp->fsm[kLCP]); }}/***********************************************************************//* pppFinished: Shutdown the state machines and serial controller *//* *//***********************************************************************/void pppFinish(void){ /*-------------------------------------------------------------------*/ /* Nothing needed if already down. */ /*-------------------------------------------------------------------*/ if (Ppp->phase == pppDEAD) return; /*-------------------------------------------------------------------*/ /* Bring serial interface down. */ /*-------------------------------------------------------------------*/ Ppp->public.disconnect();#if PPP_TRACE pppLogn("serial controller down");#endif /*-------------------------------------------------------------------*/ /* Stop state machines and timer. Set phase to dead. */ /*-------------------------------------------------------------------*/ if (Ppp->fsm[kLCP].state > fsmSTARTING) pppFsmDown(&Ppp->fsm[kLCP]); chatDown(); NetTimerStop(&Ppp->timer); NetTimerStop(&Ppp->timer2); Ppp->phase = pppDEAD; Ppp->public.flags |= PPPF_DEAD; /*-------------------------------------------------------------------*/ /* Report down event if handler is present. */ /*-------------------------------------------------------------------*/ if (Ppp->public.report) Ppp->public.report(Ppp, NIE_DOWN);}/***********************************************************************//* pppIps: Convert IP address to dotted format string *//* *//* Input: address = IP address *//* *//* Returns: pointer to string *//* *//* Note: address is assumed to be in network order *//* *//***********************************************************************/char *pppIps(ui32 address){ static char string[16]; ui8 b1, b2, b3, b4; address = ntohl(address); b1 = (ui8)(address >> 24); b2 = (ui8)(address >> 16); b3 = (ui8)(address >> 8); b4 = (ui8)(address); sprintf(string, "%u.%u.%u.%u", b1, b2, b3, b4); return string;}/***********************************************************************//* pppPrintCfg: Print PPP configuration *//* *//***********************************************************************/void pppPrintCfg(CPPP ppp){ int i; printf("PPP Configuration\nLocal Options\n"); printf("option bits = 0x%08X\n", ppp->lcp.local.options); printf("mru = %u\n", ppp->lcp.local.mru); printf("accm = 0x%08X\n", ppp->rx_accm); if (ppp->lcp.local.options & LCP_N_AUTHENT) printf("auth proto = 0x%04X\n", ppp->lcp.local.auth_proto); printf("magic = 0x%08X\n", ppp->lcp.local.magic); printf("comp proto = 0x%04X, slots = %u, flag = %u\n", ppp->ipcp.local.comp_proto, ppp->ipcp.local.slots, ppp->ipcp.local.comp_slot); if (ppp->public.flags & PPPF_NI_UP) printf("IP address = %s\n", pppIps(ppp->public.ni.ip_addr)); printf("\nRemote Options\n"); printf("option bits = 0x%08X\n", ppp->lcp.remote.options); printf("mru = %u\n", ppp->lcp.remote.mru); printf("accm = "); for (i = 0; i < 8; ++i) { printf("0x%08X ", ppp->tx_accm[i]); if (i == 3) printf("\n "); } putchar('\n'); if (ppp->lcp.remote.options & LCP_N_AUTHENT) printf("auth proto = 0x%04X\n", ppp->lcp.remote.auth_proto); printf("magic = 0x%08X\n", ppp->lcp.remote.magic); printf("comp proto = 0x%04X, slots = %u, flag = %u\n", ppp->ipcp.remote.comp_proto, ppp->ipcp.remote.slots, ppp->ipcp.remote.comp_slot); if (ppp->public.flags & PPPF_NI_UP) printf("IP address = %s\n", pppIps(ppp->public.ni.remote_addr));}/***********************************************************************//* pppAttnReq: PPP attention request *//* *//* Input: func = pointer to callback function *//* ppp = pointer to PPP control block *//* *//* Note: Called only by TCP/IP daemon task *//* *//***********************************************************************/void pppAttnReq(void (*func)(void *ptr), PPP ppp){ /*-------------------------------------------------------------------*/ /* If queue is full, schedule action for next timer tick. */ /*-------------------------------------------------------------------*/ if (NetPostMsg(func, ppp, ATTN_REQ)) { ppp->timer.action = func; ppp->timer.object = ppp; INIT_TMR(ppp->timer); NetTimerStart(&ppp->timer, 0); }}/***********************************************************************//* pppSigCheck: Check modem signals and age the persistence timeouts *//* of de-asserted signals *//* *//***********************************************************************/void pppSigCheck(void *handle){ int status; /*-------------------------------------------------------------------*/ /* Set global PPP channel identifier before calling other routines. */ /*-------------------------------------------------------------------*/ Ppp = handle; /*-------------------------------------------------------------------*/ /* Call driver to check modem control signals. */ /*-------------------------------------------------------------------*/ status = Ppp->public.sig_check(); /*-------------------------------------------------------------------*/ /* Check DCD if past CHAT and not requested to ignore it. */ /*-------------------------------------------------------------------*/ if ((Ppp->phase >= pppLCP) && (Ppp->public.DCD_timeout != 0xFFFF)) { if (status & kDCD) /* DCD active */ Ppp->dcd_persist = Ppp->public.DCD_timeout; else if (Ppp->dcd_persist == 0) goto ser_down; else --Ppp->dcd_persist; } /*-------------------------------------------------------------------*/ /* Check DSR if not requested to ignore it. */ /*-------------------------------------------------------------------*/ if (Ppp->public.DSR_timeout != 0xFFFF) { if (status & kDSR) /* DSR active */ Ppp->dsr_persist = Ppp->public.DSR_timeout; else if (Ppp->dsr_persist == 0) goto ser_down; else --Ppp->dsr_persist; } /*-------------------------------------------------------------------*/ /* Schedule next signal check and return. */ /*-------------------------------------------------------------------*/ NetTimerStart(&Ppp->timer2, TICKS_PER_SEC); return; /*-------------------------------------------------------------------*/ /* Post down event and end all PPP activity on this channel. */ /*-------------------------------------------------------------------*/ser_down: pppFinish();}#endif /* MAX_PPP_INTF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -