mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 167:e84263d55307 1 /* Ameba implementation of NetworkInterfaceAPI
AnnaBridge 167:e84263d55307 2 * Copyright (c) 2015 ARM Limited
AnnaBridge 167:e84263d55307 3 *
AnnaBridge 167:e84263d55307 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 167:e84263d55307 5 * you may not use this file except in compliance with the License.
AnnaBridge 167:e84263d55307 6 * You may obtain a copy of the License at
AnnaBridge 167:e84263d55307 7 *
AnnaBridge 167:e84263d55307 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 167:e84263d55307 9 *
AnnaBridge 167:e84263d55307 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 167:e84263d55307 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 167:e84263d55307 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 167:e84263d55307 13 * See the License for the specific language governing permissions and
AnnaBridge 167:e84263d55307 14 * limitations under the License.
AnnaBridge 167:e84263d55307 15 */
AnnaBridge 167:e84263d55307 16
AnnaBridge 167:e84263d55307 17 #ifndef RTW_INTERFACE_H
AnnaBridge 167:e84263d55307 18 #define RTW_INTERFACE_H
AnnaBridge 167:e84263d55307 19
AnnaBridge 167:e84263d55307 20 #include "netsocket/NetworkInterface.h"
AnnaBridge 167:e84263d55307 21 #include "netsocket/WiFiInterface.h"
AnnaBridge 167:e84263d55307 22 #include "nsapi.h"
AnnaBridge 167:e84263d55307 23 #include "rtos.h"
Anna Bridge 186:707f6e361f3e 24 #include "netif.h"
Anna Bridge 186:707f6e361f3e 25 #include "rtw_emac.h"
Anna Bridge 186:707f6e361f3e 26 #include "OnboardNetworkStack.h"
AnnaBridge 188:bcfe06ba3d64 27 #include "EMACInterface.h"
Anna Bridge 186:707f6e361f3e 28 #include "LWIPStack.h"
AnnaBridge 167:e84263d55307 29
AnnaBridge 167:e84263d55307 30 // Forward declaration
AnnaBridge 167:e84263d55307 31 class NetworkStack;
AnnaBridge 167:e84263d55307 32
AnnaBridge 167:e84263d55307 33 /** Realtek Wlan (RTW) interface class
AnnaBridge 167:e84263d55307 34 * Implementation of the NetworkStack for Ameba
AnnaBridge 167:e84263d55307 35 */
AnnaBridge 188:bcfe06ba3d64 36 class RTWInterface: public WiFiInterface, public EMACInterface
AnnaBridge 167:e84263d55307 37 {
AnnaBridge 167:e84263d55307 38 public:
AnnaBridge 167:e84263d55307 39 /** RTWWlanInterface lifetime
AnnaBridge 167:e84263d55307 40 */
Anna Bridge 186:707f6e361f3e 41 RTWInterface(
Anna Bridge 186:707f6e361f3e 42 RTW_EMAC &rtw_emac = RTW_EMAC::get_instance(),
AnnaBridge 189:f392fc9709a3 43 OnboardNetworkStack &rtw_lwip_stack = OnboardNetworkStack::get_default_instance(), bool debug=false);
Anna Bridge 186:707f6e361f3e 44
AnnaBridge 167:e84263d55307 45 ~RTWInterface();
AnnaBridge 167:e84263d55307 46
AnnaBridge 167:e84263d55307 47 /** Set the WiFi network credentials
AnnaBridge 167:e84263d55307 48 *
AnnaBridge 167:e84263d55307 49 * @param ssid Name of the network to connect to
AnnaBridge 167:e84263d55307 50 * @param pass Security passphrase to connect to the network
AnnaBridge 167:e84263d55307 51 * @param security Type of encryption for connection
AnnaBridge 167:e84263d55307 52 * (defaults to NSAPI_SECURITY_NONE)
AnnaBridge 167:e84263d55307 53 * @return 0 on success, or error code on failure
AnnaBridge 167:e84263d55307 54 */
AnnaBridge 167:e84263d55307 55 virtual nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
AnnaBridge 167:e84263d55307 56
AnnaBridge 167:e84263d55307 57 /** Start the interface
AnnaBridge 167:e84263d55307 58 *
AnnaBridge 167:e84263d55307 59 * Attempts to connect to a WiFi network.
AnnaBridge 167:e84263d55307 60 *
AnnaBridge 167:e84263d55307 61 * @param ssid Name of the network to connect to
AnnaBridge 167:e84263d55307 62 * @param pass Security passphrase to connect to the network
AnnaBridge 167:e84263d55307 63 * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
AnnaBridge 167:e84263d55307 64 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
AnnaBridge 167:e84263d55307 65 * @return 0 on success, or error code on failure
AnnaBridge 167:e84263d55307 66 */
AnnaBridge 167:e84263d55307 67 virtual nsapi_error_t connect(const char *ssid, const char *pass,
AnnaBridge 167:e84263d55307 68 nsapi_security_t security = NSAPI_SECURITY_NONE,
AnnaBridge 167:e84263d55307 69 uint8_t channel = 0);
AnnaBridge 167:e84263d55307 70
AnnaBridge 167:e84263d55307 71 /** Start the interface
AnnaBridge 167:e84263d55307 72 * @return 0 on success, negative on failure
AnnaBridge 167:e84263d55307 73 */
AnnaBridge 167:e84263d55307 74 virtual nsapi_error_t connect();
AnnaBridge 167:e84263d55307 75
AnnaBridge 167:e84263d55307 76 /** Stop the interface
AnnaBridge 167:e84263d55307 77 * @return 0 on success, negative on failure
AnnaBridge 167:e84263d55307 78 */
AnnaBridge 167:e84263d55307 79 virtual nsapi_error_t disconnect();
AnnaBridge 167:e84263d55307 80 virtual int is_connected();
AnnaBridge 167:e84263d55307 81
AnnaBridge 167:e84263d55307 82 /** Scan for available networks
AnnaBridge 167:e84263d55307 83 *
AnnaBridge 167:e84263d55307 84 * The scan will
AnnaBridge 167:e84263d55307 85 * If the network interface is set to non-blocking mode, scan will attempt to scan
AnnaBridge 167:e84263d55307 86 * for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
AnnaBridge 167:e84263d55307 87 * is attached, the callback will be called when the operation has completed.
AnnaBridge 167:e84263d55307 88 * @param ap Pointer to allocated array to store discovered AP
AnnaBridge 167:e84263d55307 89 * @param count Size of allocated @a res array, or 0 to only count available AP
AnnaBridge 167:e84263d55307 90 * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
AnnaBridge 167:e84263d55307 91 * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
AnnaBridge 167:e84263d55307 92 * see @a nsapi_error
AnnaBridge 167:e84263d55307 93 */
AnnaBridge 188:bcfe06ba3d64 94 virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count);
AnnaBridge 167:e84263d55307 95
AnnaBridge 188:bcfe06ba3d64 96 virtual nsapi_error_t set_channel(uint8_t channel);
AnnaBridge 188:bcfe06ba3d64 97 virtual int8_t get_rssi();
AnnaBridge 167:e84263d55307 98
Anna Bridge 186:707f6e361f3e 99 RTW_EMAC &get_emac() const { return rtw_emac; }
Anna Bridge 186:707f6e361f3e 100
Anna Bridge 186:707f6e361f3e 101 virtual RTWInterface *rtwInterface() { return this; }
Anna Bridge 186:707f6e361f3e 102
AnnaBridge 167:e84263d55307 103 protected:
AnnaBridge 167:e84263d55307 104 /** Provide access to the underlying stack
AnnaBridge 167:e84263d55307 105 *
AnnaBridge 167:e84263d55307 106 * @return The underlying network stack
AnnaBridge 167:e84263d55307 107 */
AnnaBridge 167:e84263d55307 108 virtual NetworkStack *get_stack();
Anna Bridge 186:707f6e361f3e 109 RTW_EMAC &rtw_emac;
Anna Bridge 186:707f6e361f3e 110 OnboardNetworkStack &rtw_obn_stack;
AnnaBridge 167:e84263d55307 111 char _ssid[256];
AnnaBridge 167:e84263d55307 112 char _pass[256];
AnnaBridge 167:e84263d55307 113 nsapi_security_t _security;
AnnaBridge 167:e84263d55307 114 uint8_t _channel;
AnnaBridge 189:f392fc9709a3 115 static const int SSID_MAX_LENGTH = 32; //The longest ssid
AnnaBridge 189:f392fc9709a3 116 static const int PASSPHRASE_MAX_LENGTH = 63; //The longest passphrase
AnnaBridge 189:f392fc9709a3 117 static const int PASSPHRASE_MIN_LENGTH = 8; // The shortest passphrase
AnnaBridge 167:e84263d55307 118 };
AnnaBridge 167:e84263d55307 119 #endif