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 <android-base/logging.h>
18 #include <radio_hidl_hal_utils_v1_0.h>
19
20 /*
21 * Test IRadio.getIccCardStatus() for the response returned.
22 */
TEST_P(RadioHidlTest,getIccCardStatus)23 TEST_P(RadioHidlTest, getIccCardStatus) {
24 LOG(DEBUG) << "getIccCardStatus";
25 EXPECT_LE(cardStatus.applications.size(), (unsigned int)RadioConst::CARD_MAX_APPS);
26 EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, (int)RadioConst::CARD_MAX_APPS);
27 EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, (int)RadioConst::CARD_MAX_APPS);
28 EXPECT_LT(cardStatus.imsSubscriptionAppIndex, (int)RadioConst::CARD_MAX_APPS);
29 LOG(DEBUG) << "getIccCardStatus finished";
30 }
31
32 /*
33 * Test IRadio.supplyIccPinForApp() for the response returned
34 */
TEST_P(RadioHidlTest,supplyIccPinForApp)35 TEST_P(RadioHidlTest, supplyIccPinForApp) {
36 LOG(DEBUG) << "supplyIccPinForApp";
37 serial = GetRandomSerialNumber();
38
39 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
40 // 3GPP2 apps only
41 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
42 if (cardStatus.applications[i].appType == AppType::SIM ||
43 cardStatus.applications[i].appType == AppType::USIM ||
44 cardStatus.applications[i].appType == AppType::RUIM ||
45 cardStatus.applications[i].appType == AppType::CSIM) {
46 radio->supplyIccPinForApp(serial, hidl_string("test1"),
47 cardStatus.applications[i].aidPtr);
48 EXPECT_EQ(std::cv_status::no_timeout, wait());
49 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
50 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
51 ASSERT_TRUE(CheckAnyOfErrors(
52 radioRsp->rspInfo.error,
53 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
54 }
55 }
56 LOG(DEBUG) << "supplyIccPinForApp finished";
57 }
58
59 /*
60 * Test IRadio.supplyIccPukForApp() for the response returned.
61 */
TEST_P(RadioHidlTest,supplyIccPukForApp)62 TEST_P(RadioHidlTest, supplyIccPukForApp) {
63 LOG(DEBUG) << "supplyIccPukForApp";
64 serial = GetRandomSerialNumber();
65
66 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
67 // 3GPP2 apps only
68 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
69 if (cardStatus.applications[i].appType == AppType::SIM ||
70 cardStatus.applications[i].appType == AppType::USIM ||
71 cardStatus.applications[i].appType == AppType::RUIM ||
72 cardStatus.applications[i].appType == AppType::CSIM) {
73 radio->supplyIccPukForApp(serial, hidl_string("test1"), hidl_string("test2"),
74 cardStatus.applications[i].aidPtr);
75 EXPECT_EQ(std::cv_status::no_timeout, wait());
76 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
77 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
78 ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::PASSWORD_INCORRECT,
79 RadioError::INVALID_SIM_STATE}));
80 }
81 }
82 LOG(DEBUG) << "supplyIccPukForApp finished";
83 }
84
85 /*
86 * Test IRadio.supplyIccPin2ForApp() for the response returned.
87 */
TEST_P(RadioHidlTest,supplyIccPin2ForApp)88 TEST_P(RadioHidlTest, supplyIccPin2ForApp) {
89 LOG(DEBUG) << "supplyIccPin2ForApp";
90 serial = GetRandomSerialNumber();
91
92 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
93 // 3GPP2 apps only
94 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
95 if (cardStatus.applications[i].appType == AppType::SIM ||
96 cardStatus.applications[i].appType == AppType::USIM ||
97 cardStatus.applications[i].appType == AppType::RUIM ||
98 cardStatus.applications[i].appType == AppType::CSIM) {
99 radio->supplyIccPin2ForApp(serial, hidl_string("test1"),
100 cardStatus.applications[i].aidPtr);
101 EXPECT_EQ(std::cv_status::no_timeout, wait());
102 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
103 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
104 ASSERT_TRUE(
105 CheckAnyOfErrors(radioRsp->rspInfo.error,
106 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED,
107 RadioError::SIM_PUK2}));
108 }
109 }
110 LOG(DEBUG) << "supplyIccPin2ForApp finished";
111 }
112
113 /*
114 * Test IRadio.supplyIccPuk2ForApp() for the response returned.
115 */
TEST_P(RadioHidlTest,supplyIccPuk2ForApp)116 TEST_P(RadioHidlTest, supplyIccPuk2ForApp) {
117 LOG(DEBUG) << "supplyIccPuk2ForApp";
118 serial = GetRandomSerialNumber();
119
120 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
121 // 3GPP2 apps only
122 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
123 if (cardStatus.applications[i].appType == AppType::SIM ||
124 cardStatus.applications[i].appType == AppType::USIM ||
125 cardStatus.applications[i].appType == AppType::RUIM ||
126 cardStatus.applications[i].appType == AppType::CSIM) {
127 radio->supplyIccPuk2ForApp(serial, hidl_string("test1"), hidl_string("test2"),
128 cardStatus.applications[i].aidPtr);
129 EXPECT_EQ(std::cv_status::no_timeout, wait());
130 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
131 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
132 ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::PASSWORD_INCORRECT,
133 RadioError::INVALID_SIM_STATE}));
134 }
135 }
136 LOG(DEBUG) << "supplyIccPuk2ForApp finished";
137 }
138
139 /*
140 * Test IRadio.changeIccPinForApp() for the response returned.
141 */
TEST_P(RadioHidlTest,changeIccPinForApp)142 TEST_P(RadioHidlTest, changeIccPinForApp) {
143 LOG(DEBUG) << "changeIccPinForApp";
144 serial = GetRandomSerialNumber();
145
146 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
147 // 3GPP2 apps only
148 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
149 if (cardStatus.applications[i].appType == AppType::SIM ||
150 cardStatus.applications[i].appType == AppType::USIM ||
151 cardStatus.applications[i].appType == AppType::RUIM ||
152 cardStatus.applications[i].appType == AppType::CSIM) {
153 radio->changeIccPinForApp(serial, hidl_string("test1"), hidl_string("test2"),
154 cardStatus.applications[i].aidPtr);
155 EXPECT_EQ(std::cv_status::no_timeout, wait());
156 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
157 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
158 ASSERT_TRUE(CheckAnyOfErrors(
159 radioRsp->rspInfo.error,
160 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
161 }
162 }
163 LOG(DEBUG) << "changeIccPinForApp finished";
164 }
165
166 /*
167 * Test IRadio.changeIccPin2ForApp() for the response returned.
168 */
TEST_P(RadioHidlTest,changeIccPin2ForApp)169 TEST_P(RadioHidlTest, changeIccPin2ForApp) {
170 LOG(DEBUG) << "changeIccPin2ForApp";
171 serial = GetRandomSerialNumber();
172
173 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
174 // 3GPP2 apps only
175 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
176 if (cardStatus.applications[i].appType == AppType::SIM ||
177 cardStatus.applications[i].appType == AppType::USIM ||
178 cardStatus.applications[i].appType == AppType::RUIM ||
179 cardStatus.applications[i].appType == AppType::CSIM) {
180 radio->changeIccPin2ForApp(serial, hidl_string("test1"), hidl_string("test2"),
181 cardStatus.applications[i].aidPtr);
182 EXPECT_EQ(std::cv_status::no_timeout, wait());
183 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
184 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
185 ASSERT_TRUE(
186 CheckAnyOfErrors(radioRsp->rspInfo.error,
187 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED,
188 RadioError::SIM_PUK2}));
189 }
190 }
191 LOG(DEBUG) << "changeIccPin2ForApp finished";
192 }
193
194 /*
195 * The following test is disabled due to b/109889468
196 *
197 * Test IRadio.getImsiForApp() for the response returned.
198 */
TEST_P(RadioHidlTest,DISABLED_getImsiForApp)199 TEST_P(RadioHidlTest, DISABLED_getImsiForApp) {
200 LOG(DEBUG) << "DISABLED_getImsiForApp";
201 serial = GetRandomSerialNumber();
202
203 // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
204 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
205 if (cardStatus.applications[i].appType == AppType::SIM ||
206 cardStatus.applications[i].appType == AppType::USIM ||
207 cardStatus.applications[i].appType == AppType::RUIM ||
208 cardStatus.applications[i].appType == AppType::CSIM) {
209 radio->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
210 EXPECT_EQ(std::cv_status::no_timeout, wait());
211 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
212 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
213 ASSERT_TRUE(
214 CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::NONE}, CHECK_GENERAL_ERROR));
215
216 // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
217 if (radioRsp->rspInfo.error == RadioError::NONE) {
218 EXPECT_NE(radioRsp->imsi, hidl_string());
219 EXPECT_GE((int)(radioRsp->imsi).size(), 6);
220 EXPECT_LE((int)(radioRsp->imsi).size(), 15);
221 }
222 }
223 }
224 LOG(DEBUG) << "DISABLED_getImsiForApp finished";
225 }
226
227 /*
228 * Test IRadio.iccIOForApp() for the response returned.
229 */
TEST_P(RadioHidlTest,iccIOForApp)230 TEST_P(RadioHidlTest, iccIOForApp) {
231 LOG(DEBUG) << "iccIOForApp";
232 serial = GetRandomSerialNumber();
233
234 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
235 IccIo iccIo;
236 iccIo.command = 0xc0;
237 iccIo.fileId = 0x6f11;
238 iccIo.path = hidl_string("3F007FFF");
239 iccIo.p1 = 0;
240 iccIo.p2 = 0;
241 iccIo.p3 = 0;
242 iccIo.data = hidl_string();
243 iccIo.pin2 = hidl_string();
244 iccIo.aid = cardStatus.applications[i].aidPtr;
245
246 radio->iccIOForApp(serial, iccIo);
247 EXPECT_EQ(std::cv_status::no_timeout, wait());
248 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
249 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
250 }
251 LOG(DEBUG) << "iccIOForApp finished";
252 }
253
254 /*
255 * Test IRadio.iccTransmitApduBasicChannel() for the response returned.
256 */
TEST_P(RadioHidlTest,iccTransmitApduBasicChannel)257 TEST_P(RadioHidlTest, iccTransmitApduBasicChannel) {
258 LOG(DEBUG) << "iccTransmitApduBasicChannel";
259 serial = GetRandomSerialNumber();
260 SimApdu msg;
261 memset(&msg, 0, sizeof(msg));
262 msg.data = hidl_string();
263
264 radio->iccTransmitApduBasicChannel(serial, msg);
265 EXPECT_EQ(std::cv_status::no_timeout, wait());
266 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
267 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
268
269 // TODO(sanketpadawe): Add test for error code
270 LOG(DEBUG) << "iccTransmitApduBasicChannel finished";
271 }
272
273 /*
274 * Test IRadio.iccOpenLogicalChannel() for the response returned.
275 */
TEST_P(RadioHidlTest,iccOpenLogicalChannel)276 TEST_P(RadioHidlTest, iccOpenLogicalChannel) {
277 LOG(DEBUG) << "iccOpenLogicalChannel";
278 serial = GetRandomSerialNumber();
279 int p2 = 0x04;
280 // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
281 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
282 radio->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
283 EXPECT_EQ(std::cv_status::no_timeout, wait());
284 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
285 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
286 }
287 LOG(DEBUG) << "iccOpenLogicalChannel finished";
288 }
289
290 /*
291 * Test IRadio.iccCloseLogicalChannel() for the response returned.
292 */
TEST_P(RadioHidlTest,iccCloseLogicalChannel)293 TEST_P(RadioHidlTest, iccCloseLogicalChannel) {
294 LOG(DEBUG) << "iccCloseLogicalChannel";
295 serial = GetRandomSerialNumber();
296 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
297 radio->iccCloseLogicalChannel(serial, 0);
298 EXPECT_EQ(std::cv_status::no_timeout, wait());
299 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
300 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
301
302 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp->rspInfo.error);
303 LOG(DEBUG) << "iccCloseLogicalChannel finished";
304 }
305
306 /*
307 * Test IRadio.iccTransmitApduLogicalChannel() for the response returned.
308 */
TEST_P(RadioHidlTest,iccTransmitApduLogicalChannel)309 TEST_P(RadioHidlTest, iccTransmitApduLogicalChannel) {
310 LOG(DEBUG) << "iccTransmitApduLogicalChannel";
311 serial = GetRandomSerialNumber();
312 SimApdu msg;
313 memset(&msg, 0, sizeof(msg));
314 msg.data = hidl_string();
315
316 radio->iccTransmitApduLogicalChannel(serial, msg);
317 EXPECT_EQ(std::cv_status::no_timeout, wait());
318 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
319 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
320
321 // TODO(sanketpadawe): Add test for error code
322 LOG(DEBUG) << "iccTransmitApduLogicalChannel finished";
323 }
324
325 /*
326 * Test IRadio.requestIccSimAuthentication() for the response returned.
327 */
TEST_P(RadioHidlTest,requestIccSimAuthentication)328 TEST_P(RadioHidlTest, requestIccSimAuthentication) {
329 LOG(DEBUG) << "requestIccSimAuthentication";
330 serial = GetRandomSerialNumber();
331
332 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
333 // or REQUEST_NOT_SUPPORTED returned as error.
334 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
335 radio->requestIccSimAuthentication(serial, 0, hidl_string("test"),
336 cardStatus.applications[i].aidPtr);
337 EXPECT_EQ(std::cv_status::no_timeout, wait());
338 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
339 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
340 ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::INVALID_ARGUMENTS,
341 RadioError::REQUEST_NOT_SUPPORTED}));
342 }
343 LOG(DEBUG) << "requestIccSimAuthentication finished";
344 }
345
346 /*
347 * Test IRadio.supplyNetworkDepersonalization() for the response returned.
348 */
TEST_P(RadioHidlTest,supplyNetworkDepersonalization)349 TEST_P(RadioHidlTest, supplyNetworkDepersonalization) {
350 LOG(DEBUG) << "supplyNetworkDepersonalization";
351 serial = GetRandomSerialNumber();
352
353 radio->supplyNetworkDepersonalization(serial, hidl_string("test"));
354 EXPECT_EQ(std::cv_status::no_timeout, wait());
355 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
356 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
357
358 if (cardStatus.cardState == CardState::ABSENT) {
359 ASSERT_TRUE(CheckAnyOfErrors(
360 radioRsp->rspInfo.error,
361 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::INTERNAL_ERR,
362 RadioError::INVALID_SIM_STATE, RadioError::MODEM_ERR, RadioError::NO_MEMORY,
363 RadioError::PASSWORD_INCORRECT, RadioError::SIM_ABSENT, RadioError::SYSTEM_ERR}));
364 }
365 LOG(DEBUG) << "supplyNetworkDepersonalization finished";
366 }
367