Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14664ef8 authored by ugo_yu's avatar ugo_yu Committed by Andre Eisenbach
Browse files

GATT: Deregister notification when a GATT connection is closed

Precondition:
1. Pair with specific HOGP mouse.

Steps:
1. Pair with HOGP mouse (iBuffalo BSMBB09DS)
2. Unpair the mouse.
3. Pair the mouse again.

Failure:
Pairing is successful, but the mouse won't connect.

Root Cause:
Some HOGP mice send notifications before the stack writes the
client characteristic configuration descriptor.
The Bluetooth stack doesn't deregister these notifiactions
when disconnecting.

Fix:
Deregister notifications when the GATT connection closes.

Fixes: 29111689
Change-Id: I520faeaa5fc396381cb248d3a2c49efbffa12261
parent 2eea6b15
Loading
Loading
Loading
Loading
+41 −4
Original line number Diff line number Diff line
@@ -802,7 +802,7 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 proto_mode,
                if (p_rpt->uuid == GATT_UUID_HID_REPORT &&
                    p_rpt->client_cfg_value == BTA_GATT_CLT_CONFIG_NOTIFICATION)
                {
                    APPL_TRACE_DEBUG("---> Deregister Report ID: %d", p_rpt->rpt_id);
                    APPL_TRACE_DEBUG("%s ---> Deregister Report ID: %d", __func__, p_rpt->rpt_id);
                    BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                                         p_rpt->char_inst_id);
                }
@@ -810,7 +810,7 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 proto_mode,
                else if (p_rpt->uuid == GATT_UUID_HID_BT_KB_INPUT ||
                         p_rpt->uuid == GATT_UUID_HID_BT_MOUSE_INPUT)
                {
                    APPL_TRACE_DEBUG("<--- Register Boot Report ID: %d", p_rpt->rpt_id);
                    APPL_TRACE_DEBUG("%s <--- Register Boot Report ID: %d", __func__, p_rpt->rpt_id);
                    BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                                       p_rpt->char_inst_id);
                }
@@ -822,14 +822,14 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 proto_mode,
                    p_rpt->client_cfg_value == BTA_GATT_CLT_CONFIG_NOTIFICATION)
                {

                    APPL_TRACE_DEBUG("---> Deregister Boot Report ID: %d", p_rpt->rpt_id);
                    APPL_TRACE_DEBUG("%s ---> Deregister Boot Report ID: %d", __func__, p_rpt->rpt_id);
                    BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                                         p_rpt->char_inst_id);
                }
                else if (p_rpt->uuid == GATT_UUID_HID_REPORT &&
                         p_rpt->client_cfg_value == BTA_GATT_CLT_CONFIG_NOTIFICATION)
                {
                    APPL_TRACE_DEBUG("<--- Register Report ID: %d", p_rpt->rpt_id);
                    APPL_TRACE_DEBUG("%s <--- Register Report ID: %d", __func__, p_rpt->rpt_id);
                    BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                                       p_rpt->char_inst_id);
                }
@@ -840,6 +840,41 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 proto_mode,
    }
}

/*******************************************************************************
**
** Function         bta_hh_le_deregister_input_notif
**
** Description      Deregister all notifications
**
*******************************************************************************/
void bta_hh_le_deregister_input_notif(tBTA_HH_DEV_CB *p_dev_cb)
{
    tBTA_HH_LE_RPT  *p_rpt = &p_dev_cb->hid_srvc.report[0];

    for (UINT8 i = 0; i < BTA_HH_LE_RPT_MAX; i++, p_rpt++)
    {
        if (p_rpt->rpt_type == BTA_HH_RPTT_INPUT)
        {
            if (p_rpt->uuid == GATT_UUID_HID_REPORT &&
                p_rpt->client_cfg_value == BTA_GATT_CLT_CONFIG_NOTIFICATION)
            {
                APPL_TRACE_DEBUG("%s ---> Deregister Report ID: %d", __func__, p_rpt->rpt_id);
                BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                                    p_rpt->char_inst_id);
            }
            else if ((p_rpt->uuid == GATT_UUID_HID_BT_KB_INPUT ||
                p_rpt->uuid == GATT_UUID_HID_BT_MOUSE_INPUT) &&
                p_rpt->client_cfg_value == BTA_GATT_CLT_CONFIG_NOTIFICATION)
            {
                APPL_TRACE_DEBUG("%s ---> Deregister Boot Report ID: %d", __func__, p_rpt->rpt_id);
                BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                                    p_rpt->char_inst_id);
            }
        }
    }
}


/*******************************************************************************
**
** Function         bta_hh_le_open_cmpl
@@ -2208,6 +2243,8 @@ void bta_hh_gatt_close(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
{
    tBTA_HH_CBDATA          disc_dat = {BTA_HH_OK, 0};

    /* deregister all notification */
    bta_hh_le_deregister_input_notif(p_cb);
    /* finaliza device driver */
    bta_hh_co_close(p_cb->hid_handle, p_cb->app_id);
    /* update total conn number */