UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    USB tethering not working

    Scheduled Pinned Locked Moved Oneplus 6/6T
    2 Posts 2 Posters 937 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • R Offline
        Reynald
        last edited by

        I tried to use USB tethering on my OP6: not working at all (interface stays in MTP mode).

        I found that RNDIS mode was just not implemented in /usr/share/usbinit/setupusb... snif...

        So I modified (with success) /usr/share/usbinit/setupusb:

        #!/bin/sh
        CONFIG_FS=/sys/kernel/config
        CONFIG_DIR=$CONFIG_FS/usb_gadget/
        GADGET_DIR=$CONFIG_DIR/g1
        CONFIG_NAME="c.1"
        
        SERIALNUMBER=`getprop ro.serialno`             # e.g. "0123456789ABCDEF"
        MANUFACTURER=`getprop ro.product.vendor.manufacturer` # e.g. "Volla"
        PRODUCT=`getprop ro.product.vendor.model`             # e.g. "Phone"
        CONTROLLER=`getprop sys.usb.controller`        # e.g. "musb-hdrc"
        
        write() {
        	test -w "$1" || return
        	printf "$2" > "$1"
        }
        
        symlink() {
        	ln -s "$1" "$2"
        }
        
        reset_usb() {
        	rm -f $GADGET_DIR/configs/$CONFIG_NAME/mtp.gs0
        	rm -f $GADGET_DIR/configs/$CONFIG_NAME/ffs.adb
        	rm -f $GADGET_DIR/configs/$CONFIG_NAME/rndis.usb0
        }
        
        setup_rndis() {
        	reset_usb
        	write $GADGET_DIR/configs/$CONFIG_NAME/strings/0x409/configuration "rndis"
        	symlink $GADGET_DIR/functions/rndis.usb0 $GADGET_DIR/configs/$CONFIG_NAME/
        	write $GADGET_DIR/UDC $CONTROLLER
        	setprop sys.usb.state rndis
        }
        
        setup_mtp() {
        	reset_usb
        	write $GADGET_DIR/functions/mtp.gs0/os_desc/interface.MTP/compatible_id "mtp"
        	write $GADGET_DIR/configs/$CONFIG_NAME/strings/0x409/configuration "mtp"
        	symlink $GADGET_DIR/functions/mtp.gs0 $GADGET_DIR/configs/$CONFIG_NAME/
        	write $GADGET_DIR/UDC $CONTROLLER
        	setprop sys.usb.state mtp
        }
        
        setup_mtp_adb() {
        	reset_usb
        	write $GADGET_DIR/functions/mtp.gs0/os_desc/interface.MTP/compatible_id "mtp_adb"
        	write $GADGET_DIR/configs/$CONFIG_NAME/strings/0x409/configuration "mtp_adb"
        	symlink $GADGET_DIR/functions/mtp.gs0 $GADGET_DIR/configs/$CONFIG_NAME/
        	symlink $GADGET_DIR/functions/ffs.adb $GADGET_DIR/configs/$CONFIG_NAME/
        	start android-tools-adbd
        	sleep 2
        	write $GADGET_DIR/UDC $CONTROLLER
        	setprop sys.usb.state mtp,adb
        }
        
        setup_boot() {
        	if [ -e $GADGET_DIR/functions/mtp.gs0 ]; then
        		echo "Boot setup done"
        		return
        	fi
        
        	if ! mount | grep -q "$CONFIG_FS"; then
        		mount -t configfs none $CONFIG_FS
        		mkdir -p $GADGET_DIR/strings/0x409
        		mkdir -p $GADGET_DIR/functions/rndis.usb0
        		mkdir -p $GADGET_DIR/configs/$CONFIG_NAME/strings/0x409
        	fi
        
        	write $GADGET_DIR/idVendor 0x18D1
        	write $GADGET_DIR/bcdDevice 0x0223
        	write $GADGET_DIR/bcdUSB 0x0200
        	write $GADGET_DIR/os_desc/use 1
        	write $GADGET_DIR/os_desc/b_vendor_code 0x1
        	write $GADGET_DIR/os_desc/qw_sign "MSFT100"
        	write $GADGET_DIR/strings/0x409/serialnumber $SERIALNUMBER
        	write $GADGET_DIR/strings/0x409/manufacturer $MANUFACTURER
        	write $GADGET_DIR/strings/0x409/product $PRODUCT
        	mkdir -p $GADGET_DIR/functions/mtp.gs0
        	mkdir -p $GADGET_DIR/functions/ffs.adb
        	symlink $GADGET_DIR/configs/$CONFIG_NAME $GADGET_DIR/os_desc/$CONFIG_NAME
        
        	mkdir -p /dev/usb-ffs/adb
        	mount -t functionfs -o uid=32011,gid=32011 adb /dev/usb-ffs/adb
        	chown root:plugdev /dev/usb-ffs
        	chmod 775 /dev/usb-ffs
        	chown root:plugdev /dev/usb-ffs/adb
        	chmod 775 /dev/usb-ffs/adb
        
        	chown root:plugdev /dev/mtp_usb
        	chmod 660 /dev/mtp_usb
        }
        
        setup_boot
        
        if [ "$1" = "rndis" ]; then
        	setup_rndis
        elif [ "$1" = "mtp" ]; then
        	setup_mtp
        elif [ "$1" = "mtp_adb" ]; then
        	setup_mtp_adb
        else
        	echo "No configuration selected."
        fi
        
        exit 0
        

        and /usr/bin/tethering :

        #! /bin/sh
        
        NMCONF=/etc/NetworkManager/system-connections/tethering
        
        init_interface(){
        bash /usr/share/usbinit/setupusb reset
        bash /usr/share/usbinit/setupusb rndis
        ifconfig rndis0 up
        }
        
        enable(){
            MAC="$(ip -o link show rndis0 |sed -e 's/^.*ether //'|cut -d' ' -f1)"
            UUID=ca16a21d-7d8b-4b49-926e-"$(echo $MAC|sed -e 's/://g')"
            STAMP=$(date +%s)
        
            if [ ! -e $NMCONF ];then
                cat << EOF >$NMCONF
        [802-3-ethernet]
        duplex=full
        mac-address=$MAC
        
        [connection]
        id=tethering
        uuid=$UUID
        type=802-3-ethernet
        timestamp=$STAMP
        
        [ipv6]
        method=auto
        
        [ipv4]
        method=shared
        may-fail=false
        EOF
            else
                sed -i s/^mac-address=.*/mac-address=${MAC}/ $NMCONF
                sed -i s/^uuid=.*/uuid=${UUID}/ $NMCONF
                sed -i s/^timestamp=.*/timestamp=${STAMP}/ $NMCONF
            fi
        
            chmod 0600 $NMCONF
            sleep 2
            nmcli c reload
            nmcli c up id tethering
        }
        
        disable(){
            nmcli c down id tethering || true
            rm $NMCONF || true
            initctl start mtp-state
        }
        
        case $1 in
            enable)
                init_interface
                enable
                ;;
            disable)
                disable
                ;;
            *)
                echo "need an argument (enable|disable)"
                exit 0
                ;;
        esac
        

        RNDIS is now fully usable with /usr/bin/tethering enable/disable and with UT Tweak Tool.
        Enjoy!

        1 Reply Last reply Reply Quote 0
        • SevralTS Offline
          SevralT
          last edited by

          Ubuntu Touch hasn't USB Tethering. Yes, there is RNDIS option in UT Tweak Tool but it used for USB debugging when ADB was unavailable.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post