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

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*      FILE: GENREQ.C                                                        */
  4. /*                                                                            */
  5. /*   PURPOSE: This file contains the General Request processing.              */
  6. /*                                                                            */
  7. /* FUNCTIONS: GetRCInt                                                        */
  8. /*            GenRequest                                                      */
  9. /*            CheckGenRequest                                                 */
  10. /*            GetRetCodes                                                     */
  11. /*            TTInitiateDiagnostics                                           */
  12. /*            TTReadErrorLog                                                  */
  13. /*            TTSetStationAddr                                                */
  14. /*            TTOpen                                                          */
  15. /*            TTClose                                                         */
  16. /*            TTResetMAC                                                      */
  17. /*            TTSetPacketFilter                                               */
  18. /*            TTAddMulticastAddr                                              */
  19. /*            TTDeleteMulticastAddr                                           */
  20. /*            TTUpdateStatistics                                              */
  21. /*            TTClearStat                                                     */
  22. /*            TTInterruptRequest                                              */
  23. /*            TTSetFunctionalAddr                                             */
  24. /*            TTSetLookAhead                                                  */
  25. /*            TTModifyOpenParms                                               */
  26. /*                                                                            */
  27. /* GLOBAL DATA ACCESSED                                                       */
  28. /*      char *RetStr[]                                                        */
  29. /*                                                                            */
  30. /******************************************************************************/
  31.  
  32. #define INCL_SUB
  33. #define INCL_BASE
  34. #define INCL_DOS
  35. #include <os2.h>
  36. #include <stdio.h>
  37. #include <stdarg.h>
  38. #include <malloc.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <ctype.h>
  42. #include "ndis.h"
  43. #include "ibmtool.h"
  44. #include "ioctl.h"
  45. #include "ttstr.h"
  46.  
  47. int     ExpRC[2];
  48. USHORT  ReqHandle = 0;
  49. GENREQ  GenReq;
  50.  
  51. int GetRCInt (char *RCStr)
  52. {
  53.   int i;
  54.  
  55.   for (i=0; *RetStr[i]; ++i)
  56.      if (!stricmp (RCStr, RetStr[i]))
  57.         break;
  58.  
  59.   if (*RetStr[i]) return i;
  60.   return -1;
  61. }
  62.  
  63. USHORT GenRequest ()
  64. {
  65.   IOCTLDATA      IOData;
  66.   IOCTLDATA far *IODataPtr = &IOData;
  67.  
  68.   IOData.ReqCode = GENREQUEST;
  69.   IOData.Length  = 0;
  70.   IOData.SrcDataPtr = (void far *) &GenReq;
  71.   IOData.DestDataPtr = NULL;
  72.   GenIoctl ((void far *) IODataPtr, hWedge);
  73.   return IOData.ReqCode;
  74. }
  75.  
  76. int CheckGenRequest (WORD Request, WORD Handle)
  77. {
  78.   int i;
  79.  
  80.   if (ExpRC[0] == REQUEST_QUEUED)
  81.     {
  82.      if (LastStatus != REQUEST_QUEUED)
  83.         PrintMsg (YELLOW, "Warning - TestMAC did not return REQUEST_QUEUED");
  84.      else
  85.        {
  86.         LastStatus = TMReqConf (GenReq.ReqHandle, GenReq.OpCode, ExpRC[1]);
  87.         // wait for General Request Confirm for this request
  88.         for (i=0; i<300; ++i)
  89.           {
  90.            DosSleep (100);
  91.            if (CheckIndications ()) break;
  92.           } /* endfor */
  93.         if (LastStatus != ExpRC[1])
  94.            PrintMsg (YELLOW, "Warning - TestMAC did not return %s", RetStr[ExpRC[1]]);
  95.         else return SUCCESS;
  96.        }
  97.     }
  98.   else if (LastStatus == REQUEST_QUEUED)
  99.     {
  100.      // wait for General Request Confirm for this request
  101.      for (i=0; i<300; ++i)
  102.        {
  103.         DosSleep (100);
  104.         if (CheckIndications ()) return SUCCESS;
  105.        } /* endfor */
  106.     } /* endif */
  107.  
  108.   return TT_GENREQ_NOT_COMPLETE;
  109. }
  110.  
  111. int GetRetCodes ()
  112. {
  113.   char *RetCode;
  114.   int   i;
  115.  
  116.   ExpRC[0] = ExpRC[1] = -1;
  117.  
  118.   if (Debug)
  119.     {
  120.      RetCode = strtok (NULL, "\n\t ");
  121.      if (!RetCode) return TT_INVALID_PARAMETER;
  122.  
  123.      if ((ExpRC[0] = GetRCInt (RetCode)) < 0)
  124.         return TT_INVALID_PARAMETER;
  125.      else
  126.        {
  127.         if (!stricmp (RetCode, "REQUEST_QUEUED"))
  128.           {
  129.            RetCode = strtok (NULL, "\n\t ");
  130.            if (!RetCode) return TT_INVALID_PARAMETER;
  131.  
  132.            if ((ExpRC[1] = GetRCInt (RetCode)) < 0)
  133.               return TT_INVALID_PARAMETER;
  134.           }
  135.        }
  136.  
  137.      TMSetResult (ExpRC[0]);
  138.  
  139.      return SUCCESS;
  140.     }
  141.   else if ((RetCode = strtok (NULL, "\n\t ")))
  142.      return TT_INVALID_PARAMETER;
  143.  
  144. }
  145.  
  146. int TTInitiateDiagnostics ()
  147. {
  148.   // INITDIAG [<Return> [<Return>]]
  149.  
  150.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  151.  
  152.   GenReq.ReqHandle = ++ReqHandle;
  153.   GenReq.Param1 = 0;
  154.   GenReq.Param2 = 0L;
  155.   GenReq.OpCode = INITIATEDIAGNOSTICS;
  156.  
  157.   LastStatus = GenRequest ();
  158.  
  159.   PrintMsg (0, "Initiate Diagnostics:  %s", RetStr[LastStatus]);
  160.  
  161.   CheckGenRequest (INITIATEDIAGNOSTICS, GenReq.ReqHandle);
  162.  
  163.   return SUCCESS;
  164. }
  165.  
  166. int TTReadErrorLog ()
  167. {
  168.   // READLOG <LogSize> [<Return> [<Return>]]
  169.  
  170.   char   *token;
  171.   BYTE   *LogBuffer;
  172.   int     LogSize;
  173.   int     rc;
  174.  
  175.   if ((token = strtok (NULL, "\n\t ")))
  176.     {
  177.      if ((LogSize = (int) GetNumericParm (token)) < 0)
  178.         return TT_INVALID_PARAMETER;
  179.     }
  180.   else
  181.      return TT_INVALID_PARAMETER;
  182.  
  183.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  184.  
  185.   LogBuffer = (BYTE *) calloc (LogSize, sizeof (BYTE));
  186.  
  187.   GenReq.ReqHandle = ++ReqHandle;
  188.   GenReq.Param1 = LogSize;
  189.   GenReq.Param2 = (void far *) LogBuffer;
  190.   GenReq.OpCode = READERRORLOG;
  191.  
  192.   LastStatus = GenRequest ();
  193.  
  194.   PrintMsg (0, "Read Error Log:  %s", RetStr[LastStatus]);
  195.  
  196.   CheckGenRequest (READERRORLOG, GenReq.ReqHandle);
  197.  
  198.   if (LastStatus == SUCCESS)
  199.      hexprint (LogBuffer, LogSize, 0);
  200.  
  201.   return SUCCESS;
  202. }
  203.  
  204. int TTSetStationAddr ()
  205. {
  206.   // SETSTN <NetAddr> [<Return> [<Return>]]
  207.  
  208.   char   *token;
  209.   BYTE    StnAddr[ADDR_LEN];
  210.   USHORT  temp;
  211.   int     i;
  212.  
  213.   for (i=0; i<WedgeCommon->StnAdrSz; ++i)
  214.     {
  215.      if (!(token = strtok (NULL, "\n\t ")))
  216.         return TT_INVALID_PARAMETER;
  217.      if (sscanf (token, "%02X", &temp) != 1)
  218.         return TT_INVALID_PARAMETER;
  219.      StnAddr[i] = (BYTE) temp;
  220.     } /* endfor */
  221.  
  222.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  223.  
  224.   GenReq.ReqHandle = ++ReqHandle;
  225.   GenReq.Param1 = 0;
  226.   GenReq.Param2 = (void far *) &StnAddr;
  227.   GenReq.OpCode = SETSTATIONADDRESS;
  228.  
  229.   LastStatus = GenRequest ();
  230.  
  231.   PrintMsg (0, "Set Station Address:  %s", RetStr[LastStatus]);
  232.  
  233.   CheckGenRequest (SETSTATIONADDRESS, GenReq.ReqHandle);
  234.  
  235.   return SUCCESS;
  236. }
  237.  
  238. int TTOpen ()
  239. {
  240.   // OPEN [<OpenOptions> [<ExtendedRet> [<Return> [<Return>]]]]
  241.  
  242.   char  *token;
  243.   WORD   OpenOptions = 0;
  244.   DWORD  ExtendedRet = 0xFFFFFFFF;
  245.   TMAC   TMac;
  246.  
  247.   ExpRC[0] = ExpRC[1] = -1;
  248.  
  249.   token = strtok (NULL, "\n\t ");
  250.  
  251.   if (Debug)
  252.     {
  253.      // get OpenOptions
  254.      if (!token) return TT_INVALID_PARAMETER;
  255.      OpenOptions = (WORD) GetNumericParm (token);
  256.  
  257.      // get ExtendedRet
  258.      token = strtok (NULL, "\n\t ");
  259.      if (!token) return TT_INVALID_PARAMETER;
  260.      ExtendedRet = GetNumericParm (token);
  261.  
  262.      // get Expected Return Codes
  263.      token = strtok (NULL, "\n\t ");
  264.      if (!token) return TT_INVALID_PARAMETER;
  265.  
  266.      if ((ExpRC[0] = GetRCInt (token)) < 0)
  267.         return TT_INVALID_PARAMETER;
  268.      else
  269.        {
  270.         if (!stricmp (token, "REQUEST_QUEUED"))
  271.           {
  272.            token = strtok (NULL, "\n\t ");
  273.            if (!token) return TT_INVALID_PARAMETER;
  274.  
  275.            if ((ExpRC[1] = GetRCInt (token)) < 0)
  276.               return TT_INVALID_PARAMETER;
  277.           }
  278.        }
  279.  
  280.      // set results expected from TESTMAC
  281.      TMac.EventCmd = SETRESULT;
  282.      TMac.Parm[0]  = ExpRC[0];
  283.      TMac.Parm[1]  = (WORD) (ExtendedRet & 0xFFFF);
  284.      TMac.Parm[2]  = (WORD) (ExtendedRet >> 16);
  285.      GenIoctl ((void far *) &TMac, hTestMAC);
  286.     }
  287.   else if (token)
  288.     {
  289.      // get OpenOptions
  290.      OpenOptions = (WORD) GetNumericParm (token);
  291.     }
  292.  
  293.   GenReq.ReqHandle = ++ReqHandle;
  294.   GenReq.Param1 = OpenOptions;
  295.   GenReq.Param2 = (void far *) &ExtendedRet;
  296.   GenReq.OpCode = OPENADAPTER;
  297.  
  298.   LastStatus = GenRequest ();
  299.  
  300.   PrintMsg (0, "Open Adapter:  %s  Extended Return: %08lX",
  301.             RetStr[LastStatus], ExtendedRet);
  302.  
  303.   CheckGenRequest (OPENADAPTER, GenReq.ReqHandle);
  304.  
  305.   return SUCCESS;
  306. }
  307.  
  308. int TTClose ()
  309. {
  310.   // CLOSE [<Return> [<Return>]]
  311.  
  312.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  313.  
  314.   GenReq.ReqHandle = ++ReqHandle;
  315.   GenReq.Param1 = 0;
  316.   GenReq.Param2 = 0L;
  317.   GenReq.OpCode = CLOSEADAPTER;
  318.  
  319.   LastStatus = GenRequest ();
  320.  
  321.   PrintMsg (0, "Close Adapter:  %s", RetStr[LastStatus]);
  322.  
  323.   CheckGenRequest (CLOSEADAPTER, GenReq.ReqHandle);
  324.  
  325.   return SUCCESS;
  326. }
  327.  
  328. int TTResetMAC ()
  329. {
  330.   // RESET [<Return> [<Return>]]
  331.  
  332.   int  rc;
  333.  
  334.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  335.  
  336.   GenReq.ReqHandle = ++ReqHandle;
  337.   GenReq.Param1 = 0;
  338.   GenReq.Param2 = 0L;
  339.   GenReq.OpCode = RESETMAC;
  340.  
  341.   LastStatus = GenRequest ();
  342.  
  343.   PrintMsg (0, "Reset MAC:  %s", RetStr[LastStatus]);
  344.  
  345.   CheckGenRequest (RESETMAC, GenReq.ReqHandle);
  346.  
  347.   return SUCCESS;
  348. }
  349.  
  350. int TTSetPacketFilter ()
  351. {
  352.   // FILTER # [<Return> [<Return>]]
  353.  
  354.   char   *token;
  355.   USHORT  filter;
  356.  
  357.   token = strtok (NULL, "\n\t ");
  358.   if (!token)
  359.      return TT_INVALID_PARAMETER;
  360.   else if ((filter = (USHORT) GetNumericParm (token)) < 0)
  361.      return TT_INVALID_PARAMETER;
  362.  
  363.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  364.  
  365.   GenReq.ReqHandle = ++ReqHandle;
  366.   GenReq.Param1 = filter;
  367.   GenReq.Param2 = 0L;
  368.   GenReq.OpCode = SETPACKETFILTER;
  369.  
  370.   LastStatus = GenRequest ();
  371.  
  372.   PrintMsg (0, "Set Packet Filter %d:  %s", filter, RetStr[LastStatus]);
  373.  
  374.   CheckGenRequest (SETPACKETFILTER, GenReq.ReqHandle);
  375.  
  376.   return SUCCESS;
  377. }
  378.  
  379. int TTAddMulticastAddr ()
  380. {
  381.   // ADDMC <NetAddr> [<Return> [<Return>]]
  382.  
  383.   char   *token;
  384.   BYTE    MCAddr[ADDR_LEN];
  385.   USHORT  temp;
  386.   int     i;
  387.  
  388.   for (i=0; i<WedgeCommon->StnAdrSz; ++i)
  389.     {
  390.      if (!(token = strtok (NULL, "\n\t ")))
  391.         return TT_INVALID_PARAMETER;
  392.      if (sscanf (token, "%02X", &temp) != 1)
  393.         return TT_INVALID_PARAMETER;
  394.      MCAddr[i] = (BYTE) temp;
  395.     } /* endfor */
  396.  
  397.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  398.  
  399.   GenReq.ReqHandle = ++ReqHandle;
  400.   GenReq.Param1 = 0;
  401.   GenReq.Param2 = (void far *) &MCAddr;
  402.   GenReq.OpCode = ADDMULTICASTADDRESS;
  403.  
  404.   LastStatus = GenRequest ();
  405.  
  406.   PrintMsg (0, "Add Multicast Address:  %s", RetStr[LastStatus]);
  407.  
  408.   CheckGenRequest (ADDMULTICASTADDRESS, GenReq.ReqHandle);
  409.  
  410.   return SUCCESS;
  411. }
  412.  
  413. int TTDeleteMulticastAddr ()
  414. {
  415.   // DELMC <NetAddr> [<Return> [<Return>]]
  416.  
  417.   char   *token;
  418.   BYTE    MCAddr[ADDR_LEN];
  419.   USHORT  temp;
  420.   int     i;
  421.  
  422.   for (i=0; i<WedgeCommon->StnAdrSz; ++i)
  423.     {
  424.      if (!(token = strtok (NULL, "\n\t ")))
  425.         return TT_INVALID_PARAMETER;
  426.      if (sscanf (token, "%02X", &temp) != 1)
  427.         return TT_INVALID_PARAMETER;
  428.      MCAddr[i] = (BYTE) temp;
  429.     } /* endfor */
  430.  
  431.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  432.  
  433.   GenReq.ReqHandle = ++ReqHandle;
  434.   GenReq.Param1 = 0;
  435.   GenReq.Param2 = (void far *) &MCAddr;
  436.   GenReq.OpCode = DELETEMULTICASTADDRESS;
  437.  
  438.   LastStatus = GenRequest ();
  439.  
  440.   PrintMsg (0, "Delete Multicast Address:  %s", RetStr[LastStatus]);
  441.  
  442.   CheckGenRequest (DELETEMULTICASTADDRESS, GenReq.ReqHandle);
  443.  
  444.   return SUCCESS;
  445. }
  446.  
  447. int TTUpdateStatistics ()
  448. {
  449.   // USTAT [<Return> [<Return>]]
  450.  
  451.   int   rc;
  452.  
  453.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  454.  
  455.   GenReq.ReqHandle = ++ReqHandle;
  456.   GenReq.Param1 = 0;
  457.   GenReq.Param2 = 0L;
  458.   GenReq.OpCode = UPDATESTATISTICS;
  459.  
  460.   LastStatus = GenRequest ();
  461.  
  462.   PrintMsg (0, "Update Statistics:  %s", RetStr[LastStatus]);
  463.  
  464.   CheckGenRequest (UPDATESTATISTICS, GenReq.ReqHandle);
  465.  
  466.   return SUCCESS;
  467. }
  468.  
  469. int TTClearStat ()
  470. {
  471.   // CSTAT [<Return> [<Return>]]
  472.  
  473.   int   rc;
  474.  
  475.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  476.  
  477.   GenReq.ReqHandle = ++ReqHandle;
  478.   GenReq.Param1 = 0;
  479.   GenReq.Param2 = 0L;
  480.   GenReq.OpCode = CLEARSTATISTICS;
  481.  
  482.   LastStatus = GenRequest ();
  483.  
  484.   PrintMsg (0, "Clear Statistics:  %s", RetStr[LastStatus]);
  485.  
  486.   CheckGenRequest (CLEARSTATISTICS, GenReq.ReqHandle);
  487.  
  488.   return SUCCESS;
  489. }
  490.  
  491. int TTInterruptRequest ()
  492. {
  493.   // INTREQ [<Return> [<Return>]]
  494.  
  495.   int   rc;
  496.  
  497.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  498.  
  499.   GenReq.ReqHandle = ++ReqHandle;
  500.   GenReq.Param1 = 0;
  501.   GenReq.Param2 = 0L;
  502.   GenReq.OpCode = INTERRUPT;
  503.  
  504.   LastStatus = GenRequest ();
  505.  
  506.   PrintMsg (0, "Interrupt Request:  %s", RetStr[LastStatus]);
  507.  
  508.   CheckGenRequest (INTERRUPT, GenReq.ReqHandle);
  509.  
  510.   return SUCCESS;
  511. }
  512.  
  513. int TTSetFunctionalAddr ()
  514. {
  515.   // FUNADR <ShortNetAddr> [<Return> [<Return>]]
  516.  
  517.   char   *token;
  518.   BYTE    FuncAddr[ADDR_LEN];
  519.   USHORT  temp;
  520.   int     i;
  521.  
  522.   for (i=0; i<4; ++i)
  523.     {
  524.      if (!(token = strtok (NULL, "\n\t ")))
  525.         return TT_INVALID_PARAMETER;
  526.      if (sscanf (token, "%02X", &temp) != 1)
  527.         return TT_INVALID_PARAMETER;
  528.      FuncAddr[i] = (BYTE) temp;
  529.     } /* endfor */
  530.  
  531.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  532.  
  533.   GenReq.ReqHandle = ++ReqHandle;
  534.   GenReq.Param1 = 0;
  535.   GenReq.Param2 = (void far *) &FuncAddr;
  536.   GenReq.OpCode = SETFUNCTIONALADDRESS;
  537.  
  538.   LastStatus = GenRequest ();
  539.  
  540.   PrintMsg (0, "Set Functional Address:  %s", RetStr[LastStatus]);
  541.  
  542.   CheckGenRequest (SETFUNCTIONALADDRESS, GenReq.ReqHandle);
  543.  
  544.   return SUCCESS;
  545. }
  546.  
  547. int TTSetLookAhead ()
  548. {
  549.   // SETLOOK # [<Return> [<Return>]]
  550.  
  551.   char *token;
  552.   WORD  lookahead;
  553.  
  554.   if (!(token = strtok (NULL, "\n\t ")))
  555.      return TT_INVALID_PARAMETER;
  556.  
  557.   if ((lookahead = (WORD) GetNumericParm (token)) < 0)
  558.      return TT_INVALID_PARAMETER;
  559.  
  560.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  561.  
  562.   GenReq.ReqHandle = ++ReqHandle;
  563.   GenReq.Param1 = lookahead;
  564.   GenReq.Param2 = 0L;
  565.   GenReq.OpCode = SETLOOKAHEAD;
  566.  
  567.   LastStatus = GenRequest ();
  568.  
  569.   PrintMsg (0, "Set Lookahead %d:  %s", lookahead, RetStr[LastStatus]);
  570.  
  571.   CheckGenRequest (SETLOOKAHEAD, GenReq.ReqHandle);
  572.  
  573.   return SUCCESS;
  574. }
  575.  
  576. int TTModifyOpenParms ()
  577. {
  578.   // MODOPEN <OpenOptions> ["REQUEST_QUEUED" <Return> | <Return>]
  579.  
  580.   char *token;
  581.   WORD  OpenOptions;
  582.  
  583.   if (!(token = strtok (NULL, "\n\t ")))
  584.      return TT_INVALID_PARAMETER;
  585.  
  586.   if ((OpenOptions = (WORD) GetNumericParm (token)) < 0)
  587.      return TT_INVALID_PARAMETER;
  588.  
  589.   if (GetRetCodes ()) return TT_INVALID_PARAMETER;
  590.  
  591.   GenReq.ReqHandle = ++ReqHandle;
  592.   GenReq.Param1 = OpenOptions;
  593.   GenReq.Param2 = 0L;
  594.   GenReq.OpCode = MODIFYOPENPARMS;
  595.  
  596.   LastStatus = GenRequest ();
  597.  
  598.   PrintMsg (0, "ModifyOpenParms 0x%04X:  %s", OpenOptions, RetStr[LastStatus]);
  599.  
  600.   CheckGenRequest (MODIFYOPENPARMS, GenReq.ReqHandle);
  601.  
  602.   return SUCCESS;
  603. }
  604.  
  605.