mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'fix/stack_overflow_in_example_spp_initiator' into 'master'
Fix/stack overflow in example spp initiator See merge request espressif/esp-idf!32197
This commit is contained in:
commit
3b46ee0538
@ -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
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -47,6 +47,17 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param);
|
|||||||
/*******************************
|
/*******************************
|
||||||
* STATIC FUNCTION DEFINITIONS
|
* 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_dev_cb(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param)
|
static void bt_app_dev_cb(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param)
|
||||||
{
|
{
|
||||||
@ -176,6 +187,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
|||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
char bda_str[18] = {0};
|
||||||
/* initialize NVS — it is used to store PHY calibration data */
|
/* initialize NVS — it is used to store PHY calibration data */
|
||||||
esp_err_t err = nvs_flash_init();
|
esp_err_t err = nvs_flash_init();
|
||||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
@ -230,6 +242,7 @@ void app_main(void)
|
|||||||
pin_code[3] = '4';
|
pin_code[3] = '4';
|
||||||
esp_bt_gap_set_pin(pin_type, 4, pin_code);
|
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();
|
bt_app_task_start_up();
|
||||||
/* bluetooth device name, connection mode and profile set 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);
|
bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
|
||||||
|
@ -735,6 +735,7 @@ static void bt_av_hdl_avrc_ct_evt(uint16_t event, void *p_param)
|
|||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
char bda_str[18] = {0};
|
||||||
/* initialize NVS — it is used to store PHY calibration data */
|
/* initialize NVS — it is used to store PHY calibration data */
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
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_pin_code_t pin_code;
|
||||||
esp_bt_gap_set_pin(pin_type, 0, 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();
|
bt_app_task_start_up();
|
||||||
/* Bluetooth device name, connection mode and profile set 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);
|
bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_STACK_UP_EVT, NULL, 0, NULL);
|
||||||
|
@ -272,6 +272,7 @@ static void bt_app_gap_start_up(void)
|
|||||||
|
|
||||||
void app_main(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*/
|
/* 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();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
@ -304,5 +305,6 @@ void app_main(void)
|
|||||||
return;
|
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();
|
bt_app_gap_start_up();
|
||||||
}
|
}
|
||||||
|
@ -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
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -71,6 +71,18 @@ uint8_t hid_mouse_descriptor[] = {
|
|||||||
0xc0 // END_COLLECTION
|
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);
|
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)
|
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";
|
const char *TAG = "esp_bt_gap_cb";
|
||||||
@ -390,6 +392,7 @@ void app_main(void)
|
|||||||
{
|
{
|
||||||
const char *TAG = "app_main";
|
const char *TAG = "app_main";
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
|
char bda_str[18] = {0};
|
||||||
|
|
||||||
ret = nvs_flash_init();
|
ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
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_pin_code_t pin_code;
|
||||||
esp_bt_gap_set_pin(pin_type, 0, 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");
|
ESP_LOGI(TAG, "exiting");
|
||||||
}
|
}
|
||||||
|
@ -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
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "stdlib.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.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)
|
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);
|
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_parser_register_callback(parser, spp_msg_handler);
|
||||||
spp_msg_show_usage();
|
spp_msg_show_usage();
|
||||||
#define TMP_BUF_LEN 128
|
#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 (;;) {
|
for (;;) {
|
||||||
//Waiting for UART event.
|
//Waiting for UART event.
|
||||||
if (xQueueReceive(uart_queue, (void * )&event, (TickType_t)portMAX_DELAY)) {
|
if (xQueueReceive(uart_queue, (void * )&event, (TickType_t)portMAX_DELAY)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
//Event of UART receving data
|
//Event of UART receiving data
|
||||||
case UART_DATA:
|
case UART_DATA:
|
||||||
{
|
{
|
||||||
len = uart_read_bytes(CONSOLE_UART_NUM, tmp_buf, TMP_BUF_LEN, 0);
|
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);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -32,6 +32,18 @@ enum {
|
|||||||
BT_APP_EVT_STACK_UP = 0,
|
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 */
|
/* handler for bluetooth stack enabled events */
|
||||||
static void bt_hf_hdl_stack_evt(uint16_t event, void *p_param)
|
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)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
char bda_str[18] = {0};
|
||||||
/* Initialize NVS — it is used to store PHY calibration data */
|
/* Initialize NVS — it is used to store PHY calibration data */
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||||
@ -101,6 +114,7 @@ void app_main(void)
|
|||||||
return;
|
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 */
|
/* create application task */
|
||||||
bt_app_task_start_up();
|
bt_app_task_start_up();
|
||||||
|
|
||||||
|
@ -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
|
* 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 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)
|
static bool get_name_from_eir(uint8_t *eir, char *bdname, uint8_t *bdname_len)
|
||||||
{
|
{
|
||||||
uint8_t *rmt_bdname = NULL;
|
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)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
char bda_str[18] = {0};
|
||||||
/* Initialize NVS — it is used to store PHY calibration data */
|
/* Initialize NVS — it is used to store PHY calibration data */
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||||
@ -186,6 +199,7 @@ void app_main(void)
|
|||||||
return;
|
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 */
|
/* create application task */
|
||||||
bt_app_task_start_up();
|
bt_app_task_start_up();
|
||||||
|
|
||||||
|
@ -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
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -51,6 +51,18 @@
|
|||||||
|
|
||||||
static const char *TAG = "ESP_HIDH_DEMO";
|
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)
|
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;
|
esp_hidh_event_t event = (esp_hidh_event_t)id;
|
||||||
@ -165,6 +177,7 @@ void ble_store_config_init(void);
|
|||||||
#endif
|
#endif
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
char bda_str[18] = {0};
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
#if HID_HOST_MODE == HIDH_IDLE_MODE
|
#if HID_HOST_MODE == HIDH_IDLE_MODE
|
||||||
ESP_LOGE(TAG, "Please turn on BT HID host or BLE!");
|
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_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
|
#if CONFIG_BT_NIMBLE_ENABLED
|
||||||
/* XXX Need to have template for store */
|
/* XXX Need to have template for store */
|
||||||
ble_store_config_init();
|
ble_store_config_init();
|
||||||
|
Loading…
Reference in New Issue
Block a user