Since there seems to be some interest here are the (admittedly rather simplistic) scripts i am using to automate the HiLink panel of the Huawei 3276 dongle:
/usr/libexec/wwand:
#!/bin/sh
export PATH="$PATH:/opt/bin"
wwan_state() {
_D="$( curl -s http://192.168.1.1/api/monitoring/status )"
if [ ! $? = 0 ]; then
echo FAILED
return
fi
_S="$( echo "$_D" | grep '<ConnectionStatus>' | \
sed 's/.*>\([^<]*\)<.*/\1/' )"
case "$_S" in
901) echo CONNECTED;;
902) echo DISCONNECTED;;
*) echo "UNKNOWN($_S)";;
esac
}
wwan_connect() {
_R='<?xml version="1.0" encoding="UTF-8"?><request><Action>1</Action></request>'
_T='Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
_D="$( curl -s http://192.168.1.1/api/dialup/dial \
-H "$_T" --data-raw "$_R" )"
[ $? = 0 ] || return 1
_D="$( echo "$_D" | head -n1 | \
sed 's|^.*<response>\(.*\)</response>$|\1|' )"
[ "$_D" = OK ] && return 0
return 1
}
wwan_log_err() {
logger local0.err "$*"
}
wwan_log_info() {
logger local0.notice "$*"
}
wwan_up() {
[ -d /etc/wwan.up.d ] || return
for F in /etc/wwan.up.d/*; do
[ -x "$F" ] || continue
wwan_log_info "executing '$F'..."
"$F" || wwan_log_err "executing '$F' failed"
done
}
wwan_loop() {
O=''
while true; do
S="$( wwan_state )"
if [ ! "$S" = "$O" ]; then
wwan_log_info "new state: $S"
fi
if [ "$S" = DISCONNECTED ]; then
wwan_log_info 'reconnecting...'
if ! wwan_connect; then
wwan_log_err 'connect failed - waiting...'
sleep 30
else
wwan_up
sleep 3
fi
else
sleep 3
fi
O="$S"
done
}
if [ "$1" = -d ]; then
"$0" >/dev/null 2>&1 &
echo "$!" > /var/run/wwand.pid
exit 0
fi
wwan_loop
/etc/rc.d/wwand:
!/bin/sh
# REQUIRE: network mountall
$_rc_subr_loaded . /etc/rc.subr
name=wwand
rcvar=$name
command="/usr/libexec/$name"
command_interpreter=/bin/sh
command_args=-d
pidfile="/var/run/$name.pid"
load_rc_config "$name"
run_rc_command "$1"
There obviously is some status codes it doesn't handle but in general it seems to work kinda nicely for making sure the connection stays active. Adjusting the PATH variable might be superfluous. As long as the curl executable can be found everything is fine.