[core] Move SSID & passphrase validation to common
This commit is contained in:
@@ -47,6 +47,7 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
|
||||
LT_HEAP_I();
|
||||
|
||||
__wrap_bk_printf_enable();
|
||||
return true;
|
||||
}
|
||||
|
||||
WiFiMode WiFiClass::getMode() {
|
||||
|
||||
@@ -4,15 +4,9 @@
|
||||
|
||||
WiFiStatus
|
||||
WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, const uint8_t *bssid, bool connect) {
|
||||
enableSTA(true);
|
||||
|
||||
if (!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
|
||||
LT_W("SSID not specified or too long");
|
||||
if (!enableSTA(true))
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if (passphrase && strlen(passphrase) > 64) {
|
||||
LT_W("Passphrase too long");
|
||||
if (!validate(ssid, passphrase))
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ void WiFiClass::printDiag(Print &dest) {
|
||||
dest.print("SSID: ");
|
||||
dest.println(SSID());
|
||||
if (isConnected()) {
|
||||
dest.print("Channel: ");
|
||||
dest.println(channel());
|
||||
dest.print("BSSID: ");
|
||||
dest.println(BSSIDstr());
|
||||
dest.print("RSSI: ");
|
||||
@@ -42,5 +44,24 @@ void WiFiClass::printDiag(Print &dest) {
|
||||
}
|
||||
}
|
||||
|
||||
bool WiFiClass::validate(const char *ssid, const char *passphrase) {
|
||||
if (!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
|
||||
LT_W("SSID not specified or too long");
|
||||
return false;
|
||||
}
|
||||
if (passphrase) {
|
||||
uint16_t length = strlen(passphrase);
|
||||
if (length < 8) {
|
||||
LT_W("Passphrase too short (%u)", length);
|
||||
return false;
|
||||
}
|
||||
if (length > 63) {
|
||||
LT_W("Passphrase too long (%u)", length);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
WiFiClass WiFi;
|
||||
WiFiClass *pWiFi = NULL;
|
||||
|
||||
@@ -46,6 +46,7 @@ class WiFiClass {
|
||||
WiFiClass();
|
||||
~WiFiClass();
|
||||
void printDiag(Print &dest);
|
||||
bool validate(const char *ssid, const char *passphrase);
|
||||
|
||||
public: /* WiFiGeneric.cpp */
|
||||
bool mode(WiFiMode mode);
|
||||
|
||||
@@ -9,22 +9,14 @@ typedef struct {
|
||||
|
||||
bool WiFiClass::softAP(const char *ssid, const char *passphrase, int channel, bool ssidHidden, int maxClients) {
|
||||
if (!enableAP(true))
|
||||
return false;
|
||||
return WL_CONNECT_FAILED;
|
||||
if (!validate(ssid, passphrase))
|
||||
return WL_CONNECT_FAILED;
|
||||
|
||||
LT_HEAP_I();
|
||||
|
||||
vTaskDelay(20);
|
||||
|
||||
if (!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
|
||||
LT_W("SSID not specified or too long");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (passphrase && strlen(passphrase) < 8) {
|
||||
LT_W("Passphrase too short");
|
||||
return false;
|
||||
}
|
||||
|
||||
strcpy((char *)ap.ssid.val, ssid);
|
||||
ap.ssid.len = strlen(ssid);
|
||||
ap.channel = channel;
|
||||
|
||||
@@ -6,19 +6,11 @@ WiFiStatus
|
||||
WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, const uint8_t *bssid, bool connect) {
|
||||
if (!enableSTA(true))
|
||||
return WL_CONNECT_FAILED;
|
||||
if (!validate(ssid, passphrase))
|
||||
return WL_CONNECT_FAILED;
|
||||
|
||||
LT_HEAP_I();
|
||||
|
||||
if (!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
|
||||
LT_W("SSID not specified or too long");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if (passphrase && strlen(passphrase) > 64) {
|
||||
LT_W("Passphrase too long");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
memset(wifi.bssid.octet, 0, ETH_ALEN);
|
||||
strcpy((char *)wifi.ssid.val, ssid);
|
||||
wifi.ssid.len = strlen(ssid);
|
||||
|
||||
Reference in New Issue
Block a user