summaryrefslogtreecommitdiffstats
path: root/package/hostap-driver/files/lib/wifi/hostap.sh
blob: 053c08b83a629859695012b35827951d88bbab23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
append DRIVERS "prism2"

scan_prism2() {
	local device="$1"
	
	config_get mode "$device" mode
	case "$mode" in
		ad-hoc|managed|master)
		;;
		*) echo "$device: Invalid mode, ignored."; continue;;
	esac
	
}

disable_prism2() (
	local device="$1"
	
	set_wifi_down "$device"

	include /lib/network
	ifconfig "$device" down 
	unbridge "$device"
	return 0
)

enable_prism2() {
	local irqdevs

	config_get prifw "$device" prifw
	config_get stafw "$device" stafw
	config_get mode "$device" mode
	config_get rate "$device" rate
	config_get channel "$device" channel
	config_get txpower "$device" txpower
	config_get ssid "$device" ssid
	config_get maclist "$device" maclist
	config_get macpolicy "$device" macpolicy
	[ -f "$prifw" ] || [ -f "$stafw" ] && [ -x /usr/sbin/prism2_srec ] && {
		irqdevs=$(cat /proc/interrupts | grep wifi${device##wlan} | cut -b 37- | tr -d ",")
		for dev in $irqdevs; do
			[ "$(config_get "$dev" type)" = "atheros" ] && wifi down "$dev"
		done
		[ -f "$prifw" ] && prism2_srec -g $device $prifw
		[ -f "$stafw" ] && prism2_srec -r $device $stafw
		for dev in $irqdevs; do
			[ "$(config_get "$dev" type)" = "atheros" ] && wifi up "$dev"
		done
	}
	[ -n "$mode" ] && iwconfig $device mode $mode
	[ -n "$rate" ] && iwconfig $device rate $rate
	[ -n "$channel" ] && iwconfig $device channel $channel
	[ -n "$ssid" ] && iwconfig $device essid $ssid
	ifconfig "$device" up
	[ -n "$txpower" ] && iwconfig $device txpower $txpower
	[ -n "$maclist" ] && {
		# flush MAC list
		iwpriv $device maccmd 3
		for mac in $maclist; do
			iwpriv $device addmac $mac
		done
	}
	case "$macpolicy" in
		open)
			iwpriv $device maccmd 0
		;;
		allow)
			iwpriv $device maccmd 1
		;;
		deny)
			iwpriv $device maccmd 2
		;;
		*)
			# default deny policy if mac list exists
			[ -n "$maclist" ] && iwpriv $device maccmd 2
		;;
	esac
	# kick all stations if we have policy explicitly set
	[ -n "$macpolicy" ] && iwpriv $device maccmd 4
	local net_cfg bridge
	net_cfg="$(find_net_config "$device")"
	[ -z "$net_cfg" ] || {
		bridge="$(bridge_interface "$net_cfg")"
		config_set "$device" bridge "$bridge"
		start_net "$device" "$net_cfg"
	}
	set_wifi_up "$device" "$device"
}


detect_prism2() {
	cd /proc/net/hostap
	[ -d wlan0 ] || return
	for dev in wlan*; do
		config_get type "$dev" type
		[ "$type" = prism2 ] && continue
		cat <<EOF

config wifi-device $dev
	option type	prism2
#	option rate	11M
	option channel	5
	option txpower	127
	option mode     managed
	option ssid     OpenWrt
#	option macpolicy deny
#	option maclist	'12:34:56:78:90:12
#			 09:87:65:43:21:09'

	# REMOVE THIS LINE TO ENABLE WIFI:
	option disabled 1
	
EOF
	done
}