mbed-os
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
TESTS/network/wifi/wifi_scan.cpp@0:b74591d5ab33, 2017-12-11 (annotated)
- Committer:
- be_bryan
- Date:
- Mon Dec 11 17:54:04 2017 +0000
- Revision:
- 0:b74591d5ab33
motor ++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
be_bryan | 0:b74591d5ab33 | 1 | /* |
be_bryan | 0:b74591d5ab33 | 2 | * Copyright (c) 2017, ARM Limited, All Rights Reserved |
be_bryan | 0:b74591d5ab33 | 3 | * SPDX-License-Identifier: Apache-2.0 |
be_bryan | 0:b74591d5ab33 | 4 | * |
be_bryan | 0:b74591d5ab33 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
be_bryan | 0:b74591d5ab33 | 6 | * not use this file except in compliance with the License. |
be_bryan | 0:b74591d5ab33 | 7 | * You may obtain a copy of the License at |
be_bryan | 0:b74591d5ab33 | 8 | * |
be_bryan | 0:b74591d5ab33 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
be_bryan | 0:b74591d5ab33 | 10 | * |
be_bryan | 0:b74591d5ab33 | 11 | * Unless required by applicable law or agreed to in writing, software |
be_bryan | 0:b74591d5ab33 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
be_bryan | 0:b74591d5ab33 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
be_bryan | 0:b74591d5ab33 | 14 | * See the License for the specific language governing permissions and |
be_bryan | 0:b74591d5ab33 | 15 | * limitations under the License. |
be_bryan | 0:b74591d5ab33 | 16 | */ |
be_bryan | 0:b74591d5ab33 | 17 | |
be_bryan | 0:b74591d5ab33 | 18 | #include "mbed.h" |
be_bryan | 0:b74591d5ab33 | 19 | #include "greentea-client/test_env.h" |
be_bryan | 0:b74591d5ab33 | 20 | #include "unity.h" |
be_bryan | 0:b74591d5ab33 | 21 | #include "utest.h" |
be_bryan | 0:b74591d5ab33 | 22 | #include "wifi_tests.h" |
be_bryan | 0:b74591d5ab33 | 23 | #include <stdbool.h> |
be_bryan | 0:b74591d5ab33 | 24 | |
be_bryan | 0:b74591d5ab33 | 25 | using namespace utest::v1; |
be_bryan | 0:b74591d5ab33 | 26 | |
be_bryan | 0:b74591d5ab33 | 27 | void wifi_scan(void) |
be_bryan | 0:b74591d5ab33 | 28 | { |
be_bryan | 0:b74591d5ab33 | 29 | WiFiInterface *wifi = get_interface(); |
be_bryan | 0:b74591d5ab33 | 30 | |
be_bryan | 0:b74591d5ab33 | 31 | WiFiAccessPoint ap[MBED_CONF_APP_MAX_SCAN_SIZE]; |
be_bryan | 0:b74591d5ab33 | 32 | |
be_bryan | 0:b74591d5ab33 | 33 | int size = wifi->scan(ap, MBED_CONF_APP_MAX_SCAN_SIZE); |
be_bryan | 0:b74591d5ab33 | 34 | TEST_ASSERT(size >= 2); |
be_bryan | 0:b74591d5ab33 | 35 | |
be_bryan | 0:b74591d5ab33 | 36 | bool secure_found = false; |
be_bryan | 0:b74591d5ab33 | 37 | bool unsecure_found = false; |
be_bryan | 0:b74591d5ab33 | 38 | |
be_bryan | 0:b74591d5ab33 | 39 | char secure_bssid[6]; |
be_bryan | 0:b74591d5ab33 | 40 | char unsecure_bssid[6]; |
be_bryan | 0:b74591d5ab33 | 41 | const char *coversion_string = "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"; |
be_bryan | 0:b74591d5ab33 | 42 | 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"); |
be_bryan | 0:b74591d5ab33 | 43 | 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"); |
be_bryan | 0:b74591d5ab33 | 44 | |
be_bryan | 0:b74591d5ab33 | 45 | for (int i=0; i<size; i++) { |
be_bryan | 0:b74591d5ab33 | 46 | const char *ssid = ap[i].get_ssid(); |
be_bryan | 0:b74591d5ab33 | 47 | const uint8_t *bssid = ap[i].get_bssid(); |
be_bryan | 0:b74591d5ab33 | 48 | nsapi_security_t security = ap[i].get_security(); |
be_bryan | 0:b74591d5ab33 | 49 | int8_t rssi = ap[i].get_rssi(); |
be_bryan | 0:b74591d5ab33 | 50 | uint8_t ch = ap[i].get_channel(); |
be_bryan | 0:b74591d5ab33 | 51 | TEST_ASSERT_NOT_EQUAL(0, strlen(ssid)); |
be_bryan | 0:b74591d5ab33 | 52 | TEST_ASSERT_INT8_WITHIN(-35, -65, rssi); |
be_bryan | 0:b74591d5ab33 | 53 | if (strcmp(MBED_CONF_APP_WIFI_SECURE_SSID, ssid) == 0) { |
be_bryan | 0:b74591d5ab33 | 54 | secure_found = true; |
be_bryan | 0:b74591d5ab33 | 55 | TEST_ASSERT_EQUAL_INT(NSAPI_SECURITY_WPA2, security); |
be_bryan | 0:b74591d5ab33 | 56 | TEST_ASSERT_EQUAL_INT(MBED_CONF_APP_WIFI_CH_SECURE, ch); |
be_bryan | 0:b74591d5ab33 | 57 | } |
be_bryan | 0:b74591d5ab33 | 58 | if (strcmp(MBED_CONF_APP_WIFI_UNSECURE_SSID, ssid) == 0) { |
be_bryan | 0:b74591d5ab33 | 59 | unsecure_found = true; |
be_bryan | 0:b74591d5ab33 | 60 | TEST_ASSERT_EQUAL_INT(NSAPI_SECURITY_NONE, security); |
be_bryan | 0:b74591d5ab33 | 61 | TEST_ASSERT_EQUAL_INT(MBED_CONF_APP_WIFI_CH_UNSECURE, ch); |
be_bryan | 0:b74591d5ab33 | 62 | } |
be_bryan | 0:b74591d5ab33 | 63 | } |
be_bryan | 0:b74591d5ab33 | 64 | TEST_ASSERT_TRUE(secure_found); |
be_bryan | 0:b74591d5ab33 | 65 | TEST_ASSERT_TRUE(unsecure_found); |
be_bryan | 0:b74591d5ab33 | 66 | } |
be_bryan | 0:b74591d5ab33 | 67 |