mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-29 18:27:20 +02:00
Merge branch 'bugfix/fix_spp_vfs_dynamic_memory_bugs_v3.3' into 'release/v3.3'
component_bt/fix spp vfs demo crash when use dynamic memory[backport v3.3] See merge request espressif/esp-idf!11725
This commit is contained in:
@ -1207,6 +1207,7 @@ int bta_co_rfc_data_outgoing(void *user_data, uint8_t *buf, uint16_t size)
|
||||
static ssize_t spp_vfs_write(int fd, const void * data, size_t size)
|
||||
{
|
||||
assert(data != NULL);
|
||||
errno = 0;
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
@ -1294,11 +1295,18 @@ static ssize_t spp_vfs_write(int fd, const void * data, size_t size)
|
||||
}
|
||||
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
||||
}
|
||||
|
||||
// errors occur, need to cleanup
|
||||
if (p_buf) {
|
||||
osi_free(p_buf);
|
||||
p_buf = NULL;
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
||||
static int spp_vfs_close(int fd)
|
||||
{
|
||||
errno = 0;
|
||||
if (!is_spp_init()) {
|
||||
BTC_TRACE_ERROR("%s SPP have not been init\n", __func__);
|
||||
errno = ESRCH;
|
||||
@ -1321,6 +1329,7 @@ static int spp_vfs_close(int fd)
|
||||
static ssize_t spp_vfs_read(int fd, void * dst, size_t size)
|
||||
{
|
||||
assert(dst != NULL);
|
||||
errno = 0;
|
||||
if (!is_spp_init()) {
|
||||
BTC_TRACE_ERROR("%s SPP have not been init\n", __func__);
|
||||
errno = ESRCH;
|
||||
@ -1398,6 +1407,11 @@ static ssize_t spp_vfs_read(int fd, void * dst, size_t size)
|
||||
|
||||
esp_err_t btc_spp_vfs_register(void)
|
||||
{
|
||||
if (!is_spp_init()) {
|
||||
BTC_TRACE_ERROR("%s SPP have not been init\n", __func__);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_vfs_t vfs = {
|
||||
.flags = ESP_VFS_FLAG_DEFAULT,
|
||||
.write = spp_vfs_write,
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#define SPP_TAG "SPP_ACCEPTOR_DEMO"
|
||||
#define SPP_SERVER_NAME "SPP_SERVER"
|
||||
#define EXCAMPLE_DEVICE_NAME "ESP_SPP_ACCEPTOR"
|
||||
#define EXAMPLE_DEVICE_NAME "ESP_SPP_ACCEPTOR"
|
||||
|
||||
static const esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_VFS;
|
||||
|
||||
@ -77,10 +77,13 @@ static void esp_spp_cb(uint16_t e, void *p)
|
||||
|
||||
switch (event) {
|
||||
case ESP_SPP_INIT_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT status=%d", param->init.status);
|
||||
if (param->init.status == ESP_SPP_SUCCESS) {
|
||||
esp_spp_vfs_register();
|
||||
esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_spp_start_srv(sec_mask, role_slave, 0, SPP_SERVER_NAME);
|
||||
}
|
||||
break;
|
||||
case ESP_SPP_DISCOVERY_COMP_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_DISCOVERY_COMP_EVT");
|
||||
@ -98,8 +101,10 @@ static void esp_spp_cb(uint16_t e, void *p)
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_CL_INIT_EVT");
|
||||
break;
|
||||
case ESP_SPP_SRV_OPEN_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_SRV_OPEN_EVT");
|
||||
spp_wr_task_start_up(spp_read_handle, param->srv_open.fd);
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_SRV_OPEN_EVT status=%d", param->srv_open.status);
|
||||
if (param->srv_open.status == ESP_SPP_SUCCESS) {
|
||||
spp_wr_task_start_up(spp_read_handle, param->srv_open.fd);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -203,7 +208,7 @@ void app_main()
|
||||
ESP_LOGE(SPP_TAG, "%s spp register failed", __func__);
|
||||
return;
|
||||
}
|
||||
esp_spp_vfs_register();
|
||||
|
||||
spp_task_task_start_up();
|
||||
|
||||
if (esp_spp_init(esp_spp_mode) != ESP_OK) {
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "sys/unistd.h"
|
||||
|
||||
#define SPP_TAG "SPP_INITIATOR_DEMO"
|
||||
#define EXCAMPLE_DEVICE_NAME "ESP_SPP_INITIATOR"
|
||||
#define EXAMPLE_DEVICE_NAME "ESP_SPP_INITIATOR"
|
||||
|
||||
static const esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_VFS;
|
||||
|
||||
@ -115,11 +115,13 @@ static void esp_spp_cb(uint16_t e, void *p)
|
||||
|
||||
switch (event) {
|
||||
case ESP_SPP_INIT_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
||||
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT status=%d", param->init.status);
|
||||
if (param->init.status == ESP_SPP_SUCCESS) {
|
||||
esp_spp_vfs_register();
|
||||
esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
||||
}
|
||||
break;
|
||||
case ESP_SPP_DISCOVERY_COMP_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_DISCOVERY_COMP_EVT status=%d scn_num=%d",param->disc_comp.status, param->disc_comp.scn_num);
|
||||
@ -128,8 +130,10 @@ static void esp_spp_cb(uint16_t e, void *p)
|
||||
}
|
||||
break;
|
||||
case ESP_SPP_OPEN_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT");
|
||||
spp_wr_task_start_up(spp_write_handle, param->open.fd);
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT status=%d", param->open.status);
|
||||
if (param->open.status == ESP_SPP_SUCCESS) {
|
||||
spp_wr_task_start_up(spp_write_handle, param->open.fd);
|
||||
}
|
||||
break;
|
||||
case ESP_SPP_CLOSE_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT");
|
||||
@ -271,7 +275,7 @@ void app_main()
|
||||
ESP_LOGE(SPP_TAG, "%s spp register failed", __func__);
|
||||
return;
|
||||
}
|
||||
esp_spp_vfs_register();
|
||||
|
||||
spp_task_task_start_up();
|
||||
if (esp_spp_init(esp_spp_mode) != ESP_OK) {
|
||||
ESP_LOGE(SPP_TAG, "%s spp init failed", __func__);
|
||||
|
Reference in New Issue
Block a user