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

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*      FILE: SERVER.C                                                        */
  4. /*                                                                            */
  5. /*   PURPOSE: This file contains the server/workstation command processing.   */
  6. /*                                                                            */
  7. /* FUNCTIONS: TTServer                                                        */
  8. /*            TTWorkstation                                                   */
  9. /*            TTMonitor                                                       */
  10. /*            AddWorkStation                                                  */
  11. /*            DeleteWorkStation                                               */
  12. /*                                                                            */
  13. /* GLOBAL DATA ACCESSED                                                       */
  14. /*      USHORT      LastStatus;                                               */
  15. /*      WORD        IndicationCount;                                          */
  16. /*      SERVICESTAT MACMSS;                                                   */
  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.  
  33. int TTServer ()
  34. {
  35.   // SERVER
  36.  
  37.   // set WEDGE Response Mode to SERVER
  38.   WedgeCommon->RspMode = SERVER;
  39.  
  40.   aprintf (0, 76, 0x74, "S");
  41.  
  42.   return SUCCESS;
  43. }
  44.  
  45. int TTWorkstation ()
  46. {
  47.   // WKSTA
  48.  
  49.   BOOLEAN ServerFound = FALSE;
  50.   WORD    i, j, mode;
  51.  
  52.   // clear the current server address
  53.   for (i=0; i<WedgeCommon->StnAdrSz; ++i)
  54.      WedgeCommon->ServerAddr[i] = 0;
  55.  
  56.   // temporarily set our mode to WORKSTATION
  57.   mode = WedgeCommon->RspMode;
  58.   WedgeCommon->RspMode = WORKSTATION;
  59.  
  60.   // send out a control frame to find a server
  61.   SendControlFrame (CCWKSTA);
  62.  
  63.   // wait for server's response
  64.   for (i=0; i<20; ++i)
  65.     {
  66.      CheckIndications ();
  67.      // check the server address
  68.      for (j=0; j<WedgeCommon->StnAdrSz; ++j)
  69.         if (WedgeCommon->ServerAddr[j])
  70.            ServerFound = TRUE;
  71.      if (ServerFound) break;
  72.      DosSleep (100);
  73.     } /* endfor */
  74.  
  75.   if (ServerFound)
  76.     {
  77.      aprintf (0, 76, 0x74, "W");
  78.      return (LastStatus = SUCCESS);
  79.     }
  80.   else
  81.     {
  82.      WedgeCommon->RspMode = mode;
  83.      LastStatus = GENERAL_FAILURE;
  84.      return TT_NO_SERVER;
  85.     }
  86.  
  87. }
  88.  
  89. int TTMonitor ()
  90. {
  91.   // MONITOR
  92.  
  93.   // tell SERVER we're no longer a WORKSTATION
  94.   if (WedgeCommon->RspMode == WORKSTATION)
  95.      SendControlFrame (CCDELWKSTA);
  96.  
  97.   // reset WEDGE Response Mode to PEEPER
  98.   WedgeCommon->RspMode = PEEPER;
  99.  
  100.   aprintf (0, 76, 0x74, " ");
  101.  
  102.   return SUCCESS;
  103. }
  104.  
  105. void AddWorkStation ()
  106. {
  107.   int        i;
  108.   WKSTAITEM *new, *curr = WkStaTop;
  109.  
  110.   // check that workstation's address is not already in the list
  111.   while (curr != NULL)
  112.     {
  113.      for (i=0; i<MACMSC.MscStnAdrSz; ++i)
  114.         if (curr->WkstaAddr[i] != *(ControlFrame.pSrc + i))
  115.            break;
  116.      if (i == MACMSC.MscStnAdrSz) // already there
  117.         return;
  118.      else
  119.         curr = curr->next;
  120.     } /* endwhile */
  121.  
  122.   // create workstation item
  123.   new = (WKSTAITEM *) calloc (1, sizeof (WKSTAITEM));
  124.  
  125.   // fill in workstation item's address
  126.   new->next = NULL;
  127.   for (i=0; i<MACMSC.MscStnAdrSz; ++i)
  128.      new->WkstaAddr[i] = *(ControlFrame.pSrc + i);
  129.   new->Stressing = FALSE;
  130.  
  131.   // add workstation item to the list
  132.   if (WkStaTop == NULL)
  133.     {
  134.      WkStaTop = new;
  135.      new->prev = NULL;
  136.     }
  137.   else
  138.     {
  139.      curr = WkStaTop;
  140.      while (curr->next != NULL)
  141.         curr = curr->next;
  142.  
  143.      new->prev = curr;
  144.      curr->next = new;
  145.     }
  146. }
  147.  
  148. void DeleteWorkStation ()
  149. {
  150.   int        i;
  151.   WKSTAITEM *curr = WkStaTop;
  152.  
  153.   while (curr != NULL)
  154.     {
  155.      for (i=0; i<MACMSC.MscStnAdrSz; ++i)
  156.         if (curr->WkstaAddr[i] != *(ControlFrame.pSrc + i))
  157.            break;
  158.      if (i == MACMSC.MscStnAdrSz)
  159.        {
  160.         if (curr == WkStaTop)
  161.           {
  162.            free (WkStaTop);
  163.            WkStaTop = curr->next;
  164.            curr->prev = NULL;
  165.            return;
  166.           }
  167.         else if (curr != NULL)
  168.           {
  169.            curr->next->prev = curr->prev;
  170.            curr->prev->next = curr->next;
  171.            free (curr);
  172.            return;
  173.           }
  174.        }
  175.      else
  176.         curr = curr->next;
  177.     } /* endwhile */
  178. }
  179.  
  180. USHORT QueryWorkStations ()
  181. {
  182.   USHORT     WkstaCnt = 0;
  183.   WKSTAITEM *curr = WkStaTop;
  184.  
  185.   while (curr != NULL)
  186.     {
  187.      WkstaResponded = FALSE;
  188.      _fmemcpy ((void far *) ControlFrame.pSrc,
  189.                (void far *) curr->WkstaAddr,
  190.                MACMSC.MscStnAdrSz);
  191.      SendControlFrame (CCQUERYWKSTA);
  192.      DosSleep (500);
  193.      CheckIndications ();
  194.      if (WkstaResponded == FALSE)
  195.         DeleteWorkStation ();
  196.      else
  197.        {
  198.         ++WkstaCnt;
  199.         curr->Stressing = TRUE;
  200.        }
  201.      curr = curr->next;
  202.     }
  203.  
  204.   return WkstaCnt;
  205. }
  206.  
  207. void StopWkStaStress ()
  208. {
  209.   int        i;
  210.   WKSTAITEM *curr = WkStaTop;
  211.  
  212.   while (curr != NULL)
  213.     {
  214.      for (i=0; i<MACMSC.MscStnAdrSz; ++i)
  215.         if (curr->WkstaAddr[i] != *(ControlFrame.pSrc + i))
  216.            break;
  217.      if (i == MACMSC.MscStnAdrSz)
  218.        {
  219.         if (curr->Stressing)
  220.           {
  221.            curr->Stressing = FALSE;
  222.            --WkstaStressCnt;
  223.           }
  224.         break;
  225.        }
  226.      else
  227.         curr = curr->next;
  228.     } /* endwhile */
  229. }
  230.  
  231.