Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
WiFiInterface.h
00001 /* 00002 * Copyright (c) 2015 - 2016 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /** @file WifiInterface.h Common interface between Wi-Fi devices */ 00018 /** @addtogroup netinterface 00019 * @{ 00020 */ 00021 00022 #ifndef WIFI_INTERFACE_H 00023 #define WIFI_INTERFACE_H 00024 00025 #include <string.h> 00026 #include "netsocket/NetworkInterface.h" 00027 #include "netsocket/WiFiAccessPoint.h" 00028 00029 /** Common interface between Wi-Fi devices. 00030 */ 00031 class WiFiInterface: public virtual NetworkInterface { 00032 public: 00033 /** Get the default Wi-Fi interface. 00034 * 00035 * This is provided as a weak method so applications can override it. 00036 * Default behavior is to get the target's default interface, if 00037 * any. 00038 * 00039 * @return pointer to interface, if any. 00040 */ 00041 static WiFiInterface *get_default_instance(); 00042 00043 /** Set the Wi-Fi network credentials. 00044 * 00045 * @param ssid Name of the network to connect to. 00046 * @param pass Security passphrase to connect to the network. 00047 * @param security Type of encryption for connection 00048 * (defaults to NSAPI_SECURITY_NONE). 00049 * @return NSAPI_ERROR_OK on success, or error code on failure. 00050 */ 00051 virtual nsapi_error_t set_credentials(const char *ssid, const char *pass, 00052 nsapi_security_t security = NSAPI_SECURITY_NONE ) = 0; 00053 00054 /** Set the Wi-Fi network channel. 00055 * 00056 * @param channel Channel to make the connection, or 0 for any (Default: 0). 00057 * @return NSAPI_ERROR_OK on success, or error code on failure. 00058 */ 00059 virtual nsapi_error_t set_channel(uint8_t channel) = 0; 00060 00061 /** Get the current radio signal strength for active connection. 00062 * 00063 * @return Connection strength in dBm (negative value), 00064 * or 0 if measurement impossible. 00065 */ 00066 virtual int8_t get_rssi() = 0; 00067 00068 /** Attempt to connect to a Wi-Fi network. 00069 * 00070 * @param ssid Name of the network to connect to. 00071 * @param pass Security passphrase to connect to the network. 00072 * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE). 00073 * @param channel Channel to make the connection, or 0 for any (Default: 0). 00074 * @return NSAPI_ERROR_OK on success, or error code on failure. 00075 */ 00076 virtual nsapi_error_t connect(const char *ssid, const char *pass, 00077 nsapi_security_t security = NSAPI_SECURITY_NONE , uint8_t channel = 0) = 0; 00078 00079 /** Attempt to connect to a Wi-Fi network. Requires ssid and passphrase to be set. 00080 * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned. 00081 * 00082 * @return NSAPI_ERROR_OK on success, negative error code on failure. 00083 */ 00084 virtual nsapi_error_t connect() = 0; 00085 00086 /** Stop the interface. 00087 * 00088 * @return NSAPI_ERROR_OK on success, or error code on failure. 00089 */ 00090 virtual nsapi_error_t disconnect() = 0; 00091 00092 /** Scan for available networks. 00093 * 00094 * @note This is a blocking function. 00095 * 00096 * If the \p count is 0, the function only returns the number of available networks. 00097 * If the \p count is greater than 0 and the \p res is not NULL, the array of discovered APs is populated 00098 * with discovered networks up to the value of the \p count. 00099 * 00100 * @param res Pointer to allocated array to store discovered APs. 00101 * @param count Size of allocated res array, or 0 to only count available APs. 00102 * @return Number of entries in res, or if count was 0, number of available networks. 00103 * Negative on error (@see nsapi_types.h for nsapi_error). 00104 */ 00105 virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, nsapi_size_t count) = 0; 00106 00107 /** @copydoc NetworkInterface::wifiInterface 00108 */ 00109 virtual WiFiInterface *wifiInterface () 00110 { 00111 return this; 00112 } 00113 00114 #if !defined(DOXYGEN_ONLY) 00115 protected: 00116 00117 /** Get the target's default Wi-Fi interface. 00118 * 00119 * This is provided as a weak method so targets can override it. The 00120 * default implementation returns NULL. 00121 * 00122 * @return pointer to interface, if any. 00123 */ 00124 static WiFiInterface *get_target_default_instance(); 00125 #endif //!defined(DOXYGEN_ONLY) 00126 00127 public: 00128 /** Set default parameters on a Wi-Fi interface. 00129 * 00130 * A Wi-Fi interface instantiated directly or using 00131 * WiFiInterface::get_default_instance() is initially unconfigured. 00132 * This call can be used to set the default parameters that would 00133 * have been set if the interface had been requested using 00134 * NetworkInterface::get_default_instance() (see nsapi JSON 00135 * configuration). 00136 */ 00137 virtual void set_default_parameters(); 00138 }; 00139 00140 #endif 00141 00142 /** @}*/
Generated on Tue Jul 12 2022 13:55:03 by
