Provisioning Examples : Bugfix in copying Wi-Fi SSID and Passphrase
This commit is contained in:
parent
76719b9c37
commit
accef886a9
6 changed files with 36 additions and 20 deletions
|
@ -98,10 +98,14 @@ static esp_err_t set_config_handler(const wifi_prov_config_set_data_t *req_data,
|
||||||
|
|
||||||
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
||||||
req_data->ssid, req_data->password);
|
req_data->ssid, req_data->password);
|
||||||
memcpy((char *) wifi_cfg->sta.ssid, req_data->ssid,
|
|
||||||
strnlen(req_data->ssid, sizeof(wifi_cfg->sta.ssid)));
|
/* Using strncpy allows the max SSID length to be 32 bytes (as per 802.11 standard).
|
||||||
memcpy((char *) wifi_cfg->sta.password, req_data->password,
|
* But this doesn't guarantee that the saved SSID will be null terminated, because
|
||||||
strnlen(req_data->password, sizeof(wifi_cfg->sta.password)));
|
* wifi_cfg->sta.ssid is also 32 bytes long (without extra 1 byte for null character).
|
||||||
|
* Although, this is not a matter for concern because esp_wifi library reads the SSID
|
||||||
|
* upto 32 bytes in absence of null termination */
|
||||||
|
strncpy((char *) wifi_cfg->sta.ssid, req_data->ssid, sizeof(wifi_cfg->sta.ssid));
|
||||||
|
strlcpy((char *) wifi_cfg->sta.password, req_data->password, sizeof(wifi_cfg->sta.password));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,10 +98,14 @@ static esp_err_t set_config_handler(const wifi_prov_config_set_data_t *req_data,
|
||||||
|
|
||||||
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
||||||
req_data->ssid, req_data->password);
|
req_data->ssid, req_data->password);
|
||||||
memcpy((char *) wifi_cfg->sta.ssid, req_data->ssid,
|
|
||||||
strnlen(req_data->ssid, sizeof(wifi_cfg->sta.ssid)));
|
/* Using strncpy allows the max SSID length to be 32 bytes (as per 802.11 standard).
|
||||||
memcpy((char *) wifi_cfg->sta.password, req_data->password,
|
* But this doesn't guarantee that the saved SSID will be null terminated, because
|
||||||
strnlen(req_data->password, sizeof(wifi_cfg->sta.password)));
|
* wifi_cfg->sta.ssid is also 32 bytes long (without extra 1 byte for null character).
|
||||||
|
* Although, this is not a matter for concern because esp_wifi library reads the SSID
|
||||||
|
* upto 32 bytes in absence of null termination */
|
||||||
|
strncpy((char *) wifi_cfg->sta.ssid, req_data->ssid, sizeof(wifi_cfg->sta.ssid));
|
||||||
|
strlcpy((char *) wifi_cfg->sta.password, req_data->password, sizeof(wifi_cfg->sta.password));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,13 +327,13 @@ static esp_err_t start_wifi_ap(const char *ssid, const char *pass)
|
||||||
};
|
};
|
||||||
|
|
||||||
strncpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
strncpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
||||||
wifi_config.ap.ssid_len = strlen(ssid);
|
wifi_config.ap.ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid));
|
||||||
|
|
||||||
if (strlen(pass) == 0) {
|
if (strlen(pass) == 0) {
|
||||||
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
||||||
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
|
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
|
||||||
} else {
|
} else {
|
||||||
strncpy((char *) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
|
strlcpy((char *) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
|
||||||
wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
|
wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,10 +110,14 @@ static esp_err_t set_config_handler(const wifi_prov_config_set_data_t *req_data,
|
||||||
|
|
||||||
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
||||||
req_data->ssid, req_data->password);
|
req_data->ssid, req_data->password);
|
||||||
memcpy((char *) wifi_cfg->sta.ssid, req_data->ssid,
|
|
||||||
strnlen(req_data->ssid, sizeof(wifi_cfg->sta.ssid)));
|
/* Using strncpy allows the max SSID length to be 32 bytes (as per 802.11 standard).
|
||||||
memcpy((char *) wifi_cfg->sta.password, req_data->password,
|
* But this doesn't guarantee that the saved SSID will be null terminated, because
|
||||||
strnlen(req_data->password, sizeof(wifi_cfg->sta.password)));
|
* wifi_cfg->sta.ssid is also 32 bytes long (without extra 1 byte for null character).
|
||||||
|
* Although, this is not a matter for concern because esp_wifi library reads the SSID
|
||||||
|
* upto 32 bytes in absence of null termination */
|
||||||
|
strncpy((char *) wifi_cfg->sta.ssid, req_data->ssid, sizeof(wifi_cfg->sta.ssid));
|
||||||
|
strlcpy((char *) wifi_cfg->sta.password, req_data->password, sizeof(wifi_cfg->sta.password));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -314,13 +314,13 @@ static esp_err_t start_wifi_ap(const char *ssid, const char *pass)
|
||||||
};
|
};
|
||||||
|
|
||||||
strncpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
strncpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
||||||
wifi_config.ap.ssid_len = strlen(ssid);
|
wifi_config.ap.ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid));
|
||||||
|
|
||||||
if (strlen(pass) == 0) {
|
if (strlen(pass) == 0) {
|
||||||
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
||||||
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
|
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
|
||||||
} else {
|
} else {
|
||||||
strncpy((char *) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
|
strlcpy((char *) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
|
||||||
wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
|
wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,10 +98,14 @@ static esp_err_t set_config_handler(const wifi_prov_config_set_data_t *req_data,
|
||||||
|
|
||||||
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
ESP_LOGI(TAG, "WiFi Credentials Received : \n\tssid %s \n\tpassword %s",
|
||||||
req_data->ssid, req_data->password);
|
req_data->ssid, req_data->password);
|
||||||
memcpy((char *) wifi_cfg->sta.ssid, req_data->ssid,
|
|
||||||
strnlen(req_data->ssid, sizeof(wifi_cfg->sta.ssid)));
|
/* Using strncpy allows the max SSID length to be 32 bytes (as per 802.11 standard).
|
||||||
memcpy((char *) wifi_cfg->sta.password, req_data->password,
|
* But this doesn't guarantee that the saved SSID will be null terminated, because
|
||||||
strnlen(req_data->password, sizeof(wifi_cfg->sta.password)));
|
* wifi_cfg->sta.ssid is also 32 bytes long (without extra 1 byte for null character).
|
||||||
|
* Although, this is not a matter for concern because esp_wifi library reads the SSID
|
||||||
|
* upto 32 bytes in absence of null termination */
|
||||||
|
strncpy((char *) wifi_cfg->sta.ssid, req_data->ssid, sizeof(wifi_cfg->sta.ssid));
|
||||||
|
strlcpy((char *) wifi_cfg->sta.password, req_data->password, sizeof(wifi_cfg->sta.password));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue