Add wwan networking

This commit is contained in:
Fabian Hauser 2019-12-23 21:29:42 +00:00
parent a9e5fa79a5
commit bf015614b6
4 changed files with 88 additions and 111 deletions

View file

@ -13,10 +13,6 @@ if [ "$MBIM_INTERFACE" == "" ]; then
MBIM_INTERFACE="/dev/cdc-wdm0"
fi
if [ "$MBIM_BINARY" == "" ]; then
MBIM_BINARY=mbimcli
fi
###############################################################################
# Global Variables
###############################################################################
@ -32,6 +28,10 @@ ipv6_gateway=""
ipv6_dns=()
ipv6_mtu=""
export previous_state state skip_line \
ipv4_addresses ipv4_gateway ipv4_dns ipv4_mtu \
ipv6_addresses ipv6_gateway ipv6_dns ipv6_mtu
###############################################################################
# Function
###############################################################################
@ -124,13 +124,13 @@ function parse_input_state_machine {
state="start"
while true; do
if [[ "$skip_line" == 0 ]]; then
read line
read line || break # TODO: Clean up
else
skip_line=0
fi
case "$state" in
"start")
read line # first line is empty, read a new one #TODO: This is not very clean...
read line || break # first line is empty, read a new one #TODO: This is not very clean...
case "$line" in
*"configuration available: 'none'"*)
# Skip none state
@ -267,17 +267,17 @@ function parse_input_state_machine {
}
interface_start(){
interface_stop(){
ip addr flush dev $DEV
ip route flush dev $DEV
ip -6 addr flush dev $DEV
ip -6 p route flush dev $DEV
ip -6 route flush dev $DEV
#TODO: Nameserver?
}
interface_stop() {
interface_start() {
ip link set $DEV up
if [[ "${#ipv4_addresses[@]}" > 0 ]]; then
@ -285,6 +285,8 @@ interface_stop() {
ip link set $DEV mtu $ipv4_mtu
ip route add default via $ipv4_gateway dev $DEV
#TODO: nameserver ${ipv4_dns[@]}
else
echo "No IPv4 address, skipping v4 configuration..."
fi
if [[ "${#ipv6_addresses[@]}" > 0 ]]; then
@ -292,6 +294,8 @@ interface_stop() {
ip -6 route add default via $ipv6_gateway dev $DEV
ip -6 link set $DEV mtu $ipv6_mtu
#TODO: nameserver ${ipv6_dns[@]}"
else
echo "No IPv6 address, skipping v6 configuration..."
fi
}
@ -299,21 +303,27 @@ interface_stop() {
# Execution
###############################################################################
set -x
set -e
echo "NOTE: This script does not yet support nameserver configuration."
parse_input_state_machine <(${MBIM_BINARY} -d ${MBIM_INTERFACE} -p --query-ip-configuration=0)
print_full_configuration
case "$MODE" in
"start")
interface_stop
mbim-network $MBIM_INTERFACE start
sleep 1
mbimcli -d $MBIM_INTERFACE -p --query-ip-configuration=0 | {
parse_input_state_machine
print_full_configuration
interface_stop
interface_start
}
;;
"stop")
interface_start
mbim-network $MBIM_INTERFACE stop
interface_stop
;;
*)
echo "USAGE: $0 start|stop INTERFACE" >&2
echo "You can set an env variable DEBUG to gather debugging output." >&2
exit 1
;;
esac
esac