broadcom.sh 6.1 KB

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