mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-14 19:16:20 +00:00
Merge branch 'master' into feature/esp32s2beta_update
This commit is contained in:
57
components/esp_wifi/src/crypto_ops.c
Normal file
57
components/esp_wifi/src/crypto_ops.c
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "utils/common.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
#include "crypto/sha256.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/md5.h"
|
||||
#include "crypto/sha1.h"
|
||||
#include "crypto/aes.h"
|
||||
#include "crypto/dh_group5.h"
|
||||
#include "esp_wifi_crypto_types.h"
|
||||
/*
|
||||
* This structure is used to set the cyrpto callback function for station to connect when in security mode.
|
||||
* These functions either call MbedTLS API's if USE_MBEDTLS_CRYPTO flag is set through Kconfig, or native
|
||||
* API's otherwise. We recommend setting the flag since MbedTLS API's utilize hardware acceleration while
|
||||
* native API's are use software implementations.
|
||||
*/
|
||||
const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = {
|
||||
.size = sizeof(wpa_crypto_funcs_t),
|
||||
.version = ESP_WIFI_CRYPTO_VERSION,
|
||||
.aes_wrap = (esp_aes_wrap_t)aes_wrap,
|
||||
.aes_unwrap = (esp_aes_unwrap_t)aes_unwrap,
|
||||
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)hmac_sha256_vector,
|
||||
.sha256_prf = (esp_sha256_prf_t)sha256_prf,
|
||||
.hmac_md5 = (esp_hmac_md5_t)hmac_md5,
|
||||
.hamc_md5_vector = (esp_hmac_md5_vector_t)hmac_md5_vector,
|
||||
.hmac_sha1 = (esp_hmac_sha1_t)hmac_sha1,
|
||||
.hmac_sha1_vector = (esp_hmac_sha1_vector_t)hmac_sha1_vector,
|
||||
.sha1_prf = (esp_sha1_prf_t)sha1_prf,
|
||||
.sha1_vector = (esp_sha1_vector_t)sha1_vector,
|
||||
.pbkdf2_sha1 = (esp_pbkdf2_sha1_t)pbkdf2_sha1,
|
||||
.rc4_skip = (esp_rc4_skip_t)rc4_skip,
|
||||
.md5_vector = (esp_md5_vector_t)md5_vector,
|
||||
.aes_encrypt = (esp_aes_encrypt_t)aes_encrypt,
|
||||
.aes_encrypt_init = (esp_aes_encrypt_init_t)aes_encrypt_init,
|
||||
.aes_encrypt_deinit = (esp_aes_encrypt_deinit_t)aes_encrypt_deinit,
|
||||
.aes_decrypt = (esp_aes_decrypt_t)aes_decrypt,
|
||||
.aes_decrypt_init = (esp_aes_decrypt_init_t)aes_decrypt_init,
|
||||
.aes_decrypt_deinit = (esp_aes_decrypt_deinit_t)aes_decrypt_deinit
|
||||
};
|
||||
|
||||
const mesh_crypto_funcs_t g_wifi_default_mesh_crypto_funcs = {
|
||||
.aes_128_encrypt = (esp_aes_128_encrypt_t)aes_128_cbc_encrypt,
|
||||
.aes_128_decrypt = (esp_aes_128_decrypt_t)aes_128_cbc_decrypt,
|
||||
};
|
||||
@@ -14,24 +14,10 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "esp_event.h"
|
||||
#include "esp_mesh.h"
|
||||
|
||||
/* mesh event callback handler */
|
||||
mesh_event_cb_t g_mesh_event_cb = NULL;
|
||||
ESP_EVENT_DEFINE_BASE(MESH_EVENT);
|
||||
|
||||
esp_err_t esp_event_mesh_hook(system_event_t *event)
|
||||
esp_err_t esp_mesh_send_event_internal(int32_t event_id, void* event_data, size_t event_data_size)
|
||||
{
|
||||
if (event->event_id == SYSTEM_EVENT_STA_GOT_IP || event->event_id == SYSTEM_EVENT_STA_LOST_IP) {
|
||||
if (g_mesh_event_cb) {
|
||||
mesh_event_t mevent;
|
||||
if (event->event_id == SYSTEM_EVENT_STA_GOT_IP) {
|
||||
mevent.id = MESH_EVENT_ROOT_GOT_IP;
|
||||
memcpy(&mevent.info.got_ip, &event->event_info.got_ip, sizeof(system_event_sta_got_ip_t));
|
||||
} else {
|
||||
mevent.id = MESH_EVENT_ROOT_LOST_IP;
|
||||
}
|
||||
g_mesh_event_cb(mevent);
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
return esp_event_post(MESH_EVENT, event_id, event_data, event_data_size, 0);
|
||||
}
|
||||
|
||||
77
components/esp_wifi/src/smartconfig.c
Normal file
77
components/esp_wifi/src/smartconfig.c
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_event_base.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "esp_smartconfig.h"
|
||||
#include "smartconfig_ack.h"
|
||||
|
||||
/* Smartconfig events definitions */
|
||||
ESP_EVENT_DEFINE_BASE(SC_EVENT);
|
||||
|
||||
static const char *TAG = "smartconfig";
|
||||
|
||||
static void handler_got_ssid_passwd(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
smartconfig_event_got_ssid_pswd_t *evt = (smartconfig_event_got_ssid_pswd_t *)data;
|
||||
uint8_t ssid[33] = { 0 };
|
||||
uint8_t password[65] = { 0 };
|
||||
uint8_t cellphone_ip[4];
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
memcpy(ssid, evt->ssid, sizeof(evt->ssid));
|
||||
memcpy(password, evt->password, sizeof(evt->password));
|
||||
memcpy(cellphone_ip, evt->cellphone_ip, sizeof(evt->cellphone_ip));
|
||||
|
||||
ESP_LOGD(TAG, "SSID:%s", ssid);
|
||||
ESP_LOGD(TAG, "PASSWORD:%s", password);
|
||||
ESP_LOGD(TAG, "Phone ip: %d.%d.%d.%d\n", cellphone_ip[0], cellphone_ip[1], cellphone_ip[2], cellphone_ip[3]);
|
||||
|
||||
err = sc_send_ack_start(evt->type, evt->token, evt->cellphone_ip);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Send smartconfig ACK error: %d", err);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_smartconfig_start(const smartconfig_start_config_t *config)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
err = esp_event_handler_register(SC_EVENT, SC_EVENT_GOT_SSID_PSWD, handler_got_ssid_passwd, NULL);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Register smartconfig default event handler fail!");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = esp_smartconfig_internal_start(config);
|
||||
if (err != ESP_OK) {
|
||||
esp_event_handler_unregister(SC_EVENT, SC_EVENT_GOT_SSID_PSWD, handler_got_ssid_passwd);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_smartconfig_stop(void)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
err = esp_smartconfig_internal_stop();
|
||||
if (err == ESP_OK) {
|
||||
sc_send_ack_stop();
|
||||
esp_event_handler_unregister(SC_EVENT, SC_EVENT_GOT_SSID_PSWD, handler_got_ssid_passwd);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
@@ -18,6 +18,15 @@
|
||||
#include "esp_private/wifi.h"
|
||||
#include "esp_pm.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "esp_wpa.h"
|
||||
|
||||
#if (CONFIG_ESP32_WIFI_RX_BA_WIN > CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM)
|
||||
#error "WiFi configuration check: WARNING, WIFI_RX_BA_WIN should not be larger than WIFI_DYNAMIC_RX_BUFFER_NUM!"
|
||||
#endif
|
||||
|
||||
#if (CONFIG_ESP32_WIFI_RX_BA_WIN > (CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM << 1))
|
||||
#error "WiFi configuration check: WARNING, WIFI_RX_BA_WIN should not be larger than double of the WIFI_STATIC_RX_BUFFER_NUM!"
|
||||
#endif
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(WIFI_EVENT);
|
||||
|
||||
@@ -110,6 +119,17 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
s_wifi_mac_time_update_cb = esp_wifi_internal_update_mac_time;
|
||||
#endif
|
||||
|
||||
result = esp_supplicant_init();
|
||||
if (result != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to init supplicant (0x%x)", result);
|
||||
esp_err_t deinit_ret = esp_wifi_deinit();
|
||||
if (deinit_ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to deinit Wi-Fi (0x%x)", deinit_ret);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user