test

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Nov 08 13:50:44 2017 +0000
Revision:
178:d650f5d4c87a
Parent:
170:e3b6fe271b81
This updates the lib to the mbed lib v 155

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 168:e84263d55307 1 /* Ameba implementation of NetworkInterfaceAPI
AnnaBridge 168:e84263d55307 2 * Copyright (c) 2015 ARM Limited
AnnaBridge 168:e84263d55307 3 *
AnnaBridge 168:e84263d55307 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 168:e84263d55307 5 * you may not use this file except in compliance with the License.
AnnaBridge 168:e84263d55307 6 * You may obtain a copy of the License at
AnnaBridge 168:e84263d55307 7 *
AnnaBridge 168:e84263d55307 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 168:e84263d55307 9 *
AnnaBridge 168:e84263d55307 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 168:e84263d55307 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 168:e84263d55307 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 168:e84263d55307 13 * See the License for the specific language governing permissions and
AnnaBridge 168:e84263d55307 14 * limitations under the License.
AnnaBridge 168:e84263d55307 15 */
AnnaBridge 168:e84263d55307 16
AnnaBridge 168:e84263d55307 17 #ifndef RTW_INTERFACE_H
AnnaBridge 168:e84263d55307 18 #define RTW_INTERFACE_H
AnnaBridge 168:e84263d55307 19
AnnaBridge 168:e84263d55307 20 #include "netsocket/NetworkInterface.h"
AnnaBridge 168:e84263d55307 21 #include "netsocket/WiFiInterface.h"
AnnaBridge 168:e84263d55307 22 #include "nsapi.h"
AnnaBridge 168:e84263d55307 23 #include "rtos.h"
AnnaBridge 168:e84263d55307 24 #include "lwip/netif.h"
AnnaBridge 168:e84263d55307 25
AnnaBridge 168:e84263d55307 26 // Forward declaration
AnnaBridge 168:e84263d55307 27 class NetworkStack;
AnnaBridge 168:e84263d55307 28
AnnaBridge 168:e84263d55307 29 /** Realtek Wlan (RTW) interface class
AnnaBridge 168:e84263d55307 30 * Implementation of the NetworkStack for Ameba
AnnaBridge 168:e84263d55307 31 */
AnnaBridge 168:e84263d55307 32 class RTWInterface: public WiFiInterface
AnnaBridge 168:e84263d55307 33 {
AnnaBridge 168:e84263d55307 34 public:
AnnaBridge 168:e84263d55307 35 /** RTWWlanInterface lifetime
AnnaBridge 168:e84263d55307 36 */
Kojto 170:e3b6fe271b81 37 RTWInterface(bool debug=false);
AnnaBridge 168:e84263d55307 38 ~RTWInterface();
AnnaBridge 168:e84263d55307 39
AnnaBridge 168:e84263d55307 40 /** Set a static IP address
AnnaBridge 168:e84263d55307 41 *
AnnaBridge 168:e84263d55307 42 * Configures this network interface to use a static IP address.
AnnaBridge 168:e84263d55307 43 * Implicitly disables DHCP, which can be enabled in set_dhcp.
AnnaBridge 168:e84263d55307 44 * Requires that the network is disconnected.
AnnaBridge 168:e84263d55307 45 *
AnnaBridge 168:e84263d55307 46 * @param address Null-terminated representation of the local IP address
AnnaBridge 168:e84263d55307 47 * @param netmask Null-terminated representation of the local network mask
AnnaBridge 168:e84263d55307 48 * @param gateway Null-terminated representation of the local gateway
AnnaBridge 168:e84263d55307 49 * @return 0 on success, negative error code on failure
AnnaBridge 168:e84263d55307 50 */
AnnaBridge 168:e84263d55307 51 virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
AnnaBridge 168:e84263d55307 52
AnnaBridge 168:e84263d55307 53 /** Enable or disable DHCP on the network
AnnaBridge 168:e84263d55307 54 *
AnnaBridge 168:e84263d55307 55 * Requires that the network is disconnected
AnnaBridge 168:e84263d55307 56 *
AnnaBridge 168:e84263d55307 57 * @param dhcp False to disable dhcp (defaults to enabled)
AnnaBridge 168:e84263d55307 58 * @return 0 on success, negative error code on failure
AnnaBridge 168:e84263d55307 59 */
AnnaBridge 168:e84263d55307 60 virtual nsapi_error_t set_dhcp(bool dhcp);
AnnaBridge 168:e84263d55307 61
AnnaBridge 168:e84263d55307 62 /** Set the WiFi network credentials
AnnaBridge 168:e84263d55307 63 *
AnnaBridge 168:e84263d55307 64 * @param ssid Name of the network to connect to
AnnaBridge 168:e84263d55307 65 * @param pass Security passphrase to connect to the network
AnnaBridge 168:e84263d55307 66 * @param security Type of encryption for connection
AnnaBridge 168:e84263d55307 67 * (defaults to NSAPI_SECURITY_NONE)
AnnaBridge 168:e84263d55307 68 * @return 0 on success, or error code on failure
AnnaBridge 168:e84263d55307 69 */
AnnaBridge 168:e84263d55307 70 virtual nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
AnnaBridge 168:e84263d55307 71
AnnaBridge 168:e84263d55307 72 /** Start the interface
AnnaBridge 168:e84263d55307 73 *
AnnaBridge 168:e84263d55307 74 * Attempts to connect to a WiFi network.
AnnaBridge 168:e84263d55307 75 *
AnnaBridge 168:e84263d55307 76 * @param ssid Name of the network to connect to
AnnaBridge 168:e84263d55307 77 * @param pass Security passphrase to connect to the network
AnnaBridge 168:e84263d55307 78 * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
AnnaBridge 168:e84263d55307 79 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
AnnaBridge 168:e84263d55307 80 * @return 0 on success, or error code on failure
AnnaBridge 168:e84263d55307 81 */
AnnaBridge 168:e84263d55307 82 virtual nsapi_error_t connect(const char *ssid, const char *pass,
AnnaBridge 168:e84263d55307 83 nsapi_security_t security = NSAPI_SECURITY_NONE,
AnnaBridge 168:e84263d55307 84 uint8_t channel = 0);
AnnaBridge 168:e84263d55307 85
AnnaBridge 168:e84263d55307 86 /** Start the interface
AnnaBridge 168:e84263d55307 87 * @return 0 on success, negative on failure
AnnaBridge 168:e84263d55307 88 */
AnnaBridge 168:e84263d55307 89 virtual nsapi_error_t connect();
AnnaBridge 168:e84263d55307 90
AnnaBridge 168:e84263d55307 91 /** Stop the interface
AnnaBridge 168:e84263d55307 92 * @return 0 on success, negative on failure
AnnaBridge 168:e84263d55307 93 */
AnnaBridge 168:e84263d55307 94 virtual nsapi_error_t disconnect();
AnnaBridge 168:e84263d55307 95 virtual int is_connected();
AnnaBridge 168:e84263d55307 96
AnnaBridge 168:e84263d55307 97 /** Scan for available networks
AnnaBridge 168:e84263d55307 98 *
AnnaBridge 168:e84263d55307 99 * The scan will
AnnaBridge 168:e84263d55307 100 * If the network interface is set to non-blocking mode, scan will attempt to scan
AnnaBridge 168:e84263d55307 101 * for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
AnnaBridge 168:e84263d55307 102 * is attached, the callback will be called when the operation has completed.
AnnaBridge 168:e84263d55307 103 * @param ap Pointer to allocated array to store discovered AP
AnnaBridge 168:e84263d55307 104 * @param count Size of allocated @a res array, or 0 to only count available AP
AnnaBridge 168:e84263d55307 105 * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
AnnaBridge 168:e84263d55307 106 * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
AnnaBridge 168:e84263d55307 107 * see @a nsapi_error
AnnaBridge 168:e84263d55307 108 */
AnnaBridge 168:e84263d55307 109 virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count);
AnnaBridge 168:e84263d55307 110
AnnaBridge 168:e84263d55307 111 virtual nsapi_error_t set_channel(uint8_t channel);
AnnaBridge 168:e84263d55307 112 virtual int8_t get_rssi();
AnnaBridge 168:e84263d55307 113
AnnaBridge 168:e84263d55307 114 /** Get the local MAC address
AnnaBridge 168:e84263d55307 115 *
AnnaBridge 168:e84263d55307 116 * Provided MAC address is intended for info or debug purposes and
AnnaBridge 168:e84263d55307 117 * may not be provided if the underlying network interface does not
AnnaBridge 168:e84263d55307 118 * provide a MAC address
AnnaBridge 168:e84263d55307 119 *
AnnaBridge 168:e84263d55307 120 * @return Null-terminated representation of the local MAC address
AnnaBridge 168:e84263d55307 121 * or null if no MAC address is available
AnnaBridge 168:e84263d55307 122 */
AnnaBridge 168:e84263d55307 123 virtual const char *get_mac_address();
AnnaBridge 168:e84263d55307 124
AnnaBridge 168:e84263d55307 125 /** Get the local IP address
AnnaBridge 168:e84263d55307 126 *
AnnaBridge 168:e84263d55307 127 * @return Null-terminated representation of the local IP address
AnnaBridge 168:e84263d55307 128 * or null if no IP address has been recieved
AnnaBridge 168:e84263d55307 129 */
AnnaBridge 168:e84263d55307 130 virtual const char *get_ip_address();
AnnaBridge 168:e84263d55307 131
AnnaBridge 168:e84263d55307 132 /** Get the local network mask
AnnaBridge 168:e84263d55307 133 *
AnnaBridge 168:e84263d55307 134 * @return Null-terminated representation of the local network mask
AnnaBridge 168:e84263d55307 135 * or null if no network mask has been recieved
AnnaBridge 168:e84263d55307 136 */
AnnaBridge 168:e84263d55307 137 virtual const char *get_netmask();
AnnaBridge 168:e84263d55307 138
AnnaBridge 168:e84263d55307 139 /** Get the local gateways
AnnaBridge 168:e84263d55307 140 *
AnnaBridge 168:e84263d55307 141 * @return Null-terminated representation of the local gateway
AnnaBridge 168:e84263d55307 142 * or null if no network mask has been recieved
AnnaBridge 168:e84263d55307 143 */
AnnaBridge 168:e84263d55307 144 virtual const char *get_gateway();
AnnaBridge 168:e84263d55307 145
AnnaBridge 168:e84263d55307 146 protected:
AnnaBridge 168:e84263d55307 147 /** Provide access to the underlying stack
AnnaBridge 168:e84263d55307 148 *
AnnaBridge 168:e84263d55307 149 * @return The underlying network stack
AnnaBridge 168:e84263d55307 150 */
AnnaBridge 168:e84263d55307 151 virtual NetworkStack *get_stack();
AnnaBridge 168:e84263d55307 152
AnnaBridge 168:e84263d55307 153 bool _dhcp;
AnnaBridge 168:e84263d55307 154 char _ssid[256];
AnnaBridge 168:e84263d55307 155 char _pass[256];
AnnaBridge 168:e84263d55307 156 nsapi_security_t _security;
AnnaBridge 168:e84263d55307 157 uint8_t _channel;
AnnaBridge 168:e84263d55307 158 char _ip_address[IPADDR_STRLEN_MAX];
AnnaBridge 168:e84263d55307 159 char _netmask[NSAPI_IPv4_SIZE];
AnnaBridge 168:e84263d55307 160 char _gateway[NSAPI_IPv4_SIZE];
AnnaBridge 168:e84263d55307 161 };
AnnaBridge 168:e84263d55307 162
AnnaBridge 168:e84263d55307 163 #endif