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