Review at  https://gerrit.osmocom.org/7274

modem: get IMSI from ofono

There's no need to specify the IMSI manually in resource config
and it's also prone to errors. Let's take it from ofono.
Add a 'sim' feature to allow modem to auto-discover it,
otherwise if not supported leave that feature out of the config for that
modem and an imsi can still be manually providen.

Change-Id: I20f9e8d97775293925205e4ea576d814214bf1a8
---
M example/resources.conf
M src/osmo_gsm_tester/modem.py
M src/osmo_gsm_tester/schema.py
3 files changed, 25 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/74/7274/1

diff --git a/example/resources.conf b/example/resources.conf
index fb2ac9f..cb730f5 100644
--- a/example/resources.conf
+++ b/example/resources.conf
@@ -69,32 +69,28 @@
 modem:
 - 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']
+  features: ['sms', 'voice', 'ussd', 'gprs', 'sim']
 
 - 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'
   ciphers: [a5_0, a5_1]
-  features: ['sms', 'voice', 'ussd', 'gprs']
+  features: ['sms', 'voice', 'ussd', 'gprs', 'sim']
 
 - label: ec20
   path: '/sys/devices/pci0000:00/0000:00:12.2/usb1/1-1/1-1.6'
-  imsi: '901700000009030'
   ki: 'BB70807226393CDBAC8DD3439FF54252'
   auth_algo: 'comp128v1'
   ciphers: [a5_0, a5_1]
-  features: ['sms', 'ussd', 'gprs']
+  features: ['sms', 'ussd', 'gprs', 'sim']
 
 - label: gobi2k
   path: '/sys/devices/pci0000:00/0000:00:12.2/usb1/1-1/1-1.5'
-  imsi: '901700000009032'
   ki: '2F70DCA43C45ACB97E947FDD0C7CA30A'
   auth_algo: 'comp128v1'
   ciphers: [a5_0, a5_1]
-  features: ['gprs']
+  features: ['gprs', 'sim']
diff --git a/src/osmo_gsm_tester/modem.py b/src/osmo_gsm_tester/modem.py
index 96b65d8..7fcf134 100644
--- a/src/osmo_gsm_tester/modem.py
+++ b/src/osmo_gsm_tester/modem.py
@@ -41,6 +41,7 @@
 I_CALLMGR = 'org.ofono.VoiceCallManager'
 I_CALL = 'org.ofono.VoiceCall'
 I_SS = 'org.ofono.SupplementaryServices'
+I_SIMMGR = 'org.ofono.SimManager'
 
 # See https://github.com/intgr/ofono/blob/master/doc/network-api.txt#L78
 NETREG_ST_REGISTERED = 'registered'
@@ -342,6 +343,7 @@
     msisdn = None
     sms_received_list = None
     _ki = None
+    _imsi = None
 
     CTX_PROT_IPv4 = 'ip'
     CTX_PROT_IPv6 = 'ipv6'
@@ -423,10 +425,23 @@
         self.msisdn = msisdn
 
     def imsi(self):
-        imsi = self.conf.get('imsi')
-        if not imsi:
-            raise log.Error('No IMSI')
-        return imsi
+        if self._imsi is None:
+            if 'sim' in self.features():
+                if not self.is_powered():
+                        self.set_powered()
+                # wait for SimManager iface to appear after we power on
+                event_loop.wait(self, self.dbus.has_interface, I_SIMMGR, 
timeout=10)
+                simmgr = self.dbus.interface(I_SIMMGR)
+                # If properties are requested quickly, it may happen that Sim 
property is still not there.
+                event_loop.wait(self, lambda: 
simmgr.GetProperties().get('SubscriberIdentity', None) is not None, timeout=10)
+                props = simmgr.GetProperties()
+                self.dbg('got SIM properties', props)
+                self._imsi = props.get('SubscriberIdentity', None)
+            else:
+                self._imsi = self.conf.get('imsi')
+            if self._imsi is None:
+                raise log.Error('No IMSI')
+        return self._imsi
 
     def set_ki(self, ki):
         self._ki = ki
@@ -447,6 +462,7 @@
         req_ifaces += (I_SMS,) if 'sms' in self.features() else ()
         req_ifaces += (I_SS,) if 'ussd' in self.features() else ()
         req_ifaces += (I_CONNMGR,) if 'gprs' in self.features() else ()
+        req_ifaces += (I_SIMMGR,) if 'sim' in self.features() else ()
         return req_ifaces
 
     def _on_netreg_property_changed(self, name, value):
diff --git a/src/osmo_gsm_tester/schema.py b/src/osmo_gsm_tester/schema.py
index 6c0b2b7..72649cc 100644
--- a/src/osmo_gsm_tester/schema.py
+++ b/src/osmo_gsm_tester/schema.py
@@ -95,7 +95,7 @@
     raise ValueError('Unknown Cipher value: %r' % val)
 
 def modem_feature(val):
-    if val in ('sms', 'gprs', 'voice', 'ussd'):
+    if val in ('sms', 'gprs', 'voice', 'ussd', 'sim'):
         return
     raise ValueError('Unknown Modem Feature: %r' % val)
 

-- 
To view, visit https://gerrit.osmocom.org/7274
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I20f9e8d97775293925205e4ea576d814214bf1a8
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de>

Reply via email to