02_network 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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_add_switch "rt305x" $lanports $wanports "6t@eth0"
  26. }
  27. ramips_setup_interfaces()
  28. {
  29. local board="$1"
  30. case $board in
  31. 11acnas|\
  32. w2914nsv2)
  33. ucidef_add_switch "switch0" \
  34. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
  35. ;;
  36. 3g150b|\
  37. 3g300m|\
  38. a5-v11|\
  39. all0256n|\
  40. all5002|\
  41. all5003|\
  42. broadway|\
  43. dcs-930|\
  44. dcs-930l-b1|\
  45. ht-tm02|\
  46. linkits7688 | \
  47. linkits7688d | \
  48. m2m|\
  49. microwrt|\
  50. mpr-a2|\
  51. ncs601w|\
  52. omega2 | \
  53. omega2p | \
  54. timecloud|\
  55. w150m|\
  56. widora-neo|\
  57. wnce2001|\
  58. zbt-cpe102|\
  59. zte-q7)
  60. ucidef_add_switch "switch0"
  61. ucidef_add_switch_attr "switch0" "enable" "false"
  62. ucidef_set_interface_lan "eth0"
  63. ;;
  64. mlw221|\
  65. mr-102n)
  66. ucidef_set_interface_lan "eth0.2"
  67. ;;
  68. 3g-6200n|\
  69. ac1200pro|\
  70. ai-br100|\
  71. d240|\
  72. db-wrt01|\
  73. dir-300-b7|\
  74. dir-320-b1|\
  75. dir-610-a1|\
  76. dir-615-h1|\
  77. firewrt|\
  78. hlk-rm04|\
  79. mac1200rv2|\
  80. miwifi-mini|\
  81. miwifi-nano|\
  82. mt7621|\
  83. mt7628|\
  84. mzk-750dhp|\
  85. mzk-w300nh2|\
  86. nixcore|\
  87. oy-0001|\
  88. pbr-m1|\
  89. psg1208|\
  90. psg1218|\
  91. sap-g3200u3|\
  92. sk-wb8|\
  93. vr500|\
  94. wf-2881|\
  95. witi|\
  96. wl-wn575a3|\
  97. wndr3700v5|\
  98. wt1520|\
  99. y1|\
  100. youku-yk1|\
  101. zbt-ape522ii|\
  102. zbt-we826|\
  103. zbt-wg2626|\
  104. zbt-wg3526|\
  105. zbt-wr8305rt)
  106. ucidef_add_switch "switch0" \
  107. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  108. ;;
  109. whr-300hp2|\
  110. whr-600d|\
  111. wsr-1166|\
  112. wsr-600)
  113. ucidef_add_switch "switch0" \
  114. "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
  115. ;;
  116. ar670w|\
  117. ar725w|\
  118. rt-n15|\
  119. wl-351)
  120. ucidef_add_switch "switch0" \
  121. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
  122. ;;
  123. asl26555|\
  124. rp-n53)
  125. ucidef_add_switch "switch0" \
  126. "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
  127. ;;
  128. atp-52b|\
  129. awm002-evb|\
  130. awm003-evb|\
  131. c20i|\
  132. dir-645|\
  133. f5d8235-v2|\
  134. gl-mt300a|\
  135. gl-mt300n|\
  136. gl-mt750|\
  137. hg255d|\
  138. jhr-n805r|\
  139. jhr-n825r|\
  140. jhr-n926r|\
  141. mzk-wdpr|\
  142. rb750gr3|\
  143. rt-n14u|\
  144. ubnt-erx|\
  145. ur-326n4g|\
  146. wrtnode|\
  147. wrtnode2p | \
  148. wrtnode2r | \
  149. wt3020|\
  150. zbt-wa05)
  151. ucidef_add_switch "switch0" \
  152. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
  153. ;;
  154. awapn2403)
  155. ucidef_add_switch "switch0" \
  156. "0:lan" "1:wan" "6@eth0"
  157. ;;
  158. b2c|\
  159. nw718|\
  160. psr-680w|\
  161. sl-r7205|\
  162. ur-336un|\
  163. w502u|\
  164. wr6202)
  165. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  166. ;;
  167. br-6475nd)
  168. ucidef_add_switch "switch0" \
  169. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
  170. ;;
  171. cf-wr800n|\
  172. ex2700)
  173. ucidef_add_switch "switch0" \
  174. "4:lan" "6t@eth0"
  175. ;;
  176. cy-swr1100)
  177. ucidef_add_switch "switch0" \
  178. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
  179. ;;
  180. cs-qr10|\
  181. d105|\
  182. dch-m225|\
  183. hpm|\
  184. mzk-ex300np|\
  185. mzk-ex750np|\
  186. na930|\
  187. pbr-d1|\
  188. wli-tx4-ag300n|\
  189. wmr-300|\
  190. wn3000rpv3|\
  191. wrh-300cr)
  192. ucidef_set_interface_lan "eth0"
  193. ;;
  194. c50)
  195. ucidef_add_switch "switch0" \
  196. "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
  197. ;;
  198. dir-860l-b1)
  199. ucidef_add_switch "switch0" \
  200. "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
  201. ;;
  202. gb-pc1)
  203. ucidef_add_switch "switch0" \
  204. "0:lan" "4:wan" "6@eth0"
  205. ;;
  206. duzun-dm06)
  207. ucidef_add_switch "switch0" \
  208. "1:lan" "0:wan" "6@eth0"
  209. ;;
  210. e1700|\
  211. mt7620a_mt7530)
  212. ucidef_add_switch "switch1" \
  213. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  214. ;;
  215. hc5*61|\
  216. y1s)
  217. ucidef_add_switch "switch0" \
  218. "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
  219. ;;
  220. kn_rc|\
  221. kn_rf)
  222. ucidef_add_switch "switch0" \
  223. "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
  224. ;;
  225. kng_rc)
  226. ucidef_add_switch "switch1" \
  227. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
  228. ;;
  229. mlwg2|\
  230. wizard8800|\
  231. wl-330n)
  232. ucidef_set_interface_lan "eth0.1"
  233. ;;
  234. mr200)
  235. ucidef_add_switch "switch0" \
  236. "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
  237. ucidef_set_interface_wan "usb0"
  238. ;;
  239. mzk-dp150n|\
  240. vocore)
  241. ucidef_add_switch "switch0" \
  242. "0:lan" "4:lan" "6t@eth0"
  243. ;;
  244. newifi-d1)
  245. ucidef_add_switch "switch0" \
  246. "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
  247. ;;
  248. re6500)
  249. ucidef_add_switch "switch0" \
  250. "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
  251. ;;
  252. rt-n56u)
  253. ucidef_add_switch "switch0" \
  254. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
  255. ;;
  256. tew-691gr|\
  257. tew-692gr|\
  258. wlr-6000)
  259. ucidef_add_switch "switch0" \
  260. "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
  261. ;;
  262. vocore2)
  263. ucidef_add_switch "switch0" \
  264. "0:lan" "2:lan" "6t@eth0"
  265. ;;
  266. f5d8235-v1|\
  267. tew-714tru|\
  268. v11st-fe|\
  269. wzr-agl300nh)
  270. ucidef_add_switch "switch0" \
  271. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
  272. ;;
  273. wcr-150gn)
  274. ucidef_add_switch "switch0" \
  275. "0:lan" "6t@eth0"
  276. ;;
  277. whr-1166d)
  278. ucidef_add_switch "switch0" \
  279. "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
  280. ;;
  281. wizfi630a)
  282. ucidef_add_switch "switch0" \
  283. "1:lan" "2:lan" "0:wan" "6@eth0"
  284. ;;
  285. *)
  286. RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
  287. if [ -n "${RT3X5X}" ]; then
  288. ramips_setup_rt3x5x_vlans
  289. else
  290. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  291. fi
  292. ;;
  293. esac
  294. }
  295. ramips_setup_macs()
  296. {
  297. local board="$1"
  298. local lan_mac=""
  299. local wan_mac=""
  300. case $board in
  301. a5-v11|\
  302. ht-tm02)
  303. lan_mac=$(cat /sys/class/net/eth0/address)
  304. ;;
  305. all0239-3g|\
  306. carambola|\
  307. freestation5|\
  308. w502u|\
  309. wnce2001)
  310. wan_mac=$(mtd_get_mac_binary factory 46)
  311. ;;
  312. bc2|\
  313. broadway|\
  314. d105|\
  315. dir-300-b7|\
  316. dir-320-b1|\
  317. dir-620-a1|\
  318. esr-9753|\
  319. freestation5|\
  320. hlk-rm04|\
  321. mpr-a1|\
  322. psr-680w|\
  323. sl-r7205|\
  324. y1|\
  325. y1s)
  326. lan_mac=$(cat /sys/class/net/eth0/address)
  327. lan_mac=$(macaddr_setbit_la "$lan_mac")
  328. wan_mac=$(macaddr_add "$lan_mac" 1)
  329. ;;
  330. br-6475nd)
  331. lan_mac=$(cat /sys/class/net/eth0/address)
  332. wan_mac=$(mtd_get_mac_binary devdata 7)
  333. ;;
  334. cy-swr1100|\
  335. dch-m225)
  336. lan_mac=$(mtd_get_mac_ascii factory lanmac)
  337. ;;
  338. dir-645)
  339. lan_mac=$(mtd_get_mac_ascii nvram lanmac)
  340. wan_mac=$(mtd_get_mac_ascii nvram wanmac)
  341. ;;
  342. dir-860l-b1)
  343. lan_mac=$(mtd_get_mac_ascii factory lanmac)
  344. wan_mac=$(mtd_get_mac_ascii factory wanmac)
  345. ;;
  346. e1700)
  347. wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
  348. ;;
  349. hc5*61)
  350. lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
  351. [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
  352. wan_mac=$(macaddr_add "$lan_mac" 1)
  353. ;;
  354. kn_rc|\
  355. kn_rf|\
  356. kng_rc)
  357. wan_mac=$(mtd_get_mac_binary factory 40)
  358. ;;
  359. linkits7688 | \
  360. linkits7688d)
  361. wan_mac=$(mtd_get_mac_binary factory 4)
  362. lan_mac=$(mtd_get_mac_binary factory 46)
  363. ;;
  364. mac1200rv2)
  365. lan_mac=$(mtd_get_mac_binary factory_info 13)
  366. wan_mac=$(macaddr_add "$lan_mac" 1)
  367. ;;
  368. miwifi-mini)
  369. wan_mac=$(cat /sys/class/net/eth0/address)
  370. lan_mac=$(macaddr_setbit_la "$wan_mac")
  371. ;;
  372. m3|\
  373. m4|\
  374. x5|\
  375. x8)
  376. lan_mac=$(cat /sys/class/net/eth0/address)
  377. lan_mac=$(macaddr_add "$lan_mac" -2)
  378. ;;
  379. newifi-d1)
  380. lan_mac=$(cat /sys/class/net/eth0/address)
  381. lan_mac=$(macaddr_add "$lan_mac" 2)
  382. ;;
  383. omega2|\
  384. omega2p)
  385. wan_mac=$(mtd_get_mac_binary factory 4)
  386. lan_mac=$(mtd_get_mac_binary factory 46)
  387. ;;
  388. oy-0001)
  389. lan_mac=$(mtd_get_mac_binary factory 40)
  390. wan_mac=$(mtd_get_mac_binary factory 46)
  391. ;;
  392. rt-n56u)
  393. lan_mac=$(cat /sys/class/net/eth0/address)
  394. lan_mac=$(macaddr_setbit_la "$lan_mac")
  395. wan_mac=$(mtd_get_mac_binary factory 32772)
  396. ;;
  397. sk-wb8)
  398. wan_mac=$(mtd_get_mac_binary factory 57350)
  399. ;;
  400. tew-691gr)
  401. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
  402. ;;
  403. tew-692gr)
  404. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
  405. ;;
  406. tiny-ac)
  407. lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
  408. wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
  409. ;;
  410. vr500)
  411. lan_mac=$(mtd_get_mac_binary factory 57344)
  412. wan_mac=$(mtd_get_mac_binary factory 57350)
  413. ;;
  414. w306r-v20)
  415. lan_mac=$(cat /sys/class/net/eth0/address)
  416. wan_mac=$(macaddr_add "$lan_mac" 5)
  417. ;;
  418. wcr-150gn)
  419. wan_mac=$(mtd_get_mac_binary factory 40)
  420. ;;
  421. whr-1166d|\
  422. whr-300hp2|\
  423. whr-600d|\
  424. wsr-600)
  425. wan_mac=$(mtd_get_mac_binary factory 4)
  426. lan_mac=$wan_mac
  427. ;;
  428. wizfi630a)
  429. lan_mac=$(mtd_get_mac_binary factory 4)
  430. wan_mac=$(mtd_get_mac_binary factory 40)
  431. ;;
  432. wlr-6000)
  433. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
  434. ;;
  435. wsr-1166)
  436. local index="$(find_mtd_index "board_data")"
  437. wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
  438. lan_mac=$wan_mac
  439. ;;
  440. *)
  441. lan_mac=$(cat /sys/class/net/eth0/address)
  442. wan_mac=$(macaddr_add "$lan_mac" 1)
  443. ;;
  444. esac
  445. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
  446. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
  447. }
  448. board_config_update
  449. board=$(ramips_board_name)
  450. ramips_setup_interfaces $board
  451. ramips_setup_macs $board
  452. board_config_flush
  453. exit 0