|
| 1 | +/* |
| 2 | + * Copyright (c) 2017, ARM Limited, All Rights Reserved |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | + * not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#include "mbed.h" |
| 19 | +#include "greentea-client/test_env.h" |
| 20 | +#include "unity.h" |
| 21 | +#include "utest.h" |
| 22 | +#include "wifi_tests.h" |
| 23 | + |
| 24 | +using namespace utest::v1; |
| 25 | + |
| 26 | +#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) |
| 27 | + |
| 28 | +#define SSID_MAX_LEN 32 |
| 29 | + |
| 30 | +void wifi_connect_nonblock(void) |
| 31 | +{ |
| 32 | + WiFiInterface *wifi = get_interface(); |
| 33 | + |
| 34 | + TEST_SKIP_UNLESS(wifi-> set_blocking(false) != NSAPI_ERROR_UNSUPPORTED) |
| 35 | + |
| 36 | + char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID; |
| 37 | + |
| 38 | + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL)); |
| 39 | + |
| 40 | + nsapi_error_t ret = wifi->connect(); |
| 41 | + |
| 42 | + TEST_ASSERT_TRUE((ret == NSAPI_ERROR_OK) || (ret == NSAPI_ERROR_WOULD_BLOCK)); |
| 43 | + |
| 44 | + nsapi_error_t connection_status; |
| 45 | + if (ret == NSAPI_ERROR_OK) { |
| 46 | + connection_status = wifi->get_connection_status(); |
| 47 | + TEST_ASSERT_TRUE( |
| 48 | + (connection_status == NSAPI_STATUS_GLOBAL_UP) |
| 49 | + || (connection_status == NSAPI_STATUS_LOCAL_UP)) |
| 50 | + } else { |
| 51 | + while ((connection_status != NSAPI_STATUS_GLOBAL_UP) |
| 52 | + && (connection_status != NSAPI_STATUS_LOCAL_UP)) { |
| 53 | + connection_status = wifi->get_connection_status(); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + ret = wifi->disconnect(); |
| 58 | + TEST_ASSERT_TRUE((ret == NSAPI_ERROR_OK) || (ret == NSAPI_ERROR_WOULD_BLOCK)); |
| 59 | + |
| 60 | + if (ret == NSAPI_ERROR_OK) { |
| 61 | + connection_status = wifi->get_connection_status(); |
| 62 | + TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_DISCONNECTED, connection_status); |
| 63 | + } else { |
| 64 | + while (connection_status != NSAPI_STATUS_DISCONNECTED) { |
| 65 | + connection_status = wifi->get_connection_status(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + wifi->set_blocking(true); |
| 70 | +} |
| 71 | + |
| 72 | +#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) |
0 commit comments