LWIPBP3595Interface library for mbed-os.
Dependents: LWIPBP3595Interface_STA_for_mbed-os
Fork of LWIPBP3595Interface by
LWIPBP3595Interface.h@6:993197aaf5a4, 2017-03-28 (annotated)
- Committer:
- dkato
- Date:
- Tue Mar 28 09:50:17 2017 +0000
- Revision:
- 6:993197aaf5a4
- Parent:
- 5:d03489ec5033
Fixed static IP address setting.
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:d03489ec5033 | 49 | virtual nsapi_error_t 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 | 5:d03489ec5033 | 58 | virtual nsapi_error_t 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 | 5:d03489ec5033 | 68 | virtual nsapi_error_t set_credentials(const char *ssid, const char *pass, |
dkato | 5:d03489ec5033 | 69 | nsapi_security_t security = NSAPI_SECURITY_WPA_WPA2); |
dkato | 3:2ff2514e4fca | 70 | |
dkato | 3:2ff2514e4fca | 71 | /** Set the WiFi network channel |
dkato | 3:2ff2514e4fca | 72 | * |
dkato | 3:2ff2514e4fca | 73 | * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) |
dkato | 3:2ff2514e4fca | 74 | * @return 0 on success, or error code on failure |
dkato | 3:2ff2514e4fca | 75 | */ |
dkato | 5:d03489ec5033 | 76 | virtual nsapi_error_t set_channel(uint8_t channel); |
dkato | 3:2ff2514e4fca | 77 | |
dkato | 3:2ff2514e4fca | 78 | /** Gets the current radio signal strength for active connection |
dkato | 3:2ff2514e4fca | 79 | * |
dkato | 3:2ff2514e4fca | 80 | * @return Connection strength in dBm (negative value), |
dkato | 3:2ff2514e4fca | 81 | * or 0 if measurement impossible |
dkato | 2:c7e325599570 | 82 | */ |
dkato | 3:2ff2514e4fca | 83 | virtual int8_t get_rssi(); |
dkato | 3:2ff2514e4fca | 84 | |
dkato | 3:2ff2514e4fca | 85 | /** Start the interface |
dkato | 3:2ff2514e4fca | 86 | * |
dkato | 3:2ff2514e4fca | 87 | * Attempts to connect to a WiFi network. |
dkato | 3:2ff2514e4fca | 88 | * |
dkato | 3:2ff2514e4fca | 89 | * @param ssid Name of the network to connect to |
dkato | 3:2ff2514e4fca | 90 | * @param pass Security passphrase to connect to the network |
dkato | 3:2ff2514e4fca | 91 | * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE) |
dkato | 3:2ff2514e4fca | 92 | * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) |
dkato | 3:2ff2514e4fca | 93 | * @return 0 on success, or error code on failure |
dkato | 3:2ff2514e4fca | 94 | */ |
dkato | 5:d03489ec5033 | 95 | virtual nsapi_error_t connect(const char *ssid, const char *pass, |
dkato | 5:d03489ec5033 | 96 | nsapi_security_t security = NSAPI_SECURITY_WPA2, 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 | 5:d03489ec5033 | 105 | virtual nsapi_error_t 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 | */ |
dkato | 5:d03489ec5033 | 110 | virtual nsapi_error_t disconnect(); |
tousaki | 0:a933851e5d22 | 111 | |
dkato | 3:2ff2514e4fca | 112 | /** Scan for available networks |
dkato | 3:2ff2514e4fca | 113 | * |
dkato | 5:d03489ec5033 | 114 | * This function will block. If the @a count is 0, function will only return count of available networks, so that |
dkato | 5:d03489ec5033 | 115 | * user can allocated necessary memory. If the @count is grater than 0 and the @a ap is not NULL it'll be populated |
dkato | 5:d03489ec5033 | 116 | * with discovered networks up to value of @a count. |
dkato | 3:2ff2514e4fca | 117 | * |
dkato | 5:d03489ec5033 | 118 | * @param ap Pointer to allocated array to store discovered AP |
dkato | 5:d03489ec5033 | 119 | * @param count Size of allocated @a res array, or 0 to only count available AP |
dkato | 5:d03489ec5033 | 120 | * @return Number of entries in @a, or if @a count was 0 number of available networks, |
dkato | 5:d03489ec5033 | 121 | * negative on error see @a nsapi_error |
dkato | 3:2ff2514e4fca | 122 | */ |
dkato | 5:d03489ec5033 | 123 | virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count); |
dkato | 3:2ff2514e4fca | 124 | |
dkato | 3:2ff2514e4fca | 125 | /** Get the local MAC address |
dkato | 3:2ff2514e4fca | 126 | * |
dkato | 3:2ff2514e4fca | 127 | * Provided MAC address is intended for info or debug purposes and |
dkato | 3:2ff2514e4fca | 128 | * may not be provided if the underlying network interface does not |
dkato | 3:2ff2514e4fca | 129 | * provide a MAC address |
dkato | 3:2ff2514e4fca | 130 | * |
dkato | 3:2ff2514e4fca | 131 | * @return Null-terminated representation of the local MAC address |
dkato | 3:2ff2514e4fca | 132 | * or null if no MAC address is available |
dkato | 3:2ff2514e4fca | 133 | */ |
dkato | 3:2ff2514e4fca | 134 | virtual const char *get_mac_address(); |
dkato | 3:2ff2514e4fca | 135 | |
dkato | 3:2ff2514e4fca | 136 | /** Get the local IP address |
dkato | 3:2ff2514e4fca | 137 | * |
dkato | 3:2ff2514e4fca | 138 | * @return Null-terminated representation of the local IP address |
dkato | 3:2ff2514e4fca | 139 | * or null if no IP address has been recieved |
tousaki | 0:a933851e5d22 | 140 | */ |
tousaki | 0:a933851e5d22 | 141 | virtual const char *get_ip_address(); |
dkato | 2:c7e325599570 | 142 | |
dkato | 3:2ff2514e4fca | 143 | /** Get the local network mask |
dkato | 3:2ff2514e4fca | 144 | * |
dkato | 3:2ff2514e4fca | 145 | * @return Null-terminated representation of the local network mask |
dkato | 3:2ff2514e4fca | 146 | * or null if no network mask has been recieved |
tousaki | 0:a933851e5d22 | 147 | */ |
dkato | 3:2ff2514e4fca | 148 | virtual const char *get_netmask(); |
dkato | 3:2ff2514e4fca | 149 | |
dkato | 3:2ff2514e4fca | 150 | /** Get the local gateways |
dkato | 3:2ff2514e4fca | 151 | * |
dkato | 3:2ff2514e4fca | 152 | * @return Null-terminated representation of the local gateway |
dkato | 3:2ff2514e4fca | 153 | * or null if no network mask has been recieved |
dkato | 3:2ff2514e4fca | 154 | */ |
dkato | 3:2ff2514e4fca | 155 | virtual const char *get_gateway(); |
tousaki | 0:a933851e5d22 | 156 | |
dkato | 2:c7e325599570 | 157 | protected: |
dkato | 2:c7e325599570 | 158 | /** Provide access to the underlying stack |
dkato | 2:c7e325599570 | 159 | * |
dkato | 2:c7e325599570 | 160 | * @return The underlying network stack |
dkato | 2:c7e325599570 | 161 | */ |
dkato | 2:c7e325599570 | 162 | virtual NetworkStack *get_stack(); |
dkato | 3:2ff2514e4fca | 163 | |
dkato | 3:2ff2514e4fca | 164 | bool _dhcp; |
dkato | 3:2ff2514e4fca | 165 | char _ip_address[IPADDR_STRLEN_MAX]; |
dkato | 3:2ff2514e4fca | 166 | char _netmask[NSAPI_IPv4_SIZE]; |
dkato | 3:2ff2514e4fca | 167 | char _gateway[NSAPI_IPv4_SIZE]; |
dkato | 3:2ff2514e4fca | 168 | |
dkato | 3:2ff2514e4fca | 169 | private: |
dkato | 4:b49b4b36aaa4 | 170 | char _ssid[33]; |
dkato | 4:b49b4b36aaa4 | 171 | char _pass[64]; |
dkato | 3:2ff2514e4fca | 172 | nsapi_security_t _security; |
tousaki | 0:a933851e5d22 | 173 | }; |
tousaki | 0:a933851e5d22 | 174 | |
tousaki | 0:a933851e5d22 | 175 | |
tousaki | 0:a933851e5d22 | 176 | #endif |