02_network 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. dcs-930| \
  42. wnce2001)
  43. ucidef_add_switch "switch0" "1" "0"
  44. ucidef_set_interface_lan "eth0"
  45. ;;
  46. 3g-6200nl | \
  47. wl-330n | \
  48. wmr300)
  49. ucidef_set_interface_lan "eth0.1"
  50. ;;
  51. 3g-6200n | \
  52. b2c | \
  53. nw718 | \
  54. psr-680w | \
  55. sl-r7205 | \
  56. w502u | \
  57. wr6202)
  58. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  59. ;;
  60. br-6475nd)
  61. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  62. ucidef_add_switch "switch0" "1" "1"
  63. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
  64. ucidef_add_switch_vlan "switch0" "2" "0 9t"
  65. ;;
  66. asl26555)
  67. ucidef_set_interface_lan "eth0.1"
  68. ucidef_add_switch "switch0" "1" "1"
  69. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
  70. ;;
  71. dir-610-a1 | \
  72. dir-300-b7 | \
  73. dir-320-b1 | \
  74. dir-615-h1 | \
  75. hlk-rm04 | \
  76. mzk-w300nh2)
  77. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  78. ucidef_add_switch "switch0" "1" "1"
  79. ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
  80. ucidef_add_switch_vlan "switch0" "2" "4 6t"
  81. ;;
  82. argus-atp52b | \
  83. dir-645 | \
  84. f5d8235-v1 | \
  85. f5d8235-v2 | \
  86. hg255d | \
  87. rt-n14u | \
  88. ur-326n4g)
  89. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  90. ucidef_add_switch "switch0" "1" "1"
  91. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
  92. ucidef_add_switch_vlan "switch0" "2" "0 6t"
  93. ;;
  94. ur-336un)
  95. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  96. ;;
  97. br6524n | \
  98. v11st-fe)
  99. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  100. ucidef_add_switch "switch0" "1" "1"
  101. ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
  102. ucidef_add_switch_vlan "switch0" "2" "0 5t"
  103. ;;
  104. rt-n15 | \
  105. wl-351)
  106. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  107. ucidef_add_switch "switch0" "1" "1"
  108. ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
  109. ucidef_add_switch_vlan "switch0" "2" "4 5t"
  110. ;;
  111. rt-n56u)
  112. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  113. ucidef_add_switch "switch0" "1" "1"
  114. ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
  115. ucidef_add_switch_vlan "switch0" "2" "4 8t"
  116. ;;
  117. tew-691gr|\
  118. tew-692gr)
  119. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  120. ucidef_add_switch "switch0" "1" "1"
  121. ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
  122. ucidef_add_switch_vlan "switch0" "2" "0t 5"
  123. ;;
  124. wcr-150gn)
  125. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  126. ucidef_add_switch "switch0" "1" "1"
  127. ucidef_add_switch_vlan "switch0" "1" "0 6t"
  128. ucidef_add_switch_vlan "switch0" "2" "6t"
  129. ;;
  130. d105 | \
  131. na930 | \
  132. omni-emb-hpm|\
  133. wli-tx4-ag300n)
  134. ucidef_set_interface_lan "eth0"
  135. ;;
  136. *)
  137. RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
  138. if [ -n "${RT3X5X}" ]; then
  139. ramips_setup_rt3x5x_vlans
  140. else
  141. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  142. fi
  143. ;;
  144. esac
  145. }
  146. ramips_setup_macs()
  147. {
  148. local board="$1"
  149. local lan_mac=""
  150. local wan_mac=""
  151. case $board in
  152. *)
  153. wan_mac=$(macaddr_add "$lan_mac" 1)
  154. ;;
  155. br-6475nd)
  156. lan_mac=$(mtd_get_mac_binary devdata 13)
  157. wan_mac=$(mtd_get_mac_binary devdata 7)
  158. ;;
  159. w306r-v20)
  160. wan_mac=$(macaddr_add "$lan_mac" 5)
  161. ;;
  162. tew-691gr)
  163. wan_mac=$(macaddr_add "$lan_mac" 3)
  164. ;;
  165. tew-692gr)
  166. wan_mac=$(macaddr_add "$lan_mac" 4)
  167. ;;
  168. m3 |\
  169. m4 |\
  170. x5 |\
  171. x8)
  172. lan_mac=$(macaddr_add "$lan_mac" -1)
  173. ;;
  174. dir-620-a1)
  175. lan_mac=$(macaddr_setbit_la "$lan_mac")
  176. wan_mac=$(macaddr_add "$lan_mac" 1)
  177. ;;
  178. dir-645)
  179. lan_mac=$(mtd_get_mac_ascii nvram lanmac)
  180. wan_mac=$(mtd_get_mac_ascii nvram wanmac)
  181. ;;
  182. nbg-419n | \
  183. wcr-150gn)
  184. wan_mac=$(mtd_get_mac_binary factory 40)
  185. ;;
  186. rt-n56u)
  187. wan_mac=$(mtd_get_mac_binary factory 32772)
  188. ;;
  189. all0239-3g | \
  190. carambola | \
  191. freestation5 | \
  192. w502u | \
  193. wnce2001)
  194. wan_mac=$(mtd_get_mac_binary factory 46)
  195. ;;
  196. wl341v3)
  197. lan_mac=$(mtd_get_mac_binary board-nvram 65440)
  198. wan_mac=$(macaddr_add "$lan_mac" 1)
  199. ;;
  200. esac
  201. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
  202. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
  203. }
  204. [ -e /etc/config/network ] && exit 0
  205. touch /etc/config/network
  206. board=$(ramips_board_name)
  207. ramips_setup_interfaces $board
  208. ramips_setup_macs $board
  209. uci commit network
  210. exit 0