mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-03 14:01:53 +00:00
fix SPP server bugs when the BTC layer can not allocate a slot for the listen port
This commit is contained in:
@@ -105,6 +105,8 @@ typedef int (tPORT_DATA_CO_CALLBACK) (UINT16 port_handle, UINT8 *p_buf, UINT16
|
||||
|
||||
typedef void (tPORT_CALLBACK) (UINT32 code, UINT16 port_handle);
|
||||
|
||||
typedef void (tPORT_MGMT_CALLBACK) (UINT32 code, UINT16 port_handle, void* data);
|
||||
|
||||
/*
|
||||
** Define events that registered application can receive in the callback
|
||||
*/
|
||||
@@ -219,7 +221,7 @@ extern "C"
|
||||
extern int RFCOMM_CreateConnection (UINT16 uuid, UINT8 scn,
|
||||
BOOLEAN is_server, UINT16 mtu,
|
||||
BD_ADDR bd_addr, UINT16 *p_handle,
|
||||
tPORT_CALLBACK *p_mgmt_cb);
|
||||
tPORT_MGMT_CALLBACK *p_mgmt_cb);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
|
||||
@@ -188,7 +188,7 @@ struct t_port_info {
|
||||
|
||||
UINT32 ev_mask; /* Event mask for the callback */
|
||||
tPORT_CALLBACK *p_callback; /* Pointer to users callback function */
|
||||
tPORT_CALLBACK *p_mgmt_callback; /* Callback function to receive connection up/down */
|
||||
tPORT_MGMT_CALLBACK *p_mgmt_callback; /* Callback function to receive connection up/down */
|
||||
tPORT_DATA_CALLBACK *p_data_callback; /* Callback function to receive data indications */
|
||||
tPORT_DATA_CO_CALLBACK *p_data_co_callback; /* Callback function with callouts and flowctrl */
|
||||
UINT16 credit_tx; /* Flow control credits for tx path */
|
||||
|
||||
@@ -103,7 +103,7 @@ static const char *result_code_strings[] = {
|
||||
*******************************************************************************/
|
||||
int RFCOMM_CreateConnection (UINT16 uuid, UINT8 scn, BOOLEAN is_server,
|
||||
UINT16 mtu, BD_ADDR bd_addr, UINT16 *p_handle,
|
||||
tPORT_CALLBACK *p_mgmt_cb)
|
||||
tPORT_MGMT_CALLBACK *p_mgmt_cb)
|
||||
{
|
||||
tPORT *p_port;
|
||||
int i;
|
||||
|
||||
@@ -175,7 +175,7 @@ void port_start_close (tPORT *p_port)
|
||||
if ((p_mcb == NULL) || (p_port->rfc.state == RFC_STATE_CLOSED)) {
|
||||
/* Call management callback function before calling port_release_port() to clear tPort */
|
||||
if (p_port->p_mgmt_callback) {
|
||||
p_port->p_mgmt_callback (PORT_CLOSED, p_port->inx);
|
||||
p_port->p_mgmt_callback (PORT_CLOSED, p_port->inx, NULL);
|
||||
}
|
||||
|
||||
port_release_port (p_port);
|
||||
@@ -230,7 +230,7 @@ void PORT_StartCnf (tRFC_MCB *p_mcb, UINT16 result)
|
||||
}
|
||||
|
||||
if (p_port->p_mgmt_callback) {
|
||||
p_port->p_mgmt_callback (PORT_START_FAILED, p_port->inx);
|
||||
p_port->p_mgmt_callback (PORT_START_FAILED, p_port->inx, NULL);
|
||||
}
|
||||
|
||||
port_release_port (p_port);
|
||||
@@ -427,6 +427,7 @@ void PORT_ParNegCnf (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT8 cl, UINT8 k)
|
||||
void PORT_DlcEstablishInd (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu)
|
||||
{
|
||||
tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci);
|
||||
BOOLEAN accept = true;
|
||||
|
||||
RFCOMM_TRACE_DEBUG ("PORT_DlcEstablishInd p_mcb:%p, dlci:%d mtu:%di, p_port:%p", p_mcb, dlci, mtu, p_port);
|
||||
RFCOMM_TRACE_DEBUG ("PORT_DlcEstablishInd p_mcb addr:%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
@@ -451,7 +452,7 @@ void PORT_DlcEstablishInd (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu)
|
||||
/* If there was an inactivity timer running for MCB stop it */
|
||||
rfc_timer_stop (p_mcb);
|
||||
|
||||
RFCOMM_DlcEstablishRsp (p_mcb, dlci, p_port->mtu, RFCOMM_SUCCESS);
|
||||
// RFCOMM_DlcEstablishRsp (p_mcb, dlci, p_port->mtu, RFCOMM_SUCCESS);
|
||||
|
||||
/* This is the server side. If application wants to know when connection */
|
||||
/* is established, thats the place */
|
||||
@@ -460,10 +461,15 @@ void PORT_DlcEstablishInd (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu)
|
||||
}
|
||||
|
||||
if (p_port->p_mgmt_callback) {
|
||||
p_port->p_mgmt_callback (PORT_SUCCESS, p_port->inx);
|
||||
p_port->p_mgmt_callback (PORT_SUCCESS, p_port->inx, &accept);
|
||||
}
|
||||
|
||||
p_port->state = PORT_STATE_OPENED;
|
||||
if (accept) {
|
||||
RFCOMM_DlcEstablishRsp(p_mcb, dlci, p_port->mtu, RFCOMM_SUCCESS);
|
||||
p_port->state = PORT_STATE_OPENED;
|
||||
} else {
|
||||
RFCOMM_DlcEstablishRsp(p_mcb, dlci, 0, RFCOMM_LOW_RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -506,7 +512,7 @@ void PORT_DlcEstablishCnf (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT16 resul
|
||||
}
|
||||
|
||||
if (p_port->p_mgmt_callback) {
|
||||
p_port->p_mgmt_callback (PORT_SUCCESS, p_port->inx);
|
||||
p_port->p_mgmt_callback (PORT_SUCCESS, p_port->inx, NULL);
|
||||
}
|
||||
|
||||
p_port->state = PORT_STATE_OPENED;
|
||||
@@ -1063,14 +1069,15 @@ void port_rfc_closed (tPORT *p_port, UINT8 res)
|
||||
p_port->p_callback (events, p_port->inx);
|
||||
}
|
||||
|
||||
if (p_port->p_mgmt_callback) {
|
||||
p_port->p_mgmt_callback (res, p_port->inx);
|
||||
if (p_port->p_mgmt_callback && !(p_port->state == PORT_STATE_CLOSED && p_port->is_server)) {
|
||||
p_port->p_mgmt_callback(res, p_port->inx, NULL);
|
||||
}
|
||||
|
||||
p_port->rfc.state = RFC_STATE_CLOSED;
|
||||
|
||||
RFCOMM_TRACE_WARNING ("%s RFCOMM connection in state %d closed: %s (res: %d)",
|
||||
__func__, p_port->state, PORT_GetResultString(res), res);
|
||||
RFCOMM_TRACE_WARNING("%s RFCOMM connection in server:%d state %d closed: %s (res: %d)",
|
||||
__func__, p_port->is_server, p_port->state, PORT_GetResultString(res),
|
||||
res);
|
||||
|
||||
port_release_port (p_port);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg);
|
||||
*******************************************************************************/
|
||||
void rfc_mx_sm_execute (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
|
||||
{
|
||||
RFCOMM_TRACE_DEBUG("%s st:%d, evt:%d\n", __func__, p_mcb->state, event);
|
||||
|
||||
switch (p_mcb->state) {
|
||||
case RFC_MX_STATE_IDLE:
|
||||
rfc_mx_sm_state_idle (p_mcb, event, p_data);
|
||||
|
||||
@@ -62,6 +62,8 @@ static void rfc_set_port_state(tPORT_STATE *port_pars, MX_FRAME *p_frame);
|
||||
*******************************************************************************/
|
||||
void rfc_port_sm_execute (tPORT *p_port, UINT16 event, void *p_data)
|
||||
{
|
||||
RFCOMM_TRACE_DEBUG("%s st:%d, evt:%d\n", __func__, p_port->rfc.state, event);
|
||||
|
||||
if (!p_port) {
|
||||
RFCOMM_TRACE_WARNING ("NULL port event %d", event);
|
||||
return;
|
||||
@@ -296,6 +298,11 @@ void rfc_port_sm_term_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data)
|
||||
if (*((UINT8 *)p_data) != RFCOMM_SUCCESS) {
|
||||
if (p_port->rfc.p_mcb) {
|
||||
rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, TRUE);
|
||||
if (*((UINT8 *)p_data) == RFCOMM_LOW_RESOURCES) {
|
||||
port_rfc_closed(p_port, PORT_NO_RESOURCES);
|
||||
} else {
|
||||
port_rfc_closed(p_port, PORT_UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
|
||||
|
||||
@@ -201,7 +201,6 @@ void osi_free_fun(void *p){
|
||||
*******************************************************************************/
|
||||
void rfc_release_multiplexer_channel (tRFC_MCB *p_mcb)
|
||||
{
|
||||
|
||||
rfc_timer_free (p_mcb);
|
||||
|
||||
fixed_queue_free(p_mcb->cmd_q, osi_free_fun);
|
||||
|
||||
Reference in New Issue
Block a user