• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 
16 #include "hctest.h"
17 #include "ohos_types.h"
18 #include "wifi_device.h"
19 #include "wifi_hotspot.h"
20 #include "cmsis_os2.h"
21 #include <unistd.h>
22 
23 #define DEF_TIMEOUT 15
24 #define ONE_SECOND 1
25 #define LEVEL_ERROR (-1)
26 #define LEVEL_ONE 1
27 #define LEVEL_TWO 2
28 #define LEVEL_THREE 3
29 #define LEVEL_FOUR 4
30 #define DEF_TASK_STACK 2000
31 #define DEF_TASK_PRIORITY 20
32 #define TEST_SSID_COUNT 9
33 
34 static int g_apEnableSuccess = 0;
35 static int g_staScanSuccess = 0;
36 WifiEvent g_wifiEventHandler = {0};
37 
38 /**
39  * callback task for wifi scan
40  */
WifiScanStateTask(void)41 static void WifiScanStateTask(void)
42 {
43     WifiScanInfo* info = malloc(sizeof(WifiScanInfo) * WIFI_SCAN_HOTSPOT_LIMIT);
44     if (info == NULL) {
45         printf("WifiScanStateTask:malloc fail.\n");
46         return;
47     }
48     unsigned int checkSize = WIFI_SCAN_HOTSPOT_LIMIT;
49     WifiErrorCode error = GetScanInfoList(info, &checkSize);
50     if (error != WIFI_SUCCESS) {
51         printf("WifiScanStateTask:get info fail, error is %d.\n", error);
52     } else {
53         printf("WifiScanStateTask:get scan size is %u.\n", checkSize);
54         g_staScanSuccess = 1;
55     }
56     free(info);
57     info = NULL;
58 }
59 
60 /**
61  * callback task for connection
62  */
WifiConnectionStateTask(void)63 static void WifiConnectionStateTask(void)
64 {
65     WifiLinkedInfo linkInfo = {0};
66     WifiErrorCode error = GetLinkedInfo(&linkInfo);
67     if (error != WIFI_SUCCESS) {
68         printf("WifiConnectionChanged:get link info fail, error is %d.\n", error);
69         return;
70     }
71     if (linkInfo.connState != WIFI_CONNECTED) {
72         printf("WifiConnectionChanged:connect fail!\n");
73         return;
74     }
75     printf("WifiConnectionChanged:connect success.\n");
76 }
77 
78 /**
79  * callback function for hotspot
80  */
HotspotStateTask(void)81 static void HotspotStateTask(void)
82 {
83     StationInfo info[WIFI_MAX_STA_NUM] = {0};
84     unsigned int size = WIFI_MAX_STA_NUM;
85     WifiErrorCode error = GetStationList(info, &size);
86     if (error != WIFI_SUCCESS) {
87         printf("HotspotStaJoin:get list fail, error is %d.\n", error);
88         return;
89     }
90     printf("HotspotStaJoin:list size is %u.\n", size);
91     g_apEnableSuccess++;
92 }
93 
94 /**
95  * callback function for wifi scan
96  */
OnWifiScanStateChangedHandler(int state,int size)97 static void OnWifiScanStateChangedHandler(int state, int size)
98 {
99     if (state != WIFI_STATE_AVAILABLE) {
100         printf("ScanStateChanged:state is unavailable.\n");
101     } else {
102         printf("ScanStateChanged:state[%d], size[%d].\n", state, size);
103         osThreadAttr_t attr;
104         attr.name = "WifiScanStateTask";
105         attr.attr_bits = 0U;
106         attr.cb_mem = NULL;
107         attr.cb_size = 0U;
108         attr.stack_mem = NULL;
109         attr.stack_size = DEF_TASK_STACK;
110         attr.priority = DEF_TASK_PRIORITY;
111         if (osThreadNew((osThreadFunc_t)WifiScanStateTask, NULL, &attr) == NULL) {
112             printf("ScanStateChanged:create task fail!\n");
113         }
114     }
115 }
116 
117 /**
118  * callback function for wifi connection
119  */
OnWifiConnectionChangedHandler(int state,WifiLinkedInfo * info)120 static void OnWifiConnectionChangedHandler(int state, WifiLinkedInfo* info)
121 {
122     if (info == NULL) {
123         printf("WifiConnectionChanged:info is null, stat is %d.\n", state);
124     } else {
125         osThreadAttr_t attr;
126         attr.name = "WifiConnectionStateTask";
127         attr.attr_bits = 0U;
128         attr.cb_mem = NULL;
129         attr.cb_size = 0U;
130         attr.stack_mem = NULL;
131         attr.stack_size = DEF_TASK_STACK;
132         attr.priority = DEF_TASK_PRIORITY;
133         if (osThreadNew((osThreadFunc_t)WifiConnectionStateTask, NULL, &attr) == NULL) {
134             printf("WifiConnectionStateTask:create task fail!\n");
135         }
136     }
137 }
138 
139 /**
140  * callback function for STA join AP
141  */
OnHotspotStaJoinHandler(StationInfo * info)142 static void OnHotspotStaJoinHandler(StationInfo* info)
143 {
144     if (info == NULL) {
145         printf("HotspotStaJoin:info is null.\n");
146     }  else {
147         osThreadAttr_t attr;
148         attr.name = "HotspotStateTask";
149         attr.attr_bits = 0U;
150         attr.cb_mem = NULL;
151         attr.cb_size = 0U;
152         attr.stack_mem = NULL;
153         attr.stack_size = DEF_TASK_STACK;
154         attr.priority = DEF_TASK_PRIORITY;
155         if (osThreadNew((osThreadFunc_t)HotspotStateTask, NULL, &attr) == NULL) {
156             printf("HotspotStaJoin:create task fail!\n");
157         }
158     }
159 }
160 
161 /**
162  * callback function for STA leave AP
163  */
OnHotspotStaLeaveHandler(StationInfo * info)164 static void OnHotspotStaLeaveHandler(StationInfo* info)
165 {
166     if (info == NULL) {
167         printf("HotspotStaLeave:info is null.\n");
168     } else {
169         g_apEnableSuccess--;
170     }
171 }
172 
173 /**
174  * callback function for AP
175  */
OnHotspotStateChangedHandler(int state)176 static void OnHotspotStateChangedHandler(int state)
177 {
178     printf("HotspotStateChanged:state is %d.\n", state);
179 }
180 
181 /**
182  * common wait scan result
183  */
WaitScanResult(void)184 static void WaitScanResult(void)
185 {
186     int scanTimeout = DEF_TIMEOUT;
187     while (scanTimeout > 0) {
188         sleep(ONE_SECOND);
189         scanTimeout--;
190         if (g_staScanSuccess == 1) {
191             printf("WaitScanResult:wait success[%d]s\n", (DEF_TIMEOUT - scanTimeout));
192             break;
193         }
194     }
195     if (scanTimeout <= 0) {
196         printf("WaitScanResult:timeout!\n");
197     }
198 }
199 
200 /**
201  * @tc.desc      : register a test suite, this test suite is used to test basic functions
202  * @param        : subsystem name is communication
203  * @param        : module name is wifiaware
204  * @param        : test suit name is WifiAwareReliTestSuite
205  */
206 LITE_TEST_SUIT(communication, wifiservice, WifiServiceFuncTestSuite);
207 
208 /**
209  * @tc.setup     : setup for all testcases
210  * @return       : setup result, TRUE is success, FALSE is fail
211  */
WifiServiceFuncTestSuiteSetUp(void)212 static BOOL WifiServiceFuncTestSuiteSetUp(void)
213 {
214     WifiErrorCode error;
215     // check wifi stat
216     int ret = IsWifiActive();
217     if (ret == WIFI_STATE_AVAILABLE) {
218         printf("[Setup]wifi is active, disable now...\n");
219         error = DisableWifi();
220         if (error == WIFI_SUCCESS) {
221             printf("[Setup]disable wifi success\n");
222         } else {
223             TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
224             printf("[Setup]disable wifi fail, please disable wifi, then run test cases!\n");
225             return FALSE;
226         }
227     }
228 
229     // check AP stat
230     ret = IsHotspotActive();
231     if (ret == WIFI_HOTSPOT_ACTIVE) {
232         printf("[Setup]AP is active, disable now...\n");
233         error = DisableHotspot();
234         if (error == WIFI_SUCCESS) {
235             printf("[Setup]disable AP success\n");
236         } else {
237             TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
238             printf("[Setup]disable AP fail, please disable ap, then run test cases!\n");
239             return FALSE;
240         }
241     }
242 
243     // check device config
244     WifiDeviceConfig config[WIFI_MAX_CONFIG_SIZE] = {0};
245     unsigned int size = WIFI_MAX_CONFIG_SIZE;
246     error = GetDeviceConfigs(config, &size);
247     if (error != ERROR_WIFI_NOT_AVAILABLE) {
248         printf("[Setup]there is device config, clear now...\n");
249         int count = 0;
250         for (int i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
251             if (&config[i] != NULL) {
252                 RemoveDevice(config[i].netId);
253                 count++;
254             }
255         }
256         printf("[Setup]clear count [%d]\n", count);
257     }
258 
259     // register wifi event
260     g_wifiEventHandler.OnWifiScanStateChanged = OnWifiScanStateChangedHandler;
261     g_wifiEventHandler.OnWifiConnectionChanged = OnWifiConnectionChangedHandler;
262     g_wifiEventHandler.OnHotspotStaJoin = OnHotspotStaJoinHandler;
263     g_wifiEventHandler.OnHotspotStaLeave = OnHotspotStaLeaveHandler;
264     g_wifiEventHandler.OnHotspotStateChanged = OnHotspotStateChangedHandler;
265     error = RegisterWifiEvent(&g_wifiEventHandler);
266     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
267     if (error != WIFI_SUCCESS) {
268         printf("[Setup]register wifi event fail!\n");
269         return FALSE;
270     }
271     return TRUE;
272 }
273 
274 /**
275  * @tc.teardown  : teardown for all testcases
276  * @return       : teardown result, TRUE is success, FALSE is fail
277  */
WifiServiceFuncTestSuiteTearDown(void)278 static BOOL WifiServiceFuncTestSuiteTearDown(void)
279 {
280     WifiErrorCode error = UnRegisterWifiEvent(&g_wifiEventHandler);
281     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
282     printf("+-------------------------------------------+\n");
283     if (error != WIFI_SUCCESS) {
284         return FALSE;
285     }
286     return TRUE;
287 }
288 
289 /**
290  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0100
291  * @tc.name      : Test enable and disable wifi interface
292  * @tc.desc      : [C- SOFTWARE -0200]
293  */
294 LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableWifi, Function | MediumTest | Level2)
295 {
296     int stat = IsWifiActive();
297     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
298 
299     WifiErrorCode error = EnableWifi();
300     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
301     stat = IsWifiActive();
302     TEST_ASSERT_EQUAL_INT(WIFI_STATE_AVAILABLE, stat);
303 
304     error = EnableWifi();
305     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_BUSY, error);
306     stat = IsWifiActive();
307     TEST_ASSERT_EQUAL_INT(WIFI_STATE_AVAILABLE, stat);
308 
309     error = DisableWifi();
310     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
311     stat = IsWifiActive();
312     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
313 
314     error = DisableWifi();
315     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_NOT_STARTED, error);
316     stat = IsWifiActive();
317     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
318 }
319 
320 /**
321  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0200
322  * @tc.name      : Test scan and get scan info interface
323  * @tc.desc      : [C- SOFTWARE -0200]
324  */
325 LITE_TEST_CASE(WifiServiceFuncTestSuite, testScan, Function | MediumTest | Level2)
326 {
327     unsigned int size = WIFI_SCAN_HOTSPOT_LIMIT;
328     WifiErrorCode error = EnableWifi();
329     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
330     int stat = IsWifiActive();
331     TEST_ASSERT_EQUAL_INT(WIFI_STATE_AVAILABLE, stat);
332 
333     WifiScanInfo* info = malloc(sizeof(WifiScanInfo) * WIFI_SCAN_HOTSPOT_LIMIT);
334     TEST_ASSERT_NOT_NULL(info);
335     error = GetScanInfoList(info, &size);
336     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
337     TEST_ASSERT_EQUAL_INT(0, size);
338 
339     g_staScanSuccess = 0;
340     error = Scan();
341     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
342     WaitScanResult();
343     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
344 
345     size = WIFI_SCAN_HOTSPOT_LIMIT;
346     error = GetScanInfoList(info, &size);
347     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
348     TEST_ASSERT_NOT_EQUAL(WIFI_SCAN_HOTSPOT_LIMIT, size);
349     free(info);
350 
351     error = DisableWifi();
352     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
353     stat = IsWifiActive();
354     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
355 }
356 
357 /**
358  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0300
359  * @tc.name      : Test connect and disconnect interface
360  * @tc.desc      : [C- SOFTWARE -0200]
361  */
362 LITE_TEST_CASE(WifiServiceFuncTestSuite, testConnectDisConnect, Function | MediumTest | Level2)
363 {
364     int netId = 0;
365     WifiDeviceConfig config = {0};
366     const char* ssid = "xts_execute";
367     int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid, strlen(ssid));
368     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
369 
370     config.securityType = WIFI_SEC_TYPE_OPEN;
371     WifiErrorCode error = AddDeviceConfig(&config, &netId);
372     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
373 
374     error = ConnectTo(netId);
375     TEST_ASSERT_NOT_EQUAL(WIFI_SUCCESS, error);
376     unsigned char mac[WIFI_MAC_LEN];
377     error = GetDeviceMacAddress((unsigned char *)mac);
378     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
379     error = Disconnect();
380     TEST_ASSERT_NOT_EQUAL(WIFI_SUCCESS, error);
381     error = RemoveDevice(netId);
382     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
383 }
384 
385 /**
386  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0400
387  * @tc.name      : Test handle device config interface
388  * @tc.desc      : [C- SOFTWARE -0200]
389  */
390 LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleDeviceConfig, Function | MediumTest | Level2)
391 {
392     int netId = 0;
393     const char* ssid0 = "TestWifi01";
394     const char* ssid[TEST_SSID_COUNT] = {"TestWifi02", "TestWifi03", "TestWifi04", "TestWifi05", "TestWifi06",
395     		"TestWifi07", "TestWifi08", "TestWifi09", "TestWifi10"};
396     const char* ssid10 = "TestWifi11";
397     const char* info = "12345678";
398     unsigned char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1};
399     WifiDeviceConfig config = {0};
400     config.freq = 20;
401     config.securityType = WIFI_SEC_TYPE_SAE;
402     config.wapiPskType = WIFI_PSK_TYPE_ASCII;
403     int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid0, strlen(ssid0));
404     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
405     ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
406     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
407     ret = memcpy_s(config.bssid, WIFI_MAC_LEN, bssid, WIFI_MAC_LEN);
408     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
409     WifiErrorCode error = AddDeviceConfig(&config, &netId);
410     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
411 
412     for (int i = 0; i < WIFI_MAX_CONFIG_SIZE - 1; i++) {
413         config.securityType = WIFI_SEC_TYPE_PSK;
414         config.wapiPskType = WIFI_PSK_TYPE_HEX;
415         ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid[i], sizeof(ssid[i]));
416         TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
417         ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
418         TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
419         error = AddDeviceConfig(&config, &netId);
420         TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
421         if (error != WIFI_SUCCESS) {
422             printf("Add fail[%d].\n", i);
423             break;
424         }
425     }
426 
427     ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid10, strlen(ssid10));
428     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
429     ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
430     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
431     config.securityType = WIFI_SEC_TYPE_PSK;
432     error = AddDeviceConfig(&config, &netId);
433     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_BUSY, error);
434 
435     WifiDeviceConfig allConfig[WIFI_MAX_CONFIG_SIZE] = {0};
436     unsigned int size = WIFI_MAX_CONFIG_SIZE;
437     error = GetDeviceConfigs(allConfig, &size);
438     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
439     TEST_ASSERT_EQUAL_INT(WIFI_MAX_CONFIG_SIZE, size);
440 
441     for (int i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
442         error = RemoveDevice(allConfig[i].netId);
443         TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
444     }
445 
446     error = GetDeviceConfigs(allConfig, &size);
447     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_NOT_AVAILABLE, error);
448 }
449 
450 /**
451  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0500
452  * @tc.name      : Test handle AP config interface
453  * @tc.desc      : [C- SOFTWARE -0200]
454  */
455 LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleHotspotConfig, Function | MediumTest | Level2)
456 {
457     const char* ssid = "XtsTestAp";
458     const char* info = "12345678";
459     HotspotConfig config = {0};
460     int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid, strlen(ssid));
461     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
462     ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
463     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
464     config.securityType = WIFI_SEC_TYPE_PSK;
465     WifiErrorCode error = SetHotspotConfig(&config);
466     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
467 
468     HotspotConfig getConfig = {0};
469     error = GetHotspotConfig(&getConfig);
470     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
471     TEST_ASSERT_EQUAL_INT(config.securityType, WIFI_SEC_TYPE_PSK);
472 
473     int band = 11;
474     int bandOrig = 11;
475     error = SetBand(band);
476     TEST_ASSERT_NOT_EQUAL(WIFI_SUCCESS, error);
477     error = GetBand(&band);
478     TEST_ASSERT_NOT_EQUAL(WIFI_SUCCESS, error);
479     TEST_ASSERT_EQUAL_INT(bandOrig, band);
480 
481     error = SetBand(HOTSPOT_BAND_TYPE_2G);
482     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
483     error = GetBand(&band);
484     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
485     TEST_ASSERT_EQUAL_INT(HOTSPOT_BAND_TYPE_2G, band);
486 
487     HotspotConfig getConfigAgain = {0};
488     error = GetHotspotConfig(&getConfigAgain);
489     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
490     TEST_ASSERT_EQUAL_INT(HOTSPOT_BAND_TYPE_2G, getConfigAgain.band);
491 }
492 
493 /**
494  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0600
495  * @tc.name      : Test enable and disable AP interface
496  * @tc.desc      : [C- SOFTWARE -0200]
497  */
498 LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableHotSpot, Function | MediumTest | Level2)
499 {
500     const char* ssid = "XtsTestAp";
501     const char* info = "12345678";
502     HotspotConfig config = {0};
503     int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid, strlen(ssid));
504     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
505     ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
506     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
507     config.securityType = WIFI_SEC_TYPE_PSK;
508     WifiErrorCode error = SetHotspotConfig(&config);
509     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
510 
511     int stat = IsHotspotActive();
512     TEST_ASSERT_EQUAL_INT(WIFI_HOTSPOT_NOT_ACTIVE, stat);
513     error = EnableHotspot();
514     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
515     stat = IsHotspotActive();
516     TEST_ASSERT_EQUAL_INT(WIFI_HOTSPOT_ACTIVE, stat);
517     error = EnableHotspot();
518     TEST_ASSERT_NOT_EQUAL(WIFI_SUCCESS, error);
519     stat = IsHotspotActive();
520     TEST_ASSERT_EQUAL_INT(WIFI_HOTSPOT_ACTIVE, stat);
521 
522     int timeout = 3;
523     g_apEnableSuccess = 0;
524     while (timeout > 0) {
525         sleep(ONE_SECOND);
526         timeout--;
527         if (g_apEnableSuccess >= 1) {
528             printf("Wait %d seconds.\n", (DEF_TIMEOUT - timeout));
529             break;
530         }
531     }
532 
533     error = DisableHotspot();
534     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
535     stat = IsHotspotActive();
536     TEST_ASSERT_EQUAL_INT(WIFI_HOTSPOT_NOT_ACTIVE, stat);
537     error = DisableHotspot();
538     TEST_ASSERT_NOT_EQUAL(WIFI_SUCCESS, error);
539     stat = IsHotspotActive();
540     TEST_ASSERT_EQUAL_INT(WIFI_HOTSPOT_NOT_ACTIVE, stat);
541 }
542 
543 /**
544  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0700
545  * @tc.name      : Test get signal Level interface
546  * @tc.desc      : [C- SOFTWARE -0200]
547  */
548 LITE_TEST_CASE(WifiServiceFuncTestSuite, testGetSignalLevel, Function | MediumTest | Level2)
549 {
550     int level;
551     int rssiNoLevel = -90;
552     int rssiOf2gLevel1 = -88;
553     int rssiOf2gLevel2 = -82;
554     int rssiOf2gLevel3 = -75;
555     int rssiOf5gLevel1 = -85;
556     int rssiOf5gLevel2 = -79;
557     int rssiOf5gLevel3 = -72;
558     int rssiBothLevel4 = -65;
559 
560     level = GetSignalLevel(rssiNoLevel, HOTSPOT_BAND_TYPE_2G);
561     TEST_ASSERT_EQUAL_INT(LEVEL_ERROR, level);
562     level = GetSignalLevel(rssiOf2gLevel1, HOTSPOT_BAND_TYPE_2G);
563     TEST_ASSERT_EQUAL_INT(LEVEL_ONE, level);
564     level = GetSignalLevel(rssiOf2gLevel2, HOTSPOT_BAND_TYPE_2G);
565     TEST_ASSERT_EQUAL_INT(LEVEL_TWO, level);
566     level = GetSignalLevel(rssiOf2gLevel3, HOTSPOT_BAND_TYPE_2G);
567     TEST_ASSERT_EQUAL_INT(LEVEL_THREE, level);
568     level = GetSignalLevel(rssiBothLevel4, HOTSPOT_BAND_TYPE_2G);
569     TEST_ASSERT_EQUAL_INT(LEVEL_FOUR, level);
570 
571     level = GetSignalLevel(rssiNoLevel, HOTSPOT_BAND_TYPE_5G);
572     TEST_ASSERT_EQUAL_INT(-1, level);
573     level = GetSignalLevel(rssiOf5gLevel1, HOTSPOT_BAND_TYPE_5G);
574     TEST_ASSERT_EQUAL_INT(LEVEL_ONE, level);
575     level = GetSignalLevel(rssiOf5gLevel2, HOTSPOT_BAND_TYPE_5G);
576     TEST_ASSERT_EQUAL_INT(LEVEL_TWO, level);
577     level = GetSignalLevel(rssiOf5gLevel3, HOTSPOT_BAND_TYPE_5G);
578     TEST_ASSERT_EQUAL_INT(LEVEL_THREE, level);
579     level = GetSignalLevel(rssiBothLevel4, HOTSPOT_BAND_TYPE_5G);
580     TEST_ASSERT_EQUAL_INT(LEVEL_FOUR, level);
581 }
582 
583 /**
584  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0800
585  * @tc.name      : test adavance scan interface
586  * @tc.desc      : [C- SOFTWARE -0200]
587  */
588 LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanType, Function | MediumTest | Level2)
589 {
590     WifiErrorCode error = EnableWifi();
591     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
592     int stat = IsWifiActive();
593     TEST_ASSERT_EQUAL_INT(WIFI_STATE_AVAILABLE, stat);
594 
595     int freq = 2460;
596     WifiScanParams scanParams = {0};
597     char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1};
598     (void) strcpy_s(scanParams.ssid, sizeof(scanParams.ssid), "wifi_service_xts");
599     scanParams.ssidLen = strlen(scanParams.ssid);
600     scanParams.freqs = freq;
601     (void) memcpy_s(scanParams.bssid, sizeof(scanParams.bssid), bssid, sizeof(bssid));
602 
603     scanParams.scanType = WIFI_SSID_SCAN;
604     g_staScanSuccess = 0;
605     error = AdvanceScan(&scanParams);
606     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
607     WaitScanResult();
608     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
609 
610     scanParams.scanType = WIFI_FREQ_SCAN;
611     g_staScanSuccess = 0;
612     error = AdvanceScan(&scanParams);
613     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
614     WaitScanResult();
615     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
616 
617     scanParams.scanType = WIFI_BSSID_SCAN;
618     g_staScanSuccess = 0;
619     error = AdvanceScan(&scanParams);
620     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
621     WaitScanResult();
622     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
623 
624     scanParams.scanType = WIFI_BAND_SCAN;
625     g_staScanSuccess = 0;
626     error = AdvanceScan(&scanParams);
627     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
628     WaitScanResult();
629     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
630 
631     error = DisableWifi();
632     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
633     stat = IsWifiActive();
634     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
635 }
636 
637 /**
638  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_0900
639  * @tc.name      : test adavance scan interface with invalid parameter
640  * @tc.desc      : [C- SOFTWARE -0200]
641  */
642 LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam01, Function | MediumTest | Level2)
643 {
644     WifiErrorCode error = EnableWifi();
645     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
646     int stat = IsWifiActive();
647     TEST_ASSERT_EQUAL_INT(WIFI_STATE_AVAILABLE, stat);
648 
649     g_staScanSuccess = 0;
650     error = AdvanceScan(NULL);
651     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_UNKNOWN, error);
652     TEST_ASSERT_EQUAL_INT(0, g_staScanSuccess);
653 
654     WifiScanParams scanParams = {0};
655     error = AdvanceScan(&scanParams);
656     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_UNKNOWN, error);
657     TEST_ASSERT_EQUAL_INT(0, g_staScanSuccess);
658 
659     error = DisableWifi();
660     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
661     stat = IsWifiActive();
662     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
663 }
664 
665 /**
666  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_1000
667  * @tc.name      : test adavance scan interface with different invalid scantype
668  * @tc.desc      : [C- SOFTWARE -0200]
669  */
670 LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam02, Function | MediumTest | Level2)
671 {
672     WifiErrorCode error = EnableWifi();
673     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
674     int stat = IsWifiActive();
675     TEST_ASSERT_EQUAL_INT(WIFI_STATE_AVAILABLE, stat);
676 
677     WifiScanParams* scanParams = malloc(sizeof(WifiScanParams));
678     TEST_ASSERT_NOT_NULL(scanParams);
679     (void) memset_s(scanParams, sizeof(WifiScanParams), 0, sizeof(WifiScanParams));
680 
681     error = AdvanceScan(scanParams);
682     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_UNKNOWN, error);
683 
684     scanParams->scanType = WIFI_BSSID_SCAN;
685     error = AdvanceScan(scanParams);
686     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_UNKNOWN, error);
687 
688     scanParams->scanType = WIFI_SSID_SCAN;
689     error = AdvanceScan(scanParams);
690     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_UNKNOWN, error);
691 
692     (void) memset_s(scanParams, sizeof(WifiScanParams), 0, sizeof(WifiScanParams));
693     (void) strcpy_s(scanParams->ssid, sizeof(scanParams->ssid), "wifi_service_xts");
694     scanParams->scanType = WIFI_SSID_SCAN;
695     error = AdvanceScan(scanParams);
696     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_UNKNOWN, error);
697 
698     scanParams->scanType = WIFI_FREQ_SCAN;
699     error = AdvanceScan(scanParams);
700     TEST_ASSERT_EQUAL_INT(ERROR_WIFI_UNKNOWN, error);
701 
702     error = DisableWifi();
703     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
704     stat = IsWifiActive();
705     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
706 
707     free(scanParams);
708 }
709 
710 /**
711  * @tc.number    : SUB_COMMUNICATION_WIFISERVICE_SDK_1100
712  * @tc.name      : test adavance scan interface with different invalid scantype
713  * @tc.desc      : [C- SOFTWARE -0200]
714  */
715 LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam03, Function | MediumTest | Level2)
716 {
717     WifiErrorCode error = EnableWifi();
718     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
719     int stat = IsWifiActive();
720     TEST_ASSERT_EQUAL_INT(WIFI_STATE_AVAILABLE, stat);
721 
722     WifiScanParams* scanParams = malloc(sizeof(WifiScanParams));
723     TEST_ASSERT_NOT_NULL(scanParams);
724     (void) memset_s(scanParams, sizeof(WifiScanParams), 0, sizeof(WifiScanParams));
725 
726     scanParams->scanType = WIFI_BAND_SCAN;
727     g_staScanSuccess = 0;
728     error = AdvanceScan(scanParams);
729     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
730     WaitScanResult();
731     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
732 
733     int errorType = -1; //Unnormal Type Val -> Default Type Val
734     scanParams->scanType = errorType;
735     g_staScanSuccess = 0;
736     error = AdvanceScan(scanParams);
737     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
738     WaitScanResult();
739     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
740 
741     char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1};
742     (void) memcpy_s(scanParams->bssid, sizeof(scanParams->bssid), bssid, sizeof(bssid));
743     scanParams->scanType = WIFI_BSSID_SCAN;
744     g_staScanSuccess = 0;
745     error = AdvanceScan(scanParams);
746     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
747     WaitScanResult();
748     TEST_ASSERT_EQUAL_INT(1, g_staScanSuccess);
749 
750     error = DisableWifi();
751     TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, error);
752     stat = IsWifiActive();
753     TEST_ASSERT_EQUAL_INT(WIFI_STATE_NOT_AVALIABLE, stat);
754 
755     free(scanParams);
756 }
757 
758 RUN_TEST_SUITE(WifiServiceFuncTestSuite);
759