LWIPBP3595Interface library for mbed-os.

Dependents:   LWIPBP3595Interface_STA_for_mbed-os

Fork of LWIPBP3595Interface by Rohm

Committer:
dkato
Date:
Thu Oct 27 09:30:15 2016 +0000
Revision:
3:2ff2514e4fca
Parent:
2:c7e325599570
Child:
4:b49b4b36aaa4
Supports mbed os 5.2.

Who changed what in which revision?

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