Question

I have some trouble in developing a Linux driver for an underwater acoustic modem. The general idea of my project is to bring IPv6 to the underwater network. The expected result is that the underwater sensor network will have access from any typical internet devices. To achieve and implement my target, I have to provide the modem a driver so that I can use the routing protocols provided by the Linux kernel. However, due to the differences of underwater communication and typical RF communication, I have to do some processes on the packets, including fragmenting, header compressing and mesh routing. But all these process should be transparent, and the modem should be used as any other network interfaces.

The modem can communicate with computer with serial port. But I have to use the pl2303 USB to serial converter to connect it. Also the device which drives the modem is not only computer, but also an embedded Linux system called Gumstix. I tried several different ways to do it, but I cannot achieve my final goal.

The first solution is to make a pure user mode driver. It can be easy to handle but I cannot create an interface like eth0, and I cannot ping through it. What’s worse, I have to implement all the IPv6 standard by myself, which I believe is actually a waste of time.

The second solution is to make a pure kernel mode driver. The advantage is that I can exploit the existed code to deal with the IPv6 and upper level stuff, and I can have a beautiful interface. But it is not recommended to open serial port as a file in kernel mode. Although I have tried to do that, I always receives some garbage bytes.

Later I have tried a third solution. I make a daemon program that sends and receives from the serial port and use a net link socket to communication with the driver in the kernel. I wonder if any driver is doing so. But if any user wants to use my driver, they have to compile for their device and start it up by hand. Moreover, the inter-process communication is not reliable and I have no idea if the kernel has received my packet.

Was it helpful?

Solution

For your first solution, you could look into using the "tap" driver. See Documentation/networking/tuntap.txt in the kernel source for full details, but the basic idea is that you create a "tap" network interface, and any ethernet packets that the kernel stack wants to send via that interface are actually delivered to your userspace process; similarly, your userspace process can inject packets into the tap interface and the kernel will treate them as being received by the networking stack. This would solve your problem of being able to glue a userspace networking implementation into the main kernel stack.

However, implementing everything in the kernel should be doable too. This is after all essentially what the PPP or SLIP implementations do: they create a network interface that runs via a serial interface. The key concept here is "line discipline" -- rather than trying to open the serial interface in your kernel driver, you want some userspace control that does the opening and then sets the line discipline. You should be able to model this on something like PPP or IrDA in the mainline kernel (and I believe searching the web for "linux line discipline" will give some documentation on writing one).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top