Created
December 29, 2022 14:54
mbimcli restart script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# | |
#Disable wwan | |
#echo 1-1 | sudo tee /sys/bus/usb/drivers/usb/unbind | |
uhubctl -l 1-1 -a 0 | |
rmmod cdc_mbim | |
rmmod cdc_wdm | |
rmmod cdc_ncm | |
rmmod cdc_ether | |
sleep 3 | |
#enable wwan | |
uhubctl -l 1-1 -a 1 | |
sleep 1 | |
echo 1-1 | sudo tee /sys/bus/usb/drivers/usb/bind | |
sleep 10 | |
# TODO run these on USB connect | |
mbimcli -d /dev/cdc-wdm0 -p --query-subscriber-ready-status | |
mbimcli -d /dev/cdc-wdm0 -p --query-signal-state | |
while (mbimcli -d /dev/cdc-wdm0 -p --query-packet-service-state | grep detached); do sleep .1; done | |
mbimcli -d /dev/cdc-wdm0 -p --query-registration-state | |
mbimcli -d /dev/cdc-wdm0 -p --query-packet-service-state | |
if (mbimcli -d /dev/cdc-wdm0 -p --query-ip-configuration | grep none); then | |
mbimcli -d /dev/cdc-wdm0 -p --connect=apn=4g.tele2.se,ip-type=ipv4v6 | |
fi | |
#mbimcli -d /dev/cdc-wdm0 -p --query-ip-configuration | |
for ip in $(mbimcli -d /dev/cdc-wdm0 -p --query-ip-configuration | grep -oP "IP \[0\]: '\K.*(?=')"); do ip a add $ip dev wwan0; done | |
ip link set wwan0 up | |
ip r add default via fe80::1 dev wwan0 | |
for ip in $(mbimcli -d /dev/cdc-wdm0 -p --query-ip-configuration | grep -oP "Gateway: '\K.*(?=')" | grep -e "^[0-9.]*$"); do ip r add 0.0.0.0/0 via $ip dev wwan0; done | |
# force default route thru router for ipv6 | |
dhcpcd -6 -d wwan0 -t 1 | |
wannet6=$(ip -6 r show dev wwan0 | grep -o ^2.*/64) | |
wanip6=$(ip -6 a show dev wwan0 | grep -o " 2[0-9a-f:]*/64" || ip -6 a show dev eth0 | grep -o " 2[0-9a-f:]*/64") | |
if [ ! -z "$wanip6" ]; then | |
ip a add $wanip6 dev eth0 | |
ip r del default via fe80::1 dev wwan0 | |
ip r add default via fe80::1 dev wwan0 src $(echo $wanip6 | grep -o "^[0-9a-z:]*") | |
ip a del $wanip6 dev wwan0 | |
ping 1.1.1.1 -c 1 | |
ping one.one.one.one -c 1 | |
sed -i "s#\(prefix \)2a[0-9a-f:]*/64#\1$wannet6#" /etc/radvd.conf | |
killall -9 radvd | |
radvd | |
fi | |
systemctl restart dnsmasq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment