mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix spp vfs demo crash when use dynamic memory
This commit is contained in:
parent
4f082154e0
commit
478cef9b75
@ -671,12 +671,8 @@ static void btc_spp_start_srv(btc_spp_args_t *arg)
|
||||
|
||||
if (ret != ESP_SPP_SUCCESS) {
|
||||
esp_spp_cb_param_t param;
|
||||
param.srv_open.status = ret;
|
||||
param.srv_open.handle = 0;
|
||||
param.srv_open.new_listen_handle = 0;
|
||||
param.srv_open.fd = -1;
|
||||
memset(param.srv_open.rem_bda, 0, ESP_BD_ADDR_LEN);
|
||||
btc_spp_cb_to_app(ESP_SPP_SRV_OPEN_EVT, ¶m);
|
||||
param.start.status = ret;
|
||||
btc_spp_cb_to_app(ESP_SPP_START_EVT, ¶m);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1215,6 +1211,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;
|
||||
}
|
||||
@ -1302,11 +1299,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;
|
||||
@ -1329,6 +1333,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;
|
||||
@ -1406,6 +1411,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,
|
||||
|
@ -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(EXAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_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_CONNECTABLE, ESP_BT_GENERAL_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;
|
||||
@ -207,7 +212,7 @@ void app_main(void)
|
||||
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) {
|
||||
|
@ -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(EXAMPLE_DEVICE_NAME);
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_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_CONNECTABLE, ESP_BT_GENERAL_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");
|
||||
@ -275,7 +279,7 @@ void app_main(void)
|
||||
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__);
|
||||
|
Loading…
Reference in New Issue
Block a user