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