umbim: introduce devpath option

Introduce the devpath option to find the control channel device from a
hardware path for a USB or a WWAN device.

This option is useful when there are multiple modems connected to the
system. The name of the control channel device of a modem can change
depending on which modem initialises first or if it was recently plugged
in. The devpath option allows specifying the hardware path of the modem
where the control channel device will be found using that.

For the USB device hardware path, it is allowed to specify the USB port
number the modem is directly connected to.

If the device and devpath options are both set, devpath takes precedence
over device.

The USB device hardware path of a control channel device can be found by:

readlink -f /sys/class/usbmisc/cdc-wdmX/device

The WWAN device hardware path of a control channel device can be found by:

readlink -f /sys/class/wwan/wwanXmbimX/device

An example uci configuration would be:

config interface 'wwan_usb1'
	option proto 'mbim'
	option auth 'none'
	option devpath '/sys/devices/platform/1e1c0000.xhci/usb1/1-1'
	option apn 'internet'
	option pdptype 'ipv4v6'

Or:

config interface 'wwan_pcie1'
	option proto 'mbim'
	option auth 'none'
	option devpath '/sys/devices/platform/soc/11280000.pcie/pci0003:00/0003:00:00.0/0003:01:00.0'
	option apn 'internet'
	option pdptype 'ipv4v6'

Signed-off-by: Chester A. Unal <chester.a.unal@arinc9.com>
This commit is contained in:
Chester A. Unal 2025-03-05 06:04:58 +00:00
parent c4e285049e
commit 764c503a2c

View file

@ -20,6 +20,7 @@ proto_mbim_init_config() {
proto_config_add_string username
proto_config_add_string password
[ -e /proc/sys/net/ipv6 ] && proto_config_add_string ipv6
proto_config_add_string devpath
proto_config_add_string dhcp
proto_config_add_string dhcpv6
proto_config_add_boolean sourcefilter
@ -46,8 +47,8 @@ _proto_mbim_setup() {
local tid=2
local ret
local allow_partner allow_roaming apn auth delay device password pincode username
json_get_vars allow_partner allow_roaming apn auth delay device password pincode username
local allow_partner allow_roaming apn auth delay device devpath password pincode username
json_get_vars allow_partner allow_roaming apn auth delay device devpath password pincode username
local dhcp dhcpv6 pdptype
json_get_vars dhcp dhcpv6 pdptype
@ -59,6 +60,30 @@ _proto_mbim_setup() {
[ -n "$ctl_device" ] && device=$ctl_device
if [ -n "$devpath" ]; then
local usbmisc_or_wwan_path
# For usbmisc:
# /sys/devices/platform/1e1c0000.xhci/usb1/1-2/1-2:1.4/usbmisc/cdc-wdm0
# Numbers after ":" are the configuration and interface number
# of the connected modem. There can be multiple interfaces but
# there will only be a single interface that provides the
# control channel device. Therefore, check also /*/usbmisc to
# allow specifying the USB port number the modem is directly
# connected to.
# For wwan:
# /sys/devices/platform/soc/11280000.pcie/pci0003:00/0003:00:00.0/0003:01:00.0/wwan/wwan0/wwan0mbim0
# /sys/devices/platform/soc/11280000.pcie/pci0003:00/0003:00:00.0/0003:01:00.0/mhi0/wwan/wwan0/wwan0mbim0
for usbmisc_or_wwan_path in \
"$devpath"/usbmisc/cdc-wdm* \
"$devpath"/*/usbmisc/cdc-wdm* \
"$devpath"/*/wwan[0-9]*/wwan[0-9]*mbim* \
"$devpath"/*/*/wwan[0-9]*/wwan[0-9]*mbim*; do
[ ! -e "$usbmisc_or_wwan_path" ] && continue
device="/dev/${usbmisc_or_wwan_path##*/}"
break
done
fi
[ -n "$device" ] || {
echo "mbim[$$]" "No control device specified"
proto_notify_error "$interface" NO_DEVICE
@ -321,12 +346,23 @@ proto_mbim_setup() {
proto_mbim_teardown() {
local interface="$1"
local device
json_get_vars device
local device devpath
json_get_vars device devpath
local tid=$(uci_get_state network $interface tid)
[ -n "$ctl_device" ] && device=$ctl_device
if [ -n "$devpath" ]; then
local usbmisc_or_wwan_path
for usbmisc_or_wwan_path in \
"$devpath"/usbmisc/cdc-wdm* \
"$devpath"/*/usbmisc/cdc-wdm* \
"$devpath"/*/wwan[0-9]*/wwan[0-9]*mbim* \
"$devpath"/*/*/wwan[0-9]*/wwan[0-9]*mbim*; do
device="/dev/${usbmisc_or_wwan_path##*/}"
done
fi
echo "mbim[$$]" "Stopping network"
[ -n "$tid" ] && {
umbim $DBG -t $tid -d "$device" disconnect