Fixed compilation errors that occurred after enabling blufi (#1677)

This commit is contained in:
Wang is proud
2026-01-24 21:55:24 +08:00
committed by GitHub
parent 6b3659c2f5
commit 3a52761d30
5 changed files with 207 additions and 64 deletions

View File

@ -1,12 +1,17 @@
#pragma once
#include <aes/esp_aes.h>
#include "mbedtls/dhm.h"
#include "mbedtls/aes.h"
#include "esp_err.h"
#include <cassert>
#include <cstring>
#include <vector>
#include "esp_blufi_api.h"
#include "esp_wifi_types.h"
#include "esp_err.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "mbedtls/aes.h"
#include "mbedtls/dhm.h"
#include "wifi_manager.h"
class Blufi {
public:
@ -15,6 +20,14 @@ public:
*/
static Blufi &GetInstance();
/**
* @brief Start WiFi scan for Blufi provisioning
* This method intelligently handles WiFi scanning based on current WiFi state:
* - If WiFi config mode is active, it uses the existing scan results from WifiConfigurationAp
* - Otherwise, it performs a dedicated scan without interfering with normal WiFi operations
*/
void start_wifi_scan();
/**
* @brief Initializes the Bluetooth controller, host, and Blufi profile.
* This is the main entry point to start the Blufi process.
@ -40,7 +53,6 @@ private:
~Blufi();
// Initialization logic
static esp_err_t _controller_init();
@ -58,7 +70,8 @@ private:
void _security_deinit();
void _dh_negotiate_data_handler(uint8_t *data, int len, uint8_t **output_data, int *output_len, bool *need_free);
void _dh_negotiate_data_handler(uint8_t *data, int len, uint8_t **output_data, int *output_len,
bool *need_free);
int _aes_encrypt(uint8_t iv8, uint8_t *crypt_data, int crypt_len);
@ -70,12 +83,19 @@ private:
static int _get_softap_conn_num();
// These C-style functions are registered with ESP-IDF and call the corresponding instance methods.
// WiFi scan methods
void _send_wifi_list();
void _start_dedicated_wifi_scan();
static void _wifi_scan_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
void *event_data);
// These C-style functions are registered with ESP-IDF and call the corresponding instance
// methods.
static void _event_callback_trampoline(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param);
static void _negotiate_data_handler_trampoline(uint8_t *data, int len, uint8_t **output_data, int *output_len,
bool *need_free);
static void _negotiate_data_handler_trampoline(uint8_t *data, int len, uint8_t **output_data,
int *output_len, bool *need_free);
static int _encrypt_func_trampoline(uint8_t iv8, uint8_t *crypt_data, int crypt_len);
@ -91,12 +111,12 @@ private:
// Security context, formerly blufi_sec struct
struct BlufiSecurity {
#define DH_SELF_PUB_KEY_LEN 128
#define DH_SELF_PUB_KEY_LEN 128
uint8_t self_public_key[DH_SELF_PUB_KEY_LEN];
#define SHARE_KEY_LEN 128
#define SHARE_KEY_LEN 128
uint8_t share_key[SHARE_KEY_LEN];
size_t share_len;
#define PSK_LEN 16
#define PSK_LEN 16
uint8_t psk[PSK_LEN];
uint8_t *dh_param;
int dh_param_len;
@ -109,7 +129,6 @@ private:
// State variables
wifi_config_t m_sta_config{};
wifi_config_t m_ap_config{};
bool m_ble_is_connected;
bool m_sta_connected;
bool m_sta_got_ip;
@ -120,4 +139,9 @@ private:
int m_sta_ssid_len;
bool m_sta_is_connecting;
esp_blufi_extra_info_t m_sta_conn_info{};
// WiFi scan related
std::vector<wifi_ap_record_t> m_ap_records;
bool m_scan_in_progress = false;
bool m_scan_should_save_ssid = true;
};