NEXT UP previous
Next: Mice

Modems

Adding a modem to your system can be quite a tricky operation. In general, a modem is a device which connects your computer to your phone line, so that you can dial the phone number of another computer/modem combination and get your computer to communicate with the remote machine.

When you buy a modem for a PC the first choice is whether it should be internal or external. This is purely a personal choice as there is no operational difference between them. My own preference, for what it is worth, is for internal modems, if only because its one less box collecting dust by the PC.

A modem is a serial device, which means that it requires a serial port (COMi, COM2, etc.) to operate. If you get an internal modem then it will have a serial port built into it which will just need to be configured as detailed in the modem manual. For an external modem, connection is also not a problem as most I/O cards come with two serial ports, one of which most people will use for a mouse, which leaves the other free for your modem. The only extra consideration for an external modem is that if it is a high speed modem (19200 bits per second or higher) then you need an I/O card with buffered UARTs in the serial ports.

The UART is the name of the integrated circuit which performs the serial port functions. In the standard PC design a type of UART is fitted which places a heavy load on the CPU by generating a lot of interrupts (one for each character). At high modem speeds it is possible that the CPU may not be able to keep up with the data and some data may be lost. To overcome this problem I/O cards are available which have UARTs that contain a 16-character buffer. These UARTs only need to interrupt the processor when the buffer is filling up, and during the interrupt the CPU can take all the data in the buffer at the same time. This means many fewer interrupts, so that much higher data transfer rates are possible.

The buffered UARTs (sometimes referred to as FIFO UARTs) have a chip number of 16550A and you need to get a serial card which states that it has these UARTs fitted, if you want to do high speed serial work. In the UK, a multi-function I/O card with primary and secondary EIDE controllers, a floppy disk controller, two 16550A serial ports, one parallel port and one game port can be purchased for around £15 (ummm, that's about $22 US).

The device special files to use for the four serial ports, COM1 to COM4, are given in the following table:

Outgoing device nameIncomming device nameDOS
/dev/cua0/dev/ttyS0COM1
/devcua1/dev/ttyS1COM2
/dev/cua2/dev/ttyS2COM3
/dev/cua3/dev/ttyS3COM4

One reasonable idea that will save you remembering which device your modem is connected to, is to set up a symbolic link to the modem from a device called /dev/modem using a command like:

	# ln -s /dev/cua0 /dev/modem

The next consideration when buying a modem is its speed. The bottom line here is to get the fastest modem you can afford, and in any case at least 14400 bits per second. Most modern modems will talk to your computer at a fixed high speed and then negotiate an operating speed with the remote modem on connection. The modem itself will translate between the two speeds. This makes the setup on your computer rather easyier. Many modern modems will also perform data compression where possible, which can increase the effective transmission speed to well beyond the actual speed at which the two modems are talking. For this reason it is a good idea to set the speed at which your computer talks to your modem to the maximum speed the modem can use.

This causes a small problem because the highest standard serial speeds available under Linux, in bits per second are:

	300 600 1200 1800 2400 4800 9600 19200 and 38400

whereas the highest modem speeds are:

	57600 and 115200

In order to solve this problem there is a program available which allows all sorts of low level manipulations on serial ports, called setserial. The particular manipulation we are interested in here makes it possible to set up the serial ports so they can reach these higher speeds. This is done with one of the following commands:

	# setserial /dev/cua0 spd_hi
	# setserial /dev/cua0 spd_vhi

Using the parameter spd_hi sets the maximum speed on /dev/cua0 (COM1) to 57600 bits per second, while the parameter spd_vhi sets it to 115200 bits per second. What these commands do is to swap the 38400 standard speed for the new speed you specify, so that when you set the serial port speed to 38400 you actually get the higher speed instead. In all the programs that allow you to change serial port speeds you still have to use the name 38400 as the highest speed but in fact 57600 or 115200 will be used instead.

It is normal to set serial ports up at system boot time, and this is usually done from a startup file called:

	rc.serial

which, in the Slackware distribution, is run by a command at the end of the rc.S file (or it is when you uncomment the line).

You will find that the setserial program can also handle the setup of serial port addresses and interrupt (IRQ) assignments. Full details of these and other setserial functions are in the manual page.

What you have seen so far is all the setup that is required to use your modem for outgoing calls. All you do is to run your favorite terminal emulator program, tell it which device your modem is connected to and the speed to use (38400 don't forget) and then you are ready to dial out and connect to the world.

To use your modem for incoming calls the situation is a little more involved. First you have to set up a program to run on the serial line and give a login: prompt to anyone who calls and, second, you need to set up the modem itself to answer an incoming ring and connect the remote caller to your machine.

The first of these is easy, the program you run to give a login: prompt is called getty. There are two common versions of this program available to run under Linux, called agetty and getty_ps. Both perform similar functions in that they set up the serial line characteristics and then give a login: prompt. The getty program is run by the init process as specified in its configuration file:

	/etc/inittab

Typically, using agetty, the line in this file needed to set up /dev/ttys0 (COMi) to receive incoming login requests at maximum speed would be:

	dl:45:respawn:/sbin/agetty -t60 38400 ttyS0

The configuration lines in inittab each contain four colon-separated fields. The fields are:

  1. A unique two character identifier (dl = dialup line 1).

  2. A list of the run levels to which this line applies. Here, run levels 4 and 5 are specified which are used when the system is in multi-user mode.

  3. This is the action that init should take on behalf of this line. The keyword respawn indicates that init should rerun the command on this line whenever its process terminates.

  4. This is the command line for init to run. Here, it runs the agetty command with speed 38400 on serial line /dev/ttyS0 and with a 60-second timeout for the user to respond to the login: prompt.

For the getty_ps program the equivalent inittab line would be:

	dl:45:respawn:/sbin/getty -t60 ttyS0 F38400

where F38400 is not directly used as the line speed but is a label on a line in the configuration file:

	/etc/gettydefs

which is used to set up the serial line characteristics.

Having got a login: prompt on the line, all that remains now is to set up the modem to monitor the phone line and answer when it rings. The procedure here depends very much on your modem type, though many modems are Hayes compatible in that they accept the Hayes modem command set for their operation.

If your modem is Hayes compatible, then a minimal set of commands to configure it should include:

	ATS0=1
	ATE0
	ATE1

All the Hayes commands start with AT (a few modems are case sensitive) to grab the modem's attention. This is followed directly by the command you want to execute. The three commands given here operate as follows:

  1. Hayes-compatible modems contain a set of internal registers whose values control various aspects of the modem's operation. These registers have the names S0, S1, S2 etc. Register S0 specifies how many bursts of incoming ringing the modem will count before it trips the ring and answers the call. This command sets the count in S0 to 1 so the modem will trip the ring straight away. Setting this register to 0 will disable the modem's auto answer facility.

  2. Normally, when you send a command to a Hayes-compatible modem it will echo your command back to you so you can see that you typed it correctly, and so on. However, with a getty running on the line waiting for a user to login, any characters echoed by the modem will by treated as the user's login name or password. To prevent this, the echo facility needs to be suppressed. This is done with the command E0. The command El turns the echo back on again.

  3. Along similar lines to the previous command, your modem will by default send status information and result codes for many of the actions you ask it to perform. And, once again, any of these messages could be mistaken for a login name or password by the getty program. The qi command sets the modem into quiet mode which suppresses all of these messages. The command Q0 restores normal operation.

Once you have set your modem up you should save the modem settings (if your modem supports this feature - refer to its manual) so that you do not need to set it up again every time you switch the machine and modem on.


NEXT UP previous
Next: Mice