]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/initscripts/init.d/hostapd
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into beyond-next
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / hostapd
CommitLineData
07603508
CS
1#!/bin/sh
2. /etc/sysconfig/rc
3. ${rc_functions}
4
54359730 5CHANNEL="05"
c3d9a16d 6COUNTRY="00"
54359730
CS
7TXPOWER="auto"
8INTERFACE="blue0"
79ef49bd 9MACMODE="0"
79ef49bd 10
b9694349 11eval $(/usr/local/bin/readhash /var/ipfire/wlanap/settings)
54359730 12
54359730 13case "${1}" in
8aa49c15 14 start)
54359730 15 mkdir -p /var/run/hostapd
54359730 16
7429ec82
AF
17 boot_mesg "Starting hostapd... "
18
19 # Check Interface configuration
20 if ! ip link show $INTERFACE > /dev/null 2>&1; then
c485b902 21 boot_mesg "Interface $INTERFACE doesn't exist." ${FAILURE}
7429ec82
AF
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"
071a0314 44 elif [ "$(/bin/grep hostap /sys/class/net/$INTERFACE/uevent)" != "" ]; then
8d30f4ed
AF
45 DRIVER="HOSTAP"
46 driver="hostap"
7429ec82
AF
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
79ef49bd
AF
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
8d30f4ed
AF
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... "
071a0314 73 # Set Prism Cards to master mode
8d30f4ed
AF
74 /usr/bin/iwconfig $INTERFACE mode master > /dev/null
75 fi
8aa49c15 76 fi
54359730 77
6a79396c
AF
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
c3d9a16d
AF
82 /usr/sbin/iw reg set 00
83 /usr/sbin/iw reg set $COUNTRY
84
c1fd7bc5 85 /usr/sbin/iwconfig $INTERFACE channel $CHANNEL 2>/dev/null
79ef49bd 86 /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER
7429ec82 87
61160760 88 /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 &
79ef49bd 89
c485b902 90 sleep 2
79ef49bd 91
7429ec82 92 if [ $DRIVER == "MADWIFI" ]; then
79ef49bd
AF
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
54359730 101
79ef49bd
AF
102 iwpriv $INTERFACE maccmd $MACMODE
103 fi
a494df6d 104 fi
8aa49c15 105
c485b902 106 sleep 2
7429ec82 107
54359730 108 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
8aa49c15
CS
109 boot_mesg "Error! Can't set wlan master mode"
110 echo_failure;
79ef49bd 111 exit 0;
54359730 112 else
79ef49bd 113 echo_ok
54359730 114 fi
8aa49c15 115 ;;
54359730 116
8aa49c15 117 stop)
54359730
CS
118 boot_mesg "Stopping hostapd..."
119
8aa49c15
CS
120 killproc /usr/bin/hostapd
121 evaluate_retval
122 ;;
54359730 123
8aa49c15
CS
124 restart)
125 ${0} stop
126 sleep 1
127 ${0} start
128 ;;
54359730 129
8aa49c15
CS
130 status)
131 statusproc /usr/bin/hostapd
132 ;;
54359730 133
8aa49c15
CS
134 *)
135 echo "Usage: ${0} {start|stop|restart|status}"
136 exit 1
137 ;;
54359730 138esac