]>
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 | |
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" | |
071a0314 | 41 | elif [ "$(/bin/grep hostap /sys/class/net/$INTERFACE/uevent)" != "" ]; then |
8d30f4ed AF |
42 | DRIVER="HOSTAP" |
43 | driver="hostap" | |
7429ec82 AF |
44 | else |
45 | boot_mesg "Interface $INTERFACE is a not supported wireless device." ${FAILURE} | |
46 | echo_failure | |
47 | exit 0 | |
48 | fi | |
49 | ||
50 | echo driver=$driver > /etc/hostapd.conf.tmp | |
51 | grep -v "^driver=" /etc/hostapd.conf >> /etc/hostapd.conf.tmp | |
52 | mv /etc/hostapd.conf.tmp /etc/hostapd.conf | |
53 | ||
54 | echo DRIVER=$DRIVER > /var/ipfire/wlanap/settings.tmp | |
55 | grep -v "^DRIVER=" /var/ipfire/wlanap/settings >> /var/ipfire/wlanap/settings.tmp | |
56 | chown nobody:nobody /var/ipfire/wlanap/settings.tmp | |
57 | chmod 644 /var/ipfire/wlanap/settings.tmp | |
58 | mv /var/ipfire/wlanap/settings.tmp /var/ipfire/wlanap/settings | |
59 | ||
040ec360 | 60 | if [ "$DRIVER" == "HOSTAP" ]; then |
8d30f4ed AF |
61 | if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then |
62 | boot_mesg "Setting HOSTAP wlan $INTERFACE to Master mode... " | |
071a0314 | 63 | # Set Prism Cards to master mode |
8d30f4ed AF |
64 | /usr/bin/iwconfig $INTERFACE mode master > /dev/null |
65 | fi | |
8aa49c15 | 66 | fi |
54359730 | 67 | |
6a79396c AF |
68 | # First set to any country then reset to World (00) |
69 | # and then set new country because the card is only | |
70 | # reprogrammed if the region was changed. | |
71 | /usr/sbin/iw reg set DE | |
c3d9a16d AF |
72 | /usr/sbin/iw reg set 00 |
73 | /usr/sbin/iw reg set $COUNTRY | |
74 | ||
c1fd7bc5 | 75 | /usr/sbin/iwconfig $INTERFACE channel $CHANNEL 2>/dev/null |
ed974e08 AF |
76 | |
77 | ip link set ${INTERFACE} up 2>/dev/null | |
78 | /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER 2>/dev/null | |
7429ec82 | 79 | |
61160760 | 80 | /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 & |
79ef49bd | 81 | |
040ec360 | 82 | sleep 3 |
7429ec82 | 83 | |
54359730 | 84 | if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then |
d1b89a12 AF |
85 | killproc /usr/bin/hostapd > /dev/null 2>&1 |
86 | boot_mesg "Try to create additional AP device ..." | |
87 | ip link set ${INTERFACE} down | |
88 | ip link set ${INTERFACE} name ${INTERFACE}_man | |
89 | iw dev ${INTERFACE}_man interface add ${INTERFACE} type __ap | |
90 | evaluate_retval; | |
9c47987e AF |
91 | if [ -d /sys/class/net/${INTERFACE} ]; then |
92 | /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 & | |
93 | else | |
94 | ip link set ${INTERFACE}_man down | |
95 | ip link set ${INTERFACE}_man name ${INTERFACE} | |
96 | fi | |
79ef49bd | 97 | exit 0; |
54359730 | 98 | else |
79ef49bd | 99 | echo_ok |
54359730 | 100 | fi |
8aa49c15 | 101 | ;; |
54359730 | 102 | |
8aa49c15 | 103 | stop) |
54359730 | 104 | boot_mesg "Stopping hostapd..." |
d1b89a12 AF |
105 | ip link set ${INTERFACE} down > /dev/null 2>&1 |
106 | ip link set ${INTERFACE} down_man > /dev/null 2>&1 | |
107 | sleep 1 | |
8aa49c15 CS |
108 | killproc /usr/bin/hostapd |
109 | evaluate_retval | |
110 | ;; | |
54359730 | 111 | |
8aa49c15 CS |
112 | restart) |
113 | ${0} stop | |
114 | sleep 1 | |
115 | ${0} start | |
116 | ;; | |
54359730 | 117 | |
8aa49c15 CS |
118 | status) |
119 | statusproc /usr/bin/hostapd | |
120 | ;; | |
54359730 | 121 | |
8aa49c15 CS |
122 | *) |
123 | echo "Usage: ${0} {start|stop|restart|status}" | |
124 | exit 1 | |
125 | ;; | |
54359730 | 126 | esac |