Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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