OPNsense Forum

International Forums => German - Deutsch => Topic started by: bobbis on October 01, 2017, 04:09:04 pm

Title: [Gelöst] WLAN Plug & Play, reinstecken ..los gehts
Post by: bobbis on October 01, 2017, 04:09:04 pm
Hallo,

ist es möglich ein vor konfiguriertes (also einmal grund konfiguartion in der sense vornhmen) USB-Wlan Gerät in OPNsense zu benutzen, also ich meine wenn ich den das USB-Wlan Gerät vom USB Anschluss abziehe, dass ich dann kein WLAN habe, wenn ich das USB-Wlan Gerät aber wieder in einem USB Anschluss reinstecke, dass ich dann wieder WLAN habe ohne Hand an der Sense anzulegen, ist das möglich ?

Danke
Title: Re: WLAN Plug & Play, reinstecken ..los gehts
Post by: Micky on October 01, 2017, 08:42:07 pm
Mhmm, kann dir nur von meiner apu2c4 berichten. Habe hier das interne WLAN installiert und als GästeWLAN konfiguriert. Das WLAN Interface kann problemlos deaktiviert und dann wieder aktiviert werden ohne dass die Konfig verloren geht. Vermute daher, dass es mit dem USB Stick ebenfalls klappt, im Zweifelsfall einfach mal testen
Title: Re: WLAN Plug & Play, reinstecken ..los gehts
Post by: bobbis on October 01, 2017, 09:19:00 pm
also momentan sieht es so aus, dass wenn, alles fertig konfiguriert wurde, WLAN funktioniert, entferne ich das USB-Wlan Gerät, und stecke dieses wieder in den USB Port, passiert danach nichts mehr, also auf den client erscheint der access point dann nicht mehr. sieht so aus als ob da eine art re-configuration/reload fehlt die das WLAN wieder aktiviert, bzw restartet.
Title: Re: WLAN Plug & Play, reinstecken ..los gehts
Post by: bobbis on October 07, 2017, 01:02:19 am
hier meine kleine Lösung:

Code: [Select]
#!/bin/sh
#
# PROVIDE: mywlanpnp
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Bobbis@forum.opnsense.org 07.10.2017 Version 0.001
#
# mywlanpnp enables you to use an USB-Wireless Device as pnp like.
# Make sure that you have allready the USB-Wireless Device configured before using this script.
# This script is just tested with only one USB-Wireless Device, in my case an "run0" Device.
# Modify the code to your own suit.
#
# HINT: Wait 10Seconds before disconnect or reconnect the USB-Wireless Device for better compatibility.
#
# Place this Script under /usr/local/etc/rc.d/mywlanpnp and set chmod execute flags.
# Note:
# Set "mywlanpnp_enable=YES" in /etc/rc.conf.d/mywlanpnp to run this script at boot.
#

. /etc/rc.subr

name="mywlanpnp"
rcvar=${name}_enable
mywlanpnp_enable=${mywlanpnp_enable-"NO"}

start_cmd="${name}_start"
stop_cmd="${name}_stop"

load_rc_config $name

file=/var/log/system.log

usb_disconnected_string="run[0-9]: at uhub[0-9], port [0-9], addr [0-9] (disconnected)" #run0: at uhub5, port 5, addr 2 (disconnected)
usb_connected_string="run[0-9]: <[0-9].[0-9]> on usbus[0-9]"                              #run0: <1.0> on usbus5


mywlanpnp_start() {
        if [ ! -f /var/run/mywlanpnp.pid ]
        then
            echo -n "Starting services: mywlanpnp"
            /usr/local/sbin/clog -f $file | while IFS='' read -r line; do
                case "$line" in
                    *${usb_connected_string}*)
                    #/usr/bin/head -1 | echo "connected"
                    sleep 1
                    #/sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/etc/rc.interfaces_wan_configure opt1
                    /sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/etc/rc.reload_interfaces
                    /usr/local/bin/beep
                    ;;
            *${usb_disconnected_string}*)
                    #/usr/bin/head -1 | echo "disconnected"
                    sleep 1
                    /bin/pgrep hostapd > /dev/null && sleep 1 && /bin/pgrep hostapd | /usr/bin/xargs kill && /usr/local/etc/rc.reload_interfaces
                    /usr/local/bin/beep
                    ;;
        esac
        done &
            echo $! > /var/run/mywlanpnp.pid
            echo "."
        else
            echo "It appears mywlanpnp is already running. NOT starting!"
        fi
}

mywlanpnp_stop() {
        if [ ! -f /var/run/mywlanpnp.pid ]
        then
            echo "It appears mywlanpnp is not running."
        else
            echo -n "Stopping services: mywlanpnp"
            kill `cat /var/run/mywlanpnp.pid`
            rm /var/run/mywlanpnp.pid
            echo "."
        fi
}

run_rc_command "$1"



bobbis
Title: Re: [Gelöst] WLAN Plug & Play, reinstecken ..los gehts
Post by: bobbis on October 13, 2017, 03:10:55 am
Da die erste Lösung nicht so wollte wie sie sollte ^^ hier eine andere Lösung:

cat /usr/local/etc/devd/wl0049a.conf
Code: [Select]
# Ralink Wireless USB
# RT3070
notify 100 {
match "system" "USB";
match "subsystem" "DEVICE";
match "type" "ATTACH";
match "vendor" "0x148f";
match "product" "(0x3070)";
        action "/bin/sh /conf/wl0049a.sh start";
};
notify 100 {
match "system" "USB";
match "subsystem" "DEVICE";
match "type" "DETACH";
match "vendor" "0x148f";
match "product" "(0x3070)";
        action "/bin/sh /conf/wl0049a.sh stop";
};

cat /config/wl0049a.sh
Code: [Select]
#!/bin/sh

option="${1}"

case ${option} in
    start) START="${2}"
        sleep 1
        /sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/bin/php /usr/local/etc/rc.reload_interfaces
        /usr/local/bin/beep
        ;;
    stop) STOP="${2}"
        sleep 1
        /bin/pgrep hostapd | /usr/bin/xargs kill && /usr/local/bin/php /usr/local/etc/rc.reload_interfaces
        /usr/local/bin/beep
        ;;
   *) 
      exit 0
      ;;
esac

*wl0049a steht auf meinem USB-Wlan-Stick, also Dateinamen kann auch selbsst gewählt werden.
*VENDOR und PRODUCT-ID muss unter /usr/local/etc/dev/wl0049a entsprechend angepasst werden!

Bei mir dauert es circa 20Sekunden bis ein BEEP zu hören ist, dann ist das Script fertig, wie im Code zu sehen, also immer warten bis der BEEP erfolgte und dann entweder Stick wieder rein oder raus.