]>
Commit | Line | Data |
---|---|---|
07603508 CS |
1 | #!/bin/sh |
2 | . /etc/sysconfig/rc | |
3 | . ${rc_functions} | |
4 | ||
040ec360 | 5 | CHANNEL="6" |
c3d9a16d | 6 | COUNTRY="00" |
54359730 CS |
7 | TXPOWER="auto" |
8 | INTERFACE="blue0" | |
79ef49bd | 9 | MACMODE="0" |
79ef49bd | 10 | |
b9694349 | 11 | eval $(/usr/local/bin/readhash /var/ipfire/wlanap/settings) |
54359730 | 12 | |
54359730 | 13 | case "${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 | |
0bd7b731 | 20 | if [ ! -d "/sys/class/net/${INTERFACE}" ]; then |
c485b902 | 21 | boot_mesg "Interface $INTERFACE doesn't exist." ${FAILURE} |
7429ec82 AF |
22 | echo_failure |
23 | exit 0 | |
24 | fi | |
0bd7b731 | 25 | |
7429ec82 AF |
26 | if [ "$(ip link show $INTERFACE | /bin/grep "ether")" == "" ]; then |
27 | boot_mesg "Interface $INTERFACE is assigned to wlan master device." ${FAILURE} | |
28 | boot_mesg "Please reboot to fix this." ${FAILURE} | |
29 | echo_failure | |
30 | exit 0 | |
31 | fi | |
0bd7b731 MT |
32 | |
33 | # Check if INTERFACE is an actual wireless device | |
34 | if [ ! -d "/sys/class/net/${INTERFACE}/wireless" ]; then | |
7429ec82 AF |
35 | boot_mesg "Interface $INTERFACE is no wireless device." ${FAILURE} |
36 | echo_failure | |
37 | exit 0 | |
38 | fi | |
39 | ||
40 | # Detect driver | |
41 | if [ -e "/sys/class/net/$INTERFACE/phy80211" ]; then | |
42 | DRIVER="NL80211" | |
43 | driver="nl80211" | |
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 | ||
040ec360 | 63 | if [ "$DRIVER" == "HOSTAP" ]; then |
8d30f4ed AF |
64 | if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then |
65 | boot_mesg "Setting HOSTAP wlan $INTERFACE to Master mode... " | |
071a0314 | 66 | # Set Prism Cards to master mode |
8d30f4ed AF |
67 | /usr/bin/iwconfig $INTERFACE mode master > /dev/null |
68 | fi | |
8aa49c15 | 69 | fi |
54359730 | 70 | |
6a79396c AF |
71 | # First set to any country then reset to World (00) |
72 | # and then set new country because the card is only | |
73 | # reprogrammed if the region was changed. | |
74 | /usr/sbin/iw reg set DE | |
c3d9a16d AF |
75 | /usr/sbin/iw reg set 00 |
76 | /usr/sbin/iw reg set $COUNTRY | |
77 | ||
c1fd7bc5 | 78 | /usr/sbin/iwconfig $INTERFACE channel $CHANNEL 2>/dev/null |
ed974e08 AF |
79 | |
80 | ip link set ${INTERFACE} up 2>/dev/null | |
81 | /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER 2>/dev/null | |
7429ec82 | 82 | |
61160760 | 83 | /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 & |
79ef49bd | 84 | |
040ec360 | 85 | sleep 3 |
7429ec82 | 86 | |
54359730 | 87 | if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then |
d1b89a12 AF |
88 | killproc /usr/bin/hostapd > /dev/null 2>&1 |
89 | boot_mesg "Try to create additional AP device ..." | |
90 | ip link set ${INTERFACE} down | |
91 | ip link set ${INTERFACE} name ${INTERFACE}_man | |
92 | iw dev ${INTERFACE}_man interface add ${INTERFACE} type __ap | |
93 | evaluate_retval; | |
9c47987e AF |
94 | if [ -d /sys/class/net/${INTERFACE} ]; then |
95 | /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 & | |
96 | else | |
97 | ip link set ${INTERFACE}_man down | |
98 | ip link set ${INTERFACE}_man name ${INTERFACE} | |
99 | fi | |
79ef49bd | 100 | exit 0; |
54359730 | 101 | else |
79ef49bd | 102 | echo_ok |
54359730 | 103 | fi |
8aa49c15 | 104 | ;; |
54359730 | 105 | |
8aa49c15 | 106 | stop) |
54359730 | 107 | boot_mesg "Stopping hostapd..." |
d1b89a12 AF |
108 | ip link set ${INTERFACE} down > /dev/null 2>&1 |
109 | ip link set ${INTERFACE} down_man > /dev/null 2>&1 | |
110 | sleep 1 | |
8aa49c15 CS |
111 | killproc /usr/bin/hostapd |
112 | evaluate_retval | |
113 | ;; | |
54359730 | 114 | |
8aa49c15 CS |
115 | restart) |
116 | ${0} stop | |
117 | sleep 1 | |
118 | ${0} start | |
119 | ;; | |
54359730 | 120 | |
8aa49c15 CS |
121 | status) |
122 | statusproc /usr/bin/hostapd | |
123 | ;; | |
54359730 | 124 | |
8aa49c15 CS |
125 | *) |
126 | echo "Usage: ${0} {start|stop|restart|status}" | |
127 | exit 1 | |
128 | ;; | |
54359730 | 129 | esac |