#!/bin/sh
tplink_switch_preinit()
{

	local rsa=`cat /tmp/rsa_check/rsa_result `
	if [ "$rsa" == "PASS"  ]; then
		#set switch and phy power on
		swconfig dev switch0 set link_status on
	fi
	
	
	#change led mode
	local led_state=`uci get switch.led_set.enable`
	if [ "$led_state" == "on" ]; then
		mtk-switch phy cl45 w 0 0x1f 0x24 0xc001
		mtk-switch phy cl45 w 0 0x1f 0x25 0x3
		mtk-switch phy cl45 w 0 0x1f 0x26 0xc006
		mtk-switch phy cl45 w 0 0x1f 0x27 0x3c
		mtk-switch phy cl45 w 0 0x1f 0x21 0x800b
		mtk-switch phy cl45 w 0 0x1f 0x22 0x266
		mtk-switch phy cl45 w 0 0x1f 0x23 0x4cc
	fi
	
	#avoid package loss
	devmem 0x15110100 32 0x105f33b
	devmem 0x15110200 32 0x105f33b

	#forward all lldp pkts to CPU only
	swconfig dev switch0 set lldp 1
}
