Serial PPP Links andModems

Internal modems - interrupt conflicts

If your computer already has a COM1 and COM2 serial port, then you will need to install your internal modem as COM3 or COM4. Unfortunately, the way the PC was originally designed, the choice of Interrupt Request (IRQ) lines leads to a conflict, and won't work under Linux:
Port   Linux device  Base I/O Addr   IRQ
------------------------------------------
COM1      ttyS0           3F8         4
COM2      ttyS1           2F8         3
COM3      ttyS2           3E8         4 [*]  clashes with COM1
COM4      ttyS3           2E8         3 [*]  clashes with COM2
The solution is to set your modem port to a different interrupt; good choices are COM3-IRQ5 (unless you have a sound card, which is often already using IRQ5) and COM4-IRQ2. (IRQ2 is the same as IRQ9 on a PC, so if your modem has a link for IRQ9, that's fine too). Don't use IRQ7 - this is used by the printer port.

Check the interrupts used on your machine with the command 'cat  /proc/interrupts' .

Once you have set up your modem, using on-board jumpers or DIP switches, you need to tell Linux when it boots to use a different IRQ. Add a line or lines like this to /etc/rc.d/rc.local

    setserial -v /dev/ttyS2 irq 5
    setserial -v /dev/ttyS3 irq 2
If you need to install an internal modem as COM1 or COM2, and your PC already has a COM1 or COM2, then you must disable the existing COM port (possible from BIOS if your PC motherboard is having this option). This might be a jumper on your I/O card, or for motherboards with on-board I/O, a BIOS setup setting.

External modems - old UARTs

The chip in your PC which converts parallel information into a serial data stream to your modem, and back again, is called a UART (Universal Asynchronous Receiver Transmitter). The original UART (part number 8250 or 16450) could only hold one character at a time, which meant that if the processor didn't fetch characters from it quickly enough, they could be lost. The new UART is called a 16550A, and can buffer up to 16 characters, making data loss much less likely and reducing the workload on the processor too.

It's easy to check which you have - look at the kernel messages when the system boots up. If you have 8250 or 16450 UARTs, they are unlikely to work at above 9600 bits per second (and even at 9600 may loose characters occasionally). Upgrade your PCs I/O card to one which has 16550A UARTs; this shouldn't cost you more than around US$30.

Most internal modems have 16550A UARTs on board - so this problem doesn't arise for them. Most modern motherboards also have 16550A UARTs on-board.

Cables & connectors
Serial port
A "straight" RS232 cable is used to connect a modem to a computer. The modem end usually has a 25 pin female RS232 socket, and a computer may have either a 9pin or a 25pin male socket. A "crossed" or "null modem" RS232 cable is used to connect a terminal to a computer, and should not be used to connect a modem.

A four wire RJ11 cable usually connects the phone line to the modem. Ordinary phone lines use just two of the wires, but leased lines may use all four.

Modems and Modem Configuration

Modems are devices that you use to connect your (digital) computer to an (analog) phone line. The modem communicates with the computer over a serial (COM) port. The modem is called the DCE (Data Communication Equipment), and the computer is called the DTE (Data Terminal Equipment).

Initially, very low transfer rates of only 30 or 120 characters per second (300 or 1200 bits per second (baud)) were the maximum speeds but now even 28.8Kbps is now old fashioned the 56Kbps standard has emerged.

If files are not pre-compressed before transmission, in-transfer modem compression (MNP5 or V42 protocols) can yield even higher effective transmission speeds.

But attaining these connection speeds depends very much on the quality of the telephone line and in some areas of most developing countries it is still necessary to work at lower speeds. In some cases where the signal strength is very low or if there is a lot of interference on the line, it may be necessary to re-dial many times or to drop the modem speed to 2400 or even 1200 baud to ensure a reliable connection.

Modems vary considerably in quality. Ability to handle poor phone lines varies considerably from one modem brand to another, and not necessarily in ways that would be expected - some high-end popular modems are poor at handling bad lines - for example US Robotics Sportsters. Modems that work well under difficult conditions include the Zyxel and the Microcoms, others may be just as good tho. If there are problems connecting it is well worth trying out different modem brands.

Modems have four important settings:

For configuration, modems will use either AT commands, or DIP switches, or have some configuration utility to let you set these options (e.g. via an LCD panel in the front). Most modems are "Hayes-compatible" which refers to the standard set of AT commands they can understand. Unfortunately the Hayes "standard" isn't. Simple commands, like placing a call, are pretty much the same between modems; but when you need to do something more complex, such as setting how fast your modem communicates with a remote modem, you have little choice but to dig out the manual and look up the command, since the command set varies widely from one manufacturer to another.

There are also many different parameters you can set, and manufacturers do not agree what is a "good" default setting to send from the factory. For example, U.S. Robotics Sportsters used to ship with software handshaking (XON/XOFF) enabled by default. However this setting interferes with many dial-up protocols such as SLIP and XMODEM, and in general needs to be changed. Different brands of modems have slightly different commands, so you need to refer to your modem manual to find out exactly how this works for your modem.

Dialup and leased line

Modems can be used in dialup mode on ordinary phone lines, or in leased line mode. Not all modems can operate in leased line mode. Leased line modems can usually operate in either synchronous or async mode, whereas dialup modems usually operate in async mode only.

In dialup mode, the modem dials a telephone number, attempts to connect to a modem which answers, and establishes a connection. In the leased line mode, it expects to be permanently connected to a modem on the remote side.

Exercises

Setting up the Point-to-Point Protocol (PPP)

Setting up a PPP links with Linux is done with the ppp daemon, pppd, which provides an IP transport layer for asynchronous serial interfaces.

The pppd daemon carries out the following activities after it is run:

  1. establishes the physical link
  2. negotiating the ppp Link Control Protocol (LCP)
  3. negotiating IP parameters
  4. creating a ppp device (ppp0, ppp1...)
  5. configuring the ppp device
  6. adding  a route to the ppp device.
There are many options to pppd, which are described in 'man pppd', but the examples below cover the normal cases.

You can run ppp over an RS232 link directly connecting two PCs, like this: (in one long line)
/usr/sbin/pppd ttyS0 57600 crtscts local passive persist
[your IP address]:[remote IP address]  netmask 255.255.255.252

You can run kppp that is possible to configure and use from X-Windows environment. The interface is very similar with Dial-up Networking of Microsoft Windows 95/98.

Configure and Test your Modem

The most common method of configuring modems is using the Hayes AT commands. For this, you need a program that lets you talk to the modem over the serial port. On Unix machines, this is the cu command:

cu -l /dev/ttyS0 -s 57600 (if you get permission denied, do: chown uucp /dev/ttyS0)
opens a connection to /dev/ttyS0 at 57600 bps, and sends everything you type to the modem, until terminated by a <return>~. sequence. So you can type the following sequence to manually dial and login to a remote machine. The basic setup for dialout is: AT &F1 &W - this reloads the factory defaults and saves them to non-volatile RAM on your modem. (Responses that you receive are shown in bold).
  1. AT
  2. OK
  3. AT &F1 &W
  4. OK
  5. at&f1
  6. OK
  7. ati4 [displays the current settings for a USRobotics Courier V.]

  8.    B0  C1  E1  F1  M1  Q0  V1  X7
       BAUD=57600  PARITY=N  WORDLEN=8
       DIAL=PULSE  ON HOOK   TIMER

       &A3  &B1  &C1  &D2  &G0  &H1  &I0  &K1  &L0  &M4  &N0
       &P0  &R2  &S0  &T5  &X0  &Y1  %N6

       S00=000  S01=000  S02=043  S03=013  S04=010  S05=008  S06=002 S07=060
       S08=002  S09=006  S10=007  S11=070  S12=050  S13=000  S14=001 S15=000
       S16=000  S17=000  S18=000  S19=000  S20=000  S21=010  S22=017 S23=019
       S24=150  S25=005  S26=001  S27=000  S28=008  S29=020  S30=000 S31=000
       S32=009  S33=000  S34=000  S35=000  S36=000  S37=000  S38=000 S39=000
       S40=000  S41=000  S42=126  S43=200  S44=015  S45=000  S46=000 S47=000
       S48=000  S49=000  S50=000  S51=000  S52=000  S53=000  S54=064 S55=000
       S56=000  S57=000

       LAST DIALED #: T2020

    OK

On the USR Courier, ATI4 shows the current settings in the modem (Most other modems use AT&V for this).

Setup dialout PPP

    Objective: To configure your computer for dialout PPP.
    1. Bring down the default route through the ethernet interface

    2. route del default
    3. Add debugging output to syslogd - edit /etc/syslog.conf and add:

    4. *.=debug /var/log/debug and then restart syslogd - "killall -1 syslogd", syslogd
       
    5. Configure your modem for dialout
    6. Dial out using cu and ATDTphone and manually login using the account ppp and password ppp. Note the prompts that you get, since you will use them to construct your chat script. Each of you uses the phone number based on the diagram.
    7. Dial out using pppd

    8. pppd /dev/ttyS0 57600 \
      connect 'chat -v "" AT OK ATDTPHONE ogin: ppp-user word: \\qpasswd' \
      modem crtscts debug defaultroute
      The \\q ensures that your password is not echoed in the /var/log/messages.
      Check that ppp is running. You can use tail -f /var/log/messages to view what is happening.
    Authentication:

    PAP authentication is done through the /etc/ppp/chap-secrets file
    the format is:

    login domain password
    normally 'domain' is not used unless required by the server, so a typical example is:

    js * alePest

    Note passwords are not encrypted. The file is the same on the server side, but it is also it is possible to tell pppd to use the /etc/passwd file


    How to set up your machine as a dialin PPP server

    1. Setup your computer to answer incoming calls
    2. Create a user for ppp
    3. Setup ppp to accept incoming calls
    4. Wait for a call
    5. Check /var/log/messages and ifconfig to see what happens when you receive a call.
    6. We have setup routing for the network that you are willing to serve, so that all traffic for your client is routed via you. Once the connection is established, ask your neighbour to try pinging you and using traceroute to an outside machine to check if this works.

    Additional Notes:
     

     
    You should create or edit /etc/minirc.dfl (Red Hat) or /var/lib/minicom/minirc.dfl (Slackware) so it looks like this:
    pr port             /dev/ttyS0
    pu baudrate         38400
    pu bits             8
    pu parity           N
    Note that you should never use /dev/modem to refer to your modem - it creates problems with lock files as one program might refer to the device as "/dev/modem" while another refers to it as "/dev/ttyS0", for example.

    To get minicom to give a nice colour display, add '-c on' to the command line, or put the following line in /etc/profile:
    export MINICOM='-c on'
     

    There is another way of configuring a dialin ppp link - to use an intelligent getty program that auto-senses PPP. (see below)

    Regardless of the way the link is initiated, the options are usually located in the ppp options file. The important things for a PPP server to do are to allocate an IP address for the remote end of the link (if it uses dynamic addresses, which is common for dialup PPP) and to handle routing for the link when it comes up. Routing can be handled by adding the proxyarp option to pppd, where the server responds to ARP queries on the local LAN for the remote machine, and then routes packets down the serial link. More common these days however, is to use a small network for this link and route this network to the ppp link. The pppd program automatically adds a host route for the machine at the other end of the PPP link when the link comes up and deletes it when the link goes down.

    For a dialout link, pppd needs to know the name of a connection program (like chat), and (usually) a phone number, username and password that the server recognises it by. These are usually part of the chat script. Also needed are the serial port and speed to be used for the modem connection.

    The PPP HOWTO available with all Linux distributions covers PPP setup, both as client and server, in detail.

    mgetty and auto-sensing ppp:
    For a Unix machine to accept logins on a serial port (either a directly connected terminal or a modem) there is a program called getty that runs on each line and waits for some action (either a telephone ringing, or a user pressing enter on a directly connected terminal). mgetty is a "smart" version of getty that can do a few more things than just detect a phone ring and start the login program. mgetty is started by init (from inittab) and waits for the phone to ring. It can then detect whether this is a data or fax call, and answer appropriately. All this is controlled by a config file (mgetty.config).


    When PPP clients use the PAP (or CHAP) protocol for user authentication and so do not need a separate login/password authentication at startup then mgetty has a feature whereby it can sense the PPP start-up packets and automatically start pppd (at the server end). The client end maintains the username and password in the pap-secrets file (under unix pppd) and authentication happens during the initial ppp chat. This simplifies the chat script since you no longer need to worry about what exactly the login prompt will look like.

    By default mgetty disables this feature -- to enable it, you have to recompile mgetty with -DAUTO_PPP (as documented) and uncomment the line for AutoPPP in the login.config file. On the server side, pppd can either use a pap-secrets file to authenticate the client, or, if given the "login" option, uses the regular login (/etc/password) database.

    Other programmes:
     

    uugetty
    An option to mgetty is uugetty, which can do many of the same things (allow use of a modem on a serial port for both dial in and out). uugetty requires a config file for each port that it answers on, usually
    dip
    dip is another program that handles dialup IP connections. It can do both slip and ppp (but actually just calls pppd with the appropriate arguments if you want ppp).
    diald -- dial on demand
    Another very useful feature is the ability to dial out automatically when required and hang up the line when not in use. The diald program provides this facility.
    Link Quality Monitoring (LQM)
    To ensure that the link can successfully transfer data, PPP monitors its quality LQM quality report (LQR) packets. For link quality monitoring to be operational, it only has to be enabled on one side of the link. If the two machines are configured for different link quality reporting periods, they negotiate to the lower value, so that the LQR period will be the same on both sides of the link.

    LQR packets contain counters of incoming and outgoing data packets for the routers on each side of the link. Each time an LQR packet is received, PPP uses that packet to calculate the outbound link quality (the percentage of packets the router transmitted that its peer successfully receives) and the inbound link quality (the percentage of packets that the peer transmitted that this router successfully receives).

    After five LQR reporting periods, PPP averages the inbound and outbound link quality and compares these values against a user-specified threshold. This is a rolling average. After the first five LQR reporting periods, PPP acquires the data from the next period and drops the oldest data. Then it computes the link quality average for that set of five LQR periods, and so on.

    If either the inbound or outbound link quality average drops below the threshold, PPP brings down the link. The driver software automatically brings the link back up and renegotiates the connection. PPP monitors the link control packets flowing over the connection and resumes network control protocol packet traffic when the link quality improves.

In addition to LQR packets, PPP periodically transmits echo-request packets (when echo-request is enabled). If the peer transmits a user-specified
number of echo requests before receiving an echo reply from its peer router, the router disables the link and restarts.