2016-10-04 20:02:44 +00:00
|
|
|
|
2016-04-20 19:39:13 +00:00
|
|
|
/* WiFiInterface
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2016-04-20 19:39:13 +00:00
|
|
|
/** WiFiInterface class
|
2016-04-19 22:51:51 +00:00
|
|
|
*
|
2016-04-05 14:30:31 +00:00
|
|
|
* Common interface that is shared between WiFi devices
|
2017-06-01 21:43:43 +00:00
|
|
|
* @addtogroup netsocket
|
2016-04-05 14:30:31 +00:00
|
|
|
*/
|
2017-12-05 10:45:30 +00:00
|
|
|
class WiFiInterface: public virtual NetworkInterface
|
2016-04-05 14:30:31 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-02-15 12:46:11 +00:00
|
|
|
/** Get the default WiFi interface.
|
|
|
|
*
|
|
|
|
* This is provided as a weak method so applications can override.
|
|
|
|
* Default behaviour is to get the target's default interface, if
|
|
|
|
* any.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
|
|
|
/** Set the WiFi network credentials
|
|
|
|
*
|
2016-09-30 20:28:43 +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
|
|
|
|
* (defaults to NSAPI_SECURITY_NONE)
|
|
|
|
* @return 0 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,
|
|
|
|
nsapi_security_t security = NSAPI_SECURITY_NONE) = 0;
|
2016-09-28 08:24:56 +00:00
|
|
|
|
2016-09-30 20:28:43 +00:00
|
|
|
/** Set the WiFi network channel
|
2016-04-19 22:51:51 +00:00
|
|
|
*
|
2016-09-22 10:49:02 +00:00
|
|
|
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
|
2016-09-05 15:42:19 +00:00
|
|
|
* @return 0 on success, or error code on failure
|
|
|
|
*/
|
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
|
|
|
|
2016-09-30 20:28:43 +00:00
|
|
|
/** Gets 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),
|
|
|
|
* or 0 if measurement impossible
|
|
|
|
*/
|
|
|
|
virtual int8_t get_rssi() = 0;
|
|
|
|
|
|
|
|
/** Start the interface
|
2016-09-05 15:42:19 +00:00
|
|
|
*
|
2016-09-30 20:28:43 +00:00
|
|
|
* Attempts to connect to a WiFi network.
|
2016-04-19 22:51:51 +00:00
|
|
|
*
|
2016-04-06 13:50:56 +00:00
|
|
|
* @param ssid Name of the network to connect to
|
|
|
|
* @param pass Security passphrase to connect to the network
|
2016-09-22 10:49:02 +00:00
|
|
|
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
|
2016-09-30 20:28:43 +00:00
|
|
|
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
|
|
|
|
* @return 0 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,
|
|
|
|
nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0) = 0;
|
2016-04-05 14:30:31 +00:00
|
|
|
|
2016-09-08 18:44:11 +00:00
|
|
|
/** Start the interface
|
|
|
|
*
|
|
|
|
* Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
|
|
|
|
* If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
|
|
|
|
*
|
|
|
|
* @return 0 on success, negative error code on failure
|
|
|
|
*/
|
2016-10-18 19:48:46 +00:00
|
|
|
virtual nsapi_error_t connect() = 0;
|
2016-09-08 18:44:11 +00:00
|
|
|
|
2016-04-05 14:30:31 +00:00
|
|
|
/** Stop the interface
|
2016-04-19 22:51:51 +00:00
|
|
|
*
|
2016-09-30 20:28:43 +00:00
|
|
|
* @return 0 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 disconnect() = 0;
|
2016-04-05 14:30:31 +00:00
|
|
|
|
2016-09-05 15:42:19 +00:00
|
|
|
/** Scan for available networks
|
|
|
|
*
|
2016-11-10 09:40:48 +00:00
|
|
|
* This function will block. If the @a count is 0, function will only return count of available networks, so that
|
2017-06-01 21:43:43 +00:00
|
|
|
* user can allocated necessary memory. If the \p count is grater than 0 and the a \p res is not NULL it'll be populated
|
|
|
|
* with discovered networks up to value of \p count.
|
2016-09-05 15:42:19 +00:00
|
|
|
*
|
2017-06-01 21:43:43 +00:00
|
|
|
* @param res Pointer to allocated array to store discovered AP
|
2016-11-10 09:40:48 +00:00
|
|
|
* @param count Size of allocated @a res array, or 0 to only count available AP
|
2017-06-01 21:43:43 +00:00
|
|
|
* @return Number of entries in \p count, or if \p count was 0 number of available networks,
|
2016-11-10 09:40:48 +00:00
|
|
|
* negative on error see @a 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
|
|
|
|
|
|
|
virtual WiFiInterface *wifiInterface() {
|
|
|
|
return this;
|
|
|
|
}
|
2018-02-15 12:46:11 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/** Get the target's default WiFi interface.
|
|
|
|
*
|
|
|
|
* This is provided as a weak method so targets can override. The
|
|
|
|
* default implementation returns NULL.
|
|
|
|
*
|
|
|
|
* @return pointer to interface, if any
|
|
|
|
*/
|
|
|
|
static WiFiInterface *get_target_default_instance();
|
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
|
|
|
|
|
|
|
/** @}*/
|