#!/bin/sh set -e [ "${IFACE%%[0-9]*}" = "wlan" ] || exit 0 [ "$IF_WIRELESS_SSID" ] || exit 1 [ "$IF_WIRELESS_HWMODE" ] || IF_WIRELESS_HWMODE=g [ "$IF_WIRELESS_EXTENSION" ] || IF_WIRELESS_EXTENSION=0 [ -x /usr/sbin/rfkill ] && rfkill unblock wlan 2>/dev/null wpa=0 wpa1=0 wpa2=0 case "$IF_WIRELESS_SECURITY" in none) sec=1 ;; wep) sec=2 ;; wpa) sec=1 wpa1=1 ;; wpa2) sec=1 wpa2=1 ;; wpa+wpa2) sec=1 wpa=1 ;; *) sec=1 ;; esac case "$IF_WIRELESS_MODE" in ap) logger -t hostap "Creating hostapd configuration" cat /etc/hostapd.conf > /tmp/hostapd.conf chmod 600 /tmp/hostapd.conf echo "interface=${IFACE}" >> /tmp/hostapd.conf echo "ssid=$IF_WIRELESS_SSID" >> /tmp/hostapd.conf echo "channel=$IF_WIRELESS_CHANNEL" >> /tmp/hostapd.conf echo "hw_mode=$IF_WIRELESS_HWMODE" >> /tmp/hostapd.conf echo "auth_algs=$sec" >> /tmp/hostapd.conf [ $wpa -eq 0 ] && [ $wpa1 -eq 0 ] && [ $wpa2 -eq 0 ] && { logger -t hostap "using no security mechanism" echo "wpa=0" >> /tmp/hostapd.conf } [ $wpa1 -eq 1 ] && { logger -t hostap "using WPA for security" echo "wpa=1" >> /tmp/hostapd.conf echo "wpa_key_mgmt=WPA-PSK" >> /tmp/hostapd.conf echo "wpa_pairwise=TKIP" >> /tmp/hostapd.conf echo "wpa_passphrase=$IF_WIRELESS_PASSPHRASE" >> /tmp/hostapd.conf } [ $wpa2 -eq 1 ] && { logger -t hostap "using WPA2 for security" echo "wpa=2" >> /tmp/hostapd.conf echo "wpa_key_mgmt=WPA-PSK" >> /tmp/hostapd.conf echo "rsn_pairwise=CCMP" >> /tmp/hostapd.conf echo "wpa_passphrase=$IF_WIRELESS_PASSPHRASE" >> /tmp/hostapd.conf } [ $wpa -eq 1 ] && { logger -t hostap "using WPA and WPA2 for security" echo "wpa=3" >> /tmp/hostapd.conf echo "wpa_key_mgmt=WPA-PSK" >> /tmp/hostapd.conf echo "wpa_pairwise=TKIP" >> /tmp/hostapd.conf echo "rsn_pairwise=CCMP" >> /tmp/hostapd.conf echo "wpa_passphrase=$IF_WIRELESS_PASSPHRASE" >> /tmp/hostapd.conf } ;; sta) ip link set up dev ${IFACE} [ $IF_WIRELESS_EXTENSION -eq 1 ] && { [ -x /usr/sbin/iwconfig ] || { logger -t wireless "No wireless-tools found" exit 1 } driver=wext iwconfig ${IFACE} essid $IF_WIRELESS_SSID } || { [ -x /usr/sbin/iw ] || { logger -t wireless "No iw utility found" exit 1 } driver=nl80211 [ $sec -eq 2 ] && { iw dev ${IFACE} connect $IF_WIRELESS_SSID key d:0:$IF_WIRELESS_PASSPHRASE } || { iw dev ${IFACE} connect $IF_WIRELESS_SSID } } [ $wpa2 -eq 1 ] && { [ -x /usr/sbin/wpa_supplicant ] || { logger -t wireless "No wpa_supplicant found" exit 1 } touch /tmp/wpa_supplicant.conf chmod 600 /tmp/wpa_supplicant.conf echo "network={" > /tmp/wpa_supplicant.conf echo " ssid=\"$IF_WIRELESS_SSID\"" >> /tmp/wpa_supplicant.conf echo " psk=\"$IF_WIRELESS_PASSPHRASE\"" >> /tmp/wpa_supplicant.conf echo " priority=5" >> /tmp/wpa_supplicant.conf echo "}" >> /tmp/wpa_supplicant.conf wpa_supplicant -B -D${driver} -i${IFACE} -P/var/run/wpa_supplicant.pid -c/tmp/wpa_supplicant.conf } ;; *) echo "Unknown operation mode $IF_WIRELESS_MODE given!" exit 1 ;; esac exit 0