2019-01-09 13:20:22 +00:00
|
|
|
/*
|
2016-09-05 15:42:19 +00:00
|
|
|
* Copyright (c) 2015 - 2016 ARM Limited
|
2016-04-05 14:30:31 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-01-21 09:54:49 +00:00
|
|
|
/** @file WifiInterface.h Common interface between Wi-Fi devices */
|
2019-01-09 13:20:22 +00:00
|
|
|
/** @addtogroup netinterface
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-04-05 14:30:31 +00:00
|
|
|
#ifndef WIFI_INTERFACE_H
|
|
|
|
#define WIFI_INTERFACE_H
|
|
|
|
|
2016-09-05 15:42:19 +00:00
|
|
|
#include <string.h>
|
2016-09-30 23:32:06 +00:00
|
|
|
#include "netsocket/NetworkInterface.h"
|
2016-10-02 12:24:24 +00:00
|
|
|
#include "netsocket/WiFiAccessPoint.h"
|
2016-07-19 22:12:22 +00:00
|
|
|
|
2019-01-11 09:48:45 +00:00
|
|
|
/** Common interface between Wi-Fi devices.
|
2016-04-05 14:30:31 +00:00
|
|
|
*/
|
2018-08-03 12:32:29 +00:00
|
|
|
class WiFiInterface: public virtual NetworkInterface {
|
2016-04-05 14:30:31 +00:00
|
|
|
public:
|
2018-10-25 10:24:11 +00:00
|
|
|
/** Get the default Wi-Fi interface.
|
2018-02-15 12:46:11 +00:00
|
|
|
*
|
2019-01-11 08:43:09 +00:00
|
|
|
* This is provided as a weak method so applications can override it.
|
2018-10-26 14:43:44 +00:00
|
|
|
* Default behavior is to get the target's default interface, if
|
2018-02-15 12:46:11 +00:00
|
|
|
* any.
|
|
|
|
*
|
2018-10-24 19:24:33 +00:00
|
|
|
* @return pointer to interface, if any.
|
2016-09-28 08:24:56 +00:00
|
|
|
*/
|
2018-02-15 12:46:11 +00:00
|
|
|
static WiFiInterface *get_default_instance();
|
2016-09-28 08:24:56 +00:00
|
|
|
|
2018-10-25 10:24:11 +00:00
|
|
|
/** Set the Wi-Fi network credentials.
|
2016-09-28 08:24:56 +00:00
|
|
|
*
|
2018-10-24 19:24:33 +00:00
|
|
|
* @param ssid Name of the network to connect to.
|
|
|
|
* @param pass Security passphrase to connect to the network.
|
2016-09-30 20:28:43 +00:00
|
|
|
* @param security Type of encryption for connection
|
2018-10-24 19:24:33 +00:00
|
|
|
* (defaults to NSAPI_SECURITY_NONE).
|
|
|
|
* @return NSAPI_ERROR_OK on success, or error code on failure.
|
2016-09-28 08:24:56 +00:00
|
|
|
*/
|
2016-10-18 19:48:46 +00:00
|
|
|
virtual nsapi_error_t set_credentials(const char *ssid, const char *pass,
|
2018-08-03 12:32:29 +00:00
|
|
|
nsapi_security_t security = NSAPI_SECURITY_NONE) = 0;
|
2016-09-28 08:24:56 +00:00
|
|
|
|
2018-10-25 10:24:11 +00:00
|
|
|
/** Set the Wi-Fi network channel.
|
2016-04-19 22:51:51 +00:00
|
|
|
*
|
2019-01-11 08:43:09 +00:00
|
|
|
* @param channel Channel to make the connection, or 0 for any (Default: 0).
|
2018-10-24 19:24:33 +00:00
|
|
|
* @return NSAPI_ERROR_OK on success, or error code on failure.
|
2016-09-05 15:42:19 +00:00
|
|
|
*/
|
2016-10-18 19:48:46 +00:00
|
|
|
virtual nsapi_error_t set_channel(uint8_t channel) = 0;
|
2016-09-05 15:42:19 +00:00
|
|
|
|
2018-10-24 19:24:33 +00:00
|
|
|
/** Get the current radio signal strength for active connection.
|
2016-09-05 15:42:19 +00:00
|
|
|
*
|
2016-09-30 20:28:43 +00:00
|
|
|
* @return Connection strength in dBm (negative value),
|
2018-10-24 19:24:33 +00:00
|
|
|
* or 0 if measurement impossible.
|
2016-09-30 20:28:43 +00:00
|
|
|
*/
|
|
|
|
virtual int8_t get_rssi() = 0;
|
|
|
|
|
2018-10-25 10:24:11 +00:00
|
|
|
/** Attempt to connect to a Wi-Fi network.
|
2016-09-05 15:42:19 +00:00
|
|
|
*
|
2018-10-24 19:24:33 +00:00
|
|
|
* @param ssid Name of the network to connect to.
|
|
|
|
* @param pass Security passphrase to connect to the network.
|
|
|
|
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE).
|
2019-01-11 08:43:09 +00:00
|
|
|
* @param channel Channel to make the connection, or 0 for any (Default: 0).
|
2018-10-24 19:24:33 +00:00
|
|
|
* @return NSAPI_ERROR_OK on success, or error code on failure.
|
2016-04-05 14:30:31 +00:00
|
|
|
*/
|
2016-10-18 19:48:46 +00:00
|
|
|
virtual nsapi_error_t connect(const char *ssid, const char *pass,
|
2018-08-03 12:32:29 +00:00
|
|
|
nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0) = 0;
|
2016-04-05 14:30:31 +00:00
|
|
|
|
2018-10-25 10:24:11 +00:00
|
|
|
/** Attempt to connect to a Wi-Fi network. Requires ssid and passphrase to be set.
|
2016-09-08 18:44:11 +00:00
|
|
|
* If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
|
|
|
|
*
|
2018-10-25 15:26:44 +00:00
|
|
|
* @return NSAPI_ERROR_OK on success, negative error code on failure.
|
2016-09-08 18:44:11 +00:00
|
|
|
*/
|
2020-02-21 11:49:26 +00:00
|
|
|
nsapi_error_t connect() override = 0;
|
2016-09-08 18:44:11 +00:00
|
|
|
|
2018-10-24 19:24:33 +00:00
|
|
|
/** Stop the interface.
|
2016-04-19 22:51:51 +00:00
|
|
|
*
|
2018-10-24 19:24:33 +00:00
|
|
|
* @return NSAPI_ERROR_OK on success, or error code on failure.
|
2016-04-05 14:30:31 +00:00
|
|
|
*/
|
2020-02-21 11:49:26 +00:00
|
|
|
nsapi_error_t disconnect() override = 0;
|
2016-04-05 14:30:31 +00:00
|
|
|
|
2018-10-24 19:24:33 +00:00
|
|
|
/** Scan for available networks.
|
2016-09-05 15:42:19 +00:00
|
|
|
*
|
2019-01-09 09:29:51 +00:00
|
|
|
* @note This is a blocking function.
|
|
|
|
*
|
|
|
|
* If the \p count is 0, the function only returns the number of available networks.
|
|
|
|
* If the \p count is greater than 0 and the \p res is not NULL, the array of discovered APs is populated
|
|
|
|
* with discovered networks up to the value of the \p count.
|
2016-09-05 15:42:19 +00:00
|
|
|
*
|
2018-10-24 19:24:33 +00:00
|
|
|
* @param res Pointer to allocated array to store discovered APs.
|
|
|
|
* @param count Size of allocated res array, or 0 to only count available APs.
|
2019-01-09 09:29:51 +00:00
|
|
|
* @return Number of entries in res, or if count was 0, number of available networks.
|
2018-10-24 19:24:33 +00:00
|
|
|
* Negative on error (@see nsapi_types.h for nsapi_error).
|
2016-09-05 15:42:19 +00:00
|
|
|
*/
|
2016-10-18 19:48:46 +00:00
|
|
|
virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, nsapi_size_t count) = 0;
|
2017-12-19 14:05:35 +00:00
|
|
|
|
2018-10-24 19:24:33 +00:00
|
|
|
/** @copydoc NetworkInterface::wifiInterface
|
|
|
|
*/
|
2020-02-21 11:49:26 +00:00
|
|
|
WiFiInterface *wifiInterface() final
|
2018-08-03 12:32:29 +00:00
|
|
|
{
|
2017-12-19 14:05:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
2018-02-15 12:46:11 +00:00
|
|
|
|
2018-10-24 19:24:33 +00:00
|
|
|
#if !defined(DOXYGEN_ONLY)
|
2018-02-15 12:46:11 +00:00
|
|
|
protected:
|
|
|
|
|
2018-10-25 10:24:11 +00:00
|
|
|
/** Get the target's default Wi-Fi interface.
|
2018-02-15 12:46:11 +00:00
|
|
|
*
|
2019-01-11 08:43:09 +00:00
|
|
|
* This is provided as a weak method so targets can override it. The
|
2018-02-15 12:46:11 +00:00
|
|
|
* default implementation returns NULL.
|
|
|
|
*
|
2018-10-24 19:24:33 +00:00
|
|
|
* @return pointer to interface, if any.
|
2018-02-15 12:46:11 +00:00
|
|
|
*/
|
|
|
|
static WiFiInterface *get_target_default_instance();
|
2018-10-24 19:24:33 +00:00
|
|
|
#endif //!defined(DOXYGEN_ONLY)
|
2019-01-28 11:27:10 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** Set default parameters on a Wi-Fi interface.
|
|
|
|
*
|
|
|
|
* A Wi-Fi interface instantiated directly or using
|
|
|
|
* WiFiInterface::get_default_instance() is initially unconfigured.
|
|
|
|
* This call can be used to set the default parameters that would
|
|
|
|
* have been set if the interface had been requested using
|
|
|
|
* NetworkInterface::get_default_instance() (see nsapi JSON
|
|
|
|
* configuration).
|
|
|
|
*/
|
2020-02-21 11:49:26 +00:00
|
|
|
void set_default_parameters() override;
|
2016-09-05 15:42:19 +00:00
|
|
|
};
|
2016-07-19 22:12:22 +00:00
|
|
|
|
2016-04-05 14:30:31 +00:00
|
|
|
#endif
|
2016-10-04 20:02:44 +00:00
|
|
|
|
|
|
|
/** @}*/
|