Supondo que seja suficiente para o seu protocolo controlar os pinos GPIO do userspace via /sys/class/gpio/
, a maneira mais simples é escrever um driver tap
do espaço do usuário. Da documentação do kernel linux/Documentation/networking/tuntap.txt
:
TUN/TAP provides packet reception and transmission for user space programs. It can be seen as a simple Point-to-Point or Ethernet device, which, instead of receiving packets from physical media, receives them from user space program and instead of sending packets via physical media writes them to the user space program.
In order to use the driver a program has to open
/dev/net/tun
and issue a corresponding ioctl() to register a network device with the kernel. A network device will appear astunXX
ortapXX,
depending on the options chosen. When the program closes the file descriptor, the network device and all corresponding routes will disappear.Depending on the type of device chosen the userspace program has to read/write IP packets (with tun) or ethernet frames (with tap). Which one is being used depends on the flags given with the ioctl().
The package from http://vtun.sourceforge.net/tun contains two simple examples for how to use tun and tap devices. Both programs work like a bridge between two network interfaces.
br_select.c
- bridge based on select system call.br_sigio.c
- bridge based on async io and SIGIO signal.However, the best example is VTun http://vtun.sourceforge.net :))
Você também pode pesquisar no Google muitos tutoriais (embora a maioria provavelmente seja sobre uma interface tun
, ou seja, pacotes IP em vez de quadros Ethernet).
Mesmo que o produto final precise ser um módulo do kernel, eu ainda começaria com um driver tap
, porque eles são muito mais fáceis de depurar. Você ainda pode transformá-lo em um módulo do kernel depois que a maioria já funciona.