bozon.net > Projects > ncfes   

  Network Connectivity for Embedded Systems

This project was completed in May 2003 and submitted as my final year project on a BSc Computer and Network Technology course at Northumbria University - it won best final year project for my course with a final mark of 89%.

I began research for the project around June of 2002, following the initial brief to "implement an IP stack on a PIC". At that point I had no idea what a PIC was and had never done any embedded programming before, but with a good knowledge of network protocols and an appetite for a challenge I thought I'd give it a go.

Implementation

After a good bit of reading around I decided to use the PIC18F452 because it was one of the highest specification chips within a small enough DIP footprint - making it a very popular choice and widely supported.

The PIC requires only a few external components to operate as required so the final circuit can be small. A larger board was used during development, allowing for the use of and In-Circuit Debugger (image) to monitor code running on the PIC in realtime.

The device was connected to a PC running FreeBSD (my personal choice of UNIX variant) via the COMM port. With the most basic physical media (a serial cable and a couple of DB9 connectors), the first step up the software protocol ladder must be the link layer. As I intended to concentrate efforts on the network and transport layers, a very simple link layer protocol was required - so I decided to go for SLIP, they don't come much more basic than that. FreeBSD provides an easy inteface to a SLIP connection via the slattach command, as well as a number of excellent tools for monitoring and debugging network connections. The slattach configuration is as below

root@kush ~# slattach -l -f -s 57600 /dev/cuaa0
root@kush ~# ifconfig sl0 192.168.1.1 192.168.1.2
root@kush ~# route add 192.168.1.2 -interface 192.168.1.1
root@kush ~# route -n show
root@kush ~# ifconfig sl0 mtu 1006

Where 192.168.1.1 is the local address (of the sl0 interface in my case) and 192.168.1.2 is the address of the device. Note that the MTU of the interface must be set manually as it defaults to a lower value, 1006 is the maximum suggested by the SLIP RFC.

The device doesn't do any modem emulation, so does not work well with Windows. I wanted to concentrate most of my efforts on the link (IP) and transport (TCP and UDP) layers so made an early decision to support only Unix/Linux gateway machines.

DEVICE STATUS: Offline.

For the past few months a working demo' of the device running my TCP/IP stack has been intermittently connected to the Internet via my cable modem (dependant mostly on the battery and my ISP). Connections on two specific ports are currently forwarded from an OpenBSD firewall to the FreeBSD gateway then on to the device itself, it is not possible to ping the device directly from the Internet.

The web server can be accessed with any web browser, it's currently setup to display dynamic packet statistics (screenshot) that can be reset from the browser.

The TFTP server can be accessed with the command line TFTP client that comes with most operating systems. Connecting to the device and retrieving a file with a common Unix client would look something like this:

stu@kush ~> tftp home.bozon.net
tftp> get stats
Received 64 bytes in 0.2 seconds

Have a look at what nmap thinks about the device.

Tools

Trying to complete such a project in a limited timescale makes it really important to find the right tool for the job, then learn how to use it well. I spent more time debugging code than writing it, tcpdump turned out to be the perfect tool for analysing packet contents as they were sent from and received at the FreeBSD host.

Downloads

CODE

The individual source files are listed below - or the full project directory (ncfes.zip) is available, containing all required WIZ-C project files as well as the compiled .ASM files and the resultant .HEX

Source Syntax highlighted
main.c main.c.html
common.h common.h.html
slip.c (.h) slip.c.html (.h)
ip.c (.h) ip.c.html (.h)
icmp.c (.h) icmp.c.html (.h)
udp.c (.h) udp.c.html (.h)
tcp.c (.h) tcp.c.html (.h)

Although it's worth noting that some of the code is written specifically for the WIZ-C compiler and may need considerable reworking for other platforms.

REPORT

You can download the report as a PDF (1.18mb). Unfortunately some of the diagrams didn't convert too well to PDF, but they're still legible.

Abstract

Few people could have failed to notice two important trends over recent years; the miniaturisation of electronic devices and the continued proliferation of the Internet. It is a natural step to integrate the two, fuelling the development of small, Internet enabled devices. Whilst the oft-cited idea of an Internet Toaster may be somewhat whimsical, Internet connectivity for home appliances is rapidly becoming a reality.

This report details the techniques involved in reducing the resource requirements of a network stack implementation, thus allowing it to be embedded within a small device. In order to provide an understanding of the network requirements, relevant protocols are presented and explained. Parts of an Internet Protocol stack have been developed, and a working device produced.

TOOLS

WIZ-C - visual C development environment for the PICmicro MCU. Although it has a few quirks, this is an excellent tool.

Related links

Some pertinent RFCs