Added new package: open-vm-tools.
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / hostapd
1 #!/bin/sh
2 . /etc/sysconfig/rc
3 . ${rc_functions}
4
5 CHANNEL="05"
6 TXPOWER="auto"
7 INTERFACE="blue0"
8 MACMODE="0"
9
10 eval $(/usr/local/bin/readhash /var/ipfire/wlanap/settings)
11
12 case "${1}" in
13 start)
14 mkdir -p /var/run/hostapd
15
16 boot_mesg "Starting hostapd... "
17
18 # Check Interface configuration
19 if ! ip link show $INTERFACE > /dev/null 2>&1; then
20 boot_mesg "Interface $INTERFACE does'nt exist." ${FAILURE}
21 echo_failure
22 exit 0
23 fi
24 if [ "$(ip link show $INTERFACE | /bin/grep "ether")" == "" ]; then
25 boot_mesg "Interface $INTERFACE is assigned to wlan master device." ${FAILURE}
26 boot_mesg "Please reboot to fix this." ${FAILURE}
27 echo_failure
28 exit 0
29 fi
30 if [ "$(iwconfig $INTERFACE | /bin/grep "IEEE")" == "" ]; then
31 boot_mesg "Interface $INTERFACE is no wireless device." ${FAILURE}
32 echo_failure
33 exit 0
34 fi
35
36 # Detect driver
37 if [ -e "/sys/class/net/$INTERFACE/phy80211" ]; then
38 DRIVER="NL80211"
39 driver="nl80211"
40 elif [ -e "/sys/class/net/$INTERFACE/madwifi_name_type" ]; then
41 DRIVER="MADWIFI"
42 driver="madwifi"
43 else
44 boot_mesg "Interface $INTERFACE is a not supported wireless device." ${FAILURE}
45 echo_failure
46 exit 0
47 fi
48
49 echo driver=$driver > /etc/hostapd.conf.tmp
50 grep -v "^driver=" /etc/hostapd.conf >> /etc/hostapd.conf.tmp
51 mv /etc/hostapd.conf.tmp /etc/hostapd.conf
52
53 echo DRIVER=$DRIVER > /var/ipfire/wlanap/settings.tmp
54 grep -v "^DRIVER=" /var/ipfire/wlanap/settings >> /var/ipfire/wlanap/settings.tmp
55 chown nobody:nobody /var/ipfire/wlanap/settings.tmp
56 chmod 644 /var/ipfire/wlanap/settings.tmp
57 mv /var/ipfire/wlanap/settings.tmp /var/ipfire/wlanap/settings
58
59 if [ "$DRIVER" == "MADWIFI" ]; then
60 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
61 boot_mesg "Setting MADWIFI wlan $INTERFACE to Master mode... "
62 # Set Atheros Cards to master mode
63 /usr/bin/wlanconfig $INTERFACE destroy > /dev/null
64 /usr/bin/wlanconfig $INTERFACE create wlandev wifi0 wlanmode ap > /dev/null
65 fi
66 fi
67
68 /usr/sbin/iwconfig $INTERFACE channel $CHANNEL
69 /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER
70
71 /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 &
72
73 sleep 1
74
75 if [ $DRIVER == "MADWIFI" ]; then
76 iwpriv $INTERFACE maccmd 3
77 if [ $MACMODE != 0 ]; then
78 FILE="/var/ipfire/wlanap/macfile"
79 exec < $FILE
80 while read LINE
81 do
82 iwpriv $INTERFACE addmac $LINE
83 done
84
85 iwpriv $INTERFACE maccmd $MACMODE
86 fi
87 fi
88
89 sleep 1
90
91 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
92 boot_mesg "Error! Can't set wlan master mode"
93 echo_failure;
94 exit 0;
95 else
96 # enable wlan module of collectd
97 sed -i -e "s|#LoadPlugin wireless|LoadPlugin wireless|g" /etc/collectd.conf
98 echo_ok
99 fi
100 ;;
101
102 stop)
103 boot_mesg "Stopping hostapd..."
104
105 killproc /usr/bin/hostapd
106 evaluate_retval
107 ;;
108
109 restart)
110 ${0} stop
111 sleep 1
112 ${0} start
113 ;;
114
115 status)
116 statusproc /usr/bin/hostapd
117 ;;
118
119 *)
120 echo "Usage: ${0} {start|stop|restart|status}"
121 exit 1
122 ;;
123 esac