|
|
@@ -91,11 +91,8 @@ struct wifi_prov_mgr_ctx {
|
|
|
/* Type of security to use with protocomm */
|
|
|
int security;
|
|
|
|
|
|
- /* Pointer to proof of possession */
|
|
|
- protocomm_security_pop_t pop;
|
|
|
-
|
|
|
- /* Pointer to salt and verifier */
|
|
|
- protocomm_security_sv_t sv;
|
|
|
+ /* Pointer to security params */
|
|
|
+ const void* protocomm_sec_params;
|
|
|
|
|
|
/* Handle for Provisioning Auto Stop timer */
|
|
|
esp_timer_handle_t autostop_timer;
|
|
|
@@ -311,13 +308,13 @@ static esp_err_t wifi_prov_mgr_start_service(const char *service_name, const cha
|
|
|
/* Set protocomm security type for endpoint */
|
|
|
if (prov_ctx->security == 0) {
|
|
|
ret = protocomm_set_security(prov_ctx->pc, "prov-session",
|
|
|
- &protocomm_security0, NULL, NULL);
|
|
|
+ &protocomm_security0, NULL);
|
|
|
} else if (prov_ctx->security == 1) {
|
|
|
ret = protocomm_set_security(prov_ctx->pc, "prov-session",
|
|
|
- &protocomm_security1, &prov_ctx->pop, NULL);
|
|
|
+ &protocomm_security1, prov_ctx->protocomm_sec_params);
|
|
|
} else if (prov_ctx->security == 2) {
|
|
|
ret = protocomm_set_security(prov_ctx->pc, "prov-session",
|
|
|
- &protocomm_security2, NULL, &prov_ctx->sv);
|
|
|
+ &protocomm_security2, prov_ctx->protocomm_sec_params);
|
|
|
} else {
|
|
|
ESP_LOGE(TAG, "Unsupported protocomm security version %d", prov_ctx->security);
|
|
|
ret = ESP_ERR_INVALID_ARG;
|
|
|
@@ -587,9 +584,8 @@ static bool wifi_prov_mgr_stop_service(bool blocking)
|
|
|
prov_ctx->prov_state = WIFI_PROV_STATE_STOPPING;
|
|
|
|
|
|
/* Free proof of possession */
|
|
|
- if (prov_ctx->pop.data) {
|
|
|
- free((void *)prov_ctx->pop.data);
|
|
|
- prov_ctx->pop.data = NULL;
|
|
|
+ if (prov_ctx->protocomm_sec_params) {
|
|
|
+ prov_ctx->protocomm_sec_params = NULL;
|
|
|
}
|
|
|
|
|
|
/* Delete all scan results */
|
|
|
@@ -1392,8 +1388,8 @@ void wifi_prov_mgr_deinit(void)
|
|
|
vSemaphoreDelete(prov_ctx_lock);
|
|
|
}
|
|
|
|
|
|
-esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const char *pop, const char *salt,
|
|
|
- const char *verifier, const char *service_name, const char *service_key)
|
|
|
+esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const void *wifi_prov_sec_params,
|
|
|
+ const char *service_name, const char *service_key)
|
|
|
{
|
|
|
uint8_t restore_wifi_flag = 0;
|
|
|
|
|
|
@@ -1470,35 +1466,14 @@ esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const
|
|
|
if (security == WIFI_PROV_SECURITY_0) {
|
|
|
prov_ctx->mgr_info.capabilities.no_sec = true;
|
|
|
} else if (security == WIFI_PROV_SECURITY_1) {
|
|
|
- if (pop) {
|
|
|
- prov_ctx->pop.len = strlen(pop);
|
|
|
- prov_ctx->pop.data = malloc(prov_ctx->pop.len);
|
|
|
- if (!prov_ctx->pop.data) {
|
|
|
- ESP_LOGE(TAG, "Unable to allocate PoP data");
|
|
|
- ret = ESP_ERR_NO_MEM;
|
|
|
- goto err;
|
|
|
- }
|
|
|
- memcpy((void *)prov_ctx->pop.data, pop, prov_ctx->pop.len);
|
|
|
+ if (wifi_prov_sec_params) {
|
|
|
+ prov_ctx->protocomm_sec_params = wifi_prov_sec_params;
|
|
|
} else {
|
|
|
prov_ctx->mgr_info.capabilities.no_pop = true;
|
|
|
}
|
|
|
} else if (security == WIFI_PROV_SECURITY_2) {
|
|
|
- if (salt != NULL && verifier != NULL) {
|
|
|
- prov_ctx->sv.salt_len = 4;
|
|
|
- prov_ctx->sv.verifier_len = 384;
|
|
|
- prov_ctx->sv.salt = malloc(prov_ctx->sv.salt_len);
|
|
|
- prov_ctx->sv.verifier = malloc(prov_ctx->sv.verifier_len);
|
|
|
- if (!prov_ctx->sv.salt || !prov_ctx->sv.salt) {
|
|
|
- ESP_LOGE(TAG, "Unable to allocate salt-verifier data");
|
|
|
- ret = ESP_ERR_NO_MEM;
|
|
|
- goto err;
|
|
|
- }
|
|
|
- memcpy((void *)prov_ctx->sv.salt, salt, prov_ctx->sv.salt_len);
|
|
|
- memcpy((void *)prov_ctx->sv.verifier, verifier, prov_ctx->sv.verifier_len);
|
|
|
- } else {
|
|
|
- ESP_LOGE(TAG, "Salt and verifier cannot be NULL!");
|
|
|
- ret = ESP_ERR_INVALID_ARG;
|
|
|
- goto err;
|
|
|
+ if (wifi_prov_sec_params) {
|
|
|
+ prov_ctx->protocomm_sec_params = wifi_prov_sec_params;
|
|
|
}
|
|
|
}
|
|
|
prov_ctx->security = security;
|
|
|
@@ -1513,7 +1488,6 @@ esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const
|
|
|
ret = esp_timer_create(&wifi_connect_timer_conf, &prov_ctx->wifi_connect_timer);
|
|
|
if (ret != ESP_OK) {
|
|
|
ESP_LOGE(TAG, "Failed to create Wi-Fi connect timer");
|
|
|
- free((void *)prov_ctx->pop.data);
|
|
|
goto err;
|
|
|
}
|
|
|
|
|
|
@@ -1530,7 +1504,6 @@ esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const
|
|
|
if (ret != ESP_OK) {
|
|
|
ESP_LOGE(TAG, "Failed to create auto-stop timer");
|
|
|
esp_timer_delete(prov_ctx->wifi_connect_timer);
|
|
|
- free((void *)prov_ctx->pop.data);
|
|
|
goto err;
|
|
|
}
|
|
|
}
|
|
|
@@ -1546,7 +1519,6 @@ esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const
|
|
|
if (ret != ESP_OK) {
|
|
|
esp_timer_delete(prov_ctx->autostop_timer);
|
|
|
esp_timer_delete(prov_ctx->wifi_connect_timer);
|
|
|
- free((void *)prov_ctx->pop.data);
|
|
|
}
|
|
|
ACQUIRE_LOCK(prov_ctx_lock);
|
|
|
if (ret == ESP_OK) {
|