home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / REACTX.ZIP / REACTX25 / RX25_C / REACTX25.C < prev    next >
Text File  |  1991-09-03  |  16KB  |  358 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /*  MODULE NAME : REACTX25.C                                             */
  4. /*                                                                       */
  5. /*  DESCRIPTIVE : REACTIVATE THE X.25 DLC "C" SAMPLE PROGRAM             */
  6. /*                                                                       */
  7. /*  FUNCTION:   This program issues the SET_USER_LOG_QUEUE verb          */
  8. /*              to wait for an error of type 0017.  If this is           */
  9. /*              a subtype 2 then either a link failure or an             */
  10. /*              adapter failure occured.  This module assumes an         */
  11. /*              adapter failed.  The DISCONNECT_PHYSICAL_LINK            */
  12. /*              and CONNECT_PHYSICAL_LINK verbs are then issued          */
  13. /*              until the CONNECT_PHYSICAL_LINK verb returns with        */
  14. /*              a non zero return code.  The Communications              */
  15. /*              Manager periodically reactivates the DLC so that         */
  16. /*              when this X.25 is reconnected the DLC should be          */
  17. /*              automatically reactivated.  It is still up to the        */
  18. /*              users application to reactivate the link either          */
  19. /*              explicitly or by attempting to use it again.             */
  20. /*                                                                       */
  21. /*  NOTES:      1. If the adapter is in a condition such that it can     */
  22. /*                 not be reactivated successfully then this program     */
  23. /*                 may attempt many times.  Each attempt will cause      */
  24. /*                 errors to be logged.                                  */
  25. /*                                                                       */
  26. /*  Licensed Material - Program Property of IBM - All Rights Reserved    */
  27. /*                                                                       */
  28. /*************************************************************************/
  29.  
  30. #include <STDIO.H>
  31. #include <STDDEF.H>
  32. #include <STDLIB.H>
  33. #include <STRING.H>
  34. #include <ACSMGTC.H>
  35. #include <ACSSVCC.H>
  36. #include <io.h>
  37.  
  38. /* Macro clear_vcb sets the APPC verb control block to zeros */
  39.  
  40. #define clear_vcb()     memset(&vcb,(int)'\0',sizeof(vcb))
  41.  
  42. /* Extract selector or offset from far pointer */
  43. #define SELECTOROF(p)       (((unsigned short *)&(p))[1])
  44. #define OFFSETOF(p)         (((unsigned short *)&(p))[0])
  45.  
  46. /***********************************************************/
  47. /*        General Declares                                 */
  48. /***********************************************************/
  49.  
  50. unsigned far *vcbptr;                       /* Pointer to the vcb           */
  51. unsigned short error_code;                  /* Dos Call return code         */
  52. unsigned short qhandle;                     /* Queue handle                 */
  53. unsigned long qrequest;                     /* Queue request                */
  54. unsigned char qpriority;                    /* Queue priority               */
  55. void far *qsemhandle;                       /* Queue semephore handle       */
  56. unsigned short qlength;                     /* Queue element length         */
  57. unsigned char qname[17];                    /* Queue name \QUEUES\ERRLOG17  */
  58. unsigned long thirty_seconds = 30000;       /* Wait time for CM to start    */
  59. unsigned long forty_five_seconds = 45000;   /* Wait time betweeen attempts  */
  60. unsigned short msel;                        /* Selector of CM shared mem    */
  61. unsigned short cont;                        /* Continue if adap fail        */
  62. unsigned short i;
  63. unsigned short j;
  64. unsigned char mname[24];                    /* Memory \SHAREMEM\ACSLGMEM    */
  65. unsigned char save_link_name[8] = "";       /* X.25 link name               */
  66. unsigned char save_link_mode = ' ';         /* X.25 link mode               */
  67. struct x25_overlay far *x25_info_ptr;       /* Pointer to X.25 display info */
  68.  
  69. struct allocmem
  70.     {
  71.     unsigned short allocoff;
  72.     unsigned short allocsel;
  73.     };
  74.  
  75. union
  76.     {
  77.     struct allocmem am;
  78.     unsigned char far *buff_ptr;
  79.     } alloc_ptr;
  80.  
  81. /***********************************************************/
  82. /*        General Constants                                */
  83. /***********************************************************/
  84.  
  85. #define ON                  0x01
  86. #define OFF                 0x00
  87. #define YES                 0x01
  88. #define NO                  0x00
  89. #define LOGS                0x00
  90. #define ALL                 0x01
  91. #define SOME                0x00
  92. #define ZERO                0x00
  93. #define ONE                 0x01
  94. #define TWO                 0x02
  95. #define FIFO                0x0000
  96. #define ALLOC_FLAGS         0x0003
  97. #define ERROR_TYPE          0x1700
  98. #define NUM_BYTES           0x0400
  99. #define WAIT                0x00
  100. #define NOWAIT              0x01
  101. #define LEN_INIT_SECT       44;
  102. #define NUM_SECTIONS        9;
  103.  
  104. /***********************************************************/
  105. /*        External Entry Points                            */
  106. /***********************************************************/
  107.  
  108.                                             /* DosAllocSeg                  */
  109.      extern unsigned short pascal far DosAllocSeg (
  110.             unsigned short,
  111.             unsigned short far *,
  112.             unsigned short);
  113.                                             /* DosCreateQueue               */
  114.      extern unsigned short pascal far DosCreateQueue (
  115.             unsigned short far *,
  116.             unsigned short,
  117.             unsigned char far *);
  118.                                             /* DosReadQueue                 */
  119.      extern unsigned short pascal far DosReadQueue (
  120.             unsigned short,
  121.             unsigned long far *,
  122.             unsigned short far *,
  123.             unsigned long far *,
  124.             unsigned char,
  125.             unsigned char,
  126.             unsigned char far *,
  127.             void far *);
  128.                                             /* DosGetShrSeg                 */
  129.      extern unsigned short pascal far DosGetShrSeg (
  130.             unsigned char far *,
  131.             unsigned short far *);
  132.                                             /* DosSubFree                   */
  133.      extern unsigned short pascal far DosSubFree (
  134.             unsigned short,
  135.             unsigned short,
  136.             unsigned short);
  137.  
  138.                                             /* DosSleep                     */
  139.      extern unsigned short pascal far DosSleep (
  140.             unsigned long);
  141.  
  142.    /**********************************************************/
  143.    /*            Application Control Interface               */
  144.    /**********************************************************/
  145.  
  146.  struct return_code
  147.      {
  148.      unsigned short opcode;
  149.      unsigned short opext;
  150.      unsigned char prim_rc1;
  151.      unsigned char prim_rc2;
  152.      };
  153.  
  154.  union verbs
  155.      {
  156.      struct connect_physical_link cl;
  157.      struct disconnect_physical_link dl;
  158.      struct display dsp;
  159.      struct set_user_log_queue sulq;
  160.      struct return_code rc;
  161.      } vcb;
  162.  
  163.  struct error_log_queue_element
  164.      {
  165.      unsigned short elqqueue_id;  /* Verb operation code      */
  166.      unsigned char reserv2[8];    /* Reserved                 */
  167.      unsigned char elqhour;       /* Hour                     */
  168.      unsigned char elqminute;     /* Minute                   */
  169.      unsigned char elqsecond;     /* Second                   */
  170.      unsigned char elqhundred;    /* Hundreth of second       */
  171.      unsigned char elqday;        /* Day                      */
  172.      unsigned char elqmonth;      /* Month                    */
  173.      unsigned short elqyear;      /* Year                     */
  174.      unsigned short elqtype;      /* Error Type               */
  175.      unsigned long elqsubtype;    /* Error Subtype            */
  176.      unsigned char elqconv_id[4]; /* Conversation ID          */
  177.      unsigned char elqorig_id[8]; /* Originator ID            */
  178.      unsigned char reserv3[4];    /* Reserved                 */
  179.      unsigned short elqpid;       /* Process ID               */
  180.      unsigned short elqlength;    /* Element Length           */
  181.      unsigned char elqdata[20];   /* Element Data             */
  182.      } far *error_log_ptr;
  183.  
  184.  union
  185.      {
  186.      unsigned long log_ptr;
  187.      struct error_log_queue_element far *error_log_ptr;
  188.      } lp;
  189. /*--------------------------------------------------------------------------*/
  190. /*                       Function Prototypes                                */
  191. /*--------------------------------------------------------------------------*/
  192.  
  193. void main(void);
  194. void GET_INFO(void);                        /* Copy Error Log               */
  195. void SET_LOG_QUEUE(void);                   /* Set User Log Queue           */
  196. void CONNECT_X25(void);                     /* Activate DLC                 */
  197.  
  198. /****************************************************************************/
  199. /*                                                                          */
  200. /*                       Main Program Section                               */
  201. /*                                                                          */
  202. /****************************************************************************/
  203.  
  204. void
  205. main()
  206.  
  207. {
  208.   qsemhandle = 0;                          /* Queue semephore not used     */
  209.  
  210.   SET_LOG_QUEUE();
  211.   while (1 == 1) {
  212.      printf("\nWaiting for Adapter Failure");
  213.                                             /* Read Queue with WAIT option  */
  214.      error_code = DosReadQueue(qhandle,
  215.                                &qrequest,
  216.                                &qlength,
  217.                                &lp.log_ptr,
  218.                                FIFO,
  219.                                WAIT,
  220.                                &qpriority,
  221.                                qsemhandle);
  222.      printf("\nRead Queue Wait error code:  %u", error_code);
  223.      printf("\nError Log Subtype:  %lu", lp.error_log_ptr->elqsubtype);
  224.                                             /* If error subtype 00000002    */
  225.                                             /* then it is either a link     */
  226.                                             /* or an adapter failure.       */
  227.                                             /* Treat as an adapter failure  */
  228.      if (lp.error_log_ptr->elqsubtype == 2) {
  229.                                             /* Free the memory for the      */
  230.                                             /* error log                    */
  231.         error_code = DosSubFree (SELECTOROF(lp.error_log_ptr),
  232.                                  OFFSETOF(lp.error_log_ptr),
  233.                                  44 + lp.error_log_ptr->elqlength);
  234.         printf("\nDosSubFree error code:  %u", error_code);
  235.                                             /* Get X.25 information with    */
  236.                                             /* the DISPLAY verb.            */
  237.         GET_INFO();
  238.                                             /* Reactivate the DLC           */
  239.         if ((vcb.dsp.primary_rc == 0) && (cont == YES)) {
  240.            do {
  241.                CONNECT_X25();
  242.                if (vcb.dsp.primary_rc > 0) {
  243.                    printf("\nSleeping 45 seconds");
  244.                    DosSleep(forty_five_seconds);
  245.                }
  246.            } while (vcb.cl.primary_rc > 0);
  247.         }
  248.      }
  249.   }
  250. }
  251.  
  252. /****************************************************************************/
  253. /*                                                                          */
  254. /*                            FUNCTIONS                                     */
  255. /*                                                                          */
  256. /****************************************************************************/
  257.  
  258. void
  259. SET_LOG_QUEUE (void)
  260. {
  261.    strcpy (qname,"\\QUEUES\\ERRLOG17");     /* Create the Queue             */
  262.    error_code = DosCreateQueue(&qhandle,FIFO,qname);
  263.    printf("\nCreate Queue error code:  %u", error_code);
  264.    strcpy (mname,"\\SHAREMEM\\ACSLGMEM");   /* Access the memory where CM   */
  265.    error_code = DosGetShrSeg(mname,&msel);  /* puts the error log           */
  266.    while (error_code == 2) {
  267.       printf("\nWaiting for 30 seconds for Comm Mgr to start");
  268.       DosSleep(thirty_seconds);
  269.       error_code = DosGetShrSeg(mname,&msel);
  270.    } /* endif */
  271.    printf("\nGet Share Memory error code:  %u", error_code);
  272.    clear_vcb();
  273.    vcb.sulq.opcode = SV_SET_USER_LOG_QUEUE;
  274.    strcpy (vcb.sulq.queue_name, qname);     /* Queue name                   */
  275.    vcb.sulq.forward = LOGS;                 /* Receive LOGS only            */
  276.    vcb.sulq.suppress = ALL;                 /* Suppress all onscreen msgs   */
  277.    vcb.sulq.selection = SOME;               /* Receive some error logs      */
  278.    vcb.sulq.numbers[0] = 23;                /* Receive only Type 0017       */
  279.    vcbptr = (unsigned far *)&vcb;
  280.    ACSSVC((long) vcbptr);                   /* Call Common Services         */
  281.    printf("\nSet User Log Queue primary rc:  %2.2X%2.2X",
  282.           vcb.rc.prim_rc1, vcb.rc.prim_rc2);
  283. }
  284.  
  285. void
  286. GET_INFO (void)
  287. {
  288.    error_code = DosAllocSeg(NUM_BYTES, &alloc_ptr.am.allocsel, ALLOC_FLAGS);
  289.    printf("\nAlloc Seg error code:  %u", error_code);
  290.    clear_vcb();
  291.    vcb.dsp.opcode = AP_DISPLAY;             /* Prepare and call the         */
  292.    vcb.dsp.init_sect_len = LEN_INIT_SECT;   /* DISPLAY verb                 */
  293.    vcb.dsp.buffer_len = NUM_BYTES;
  294.    vcb.dsp.buffer_ptr = alloc_ptr.buff_ptr;
  295.    vcb.dsp.num_sections = NUM_SECTIONS;
  296.    vcb.dsp.x25_physical_link_info = AP_YES;
  297.    vcbptr = (unsigned far *)&vcb;
  298.    ACSMGT((long) vcbptr);                   /* Call Common Services         */
  299.    printf("\nDisplay primary rc:  %2.2X%2.2X",
  300.           vcb.rc.prim_rc1, vcb.rc.prim_rc2);
  301.                                             /* Save the link name and the   */
  302.                                             /* link mode.                   */
  303.                                             /* This code assumes only one   */
  304.                                             /* failure.                     */
  305.    if (vcb.dsp.primary_rc == 0) {
  306.         cont = NO;
  307.         x25_info_ptr =
  308.             (struct x25_overlay far *)
  309.             ((char far *) vcb.dsp.x25_physical_link_info_ptr +
  310.             vcb.dsp.x25_physical_link_info_ptr -> x25_init_sect_len);
  311.         for (i=0;
  312.              i<=vcb.dsp.x25_physical_link_info_ptr->num_x25_link_entries;
  313.              i++) {
  314.             if (x25_info_ptr->link_state == AP_ERROR_LEVEL_1 |
  315.                 x25_info_ptr->link_state == AP_ERROR_LEVEL_2 ) {
  316.                for (j=0;j<8;j++) {
  317.                save_link_name[j] = x25_info_ptr->link_name[j];
  318.                }
  319.                save_link_mode = x25_info_ptr->link_mode;
  320.                cont = YES;
  321.             }
  322.         } /* endfor */
  323.    }
  324. }
  325.  
  326. void
  327. CONNECT_X25 ()
  328. {
  329.   clear_vcb();                                /* Zero the vcb               */
  330.   vcb.dl.opcode = AP_DISCONNECT_PHYSICAL_LINK;/* MGMT verb - ACTIVATE_DLC   */
  331.   memcpy (vcb.dl.physical_link_name, save_link_name, 8);
  332.  
  333.   vcbptr = (unsigned far *)&vcb;              /* Get pointer to the vcb     */
  334.  
  335.   ACSMGT((long) vcbptr);                      /* Call MGMT Services         */
  336.   printf("\nDisconnect Physical Link primary rc:  %2.2X%2.2X",
  337.           vcb.rc.prim_rc1, vcb.rc.prim_rc2);
  338.  
  339.   clear_vcb();                                /* Zero the vcb               */
  340.   vcb.cl.opcode = AP_CONNECT_PHYSICAL_LINK;   /* MGMT verb - ACTIVATE_DLC   */
  341.   memcpy (vcb.cl.physical_link_name, save_link_name, 8);
  342.   if (save_link_mode == TWO) {
  343.      vcb.cl.connection_type = ONE;
  344.   } else {
  345.      vcb.cl.connection_type = ZERO;
  346.   }
  347.  
  348.   vcbptr = (unsigned far *)&vcb;              /* Get pointer to the vcb     */
  349.  
  350.   ACSMGT((long) vcbptr);                      /* Call MGMT Services         */
  351.   printf("\nConnect Physical Link primary rc:  %2.2X%2.2X",
  352.           vcb.rc.prim_rc1, vcb.rc.prim_rc2);
  353.  
  354. }
  355.  
  356.  
  357. /* EOF - REACTX25.C */
  358.