1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import dbus
6import dbus.types
7import time
8
9from autotest_lib.client.cros.cellular import mm1_constants
10from autotest_lib.client.cros.cellular.pseudomodem import modem_3gpp
11from autotest_lib.client.cros.cellular.pseudomodem import sim
12from autotest_lib.client.cros.cellular.pseudomodem import utils as pm_utils
13
14I_ACTIVATION_TEST = 'Interface.LTEActivationTest'
15
16class TestModem(modem_3gpp.Modem3gpp):
17    """
18    Base class for the custom 3GPP fake modems that are defined in this test.
19    This modem boots up as unprovisioned & becomes activated only if it has
20    been explicitly activated by calling CompleteCellularActivation
21
22    """
23    def __init__(self,
24                 state_machine_factory=None,
25                 bus=None,
26                 device='pseudomodem0',
27                 index=0,
28                 roaming_networks=None,
29                 config=None):
30        super(TestModem, self).__init__(state_machine_factory,
31                                        bus=bus,
32                                        device=device,
33                                        roaming_networks=roaming_networks,
34                                        config=config)
35        # Update the registered susbscription state as unprovisioned
36        # for this activation test
37        self._cached_registered_subscription_state = (
38                mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_UNPROVISIONED)
39
40
41    def _InitializeProperties(self):
42        props = modem_3gpp.Modem3gpp._InitializeProperties(self)
43        modem_props = props[mm1_constants.I_MODEM]
44        modem_props['OwnNumbers'] = ['0000000000']
45        modem_props['AccessTechnologies'] = dbus.types.UInt32(
46            mm1_constants.MM_MODEM_ACCESS_TECHNOLOGY_LTE)
47        modem_props['ModemCapabilities'] = dbus.types.UInt32(
48            mm1_constants.MM_MODEM_CAPABILITY_LTE)
49        modem_props['CurrentCapabilities'] = dbus.types.UInt32(
50            mm1_constants.MM_MODEM_CAPABILITY_LTE)
51
52        # For the purposes of this test, introduce a property to help
53        # verify that a reset has taken place. Expose this under a test
54        # specific interface.
55        if hasattr(self, '_properties'):
56            reset_called = \
57                self._properties[I_ACTIVATION_TEST]['ResetCalled']
58        else:
59            reset_called = False
60        props[I_ACTIVATION_TEST] = {
61            'ResetCalled' : dbus.types.Boolean(reset_called)
62        }
63        return props
64
65
66    @pm_utils.log_dbus_method()
67    def Reset(self):
68        self.Set(
69            I_ACTIVATION_TEST, 'ResetCalled', dbus.types.Boolean(True))
70        modem_3gpp.Modem3gpp.Reset(self)
71
72
73class TestSIM(sim.SIM):
74    """ SIM instantiated with the default test network, for ease of use. """
75    def __init__(self):
76        # Shill's activating ICCID store tracks which SIM identifiers are in
77        # the process of activation. If we use the same SIM identifier for
78        # every test pass, then a failed test may leave a stale entry in the
79        # activating ICCD store which will erroneously mark the SIM as pending
80        # activation. So, to avoid this, try to use a unique SIM identifier
81        # each time.
82        sim_identifier = int(time.time())
83        sim.SIM.__init__(
84                self,
85                sim.SIM.Carrier('test'),
86                mm1_constants.MM_MODEM_ACCESS_TECHNOLOGY_LTE,
87                msin=str(sim_identifier))
88