[Android Q&A, Help & Troubleshooting] prqek:
Hi,

I created some scripts to use reverse tethering over usb (connect the phone to internert over usb) on my rooted SE Xperia pro (official fw 4.1.B.0.587).

Here is the first one - used to conffugure usb function:

#!/system/bin/sh
if [ "$1" = "" ]
then
echo "missing argument!"
exit 1
fi

echo "actual state:"
getprop sys.usb.state
echo "setting to: " $1
setprop sys.usb.config $1

until getprop sys.usb.state | grep "$1" > /dev/null
do
echo "waiting...."
sleep 1;
done

echo "new state:"
getprop sys.usb.state
echo "setting persistent state"
setprop persist.sys.usb.config $1

echo DONE

I call this one with rndis argument, so the networing over usb is set up. And this is the second one:

#!/system/bin/sh
ip route del default
ip link set usb0 down
ip link set usb0 address b2:52:71:6d:fe:4e
ip link set usb0 up
netcfg usb0 dhcp
ip addr show usb0

setprop net.dns1 "`getprop net.usb0.dns1`"
setprop net.dns2 "`getprop net.usb0.dns2`"

echo DONE

Everything has been working well until today, when the phone didn`t receive ip address from dhcp server. I found that the problem is caused by calling ip link set usb0 down

Whenever I do it, the usb0 interface stops working (I did ip link set usb0 up, of course) until I restart the phone, or reset the usb by:

setprop sys.usb.config "`getprop sys.usb.state`"

But I want to use a static MAC address to get always the same ip address from dhcp server. But the MAC cannot be changed, when the interface is up. I have a solution for this - befor I call the first script, I call this one:

#!/system/bin/sh

MAC=xx:xx:xx:xx:xx:xx

if grep $MAC /sys/module/android/parameters/dev_addr > /dev/null
then
echo "usb0 MAC OK"
else
echo "setting usb0 MAC"
chmod 644 /sys/module/android/parameters/dev_addr
echo "$MAC" -en > /sys/module/android/parameters/dev_addr
fi

The MAC address is not generated randomly, so it`s always the same.

The problem seems to be solved, but I`d like to know, why ip link set usb0 down completly disables the comunication over usb0. It is disabled even if ip link show usb0 says UP and LOWER_UP. There is one more detail - I noticed, that if set up the comunication (ip`s on both ends etc.), run ping from computer to the phone, do ip link set usb0 down, ip link set usb0 up and reset usb (as mentioned before), then the ping receives several old and broken replays before the link is completly down - something like this:

64 bytes from 192.168.4.1: icmp_req=19 ttl=64 time=16.5 ms

64 bytes from 192.168.4.1: icmp_req=20 ttl=64 time=16.4 ms

From 192.168.4.5 icmp_seq=71 Destination Host Unreachable

...

From 192.168.4.5 icmp_seq=80 Destination Host Unreachable

64 bytes from 192.168.4.1: icmp_req=20 ttl=64 time=61093 ms (DUP!)

64 bytes from 192.168.4.1: icmp_req=16 ttl=64 time=65155 ms (DUP!)

64 bytes from 192.168.4.1: icmp_req=17 ttl=64 time=64140 ms (DUP!)

64 bytes from 192.168.4.1: icmp_req=18 ttl=64 time=63124 ms (DUP!)

64 bytes from 192.168.4.1: icmp_req=1 ttl=64 time=80251 ms (DUP!)

Warning: time of day goes back (-276781472us), taking countermeasures.

Warning: time of day goes back (-276779504us), taking countermeasures.

64 bytes from 192.168.4.1: icmp_req=20 ttl=64 time=0.000 ms (DUP!)

wrong data byte #8 should be 0x8 but was 0x0

#8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

#40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

64 bytes from 192.168.4.1: icmp_req=14 ttl=64 time=67189 ms (DUP!)

64 bytes from 192.168.4.1: icmp_req=20 ttl=64 time=61608 ms (DUP!)

64 bytes from 192.168.4.1: icmp_req=1 ttl=64 time=80767 ms (DUP!)

Warning: time of day goes back (-276266195us), taking countermeasures.

64 bytes from 192.168.4.1: icmp_req=20 ttl=64 time=0.000 ms (DUP!)

wrong data byte #8 should be 0x8 but was 0x0

#8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

#40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

64 bytes from 192.168.4.1: icmp_req=14 ttl=64 time=67702 ms (DUP!)

64 bytes from 192.168.4.1: icmp_req=16 ttl=64 time=65671 ms (DUP!)

Did you see anything like this? Any idea why is this happening?

Thanks for any advices.

P.

P.S. I am not sure how much is this related to my phone (If I would I knew the answer :) ) and I didn`t find any thread related directly to my phone, so I posted this here, hope it`s OK. And sorry for all the mistakes, english isn`t my native language.