Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!purdue!decwrl!sun!pitstop!sundc!seismo!uunet!van-bc!sl
From: sl@van-bc.UUCP (pri=-10 Stuart Lynne)
Newsgroups: comp.dcom.modems
Subject: Re: Solution to Problems with UUCP/modems.
Keywords: modems ACU driver
Message-ID: <1888@van-bc.UUCP>
Date: 22 Sep 88 19:17:26 GMT
References: <1260@moscom.UUCP> <324@mikros.systemware.de>
Reply-To: sl@van-bc.UUCP (pri=-10 Stuart Lynne)
Organization: Wimsey Associates, Vancouver, BC.
Lines: 89

In article <324@mikros.systemware.de> stefan@mikros.UUCP (Stefan Stapelberg) writes:
>In article <1260@moscom.UUCP> jgp@moscom.UUCP (Jim Prescott) writes:
>>
>>[driver supporting dialin/dialout on same device]
>>
>>Anybody know why everyone hasn't picked up on this?  I know that some of
>>the PC Unix systems use it.
>
>I would like to implement this scheme, but controlling the
>DTR signal from the modem turns out to be a problem: The modem
>doesn't answer rings if DTR has not been asserted by the opening
>process.  Unfortunately, I have to use DTR to hangup the modem
>after dialing out.
>
>So my question is: If getty's open has asserted DTR high and
>uucico's last close sets DTR to low, how can I ensure that the
>modem still will answer rings?  I cannot use the RI signal.
>
>I didn't want to have the driver to look for a "RING" (in word
>responses or as a hardware signal) and initializing the modem
>from within driver level seems to be a bad idea also.
>

It's actually quite easy when you do it in the driver. In the close routine
you must:

	wakeup((caddr_t)&tp->t_canq);

This wakes up the process (getty in this case) waiting for DCD to be set
(remembering that getty already saw DCD get set for this session, but
ignored it because another process was also waiting, so it went back to
sleep). Then in the wait loop for the getty device:

	
  case GDEVICE:        		/* getty, wait for carrier 		*/
    /* if nobody is already waiting or has opened the physical device
     * we init tp, and the hardware, to raise DTR 
     */
    if ( !( *statep & GISOPEN ) ) {
      *statep |= GWOPEN;
      x = SPLTTY();
      if ( !( flag & FNDELAY ) ) 	/* should we wait for CARR_ON 	*/
	while ( 
	  (*statep & GWOPEN ) &&	/* have we been cancelled? 	*/
	  (( *statep & (LISOPEN|MISOPEN)) || 	/* anyone else open? 	*/
	  (!( tp->t_state & CARR_ON )) )	/* no carrier yet? 	*/
	) {
          delay(GETTYWAIT*HZ);		/* wait a bit			*/
          if ( *statep == GWOPEN ) {	/* if only GWOPEN		*/
            ttinit( tp );		/* fake tty init and raise DTR	*/
            tp->t_proc = XXXPROC;
            tp->t_state |= WOPEN;	/* getty waiting		*/
            XXXPARAM( dev, tp, ON, NO );
            YYYSTS( chan );		/* should we be doing this?	*/
            if ( YYYSDCD( chan ) ) 
              tp->t_state |= CARR_ON;
            else
              tp->t_state &= ~CARR_ON;
          }
          if ( !(tp->t_state&CARR_ON) || (*statep != GWOPEN) )
	    sleep((caddr_t)&tp->t_canq, TTIPRI );/* wait for carrier 	*/
	}
      if ( *statep & GWOPEN ) {		/* was open cancelled by close? */
	*statep &= ~GWOPEN;		/* reset GWOPEN			*/
	*statep |= GISOPEN;		/* set GISOPEN			*/
        delay(GETTYWAIT*HZ);		/* give modem time to get line	*/
        ttyflush( tp, FREAD|FWRITE );	/* dump any messages from modem	*/	
        YYYSTS( chan );			/* should we be doing this?	*/
        if ( !YYYSDCD( chan ) ) 	/* check for DCD again		*/
          goto errexit;			/* oh boy! let's bomb out	*/
					/* could try goto top;		*/
      }
      else {
	*statep &= ~(GWOPEN|GISOPEN);	/* reset GWOPEN			*/
	goto errexit;			/* can't hack it bomb out	*/
      }

Basically getty continously sleeps waiting for DCD. Whenever it wakes up it
checks for DCD, no one else having the port open, etc. If DCD is no asserted
then it waits two seconds, raises DTR and goes back to sleep. This gives the
modem plenty of time to reset (Hayes are the worst I've seen, take about 1
second to reset). 

Another little feature is to wait one or two seconds after seeing DCD and
flushing the buffers. This will get rid of any unwanted messages from your
modem.

-- 
Stuart.Lynne@wimsey.bc.ca {ubc-cs,uunet}!van-bc!sl     Vancouver,BC,604-937-7532