02_network 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/ramips.sh
  4. . /lib/functions/uci-defaults.sh
  5. . /lib/functions/system.sh
  6. ramips_setup_rt3x5x_vlans()
  7. {
  8. if [ ! -x /sbin/swconfig ]; then
  9. # legacy default
  10. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  11. return
  12. fi
  13. local wanports=""
  14. local lanports=""
  15. for port in 5 4 3 2 1 0; do
  16. if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
  17. continue
  18. fi
  19. if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
  20. wanports="$port:wan $wanports"
  21. else
  22. lanports="$port:lan $lanports"
  23. fi
  24. done
  25. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  26. ucidef_add_switch "rt305x" $lanports $wanports "6@eth0"
  27. }
  28. ramips_setup_interfaces()
  29. {
  30. local board="$1"
  31. case $board in
  32. 3g150b|\
  33. 3g300m|\
  34. a5-v11|\
  35. all0256n|\
  36. all5002|\
  37. all5003|\
  38. broadway|\
  39. dcs-930|\
  40. dcs-930l-b1|\
  41. ht-tm02|\
  42. linkits7688 | \
  43. linkits7688d | \
  44. m2m|\
  45. microwrt|\
  46. mpr-a2|\
  47. ncs601w|\
  48. w150m|\
  49. widora-neo|\
  50. wnce2001|\
  51. zte-q7)
  52. ucidef_add_switch "switch0"
  53. ucidef_add_switch_attr "switch0" "enable" "false"
  54. ucidef_set_interface_lan "eth0"
  55. ;;
  56. 3g-6200nl|\
  57. mlw221|\
  58. mr-102n)
  59. ucidef_set_interface_lan "eth0.2"
  60. ;;
  61. 3g-6200n|\
  62. ai-br100|\
  63. db-wrt01|\
  64. dir-300-b7|\
  65. dir-320-b1|\
  66. dir-610-a1|\
  67. dir-615-h1|\
  68. firewrt|\
  69. hlk-rm04|\
  70. miwifi-mini|\
  71. miwifi-nano|\
  72. mt7621|\
  73. mt7628|\
  74. mzk-750dhp|\
  75. mzk-w300nh2|\
  76. oy-0001|\
  77. pbr-m1|\
  78. psg1208|\
  79. psg1218|\
  80. sap-g3200u3|\
  81. sk-wb8|\
  82. wf-2881|\
  83. whr-300hp2|\
  84. whr-600d|\
  85. witi|\
  86. wndr3700v5|\
  87. wsr-1166|\
  88. wsr-600|\
  89. wt1520|\
  90. y1|\
  91. zbt-wg2626|\
  92. zbt-wg3526|\
  93. youku-yk1)
  94. ucidef_add_switch "switch0" \
  95. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  96. ;;
  97. ar670w|\
  98. ar725w|\
  99. rt-n15|\
  100. wl-351)
  101. ucidef_add_switch "switch0" \
  102. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
  103. ;;
  104. asl26555|\
  105. re6500|\
  106. rp-n53)
  107. ucidef_add_switch "switch0" \
  108. "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
  109. ;;
  110. atp-52b|\
  111. awm002-evb|\
  112. awm003-evb|\
  113. c50|\
  114. dir-645|\
  115. dir-860l-b1|\
  116. f5d8235-v1|\
  117. f5d8235-v2|\
  118. gl-mt300a|\
  119. gl-mt300n|\
  120. gl-mt750|\
  121. hg255d|\
  122. mzk-wdpr|\
  123. jhr-n805r|\
  124. jhr-n825r|\
  125. jhr-n926r|\
  126. rt-n14u|\
  127. ubnt-erx|\
  128. ur-326n4g|\
  129. wrtnode|\
  130. wrtnode2p | \
  131. wrtnode2r | \
  132. wt3020|\
  133. zbt-wa05)
  134. ucidef_add_switch "switch0" \
  135. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
  136. ;;
  137. awapn2403)
  138. ucidef_add_switch "switch0" \
  139. "0:lan" "1:wan" "6@eth0"
  140. ;;
  141. b2c|\
  142. nw718|\
  143. psr-680w|\
  144. sl-r7205|\
  145. ur-336un|\
  146. w502u|\
  147. wr6202)
  148. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  149. ;;
  150. br-6475nd)
  151. ucidef_add_switch "switch0" \
  152. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
  153. ;;
  154. cf-wr800n|\
  155. ex2700)
  156. ucidef_add_switch "switch0" \
  157. "4:lan" "6t@eth0"
  158. ;;
  159. cy-swr1100)
  160. ucidef_add_switch "switch0" \
  161. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
  162. ;;
  163. cs-qr10|\
  164. d105|\
  165. hpm|\
  166. mzk-ex300np|\
  167. mzk-ex750np|\
  168. na930|\
  169. wli-tx4-ag300n|\
  170. wrh-300cr)
  171. ucidef_set_interface_lan "eth0"
  172. ;;
  173. duzun-dm06)
  174. ucidef_add_switch "switch0" \
  175. "1:lan" "0:wan" "6@eth0"
  176. ;;
  177. e1700|\
  178. mt7620a_mt7530)
  179. ucidef_add_switch "switch1" \
  180. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  181. ;;
  182. hc5*61|\
  183. y1s)
  184. ucidef_add_switch "switch0" \
  185. "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
  186. ;;
  187. mlwg2|\
  188. wizard8800|\
  189. wl-330n|\
  190. wmr-300)
  191. ucidef_set_interface_lan "eth0.1"
  192. ;;
  193. mzk-dp150n|\
  194. vocore)
  195. ucidef_add_switch "switch0" \
  196. "0:lan" "4:lan" "6t@eth0"
  197. ;;
  198. rt-n56u)
  199. ucidef_add_switch "switch0" \
  200. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
  201. ;;
  202. tew-691gr|\
  203. tew-692gr)
  204. ucidef_add_switch "switch0" \
  205. "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
  206. ;;
  207. v11st-fe|\
  208. wzr-agl300nh)
  209. ucidef_add_switch "switch0" \
  210. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
  211. ;;
  212. wcr-150gn)
  213. ucidef_add_switch "switch0" \
  214. "0:lan" "6t@eth0"
  215. ;;
  216. whr-1166d)
  217. ucidef_add_switch "switch0" \
  218. "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
  219. ;;
  220. wizfi630a)
  221. ucidef_add_switch "switch0" \
  222. "1:lan" "2:lan" "0:wan" "6@eth0"
  223. ;;
  224. zbt-ape522ii|\
  225. zbt-we826|\
  226. zbt-wr8305rt)
  227. ucidef_add_switch "switch0" \
  228. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  229. ;;
  230. *)
  231. RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
  232. if [ -n "${RT3X5X}" ]; then
  233. ramips_setup_rt3x5x_vlans
  234. else
  235. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  236. fi
  237. ;;
  238. esac
  239. }
  240. ramips_setup_macs()
  241. {
  242. local board="$1"
  243. local lan_mac=""
  244. local wan_mac=""
  245. case $board in
  246. a5-v11|\
  247. ht-tm02)
  248. lan_mac=$(cat /sys/class/net/eth0/address)
  249. ;;
  250. all0239-3g|\
  251. carambola|\
  252. freestation5|\
  253. w502u|\
  254. wnce2001)
  255. wan_mac=$(mtd_get_mac_binary factory 46)
  256. ;;
  257. bc2|\
  258. broadway|\
  259. d105|\
  260. dir-300-b7|\
  261. dir-320-b1|\
  262. dir-620-a1|\
  263. esr-9753|\
  264. freestation5|\
  265. hlk-rm04|\
  266. mpr-a1|\
  267. psr-680w|\
  268. sl-r7205|\
  269. y1|\
  270. y1s)
  271. lan_mac=$(cat /sys/class/net/eth0/address)
  272. lan_mac=$(macaddr_setbit_la "$lan_mac")
  273. wan_mac=$(macaddr_add "$lan_mac" 1)
  274. ;;
  275. br-6475nd)
  276. lan_mac=$(cat /sys/class/net/eth0/address)
  277. wan_mac=$(mtd_get_mac_binary devdata 7)
  278. ;;
  279. cy-swr1100|\
  280. dir-645)
  281. lan_mac=$(mtd_get_mac_ascii nvram lanmac)
  282. wan_mac=$(mtd_get_mac_ascii nvram wanmac)
  283. ;;
  284. dir-860l-b1)
  285. lan_mac=$(mtd_get_mac_ascii factory lanmac)
  286. wan_mac=$(mtd_get_mac_ascii factory wanmac)
  287. ;;
  288. e1700)
  289. wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
  290. ;;
  291. hc5*61)
  292. lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
  293. [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
  294. wan_mac=$(macaddr_add "$lan_mac" 1)
  295. ;;
  296. linkits7688 | \
  297. linkits7688d)
  298. wan_mac=$(mtd_get_mac_binary factory 4)
  299. lan_mac=$(mtd_get_mac_binary factory 46)
  300. ;;
  301. m3|\
  302. m4|\
  303. x5|\
  304. x8)
  305. lan_mac=$(cat /sys/class/net/eth0/address)
  306. lan_mac=$(macaddr_add "$lan_mac" -2)
  307. ;;
  308. oy-0001)
  309. lan_mac=$(mtd_get_mac_binary factory 40)
  310. wan_mac=$(mtd_get_mac_binary factory 46)
  311. ;;
  312. rt-n56u)
  313. lan_mac=$(cat /sys/class/net/eth0/address)
  314. lan_mac=$(macaddr_setbit_la "$lan_mac")
  315. wan_mac=$(mtd_get_mac_binary factory 32772)
  316. ;;
  317. sk-wb8)
  318. wan_mac=$(mtd_get_mac_binary factory 57350)
  319. ;;
  320. tew-691gr)
  321. lan_mac=$(cat /sys/class/net/eth0/address)
  322. wan_mac=$(macaddr_add "$lan_mac" 3)
  323. ;;
  324. tew-692gr)
  325. lan_mac=$(cat /sys/class/net/eth0/address)
  326. wan_mac=$(macaddr_add "$lan_mac" 4)
  327. ;;
  328. tiny-ac)
  329. lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
  330. wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
  331. ;;
  332. w306r-v20)
  333. lan_mac=$(cat /sys/class/net/eth0/address)
  334. wan_mac=$(macaddr_add "$lan_mac" 5)
  335. ;;
  336. wcr-150gn)
  337. wan_mac=$(mtd_get_mac_binary factory 40)
  338. ;;
  339. whr-1166d|\
  340. whr-300hp2|\
  341. whr-600d|\
  342. wsr-600)
  343. wan_mac=$(mtd_get_mac_binary factory 4)
  344. lan_mac=$wan_mac
  345. ;;
  346. wizfi630a)
  347. lan_mac=$(mtd_get_mac_binary factory 4)
  348. wan_mac=$(mtd_get_mac_binary factory 40)
  349. ;;
  350. wsr-1166)
  351. local index="$(find_mtd_index "board_data")"
  352. wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
  353. lan_mac=$wan_mac
  354. ;;
  355. *)
  356. lan_mac=$(cat /sys/class/net/eth0/address)
  357. wan_mac=$(macaddr_add "$lan_mac" 1)
  358. ;;
  359. esac
  360. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
  361. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
  362. }
  363. board_config_update
  364. board=$(ramips_board_name)
  365. ramips_setup_interfaces $board
  366. ramips_setup_macs $board
  367. board_config_flush
  368. exit 0