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

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*      FILE: IBMTOOL.C                                                       */
  4. /*                                                                            */
  5. /* FUNCTIONS: BindToWedge                                                     */
  6. /*            Initialize                                                      */
  7. /*            main                                                            */
  8. /*                                                                            */
  9. /*   PURPOSE: This file contains the command line interface and main          */
  10. /*            initialization routines for IBMTOOL.                            */
  11. /*                                                                            */
  12. /*            Command Line Arguments: ScriptFile LogFile                      */
  13. /*                                                                            */
  14. /* GLOBAL DATA ACCESSED                                                       */
  15. /*      COMMONCHAR  MACMCC                                                    */
  16. /*      SERVICECHAR MACMSC                                                    */
  17. /*                                                                            */
  18. /******************************************************************************/
  19.  
  20. #define INCL_SUB
  21. #define INCL_BASE
  22. #define INCL_DOS
  23. #include <os2.h>
  24. #include <stdio.h>
  25. #include <stdarg.h>
  26. #include <malloc.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include "ndis.h"
  31. #include "ibmtool.h"
  32. #include "ioctl.h"
  33.  
  34. int BindToWedge ()
  35. {
  36.   char           *DriverName = "WEDGE$", *p;
  37.   USHORT          DHandle = (USHORT) hWedge, apiAction, rc;
  38.   IOCTLDATA       IOData;
  39.   IOCTLDATA far  *IODataPtr = &IOData;
  40.  
  41.  
  42.   WedgeCommon = (WEDGECOMMON far *) _fcalloc (1, sizeof (WEDGECOMMON));
  43.   memset (WedgeCommon, 0, sizeof (WEDGECOMMON));
  44.  
  45.  
  46.   Version ();
  47.   // Open WEDGE
  48.   if (rc = DosOpen (DriverName,   // char * to device driver to open=TESTMAC$
  49.                     &DHandle,     // address of file handle
  50.                     &apiAction,   // action taken by the DosOpen API function
  51.                     0L,           // file size
  52.                     FILE_NORMAL,  // file attribute
  53.                     FILE_OPEN,    // open flag - file must exist already
  54.                     OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,  //open mode
  55.                     0L)           //reserved
  56.       )
  57.     {
  58.      printf ("Failure opening WEDGE\n");
  59.      exit (1);
  60.     }
  61.  
  62.  
  63.   hWedge = (USHORT) DHandle;
  64.  
  65.   // lock the WedgeCommon area
  66.   IOData.ReqCode = LOCK_GDT;
  67.   IOData.Length = sizeof (WEDGECOMMON);
  68.   IOData.SrcDataPtr = (void far *) WedgeCommon;
  69.   GenIoctl ((void far *) IODataPtr, hWedge);
  70.   // Bind to WEDGE (Get the MAC's Common Characteristics Table)
  71.   IOData.ReqCode = WEDGEBIND;
  72.   IOData.Length  = 0;
  73.   IOData.SrcDataPtr = (void far *) IOData.DestDataPtr;
  74.   IOData.DestDataPtr = (void far *) &MACMCC;
  75.   if (GenIoctl ((void far *) IODataPtr, hWedge))
  76.      return GENERAL_FAILURE;
  77.   // Get the MAC's Service-Specific Characteristics Table
  78.   if (!GetTable (MSC))
  79.      rc = GENERAL_FAILURE;
  80.  
  81.   // Get the MAC's Service-Specific Status Table
  82.   if (!GetTable (MSS))
  83.      rc = GENERAL_FAILURE;
  84.  
  85.   // Get the MAC's Upper Dispatch Table
  86.   if (!GetTable (MUD))
  87.      rc = GENERAL_FAILURE;
  88.  
  89.   // Get the MAC's Vendor Description
  90.   if (!GetTable (VENDOR))
  91.      rc = GENERAL_FAILURE;
  92.   // Get the MAC's Media Specific Status Table
  93.   if (MACMSS.MssM8Sp != NULL)
  94.      if (!GetTable (MEDIA))
  95.         rc = GENERAL_FAILURE;
  96.   if (MACMSC.MscCCB != NULL)
  97.      // Get the MAC's CCB Table
  98.      if (!GetTable (MCB))
  99.         rc = GENERAL_FAILURE;
  100.  
  101.   return rc;
  102. }
  103.  
  104. void Initialize ()
  105. {
  106.   IOCTLDATA      IOData;
  107.   IOCTLDATA far *IODataPtr = &IOData;
  108.  
  109.   BindToWedge ();
  110.   // set up some WedgeCommon variables
  111.   WedgeCommon->SrcAddrOffset = WedgeCommon->StnAdrSz = MACMSC.MscStnAdrSz;
  112.   WedgeCommon->HeaderLen = 14;
  113.   WedgeCommon->DestAddrOffset = 0;
  114.  
  115.   // see if the MAC is a Token Ring adapter
  116.   TokenRing = FALSE;
  117.   if (!stricmp (MACMSC.MscType, "802.5"))
  118.     {
  119.      TokenRing = TRUE;
  120.      WedgeCommon->HeaderLen += 2;
  121.      WedgeCommon->DestAddrOffset += 2;
  122.      WedgeCommon->SrcAddrOffset += 2;
  123.     }
  124.  
  125.   InitXmit ();
  126.  
  127.   // allocate memory for the indication queue
  128.   WedgeCommon->IndicQueue =
  129.        (INDICQ far *) _fcalloc (INDIC_QUEUE_SIZE, sizeof (INDICQ));
  130.  
  131.   // lock it down
  132.   IOData.ReqCode = LOCK_GDT;
  133.   IOData.Length  = INDIC_QUEUE_SIZE * sizeof (INDICQ);
  134.   IOData.SrcDataPtr = (void far *) WedgeCommon->IndicQueue;
  135.   IOData.DestDataPtr = NULL;
  136.   GenIoctl ((void far *) IODataPtr, hWedge);
  137.   WedgeCommon->IndicGDT = (DWORD) IOData.DestDataPtr;
  138.  
  139.   // allocate memory for the common receive buffer
  140.   WedgeCommon->RcvData =
  141.        (BYTE far *) calloc (MACMSC.MscMaxFrame, sizeof (BYTE));
  142.  
  143.   // lock it down
  144.   IOData.ReqCode = LOCK_GDT;
  145.   IOData.Length  = MACMSC.MscMaxFrame;
  146.   IOData.SrcDataPtr = (void far *) WedgeCommon->RcvData;
  147.   IOData.DestDataPtr = NULL;
  148.   GenIoctl ((void far *) IODataPtr, hWedge);
  149.   WedgeCommon->RcvGDT = (DWORD) IOData.DestDataPtr;
  150.  
  151.   // set up the common physical address of the receive buffer
  152.   IOData.ReqCode = VIRT_TO_PHYS;
  153.   IOData.Length  = 0;
  154.   IOData.SrcDataPtr = (void far *) WedgeCommon->RcvData;
  155.   IOData.DestDataPtr = NULL;
  156.   GenIoctl ((void far *) IODataPtr, hWedge);
  157.   WedgeCommon->RcvDataPhys = IOData.SrcDataPtr;
  158.  
  159.   // set up the Control Frame receive buffer
  160.   ControlFrame.pBuffer = (BYTE far *) calloc (MAX_IMMED_LEN, sizeof (BYTE));
  161.  
  162.   // initialize pointers to the Control Frame buffer areas
  163.   ControlFrame.pDest   = ControlFrame.pBuffer + WedgeCommon->DestAddrOffset;
  164.   ControlFrame.pSrc    = ControlFrame.pDest + MACMSC.MscStnAdrSz;
  165.   ControlFrame.pLength = ControlFrame.pSrc + MACMSC.MscStnAdrSz;
  166.   ControlFrame.pID     = ControlFrame.pLength + sizeof (WORD);
  167.   ControlFrame.pOpCode = ControlFrame.pID + strlen (CTRLID);
  168.   ControlFrame.pData   = ControlFrame.pOpCode + sizeof (WORD);
  169.  
  170.   // initialize some global variables
  171.   AllDone    = FALSE;
  172.   Debug      = FALSE;
  173.   Echo       = FALSE;
  174.   SLog       = FALSE;
  175.  
  176.   ReqHandle = 0;
  177.   WkStaTop  = NULL;
  178.  
  179.   TTClearIndications ();
  180.  
  181. }
  182.  
  183. int TTExit ()
  184. {
  185.   // EXIT | QUIT
  186.  
  187.   AllDone = TRUE;
  188.  
  189.   // tell SERVER we're no longer a WORKSTATION
  190.   if (WedgeCommon->RspMode == WORKSTATION)
  191.      SendControlFrame (CCDELWKSTA);
  192.  
  193.   if (SLog) fclose (LogFile);
  194.   if (ScriptMode) fclose (ScriptFile);
  195.  
  196.   return SUCCESS;
  197. }
  198.  
  199. void main (int argc, char *argv[])
  200. {
  201.   char        vAttr[2] = " ";
  202.   VIOMODEINFO OrgModeInfo;
  203.  
  204.   if (argc >= 2)
  205.     {
  206.      ScriptMode = TRUE;
  207.      ScriptFile = fopen (argv[1], "rt");
  208.      if (argc == 3)
  209.         LogFile = fopen (argv[2], "wt");
  210.      else
  211.         LogFile = fopen ("IBMTEST.LOG", "wt");
  212.      Initialize ();
  213.      DoScript ();
  214.     }
  215.   else
  216.     {
  217.      ScriptMode = FALSE;
  218.      Initialize ();
  219.      OrgModeInfo.cb = sizeof (VIOMODEINFO);
  220.      VioGetMode (&OrgModeInfo, 0);
  221.      InitInterface ();
  222.      while (!AllDone)
  223.         GetCommand ();
  224.     } /* endif */
  225.  
  226.   if (!ScriptMode)
  227.     {
  228.      // blank the screen and restore the original video mode
  229.      vAttr[1] = 0x07;
  230.      VioScrollUp (0, 0, -1, -1, -1, vAttr, 0);
  231.      VioSetMode (&OrgModeInfo, 0);
  232.     } /* endif */
  233.  
  234. }
  235.