mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1
elessair 0:f269e3021894 2 /** \addtogroup netsocket */
elessair 0:f269e3021894 3 /** @{*/
elessair 0:f269e3021894 4 /* WiFiInterface
elessair 0:f269e3021894 5 * Copyright (c) 2015 - 2016 ARM Limited
elessair 0:f269e3021894 6 *
elessair 0:f269e3021894 7 * Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 8 * you may not use this file except in compliance with the License.
elessair 0:f269e3021894 9 * You may obtain a copy of the License at
elessair 0:f269e3021894 10 *
elessair 0:f269e3021894 11 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 12 *
elessair 0:f269e3021894 13 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 14 * distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 16 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 17 * limitations under the License.
elessair 0:f269e3021894 18 */
elessair 0:f269e3021894 19
elessair 0:f269e3021894 20 #ifndef WIFI_INTERFACE_H
elessair 0:f269e3021894 21 #define WIFI_INTERFACE_H
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 #include <string.h>
elessair 0:f269e3021894 24 #include "Callback.h"
elessair 0:f269e3021894 25 #include "netsocket/NetworkInterface.h"
elessair 0:f269e3021894 26 #include "netsocket/WiFiAccessPoint.h"
elessair 0:f269e3021894 27
elessair 0:f269e3021894 28 /** WiFiInterface class
elessair 0:f269e3021894 29 *
elessair 0:f269e3021894 30 * Common interface that is shared between WiFi devices
elessair 0:f269e3021894 31 */
elessair 0:f269e3021894 32 class WiFiInterface: public NetworkInterface
elessair 0:f269e3021894 33 {
elessair 0:f269e3021894 34 public:
elessair 0:f269e3021894 35 /** WiFiInterface lifetime
elessair 0:f269e3021894 36 */
elessair 0:f269e3021894 37 virtual ~WiFiInterface() {};
elessair 0:f269e3021894 38
elessair 0:f269e3021894 39 /** Set the WiFi network credentials
elessair 0:f269e3021894 40 *
elessair 0:f269e3021894 41 * @param ssid Name of the network to connect to
elessair 0:f269e3021894 42 * @param pass Security passphrase to connect to the network
elessair 0:f269e3021894 43 * @param security Type of encryption for connection
elessair 0:f269e3021894 44 * (defaults to NSAPI_SECURITY_NONE)
elessair 0:f269e3021894 45 * @return 0 on success, or error code on failure
elessair 0:f269e3021894 46 */
elessair 0:f269e3021894 47 virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE) = 0;
elessair 0:f269e3021894 48
elessair 0:f269e3021894 49 /** Set the WiFi network channel
elessair 0:f269e3021894 50 *
elessair 0:f269e3021894 51 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
elessair 0:f269e3021894 52 * @return 0 on success, or error code on failure
elessair 0:f269e3021894 53 */
elessair 0:f269e3021894 54 virtual int set_channel(uint8_t channel) = 0;
elessair 0:f269e3021894 55
elessair 0:f269e3021894 56 /** Gets the current radio signal strength for active connection
elessair 0:f269e3021894 57 *
elessair 0:f269e3021894 58 * @return Connection strength in dBm (negative value),
elessair 0:f269e3021894 59 * or 0 if measurement impossible
elessair 0:f269e3021894 60 */
elessair 0:f269e3021894 61 virtual int8_t get_rssi() = 0;
elessair 0:f269e3021894 62
elessair 0:f269e3021894 63 /** Start the interface
elessair 0:f269e3021894 64 *
elessair 0:f269e3021894 65 * Attempts to connect to a WiFi network.
elessair 0:f269e3021894 66 *
elessair 0:f269e3021894 67 * @param ssid Name of the network to connect to
elessair 0:f269e3021894 68 * @param pass Security passphrase to connect to the network
elessair 0:f269e3021894 69 * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
elessair 0:f269e3021894 70 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
elessair 0:f269e3021894 71 * @return 0 on success, or error code on failure
elessair 0:f269e3021894 72 */
elessair 0:f269e3021894 73 virtual int connect(const char *ssid, const char *pass,
elessair 0:f269e3021894 74 nsapi_security_t security = NSAPI_SECURITY_NONE,
elessair 0:f269e3021894 75 uint8_t channel = 0) = 0;
elessair 0:f269e3021894 76
elessair 0:f269e3021894 77 /** Start the interface
elessair 0:f269e3021894 78 *
elessair 0:f269e3021894 79 * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
elessair 0:f269e3021894 80 * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
elessair 0:f269e3021894 81 *
elessair 0:f269e3021894 82 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 83 */
elessair 0:f269e3021894 84 virtual int connect() = 0;
elessair 0:f269e3021894 85
elessair 0:f269e3021894 86 /** Stop the interface
elessair 0:f269e3021894 87 *
elessair 0:f269e3021894 88 * @return 0 on success, or error code on failure
elessair 0:f269e3021894 89 */
elessair 0:f269e3021894 90 virtual int disconnect() = 0;
elessair 0:f269e3021894 91
elessair 0:f269e3021894 92 /** Scan for available networks
elessair 0:f269e3021894 93 *
elessair 0:f269e3021894 94 * The scan will
elessair 0:f269e3021894 95 * If the network interface is set to non-blocking mode, scan will attempt to scan
elessair 0:f269e3021894 96 * for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
elessair 0:f269e3021894 97 * is attached, the callback will be called when the operation has completed.
elessair 0:f269e3021894 98 *
elessair 0:f269e3021894 99 * @param ap Pointer to allocated array to store discovered AP
elessair 0:f269e3021894 100 * @param count Size of allocated @a res array, or 0 to only count available AP
elessair 0:f269e3021894 101 * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
elessair 0:f269e3021894 102 * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
elessair 0:f269e3021894 103 * see @a nsapi_error
elessair 0:f269e3021894 104 */
elessair 0:f269e3021894 105 virtual int scan(WiFiAccessPoint *res, unsigned count) = 0;
elessair 0:f269e3021894 106 };
elessair 0:f269e3021894 107
elessair 0:f269e3021894 108 #endif
elessair 0:f269e3021894 109
elessair 0:f269e3021894 110 /** @}*/