broadcom.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. append DRIVERS "broadcom"
  2. scan_broadcom() {
  3. local device="$1"
  4. local wds
  5. local adhoc sta apmode mon
  6. local adhoc_if sta_if ap_if mon_if
  7. local _c=0
  8. config_get vifs "$device" vifs
  9. for vif in $vifs; do
  10. config_get mode "$vif" mode
  11. _c=$(($_c + 1))
  12. case "$mode" in
  13. adhoc)
  14. adhoc=1
  15. adhoc_if="$vif"
  16. ;;
  17. sta)
  18. sta=1
  19. sta_if="$vif"
  20. ;;
  21. ap)
  22. apmode=1
  23. ap_if="${ap_if:+$ap_if }$vif"
  24. ;;
  25. wds)
  26. config_get addr "$vif" bssid
  27. [ -z "$addr" ] || {
  28. addr=$(echo "$addr" | tr 'A-F' 'a-f')
  29. append wds "$addr"
  30. }
  31. ;;
  32. monitor)
  33. mon=1
  34. mon_if="$vif"
  35. ;;
  36. *) echo "$device($vif): Invalid mode";;
  37. esac
  38. done
  39. config_set "$device" wds "$wds"
  40. local _c=
  41. for vif in ${adhoc_if:-$sta_if $ap_if $mon_if}; do
  42. config_set "$vif" ifname "wl0${_c:+.$_c}"
  43. _c=$((${_c:-0} + 1))
  44. done
  45. config_set "$device" vifs "${adhoc_if:-$sta_if $ap_if $mon_if}"
  46. ifdown="down"
  47. for vif in 0 1 2 3; do
  48. append ifdown "vif $vif" "$N"
  49. append ifdown "enabled 0" "$N"
  50. done
  51. ap=1
  52. infra=1
  53. if [ "$_c" -gt 1 ]; then
  54. mssid=1
  55. else
  56. mssid=
  57. fi
  58. apsta=0
  59. radio=1
  60. monitor=0
  61. passive=0
  62. case "$adhoc:$sta:$apmode:$mon" in
  63. 1*)
  64. ap=0
  65. mssid=
  66. infra=0
  67. ;;
  68. :1:1:)
  69. apsta=1
  70. wet=1
  71. ;;
  72. :1::)
  73. wet=1
  74. ap=0
  75. mssid=
  76. ;;
  77. :::1)
  78. wet=1
  79. ap=0
  80. mssid=
  81. monitor=1
  82. passive=1
  83. ;;
  84. ::)
  85. radio=0
  86. ;;
  87. esac
  88. }
  89. disable_broadcom() {
  90. set_wifi_down "$1"
  91. wlc down
  92. (
  93. include /lib/network
  94. # make sure the interfaces are down and removed from all bridges
  95. for dev in wl0 wl0.1 wl0.2 wl0.3; do
  96. ifconfig "$dev" down 2>/dev/null >/dev/null && {
  97. unbridge "$dev"
  98. }
  99. done
  100. )
  101. true
  102. }
  103. enable_broadcom() {
  104. local _c
  105. config_get channel "$device" channel
  106. config_get country "$device" country
  107. config_get maxassoc "$device" maxassoc
  108. config_get wds "$device" wds
  109. config_get vifs "$device" vifs
  110. config_get distance "$device" distance
  111. config_get slottime "$device" slottime
  112. config_get rxantenna "$device" rxantenna
  113. config_get txantenna "$device" txantenna
  114. config_get_bool frameburst "$device" frameburst
  115. config_get macfilter "$device" macfilter
  116. config_get maclist "$device" maclist
  117. config_get macaddr "$device" macaddr
  118. config_get txpower "$device" txpower
  119. local vif_pre_up vif_post_up vif_do_up vif_txpower
  120. local doth=0
  121. local wmm=0
  122. _c=0
  123. nas="$(which nas)"
  124. nas_cmd=
  125. if_up=
  126. [ -z "$slottime" ] && {
  127. [ -n "$distance" ] && {
  128. # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
  129. slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
  130. }
  131. } || {
  132. slottime="${slottime:--1}"
  133. }
  134. case "$macfilter" in
  135. allow|2)
  136. macfilter=2;
  137. ;;
  138. deny|1)
  139. macfilter=1;
  140. ;;
  141. disable|none|0)
  142. macfilter=0;
  143. ;;
  144. esac
  145. for vif in $vifs; do
  146. config_get vif_txpower "$vif" txpower
  147. config_get mode "$vif" mode
  148. append vif_pre_up "vif $_c" "$N"
  149. append vif_post_up "vif $_c" "$N"
  150. append vif_do_up "vif $_c" "$N"
  151. config_get_bool wmm "$vif" wmm "$wmm"
  152. config_get_bool doth "$vif" doth "$doth"
  153. [ "$mode" = "sta" ] || {
  154. config_get_bool hidden "$vif" hidden 0
  155. append vif_pre_up "closed $hidden" "$N"
  156. config_get_bool isolate "$vif" isolate 0
  157. append vif_pre_up "ap_isolate $isolate" "$N"
  158. }
  159. wsec_r=0
  160. eap_r=0
  161. wsec=0
  162. auth=0
  163. nasopts=
  164. config_get enc "$vif" encryption
  165. case "$enc" in
  166. WEP|wep)
  167. wsec_r=1
  168. wsec=1
  169. defkey=1
  170. config_get key "$vif" key
  171. case "$key" in
  172. [1234])
  173. defkey="$key"
  174. for knr in 1 2 3 4; do
  175. config_get k "$vif" key$knr
  176. [ -n "$k" ] || continue
  177. [ "$defkey" = "$knr" ] && def="=" || def=""
  178. append vif_do_up "wepkey $def$knr,$k" "$N"
  179. done
  180. ;;
  181. "");;
  182. *) append vif_do_up "wepkey =1,$key" "$N";;
  183. esac
  184. ;;
  185. *psk*|*PSK*)
  186. wsec_r=1
  187. config_get key "$vif" key
  188. case "$enc" in
  189. wpa*+wpa2*|WPA*+WPA2*|*psk+*psk2|*PSK+*PSK2) auth=132; wsec=6;;
  190. wpa2*|WPA2*|*PSK2|*psk2) auth=128; wsec=4;;
  191. *aes|*AES) auth=4; wsec=4;;
  192. *) auth=4; wsec=2;;
  193. esac
  194. eval "${vif}_key=\"\$key\""
  195. nasopts="-k \"\$${vif}_key\""
  196. ;;
  197. *wpa*|*WPA*)
  198. wsec_r=1
  199. eap_r=1
  200. config_get key "$vif" key
  201. config_get server "$vif" server
  202. config_get port "$vif" port
  203. case "$enc" in
  204. wpa*+wpa2*|WPA*+WPA2*) auth=66; wsec=6;;
  205. wpa2*|WPA2*) auth=64; wsec=4;;
  206. *) auth=2; wsec=2;;
  207. esac
  208. eval "${vif}_key=\"\$key\""
  209. nasopts="-r \"\$${vif}_key\" -h $server -p ${port:-1812}"
  210. ;;
  211. esac
  212. append vif_do_up "wsec $wsec" "$N"
  213. append vif_do_up "wpa_auth $auth" "$N"
  214. append vif_do_up "wsec_restrict $wsec_r" "$N"
  215. append vif_do_up "eap_restrict $eap_r" "$N"
  216. config_get ssid "$vif" ssid
  217. append vif_post_up "vlan_mode 0" "$N"
  218. append vif_post_up "ssid $ssid" "$N"
  219. append vif_do_up "ssid $ssid" "$N"
  220. [ "$mode" = "monitor" ] && {
  221. append vif_post_up "monitor $monitor" "$N"
  222. append vif_post_up "passive $passive" "$N"
  223. }
  224. [ "$mode" = "adhoc" ] && {
  225. config_get bssid "$vif" bssid
  226. [ -n "$bssid" ] && {
  227. append vif_pre_up "des_bssid $bssid" "$N"
  228. append vif_pre_up "allow_mode 1" "$N"
  229. }
  230. } || append vif_pre_up "allow_mode 0" "$N"
  231. append vif_post_up "enabled 1" "$N"
  232. config_get ifname "$vif" ifname
  233. #append if_up "ifconfig $ifname up" ";$N"
  234. local net_cfg bridge
  235. net_cfg="$(find_net_config "$vif")"
  236. [ -z "$net_cfg" ] || {
  237. bridge="$(bridge_interface "$net_cfg")"
  238. append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
  239. append if_up "start_net '$ifname' '$net_cfg' \$(wlc ifname '$ifname' bssid)" ";$N"
  240. }
  241. [ -z "$nasopts" ] || {
  242. eval "${vif}_ssid=\"\$ssid\""
  243. nas_mode="-A"
  244. use_nas=1
  245. [ "$mode" = "sta" ] && {
  246. nas_mode="-S"
  247. [ -z "$bridge" ] || {
  248. append vif_post_up "supplicant 1" "$N"
  249. append vif_post_up "passphrase $key" "$N"
  250. use_nas=0
  251. }
  252. }
  253. [ -z "$nas" -o "$use_nas" = "0" ] || nas_cmd="${nas_cmd:+$nas_cmd$N}$nas -P /var/run/nas.$ifname.pid -H 34954 ${bridge:+ -l $bridge} -i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 $nasopts &"
  254. }
  255. _c=$(($_c + 1))
  256. done
  257. killall -KILL nas >&- 2>&-
  258. wlc stdin <<EOF
  259. $ifdown
  260. apsta $apsta
  261. ap $ap
  262. ${mssid:+mssid $mssid}
  263. infra $infra
  264. ${wet:+wet 1}
  265. 802.11d 0
  266. 802.11h ${doth:-0}
  267. wme ${wmm:-0}
  268. rxant ${rxantenna:-3}
  269. txant ${txantenna:-3}
  270. monitor ${monitor:-0}
  271. passive ${passive:-0}
  272. radio ${radio:-1}
  273. macfilter ${macfilter:-0}
  274. maclist ${maclist:-none}
  275. wds none
  276. ${wds:+wds $wds}
  277. country ${country:-IL0}
  278. ${channel:+channel $channel}
  279. maxassoc ${maxassoc:-128}
  280. slottime ${slottime:--1}
  281. ${frameburst:+frameburst $frameburst}
  282. $vif_pre_up
  283. up
  284. $vif_post_up
  285. EOF
  286. eval "$if_up"
  287. wlc stdin <<EOF
  288. $vif_do_up
  289. EOF
  290. # use vif_txpower (from last wifi-iface) instead of txpower (from
  291. # wifi-device) if the latter does not exist
  292. txpower=${txpower:-$vif_txpower}
  293. [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
  294. eval "$nas_cmd"
  295. }
  296. detect_broadcom() {
  297. [ -f /proc/net/wl0 ] || return
  298. config_get type wl0 type
  299. [ "$type" = broadcom ] && return
  300. cat <<EOF
  301. config wifi-device wl0
  302. option type broadcom
  303. option channel 5
  304. # REMOVE THIS LINE TO ENABLE WIFI:
  305. option disabled 1
  306. config wifi-iface
  307. option device wl0
  308. option network lan
  309. option mode ap
  310. option ssid OpenWrt
  311. option encryption none
  312. EOF
  313. }