• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <radio_hidl_hal_utils_v1_0.h>
18 
19 /*
20  * Test IRadio.getIccCardStatus() for the response returned.
21  */
TEST_F(RadioHidlTest,getIccCardStatus)22 TEST_F(RadioHidlTest, getIccCardStatus) {
23     EXPECT_LE(cardStatus.applications.size(), (unsigned int)RadioConst::CARD_MAX_APPS);
24     EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, (int)RadioConst::CARD_MAX_APPS);
25     EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, (int)RadioConst::CARD_MAX_APPS);
26     EXPECT_LT(cardStatus.imsSubscriptionAppIndex, (int)RadioConst::CARD_MAX_APPS);
27 }
28 
29 /*
30  * Test IRadio.supplyIccPinForApp() for the response returned
31  */
TEST_F(RadioHidlTest,supplyIccPinForApp)32 TEST_F(RadioHidlTest, supplyIccPinForApp) {
33     serial = GetRandomSerialNumber();
34 
35     // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
36     // 3GPP2 apps only
37     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
38         if (cardStatus.applications[i].appType == AppType::SIM ||
39             cardStatus.applications[i].appType == AppType::USIM ||
40             cardStatus.applications[i].appType == AppType::RUIM ||
41             cardStatus.applications[i].appType == AppType::CSIM) {
42             radio->supplyIccPinForApp(serial, hidl_string("test1"),
43                                       cardStatus.applications[i].aidPtr);
44             EXPECT_EQ(std::cv_status::no_timeout, wait());
45             EXPECT_EQ(serial, radioRsp->rspInfo.serial);
46             EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
47             ASSERT_TRUE(CheckAnyOfErrors(
48                 radioRsp->rspInfo.error,
49                 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
50         }
51     }
52 }
53 
54 /*
55  * Test IRadio.supplyIccPukForApp() for the response returned.
56  */
TEST_F(RadioHidlTest,supplyIccPukForApp)57 TEST_F(RadioHidlTest, supplyIccPukForApp) {
58     serial = GetRandomSerialNumber();
59 
60     // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
61     // 3GPP2 apps only
62     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
63         if (cardStatus.applications[i].appType == AppType::SIM ||
64             cardStatus.applications[i].appType == AppType::USIM ||
65             cardStatus.applications[i].appType == AppType::RUIM ||
66             cardStatus.applications[i].appType == AppType::CSIM) {
67             radio->supplyIccPukForApp(serial, hidl_string("test1"), hidl_string("test2"),
68                                       cardStatus.applications[i].aidPtr);
69             EXPECT_EQ(std::cv_status::no_timeout, wait());
70             EXPECT_EQ(serial, radioRsp->rspInfo.serial);
71             EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
72             ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::PASSWORD_INCORRECT,
73                                                                    RadioError::INVALID_SIM_STATE}));
74         }
75     }
76 }
77 
78 /*
79  * Test IRadio.supplyIccPin2ForApp() for the response returned.
80  */
TEST_F(RadioHidlTest,supplyIccPin2ForApp)81 TEST_F(RadioHidlTest, supplyIccPin2ForApp) {
82     serial = GetRandomSerialNumber();
83 
84     // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
85     // 3GPP2 apps only
86     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
87         if (cardStatus.applications[i].appType == AppType::SIM ||
88             cardStatus.applications[i].appType == AppType::USIM ||
89             cardStatus.applications[i].appType == AppType::RUIM ||
90             cardStatus.applications[i].appType == AppType::CSIM) {
91             radio->supplyIccPin2ForApp(serial, hidl_string("test1"),
92                                        cardStatus.applications[i].aidPtr);
93             EXPECT_EQ(std::cv_status::no_timeout, wait());
94             EXPECT_EQ(serial, radioRsp->rspInfo.serial);
95             EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
96             ASSERT_TRUE(
97                 CheckAnyOfErrors(radioRsp->rspInfo.error,
98                                  {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED,
99                                   RadioError::SIM_PUK2}));
100         }
101     }
102 }
103 
104 /*
105  * Test IRadio.supplyIccPuk2ForApp() for the response returned.
106  */
TEST_F(RadioHidlTest,supplyIccPuk2ForApp)107 TEST_F(RadioHidlTest, supplyIccPuk2ForApp) {
108     serial = GetRandomSerialNumber();
109 
110     // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
111     // 3GPP2 apps only
112     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
113         if (cardStatus.applications[i].appType == AppType::SIM ||
114             cardStatus.applications[i].appType == AppType::USIM ||
115             cardStatus.applications[i].appType == AppType::RUIM ||
116             cardStatus.applications[i].appType == AppType::CSIM) {
117             radio->supplyIccPuk2ForApp(serial, hidl_string("test1"), hidl_string("test2"),
118                                        cardStatus.applications[i].aidPtr);
119             EXPECT_EQ(std::cv_status::no_timeout, wait());
120             EXPECT_EQ(serial, radioRsp->rspInfo.serial);
121             EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
122             ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::PASSWORD_INCORRECT,
123                                                                    RadioError::INVALID_SIM_STATE}));
124         }
125     }
126 }
127 
128 /*
129  * Test IRadio.changeIccPinForApp() for the response returned.
130  */
TEST_F(RadioHidlTest,changeIccPinForApp)131 TEST_F(RadioHidlTest, changeIccPinForApp) {
132     serial = GetRandomSerialNumber();
133 
134     // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
135     // 3GPP2 apps only
136     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
137         if (cardStatus.applications[i].appType == AppType::SIM ||
138             cardStatus.applications[i].appType == AppType::USIM ||
139             cardStatus.applications[i].appType == AppType::RUIM ||
140             cardStatus.applications[i].appType == AppType::CSIM) {
141             radio->changeIccPinForApp(serial, hidl_string("test1"), hidl_string("test2"),
142                                       cardStatus.applications[i].aidPtr);
143             EXPECT_EQ(std::cv_status::no_timeout, wait());
144             EXPECT_EQ(serial, radioRsp->rspInfo.serial);
145             EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
146             ASSERT_TRUE(CheckAnyOfErrors(
147                 radioRsp->rspInfo.error,
148                 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
149         }
150     }
151 }
152 
153 /*
154  * Test IRadio.changeIccPin2ForApp() for the response returned.
155  */
TEST_F(RadioHidlTest,changeIccPin2ForApp)156 TEST_F(RadioHidlTest, changeIccPin2ForApp) {
157     serial = GetRandomSerialNumber();
158 
159     // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
160     // 3GPP2 apps only
161     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
162         if (cardStatus.applications[i].appType == AppType::SIM ||
163             cardStatus.applications[i].appType == AppType::USIM ||
164             cardStatus.applications[i].appType == AppType::RUIM ||
165             cardStatus.applications[i].appType == AppType::CSIM) {
166             radio->changeIccPin2ForApp(serial, hidl_string("test1"), hidl_string("test2"),
167                                        cardStatus.applications[i].aidPtr);
168             EXPECT_EQ(std::cv_status::no_timeout, wait());
169             EXPECT_EQ(serial, radioRsp->rspInfo.serial);
170             EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
171             ASSERT_TRUE(
172                 CheckAnyOfErrors(radioRsp->rspInfo.error,
173                                  {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED,
174                                   RadioError::SIM_PUK2}));
175         }
176     }
177 }
178 
179 /*
180  * Test IRadio.getImsiForApp() for the response returned.
181  */
TEST_F(RadioHidlTest,getImsiForApp)182 TEST_F(RadioHidlTest, getImsiForApp) {
183     serial = GetRandomSerialNumber();
184 
185     // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
186     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
187         if (cardStatus.applications[i].appType == AppType::SIM ||
188             cardStatus.applications[i].appType == AppType::USIM ||
189             cardStatus.applications[i].appType == AppType::RUIM ||
190             cardStatus.applications[i].appType == AppType::CSIM) {
191             radio->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
192             EXPECT_EQ(std::cv_status::no_timeout, wait());
193             EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
194             EXPECT_EQ(serial, radioRsp->rspInfo.serial);
195             ASSERT_TRUE(
196                 CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::NONE}, CHECK_GENERAL_ERROR));
197 
198             // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
199             if (radioRsp->rspInfo.error == RadioError::NONE) {
200                 EXPECT_NE(radioRsp->imsi, hidl_string());
201                 EXPECT_GE((int)(radioRsp->imsi).size(), 6);
202                 EXPECT_LE((int)(radioRsp->imsi).size(), 15);
203             }
204         }
205     }
206 }
207 
208 /*
209  * Test IRadio.iccIOForApp() for the response returned.
210  */
TEST_F(RadioHidlTest,iccIOForApp)211 TEST_F(RadioHidlTest, iccIOForApp) {
212     serial = GetRandomSerialNumber();
213 
214     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
215         IccIo iccIo;
216         iccIo.command = 0xc0;
217         iccIo.fileId = 0x6f11;
218         iccIo.path = hidl_string("3F007FFF");
219         iccIo.p1 = 0;
220         iccIo.p2 = 0;
221         iccIo.p3 = 0;
222         iccIo.data = hidl_string();
223         iccIo.pin2 = hidl_string();
224         iccIo.aid = cardStatus.applications[i].aidPtr;
225 
226         radio->iccIOForApp(serial, iccIo);
227         EXPECT_EQ(std::cv_status::no_timeout, wait());
228         EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
229         EXPECT_EQ(serial, radioRsp->rspInfo.serial);
230     }
231 }
232 
233 /*
234  * Test IRadio.iccTransmitApduBasicChannel() for the response returned.
235  */
TEST_F(RadioHidlTest,iccTransmitApduBasicChannel)236 TEST_F(RadioHidlTest, iccTransmitApduBasicChannel) {
237     serial = GetRandomSerialNumber();
238     SimApdu msg;
239     memset(&msg, 0, sizeof(msg));
240     msg.data = hidl_string();
241 
242     radio->iccTransmitApduBasicChannel(serial, msg);
243     EXPECT_EQ(std::cv_status::no_timeout, wait());
244     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
245     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
246 
247     // TODO(sanketpadawe): Add test for error code
248 }
249 
250 /*
251  * Test IRadio.iccOpenLogicalChannel() for the response returned.
252  */
TEST_F(RadioHidlTest,iccOpenLogicalChannel)253 TEST_F(RadioHidlTest, iccOpenLogicalChannel) {
254     serial = GetRandomSerialNumber();
255     int p2 = 0x04;
256     // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
257     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
258         radio->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
259         EXPECT_EQ(std::cv_status::no_timeout, wait());
260         EXPECT_EQ(serial, radioRsp->rspInfo.serial);
261         EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
262     }
263 }
264 
265 /*
266  * Test IRadio.iccCloseLogicalChannel() for the response returned.
267  */
TEST_F(RadioHidlTest,iccCloseLogicalChannel)268 TEST_F(RadioHidlTest, iccCloseLogicalChannel) {
269     serial = GetRandomSerialNumber();
270     // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
271     radio->iccCloseLogicalChannel(serial, 0);
272     EXPECT_EQ(std::cv_status::no_timeout, wait());
273     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
274     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
275 
276     EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp->rspInfo.error);
277 }
278 
279 /*
280  * Test IRadio.iccTransmitApduLogicalChannel() for the response returned.
281  */
TEST_F(RadioHidlTest,iccTransmitApduLogicalChannel)282 TEST_F(RadioHidlTest, iccTransmitApduLogicalChannel) {
283     serial = GetRandomSerialNumber();
284     SimApdu msg;
285     memset(&msg, 0, sizeof(msg));
286     msg.data = hidl_string();
287 
288     radio->iccTransmitApduLogicalChannel(serial, msg);
289     EXPECT_EQ(std::cv_status::no_timeout, wait());
290     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
291     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
292 
293     // TODO(sanketpadawe): Add test for error code
294 }
295 
296 /*
297  * Test IRadio.requestIccSimAuthentication() for the response returned.
298  */
TEST_F(RadioHidlTest,requestIccSimAuthentication)299 TEST_F(RadioHidlTest, requestIccSimAuthentication) {
300     serial = GetRandomSerialNumber();
301 
302     // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
303     // or REQUEST_NOT_SUPPORTED returned as error.
304     for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
305         radio->requestIccSimAuthentication(serial, 0, hidl_string("test"),
306                                            cardStatus.applications[i].aidPtr);
307         EXPECT_EQ(std::cv_status::no_timeout, wait());
308         EXPECT_EQ(serial, radioRsp->rspInfo.serial);
309         EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
310         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::INVALID_ARGUMENTS,
311                                                                RadioError::REQUEST_NOT_SUPPORTED}));
312     }
313 }
314 
315 /*
316  * Test IRadio.supplyNetworkDepersonalization() for the response returned.
317  */
TEST_F(RadioHidlTest,supplyNetworkDepersonalization)318 TEST_F(RadioHidlTest, supplyNetworkDepersonalization) {
319     serial = GetRandomSerialNumber();
320 
321     radio->supplyNetworkDepersonalization(serial, hidl_string("test"));
322     EXPECT_EQ(std::cv_status::no_timeout, wait());
323     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
324     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
325 
326     if (cardStatus.cardState == CardState::ABSENT) {
327         ASSERT_TRUE(CheckAnyOfErrors(
328             radioRsp->rspInfo.error,
329             {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::INTERNAL_ERR,
330              RadioError::INVALID_SIM_STATE, RadioError::MODEM_ERR, RadioError::NO_MEMORY,
331              RadioError::PASSWORD_INCORRECT, RadioError::SIM_ABSENT, RadioError::SYSTEM_ERR}));
332     }
333 }
334