From owner-mgetty Tue Apr 12 07:03:18 1994
Return-Path: <owner-mgetty>
Received: by greenie.muc.de (/\==/\ Smail3.1.24.1 #24.3)
	id <m0pqad2-0001JIC@greenie.muc.de>; Tue, 12 Apr 94 07:03 MEST
Return-Path: <colin!phiger.com!argus>
Received: by greenie.muc.de (/\==/\ Smail3.1.24.1 #24.3)
	id <m0pqad2-00022vC@greenie.muc.de>; Tue, 12 Apr 94 07:03 MEST
Received: from subnet.sub.net ([192.101.75.3]) by colin.muc.de with SMTP id <135983>; Tue, 12 Apr 1994 05:45:04 +0200
Received: from flatlin.ka.sub.org by subnet.sub.net with bsmtp id <16268>; Tue, 12 Apr 1994 05:43:26 +0200
Received: by flatlin.ka.sub.org id <m0pqXOt-0000zeC>; 12 Apr 1994 03:36 +0200
Received: by phiger.com (Smail3.1.28.1 #3)
	id m0pqTmj-00024AC; Mon, 11 Apr 94 23:44 CDT
Message-Id: <m0pqTmj-00024AC@phiger.com>
Subject: Who asked for the "last call's diagnosis"-logging? Here it is...
To:	mgetty@muc.de (MGETTY Mailing List)
Date:	Mon, 11 Apr 1994 23:44:48 +0200
From:	Uwe Fuerst <argus@ganymed.phiger.com>
Reply-To: "Uwe S. Fuerst" <uf@phiger.com>
X-Disclaimer: All views are my own unless explicitly stated otherwise.
X-Organization: PHI-Germany,Uwe S.Fuerst,Maeuslpoint 33,94557 Niederalteich,FRG
X-Phone: Mobil: +49 161 5213751,Office: +49 9901 3691,FAX/Data: +49 9901 3692
X-Fidonet: Uwe Fuerst 2:2494/22.4
X-Datex-J: 099013691-0001
X-Mailer: ELM [version 2.4 PL21]
Content-Type: text
Content-Length: 8123      
Status: RO

Hi all,

I've just finished the work on the logging facility for the diagnosis
information of the last call. I've tested this feature with my ZyXEL, but
the function should be useable with every other modem that supports this
feature, too.

In policy.h you now can define the "AT.." command that requests the last
call's diagnosis (e.g. "ATI2" for ZyXEL modems), and a log level at which
the output of this command should get logged to the logfile under /tmp
(and -- if SYSLOG is defined -- to your syslog file, too).

This command get executed every once *before* the modem gets re-initialized.
By this you'll get the diagnosis information for every dial/fax-in/out.

The log for a ZyXEL will look like:

in /tmp/log_mg.<device>:
-------------------------------------------------------------------------------
04/11 23:10:42  check for lockfiles
04/11 23:10:43  locking the line
04/11 23:10:43  lowering DTR to reset Modem
04/11 23:10:43  send: \d\d\d+++\d\d\d[0d]\dATQ0V1H0[0d][0a]
04/11 23:10:47  waiting for ``OK'' ** found **
04/11 23:10:47  send: ATI2[0d][0a]
04/11 23:10:47  waiting for ``OK''
04/11 23:10:47 ##### diag:    ZyXEL U-MODEM LINK STATUS REPORT

04/11 23:10:47 ##### diag:    Chars Sent           498     Chars Received      16128k

04/11 23:10:47 ##### diag:    Octets Sent          526     Octets Received       403

04/11 23:10:47 ##### diag:    Blocks Sent           29     Blocks Received        57

04/11 23:10:47 ##### diag:    Blocks Resent          0     Max Outstanding         7

04/11 23:10:47 ##### diag:    Max Block Size       256     Retrains Requested      0

04/11 23:10:47 ##### diag:    Link Duration          0     Retrains Granted        0

04/11 23:10:47 ##### diag:    T401 Timeouts          0     T402 Timeouts           4

04/11 23:10:47 ##### diag:    FCS Errors             1     Round Trip Delay       14

04/11 23:10:47 ##### diag:    Xmitter Underrun       0     Receiver Overrun        0

04/11 23:10:47 ##### diag:    Last Speed/Protocol     CONNECT 2400/ARQ/V42b

04/11 23:10:47 ##### diag:    Disconnect Reason      Local Hang Up
 ** found **
04/11 23:10:48  send: ATS0=0S10=20Q0&D3&H3&N0&K4S40.2=1[0d][0a]
04/11 23:10:48  waiting for ``OK'' ** found **
04/11 23:10:48  send: AT+FCLASS=0[0d][0a]
04/11 23:10:48  waiting for ``OK'' ** found **
04/11 23:10:48  send: AT+FAA=1;+FBOR=0;+FCR=1[0d][0a]
04/11 23:10:48  waiting for ``OK'' ** found **
04/11 23:10:48  send: AT+FLID="+49 9901 3692"[0d][0a]
04/11 23:10:48  waiting for ``OK'' ** found **
04/11 23:10:48  send: AT+FDCC=1,5,0,2,0,0,0[0d][0a]
04/11 23:10:48  waiting for ``OK'' ** found **
04/11 23:10:48  waiting...
-------------------------------------------------------------------------------

in <somewhere>/syslog:
-------------------------------------------------------------------------------
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    ZyXEL U-MODEM LINK STATUS REPORT
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Chars Sent           498     Chars Received      16128k
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Octets Sent          526     Octets Received       403
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Blocks Sent           29     Blocks Received        57
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Blocks Resent          0     Max Outstanding         7
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Max Block Size       256     Retrains Requested      0
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Link Duration          0     Retrains Granted        0
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    T401 Timeouts          0     T402 Timeouts           4
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    FCS Errors             1     Round Trip Delay       14
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Xmitter Underrun       0     Receiver Overrun        0
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Last Speed/Protocol     CONNECT 2400/ARQ/V42b
Apr 11 23:10:47 ganymed mgetty[8422]: diag:    Disconnect Reason      Local Hang Up
-------------------------------------------------------------------------------

I have no idea where the empty lines in "/tmp/log_mg.<device>" come from,
they do not appear in my syslog file...

Comments? Bugs?

Regards,
		Uwe

Here's the diff:
-------------------------------------------------------------------------------
*** orig/mgetty.c	Mon Apr 11 23:24:48 1994
--- mgetty.c	Mon Apr 11 23:25:49 1994
***************
*** 54,59 ****
--- 54,65 ----
  
  char *	init_chat_seq[] = { "", "\\d\\d\\d+++\\d\\d\\d\r\\dATQ0V1H0", "OK",
  
+ #ifdef CALL_DIAGNOSIS
+ /* display diagnosis information ? - may be defined in policy.h
+  */
+  			    CALL_DIAGNOSIS, "OK",
+ #endif
+ 
  /* initialize the modem - defined in policy.h
   */
  			    MODEM_INIT_STRING, "OK",
*** orig/policy.h-dist	Mon Apr 11 23:19:54 1994
--- policy.h-dist	Mon Apr 11 23:23:50 1994
***************
*** 205,210 ****
--- 205,226 ----
   */
  #define MODEM_INIT_STRING	"ATS0=0Q0&D3&H3&N0&K4"
  
+ /* output of the last call's diagnosis
+  *
+  * set this to the proper command for your modem to display diagnosis
+  * information about the last connection. For ZyXELs this is "ATI2"
+  * if this is defined, this command gets executed every time *before*
+  * the modem is re-initialized.
+  */
+ #define CALL_DIAGNOSIS		"ATI2"
+ 
+ /* log level for CALL_DIAGNOSIS
+  *
+  * set this to the level you want to get the information logged at.
+  * Default is "L_AUDIT" (see mgetty.h for available log level).
+  */
+ #define CALL_DIAG_LOG_LEVEL	L_AUDIT
+ 
  /* command termination string
   *
   * for most modems, terminating the AT... command with "\r" is
*** orig/do_chat.c	Mon Apr 11 23:27:20 1994
--- do_chat.c	Mon Apr 11 23:39:09 1994
***************
*** 44,50 ****
  int	str;
  char	*p;
  int	h;
! boolean	nocr;
  TIO	tio, save_tio;
  #define	LSIZE	100
  static	char	lbuf[LSIZE];
--- 44,50 ----
  int	str;
  char	*p;
  int	h;
! boolean	nocr, diag;
  TIO	tio, save_tio;
  #define	LSIZE	100
  static	char	lbuf[LSIZE];
***************
*** 113,133 ****
  
  		if ( cnt > 0 )
  		{
! 		    lputc( L_NOISE, buffer[i] );
  
! 		    /* build full lines, feed them to caller-id / connect
! 		     * string parsing routine in cnd.c
! 		     */
! 		    if ( buffer[i] == '\r' || buffer[i] == '\n' ||
! 			 (lptr >= lbuf+LSIZE-3) )
! 		    {
! 			*lptr = '\0';
! 			if (lbuf[0])
! 			    cndfind(lbuf);
! 			lptr = lbuf;
  		    }
! 		    else
! 			*lptr++ = buffer[i];
  		}
  
  		i += cnt;
--- 113,155 ----
  
  		if ( cnt > 0 )
  		{
! #ifdef CALL_DIAGNOSIS
! 		    if ( diag && strncmp(lbuf, "OK", 2) != 0 ) {
! 		        if ( buffer[i] == '\r' || buffer[i] == '\n' ||
! 			     (lptr >= lbuf+LSIZE-3) )
! 		        {
! 			    *lptr = '\0';
! 			    if (lbuf[0])
! #ifdef CALL_DIAG_LOG_LEVEL
! 				lprintf( CALL_DIAG_LOG_LEVEL, "diag: %s", lbuf );
! #else
! 				lprintf( L_AUDIT, "diag: %s", lbuf );
! #endif
! 			    lptr = lbuf;
! 		        }
! 		        else
! 			    *lptr++ = buffer[i];
! 		    }
! 		    else {
! #endif
! 		        lputc( L_NOISE, buffer[i] );
  
! 		        /* build full lines, feed them to caller-id / connect
! 		         * string parsing routine in cnd.c
! 		         */
! 		        if ( buffer[i] == '\r' || buffer[i] == '\n' ||
! 			     (lptr >= lbuf+LSIZE-3) )
! 		        {
! 			    *lptr = '\0';
! 			    if (lbuf[0])
! 			        cndfind(lbuf);
! 			    lptr = lbuf;
! 		        }
! 		        else
! 			    *lptr++ = buffer[i];
! #ifdef CALL_DIAGNOSIS
  		    }
! #endif
  		}
  
  		i += cnt;
***************
*** 188,194 ****
--- 210,223 ----
  
  	p = expect_send[str];
  	nocr = FALSE;
+ 	diag = FALSE;
          h = 0;
+ 
+ #ifdef CALL_DIAGNOSIS
+         if ( strncmp( p, CALL_DIAGNOSIS, strlen(CALL_DIAGNOSIS) ) == 0 )
+             diag = TRUE;
+ #endif
+ 
  	while ( *p != 0 ) 
  	{
  	    if ( *p == '\\' )
-------------------------------------------------------------------------------
-- 
Uwe S. ___ # uf@phiger.com            Just my $0.02 (thanks for the bandwidth).
Fuerst <|> # "I think your conclusions are valid for an optimal kernel, but
       ~~~ #  this is SCO, and we have no such thing."         -- Bill Davidsen

