forked from linrunner/TLP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlp-rdw-nm.in
134 lines (112 loc) · 3.67 KB
/
tlp-rdw-nm.in
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh
# tlp-rdw - network manager dispatcher hook:
# enable/disable radios on ifup/ifdown
#
# Copyright (c) 2015 Thomas Koch <linrunner at gmx.net>
# This software is licensed under the GPL v2 or later.
# --- Constants
readonly LIBDIR="@TLP_TLIB@"
readonly LIBS="tlp-functions tlp-rf-func"
readonly RDW_NM_LOCK="rdw_nm"
readonly RDW_NM_LOCKTIME=2
# --- Source libraries
for lib in $LIBS; do
if [ ! -f $LIBDIR/$lib ]; then
echo "Error: missing function library \'$LIBDIR/$lib\'." 1>&2
exit 1
fi
. $LIBDIR/$lib
done
# --- MAIN
read_defaults
check_tlp_enabled || exit 0
add_sbin2path
# Get args
iface="$1"
action="$2"
itype="unknown"
# Quit for invalid interfaces
[ -n "$iface" ] && [ "$iface" != "none" ] || exit 0
echo_debug "nm" "rdw_nm($iface).$action"
if [ -n "$addpath" ]; then
echo_debug "path" "PATH=$oldpath[$addpath]"
else
echo_debug "path" "PATH=$oldpath"
fi
# Quit if timed lock in progress
check_timed_lock $RDW_NM_LOCK && exit 0
# Determine interface type
if cmd_exists $NMCLI ; then
# nmcli is available --> check if nmcli dev output matches interface
itype="$($NMCLI dev | awk '$1 ~ /'$iface'/ { print $2; }')"
if [ -z "$itype" ]; then
# iface is not found in nmcli dev output: many WWAN devices have
# different devices for control and the actual network connection
# --> check if interface matches a WWAN device
get_wwan_ifaces
if wordinlist "$iface" "$wanifaces"; then
itype="wwan"
else
# if interface type detetion with nmcli failed, then try to
# deduct it using interface name: it can happen if e.g.
# usb network card is unplugged
case "$iface" in
en* | eth*)
itype="ethernet"
;;
wl* | wlan*)
itype="wifi"
;;
*)
itype="unknown"
;;
esac
fi
fi
echo_debug "nm" "rdw_nm($iface).$action: type=$itype [nmcli]"
else
# nmcli is not available
echo_debug "nm" "rdw_nm($iface)$action.nmcli_not_available"
fi
case $action in
up) # interface up, disable configured interfaces
set_timed_lock $RDW_NM_LOCK $RDW_NM_LOCKTIME # lock rdw events
case $itype in
*ethernet)
for dev in $DEVICES_TO_DISABLE_ON_LAN_CONNECT; do
[ -n "$dev" ] && device_switch $dev off
done
;;
*wireless|wifi)
for dev in $DEVICES_TO_DISABLE_ON_WIFI_CONNECT; do
[ -n "$dev" ] && [ "$dev" != wifi ] && device_switch $dev off
done
;;
gsm|wwan)
for dev in $DEVICES_TO_DISABLE_ON_WWAN_CONNECT; do
[ -n "$dev" ] && [ "$dev" != wwan ] && device_switch $dev off
done
;;
esac
;; # up
down) # interface down, enable configured interfaces
case $itype in
*ethernet)
for dev in $DEVICES_TO_ENABLE_ON_LAN_DISCONNECT; do
[ -n "$dev" ] && device_switch $dev on
done
;;
*wireless|wifi)
for dev in $DEVICES_TO_ENABLE_ON_WIFI_DISCONNECT; do
[ -n "$dev" ] && [ "$dev" != wifi ] && device_switch $dev on
done
;;
gsm)
for dev in $DEVICES_TO_ENABLE_ON_WWAN_DISCONNECT; do
[ -n "$dev" ] && [ "$dev" != wwan ] && device_switch $dev on
done
;;
esac
;; # down
esac
exit 0