1#!/usr/bin/env python3
2#
3#   Copyright 2016 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17Tests for reading UE Identity
18"""
19import time
20from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError
21from acts.controllers.anritsu_lib.md8475a import MD8475A
22from acts.controllers.anritsu_lib.md8475a import UEIdentityType
23from acts.test_utils.tel.anritsu_utils import WAIT_TIME_ANRITSU_REG_AND_OPER
24from acts.test_utils.tel.anritsu_utils import read_ue_identity
25from acts.test_utils.tel.anritsu_utils import set_system_model_gsm
26from acts.test_utils.tel.anritsu_utils import set_system_model_lte
27from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma
28from acts.test_utils.tel.tel_defines import NETWORK_MODE_CDMA
29from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY
30from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS
31from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA
32from acts.test_utils.tel.tel_defines import RAT_1XRTT
33from acts.test_utils.tel.tel_defines import RAT_GSM
34from acts.test_utils.tel.tel_defines import RAT_LTE
35from acts.test_utils.tel.tel_defines import RAT_WCDMA
36from acts.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000
37from acts.test_utils.tel.tel_defines import RAT_FAMILY_GSM
38from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE
39from acts.test_utils.tel.tel_defines import RAT_FAMILY_UMTS
40from acts.test_utils.tel.tel_test_utils import ensure_network_rat
41from acts.test_utils.tel.tel_test_utils import ensure_phones_idle
42from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
43from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
44
45
46class TelLabUeIdentityTest(TelephonyBaseTest):
47
48    CELL_PARAM_FILE = 'C:\\MX847570\\CellParam\\ACTS\\2cell_param.wnscp'
49
50    def setup_class(self):
51        super().setup_class()
52        self.ad = self.android_devices[0]
53        self.md8475a_ip_address = self.user_params[
54            "anritsu_md8475a_ip_address"]
55        self.ad.sim_card = getattr(self.ad, "sim_card", None)
56
57        try:
58            self.anritsu = MD8475A(self.md8475a_ip_address)
59        except AnritsuError:
60            self.log.error("Error in connecting to Anritsu Simulator")
61            return False
62        return True
63
64    def setup_test(self):
65        ensure_phones_idle(self.log, self.android_devices)
66        toggle_airplane_mode(self.log, self.ad, True)
67        self.ad.adb.shell("setprop net.lte.ims.volte.provisioned 1",
68                          ignore_status=True)
69        return True
70
71    def teardown_test(self):
72        self.log.info("Stopping Simulation")
73        self.anritsu.stop_simulation()
74        toggle_airplane_mode(self.log, self.ad, True)
75        return True
76
77    def teardown_class(self):
78        self.anritsu.disconnect()
79        return True
80
81    def _read_identity(self, set_simulation_func, rat, identity_type):
82        try:
83            self.anritsu.reset()
84            self.anritsu.load_cell_paramfile(self.CELL_PARAM_FILE)
85            set_simulation_func(self.anritsu, self.user_params,
86                                self.ad.sim_card)
87            self.anritsu.start_simulation()
88
89            if rat == RAT_LTE:
90                preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA
91                rat_family = RAT_FAMILY_LTE
92            elif rat == RAT_WCDMA:
93                preferred_network_setting = NETWORK_MODE_GSM_UMTS
94                rat_family = RAT_FAMILY_UMTS
95            elif rat == RAT_GSM:
96                preferred_network_setting = NETWORK_MODE_GSM_ONLY
97                rat_family = RAT_FAMILY_GSM
98            elif rat == RAT_1XRTT:
99                preferred_network_setting = NETWORK_MODE_CDMA
100                rat_family = RAT_FAMILY_CDMA2000
101            else:
102                self.log.error("Invalid RAT - Please specify a valid RAT")
103                return False
104
105            self.ad.droid.telephonyToggleDataConnection(True)
106            if not ensure_network_rat(
107                    self.log,
108                    self.ad,
109                    preferred_network_setting,
110                    rat_family,
111                    toggle_apm_after_setting=True):
112                self.log.error(
113                    "Failed to set rat family {}, preferred network:{}".format(
114                        rat_family, preferred_network_setting))
115                return False
116            self.anritsu.wait_for_registration_state()
117            time.sleep(WAIT_TIME_ANRITSU_REG_AND_OPER)
118            identity = read_ue_identity(self.log, self.ad, self.anritsu,
119                                        identity_type)
120            if identity is None:
121                self.log.error("Phone {} Failed to get {}"
122                               .format(self.ad.serial, identity_type.value))
123                return False
124            else:
125                self.log.info("{}".format(identity))
126        except AnritsuError as e:
127            self.log.error("Error in connection with Anritsu Simulator: " +
128                           str(e))
129            return False
130        except Exception as e:
131            self.log.error("Exception during reading identity: " + str(e))
132            return False
133        return True
134
135    """ Tests Begin """
136
137    @TelephonyBaseTest.tel_test_wrap
138    def test_read_imsi_lte(self):
139        """Reading the IMSI of UE on LTE
140
141        Reads the IMSI of the UE when device is camped on LTE newtork
142
143        Steps:
144        1. Make Sure Phone is camped on LTE network
145        2. Send IMSI request from Anritsu
146        3. Display the IMSI returned by UE
147
148        Expected Result:
149        UE sends the correct IMSI to the Anritsu
150
151        Returns:
152            True if pass; False if fail
153        """
154        return self._read_identity(set_system_model_lte, RAT_LTE,
155                                   UEIdentityType.IMSI)
156
157    @TelephonyBaseTest.tel_test_wrap
158    def test_read_imei_lte(self):
159        """Reading the IMEI of UE on LTE
160
161        Reads the IMEI of the UE when device is camped on LTE newtork
162
163        Steps:
164        1. Make Sure Phone is camped on LTE network
165        2. Send IMEI request from Anritsu
166        3. Display the IMEI returned by UE
167
168        Expected Result:
169        UE sends the correct IMEI to the Anritsu
170
171        Returns:
172            True if pass; False if fail
173        """
174        return self._read_identity(set_system_model_lte, RAT_LTE,
175                                   UEIdentityType.IMEI)
176
177    @TelephonyBaseTest.tel_test_wrap
178    def test_read_imeisv_lte(self):
179        """Reading the IMEISV of UE on LTE
180
181        Reads the IMEISV of the UE when device is camped on LTE newtork
182
183        Steps:
184        1. Make Sure Phone is camped on LTE network
185        2. Send IMEISV request from Anritsu
186        3. Display the IMEISV returned by UE
187
188        Expected Result:
189        UE sends the correct IMEISV to the Anritsu
190
191        Returns:
192            True if pass; False if fail
193        """
194        return self._read_identity(set_system_model_lte, RAT_LTE,
195                                   UEIdentityType.IMEISV)
196
197    @TelephonyBaseTest.tel_test_wrap
198    def test_read_imsi_wcdma(self):
199        """Reading the IMSI of UE on WCDMA
200
201        Reads the IMSI of the UE when device is camped on WCDMA newtork
202
203        Steps:
204        1. Make Sure Phone is camped on WCDMA network
205        2. Send IMSI request from Anritsu
206        3. Display the IMSI returned by UE
207
208        Expected Result:
209        UE sends the correct IMSI to the Anritsu
210
211        Returns:
212            True if pass; False if fail
213        """
214        return self._read_identity(set_system_model_wcdma, RAT_WCDMA,
215                                   UEIdentityType.IMSI)
216
217    @TelephonyBaseTest.tel_test_wrap
218    def test_read_imei_wcdma(self):
219        """Reading the IMEI of UE on WCDMA
220
221        Reads the IMEI of the UE when device is camped on WCDMA newtork
222
223        Steps:
224        1. Make Sure Phone is camped on WCDMA network
225        2. Send IMEI request from Anritsu
226        3. Display the IMEI returned by UE
227
228        Expected Result:
229        UE sends the correct IMEI to the Anritsu
230
231        Returns:
232            True if pass; False if fail
233        """
234        return self._read_identity(set_system_model_wcdma, RAT_WCDMA,
235                                   UEIdentityType.IMEI)
236
237    @TelephonyBaseTest.tel_test_wrap
238    def test_read_imeisv_wcdma(self):
239        """Reading the IMEISV of UE on WCDMA
240
241        Reads the IMEISV of the UE when device is camped on WCDMA newtork
242
243        Steps:
244        1. Make Sure Phone is camped on WCDMA network
245        2. Send IMEISV request from Anritsu
246        3. Display the IMEISV returned by UE
247
248        Expected Result:
249        UE sends the correct IMEISV to the Anritsu
250
251        Returns:
252            True if pass; False if fail
253        """
254        return self._read_identity(set_system_model_wcdma, RAT_WCDMA,
255                                   UEIdentityType.IMEISV)
256
257    @TelephonyBaseTest.tel_test_wrap
258    def test_read_imsi_gsm(self):
259        """Reading the IMSI of UE on GSM
260
261        Reads the IMSI of the UE when device is camped on GSM newtork
262
263        Steps:
264        1. Make Sure Phone is camped on GSM network
265        2. Send IMSI request from Anritsu
266        3. Display the IMSI returned by UE
267
268        Expected Result:
269        UE sends the correct IMSI to the Anritsu
270
271        Returns:
272            True if pass; False if fail
273        """
274        return self._read_identity(set_system_model_gsm, RAT_GSM,
275                                   UEIdentityType.IMSI)
276
277    @TelephonyBaseTest.tel_test_wrap
278    def test_read_imei_gsm(self):
279        """Reading the IMEI of UE on GSM
280
281        Reads the IMEI of the UE when device is camped on GSM newtork
282
283        Steps:
284        1. Make Sure Phone is camped on GSM network
285        2. Send IMEI request from Anritsu
286        3. Display the IMEI returned by UE
287
288        Expected Result:
289        UE sends the correct IMEI to the Anritsu
290
291        Returns:
292            True if pass; False if fail
293        """
294        return self._read_identity(set_system_model_gsm, RAT_GSM,
295                                   UEIdentityType.IMEI)
296
297    @TelephonyBaseTest.tel_test_wrap
298    def test_read_imeisv_gsm(self):
299        """Reading the IMEISV of UE on GSM
300
301        Reads the IMEISV of the UE when device is camped on GSM newtork
302
303        Steps:
304        1. Make Sure Phone is camped on GSM network
305        2. Send IMEISV request from Anritsu
306        3. Display the IMEISV returned by UE
307
308        Expected Result:
309        UE sends the correct IMEISV to the Anritsu
310
311        Returns:
312            True if pass; False if fail
313        """
314        return self._read_identity(set_system_model_gsm, RAT_GSM,
315                                   UEIdentityType.IMEISV)
316
317    """ Tests End """
318