fix(hid): Fixed HID repeatedly reporting the close event

This commit is contained in:
yangfeng
2026-03-13 16:26:41 +08:00
parent 17b5ebc442
commit d5ebefbe0e
2 changed files with 16 additions and 9 deletions
@@ -250,7 +250,10 @@ static void hidd_l2cif_connect_cfm(uint16_t cid, uint16_t result)
} }
hidd_conn_disconnect(); hidd_conn_disconnect();
hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, HID_L2CAP_CONN_FAIL | (uint32_t)result, NULL); p_hcon->disc_reason = HID_L2CAP_CONN_FAIL | (uint32_t)result;
if (p_hcon->conn_state == HID_CONN_STATE_UNUSED) {
hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, p_hcon->disc_reason, NULL);
}
return; return;
} }
/* CTRL connect conf */ /* CTRL connect conf */
@@ -329,7 +332,6 @@ static void hidd_l2cif_config_ind(uint16_t cid, tL2CAP_CFG_INFO *p_cfg)
static void hidd_l2cif_config_cfm(uint16_t cid, tL2CAP_CFG_INFO *p_cfg) static void hidd_l2cif_config_cfm(uint16_t cid, tL2CAP_CFG_INFO *p_cfg)
{ {
tHID_CONN *p_hcon; tHID_CONN *p_hcon;
uint32_t reason;
HIDD_TRACE_EVENT("%s: cid=%04x pcfg->result=%d", __func__, cid, p_cfg->result); HIDD_TRACE_EVENT("%s: cid=%04x pcfg->result=%d", __func__, cid, p_cfg->result);
p_hcon = &hd_cb.device.conn; p_hcon = &hd_cb.device.conn;
if (p_hcon->ctrl_cid != cid && p_hcon->intr_cid != cid) { if (p_hcon->ctrl_cid != cid && p_hcon->intr_cid != cid) {
@@ -353,8 +355,10 @@ static void hidd_l2cif_config_cfm(uint16_t cid, tL2CAP_CFG_INFO *p_cfg)
} else if (p_cfg->result != L2CAP_CFG_OK) { } else if (p_cfg->result != L2CAP_CFG_OK) {
HIDD_TRACE_WARNING("%s: config failed, disconnecting", __func__); HIDD_TRACE_WARNING("%s: config failed, disconnecting", __func__);
hidd_conn_disconnect(); hidd_conn_disconnect();
reason = HID_L2CAP_CFG_FAIL | (uint32_t)p_cfg->result; p_hcon->disc_reason = HID_L2CAP_CFG_FAIL | (uint32_t)p_cfg->result;
hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, reason, NULL); if (p_hcon->conn_state == HID_CONN_STATE_UNUSED) {
hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, p_hcon->disc_reason, NULL);
}
return; return;
} }
// update flags // update flags
@@ -353,7 +353,6 @@ static void hidh_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result)
{ {
UINT8 dhandle; UINT8 dhandle;
tHID_CONN *p_hcon = NULL; tHID_CONN *p_hcon = NULL;
UINT32 reason;
tHID_HOST_DEV_CTB *p_dev = NULL; tHID_HOST_DEV_CTB *p_dev = NULL;
/* Find CCB based on CID, and verify we are in a state to accept this message */ /* Find CCB based on CID, and verify we are in a state to accept this message */
@@ -388,8 +387,10 @@ static void hidh_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result)
} else } else
#endif #endif
{ {
reason = HID_L2CAP_CONN_FAIL | (UINT32) result ; p_hcon->disc_reason = HID_L2CAP_CONN_FAIL | (UINT32) result;
hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; if (p_hcon->conn_state == HID_CONN_STATE_UNUSED) {
hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, p_hcon->disc_reason, NULL ) ;
}
} }
return; return;
} }
@@ -521,8 +522,10 @@ static void hidh_l2cif_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
/* If configuration failed, disconnect the channel(s) */ /* If configuration failed, disconnect the channel(s) */
if (p_cfg->result != L2CAP_CFG_OK) { if (p_cfg->result != L2CAP_CFG_OK) {
hidh_conn_disconnect (dhandle); hidh_conn_disconnect (dhandle);
reason = HID_L2CAP_CFG_FAIL | (UINT32) p_cfg->result ; p_hcon->disc_reason = HID_L2CAP_CFG_FAIL | (UINT32) p_cfg->result ;
hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; if (p_hcon->conn_state == HID_CONN_STATE_UNUSED) {
hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, p_hcon->disc_reason, NULL ) ;
}
return; return;
} }