Преглед изворни кода

uqmi: 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/wwanXqmiX/device

An example uci configuration would be:

config interface 'wwan_usb1'
	option proto 'qmi'
	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 'qmi'
	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 <[email protected]>
Chester A. Unal пре 2 месеци
родитељ
комит
e83da3bada
1 измењених фајлова са 40 додато и 4 уклоњено
  1. 40 4
      package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh

+ 40 - 4
package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh

@@ -21,6 +21,7 @@ proto_qmi_init_config() {
 	proto_config_add_string pdptype
 	proto_config_add_int profile
 	proto_config_add_int v6profile
+	proto_config_add_string devpath
 	proto_config_add_boolean dhcp
 	proto_config_add_boolean dhcpv6
 	proto_config_add_boolean sourcefilter
@@ -46,8 +47,8 @@ proto_qmi_setup() {
 	local apn auth delay device modes password pdptype pincode username v6apn
 	json_get_vars apn auth delay device modes password pdptype pincode username v6apn
 
-	local profile v6profile dhcp dhcpv6 autoconnect plmn timeout
-	json_get_vars profile v6profile dhcp dhcpv6 autoconnect plmn timeout
+	local profile v6profile devpath dhcp dhcpv6 autoconnect plmn timeout
+	json_get_vars profile v6profile devpath dhcp dhcpv6 autoconnect plmn timeout
 
 	[ "$timeout" = "" ] && timeout="10"
 
@@ -55,6 +56,30 @@ proto_qmi_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/wwan0qmi0
+		# /sys/devices/platform/soc/11280000.pcie/pci0003:00/0003:00:00.0/0003:01:00.0/mhi0/wwan/wwan0/wwan0qmi0
+		for usbmisc_or_wwan_path in \
+		    "$devpath"/usbmisc/cdc-wdm* \
+		    "$devpath"/*/usbmisc/cdc-wdm* \
+		    "$devpath"/*/wwan[0-9]*/wwan[0-9]*qmi* \
+		    "$devpath"/*/*/wwan[0-9]*/wwan[0-9]*qmi*; do
+			[ ! -e "$usbmisc_or_wwan_path" ] && continue
+			device="/dev/${usbmisc_or_wwan_path##*/}"
+			break
+		done
+	fi
+
 	[ -n "$device" ] || {
 		echo "No control device specified"
 		proto_notify_error "$interface" NO_DEVICE
@@ -519,11 +544,22 @@ qmi_wds_stop() {
 proto_qmi_teardown() {
 	local interface="$1"
 
-	local device cid_4 pdh_4 cid_6 pdh_6
-	json_get_vars device
+	local device devpath cid_4 pdh_4 cid_6 pdh_6
+	json_get_vars device devpath
 
 	[ -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]*qmi* \
+		    "$devpath"/*/*/wwan[0-9]*/wwan[0-9]*qmi*; do
+			device="/dev/${usbmisc_or_wwan_path##*/}"
+		done
+	fi
+
 	echo "Stopping network $interface"
 
 	json_load "$(ubus call network.interface.$interface status)"