public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] repo/proj/guru:master commit in: app-mobilephone/usb-tethering/files/, app-mobilephone/usb-tethering/
@ 2021-06-25 10:11 Andrew Ammerlaan
  0 siblings, 0 replies; only message in thread
From: Andrew Ammerlaan @ 2021-06-25 10:11 UTC (permalink / raw
  To: gentoo-commits

commit:     f723db403f7a32a302b62686d549633999a2e9b2
Author:     Marco Scardovi <marco <AT> scardovi <DOT> com>
AuthorDate: Thu Jun 24 12:16:46 2021 +0000
Commit:     Andrew Ammerlaan <andrewammerlaan <AT> gentoo <DOT> org>
CommitDate: Thu Jun 24 12:18:56 2021 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=f723db40

app-mobilephone/usb-tethering: add new package

this package enable the usb tethering for pinephone

Package-Manager: Portage-3.0.20, Repoman-3.0.3
Signed-off-by: Marco Scardovi <marco <AT> scardovi.com>

 app-mobilephone/usb-tethering/files/dhcpd.conf     |  5 ++
 .../files/dhcpd4.service-customexec.conf           |  9 +++
 .../files/tmpfiles.d.danctnix-usb.conf             |  2 +
 app-mobilephone/usb-tethering/files/usb-tethering  | 77 ++++++++++++++++++++++
 .../usb-tethering/files/usb-tethering.service      | 12 ++++
 app-mobilephone/usb-tethering/metadata.xml         |  8 +++
 .../usb-tethering/usb-tethering-0.1.ebuild         | 33 ++++++++++
 7 files changed, 146 insertions(+)

diff --git a/app-mobilephone/usb-tethering/files/dhcpd.conf b/app-mobilephone/usb-tethering/files/dhcpd.conf
new file mode 100644
index 000000000..d7600ea7e
--- /dev/null
+++ b/app-mobilephone/usb-tethering/files/dhcpd.conf
@@ -0,0 +1,5 @@
+option domain-name-servers 8.8.8.8, 8.8.4.4;
+option subnet-mask 255.255.255.0;
+subnet 10.15.19.0 netmask 255.255.255.0 {
+  range 10.15.19.100 10.15.19.254;
+}

diff --git a/app-mobilephone/usb-tethering/files/dhcpd4.service-customexec.conf b/app-mobilephone/usb-tethering/files/dhcpd4.service-customexec.conf
new file mode 100644
index 000000000..82e4c9d20
--- /dev/null
+++ b/app-mobilephone/usb-tethering/files/dhcpd4.service-customexec.conf
@@ -0,0 +1,9 @@
+[Service]
+PIDFile=/run/danctnix/dhcpd4.pid
+
+# We need to fix this ASAP, dhcpd won't run with dhcp user, this needs
+# to be investigated.
+User=root
+
+ExecStart=
+ExecStart=/usr/bin/dhcpd -4 -q -cf /etc/danctnix/dhcpd.conf -pf /run/danctnix/dhcpd4.pid -lf /run/danctnix/dhcpd4.lease

diff --git a/app-mobilephone/usb-tethering/files/tmpfiles.d.danctnix-usb.conf b/app-mobilephone/usb-tethering/files/tmpfiles.d.danctnix-usb.conf
new file mode 100644
index 000000000..960f43802
--- /dev/null
+++ b/app-mobilephone/usb-tethering/files/tmpfiles.d.danctnix-usb.conf
@@ -0,0 +1,2 @@
+d /run/danctnix 0755 root root
+f /run/danctnix/dhcpd4.lease 0644 root root

diff --git a/app-mobilephone/usb-tethering/files/usb-tethering b/app-mobilephone/usb-tethering/files/usb-tethering
new file mode 100644
index 000000000..aaa63eb55
--- /dev/null
+++ b/app-mobilephone/usb-tethering/files/usb-tethering
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+# ConfigFS script is taken from postmarketOS
+# https://postmarketos.org
+
+# These are very important, it defines what is the device:
+
+deviceinfo_usb_idVendor="0x1F3A"
+deviceinfo_usb_idProduct="0xEFE8"
+deviceinfo_manufacturer="DanctNIX"
+deviceinfo_name="Arch Linux Mobile"
+
+# We'll let them know that this device is Arch ARM.
+deviceinfo_usb_serialnumber="Arch"
+
+setup_usb_network_configfs() {
+	# See: https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
+	CONFIGFS=/sys/kernel/config/usb_gadget/
+
+	if ! [ -e "$CONFIGFS" ]; then
+		echo "  $CONFIGFS does not exist, skipping configfs usb gadget"
+		return
+	fi
+
+	# Default values for USB-related deviceinfo variables
+	usb_idVendor="${deviceinfo_usb_idVendor:-0x18D1}"   # default: Google Inc.
+	usb_idProduct="${deviceinfo_usb_idProduct:-0xD001}" # default: Nexus 4 (fastboot)
+	usb_serialnumber="${deviceinfo_usb_serialnumber:-postmarketOS}"
+	usb_rndis_function="${deviceinfo_usb_rndis_function:-rndis.usb0}"
+
+	echo "  Setting up an USB gadget through configfs"
+	# Create an usb gadet configuration
+	mkdir $CONFIGFS/g1 || echo "  Couldn't create $CONFIGFS/g1"
+	echo "$usb_idVendor"  > "$CONFIGFS/g1/idVendor"
+	echo "$usb_idProduct" > "$CONFIGFS/g1/idProduct"
+
+	# Create english (0x409) strings
+	mkdir $CONFIGFS/g1/strings/0x409 || echo "  Couldn't create $CONFIGFS/g1/strings/0x409"
+
+	# shellcheck disable=SC2154
+	echo "$deviceinfo_manufacturer" > "$CONFIGFS/g1/strings/0x409/manufacturer"
+	echo "$usb_serialnumber"        > "$CONFIGFS/g1/strings/0x409/serialnumber"
+	# shellcheck disable=SC2154
+	echo "$deviceinfo_name"         > "$CONFIGFS/g1/strings/0x409/product"
+
+	# Create rndis function. The function can be named differently in downstream kernels.
+	mkdir $CONFIGFS/g1/functions/"$usb_rndis_function" \
+		|| echo "  Couldn't create $CONFIGFS/g1/functions/$usb_rndis_function"
+
+	# Create configuration instance for the gadget
+	mkdir $CONFIGFS/g1/configs/c.1 \
+		|| echo "  Couldn't create $CONFIGFS/g1/configs/c.1"
+	mkdir $CONFIGFS/g1/configs/c.1/strings/0x409 \
+		|| echo "  Couldn't create $CONFIGFS/g1/configs/c.1/strings/0x409"
+	echo "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration \
+		|| echo "  Couldn't write configration name"
+
+	# Link the rndis instance to the configuration
+	ln -s $CONFIGFS/g1/functions/"$usb_rndis_function" $CONFIGFS/g1/configs/c.1 \
+		|| echo "  Couldn't symlink $usb_rndis_function"
+
+	# Check if there's an USB Device Controller
+	if [ -z "$(ls /sys/class/udc)" ]; then
+		echo "  No USB Device Controller available"
+		return
+	fi
+
+	# Link the gadget instance to an USB Device Controller. This activates the gadget.
+	# See also: https://github.com/postmarketOS/pmbootstrap/issues/338
+	# shellcheck disable=SC2005
+	echo "$(ls /sys/class/udc)" > $CONFIGFS/g1/UDC || echo "  Couldn't write UDC"
+}
+
+# And we go.
+setup_usb_network_configfs
+ip address add 10.15.19.82/24 dev usb0
+ip link set usb0 up

diff --git a/app-mobilephone/usb-tethering/files/usb-tethering.service b/app-mobilephone/usb-tethering/files/usb-tethering.service
new file mode 100644
index 000000000..25620f7da
--- /dev/null
+++ b/app-mobilephone/usb-tethering/files/usb-tethering.service
@@ -0,0 +1,12 @@
+# systemd service file for usb-tethering
+
+[Unit]
+Wants=dhcpd4.service
+Description=USB Tethering
+
+[Service]
+Type=oneshot
+ExecStart=/bin/bash /usr/lib/danctnix/usb-tethering
+
+[Install]
+WantedBy=multi-user.target

diff --git a/app-mobilephone/usb-tethering/metadata.xml b/app-mobilephone/usb-tethering/metadata.xml
new file mode 100644
index 000000000..144c8091c
--- /dev/null
+++ b/app-mobilephone/usb-tethering/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+	<maintainer type="person">
+		<email>marco@scardovi.com</email>
+		<name>Marco Scardovi</name>
+	</maintainer>
+</pkgmetadata>

diff --git a/app-mobilephone/usb-tethering/usb-tethering-0.1.ebuild b/app-mobilephone/usb-tethering/usb-tethering-0.1.ebuild
new file mode 100644
index 000000000..7ef20b167
--- /dev/null
+++ b/app-mobilephone/usb-tethering/usb-tethering-0.1.ebuild
@@ -0,0 +1,33 @@
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit systemd
+
+DESCRIPTION="USB tethering on Pine64/ConfigFS systems"
+HOMEPAGE="https://github.com/dreemurrs-embedded/Pine64-Arch"
+
+LICENSE="GPL-2+"
+SLOT="0"
+KEYWORDS="~arm64"
+
+DEPEND="
+	net-misc/dhcp
+	sys-apps/systemd
+"
+RDEPEND="${DEPEND}"
+
+S="${WORKDIR}"
+
+src_install() {
+	exeinto "/usr/lib/danctnix"
+	doexe "${FILESDIR}/usb-tethering"
+	systemd_dounit "${FILESDIR}"/usb-tethering.service
+	insinto "/usr/lib/tmpfiles.d/"
+	doins "${FILESDIR}"/tmpfiles.d.danctnix-usb.conf
+	insinto "/etc/systemd/system/dhcpd4.service.d/"
+	doins "${FILESDIR}"/dhcpd4.service-customexec.conf
+	insinto "/etc/danctnix/"
+	doins "${FILESDIR}"/dhcpd.conf
+}


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-25 10:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-25 10:11 [gentoo-commits] repo/proj/guru:master commit in: app-mobilephone/usb-tethering/files/, app-mobilephone/usb-tethering/ Andrew Ammerlaan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox