Project

General

Profile

USB networking: updates for wiki

Added by Dmitry Samoyloff over 6 years ago

Hi,

I have some updates and additional info for http://redmine.replicant.us/projects/replicant/wiki/ReplicantUSBNetworking :

1. Small fix for run_dev.sh (for 4.0, the same goes to 2.3):

26c26
<     ifconfig rndis0 up
---
>     ifconfig $USB_IFACE up
39c39
<     ifconfig rndis0 down
---
>     ifconfig $USB_IFACE down

2. It's probably worth to mention that it is needed to enable the USB tethering to make rndis0 network interface available:

System settings -> Wireless & networks -> More -> Tethering & portable hotspot

It's always off when I turn on my I9300 (is it possible to switch it on permanently?).


Replies (11)

RE: USB networking: updates for wiki - Added by Paul Kocialkowski over 6 years ago

Using tethering is not a good way to do this. Could you investigate how to properly rewrite the scripts so that it works directly, with Replicant 4.0?

RE: USB networking: updates for wiki - Added by Dmitry Samoyloff over 6 years ago

Honestly, all I know is that without tethering I have no rndis0:

# netcfg                                                           
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
rmnet0   DOWN                                   0.0.0.0/0   0x00001090 00:00:00:00:00:00
rmnet1   DOWN                                   0.0.0.0/0   0x00001090 00:00:00:00:00:00
rmnet2   DOWN                                   0.0.0.0/0   0x00001090 00:00:00:00:00:00

After turning it on, run_dev.sh works without errors and I have one more line in netcfg output:

rndis0   UP                               192.168.4.202/24  0x00001043 aa:bb:cc:dd:ee:ff

ifconfig's output is always empty on my device for some reason.

I have no idea how to do this without tethering. Why is it so bad?

RE: USB networking: updates for wiki - Added by Paul Kocialkowski over 6 years ago

Why is it so bad?

It is just inappropriate: you don't want to use tethering but the other way round.

After turning it on, run_dev.sh works without errors and I have one more line in netcfg output

The point of run_dev.sh is to enable that interface too. I think it fails to do it on its own because the sysfs interface changed.

RE: USB networking: updates for wiki - Added by Dmitry Samoyloff over 6 years ago

Paul Kocialkowski wrote:

Why is it so bad?

It is just inappropriate: you don't want to use tethering but the other way round.

Ah, I see, it's for using devices's internet connection on PC.

After turning it on, run_dev.sh works without errors and I have one more line in netcfg output

The point of run_dev.sh is to enable that interface too. I think it fails to do it on its own because the sysfs interface changed.

In the shell on the device, while the script wasn't run yet and the tethering is off, I have the following:

$ ./adb shell
root@android:/ # bash
localhost / # netcfg
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
rmnet0   DOWN                                   0.0.0.0/0   0x00001090 00:00:00:00:00:00
rmnet1   DOWN                                   0.0.0.0/0   0x00001090 00:00:00:00:00:00
rmnet2   DOWN                                   0.0.0.0/0   0x00001090 00:00:00:00:00:00
localhost / # cat /sys/class/android_usb/android0/enable
1

So, the enable file which is used in the script, is present and rndis0 is absent.

localhost / # find /sys > /mnt/sdcard/sys.tree                                 

Here's the /sys tree on my device: http://obscurehalt.org/tmp/sys.tree

RE: USB networking: updates for wiki - Added by Paul Kocialkowski over 6 years ago

I was told you can use a prop instead of sysfs, which is probably easier actually.

RE: USB networking: updates for wiki - Added by Dmitry Samoyloff over 6 years ago

Hm, I can't see anything interesting there:

localhost / # find /proc -name '*rndis*' 
localhost / # find /proc -name '*enable*'                                      
/proc/sys/fs/leases-enable
localhost / # find /proc -name '*android*'                                     
localhost / # find /proc -name '*usb*'                                         
/proc/irq/134/ohci_hcd:usb2
/proc/irq/134/ehci_hcd:usb1
/proc/bus/usb
/proc/tty/driver/usbserial
localhost / #                                                                  

Or do you mean build.prop?

RE: USB networking: updates for wiki - Added by Paul Kocialkowski over 6 years ago

It seems like you don't have all the elements in hand to do this task. Do you want me to guide you through it or do you prefer to leave this up to someone else?

RE: USB networking: updates for wiki - Added by Dmitry Samoyloff over 6 years ago

Well, I'm a newbie in android yet, so your help would be very much appreciated :-)

RE: USB networking: updates for wiki - Added by Riku Saikkonen over 6 years ago

I was able to enable the rndis0 interface on my device from the command line with the command "setprop sys.usb.config rndis,adb" (I tried it using adb shell). You could disable it using "setprop sys.usb.config mtp,adb", although I guess the default value of that property would be different if you e.g. enabled ptp instead of mtp from the Settings menu, or disabled adb. (To work cleanly, I guess the script should add or delete "rndis," from the current value of the property instead of assigning a fixed value. Though I'm a beginner in Android/Replicant so I don't know if setting the property is the proper way to do this - but it seemed to work. I found that using a bit of googling and looking at what "getprop" prints out.)

I didn't have to touch /sys/class/android_usb/android0/enable at all: I guess it was already enabled because I had adb on already. (Or maybe this is device-dependent?)

However, one thing confused me for a while: When I modified the device-side script to include that setprop command, running it through adb shell did not work: the script appeared to stop just after the setprop command. I think the reason could be that changing the USB connection type resets the adb connection which then kills the shell and whatever it is doing. I guess there are three possible solutions: 1) just don't run it through adb but instead using the Terminal Emulator (using su to run it as root), 2) run the setprop command separately before running the script, or 3) perhaps you could use "nohup" but that seems to want to write to a nohup.out file which would be nice to avoid.

RE: USB networking: updates for wiki - Added by Dmitry Samoyloff over 6 years ago

setprop sys.usb.config rndis,adb

It works for me too, thanks!

RE: USB networking: updates for wiki - Added by Dmitry Samoyloff over 6 years ago

Here's my wrapper script over run_dev.sh and run_pc.sh to do everything at once. It starts adb server, enables rndis on device, pushes run_dev.sh, etc.

#!/bin/sh -e

SCRIPT_PATH=`dirname $0`

ADB_PATH=/home/dmitry/software/replicant-4.0-0005/sdk/replicant-sdk_linux-x86/platform-tools
ADB=$ADB_PATH/adb

usage() {
    echo "Usage: `basename $0` [start | stop]" 
    exit 1
}

rundev() {
    $ADB push $SCRIPT_PATH/run_dev.sh /data/
    $ADB shell "sh /data/run_dev.sh $ACTION" 
}

runpc() {
    sudo $SCRIPT_PATH/run_pc.sh $ACTION
}

[ $# = 1 ] || usage
[ $1 != start ] && [ $1 != stop ] && usage

ACTION=$1

sudo $ADB start-server

[ $ACTION = start ] && $ADB shell "setprop sys.usb.config rndis,adb" 
sleep 1

case $ACTION in
    start ) rundev; runpc ;;
    stop  ) runpc; rundev ;;
esac
    (1-11/11)