Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wifi_scan.cpp Source File

wifi_scan.cpp

00001 /*
00002  * Copyright (c) 2017, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "mbed.h"
00019 #include "greentea-client/test_env.h"
00020 #include "unity.h"
00021 #include "utest.h"
00022 #include "wifi_tests.h"
00023 #include <stdbool.h>
00024 
00025 using namespace utest::v1;
00026 
00027 #if defined(MBED_CONF_APP_WIFI_SECURE_SSID) && defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
00028 
00029 void wifi_scan(void)
00030 {
00031     WiFiInterface *wifi = get_interface();
00032 
00033     WiFiAccessPoint ap[MBED_CONF_APP_MAX_SCAN_SIZE];
00034 
00035     int size = wifi->scan(ap, MBED_CONF_APP_MAX_SCAN_SIZE);
00036     TEST_ASSERT(size >= 2);
00037 
00038     bool secure_found = false;
00039     bool unsecure_found = false;
00040 
00041     char secure_bssid[6];
00042     char unsecure_bssid[6];
00043     const char *coversion_string = "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx";
00044     TEST_ASSERT_EQUAL_INT_MESSAGE(6, sscanf(MBED_CONF_APP_AP_MAC_SECURE, coversion_string, &secure_bssid[0], &secure_bssid[1], &secure_bssid[2], &secure_bssid[3], &secure_bssid[4], &secure_bssid[5]), "Failed to convert ap-mac-secure from mbed_app.json");
00045     TEST_ASSERT_EQUAL_INT_MESSAGE(6, sscanf(MBED_CONF_APP_AP_MAC_UNSECURE, coversion_string, &unsecure_bssid[0], &unsecure_bssid[1], &unsecure_bssid[2], &unsecure_bssid[3], &unsecure_bssid[4], &unsecure_bssid[5]), "Failed to convert ap-mac-unsecure from mbed_app.json");
00046 
00047     for (int i=0; i<size; i++) {
00048         const char *ssid = ap[i].get_ssid();
00049         nsapi_security_t security = ap[i].get_security();
00050         int8_t rssi = ap[i].get_rssi();
00051         uint8_t ch = ap[i].get_channel();
00052         TEST_ASSERT_INT8_WITHIN(-10, -100, rssi);
00053         if (strcmp(MBED_CONF_APP_WIFI_SECURE_SSID, ssid) == 0) {
00054             secure_found = true;
00055             TEST_ASSERT_EQUAL_INT(get_security(), security);
00056             if (MBED_CONF_APP_WIFI_CH_SECURE) {
00057                 TEST_ASSERT_EQUAL_INT(MBED_CONF_APP_WIFI_CH_SECURE, ch);
00058             }
00059         }
00060         if (strcmp(MBED_CONF_APP_WIFI_UNSECURE_SSID, ssid) == 0) {
00061             unsecure_found = true;
00062             TEST_ASSERT_EQUAL_INT(NSAPI_SECURITY_NONE , security);
00063             if (MBED_CONF_APP_WIFI_CH_UNSECURE) {
00064                 TEST_ASSERT_EQUAL_INT(MBED_CONF_APP_WIFI_CH_UNSECURE, ch);
00065             }
00066         }
00067     }
00068     TEST_ASSERT_TRUE(secure_found);
00069     TEST_ASSERT_TRUE(unsecure_found);
00070 }
00071 
00072 #endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) && defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)