doc/FAQ/serial.sgml
Jordan K. Hubbard 6d48a3a8d7 Added pointer to Greg's serial port patch for Acer UART-based systems.
Submitted by: Doug White <dwhite@gdi.uoregon.edu>
1998-05-19 01:47:43 +00:00

535 lines
21 KiB
Text

<!-- $Id: serial.sgml,v 1.2 1998-05-19 01:47:43 jkh Exp $ -->
<!-- The FreeBSD Documentation Project -->
<sect>
<heading>Serial Communications<label id="serial"></heading>
<p>This section answers common questions about serial communications
with FreeBSD. PPP and SLIP are covered in the <ref id="networking"
name="Networking"> section.
<sect1>
<heading>How do I tell if FreeBSD found my serial ports?</heading>
<p>As the FreeBSD kernel boots, it will probe for the serial ports
in your system for which the kernel was configured. You can
either watch your system closely for the messages it prints or
run the command
<verb>
dmesg | grep sio
</verb>
<p>after your system's up and running.
<p>Here's some example output from the above command:
<verb>
sio0 at 0x3f8-0x3ff irq 4 on isa
sio0: type 16550A
sio1 at 0x2f8-0x2ff irq 3 on isa
sio1: type 16550A
</verb>
<p>This shows two serial ports. The first is on irq 4, is using
port address <tt/0x3f8/, and has a 16550A-type UART chip. The
second uses the same kind of chip but is on irq 3 and is at port
address <tt/0x2f8/. Internal modem cards are treated just like
serial ports---except that they always have a modem ``attached''
to the port.
<p>The <tt/GENERIC/ kernel includes support for two serial ports
using the same irq and port address settings in the above
example. If these settings aren't right for your system, or if
you've added modem cards or have more serial ports than your
kernel is configured for, just reconfigure your kernel. See
section <ref id="make-kernel" name="about building a kernel"> for
more details.
<sect1>
<heading>How do I tell if FreeBSD found my modem cards?</heading>
<p>Refer to the answer to the previous question.
<sect1>
<heading>I just upgraded to 2.0.5 and my <tt/tty0X/ are missing!</heading>
<p>Don't worry, they have been merged with the <tt/ttydX/ devices.
You'll have to change any old configuration files you have, though.
<sect1>
<heading>How do I access the serial ports on FreeBSD?</heading>
<p>The third serial port, <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?sio" name="sio2"> (known as
COM3 in DOS), is on <tt>/dev/cuaa2</tt> for dial-out devices, and on
<tt>/dev/ttyd2</tt> for dial-in devices. What's the difference
between these two classes of devices?
<p>You use <tt/ttydX/ for dial-ins. When opening <tt>/dev/ttydX</tt>
in blocking mode, a process will wait for the corresponding
<tt/cuaaX/ device to become inactive, and then wait
for the carrier detect line to go active. When you open the
<tt/cuaaX/ device, it makes sure the serial port isn't already in
use by the <tt/ttydX/ device. If the port's available, it
``steals'' it from the <tt/ttydX/ device. Also, the <tt/cuaXX/
device doesn't care about carrier detect. With this scheme and
an auto-answer modem, you can have remote users log in and you
can still dialout with the same modem and the system will take
care of all the conflicts.
<sect1>
<heading>How do I enable support for a multiport serial card?</heading>
<p>Again, the section on kernel configuration provides information
about configuring your kernel. For a multiport serial card,
place an <htmlurl url="http://www.freebsd.org/cgi/man.cgi?sio"
name="sio"> line for each serial port on the card in the
kernel configuration file. But place the irq and vector
specifiers on only one of the entries. All of the ports on the
card should share one irq. For consistency, use the last serial
port to specify the irq. Also, specify the <tt/COM&lowbar;MULTIPORT/
option.
<p>The following example is for an AST 4-port serial card on irq 7:
<verb>
options "COM_MULTIPORT"
device sio4 at isa? port 0x2a0 tty flags 0x781
device sio5 at isa? port 0x2a8 tty flags 0x781
device sio6 at isa? port 0x2b0 tty flags 0x781
device sio7 at isa? port 0x2b8 tty flags 0x781 irq 7 vector siointr
</verb>
<p>The flags indicate that the master port has minor number 7
(<tt/0x700/), diagnostics enabled during probe (<tt/0x080/), and
all the ports share an irq (<tt/0x001/).
<sect1>
<heading>Can FreeBSD handle multiport serial cards sharing irqs?</heading>
<p>Not yet. You'll have to use a different irq for each card.
<sect1>
<heading>Can I set the default serial parameters for a port?</heading>
<p>The <tt/ttydX/ (or <tt/cuaaX/) device is the regular device
you'll want to open for your applications. When a process opens
the device, it'll have a default set of terminal I/O settings.
You can see these settings with the command
<verb>
stty -a -f /dev/ttyd1
</verb>
<p>When you change the settings to this device, the settings are in
effect until the device is closed. When it's reopened, it goes
back to the default set. To make changes to the default set, you
can open and adjust the settings of the ``initial state'' device.
For example, to turn on <tt/CLOCAL/ mode, 8 bits, and
<tt>XON/XOFF</tt> flow control by default for ttyd5, do:
<verb>
stty -f /dev/ttyid5 clocal cs8 ixon ixoff
</verb>
<p>A good place to do this is in <tt>/etc/rc.serial</tt>. Now, an
application will have these settings by default when it opens
<tt/ttyd5/. It can still change these settings to its liking,
though.
<p>You can also prevent certain settings from being changed by an
application by making adjustments to the ``lock state'' device.
For example, to lock the speed of <tt/ttyd5/ to 57600 bps, do
<verb>
stty -f /dev/ttyld5 57600
</verb>
<p>Now, an application that opens <tt/ttyd5/ and tries to change the
speed of the port will be stuck with 57600 bps.
<p>Naturally, you should make the initial state and lock state
devices writable only by <tt/root/. The <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?MAKEDEV"
name="MAKEDEV"> script does <bf/NOT/ do this when it creates the
device entries.
<sect1>
<heading>How can I enable dialup logins on my modem?</heading>
<p>So you want to become an Internet service provider, eh? First,
you'll need one or more modems that can auto-answer. Your modem
will need to assert carrier-detect when it detects a carrier and
not assert it all the time. It will need to hang up the phone
and reset itself when the data terminal ready (<tt/DTR/) line
goes from on to off. It should probably use <tt>RTS/CTS</tt>
flow control or no local flow control at all. Finally, it must
use a constant speed between the computer and itself, but (to be
nice to your callers) it should negotiate a speed between itself
and the remote modem.
<p>For many Hayes command-set--compatible modems, this command will
make these settings and store them in nonvolatile memory:
<verb>
AT &amp;C1 &amp;D3 &amp;K3 &amp;Q6 S0=1 &amp;W
</verb>
<p>See the section <ref id="direct-at" name="on sending AT
commands"> below for information on how to make these settings
without resorting to an MS-DOS terminal program.
<p>Next, make an entry in <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?ttys" name="/etc/ttys"> for the
modem. This file lists all the ports on which the operating system will
await logins. Add a line that looks something like this:
<verb>
ttyd1 "/usr/libexec/getty std.57600" dialup on insecure
</verb>
<p>This line indicates that the second serial port
(<tt>/dev/ttyd1</tt>) has a modem connected running at 57600 bps
and no parity (<tt/std.57600/, which comes from the file
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?gettytab"
name="/etc/gettytab">). The terminal type for this port is
``dialup.'' The port is ``on'' and is ``insecure''---meaning
root logins on the port aren't allowed. For dialin ports like
this one, use the <tt/ttydX/ entry.
<p>It's common practice to use ``dialup'' as the terminal type.
Many users set up in their .profile or .login files a prompt for
the actual terminal type if the starting type is dialup. The
example shows the port as insecure. To become root on this port,
you have to login as a regular user, then <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?su" name="su">'' to
<tt/root/. If you use ``secure'' then <tt/root/ can login in
directly.
<p>After making modifications to <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?ttys" name="/etc/ttys">, you
need to send a hangup or <tt/HUP/ signal to the <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?init" name="init"> process:
<verb>
kill -HUP 1
</verb>
<p>This forces the init process to reread <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?ttys" name="/etc/ttys">. The
init process will then start getty processes on all ``on'' ports.
You can find out if logins are available for your port by typing
<verb>
ps -ax | grep '[t]tyd1'
</verb>
<p>You should see something like:
<verb>
747 ?? I 0:00.04 /usr/libexec/getty std.57600 ttyd1
</verb>
<sect1>
<heading>How can I connect a dumb terminal to my FreeBSD box?</heading>
<p>If you're using another computer as a terminal into your FreeBSD
system, get a null modem cable to go between the two serial
ports. If you're using an actual terminal, see its accompanying
instructions.
<p>Then, modify <htmlurl url="http://www.freebsd.org/cgi/man.cgi?ttys"
name="/etc/ttys">, like above. For example, if you're hooking up a
WYSE-50 terminal to the fifth serial port, use an entry like this:
<verb>
ttyd4 "/usr/libexec/getty std.38400" wyse50 on secure
</verb>
<p>This example shows that the port on <tt>/dev/ttyd4</tt> has a
wyse50 terminal connected at 38400 bps with no parity
(<tt/std.38400/ from <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?gettytab"
name="/etc/gettytab">) and <tt/root/ logins are allowed (secure).
<sect1>
<heading>Why can't I run <tt/tip/ or <tt/cu/?</heading>
<p>On your system, the programs <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip"> and <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?cu" name="cu"> are probably
executable only by <htmlurl url="http://www.freebsd.org/cgi/man.cgi?uucp"
name="uucp"> and group <tt/dialer/. You can use the group <tt/dialer/
to control who has access to your modem or remote systems. Just add
yourself to group dialer.
<p>Alternatively, you can let everyone on your system run <tt/tip/
and <tt/cu/ by typing:
<verb>
# chmod 4511 /usr/bin/cu
# chmod 4511 /usr/bin/tip
</verb>
<sect1>
<heading>My stock Hayes modem isn't supported---what can I do?</heading>
<p>Actually, the man page for <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip"> is out of
date. There is a generic Hayes dialer already built in. Just use
``<tt/at=hayes/'' in your <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?remote" name="/etc/remote"> file.
<p>The Hayes driver isn't smart enough to recognize some of the
advanced features of newer modems---messages like <tt/BUSY/,
<tt/NO DIALTONE/, or <tt/CONNECT 115200/ will just confuse it.
You should turn those messages off when you use <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip"> (using
<tt/ATX0&amp;W/).
<p>Also, the dial timeout for <tt/tip/ is 60 seconds. Your modem
should use something less, or else tip will think there's a
communication problem. Try <tt/ATS7=45&amp;W/.
<p>Actually, as shipped <tt/tip/ doesn't yet support it fully. The
solution is to edit the file <tt/tipconf.h/ in the directory
<tt>/usr/src/usr.bin/tip/tip</tt> Obviously you need the source
distribution to do this.
<p>Edit the line ``<tt/#define HAYES 0/'' to ``<tt/#define HAYES
1/''. Then ``<tt/make/'' and ``<tt/make install/''. Everything
works nicely after that.
<sect1>
<heading>
How am I expected to enter these AT commands?<label id="direct-at">
</heading>
<p>Make what's called a ``<tt/direct/'' entry in your
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?remote"
name="/etc/remote"> file. For example, if your modem's hooked
up to the first serial port, <tt>/dev/cuaa0</tt>, then put in the
following line:
<verb>
cuaa0:dv=/dev/cuaa0:br#19200:pa=none
</verb>
<p>Use the highest bps rate your modem supports in the br
capability. Then, type <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip cuaa0"> and
you'll be connected to your modem.
<p>If there is no <tt>/dev/cuaa0</tt> on your system, do this:
<verb>
# cd /dev
# ./MAKEDEV cuaa0
</verb>
<p>Or use cu as root with the following command:
<verb>
# cu -l``line'' -s``speed''
</verb>
<p>with line being the serial port (e.g.<tt>/dev/cuaa0</tt>)
and speed being the speed (e.g.<tt>57600</tt>). When you are done
entering the AT commands hit <tt>~.</tt> to exit.
<sect1>
<heading>The <tt/@/ sign for the pn capability doesn't work!</heading>
<p>The <tt/@/ sign in the phone number capability tells tip to look in
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?phones(5)"
name="/etc/phones"> for a phone number. But the <tt/@/ sign is
also a special character in capability files like
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?remote"
name="/etc/remote">. Escape it with a backslash:
<verb>
pn=\@
</verb>
<sect1>
<heading>How can I dial a phone number on the command line?</heading>
<p>Put what's called a ``<tt/generic/'' entry in your
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?remote"
name="/etc/remote"> file. For example:
<verb>
tip115200|Dial any phone number at 115200 bps:\
:dv=/dev/cuaa0:br#115200:at=hayes:pa=none:du:
tip57600|Dial any phone number at 57600 bps:\
:dv=/dev/cuaa0:br#57600:at=hayes:pa=none:du:
</verb>
<p>Then you can things like ``<tt/tip -115200 5551234/''. If you
prefer <htmlurl url="http://www.freebsd.org/cgi/man.cgi?cu"
name="cu"> over <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip">, use a
generic cu entry:
<verb>
cu115200|Use cu to dial any number at 115200bps:\
:dv=/dev/cuaa1:br#57600:at=hayes:pa=none:du:
</verb>
<p>and type ``<tt/cu 5551234 -s 115200/''.
<sect1>
<heading>Do I have to type in the bps rate every time I do that?</heading>
<p>Put in an entry for <tt/tip1200/ or <tt/cu1200/, but go ahead and
use whatever bps rate is appropriate with the br capability. <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip"> thinks a good
default is 1200 bps which is why it looks for a ``<tt/tip1200/'' entry.
You don't have to use 1200 bps, though.
<sect1>
<heading>I access a number of hosts through a terminal server.</heading>
<p>Rather than waiting until you're connected and typing
``<tt/CONNECT &lt;host&gt;/'' each time, use tip's <tt/cm/
capability. For example, these entries in
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?remote"
name="/etc/remote">:
<verb>
pain|pain.deep13.com|Forrester's machine:\
:cm=CONNECT pain\n:tc=deep13:
muffin|muffin.deep13.com|Frank's machine:\
:cm=CONNECT muffin\n:tc=deep13:
deep13:Gizmonics Institute terminal server:\
:dv=/dev/cua02:br#38400:at=hayes:du:pa=none:pn=5551234:
</verb>
<p>will let you type ``<tt/tip pain/'' or ``<tt/tip muffin/'' to
connect to the hosts pain or muffin; and ``<tt/tip deep13/'' to
get to the terminal server.
<sect1>
<heading>Can tip try more than one line for each site?</heading>
<p>This is often a problem where a university has several modem lines
and several thousand students trying to use them...
<p>Make an entry for your university in <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?remote" name="/etc/remote">
and use <tt>\@</tt> for the <tt/pn/ capability:
<verb>
big-university:\
:pn=\@:tc=dialout
dialout:\
:dv=/dev/cuaa3:br#9600:at=courier:du:pa=none:
</verb>
<p>Then, list the phone numbers for the university in
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?phones"
name="/etc/phones">:
<verb>
big-university 5551111
big-university 5551112
big-university 5551113
big-university 5551114
</verb>
<p><htmlurl url="http://www.freebsd.org/cgi/man.cgi?tip"
name="tip"> will try each one in the listed order, then give up. If
you want to keep retrying, run <tt/tip/ in a while loop.
<sect1>
<heading>Why do I have to hit CTRL+P twice to send CTRL+P once?</heading>
<p>CTRL+P is the default ``force'' character, used to tell
<htmlurl url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip">
that the next character is literal data. You can set the force
character to any other character with the <tt/~s/ escape, which
means ``set a variable.''
<p>Type ``<tt/~sforce=&lt;single-char&gt;/'' followed by a newline.
<tt/&lt;single-char&gt;/ is any single character. If you leave
out <tt/&lt;single-char&gt;/, then the force character is the nul
character, which you can get by typing CTRL+2 or CTRL+SPACE. A
pretty good value for <tt/&lt;single-char&gt;/ is SHIFT+CTRL+6,
which I've seen only used on some terminal servers.
<p>You can have the force character be whatever you want by
specifying the following in your <tt>&dollar;HOME/.tiprc</tt>
file:
<verb>
force=<single-char>
</verb>
<sect1>
<heading>Suddenly everything I type is in UPPER CASE??</heading>
<p>You must've pressed CTRL+A, <htmlurl
url="http://www.freebsd.org/cgi/man.cgi?tip" name="tip"> ``raise
character,'' specially designed for people with broken caps-lock keys.
Use <tt/~s/ as above and set the variable ``raisechar'' to something
reasonable. In fact, you can set it to the same as the force
character, if you never expect to use either of these features.
<p>Here's a sample .tiprc file perfect for Emacs users who need to
type CTRL+2 and CTRL+A a lot:
<verb>
force=^^
raisechar=^^
</verb>
<p>The ^^ is SHIFT+CTRL+6.
<sect1>
<heading>How can I do file transfers with <tt/tip/?</heading>
<p>If you're talking to another UNIX system, you can send and
receive files with <tt/~p/ (put) and <tt/~t/ (take). These
commands run <htmlurl url="http://www.freebsd.org/cgi/man.cgi?cat"
name="cat"> and <htmlurl url="http://www.freebsd.org/cgi/man.cgi?echo"
name="echo"> on the remote system to accept and send files. The syntax
is:
<verb>
~p <local-file> [<remote-file>]
~t <remote-file> [<local-file>]
</verb>
<p>There's no error checking, so you probably should use another
protocol, like zmodem.
<sect1>
<heading>How can I run zmodem with <tt/tip/?</heading>
<p>First, install one of the zmodem programs from the ports
collection (such as one of the two from the comms category,
<htmlurl url="http://www.freebsd.org/cgi/ports.cgi?^lrzsz" name="lrzsz">
and <htmlurl url="http://www.freebsd.org/cgi/ports.cgi?^rzsz"
name="rzsz">).
<p>To receive files, start the sending program on the remote end.
Then, press enter and type ``<tt/~C rz/'' (or ``<tt/~C lrz/'' if
you installed lrzsz) to begin receiving them locally.
<p>To send files, start the receiving program on the remote end.
Then, press enter and type ``<tt/~C sz &lt;files&gt;/'' (or
``<tt/~C lsz &lt;files&gt;/'') to send them to the
remote system.
<sect1>
<heading>FreeBSD can't seem to find my serial ports, even when the
settings are correct.</heading>
<p>Motherboards and cards with Acer UARTs do not probe properly under
the FreeBSD sio probe. Obtain a patch from
<url url="http://www.lemis.com/serial-port-patch.html"
name="www.lemis.com"> to fix your problem.
</sect>