mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-10 18:06:29 +00:00
wifi_provisioning: Update the APIs with reference to the new APIs from protocomm
esp_local_ctrl: Update the code with reference to new changes in protocomm component
This commit is contained in:
@@ -201,9 +201,17 @@ typedef enum wifi_prov_security {
|
||||
*/
|
||||
WIFI_PROV_SECURITY_1,
|
||||
|
||||
/**
|
||||
* This secure communication mode consists of
|
||||
* SRP6a based authentication and key exchange
|
||||
* + AES-GCM encryption/decryption
|
||||
*/
|
||||
WIFI_PROV_SECURITY_2
|
||||
} wifi_prov_security_t;
|
||||
|
||||
typedef protocomm_security1_params_t wifi_prov_security1_params_t;
|
||||
typedef protocomm_security2_params_t wifi_prov_security2_params_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize provisioning manager instance
|
||||
*
|
||||
@@ -285,9 +293,14 @@ esp_err_t wifi_prov_mgr_is_provisioned(bool *provisioned);
|
||||
* - WIFI_PROV_SECURITY_0 : For no security
|
||||
* - WIFI_PROV_SECURITY_1 : x25519 secure handshake for session
|
||||
* establishment followed by AES-CTR encryption of provisioning messages
|
||||
* @param[in] pop Pointer to proof of possession string (NULL if not needed). This
|
||||
* is relevant only for protocomm security 1, in which case it is used
|
||||
* for authenticating secure session
|
||||
* - WIFI_PROV_SECURITY_2: SRP6a based authentication and key exchange
|
||||
* followed by AES-GCM encryption/decryption of provisioning messages
|
||||
* @param[in] wifi_prov_sec_params
|
||||
* Pointer to security params (NULL if not needed).
|
||||
* This is not needed for protocomm security 0
|
||||
* This pointer should hold the struct of type
|
||||
* wifi_prov_security1_params_t for protocomm security 1
|
||||
* and wifi_prov_security2_params_t for protocomm security 2 respectively.
|
||||
* @param[in] service_name Unique name of the service. This translates to:
|
||||
* - Wi-Fi SSID when provisioning mode is softAP
|
||||
* - Device name when provisioning mode is BLE
|
||||
@@ -301,8 +314,7 @@ esp_err_t wifi_prov_mgr_is_provisioned(bool *provisioned);
|
||||
* - ESP_FAIL : Failed to start provisioning service
|
||||
* - ESP_ERR_INVALID_STATE : Provisioning manager not initialized or already started
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief Stop provisioning service
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user