]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/initscripts/init.d/hostapd
Merge branch 'master' of ssh://arne_f@ipfire.org/pub/git/ipfire-2.x
[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
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"
8d30f4ed
AF
43 elif [ "$(/bin/grep hostap_pci /sys/class/net/$INTERFACE/uevent)" != "" ]; then
44 #PHYSDEVDRIVER=hostap_pci
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... "
73 # Set Prism 2.4 Cards to master mode
74 /usr/bin/iwconfig $INTERFACE mode master > /dev/null
75 fi
8aa49c15 76 fi
54359730 77
79ef49bd
AF
78 /usr/sbin/iwconfig $INTERFACE channel $CHANNEL
79 /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER
7429ec82 80
61160760 81 /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 &
79ef49bd 82
c485b902 83 sleep 2
79ef49bd 84
7429ec82 85 if [ $DRIVER == "MADWIFI" ]; then
79ef49bd
AF
86 iwpriv $INTERFACE maccmd 3
87 if [ $MACMODE != 0 ]; then
88 FILE="/var/ipfire/wlanap/macfile"
89 exec < $FILE
90 while read LINE
91 do
92 iwpriv $INTERFACE addmac $LINE
93 done
54359730 94
79ef49bd
AF
95 iwpriv $INTERFACE maccmd $MACMODE
96 fi
a494df6d 97 fi
8aa49c15 98
c485b902 99 sleep 2
7429ec82 100
54359730 101 if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then
8aa49c15
CS
102 boot_mesg "Error! Can't set wlan master mode"
103 echo_failure;
79ef49bd 104 exit 0;
54359730 105 else
79ef49bd 106 echo_ok
54359730 107 fi
8aa49c15 108 ;;
54359730 109
8aa49c15 110 stop)
54359730
CS
111 boot_mesg "Stopping hostapd..."
112
8aa49c15
CS
113 killproc /usr/bin/hostapd
114 evaluate_retval
115 ;;
54359730 116
8aa49c15
CS
117 restart)
118 ${0} stop
119 sleep 1
120 ${0} start
121 ;;
54359730 122
8aa49c15
CS
123 status)
124 statusproc /usr/bin/hostapd
125 ;;
54359730 126
8aa49c15
CS
127 *)
128 echo "Usage: ${0} {start|stop|restart|status}"
129 exit 1
130 ;;
54359730 131esac