Verified Commit 8ca37722 authored by Martin Prudek's avatar Martin Prudek
Browse files

mbim: Upgrade to version downloaded from [1]

[1] lteforum.at/mobilfunk/cat-6-module-basteleien.4969/seite-113.html#post-106295
parent 3dfe3697
#!/bin/sh
mask="0"
[ -n "$INCLUDE_ONLY" ] || {
. /lib/functions.sh
. ../netifd-proto.sh
......@@ -19,6 +21,16 @@ proto_mbim_init_config() {
proto_config_add_string password
}
# https://stackoverflow.com/questions/20762575
cdr2mask ()
{
# Number of args to shift, 255..255, first non-255 byte, zeroes
set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
[ $1 -gt 1 ] && shift $1 || shift
# echo "MASK: ${1-0}.${2-0}.${3-0}.${4-0}"
mask=${1-0}.${2-0}.${3-0}.${4-0}
}
_proto_mbim_setup() {
local interface="$1"
local tid=2
......@@ -59,35 +71,18 @@ _proto_mbim_setup() {
return 1
}
[ -n "$delay" ] && sleep "$delay"
/etc/init.d/sessionhold.sh stop
echo "LTE-Watchdog stopped"
echo "mbim[$$]" "Reading capabilities"
umbim $DBG -n -d $device caps || {
echo "mbim[$$]" "Failed to read modem caps"
proto_notify_error "$interface" PIN_FAILED
return 1
}
tid=$((tid + 1))
[ "$pincode" ] && {
echo "mbim[$$]" "Sending pin"
umbim $DBG -n -t $tid -d $device unlock "$pincode" || {
echo "mbim[$$]" "Unable to verify PIN"
proto_notify_error "$interface" PIN_FAILED
proto_block_restart "$interface"
return 1
}
}
tid=$((tid + 1))
[ -n "$delay" ] && sleep "$delay"
echo "mbim[$$]" "Checking pin"
umbim $DBG -n -t $tid -d $device pinstate || {
echo "mbim[$$]" "PIN required"
proto_notify_error "$interface" PIN_FAILED
proto_block_restart "$interface"
return 1
}
tid=$((tid + 1))
echo "mbim[$$]" "Reading capabilities"
umbim $DBG -n -d $device caps || {
echo "mbim[$$]" "Failed to read modem caps"
proto_notify_error "$interface" PIN_FAILED
return 1
}
tid=$((tid + 1))
echo "mbim[$$]" "Checking subscriber"
umbim $DBG -n -t $tid -d $device subscriber || {
......@@ -119,25 +114,51 @@ _proto_mbim_setup() {
sleep 1;
done
tid=$((tid + 1))
echo "mbim[$$]" "Get IP config"
CONFIG=$(umbim $DBG -n -t $tid -d $device config) || {
echo "mbim[$$]" "config failed"
return 1
}
tid=$((tid + 1))
echo "$CONFIG" > /tmp/ip
IP=$(cat /tmp/ip |grep ipv4address |grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
NM=$(cat /tmp/ip |grep ipv4address |grep -o '.\{2\}$')
GW=$(cat /tmp/ip |grep ipv4gateway |grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
DNS=$(cat /tmp/ip |grep ipv4dnsserver |grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" |head -1)
cdr2mask $NM
echo "IP: $IP"
echo "MASK: $mask"
echo "GW: $GW"
echo "DNS: $DNS"
uci_set_state network $interface tid "$tid"
echo "mbim[$$]" "Connected, starting DHCP"
echo "mbim[$$]" "Connected, setting IP"
proto_init_update "$ifname" 1
proto_send_update "$interface"
json_init
json_add_string name "${interface}_4"
json_add_string ifname "@$interface"
json_add_string proto "dhcp"
json_close_object
ubus call network add_dynamic "$(json_dump)"
json_init
json_add_string name "${interface}_6"
json_add_string ifname "@$interface"
json_add_string proto "dhcpv6"
ubus call network add_dynamic "$(json_dump)"
json_add_string proto "static"
ifconfig wwan0 $IP netmask $mask
ip route add default dev wwan0
# ifup wwan0
echo "nameserver $DNS" >> /tmp/resolv.conf.auto
echo "nameserver $DNS" >> /etc/resolv.conf
# echo "$mask"
/bin/sh /home/loopback.sh
echo "Loopback created for IP: $IP"
/etc/init.d/sessionhold.sh start
echo "LTE-Watchdog started"
return 0
}
proto_mbim_setup() {
......@@ -147,8 +168,8 @@ proto_mbim_setup() {
ret=$?
[ "$ret" = 0 ] || {
logger "mbim bringup failed, retry in 15s"
sleep 15
logger "mbim bringup failed, retry in 5s"
sleep 5
}
return $rt
......@@ -170,7 +191,7 @@ proto_mbim_teardown() {
}
proto_init_update "*" 0
proto_send_update "$interface"
# proto_send_update "$interface"
}
[ -n "$INCLUDE_ONLY" ] || add_protocol mbim
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment