1 /*
2 * Copyright (c) 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 HdiDirectTest {
25 const int32_t DEFAULT_COMBO_SIZE = 6;
26 const int32_t WLAN_MAX_NUM_STA_WITH_AP = 4;
27 const int32_t WLAN_FREQ_MAX_NUM = 35;
28 const int32_t WLAN_TX_POWER = 160;
29 const char *WLAN_SERVICE_NAME = "wlan_interface_service";
30
31 class HdfWifiDirectTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 };
38
39 static struct IWlanInterface *g_wlanObj = nullptr;
40 struct IWlanCallback *g_wlanCallbackObj = nullptr;
SetUpTestCase()41 void HdfWifiDirectTest::SetUpTestCase()
42 {
43 g_wlanObj = IWlanInterfaceGetInstance(WLAN_SERVICE_NAME, true);
44 g_wlanCallbackObj = WlanCallbackServiceGet();
45 ASSERT_TRUE(g_wlanObj != nullptr);
46 ASSERT_TRUE(g_wlanCallbackObj != nullptr);
47 }
48
TearDownTestCase()49 void HdfWifiDirectTest::TearDownTestCase()
50 {
51 IWlanInterfaceReleaseInstance(WLAN_SERVICE_NAME, g_wlanObj, true);
52 WlanCallbackServiceRelease(g_wlanCallbackObj);
53 }
54
SetUp()55 void HdfWifiDirectTest::SetUp()
56 {
57 }
58
TearDown()59 void HdfWifiDirectTest::TearDown()
60 {
61 }
62
63 /**
64 * @tc.name: GetSupportFeatureTest_001
65 * @tc.desc: Wifi hdi get support feature function test
66 * @tc.type: FUNC
67 */
68 HWTEST_F(HdfWifiDirectTest, GetSupportFeatureTest_001, Function | MediumTest | Level2)
69 {
70 uint8_t supType[PROTOCOL_80211_IFTYPE_NUM + 1] = {0};
71 uint32_t supTypeLenInvalid = 6;
72
73 int32_t rc = g_wlanObj->GetSupportFeature(g_wlanObj, nullptr, &supTypeLenInvalid);
74 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
75 rc = g_wlanObj->GetSupportFeature(g_wlanObj, supType, nullptr);
76 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
77 rc = g_wlanObj->GetSupportFeature(g_wlanObj, supType, &supTypeLenInvalid);
78 ASSERT_EQ(rc, HDF_FAILURE);
79 }
80
81 /**
82 * @tc.name: GetSupportComboTest_002
83 * @tc.desc: Wifi hdi get support combo function test
84 * @tc.type: FUNC
85 */
86 HWTEST_F(HdfWifiDirectTest, GetSupportComboTest_002, Function | MediumTest | Level2)
87 {
88 uint64_t combo[DEFAULT_COMBO_SIZE] = {0};
89
90 int32_t rc = g_wlanObj->GetSupportCombo(g_wlanObj, nullptr);
91 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
92 rc = g_wlanObj->GetSupportCombo(g_wlanObj, combo);
93 ASSERT_EQ(rc, HDF_FAILURE);
94 }
95
96 /**
97 * @tc.name: CreateFeatureTest_003
98 * @tc.desc: Wifi hdi create feature function test
99 * @tc.type: FUNC
100 */
101 HWTEST_F(HdfWifiDirectTest, CreateFeatureTest_003, Function | MediumTest | Level2)
102 {
103 struct HdfFeatureInfo ifeature;
104 const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
105
106 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
107 int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, nullptr);
108 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
109 rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
110 ASSERT_EQ(rc, HDF_FAILURE);
111 }
112
113 /**
114 * @tc.name: DestroyFeatureTest_004
115 * @tc.desc: Wifi hdi destroy feature function test
116 * @tc.type: FUNC
117 */
118 HWTEST_F(HdfWifiDirectTest, DestroyFeatureTest_004, Function | MediumTest | Level2)
119 {
120 struct HdfFeatureInfo ifeature;
121 string ifName = "wlan0";
122
123 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
124 int32_t rc = g_wlanObj->DestroyFeature(g_wlanObj, nullptr);
125 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
126 ifeature.ifName = nullptr;
127 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
128 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
129 ifeature.ifName = const_cast<char*>(ifName.c_str());
130 rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
131 ASSERT_EQ(rc, HDF_FAILURE);
132 }
133
134 /**
135 * @tc.name: GetAssociatedStasTest_005
136 * @tc.desc: Wifi hdi get associated stas function test
137 * @tc.type: FUNC
138 */
139 HWTEST_F(HdfWifiDirectTest, GetAssociatedStasTest_005, Function | MediumTest | Level2)
140 {
141 struct HdfFeatureInfo ifeature;
142 struct HdfStaInfo staInfo[WLAN_MAX_NUM_STA_WITH_AP] = {{0}};
143 uint32_t staInfoLen = WLAN_MAX_NUM_STA_WITH_AP;
144 uint32_t num = 0;
145 string ifName = "wlan0";
146
147 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
148 int32_t rc = g_wlanObj->GetAssociatedStas(g_wlanObj, nullptr, staInfo, &staInfoLen, &num);
149 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
150 ifeature.ifName = nullptr;
151 rc = g_wlanObj->GetAssociatedStas(g_wlanObj, &ifeature, staInfo, &staInfoLen, &num);
152 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
153 ifeature.ifName = const_cast<char*>(ifName.c_str());
154 rc = g_wlanObj->GetAssociatedStas(g_wlanObj, &ifeature, nullptr, &staInfoLen, &num);
155 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
156 rc = g_wlanObj->GetAssociatedStas(g_wlanObj, &ifeature, staInfo, nullptr, &num);
157 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
158 rc = g_wlanObj->GetAssociatedStas(g_wlanObj, &ifeature, staInfo, &staInfoLen, nullptr);
159 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
160 rc = g_wlanObj->GetAssociatedStas(g_wlanObj, &ifeature, staInfo, &staInfoLen, &num);
161 ASSERT_EQ(rc, HDF_FAILURE);
162 }
163
164 /**
165 * @tc.name: GetChipIdTest_006
166 * @tc.desc: Wifi hdi get chip id function test
167 * @tc.type: FUNC
168 */
169 HWTEST_F(HdfWifiDirectTest, GetChipIdTest_006, Function | MediumTest | Level2)
170 {
171 struct HdfFeatureInfo ifeature;
172 uint8_t chipId = 0;
173 string ifName = "wlan0";
174
175 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
176 int32_t rc = g_wlanObj->GetChipId(g_wlanObj, nullptr, &chipId);
177 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
178 ifeature.ifName = nullptr;
179 rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
180 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
181 ifeature.ifName = const_cast<char*>(ifName.c_str());
182 rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, nullptr);
183 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
184 rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
185 ASSERT_EQ(rc, HDF_FAILURE);
186 }
187
188 /**
189 * @tc.name: GetDeviceMacAddressTest_007
190 * @tc.desc: Wifi hdi get device mac addr function test on STA feature
191 * @tc.type: FUNC
192 */
193 HWTEST_F(HdfWifiDirectTest, GetDeviceMacAddressTest_007, Function | MediumTest | Level2)
194 {
195 struct HdfFeatureInfo ifeature;
196 uint8_t mac[ETH_ADDR_LEN] = {0};
197 uint32_t macLen = ETH_ADDR_LEN;
198 string ifName = "wlan0";
199
200 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
201 int32_t rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, nullptr, mac, &macLen, ETH_ADDR_LEN);
202 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
203 ifeature.ifName = nullptr;
204 rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN);
205 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
206 ifeature.ifName = const_cast<char*>(ifName.c_str());
207 rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, nullptr, &macLen, ETH_ADDR_LEN);
208 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
209 rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, nullptr, ETH_ADDR_LEN);
210 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
211 rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN);
212 ASSERT_EQ(rc, HDF_FAILURE);
213 }
214
215 /**
216 * @tc.name: GetFeatureByIfNameTest_008
217 * @tc.desc: Wifi hdi get feature by ifname function test
218 * @tc.type: FUNC
219 */
220 HWTEST_F(HdfWifiDirectTest, GetFeatureByIfNameTest_008, Function | MediumTest | Level2)
221 {
222 struct HdfFeatureInfo ifeature;
223 const char *ifName = "wlan0";
224
225 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
226 int32_t rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, nullptr, &ifeature);
227 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
228 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifName, nullptr);
229 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
230 rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifName, &ifeature);
231 ASSERT_EQ(rc, HDF_FAILURE);
232 }
233
234 /**
235 * @tc.name: GetFeatureTypeTest_009
236 * @tc.desc: Wifi hdi get feature type function test on STA feature
237 * @tc.type: FUNC
238 */
239 HWTEST_F(HdfWifiDirectTest, GetFeatureTypeTest_009, Function | MediumTest | Level2)
240 {
241 struct HdfFeatureInfo ifeature;
242 int32_t featureType;
243
244 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
245 int32_t rc = g_wlanObj->GetFeatureType(g_wlanObj, nullptr, &featureType);
246 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
247 rc = g_wlanObj->GetFeatureType(g_wlanObj, &ifeature, nullptr);
248 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
249 rc = g_wlanObj->GetFeatureType(g_wlanObj, &ifeature, &featureType);
250 ASSERT_EQ(rc, HDF_FAILURE);
251 }
252
253 /**
254 * @tc.name: GetFreqsWithBandTest_010
255 * @tc.desc: Wifi hdi get freqs function test on STA feature
256 * @tc.type: FUNC
257 */
258 HWTEST_F(HdfWifiDirectTest, GetFreqsWithBandTest_010, Function | MediumTest | Level2)
259 {
260 struct HdfFeatureInfo ifeature;
261 struct HdfWifiInfo wifiInfo;
262 int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
263 uint32_t freqLen = WLAN_FREQ_MAX_NUM;
264 wifiInfo.band = IEEE80211_BAND_2GHZ;
265 wifiInfo.size = WLAN_FREQ_MAX_NUM;
266 string ifName = "wlan0";
267
268 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
269 int32_t rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, nullptr, &wifiInfo, freq, &freqLen);
270 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
271 ifeature.ifName = nullptr;
272 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, freq, &freqLen);
273 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
274 ifeature.ifName = const_cast<char*>(ifName.c_str());
275 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, nullptr, freq, &freqLen);
276 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
277 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, nullptr, &freqLen);
278 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
279 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, freq, nullptr);
280 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
281 rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, freq, &freqLen);
282 ASSERT_EQ(rc, HDF_FAILURE);
283 }
284
285 /**
286 * @tc.name: GetChipIdTest_011
287 * @tc.desc: Wifi hdi get chip id function test on STA feature
288 * @tc.type: FUNC
289 */
290 HWTEST_F(HdfWifiDirectTest, GetChipIdTest_011, Function | MediumTest | Level2)
291 {
292 uint8_t chipId = 0;
293 uint32_t num = 0;
294 char ifNames[IFNAMSIZ] = {0};
295
296 int32_t rc = g_wlanObj->GetIfNamesByChipId(g_wlanObj, chipId, nullptr, IFNAMSIZ, &num);
297 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
298 rc = g_wlanObj->GetIfNamesByChipId(g_wlanObj, chipId, ifNames, IFNAMSIZ, nullptr);
299 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
300 rc = g_wlanObj->GetIfNamesByChipId(g_wlanObj, chipId, ifNames, IFNAMSIZ, &num);
301 ASSERT_EQ(rc, HDF_FAILURE);
302 }
303
304 /**
305 * @tc.name: GetNetworkIfaceNameTest_012
306 * @tc.desc: Wifi hdi get network interface name function test on STA feature
307 * @tc.type: FUNC
308 */
309 HWTEST_F(HdfWifiDirectTest, GetNetworkIfaceNameTest_012, Function | MediumTest | Level2)
310 {
311 struct HdfFeatureInfo ifeature;
312 char ifNames[IFNAMSIZ] = {0};
313 string ifName = "wlan0";
314
315 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
316 int32_t rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, nullptr, ifNames, IFNAMSIZ);
317 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
318 ifeature.ifName = nullptr;
319 rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, &ifeature, ifNames, IFNAMSIZ);
320 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
321 ifeature.ifName = const_cast<char*>(ifName.c_str());
322 rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, &ifeature, nullptr, IFNAMSIZ);
323 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
324 rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, &ifeature, ifNames, IFNAMSIZ);
325 ASSERT_EQ(rc, HDF_FAILURE);
326 }
327
328 /**
329 * @tc.name: RegisterEventCallbackTest_013
330 * @tc.desc: Wifi hdi register event call back function test
331 * @tc.type: FUNC
332 */
333 HWTEST_F(HdfWifiDirectTest, RegisterEventCallbackTest_013, Function | MediumTest | Level2)
334 {
335 const char *ifName = "wlan0";
336
337 int32_t rc = g_wlanObj->RegisterEventCallback(g_wlanObj, nullptr, ifName);
338 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
339 rc = g_wlanObj->RegisterEventCallback(g_wlanObj, g_wlanCallbackObj, nullptr);
340 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
341 rc = g_wlanObj->RegisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
342 ASSERT_EQ(rc, HDF_FAILURE);
343 }
344
345 /**
346 * @tc.name: ResetDriverTest_014
347 * @tc.desc: Wifi hdi reset driver function test
348 * @tc.type: FUNC
349 */
350 HWTEST_F(HdfWifiDirectTest, ResetDriverTest_014, Function | MediumTest | Level2)
351 {
352 const char *ifName = "wlan0";
353 uint8_t chipId = 0;
354
355 int32_t rc = g_wlanObj->ResetDriver(g_wlanObj, chipId, nullptr);
356 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
357 rc = g_wlanObj->ResetDriver(g_wlanObj, chipId, ifName);
358 ASSERT_EQ(rc, HDF_FAILURE);
359 }
360
361 /**
362 * @tc.name: StartScanTest_015
363 * @tc.desc: Wifi hdi start scan function test
364 * @tc.type: FUNC
365 */
366 HWTEST_F(HdfWifiDirectTest, StartScanTest_015, Function | MediumTest | Level2)
367 {
368 struct HdfFeatureInfo ifeature;
369 struct HdfWifiScan scan = {0};
370 string ifName = "wlan0";
371
372 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
373 int32_t rc = g_wlanObj->StartScan(g_wlanObj, nullptr, &scan);
374 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
375 ifeature.ifName = nullptr;
376 rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, &scan);
377 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
378 ifeature.ifName = const_cast<char*>(ifName.c_str());
379 rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, nullptr);
380 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
381 rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, &scan);
382 ASSERT_EQ(rc, HDF_FAILURE);
383 }
384
385 /**
386 * @tc.name: UnregisterEventCallbackTest_016
387 * @tc.desc: Wifi hdi unreister event call back function test
388 * @tc.type: FUNC
389 */
390 HWTEST_F(HdfWifiDirectTest, UnregisterEventCallbackTest_016, Function | MediumTest | Level2)
391 {
392 const char *ifName = "wlan0";
393
394 int32_t rc = g_wlanObj->UnregisterEventCallback(g_wlanObj, nullptr, ifName);
395 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
396 rc = g_wlanObj->UnregisterEventCallback(g_wlanObj, g_wlanCallbackObj, nullptr);
397 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
398 rc = g_wlanObj->UnregisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
399 ASSERT_EQ(rc, HDF_FAILURE);
400 }
401
402 /**
403 * @tc.name: SetCountryCodeTest_017
404 * @tc.desc: Wifi hdi set country code function test
405 * @tc.type: FUNC
406 */
407 HWTEST_F(HdfWifiDirectTest, SetCountryCodeTest_017, Function | MediumTest | Level2)
408 {
409 const char *code = "CN";
410 struct HdfFeatureInfo ifeature;
411 const char *codeDigital = "99";
412 uint32_t size = 2;
413 string ifName = "wlan0";
414
415 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
416 int32_t rc = g_wlanObj->SetCountryCode(g_wlanObj, nullptr, codeDigital, size);
417 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
418 ifeature.ifName = nullptr;
419 rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, code, size);
420 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
421 ifeature.ifName = const_cast<char*>(ifName.c_str());
422 rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, nullptr, size);
423 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
424 rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, code, size);
425 ASSERT_EQ(rc, HDF_FAILURE);
426 }
427
428 /**
429 * @tc.name: SetMacAddressTest_018
430 * @tc.desc: Wifi hdi set mac addr function test on STA feature
431 * @tc.type: FUNC
432 */
433 HWTEST_F(HdfWifiDirectTest, SetMacAddressTest_018, Function | MediumTest | Level2)
434 {
435 uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
436 struct HdfFeatureInfo ifeature;
437 uint32_t macLen = ETH_ADDR_LEN;
438 string ifName = "wlan0";
439
440 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
441 int32_t rc = g_wlanObj->SetMacAddress(g_wlanObj, nullptr, mac, macLen);
442 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
443 ifeature.ifName = nullptr;
444 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, mac, macLen);
445 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
446 ifeature.ifName = const_cast<char*>(ifName.c_str());
447 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, nullptr, macLen);
448 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
449 rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, mac, macLen);
450 ASSERT_EQ(rc, HDF_FAILURE);
451 }
452
453 /**
454 * @tc.name: SetScanningMacAddressTest_019
455 * @tc.desc: Wifi hdi set scanning mac addr function test
456 * @tc.type: FUNC
457 */
458 HWTEST_F(HdfWifiDirectTest, SetScanningMacAddressTest_019, Function | MediumTest | Level2)
459 {
460 struct HdfFeatureInfo ifeature;
461 uint8_t scanMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
462 uint32_t macLen = ETH_ADDR_LEN;
463 string ifName = "wlan0";
464
465 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
466 int32_t rc = g_wlanObj->SetScanningMacAddress(g_wlanObj, nullptr, scanMac, macLen);
467 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
468 ifeature.ifName = nullptr;
469 rc = g_wlanObj->SetScanningMacAddress(g_wlanObj, &ifeature, scanMac, macLen);
470 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
471 ifeature.ifName = const_cast<char*>(ifName.c_str());
472 rc = g_wlanObj->SetScanningMacAddress(g_wlanObj, &ifeature, nullptr, macLen);
473 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
474 rc = g_wlanObj->SetScanningMacAddress(g_wlanObj, &ifeature, scanMac, macLen);
475 ASSERT_EQ(rc, HDF_FAILURE);
476 }
477
478 /**
479 * @tc.name: SetTxPowerTest_020
480 * @tc.desc: Wifi hdi set tx power function test on STA feature
481 * @tc.type: FUNC
482 */
483 HWTEST_F(HdfWifiDirectTest, SetTxPowerTest_020, Function | MediumTest | Level2)
484 {
485 struct HdfFeatureInfo ifeature;
486 int32_t power = WLAN_TX_POWER;
487 string ifName = "wlan0";
488
489 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
490 int32_t rc = g_wlanObj->SetTxPower(g_wlanObj, nullptr, power);
491 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
492 ifeature.ifName = nullptr;
493 rc = g_wlanObj->SetTxPower(g_wlanObj, &ifeature, power);
494 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
495 ifeature.ifName = const_cast<char*>(ifName.c_str());
496 rc = g_wlanObj->SetTxPower(g_wlanObj, &ifeature, power);
497 ASSERT_EQ(rc, HDF_FAILURE);
498 }
499
500 /**
501 * @tc.name: GetNetdevInfoTest_021
502 * @tc.desc: Wifi hdi get netdev info function test
503 * @tc.type: FUNC
504 */
505 HWTEST_F(HdfWifiDirectTest, GetNetdevInfoTest_021, Function | MediumTest | Level2)
506 {
507 int32_t rc;
508 struct HdfNetDeviceInfoResult netDeviceInfoResult;
509
510 (void)memset_s(
511 &netDeviceInfoResult, sizeof(struct HdfNetDeviceInfoResult), 0, sizeof(struct HdfNetDeviceInfoResult));
512 rc = g_wlanObj->GetNetDevInfo(g_wlanObj, (struct HdfNetDeviceInfoResult *)&netDeviceInfoResult);
513 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
514 rc = g_wlanObj->GetNetDevInfo(g_wlanObj, nullptr);
515 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
516 }
517
518 /**
519 * @tc.name: GetPowerModeTest_022
520 * @tc.desc: Wifi hdi get power mode function test
521 * @tc.type: FUNC
522 */
523 HWTEST_F(HdfWifiDirectTest, GetPowerModeTest_022, Function | MediumTest | Level2)
524 {
525 struct HdfFeatureInfo ifeature;
526 uint8_t mode = 0;
527 string ifName = "wlan0";
528
529 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
530 int32_t rc = g_wlanObj->GetPowerMode(g_wlanObj, nullptr, &mode);
531 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
532 ifeature.ifName = nullptr;
533 rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, &mode);
534 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
535 ifeature.ifName = const_cast<char*>(ifName.c_str());
536 rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, nullptr);
537 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
538 rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, &mode);
539 ASSERT_EQ(rc, HDF_FAILURE);
540 }
541
542 /**
543 * @tc.name: SetPowerModeTest_023
544 * @tc.desc: Wifi hdi set power mode function test
545 * @tc.type: FUNC
546 */
547 HWTEST_F(HdfWifiDirectTest, SetPowerModeTest_023, Function | MediumTest | Level2)
548 {
549 struct HdfFeatureInfo ifeature;
550 uint8_t mode = WIFI_POWER_MODE_SLEEPING;
551 string ifName = "wlan0";
552
553 (void)memset_s(&ifeature, sizeof(struct HdfFeatureInfo), 0, sizeof(struct HdfFeatureInfo));
554 int32_t rc = g_wlanObj->SetPowerMode(g_wlanObj, nullptr, mode);
555 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
556 ifeature.ifName = nullptr;
557 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
558 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
559 ifeature.ifName = const_cast<char*>(ifName.c_str());
560 rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
561 ASSERT_EQ(rc, HDF_FAILURE);
562 }
563
564 /**
565 * @tc.name: SetProjectionScreenParam_024
566 * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
567 * @tc.type: FUNC
568 */
569 HWTEST_F(HdfWifiDirectTest, SetProjectionScreenParam_024, Function | MediumTest | Level2)
570 {
571 const char *ifName = "wlan0";
572 int32_t rc;
573 struct ProjectionScreenCmdParam param;
574
575 (void)memset_s(¶m, sizeof(struct ProjectionScreenCmdParam), 0, sizeof(struct ProjectionScreenCmdParam));
576 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, nullptr, ¶m);
577 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
578 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, nullptr);
579 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
580 rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m);
581 ASSERT_EQ(rc, HDF_FAILURE);
582 }
583
584 /**
585 * @tc.name: GetStaInfo_025
586 * @tc.desc: Wifi hdi get station information function test
587 * @tc.type: FUNC
588 */
589 HWTEST_F(HdfWifiDirectTest, GetStaInfo_025, Function | MediumTest | Level2)
590 {
591 const char *ifName = "wlan0";
592 int32_t rc;
593 struct WifiStationInfo info;
594 uint8_t mac[ETH_ADDR_LEN] = {0};
595
596 (void)memset_s(&info, sizeof(struct WifiStationInfo), 0, sizeof(struct WifiStationInfo));
597 rc = g_wlanObj->GetStaInfo(g_wlanObj, nullptr, &info, mac, ETH_ADDR_LEN);
598 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
599 rc = g_wlanObj->GetStaInfo(g_wlanObj, ifName, nullptr, mac, ETH_ADDR_LEN);
600 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
601 rc = g_wlanObj->GetStaInfo(g_wlanObj, ifName, &info, nullptr, ETH_ADDR_LEN);
602 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
603 rc = g_wlanObj->GetStaInfo(g_wlanObj, ifName, &info, mac, ETH_ADDR_LEN);
604 ASSERT_EQ(rc, HDF_FAILURE);
605 }
606 };
607