Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix openwrt /lib/netifd/proto/qmi.sh to allow direct address configuration of qmi interfaces
diff --git a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
index 8cbe9e97e7..4aadd57813 100755
--- a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
+++ b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
@@ -19,6 +19,7 @@ proto_qmi_init_config() {
proto_config_add_string modes
proto_config_add_string pdptype
proto_config_add_int profile
+ proto_config_add_boolean dhcp
proto_config_add_boolean dhcpv6
proto_config_add_boolean autoconnect
proto_config_add_int plmn
@@ -31,13 +32,14 @@ proto_qmi_setup() {
local interface="$1"
local dataformat connstat
local device apn auth username password pincode delay modes pdptype
- local profile dhcpv6 autoconnect plmn timeout mtu $PROTO_DEFAULT_OPTIONS
- local ip4table ip6table
+ local profile dhcp dhcpv6 autoconnect plmn timeout mtu
+ local $PROTO_DEFAULT_OPTIONS ip4table ip6table
local cid_4 pdh_4 cid_6 pdh_6
+ local ip subnet gateway dns1 dns2
local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
json_get_vars device apn auth username password pincode delay modes
- json_get_vars pdptype profile dhcpv6 autoconnect plmn ip4table
+ json_get_vars pdptype profile dhcp dhcpv6 autoconnect plmn ip4table
json_get_vars ip6table timeout mtu $PROTO_DEFAULT_OPTIONS
[ "$timeout" = "" ] && timeout="10"
@@ -353,15 +355,36 @@ proto_qmi_setup() {
}
[ -n "$pdh_4" ] && {
- json_init
- json_add_string name "${interface}_4"
- json_add_string ifname "@$interface"
- json_add_string proto "dhcp"
- [ -n "$ip4table" ] && json_add_string ip4table "$ip4table"
- proto_add_dynamic_defaults
- [ -n "$zone" ] && json_add_string zone "$zone"
- json_close_object
- ubus call network add_dynamic "$(json_dump)"
+ if [ "$dhcp" = 0 ]; then
+ json_load "$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)"
+ json_select ipv4
+ json_get_vars ip subnet gateway dns1 dns2
+
+ proto_init_update "$ifname" 1
+ proto_set_keep 1
+ proto_add_ipv4_address "$ip" "$subnet"
+ [ "$defaultroute" = 0 ] || proto_add_ipv4_route "0.0.0.0" 0 "$gateway"
+ [ "$peerdns" = 0 ] || {
+ proto_add_dns_server "$dns1"
+ proto_add_dns_server "$dns2"
+ }
+ [ -n "$zone" ] && {
+ proto_add_data
+ json_add_string zone "$zone"
+ proto_close_data
+ }
+ proto_send_update "$interface"
+ else
+ json_init
+ json_add_string name "${interface}_4"
+ json_add_string ifname "@$interface"
+ json_add_string proto "dhcp"
+ [ -n "$ip4table" ] && json_add_string ip4table "$ip4table"
+ proto_add_dynamic_defaults
+ [ -n "$zone" ] && json_add_string zone "$zone"
+ json_close_object
+ ubus call network add_dynamic "$(json_dump)"
+ fi
}
}
@ashishkamble
Copy link

ashishkamble commented Aug 31, 2021

These changes are working?

@arachsys
Copy link
Author

arachsys commented Aug 31, 2021

These changes are working?

Yes, they're what I use on my own 4G router for the farm. They're a diff against an OpenWRT snapshot from Dec 2019 though, so there may be upstream updates that conflict by now. At some point I should build a new version and update…

The diff would be easy to recreate if it's outdated/broken against newer versions. The two arms of the if [ "$dhcp" = 0 ] are (respectively) the non-dhcpv6 version of the pdh_6 setup ported to ipv4, and the existing dhcp4 code.

@ashishkamble
Copy link

ashishkamble commented Aug 31, 2021

This line json_load "$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)" return below json output

{
"pdp-type": "ipv4-or-ipv6",
"ip-family": "ipv4",
"mtu": 263644,
"ipv4": {
"ip": "0.84.112.109",
"dns1": "0.4.21.46",
"dns2": "0.4.160.7",
"gateway": "100.84.112.110",
"subnet": "0.4.33.252"
},
"ipv6": {

},
"domain-names": {
	
}

}

The ip addresses are incorrect and the interface is not able to ping outer network.

@arachsys
Copy link
Author

arachsys commented Aug 31, 2021

Interesting, for my Quectel EP06-E card, uqmi --get-current-settings does give the correct network config, which is why I'm able to use it.

# uqmi -d /dev/cdc-wdm0  --get-current-settings
{
	"pdp-type": "ipv4",
	"ip-family": "ipv4",
	"mtu": 1500,
	"ipv4": {
		"ip": "10.25.110.223",
		"dns1": "10.206.128.1",
		"dns2": "10.206.128.1",
		"gateway": "10.25.110.224",
		"subnet": "255.255.255.192"
	},
	"ipv6": {
		
	},
	"domain-names": {
		
	}
}

If you get nonsense values back from uqmi --get-current-settings, you're right that you won't be able to use it to avoid the need for a dhcp client.

@ashishkamble
Copy link

ashishkamble commented Aug 31, 2021

Even this page is saying that it should get correct ip address.
http://trac.gateworks.com/wiki/wireless/modem

On my device with callbox sim card i am able to fetch proper ip addresses.
uqmi -d /dev/cdc-wdm0 --get-current-settings
{
"pdp-type": "ipv4",
"ip-family": "ipv4",
"mtu": 1500,
"ipv4": {
"ip": "192.168.2.6",
"dns1": "8.8.8.8",
"gateway": "192.168.2.5",
"subnet": "255.255.255.252"
},
"ipv6": {

},
"domain-names": {
	
}

}
But with live operator sim card its weird output. I think its class A ip network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment