]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/hostapd
BUG10797: Fix addontable in services.cgi when using squid-accounting addon
[ipfire-2.x.git] / src / initscripts / init.d / hostapd
1 #!/bin/sh
2 . /etc/sysconfig/rc
3 . ${rc_functions}
4
5 CHANNEL="05"
6 COUNTRY="00"
7 TXPOWER="auto"
8 INTERFACE="blue0"
9 MACMODE="0"
10
11 eval $(/usr/local/bin/readhash /var/ipfire/wlanap/settings)
12
13 case "${1}" in
14 start)
15 mkdir -p /var/run/hostapd
16
17 boot_mesg "Starting hostapd... "
18
19 # Check Interface configuration
20 if ! ip link show $INTERFACE > /dev/null 2>&1; then
21 boot_mesg "Interface $INTERFACE doesn't exist." ${FAILURE}
22 echo_failure
23 exit 0
24 fi
25 if [ "$(ip link show $INTERFACE | /bin/grep "ether")" == "" ]; then
26 boot_mesg "Interface $INTERFACE is assigned to wlan master device." ${FAILURE}
27 boot_mesg "Please reboot to fix this." ${FAILURE}
28 echo_failure
29 exit 0
30 fi
31 if [ "$(iwconfig $INTERFACE | /bin/grep "IEEE")" == "" ]; then
32 boot_mesg "Interface $INTERFACE is no wireless device." ${FAILURE}
33 echo_failure
34 exit 0
35 fi
36
37 # Detect driver
38 if [ -e "/sys/class/net/$INTERFACE/phy80211" ]; then
39 DRIVER="NL80211"
40 driver="nl80211"
41 elif [ -e "/sys/class/net/$INTERFACE/madwifi_name_type" ]; then
42 DRIVER="MADWIFI"
43 driver="madwifi"
44 elif [ "$(/bin/grep hostap /sys/class/net/$INTERFACE/uevent)" != "" ]; then
45 DRIVER="HOSTAP"
46 driver="hostap"
47 else
48 boot_mesg "Interface $INTERFACE is a not supported wireless device." ${FAILURE}
49 echo_failure
50 exit 0
51 fi
52
53 echo driver=$driver > /etc/hostapd.conf.tmp
54 grep -v "^driver=" /etc/hostapd.conf >> /etc/hostapd.conf.tmp
55 mv /etc/hostapd.conf.tmp /etc/hostapd.conf
56
57 echo DRIVER=$DRIVER > /var/ipfire/wlanap/settings.tmp
58 grep -v "^DRIVER=" /var/ipfire/wlanap/settings >> /var/ipfire/wlanap/settings.tmp
59 chown nobody:nobody /var/ipfire/wlanap/settings.tmp
60 chmod 644 /var/ipfire/wlanap/settings.tmp
61 mv /var/ipfire/wlanap/settings.tmp /var/ipfire/wlanap/settings
62
63 if [ "$DRIVER" == "MADWIFI" ]; then
64 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
65 boot_mesg "Setting MADWIFI wlan $INTERFACE to Master mode... "
66 # Set Atheros Cards to master mode
67 /usr/bin/wlanconfig $INTERFACE destroy > /dev/null
68 /usr/bin/wlanconfig $INTERFACE create wlandev wifi0 wlanmode ap > /dev/null
69 fi
70 elif [ "$DRIVER" == "HOSTAP" ]; then
71 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
72 boot_mesg "Setting HOSTAP wlan $INTERFACE to Master mode... "
73 # Set Prism Cards to master mode
74 /usr/bin/iwconfig $INTERFACE mode master > /dev/null
75 fi
76 fi
77
78 # First set to any country then reset to World (00)
79 # and then set new country because the card is only
80 # reprogrammed if the region was changed.
81 /usr/sbin/iw reg set DE
82 /usr/sbin/iw reg set 00
83 /usr/sbin/iw reg set $COUNTRY
84
85 /usr/sbin/iwconfig $INTERFACE channel $CHANNEL 2>/dev/null
86 /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER
87
88 /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 &
89
90 sleep 2
91
92 if [ $DRIVER == "MADWIFI" ]; then
93 iwpriv $INTERFACE maccmd 3
94 if [ $MACMODE != 0 ]; then
95 FILE="/var/ipfire/wlanap/macfile"
96 exec < $FILE
97 while read LINE
98 do
99 iwpriv $INTERFACE addmac $LINE
100 done
101
102 iwpriv $INTERFACE maccmd $MACMODE
103 fi
104 fi
105
106 sleep 2
107
108 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
109 killproc /usr/bin/hostapd > /dev/null 2>&1
110 boot_mesg "Try to create additional AP device ..."
111 ip link set ${INTERFACE} down
112 ip link set ${INTERFACE} name ${INTERFACE}_man
113 iw dev ${INTERFACE}_man interface add ${INTERFACE} type __ap
114 evaluate_retval;
115 if [ -d /sys/class/net/${INTERFACE} ]; then
116 /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 &
117 else
118 ip link set ${INTERFACE}_man down
119 ip link set ${INTERFACE}_man name ${INTERFACE}
120 fi
121 exit 0;
122 else
123 echo_ok
124 fi
125 ;;
126
127 stop)
128 boot_mesg "Stopping hostapd..."
129 ip link set ${INTERFACE} down > /dev/null 2>&1
130 ip link set ${INTERFACE} down_man > /dev/null 2>&1
131 sleep 1
132 killproc /usr/bin/hostapd
133 evaluate_retval
134 ;;
135
136 restart)
137 ${0} stop
138 sleep 1
139 ${0} start
140 ;;
141
142 status)
143 statusproc /usr/bin/hostapd
144 ;;
145
146 *)
147 echo "Usage: ${0} {start|stop|restart|status}"
148 exit 1
149 ;;
150 esac