modem: Identify modems by sysfs path instead of ofono dbus path

ofono dbus paths are non-deterministic and can change over time for a
given modem. For instance when ofono is restartd or if a modem crashes
and the object is destroyed and re-announced by udev.

Requires at least ofono 1df92289d4e09a1e2db0b189b5153a4c238f98f1, which
implemented the feature to export the sysfs path to modem properties.

Related: OS#2509

Change-Id: Ibc45a196abadded2706dc9d57b6a3a796b43a201
This commit is contained in:
Pau Espin 2018-02-23 17:00:09 +01:00
parent b2a94e8430
commit e25cf04aeb
2 changed files with 19 additions and 9 deletions

View File

@ -67,16 +67,16 @@ arfcn:
band: GSM-1900
modem:
- label: sierra_1
path: '/sierra_1'
- label: sierra_1st
path: '/sys/devices/pci0000:00/0000:00:12.2/usb1/1-1/1-1.2'
imsi: '901700000009031'
ki: '80A37E6FDEA931EAC92FFA5F671EFEAD'
auth_algo: 'comp128v1'
ciphers: [a5_0, a5_1]
features: ['sms', 'voice', 'ussd', 'gprs']
- label: sierra_2
path: '/sierra_2'
- label: sierra_2nd
path: '/sys/devices/pci0000:00/0000:00:12.2/usb1/1-1/1-1.3'
imsi: '901700000009029'
ki: '00969E283349D354A8239E877F2E0866'
auth_algo: 'comp128v1'
@ -84,7 +84,7 @@ modem:
features: ['sms', 'voice', 'ussd', 'gprs']
- label: ec20
path: '/gobi_0'
path: '/sys/devices/pci0000:00/0000:00:12.2/usb1/1-1/1-1.6'
imsi: '901700000009030'
ki: 'BB70807226393CDBAC8DD3439FF54252'
auth_algo: 'comp128v1'
@ -92,7 +92,7 @@ modem:
features: ['sms', 'ussd', 'gprs']
- label: gobi2k
path: '/gobi_3'
path: '/sys/devices/pci0000:00/0000:00:12.2/usb1/1-1/1-1.5'
imsi: '901700000009032'
ki: '2F70DCA43C45ACB97E947FDD0C7CA30A'
auth_algo: 'comp128v1'

View File

@ -92,6 +92,14 @@ def list_modems():
root = systembus_get('/')
return sorted(root.GetModems())
def get_dbuspath_from_syspath(syspath):
modems = list_modems()
for dbuspath, props in modems:
if props.get('SystemPath', '') == syspath:
return dbuspath
raise ValueError('could not find %s in modem list: %s' % (syspath, modems))
def _async_result_handler(obj, result, user_data):
'''Generic callback dispatcher called from glib loop when an async method
call has returned. This callback is set up by method dbus_async_call.'''
@ -341,10 +349,12 @@ class Modem(log.Origin):
def __init__(self, conf):
self.conf = conf
self.path = conf.get('path')
super().__init__(log.C_TST, self.path)
self.syspath = conf.get('path')
self.dbuspath = get_dbuspath_from_syspath(self.syspath)
super().__init__(log.C_TST, self.dbuspath)
self.dbg('creating from syspath %s', self.syspath)
self.sms_received_list = []
self.dbus = ModemDbusInteraction(self.path)
self.dbus = ModemDbusInteraction(self.dbuspath)
self.register_attempts = 0
self.call_list = []
# one Cancellable can handle several concurrent methods.