-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodem
executable file
·186 lines (163 loc) · 4.54 KB
/
modem
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This is a wrapper around a lot of different DBus calls, written in sh; this is
# meant to replace parts of flimflam-test, and also to be callable from crosh.
. /usr/lib/connectivity-common.sh
. /usr/lib/modem-common.sh
# Wait for a modem to reset itself and come back with a new DBus name
# args:
# $1 - dbus name of the modem before reset
# $2 - timeout in seconds
wait_for_modem_reset() {
local modem
local oldmodem="$1"
local timeout="$2"
local status="Timed out"
echo -n "Waiting..."
while test ${timeout} -gt 0; do
modem=$(default_modem)
if [ -n "${modem}" -a "${modem}" != "${oldmodem}" ]; then
status="Done"
break
fi
sleep 1
timeout=$((timeout - 1))
echo -n "."
done
echo "${status}"
}
activate() {
$(arg_or_default modem $(default_modem))
[ -z "${modem}" ] && error_exit "No modem found."
# Work around braindead crosh quoting semantics (i.e., there are none,
# arguments are tokenized on spaces). Sigh.
local carrier=$(echo "$@")
mmcli -m "${modem}" --cdma-activate="${carrier}"
}
connect() {
$(arg_or_default modem $(default_modem))
[ -z "${modem}" ] && error_exit "No modem found."
# Work around braindead quoting again...
local args=$(echo "$@")
[ -n "${args}" ] && args="number=${args}"
mmcli -m "${modem}" --simple-connect="${args}"
}
factory_reset() {
$(arg_or_default modem $(default_modem))
[ -z "${modem}" ] && error_exit "No modem found."
$(arg_or_prompt spc 000000)
# TODO(benchan): Evaluate if a warning should be given when factory
# resetting under certain modem configurations.
mmcli -m "${modem}" --factory-reset="${spc}"
}
reset() {
$(arg_or_default modem $(default_modem))
[ -z "${modem}" ] && error_exit "No modem found."
mmcli -m "${modem}" --reset
wait_for_modem_reset "${modem}" 40
}
status() {
all_modem_status 2>/dev/null
}
status_feedback() {
all_modem_status 2>/dev/null | mask_modem_properties
}
ussd() {
local modem
local operation="$1"
local data="$2"
$(arg_or_default modem $(default_modem))
[ -z "${modem}" ] && error_exit "No modem found."
if [ -z "${operation}" ]; then
echo "Valid USSD operations are: status, initiate, respond, cancel"
return
fi
case "${operation}" in
status)
mmcli -m "${modem}" --3gpp-ussd-status
;;
initiate)
[ -z "${data}" ] && error_exit "Missing USSD data."
mmcli -m "${modem}" --3gpp-ussd-initiate="${data}"
;;
respond)
[ -z "${data}" ] && error_exit "Missing USSD data."
mmcli -m "${modem}" --3gpp-ussd-respond="${data}"
;;
cancel)
mmcli -m "${modem}" --3gpp-ussd-cancel
;;
*)
error_exit "'${operation}' is not valid USSD operation."
;;
esac
}
set_logging() {
local level="$1"
local manager
if [ -z "${level}" ]; then
echo "Valid logging levels are: debug, info, warn, error"
return
fi
case "${level}" in
debug|info|warn|error)
set_modem_manager_logging "${level}"
;;
*)
error_exit "'${level}' is not a valid logging level."
;;
esac
}
usage() {
echo "Usage: $(basename $0) <command> [args...]"
echo " activate [-modem <modem>] [<carrier>] Activate modem"
echo " connect [-modem <modem>] [phone number] Connect modem"
echo " factory-reset [-modem <modem>] [<spc>] Factory-reset the modem"
echo " force-flash <device_id> Force-flash the modem"
echo " reset [-modem <modem>] Reset the modem"
echo " set-logging (debug|info|warn|error) Set logging level"
echo " status Display modem status"
echo " ussd [-modem <modem>] status " \
"Show status of ongoing USSD session"
echo " ussd [-modem <modem>] initiate <command> Initiate a USSD session"
echo " ussd [-modem <modem>] respond <response> " \
"Respond to a USSD request"
echo " ussd [-modem <modem>] cancel " \
"Cancel ongoing USSD session"
exit 0
}
$(needarg cmd)
case "${cmd}" in
activate)
activate "$@"
;;
connect)
connect "$@"
;;
factory-reset)
factory_reset "$@"
;;
force-flash)
force_flash "$@"
;;
reset)
reset "$@"
;;
set-logging)
set_logging "$@"
;;
status)
status "$@"
;;
status-feedback)
status_feedback "$@"
;;
ussd)
ussd "$@"
;;
*)
usage
;;
esac