aboutsummaryrefslogtreecommitdiffstats
path: root/mageia/network-scripts/ifdown-hso
blob: a920c17c8a9afc4fda9160bd416f5c12f868d83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash

. /etc/init.d/functions

cd /etc/sysconfig/network-scripts
. ./network-functions

CONFIG=${1}

source_config

[ -z "$CELLULAR_CID" ] && CELLULAR_CID=1
[ "${DEBUG}" = "yes" ] && CHATDBG="-v"

CHATSCRIPT=$(mktemp /tmp/chatXXXXXX)
cat > "$CHATSCRIPT" <<EOF
ABORT ERROR
TIMEOUT 5
"" ATZ
OK "AT_OWANCALL=${CELLULAR_CID},0,0"
OK ""
EOF

if ! /usr/sbin/chat ${CHATDBG} -s -f "${CHATSCRIPT}" < "$MODEMPORT" > "$MODEMPORT"; then
    echo $"Disconnect script failed (HSO)"
fi

# ask status (it also waits for device state to be cleaner)
# do not fail if status querying fail
cat > "$CHATSCRIPT" <<EOF
ABORT ERROR
TIMEOUT 2
"" ATZ
OK "AT_OWANDATA=${CELLULAR_CID}"
EOF
/usr/sbin/chat ${CHATDBG} -s -f "${CHATSCRIPT}" < "$MODEMPORT" > "$MODEMPORT"

rm -f "$CHATSCRIPT"

ip addr flush dev "${DEVICE}" 2>/dev/null
ip link set dev "${DEVICE}" down 2>/dev/null
retcode=$?

# wait up to 5 seconds for device to actually come down...
waited=0
while ! check_device_down "${DEVICE}" && [ "$waited" -lt 50 ] ; do
    usleep 10000
    (( waited++ ))
done

if [ "$retcode" = 0 ] ; then
    /etc/sysconfig/network-scripts/ifdown-post "$CONFIG"
    # do NOT use $? because ifdown should return whether or not
    # the interface went down.
fi

exit $retcode