02_network 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/ramips.sh
  4. . /lib/functions/uci-defaults.sh
  5. ramips_setup_rt3x5x_vlans()
  6. {
  7. if [ ! -x /sbin/swconfig ]; then
  8. # legacy default
  9. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  10. return
  11. fi
  12. local wanports=""
  13. local lanports=""
  14. for port in 5 4 3 2 1 0; do
  15. if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
  16. continue
  17. fi
  18. if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
  19. wanports="$port $wanports"
  20. else
  21. lanports="$port $lanports"
  22. fi
  23. done
  24. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  25. ucidef_add_switch "rt305x" "1" "1"
  26. ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
  27. ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
  28. }
  29. ramips_setup_interfaces()
  30. {
  31. local board="$1"
  32. ucidef_set_interface_loopback
  33. case $board in
  34. 3g300m | \
  35. w150m | \
  36. all0256n | \
  37. all5002 | \
  38. all5003 | \
  39. awm002-evb | \
  40. broadway | \
  41. wnce2001)
  42. ucidef_add_switch "switch0" "1" "0"
  43. ucidef_set_interface_lan "eth0"
  44. ;;
  45. 3g-6200nl | \
  46. wl-330n)
  47. ucidef_set_interface_lan "eth0.1"
  48. ;;
  49. 3g-6200n | \
  50. argus-atp52b | \
  51. b2c | \
  52. nw718 | \
  53. psr-680w | \
  54. sl-r7205 | \
  55. w502u | \
  56. wr6202)
  57. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  58. ;;
  59. asl26555)
  60. ucidef_set_interface_lan "eth0.1"
  61. ucidef_add_switch "switch0" "1" "1"
  62. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
  63. ;;
  64. dir-645)
  65. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  66. ucidef_add_switch "switch0" "1" "1"
  67. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
  68. ucidef_add_switch_vlan "switch0" "2" "0 6t"
  69. ;;
  70. dir-615-h1 | \
  71. mzk-w300nh2)
  72. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  73. ucidef_add_switch "switch0" "1" "1"
  74. ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
  75. ucidef_add_switch_vlan "switch0" "2" "4 6t"
  76. ;;
  77. f5d8235-v1 | \
  78. f5d8235-v2 | \
  79. hg255d | \
  80. ur-326n4g)
  81. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  82. ucidef_add_switch "switch0" "1" "1"
  83. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
  84. ucidef_add_switch_vlan "switch0" "2" "0 6t"
  85. ;;
  86. ur-336un)
  87. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  88. ;;
  89. br6524n | \
  90. v11st-fe)
  91. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  92. ucidef_add_switch "switch0" "1" "1"
  93. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
  94. ucidef_add_switch_vlan "switch0" "2" "0 5t"
  95. ;;
  96. rt-n15 | \
  97. wl-351)
  98. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  99. ucidef_add_switch "switch0" "1" "1"
  100. ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
  101. ucidef_add_switch_vlan "switch0" "2" "4 5t"
  102. ;;
  103. rt-n56u)
  104. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  105. ucidef_add_switch "switch0" "1" "1"
  106. ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
  107. ucidef_add_switch_vlan "switch0" "2" "4 8t"
  108. ;;
  109. tew-691gr|\
  110. tew-692gr)
  111. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  112. ucidef_add_switch "switch0" "1" "1"
  113. ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
  114. ucidef_add_switch_vlan "switch0" "2" "0t 5"
  115. ;;
  116. wcr-150gn)
  117. ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
  118. ;;
  119. d105 | \
  120. omni-emb-hpm|\
  121. wli-tx4-ag300n)
  122. ucidef_set_interface_lan "eth0"
  123. ;;
  124. *)
  125. RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
  126. if [ -n "${RT3X5X}" ]; then
  127. ramips_setup_rt3x5x_vlans
  128. else
  129. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  130. fi
  131. ;;
  132. esac
  133. }
  134. ramips_setup_macs()
  135. {
  136. local board="$1"
  137. local lan_mac=""
  138. local wan_mac=""
  139. case $board in
  140. all0256n | \
  141. all5002 | \
  142. dir-615-h1)
  143. lan_mac=$(mtd_get_mac_binary factory 40)
  144. ;;
  145. 3g-6200n | \
  146. 3g300m | \
  147. w150m | \
  148. air3gii | \
  149. argus-atp52b | \
  150. bc2 | \
  151. br6425 | \
  152. broadway | \
  153. dir-620-d1 | \
  154. f5d8235-v1 | \
  155. mpr-a1 | \
  156. mpr-a2 | \
  157. mzk-w300nh2 | \
  158. nw718 | \
  159. psr-680w | \
  160. rt-n15 | \
  161. sl-r7205 | \
  162. wl-351)
  163. lan_mac=$(mtd_get_mac_binary factory 4)
  164. wan_mac=$(macaddr_add "$lan_mac" 1)
  165. ;;
  166. asl26555)
  167. lan_mac=$(mtd_get_mac_binary devdata 16388)
  168. ;;
  169. w306r-v20)
  170. lan_mac=$(mtd_get_mac_binary factory 4)
  171. wan_mac=$(macaddr_add "$lan_mac" 5)
  172. ;;
  173. rt-n13u | \
  174. hg255d | \
  175. fonera20n)
  176. lan_mac=$(mtd_get_mac_binary factory 40)
  177. wan_mac=$(macaddr_add "$lan_mac" 1)
  178. ;;
  179. dir-300-b1 |\
  180. dir-300-b2 |\
  181. dir-600-b1)
  182. lan_mac=$(mtd_get_mac_binary devdata 16388)
  183. wan_mac=$(macaddr_add "$lan_mac" 1)
  184. ;;
  185. dir-620-a1)
  186. lan_mac=$(mtd_get_mac_binary factory 4)
  187. lan_mac=$(macaddr_setbit_la "$lan_mac")
  188. wan_mac=$(macaddr_add "$lan_mac" 1)
  189. ;;
  190. dir-645)
  191. lan_mac=$(mtd_get_mac_ascii nvram lanmac)
  192. wan_mac=$(mtd_get_mac_ascii nvram wanmac)
  193. ;;
  194. esr-9753 | \
  195. ur-326n4g | \
  196. ur-336un)
  197. lan_mac=$(mtd_get_mac_binary devdata 16388)
  198. wan_mac=$(macaddr_add "$lan_mac" 1)
  199. ;;
  200. nbg-419n | \
  201. wcr-150gn)
  202. lan_mac=$(mtd_get_mac_binary factory 4)
  203. wan_mac=$(mtd_get_mac_binary factory 40)
  204. ;;
  205. omni-emb-hpm)
  206. lan_mac=$(mtd_get_mac_binary factory 40)
  207. ;;
  208. f5d8235-v2)
  209. lan_mac=$(mtd_get_mac_binary "u-boot" 262148)
  210. wan_mac=$(macaddr_add "$lan_mac" 1)
  211. ;;
  212. rt-n56u)
  213. lan_mac=$(mtd_get_mac_binary factory 4)
  214. wan_mac=$(mtd_get_mac_binary factory 32772)
  215. ;;
  216. tew-691gr)
  217. lan_mac=$(mtd_get_mac_binary factory 40)
  218. wan_mac=$(macaddr_add "$lan_mac" 3)
  219. ;;
  220. tew-692gr)
  221. lan_mac=$(mtd_get_mac_binary factory 40)
  222. wan_mac=$(macaddr_add "$lan_mac" 4)
  223. ;;
  224. all0239-3g | \
  225. carambola | \
  226. freestation5 | \
  227. w502u | \
  228. wnce2001)
  229. lan_mac=$(mtd_get_mac_binary factory 40)
  230. wan_mac=$(mtd_get_mac_binary factory 46)
  231. ;;
  232. wl341v3)
  233. lan_mac=$(mtd_get_mac_binary board-nvram 65440)
  234. wan_mac=$(macaddr_add "$lan_mac" 1)
  235. ;;
  236. d105 | \
  237. wli-tx4-ag300n)
  238. lan_mac=$(mtd_get_mac_binary factory 4)
  239. ;;
  240. esac
  241. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
  242. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
  243. }
  244. [ -e /etc/config/network ] && exit 0
  245. touch /etc/config/network
  246. board=$(ramips_board_name)
  247. ramips_setup_interfaces $board
  248. ramips_setup_macs $board
  249. uci commit network
  250. exit 0