home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmtool.zip / mactest.c < prev    next >
Text File  |  1997-11-07  |  6KB  |  212 lines

  1. #define INCL_SUB
  2. #define INCL_BASE
  3. #define INCL_DOS
  4. #include <os2.h>
  5. #include <stdio.h>
  6. #include <stdarg.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include "ndis.h"
  11. #include "ioctl.h"
  12. #include "ibmtool.h"
  13. #include "intrface.h"
  14.  
  15. int MTMulticast ()
  16. {
  17.   char   *AddTokenCmd = "ADDMC C0 00 80 01 02 01";
  18.   char   *AddEthCmd   = "ADDMC 01 02 03 04 05 01";
  19.   char   *RxCmd       = "SRVTX 1 100 100 1 ";
  20.   char    cmd[80];
  21.   BYTE    MCAddr[ADDR_LEN];
  22.   USHORT  retval = SUCCESS;
  23.   int     i;
  24.  
  25.   TTClearMac ();
  26.   GetTable (MMC);
  27.  
  28.   // open adapter - if supported
  29.   if (MACMSC.MscService & OPEN_ADAPTER_SUPP)
  30.     {
  31.      ParseCommand ("OPEN");
  32.      if (LastStatus != SUCCESS)
  33.        {
  34.         PrintMsg ("OpenAdapter failed - exiting MACTEST");
  35.         return GENERAL_FAILURE;
  36.        }
  37.     }
  38.  
  39.   // set filter to 3
  40.   ParseCommand ("FILTER 3");
  41.   if (LastStatus != SUCCESS)
  42.     {
  43.      PrintMsg ("SePacketFilter 3 failed - exiting MACTEST");
  44.      return GENERAL_FAILURE;
  45.     }
  46.  
  47.   // identify the server
  48.   ParseCommand ("WKSTA");
  49.   if (LastStatus != SUCCESS)
  50.     {
  51.      PrintMsg ("Unable to identify the server - exiting MACTEST");
  52.      return GENERAL_FAILURE;
  53.     }
  54.  
  55.   // Test 1 - check that Multicast and Functional/Group bits are not both set
  56.   if ((MACMSC.MscService & MULTICAST_SUPP &&
  57.       (MACMSC.MscService & FUNC_GROUP_ADDR_SUPP))
  58.     {
  59.      PrintMsg ("Multicast Address and Functional/Group bits are both set.");
  60.      PrintMsg ("MULTICASTADDRESS Test 1 FAIL");
  61.      retval = GENERAL_FAILURE;
  62.     }
  63.   else
  64.     {
  65.      PrintMsg ("Multicast Address and Functional/Group bits are not both set.");
  66.      PrintMsg ("MULTICASTADDRESS Test 1 PASS");
  67.     }
  68.  
  69.   // see if Multicast Addresses are supported
  70.   if (!(MACMSC.MscService & MULTICAST_SUPP))
  71.     {
  72.      PrintMsg ("Service-Specific Characteristics Tables says");
  73.      PrintMsg ("   Multicast Addresses are not supported - ");
  74.      // Test 2 - verify AddMulticastAddress returns NOT_SUPPORTED
  75.      if (TokenRing)
  76.         ParseCommand (AddTokenCmd);
  77.      else
  78.         ParseCommand (AddEthCmd);
  79.      if (LastStatus == NOT_SUPPORTED)
  80.        {
  81.         PrintMsg ("AddMulticastAddress returned NOT_SUPPORTED");
  82.         PrintMsg ("ADDMULTICASTADDRESS Test 2 PASS");
  83.         return SUCCESS;
  84.        }
  85.      else
  86.        {
  87.         PrintMsg ("AddMulticastAddress did not return NOT_SUPPORTED");
  88.         PrintMsg ("ADDMULTICASTADDRESS Test 2 FAIL");
  89.         retval = GENERAL_FAILURE;
  90.        } /* endif */
  91.     }
  92.  
  93.   // Test 3 - add invalid Multicast Address
  94.   ParseCommand ("ADDMC 00 00 00 00 00 00");
  95.   if (LastStatus == INVALID_PARAMETER)
  96.     {
  97.      PrintMsg ("Addition of invalid Multicast Address returned INVALID_PARAMETER");
  98.      PrintMsg ("ADDMULTICASTADDRESS Test 3 PASS");
  99.     }
  100.   else
  101.     {
  102.      PrintMsg ("Addition of invalid Multicast Address did not return INVALID_PARAMETER");
  103.      PrintMsg ("ADDMULTICASTADDRESS Test 3 FAIL");
  104.     }
  105.  
  106.   // Test 4 - Attempt to add the maximum number of Multicast Addresses and
  107.   //          receive a frame sent to each one.
  108.   for (i=1; i<MACMCBuff.McbMax + 1; ++i)
  109.     {
  110.      if (TokenRing)
  111.         strcpy (cmd, AddTokenCmd);
  112.      else
  113.         strcpy (cmd, AddEthCmd);
  114.      sprintf (cmd + 21, "%02X", &i);
  115.      ParseCommand (cmd);
  116.      if (LastStatus == SUCCESS)
  117.         PrintMsg ("Added Multicast Address %d", i);
  118.      else
  119.        {
  120.         PrintMsg ("Addition of Multicast Address %d Failed", i);
  121.         return GENERAL_FAILURE;
  122.        } /* endif */
  123.      GetTable (MMC);
  124.      if (MACMCBuff.McbCnt != i)
  125.        {
  126.         PrintMsg ("Multicast Address count != %d, i);
  127.         retval = GENERAL_FAILURE;
  128.        }
  129.      // Receive to the Multicast Address
  130.      IndicationCount = 0;
  131.      strcpy (cmd, "SRVTX 1 100 100 1 ");
  132.      if (TokenRing)
  133.         strcat (cmd, AddTokenCmd + 6);
  134.      else
  135.         strcat (cmd, AddEthCmd + 6);
  136.      ParseCommand (cmd);
  137.      DosSleep (2000);
  138.      if (IndicationCount == 2)
  139.         PrintMsg ("Receive to Multicast Address %d Passed", i);
  140.      else
  141.        {
  142.         PrintMsg ("Receive to Multicast Address %d Failed", i);
  143.         retval = GENERAL_FAILURE;
  144.        } /* endif */
  145.     } /* endfor */
  146.   if (retval == SUCCESS)
  147.     {
  148.      PrintMsg ("Addition of all Multicast Addresses succeeded.");
  149.      PrintMsg ("ADDMULTICASTADDRESS Test 4 PASS");
  150.     }
  151.   else
  152.     {
  153.      PrintMsg ("Addition of all Multicast Addresses failed.");
  154.      PrintMsg ("ADDMULTICASTADDRESS Test 4 FAIL");
  155.      return retval;
  156.     } /* endif */
  157.  
  158.   // Test 5 - Attempt to add an extra Multicast Address
  159.   if (TokenRing)
  160.      strcpy (cmd, AddTokenCmd);
  161.   else
  162.      strcpy (cmd, AddEthCmd);
  163.   sprintf (cmd + 21, "%02X", &i);
  164.   ParseCommand (cmd);
  165.   if (LastStatus != INVALID_FUNCTION)
  166.     {
  167.      PrintMsg ("Addition of extra Multicast Address succeeded - Failure");
  168.      PrintMsg ("ADDMULTICASTADDRESS Test 5 FAIL");
  169.      retval = GENERAL_FAILURE;
  170.     } /* endif */
  171.   GetTable (MMC);
  172.   if (MACMCBuff.McbCnt != MACMCBuff.McbMax)
  173.     {
  174.      PrintMsg ("Multicast Address count != maximum");
  175.      PrintMsg ("ADDMULTICASTADDRESS Test 5 FAIL");
  176.      retval = GENERAL_FAILURE;
  177.     }
  178.   // Receive to the extra Multicast Address
  179.   IndicationCount = 0;
  180.   strcpy (cmd, "SRVTX 1 100 100 1 ");
  181.   if (TokenRing)
  182.      strcat (cmd, AddTokenCmd + 6);
  183.   else
  184.      strcat (cmd, AddEthCmd + 6);
  185.   ParseCommand (cmd);
  186.   DosSleep (2000);
  187.   if (IndicationCount > 1)
  188.     {
  189.      PrintMsg ("Receive to extra Multicast Address succeeded - Failure");
  190.      PrintMsg ("ADDMULTICASTADDRESS Test 5 FAIL");
  191.      retval = GENERAL_FAILURE;
  192.     } /* endif */
  193.  
  194.   // Test 6 - Attempt to add a previously added Multicast Address
  195.   if (TokenRing)
  196.      strcpy (cmd, AddTokenCmd);
  197.   else
  198.      strcpy (cmd, AddEthCmd);
  199.   strcat (cmd, "01");
  200.   ParseCommand (cmd);
  201.   if (LastStatus != INVALID_PARAMETER)
  202.     {
  203.      PrintMsg ("Addition of extra Multicast Address succeeded - Failure");
  204.      PrintMsg ("ADDMULTICASTADDRESS Test 6 FAIL");
  205.      retval = GENERAL_FAILURE;
  206.     } /* endif */
  207.  
  208.   return retval;
  209.  
  210. }
  211.  
  212.