ON Semiconductor / mbed-os

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WiFiInterface.h Source File

WiFiInterface.h

00001 
00002 /** \addtogroup netsocket */
00003 /** @{*/
00004 /* WiFiInterface
00005  * Copyright (c) 2015 - 2016 ARM Limited
00006  *
00007  * Licensed under the Apache License, Version 2.0 (the "License");
00008  * you may not use this file except in compliance with the License.
00009  * You may obtain a copy of the License at
00010  *
00011  *     http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing, software
00014  * distributed under the License is distributed on an "AS IS" BASIS,
00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  * See the License for the specific language governing permissions and
00017  * limitations under the License.
00018  */
00019 
00020 #ifndef WIFI_INTERFACE_H
00021 #define WIFI_INTERFACE_H
00022 
00023 #include <string.h>
00024 #include "netsocket/NetworkInterface.h"
00025 #include "netsocket/WiFiAccessPoint.h"
00026 
00027 /** WiFiInterface class
00028  *
00029  *  Common interface that is shared between WiFi devices
00030  */
00031 class WiFiInterface: public NetworkInterface
00032 {
00033 public:
00034     /** WiFiInterface lifetime
00035      */
00036     virtual ~WiFiInterface() {};
00037 
00038     /** Set the WiFi network credentials
00039      *
00040      *  @param ssid      Name of the network to connect to
00041      *  @param pass      Security passphrase to connect to the network
00042      *  @param security  Type of encryption for connection
00043      *                   (defaults to NSAPI_SECURITY_NONE)
00044      *  @return          0 on success, or error code on failure
00045      */
00046     virtual nsapi_error_t set_credentials(const char *ssid, const char *pass,
00047             nsapi_security_t security = NSAPI_SECURITY_NONE ) = 0;
00048 
00049     /** Set the WiFi network channel
00050      *
00051      *  @param channel   Channel on which the connection is to be made, or 0 for any (Default: 0)
00052      *  @return          0 on success, or error code on failure
00053      */
00054     virtual nsapi_error_t set_channel(uint8_t channel) = 0;
00055 
00056     /** Gets the current radio signal strength for active connection
00057      *
00058      *  @return         Connection strength in dBm (negative value),
00059      *                  or 0 if measurement impossible
00060      */
00061     virtual int8_t get_rssi() = 0;
00062 
00063     /** Start the interface
00064      *
00065      *  Attempts to connect to a WiFi network.
00066      *
00067      *  @param ssid      Name of the network to connect to
00068      *  @param pass      Security passphrase to connect to the network
00069      *  @param security  Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
00070      *  @param channel   Channel on which the connection is to be made, or 0 for any (Default: 0)
00071      *  @return          0 on success, or error code on failure
00072      */
00073     virtual nsapi_error_t connect(const char *ssid, const char *pass,
00074             nsapi_security_t security = NSAPI_SECURITY_NONE , uint8_t channel = 0) = 0;
00075 
00076     /** Start the interface
00077      *
00078      *  Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
00079      *  If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
00080      *
00081      *  @return         0 on success, negative error code on failure
00082      */
00083     virtual nsapi_error_t connect() = 0;
00084 
00085     /** Stop the interface
00086      *
00087      *  @return         0 on success, or error code on failure
00088      */
00089     virtual nsapi_error_t disconnect() = 0;
00090 
00091     /** Scan for available networks
00092      *
00093      *  This function will block. If the @a count is 0, function will only return count of available networks, so that
00094      *  user can allocated necessary memory. If the @count is grater than 0 and the @a ap is not NULL it'll be populated
00095      *  with discovered networks up to value of @a count.
00096      *
00097      *  @param  ap       Pointer to allocated array to store discovered AP
00098      *  @param  count    Size of allocated @a res array, or 0 to only count available AP
00099      *  @return          Number of entries in @a, or if @a count was 0 number of available networks,
00100      *                   negative on error see @a nsapi_error
00101      */
00102     virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, nsapi_size_t count) = 0;
00103 };
00104 
00105 #endif
00106 
00107 /** @}*/