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