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

Commit 7ae134ef authored by Rahul Arya's avatar Rahul Arya Committed by Gerrit Code Review
Browse files

Merge "Fix issue where GATT callbacks are dropped"

parents 1d9ab0bb a8e1cb7d
Loading
Loading
Loading
Loading
+34 −29
Original line number Original line Diff line number Diff line
@@ -124,7 +124,7 @@ static bool btm_dev_encrypted(tBTM_SEC_DEV_REC* p_dev_rec);
static uint16_t btm_sec_set_serv_level4_flags(uint16_t cur_security,
static uint16_t btm_sec_set_serv_level4_flags(uint16_t cur_security,
                                              bool is_originator);
                                              bool is_originator);


static bool btm_sec_queue_encrypt_request(const RawAddress& bd_addr,
static void btm_sec_queue_encrypt_request(const RawAddress& bd_addr,
                                          tBT_TRANSPORT transport,
                                          tBT_TRANSPORT transport,
                                          tBTM_SEC_CALLBACK* p_callback,
                                          tBTM_SEC_CALLBACK* p_callback,
                                          void* p_ref_data,
                                          void* p_ref_data,
@@ -1044,10 +1044,9 @@ tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType(const RawAddress& bd_addr) {
 *
 *
 * Parameters:      bd_addr       - Address of the peer device
 * Parameters:      bd_addr       - Address of the peer device
 *                  transport     - Link transport
 *                  transport     - Link transport
 *                  p_callback    - Pointer to callback function called if
 *                  p_callback    - Pointer to callback function called after
 *                                  this function returns PENDING after required
 *                                  required procedures are completed. Can be
 *                                  procedures are completed.  Can be set to
 *                                  set to NULL if status is not desired.
 *                                  NULL if status is not desired.
 *                  p_ref_data    - pointer to any data the caller wishes to
 *                  p_ref_data    - pointer to any data the caller wishes to
 *                                  receive in the callback function upon
 *                                  receive in the callback function upon
 *                                  completion. can be set to NULL if not used.
 *                                  completion. can be set to NULL if not used.
@@ -1075,6 +1074,8 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
    return BTM_WRONG_MODE;
    return BTM_WRONG_MODE;
  }
  }


  auto owned_bd_addr = base::Owned(new RawAddress(bd_addr));

  switch (transport) {
  switch (transport) {
    case BT_TRANSPORT_BR_EDR:
    case BT_TRANSPORT_BR_EDR:
      if (p_dev_rec->hci_handle == HCI_INVALID_HANDLE) {
      if (p_dev_rec->hci_handle == HCI_INVALID_HANDLE) {
@@ -1082,8 +1083,11 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
            "Security Manager: BTM_SetEncryption not connected peer:%s "
            "Security Manager: BTM_SetEncryption not connected peer:%s "
            "transport:%s",
            "transport:%s",
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
        if (p_callback)
        if (p_callback) {
          (*p_callback)(&bd_addr, transport, p_ref_data, BTM_WRONG_MODE);
          do_in_main_thread(FROM_HERE,
                            base::Bind(p_callback, std::move(owned_bd_addr),
                                       transport, p_ref_data, BTM_WRONG_MODE));
        }
        return BTM_WRONG_MODE;
        return BTM_WRONG_MODE;
      }
      }
      if (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) {
      if (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) {
@@ -1091,8 +1095,11 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
            "Security Manager: BTM_SetEncryption already encrypted peer:%s "
            "Security Manager: BTM_SetEncryption already encrypted peer:%s "
            "transport:%s",
            "transport:%s",
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
        if (*p_callback)
        if (p_callback) {
          (*p_callback)(&bd_addr, transport, p_ref_data, BTM_SUCCESS);
          do_in_main_thread(FROM_HERE,
                            base::Bind(p_callback, std::move(owned_bd_addr),
                                       transport, p_ref_data, BTM_SUCCESS));
        }
        return BTM_SUCCESS;
        return BTM_SUCCESS;
      }
      }
      break;
      break;
@@ -1103,9 +1110,11 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
            "Security Manager: BTM_SetEncryption not connected peer:%s "
            "Security Manager: BTM_SetEncryption not connected peer:%s "
            "transport:%s",
            "transport:%s",
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
        if (p_callback)
        if (p_callback) {
          (*p_callback)(&bd_addr, transport, p_ref_data, BTM_WRONG_MODE);
          do_in_main_thread(FROM_HERE,

                            base::Bind(p_callback, std::move(owned_bd_addr),
                                       transport, p_ref_data, BTM_WRONG_MODE));
        }
        return BTM_WRONG_MODE;
        return BTM_WRONG_MODE;
      }
      }
      if (p_dev_rec->sec_flags & BTM_SEC_LE_ENCRYPTED) {
      if (p_dev_rec->sec_flags & BTM_SEC_LE_ENCRYPTED) {
@@ -1113,9 +1122,11 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
            "Security Manager: BTM_SetEncryption already encrypted peer:%s "
            "Security Manager: BTM_SetEncryption already encrypted peer:%s "
            "transport:%s",
            "transport:%s",
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
        if (*p_callback)
        if (p_callback) {
          (*p_callback)(&bd_addr, transport, p_ref_data, BTM_SUCCESS);
          do_in_main_thread(FROM_HERE,

                            base::Bind(p_callback, std::move(owned_bd_addr),
                                       transport, p_ref_data, BTM_SUCCESS));
        }
        return BTM_SUCCESS;
        return BTM_SUCCESS;
      }
      }
      break;
      break;
@@ -1128,16 +1139,10 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
  /* enqueue security request if security is active */
  /* enqueue security request if security is active */
  if (p_dev_rec->p_callback || (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE)) {
  if (p_dev_rec->p_callback || (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE)) {
    LOG_WARN("Security Manager: BTM_SetEncryption busy, enqueue request");
    LOG_WARN("Security Manager: BTM_SetEncryption busy, enqueue request");
    if (btm_sec_queue_encrypt_request(bd_addr, transport, p_callback,
    btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data,
                                      p_ref_data, sec_act)) {
                                  sec_act);
    LOG_INFO("Queued start encryption");
    LOG_INFO("Queued start encryption");
    return BTM_CMD_STARTED;
    return BTM_CMD_STARTED;
    } else {
      LOG_WARN("Unable to enqueue start encryption request");
      if (p_callback)
        (*p_callback)(&bd_addr, transport, p_ref_data, BTM_NO_RESOURCES);
      return BTM_NO_RESOURCES;
    }
  }
  }


  p_dev_rec->p_callback = p_callback;
  p_dev_rec->p_callback = p_callback;
@@ -1186,7 +1191,9 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
                  ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
                  ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
                  bt_transport_text(transport).c_str());
                  bt_transport_text(transport).c_str());
        p_dev_rec->p_callback = nullptr;
        p_dev_rec->p_callback = nullptr;
        (*p_callback)(&bd_addr, transport, p_dev_rec->p_ref_data, rc);
        do_in_main_thread(FROM_HERE,
                          base::Bind(p_callback, std::move(owned_bd_addr),
                                     transport, p_dev_rec->p_ref_data, rc));
      }
      }
      break;
      break;
  }
  }
@@ -4890,7 +4897,7 @@ static bool btm_sec_check_prefetch_pin(tBTM_SEC_DEV_REC* p_dev_rec) {
 *                  process pending.
 *                  process pending.
 *
 *
 ******************************************************************************/
 ******************************************************************************/
static bool btm_sec_queue_encrypt_request(const RawAddress& bd_addr,
static void btm_sec_queue_encrypt_request(const RawAddress& bd_addr,
                                          tBT_TRANSPORT transport,
                                          tBT_TRANSPORT transport,
                                          tBTM_SEC_CALLBACK* p_callback,
                                          tBTM_SEC_CALLBACK* p_callback,
                                          void* p_ref_data,
                                          void* p_ref_data,
@@ -4905,8 +4912,6 @@ static bool btm_sec_queue_encrypt_request(const RawAddress& bd_addr,
  p_e->sec_act = sec_act;
  p_e->sec_act = sec_act;
  p_e->bd_addr = bd_addr;
  p_e->bd_addr = bd_addr;
  fixed_queue_enqueue(btm_cb.sec_pending_q, p_e);
  fixed_queue_enqueue(btm_cb.sec_pending_q, p_e);

  return true;
}
}


/*******************************************************************************
/*******************************************************************************