mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +03:00
check for WiFi pass < 8 (not allowed for WPA2)
simplify STA config and allow setting of second DNS server for fallback code style
This commit is contained in:
parent
7edcda4a0f
commit
293e55c690
@ -54,14 +54,18 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r
|
|||||||
* @return equal
|
* @return equal
|
||||||
*/
|
*/
|
||||||
static bool softap_config_equal(const softap_config& lhs, const softap_config& rhs) {
|
static bool softap_config_equal(const softap_config& lhs, const softap_config& rhs) {
|
||||||
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
|
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0) {
|
||||||
return false;
|
return false;
|
||||||
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
|
}
|
||||||
|
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0) {
|
||||||
return false;
|
return false;
|
||||||
if(lhs.channel != rhs.channel)
|
}
|
||||||
|
if(lhs.channel != rhs.channel) {
|
||||||
return false;
|
return false;
|
||||||
if(lhs.ssid_hidden != rhs.ssid_hidden)
|
}
|
||||||
|
if(lhs.ssid_hidden != rhs.ssid_hidden) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +93,8 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(passphrase && strlen(passphrase) > 63) {
|
if(passphrase && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) {
|
||||||
// fail passphrase to long!
|
// fail passphrase to long or short!
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ void ESP8266WiFiGenericClass::onEvent(WiFiEventCb cbEvent) {
|
|||||||
*/
|
*/
|
||||||
void ESP8266WiFiGenericClass::_eventCallback(void* arg) {
|
void ESP8266WiFiGenericClass::_eventCallback(void* arg) {
|
||||||
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);
|
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);
|
||||||
DEBUGV("wifi evt: %d\r\n", event->event);
|
DEBUGV("wifi evt: %d\n", event->event);
|
||||||
|
|
||||||
if(event->event == EVENT_STAMODE_DISCONNECTED) {
|
if(event->event == EVENT_STAMODE_DISCONNECTED) {
|
||||||
WiFiClient::stopAll();
|
WiFiClient::stopAll();
|
||||||
@ -170,7 +170,7 @@ WiFiMode_t ESP8266WiFiGenericClass::getMode() {
|
|||||||
*/
|
*/
|
||||||
bool ESP8266WiFiGenericClass::enableSTA(bool enable) {
|
bool ESP8266WiFiGenericClass::enableSTA(bool enable) {
|
||||||
|
|
||||||
WiFiMode_t currentMode = (WiFiMode_t) wifi_get_opmode();
|
WiFiMode_t currentMode = getMode();
|
||||||
bool isEnabled = ((currentMode & WIFI_STA) != 0);
|
bool isEnabled = ((currentMode & WIFI_STA) != 0);
|
||||||
|
|
||||||
if(isEnabled != enable) {
|
if(isEnabled != enable) {
|
||||||
@ -191,7 +191,7 @@ bool ESP8266WiFiGenericClass::enableSTA(bool enable) {
|
|||||||
*/
|
*/
|
||||||
bool ESP8266WiFiGenericClass::enableAP(bool enable){
|
bool ESP8266WiFiGenericClass::enableAP(bool enable){
|
||||||
|
|
||||||
WiFiMode_t currentMode = (WiFiMode_t) wifi_get_opmode();
|
WiFiMode_t currentMode = getMode();
|
||||||
bool isEnabled = ((currentMode & WIFI_AP) != 0);
|
bool isEnabled = ((currentMode & WIFI_AP) != 0);
|
||||||
|
|
||||||
if(isEnabled != enable) {
|
if(isEnabled != enable) {
|
||||||
|
@ -57,22 +57,23 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
|
|||||||
* @return equal
|
* @return equal
|
||||||
*/
|
*/
|
||||||
static bool sta_config_equal(const station_config& lhs, const station_config& rhs) {
|
static bool sta_config_equal(const station_config& lhs, const station_config& rhs) {
|
||||||
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
|
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
|
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lhs.bssid_set != rhs.bssid_set) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(lhs.bssid_set) {
|
if(lhs.bssid_set) {
|
||||||
if(!rhs.bssid_set)
|
if(memcmp(lhs.bssid, rhs.bssid, 6) != 0) {
|
||||||
return false;
|
|
||||||
|
|
||||||
if(memcmp(lhs.bssid, rhs.bssid, 6) != 0)
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if(rhs.bssid_set)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -183,34 +184,10 @@ wl_status_t ESP8266WiFiSTAClass::begin() {
|
|||||||
* @param local_ip Static ip configuration
|
* @param local_ip Static ip configuration
|
||||||
* @param gateway Static gateway configuration
|
* @param gateway Static gateway configuration
|
||||||
* @param subnet Static Subnet mask
|
* @param subnet Static Subnet mask
|
||||||
|
* @param dns1 Static DNS server 1
|
||||||
|
* @param dns2 Static DNS server 2
|
||||||
*/
|
*/
|
||||||
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
|
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) {
|
||||||
|
|
||||||
if(!WiFi.enableSTA(true)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ip_info info;
|
|
||||||
info.ip.addr = static_cast<uint32_t>(local_ip);
|
|
||||||
info.gw.addr = static_cast<uint32_t>(gateway);
|
|
||||||
info.netmask.addr = static_cast<uint32_t>(subnet);
|
|
||||||
|
|
||||||
wifi_station_dhcpc_stop();
|
|
||||||
if(wifi_set_ip_info(STATION_IF, &info)) {
|
|
||||||
_useStaticIp = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change IP configuration settings disabling the dhcp client
|
|
||||||
* @param local_ip Static ip configuration
|
|
||||||
* @param gateway Static gateway configuration
|
|
||||||
* @param subnet Static Subnet mask
|
|
||||||
* @param dns Static DNS server
|
|
||||||
*/
|
|
||||||
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns) {
|
|
||||||
|
|
||||||
if(!WiFi.enableSTA(true)) {
|
if(!WiFi.enableSTA(true)) {
|
||||||
return false;
|
return false;
|
||||||
@ -227,11 +204,19 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set DNS-Server
|
|
||||||
ip_addr_t d;
|
ip_addr_t d;
|
||||||
d.addr = static_cast<uint32_t>(dns);
|
|
||||||
|
if(dns1 != (uint32_t)0x00000000) {
|
||||||
|
// Set DNS1-Server
|
||||||
|
d.addr = static_cast<uint32_t>(dns1);
|
||||||
dns_setserver(0, &d);
|
dns_setserver(0, &d);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dns2 != (uint32_t)0x00000000) {
|
||||||
|
// Set DNS2-Server
|
||||||
|
d.addr = static_cast<uint32_t>(dns2);
|
||||||
|
dns_setserver(1, &d);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -617,7 +602,7 @@ void ESP8266WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
|
|||||||
wifi_station_disconnect();
|
wifi_station_disconnect();
|
||||||
wifi_station_connect();
|
wifi_station_connect();
|
||||||
|
|
||||||
WiFi._smartConfigDone = true;
|
_smartConfigDone = true;
|
||||||
} else if(status == SC_STATUS_LINK_OVER) {
|
} else if(status == SC_STATUS_LINK_OVER) {
|
||||||
WiFi.stopSmartConfig();
|
WiFi.stopSmartConfig();
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,7 @@ class ESP8266WiFiSTAClass {
|
|||||||
wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL);
|
wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL);
|
||||||
wl_status_t begin();
|
wl_status_t begin();
|
||||||
|
|
||||||
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
|
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
|
||||||
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns);
|
|
||||||
|
|
||||||
bool reconnect();
|
bool reconnect();
|
||||||
bool disconnect(bool wifioff = false);
|
bool disconnect(bool wifioff = false);
|
||||||
@ -92,6 +91,7 @@ class ESP8266WiFiSTAClass {
|
|||||||
|
|
||||||
static bool _smartConfigStarted;
|
static bool _smartConfigStarted;
|
||||||
static bool _smartConfigDone;
|
static bool _smartConfigDone;
|
||||||
|
|
||||||
static void _smartConfigCallback(uint32_t status, void* result);
|
static void _smartConfigCallback(uint32_t status, void* result);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -314,7 +314,6 @@ void ESP8266WiFiScanClass::_scanDone(void* result, int status) {
|
|||||||
* @return bss_info *
|
* @return bss_info *
|
||||||
*/
|
*/
|
||||||
void * ESP8266WiFiScanClass::_getScanInfoByIndex(int i) {
|
void * ESP8266WiFiScanClass::_getScanInfoByIndex(int i) {
|
||||||
//TODO why its void * and not bss_info * ?
|
|
||||||
if(!ESP8266WiFiScanClass::_scanResult || (size_t) i > ESP8266WiFiScanClass::_scanCount) {
|
if(!ESP8266WiFiScanClass::_scanResult || (size_t) i > ESP8266WiFiScanClass::_scanCount) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user