bsbf-autoconf-cellular: add
authorChester A. Unal <redacted>
Tue, 3 Mar 2026 10:19:17 +0000 (12:19 +0200)
committerChester A. Unal <redacted>
Wed, 4 Mar 2026 10:41:29 +0000 (12:41 +0200)
bsbf-autoconf-cellular creates a network with MBIM or QMI protocol using a
newly created network interface. It uses metric values from 1 to 8.

Signed-off-by: Chester A. Unal <redacted>
net/bsbf-openwrt-resources/Makefile
net/bsbf-openwrt-resources/files/etc/hotplug.d/net/99-bsbf-autoconf-cellular [new file with mode: 0644]

index b36331717a15555930a32bef485f8068ac2f615d..a9f8e7df9f0a38af2947c14cf0be664da2ffe821 100644 (file)
@@ -11,6 +11,17 @@ PKG_MAINTAINER:=Chester A. Unal <chester.a.unal@arinc9.com>
 
 include $(INCLUDE_DIR)/package.mk
 
+define Package/bsbf-autoconf-cellular
+  SECTION:=net
+  CATEGORY:=Network
+  TITLE:=bsbf-autoconf-cellular
+endef
+
+define Package/bsbf-autoconf-cellular/description
+  bsbf-autoconf-cellular creates a network with MBIM or QMI protocol using a
+  newly created network interface. It uses metric values from 1 to 8.
+endef
+
 define Package/bsbf-autoconf-dhcp
   SECTION:=net
   CATEGORY:=Network
@@ -37,6 +48,11 @@ endef
 define Build/Compile
 endef
 
+define Package/bsbf-autoconf-cellular/install
+       $(INSTALL_DIR) $(1)/etc/hotplug.d/net
+       $(INSTALL_BIN) ./files/etc/hotplug.d/net/99-bsbf-autoconf-cellular $(1)/etc/hotplug.d/net
+endef
+
 define Package/bsbf-autoconf-dhcp/install
        $(INSTALL_DIR) $(1)/etc/hotplug.d/net
        $(INSTALL_BIN) ./files/etc/hotplug.d/net/99-bsbf-autoconf-dhcp $(1)/etc/hotplug.d/net
@@ -50,5 +66,6 @@ define Package/bsbf-bonding/install
        $(INSTALL_BIN) ./files/etc/uci-defaults/99-bsbf-bonding $(1)/etc/uci-defaults
 endef
 
+$(eval $(call BuildPackage,bsbf-autoconf-cellular))
 $(eval $(call BuildPackage,bsbf-autoconf-dhcp))
 $(eval $(call BuildPackage,bsbf-bonding))
diff --git a/net/bsbf-openwrt-resources/files/etc/hotplug.d/net/99-bsbf-autoconf-cellular b/net/bsbf-openwrt-resources/files/etc/hotplug.d/net/99-bsbf-autoconf-cellular
new file mode 100644 (file)
index 0000000..76f9b61
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/sh
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# Copyright (C) 2026 Chester A. Unal <chester.a.unal@arinc9.com>
+
+# Only run if an MBIM or QMI network interface is being added.
+[ "$ACTION" = "add" ] && cur_proto=$(grep -oE "(mbim|qmi)" /sys"${DEVPATH%/*/*}/uevent") || exit
+
+# Find the device path.
+if echo "$DEVPATH" | grep -q usb; then
+       devpath=/sys"${DEVPATH%/*/*/*}"
+elif echo "$DEVPATH" | grep -q mhi; then
+       devpath=/sys"${DEVPATH%/*/*/*/*/*}"
+else
+       devpath=/sys"${DEVPATH%/*/*/*/*}"
+fi
+
+# If a network with the device path already exists, set control model to the
+# current detected one and exit.
+uci_network=$(uci show network)
+section=$(echo "$uci_network" | grep ".devpath='$devpath'" | cut -d. -f2)
+if [ -n "$section" ]; then
+       uci set network.$section.proto="$cur_proto"
+       uci commit network
+       ifup $section
+       exit
+fi
+
+# Decide on the metric value. Start from 1 and work up to 8.
+metric=1
+while [ $metric -le 8 ]; do
+       # Break if this metric isn't in use.
+       echo "$uci_network" | grep -q ".metric='$metric'" || break
+
+       # Add 1 to metric if another network uses this metric.
+       metric=$((metric + 1))
+done
+# If there are no available metrics, exit with code 1.
+[ "$metric" -gt 8 ] && exit 1
+
+# Decide on the network name. Start from wwan1.
+index=1
+while echo "$uci_network" | grep -q "wwan$index"; do
+       index=$((index + 1))
+done
+
+uci set network.wwan$index=interface
+uci set network.wwan$index.devpath="$devpath"
+uci set network.wwan$index.proto="$cur_proto"
+uci set network.wwan$index.apn='internet'
+uci set network.wwan$index.peerdns='0'
+uci set network.wwan$index.metric="$metric"
+uci commit network
+ifup wwan$index
git clone https://git.99rst.org/PROJECT