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/hardware/radio/1.2/IRadio.h>
18 #include <radio_hidl_hal_utils_v1_1.h>
19 #include <vector>
20
21 /*
22 * Test IRadio.setSimCardPower() for the response returned.
23 */
TEST_P(RadioHidlTest_v1_1,setSimCardPower_1_1)24 TEST_P(RadioHidlTest_v1_1, setSimCardPower_1_1) {
25 /* Record the sim card state for the testing environment */
26 CardState cardStateForTest = cardStatus.cardState;
27
28 #if 0
29 /* This test has to be removed for Japan Model.
30 * After "setSimCardPower power down", Japan model can not "setSimCardPower power up" */
31 /* Test setSimCardPower power down */
32 serial = GetRandomSerialNumber();
33 radio_v1_1->setSimCardPower_1_1(serial, CardPowerState::POWER_DOWN);
34 EXPECT_EQ(std::cv_status::no_timeout, wait());
35 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
36 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
37 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_v1_1->rspInfo.error,
38 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED,
39 RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE}));
40 if (radioRsp_v1_1->rspInfo.error == RadioError::NONE) {
41 /* Wait some time for setting sim power down and then verify it */
42 updateSimCardStatus();
43 auto startTime = std::chrono::system_clock::now();
44 while (cardStatus.cardState != CardState::ABSENT &&
45 std::chrono::duration_cast<chrono::seconds>(std::chrono::system_clock::now() - startTime)
46 .count() < 80) {
47 /* Set 2 seconds as interval to check card status */
48 sleep(2);
49 updateSimCardStatus();
50 }
51 EXPECT_EQ(CardState::ABSENT, cardStatus.cardState);
52 }
53
54 /* Test setSimCardPower power up */
55 serial = GetRandomSerialNumber();
56 radio_v1_1->setSimCardPower_1_1(serial, CardPowerState::POWER_UP);
57 EXPECT_EQ(std::cv_status::no_timeout, wait());
58 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
59 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
60 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_v1_1->rspInfo.error,
61 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED,
62 RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE}));
63 #endif
64
65 /**
66 * If the sim card status for the testing environment is PRESENT,
67 * verify if sim status is reset back.
68 */
69 if (cardStateForTest == CardState::PRESENT &&
70 radioRsp_v1_1->rspInfo.error == RadioError::NONE) {
71 /* Wait some time for resetting back to sim power on and then verify it */
72 updateSimCardStatus();
73 auto startTime = std::chrono::system_clock::now();
74 while (cardStatus.cardState != CardState::PRESENT &&
75 std::chrono::duration_cast<chrono::seconds>(std::chrono::system_clock::now() -
76 startTime)
77 .count() < 80) {
78 /* Set 2 seconds as interval to check card status */
79 sleep(2);
80 updateSimCardStatus();
81 }
82 EXPECT_EQ(CardState::PRESENT, cardStatus.cardState);
83 }
84 }
85
86 /*
87 * Test IRadio.startNetworkScan() for the response returned.
88 */
TEST_P(RadioHidlTest_v1_1,startNetworkScan)89 TEST_P(RadioHidlTest_v1_1, startNetworkScan) {
90 serial = GetRandomSerialNumber();
91
92 NetworkScanRequest request;
93 request.type = ScanType::ONE_SHOT;
94 request.interval = 60;
95 RadioAccessSpecifier specifier;
96 specifier.radioAccessNetwork = RadioAccessNetworks::GERAN;
97 specifier.geranBands.resize(2);
98 specifier.geranBands[0] = GeranBands::BAND_450;
99 specifier.geranBands[1] = GeranBands::BAND_480;
100 specifier.channels.resize(2);
101 specifier.channels[0] = 1;
102 specifier.channels[1] = 2;
103 request.specifiers.resize(1);
104 request.specifiers[0] = specifier;
105
106 radio_v1_1->startNetworkScan(serial, request);
107 EXPECT_EQ(std::cv_status::no_timeout, wait());
108 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
109 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
110
111 // startNetworkScan is deprecated on radio::V1_2 with startNetworkScan_1_2
112 SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL_VERSION_AT_LEAST(1_2);
113
114 if (cardStatus.cardState == CardState::ABSENT) {
115 ALOGI("startNetworkScan, rspInfo.error = %d\n", (int32_t)radioRsp_v1_1->rspInfo.error);
116 ASSERT_TRUE(CheckAnyOfErrors(
117 radioRsp_v1_1->rspInfo.error,
118 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::INVALID_ARGUMENTS,
119 RadioError::SIM_ABSENT, RadioError::OPERATION_NOT_ALLOWED}));
120 }
121 }
122
123 /*
124 * Test IRadio.startNetworkScan() for the response returned.
125 */
TEST_P(RadioHidlTest_v1_1,startNetworkScan_InvalidArgument)126 TEST_P(RadioHidlTest_v1_1, startNetworkScan_InvalidArgument) {
127 serial = GetRandomSerialNumber();
128
129 NetworkScanRequest request;
130 request.type = ScanType::ONE_SHOT;
131 request.interval = 60;
132
133 radio_v1_1->startNetworkScan(serial, request);
134 EXPECT_EQ(std::cv_status::no_timeout, wait());
135 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
136 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
137
138 // startNetworkScan is deprecated on radio::V1_2 with startNetworkScan_1_2
139 SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL_VERSION_AT_LEAST(1_2);
140
141 if (cardStatus.cardState == CardState::ABSENT) {
142 ALOGI("startNetworkScan_InvalidArgument, rspInfo.error = %d\n",
143 (int32_t)radioRsp_v1_1->rspInfo.error);
144 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_v1_1->rspInfo.error,
145 {RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT,
146 RadioError::REQUEST_NOT_SUPPORTED}));
147 }
148 }
149
150 /*
151 * Test IRadio.stopNetworkScan() for the response returned.
152 */
TEST_P(RadioHidlTest_v1_1,stopNetworkScan)153 TEST_P(RadioHidlTest_v1_1, stopNetworkScan) {
154 serial = GetRandomSerialNumber();
155
156 radio_v1_1->stopNetworkScan(serial);
157 EXPECT_EQ(std::cv_status::no_timeout, wait());
158 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
159 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
160
161 if (cardStatus.cardState == CardState::ABSENT) {
162 ALOGI("stopNetworkScan rspInfo.error = %d\n", (int32_t)radioRsp_v1_1->rspInfo.error);
163 ASSERT_TRUE(CheckAnyOfErrors(
164 radioRsp_v1_1->rspInfo.error,
165 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::REQUEST_NOT_SUPPORTED}));
166 }
167 }
168
169 /*
170 * Test IRadio.setCarrierInfoForImsiEncryption() for the response returned.
171 */
TEST_P(RadioHidlTest_v1_1,setCarrierInfoForImsiEncryption)172 TEST_P(RadioHidlTest_v1_1, setCarrierInfoForImsiEncryption) {
173 serial = GetRandomSerialNumber();
174 ImsiEncryptionInfo imsiInfo;
175 imsiInfo.mcc = "310";
176 imsiInfo.mnc = "004";
177 imsiInfo.carrierKey = (std::vector<uint8_t>){1, 2, 3, 4, 5, 6};
178 imsiInfo.keyIdentifier = "Test";
179 imsiInfo.expirationTime = 20180101;
180
181 radio_v1_1->setCarrierInfoForImsiEncryption(serial, imsiInfo);
182 EXPECT_EQ(std::cv_status::no_timeout, wait());
183 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
184 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
185
186 if (cardStatus.cardState == CardState::ABSENT) {
187 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_v1_1->rspInfo.error,
188 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
189 }
190 }
191
192 /*
193 * Test IRadio.startKeepalive() for the response returned.
194 */
TEST_P(RadioHidlTest_v1_1,startKeepalive)195 TEST_P(RadioHidlTest_v1_1, startKeepalive) {
196 std::vector<KeepaliveRequest> requests = {
197 {
198 // Invalid IPv4 source address
199 KeepaliveType::NATT_IPV4,
200 {192, 168, 0 /*, 100*/},
201 1234,
202 {8, 8, 4, 4},
203 4500,
204 20000,
205 0xBAD,
206 },
207 {
208 // Invalid IPv4 destination address
209 KeepaliveType::NATT_IPV4,
210 {192, 168, 0, 100},
211 1234,
212 {8, 8, 4, 4, 1, 2, 3, 4},
213 4500,
214 20000,
215 0xBAD,
216 },
217 {
218 // Invalid Keepalive Type
219 static_cast<KeepaliveType>(-1),
220 {192, 168, 0, 100},
221 1234,
222 {8, 8, 4, 4},
223 4500,
224 20000,
225 0xBAD,
226 },
227 {
228 // Invalid IPv6 source address
229 KeepaliveType::NATT_IPV6,
230 {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xED,
231 0xBE, 0xEF, 0xBD},
232 1234,
233 {0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x88, 0x44},
235 4500,
236 20000,
237 0xBAD,
238 },
239 {
240 // Invalid IPv6 destination address
241 KeepaliveType::NATT_IPV6,
242 {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xED,
243 0xBE, 0xEF},
244 1234,
245 {0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x88,
247 /*0x44*/},
248 4500,
249 20000,
250 0xBAD,
251 },
252 {
253 // Invalid Context ID (cid), this should survive the initial
254 // range checking and fail in the modem data layer
255 KeepaliveType::NATT_IPV4,
256 {192, 168, 0, 100},
257 1234,
258 {8, 8, 4, 4},
259 4500,
260 20000,
261 0xBAD,
262 },
263 {
264 // Invalid Context ID (cid), this should survive the initial
265 // range checking and fail in the modem data layer
266 KeepaliveType::NATT_IPV6,
267 {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xED,
268 0xBE, 0xEF},
269 1234,
270 {0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x88, 0x44},
272 4500,
273 20000,
274 0xBAD,
275 }};
276
277 for (auto req = requests.begin(); req != requests.end(); req++) {
278 serial = GetRandomSerialNumber();
279 radio_v1_1->startKeepalive(serial, *req);
280 EXPECT_EQ(std::cv_status::no_timeout, wait());
281 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
282 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
283
284 ASSERT_TRUE(
285 CheckAnyOfErrors(radioRsp_v1_1->rspInfo.error,
286 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
287 }
288 }
289
290 /*
291 * Test IRadio.stopKeepalive() for the response returned.
292 */
TEST_P(RadioHidlTest_v1_1,stopKeepalive)293 TEST_P(RadioHidlTest_v1_1, stopKeepalive) {
294 serial = GetRandomSerialNumber();
295
296 radio_v1_1->stopKeepalive(serial, 0xBAD);
297 EXPECT_EQ(std::cv_status::no_timeout, wait());
298 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_1->rspInfo.type);
299 EXPECT_EQ(serial, radioRsp_v1_1->rspInfo.serial);
300
301 ASSERT_TRUE(
302 CheckAnyOfErrors(radioRsp_v1_1->rspInfo.error,
303 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
304 }
305