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