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