network: Add support for QMI modems

QMI is a proprietary interface from Qualcomm which are absolute pioneers
when it comes to interfacing with modems. I don't think there would be
any way to make this any more complicated and bloated.

So, bascially we will put the modem into a raw IP mode which changes the
interface into Point-to-Point mode.

We then configure the provider settings using qmicli. After that, the
modem will try to connect to the provider and obtain an IP address.

We will then start a DHCP client which does not do any DHCP-ing because
implementing that would be too complicated. Instead we do something even
*more* complicated where we would launch a custom script which asks the
modem for the allocated IP address and will configure it into the
device. The DHCP client then reads that IP address from the device and
pretends it came up with it by itself. Such an easy way to do this.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2022-12-01 17:22:55 +00:00
committed by Peter Müller
parent c6551e73c2
commit 957863f754
3 changed files with 188 additions and 0 deletions

View File

@@ -169,3 +169,93 @@ dhcpcd_stop() {
echo_failure
fi
}
# QMI stuff
qmi_find_device() {
local intf="${1}"
local _intf
local path
for path in /dev/cdc-*; do
if [ -c "${path}" ]; then
_intf="$(qmicli --device="${path}" --device-open-proxy --get-wwan-iface)"
# Check if the interface matches
if [ "${intf}" = "${_intf}" ]; then
echo "${path}"
return 0
fi
fi
done
# Nothing found
return 1
}
qmi_enable_rawip_mode() {
local intf="${1}"
# Shut down the device first
ip link set "${intf}" down &>/dev/null
echo "Y" > "/sys/class/net/${intf}/qmi/raw_ip"
}
qmi_configure_apn() {
local device="${1}"
# APN settings
local apn="${2}"
local auth="${3}"
local username="${4}"
local password="${5}"
local args=(
# We only support IPv4 right now
"ip-type=4"
)
# Set APN
if [ -n "${apn}" ]; then
args+=( "apn=${apn}" )
fi
# Set auth
case "${auth}" in
PAP|CHAP)
args+=( "auth=${auth}" )
;;
esac
# Set username
if [ -n "${username}" ]; then
args+=( "username=${username}" )
fi
# Set password
if [ -n "${password}" ]; then
args+=( "password=${password}" )
fi
local _args
local arg
for arg in ${args[@]}; do
if [ -n "${_args}" ]; then
_args="${_args},"
fi
_args="${_args}${arg}"
done
qmicli --device="${device}" --device-open-proxy \
--wds-start-network="${_args}" \
--client-no-release-cid
}
qmi_reset() {
local device="${1}"
qmicli --device="${device}" --device-open-proxy \
--wds-reset
}