Hi,
I found on Writing a Network device driver - Part 1 LG #93 page very useful sample of virtual driver (not connected to real hardware).
I try to compile it with no effect.
So:
I got fresh Ubuntu 9.10 (kernel 2.6.31-14)
My source is saved in networkAdapter.c file in /usr/src/myModules directory.
I created Makefile too with: obj-m = networkAdapter.o content in /usr/src/myModules directory.
I try to compile with:
make -C /usr/src/linux-headers-2.6.31-14-generic/ M=$(pwd) modules
cc -I /usr/src/linux-headers-2.6.31-14-generic/include/ -c networkAdapter.c
being in /usr/src/myModules directory.
Make -c ... output contains 3 errors:
'struct net_device' has no member named 'open'
'struct net_device' has no member named 'stop'
'struct net_device' has no member named 'hard_start_xmit'
cc -I ... output is very long and contains lots of errors.
Yes, I have made a little research and found that net_device struct is a little bit different since 2009. I am trying to fit this code to new net_device struct that is no so easy.
Have you got any samples of network drivers basic source code?
I have no idea how to make brand new code. What is more - I haven't found any tutorials containing writing network drivers based on new net_structure. All of them are old. That is the purpose to searching on unix.com forum for help.
As suggested before, you can find better source code inside the linux kernel itself than by browsing the internet for random code to try and hope it works.
This ebook (3rd edition) is also little bit outdated if we consider net_device structure (chapter 17 - network drivers).
At this moment that structure is different since 2009. However they say:
It is only mentioned that struct differ from old one, which all examples are based on.
I have not found on the internet any examples of network drivers written with new net_structure and believe me I am searching few days. Unfortunatelly link passed by fpmurphy is also describing driver based on old net_structure.
I got only "/usr/src/linux-headers-2.6.31-14" - headers. No *.c files.
I don't think that's a generic network driver. It's for PowerPC only, it seems, and may be some kind of odd builtin.
Install some kernel source already(It's free) so you can use the files I suggested. Preferably the same version as the kernel you have, which you can get with 'cat /proc/verson'. If you can't find a way to install source in your distro you can still download tarballs from kernel.org
You seem to be having great difficulty getting going on building a simple network module. Let me try and help you. It is not difficult but can be a bit daunting the first time around.
Install the Ubuntu kernel sources for your current kernel See Kernel/Compile - Community Help Wiki and elsewhere for how to do this. Follow the instructions to the letter. Do not try and take any shortcuts.
Copy the following source file from your kernel source tree to your work area: .../drivers/net/dummy.c. Read the comments at the top of this file for an explanation of the dummy network driver. This driver is about as simple as a 2.6 kernel network driver gets.
Create the following Makefile in your work area:
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := dummy.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
Type 'make'. dummy.ko should be built.
Install the dummy network driver using "inmod ./dummy.ko"
Possible operations:
To list this driver: ifconfig -a. It will show up as dummy0
To remove the driver: rmmod dummy0
To config the driver: ifconfig dummy0 192.168.0.100 netmask 255.255.255.0
Thank you man. You made my day. I got working virtual driver at this moment. Now I add new features and work on makefile (that one you posted does not work for me: "nothing to do in 'default'").
Great job.
There is probably something wrong with your development/build environment if the Makefile did not work. It is basically the standard default build-a-module-outside-of-kernel-build-tree Makefile.