Lee Kai Xuan / mbed-os

Fork of mbed-os by erkin yucel

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 "Callback.h"
00025 #include "netsocket/NetworkInterface.h"
00026 #include "netsocket/WiFiAccessPoint.h"
00027 
00028 /** WiFiInterface class
00029  *
00030  *  Common interface that is shared between WiFi devices
00031  */
00032 class WiFiInterface: public NetworkInterface
00033 {
00034 public:
00035     /** WiFiInterface lifetime
00036      */
00037     virtual ~WiFiInterface() {};
00038 
00039     /** Set the WiFi network credentials
00040      *
00041      *  @param ssid      Name of the network to connect to
00042      *  @param pass      Security passphrase to connect to the network
00043      *  @param security  Type of encryption for connection
00044      *                   (defaults to NSAPI_SECURITY_NONE)
00045      *  @return          0 on success, or error code on failure
00046      */
00047     virtual int set_credentials(const char *ssid, const char *pass, 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 int 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 int connect(const char *ssid, const char *pass,
00074             nsapi_security_t security = NSAPI_SECURITY_NONE ,
00075             uint8_t channel = 0) = 0;
00076 
00077     /** Start the interface
00078      *
00079      *  Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
00080      *  If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
00081      *
00082      *  @return         0 on success, negative error code on failure
00083      */
00084     virtual int connect() = 0;
00085 
00086     /** Stop the interface
00087      *
00088      *  @return         0 on success, or error code on failure
00089      */
00090     virtual int disconnect() = 0;
00091 
00092     /** Scan for available networks
00093      *
00094      *  The scan will 
00095      *  If the network interface is set to non-blocking mode, scan will attempt to scan
00096      *  for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
00097      *  is attached, the callback will be called when the operation has completed.
00098      *
00099      * @param  ap       Pointer to allocated array to store discovered AP
00100      * @param  count    Size of allocated @a res array, or 0 to only count available AP
00101      * @param  timeout  Timeout in milliseconds; 0 for no timeout (Default: 0)
00102      * @return          Number of entries in @a, or if @a count was 0 number of available networks, negative on error
00103      *                  see @a nsapi_error
00104      */
00105     virtual int scan(WiFiAccessPoint *res, unsigned count) = 0;
00106 };
00107 
00108 #endif
00109 
00110 /** @}*/