mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.h@181:57724642e740, 2018-02-16 (annotated)
- Committer:
- AnnaBridge
- Date:
- Fri Feb 16 16:09:33 2018 +0000
- Revision:
- 181:57724642e740
- Parent:
- 169:e3b6fe271b81
- Child:
- 186:707f6e361f3e
mbed-dev library. Release version 159.
Who changed what in which revision?
User | Revision | Line number | New 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" |
AnnaBridge | 167:e84263d55307 | 24 | #include "lwip/netif.h" |
AnnaBridge | 167:e84263d55307 | 25 | |
AnnaBridge | 167:e84263d55307 | 26 | // Forward declaration |
AnnaBridge | 167:e84263d55307 | 27 | class NetworkStack; |
AnnaBridge | 167:e84263d55307 | 28 | |
AnnaBridge | 167:e84263d55307 | 29 | /** Realtek Wlan (RTW) interface class |
AnnaBridge | 167:e84263d55307 | 30 | * Implementation of the NetworkStack for Ameba |
AnnaBridge | 167:e84263d55307 | 31 | */ |
AnnaBridge | 167:e84263d55307 | 32 | class RTWInterface: public WiFiInterface |
AnnaBridge | 167:e84263d55307 | 33 | { |
AnnaBridge | 167:e84263d55307 | 34 | public: |
AnnaBridge | 167:e84263d55307 | 35 | /** RTWWlanInterface lifetime |
AnnaBridge | 167:e84263d55307 | 36 | */ |
Kojto | 169:e3b6fe271b81 | 37 | RTWInterface(bool debug=false); |
AnnaBridge | 167:e84263d55307 | 38 | ~RTWInterface(); |
AnnaBridge | 167:e84263d55307 | 39 | |
AnnaBridge | 167:e84263d55307 | 40 | /** Set a static IP address |
AnnaBridge | 167:e84263d55307 | 41 | * |
AnnaBridge | 167:e84263d55307 | 42 | * Configures this network interface to use a static IP address. |
AnnaBridge | 167:e84263d55307 | 43 | * Implicitly disables DHCP, which can be enabled in set_dhcp. |
AnnaBridge | 167:e84263d55307 | 44 | * Requires that the network is disconnected. |
AnnaBridge | 167:e84263d55307 | 45 | * |
AnnaBridge | 167:e84263d55307 | 46 | * @param address Null-terminated representation of the local IP address |
AnnaBridge | 167:e84263d55307 | 47 | * @param netmask Null-terminated representation of the local network mask |
AnnaBridge | 167:e84263d55307 | 48 | * @param gateway Null-terminated representation of the local gateway |
AnnaBridge | 167:e84263d55307 | 49 | * @return 0 on success, negative error code on failure |
AnnaBridge | 167:e84263d55307 | 50 | */ |
AnnaBridge | 167:e84263d55307 | 51 | virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway); |
AnnaBridge | 167:e84263d55307 | 52 | |
AnnaBridge | 167:e84263d55307 | 53 | /** Enable or disable DHCP on the network |
AnnaBridge | 167:e84263d55307 | 54 | * |
AnnaBridge | 167:e84263d55307 | 55 | * Requires that the network is disconnected |
AnnaBridge | 167:e84263d55307 | 56 | * |
AnnaBridge | 167:e84263d55307 | 57 | * @param dhcp False to disable dhcp (defaults to enabled) |
AnnaBridge | 167:e84263d55307 | 58 | * @return 0 on success, negative error code on failure |
AnnaBridge | 167:e84263d55307 | 59 | */ |
AnnaBridge | 167:e84263d55307 | 60 | virtual nsapi_error_t set_dhcp(bool dhcp); |
AnnaBridge | 167:e84263d55307 | 61 | |
AnnaBridge | 167:e84263d55307 | 62 | /** Set the WiFi network credentials |
AnnaBridge | 167:e84263d55307 | 63 | * |
AnnaBridge | 167:e84263d55307 | 64 | * @param ssid Name of the network to connect to |
AnnaBridge | 167:e84263d55307 | 65 | * @param pass Security passphrase to connect to the network |
AnnaBridge | 167:e84263d55307 | 66 | * @param security Type of encryption for connection |
AnnaBridge | 167:e84263d55307 | 67 | * (defaults to NSAPI_SECURITY_NONE) |
AnnaBridge | 167:e84263d55307 | 68 | * @return 0 on success, or error code on failure |
AnnaBridge | 167:e84263d55307 | 69 | */ |
AnnaBridge | 167:e84263d55307 | 70 | virtual nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE); |
AnnaBridge | 167:e84263d55307 | 71 | |
AnnaBridge | 167:e84263d55307 | 72 | /** Start the interface |
AnnaBridge | 167:e84263d55307 | 73 | * |
AnnaBridge | 167:e84263d55307 | 74 | * Attempts to connect to a WiFi network. |
AnnaBridge | 167:e84263d55307 | 75 | * |
AnnaBridge | 167:e84263d55307 | 76 | * @param ssid Name of the network to connect to |
AnnaBridge | 167:e84263d55307 | 77 | * @param pass Security passphrase to connect to the network |
AnnaBridge | 167:e84263d55307 | 78 | * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE) |
AnnaBridge | 167:e84263d55307 | 79 | * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) |
AnnaBridge | 167:e84263d55307 | 80 | * @return 0 on success, or error code on failure |
AnnaBridge | 167:e84263d55307 | 81 | */ |
AnnaBridge | 167:e84263d55307 | 82 | virtual nsapi_error_t connect(const char *ssid, const char *pass, |
AnnaBridge | 167:e84263d55307 | 83 | nsapi_security_t security = NSAPI_SECURITY_NONE, |
AnnaBridge | 167:e84263d55307 | 84 | uint8_t channel = 0); |
AnnaBridge | 167:e84263d55307 | 85 | |
AnnaBridge | 167:e84263d55307 | 86 | /** Start the interface |
AnnaBridge | 167:e84263d55307 | 87 | * @return 0 on success, negative on failure |
AnnaBridge | 167:e84263d55307 | 88 | */ |
AnnaBridge | 167:e84263d55307 | 89 | virtual nsapi_error_t connect(); |
AnnaBridge | 167:e84263d55307 | 90 | |
AnnaBridge | 167:e84263d55307 | 91 | /** Stop the interface |
AnnaBridge | 167:e84263d55307 | 92 | * @return 0 on success, negative on failure |
AnnaBridge | 167:e84263d55307 | 93 | */ |
AnnaBridge | 167:e84263d55307 | 94 | virtual nsapi_error_t disconnect(); |
AnnaBridge | 167:e84263d55307 | 95 | virtual int is_connected(); |
AnnaBridge | 167:e84263d55307 | 96 | |
AnnaBridge | 167:e84263d55307 | 97 | /** Scan for available networks |
AnnaBridge | 167:e84263d55307 | 98 | * |
AnnaBridge | 167:e84263d55307 | 99 | * The scan will |
AnnaBridge | 167:e84263d55307 | 100 | * If the network interface is set to non-blocking mode, scan will attempt to scan |
AnnaBridge | 167:e84263d55307 | 101 | * for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback |
AnnaBridge | 167:e84263d55307 | 102 | * is attached, the callback will be called when the operation has completed. |
AnnaBridge | 167:e84263d55307 | 103 | * @param ap Pointer to allocated array to store discovered AP |
AnnaBridge | 167:e84263d55307 | 104 | * @param count Size of allocated @a res array, or 0 to only count available AP |
AnnaBridge | 167:e84263d55307 | 105 | * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0) |
AnnaBridge | 167:e84263d55307 | 106 | * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error |
AnnaBridge | 167:e84263d55307 | 107 | * see @a nsapi_error |
AnnaBridge | 167:e84263d55307 | 108 | */ |
AnnaBridge | 167:e84263d55307 | 109 | virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count); |
AnnaBridge | 167:e84263d55307 | 110 | |
AnnaBridge | 167:e84263d55307 | 111 | virtual nsapi_error_t set_channel(uint8_t channel); |
AnnaBridge | 167:e84263d55307 | 112 | virtual int8_t get_rssi(); |
AnnaBridge | 167:e84263d55307 | 113 | |
AnnaBridge | 167:e84263d55307 | 114 | /** Get the local MAC address |
AnnaBridge | 167:e84263d55307 | 115 | * |
AnnaBridge | 167:e84263d55307 | 116 | * Provided MAC address is intended for info or debug purposes and |
AnnaBridge | 167:e84263d55307 | 117 | * may not be provided if the underlying network interface does not |
AnnaBridge | 167:e84263d55307 | 118 | * provide a MAC address |
AnnaBridge | 167:e84263d55307 | 119 | * |
AnnaBridge | 167:e84263d55307 | 120 | * @return Null-terminated representation of the local MAC address |
AnnaBridge | 167:e84263d55307 | 121 | * or null if no MAC address is available |
AnnaBridge | 167:e84263d55307 | 122 | */ |
AnnaBridge | 167:e84263d55307 | 123 | virtual const char *get_mac_address(); |
AnnaBridge | 167:e84263d55307 | 124 | |
AnnaBridge | 167:e84263d55307 | 125 | /** Get the local IP address |
AnnaBridge | 167:e84263d55307 | 126 | * |
AnnaBridge | 167:e84263d55307 | 127 | * @return Null-terminated representation of the local IP address |
AnnaBridge | 167:e84263d55307 | 128 | * or null if no IP address has been recieved |
AnnaBridge | 167:e84263d55307 | 129 | */ |
AnnaBridge | 167:e84263d55307 | 130 | virtual const char *get_ip_address(); |
AnnaBridge | 167:e84263d55307 | 131 | |
AnnaBridge | 167:e84263d55307 | 132 | /** Get the local network mask |
AnnaBridge | 167:e84263d55307 | 133 | * |
AnnaBridge | 167:e84263d55307 | 134 | * @return Null-terminated representation of the local network mask |
AnnaBridge | 167:e84263d55307 | 135 | * or null if no network mask has been recieved |
AnnaBridge | 167:e84263d55307 | 136 | */ |
AnnaBridge | 167:e84263d55307 | 137 | virtual const char *get_netmask(); |
AnnaBridge | 167:e84263d55307 | 138 | |
AnnaBridge | 167:e84263d55307 | 139 | /** Get the local gateways |
AnnaBridge | 167:e84263d55307 | 140 | * |
AnnaBridge | 167:e84263d55307 | 141 | * @return Null-terminated representation of the local gateway |
AnnaBridge | 167:e84263d55307 | 142 | * or null if no network mask has been recieved |
AnnaBridge | 167:e84263d55307 | 143 | */ |
AnnaBridge | 167:e84263d55307 | 144 | virtual const char *get_gateway(); |
AnnaBridge | 167:e84263d55307 | 145 | |
AnnaBridge | 167:e84263d55307 | 146 | protected: |
AnnaBridge | 167:e84263d55307 | 147 | /** Provide access to the underlying stack |
AnnaBridge | 167:e84263d55307 | 148 | * |
AnnaBridge | 167:e84263d55307 | 149 | * @return The underlying network stack |
AnnaBridge | 167:e84263d55307 | 150 | */ |
AnnaBridge | 167:e84263d55307 | 151 | virtual NetworkStack *get_stack(); |
AnnaBridge | 167:e84263d55307 | 152 | |
AnnaBridge | 167:e84263d55307 | 153 | bool _dhcp; |
AnnaBridge | 167:e84263d55307 | 154 | char _ssid[256]; |
AnnaBridge | 167:e84263d55307 | 155 | char _pass[256]; |
AnnaBridge | 167:e84263d55307 | 156 | nsapi_security_t _security; |
AnnaBridge | 167:e84263d55307 | 157 | uint8_t _channel; |
AnnaBridge | 167:e84263d55307 | 158 | char _ip_address[IPADDR_STRLEN_MAX]; |
AnnaBridge | 167:e84263d55307 | 159 | char _netmask[NSAPI_IPv4_SIZE]; |
AnnaBridge | 167:e84263d55307 | 160 | char _gateway[NSAPI_IPv4_SIZE]; |
AnnaBridge | 167:e84263d55307 | 161 | }; |
AnnaBridge | 167:e84263d55307 | 162 | |
AnnaBridge | 167:e84263d55307 | 163 | #endif |