An open API service indexing awesome lists of open source software.

https://github.com/seantywork/gpiosk

GPIO based Linux netdevice kernel module
https://github.com/seantywork/gpiosk

gpio kernel linux networking raspberry-pi

Last synced: 2 months ago
JSON representation

GPIO based Linux netdevice kernel module

Awesome Lists containing this project

README

          

# gpiosk

GPIO based Linux netdevice kernel module

![thumbnail](docs/blueprint.jpg)

- [what is this?](#what-is-this)
- [specification](#specification)
- [documentation](#documentation)
- [how to](#how-to)
- [xdp feature](#xdp-feature)

# what is this?

This kernel module is no different from a plain old Linux networking interface...\
except it uses GPIO to send and receive data

### interface info

```shell
# on rpi1
# ip a
15: geth0: mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 47:45:54:48:30:36 brd ff:ff:ff:ff:ff:ff
inet 10.10.0.1/24 scope global geth0
valid_lft forever preferred_lft forever
inet6 fe80::4545:54ff:fe48:3036/64 scope link
valid_lft forever preferred_lft forever

```

```shell

# on rpi2
# ip a

1: geth0: mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 47:45:54:48:30:33 brd ff:ff:ff:ff:ff:ff
inet 10.10.0.2/24 scope global geth0
valid_lft forever preferred_lft forever
inet6 fe80::4545:54ff:fe48:3033/64 scope link
valid_lft forever preferred_lft forever

```

### example: tcp communication using nc
```shell
# on rpi2
$ nc -l 10.10.0.2 9999
helllo
echo
bye
```

```shell
# on rpi1
$ nc 10.10.0.2 9999
helllo
echo
bye

```

# specification

So far, I only tested it on my raspberry pi 4b with spec below

```shell
# lscpu
Architecture: aarch64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Vendor ID: ARM
Model name: Cortex-A72
Model: 3
Thread(s) per core: 1
Core(s) per cluster: 4
Socket(s): -
Cluster(s): 1
Stepping: r0p3
CPU(s) scaling MHz: 33%
CPU max MHz: 1800.0000
CPU min MHz: 600.0000
BogoMIPS: 108.00
Flags: fp asimd evtstrm crc32 cpuid
```

```shell
# uname -a
Linux raspberrypi 6.12.25+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.25-1+rpt1 (2025-04-30) aarch64 GNU/Linux
```
# documentation

Refer to the following [how to](#how-to) section

~~- [version 1.0](https://medium.com/@seantywork/gpiosk-introducing-my-gpio-based-linux-socket-kernel-module-bba2d114236e)~~

# how to

1. physical wiring

- blueprint

![blueprint](docs/blueprint.jpg)

- actual

![actual](docs/actual.jpg)

2. build

```shell
make
```

3. insmod

```shell
# hwid should be an interger ranging from 1 to 9
# and should be set differently for each host
# because `gpiosk` module uses it to set hw addr
sudo insmod gpiosk.ko hwid=$HWID
```

# xdp feature

### install xdp-tools

```shell
cd xdp-prog

./install.sh

```

### build sample xdp programs

```shell
cd xdp-prog

make

```

### example: allowing tcp communication

```shell
# on rpi2
$ cd xdp-prog
$ sudo xdp-loader load -m native -s xdp_prog geth0 "xdp_pass.o"
$ nc -l 10.10.0.2 9999

# on rpi2, terminal 2
sudo dmesg -wH

```

```shell
# on rpi1
$ nc 10.10.0.1 9999

```

```shell

# on rpi2, terminal 2
[ +0.000035] entered xmit
[ +0.000004] entered hw tx
[ +0.000003] eth src: 47:45:54:48:30:33
[ +0.000005] eth dst: 47:45:54:48:30:36
[ +0.000004] src: 0a0a0002:09999
[ +0.000004] dst: 0a0a0001:37512
[ +0.048151] exiting xmit
[ +0.000006] npackets smaller than budget
[ +0.000004] napi complete
[ +0.000003] polling end
[ +0.223525] napi interrupt
[ +0.000010] napi receive
[ +0.000002] napi interrupt end
[ +0.000009] polling
[ +0.000005] geth: XDP_PASS # <------- here you can see the traffic is allowed by the sample program

```

```shell
# unload

$ sudo xdp-loader unload geth0 -a

```

### example: blocking tcp communication

```shell
# on rpi2
$ cd xdp-prog
$ sudo xdp-loader load -m native -s xdp_prog geth0 "xdp_drop.o"
$ nc -l 10.10.0.2 9999

# on rpi2, terminal 2
sudo dmesg -wH

```

```shell
# on rpi1
$ nc 10.10.0.1 9999

```

```shell

# on rpi2, terminal 2
[Sep15 01:48] napi interrupt
[ +0.000013] napi receive
[ +0.000003] napi interrupt end
[ +0.000013] polling
[ +0.000008] geth: XDP_DROP # <---------- here you can see the traffic is blocked by the sample program

```

```shell
# unload

$ sudo xdp-loader unload geth0 -a

```