5 IP Packets over Serial Interface
Now you are ready to write your first Linux network driver that
allows us to send raw IP packets over a serial line.
5.1 Frame
We will use character count framing with our driver , since character count framing is the simplest framing in data networking. The character count framing method uses a field in the header to specify the number of characters in the frame. When the driver at the destination sees the character count, it know how many characters follow, and hence where the end of the frane is. This technique is shown in the figure below for three frames of sizes 5,5,8 respectively.
The short-coming with this method is that the count can be corrupted by a transmission error. For example, if the character count of 5 in the first frame of the above figure become a 7, the receiver will get out of synchronization and will be unable to locate the start of the next frame. There are other framing methods to get around the resynchronization after an error. However, we will stick with the character count method, since it is the simplest method and the main purpose of this tutorial is to learn device driver programming.
5.2 Install the Sealevel card
When you buy the serial card from Sealevel, it comes
with a User Manual that shows you how to install the hardware. I
will not cover this in this tutorial. You must remember that this
Sealevel card uses ISA bus. ISA bus requires fixed resources such as interrupt
and I/O base address. You need to know how to set the jumpers to
configure the board properly.
5.3 Basic Configuration
Now you will need to configure your two
Linux systems. Note that we need to have root
access to configure the driver our computers. The network's
structure is shown in the figure below:
You need to edit the files /etc/hosts and /etc/networks
on each system . The /etc/hosts is a text file that associates IP
addresses with host names. The /etc/hosts file should contain
the following entries:
192.168.2.1 Peanut.mycompany.com
192.168.2.2 Walnut.mycompany.com
The /etc/networks is a text file that associates each network name
with an assigned network number. Add the following in the /etc/networks
file:
mycompany.com 192.168.2.0
The next step is to to select the base address and the interrupt number. Note we need to go through this step because the Sealevel card uses ISA bus. These days most peripheral cards use PCI bus. PCI is much better because the BIOS initializes the base address and interrupt for you. At boot time (this is when you turn ON your computer) , The BIOS assigns a PCI configuration space to each PCI device on the system.Later when the operating system is loaded into RAM, the device driver of the PCI device must access to the configuration space to complete the initialization.
Under a x86 machine, the I/O ports range is between 0x0000 and 0xFFFF. Under my PC, the /proc/ioports looks like this :
0000-001f : dma1
0020-003f : pic1
0040-005f : timer
0060-006f : keyboard
02f8-02ff : serial(set)
0376-0376 : ide1
03c0-03df : vga+
d000-d0fe : aic7xxx
d800-d807 : ide0
d808-d80f : ide1
You must choose a base address that is unused. In my
case I use 0x300. The /proc/interrupts shows the number of
interrupts by each IRQ on the system:
CPU0
0: 342490372
IO-APIC-edge timer
1: 0
IO-APIC-edge
keyboard
2: 0
XT-PIC cascade
9: 421711
IO-APIC-level aic7xxx
11: 377750407
IO-APIC-level eth0
13: 13
XT-PIC fpu
14: 10892247
IO-APIC-edge ide0
15: 524888
IO-APIC-edge ide1
Under a x86 machine, the IRQ is between 0 and 15. The IRQ 10 has not been used, so I use 10 as IRQ for the driver. In summary, I use 0x300 for my base address and 10 for my IRQ. You may used different values with your systems.