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

VxWorks

开发平台:

C/C++

  1. /* usrNetSmSecBoot.c - Start the SM as a second interface */
  2. /* Copyright 1992 - 2002 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01f,24apr02,mas  non-boot 'sm' unit number hard-coded to zero (SPR 74787); now
  7.  smNetShowInit() is properly dependent upon INCLUDE_SM_NET_SHOW
  8. 01e,08oct01,mas  code cleanup, added IP address display (SPR 4547)
  9. 01d,07feb01,spm  added merge record for 30jan01 update from version 01d of
  10.                  tor2_0_x branch (base 01b) and fixed modification history
  11. 01c,30jan01,ijm  merged SPR #28602 fixes: proxy ARP services are obsolete
  12. 01b,23mar99,dat  SPR 25877, removed old bp driver config
  13. 01a,18aug98,ann  created from usrNetwork.c
  14. */
  15. /*
  16. DESCRIPTION
  17. This file is included by the configuration tool to initialize a shared memory
  18. network device according to the parameters in the boot line. It is called by
  19. the INCLUDE_SECOND_SMNET component and attaches the backplane interface to
  20. allow shared memory communication regardless of the selected boot device.
  21. NOMANUAL
  22. */
  23. /******************************************************************************
  24. *
  25. * usrBpSecondAttach - Attach backplane interface as second interface
  26. *
  27. * This routine attaches the backplane interface if it was not used as the
  28. * boot device.  In such cases the unit number is always zero.
  29. *
  30. * RETURNS: N/A
  31. *
  32. * NOMANUAL
  33. */
  34. void usrBpSecondAttach (void)
  35.     {
  36.     char *         bpDev;
  37.     BOOL           proxyOn      = FALSE;     /* Initialize Defaults */
  38.     u_long         startAddr    = 0;         /* Default sequential Addr off */
  39.     int            proxymask    = 0;
  40.     char           netDev [BOOT_DEV_LEN + 1];
  41.     char           bpAddr [BOOT_DEV_LEN];    /* backplane IP address */
  42.     struct in_addr localAddr;
  43.     BOOL           seqAddrOn    = FALSE;
  44.     BOOL           configureBp  = TRUE;
  45.     BOOL           useEtherAddr = FALSE;
  46.     /* attach backplane interface (as second interface) */
  47. #define BP_ADDR_GIVEN           (sysBootParams.bad [0] != EOS)
  48. #define BP_ADDR_NOT_GIVEN       (sysBootParams.bad [0] == EOS)
  49.     if (!backplaneBoot)
  50.         {
  51.         /* Turn switches ON as needed */
  52. #ifdef INCLUDE_SM_SEQ_ADDR
  53.         seqAddrOn = TRUE;
  54. #endif
  55. #ifdef INCLUDE_PROXY_DEFAULT_ADDR
  56.         useEtherAddr = TRUE;
  57. #endif
  58. #ifdef INCLUDE_PROXY_SERVER
  59.         proxyOn = TRUE;
  60. #endif
  61.         bpDev = "sm";
  62.         sprintf (netDev, "%s", "sm0");
  63.         bootNetmaskExtract (sysBootParams.bad, &proxymask);
  64.         /* Using Subnet with PROXY Arp */
  65.         if (proxyOn == TRUE)
  66.             {
  67.             if (seqAddrOn == TRUE)   /* PROXY WITH SEQ ADDR */
  68.                 {
  69.                 /* Pick address from backplane or ethernet */
  70.                 if (BP_ADDR_GIVEN)
  71.                     {
  72.                      startAddr = ntohl (inet_addr (sysBootParams.bad));
  73.                      netmask = proxymask;
  74.                     }
  75.                 else if (sysProcNumGet () == 0)
  76.                     {
  77.                     /*
  78.                      * The shared memory master calculates the next available
  79.                      * address, if possible. Slaves will read it directly.
  80.                      */
  81.                     if ( useEtherAddr )
  82.                         {
  83.                         startAddr = ntohl (inet_addr (sysBootParams.ead)) + 1;
  84.                         netmask = 0xffffffff;
  85.                         }
  86.                     else                /* Configuration error */
  87.                        {
  88.                        printf("Error: No address for proxy service.n");
  89.                        printf("Backplane IP Address must be specified.n");
  90.                        configureBp = FALSE;
  91.                        }
  92.                     }
  93.                 }
  94.             else                     /* PROXY WITHOUT SEQ ADDR */
  95.                 {
  96.                 if (BP_ADDR_NOT_GIVEN)
  97.                     {
  98.                     if (sysProcNumGet () == 0)
  99.                         configureBp = FALSE;    /* Can't start master. */
  100.                     }
  101.                 else                 /* startAddr is left as zero */
  102.                     {
  103.                     netmask = proxymask;
  104.                     }
  105.                 }
  106.             }
  107.         /* Using Subnet without PROXY Arp */
  108.         else
  109.             {
  110.             if (BP_ADDR_GIVEN)
  111.                 {
  112.                 if (seqAddrOn == TRUE)
  113.                     {
  114.                     /* Assign sequential address to backplane */
  115.                     startAddr = ntohl (inet_addr (sysBootParams.bad));
  116.                     }
  117.                 netmask = proxymask;
  118.                 }
  119.             else if (sysProcNumGet () == SM_MASTER)
  120.                 {
  121.                 /* Don't start the master if the backplane address is empty. */
  122.                 configureBp = FALSE;
  123.                 printf ("Backplane IP address required if no Proxy ARPn");
  124.                 }
  125.             }
  126.         if (configureBp == TRUE)
  127.             {
  128.             if (usrBpInit (bpDev, 0, startAddr) == ERROR)
  129.                 return;
  130.             if (startAddr != 0)
  131.                 {
  132.                 localAddr.s_addr = htonl (startAddr);
  133.                 inet_ntoa_b (localAddr, bpAddr);
  134.                 }
  135.             else
  136.                 {
  137.                 strcpy (bpAddr, sysBootParams.bad);
  138.                 }
  139.             printf ("Backplane IP address = %sn", bpAddr);
  140.             (void) usrNetIfAttach (bpDev, 0, sysBootParams.bad);
  141.             /* Assigned Back Plane Address if needed */
  142.             if ((BP_ADDR_NOT_GIVEN) &&
  143.                  (smNetInetGet (netDev, sysBootParams.bad, NONE) == OK))
  144.                  printf ("Backplane address: %sn", sysBootParams.bad);
  145.             (void) usrNetIfConfig (bpDev, 0, sysBootParams.bad,
  146.                                    (char *) NULL, netmask);
  147.             }
  148.         }
  149. #ifdef INCLUDE_SM_NET_SHOW
  150. # ifndef INCLUDE_BP_5_0
  151.     smNetShowInit ();
  152. # endif /* INCLUDE_BP_5_0 */
  153. #endif /* INCLUDE_SM_NET_SHOW */
  154.     }