mac80211.sh 3.7 KB
Newer Older
ejka's avatar
ejka committed
1
2
3
#!/bin/sh
append DRIVERS "mac80211"

4
5
lookup_phy() {
	[ -n "$phy" ] && {
6
		[ -d /sys/class/ieee80211/$phy ] && return
7
8
9
10
	}

	local devpath
	config_get devpath "$device" path
11
12
13
14
15
16
17
	[ -n "$devpath" ] && {
		for _phy in /sys/devices/$devpath/ieee80211/phy*; do
			[ -e "$_phy" ] && {
				phy="${_phy##*/}"
				return
			}
		done
18
	}
19
20

	local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
21
	[ -n "$macaddr" ] && {
22
23
24
25
26
		for _phy in /sys/class/ieee80211/*; do
			[ -e "$_phy" ] || continue

			[ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue
			phy="${_phy##*/}"
27
			return
28
29
		done
	}
30
31
32
33
34
35
36
37
38
	phy=
	return
}

find_mac80211_phy() {
	local device="$1"

	config_get phy "$device" phy
	lookup_phy
39
40
41
42
	[ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
		echo "PHY for wifi device $1 not found"
		return 1
	}
43
44
45
	config_set "$device" phy "$phy"

	config_get macaddr "$device" macaddr
46
47
48
	[ -z "$macaddr" ] && {
		config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
	}
49

50
51
52
	return 0
}

53
check_mac80211_device() {
54
55
	config_get phy "$1" phy
	[ -z "$phy" ] && {
56
		find_mac80211_phy "$1" >/dev/null || return 0
57
58
59
60
61
		config_get phy "$1" phy
	}
	[ "$phy" = "$dev" ] && found=1
}

ejka's avatar
ejka committed
62
detect_mac80211() {
63
64
	devidx=0
	config_load wireless
65
	while :; do
66
		config_get type "radio$devidx" type
67
68
69
		[ -n "$type" ] || break
		devidx=$(($devidx + 1))
	done
70
71
72
73
74
75

	for _dev in /sys/class/ieee80211/*; do
		[ -e "$_dev" ] || continue

		dev="${_dev##*/}"

76
		found=0
77
		config_foreach check_mac80211_device wifi-device
78
79
		[ "$found" -gt 0 ] && continue

80
		mode_band="g"
81
		channel="11"
nbd's avatar
nbd committed
82
		htmode=""
nbd's avatar
nbd committed
83
		ht_capab=""
nbd's avatar
nbd committed
84

85
		iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20
86
		iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
87

nbd's avatar
nbd committed
88
89
90
91
92
93
94
95
96
		vht_cap=$(iw phy "$dev" info | grep -c 'VHT Capabilities')
		[ "$vht_cap" -gt 0 ] && {
			mode_band="a";
			channel="36"
			htmode="VHT80"
		}

		[ -n $htmode ] && append ht_capab "	option htmode	$htmode" "$N"

97
98
99
100
101
102
103
104
		if [ -x /usr/bin/readlink ]; then
			path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
			path="${path##/sys/devices/}"
			dev_id="	option path	'$path'"
		else
			dev_id="	option macaddr	$(cat /sys/class/ieee80211/${dev}/macaddress)"
		fi

ejka's avatar
ejka committed
105
		cat <<EOF
106
config wifi-device  radio$devidx
ejka's avatar
ejka committed
107
	option type     mac80211
108
	option channel  ${channel}
109
	option hwmode	11${mode_band}
110
$dev_id
111
$ht_capab
ejka's avatar
ejka committed
112
	# REMOVE THIS LINE TO ENABLE WIFI:
113
114
	#option disabled 1
        option country FR
ejka's avatar
ejka committed
115
116

config wifi-iface
117
	option device   radio$devidx
118
	option network  vlan3
119
	option mode     ap
120
121
122
123
124
125
126
        option wmm      1
	option ssid     Cr@ns
	option encryption wpa2
        option server     fda8:5d34:a228:c04:7261:6469:7573:3031
        option key        fill_it
        option disabled 1
        option dynamic_vlan 1
127
        option vlan_bridge br-vlan
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
config wifi-iface
        option device   radio$devidx
        option network  vlan12
        option mode     ap
        option isolate  0
        option wmm      1
        option ssid     Federez
        option encryption wpa2
        # Serveur radius de prod:
        option server     fda8:5d34:a228:c04:7261:6469:7573:3031
        option key        fill_it
        option disabled 1
        option dynamic_vlan 1

143
config wifi-iface
144
145
146
147
148
149
150
151
        option device   radio$devidx
        option network  vlan10
        option mode     ap
        option isolate  0
        option wmm      1
        option ssid     Cr@ns-Install
        option encryption none
        option disabled 1
152
153
154
155
156
157
158

config 'wifi-iface'
        option 'device' 'radio$devidx'
        option 'network' 'vlan7'
        option 'mode' 'ap'
        option 'ssid' 'Cr@ns-accueil'
        option 'encryption' 'none'
159
        option 'test_connect' 'ping fe80::1%br-vlan7 -c 4'
160
161
        option 'isolate' '1'
        option 'wmm' '1'
162

ejka's avatar
ejka committed
163
EOF
164
	devidx=$(($devidx + 1))
ejka's avatar
ejka committed
165
166
	done
}
167