Wish List
#3
in order to have usb tethering, you need those two scripts:

pinephone-setup-usb-nework.sh:
Code:
#!/bin/sh

if [ ! -e /etc/NetworkManager/system-connections/USB.nmconnection ]; then
    # Create network connection
    nmcli connection add con-name USB \
                        ifname usb0 \
                        type ethernet \
                        ip4 10.66.0.1/8

    # Set priorities so it doesn't take precedence over WiFi/mobile connections
    nmcli connection modify USB ipv4.route-metric 1500
    nmcli connection modify USB ipv4.dns-priority 150

    # Share connection so it can be used for tethering
    nmcli connection modify USB ipv4.method shared
fi

and, pinephone-usb-gadget.sh:
Code:
#!/bin/sh

CONFIGFS=/sys/kernel/config/usb_gadget/g1
USB_VENDORID="0x1D6B"  # Linux Foundation
USB_PRODUCTID="0x0104" # Multifunction composite gadget
USB_MANUF="Mobian Project"
USB_PRODUCT="Mobian"
USB_SERIAL=`cat /etc/machine-id`

setup() {
    # Don't do anything if the USB gadget already exists
    #[ -d $CONFIGFS ] && exit 0

    # Required to make a composite gadget
    modprobe libcomposite

    # Create all required directories
    echo "Creating the USB gadget..."
    mkdir -p $CONFIGFS
    mkdir -p $CONFIGFS/strings/0x409
    mkdir -p $CONFIGFS/configs/c.1
    mkdir -p $CONFIGFS/configs/c.1/strings/0x409

    # Setup IDs and strings
    echo "Setting up gadget strings..."
    echo $USB_VENDORID > $CONFIGFS/idVendor
    echo $USB_PRODUCTID > $CONFIGFS/idProduct
    echo $USB_MANUF > $CONFIGFS/strings/0x409/manufacturer
    echo $USB_PRODUCT > $CONFIGFS/strings/0x409/product
    echo $USB_SERIAL > $CONFIGFS/strings/0x409/serialnumber

    # Create ECM (ethernet) function
    echo "Adding ECM function..."
    mkdir $CONFIGFS/functions/ecm.usb0

    # TODO: create RNDIS function for Windows compatibility

    # Create MTP using FunctionFS
    # echo "Adding MTP function using FunctionFS..."
    # mkdir $CONFIGFS/functions/ffs.mtp

    # Create configuration
    echo "Creating gadget configuration..."
    echo "Ethernet" > $CONFIGFS/configs/c.1/strings/0x409/configuration
    # echo "Ethernet + MTP" > $CONFIGFS/configs/c.1/strings/0x409/configuration
    ln -s $CONFIGFS/functions/ecm.usb0 $CONFIGFS/configs/c.1
    # ln -s $CONFIGFS/functions/ffs.mtp $CONFIGFS/configs/c.1

    # Mount the MTP FunctionFS
    # echo "Mounting FunctionFS..."
    # mkdir -p /dev/ffs-mtp
    # mount -t functionfs mtp /dev/ffs-mtp
}

start() {
    echo "Enabling the USB gadget..."
    sleep 1
    UDC=`ls /sys/class/udc`
    echo "$UDC" > $CONFIGFS/UDC
}

reset() {
    echo "Removing the USB gadget..."

    # Remove USB gadget
    if [ -d $CONFIGFS ]; then
        echo "Removing gadget configuration..."
        # rm $CONFIGFS/configs/c.1/ffs.mtp
        rm $CONFIGFS/configs/c.1/ecm.usb0
        rmdir $CONFIGFS/configs/c.1/strings/0x409/
        rmdir $CONFIGFS/configs/c.1/
        # rmdir $CONFIGFS/functions/ffs.mtp
        rmdir $CONFIGFS/functions/ecm.usb0
        rmdir $CONFIGFS/strings/0x409/
        rmdir $CONFIGFS
    fi

    # Unmount FunctionFS and delete its mount point
    # if [ -d /dev/ffs-mtp ]; then
    #    echo "Unmounting FunctionFS..."
    #    umount /dev/ffs-mtp
    #    rmdir /dev/ffs-mtp
    #fi
}


case "$1" in
    reset) reset ;;
    setup) setup ;;
    start) start ;;
    *) ;;
esac

then run:


Code:
sudo ./pinephone-setup-usb-nework.sh
sudo ./pinephone-usb-gadget.sh reset
sudo ./pinephone-usb-gadget.sh setup
sudo ./pinephone-usb-gadget.sh start
  Reply


Messages In This Thread
Wish List - by CitizenZeven - 11-10-2020, 06:05 AM
RE: Wish List - by ak42 - 11-12-2020, 05:46 PM
RE: Wish List - by user12345 - 04-14-2021, 08:57 AM
RE: Wish List - by ak42 - 11-13-2020, 04:20 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)