blob: e03bab891bd4139c30c3d47ceb834992d2d2e7dd [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001# osmo_gsm_tester: DBUS client to talk to ofono
2#
3# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Neels Hofmeyr <neels@hofmeyr.de>
6#
7# This program is free software: you can redistribute it and/or modify
Harald Welte27205342017-06-03 09:51:45 +02008# it under the terms of the GNU General Public License as
Neels Hofmeyr3531a192017-03-28 14:30:28 +02009# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte27205342017-06-03 09:51:45 +020015# GNU General Public License for more details.
Neels Hofmeyr3531a192017-03-28 14:30:28 +020016#
Harald Welte27205342017-06-03 09:51:45 +020017# You should have received a copy of the GNU General Public License
Neels Hofmeyr3531a192017-03-28 14:30:28 +020018# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
Pau Espin Pedrole1a58bd2020-04-10 20:46:07 +020020from ..core import log, util, process
21from ..core.event_loop import MainLoop
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000022from .ms import MS
Pau Espin Pedrole8bbcbf2020-04-10 19:51:31 +020023from . import sms
Neels Hofmeyr3531a192017-03-28 14:30:28 +020024
25from pydbus import SystemBus, Variant
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +020026import os
Neels Hofmeyr3531a192017-03-28 14:30:28 +020027
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +020028# Required for Gio.Cancellable.
29# See https://lazka.github.io/pgi-docs/Gio-2.0/classes/Cancellable.html#Gio.Cancellable
30from gi.module import get_introspection_module
31Gio = get_introspection_module('Gio')
32
Neels Hofmeyr3531a192017-03-28 14:30:28 +020033from gi.repository import GLib
Holger Hans Peter Freytherae0dae82019-02-20 08:57:46 +000034bus = None
Neels Hofmeyr3531a192017-03-28 14:30:28 +020035
Pau Espin Pedrol504a6642017-05-04 11:38:23 +020036I_MODEM = 'org.ofono.Modem'
Neels Hofmeyrb3daaea2017-04-09 14:18:34 +020037I_NETREG = 'org.ofono.NetworkRegistration'
38I_SMS = 'org.ofono.MessageManager'
Pau Espin Pedrolde899612017-11-23 17:18:40 +010039I_CONNMGR = 'org.ofono.ConnectionManager'
Pau Espin Pedrold71edd12017-10-06 13:53:54 +020040I_CALLMGR = 'org.ofono.VoiceCallManager'
41I_CALL = 'org.ofono.VoiceCall'
Pau Espin Pedrol03983aa2017-06-12 15:31:27 +020042I_SS = 'org.ofono.SupplementaryServices'
Pau Espin Pedrolbfd0b232018-03-13 18:32:57 +010043I_SIMMGR = 'org.ofono.SimManager'
Pau Espin Pedrole02158f2019-02-13 19:38:09 +010044I_VOICECALL = 'org.ofono.VoiceCall'
Neels Hofmeyrb3daaea2017-04-09 14:18:34 +020045
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +020046# See https://github.com/intgr/ofono/blob/master/doc/network-api.txt#L78
47NETREG_ST_REGISTERED = 'registered'
48NETREG_ST_ROAMING = 'roaming'
49
50NETREG_MAX_REGISTER_ATTEMPTS = 3
51
Pau Espin Pedrolbf176e42018-03-26 19:13:32 +020052class DeferredDBus:
Neels Hofmeyr035cda82017-05-05 17:52:45 +020053
54 def __init__(self, dbus_iface, handler):
55 self.handler = handler
Neels Hofmeyr47de6b02017-05-10 13:24:05 +020056 self.subscription_id = dbus_iface.connect(self.receive_signal)
Neels Hofmeyr035cda82017-05-05 17:52:45 +020057
58 def receive_signal(self, *args, **kwargs):
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +020059 MainLoop.defer(self.handler, *args, **kwargs)
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +020060
Neels Hofmeyr035cda82017-05-05 17:52:45 +020061def dbus_connect(dbus_iface, handler):
62 '''This function shall be used instead of directly connecting DBus signals.
63 It ensures that we don't nest a glib main loop within another, and also
64 that we receive exceptions raised within the signal handlers. This makes it
65 so that a signal handler is invoked only after the DBus polling is through
66 by enlisting signals that should be handled in the
67 DeferredHandling.defer_queue.'''
Pau Espin Pedrolbf176e42018-03-26 19:13:32 +020068 return DeferredDBus(dbus_iface, handler).subscription_id
Pau Espin Pedrol927344b2017-05-22 16:38:49 +020069
Neels Hofmeyr93f58662017-05-03 16:32:16 +020070def systembus_get(path):
Neels Hofmeyr3531a192017-03-28 14:30:28 +020071 global bus
Holger Hans Peter Freytherae0dae82019-02-20 08:57:46 +000072 if not bus:
73 bus = SystemBus()
Neels Hofmeyr3531a192017-03-28 14:30:28 +020074 return bus.get('org.ofono', path)
75
76def list_modems():
Neels Hofmeyr93f58662017-05-03 16:32:16 +020077 root = systembus_get('/')
Neels Hofmeyr3531a192017-03-28 14:30:28 +020078 return sorted(root.GetModems())
79
Pau Espin Pedrole25cf042018-02-23 17:00:09 +010080def get_dbuspath_from_syspath(syspath):
81 modems = list_modems()
82 for dbuspath, props in modems:
83 if props.get('SystemPath', '') == syspath:
84 return dbuspath
85 raise ValueError('could not find %s in modem list: %s' % (syspath, modems))
86
87
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +020088def _async_result_handler(obj, result, user_data):
89 '''Generic callback dispatcher called from glib loop when an async method
90 call has returned. This callback is set up by method dbus_async_call.'''
91 (result_callback, error_callback, real_user_data) = user_data
92 try:
93 ret = obj.call_finish(result)
94 except Exception as e:
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +020095 if isinstance(e, GLib.Error) and e.code == Gio.IOErrorEnum.CANCELLED:
96 log.dbg('DBus method cancelled')
97 return
98
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +020099 if error_callback:
100 error_callback(obj, e, real_user_data)
101 else:
102 result_callback(obj, e, real_user_data)
103 return
104
105 ret = ret.unpack()
106 # to be compatible with standard Python behaviour, unbox
107 # single-element tuples and return None for empty result tuples
108 if len(ret) == 1:
109 ret = ret[0]
110 elif len(ret) == 0:
111 ret = None
112 result_callback(obj, ret, real_user_data)
113
114def dbus_async_call(instance, proxymethod, *proxymethod_args,
115 result_handler=None, error_handler=None,
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +0200116 user_data=None, timeout=30, cancellable=None,
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200117 **proxymethod_kwargs):
118 '''pydbus doesn't support asynchronous methods. This method adds support for
119 it until pydbus implements it'''
120
121 argdiff = len(proxymethod_args) - len(proxymethod._inargs)
122 if argdiff < 0:
123 raise TypeError(proxymethod.__qualname__ + " missing {} required positional argument(s)".format(-argdiff))
124 elif argdiff > 0:
125 raise TypeError(proxymethod.__qualname__ + " takes {} positional argument(s) but {} was/were given".format(len(proxymethod._inargs), len(proxymethod_args)))
126
127 timeout = timeout * 1000
128 user_data = (result_handler, error_handler, user_data)
129
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +0200130 # See https://lazka.github.io/pgi-docs/Gio-2.0/classes/DBusProxy.html#Gio.DBusProxy.call
Holger Hans Peter Freyther34dce0e2019-02-27 04:34:00 +0000131 instance._bus.con.call(
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200132 instance._bus_name, instance._path,
133 proxymethod._iface_name, proxymethod.__name__,
134 GLib.Variant(proxymethod._sinargs, proxymethod_args),
135 GLib.VariantType.new(proxymethod._soutargs),
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +0200136 0, timeout, cancellable,
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200137 _async_result_handler, user_data)
138
Pau Espin Pedrol7423d2e2017-08-25 12:58:25 +0200139def dbus_call_dismiss_error(log_obj, err_str, method):
140 try:
141 method()
Pau Espin Pedrol9b670212017-11-07 17:50:20 +0100142 except GLib.Error as e:
143 if Gio.DBusError.is_remote_error(e) and Gio.DBusError.get_remote_error(e) == err_str:
Pau Espin Pedrol7423d2e2017-08-25 12:58:25 +0200144 log_obj.log('Dismissed Dbus method error: %r' % e)
145 return
Pau Espin Pedrol9b670212017-11-07 17:50:20 +0100146 raise e
Pau Espin Pedrol7423d2e2017-08-25 12:58:25 +0200147
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200148class ModemDbusInteraction(log.Origin):
149 '''Work around inconveniences specific to pydbus and ofono.
150 ofono adds and removes DBus interfaces and notifies about them.
151 Upon changes we need a fresh pydbus object to benefit from that.
152 Watching the interfaces change is optional; be sure to call
153 watch_interfaces() if you'd like to have signals subscribed.
154 Related: https://github.com/LEW21/pydbus/issues/56
155 '''
156
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200157 modem_path = None
158 watch_props_subscription = None
159 _dbus_obj = None
160 interfaces = None
161
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200162 def __init__(self, modem_path):
163 self.modem_path = modem_path
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200164 super().__init__(log.C_BUS, self.modem_path)
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200165 self.interfaces = set()
166
167 # A dict listing signal handlers to connect, e.g.
168 # { I_SMS: ( ('IncomingMessage', self._on_incoming_message), ), }
169 self.required_signals = {}
170
171 # A dict collecting subscription tokens for connected signal handlers.
172 # { I_SMS: ( token1, token2, ... ), }
173 self.connected_signals = util.listdict()
174
Neels Hofmeyr4d688c22017-05-29 04:13:58 +0200175 def cleanup(self):
Pau Espin Pedrol58ff38d2017-06-23 13:10:38 +0200176 self.set_powered(False)
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200177 self.unwatch_interfaces()
178 for interface_name in list(self.connected_signals.keys()):
179 self.remove_signals(interface_name)
180
Neels Hofmeyr4d688c22017-05-29 04:13:58 +0200181 def __del__(self):
182 self.cleanup()
183
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200184 def get_new_dbus_obj(self):
185 return systembus_get(self.modem_path)
186
187 def dbus_obj(self):
188 if self._dbus_obj is None:
189 self._dbus_obj = self.get_new_dbus_obj()
190 return self._dbus_obj
191
192 def interface(self, interface_name):
193 try:
194 return self.dbus_obj()[interface_name]
195 except KeyError:
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200196 raise log.Error('Modem interface is not available:', interface_name)
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200197
198 def signal(self, interface_name, signal):
199 return getattr(self.interface(interface_name), signal)
200
201 def watch_interfaces(self):
202 self.unwatch_interfaces()
203 # Note: we are watching the properties on a get_new_dbus_obj() that is
204 # separate from the one used to interact with interfaces. We need to
205 # refresh the pydbus object to interact with Interfaces that have newly
206 # appeared, but exchanging the DBus object to watch Interfaces being
207 # enabled and disabled is racy: we may skip some removals and
208 # additions. Hence do not exchange this DBus object. We don't even
209 # need to store the dbus object used for this, we will not touch it
210 # again. We only store the signal subscription.
211 self.watch_props_subscription = dbus_connect(self.get_new_dbus_obj().PropertyChanged,
212 self.on_property_change)
213 self.on_interfaces_change(self.properties().get('Interfaces'))
214
215 def unwatch_interfaces(self):
216 if self.watch_props_subscription is None:
217 return
218 self.watch_props_subscription.disconnect()
219 self.watch_props_subscription = None
220
221 def on_property_change(self, name, value):
222 if name == 'Interfaces':
223 self.on_interfaces_change(value)
Pau Espin Pedrol77631212017-09-05 19:04:06 +0200224 else:
225 self.dbg('%r.PropertyChanged() -> %s=%s' % (I_MODEM, name, value))
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200226
227 def on_interfaces_change(self, interfaces_now):
228 # First some logging.
229 now = set(interfaces_now)
230 additions = now - self.interfaces
231 removals = self.interfaces - now
232 self.interfaces = now
233 if not (additions or removals):
234 # nothing changed.
235 return
236
237 if additions:
238 self.dbg('interface enabled:', ', '.join(sorted(additions)))
239
240 if removals:
241 self.dbg('interface disabled:', ', '.join(sorted(removals)))
242
243 # The dbus object is now stale and needs refreshing before we
244 # access the next interface function.
245 self._dbus_obj = None
246
247 # If an interface disappeared, disconnect the signal handlers for it.
248 # Even though we're going to use a fresh dbus object for new
249 # subscriptions, we will still keep active subscriptions alive on the
250 # old dbus object which will linger, associated with the respective
251 # signal subscription.
252 for removed in removals:
253 self.remove_signals(removed)
254
255 # Connect signals for added interfaces.
256 for interface_name in additions:
257 self.connect_signals(interface_name)
258
259 def remove_signals(self, interface_name):
260 got = self.connected_signals.pop(interface_name, [])
261
262 if not got:
263 return
264
265 self.dbg('Disconnecting', len(got), 'signals for', interface_name)
266 for subscription in got:
267 subscription.disconnect()
268
269 def connect_signals(self, interface_name):
270 # If an interface was added, it must not have existed before. For
271 # paranoia, make sure we have no handlers for those.
272 self.remove_signals(interface_name)
273
274 want = self.required_signals.get(interface_name, [])
275 if not want:
276 return
277
278 self.dbg('Connecting', len(want), 'signals for', interface_name)
279 for signal, cb in self.required_signals.get(interface_name, []):
280 subscription = dbus_connect(self.signal(interface_name, signal), cb)
281 self.connected_signals.add(interface_name, subscription)
282
283 def has_interface(self, *interface_names):
284 try:
285 for interface_name in interface_names:
286 self.dbus_obj()[interface_name]
287 result = True
288 except KeyError:
289 result = False
290 self.dbg('has_interface(%s) ==' % (', '.join(interface_names)), result)
291 return result
292
293 def properties(self, iface=I_MODEM):
294 return self.dbus_obj()[iface].GetProperties()
295
296 def property_is(self, name, val, iface=I_MODEM):
297 is_val = self.properties(iface).get(name)
298 self.dbg(name, '==', is_val)
299 return is_val is not None and is_val == val
300
301 def set_bool(self, name, bool_val, iface=I_MODEM):
302 # to make sure any pending signals are received before we send out more DBus requests
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200303 MainLoop.poll()
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200304
305 val = bool(bool_val)
306 self.log('Setting', name, val)
307 self.interface(iface).SetProperty(name, Variant('b', val))
308
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200309 MainLoop.wait(self, self.property_is, name, bool_val)
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200310
311 def set_powered(self, powered=True):
312 self.set_bool('Powered', powered)
313
314 def set_online(self, online=True):
315 self.set_bool('Online', online)
316
317 def is_powered(self):
318 return self.property_is('Powered', True)
319
320 def is_online(self):
321 return self.property_is('Online', True)
322
Pau Espin Pedrole02158f2019-02-13 19:38:09 +0100323class ModemCall(log.Origin):
324 'ofono Modem voicecall dbus object'
325
326 def __init__(self, modem, dbuspath):
327 super().__init__(log.C_TST, dbuspath)
328 self.modem = modem
329 self.dbuspath = dbuspath
330 self.signal_list = []
331 self.register_signals()
332
333 def register_signals(self):
334 call_dbus_obj = systembus_get(self.dbuspath)
335 subscr = dbus_connect(call_dbus_obj.PropertyChanged, lambda name, value: self.on_voicecall_property_change(self.dbuspath, name, value))
336 self.signal_list.append(subscr)
337 subscr = dbus_connect(call_dbus_obj.DisconnectReason, lambda reason: self.on_voicecall_disconnect_reason(self.dbuspath, reason))
338 self.signal_list.append(subscr)
339
340 def unregister_signals(self):
341 for subscr in self.signal_list:
342 subscr.disconnect()
343 self.signal_list = []
344
345 def cleanup(self):
346 self.unregister_signals()
347
348 def __del__(self):
349 self.cleanup()
350
351 def on_voicecall_property_change(self, obj_path, name, value):
352 self.dbg('%r:%r.PropertyChanged() -> %s=%s' % (obj_path, I_VOICECALL, name, value))
353
354 def on_voicecall_disconnect_reason(self, obj_path, reason):
355 self.dbg('%r:%r.DisconnectReason() -> %s' % (obj_path, I_VOICECALL, reason))
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200356
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000357class Modem(MS):
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200358 'convenience for ofono Modem interaction'
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200359
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100360 CTX_PROT_IPv4 = 'ip'
361 CTX_PROT_IPv6 = 'ipv6'
362 CTX_PROT_IPv46 = 'dual'
363
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200364 def __init__(self, testenv, conf):
Pau Espin Pedrole25cf042018-02-23 17:00:09 +0100365 self.syspath = conf.get('path')
366 self.dbuspath = get_dbuspath_from_syspath(self.syspath)
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000367 super().__init__(self.dbuspath, conf)
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +0200368 self.dbg('creating from syspath %s' % self.syspath)
Pau Espin Pedrol58603672018-08-09 13:45:55 +0200369 self._ki = None
370 self._imsi = None
Andre Puschmann22ec00a2020-03-24 09:58:06 +0100371 self._apn_ipaddr = None
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200372 self.run_dir = util.Dir(testenv.suite().get_run_dir().new_dir(self.name().strip('/')))
Neels Hofmeyrfec7d162017-05-02 16:29:09 +0200373 self.sms_received_list = []
Pau Espin Pedrole25cf042018-02-23 17:00:09 +0100374 self.dbus = ModemDbusInteraction(self.dbuspath)
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200375 self.register_attempts = 0
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200376 self.call_list = []
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +0200377 # one Cancellable can handle several concurrent methods.
378 self.cancellable = Gio.Cancellable.new()
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200379 self.dbus.required_signals = {
380 I_SMS: ( ('IncomingMessage', self._on_incoming_message), ),
Pau Espin Pedrol56bf31c2017-05-31 12:05:20 +0200381 I_NETREG: ( ('PropertyChanged', self._on_netreg_property_changed), ),
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100382 I_CONNMGR: ( ('PropertyChanged', self._on_connmgr_property_changed), ),
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200383 I_CALLMGR: ( ('PropertyChanged', self._on_callmgr_property_changed),
384 ('CallAdded', self._on_callmgr_call_added),
385 ('CallRemoved', self._on_callmgr_call_removed), ),
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200386 }
387 self.dbus.watch_interfaces()
388
Neels Hofmeyr4d688c22017-05-29 04:13:58 +0200389 def cleanup(self):
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +0200390 self.dbg('cleanup')
391 if self.cancellable:
Pau Espin Pedrol6680ef22017-09-11 01:24:05 +0200392 self.cancel_pending_dbus_methods()
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +0200393 self.cancellable = None
Pau Espin Pedrol7aef3862017-11-23 12:15:55 +0100394 if self.is_powered():
395 self.power_off()
Pau Espin Pedrole02158f2019-02-13 19:38:09 +0100396 for call_obj in self.call_list:
397 call_obj.cleanup()
398 self.call_list = []
Neels Hofmeyr4d688c22017-05-29 04:13:58 +0200399 self.dbus.cleanup()
400 self.dbus = None
401
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +0200402 def netns(self):
403 return os.path.basename(self.syspath.rstrip('/'))
404
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200405 def properties(self, *args, **kwargs):
406 '''Return a dict of properties on this modem. For the actual arguments,
407 see ModemDbusInteraction.properties(), which this function calls. The
408 returned dict is defined by ofono. An example is:
409 {'Lockdown': False,
410 'Powered': True,
411 'Model': 'MC7304',
412 'Revision': 'SWI9X15C_05.05.66.00 r29972 CARMD-EV-FRMWR1 2015/10/08 08:36:28',
413 'Manufacturer': 'Sierra Wireless, Incorporated',
414 'Emergency': False,
415 'Interfaces': ['org.ofono.SmartMessaging',
416 'org.ofono.PushNotification',
417 'org.ofono.MessageManager',
418 'org.ofono.NetworkRegistration',
419 'org.ofono.ConnectionManager',
420 'org.ofono.SupplementaryServices',
421 'org.ofono.RadioSettings',
422 'org.ofono.AllowedAccessPoints',
423 'org.ofono.SimManager',
424 'org.ofono.LocationReporting',
425 'org.ofono.VoiceCallManager'],
426 'Serial': '356853054230919',
427 'Features': ['sms', 'net', 'gprs', 'ussd', 'rat', 'sim', 'gps'],
428 'Type': 'hardware',
429 'Online': True}
430 '''
431 return self.dbus.properties(*args, **kwargs)
432
433 def set_powered(self, powered=True):
434 return self.dbus.set_powered(powered=powered)
435
436 def set_online(self, online=True):
437 return self.dbus.set_online(online=online)
438
439 def is_powered(self):
440 return self.dbus.is_powered()
441
442 def is_online(self):
443 return self.dbus.is_online()
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200444
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200445 def imsi(self):
Pau Espin Pedrolbfd0b232018-03-13 18:32:57 +0100446 if self._imsi is None:
447 if 'sim' in self.features():
448 if not self.is_powered():
449 self.set_powered()
450 # wait for SimManager iface to appear after we power on
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200451 MainLoop.wait(self, self.dbus.has_interface, I_SIMMGR, timeout=10)
Pau Espin Pedrolbfd0b232018-03-13 18:32:57 +0100452 simmgr = self.dbus.interface(I_SIMMGR)
453 # If properties are requested quickly, it may happen that Sim property is still not there.
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200454 MainLoop.wait(self, lambda: simmgr.GetProperties().get('SubscriberIdentity', None) is not None, timeout=10)
Pau Espin Pedrolbfd0b232018-03-13 18:32:57 +0100455 props = simmgr.GetProperties()
456 self.dbg('got SIM properties', props)
457 self._imsi = props.get('SubscriberIdentity', None)
458 else:
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000459 self._imsi = super().imsi()
Pau Espin Pedrolbfd0b232018-03-13 18:32:57 +0100460 if self._imsi is None:
461 raise log.Error('No IMSI')
462 return self._imsi
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200463
Pau Espin Pedrolcd6ad9d2017-08-22 19:10:20 +0200464 def set_ki(self, ki):
465 self._ki = ki
466
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200467 def ki(self):
Pau Espin Pedrolcd6ad9d2017-08-22 19:10:20 +0200468 if self._ki is not None:
469 return self._ki
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000470 return super().ki()
Pau Espin Pedrol713ce2c2017-08-24 16:57:17 +0200471
Andre Puschmann22ec00a2020-03-24 09:58:06 +0100472 def apn_ipaddr(self):
473 if self._apn_ipaddr is not None:
474 return self._apn_ipaddr
475 return 'dynamic'
476
Pau Espin Pedrole0f49862017-11-23 11:37:34 +0100477 def features(self):
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000478 return self._conf.get('features', [])
Pau Espin Pedrole0f49862017-11-23 11:37:34 +0100479
480 def _required_ifaces(self):
481 req_ifaces = (I_NETREG,)
482 req_ifaces += (I_SMS,) if 'sms' in self.features() else ()
483 req_ifaces += (I_SS,) if 'ussd' in self.features() else ()
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100484 req_ifaces += (I_CONNMGR,) if 'gprs' in self.features() else ()
Pau Espin Pedrolbfd0b232018-03-13 18:32:57 +0100485 req_ifaces += (I_SIMMGR,) if 'sim' in self.features() else ()
Pau Espin Pedrole0f49862017-11-23 11:37:34 +0100486 return req_ifaces
487
Pau Espin Pedrol56bf31c2017-05-31 12:05:20 +0200488 def _on_netreg_property_changed(self, name, value):
489 self.dbg('%r.PropertyChanged() -> %s=%s' % (I_NETREG, name, value))
490
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200491 def is_connected(self, mcc_mnc=None):
492 netreg = self.dbus.interface(I_NETREG)
493 prop = netreg.GetProperties()
494 status = prop.get('Status')
Pau Espin Pedrol4d63d922017-06-13 16:23:23 +0200495 self.dbg('status:', status)
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200496 if not (status == NETREG_ST_REGISTERED or status == NETREG_ST_ROAMING):
497 return False
498 if mcc_mnc is None: # Any network is fine and we are registered.
499 return True
500 mcc = prop.get('MobileCountryCode')
501 mnc = prop.get('MobileNetworkCode')
502 if (mcc, mnc) == mcc_mnc:
503 return True
504 return False
505
506 def schedule_scan_register(self, mcc_mnc):
507 if self.register_attempts > NETREG_MAX_REGISTER_ATTEMPTS:
Pau Espin Pedrolcc5b5a22017-06-13 16:55:31 +0200508 raise log.Error('Failed to find Network Operator', mcc_mnc=mcc_mnc, attempts=self.register_attempts)
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200509 self.register_attempts += 1
510 netreg = self.dbus.interface(I_NETREG)
511 self.dbg('Scanning for operators...')
512 # Scan method can take several seconds, and we don't want to block
513 # waiting for that. Make it async and try to register when the scan is
514 # finished.
515 register_func = self.scan_cb_register_automatic if mcc_mnc is None else self.scan_cb_register
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200516 result_handler = lambda obj, result, user_data: MainLoop.defer(register_func, result, user_data)
517 error_handler = lambda obj, e, user_data: MainLoop.defer(self.scan_cb_error_handler, e, mcc_mnc)
Pau Espin Pedrolfbecf412017-06-14 12:14:53 +0200518 dbus_async_call(netreg, netreg.Scan, timeout=30, cancellable=self.cancellable,
519 result_handler=result_handler, error_handler=error_handler,
520 user_data=mcc_mnc)
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200521
Pau Espin Pedrol4d63d922017-06-13 16:23:23 +0200522 def scan_cb_error_handler(self, e, mcc_mnc):
523 # It was detected that Scan() method can fail for some modems on some
524 # specific circumstances. For instance it fails with org.ofono.Error.Failed
525 # if the modem starts to register internally after we started Scan() and
526 # the registering succeeds while we are still waiting for Scan() to finsih.
527 # So far the easiest seems to check if we are now registered and
528 # otherwise schedule a scan again.
Pau Espin Pedrol910f3a12017-06-13 16:59:19 +0200529 self.err('Scan() failed, retrying if needed:', e)
Pau Espin Pedrol4d63d922017-06-13 16:23:23 +0200530 if not self.is_connected(mcc_mnc):
531 self.schedule_scan_register(mcc_mnc)
Pau Espin Pedrol910f3a12017-06-13 16:59:19 +0200532 else:
533 self.log('Already registered with network', mcc_mnc)
Pau Espin Pedrol4d63d922017-06-13 16:23:23 +0200534
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200535 def scan_cb_register_automatic(self, scanned_operators, mcc_mnc):
536 self.dbg('scanned operators: ', scanned_operators);
537 for op_path, op_prop in scanned_operators:
538 if op_prop.get('Status') == 'current':
539 mcc = op_prop.get('MobileCountryCode')
540 mnc = op_prop.get('MobileNetworkCode')
541 self.log('Already registered with network', (mcc, mnc))
542 return
543 self.log('Registering with the default network')
544 netreg = self.dbus.interface(I_NETREG)
Pau Espin Pedrol7423d2e2017-08-25 12:58:25 +0200545 dbus_call_dismiss_error(self, 'org.ofono.Error.InProgress', netreg.Register)
546
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200547
548 def scan_cb_register(self, scanned_operators, mcc_mnc):
549 self.dbg('scanned operators: ', scanned_operators);
550 matching_op_path = None
551 for op_path, op_prop in scanned_operators:
552 mcc = op_prop.get('MobileCountryCode')
553 mnc = op_prop.get('MobileNetworkCode')
554 if (mcc, mnc) == mcc_mnc:
555 if op_prop.get('Status') == 'current':
556 self.log('Already registered with network', mcc_mnc)
557 # We discovered the network and we are already registered
558 # with it. Avoid calling op.Register() in this case (it
559 # won't act as a NO-OP, it actually returns an error).
560 return
561 matching_op_path = op_path
562 break
563 if matching_op_path is None:
564 self.dbg('Failed to find Network Operator', mcc_mnc=mcc_mnc, attempts=self.register_attempts)
565 self.schedule_scan_register(mcc_mnc)
566 return
567 dbus_op = systembus_get(matching_op_path)
568 self.log('Registering with operator', matching_op_path, mcc_mnc)
Pau Espin Pedrol9f59b822017-11-07 17:50:52 +0100569 try:
570 dbus_call_dismiss_error(self, 'org.ofono.Error.InProgress', dbus_op.Register)
571 except GLib.Error as e:
572 if Gio.DBusError.is_remote_error(e) and Gio.DBusError.get_remote_error(e) == 'org.ofono.Error.NotSupported':
573 self.log('modem does not support manual registering, attempting automatic registering')
574 self.scan_cb_register_automatic(scanned_operators, mcc_mnc)
575 return
576 raise e
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200577
Pau Espin Pedrol6680ef22017-09-11 01:24:05 +0200578 def cancel_pending_dbus_methods(self):
579 self.cancellable.cancel()
580 # Cancel op is applied as a signal coming from glib mainloop, so we
581 # need to run it and wait for the callbacks to handle cancellations.
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200582 MainLoop.poll()
Pau Espin Pedrole685c622017-10-04 18:30:22 +0200583 # once it has been triggered, create a new one for next operation:
584 self.cancellable = Gio.Cancellable.new()
Pau Espin Pedrol6680ef22017-09-11 01:24:05 +0200585
Pau Espin Pedrol7aef3862017-11-23 12:15:55 +0100586 def power_off(self):
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100587 if self.dbus.has_interface(I_CONNMGR) and self.is_attached():
588 self.detach()
Pau Espin Pedrol7aef3862017-11-23 12:15:55 +0100589 self.set_online(False)
590 self.set_powered(False)
591 req_ifaces = self._required_ifaces()
592 for iface in req_ifaces:
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200593 MainLoop.wait(self, lambda: not self.dbus.has_interface(iface), timeout=10)
Pau Espin Pedrol7aef3862017-11-23 12:15:55 +0100594
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200595 def power_cycle(self):
596 'Power the modem and put it online, power cycle it if it was already on'
Pau Espin Pedrole0f49862017-11-23 11:37:34 +0100597 req_ifaces = self._required_ifaces()
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200598 if self.is_powered():
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200599 self.dbg('Power cycling')
Pau Espin Pedrol7aef3862017-11-23 12:15:55 +0100600 self.power_off()
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200601 else:
602 self.dbg('Powering on')
Neels Hofmeyrb3daaea2017-04-09 14:18:34 +0200603 self.set_powered()
Pau Espin Pedrolb9955762017-05-02 09:39:27 +0200604 self.set_online()
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200605 MainLoop.wait(self, self.dbus.has_interface, *req_ifaces, timeout=10)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200606
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200607 def connect(self, mcc_mnc=None):
608 'Connect to MCC+MNC'
609 if (mcc_mnc is not None) and (len(mcc_mnc) != 2 or None in mcc_mnc):
Pau Espin Pedrolcc5b5a22017-06-13 16:55:31 +0200610 raise log.Error('mcc_mnc value is invalid. It should be None or contain both valid mcc and mnc values:', mcc_mnc=mcc_mnc)
Pau Espin Pedrol6680ef22017-09-11 01:24:05 +0200611 # if test called connect() before and async scanning has not finished, we need to get rid of it:
612 self.cancel_pending_dbus_methods()
Pau Espin Pedrol0e57aad2017-05-29 14:25:22 +0200613 self.power_cycle()
614 self.register_attempts = 0
615 if self.is_connected(mcc_mnc):
616 self.log('Already registered with', mcc_mnc if mcc_mnc else 'default network')
617 else:
618 self.log('Connect to', mcc_mnc if mcc_mnc else 'default network')
619 self.schedule_scan_register(mcc_mnc)
620
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100621 def is_attached(self):
622 connmgr = self.dbus.interface(I_CONNMGR)
623 prop = connmgr.GetProperties()
624 attached = prop.get('Attached')
625 self.dbg('attached:', attached)
626 return attached
627
628 def attach(self, allow_roaming=False):
629 self.dbg('attach')
630 if self.is_attached():
631 self.detach()
632 connmgr = self.dbus.interface(I_CONNMGR)
Holger Hans Peter Freyther34dce0e2019-02-27 04:34:00 +0000633 connmgr.SetProperty('RoamingAllowed', Variant('b', allow_roaming))
634 connmgr.SetProperty('Powered', Variant('b', True))
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100635
636 def detach(self):
637 self.dbg('detach')
638 connmgr = self.dbus.interface(I_CONNMGR)
Holger Hans Peter Freyther34dce0e2019-02-27 04:34:00 +0000639 connmgr.SetProperty('RoamingAllowed', Variant('b', False))
640 connmgr.SetProperty('Powered', Variant('b', False))
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100641 connmgr.DeactivateAll()
642 connmgr.ResetContexts() # Requires Powered=false
643
644 def activate_context(self, apn='internet', user='ogt', pwd='', protocol='ip'):
Pau Espin Pedrolb05e36a2017-12-15 12:39:36 +0100645 self.dbg('activate_context', apn=apn, user=user, protocol=protocol)
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100646
647 connmgr = self.dbus.interface(I_CONNMGR)
648 ctx_path = connmgr.AddContext('internet')
649
650 ctx = systembus_get(ctx_path)
651 ctx.SetProperty('AccessPointName', Variant('s', apn))
652 ctx.SetProperty('Username', Variant('s', user))
653 ctx.SetProperty('Password', Variant('s', pwd))
654 ctx.SetProperty('Protocol', Variant('s', protocol))
655
656 # Activate can only be called after we are attached
657 ctx.SetProperty('Active', Variant('b', True))
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200658 MainLoop.wait(self, lambda: ctx.GetProperties()['Active'] == True)
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100659 self.log('context activated', path=ctx_path, apn=apn, user=user, properties=ctx.GetProperties())
660 return ctx_path
661
662 def deactivate_context(self, ctx_id):
Pau Espin Pedrol263dd3b2018-02-13 16:53:51 +0100663 self.dbg('deactivate_context', path=ctx_id)
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100664 ctx = systembus_get(ctx_id)
665 ctx.SetProperty('Active', Variant('b', False))
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200666 MainLoop.wait(self, lambda: ctx.GetProperties()['Active'] == False)
Pau Espin Pedrolcdac2972018-02-16 15:14:32 +0100667 self.dbg('deactivate_context active=false, removing', path=ctx_id)
668 connmgr = self.dbus.interface(I_CONNMGR)
669 connmgr.RemoveContext(ctx_id)
Pau Espin Pedrolb05aa3c2018-02-16 15:03:50 +0100670 self.log('context deactivated', path=ctx_id)
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100671
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +0200672 def run_netns_wait(self, name, popen_args):
673 proc = process.NetNSProcess(name, self.run_dir.new_dir(name), self.netns(), popen_args,
674 env={})
Pau Espin Pedrol79df7392018-11-12 18:15:30 +0100675 proc.launch_sync()
Pau Espin Pedrol2bcd3462020-03-05 18:30:37 +0100676 return proc
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +0200677
678 def setup_context_data_plane(self, ctx_id):
679 self.dbg('setup_context_data', path=ctx_id)
680 ctx = systembus_get(ctx_id)
681 ctx_settings = ctx.GetProperties().get('Settings', None)
682 if not ctx_settings:
683 raise log.Error('%s no Settings found! No way to get iface!' % ctx_id)
684 iface = ctx_settings.get('Interface', None)
685 if not iface:
686 raise log.Error('%s Settings contains no iface! %r' % (ctx_id, repr(ctx_settings)))
Pau Espin Pedrol4c8cd7b2019-04-04 16:08:27 +0200687 util.move_iface_to_netns(iface, self.netns(), self.run_dir.new_dir('move_netns'))
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +0200688 self.run_netns_wait('ifup', ('ip', 'link', 'set', 'dev', iface, 'up'))
689 self.run_netns_wait('dhcp', ('udhcpc', '-q', '-i', iface))
690
Neels Hofmeyr8c7477f2017-05-25 04:33:53 +0200691 def sms_send(self, to_msisdn_or_modem, *tokens):
692 if isinstance(to_msisdn_or_modem, Modem):
693 to_msisdn = to_msisdn_or_modem.msisdn
694 tokens = list(tokens)
695 tokens.append('to ' + to_msisdn_or_modem.name())
696 else:
697 to_msisdn = str(to_msisdn_or_modem)
Pau Espin Pedrol996651a2017-05-30 15:13:29 +0200698 msg = sms.Sms(self.msisdn, to_msisdn, 'from ' + self.name(), *tokens)
699 self.log('sending sms to MSISDN', to_msisdn, sms=msg)
Neels Hofmeyr896f08f2017-05-24 20:17:26 +0200700 mm = self.dbus.interface(I_SMS)
Pau Espin Pedrol996651a2017-05-30 15:13:29 +0200701 mm.SendMessage(to_msisdn, str(msg))
702 return msg
Neels Hofmeyrb3daaea2017-04-09 14:18:34 +0200703
704 def _on_incoming_message(self, message, info):
Neels Hofmeyr2e41def2017-05-06 22:42:57 +0200705 self.log('Incoming SMS:', repr(message))
Neels Hofmeyrf49c7da2017-05-06 22:43:32 +0200706 self.dbg(info=info)
Neels Hofmeyrfec7d162017-05-02 16:29:09 +0200707 self.sms_received_list.append((message, info))
Neels Hofmeyrb3daaea2017-04-09 14:18:34 +0200708
Pau Espin Pedrol996651a2017-05-30 15:13:29 +0200709 def sms_was_received(self, sms_obj):
Neels Hofmeyrfec7d162017-05-02 16:29:09 +0200710 for msg, info in self.sms_received_list:
Pau Espin Pedrol996651a2017-05-30 15:13:29 +0200711 if sms_obj.matches(msg):
Neels Hofmeyr2e41def2017-05-06 22:42:57 +0200712 self.log('SMS received as expected:', repr(msg))
Neels Hofmeyrf49c7da2017-05-06 22:43:32 +0200713 self.dbg(info=info)
Neels Hofmeyrfec7d162017-05-02 16:29:09 +0200714 return True
715 return False
Neels Hofmeyrb3daaea2017-04-09 14:18:34 +0200716
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200717 def call_id_list(self):
Pau Espin Pedrole02158f2019-02-13 19:38:09 +0100718 li = [call.dbuspath for call in self.call_list]
719 self.dbg('call_id_list: %r' % li)
720 return li
721
722 def call_find_by_id(self, id):
723 for call in self.call_list:
724 if call.dbuspath == id:
725 return call
726 return None
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200727
728 def call_dial(self, to_msisdn_or_modem):
729 if isinstance(to_msisdn_or_modem, Modem):
730 to_msisdn = to_msisdn_or_modem.msisdn
731 else:
732 to_msisdn = str(to_msisdn_or_modem)
733 self.dbg('Dialing:', to_msisdn)
734 cmgr = self.dbus.interface(I_CALLMGR)
735 call_obj_path = cmgr.Dial(to_msisdn, 'default')
Pau Espin Pedrole02158f2019-02-13 19:38:09 +0100736 if self.call_find_by_id(call_obj_path) is None:
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200737 self.dbg('Adding %s to call list' % call_obj_path)
Pau Espin Pedrole02158f2019-02-13 19:38:09 +0100738 self.call_list.append(ModemCall(self, call_obj_path))
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200739 else:
740 self.dbg('Dial returned already existing call')
741 return call_obj_path
742
743 def _find_call_msisdn_state(self, msisdn, state):
744 cmgr = self.dbus.interface(I_CALLMGR)
745 ret = cmgr.GetCalls()
746 for obj_path, props in ret:
747 if props['LineIdentification'] == msisdn and props['State'] == state:
748 return obj_path
749 return None
750
751 def call_wait_incoming(self, caller_msisdn_or_modem, timeout=60):
752 if isinstance(caller_msisdn_or_modem, Modem):
753 caller_msisdn = caller_msisdn_or_modem.msisdn
754 else:
755 caller_msisdn = str(caller_msisdn_or_modem)
756 self.dbg('Waiting for incoming call from:', caller_msisdn)
Pau Espin Pedrol9a4631c2018-03-28 19:17:34 +0200757 MainLoop.wait(self, lambda: self._find_call_msisdn_state(caller_msisdn, 'incoming') is not None, timeout=timeout)
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200758 return self._find_call_msisdn_state(caller_msisdn, 'incoming')
759
760 def call_answer(self, call_id):
761 self.dbg('Answer call %s' % call_id)
762 assert self.call_state(call_id) == 'incoming'
763 call_dbus_obj = systembus_get(call_id)
764 call_dbus_obj.Answer()
Pau Espin Pedrol4d7f7702019-02-13 19:30:38 +0100765 self.dbg('Answered call %s' % call_id)
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200766
767 def call_hangup(self, call_id):
768 self.dbg('Hang up call %s' % call_id)
769 call_dbus_obj = systembus_get(call_id)
770 call_dbus_obj.Hangup()
771
772 def call_is_active(self, call_id):
773 return self.call_state(call_id) == 'active'
774
775 def call_state(self, call_id):
Pau Espin Pedrolccb1bc62018-04-22 12:58:08 +0200776 try:
777 call_dbus_obj = systembus_get(call_id)
778 props = call_dbus_obj.GetProperties()
779 state = props.get('State')
Holger Hans Peter Freyther34dce0e2019-02-27 04:34:00 +0000780 except Exception:
Pau Espin Pedrolccb1bc62018-04-22 12:58:08 +0200781 self.log('asking call state for non existent call')
782 log.log_exn()
783 state = 'disconnected'
Pau Espin Pedrol32e9d8c2019-02-13 17:40:31 +0100784 self.dbg('call state: %s' % state, call_id=call_id)
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200785 return state
786
787 def _on_callmgr_call_added(self, obj_path, properties):
788 self.dbg('%r.CallAdded() -> %s=%r' % (I_CALLMGR, obj_path, repr(properties)))
Pau Espin Pedrole02158f2019-02-13 19:38:09 +0100789 if self.call_find_by_id(obj_path) is None:
790 self.call_list.append(ModemCall(self, obj_path))
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200791 else:
792 self.dbg('Call already exists %r' % obj_path)
793
794 def _on_callmgr_call_removed(self, obj_path):
795 self.dbg('%r.CallRemoved() -> %s' % (I_CALLMGR, obj_path))
Pau Espin Pedrole02158f2019-02-13 19:38:09 +0100796 call_obj = self.call_find_by_id(obj_path)
797 if call_obj is not None:
798 self.call_list.remove(call_obj)
799 call_obj.cleanup()
Pau Espin Pedrold71edd12017-10-06 13:53:54 +0200800 else:
801 self.dbg('Trying to remove non-existing call %r' % obj_path)
802
803 def _on_callmgr_property_changed(self, name, value):
804 self.dbg('%r.PropertyChanged() -> %s=%s' % (I_CALLMGR, name, value))
805
Pau Espin Pedrolde899612017-11-23 17:18:40 +0100806 def _on_connmgr_property_changed(self, name, value):
807 self.dbg('%r.PropertyChanged() -> %s=%s' % (I_CONNMGR, name, value))
808
Pau Espin Pedrolee6e4912017-09-05 18:46:34 +0200809 def info(self, keys=('Manufacturer', 'Model', 'Revision', 'Serial')):
Neels Hofmeyrb8011692017-05-29 03:45:24 +0200810 props = self.properties()
811 return ', '.join(['%s: %r'%(k,props.get(k)) for k in keys])
812
813 def log_info(self, *args, **kwargs):
814 self.log(self.info(*args, **kwargs))
815
Pau Espin Pedrol03983aa2017-06-12 15:31:27 +0200816 def ussd_send(self, command):
817 ss = self.dbus.interface(I_SS)
818 service_type, response = ss.Initiate(command)
819 return response
820
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200821# vim: expandtab tabstop=4 shiftwidth=4