|
|
@@ -1,16 +1,8 @@
|
|
|
-// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
-//
|
|
|
-// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
-// you may not use this file except in compliance with the License.
|
|
|
-// You may obtain a copy of the License at
|
|
|
-
|
|
|
-// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
-//
|
|
|
-// Unless required by applicable law or agreed to in writing, software
|
|
|
-// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
-// See the License for the specific language governing permissions and
|
|
|
-// limitations under the License.
|
|
|
+/*
|
|
|
+ * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
+ *
|
|
|
+ * SPDX-License-Identifier: Apache-2.0
|
|
|
+ */
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
@@ -55,8 +47,9 @@ typedef struct {
|
|
|
} slot_data_t;
|
|
|
|
|
|
typedef struct {
|
|
|
- uint8_t serial;
|
|
|
bool connected;
|
|
|
+ bool is_server;
|
|
|
+ uint8_t serial;
|
|
|
uint8_t scn;
|
|
|
uint8_t max_session;
|
|
|
uint32_t id;
|
|
|
@@ -137,29 +130,39 @@ static spp_slot_t *spp_malloc_slot(void)
|
|
|
(*slot)->sdp_handle = 0;
|
|
|
(*slot)->rfc_handle = 0;
|
|
|
(*slot)->rfc_port_handle = 0;
|
|
|
- (*slot)->connected = FALSE;
|
|
|
+ (*slot)->fd = -1;
|
|
|
+ (*slot)->connected = false;
|
|
|
+ (*slot)->is_server = false;
|
|
|
(*slot)->write_data = NULL;
|
|
|
(*slot)->close_alarm = NULL;
|
|
|
+ /* clear the old event bits */
|
|
|
+ if (spp_local_param.tx_event_group) {
|
|
|
+ xEventGroupClearBits(spp_local_param.tx_event_group, SLOT_WRITE_BIT(i) | SLOT_CLOSE_BIT(i));
|
|
|
+ }
|
|
|
+
|
|
|
if (init_slot_data(&(*slot)->rx, QUEUE_SIZE_MAX)) {
|
|
|
BTC_TRACE_ERROR("%s unable to malloc rx queue!", __func__);
|
|
|
err_no = 1;
|
|
|
- break;
|
|
|
+ goto err;
|
|
|
}
|
|
|
if (init_slot_data(&(*slot)->tx, SLOT_TX_QUEUE_SIZE)) {
|
|
|
BTC_TRACE_ERROR("%s unable to malloc tx queue!", __func__);
|
|
|
err_no = 2;
|
|
|
- break;
|
|
|
+ goto err;
|
|
|
}
|
|
|
if (spp_local_param.spp_mode == ESP_SPP_MODE_VFS) {
|
|
|
if (esp_vfs_register_fd(spp_local_param.spp_vfs_id, &(*slot)->fd) != ESP_OK) {
|
|
|
BTC_TRACE_ERROR("%s unable to register fd!", __func__);
|
|
|
err_no = 3;
|
|
|
- break;
|
|
|
+ goto err;
|
|
|
}
|
|
|
}
|
|
|
return (*slot);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+err:
|
|
|
switch (err_no) {
|
|
|
case 3:
|
|
|
free_slot_data(&(*slot)->tx);
|
|
|
@@ -177,9 +180,11 @@ static spp_slot_t *spp_malloc_slot(void)
|
|
|
|
|
|
static spp_slot_t *spp_find_slot_by_id(uint32_t id)
|
|
|
{
|
|
|
+ spp_slot_t *slot = NULL;
|
|
|
for (size_t i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->id == id) {
|
|
|
- return spp_local_param.spp_slots[i];
|
|
|
+ slot = spp_local_param.spp_slots[i];
|
|
|
+ if (slot != NULL && slot->id == id) {
|
|
|
+ return slot;
|
|
|
}
|
|
|
}
|
|
|
return NULL;
|
|
|
@@ -187,9 +192,11 @@ static spp_slot_t *spp_find_slot_by_id(uint32_t id)
|
|
|
|
|
|
static spp_slot_t *spp_find_slot_by_handle(uint32_t handle)
|
|
|
{
|
|
|
+ spp_slot_t *slot = NULL;
|
|
|
for (size_t i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->rfc_handle == handle) {
|
|
|
- return spp_local_param.spp_slots[i];
|
|
|
+ slot = spp_local_param.spp_slots[i];
|
|
|
+ if (slot != NULL && slot->rfc_handle == handle) {
|
|
|
+ return slot;
|
|
|
}
|
|
|
}
|
|
|
return NULL;
|
|
|
@@ -197,9 +204,11 @@ static spp_slot_t *spp_find_slot_by_handle(uint32_t handle)
|
|
|
|
|
|
static spp_slot_t *spp_find_slot_by_fd(int fd)
|
|
|
{
|
|
|
+ spp_slot_t *slot = NULL;
|
|
|
for (size_t i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->fd == fd) {
|
|
|
- return spp_local_param.spp_slots[i];
|
|
|
+ slot = spp_local_param.spp_slots[i];
|
|
|
+ if (slot != NULL && slot->fd == fd) {
|
|
|
+ return slot;
|
|
|
}
|
|
|
}
|
|
|
return NULL;
|
|
|
@@ -207,9 +216,11 @@ static spp_slot_t *spp_find_slot_by_fd(int fd)
|
|
|
|
|
|
static spp_slot_t *spp_find_slot_by_scn(uint32_t scn)
|
|
|
{
|
|
|
+ spp_slot_t *slot = NULL;
|
|
|
for (size_t i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->scn == (uint8_t)scn) {
|
|
|
- return spp_local_param.spp_slots[i];
|
|
|
+ slot = spp_local_param.spp_slots[i];
|
|
|
+ if (slot != NULL && slot->is_server && slot->scn == (uint8_t)scn) {
|
|
|
+ return slot;
|
|
|
}
|
|
|
}
|
|
|
return NULL;
|
|
|
@@ -277,9 +288,9 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
|
|
|
bt_status_t status;
|
|
|
btc_msg_t msg;
|
|
|
void *new_user_data = NULL;
|
|
|
-
|
|
|
- uint32_t id = (uintptr_t)user_data;
|
|
|
+ uint32_t id = (uintptr_t)user_data, id_temp = 0;
|
|
|
spp_slot_t *slot = NULL, *slot_new = NULL;
|
|
|
+
|
|
|
if (!is_spp_init()) {
|
|
|
BTC_TRACE_WARNING("%s SPP have been deinit, incoming events ignore!\n", __func__);
|
|
|
return new_user_data;
|
|
|
@@ -289,7 +300,7 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
|
|
|
case BTA_JV_RFCOMM_START_EVT:
|
|
|
slot = spp_find_slot_by_id(id);
|
|
|
if (!slot) {
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
p_data->rfc_start.status = ESP_SPP_NO_CONNECTION;
|
|
|
break;
|
|
|
}
|
|
|
@@ -299,42 +310,52 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
|
|
|
case BTA_JV_RFCOMM_SRV_OPEN_EVT:
|
|
|
slot = p_data->rfc_srv_open.handle ? spp_find_slot_by_id(id) : spp_find_slot_by_scn((uint32_t)user_data);
|
|
|
if (!slot) {
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
p_data->rfc_srv_open.status = ESP_SPP_NO_CONNECTION;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if (p_data->rfc_srv_open.handle) {
|
|
|
- new_user_data = (void *)(uintptr_t)slot->id;
|
|
|
- memcpy(slot->addr, p_data->rfc_srv_open.rem_bda, ESP_BD_ADDR_LEN);
|
|
|
- slot->connected = TRUE;
|
|
|
- slot->rfc_handle = p_data->rfc_srv_open.handle;
|
|
|
- slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_data->rfc_srv_open.handle);
|
|
|
- BTA_JvSetPmProfile(p_data->rfc_srv_open.handle, BTA_JV_PM_ALL, BTA_JV_CONN_OPEN);
|
|
|
- }
|
|
|
-
|
|
|
- if (p_data->rfc_srv_open.handle != p_data->rfc_srv_open.new_listen_handle) {
|
|
|
+ if (!p_data->rfc_srv_open.handle) {
|
|
|
+ /* match with the exist server solt */
|
|
|
+ slot->rfc_handle = p_data->rfc_srv_open.new_listen_handle;
|
|
|
+ slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(slot->rfc_handle);
|
|
|
+ } else {
|
|
|
slot_new = spp_malloc_slot();
|
|
|
if (!slot_new) {
|
|
|
BTC_TRACE_ERROR("%s unable to malloc RFCOMM slot!", __func__);
|
|
|
p_data->rfc_srv_open.status = ESP_SPP_NO_RESOURCE;
|
|
|
break;
|
|
|
}
|
|
|
- new_user_data = (void *)(uintptr_t)slot_new->id;
|
|
|
+ slot_new->connected = true;
|
|
|
slot_new->security = slot->security;
|
|
|
slot_new->role = slot->role;
|
|
|
slot_new->scn = slot->scn;
|
|
|
slot_new->max_session = slot->max_session;
|
|
|
strcpy(slot_new->service_name, slot->service_name);
|
|
|
slot_new->sdp_handle = slot->sdp_handle;
|
|
|
- slot_new->rfc_handle = p_data->rfc_srv_open.new_listen_handle;
|
|
|
- slot_new->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_data->rfc_srv_open.new_listen_handle);
|
|
|
+ slot_new->rfc_handle = p_data->rfc_srv_open.handle;
|
|
|
+ slot_new->rfc_port_handle = BTA_JvRfcommGetPortHdl(slot_new->rfc_handle);
|
|
|
+ BTA_JvSetPmProfile(p_data->rfc_srv_open.handle, BTA_JV_PM_ALL, BTA_JV_CONN_OPEN);
|
|
|
+
|
|
|
+ if (p_data->rfc_srv_open.new_listen_handle) {
|
|
|
+ slot->rfc_handle = p_data->rfc_srv_open.new_listen_handle;
|
|
|
+ slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(slot->rfc_handle);
|
|
|
+ } else {
|
|
|
+ /* means lower layer can alloc port */
|
|
|
+ slot->rfc_handle = 0;
|
|
|
+ slot->rfc_port_handle = 0;
|
|
|
+ }
|
|
|
+ /* swap slot id */
|
|
|
+ id_temp = slot->id;
|
|
|
+ slot->id = slot_new->id;
|
|
|
+ slot_new->id = id_temp;
|
|
|
}
|
|
|
+ new_user_data = (void *)(uintptr_t)slot->id;
|
|
|
break;
|
|
|
case BTA_JV_RFCOMM_OPEN_EVT:
|
|
|
slot = spp_find_slot_by_id(id);
|
|
|
if (!slot) {
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
p_data->rfc_open.status = ESP_SPP_NO_CONNECTION;
|
|
|
break;
|
|
|
}
|
|
|
@@ -346,7 +367,7 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
|
|
|
case BTA_JV_RFCOMM_CLOSE_EVT:
|
|
|
slot = spp_find_slot_by_id(id);
|
|
|
if (!slot) {
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
p_data->rfc_close.status = ESP_SPP_NO_CONNECTION;
|
|
|
break;
|
|
|
}
|
|
|
@@ -354,6 +375,7 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
|
|
|
BTA_JvRfcommClose(slot->rfc_handle, NULL, (void *)slot->id);
|
|
|
}
|
|
|
p_data->rfc_close.status = BTA_JV_SUCCESS;
|
|
|
+ p_data->rfc_close.user_data = (void *)(uintptr_t)slot->id;
|
|
|
break;
|
|
|
case BTA_JV_RFCOMM_DATA_IND_EVT:
|
|
|
break;
|
|
|
@@ -364,7 +386,7 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
|
|
|
if (slot) {
|
|
|
spp_free_slot(slot);
|
|
|
} else {
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
p_data->free_scn.status = ESP_SPP_NO_CONNECTION;
|
|
|
}
|
|
|
osi_free(user_data);
|
|
|
@@ -401,7 +423,7 @@ static void btc_spp_dm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_d
|
|
|
slot = spp_find_slot_by_id(id);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
break;
|
|
|
}
|
|
|
if (p_data->scn == 0) {
|
|
|
@@ -421,7 +443,7 @@ static void btc_spp_dm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_d
|
|
|
slot = spp_find_slot_by_id(id);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
break;
|
|
|
}
|
|
|
if (p_data->create_rec.status == BTA_JV_SUCCESS) {
|
|
|
@@ -510,14 +532,14 @@ static void btc_spp_uninit(void)
|
|
|
osi_mutex_lock(&spp_local_param.spp_slot_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
|
|
// first, remove all connection
|
|
|
for (size_t i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->connected) {
|
|
|
+ if (spp_local_param.spp_slots[i] != NULL && !spp_local_param.spp_slots[i]->is_server) {
|
|
|
BTA_JvRfcommClose(spp_local_param.spp_slots[i]->rfc_handle, (tBTA_JV_RFCOMM_CBACK *)btc_spp_rfcomm_inter_cb,
|
|
|
(void *)spp_local_param.spp_slots[i]->id);
|
|
|
}
|
|
|
}
|
|
|
// second, remove all server
|
|
|
for (size_t i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && !spp_local_param.spp_slots[i]->connected) {
|
|
|
+ if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->is_server) {
|
|
|
if (spp_local_param.spp_slots[i]->sdp_handle > 0) {
|
|
|
BTA_JvDeleteRecord(spp_local_param.spp_slots[i]->sdp_handle);
|
|
|
}
|
|
|
@@ -669,6 +691,10 @@ static void btc_spp_start_srv(btc_spp_args_t *arg)
|
|
|
ret = ESP_SPP_NO_RESOURCE;
|
|
|
break;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * make this slot become a listening slot
|
|
|
+ */
|
|
|
+ slot->is_server = true;
|
|
|
slot->security = arg->start_srv.sec_mask;
|
|
|
slot->role = arg->start_srv.role;
|
|
|
slot->scn = arg->start_srv.local_scn;
|
|
|
@@ -738,7 +764,7 @@ static void btc_spp_stop_srv(btc_spp_args_t *arg)
|
|
|
// [2] remove all local related connection
|
|
|
for (j = 0; j < srv_cnt; j++) {
|
|
|
for (i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->connected &&
|
|
|
+ if (spp_local_param.spp_slots[i] != NULL && !spp_local_param.spp_slots[i]->is_server &&
|
|
|
spp_local_param.spp_slots[i]->sdp_handle > 0 &&
|
|
|
spp_local_param.spp_slots[i]->scn == srv_scn_arr[j]) {
|
|
|
BTA_JvRfcommClose(spp_local_param.spp_slots[i]->rfc_handle,
|
|
|
@@ -751,7 +777,7 @@ static void btc_spp_stop_srv(btc_spp_args_t *arg)
|
|
|
// [3] remove all server
|
|
|
for (j = 0; j < srv_cnt; j++) {
|
|
|
for (i = 1; i <= MAX_RFC_PORTS; i++) {
|
|
|
- if (spp_local_param.spp_slots[i] != NULL && !spp_local_param.spp_slots[i]->connected &&
|
|
|
+ if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->is_server &&
|
|
|
spp_local_param.spp_slots[i]->sdp_handle > 0 &&
|
|
|
spp_local_param.spp_slots[i]->scn == srv_scn_arr[j]) {
|
|
|
if (spp_local_param.spp_slots[i]->sdp_handle > 0) {
|
|
|
@@ -933,7 +959,9 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
tBTA_JV *p_data = (tBTA_JV *)msg->arg;
|
|
|
spp_slot_t *slot = NULL;
|
|
|
uint8_t serial = 0;
|
|
|
- switch (msg->act) {
|
|
|
+ uint8_t event = msg->act;
|
|
|
+
|
|
|
+ switch (event) {
|
|
|
case BTA_JV_ENABLE_EVT:
|
|
|
param.init.status = p_data->status;
|
|
|
btc_spp_cb_to_app(ESP_SPP_INIT_EVT, ¶m);
|
|
|
@@ -960,12 +988,14 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
slot = spp_find_slot_by_handle(p_data->rfc_open.handle);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
param.open.status = ESP_SPP_NO_CONNECTION;
|
|
|
break;
|
|
|
}
|
|
|
param.open.fd = slot->fd;
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
+ } else {
|
|
|
+ param.open.fd = -1;
|
|
|
}
|
|
|
param.open.status = p_data->rfc_open.status;
|
|
|
} while (0);
|
|
|
@@ -989,12 +1019,14 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
slot = spp_find_slot_by_handle(p_data->rfc_srv_open.handle);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
param.srv_open.status = ESP_SPP_NO_CONNECTION;
|
|
|
break;
|
|
|
}
|
|
|
param.srv_open.fd = slot->fd;
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
+ } else {
|
|
|
+ param.srv_open.fd = -1;
|
|
|
}
|
|
|
param.srv_open.status = p_data->rfc_srv_open.status;
|
|
|
} while (0);
|
|
|
@@ -1065,10 +1097,11 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
if (spp_local_param.spp_mode == ESP_SPP_MODE_CB) {
|
|
|
btc_spp_cb_to_app(ESP_SPP_CLOSE_EVT, ¶m);
|
|
|
osi_mutex_lock(&spp_local_param.spp_slot_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
|
|
- slot = spp_find_slot_by_handle(p_data->rfc_close.handle);
|
|
|
+ uint32_t id = (uintptr_t)p_data->rfc_close.user_data;
|
|
|
+ slot = spp_find_slot_by_id(id);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
break;
|
|
|
}
|
|
|
spp_free_slot(slot);
|
|
|
@@ -1077,11 +1110,12 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
bool need_call = true;
|
|
|
do {
|
|
|
osi_mutex_lock(&spp_local_param.spp_slot_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
|
|
- slot = spp_find_slot_by_handle(p_data->rfc_close.handle);
|
|
|
+ uint32_t id = (uintptr_t)p_data->rfc_close.user_data;
|
|
|
+ slot = spp_find_slot_by_id(id);
|
|
|
if (!slot) {
|
|
|
param.close.status = ESP_SPP_NO_CONNECTION;
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
break;
|
|
|
}
|
|
|
// if rx still has data, delay free slot
|
|
|
@@ -1110,8 +1144,8 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
BTC_TRACE_ERROR("%s set slot close_alarm failed!", __func__);
|
|
|
break;
|
|
|
}
|
|
|
- BTC_TRACE_WARNING("%s slot rx data will be discard in %d seconds!", __func__,
|
|
|
- VFS_CLOSE_TIMEOUT / 1000);
|
|
|
+ BTC_TRACE_WARNING("%s slot rx data will be discard in %d milliseconds!",
|
|
|
+ __func__, VFS_CLOSE_TIMEOUT);
|
|
|
slot->connected = false;
|
|
|
need_call = false;
|
|
|
}
|
|
|
@@ -1137,7 +1171,7 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
slot = spp_find_slot_by_handle(p_data->rfc_cong.handle);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
break;
|
|
|
}
|
|
|
if (!p_data->rfc_cong.cong) {
|
|
|
@@ -1159,7 +1193,7 @@ void btc_spp_cb_handler(btc_msg_t *msg)
|
|
|
slot = spp_find_slot_by_handle(p_data->data_ind.handle);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot, event:%d!", __func__, event);
|
|
|
break;
|
|
|
}
|
|
|
serial = slot->serial;
|
|
|
@@ -1416,7 +1450,7 @@ static ssize_t spp_vfs_read(int fd, void * dst, size_t size)
|
|
|
slot = spp_find_slot_by_fd(fd);
|
|
|
if (!slot) {
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
- BTC_TRACE_ERROR("%s unable to find RFCOMM slot!\n", __func__);
|
|
|
+ BTC_TRACE_ERROR("%s unable to find RFCOMM slot!", __func__);
|
|
|
errno = ENOENT;
|
|
|
return -1;
|
|
|
}
|
|
|
@@ -1441,6 +1475,14 @@ static ssize_t spp_vfs_read(int fd, void * dst, size_t size)
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
+ /**
|
|
|
+ * If close_alarm is not NULL, it means that we have received the BTA_JV_RFCOMM_CLOSE_EVT.
|
|
|
+ * And we can trigger close_alarm immediately.
|
|
|
+ */
|
|
|
+ if (slot->close_alarm && osi_alarm_is_active(slot->close_alarm)) {
|
|
|
+ osi_alarm_cancel(slot->close_alarm);
|
|
|
+ osi_alarm_set(slot->close_alarm, 0);
|
|
|
+ }
|
|
|
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
|
|
|
break;
|
|
|
}
|