home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************/
- /* */
- /* FILE: SUPPORT.C */
- /* */
- /* PURPOSE: This file contains the support functions for IBMTOOL. */
- /* */
- /* FUNCTIONS: GetNumericParm */
- /* TTEcho */
- /* TTDispRcvBufs */
- /* TTReadMAC */
- /* TTLog */
- /* TTDebug */
- /* TTCheckData */
- /* TTJump */
- /* TTClearIndications */
- /* TTCheckIndications */
- /* TTClearMAC */
- /* TTServerXmit */
- /* TTSleep */
- /* TTCheckLookahead */
- /* TTSetStatus */
- /* TTCheckStatus */
- /* TTRun */
- /* TTCheckTokenRing */
- /* */
- /* GLOBAL DATA ACCESSED */
- /* char *RetStr[] */
- /* BYTE far *TMRcvBuff */
- /* BOOLEAN Debug */
- /* BOOLEAN SLog */
- /* BOOLEAN ScriptMode */
- /* BOOLEAN TokenRing */
- /* ULONG hTestMAC */
- /* FILE *ScriptFile */
- /* FILE *LogFile */
- /* SERVICECHAR MACMSC */
- /* MCASTBUF MACMCBuff */
- /* INDICCNT IndicCnt */
- /* */
- /******************************************************************************/
-
- #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"
- #include "intrface.h"
-
- extern BYTE far *TMRcvBuff;
-
- USHORT LastStatus;
- WORD IndicationCount = 0;
- WORD LastFrameSize = 0;
- WORD LastLookahead = 0;
- WORD ScriptStatus = 0;
-
- ULONG GetNumericParm (char *token)
- {
- ULONG tlong;
-
- if (!strncmp (token, "0X", 2))
- {
- // convert hex input
- if (strlen (token + 2) == 2)
- if (sscanf (token + 2, "%02X", &tlong) != 1)
- return -1L;
- else
- return tlong;
- else if (strlen (token + 2) == 4)
- if (sscanf (token + 2, "%04X", &tlong) != 1)
- return -1L;
- else
- return tlong;
- else
- if (sscanf (token + 2, "%08lX", &tlong) != 1)
- return -1L;
- else
- return tlong;
- }
- else
- {
- // convert decimal input
- if (sscanf (token, "%ld", &tlong) != 1)
- return -1L;
- else
- return tlong;
- } /* endif */
-
- }
-
- int TTEcho ()
- {
- // ECHO
-
- Echo = (Echo) ? FALSE : TRUE;
-
- if (Echo)
- aprintf (0, 75, 0x74, "E");
- else
- aprintf (0, 75, 0x70, " ");
-
- return SUCCESS;
- }
-
- int TTDispRcvBufs ()
- {
- char *token;
-
- PrintMsg (0, "Receive Buffer");
-
- if ((token = strtok (NULL, "\n\t ")))
- {
- if (*token == 'P')
- hexprint (WedgeCommon->RcvData, LastFrameSize, TRUE);
- }
- else
- hexprint (WedgeCommon->RcvData, LastFrameSize, FALSE);
-
- return SUCCESS;
- }
-
- int TTReadMAC ()
- {
- // READMAC {"MCC" | "MSC" | "MSS" | "MMC"} <offset> [{"=" | "&"} <xx>*]
-
- BYTE *TablePtr, *p;
- char *token;
- char *tablename[] = { "MCC", "MSC", "MSS", "MMC", "" };
- char *longtablename[] = { "Common Characteristics Table",
- "Sevice-Specific Characteristics Table",
- "Sevice-Specific Status Table",
- "Multicast Address List" };
- BYTE tablevalue, value[256];
- int i, table, offset, valuecnt = 0, temp;
-
- // get the table
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
-
- for (table=0; *tablename[table]; ++table)
- if (!stricmp (token, tablename[table]))
- break;
- if (table > MMC) return TT_INVALID_PARAMETER;
- TablePtr = GetTable (table);
-
- // get the offset
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
- if ((offset = (int) GetNumericParm (token)) < 0)
- return TT_INVALID_PARAMETER;
-
- // get the value
- TablePtr += offset;
- tablevalue = *TablePtr;
-
- // get the operator
- if ((token = strtok (NULL, "\n\t ")))
- {
- switch (*token)
- {
- case '=':
- // get the test value(s)
- while ((token = strtok (NULL, "\n\t ")))
- {
- sscanf (token, "%02X", &temp);
- value[valuecnt] = (BYTE) temp;
- ++valuecnt;
- }
- if (!valuecnt)
- return TT_INVALID_PARAMETER;
- LastStatus = GENERAL_FAILURE;
- i = 0;
- if ((valuecnt == 1) && (tablevalue == value[0]))
- LastStatus = SUCCESS;
- else
- {
- for (i=0; i<valuecnt; ++i)
- if (*(TablePtr + i) != value[i]) break;
- if (i == valuecnt)
- LastStatus = SUCCESS;
- }
- PrintMsg (0, "%s", RetStr[LastStatus]);
- break;
- case '&':
- // get the test value(s)
- while ((token = strtok (NULL, "\n\t ")))
- {
- sscanf (token, "%02X", &temp);
- value[valuecnt] = (BYTE) temp;
- ++valuecnt;
- }
- if (!valuecnt)
- return TT_INVALID_PARAMETER;
- LastStatus = GENERAL_FAILURE;
- if ((valuecnt == 1) && (tablevalue & value[0]))
- LastStatus = SUCCESS;
- else
- {
- for (i=0; i<valuecnt; ++i)
- if (!(tablevalue & value[i])) break;
- if (i == valuecnt)
- LastStatus = SUCCESS;
- }
- PrintMsg (0, "%s", RetStr[LastStatus]);
- break;
- default:
- return TT_INVALID_PARAMETER;
- break;
- } /* endswitch */
- }
- else
- PrintMsg (0, "%s byte %d = 0x%02X", longtablename[table], offset, tablevalue);
-
- return SUCCESS;
- }
-
- int TTLog ()
- {
- // LOG filename
-
- char *filename;
-
- filename = strtok (NULL, "\n\t ");
- if (filename)
- {
- LogFile = fopen (filename, "wt");
- SLog = TRUE;
- }
- else if (!SLog)
- return TT_INVALID_PARAMETER;
- else
- SLog = FALSE;
-
- if (SLog)
- aprintf (0, 78, 0x74, "L");
- else
- aprintf (0, 78, 0x70, " ");
-
- return SUCCESS;
- }
-
- int TTDebug ()
- {
- // DEBUG <"ON" | "OFF">
-
- char *State;
-
- State = strtok (NULL, "\n\t ");
- if (!stricmp (State, "ON"))
- {
- // Open TESTMAC
- if (!OpenTestMAC ()) Debug = TRUE;
- }
- else if (!stricmp (State, "OFF"))
- {
- Debug = FALSE;
- DosClose ((USHORT) hTestMAC);
- _ffree (TMRcvBuff);
- }
- else
- return TT_INVALID_PARAMETER;
-
- if (Debug)
- aprintf (0, 79, 0x74, "D");
- else
- aprintf (0, 79, 0x70, " ");
-
- return SUCCESS;
- }
-
- int TTCheckData ()
- {
- // CHKDATA { "ON" | "OFF" } ["STOP" | "NOSTOP"]
-
- char *token;
-
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
- if (stricmp (token, "ON") && stricmp (token, "OFF"))
- return TT_INVALID_PARAMETER;
-
- // Set data verification checking in WEDGE
- WedgeCommon->CheckData = (stricmp (token, "ON")) ? FALSE : TRUE;
-
- if ((token = strtok (NULL, "\n\t ")))
- {
- if (stricmp (token, "STOP") && stricmp (token, "NOSTOP"))
- return TT_INVALID_PARAMETER;
- // Set StopOnErr in WEDGE
- WedgeCommon->StopOnErr = (stricmp (token, "NOSTOP")) ? FALSE : TRUE;
- }
-
- // display the data check flag
- if (WedgeCommon->CheckData)
- aprintf (0, 75, 0x74, "C");
- else
- aprintf (0, 75, 0x70, " ");
-
- return SUCCESS;
- }
-
- int TTJump ()
- {
- // JUMP [[!] <Status>] [Label]
- // Status = any NDIS defined return code
- // Label = where to jump to, if not present skip one instruction
-
- char str[80], searchstr[80];
- char *token, *label;
- int status;
- BOOLEAN found = FALSE, not = FALSE, statuscheck = FALSE;
-
- if (!ScriptMode) return SUCCESS;
-
- if (!(token = strtok (NULL, "\n\t ")))
- {
- // no parameters - skip the next instruction
- while (!(token = strtok (fgets (str, 80, ScriptFile), "\n\t ")));
- return SUCCESS;
- }
- else if (*token == '!')
- {
- not = TRUE;
- // get conditional status
- if ((status = GetRCInt (token+1)) < 0)
- return TT_INVALID_PARAMETER;
- statuscheck = TRUE;
- // see if there's a label
- if (!(token = strtok (NULL, "\n\t ")))
- {
- // no label - skip the next instruction
- while (!(token = strtok (fgets (str, 80, ScriptFile), "\n\t ")));
- return SUCCESS;
- }
- else
- label = token;
- }
- else if ((status = GetRCInt (token)) < 0)
- {
- // not a valid return code - assume it's a label
- label = token;
- }
- else
- {
- // see if there's a label
- statuscheck = TRUE;
- if (!(token = strtok (NULL, "\n\t ")))
- {
- // no label - skip the next instruction
- while (!(token = strtok (fgets (str, 80, ScriptFile), "\n\t ")));
- return SUCCESS;
- }
- else
- {
- label = token;
- }
- }
-
- // here's the check for the jump - returning SUCCESS means we won't jump
- if (statuscheck)
- {
- if (not)
- {
- if (LastStatus == status) return SUCCESS;
- }
- else if (LastStatus != status) return SUCCESS;
- }
-
- // otherwise, jump
- rewind (ScriptFile);
- while (fgets (searchstr, 80, ScriptFile))
- if (*searchstr == ':')
- {
- strcpy (str, searchstr);
- token = strtok (searchstr + 1, "\n\t ");
- if (!stricmp (searchstr + 1, label))
- {
- fprintf (LogFile, "\n%s", str);
- return SUCCESS;
- }
- }
-
- return TT_INVALID_PARAMETER;
-
- }
-
- int TTClearIndications ()
- {
- // CLRIND
-
- IndicationCount = 0;
- IndicCnt.Rx = 0;
- IndicCnt.Tx = 0;
- IndicCnt.Stat = 0;
- IndicCnt.Comp = 0;
- IndicCnt.GenReq = 0;
- IndicCnt.RingStatus = 0;
- IndicCnt.AdapterCheck = 0;
- IndicCnt.StartReset = 0;
- IndicCnt.EndReset = 0;
- IndicCnt.Interrupt = 0;
- IndicCnt.Total = 0;
- return SUCCESS;
- }
-
- int TTCheckIndications ()
- {
- // CHKIND [<Count> <Type>]
- // Type = { "RX" | "TX" | "ICOMP" | "GENREQ" | "STAT" [<StatType>] }
- // StatType = { "RING" | "ADAPTER" | "START" | "END" | "INT" }
-
- char *token;
- WORD IndCnt;
- WORD Type = 0;
- WORD StatType = 0;
-
- LastStatus = GENERAL_FAILURE;
-
- // get Count to check for
- if ((token = strtok (NULL, "\n\t ")))
- {
- if ((IndCnt = (WORD) GetNumericParm (token)) < 0)
- return TT_INVALID_PARAMETER;
- }
-
- // get Type
- if ((token = strtok (NULL, "\n\t ")))
- {
- if (!stricmp (token, "RX"))
- Type = 1;
- else if (!stricmp (token, "TX"))
- Type = 2;
- else if (!stricmp (token, "STAT"))
- {
- Type = 3;
- if ((token = strtok (NULL, "\n\t ")))
- {
- if (!stricmp (token, "RING"))
- StatType = 1;
- else if (!stricmp (token, "ADAPTER"))
- StatType = 2;
- else if (!stricmp (token, "START"))
- StatType = 3;
- else if (!stricmp (token, "END"))
- StatType = 4;
- else if (!stricmp (token, "INT"))
- StatType = 5;
- else
- return TT_INVALID_PARAMETER;
- }
- }
- else if (!stricmp (token, "ICOMP"))
- Type = 4;
- else if (!stricmp (token, "GENREQ"))
- Type = 5;
- else
- return TT_INVALID_PARAMETER;
- }
-
- CheckIndications ();
-
- switch (Type)
- {
- case 0:
- if (IndicationCount == IndCnt) LastStatus = SUCCESS;
- break;
- case 1:
- if (IndicCnt.Rx == IndCnt) LastStatus = SUCCESS;
- break;
- case 2:
- if (IndicCnt.Tx == IndCnt) LastStatus = SUCCESS;
- break;
- case 3:
- switch (StatType)
- {
- case 0:
- if (IndicCnt.Stat == IndCnt) LastStatus = SUCCESS;
- break;
- case 1:
- if (IndicCnt.RingStatus == IndCnt) LastStatus = SUCCESS;
- break;
- case 2:
- if (IndicCnt.AdapterCheck == IndCnt) LastStatus = SUCCESS;
- break;
- case 3:
- if (IndicCnt.StartReset == IndCnt) LastStatus = SUCCESS;
- break;
- case 4:
- if (IndicCnt.EndReset == IndCnt) LastStatus = SUCCESS;
- break;
- case 5:
- if (IndicCnt.Interrupt == IndCnt) LastStatus = SUCCESS;
- break;
- } /* endswitch */
- break;
- case 4:
- if (IndicCnt.Comp == IndCnt) LastStatus = SUCCESS;
- break;
- case 5:
- if (IndicCnt.GenReq == IndCnt) LastStatus = SUCCESS;
- break;
- } /* endswitch */
-
- if (!token)
- {
- PrintMsg (0, "Indications:");
- PrintMsg (0, " Receive = %d", IndicCnt.Rx);
- PrintMsg (0, " TransmitConfirm = %d", IndicCnt.Tx);
- PrintMsg (0, " Status = %d", IndicCnt.Stat);
- PrintMsg (0, " IndicationComplete = %d", IndicCnt.Comp);
- PrintMsg (0, " General Request Confirm = %d", IndicCnt.GenReq);
- } /* endif */
- else
- PrintMsg (0, "CheckIndications: %s", RetStr[LastStatus]);
-
- return SUCCESS;
- }
-
- int TTClearMAC ()
- {
- // CLRMAC
-
- char cmd[80];
- int i, j;
-
- // set Filter = 0
- ParseCommand ("FILTER 0");
-
- // clear the Multicast Address List
- GetTable (MMC);
- for (i=0; i<MACMCBuff.McbCnt; ++i)
- {
- strcpy (cmd, "DELMC ");
- for (j=0; j<MACMSC.MscStnAdrSz; ++j)
- sprintf (cmd + 6 + 3 * j, "%02X ", MACMCBuff.McbAddrs[i].mAddr[j]);
- ParseCommand (cmd);
- }
-
- // Close the MAC
- ParseCommand ("CLOSE");
-
- // set Current Station Address = Permanent Station Address
- strcpy (cmd, "SETSTN ");
- GetTable (MSC);
- for (i=0; i<WedgeCommon->StnAdrSz; ++i)
- sprintf (cmd + 7 + 3 * i, "%02X ", (BYTE) MACMSC.MscPermStnAdr[i]);
- ParseCommand (cmd);
-
- LastStatus = SUCCESS;
-
- ScriptStatus = 0;
-
- return SUCCESS;
- }
-
- int TTServerXmit ()
- {
- // SRVTX <Cnt> <Min> <Max> [<Type> [<NetAddr>]]
- // Tells the current server to transmit (MULTRAN)
- // Type: 0 = BROADCAST (default)
- // 1 = DIRECTED - <NetAddr> required
- // 2 = DIRECTED TO WHOEVER SENT THE CONTROL FRAME
- // 3 = DIRECTED TO SERVER
-
- USHORT rc;
-
- if ((rc = SendControlFrame (CCXMIT)))
- {
- // LastStatus = GENERAL_FAILURE;
- return rc;
- }
-
- // LastStatus = SUCCESS;
- return SUCCESS;
- }
-
- int TTSleep ()
- {
- // SLEEP <Seconds>
-
- char *token;
- WORD Seconds;
-
- if (!ScriptMode) return SUCCESS;
-
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
-
- if ((Seconds = (WORD) GetNumericParm (token)) < 0)
- return TT_INVALID_PARAMETER;
-
- DosSleep (Seconds * 1000);
-
- return SUCCESS;
- }
-
- int TTCheckLookahead ()
- {
- char *token;
- WORD Lookahead;
-
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
-
- if ((Lookahead = (WORD) GetNumericParm (token)) < 0)
- return TT_INVALID_PARAMETER;
-
- LastStatus = (LastLookahead == Lookahead) ? SUCCESS : GENERAL_FAILURE;
-
- return SUCCESS;
- }
-
- int TTSetStatus ()
- {
- // SETSTAT <Status>
-
- char *token;
-
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
-
- if ((ScriptStatus = (WORD) GetNumericParm (token)) < 0)
- return TT_INVALID_PARAMETER;
-
- return SUCCESS;
- }
-
- int TTCheckStatus ()
- {
- // CHKSTAT <Status>
-
- char *token;
- WORD status;
-
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
-
- if ((status = (WORD) GetNumericParm (token)) < 0)
- return TT_INVALID_PARAMETER;
-
- LastStatus = (status == ScriptStatus) ? SUCCESS : GENERAL_FAILURE;
-
- return SUCCESS;
- }
-
- int TTRun ()
- {
- // RUN <ScriptFile> [<LogFile>]
-
- char *token;
- char cmd[MAXSTRING];
-
- // get ScriptFile
- if (!(token = strtok (NULL, "\n\t ")))
- return TT_INVALID_PARAMETER;
-
- ScriptFile = fopen (token, "rt");
-
- // get LogFile (optional)
- if ((token = strtok (NULL, "\n\t ")))
- {
- SLog = TRUE;
- LogFile = fopen (token, "wt");
- }
-
- memset (cmd, '\0', MAXSTRING);
-
- while (fgets (cmd, MAXSTRING, ScriptFile))
- {
- CheckIndications ();
-
- if (*cmd != ':' && SLog)
- {
- if (strstr (cmd, "\n"))
- fprintf (LogFile, "%s", cmd);
- else
- fprintf (LogFile, "%s\n", cmd);
- }
-
- if (*cmd != '#' && *cmd != ':')
- ParseCommand (cmd);
-
- } /* endwhile */
-
- fclose (ScriptFile);
- if (SLog) fclose (LogFile);
-
- return SUCCESS;
- }
-
- int TTCheckTokenRing ()
- {
- LastStatus = (TokenRing) ? SUCCESS : GENERAL_FAILURE;
- return SUCCESS;
- }
-
- int TTInt3 ()
- {
- _asm int 3
- return SUCCESS;
- }
-
- int TTVersion ()
- {
- char *Version = "IBM NDIS TEST TOOL Version 1.10";
-
- PrintMsg (YELLOW, "%s", Version);
- return SUCCESS;
- }
-