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

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*      FILE: INDIC.C                                                         */
  4. /*                                                                            */
  5. /*   PURPOSE: This file contains the Indications processing.                  */
  6. /*                                                                            */
  7. /* FUNCTIONS: CheckIndications                                                */
  8. /*            CheckControlFrame                                               */
  9. /*            TTXmitConfirm                                                   */
  10. /*            TTReceiveLookahead                                              */
  11. /*            TTIndicationComplete                                            */
  12. /*            TTReceiveChain                                                  */
  13. /*            TTStatusIndication                                              */
  14. /*            TTGenReqConf                                                    */
  15. /*                                                                            */
  16. /* GLOBAL DATA ACCESSED                                                       */
  17. /*      char     *RetStr[]                                                    */
  18. /*      char     *GenReqStr[]                                                 */
  19. /*      BOOLEAN   Echo,                                                       */
  20. /*                ServerStressAck,                                            */
  21. /*                WkstaResponded                                              */
  22. /*      USHORT    ReqHandle,                                                  */
  23. /*                LastStatus,                                                 */
  24. /*                WkstaStressCnt                                              */
  25. /*      WORD      IndicationCount,                                            */
  26. /*                LastFrameSize,                                              */
  27. /*                LastLookahead                                               */
  28. /*      CTRLFRAME ControlFrame                                                */
  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.  
  46. BOOLEAN StartWkstaStress = FALSE;
  47.  
  48. WORD CheckIndications ()
  49. {
  50.   INDICQ IndicQElem;
  51.  
  52.   while (WedgeCommon->CurrIndic != WedgeCommon->NextFreeIndic)
  53.     {
  54.      IndicQElem = WedgeCommon->IndicQueue[WedgeCommon->CurrIndic];
  55.      if (++WedgeCommon->CurrIndic == INDIC_QUEUE_SIZE)
  56.         WedgeCommon->CurrIndic = 0;
  57.  
  58.      ++IndicationCount;
  59.      ++IndicCnt.Total;
  60.  
  61.      switch (IndicQElem.IndicType)
  62.        {
  63.         case TRANSMITCONFIRM:
  64.           ++IndicCnt.Tx;
  65.           TTXmitConfirm (IndicQElem);
  66.           break;
  67.         case RECEIVELOOKAHEAD:
  68.           ++IndicCnt.Rx;
  69.           _fmemcpy ((void far *) ControlFrame.pBuffer,
  70.                     (void far *) WedgeCommon->RcvData,
  71.                     MAX_IMMED_LEN);
  72.           TTReceiveLookahead (IndicQElem);
  73.           break;
  74.         case INDICATIONCOMPLETE:
  75.           ++IndicCnt.Comp;
  76.           TTIndicationComplete (IndicQElem);
  77.           break;
  78.         case RECEIVECHAIN:
  79.           ++IndicCnt.Rx;
  80.           _fmemcpy ((void far *) ControlFrame.pBuffer,
  81.                     (void far *) WedgeCommon->RcvData,
  82.                     MAX_IMMED_LEN);
  83.           TTReceiveChain (IndicQElem);
  84.           break;
  85.         case STATUSINDICATION:
  86.           ++IndicCnt.Stat;
  87.           TTStatusIndication (IndicQElem);
  88.           break;
  89.         case GENREQCONF:
  90.           ++IndicCnt.GenReq;
  91.           TTGenReqConf (IndicQElem);
  92.           break;
  93.        } /* endswitch */
  94.  
  95.      return IndicQElem.IndicType;
  96.     } /* endif */
  97.  
  98.   if (StartWkstaStress)
  99.     {
  100.      StartWkstaStress = FALSE;
  101.      StressWksta ();
  102.     }
  103.  
  104.   return 0;
  105. }
  106.  
  107. int CheckControlFrame ()
  108. {
  109.   // check the Receive Data Buffer (RcvData) for control frames
  110.  
  111.   char      cmd[80], *p;
  112.   BYTE far *data;
  113.   int       i, offset, opcode = 0;
  114.  
  115.   if (!strncmp ((char *) ControlFrame.pID, "IBM", 3))
  116.     {
  117.      _fmemset (ControlFrame.pID, 0, 4);
  118.      // we got a control frame
  119.      opcode = (int) *(int *) (ControlFrame.pOpCode);
  120.      switch (opcode)
  121.        {
  122.         case CCWKSTA:
  123.           // Broadcast Control Frame: WORKSTATION -> SERVER
  124.           //    Tells the SERVER the WORKSTATION's address
  125.           // if we're a Server
  126.           //    1) add this workstation to the list of workstations and
  127.           //    2) send out a control frame directed to the workstation
  128.           //       to let him know this server's address
  129.           if (WedgeCommon->RspMode == SERVER)
  130.             {
  131.              AddWorkStation ();
  132.              DosSleep (1000);
  133.              SendControlFrame (CCSERVER);
  134.             }
  135.           break;
  136.         case CCSERVER:
  137.           // Directed Control Frame: SERVER -> WORKSTATION
  138.           //    Tells the WORKSTATION the SERVER's address
  139.           // if we're a Workstation,
  140.           //    copy the Source Address into WedgeCommon->ServerAddr
  141.           if (WedgeCommon->RspMode == WORKSTATION)
  142.             {
  143.              _fmemcpy ((void far *) WedgeCommon->ServerAddr,
  144.                        (void far *) ControlFrame.pSrc,
  145.                        WedgeCommon->StnAdrSz);
  146.             } /* endif */
  147.           break;
  148.         case CCSTRESS:
  149.           // Broadcast Control Frame: SERVER -> WORKSTATIONs
  150.           //    Tells WORKSTATIONs to start stressing
  151.           if (WedgeCommon->RspMode == WORKSTATION && !WedgeCommon->StressMode)
  152.             {
  153.              DosSleep (1000);
  154.              PrintMsg (RED, "CCSTRESS received");
  155.              hexprint (ControlFrame.pBuffer, 64, 0);
  156.              StartWkstaStress = TRUE;
  157.             }
  158.           break;
  159.         case CCXMIT:
  160.           // Directed Control Frame: WORKSTATION -> SERVER
  161.           //    Tells SERVER to transmit frame(s) to the WORKSTATION.
  162.           //    (Essentially a MULTRAN command to the SERVER.)
  163.           if (WedgeCommon->RspMode == SERVER)
  164.             {
  165.              strcpy (cmd, "MULTRAN ");
  166.              /* get the data out of the frame */
  167.              data = (BYTE far *) ControlFrame.pData;
  168.  
  169.              // get the frame count (required)
  170.              sprintf (cmd + 8, "%ld ", *(DWORD *) data);
  171.              p = cmd + strlen (cmd);
  172.              data += sizeof (DWORD);
  173.  
  174.              // get the Min (required)
  175.              sprintf (p, "%ld ", *(DWORD *) data);
  176.              p = cmd + strlen (cmd);
  177.              data += sizeof (DWORD);
  178.  
  179.              // get the Max (required)
  180.              sprintf (p, "%ld ", *(DWORD *) data);
  181.              p = cmd + strlen (cmd);
  182.              data += sizeof (DWORD);
  183.  
  184.              // get Type - if DIRECTED, fill in Type and NetAddr
  185.              if (*(WORD *) data == DIRECTED)
  186.                {
  187.                 sprintf (p, "%d ", *(WORD *) data);
  188.                 p = cmd + strlen (cmd);
  189.                 data += sizeof (WORD);
  190.                 // frame is directed to the given address
  191.                 for (i=0; i<WedgeCommon->StnAdrSz; ++i, p+=3, ++data)
  192.                    sprintf (p, "%02X ", *(BYTE *) data);
  193.                }
  194.              else if (*(WORD *) data == DIRECTED_TO_WKSTA)
  195.                {
  196.                 sprintf (p, "%d ", *(WORD *) data);
  197.                 p = cmd + strlen (cmd);
  198.                 data = (BYTE far *) ControlFrame.pSrc;
  199.                 // frame is directed to the workstation
  200.                 // sending the control frames
  201.                 for (i=0; i<WedgeCommon->StnAdrSz; ++i, p+=3, ++data)
  202.                    sprintf (p, "%02X ", *(BYTE *) data);
  203.                }
  204.  
  205.              // call MULTRAN with command parameters set up
  206.              ParseCommand (cmd);
  207.             }
  208.           break;
  209.  
  210.         case CCDELWKSTA:
  211.           // Directed Control Frame: WORKSTATION -> SERVER
  212.           //    Workstation is logging off
  213.           // If we're a SERVER,
  214.           //    Delete the workstation from the list
  215.           if (WedgeCommon->RspMode == SERVER)
  216.             {
  217.              PrintMsg (RED, "CCDELWKSTA received");
  218.              hexprint (ControlFrame.pBuffer, 64, 0);
  219.              DeleteWorkStation ();
  220.             }
  221.           break;
  222.  
  223.         case CCENDSTRESS:
  224.           // Directed Control Frame: WORKSTATION -> SERVER
  225.           //    Tells the SERVER the WORKSTATION is finished stressing.
  226.           // If we're a SERVER,
  227.           //    1) Acknowledge the WORKSTATION
  228.           //    2) Decrement number of WORKSTATIONs stressing
  229.           if (WedgeCommon->RspMode == SERVER)
  230.             {
  231.              PrintMsg (RED, "CCENDSTRESS received");
  232.              hexprint (ControlFrame.pSrc, MACMSC.MscStnAdrSz, 0);
  233.              StopWkStaStress ();
  234.              SendControlFrame (CCENDSTRESSACK);
  235.             }
  236.           break;
  237.  
  238.         case CCENDSTRESSACK:
  239.           // Directed Control Frame: SERVER -> WORKSTATION
  240.           //    Acknowledges the WORKSTATION's ENDSTRESS frame.
  241.           PrintMsg (RED, "CCENDSTRESSACK received");
  242.         case CCSRVSTOP:
  243.           // Broadcast Control Frame: SERVER -> WORKSTATIONs
  244.           //    Tells WORKSTATION's that SERVER has ended stress test.
  245.           if (opcode == CCSRVSTOP)
  246.              PrintMsg (RED, "CCSRVSTOP received");
  247.  
  248.           // If we're a WORKSTATION,
  249.           //    Cease sending ENDSTRESS
  250.           if (WedgeCommon->RspMode == WORKSTATION)
  251.              ServerStressAck = TRUE;
  252.           break;
  253.  
  254.         case CCQUERYWKSTA:
  255.           // Directed Control Frame: SERVER -> WORKSTATION
  256.           //    Asks WORKSTATIONs to respond.
  257.           // If we're a WORKSTATION,
  258.           //    Send a CCQUERYACK frame back to the SERVER
  259.           if (WedgeCommon->RspMode == WORKSTATION)
  260.             {
  261.              PrintMsg (RED, "CCQUERYWKSTA received");
  262.              hexprint (ControlFrame.pDest, 2 * MACMSC.MscStnAdrSz, 0);
  263.              SendControlFrame (CCQUERYACK);
  264.             }
  265.           break;
  266.  
  267.         case CCQUERYACK:
  268.           // Directed Control Frame: WORKSTATION -> SERVER
  269.           //    Acknowledges the SERVER's QUERYWKSTA frame.
  270.           // If we're a SERVER,
  271.           //    Check the WORKSTATION list
  272.           if (WedgeCommon->RspMode == SERVER)
  273.             {
  274.              PrintMsg (RED, "CCQUERYACK received");
  275.              hexprint (ControlFrame.pDest, 2 * MACMSC.MscStnAdrSz, 0);
  276.              WkstaResponded = TRUE;
  277.             }
  278.           break;
  279.        } /* endswitch */
  280.     }
  281.  
  282.   return opcode;
  283.  
  284. }
  285.  
  286. int TTXmitConfirm (INDICQ IndicQElem)
  287. {
  288.   LastStatus = IndicQElem.Parm[1];
  289.  
  290.   PrintMsg (0, "TransmitConfirm:  Status = %s  Handle = %u",
  291.                 RetStr[LastStatus], IndicQElem.Parm[0]);
  292.  
  293.   UpdateInfo ();
  294.  
  295.   return SUCCESS;
  296. }
  297.  
  298. int TTReceiveLookahead (INDICQ IndicQElem)
  299. {
  300.   LastFrameSize = IndicQElem.Parm[0];
  301.   LastLookahead = IndicQElem.Parm[1];
  302.  
  303.   PrintMsg (0, "ReceiveLookahead:  FrameSize = %d  Lookahead = %d",
  304.              LastFrameSize, LastLookahead);
  305.  
  306.   if (!CheckControlFrame () && Echo)
  307.     {
  308.      // echo the received frame back to the sender
  309.      PrimEcho ();
  310.     }
  311.  
  312.   UpdateInfo ();
  313.  
  314. //if (WedgeCommon->TotalRxErr && WedgeCommon->CheckData)
  315. //  {
  316. //   WedgeCommon->TotalRxErr = 0L;
  317. //   PrintMsg (RED, "Data Error in Received Frame");
  318. //  }
  319.  
  320.   return SUCCESS;
  321. }
  322.  
  323. int TTIndicationComplete (INDICQ IndicQElem)
  324. {
  325.   PrintMsg (0, "Indication Complete");
  326.   return SUCCESS;
  327. }
  328.  
  329. int TTReceiveChain (INDICQ IndicQElem)
  330. {
  331.   LastFrameSize = IndicQElem.Parm[0];
  332.   LastLookahead = IndicQElem.Parm[1];
  333.  
  334.   PrintMsg (0, "Receive Chain:  FrameSize = %d   Handle = %u",
  335.              LastFrameSize, LastLookahead);
  336.  
  337.   CheckControlFrame ();
  338.  
  339.   UpdateInfo ();
  340.  
  341. //if (WedgeCommon->TotalRxErr)
  342. //  {
  343. //   WedgeCommon->TotalRxErr = 0L;
  344. //   PrintMsg (RED, "Data Error in Received Frame");
  345. //  }
  346.  
  347.   return SUCCESS;
  348. }
  349.  
  350. int TTStatusIndication (INDICQ IndicQElem)
  351. {
  352.   switch (IndicQElem.Parm[1])
  353.     {
  354.      case RINGSTATUS:
  355.        ++IndicCnt.RingStatus;
  356.        PrintMsg (0, "Ring Status Indication:  %04X", IndicQElem.Parm[0]);
  357.        break;
  358.      case ADAPTERCHECK:
  359.        ++IndicCnt.AdapterCheck;
  360.        PrintMsg (0, "Adapter Check Indication:  %04X", IndicQElem.Parm[0]);
  361.        break;
  362.      case STARTRESET:
  363.        ++IndicCnt.StartReset;
  364.        PrintMsg (0, "MAC Start Reset Indication");
  365.        break;
  366.      case ENDRESET:
  367.        ++IndicCnt.EndReset;
  368.        PrintMsg (0, "MAC End Reset Indication");
  369.        break;
  370.      case INTERRUPT:
  371.        ++IndicCnt.Interrupt;
  372.        PrintMsg (0, "Interrupt Indication");
  373.        break;
  374.     } /* endswitch */
  375.  
  376.   return SUCCESS;
  377. }
  378.  
  379. int TTGenReqConf (INDICQ IndicQElem)
  380. {
  381.   LastStatus = IndicQElem.Parm[1];
  382.  
  383.   PrintMsg (0, "General Request Confirmation:  %s",
  384.                                    GenReqStr[IndicQElem.Parm[2] - 1]);
  385.   PrintMsg (0, "                               Handle %u", IndicQElem.Parm[0]);
  386.   PrintMsg (0, "                               Status %s", RetStr[LastStatus]);
  387.  
  388.   return SUCCESS;
  389. }
  390.  
  391.