Remove errormessage at hostapd channel set.
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / hostapd
CommitLineData
07603508
CS
1#!/bin/sh
2. /etc/sysconfig/rc
3. ${rc_functions}
4
54359730
CS
5CHANNEL="05"
6TXPOWER="auto"
7INTERFACE="blue0"
79ef49bd 8MACMODE="0"
79ef49bd 9
b9694349 10eval $(/usr/local/bin/readhash /var/ipfire/wlanap/settings)
54359730 11
54359730 12case "${1}" in
8aa49c15 13 start)
54359730 14 mkdir -p /var/run/hostapd
54359730 15
7429ec82
AF
16 boot_mesg "Starting hostapd... "
17
18 # Check Interface configuration
19 if ! ip link show $INTERFACE > /dev/null 2>&1; then
c485b902 20 boot_mesg "Interface $INTERFACE doesn't exist." ${FAILURE}
7429ec82
AF
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"
071a0314 43 elif [ "$(/bin/grep hostap /sys/class/net/$INTERFACE/uevent)" != "" ]; then
8d30f4ed
AF
44 DRIVER="HOSTAP"
45 driver="hostap"
7429ec82
AF
46 else
47 boot_mesg "Interface $INTERFACE is a not supported wireless device." ${FAILURE}
48 echo_failure
49 exit 0
50 fi
51
52 echo driver=$driver > /etc/hostapd.conf.tmp
53 grep -v "^driver=" /etc/hostapd.conf >> /etc/hostapd.conf.tmp
54 mv /etc/hostapd.conf.tmp /etc/hostapd.conf
55
56 echo DRIVER=$DRIVER > /var/ipfire/wlanap/settings.tmp
57 grep -v "^DRIVER=" /var/ipfire/wlanap/settings >> /var/ipfire/wlanap/settings.tmp
58 chown nobody:nobody /var/ipfire/wlanap/settings.tmp
59 chmod 644 /var/ipfire/wlanap/settings.tmp
60 mv /var/ipfire/wlanap/settings.tmp /var/ipfire/wlanap/settings
61
79ef49bd
AF
62 if [ "$DRIVER" == "MADWIFI" ]; then
63 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
64 boot_mesg "Setting MADWIFI wlan $INTERFACE to Master mode... "
65 # Set Atheros Cards to master mode
66 /usr/bin/wlanconfig $INTERFACE destroy > /dev/null
67 /usr/bin/wlanconfig $INTERFACE create wlandev wifi0 wlanmode ap > /dev/null
68 fi
8d30f4ed
AF
69 elif [ "$DRIVER" == "HOSTAP" ]; then
70 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
71 boot_mesg "Setting HOSTAP wlan $INTERFACE to Master mode... "
071a0314 72 # Set Prism Cards to master mode
8d30f4ed
AF
73 /usr/bin/iwconfig $INTERFACE mode master > /dev/null
74 fi
8aa49c15 75 fi
54359730 76
c1fd7bc5 77 /usr/sbin/iwconfig $INTERFACE channel $CHANNEL 2>/dev/null
79ef49bd 78 /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER
7429ec82 79
61160760 80 /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 &
79ef49bd 81
c485b902 82 sleep 2
79ef49bd 83
7429ec82 84 if [ $DRIVER == "MADWIFI" ]; then
79ef49bd
AF
85 iwpriv $INTERFACE maccmd 3
86 if [ $MACMODE != 0 ]; then
87 FILE="/var/ipfire/wlanap/macfile"
88 exec < $FILE
89 while read LINE
90 do
91 iwpriv $INTERFACE addmac $LINE
92 done
54359730 93
79ef49bd
AF
94 iwpriv $INTERFACE maccmd $MACMODE
95 fi
a494df6d 96 fi
8aa49c15 97
c485b902 98 sleep 2
7429ec82 99
54359730 100 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
8aa49c15
CS
101 boot_mesg "Error! Can't set wlan master mode"
102 echo_failure;
79ef49bd 103 exit 0;
54359730 104 else
79ef49bd 105 echo_ok
54359730 106 fi
8aa49c15 107 ;;
54359730 108
8aa49c15 109 stop)
54359730
CS
110 boot_mesg "Stopping hostapd..."
111
8aa49c15
CS
112 killproc /usr/bin/hostapd
113 evaluate_retval
114 ;;
54359730 115
8aa49c15
CS
116 restart)
117 ${0} stop
118 sleep 1
119 ${0} start
120 ;;
54359730 121
8aa49c15
CS
122 status)
123 statusproc /usr/bin/hostapd
124 ;;
54359730 125
8aa49c15
CS
126 *)
127 echo "Usage: ${0} {start|stop|restart|status}"
128 exit 1
129 ;;
54359730 130esac