[mdlug] Serial port monitoring
Robert Meier
list1c30fe42 at bellsouth.net
Thu Jan 31 22:24:29 EST 2008
>> I wish to write a script that returns a TRUE value if and only if
>> (1) VMware is running, AND (2) the serial port (/dev/ttyS0) is actually
>> connected through the modem and phone line to a remote host.
>> * How may the state of Carrier Detect be read?
> By reading the status register of the port.
> stty -a < /dev/ttyS0
I assume you are refering to pin 8 in the IEEE/EIA RS-232 serial interface.
Unfortunately, stty only reports on the tty device,
which loses carrier detect in the abstraction.
The underlying hardware, if access is supported,
should be available via ioctl(2).
Start by looking at tty_ioctl(4), including TIOCM_CD.
It is probable you will have to load some additional
CONFIG_SERIAL_8250 kernel modules.
It is possible you will have to recompile your kernel,
as IIRC tty_ioctl support is no longer standard.
To interpret much of the above man pages you will need to download and
understand the spec sheet for the 8251 Universal Asynchronous Receiver
Transmitter that is the canonical hardware implementation of RS-232.
>> * If there is no actual modem, but just a straight serial connection
>> using pins 2, 3, and ground, can reading Carrier Detect in that
>> manner be relied upon to return an OFF status?
No.
If DCD pin 8 is disconnected, the standard requires that it be
pulled through a 3-7K resistance to within 2V of ground.
The standard identifies this as "transition" state,
neither logical 1 nor logical 0.
The analog portion of your motherboard,
between the serial port and the 8251 chip (or implementation),
may go to 1 (probable), go to 0, or wander randomly.
See http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html
for details.
If your goal is security,
then you might consider wiring the carrier detect line to a parallel
port pin to monitor it.
The standard method is ppp with chap.
Periodically, one side transmits a challenge (random integer?).
The receiver hashes the challenge with a secret key and returns it.
The transmitter compares the challenge and hash (with its own secret key).
A disconnected line is detected as soon as a challenge is unanswered.
Hopefully helpful,
--
Bob
"Computers are so badly designed!"
-- Brian Eno
More information about the mdlug
mailing list