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