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

Commit 17f791e6 authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge "Use command_with_cb for Vendor commands"

parents a68dc2cd 5a865e98
Loading
Loading
Loading
Loading
+1 −31
Original line number Diff line number Diff line
@@ -453,41 +453,11 @@ uint8_t* BTM_ReadDeviceClass(void) {
 ******************************************************************************/
void BTM_VendorSpecificCommand(uint16_t opcode, uint8_t param_len,
                               uint8_t* p_param_buf, tBTM_VSC_CMPL_CB* p_cb) {
  /* Allocate a buffer to hold HCI command plus the callback function */
  void* p_buf = osi_malloc(sizeof(BT_HDR) + sizeof(tBTM_CMPL_CB*) + param_len +
                           HCIC_PREAMBLE_SIZE);

  BTM_TRACE_EVENT("BTM: %s: Opcode: 0x%04X, ParamLen: %i.", __func__, opcode,
                  param_len);

  /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */
  btsnd_hcic_vendor_spec_cmd(p_buf, opcode, param_len, p_param_buf,
                             (void*)p_cb);
}

/*******************************************************************************
 *
 * Function         btm_vsc_complete
 *
 * Description      This function is called when local HCI Vendor Specific
 *                  Command complete message is received from the HCI.
 *
 * Returns          void
 *
 ******************************************************************************/
void btm_vsc_complete(uint8_t* p, uint16_t opcode, uint16_t evt_len,
                      tBTM_VSC_CMPL_CB* p_vsc_cplt_cback) {
  tBTM_VSC_CMPL vcs_cplt_params;

  /* If there was a callback address for vcs complete, call it */
  if (p_vsc_cplt_cback) {
    /* Pass paramters to the callback function */
    vcs_cplt_params.opcode = opcode;     /* Number of bytes in return info */
    vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */
    vcs_cplt_params.p_param_buf = p;
    (*p_vsc_cplt_cback)(
        &vcs_cplt_params); /* Call the VSC complete callback function */
  }
  btsnd_hcic_vendor_spec_cmd(opcode, param_len, p_param_buf, p_cb);
}

/*******************************************************************************
+5 −23
Original line number Diff line number Diff line
@@ -638,25 +638,16 @@ void btu_hcif_send_cmd(UNUSED_ATTR uint8_t controller_id, const BT_HDR* p_buf) {

  uint16_t opcode;
  const uint8_t* stream = p_buf->data + p_buf->offset;
  void* vsc_callback = NULL;

  STREAM_TO_UINT16(opcode, stream);

  // Eww...horrible hackery here
  /* If command was a VSC, then extract command_complete callback */
  if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC ||
      (opcode == HCI_BLE_RAND) || (opcode == HCI_BLE_ENCRYPT)) {
    vsc_callback = *((void**)(p_buf + 1));
  }

  // Skip parameter length before logging
  stream++;
  btu_hcif_log_command_metrics(opcode, stream,
                               android::bluetooth::hci::STATUS_UNKNOWN, false);

  bluetooth::shim::hci_layer_get_interface()->transmit_command(
      p_buf, btu_hcif_command_complete_evt, btu_hcif_command_status_evt,
      vsc_callback);
      p_buf, btu_hcif_command_complete_evt, btu_hcif_command_status_evt, NULL);
}

using hci_cmd_cb = base::OnceCallback<void(
@@ -1168,16 +1159,9 @@ static void btu_hcif_hdl_command_complete(uint16_t opcode, uint8_t* p,
    case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT:
      break;

    case HCI_BLE_CREATE_CONN_CANCEL:
      LOG_ERROR(
          "Unexpectedly received command complete for opcode:0x%02x that "
          "should not be "
          "handled here",
          opcode);
      break;
    default:
      if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
        btm_vsc_complete(p, opcode, evt_len, (tBTM_VSC_CMPL_CB*)p_cplt_cback);
      LOG_ERROR("Command complete for opcode:0x%02x should not be handled here",
                opcode);
      break;
  }
}
@@ -1328,10 +1312,8 @@ static void btu_hcif_hdl_command_status(uint16_t opcode, uint8_t status,
      break;

    default:
      if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) {
        btm_vsc_complete(&status, opcode, 1,
                         (tBTM_VSC_CMPL_CB*)p_vsc_status_cback);
      }
      LOG_ERROR("Command status for opcode:0x%02x should not be handled here",
                opcode);
  }
}

+20 −20
Original line number Diff line number Diff line
@@ -1644,28 +1644,28 @@ void btsnd_hcic_write_pagescan_type(uint8_t type) {
  btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
}

/* Must have room to store BT_HDR + max VSC length + callback pointer */
#if (HCI_CMD_BUF_SIZE < 268)
#error "HCI_CMD_BUF_SIZE must be larger than 268"
#endif

void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, uint8_t len,
                                uint8_t* p_data, void* p_cmd_cplt_cback) {
  BT_HDR* p = (BT_HDR*)buffer;
  uint8_t* pp = (uint8_t*)(p + 1);

  p->len = HCIC_PREAMBLE_SIZE + len;
  p->offset = sizeof(void*);

  *((void**)pp) =
      p_cmd_cplt_cback; /* Store command complete callback in buffer */
  pp += sizeof(void*);  /* Skip over callback pointer */

  UINT16_TO_STREAM(pp, HCI_GRP_VENDOR_SPECIFIC | opcode);
  UINT8_TO_STREAM(pp, len);
  ARRAY_TO_STREAM(pp, p_data, len);

  btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
static void btsnd_hcic_vendor_spec_complete(tBTM_VSC_CMPL_CB* p_vsc_cplt_cback,
                                            uint16_t opcode, uint8_t* data,
                                            uint16_t len) {
  /* If there was a callback address for vcs complete, call it */
  if (p_vsc_cplt_cback) {
    tBTM_VSC_CMPL vcs_cplt_params;
    vcs_cplt_params.opcode = opcode;
    vcs_cplt_params.param_len = len;
    vcs_cplt_params.p_param_buf = data;
    /* Call the VSC complete callback function */
    (*p_vsc_cplt_cback)(&vcs_cplt_params);
  }
}

void btsnd_hcic_vendor_spec_cmd(uint16_t opcode, uint8_t len, uint8_t* p_data,
                                tBTM_VSC_CMPL_CB* p_cmd_cplt_cback) {
  uint16_t v_opcode = HCI_GRP_VENDOR_SPECIFIC | opcode;

  btu_hcif_send_cmd_with_cb(
      FROM_HERE, v_opcode, p_data, len,
      base::BindOnce(&btsnd_hcic_vendor_spec_complete,
                     base::Unretained(p_cmd_cplt_cback), v_opcode));
}

void btsnd_hcic_configure_data_path(uint8_t data_path_direction,
+0 −2
Original line number Diff line number Diff line
@@ -25,6 +25,4 @@

void btm_delete_stored_link_key_complete(uint8_t* p);
void btm_vendor_specific_evt(const uint8_t* p, uint8_t evt_len);
void btm_vsc_complete(uint8_t* p, uint16_t cc_opcode, uint16_t evt_len,
                      tBTM_VSC_CMPL_CB* p_vsc_cplt_cback);
void btm_read_local_name_complete(uint8_t* p, uint16_t evt_len);
+3 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_name.h"
#include "stack/include/bt_octets.h"
#include "stack/include/btm_api_types.h"
#include "types/ble_address_with_type.h"
#include "types/raw_address.h"

@@ -287,8 +288,8 @@ void btsnd_hcic_enhanced_accept_synchronous_connection(
#define HCID_GET_EVENT(u16) \
  (uint8_t)(((u16) >> HCI_DATA_EVENT_OFFSET) & HCI_DATA_EVENT_MASK)

void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, uint8_t len,
                                uint8_t* p_data, void* p_cmd_cplt_cback);
void btsnd_hcic_vendor_spec_cmd(uint16_t opcode, uint8_t len, uint8_t* p_data,
                                tBTM_VSC_CMPL_CB* p_cmd_cplt_cback);

/*******************************************************************************
 * BLE Commands
Loading