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

📄 ipcp.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
📖 第 1 页 / 共 3 页
字号:
               else 
               {
                  go->ouraddr = ciaddr2;     /* accept peer's idea */
               }
            }
            if (go->ouraddr == 0L) { /*ConPrintf("ipcp_reqci: ouraddr==0.0.0.0\n");*/ }
            ho->old_addrs = 1;
            ho->ouraddr = ciaddr2;
         }
#endif   /* PPP_OLDFORMS */

         ho->neg_addr = 1;
         ho->hisaddr = ciaddr1;
         //ConPrintf("\n");
         break;

      case CI_COMPRESSTYPE:
        // ConPrintf("ipcp: received COMPRESSTYPE ");
#ifdef PPP_VJC
         if ((!wo->neg_vj) ||
             (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
         {
            orc = CONFREJ;
            break;
         }
         cishort = ppp_getshort(p + 2);   /* get the compress type */
         //ConPrintf("(%d)", cishort);
         if (!(cishort == IPCP_VJ_COMP ||
             (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) 
         {
            orc = CONFREJ;
            break;
         }

         ho->neg_vj = 1;
         ho->vj_protocol = cishort;
         if (cilen == CILEN_VJ) 
         {
            maxslotindex = *(p + 4);
            if (maxslotindex > wo->maxslotindex) 
            {
               orc = CONFNAK;
               if (!reject_if_disagree)
               {
                  *(p + 4) = wo->maxslotindex;
               }
            }
            cflag = *(p + 5);
            if (cflag && !wo->cflag) 
            {
               orc = CONFNAK;
               if (!reject_if_disagree)
               {
                  *(p +4) = wo->cflag;
               }
            }
            ho->maxslotindex = maxslotindex;
            ho->cflag = wo->cflag;
         }
#else    /* not PPP_VJC */
         /* we don't suport VJ compression, reject it */
         orc = CONFREJ;
#endif   /* not PPP_VJC */
         break;

#ifdef PPP_DNS          
      case CI_DNSADDR_PRI:
      case CI_DNSADDR_SEC:
         //ConPrintf("ipcp: received DNSADDR(%x) ", citype);

         tl = ppp_getlong(p + 2);
         ciaddr1 = htonl(tl);
         //ConPrintf("(%u.%u.%u.%u.)", PUSH_IPADDR(ciaddr1) );
         if((ciaddr1 == 0) || (wo->accept_dnsaddrs == 0))
         {
            orc = CONFNAK;
            if (!reject_if_disagree)
            {
               tl = ntohl(wo->dnsaddr_pri);
               ppp_putlong(p + 2, tl);
            }
            break;
         }
         if(citype == CI_DNSADDR_PRI)
         {
            ho->neg_dnsaddr_pri = 1;
            ho->dnsaddr_pri = ciaddr1;
         }
         else  /* not primary, must be secondary */
         {
            ho->neg_dnsaddr_sec = 1;
            ho->dnsaddr_sec = ciaddr1;
         }
         break;
#endif   /* PPP_DNS */

      default:
         orc = CONFREJ;
         break;
      }

endswitch:
      //ConPrintf(" (%s)\n", CODENAME(orc));

      if((orc == CONFACK) &&     /* Good CI */
          (rc != CONFACK))       /*  but prior CI wasnt? */
      {
         continue;               /* Don't send this one */
      }

      if (orc == CONFNAK)        /* Nak this CI? */
      {
         if (reject_if_disagree) /* Getting fed up with sending NAKs? */
            orc = CONFREJ;       /* Get tough if so */
         else 
         {
            if (rc == CONFREJ)   /* Rejecting prior CI? */
               continue;         /* Don't send this one */
            if (rc == CONFACK)   /* Ack'd all prior CIs? */
            {
               rc = CONFNAK;     /* Not anymore... */
               ucp = inp;        /* Backup */
            }
         }
      }

      if (orc == CONFREJ &&      /* Reject this CI */
          rc != CONFREJ)         /*  but no prior ones? */
      {
         rc = CONFREJ;
         ucp = inp;              /* Backup */
      }

      if (ucp != p)              /* need to move CI? */
         MEMCPY(ucp, p, cilen);  /* move it */

      ucp += cilen;     /* Update output pointer */
      p += cilen;       /* Update input pointer */
   }

#ifdef PPP_OTHERIP
   /* If we aren't rejecting this packet, and we want to negotiate
    * their address, and they didn't send their address, then we
    * send a NAK with a CI_ADDR option appended.  We assume the
    * input buffer is long enough that we can append the extra
    * option safely.
    */
   if ((rc != CONFREJ) &&
      (!ho->neg_addr ) &&
      (wo->req_addr) &&
      (!reject_if_disagree) &&
      (!nakaddrdone))
   {
      if (rc == CONFACK) 
      {
         rc = CONFNAK;
         ucp = inp;           /* reset pointer */
         wo->req_addr = 0;    /* don't ask again */
      }
      *ucp++ = CI_ADDR;
      *ucp++ = CILEN_ADDR;
      tl = ntohl(wo->hisaddr);
      ucp = ppp_putlong(ucp, tl);
      nakaddrdone = 1;
   }
#else
   USE_ARG(nakaddrdone);
#endif /* PPP_OTHERIP */

   *lenp = ucp - inp;          /* Compute output length */
   //ConPrintf("ipcp: returning Configure-%s", CODENAME(rc));

   /* RFC1661 actions (pg 10) don't distinguish between send-conf-nak and
    * send-conf-reject; however we need to. Set the PPP flags bit to
    * indicate to the logic which will form the NAK/REJ reply which code
    * to use.
    */
   if(rc == CONFREJ)
      mppp->pppflags |= SEND_REJECT;
   else
      mppp->pppflags &= ~SEND_REJECT;

   return (rc);               /* Return final code */
}

/* (yaxon add) */
extern void PPP_Established(void);

/* FUNCTION: ipcp_up()
 *
 * ipcp_up - IPCP has come UP.
 * Configure the IP network interface appropriately and bring it up.
 *
 * PARAM1: M_PPP mppp
 *
 * RETURNS: 
 */

void
ipcp_up(M_PPP mppp)
{
   ipcp_options * ho = &mppp->ipcp_hisoptions;
   ipcp_options * go = &mppp->ipcp_gotoptions;

   //ConPrintf("ipcp: up");
   go->default_route = 0;
   go->proxy_arp = 0;

#ifdef PPP_OTHERIP
   /* make sure other guy sent a real IP address */
   if (ho->hisaddr == 0)
   {
      //ConPrintf("Could not determine remote IP address");
      ppp_close(mppp, LCP_STATE);
      return;
   }

   /* Check that the peer is allowed to use the IP address he wants. */
   if (!ppp_authaddr(mppp, ho->hisaddr)) 
   {
      //ConPrintf("Peer is not authorized to use remote address %u.%u.%u.%u.",
         //PUSH_IPADDR(ho->hisaddr));
      ppp_close(mppp, LCP_STATE);
      return;
   }
#endif   /* PPP_OTHERIP */

   /* We must have a non-zero IP address for both ends of the link. */
   if (!ho->neg_addr)
      ho->hisaddr = mppp->ipcp_wantoptions.hisaddr;

   if (go->ouraddr == 0) 
   {
   //   ConPrintf("Could not determine local IP address");
#ifndef DHCP_CLIENT
      ppp_close(mppp, LCP_STATE);
      return;
#endif
   }


  // ConPrintf("IPCP: local  IP address %u.%u.%u.%u",
     //       PUSH_IPADDR(go->ouraddr));
#ifdef PPP_OTHERIP
 //  ConPrintf("IPCP: remote IP address %u.%u.%u.%u",
    //        PUSH_IPADDR(ho->hisaddr));
#endif   /* PPP_OTHERIP */

   /* Set IP addresses  */
   if (!ppp_setaddr(mppp, go->ouraddr)) 
   {
     // ConPrintf("setaddr failed");
      ppp_close(mppp, LCP_STATE);
      return;
   }

#ifdef PPP_VJC
   /* set tcp compression before we send DHCP packet */
   sifvjcomp(mppp, go->neg_vj, go->maxslotindex, go->cflag);
#endif   /* PPP_VJC */

#ifdef PPP_DHCP_CLIENT
   if (mppp->pppflags & IPCP_DHCP)
   {
      ppp_start_dhcp(mppp);   /* start dhcp transaction */
   }
#endif   /* PPP_DHCP_CLIENT */

   /* bring the interface up for IP */
   if (!ppp_ifup(mppp)) 
   {
   //   ConPrintf("sifup failed");
      ppp_close(mppp, LCP_STATE);
      return;
   }

   /* assign a default route through the interface if required */
   if (mppp->ipcp_wantoptions.default_route) 
      if (ppp_setroute(mppp, ho->hisaddr))
         go->default_route = 1;

#ifdef PROXY_ARP
#ifndef PPP_OTHERIP
#error PROXY_ARP requires PPP_OTHERIP define
#endif /* PPP_OTHERIP */
   /* Make a proxy ARP entry if requested. */
   if (mppp->ipcp_wantoptions.proxy_arp)
      if (ppp_setproxyarp(mppp, ho->hisaddr))
         go->proxy_arp = 1;
#endif   /* PROXY_ARP */

#ifdef PPP_DNS
   /* if we got nameserver addresses from the peer, set them */
   if (mppp->ipcp_gotoptions.neg_dnsaddr_pri)
      if (!ppp_setdnsaddr(mppp, go->dnsaddr_pri))
         go->neg_dnsaddr_pri = 0;
   if (mppp->ipcp_gotoptions.neg_dnsaddr_sec)
      if (!ppp_setdnsaddr(mppp, go->dnsaddr_sec))
         go->neg_dnsaddr_sec = 0;
#endif   /* PPP_DNS */

   /* (yaxon add) */
   PPP_Established();
   return;
}


/* FUNCTION: ipcp_down()
 *
 * ipcp_down - IPCP has gone DOWN.
 * Take the IP network interface down, clear its addresses
 * and delete routes through it.
 *
 * 
 * PARAM1: fsm * f
 *
 * RETURNS: 
 */

void
ipcp_down(M_PPP mppp)
{
   //ConPrintf("ipcp: down");

#ifdef PPP_DNS
   if (mppp->ipcp_gotoptions.neg_dnsaddr_sec)
      ppp_cleardnsaddr(mppp, mppp->ipcp_gotoptions.dnsaddr_sec);
   if (mppp->ipcp_gotoptions.neg_dnsaddr_pri)
      ppp_cleardnsaddr(mppp, mppp->ipcp_gotoptions.dnsaddr_pri);
#endif   /* PPP_DNS */

#ifdef PPP_MULTILINK
   mppp->pppflags &= ~ML_IPCP;   /* clear multilink bundle flag */
#endif  

   ppp_ifdown(mppp);
   ppp_clearaddr(mppp);
}



/* FUNCTION: ipcp_started()
 *
 * This-Layer-Started (tls) event for IPCP
 *
 * Called when the IPCP layer is started by the application. 
 * 
 * PARAM1: fsm * f
 *
 * RETURNS: 
 */

void
ipcp_started(M_PPP mppp)
{
   ppp_open(mppp, LCP_STATE);
}

/* FUNCTION: ipcp_finished()
 *
 * This-Layer-Started (tls) event for IPCP
 *
 * Called when the IPCP layer is started by the application. 
 * 
 * PARAM1: fsm * f
 *
 * RETURNS: 
 */

void
ipcp_finished(M_PPP mppp)
{
   ppp_close(mppp, LCP_STATE);
}

#endif   /* USE_PPP */

/* end of file ipcp.c */


        

⌨️ 快捷键说明

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