]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/initscripts/networking/dhcpcd.exe
network: Add support for QMI modems
[ipfire-2.x.git] / src / initscripts / networking / dhcpcd.exe
index 8a409d0109c1c701c7d4bfe5ea70be9fe8a62395..be6d63708862a130475202765e37907eaefe2b4d 100644 (file)
@@ -20,6 +20,7 @@
 
 . /etc/sysconfig/rc
 . $rc_functions
+. /etc/init.d/networking/functions.network
 
 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
 
@@ -85,9 +86,70 @@ dhcpcd_down()
        fi
 }
 
+# Called when dhcpcd relies on a third party to configure an IP address
+dhcpcd_3rdparty() {
+       local qmi_device="$(qmi_find_device "${interface}")"
+
+       if [ -n "${qmi_device}" ]; then
+               setup_qmi "${qmi_device}" || return $?
+       fi
+
+       return 0
+}
+
+setup_qmi() {
+       local device="${1}"
+
+       local address
+       local netmask
+       local gateway
+       local mtu=1500
+
+       local line
+       while read -r line; do
+               # Extract the value
+               value="${line#*: }"
+
+               case "${line}" in
+                       *IPv4\ address:*)
+                               address="${value}"
+                               ;;
+                       *IPv4\ subnet\ mask:*)
+                               netmask="${value}"
+                               ;;
+                       *IPv4\ gateway\ address:*)
+                               gateway="${value}"
+                               ;;
+                       *MTU:*)
+                               mtu="${value}"
+                               ;;
+               esac
+       done <<< "$(qmicli --device="${device}" --wds-get-current-settings)"
+
+       if [ -z "${address}" ] || [ -z "${netmask}" ] || [ -z "${gateway}" ]; then
+               logger -p "local0.info" -t "dhcpcd.exe[$$]" \
+                       "Could not retrieve all information from the QMI interface"
+               return 1
+       fi
+
+       # Flush any previous configuration
+       ip addr flush dev "${interface}"
+
+       # Configure the IP address
+       ip addr add "${address}/${netmask}" dev "${interface}"
+
+       # Configure the default route
+       ip route add default via "${gateway}" #mtu "${mtu}"
+
+       return 0
+}
+
 case "$reason" in
 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)       dhcpcd_up;;
 PREINIT|EXPIRE|FAIL|IPV4LL|NAK|RELEASE|STOP)           dhcpcd_down;;
+3RDPARTY)
+       dhcpcd_3rdparty
+       ;;
 *)
        logger -p "local0.info" -t "dhcpcd.exe[$$]" "Unhandled DHCP event: ${reason}"
        ;;