summaryrefslogtreecommitdiff
path: root/aports/wpa_passthru
diff options
context:
space:
mode:
Diffstat (limited to 'aports/wpa_passthru')
-rw-r--r--aports/wpa_passthru/APKBUILD23
-rw-r--r--aports/wpa_passthru/wpa_passthru101
-rw-r--r--aports/wpa_passthru/wpa_passthru.initd12
3 files changed, 136 insertions, 0 deletions
diff --git a/aports/wpa_passthru/APKBUILD b/aports/wpa_passthru/APKBUILD
new file mode 100644
index 0000000..5672428
--- /dev/null
+++ b/aports/wpa_passthru/APKBUILD
@@ -0,0 +1,23 @@
+# Maintainer: Gabor Pali <pali.gabor@gmail.com>
+
+pkgname=wpa_passthru
+pkgver=0.1.0
+pkgrel=0
+pkgdesc="WPA Supplicant pass-through for Wifibox"
+url="https://github.com/pgj/freebsd-wifibox-alpine"
+arch="all"
+license="BSD2"
+install=""
+subpackages=
+source="wpa_passthru.initd
+ wpa_passthru
+"
+
+package() {
+ install -D -m755 "$srcdir"/wpa_passthru.initd "$pkgdir"/etc/init.d/wpa_passthru
+ install -D -m755 "$srcdir"/wpa_passthru "$pkgdir"/sbin/wpa_passthru
+}
+sha512sums="
+ab107ef28b73517468c8e4558642b798fb3b6861e9ad92df4fd9912b5c3a56aa83822ce71ac1d4b84bf3113dc9c8c1aec6a76e3be17f0613ee722108a384e3ff wpa_passthru.initd
+46178341d5cd323bc2e7bdf1f21158e7806f6746efe480f1f0f9b57254355b78def8e90d5f5e87e10122b04f6280da711865640ee38faa7566c5da0f3d9f18c3 wpa_passthru
+"
diff --git a/aports/wpa_passthru/wpa_passthru b/aports/wpa_passthru/wpa_passthru
new file mode 100644
index 0000000..4e95d2f
--- /dev/null
+++ b/aports/wpa_passthru/wpa_passthru
@@ -0,0 +1,101 @@
+#!/bin/sh
+# shellcheck disable=SC2034,SC3043,SC3060
+
+log() {
+ local _level="$1"
+ local _message="$2"
+
+ /usr/bin/logger -p "daemon.${_level}" -t "wpa_passthru[$$]" "${_message}"
+}
+
+enabled=no
+
+# shellcheck disable=SC1091
+. /media/etc/wpa_ctrl.conf
+
+_wlan_devs=$(set | /bin/grep -F "_port=" | /bin/sed 's!_port=.*!!')
+log debug "Configuration: enabled=${enabled}, network=${network}, wlan devs=[${_wlan_devs}]"
+
+if [ "${enabled}" = "no" ]; then
+ log info "Not enabled, exiting."
+ exit 0
+fi
+
+if_lan=eth0
+wpa_conf="/media/wpa/wpa_supplicant.conf"
+
+cleanup() {
+ local _socats
+
+ _socats=$(/usr/bin/pgrep socat)
+ log info "Stopping, socat processes: [${_socats}]"
+ [ -n "${_socats}" ] \
+ && /usr/bin/kill -TERM ${_socats}
+ [ -n "${_socket_directory}" ] \
+ && /bin/rm -rf "${_socket_directory}"
+}
+
+trap cleanup EXIT TERM
+
+find_network() {
+ /sbin/ifconfig ${if_lan} \
+ | /bin/grep -F "inet addr:" \
+ | /bin/sed -E 's!.*inet addr:([0-9\.]+).*Mask:([0-9\.]+)!\1:\2!'
+}
+
+get_ctrl_interface() {
+ /bin/grep "^ctrl_interface=" "${wpa_conf}" \
+ | /bin/sed 's!^ctrl_interface=!!'
+}
+
+if [ -z "${network}" ]; then
+ if ! /sbin/ifconfig ${if_lan}; then
+ log error "Interface ${if_lan} not found, exiting."
+ exit 1
+ fi
+
+ network=$(find_network)
+fi
+
+_ip=${network%%:*}
+
+if [ -z "${_ip}" ]; then
+ log error "No IP address for ${if_lan} could found, exiting."
+ exit 1
+fi
+
+_ctrl_interface=$(get_ctrl_interface)
+
+if [ -z "${_ctrl_interface}" ]; then
+ log warn "No control interface found, exiting."
+ exit 0
+fi
+
+_socket_directory=$(/bin/mktemp -d)
+
+for _wlan_dev in ${_wlan_devs}; do
+ _wlan=${_wlan_dev//_/-}
+ _ctrl_socket="${_ctrl_interface}/${_wlan}"
+
+ if [ ! -S "${_ctrl_socket}" ]; then
+ log warn "${_ctrl_socket} is not available, skipping."
+ continue
+ fi
+
+ _socket="${_socket_directory}/${_wlan}"
+ _port=$(eval "echo \${${_wlan_dev}_port}")
+
+ if [ -z "${_port}" ]; then
+ log warn "No port defined for ${_wlan}, skipping."
+ continue
+ fi
+
+ log info "Associating ${_ip}:${_port} (${network}) with ${_ctrl_socket} (${_socket})"
+ /usr/bin/socat \
+ TCP4-LISTEN:"${_port}",reuseaddr,bind="${_ip}",range="${network}",fork \
+ UNIX-SENDTO:"${_ctrl_socket}",bind="${_socket}",unlink-early &
+done
+
+while /bin/true; do
+ /bin/sleep 60
+done
diff --git a/aports/wpa_passthru/wpa_passthru.initd b/aports/wpa_passthru/wpa_passthru.initd
new file mode 100644
index 0000000..d7c5c07
--- /dev/null
+++ b/aports/wpa_passthru/wpa_passthru.initd
@@ -0,0 +1,12 @@
+#!/sbin/openrc-run
+
+supervisor=supervise-daemon
+name="WPA Supplicant pass-through"
+description="Control socket pass-through support for WPA Supplicant"
+
+command=/sbin/wpa_passthru
+command_background=true
+
+depend() {
+ need wpa_supplicant
+}