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

Commit 56546a4c authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Set preferred PHY and read PHY implementation (3/3)

Test: manual
Bug: 30622771
Change-Id: I4267238a0b5c7bc373ae1846ebd19a716881a4ec
parent 1e200765
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -61,6 +61,9 @@ static void bta_gattc_cmpl_sendmsg(uint16_t conn_id, tGATTC_OPTYPE op,
static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB* p_clreg);
static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda);
static void bta_gattc_cong_cback(uint16_t conn_id, bool congested);
static void bta_gattc_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id,
                                       uint8_t tx_phy, uint8_t rx_phy,
                                       uint8_t status);

static tGATT_CBACK bta_gattc_cl_cback = {bta_gattc_conn_cback,
                                         bta_gattc_cmpl_cback,
@@ -68,7 +71,8 @@ static tGATT_CBACK bta_gattc_cl_cback = {bta_gattc_conn_cback,
                                         bta_gattc_disc_cmpl_cback,
                                         NULL,
                                         bta_gattc_enc_cmpl_cback,
                                         bta_gattc_cong_cback};
                                         bta_gattc_cong_cback,
                                         bta_gattc_phy_update_cback};

/* opcode(tGATTC_OPTYPE) order has to be comply with internal event order */
static uint16_t bta_gattc_opcode_to_int_evt[] = {
@@ -1700,3 +1704,22 @@ static void bta_gattc_cong_cback(uint16_t conn_id, bool congested) {
    }
  }
}

static void bta_gattc_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id,
                                       uint8_t tx_phy, uint8_t rx_phy,
                                       uint8_t status) {
  tBTA_GATTC_RCB* p_clreg = bta_gattc_cl_get_regcb(gatt_if);

  if (!p_clreg || !p_clreg->p_cback) {
    APPL_TRACE_ERROR("%s: client_if=%d not found", __func__, gatt_if);
    return;
  }

  tBTA_GATTC cb_data;
  cb_data.phy_update.conn_id = conn_id;
  cb_data.phy_update.server_if = gatt_if;
  cb_data.phy_update.tx_phy = tx_phy;
  cb_data.phy_update.rx_phy = rx_phy;
  cb_data.phy_update.status = status;
  (*p_clreg->p_cback)(BTA_GATTC_PHY_UPDATE_EVT, &cb_data);
}
+30 −4
Original line number Diff line number Diff line
@@ -49,10 +49,18 @@ static void bta_gatts_send_request_cback(uint16_t conn_id, uint32_t trans_id,
                                         tGATTS_REQ_TYPE req_type,
                                         tGATTS_DATA* p_data);
static void bta_gatts_cong_cback(uint16_t conn_id, bool congested);

static tGATT_CBACK bta_gatts_cback = {
    bta_gatts_conn_cback, NULL, NULL, NULL, bta_gatts_send_request_cback, NULL,
    bta_gatts_cong_cback};
static void bta_gatts_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id,
                                       uint8_t tx_phy, uint8_t rx_phy,
                                       uint8_t status);

static tGATT_CBACK bta_gatts_cback = {bta_gatts_conn_cback,
                                      NULL,
                                      NULL,
                                      NULL,
                                      bta_gatts_send_request_cback,
                                      NULL,
                                      bta_gatts_cong_cback,
                                      bta_gatts_phy_update_cback};

tGATT_APPL_INFO bta_gatts_nv_cback = {bta_gatts_nv_save_cback,
                                      bta_gatts_nv_srv_chg_cback};
@@ -605,6 +613,24 @@ static void bta_gatts_conn_cback(tGATT_IF gatt_if, BD_ADDR bda,
  }
}

static void bta_gatts_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id,
                                       uint8_t tx_phy, uint8_t rx_phy,
                                       uint8_t status) {
  tBTA_GATTS_RCB* p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if);
  if (!p_reg || !p_reg->p_cback) {
    APPL_TRACE_ERROR("%s: server_if=%d not found", __func__, gatt_if);
    return;
  }

  tBTA_GATTS cb_data;
  cb_data.phy_update.conn_id = conn_id;
  cb_data.phy_update.server_if = gatt_if;
  cb_data.phy_update.tx_phy = tx_phy;
  cb_data.phy_update.rx_phy = rx_phy;
  cb_data.phy_update.status = status;
  (*p_reg->p_cback)(BTA_GATTS_PHY_UPDATE_EVT, &cb_data);
}

/*******************************************************************************
 *
 * Function         bta_gatts_cong_cback
+20 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ typedef uint8_t tBTA_GATT_STATUS;
#define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
#define BTA_GATTC_CFG_MTU_EVT 18     /* configure MTU complete event */
#define BTA_GATTC_CONGEST_EVT 24     /* Congestion event */
#define BTA_GATTC_PHY_UPDATE_EVT 25  /* PHY change event */

typedef uint8_t tBTA_GATTC_EVT;

@@ -304,6 +305,14 @@ typedef struct {
  BD_ADDR remote_bda;
} tBTA_GATTC_ENC_CMPL_CB;

typedef struct {
  tBTA_GATTC_IF server_if;
  uint16_t conn_id;
  uint8_t tx_phy;
  uint8_t rx_phy;
  tBTA_GATT_STATUS status;
} tBTA_GATTC_PHY_UPDATE;

typedef union {
  tBTA_GATT_STATUS status;

@@ -320,6 +329,7 @@ typedef union {
  BD_ADDR remote_bda;         /* service change event */
  tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */
  tBTA_GATTC_CONGEST congest;
  tBTA_GATTC_PHY_UPDATE phy_update;
} tBTA_GATTC;

/* GATTC enable callback function */
@@ -349,6 +359,7 @@ typedef void(tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
#define BTA_GATTS_CANCEL_OPEN_EVT 17
#define BTA_GATTS_CLOSE_EVT 18
#define BTA_GATTS_CONGEST_EVT 20
#define BTA_GATTS_PHY_UPDATE_EVT 21

typedef uint8_t tBTA_GATTS_EVT;
typedef tGATT_IF tBTA_GATTS_IF;
@@ -487,6 +498,14 @@ typedef struct {
  tBTA_GATT_STATUS status; /* notification/indication status */
} tBTA_GATTS_CONF;

typedef struct {
  tBTA_GATTS_IF server_if;
  uint16_t conn_id;
  uint8_t tx_phy;
  uint8_t rx_phy;
  tBTA_GATT_STATUS status;
} tBTA_GATTS_PHY_UPDATE;

/* GATTS callback data */
typedef union {
  tBTA_GATTS_REG_OPER reg_oper;
@@ -497,6 +516,7 @@ typedef union {
  tBTA_GATTS_CONN conn;       /* BTA_GATTS_CONN_EVT */
  tBTA_GATTS_CONGEST congest; /* BTA_GATTS_CONGEST_EVT callback data */
  tBTA_GATTS_CONF confirm;    /* BTA_GATTS_CONF_EVT callback data */
  tBTA_GATTS_PHY_UPDATE phy_update; /* BTA_GATTS_PHY_UPDATE_EVT callback data */
} tBTA_GATTS;

/* GATTS enable callback function */
+26 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include <hardware/bt_gatt.h>

#include "bta_api.h"
#include "bta_closure_api.h"
#include "bta_gatt_api.h"
#include "btif_config.h"
#include "btif_dm.h"
@@ -179,6 +180,12 @@ void btif_gattc_upstreams_evt(uint16_t event, char* p_param) {
                p_data->congest.conn_id, p_data->congest.congested);
      break;

    case BTA_GATTC_PHY_UPDATE_EVT:
      HAL_CBACK(bt_gatt_callbacks, client->phy_updated_cb,
                p_data->phy_update.conn_id, p_data->phy_update.tx_phy,
                p_data->phy_update.rx_phy, p_data->phy_update.status);
      break;

    default:
      LOG_ERROR(LOG_TAG, "%s: Unhandled event (%d)!", __func__, event);
      break;
@@ -527,6 +534,23 @@ bt_status_t btif_gattc_conn_parameter_update(const bt_bdaddr_t* bd_addr,
           min_interval, max_interval, latency, timeout));
}

bt_status_t btif_gattc_set_preferred_phy(int conn_id, uint8_t tx_phy,
                                         uint8_t rx_phy, uint16_t phy_options) {
  CHECK_BTGATT_INIT();
  do_in_bta_thread(FROM_HERE, Bind(&GATTC_SetPreferredPHY, conn_id, tx_phy,
                                   rx_phy, phy_options));
  return BT_STATUS_SUCCESS;
}

bt_status_t btif_gattc_read_phy(
    int conn_id,
    base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb) {
  CHECK_BTGATT_INIT();
  do_in_bta_thread(FROM_HERE, Bind(&GATTC_ReadPHY, conn_id,
                                   jni_thread_wrapper(FROM_HERE, cb)));
  return BT_STATUS_SUCCESS;
}

int btif_gattc_get_device_type(const bt_bdaddr_t* bd_addr) {
  int device_type = 0;
  char bd_addr_str[18] = {0};
@@ -561,5 +585,7 @@ const btgatt_client_interface_t btgattClientInterface = {
    btif_gattc_get_device_type,
    btif_gattc_configure_mtu,
    btif_gattc_conn_parameter_update,
    btif_gattc_set_preferred_phy,
    btif_gattc_read_phy,
    btif_gattc_test_command,
    btif_gattc_get_gatt_db};
+27 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@

#include "bt_common.h"
#include "bta_api.h"
#include "bta_closure_api.h"
#include "bta_gatt_api.h"
#include "btif_config.h"
#include "btif_dm.h"
@@ -247,6 +248,12 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) {
      LOG_DEBUG(LOG_TAG, "%s: Empty event (%d)!", __func__, event);
      break;

    case BTA_GATTS_PHY_UPDATE_EVT:
      HAL_CBACK(bt_gatt_callbacks, server->phy_updated_cb,
                p_data->phy_update.conn_id, p_data->phy_update.tx_phy,
                p_data->phy_update.rx_phy, p_data->phy_update.status);
      break;

    default:
      LOG_ERROR(LOG_TAG, "%s: Unhandled event (%d)!", __func__, event);
      break;
@@ -430,9 +437,28 @@ static bt_status_t btif_gatts_send_response(int conn_id, int trans_id,
                               trans_id, status, *response));
}

static bt_status_t btif_gattc_set_preferred_phy(int conn_id, uint8_t tx_phy,
                                                uint8_t rx_phy,
                                                uint16_t phy_options) {
  CHECK_BTGATT_INIT();
  do_in_bta_thread(FROM_HERE, Bind(&GATTC_SetPreferredPHY, conn_id, tx_phy,
                                   rx_phy, phy_options));
  return BT_STATUS_SUCCESS;
}

static bt_status_t btif_gattc_read_phy(
    int conn_id,
    base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb) {
  CHECK_BTGATT_INIT();
  do_in_bta_thread(FROM_HERE, Bind(&GATTC_ReadPHY, conn_id,
                                   jni_thread_wrapper(FROM_HERE, cb)));
  return BT_STATUS_SUCCESS;
}

const btgatt_server_interface_t btgattServerInterface = {
    btif_gatts_register_app,   btif_gatts_unregister_app,
    btif_gatts_open,           btif_gatts_close,
    btif_gatts_add_service,    btif_gatts_stop_service,
    btif_gatts_delete_service, btif_gatts_send_indication,
    btif_gatts_send_response};
    btif_gatts_send_response,  btif_gattc_set_preferred_phy,
    btif_gattc_read_phy};
Loading