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

Commit cc2d3e76 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes Icf1a6f56,I1dad4b78,I2ac68e30,Ic7083219

* changes:
  btm: Indicate scan start/stop
  TEST_MAPPING add net_test_stack_btm
  Land btm control block history
  Use btm_cb Init/Free
parents 834aeb60 a4e9bb6b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@
    },
    {
      "name" : "net_test_btif_hf_client_service"
    },
    {
      "name" : "net_test_stack_btm"
    }
  ]
}
+7 −1
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@
 *
 ******************************************************************************/

#include <log/log.h>
#define LOG_TAG "bluetooth"

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,6 +34,7 @@

#include "common/time_util.h"
#include "device/include/controller.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"

#include "advertise_data_parser.h"
@@ -425,6 +427,8 @@ void BTM_CancelInquiry(void) {
    return;
  }

  btm_cb.history_->Push("%-32s", "Inquiry scan stopped");

  tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars;
  BTM_TRACE_API("BTM_CancelInquiry called");

@@ -505,6 +509,8 @@ tBTM_STATUS BTM_StartInquiry(tBTM_INQ_RESULTS_CB* p_results_cb,
    return BTM_WRONG_MODE;
  }

  btm_cb.history_->Push("%-32s", "Inquiry scan started");

  /* Save the inquiry parameters to be used upon the completion of
   * setting/clearing the inquiry filter */
  p_inq->inqparms = {};
+0 −1
Original line number Diff line number Diff line
@@ -329,7 +329,6 @@ typedef struct {
    memset(&api, 0, sizeof(api));
    memset(p_rmt_name_callback, 0, sizeof(p_rmt_name_callback));
    memset(&pin_code, 0, sizeof(pin_code));
    pairing_bda = RawAddress::kEmpty;
    memset(sec_serv_rec, 0, sizeof(sec_serv_rec));

    connecting_bda = RawAddress::kEmpty;
+13 −47
Original line number Diff line number Diff line
@@ -22,10 +22,12 @@
 *
 ******************************************************************************/

#include <string.h>
#include <memory>
#include <string>
#include "bt_target.h"
#include "bt_types.h"
#include "btm_int.h"
#include "stack/btm/btm_int_types.h"
#include "stack_config.h"

/* Global BTM control block structure
@@ -53,28 +55,9 @@ extern void wipe_secrets_and_remove(tBTM_SEC_DEV_REC* p_dev_rec);
 *
 ******************************************************************************/
void btm_init(void) {
  /* All fields are cleared; nonzero fields are reinitialized in appropriate
   * function */
  memset(&btm_cb, 0, sizeof(tBTM_CB));
  btm_cb.btm_inq_vars.remote_name_timer = nullptr;

  btm_cb.page_queue = fixed_queue_new(SIZE_MAX);
  btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX);
  btm_cb.sec_collision_timer = alarm_new("btm.sec_collision_timer");
  btm_cb.pairing_timer = alarm_new("btm.pairing_timer");

#if defined(BTM_INITIAL_TRACE_LEVEL)
  btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL;
#else
  btm_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */
#endif
  /* Security Manager Database and Structures */
  if (stack_config_get_interface()->get_pts_secure_only_mode())
    btm_cb.security_mode = BTM_SEC_MODE_SC;
  else
    btm_cb.security_mode = BTM_SEC_MODE_SP;
  btm_cb.pairing_bda = RawAddress::kAny;
  btm_cb.sec_dev_rec = list_new(osi_free);
  btm_cb.Init(stack_config_get_interface()->get_pts_secure_only_mode()
                  ? BTM_SEC_MODE_SC
                  : BTM_SEC_MODE_SP);

  /* Initialize BTM component structures */
  btm_inq_db_init(); /* Inquiry Database and Structures */
@@ -82,35 +65,18 @@ void btm_init(void) {
  btm_sco_init(); /* SCO Database and Structures (If included) */

  btm_dev_init(); /* Device Manager Structures & HCI_Reset */

  btm_cb.history_ = std::make_shared<TimestampedStringCircularBuffer>(40);
  CHECK(btm_cb.history_ != nullptr);
  btm_cb.history_->Push(std::string("Initialized btm history"));
}

/** This function is called to free dynamic memory and system resource allocated by btm_init */
void btm_free(void) {
  btm_cb.history_.reset();

  btm_dev_free();
  btm_inq_db_free();

  fixed_queue_free(btm_cb.page_queue, NULL);
  btm_cb.page_queue = NULL;

  fixed_queue_free(btm_cb.sec_pending_q, NULL);
  btm_cb.sec_pending_q = NULL;

  list_node_t* end = list_end(btm_cb.sec_dev_rec);
  list_node_t* node = list_begin(btm_cb.sec_dev_rec);
  while (node != end) {
    tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(list_node(node));

    // we do list_remove in, must grab next before removing
    node = list_next(node);
    wipe_secrets_and_remove(p_dev_rec);
  }

  list_free(btm_cb.sec_dev_rec);
  btm_cb.sec_dev_rec = NULL;

  alarm_free(btm_cb.sec_collision_timer);
  btm_cb.sec_collision_timer = NULL;

  alarm_free(btm_cb.pairing_timer);
  btm_cb.pairing_timer = NULL;
  btm_cb.Free();
}