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_1/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);
493 ASSERT_TRUE(flag);
494 rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, code, size);
495 ASSERT_EQ(rc, HDF_SUCCESS);
496 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
497 ASSERT_EQ(rc, HDF_SUCCESS);
498 }
499 }
500
501 /**
502 * @tc.name: CreateFeatureTest_021
503 * @tc.desc: Wifi hdi create feature function test
504 * @tc.type: FUNC
505 */
506 HWTEST_F(HdfWifiServiceCTest, CreateFeatureTest_021, Function | MediumTest | Level2)
507 {
508 struct HdfFeatureInfo ifeature;
509 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
510 int32_t wlanTypeInvalid = PROTOCOL_80211_IFTYPE_NUM;
511
512 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanTypeInvalid, &ifeature);
513 if (rc == HDF_SUCCESS) {
514 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
515 ASSERT_EQ(rc, HDF_SUCCESS);
516 printf("ifname = %s\n", ifeature.ifName);
517 printf("type = %d\n", ifeature.type);
518 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
519 ASSERT_EQ(rc, HDF_SUCCESS);
520 }
521 }
522
523 /**
524 * @tc.name: GetChipIdTest_022
525 * @tc.desc: Wifi hdi get chip id function test
526 * @tc.type: FUNC
527 */
528 HWTEST_F(HdfWifiServiceCTest, GetChipIdTest_022, Function | MediumTest | Level2)
529 {
530 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
531 struct HdfFeatureInfo ifeature;
532 uint8_t chipId = 0;
533
534 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
535 if (rc == HDF_SUCCESS) {
536 rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
537 ASSERT_EQ(rc, HDF_SUCCESS);
538 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
539 ASSERT_EQ(rc, HDF_SUCCESS);
540 }
541 }
542
543 /**
544 * @tc.name: GetDeviceMacAddressTest_023
545 * @tc.desc: Wifi hdi get device mac addr function test on STA feature
546 * @tc.type: FUNC
547 */
548 HWTEST_F(HdfWifiServiceCTest, GetDeviceMacAddressTest_023, Function | MediumTest | Level2)
549 {
550 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
551 struct HdfFeatureInfo ifeature;
552 uint8_t mac[ETH_ADDR_LEN] = {0};
553 uint32_t macLen = ETH_ADDR_LEN;
554
555 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
556 if (rc == HDF_SUCCESS) {
557 rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN);
558 ASSERT_EQ(rc, HDF_SUCCESS);
559 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
560 ASSERT_EQ(rc, HDF_SUCCESS);
561 }
562 }
563
564 /**
565 * @tc.name: GetFeatureByIfNameTest_024
566 * @tc.desc: Wifi hdi get feature by ifname function test
567 * @tc.type: FUNC
568 */
569 HWTEST_F(HdfWifiServiceCTest, GetFeatureByIfNameTest_024, Function | MediumTest | Level2)
570 {
571 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
572 struct HdfFeatureInfo ifeature;
573 const char *ifNameInvalid = "wlanTest";
574
575 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
576 if (rc == HDF_SUCCESS) {
577 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifNameInvalid, &ifeature);
578 ASSERT_NE(rc, HDF_SUCCESS);
579 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifeature.ifName, &ifeature);
580 ASSERT_EQ(rc, HDF_SUCCESS);
581 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
582 ASSERT_EQ(rc, HDF_SUCCESS);
583 }
584 }
585
586 /**
587 * @tc.name: SetMacAddressTest_025
588 * @tc.desc: Wifi hdi set mac addr function test on STA feature
589 * @tc.type: FUNC
590 */
591 HWTEST_F(HdfWifiServiceCTest, SetMacAddressTest_025, Function | MediumTest | Level2)
592 {
593 uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
594 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
595 struct HdfFeatureInfo ifeature;
596 uint32_t macLen = ETH_ADDR_LEN;
597 uint8_t errorMac[ETH_ADDR_LEN] = {0x11, 0x34, 0x56, 0x78, 0xab, 0xcd};
598
599 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
600 if (rc == HDF_SUCCESS) {
601 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, errorMac, macLen);
602 ASSERT_NE(rc, HDF_SUCCESS);
603 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, mac, macLen);
604 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_ERR_DEVICE_BUSY);
605 ASSERT_TRUE(flag);
606 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
607 ASSERT_EQ(rc, HDF_SUCCESS);
608 }
609 }
610
611 /**
612 * @tc.name: GetPowerModeTest_026
613 * @tc.desc: Wifi hdi get power mode function test
614 * @tc.type: FUNC
615 */
616 HWTEST_F(HdfWifiServiceCTest, GetPowerModeTest_026, Function | MediumTest | Level2)
617 {
618 struct HdfFeatureInfo ifeature;
619 uint8_t mode = 0;
620
621 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
622 if (rc == HDF_SUCCESS) {
623 rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, &mode);
624 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
625 ASSERT_TRUE(flag);
626 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
627 ASSERT_EQ(rc, HDF_SUCCESS);
628 }
629 }
630
631 /**
632 * @tc.name: SetPowerModeTest_027
633 * @tc.desc: Wifi hdi set power mode function test
634 * @tc.type: FUNC
635 */
636 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_027, Function | MediumTest | Level2)
637 {
638 struct HdfFeatureInfo ifeature;
639 uint8_t mode = WIFI_POWER_MODE_GENERAL;
640
641 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
642 if (rc == HDF_SUCCESS) {
643 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
644 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
645 ASSERT_TRUE(flag);
646 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
647 ASSERT_EQ(rc, HDF_SUCCESS);
648 }
649 }
650
651 /**
652 * @tc.name: SetPowerModeTest_028
653 * @tc.desc: Wifi hdi set power mode function test
654 * @tc.type: FUNC
655 */
656 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_028, Function | MediumTest | Level2)
657 {
658 struct HdfFeatureInfo ifeature;
659 uint8_t mode = WIFI_POWER_MODE_THROUGH_WALL;
660
661 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
662 if (rc == HDF_SUCCESS) {
663 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
664 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
665 ASSERT_TRUE(flag);
666 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
667 ASSERT_EQ(rc, HDF_SUCCESS);
668 }
669 }
670
671 /**
672 * @tc.name: SetPowerModeTest_029
673 * @tc.desc: Wifi hdi set power mode function test
674 * @tc.type: FUNC
675 */
676 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_029, Function | MediumTest | Level2)
677 {
678 struct HdfFeatureInfo ifeature;
679 uint8_t mode = WIFI_POWER_MODE_NUM;
680
681 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
682 if (rc == HDF_SUCCESS) {
683 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
684 ASSERT_NE(rc, HDF_SUCCESS);
685 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
686 ASSERT_EQ(rc, HDF_SUCCESS);
687 }
688 }
689
690 /**
691 * @tc.name: SetPowerModeTest_30
692 * @tc.desc: Wifi hdi set power mode function test
693 * @tc.type: FUNC
694 */
695 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_030, Function | MediumTest | Level2)
696 {
697 struct HdfFeatureInfo ifeature;
698 uint8_t mode = WIFI_POWER_MODE_SLEEPING;
699
700 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
701 if (rc == HDF_SUCCESS) {
702 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
703 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
704 ASSERT_TRUE(flag);
705 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
706 ASSERT_EQ(rc, HDF_SUCCESS);
707 }
708 }
709
710 /**
711 * @tc.name: SetPowerModeTest_031
712 * @tc.desc: Wifi hdi set power mode function test
713 * @tc.type: FUNC
714 */
715 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_031, Function | MediumTest | Level2)
716 {
717 struct HdfFeatureInfo ifeature;
718 uint8_t mode = WIFI_POWER_MODE_GENERAL;
719
720 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
721 if (rc == HDF_SUCCESS) {
722 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
723 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
724 ASSERT_TRUE(flag);
725 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
726 ASSERT_EQ(rc, HDF_SUCCESS);
727 }
728 }
729
730 /**
731 * @tc.name: SetPowerModeTest_032
732 * @tc.desc: Wifi hdi set power mode function test
733 * @tc.type: FUNC
734 */
735 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_032, Function | MediumTest | Level2)
736 {
737 struct HdfFeatureInfo ifeature;
738 uint8_t mode = WIFI_POWER_MODE_THROUGH_WALL;
739
740 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
741 if (rc == HDF_SUCCESS) {
742 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
743 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
744 ASSERT_TRUE(flag);
745 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
746 ASSERT_EQ(rc, HDF_SUCCESS);
747 }
748 }
749
750 /**
751 * @tc.name: SetPowerModeTest_033
752 * @tc.desc: Wifi hdi set power mode function test
753 * @tc.type: FUNC
754 */
755 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_033, Function | MediumTest | Level2)
756 {
757 struct HdfFeatureInfo ifeature;
758 uint8_t mode = WIFI_POWER_MODE_NUM;
759
760 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
761 if (rc == HDF_SUCCESS) {
762 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
763 ASSERT_NE(rc, HDF_SUCCESS);
764 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
765 ASSERT_EQ(rc, HDF_SUCCESS);
766 }
767 }
768
769 /**
770 * @tc.name: StartChannelMeasTest_034
771 * @tc.desc: Wifi hdi start channel meas and get meas result function test
772 * @tc.type: FUNC
773 */
774 HWTEST_F(HdfWifiServiceCTest, StartChannelMeasTest_034, Function | MediumTest | Level2)
775 {
776 const char *ifName = "wlan0";
777 struct MeasChannelParam measChannelParam;
778 struct MeasChannelResult measChannelResult = {0};
779
780 measChannelParam.channelId = 1;
781 measChannelParam.measTime = 15;
782 int32_t rc = g_wlanObj->StartChannelMeas(g_wlanObj, ifName, &measChannelParam);
783 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
784 ASSERT_TRUE(flag);
785 sleep(MEAS_CHANNEL_TIME);
786 rc = g_wlanObj->GetChannelMeasResult(g_wlanObj, ifName, &measChannelResult);
787 flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NODATA);
788 ASSERT_TRUE(flag);
789 rc = g_wlanObj->StartChannelMeas(g_wlanObj, nullptr, &measChannelParam);
790 ASSERT_NE(rc, HDF_SUCCESS);
791 rc = g_wlanObj->StartChannelMeas(g_wlanObj, ifName, nullptr);
792 ASSERT_NE(rc, HDF_SUCCESS);
793 rc = g_wlanObj->GetChannelMeasResult(g_wlanObj, nullptr, &measChannelResult);
794 ASSERT_NE(rc, HDF_SUCCESS);
795 rc = g_wlanObj->GetChannelMeasResult(g_wlanObj, ifName, nullptr);
796 ASSERT_NE(rc, HDF_SUCCESS);
797 }
798
799 /**
800 * @tc.name: SetProjectionScreenParam_035
801 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
802 * @tc.type: FUNC
803 */
804 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_035, Function | MediumTest | Level2)
805 {
806 const char *ifName = "wlan0";
807 int32_t rc;
808 struct ProjectionScreenCmdParam param;
809 int8_t data = 0;
810 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
811
812 param.buf = &data;
813 param.bufLen = sizeof(data);
814 param.cmdId = CMD_CLOSE_GO_CAC;
815 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
816 printf("ScreenParam = %d, rc = %d.\n", CMD_CLOSE_GO_CAC, rc);
817 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
818 ASSERT_TRUE(flag);
819 }
820
821 /**
822 * @tc.name: SetProjectionScreenParam_036
823 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
824 * @tc.type: FUNC
825 */
826 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_036, Function | MediumTest | Level2)
827 {
828 const char *ifName = "wlan0";
829 int32_t rc;
830 struct ProjectionScreenCmdParam param;
831 int8_t data = 0;
832 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
833
834 param.buf = &data;
835 param.bufLen = sizeof(data);
836 param.cmdId = CMD_SET_GO_CSA_CHANNEL;
837 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
838 printf("ScreenParam = %d, rc = %d.\n", CMD_SET_GO_CSA_CHANNEL, rc);
839 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
840 ASSERT_TRUE(flag);
841 }
842
843 /**
844 * @tc.name: SetProjectionScreenParam_037
845 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
846 * @tc.type: FUNC
847 */
848 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_037, Function | MediumTest | Level2)
849 {
850 const char *ifName = "wlan0";
851 int32_t rc;
852 struct ProjectionScreenCmdParam param;
853 int8_t data = 0;
854 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
855
856 param.buf = &data;
857 param.bufLen = sizeof(data);
858 param.cmdId = CMD_SET_GO_RADAR_DETECT;
859 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
860 printf("ScreenParam = %d, rc = %d.\n", CMD_SET_GO_RADAR_DETECT, rc);
861 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
862 ASSERT_TRUE(flag);
863 }
864
865 /**
866 * @tc.name: SetProjectionScreenParam_038
867 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
868 * @tc.type: FUNC
869 */
870 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_038, Function | MediumTest | Level2)
871 {
872 const char *ifName = "wlan0";
873 int32_t rc;
874 struct ProjectionScreenCmdParam param;
875 int8_t data = 0;
876 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
877
878 param.buf = &data;
879 param.bufLen = sizeof(data);
880 param.cmdId = CMD_ID_MCC_STA_P2P_QUOTA_TIME;
881 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
882 printf("ScreenParam = %d, rc = %d.\n", CMD_ID_MCC_STA_P2P_QUOTA_TIME, rc);
883 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
884 ASSERT_TRUE(flag);
885 }
886
887 /**
888 * @tc.name: SetProjectionScreenParam_039
889 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
890 * @tc.type: FUNC
891 */
892 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_039, Function | MediumTest | Level2)
893 {
894 const char *ifName = "wlan0";
895 int32_t rc;
896 struct ProjectionScreenCmdParam param;
897 int8_t data = 0;
898 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
899
900 param.buf = &data;
901 param.bufLen = sizeof(data);
902 param.cmdId = CMD_ID_CTRL_ROAM_CHANNEL;
903 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
904 printf("ScreenParam = %d, rc = %d.\n", CMD_ID_CTRL_ROAM_CHANNEL, rc);
905 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NETDOWN);
906 ASSERT_TRUE(flag);
907 }
908
909 /**
910 * @tc.name: SendCmdIoctl_040
911 * @tc.desc: Wifi hdi send ioctl command function test
912 * @tc.type: FUNC
913 */
914 HWTEST_F(HdfWifiServiceCTest, SendCmdIoctl_040, Function | MediumTest | Level2)
915 {
916 const char *ifName = "wlan0";
917 int32_t rc;
918 bool flag;
919
920 uint8_t deviceType = 5;
921 rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_HID2D_MODULE_INIT, (const int8_t *)&deviceType,
922 sizeof(deviceType));
923 printf("SendCmdIoctl MODULE_INIT, rc=%d.\n", rc);
924 flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT));
925 ASSERT_TRUE(flag);
926 }
927
928 /**
929 * @tc.name: SendCmdIoctl_041
930 * @tc.desc: Wifi hdi send ioctl command function test
931 * @tc.type: FUNC
932 */
933 HWTEST_F(HdfWifiServiceCTest, SendCmdIoctl_041, Function | MediumTest | Level2)
934 {
935 const char *ifName = "wlan0";
936 int32_t rc;
937 bool flag;
938
939 uint8_t batterylevel = 50;
940 rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_SET_BATTERY_LEVEL, (const int8_t *)&batterylevel,
941 sizeof(batterylevel));
942 printf("SendCmdIoctl BATTERY_LEVEL, rc=%d.\n", rc);
943 flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT));
944 ASSERT_TRUE(flag);
945 }
946
947 /**
948 * @tc.name: SendCmdIoctl_042
949 * @tc.desc: Wifi hdi send ioctl command function test
950 * @tc.type: FUNC
951 */
952 HWTEST_F(HdfWifiServiceCTest, SendCmdIoctl_042, Function | MediumTest | Level2)
953 {
954 const char *ifName = "wlan0";
955 int32_t rc;
956 bool flag;
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 flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT) || (rc == HDF_DEV_ERR_NETDOWN));
967 ASSERT_TRUE(flag);
968 }
969
970 /**
971 * @tc.name: GetStaInfo_043
972 * @tc.desc: Wifi hdi get station information function test
973 * @tc.type: FUNC
974 */
975 HWTEST_F(HdfWifiServiceCTest, GetStaInfo_043, Function | MediumTest | Level2)
976 {
977 const char *ifName = "wlan0";
978 int32_t rc;
979 struct WifiStationInfo info;
980 bool flag;
981 uint8_t mac[ETH_ADDR_LEN] = {0};
982
983 rc = g_wlanObj->GetStaInfo(g_wlanObj, ifName, &info, mac, ETH_ADDR_LEN);
984 flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
985 ASSERT_TRUE(flag);
986 }
987
988 /**
989 * @tc.name: GetFeatureTypeTest_044
990 * @tc.desc: Wifi hdi get feature type function test on STA feature
991 * @tc.type: FUNC
992 */
993 HWTEST_F(HdfWifiServiceCTest, GetFeatureTypeTest_044, Function | MediumTest | Level2)
994 {
995 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
996 struct HdfFeatureInfo ifeature;
997 int32_t featureType;
998
999 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1000 if (rc == HDF_SUCCESS) {
1001 rc = g_wlanObj->GetFeatureType(g_wlanObj, &ifeature, &featureType);
1002 ASSERT_EQ(rc, HDF_SUCCESS);
1003 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1004 ASSERT_EQ(rc, HDF_SUCCESS);
1005 }
1006 }
1007
1008 /**
1009 * @tc.name: GetFreqsWithBandTest_045
1010 * @tc.desc: Wifi hdi get freqs function test on STA feature
1011 * @tc.type: FUNC
1012 */
1013 HWTEST_F(HdfWifiServiceCTest, GetFreqsWithBandTest_045, Function | MediumTest | Level2)
1014 {
1015 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1016 struct HdfFeatureInfo ifeature;
1017 struct HdfWifiInfo wifiInfo;
1018 int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
1019 uint32_t freqLen = WLAN_FREQ_MAX_NUM;
1020 wifiInfo.band = IEEE80211_BAND_2GHZ;
1021 wifiInfo.size = WLAN_FREQ_MAX_NUM;
1022 uint32_t i;
1023
1024 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1025 if (rc == HDF_SUCCESS) {
1026 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, freq, &freqLen);
1027 ASSERT_EQ(rc, HDF_SUCCESS);
1028 if (rc == HDF_SUCCESS) {
1029 for (i = 0; i < freqLen; i++) {
1030 printf("%s: freq[%d] = %d\n", __func__, i, freq[i]);
1031 }
1032 }
1033
1034 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1035 ASSERT_EQ(rc, HDF_SUCCESS);
1036 }
1037 }
1038
1039 /**
1040 * @tc.name: GetNetworkIfaceNameTest_046
1041 * @tc.desc: Wifi hdi get network interface name function test on STA feature
1042 * @tc.type: FUNC
1043 */
1044 HWTEST_F(HdfWifiServiceCTest, GetNetworkIfaceNameTest_046, Function | MediumTest | Level2)
1045 {
1046 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1047 struct HdfFeatureInfo ifeature;
1048 char ifNames[IFNAMSIZ] = {0};
1049
1050 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1051 if (rc == HDF_SUCCESS) {
1052 rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, &ifeature, ifNames, IFNAMSIZ);
1053 ASSERT_EQ(rc, HDF_SUCCESS);
1054 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1055 ASSERT_EQ(rc, HDF_SUCCESS);
1056 }
1057 }
1058
1059 /**
1060 * @tc.name: SetTxPowerTest_047
1061 * @tc.desc: Wifi hdi set tx power function test on STA feature
1062 * @tc.type: FUNC
1063 */
1064 HWTEST_F(HdfWifiServiceCTest, SetTxPowerTest_047, Function | MediumTest | Level2)
1065 {
1066 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1067 struct HdfFeatureInfo ifeature;
1068 int32_t power = WLAN_TX_POWER;
1069
1070 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1071 if (rc == HDF_SUCCESS) {
1072 rc = g_wlanObj->SetTxPower(g_wlanObj, &ifeature, power);
1073 ASSERT_EQ(rc, HDF_SUCCESS);
1074 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1075 ASSERT_EQ(rc, HDF_SUCCESS);
1076 }
1077 }
1078
1079 /**
1080 * @tc.name: GetSignalPollInfo_048
1081 * @tc.desc: Wifi hdi get signal information
1082 * @tc.type: FUNC
1083 */
1084 HWTEST_F(HdfWifiServiceCTest, GetSignalPollInfo_048, Function | MediumTest | Level2)
1085 {
1086 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1087 struct HdfFeatureInfo ifeature;
1088 const char *ifName = "wlan0";
1089 struct SignalPollResult signalResult;
1090 (void)memset_s(&signalResult, sizeof(struct SignalPollResult), 0, sizeof(struct SignalPollResult));
1091
1092 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1093 if (rc == HDF_SUCCESS) {
1094 rc = g_wlanObj->GetSignalPollInfo(g_wlanObj, ifName, &signalResult);
1095 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
1096 printf("GetSignalPollInfo rc = %d.\n", rc);
1097 ASSERT_TRUE(flag);
1098 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1099 ASSERT_EQ(rc, HDF_SUCCESS);
1100 }
1101 }
1102
1103 /**
1104 * @tc.name: StartPnoScan_049
1105 * @tc.desc: Wifi hdi start pno scan
1106 * @tc.type: FUNC
1107 */
1108 HWTEST_F(HdfWifiServiceCTest, StartPnoScan_049, Function | MediumTest | Level2)
1109 {
1110 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1111 struct HdfFeatureInfo ifeature;
1112 const char *ifName = "wlan0";
1113 string ssid1 = "xa-hw";
1114 string ssid2 = "xa-hw-03";
1115 struct PnoSettings pnoSettings;
1116 (void)memset_s(&pnoSettings, sizeof(struct PnoSettings), 0, sizeof(struct PnoSettings));
1117 pnoSettings.min2gRssi = -100;
1118 pnoSettings.min5gRssi = -120;
1119 pnoSettings.scanIntervalMs = 60000;
1120 pnoSettings.scanIterations = 3;
1121
1122 pnoSettings.pnoNetworksLen = 2;
1123 pnoSettings.pnoNetworks = (struct PnoNetwork *)OsalMemCalloc(sizeof(struct PnoNetwork) * 2);
1124 pnoSettings.pnoNetworks[0].isHidden = 1;
1125 pnoSettings.pnoNetworks[0].ssid.ssid = const_cast<char*>(ssid1.c_str());
1126 pnoSettings.pnoNetworks[0].ssid.ssidLen = ssid1.length();
1127 pnoSettings.pnoNetworks[0].freqsLen = 2;
1128 pnoSettings.pnoNetworks[0].freqs = (int32_t *)OsalMemCalloc(sizeof(int32_t) * 2);
1129 pnoSettings.pnoNetworks[0].freqs[0] = 2412;
1130 pnoSettings.pnoNetworks[0].freqs[1] = 2447;
1131 pnoSettings.pnoNetworks[1].isHidden = 0;
1132 pnoSettings.pnoNetworks[1].ssid.ssid = const_cast<char*>(ssid2.c_str());
1133 pnoSettings.pnoNetworks[1].ssid.ssidLen = ssid2.length();
1134
1135 int32_t rc = g_wlanObj->RegisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
1136 ASSERT_EQ(rc, HDF_SUCCESS);
1137 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1138 if (rc == HDF_SUCCESS) {
1139 rc = g_wlanObj->StartPnoScan(g_wlanObj, nullptr, &pnoSettings);
1140 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
1141 rc = g_wlanObj->StartPnoScan(g_wlanObj, ifName, nullptr);
1142 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
1143 rc = g_wlanObj->StartPnoScan(g_wlanObj, ifName, &pnoSettings);
1144 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
1145 ASSERT_TRUE(flag);
1146 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1147 ASSERT_EQ(rc, HDF_SUCCESS);
1148 }
1149 rc = g_wlanObj->UnregisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
1150 ASSERT_EQ(rc, HDF_SUCCESS);
1151 OsalMemFree(pnoSettings.pnoNetworks[0].freqs);
1152 OsalMemFree(pnoSettings.pnoNetworks);
1153 }
1154
1155 /**
1156 * @tc.name: StopPnoScan_050
1157 * @tc.desc: Wifi hdi stop pno scan
1158 * @tc.type: FUNC
1159 */
1160 HWTEST_F(HdfWifiServiceCTest, StopPnoScan_050, Function | MediumTest | Level2)
1161 {
1162 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1163 struct HdfFeatureInfo ifeature;
1164 const char *ifName = "wlan0";
1165
1166 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1167 if (rc == HDF_SUCCESS) {
1168 rc = g_wlanObj->StopPnoScan(g_wlanObj, nullptr);
1169 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
1170 rc = g_wlanObj->StopPnoScan(g_wlanObj, ifName);
1171 bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
1172 ASSERT_TRUE(flag);
1173 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1174 ASSERT_EQ(rc, HDF_SUCCESS);
1175 }
1176 }
1177
1178 /**
1179 * @tc.name: StartScanTest_051
1180 * @tc.desc: Wifi hdi start scan function test
1181 * @tc.type: FUNC
1182 */
1183 HWTEST_F(HdfWifiServiceCTest, StartScanTest_051, Function | MediumTest | Level2)
1184 {
1185 int32_t rc;
1186 const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
1187 string ssid1 = "xa-hw";
1188 struct HdfFeatureInfo ifeature;
1189 struct HdfWifiScan scan;
1190
1191 (void)memset_s(&scan, sizeof(struct HdfWifiScan), 0, sizeof(struct HdfWifiScan));
1192 scan.ssidsLen = 1;
1193 scan.ssids = (HdfWifiDriverScanSsid *)OsalMemCalloc(sizeof(HdfWifiDriverScanSsid) * (scan.ssidsLen));
1194 scan.ssids[0].ssid = const_cast<char*>(ssid1.c_str());
1195 scan.ssids[0].ssidLen = ssid1.length();
1196 scan.freqsLen = 2;
1197 scan.freqs = (int32_t *)OsalMemCalloc(sizeof(int32_t) * (scan.freqsLen));
1198 scan.freqs[0] = 2412;
1199 scan.freqs[1] = 2447;
1200 scan.bssidLen = 6;
1201 scan.bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (scan.bssidLen));
1202 scan.bssid[0] = 0x12;
1203 scan.bssid[1] = 0x34;
1204 scan.bssid[2] = 0x56;
1205 scan.bssid[3] = 0x78;
1206 scan.bssid[4] = 0x9A;
1207 scan.bssid[5] = 0xBC;
1208
1209 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
1210 if (rc == HDF_SUCCESS) {
1211 rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, &scan);
1212 ASSERT_EQ(rc, HDF_SUCCESS);
1213 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
1214 ASSERT_EQ(rc, HDF_SUCCESS);
1215 sleep(SCAN_TIME);
1216 }
1217 OsalMemFree(scan.bssid);
1218 OsalMemFree(scan.freqs);
1219 OsalMemFree(scan.ssids);
1220 }
1221 };
1222