LWIPBP3595Interface library for mbed-os.

Dependents:   LWIPBP3595Interface_STA_for_mbed-os

Fork of LWIPBP3595Interface by Rohm

Committer:
dkato
Date:
Fri Oct 28 06:27:14 2016 +0000
Revision:
4:b49b4b36aaa4
Parent:
3:2ff2514e4fca
Child:
5:d03489ec5033
Support the API set_channel(), get_rssi(), and scan().

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 /** Set a static IP address
dkato 3:2ff2514e4fca 39 *
dkato 3:2ff2514e4fca 40 * Configures this network interface to use a static IP address.
dkato 3:2ff2514e4fca 41 * Implicitly disables DHCP, which can be enabled in set_dhcp.
dkato 3:2ff2514e4fca 42 * Requires that the network is disconnected.
dkato 2:c7e325599570 43 *
dkato 3:2ff2514e4fca 44 * @param address Null-terminated representation of the local IP address
dkato 3:2ff2514e4fca 45 * @param netmask Null-terminated representation of the local network mask
dkato 3:2ff2514e4fca 46 * @param gateway Null-terminated representation of the local gateway
dkato 3:2ff2514e4fca 47 * @return 0 on success, negative error code on failure
dkato 3:2ff2514e4fca 48 */
dkato 3:2ff2514e4fca 49 virtual int set_network(const char *ip_address, const char *netmask, const char *gateway);
dkato 3:2ff2514e4fca 50
dkato 3:2ff2514e4fca 51 /** Enable or disable DHCP on the network
dkato 3:2ff2514e4fca 52 *
dkato 3:2ff2514e4fca 53 * Requires that the network is disconnected
dkato 3:2ff2514e4fca 54 *
dkato 3:2ff2514e4fca 55 * @param dhcp False to disable dhcp (defaults to enabled)
dkato 3:2ff2514e4fca 56 * @return 0 on success, negative error code on failure
dkato 3:2ff2514e4fca 57 */
dkato 3:2ff2514e4fca 58 virtual int set_dhcp(bool dhcp);
dkato 3:2ff2514e4fca 59
dkato 3:2ff2514e4fca 60 /** Set the WiFi network credentials
dkato 2:c7e325599570 61 *
dkato 2:c7e325599570 62 * @param ssid Name of the network to connect to
dkato 2:c7e325599570 63 * @param pass Security passphrase to connect to the network
dkato 2:c7e325599570 64 * @param security Type of encryption for connection
dkato 3:2ff2514e4fca 65 * (defaults to NSAPI_SECURITY_NONE)
dkato 3:2ff2514e4fca 66 * @return 0 on success, or error code on failure
dkato 3:2ff2514e4fca 67 */
dkato 4:b49b4b36aaa4 68 virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_WPA_WPA2);
dkato 3:2ff2514e4fca 69
dkato 3:2ff2514e4fca 70 /** Set the WiFi network channel
dkato 3:2ff2514e4fca 71 *
dkato 3:2ff2514e4fca 72 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
dkato 3:2ff2514e4fca 73 * @return 0 on success, or error code on failure
dkato 3:2ff2514e4fca 74 */
dkato 3:2ff2514e4fca 75 virtual int set_channel(uint8_t channel);
dkato 3:2ff2514e4fca 76
dkato 3:2ff2514e4fca 77 /** Gets the current radio signal strength for active connection
dkato 3:2ff2514e4fca 78 *
dkato 3:2ff2514e4fca 79 * @return Connection strength in dBm (negative value),
dkato 3:2ff2514e4fca 80 * or 0 if measurement impossible
dkato 2:c7e325599570 81 */
dkato 3:2ff2514e4fca 82 virtual int8_t get_rssi();
dkato 3:2ff2514e4fca 83
dkato 3:2ff2514e4fca 84 /** Start the interface
dkato 3:2ff2514e4fca 85 *
dkato 3:2ff2514e4fca 86 * Attempts to connect to a WiFi network.
dkato 3:2ff2514e4fca 87 *
dkato 3:2ff2514e4fca 88 * @param ssid Name of the network to connect to
dkato 3:2ff2514e4fca 89 * @param pass Security passphrase to connect to the network
dkato 3:2ff2514e4fca 90 * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
dkato 3:2ff2514e4fca 91 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
dkato 3:2ff2514e4fca 92 * @return 0 on success, or error code on failure
dkato 3:2ff2514e4fca 93 */
dkato 3:2ff2514e4fca 94 virtual int connect(const char *ssid, const char *pass,
dkato 3:2ff2514e4fca 95 nsapi_security_t security = NSAPI_SECURITY_WPA2,
dkato 3:2ff2514e4fca 96 uint8_t channel = 0);
dkato 3:2ff2514e4fca 97
dkato 3:2ff2514e4fca 98 /** Start the interface
dkato 3:2ff2514e4fca 99 *
dkato 3:2ff2514e4fca 100 * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
dkato 3:2ff2514e4fca 101 * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
dkato 3:2ff2514e4fca 102 *
dkato 3:2ff2514e4fca 103 * @return 0 on success, negative error code on failure
dkato 3:2ff2514e4fca 104 */
dkato 3:2ff2514e4fca 105 virtual int connect();
tousaki 0:a933851e5d22 106
dkato 2:c7e325599570 107 /** Stop the interface
dkato 2:c7e325599570 108 * @return 0 on success, negative on failure
tousaki 0:a933851e5d22 109 */
tousaki 0:a933851e5d22 110 virtual int disconnect();
tousaki 0:a933851e5d22 111
dkato 3:2ff2514e4fca 112 /** Scan for available networks
dkato 3:2ff2514e4fca 113 *
dkato 4:b49b4b36aaa4 114 * This function will block.
dkato 3:2ff2514e4fca 115 *
dkato 3:2ff2514e4fca 116 * @param ap Pointer to allocated array to store discovered AP
dkato 3:2ff2514e4fca 117 * @param count Size of allocated @a res array, or 0 to only count available AP
dkato 3:2ff2514e4fca 118 * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
dkato 3:2ff2514e4fca 119 * see @a nsapi_error
dkato 3:2ff2514e4fca 120 */
dkato 3:2ff2514e4fca 121 virtual int scan(WiFiAccessPoint *res, unsigned count);
dkato 3:2ff2514e4fca 122
dkato 3:2ff2514e4fca 123 /** Get the local MAC address
dkato 3:2ff2514e4fca 124 *
dkato 3:2ff2514e4fca 125 * Provided MAC address is intended for info or debug purposes and
dkato 3:2ff2514e4fca 126 * may not be provided if the underlying network interface does not
dkato 3:2ff2514e4fca 127 * provide a MAC address
dkato 3:2ff2514e4fca 128 *
dkato 3:2ff2514e4fca 129 * @return Null-terminated representation of the local MAC address
dkato 3:2ff2514e4fca 130 * or null if no MAC address is available
dkato 3:2ff2514e4fca 131 */
dkato 3:2ff2514e4fca 132 virtual const char *get_mac_address();
dkato 3:2ff2514e4fca 133
dkato 3:2ff2514e4fca 134 /** Get the local IP address
dkato 3:2ff2514e4fca 135 *
dkato 3:2ff2514e4fca 136 * @return Null-terminated representation of the local IP address
dkato 3:2ff2514e4fca 137 * or null if no IP address has been recieved
tousaki 0:a933851e5d22 138 */
tousaki 0:a933851e5d22 139 virtual const char *get_ip_address();
dkato 2:c7e325599570 140
dkato 3:2ff2514e4fca 141 /** Get the local network mask
dkato 3:2ff2514e4fca 142 *
dkato 3:2ff2514e4fca 143 * @return Null-terminated representation of the local network mask
dkato 3:2ff2514e4fca 144 * or null if no network mask has been recieved
tousaki 0:a933851e5d22 145 */
dkato 3:2ff2514e4fca 146 virtual const char *get_netmask();
dkato 3:2ff2514e4fca 147
dkato 3:2ff2514e4fca 148 /** Get the local gateways
dkato 3:2ff2514e4fca 149 *
dkato 3:2ff2514e4fca 150 * @return Null-terminated representation of the local gateway
dkato 3:2ff2514e4fca 151 * or null if no network mask has been recieved
dkato 3:2ff2514e4fca 152 */
dkato 3:2ff2514e4fca 153 virtual const char *get_gateway();
tousaki 0:a933851e5d22 154
dkato 2:c7e325599570 155 protected:
dkato 2:c7e325599570 156 /** Provide access to the underlying stack
dkato 2:c7e325599570 157 *
dkato 2:c7e325599570 158 * @return The underlying network stack
dkato 2:c7e325599570 159 */
dkato 2:c7e325599570 160 virtual NetworkStack *get_stack();
dkato 3:2ff2514e4fca 161
dkato 3:2ff2514e4fca 162 bool _dhcp;
dkato 3:2ff2514e4fca 163 char _ip_address[IPADDR_STRLEN_MAX];
dkato 3:2ff2514e4fca 164 char _netmask[NSAPI_IPv4_SIZE];
dkato 3:2ff2514e4fca 165 char _gateway[NSAPI_IPv4_SIZE];
dkato 3:2ff2514e4fca 166
dkato 3:2ff2514e4fca 167 private:
dkato 4:b49b4b36aaa4 168 char _ssid[33];
dkato 4:b49b4b36aaa4 169 char _pass[64];
dkato 3:2ff2514e4fca 170 nsapi_security_t _security;
tousaki 0:a933851e5d22 171 };
tousaki 0:a933851e5d22 172
tousaki 0:a933851e5d22 173
tousaki 0:a933851e5d22 174 #endif