diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-10-20 09:55:55 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-10-20 09:55:55 -0200 |
commit | a0a9ec26ab205bc63eac9a278d4f66de5cdfebe2 (patch) | |
tree | 9928795ff10a711f0ad147066249d05ba5742077 | |
parent | d6fa45f002bd428775f310cd10003bbd3dd87ebe (diff) | |
download | hydra-a0a9ec26ab205bc63eac9a278d4f66de5cdfebe2.tar.gz hydra-a0a9ec26ab205bc63eac9a278d4f66de5cdfebe2.tar.bz2 |
Adds USB hotplug switch from old badusb-switcher project
-rwxr-xr-x | share/hydractl/usb-disable | 43 | ||||
l--------- | share/hydractl/usb-enable | 1 | ||||
l--------- | share/hydractl/usb-status | 1 |
3 files changed, 45 insertions, 0 deletions
diff --git a/share/hydractl/usb-disable b/share/hydractl/usb-disable new file mode 100755 index 0000000..9314bf3 --- /dev/null +++ b/share/hydractl/usb-disable @@ -0,0 +1,43 @@ +#!/bin/bash +# +# USB hotplug switcher. +# See https://links.fluxo.info/tags/badusb +# https://www.kernel.org/doc/Documentation/usb/authorization.txt +# http://marc.info/?l=git-commits-head&m=131166366113680&w=2 + +# Parameters +BASENAME="`basename $0`" + +# Set hotplug state +function usb_set_state { + echo "Applying at /sys/module/usbcore/parameters/authorized_default..." + sudo su -c "echo $1 > /sys/module/usbcore/parameters/authorized_default" + + for bus in /sys/bus/usb/devices/usb*; do + echo "Applying at ${bus}/authorized_default..." + sudo su -c "echo $1 > ${bus}/authorized_default" + done +} + +# Dispatch +if [ "$BASENAME" == 'usb-enable' ]; then + usb_set_state 1 +elif [ "$BASENAME" == 'usb-disable' ]; then + usb_set_state 0 +elif [ "$BASENAME" == 'usb-status' ]; then + status="`cat /sys/module/usbcore/parameters/authorized_default`" + + # The "authorized_default" module parameter of usbcore controls the default + # for the authorized_default variable of each USB host controller. + # + # -1 is authorized for all devices except wireless (default, old behaviour) + # 0 is unauthorized for all devices + # 1 is authorized for all devices + if [ "$status" == "0" ]; then + echo "Hotplug disabled." + elif [ "$status" == "1" ]; then + echo "Hotplug enabled." + elif [ "$status" == "-1" ]; then + echo "Hotplug enabled except wireless" + fi +fi diff --git a/share/hydractl/usb-enable b/share/hydractl/usb-enable new file mode 120000 index 0000000..f54f446 --- /dev/null +++ b/share/hydractl/usb-enable @@ -0,0 +1 @@ +usb-disable
\ No newline at end of file diff --git a/share/hydractl/usb-status b/share/hydractl/usb-status new file mode 120000 index 0000000..f54f446 --- /dev/null +++ b/share/hydractl/usb-status @@ -0,0 +1 @@ +usb-disable
\ No newline at end of file |