;;; -*- Mode:Common-Lisp; Package:TELNET; Base:10 -*-


;;;                           RESTRICTED RIGHTS LEGEND

;;;Use, duplication, or disclosure by the Government is subject to
;;;restrictions as set forth in subdivision (b)(3)(ii) of the Rights in
;;;Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;                     TEXAS INSTRUMENTS INCORPORATED.
;;;                              P.O. BOX 2909
;;;                           AUSTIN, TEXAS 78769
;;;                                 MS 2151
;;;
;;; Copyright (C) 1987, Texas Instruments Incorporated. All rights reserved.
;;; Copyright (C) 1987 Unisys Corporation
;;; All Rights Reserved

(NET:DEFINE-LOGICAL-CONTACT-NAME "telnet" '((:serial-stream t)))

(DEFMETHOD (BASIC-NVT :CASE :NETWORK-CONNECTED-P :SERIAL) ()
  stream)

(DEFMETHOD (BASIC-NVT :CASE :CHECK-CONNECTION-STATE :SERIAL) ()	  
  (IF stream
      :ESTABLISHED
      (THROW 'NVT-DONE (FORMAT () "Connection in unknown state:~S" (SEND stream :STATUS)))))

(DEFMETHOD (BASIC-TELNET :CASE :NETWORK-SEND-IP :SERIAL) ())




#|   The rest of this stuff is from the Rel 2.0 implementation just in case I need it

;;; This method should return the network connection. This can
;;; be a stream or a connection object depending on the network type.
;;;
;;; The method :NETWORK-NEW-CONNECTION is not needed for serial telnet.
(DEFMETHOD (basic-nvt :case :network-new-connection :serial) 
	   (host &optional (contact "TELNET") (window nil) )
  window contact host nil)                                       ; BAC to eliminate compile warnings

(RECOMPILE-FLAVOR 'vt100-frame :NETWORK-NEW-CONNECTION)

;;; Return nil if the connection is not connected.
(DEFMETHOD (basic-nvt :case :network-connected-p :serial)()
  (and stream connection))

(RECOMPILE-FLAVOR 'vt100-frame :NETWORK-CONNECTED-P)

;;; The method :NETWORK-NEW-CONNECTION passes the arguement which we
;;; ignore for the serial implementation.
;;;
;;; Set stream to be the serial stream.
;;; Connection should be something non nil, but does not need to be a connection.  
;;; The connection instance variable is used by CHAOSNET.
(DEFMETHOD (basic-nvt :case :set-connection :serial) (ignore)
  (SEND typein-process :reset)
  (SEND typeout-process :reset)
  (SETF stream (MAKE-SERIAL-STREAM-FROM-CVV))
;;  (SEND self :gobble-greeting)
  (SETF connection t)
  (SETQ black-on-white nil))

(RECOMPILE-FLAVOR 'vt100-frame :SET-CONNECTION)

;;; This method should close the serial TELNET connection.
;;; Make sure to set both instance variables, STREAM and CONNECTION,
;;; to nil.
(DEFMETHOD (basic-nvt :case :network-disconnect :serial)()
  (WHEN stream
    (SEND stream :close)
    (SETF stream nil
	  connection nil)))

(RECOMPILE-FLAVOR 'vt100-frame :NETWORK-DISCONNECT)

;;; This method should indicate the connection state.
;;; It would be nice if you could signal errors in the connection
;;; state by throwing 'NVT-DONE because TELNET will try to eloquently
;;; close the connection.
(defmethod (basic-nvt :case :check-connection-state :serial)()
  (unless stream
      (*THROW 'TELNET:NVT-DONE "Stream never opened.")))

(RECOMPILE-FLAVOR 'vt100-frame :CHECK-CONNECTION-STATE)

;;; Send the TELNET command interrupt process (IP) to the remote host.
;;; (Note: IP should not be confused with the acronym for a well known
;;; network type.)
;;; An IP command is defined to be the following two bytes: NVT-IAC NVT-IP.
;;; Many implementations send the IP in urgent mode as the following sequence of bytes
;;; NVT-IAC, NVT-IP, NVT-IAC, NVT-DM.  This is technically a SYNC signal but 
;;; most systems handle no differently. The TCP/IP network sends a SYNC signal
;;; in urgent mode, the CHAOS network sends a SYNC signal not in urgent mode
;;; because there is no concept of urgent data, Wollongong sends just an IP command
;;; and the MIT PC software sends a SYNC signal in urgent mode.
;;;  
;;; You may choose to send a SYNC signal or just IP command I think it makes little
;;; difference (except with Wollongong which can't handle SYNC signals successfully).
;;; However, since serial streams do not have a concept of 
;;; urgent mode I choose to send a SYNC signal.
(DEFMETHOD (basic-telnet :case :network-send-ip :serial)()
  (lock-output
    (SEND stream :tyo NVT-IAC)
    (SEND stream :tyo NVT-IP)
    (SEND stream :tyo NVT-IAC)
    (SEND stream :tyo NVT-DM)
    ))

(RECOMPILE-FLAVOR 'vt100-frame :NETWORK-SEND-IP)

(UNLESS (MEMBER :serial protocols-supporting-telnet)   
  (PUSH :serial protocols-supporting-telnet))

;;; This is a kludge to make serial telnet work correctly.
;;; If there were serial host objects then this would not 
;;; be necessary.
(setq default-network-type :serial)         |#
  

