mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5743 from VeijoPesonen/greentea-wifi-fixes-disconnect
Greentea wifi test cases - disconnect done as teardown after each connectpull/5420/merge
commit
43af0d7395
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include "mbed.h"
|
||||
#include "nsapi_types.h"
|
||||
|
||||
nsapi_security get_security()
|
||||
{
|
||||
#if defined MBED_CONF_APP_WIFI_SECURE_PROTOCOL
|
||||
static const char *SEC_WEP = "WEP";
|
||||
static const char *SEC_WPA = "WPA";
|
||||
static const char *SEC_WPA2 = "WPA2";
|
||||
static const char *SEC_WPA_WPA2 = "WPA/WPA2";
|
||||
|
||||
if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WEP) == 0) {
|
||||
return NSAPI_SECURITY_WEP;
|
||||
}
|
||||
if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA) == 0) {
|
||||
return NSAPI_SECURITY_WPA;
|
||||
}
|
||||
if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA2) == 0) {
|
||||
return NSAPI_SECURITY_WPA2;
|
||||
}
|
||||
if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA_WPA2) == 0) {
|
||||
return NSAPI_SECURITY_WPA_WPA2;
|
||||
}
|
||||
#endif
|
||||
return NSAPI_SECURITY_NONE;
|
||||
}
|
|
@ -30,7 +30,8 @@
|
|||
!defined(MBED_CONF_APP_WIFI_PASSWORD) || \
|
||||
!defined(MBED_CONF_APP_WIFI_RX) || \
|
||||
!defined(MBED_CONF_APP_WIFI_SECURE_SSID) || \
|
||||
!defined(MBED_CONF_APP_WIFI_TX)
|
||||
!defined(MBED_CONF_APP_WIFI_TX) || \
|
||||
!defined MBED_CONF_APP_WIFI_SECURE_PROTOCOL
|
||||
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for secure connections)
|
||||
#endif
|
||||
#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID)
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
"help": "WiFi Password",
|
||||
"value": "\"PASSWORD\""
|
||||
},
|
||||
"wifi-secure-protocol": {
|
||||
"help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA/WPA2",
|
||||
"value": "\"WPA/WPA2\""
|
||||
},
|
||||
"wifi-ch-secure": {
|
||||
"help": "Channel number of secure SSID",
|
||||
"value": 1
|
||||
|
|
|
@ -28,6 +28,5 @@ void wifi_connect_nocredentials(void)
|
|||
WiFiInterface *wifi = get_interface();
|
||||
nsapi_error_t error;
|
||||
error = wifi->connect();
|
||||
wifi->disconnect();
|
||||
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
|
||||
TEST_ASSERT(error == NSAPI_ERROR_NO_SSID || error == NSAPI_ERROR_PARAMETER);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ void wifi_connect_params_channel(void)
|
|||
return;
|
||||
}
|
||||
|
||||
nsapi_error_t error = wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA2, MBED_CONF_APP_WIFI_CH_SECURE);
|
||||
nsapi_error_t error = wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security(), MBED_CONF_APP_WIFI_CH_SECURE);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void wifi_connect_params_channel_fail(void)
|
|||
return;
|
||||
}
|
||||
|
||||
nsapi_error_t error = wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA2, MBED_CONF_APP_WIFI_CH_SECURE);
|
||||
nsapi_error_t error = wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security(), MBED_CONF_APP_WIFI_CH_SECURE);
|
||||
TEST_ASSERT(error==NSAPI_ERROR_CONNECTION_TIMEOUT || error==NSAPI_ERROR_NO_CONNECTION);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,19 +29,7 @@ void wifi_connect_params_valid_secure(void)
|
|||
{
|
||||
WiFiInterface *wifi = get_interface();
|
||||
|
||||
if(wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA2) == NSAPI_ERROR_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2) == NSAPI_ERROR_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA) == NSAPI_ERROR_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WEP) == NSAPI_ERROR_OK) {
|
||||
if(wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()) == NSAPI_ERROR_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ void wifi_connect_secure(void)
|
|||
{
|
||||
WiFiInterface *wifi = get_interface();
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA2));
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()));
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect());
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void wifi_connect_secure_fail(void)
|
|||
{
|
||||
WiFiInterface *wifi = get_interface();
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, "aaaaaaaa", NSAPI_SECURITY_WPA2));
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, "aaaaaaaa", get_security()));
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_AUTH_FAILURE, wifi->connect());
|
||||
}
|
||||
|
|
|
@ -46,22 +46,25 @@ void wifi_scan(void)
|
|||
|
||||
for (int i=0; i<size; i++) {
|
||||
const char *ssid = ap[i].get_ssid();
|
||||
const uint8_t *bssid = ap[i].get_bssid();
|
||||
nsapi_security_t security = ap[i].get_security();
|
||||
int8_t rssi = ap[i].get_rssi();
|
||||
uint8_t ch = ap[i].get_channel();
|
||||
TEST_ASSERT_INT8_WITHIN(-10, -100, rssi);
|
||||
if (strcmp(MBED_CONF_APP_WIFI_SECURE_SSID, ssid) == 0) {
|
||||
secure_found = true;
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_SECURITY_WPA2, security);
|
||||
TEST_ASSERT_EQUAL_INT(get_security(), security);
|
||||
if (MBED_CONF_APP_WIFI_CH_SECURE) {
|
||||
TEST_ASSERT_EQUAL_INT(MBED_CONF_APP_WIFI_CH_SECURE, ch);
|
||||
}
|
||||
}
|
||||
if (strcmp(MBED_CONF_APP_WIFI_UNSECURE_SSID, ssid) == 0) {
|
||||
unsecure_found = true;
|
||||
TEST_ASSERT_EQUAL_INT(NSAPI_SECURITY_NONE, security);
|
||||
if (MBED_CONF_APP_WIFI_CH_UNSECURE) {
|
||||
TEST_ASSERT_EQUAL_INT(MBED_CONF_APP_WIFI_CH_UNSECURE, ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_ASSERT_TRUE(secure_found);
|
||||
TEST_ASSERT_TRUE(unsecure_found);
|
||||
}
|
||||
|
|
|
@ -47,17 +47,17 @@ void wifi_set_credential(void)
|
|||
TEST_ASSERT((error == NSAPI_ERROR_OK) || (error == NSAPI_ERROR_UNSUPPORTED));
|
||||
|
||||
error = iface->set_credentials("OK", "12345678", NSAPI_SECURITY_WPA);
|
||||
TEST_ASSERT(error == NSAPI_ERROR_OK);
|
||||
TEST_ASSERT((error == NSAPI_ERROR_OK) || (error == NSAPI_ERROR_UNSUPPORTED));
|
||||
|
||||
error = iface->set_credentials("OK", "12345678", NSAPI_SECURITY_WPA2);
|
||||
TEST_ASSERT(error == NSAPI_ERROR_OK);
|
||||
TEST_ASSERT((error == NSAPI_ERROR_OK) || (error == NSAPI_ERROR_UNSUPPORTED));
|
||||
|
||||
error = iface->set_credentials("OK", "12345678", NSAPI_SECURITY_WPA_WPA2);
|
||||
TEST_ASSERT(error == NSAPI_ERROR_OK);
|
||||
|
||||
error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni", NSAPI_SECURITY_WPA2);
|
||||
error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni", get_security());
|
||||
TEST_ASSERT(error == NSAPI_ERROR_OK);
|
||||
|
||||
error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni8", NSAPI_SECURITY_WPA2);
|
||||
error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni8", get_security());
|
||||
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
* app_json. */
|
||||
WiFiInterface *get_interface(void);
|
||||
|
||||
/**
|
||||
* Get security protocol to be used
|
||||
*/
|
||||
nsapi_security get_security(void);
|
||||
|
||||
/*
|
||||
* Test cases
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue