usrPPPCfg.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:6k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrPPPCfg.c - Configlette for configuring PPP */
  2. /* Copyright 1992 - 1998 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01a,18aug98,ann  created this configlette from usrNetwork.c
  7. */
  8. /*
  9. DESCRIPTION
  10. This configlette contains the init routine for the INCLUDE_PPP 
  11. component. The usrPPPInit routine is actually called from
  12. usrNetPPPBoot.c
  13. NOMANUAL
  14. */
  15. #include "pppLib.h"
  16. #include "netinet/ppp/options.h"
  17. #ifndef PPP_OPTIONS_FLAGS
  18. #define PPP_OPTIONS_FLAGS ((PPP_OPT_NO_ALL << PPP_S_NO_ALL)  | 
  19.     (PPP_OPT_PASSIVE_MODE << PPP_S_PASSIVE_MODE)             | 
  20.     (PPP_OPT_SILENT_MODE << PPP_S_SILENT_MODE)               | 
  21.     (PPP_OPT_DEFAULTROUTE << PPP_S_DEFAULTROUTE)             | 
  22.     (PPP_OPT_PROXYARP << PPP_S_PROXYARP)                     | 
  23.     (PPP_OPT_IPCP_ACCEPT_LOCAL << PPP_S_IPCP_ACCEPT_LOCAL)   | 
  24.     (PPP_OPT_IPCP_ACCEPT_REMOTE << PPP_S_IPCP_ACCEPT_REMOTE) | 
  25.     (PPP_OPT_NO_IP << PPP_S_NO_IP)                           | 
  26.     (PPP_OPT_NO_ACC << PPP_S_NO_ACC)                         | 
  27.     (PPP_OPT_NO_PC << PPP_S_NO_PC)                           | 
  28.     (PPP_OPT_NO_VJ << PPP_S_NO_VJ)                           | 
  29.     (PPP_OPT_NO_VJCCOMP << PPP_S_NO_VJCCOMP)                 | 
  30.     (PPP_OPT_NO_ASYNCMAP << PPP_S_NO_ASYNCMAP)               | 
  31.     (PPP_OPT_NO_MN << PPP_S_NO_MN)                           | 
  32.     (PPP_OPT_NO_MRU << PPP_S_NO_MRU)                         | 
  33.     (PPP_OPT_NO_PAP << PPP_S_NO_PAP)                         | 
  34.     (PPP_OPT_NO_CHAP << PPP_S_NO_CHAP)                       | 
  35.     (PPP_OPT_REQUIRE_PAP << PPP_S_REQUIRE_PAP)               | 
  36.     (PPP_OPT_REQUIRE_CHAP << PPP_S_REQUIRE_CHAP)             | 
  37.     (PPP_OPT_LOGIN << PPP_S_LOGIN)                           | 
  38.     (PPP_OPT_DEBUG << PPP_S_DEBUG)                           | 
  39.     (PPP_OPT_DRIVER_DEBUG << PPP_S_DRIVER_DEBUG))
  40. #endif  /* PPP_OPTIONS_FLAGS */
  41.  
  42. PPP_OPTIONS pppOptions = 
  43.     {
  44.     PPP_OPTIONS_FLAGS,              /* flags field */
  45.     PPP_STR_ASYNCMAP,               /* Set the desired async map */
  46.     PPP_STR_ESCAPE_CHARS,           /* Set chars to escape on transmission */
  47.     PPP_STR_VJ_MAX_SLOTS,           /* Set max VJ compression header slots */
  48.     PPP_STR_NETMASK,                /* Set netmask value for negotiation */
  49.     PPP_STR_MRU,                    /* Set MRU value for negotiation */
  50.     PPP_STR_MTU,                    /* Set MTU value for negotiation */
  51.     PPP_STR_LCP_ECHO_FAILURE,       /* Set max consecutive LCP echo failures */
  52.     PPP_STR_LCP_ECHO_INTERVAL,      /* Set time for LCP echo requests */
  53.     PPP_STR_LCP_RESTART,            /* Set timeout for LCP */
  54.     PPP_STR_LCP_MAX_TERMINATE,      /* Set max # xmits for LCP term-reqs */
  55.     PPP_STR_LCP_MAX_CONFIGURE,      /* Set max # xmits for LCP conf-reqs */
  56.     PPP_STR_LCP_MAX_FAILURE,        /* Set max # conf-naks for LCP */
  57.     PPP_STR_IPCP_RESTART,           /* Set timeout for IPCP */
  58.     PPP_STR_IPCP_MAX_TERMINATE,     /* Set max # xmits for IPCP term-reqs */
  59.     PPP_STR_IPCP_MAX_CONFIGURE,     /* Set max # xmits for IPCP conf-reqs */
  60.     PPP_STR_IPCP_MAX_FAILURE,       /* Set max # conf-naks for IPCP */
  61.     PPP_STR_LOCAL_AUTH_NAME,        /* Set local name for authentication */
  62.     PPP_STR_REMOTE_AUTH_NAME,       /* Set remote name for authentication */
  63.     PPP_STR_PAP_FILE,               /* Set the PAP secrets file */
  64.     PPP_STR_PAP_USER_NAME,          /* Set username for PAP auth with peer */
  65.     PPP_STR_PAP_PASSWD,             /* Set password for PAP auth with peer */
  66.     PPP_STR_PAP_RESTART,            /* Set timeout for PAP */
  67.     PPP_STR_PAP_MAX_AUTHREQ,        /* Set max # xmits for PAP auth-reqs */
  68.     PPP_STR_CHAP_FILE,              /* Set the CHAP secrets file */
  69.     PPP_STR_CHAP_RESTART,           /* Set timeout for CHAP */
  70.     PPP_STR_CHAP_INTERVAL,          /* Set interval for CHAP rechallenge */
  71.     PPP_STR_CHAP_MAX_CHALLENGE      /* Set max # xmits for CHAP challenge */
  72.     };
  73. /********************************************************************************
  74. * usrPPPInit - initialize a ppp channel
  75. *
  76. * RETURNS: OK if successful, otherwise ERROR.
  77. *
  78. * NOMANUAL
  79. */
  80.  
  81. STATUS usrPPPInit 
  82.     (
  83.     char *      pBootDev, /* boot device */
  84.     int  unitNum,  /* unit number */
  85.     char *      localAddr, /* local address */
  86.     char *      peerAddr /* peer address */
  87.     )
  88.     {
  89. #ifdef INCLUDE_PPP
  90.     PPP_INFO    pppInfo;
  91.     PPP_OPTIONS *pOptions = NULL;
  92.     char        pppTyDev [20];           /* ppp device */
  93. #ifdef PPP_BAUDRATE
  94.     int pppBaudRate = PPP_BAUDRATE; /* ppp baud rate */
  95. #else
  96.     int pppBaudRate = 0; /* ppp baud rate */
  97. #endif /* PPP_BAUDRATE */
  98.     char * pBaudStr; /* ppp boot string */
  99.     int         netmask;                 /* netmask */
  100.     int         sysRate = sysClkRateGet(); /* system clock rate */
  101.     int         ix;
  102. #ifdef PPP_OPTIONS_STRUCT
  103.     pOptions = &pppOptions;
  104. #endif /* PPP_OPTIONS_STRUCT */
  105.     if ((pBaudStr = strpbrk (pBootDev, ",")) != NULL)
  106.         {
  107. *pBaudStr++ = '';
  108. pppBaudRate = atoi (pBaudStr);
  109. }
  110.     if (pBootDev [3] == '=')
  111.         {
  112.         /* get the tty device used for PPP interface e.g. "ppp=/tyCo/1" */
  113.         strcpy (pppTyDev, &pBootDev [4]);
  114.         pBootDev [3] = '';
  115.         }
  116.     else 
  117.         {
  118.         /* construct the default PPP tty device */
  119.         sprintf (pppTyDev, "%s%d", "/tyCo/", PPP_TTY);
  120.         }
  121.  
  122.     printf ("Attaching network interface ppp%d...n", unitNum);
  123.  
  124.     bootNetmaskExtract (localAddr, &netmask); /* remove and ignore mask */
  125.  
  126.     if (pppInit (unitNum, pppTyDev, localAddr, peerAddr, pppBaudRate,
  127.  pOptions, PPP_OPTIONS_FILE) == ERROR)
  128.         {
  129.         printf ("npppInit failed 0x%xn", errno);
  130.         return (ERROR);
  131.         }
  132.  
  133.     /* wait for PPP link to be established */
  134.     for (ix = 0; ix < PPP_CONNECT_DELAY; ix++)
  135.         {
  136.         taskDelay (sysRate);
  137.         if ((pppInfoGet (unitNum, &pppInfo) == OK) &&
  138.             ((pppInfo.ipcp_fsm.state == OPENED) ||
  139.      (pppInfo.lcp_wantoptions.silent) ||
  140.      (pppInfo.lcp_wantoptions.passive)))
  141.            break;
  142.         }
  143.     if (ix == PPP_CONNECT_DELAY)
  144.         {
  145.   pppDelete (unitNum); /* kill the interface */
  146.         printf ("ppp0: timeout: could not establish link with peer.n");
  147.         return (ERROR);
  148.   }
  149.  
  150. #if CPU==SIMSPARCSOLARIS
  151.      /* Add default route thru ppp gateway */
  152.     routeAdd ("0.0.0.0", peerAddr);
  153.     routeAdd (localAddr, "127.0.0.1"); /* loopback for local addresses */
  154. #endif
  155.     printf ("done.n");
  156.     return (OK);
  157.      
  158. #else /* INCLUDE_PPP */
  159.     printf ("nError: ppp not included.n");
  160.     return (ERROR);
  161. #endif  /* INCLUDE_PPP */
  162.     }