OSDN Git Service

hci_legacy_interface: Add Start/Cancel Inquiry
authorChris Manton <cmanton@google.com>
Tue, 5 Jan 2021 18:20:53 +0000 (10:20 -0800)
committerChris Manton <cmanton@google.com>
Thu, 7 Jan 2021 00:56:35 +0000 (16:56 -0800)
Towards testable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run --host

Change-Id: Ieb9aa232ccc29de4aec15b722ff7a105859a1ca4

stack/btm/btm_inq.cc
stack/hcic/hcicmds.cc
stack/include/hcimsgs.h

index 9f44be8..83e26f2 100644 (file)
 #include "btm_int.h"
 #include "btu.h"
 #include "hcidefs.h"
-#include "hcimsgs.h"
 #include "main/shim/btm_api.h"
 #include "main/shim/shim.h"
 #include "stack/include/acl_api.h"
+#include "stack/include/hcimsgs.h"
 #include "stack/include/inq_hci_link_interface.h"
 
 extern void btm_inq_remote_name_timer_timeout(void* data);
@@ -443,7 +443,7 @@ void BTM_CancelInquiry(void) {
     p_inq->p_inq_cmpl_cb = NULL;    /* Do not notify caller anymore */
 
     if ((p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK) != 0) {
-      btsnd_hcic_inq_cancel();
+      bluetooth::legacy::hci::GetInterface().InquiryCancel();
     }
     if ((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0)
       btm_ble_stop_inquiry();
@@ -546,7 +546,8 @@ tBTM_STATUS BTM_StartInquiry(tBTM_INQ_RESULTS_CB* p_results_cb,
   p_inq->max_bd_entries =
       (uint16_t)(BT_DEFAULT_BUFFER_SIZE / sizeof(tINQ_BDADDR));
 
-  btsnd_hcic_inquiry(general_inq_lap, p_inq->inqparms.duration, 0);
+  bluetooth::legacy::hci::GetInterface().StartInquiry(
+      general_inq_lap, p_inq->inqparms.duration, 0);
   return BTM_CMD_STARTED;
 }
 
@@ -842,7 +843,7 @@ void btm_inq_stop_on_ssp(void) {
       if (btm_cb.btm_inq_vars.inq_active & normal_active) {
         /* can not call BTM_CancelInquiry() here. We need to report inquiry
          * complete evt */
-        btsnd_hcic_inq_cancel();
+        bluetooth::legacy::hci::GetInterface().InquiryCancel();
       }
     }
     /* do not allow inquiry to start */
index 89cc148..e207700 100644 (file)
@@ -35,8 +35,8 @@
 #include "btm_int.h" /* Included for UIPC_* macro definitions */
 #include "stack/include/acl_hci_link_interface.h"
 
-void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration,
-                        uint8_t response_cnt) {
+static void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration,
+                               uint8_t response_cnt) {
   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
   uint8_t* pp = (uint8_t*)(p + 1);
 
@@ -53,7 +53,7 @@ void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration,
   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
 }
 
-void btsnd_hcic_inq_cancel(void) {
+static void btsnd_hcic_inq_cancel(void) {
   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
   uint8_t* pp = (uint8_t*)(p + 1);
 
@@ -1432,6 +1432,8 @@ void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, uint8_t len,
 }
 
 bluetooth::legacy::hci::Interface interface_ = {
+    .StartInquiry = btsnd_hcic_inquiry,      // OCF 0x0001
+    .InquiryCancel = btsnd_hcic_inq_cancel,  // OCF 0x0002
     .Disconnect = btsnd_hcic_disconnect,
     .StartRoleSwitch = btsnd_hcic_switch_role,
 };
index ea126df..a13f3c4 100644 (file)
@@ -30,9 +30,6 @@ void bte_main_hci_send(BT_HDR* p_msg, uint16_t event);
 
 /* Message by message.... */
 
-extern void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration,
-                               uint8_t response_cnt);
-
 #define HCIC_PARAM_SIZE_INQUIRY 5
 
 #define HCIC_INQ_INQ_LAP_OFF 0
@@ -41,7 +38,6 @@ extern void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration,
 /* Inquiry */
 
 /* Inquiry Cancel */
-extern void btsnd_hcic_inq_cancel(void);
 
 #define HCIC_PARAM_SIZE_INQ_CANCEL 0
 
@@ -85,6 +81,9 @@ namespace bluetooth {
 namespace legacy {
 namespace hci {
 struct Interface {
+  void (*StartInquiry)(const LAP inq_lap, uint8_t duration,
+                       uint8_t response_cnt);
+  void (*InquiryCancel)();
   void (*Disconnect)(uint16_t handle, uint8_t reason);
   void (*StartRoleSwitch)(const RawAddress& bd_addr, uint8_t role);
 };