Introduce auth_algo modem config attribute

Algorithm to use to generate response for the challenge during
authentication time is hardcoded in the sim card and cannot be easily
changed. Thus specify in the config of each modem the algorithm used by
the SIM Card. This attribute is used add subscriber_add() time, when the
IMSI, KI and algorithm to use in the MSC to authenticate a given
subscriber is stored in the database. This way we can easily set up
a specific algorithm for each SimCard/Modem, in case different SimCards
are configured with different algorithms.

This can be used to specificially test different algorithms too. For
instance, let's imagine we have 2 simcards, one configured to use comp128v1
and another one with xor, and we create a test which ckecks that XOR is
algo is working fine. We don't want to accidentally select the modem
with comp128v1 in this case. Thus we can use this attribute to create a
scenario file matching 'auth_algo: xor' to ensure always the correct
modem is picked.

Change-Id: Ifdf74630afeb05452994bbc9eb62a745a1d745ce
diff --git a/src/osmo_gsm_tester/osmo_hlr.py b/src/osmo_gsm_tester/osmo_hlr.py
index 08de07c..0b763c7 100644
--- a/src/osmo_gsm_tester/osmo_hlr.py
+++ b/src/osmo_gsm_tester/osmo_hlr.py
@@ -114,8 +114,18 @@
         modem.set_msisdn(msisdn)
         subscriber_id = self.next_subscriber_id
         self.next_subscriber_id += 1
+
         if not algo:
-            algo = self.AUTH_ALGO_COMP128v1 if modem.ki() else self.AUTH_ALGO_NONE
+            alg_str = modem.auth_algo()
+            if alg_str is None or alg_str == 'none':
+                algo = self.AUTH_ALGO_NONE
+            elif alg_str == 'comp128v1':
+                algo = self.AUTH_ALGO_COMP128v1
+            elif alg_str == 'xor':
+                algo = self.AUTH_ALGO_XOR
+        if algo != self.AUTH_ALGO_NONE and not modem.ki():
+            raise log.Error("Auth algo %r selected and no KI specified" % algo)
+
         self.log('Add subscriber', msisdn=msisdn, imsi=modem.imsi(), subscriber_id=subscriber_id, algo=algo)
         conn = sqlite3.connect(self.db_file)
         try: