1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <gtest/gtest.h>
16 #include <servmgr_hdi.h>
17 #include "v1_3/iwlan_interface.h"
18 #include "wlan_callback_impl.h"
19 #include "wlan_impl.h"
20
21 #define HDF_LOG_TAG service_manager_test
22 using namespace testing::ext;
23
24 namespace HdiTest {
25 const int32_t WLAN_FREQ_MAX_NUM = 35;
26 const int32_t WLAN_TX_POWER = 160;
27 const int32_t DEFAULT_COMBO_SIZE = 6;
28 const int32_t WLAN_MAX_NUM_STA_WITH_AP = 4;
29 const uint32_t RESET_TIME = 3;
30 const uint32_t MEAS_CHANNEL_TIME = 1;
31 const uint32_t SCAN_TIME = 3;
32 const char *WLAN_SERVICE_NAME = "wlan_interface_service";
33
34 class HdfWifiServiceCTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp();
39 void TearDown();
40 };
41
42 static struct IWlanInterface *g_wlanObj = nullptr;
43 struct IWlanCallback *g_wlanCallbackObj = nullptr;
SetUpTestCase()44 void HdfWifiServiceCTest::SetUpTestCase()
45 {
46 g_wlanObj = IWlanInterfaceGetInstance(WLAN_SERVICE_NAME, false);
47 g_wlanCallbackObj = WlanCallbackServiceGet();
48 ASSERT_TRUE(g_wlanObj != nullptr);
49 ASSERT_TRUE(g_wlanCallbackObj != nullptr);
50 }
51
TearDownTestCase()52 void HdfWifiServiceCTest::TearDownTestCase()
53 {
54 IWlanInterfaceReleaseInstance(WLAN_SERVICE_NAME, g_wlanObj, false);
55 WlanCallbackServiceRelease(g_wlanCallbackObj);
56 }
57
SetUp()58 void HdfWifiServiceCTest::SetUp()
59 {
60 int32_t rc = g_wlanObj->Start(g_wlanObj);
61 ASSERT_EQ(rc, HDF_SUCCESS);
62 }
63
TearDown()64 void HdfWifiServiceCTest::TearDown()
65 {
66 int32_t rc = g_wlanObj->Stop(g_wlanObj);
67 ASSERT_EQ(rc, HDF_SUCCESS);
68 }
69
70 /**
71 * @tc.name: GetSupportFeatureComboTest_001
72 * @tc.desc: Wifi hdi get support feature and combo function test
73 * @tc.type: FUNC
74 */
75 HWTEST_F(HdfWifiServiceCTest, GetSupportFeatureComboTest_001, Function | MediumTest | Level2)
76 {
77 uint8_t supType[PROTOCOL_80211_IFTYPE_NUM + 1] = {0};
78 uint32_t supTypeLen = PROTOCOL_80211_IFTYPE_NUM + 1;
79 uint64_t combo[DEFAULT_COMBO_SIZE] = {0};
80 uint32_t supTypeLenInvalid = 6;
81
82 int32_t rc = g_wlanObj->GetSupportFeature(g_wlanObj, supType, &supTypeLenInvalid);
83 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
84 rc = g_wlanObj->GetSupportFeature(g_wlanObj, supType, &supTypeLen);
85 ASSERT_EQ(rc, HDF_SUCCESS);
86 rc = g_wlanObj->GetSupportCombo(g_wlanObj, combo);
87 ASSERT_NE(rc, HDF_FAILURE);
88 }
89
90 /**
91 * @tc.name: CreateFeatureTest_002
92 * @tc.desc: Wifi hdi create feature function test
93 * @tc.type: FUNC
94 */
95 HWTEST_F(HdfWifiServiceCTest, CreateFeatureTest_002, Function | MediumTest | Level2)
96 {
97 struct HdfFeatureInfo ifeature;
98 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
99
100 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
101 if (rc == HDF_SUCCESS) {
102 printf("ifname = %s\n", ifeature.ifName);
103 printf("type = %d\n", ifeature.type);
104 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
105 ASSERT_EQ(rc, HDF_SUCCESS);
106 }
107 }
108
109 /**
110 * @tc.name: GetFeatureByIfNameTest_003
111 * @tc.desc: Wifi hdi get feature by ifname function test
112 * @tc.type: FUNC
113 */
114 HWTEST_F(HdfWifiServiceCTest, GetFeatureByIfNameTest_003, Function | MediumTest | Level2)
115 {
116 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
117 struct HdfFeatureInfo ifeature;
118 const char *ifNameInvalid = "wlanTest";
119
120 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
121 if (rc == HDF_SUCCESS) {
122 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifNameInvalid, &ifeature);
123 ASSERT_NE(rc, HDF_SUCCESS);
124 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifeature.ifName, &ifeature);
125 ASSERT_EQ(rc, HDF_SUCCESS);
126 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
127 ASSERT_EQ(rc, HDF_SUCCESS);
128 }
129 }
130
131 /**
132 * @tc.name: GetNetworkIfaceNameTest_004
133 * @tc.desc: Wifi hdi get network interface name function test on AP feature
134 * @tc.type: FUNC
135 */
136 HWTEST_F(HdfWifiServiceCTest, GetNetworkIfaceNameTest_004, Function | MediumTest | Level2)
137 {
138 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
139 struct HdfFeatureInfo ifeature;
140 char ifNames[IFNAMSIZ] = {0};
141
142 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
143 if (rc == HDF_SUCCESS) {
144 rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, &ifeature, ifNames, IFNAMSIZ);
145 ASSERT_EQ(rc, HDF_SUCCESS);
146 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
147 ASSERT_EQ(rc, HDF_SUCCESS);
148 }
149 }
150
151 /**
152 * @tc.name: GetFeatureTypeTest_005
153 * @tc.desc: Wifi hdi get feature type function test on AP feature
154 * @tc.type: FUNC
155 */
156 HWTEST_F(HdfWifiServiceCTest, GetFeatureTypeTest_005, Function | MediumTest | Level2)
157 {
158 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
159 struct HdfFeatureInfo ifeature;
160 int32_t featureType;
161
162 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
163 if (rc == HDF_SUCCESS) {
164 rc = g_wlanObj->GetFeatureType(g_wlanObj, &ifeature, &featureType);
165 ASSERT_EQ(rc, HDF_SUCCESS);
166 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
167 ASSERT_EQ(rc, HDF_SUCCESS);
168 }
169 }
170
171 /**
172 * @tc.name: SetMacAddressTest_006
173 * @tc.desc: Wifi hdi set mac addr function test on AP feature
174 * @tc.type: FUNC
175 */
176 HWTEST_F(HdfWifiServiceCTest, SetMacAddressTest_006, Function | MediumTest | Level2)
177 {
178 uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
179 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
180 struct HdfFeatureInfo ifeature;
181 uint32_t macLen = ETH_ADDR_LEN;
182 uint8_t errorMac[ETH_ADDR_LEN] = {0x11, 0x34, 0x56, 0x78, 0xab, 0xcd};
183
184 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
185 if (rc == HDF_SUCCESS) {
186 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, errorMac, macLen);
187 ASSERT_NE(rc, HDF_SUCCESS);
188 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, mac, macLen);
189 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_ERR_DEVICE_BUSY);
190 ASSERT_TRUE(flag);
191 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
192 ASSERT_EQ(rc, HDF_SUCCESS);
193 }
194 }
195
196 /**
197 * @tc.name: GetDeviceMacAddressTest_007
198 * @tc.desc: Wifi hdi get device mac addr function test on AP feature
199 * @tc.type: FUNC
200 */
201 HWTEST_F(HdfWifiServiceCTest, GetDeviceMacAddressTest_007, Function | MediumTest | Level2)
202 {
203 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
204 struct HdfFeatureInfo ifeature;
205 uint8_t mac[ETH_ADDR_LEN] = {0};
206 uint32_t macLen = ETH_ADDR_LEN;
207
208 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
209 if (rc == HDF_SUCCESS) {
210 rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN);
211 ASSERT_EQ(rc, HDF_SUCCESS);
212 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
213 ASSERT_EQ(rc, HDF_SUCCESS);
214 }
215 }
216
217 /**
218 * @tc.name: GetFreqsWithBandTest_008
219 * @tc.desc: Wifi hdi get freqs function test on AP feature
220 * @tc.type: FUNC
221 */
222 HWTEST_F(HdfWifiServiceCTest, GetFreqsWithBandTest_008, Function | MediumTest | Level2)
223 {
224 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
225 struct HdfFeatureInfo ifeature;
226 struct HdfWifiInfo wifiInfo;
227 int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
228 uint32_t freqLen = WLAN_FREQ_MAX_NUM ;
229 wifiInfo.band = IEEE80211_BAND_2GHZ;
230 wifiInfo.size = WLAN_FREQ_MAX_NUM;
231 struct HdfWifiInfo wifiInfoInvalid;
232 wifiInfoInvalid.band = IEEE80211_NUM_BANDS;
233 wifiInfoInvalid.size = WLAN_FREQ_MAX_NUM;
234 uint32_t i;
235
236 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
237 if (rc == HDF_SUCCESS) {
238 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfoInvalid, freq, &freqLen);
239 ASSERT_NE(rc, HDF_SUCCESS);
240 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, freq, &freqLen);
241 ASSERT_EQ(rc, HDF_SUCCESS);
242 if (rc == HDF_SUCCESS) {
243 for (i = 0; i < freqLen; i++) {
244 printf("%s: freq[%d] = %d\n", __func__, i, freq[i]);
245 }
246 }
247
248 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
249 ASSERT_EQ(rc, HDF_SUCCESS);
250 }
251 }
252
253 /**
254 * @tc.name: SetTxPowerTest_009
255 * @tc.desc: Wifi hdi set tx power function test on AP feature
256 * @tc.type: FUNC
257 */
258 HWTEST_F(HdfWifiServiceCTest, SetTxPowerTest_009, Function | MediumTest | Level2)
259 {
260 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
261 struct HdfFeatureInfo ifeature;
262 int32_t power = WLAN_TX_POWER;
263
264 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
265 if (rc == HDF_SUCCESS) {
266 rc = g_wlanObj->SetTxPower(g_wlanObj, &ifeature, power);
267 ASSERT_EQ(rc, HDF_SUCCESS);
268 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
269 ASSERT_EQ(rc, HDF_SUCCESS);
270 }
271 }
272
273 /**
274 * @tc.name: GetChipIdTest_010
275 * @tc.desc: Wifi hdi get chip id function test on STA feature
276 * @tc.type: FUNC
277 */
278 HWTEST_F(HdfWifiServiceCTest, GetChipIdTest_010, Function | MediumTest | Level2)
279 {
280 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
281 struct HdfFeatureInfo ifeature;
282 uint8_t chipId = 0;
283 uint8_t chipIdInvalid = 100;
284 unsigned int num = 0;
285 char ifNames[IFNAMSIZ] = {0};
286
287 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
288 if (rc == HDF_SUCCESS) {
289 rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
290 ASSERT_EQ(rc, HDF_SUCCESS);
291 rc = g_wlanObj->GetIfNamesByChipId(g_wlanObj, chipIdInvalid, ifNames, IFNAMSIZ, &num);
292 ASSERT_NE(rc, HDF_SUCCESS);
293 rc = g_wlanObj->GetIfNamesByChipId(g_wlanObj, chipId, ifNames, IFNAMSIZ, &num);
294 printf("ifnames = %s\n", ifNames);
295 ASSERT_EQ(rc, HDF_SUCCESS);
296 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
297 ASSERT_EQ(rc, HDF_SUCCESS);
298 }
299 }
300
301 /**
302 * @tc.name: SetScanningMacAddressTest_011
303 * @tc.desc: Wifi hdi set scanning mac addr function test
304 * @tc.type: FUNC
305 */
306 HWTEST_F(HdfWifiServiceCTest, SetScanningMacAddressTest_011, Function | MediumTest | Level2)
307 {
308 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
309 struct HdfFeatureInfo ifeature;
310 uint8_t scanMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
311 uint32_t macLen = ETH_ADDR_LEN;
312
313 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
314 if (rc == HDF_SUCCESS) {
315 rc = g_wlanObj->SetScanningMacAddress(g_wlanObj, &ifeature, scanMac, macLen);
316 ASSERT_NE(rc, HDF_FAILURE);
317 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
318 ASSERT_EQ(rc, HDF_SUCCESS);
319 }
320 }
321
322 /**
323 * @tc.name: GetNetdevInfoTest_012
324 * @tc.desc: Wifi hdi get netdev info function test
325 * @tc.type: FUNC
326 */
327 HWTEST_F(HdfWifiServiceCTest, GetNetdevInfoTest_012, Function | MediumTest | Level2)
328 {
329 int32_t rc;
330 struct HdfNetDeviceInfoResult netDeviceInfoResult;
331
332 (void)memset_s(
333 &netDeviceInfoResult, sizeof(struct HdfNetDeviceInfoResult), 0, sizeof(struct HdfNetDeviceInfoResult));
334 rc = g_wlanObj->GetNetDevInfo(g_wlanObj, (struct HdfNetDeviceInfoResult *)&netDeviceInfoResult);
335 ASSERT_EQ(rc, HDF_SUCCESS);
336 }
337
338 /**
339 * @tc.name: GetPowerModeTest_013
340 * @tc.desc: Wifi hdi get power mode function test
341 * @tc.type: FUNC
342 */
343 HWTEST_F(HdfWifiServiceCTest, GetPowerModeTest_013, Function | MediumTest | Level2)
344 {
345 struct HdfFeatureInfo ifeature;
346 uint8_t mode = 0;
347
348 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
349 if (rc == HDF_SUCCESS) {
350 rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, &mode);
351 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
352 ASSERT_TRUE(flag);
353 printf("mode = 0x%02x\n", mode);
354 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
355 ASSERT_EQ(rc, HDF_SUCCESS);
356 }
357 }
358
359 /**
360 * @tc.name: SetPowerModeTest_014
361 * @tc.desc: Wifi hdi set power mode function test
362 * @tc.type: FUNC
363 */
364 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_014, Function | MediumTest | Level2)
365 {
366 struct HdfFeatureInfo ifeature;
367 uint8_t mode = WIFI_POWER_MODE_SLEEPING;
368
369 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
370 if (rc == HDF_SUCCESS) {
371 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
372 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
373 ASSERT_TRUE(flag);
374 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
375 ASSERT_EQ(rc, HDF_SUCCESS);
376 }
377 }
378
379 /**
380 * @tc.name: RegisterEventCallbackTest_015
381 * @tc.desc: Wifi hdi register event call back function test
382 * @tc.type: FUNC
383 */
384 HWTEST_F(HdfWifiServiceCTest, RegisterEventCallbackTest_015, Function | MediumTest | Level2)
385 {
386 const char *ifName = "wlan0";
387 int32_t rc = g_wlanObj->RegisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
388 ASSERT_EQ(rc, HDF_SUCCESS);
389 }
390
391 /**
392 * @tc.name: ResetDriverTest_016
393 * @tc.desc: Wifi hdi reset driver function test
394 * @tc.type: FUNC
395 */
396 HWTEST_F(HdfWifiServiceCTest, ResetDriverTest_016, Function | MediumTest | Level2)
397 {
398 int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
399 struct HdfFeatureInfo ifeature;
400 const char *ifName = "wlan0";
401 uint8_t chipId = 0;
402 int32_t rc;
403
404 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
405 if (rc == HDF_SUCCESS) {
406 rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
407 ASSERT_EQ(rc, HDF_SUCCESS);
408 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
409 ASSERT_EQ(rc, HDF_SUCCESS);
410 rc = g_wlanObj->ResetDriver(g_wlanObj, chipId, ifName);
411 ASSERT_EQ(rc, HDF_SUCCESS);
412 sleep(RESET_TIME);
413 }
414 }
415
416 /**
417 * @tc.name: StartScanTest_017
418 * @tc.desc: Wifi hdi start scan function test
419 * @tc.type: FUNC
420 */
421 HWTEST_F(HdfWifiServiceCTest, StartScanTest_017, Function | MediumTest | Level2)
422 {
423 int32_t rc;
424 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
425 struct HdfFeatureInfo ifeature;
426 struct HdfWifiScan scan = {0};
427
428 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
429 if (rc == HDF_SUCCESS) {
430 rc = g_wlanObj->StartScan(g_wlanObj, nullptr, &scan);
431 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
432 rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, nullptr);
433 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
434 rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, &scan);
435 ASSERT_EQ(rc, HDF_SUCCESS);
436 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
437 ASSERT_EQ(rc, HDF_SUCCESS);
438 sleep(SCAN_TIME);
439 }
440 }
441
442 /**
443 * @tc.name: UnregisterEventCallbackTest_018
444 * @tc.desc: Wifi hdi unreister event call back function test
445 * @tc.type: FUNC
446 */
447 HWTEST_F(HdfWifiServiceCTest, UnregisterEventCallbackTest_018, Function | MediumTest | Level2)
448 {
449 const char *ifName = "wlan0";
450 int32_t rc = g_wlanObj->UnregisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
451 ASSERT_EQ(rc, HDF_SUCCESS);
452 }
453
454 /**
455 * @tc.name: GetAssociatedStasTest_019
456 * @tc.desc: Wifi hdi get assoc stas function test
457 * @tc.type: FUNC
458 */
459 HWTEST_F(HdfWifiServiceCTest, GetAssociatedStasTest_019, Function | MediumTest | Level2)
460 {
461 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
462 struct HdfFeatureInfo ifeature;
463 struct HdfStaInfo staInfo[WLAN_MAX_NUM_STA_WITH_AP] = {{0}};
464 uint32_t staInfoLen = WLAN_MAX_NUM_STA_WITH_AP;
465 uint32_t num = 0;
466
467 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
468 if (rc == HDF_SUCCESS) {
469 rc = g_wlanObj->GetAssociatedStas(g_wlanObj, &ifeature, staInfo, &staInfoLen, &num);
470 ASSERT_EQ(rc, HDF_SUCCESS);
471 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
472 ASSERT_EQ(rc, HDF_SUCCESS);
473 }
474 }
475
476 /**
477 * @tc.name: SetCountryCodeTest_020
478 * @tc.desc: Wifi hdi set country code function test
479 * @tc.type: FUNC
480 */
481 HWTEST_F(HdfWifiServiceCTest, SetCountryCodeTest_020, Function | MediumTest | Level2)
482 {
483 const char *code = "CN";
484 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
485 struct HdfFeatureInfo ifeature;
486 const char *codeDigital = "99";
487 uint32_t size = 2;
488
489 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
490 if (rc == HDF_SUCCESS) {
491 rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, codeDigital, size);
492 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == RET_CODE_UNKNOW);
493 ASSERT_TRUE(flag);
494 rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, code, size);
495 flag = (rc == HDF_SUCCESS || rc == RET_CODE_UNKNOW);
496 ASSERT_TRUE(flag);
497 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
498 ASSERT_EQ(rc, HDF_SUCCESS);
499 }
500 }
501
502 /**
503 * @tc.name: CreateFeatureTest_021
504 * @tc.desc: Wifi hdi create feature function test
505 * @tc.type: FUNC
506 */
507 HWTEST_F(HdfWifiServiceCTest, CreateFeatureTest_021, Function | MediumTest | Level2)
508 {
509 struct HdfFeatureInfo ifeature;
510 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
511 int32_t wlanTypeInvalid = PROTOCOL_80211_IFTYPE_NUM;
512
513 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanTypeInvalid, &ifeature);
514 if (rc == HDF_SUCCESS) {
515 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
516 ASSERT_EQ(rc, HDF_SUCCESS);
517 printf("ifname = %s\n", ifeature.ifName);
518 printf("type = %d\n", ifeature.type);
519 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
520 ASSERT_EQ(rc, HDF_SUCCESS);
521 }
522 }
523
524 /**
525 * @tc.name: GetChipIdTest_022
526 * @tc.desc: Wifi hdi get chip id function test
527 * @tc.type: FUNC
528 */
529 HWTEST_F(HdfWifiServiceCTest, GetChipIdTest_022, Function | MediumTest | Level2)
530 {
531 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
532 struct HdfFeatureInfo ifeature;
533 uint8_t chipId = 0;
534
535 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
536 if (rc == HDF_SUCCESS) {
537 rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
538 ASSERT_EQ(rc, HDF_SUCCESS);
539 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
540 ASSERT_EQ(rc, HDF_SUCCESS);
541 }
542 }
543
544 /**
545 * @tc.name: GetDeviceMacAddressTest_023
546 * @tc.desc: Wifi hdi get device mac addr function test on STA feature
547 * @tc.type: FUNC
548 */
549 HWTEST_F(HdfWifiServiceCTest, GetDeviceMacAddressTest_023, Function | MediumTest | Level2)
550 {
551 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
552 struct HdfFeatureInfo ifeature;
553 uint8_t mac[ETH_ADDR_LEN] = {0};
554 uint32_t macLen = ETH_ADDR_LEN;
555
556 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
557 if (rc == HDF_SUCCESS) {
558 rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN);
559 ASSERT_EQ(rc, HDF_SUCCESS);
560 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
561 ASSERT_EQ(rc, HDF_SUCCESS);
562 }
563 }
564
565 /**
566 * @tc.name: GetFeatureByIfNameTest_024
567 * @tc.desc: Wifi hdi get feature by ifname function test
568 * @tc.type: FUNC
569 */
570 HWTEST_F(HdfWifiServiceCTest, GetFeatureByIfNameTest_024, Function | MediumTest | Level2)
571 {
572 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
573 struct HdfFeatureInfo ifeature;
574 const char *ifNameInvalid = "wlanTest";
575
576 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
577 if (rc == HDF_SUCCESS) {
578 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifNameInvalid, &ifeature);
579 ASSERT_NE(rc, HDF_SUCCESS);
580 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifeature.ifName, &ifeature);
581 ASSERT_EQ(rc, HDF_SUCCESS);
582 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
583 ASSERT_EQ(rc, HDF_SUCCESS);
584 }
585 }
586
587 /**
588 * @tc.name: SetMacAddressTest_025
589 * @tc.desc: Wifi hdi set mac addr function test on STA feature
590 * @tc.type: FUNC
591 */
592 HWTEST_F(HdfWifiServiceCTest, SetMacAddressTest_025, Function | MediumTest | Level2)
593 {
594 uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
595 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
596 struct HdfFeatureInfo ifeature;
597 uint32_t macLen = ETH_ADDR_LEN;
598 uint8_t errorMac[ETH_ADDR_LEN] = {0x11, 0x34, 0x56, 0x78, 0xab, 0xcd};
599
600 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
601 if (rc == HDF_SUCCESS) {
602 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, errorMac, macLen);
603 ASSERT_NE(rc, HDF_SUCCESS);
604 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, mac, macLen);
605 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_ERR_DEVICE_BUSY);
606 ASSERT_TRUE(flag);
607 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
608 ASSERT_EQ(rc, HDF_SUCCESS);
609 }
610 }
611
612 /**
613 * @tc.name: GetPowerModeTest_026
614 * @tc.desc: Wifi hdi get power mode function test
615 * @tc.type: FUNC
616 */
617 HWTEST_F(HdfWifiServiceCTest, GetPowerModeTest_026, Function | MediumTest | Level2)
618 {
619 struct HdfFeatureInfo ifeature;
620 uint8_t mode = 0;
621
622 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
623 if (rc == HDF_SUCCESS) {
624 rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, &mode);
625 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
626 ASSERT_TRUE(flag);
627 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
628 ASSERT_EQ(rc, HDF_SUCCESS);
629 }
630 }
631
632 /**
633 * @tc.name: SetPowerModeTest_027
634 * @tc.desc: Wifi hdi set power mode function test
635 * @tc.type: FUNC
636 */
637 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_027, Function | MediumTest | Level2)
638 {
639 struct HdfFeatureInfo ifeature;
640 uint8_t mode = WIFI_POWER_MODE_GENERAL;
641
642 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
643 if (rc == HDF_SUCCESS) {
644 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
645 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
646 ASSERT_TRUE(flag);
647 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
648 ASSERT_EQ(rc, HDF_SUCCESS);
649 }
650 }
651
652 /**
653 * @tc.name: SetPowerModeTest_028
654 * @tc.desc: Wifi hdi set power mode function test
655 * @tc.type: FUNC
656 */
657 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_028, Function | MediumTest | Level2)
658 {
659 struct HdfFeatureInfo ifeature;
660 uint8_t mode = WIFI_POWER_MODE_THROUGH_WALL;
661
662 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
663 if (rc == HDF_SUCCESS) {
664 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
665 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
666 ASSERT_TRUE(flag);
667 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
668 ASSERT_EQ(rc, HDF_SUCCESS);
669 }
670 }
671
672 /**
673 * @tc.name: SetPowerModeTest_029
674 * @tc.desc: Wifi hdi set power mode function test
675 * @tc.type: FUNC
676 */
677 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_029, Function | MediumTest | Level2)
678 {
679 struct HdfFeatureInfo ifeature;
680 uint8_t mode = WIFI_POWER_MODE_NUM;
681
682 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
683 if (rc == HDF_SUCCESS) {
684 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
685 ASSERT_NE(rc, HDF_SUCCESS);
686 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
687 ASSERT_EQ(rc, HDF_SUCCESS);
688 }
689 }
690
691 /**
692 * @tc.name: SetPowerModeTest_30
693 * @tc.desc: Wifi hdi set power mode function test
694 * @tc.type: FUNC
695 */
696 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_030, Function | MediumTest | Level2)
697 {
698 struct HdfFeatureInfo ifeature;
699 uint8_t mode = WIFI_POWER_MODE_SLEEPING;
700
701 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
702 if (rc == HDF_SUCCESS) {
703 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
704 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
705 ASSERT_TRUE(flag);
706 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
707 ASSERT_EQ(rc, HDF_SUCCESS);
708 }
709 }
710
711 /**
712 * @tc.name: SetPowerModeTest_031
713 * @tc.desc: Wifi hdi set power mode function test
714 * @tc.type: FUNC
715 */
716 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_031, Function | MediumTest | Level2)
717 {
718 struct HdfFeatureInfo ifeature;
719 uint8_t mode = WIFI_POWER_MODE_GENERAL;
720
721 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
722 if (rc == HDF_SUCCESS) {
723 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
724 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
725 ASSERT_TRUE(flag);
726 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
727 ASSERT_EQ(rc, HDF_SUCCESS);
728 }
729 }
730
731 /**
732 * @tc.name: SetPowerModeTest_032
733 * @tc.desc: Wifi hdi set power mode function test
734 * @tc.type: FUNC
735 */
736 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_032, Function | MediumTest | Level2)
737 {
738 struct HdfFeatureInfo ifeature;
739 uint8_t mode = WIFI_POWER_MODE_THROUGH_WALL;
740
741 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
742 if (rc == HDF_SUCCESS) {
743 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
744 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
745 ASSERT_TRUE(flag);
746 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
747 ASSERT_EQ(rc, HDF_SUCCESS);
748 }
749 }
750
751 /**
752 * @tc.name: SetPowerModeTest_033
753 * @tc.desc: Wifi hdi set power mode function test
754 * @tc.type: FUNC
755 */
756 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_033, Function | MediumTest | Level2)
757 {
758 struct HdfFeatureInfo ifeature;
759 uint8_t mode = WIFI_POWER_MODE_NUM;
760
761 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
762 if (rc == HDF_SUCCESS) {
763 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
764 ASSERT_NE(rc, HDF_SUCCESS);
765 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
766 ASSERT_EQ(rc, HDF_SUCCESS);
767 }
768 }
769
770 /**
771 * @tc.name: StartChannelMeasTest_034
772 * @tc.desc: Wifi hdi start channel meas and get meas result function test
773 * @tc.type: FUNC
774 */
775 HWTEST_F(HdfWifiServiceCTest, StartChannelMeasTest_034, Function | MediumTest | Level2)
776 {
777 const char *ifName = "wlan0";
778 struct MeasChannelParam measChannelParam;
779 struct MeasChannelResult measChannelResult = {0};
780
781 measChannelParam.channelId = 1;
782 measChannelParam.measTime = 15;
783 int32_t rc = g_wlanObj->StartChannelMeas(g_wlanObj, ifName, &measChannelParam);
784 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
785 ASSERT_TRUE(flag);
786 sleep(MEAS_CHANNEL_TIME);
787 rc = g_wlanObj->GetChannelMeasResult(g_wlanObj, ifName, &measChannelResult);
788 flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NODATA);
789 ASSERT_TRUE(flag);
790 rc = g_wlanObj->StartChannelMeas(g_wlanObj, nullptr, &measChannelParam);
791 ASSERT_NE(rc, HDF_SUCCESS);
792 rc = g_wlanObj->StartChannelMeas(g_wlanObj, ifName, nullptr);
793 ASSERT_NE(rc, HDF_SUCCESS);
794 rc = g_wlanObj->GetChannelMeasResult(g_wlanObj, nullptr, &measChannelResult);
795 ASSERT_NE(rc, HDF_SUCCESS);
796 rc = g_wlanObj->GetChannelMeasResult(g_wlanObj, ifName, nullptr);
797 ASSERT_NE(rc, HDF_SUCCESS);
798 }
799
800 /**
801 * @tc.name: SetProjectionScreenParam_035
802 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
803 * @tc.type: FUNC
804 */
805 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_035, Function | MediumTest | Level2)
806 {
807 const char *ifName = "wlan0";
808 int32_t rc;
809 struct ProjectionScreenCmdParam param;
810 int8_t data = 0;
811 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
812
813 param.buf = &data;
814 param.bufLen = sizeof(data);
815 param.cmdId = CMD_CLOSE_GO_CAC;
816 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
817 printf("ScreenParam = %d, rc = %d.\n", CMD_CLOSE_GO_CAC, rc);
818 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
819 ASSERT_TRUE(flag);
820 }
821
822 /**
823 * @tc.name: SetProjectionScreenParam_036
824 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
825 * @tc.type: FUNC
826 */
827 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_036, Function | MediumTest | Level2)
828 {
829 const char *ifName = "wlan0";
830 int32_t rc;
831 struct ProjectionScreenCmdParam param;
832 int8_t data = 0;
833 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
834
835 param.buf = &data;
836 param.bufLen = sizeof(data);
837 param.cmdId = CMD_SET_GO_CSA_CHANNEL;
838 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
839 printf("ScreenParam = %d, rc = %d.\n", CMD_SET_GO_CSA_CHANNEL, rc);
840 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
841 ASSERT_TRUE(flag);
842 }
843
844 /**
845 * @tc.name: SetProjectionScreenParam_037
846 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
847 * @tc.type: FUNC
848 */
849 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_037, Function | MediumTest | Level2)
850 {
851 const char *ifName = "wlan0";
852 int32_t rc;
853 struct ProjectionScreenCmdParam param;
854 int8_t data = 0;
855 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
856
857 param.buf = &data;
858 param.bufLen = sizeof(data);
859 param.cmdId = CMD_SET_GO_RADAR_DETECT;
860 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
861 printf("ScreenParam = %d, rc = %d.\n", CMD_SET_GO_RADAR_DETECT, rc);
862 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
863 ASSERT_TRUE(flag);
864 }
865
866 /**
867 * @tc.name: SetProjectionScreenParam_038
868 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
869 * @tc.type: FUNC
870 */
871 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_038, Function | MediumTest | Level2)
872 {
873 const char *ifName = "wlan0";
874 int32_t rc;
875 struct ProjectionScreenCmdParam param;
876 int8_t data = 0;
877 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
878
879 param.buf = &data;
880 param.bufLen = sizeof(data);
881 param.cmdId = CMD_ID_MCC_STA_P2P_QUOTA_TIME;
882 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
883 printf("ScreenParam = %d, rc = %d.\n", CMD_ID_MCC_STA_P2P_QUOTA_TIME, rc);
884 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
885 ASSERT_TRUE(flag);
886 }
887
888 /**
889 * @tc.name: SetProjectionScreenParam_039
890 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
891 * @tc.type: FUNC
892 */
893 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_039, Function | MediumTest | Level2)
894 {
895 const char *ifName = "wlan0";
896 int32_t rc;
897 struct ProjectionScreenCmdParam param;
898 int8_t data = 0;
899 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
900
901 param.buf = &data;
902 param.bufLen = sizeof(data);
903 param.cmdId = CMD_ID_CTRL_ROAM_CHANNEL;
904 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
905 printf("ScreenParam = %d, rc = %d.\n", CMD_ID_CTRL_ROAM_CHANNEL, rc);
906 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
907 ASSERT_TRUE(flag);
908 }
909
910 /**
911 * @tc.name: SendCmdIoctl_040
912 * @tc.desc: Wifi hdi send ioctl command function test
913 * @tc.type: FUNC
914 */
915 HWTEST_F(HdfWifiServiceCTest, SendCmdIoctl_040, Function | MediumTest | Level2)
916 {
917 const char *ifName = "wlan0";
918 int32_t rc;
919 bool flag;
920
921 uint8_t deviceType = 5;
922 rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_HID2D_MODULE_INIT, (const int8_t *)&deviceType,
923 sizeof(deviceType));
924 printf("SendCmdIoctl MODULE_INIT, rc=%d.\n", rc);
925 flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT));
926 ASSERT_TRUE(flag);
927 }
928
929 /**
930 * @tc.name: SendCmdIoctl_041
931 * @tc.desc: Wifi hdi send ioctl command function test
932 * @tc.type: FUNC
933 */
934 HWTEST_F(HdfWifiServiceCTest, SendCmdIoctl_041, Function | MediumTest | Level2)
935 {
936 const char *ifName = "wlan0";
937 int32_t rc;
938 bool flag;
939
940 uint8_t batterylevel = 50;
941 rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_SET_BATTERY_LEVEL, (const int8_t *)&batterylevel,
942 sizeof(batterylevel));
943 printf("SendCmdIoctl BATTERY_LEVEL, rc=%d.\n", rc);
944 flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT));
945 ASSERT_TRUE(flag);
946 }
947
948 /**
949 * @tc.name: SendCmdIoctl_042
950 * @tc.desc: Wifi hdi send ioctl command function test
951 * @tc.type: FUNC
952 */
953 HWTEST_F(HdfWifiServiceCTest, SendCmdIoctl_042, Function | MediumTest | Level2)
954 {
955 const char *ifName = "wlan0";
956 int32_t rc;
957
958 struct AdjustChannelInfo chanInfo;
959 chanInfo.msgId = 5;
960 chanInfo.chanNumber = 36;
961 chanInfo.bandwidth = 80;
962 chanInfo.switchType = 0;
963 rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_SET_CHAN_ADJUST, (const int8_t *)&chanInfo,
964 sizeof(chanInfo));
965 printf("SendCmdIoctl CHAN_ADJUST, rc=%d.\n", rc);
966 ASSERT_EQ(rc, -1);
967 }
968
969 /**
970 * @tc.name: GetStaInfo_043
971 * @tc.desc: Wifi hdi get station information function test
972 * @tc.type: FUNC
973 */
974 HWTEST_F(HdfWifiServiceCTest, GetStaInfo_043, Function | MediumTest | Level2)
975 {
976 const char *ifName = "wlan0";
977 int32_t rc;
978 struct WifiStationInfo info;
979 bool flag;
980 uint8_t mac[ETH_ADDR_LEN] = {0};
981
982 rc = g_wlanObj->GetStaInfo(g_wlanObj, ifName, &info, mac, ETH_ADDR_LEN);
983 flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
984 ASSERT_TRUE(flag);
985 }
986
987 /**
988 * @tc.name: GetFeatureTypeTest_044
989 * @tc.desc: Wifi hdi get feature type function test on STA feature
990 * @tc.type: FUNC
991 */
992 HWTEST_F(HdfWifiServiceCTest, GetFeatureTypeTest_044, Function | MediumTest | Level2)
993 {
994 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
995 struct HdfFeatureInfo ifeature;
996 int32_t featureType;
997
998 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
999 if (rc == HDF_SUCCESS) {
1000 rc = g_wlanObj->GetFeatureType(g_wlanObj, &ifeature, &featureType);
1001 ASSERT_EQ(rc, HDF_SUCCESS);
1002 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1003 ASSERT_EQ(rc, HDF_SUCCESS);
1004 }
1005 }
1006
1007 /**
1008 * @tc.name: GetFreqsWithBandTest_045
1009 * @tc.desc: Wifi hdi get freqs function test on STA feature
1010 * @tc.type: FUNC
1011 */
1012 HWTEST_F(HdfWifiServiceCTest, GetFreqsWithBandTest_045, Function | MediumTest | Level2)
1013 {
1014 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1015 struct HdfFeatureInfo ifeature;
1016 struct HdfWifiInfo wifiInfo;
1017 int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
1018 uint32_t freqLen = WLAN_FREQ_MAX_NUM;
1019 wifiInfo.band = IEEE80211_BAND_2GHZ;
1020 wifiInfo.size = WLAN_FREQ_MAX_NUM;
1021 uint32_t i;
1022
1023 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1024 if (rc == HDF_SUCCESS) {
1025 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, freq, &freqLen);
1026 ASSERT_EQ(rc, HDF_SUCCESS);
1027 if (rc == HDF_SUCCESS) {
1028 for (i = 0; i < freqLen; i++) {
1029 printf("%s: freq[%d] = %d\n", __func__, i, freq[i]);
1030 }
1031 }
1032
1033 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1034 ASSERT_EQ(rc, HDF_SUCCESS);
1035 }
1036 }
1037
1038 /**
1039 * @tc.name: GetNetworkIfaceNameTest_046
1040 * @tc.desc: Wifi hdi get network interface name function test on STA feature
1041 * @tc.type: FUNC
1042 */
1043 HWTEST_F(HdfWifiServiceCTest, GetNetworkIfaceNameTest_046, Function | MediumTest | Level2)
1044 {
1045 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1046 struct HdfFeatureInfo ifeature;
1047 char ifNames[IFNAMSIZ] = {0};
1048
1049 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1050 if (rc == HDF_SUCCESS) {
1051 rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, &ifeature, ifNames, IFNAMSIZ);
1052 ASSERT_EQ(rc, HDF_SUCCESS);
1053 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1054 ASSERT_EQ(rc, HDF_SUCCESS);
1055 }
1056 }
1057
1058 /**
1059 * @tc.name: SetTxPowerTest_047
1060 * @tc.desc: Wifi hdi set tx power function test on STA feature
1061 * @tc.type: FUNC
1062 */
1063 HWTEST_F(HdfWifiServiceCTest, SetTxPowerTest_047, Function | MediumTest | Level2)
1064 {
1065 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1066 struct HdfFeatureInfo ifeature;
1067 int32_t power = WLAN_TX_POWER;
1068
1069 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1070 if (rc == HDF_SUCCESS) {
1071 rc = g_wlanObj->SetTxPower(g_wlanObj, &ifeature, power);
1072 ASSERT_EQ(rc, HDF_SUCCESS);
1073 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1074 ASSERT_EQ(rc, HDF_SUCCESS);
1075 }
1076 }
1077
1078 /**
1079 * @tc.name: GetSignalPollInfo_048
1080 * @tc.desc: Wifi hdi get signal information
1081 * @tc.type: FUNC
1082 */
1083 HWTEST_F(HdfWifiServiceCTest, GetSignalPollInfo_048, Function | MediumTest | Level2)
1084 {
1085 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1086 struct HdfFeatureInfo ifeature;
1087 const char *ifName = "wlan0";
1088 struct SignalPollResult signalResult;
1089 (void)memset_s(&signalResult, sizeof(struct SignalPollResult), 0, sizeof(struct SignalPollResult));
1090
1091 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1092 if (rc == HDF_SUCCESS) {
1093 rc = g_wlanObj->GetSignalPollInfo(g_wlanObj, ifName, &signalResult);
1094 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
1095 printf("GetSignalPollInfo rc = %d.\n", rc);
1096 ASSERT_TRUE(flag);
1097 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1098 ASSERT_EQ(rc, HDF_SUCCESS);
1099 }
1100 }
1101
1102 /**
1103 * @tc.name: StartPnoScan_049
1104 * @tc.desc: Wifi hdi start pno scan
1105 * @tc.type: FUNC
1106 */
1107 HWTEST_F(HdfWifiServiceCTest, StartPnoScan_049, Function | MediumTest | Level2)
1108 {
1109 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1110 struct HdfFeatureInfo ifeature;
1111 const char *ifName = "wlan0";
1112 string ssid1 = "xa-hw";
1113 string ssid2 = "xa-hw-03";
1114 struct PnoSettings pnoSettings;
1115 (void)memset_s(&pnoSettings, sizeof(struct PnoSettings), 0, sizeof(struct PnoSettings));
1116 pnoSettings.min2gRssi = -100;
1117 pnoSettings.min5gRssi = -120;
1118 pnoSettings.scanIntervalMs = 60000;
1119 pnoSettings.scanIterations = 3;
1120
1121 pnoSettings.pnoNetworksLen = 2;
1122 pnoSettings.pnoNetworks = (struct PnoNetwork *)OsalMemCalloc(sizeof(struct PnoNetwork) * 2);
1123 pnoSettings.pnoNetworks[0].isHidden = 1;
1124 pnoSettings.pnoNetworks[0].ssid.ssid = const_cast<char*>(ssid1.c_str());
1125 pnoSettings.pnoNetworks[0].ssid.ssidLen = ssid1.length();
1126 pnoSettings.pnoNetworks[0].freqsLen = 2;
1127 pnoSettings.pnoNetworks[0].freqs = (int32_t *)OsalMemCalloc(sizeof(int32_t) * 2);
1128 pnoSettings.pnoNetworks[0].freqs[0] = 2412;
1129 pnoSettings.pnoNetworks[0].freqs[1] = 2447;
1130 pnoSettings.pnoNetworks[1].isHidden = 0;
1131 pnoSettings.pnoNetworks[1].ssid.ssid = const_cast<char*>(ssid2.c_str());
1132 pnoSettings.pnoNetworks[1].ssid.ssidLen = ssid2.length();
1133
1134 int32_t rc = g_wlanObj->RegisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
1135 ASSERT_EQ(rc, HDF_SUCCESS);
1136 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1137 if (rc == HDF_SUCCESS) {
1138 rc = g_wlanObj->StartPnoScan(g_wlanObj, nullptr, &pnoSettings);
1139 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
1140 rc = g_wlanObj->StartPnoScan(g_wlanObj, ifName, nullptr);
1141 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
1142 rc = g_wlanObj->StartPnoScan(g_wlanObj, ifName, &pnoSettings);
1143 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
1144 ASSERT_TRUE(flag);
1145 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1146 ASSERT_EQ(rc, HDF_SUCCESS);
1147 }
1148 rc = g_wlanObj->UnregisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
1149 ASSERT_EQ(rc, HDF_SUCCESS);
1150 OsalMemFree(pnoSettings.pnoNetworks[0].freqs);
1151 OsalMemFree(pnoSettings.pnoNetworks);
1152 }
1153
1154 /**
1155 * @tc.name: StopPnoScan_050
1156 * @tc.desc: Wifi hdi stop pno scan
1157 * @tc.type: FUNC
1158 */
1159 HWTEST_F(HdfWifiServiceCTest, StopPnoScan_050, Function | MediumTest | Level2)
1160 {
1161 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1162 struct HdfFeatureInfo ifeature;
1163 const char *ifName = "wlan0";
1164
1165 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1166 if (rc == HDF_SUCCESS) {
1167 rc = g_wlanObj->StopPnoScan(g_wlanObj, nullptr);
1168 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
1169 rc = g_wlanObj->StopPnoScan(g_wlanObj, ifName);
1170 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
1171 ASSERT_TRUE(flag);
1172 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1173 ASSERT_EQ(rc, HDF_SUCCESS);
1174 }
1175 }
1176
1177 /**
1178 * @tc.name: StartScanTest_051
1179 * @tc.desc: Wifi hdi start scan function test
1180 * @tc.type: FUNC
1181 */
1182 HWTEST_F(HdfWifiServiceCTest, StartScanTest_051, Function | MediumTest | Level2)
1183 {
1184 int32_t rc;
1185 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1186 string ssid1 = "xa-hw";
1187 struct HdfFeatureInfo ifeature;
1188 struct HdfWifiScan scan;
1189
1190 (void)memset_s(&scan, sizeof(struct HdfWifiScan), 0, sizeof(struct HdfWifiScan));
1191 scan.ssidsLen = 1;
1192 scan.ssids = (HdfWifiDriverScanSsid *)OsalMemCalloc(sizeof(HdfWifiDriverScanSsid) * (scan.ssidsLen));
1193 scan.ssids[0].ssid = const_cast<char*>(ssid1.c_str());
1194 scan.ssids[0].ssidLen = ssid1.length();
1195 scan.freqsLen = 2;
1196 scan.freqs = (int32_t *)OsalMemCalloc(sizeof(int32_t) * (scan.freqsLen));
1197 scan.freqs[0] = 2412;
1198 scan.freqs[1] = 2447;
1199 scan.bssidLen = 6;
1200 scan.bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (scan.bssidLen));
1201 scan.bssid[0] = 0x12;
1202 scan.bssid[1] = 0x34;
1203 scan.bssid[2] = 0x56;
1204 scan.bssid[3] = 0x78;
1205 scan.bssid[4] = 0x9A;
1206 scan.bssid[5] = 0xBC;
1207
1208 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1209 if (rc == HDF_SUCCESS) {
1210 rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, &scan);
1211 ASSERT_EQ(rc, HDF_SUCCESS);
1212 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1213 ASSERT_EQ(rc, HDF_SUCCESS);
1214 sleep(SCAN_TIME);
1215 }
1216 OsalMemFree(scan.bssid);
1217 OsalMemFree(scan.freqs);
1218 OsalMemFree(scan.ssids);
1219 }
1220 };
1221