znailnetem / znail

Network emulator intended to run on a Raspberry Pi.
Apache License 2.0
16 stars 3 forks source link

nanopi-r2s: add support for disconnecting LAN port #7

Closed Risca closed 3 years ago

Risca commented 3 years ago

This implements the suggested approach for disconnecting the LAN port of the NanoPi R2S.

Basically, the LAN port of the NanoPi R2S is a USB device and there's a GPIO pin that controls the 5V power supply to that device. This gpio pin is by default claimed by the vcc_rtl8153 regulator, so no luck controlling the pin directly from userspace. When a regulator has no consumers (nobody which uses it), it will automatically turn off. That is, unless the always-on property is set, which is true for the NanoPi R2S.

The trick is to remove the always-on property from the device tree and use a reg-userspace-consumer device to control whether this regulator should be switched on or not.

This requires changes to the NanoPi R2S device tree, a custom kernel config, and a small wrapper script to mimic the hub-ctrl tool used by Znail.