home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ibmtool.zip
/
debug.c
next >
Wrap
Text File
|
1997-11-07
|
8KB
|
247 lines
/******************************************************************************/
/* */
/* FILE: IBMTOOL.C */
/* */
/* FUNCTIONS: BindToWedge */
/* Initialize */
/* main */
/* */
/* PURPOSE: This file contains the command line interface and main */
/* initialization routines for IBMTOOL. */
/* */
/* Command Line Arguments: ScriptFile LogFile */
/* */
/* GLOBAL DATA ACCESSED */
/* COMMONCHAR MACMCC */
/* SERVICECHAR MACMSC */
/* */
/******************************************************************************/
#define INCL_SUB
#define INCL_BASE
#define INCL_DOS
#include <os2.h>
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "ndis.h"
#include "ibmtool.h"
#include "ioctl.h"
int BindToWedge ()
{
char *DriverName = "WEDGE$", *p;
USHORT DHandle = (USHORT) hWedge, apiAction, rc;
IOCTLDATA IOData;
IOCTLDATA far *IODataPtr = &IOData;
printf("debug 1\n");
WedgeCommon = (WEDGECOMMON far *) _fcalloc (1, sizeof (WEDGECOMMON));
memset (WedgeCommon, 0, sizeof (WEDGECOMMON));
printf("debug 2\n");
Version ();
printf("debug 3\n");
// Open WEDGE
if (rc = DosOpen (DriverName, // char * to device driver to open=TESTMAC$
&DHandle, // address of file handle
&apiAction, // action taken by the DosOpen API function
0L, // file size
FILE_NORMAL, // file attribute
FILE_OPEN, // open flag - file must exist already
OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, //open mode
0L) //reserved
)
{
printf ("Failure opening WEDGE\n");
exit (1);
}
printf("debug 5\n");
hWedge = (USHORT) DHandle;
// lock the WedgeCommon area
IOData.ReqCode = LOCK_GDT;
printf("debug 6\n");
IOData.Length = sizeof (WEDGECOMMON);
printf("debug 7\n");
IOData.SrcDataPtr = (void far *) WedgeCommon;
printf("debug 8\n");
GenIoctl ((void far *) IODataPtr, hWedge);
printf("debug 9\n");
// Bind to WEDGE (Get the MAC's Common Characteristics Table)
IOData.ReqCode = WEDGEBIND;
IOData.Length = 0;
IOData.SrcDataPtr = (void far *) IOData.DestDataPtr;
IOData.DestDataPtr = (void far *) &MACMCC;
if (GenIoctl ((void far *) IODataPtr, hWedge))
return GENERAL_FAILURE;
printf("debug 10\n");
// Get the MAC's Service-Specific Characteristics Table
if (!GetTable (MSC))
rc = GENERAL_FAILURE;
// Get the MAC's Service-Specific Status Table
if (!GetTable (MSS))
rc = GENERAL_FAILURE;
// Get the MAC's Upper Dispatch Table
if (!GetTable (MUD))
rc = GENERAL_FAILURE;
// Get the MAC's Vendor Description
if (!GetTable (VENDOR))
rc = GENERAL_FAILURE;
printf("debug 11\n");
// Get the MAC's Media Specific Status Table
if (MACMSS.MssM8Sp != NULL)
if (!GetTable (MEDIA))
rc = GENERAL_FAILURE;
printf("debug 12\n");
if (MACMSC.MscCCB != NULL)
// Get the MAC's CCB Table
if (!GetTable (MCB))
rc = GENERAL_FAILURE;
return rc;
}
void Initialize ()
{
IOCTLDATA IOData;
IOCTLDATA far *IODataPtr = &IOData;
BindToWedge ();
printf("debug xx\n");
// set up some WedgeCommon variables
WedgeCommon->SrcAddrOffset = WedgeCommon->StnAdrSz = MACMSC.MscStnAdrSz;
WedgeCommon->HeaderLen = 14;
WedgeCommon->DestAddrOffset = 0;
// see if the MAC is a Token Ring adapter
TokenRing = FALSE;
if (!stricmp (MACMSC.MscType, "802.5"))
{
TokenRing = TRUE;
WedgeCommon->HeaderLen += 2;
WedgeCommon->DestAddrOffset += 2;
WedgeCommon->SrcAddrOffset += 2;
}
InitXmit ();
// allocate memory for the indication queue
WedgeCommon->IndicQueue =
(INDICQ far *) _fcalloc (INDIC_QUEUE_SIZE, sizeof (INDICQ));
// lock it down
IOData.ReqCode = LOCK_GDT;
IOData.Length = INDIC_QUEUE_SIZE * sizeof (INDICQ);
IOData.SrcDataPtr = (void far *) WedgeCommon->IndicQueue;
IOData.DestDataPtr = NULL;
GenIoctl ((void far *) IODataPtr, hWedge);
WedgeCommon->IndicGDT = (DWORD) IOData.DestDataPtr;
// allocate memory for the common receive buffer
WedgeCommon->RcvData =
(BYTE far *) calloc (MACMSC.MscMaxFrame, sizeof (BYTE));
// lock it down
IOData.ReqCode = LOCK_GDT;
IOData.Length = MACMSC.MscMaxFrame;
IOData.SrcDataPtr = (void far *) WedgeCommon->RcvData;
IOData.DestDataPtr = NULL;
GenIoctl ((void far *) IODataPtr, hWedge);
WedgeCommon->RcvGDT = (DWORD) IOData.DestDataPtr;
// set up the common physical address of the receive buffer
IOData.ReqCode = VIRT_TO_PHYS;
IOData.Length = 0;
IOData.SrcDataPtr = (void far *) WedgeCommon->RcvData;
IOData.DestDataPtr = NULL;
GenIoctl ((void far *) IODataPtr, hWedge);
WedgeCommon->RcvDataPhys = IOData.SrcDataPtr;
// set up the Control Frame receive buffer
ControlFrame.pBuffer = (BYTE far *) calloc (MAX_IMMED_LEN, sizeof (BYTE));
// initialize pointers to the Control Frame buffer areas
ControlFrame.pDest = ControlFrame.pBuffer + WedgeCommon->DestAddrOffset;
ControlFrame.pSrc = ControlFrame.pDest + MACMSC.MscStnAdrSz;
ControlFrame.pLength = ControlFrame.pSrc + MACMSC.MscStnAdrSz;
ControlFrame.pID = ControlFrame.pLength + sizeof (WORD);
ControlFrame.pOpCode = ControlFrame.pID + strlen (CTRLID);
ControlFrame.pData = ControlFrame.pOpCode + sizeof (WORD);
// initialize some global variables
AllDone = FALSE;
Debug = FALSE;
Echo = FALSE;
SLog = FALSE;
ReqHandle = 0;
WkStaTop = NULL;
TTClearIndications ();
}
int TTExit ()
{
// EXIT | QUIT
AllDone = TRUE;
// tell SERVER we're no longer a WORKSTATION
if (WedgeCommon->RspMode == WORKSTATION)
SendControlFrame (CCDELWKSTA);
if (SLog) fclose (LogFile);
if (ScriptMode) fclose (ScriptFile);
return SUCCESS;
}
void main (int argc, char *argv[])
{
char vAttr[2] = " ";
VIOMODEINFO OrgModeInfo;
if (argc >= 2)
{
ScriptMode = TRUE;
ScriptFile = fopen (argv[1], "rt");
if (argc == 3)
LogFile = fopen (argv[2], "wt");
else
LogFile = fopen ("IBMTEST.LOG", "wt");
Initialize ();
DoScript ();
}
else
{
ScriptMode = FALSE;
Initialize ();
OrgModeInfo.cb = sizeof (VIOMODEINFO);
VioGetMode (&OrgModeInfo, 0);
InitInterface ();
while (!AllDone)
GetCommand ();
} /* endif */
if (!ScriptMode)
{
// blank the screen and restore the original video mode
vAttr[1] = 0x07;
VioScrollUp (0, 0, -1, -1, -1, vAttr, 0);
VioSetMode (&OrgModeInfo, 0);
} /* endif */
}