Merge branch 'fix/stack_overflow_in_example_spp_initiator_v5.2' into 'release/v5.2'
Some checks failed
docker / docker (push) Has been cancelled

Fix/stack overflow in example spp initiator (backport v5.2)

See merge request espressif/esp-idf!32233
This commit is contained in:
Jiang Jiang Jian 2024-07-26 18:00:20 +08:00
commit dea1450d6e
8 changed files with 90 additions and 20 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -45,6 +45,17 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param);
/*******************************
* STATIC FUNCTION DEFINITIONS
******************************/
static char *bda2str(uint8_t * bda, char *str, size_t size)
{
if (bda == NULL || str == NULL || size < 18) {
return NULL;
}
uint8_t *p = bda;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
return str;
}
static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
@ -155,6 +166,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
void app_main(void)
{
char bda_str[18] = {0};
/* initialize NVS — it is used to store PHY calibration data */
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@ -209,6 +221,7 @@ void app_main(void)
pin_code[3] = '4';
esp_bt_gap_set_pin(pin_type, 4, pin_code);
ESP_LOGI(BT_AV_TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str)));
bt_app_task_start_up();
/* bluetooth device name, connection mode and profile set up */
bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);

View File

@ -735,6 +735,7 @@ static void bt_av_hdl_avrc_ct_evt(uint16_t event, void *p_param)
void app_main(void)
{
char bda_str[18] = {0};
/* initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@ -788,6 +789,7 @@ void app_main(void)
esp_bt_pin_code_t pin_code;
esp_bt_gap_set_pin(pin_type, 0, pin_code);
ESP_LOGI(BT_AV_TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str)));
bt_app_task_start_up();
/* Bluetooth device name, connection mode and profile set up */
bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_STACK_UP_EVT, NULL, 0, NULL);

View File

@ -272,6 +272,7 @@ static void bt_app_gap_start_up(void)
void app_main(void)
{
char bda_str[18] = {0};
/* Initialize NVS — it is used to store PHY calibration data and save key-value pairs in flash memory*/
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@ -304,5 +305,6 @@ void app_main(void)
return;
}
ESP_LOGI(GAP_TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str)));
bt_app_gap_start_up();
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -71,6 +71,18 @@ uint8_t hid_mouse_descriptor[] = {
0xc0 // END_COLLECTION
};
static char *bda2str(esp_bd_addr_t bda, char *str, size_t size)
{
if (bda == NULL || str == NULL || size < 18) {
return NULL;
}
uint8_t *p = bda;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
return str;
}
const int hid_mouse_descriptor_len = sizeof(hid_mouse_descriptor);
/**
@ -158,16 +170,6 @@ void mouse_move_task(void *pvParameters)
}
}
static void print_bt_address(void)
{
const char *TAG = "bt_address";
const uint8_t *bd_addr;
bd_addr = esp_bt_dev_get_address();
ESP_LOGI(TAG, "my bluetooth address is %02X:%02X:%02X:%02X:%02X:%02X",
bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
}
void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
const char *TAG = "esp_bt_gap_cb";
@ -390,6 +392,7 @@ void app_main(void)
{
const char *TAG = "app_main";
esp_err_t ret;
char bda_str[18] = {0};
ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@ -477,6 +480,6 @@ void app_main(void)
esp_bt_pin_code_t pin_code;
esp_bt_gap_set_pin(pin_type, 0, pin_code);
print_bt_address();
ESP_LOGI(TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str)));
ESP_LOGI(TAG, "exiting");
}

View File

@ -1,9 +1,10 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "stdlib.h"
#include "driver/uart.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -31,7 +32,7 @@ extern void spp_msg_args_parser(char *buf, int len);
void spp_msg_handler(char *buf, int len)
{
ESP_LOGE(TAG_CNSL, "Command [%s]", buf);
ESP_LOGI(TAG_CNSL, "Command [%s]", buf);
spp_msg_args_parser(buf, len);
}
@ -44,13 +45,18 @@ static void console_uart_task(void *pvParameters)
spp_msg_parser_register_callback(parser, spp_msg_handler);
spp_msg_show_usage();
#define TMP_BUF_LEN 128
uint8_t tmp_buf[128] = {0};
uint8_t *tmp_buf = NULL;
if ((tmp_buf = (uint8_t *)calloc(TMP_BUF_LEN, sizeof(uint8_t))) == NULL) {
ESP_LOGE(TAG_CNSL,"temp buf malloc fail");
return;
}
for (;;) {
//Waiting for UART event.
if (xQueueReceive(uart_queue, (void * )&event, (TickType_t)portMAX_DELAY)) {
switch (event.type) {
//Event of UART receving data
//Event of UART receiving data
case UART_DATA:
{
len = uart_read_bytes(CONSOLE_UART_NUM, tmp_buf, TMP_BUF_LEN, 0);
@ -95,6 +101,8 @@ static void console_uart_task(void *pvParameters)
}
}
}
free(tmp_buf);
vTaskDelete(NULL);
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -32,6 +32,18 @@ enum {
BT_APP_EVT_STACK_UP = 0,
};
static char *bda2str(esp_bd_addr_t bda, char *str, size_t size)
{
if (bda == NULL || str == NULL || size < 18) {
return NULL;
}
uint8_t *p = bda;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
return str;
}
/* handler for bluetooth stack enabled events */
static void bt_hf_hdl_stack_evt(uint16_t event, void *p_param)
{
@ -73,6 +85,7 @@ static void bt_hf_hdl_stack_evt(uint16_t event, void *p_param)
void app_main(void)
{
char bda_str[18] = {0};
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
@ -101,6 +114,7 @@ void app_main(void)
return;
}
ESP_LOGI(BT_HF_TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str)));
/* create application task */
bt_app_task_start_up();

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -32,6 +32,18 @@ static uint8_t peer_bdname_len;
static const char remote_device_name[] = "ESP_HFP_AG";
static char *bda2str(esp_bd_addr_t bda, char *str, size_t size)
{
if (bda == NULL || str == NULL || size < 18) {
return NULL;
}
uint8_t *p = bda;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
return str;
}
static bool get_name_from_eir(uint8_t *eir, char *bdname, uint8_t *bdname_len)
{
uint8_t *rmt_bdname = NULL;
@ -151,6 +163,7 @@ static void bt_hf_client_hdl_stack_evt(uint16_t event, void *p_param);
void app_main(void)
{
char bda_str[18] = {0};
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
@ -186,6 +199,7 @@ void app_main(void)
return;
}
ESP_LOGI(BT_HF_TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str)));
/* create application task */
bt_app_task_start_up();

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -51,6 +51,18 @@
static const char *TAG = "ESP_HIDH_DEMO";
static char *bda2str(esp_bd_addr_t bda, char *str, size_t size)
{
if (bda == NULL || str == NULL || size < 18) {
return NULL;
}
uint8_t *p = bda;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
return str;
}
void hidh_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data)
{
esp_hidh_event_t event = (esp_hidh_event_t)id;
@ -165,6 +177,7 @@ void ble_store_config_init(void);
#endif
void app_main(void)
{
char bda_str[18] = {0};
esp_err_t ret;
#if HID_HOST_MODE == HIDH_IDLE_MODE
ESP_LOGE(TAG, "Please turn on BT HID host or BLE!");
@ -188,6 +201,7 @@ void app_main(void)
};
ESP_ERROR_CHECK( esp_hidh_init(&config) );
ESP_LOGI(TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str)));
#if CONFIG_BT_NIMBLE_ENABLED
/* XXX Need to have template for store */
ble_store_config_init();