LWIPBP3595Interface library for mbed-os.
Dependents: LWIPBP3595Interface_STA_for_mbed-os
Fork of LWIPBP3595Interface by
LWIPBP3595Interface.h
00001 /* LWIP implementation of NetworkInterfaceAPI 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef LWIPBP3595_INTERFACE_H 00018 #define LWIPBP3595_INTERFACE_H 00019 00020 #include "nsapi.h" 00021 #include "rtos.h" 00022 #include "lwip/netif.h" 00023 00024 // Forward declaration 00025 class NetworkStack; 00026 00027 00028 /** EthernetInterface class 00029 * Implementation of the NetworkStack for LWIP 00030 */ 00031 class LWIPBP3595Interface : public WiFiInterface 00032 { 00033 public: 00034 /** LWIPBP3595Interface lifetime 00035 */ 00036 LWIPBP3595Interface(); 00037 00038 /** Set a static IP address 00039 * 00040 * Configures this network interface to use a static IP address. 00041 * Implicitly disables DHCP, which can be enabled in set_dhcp. 00042 * Requires that the network is disconnected. 00043 * 00044 * @param address Null-terminated representation of the local IP address 00045 * @param netmask Null-terminated representation of the local network mask 00046 * @param gateway Null-terminated representation of the local gateway 00047 * @return 0 on success, negative error code on failure 00048 */ 00049 virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway); 00050 00051 /** Enable or disable DHCP on the network 00052 * 00053 * Requires that the network is disconnected 00054 * 00055 * @param dhcp False to disable dhcp (defaults to enabled) 00056 * @return 0 on success, negative error code on failure 00057 */ 00058 virtual nsapi_error_t set_dhcp(bool dhcp); 00059 00060 /** Set the WiFi network credentials 00061 * 00062 * @param ssid Name of the network to connect to 00063 * @param pass Security passphrase to connect to the network 00064 * @param security Type of encryption for connection 00065 * (defaults to NSAPI_SECURITY_NONE) 00066 * @return 0 on success, or error code on failure 00067 */ 00068 virtual nsapi_error_t set_credentials(const char *ssid, const char *pass, 00069 nsapi_security_t security = NSAPI_SECURITY_WPA_WPA2); 00070 00071 /** Set the WiFi network channel 00072 * 00073 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) 00074 * @return 0 on success, or error code on failure 00075 */ 00076 virtual nsapi_error_t set_channel(uint8_t channel); 00077 00078 /** Gets the current radio signal strength for active connection 00079 * 00080 * @return Connection strength in dBm (negative value), 00081 * or 0 if measurement impossible 00082 */ 00083 virtual int8_t get_rssi(); 00084 00085 /** Start the interface 00086 * 00087 * Attempts to connect to a WiFi network. 00088 * 00089 * @param ssid Name of the network to connect to 00090 * @param pass Security passphrase to connect to the network 00091 * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE) 00092 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) 00093 * @return 0 on success, or error code on failure 00094 */ 00095 virtual nsapi_error_t connect(const char *ssid, const char *pass, 00096 nsapi_security_t security = NSAPI_SECURITY_WPA2, uint8_t channel = 0); 00097 00098 /** Start the interface 00099 * 00100 * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set. 00101 * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned. 00102 * 00103 * @return 0 on success, negative error code on failure 00104 */ 00105 virtual nsapi_error_t connect(); 00106 00107 /** Stop the interface 00108 * @return 0 on success, negative on failure 00109 */ 00110 virtual nsapi_error_t disconnect(); 00111 00112 /** Scan for available networks 00113 * 00114 * This function will block. If the @a count is 0, function will only return count of available networks, so that 00115 * user can allocated necessary memory. If the @count is grater than 0 and the @a ap is not NULL it'll be populated 00116 * with discovered networks up to value of @a count. 00117 * 00118 * @param ap Pointer to allocated array to store discovered AP 00119 * @param count Size of allocated @a res array, or 0 to only count available AP 00120 * @return Number of entries in @a, or if @a count was 0 number of available networks, 00121 * negative on error see @a nsapi_error 00122 */ 00123 virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count); 00124 00125 /** Get the local MAC address 00126 * 00127 * Provided MAC address is intended for info or debug purposes and 00128 * may not be provided if the underlying network interface does not 00129 * provide a MAC address 00130 * 00131 * @return Null-terminated representation of the local MAC address 00132 * or null if no MAC address is available 00133 */ 00134 virtual const char *get_mac_address(); 00135 00136 /** Get the local IP address 00137 * 00138 * @return Null-terminated representation of the local IP address 00139 * or null if no IP address has been recieved 00140 */ 00141 virtual const char *get_ip_address(); 00142 00143 /** Get the local network mask 00144 * 00145 * @return Null-terminated representation of the local network mask 00146 * or null if no network mask has been recieved 00147 */ 00148 virtual const char *get_netmask(); 00149 00150 /** Get the local gateways 00151 * 00152 * @return Null-terminated representation of the local gateway 00153 * or null if no network mask has been recieved 00154 */ 00155 virtual const char *get_gateway(); 00156 00157 protected: 00158 /** Provide access to the underlying stack 00159 * 00160 * @return The underlying network stack 00161 */ 00162 virtual NetworkStack *get_stack(); 00163 00164 bool _dhcp; 00165 char _ip_address[IPADDR_STRLEN_MAX]; 00166 char _netmask[NSAPI_IPv4_SIZE]; 00167 char _gateway[NSAPI_IPv4_SIZE]; 00168 00169 private: 00170 char _ssid[33]; 00171 char _pass[64]; 00172 nsapi_security_t _security; 00173 }; 00174 00175 00176 #endif
Generated on Fri Jul 15 2022 11:35:20 by 1.7.2