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

Commit 1453168d authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Unify LE advertising instance identifiers

Up till now, we had three numbers associated with each advertising
instance: client_id, inst_id, and cbindex. We also had special structure
mapping each of those numbers to another.

From now on, when registering advertiser, we'll grab next free
advertising instance id and make advertiser_id equal to it. Thanks to
this, we can remove all the mapping and have just one number associated
with each advertising instance.

This also means we no longer need to pass *p_ref value to the BTM layer
with each request, as advertiser_id is equal to inst_id.

Bug: 30622771
Change-Id: Ied71bff36e30d6c6ce4ca3e62d46ba96320cf597
parent 9f6c1fb7
Loading
Loading
Loading
Loading
+16 −17
Original line number Diff line number Diff line
@@ -4810,6 +4810,13 @@ void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data)
    BTM_BleBroadcast(p_data->ble_observe.start);
}


void bta_dm_ble_multi_adv_register(tBTA_BLE_MULTI_ADV_CBACK *p_cback) {
    bta_dm_cb.p_multi_adv_cback = p_cback;

    BTM_BleAdvRegister((tBTM_BLE_MULTI_ADV_CBACK *)p_cback);
}

/*******************************************************************************
**
** Function         bta_dm_ble_multi_adv_enb
@@ -4819,20 +4826,18 @@ void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data)
** Parameters:
**
*******************************************************************************/
void bta_dm_ble_multi_adv_enb(tBTA_BLE_ADV_PARAMS *p_params,
                              tBTA_BLE_MULTI_ADV_CBACK *p_cback,void *p_ref)
void bta_dm_ble_multi_adv_enb(uint8_t inst_id, tBTA_BLE_ADV_PARAMS *p_params)
{
    tBTM_STATUS btm_status = 0;

    bta_dm_cb.p_multi_adv_cback = p_cback;
    if (BTM_BleMaxMultiAdvInstanceCount() > 0 && NULL != p_ref) {
        btm_status = BTM_BleEnableAdvInstance((tBTM_BLE_ADV_PARAMS *)p_params,
                                              p_cback, p_ref);
    if (BTM_BleMaxMultiAdvInstanceCount() > 0) {
        btm_status = BTM_BleEnableAdvInstance(inst_id,
                                              (tBTM_BLE_ADV_PARAMS *)p_params);
    }

    if (BTM_CMD_STARTED != btm_status) {
        bta_dm_cb.p_multi_adv_cback(BTA_BLE_MULTI_ADV_ENB_EVT, 0xFF,
                                    p_ref, BTA_FAILURE);
        bta_dm_cb.p_multi_adv_cback(BTA_BLE_MULTI_ADV_ENB_EVT, inst_id,
                                    BTA_FAILURE);
    }
}
/*******************************************************************************
@@ -4847,7 +4852,6 @@ void bta_dm_ble_multi_adv_enb(tBTA_BLE_ADV_PARAMS *p_params,
void bta_dm_ble_multi_adv_upd_param(uint8_t inst_id, tBTA_BLE_ADV_PARAMS *p_params)
{
    tBTM_STATUS btm_status = 0;
    void *p_ref = NULL;

    if (BTM_BleMaxMultiAdvInstanceCount() > 0 && inst_id > 0
        && inst_id < BTM_BleMaxMultiAdvInstanceCount()) {
@@ -4856,8 +4860,7 @@ void bta_dm_ble_multi_adv_upd_param(uint8_t inst_id, tBTA_BLE_ADV_PARAMS *p_para
    }

    if (BTM_CMD_STARTED != btm_status) {
       p_ref = btm_ble_multi_adv_get_ref(inst_id);
       bta_dm_cb.p_multi_adv_cback(BTA_BLE_MULTI_ADV_PARAM_EVT, inst_id, p_ref, BTA_FAILURE);
       bta_dm_cb.p_multi_adv_cback(BTA_BLE_MULTI_ADV_PARAM_EVT, inst_id, BTA_FAILURE);
    }
}
/*******************************************************************************
@@ -4874,7 +4877,6 @@ void bta_dm_ble_multi_adv_data(uint8_t inst_id, bool is_scan_rsp,
                               tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA data)
{
    tBTM_STATUS btm_status = 0;
    void *p_ref = NULL;

    if (BTM_BleMaxMultiAdvInstanceCount() > 0 && inst_id > 0
        && inst_id < BTM_BleMaxMultiAdvInstanceCount()) {
@@ -4883,9 +4885,8 @@ void bta_dm_ble_multi_adv_data(uint8_t inst_id, bool is_scan_rsp,
    }

    if (BTM_CMD_STARTED != btm_status) {
       p_ref = btm_ble_multi_adv_get_ref(inst_id);
       bta_dm_cb.p_multi_adv_cback(BTA_BLE_MULTI_ADV_DATA_EVT,
                                   inst_id, p_ref, BTA_FAILURE);
                                   inst_id, BTA_FAILURE);
    }
}
/*******************************************************************************
@@ -4900,7 +4901,6 @@ void bta_dm_ble_multi_adv_data(uint8_t inst_id, bool is_scan_rsp,
void btm_dm_ble_multi_adv_disable(uint8_t inst_id)
{
    tBTM_STATUS btm_status = 0;
    void *p_ref = NULL;

    if (BTM_BleMaxMultiAdvInstanceCount() > 0 && inst_id > 0
        && inst_id < BTM_BleMaxMultiAdvInstanceCount()) {
@@ -4908,9 +4908,8 @@ void btm_dm_ble_multi_adv_disable(uint8_t inst_id)
    }

    if (BTM_CMD_STARTED != btm_status) {
       p_ref = btm_ble_multi_adv_get_ref(inst_id);
       bta_dm_cb.p_multi_adv_cback(BTA_BLE_MULTI_ADV_DISABLE_EVT,
                                   inst_id, p_ref, BTA_FAILURE);
                                   inst_id, BTA_FAILURE);
    }
}

+18 −9
Original line number Diff line number Diff line
@@ -1362,6 +1362,19 @@ void BTA_DmBleConfigLocalPrivacy(bool privacy_enable)
}

#if (BLE_INCLUDED == TRUE)

/*******************************************************************************
**
** Register an advertising instance, status will be returned in |p_cback|
** callback, with assigned id, if operation succeeds. Instance is freed when
** advertising is disabled by calling |BTA_BleDisableAdvInstance|, or when any
** of the operations fails.
*******************************************************************************/
void BTA_BleAdvRegisterInstance(tBTA_BLE_MULTI_ADV_CBACK *p_cback) {
    do_in_bta_thread(FROM_HERE,
        base::Bind(&bta_dm_ble_multi_adv_register, p_cback));
}

/*******************************************************************************
**
** Function         BTA_BleEnableAdvInstance
@@ -1369,16 +1382,13 @@ void BTA_DmBleConfigLocalPrivacy(bool privacy_enable)
** Description      This function enable a Multi-ADV instance with the specififed
**                  adv parameters
**
** Parameters       p_params: pointer to the adv parameter structure.
**                  p_cback: callback function associated to this adv instance.
**                  p_ref: reference data pointer to this adv instance.
** Parameters       inst_id: Adv instance to update the parameter.
**                  p_params: pointer to the adv parameter structure.
**
** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
**
*******************************************************************************/
void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
                               tBTA_BLE_MULTI_ADV_CBACK *p_cback,
                               void *p_ref)
void BTA_BleEnableAdvInstance (uint8_t inst_id, tBTA_BLE_ADV_PARAMS *p_params)
{
    APPL_TRACE_API("%s", __func__);

@@ -1386,11 +1396,10 @@ void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
        tBTA_BLE_ADV_PARAMS *params = new tBTA_BLE_ADV_PARAMS;
        memcpy(params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
        do_in_bta_thread(FROM_HERE,
            base::Bind(&bta_dm_ble_multi_adv_enb, base::Owned(params),
                       p_cback, p_ref));
            base::Bind(&bta_dm_ble_multi_adv_enb, inst_id, base::Owned(params)));
    } else {
        do_in_bta_thread(FROM_HERE,
            base::Bind(&bta_dm_ble_multi_adv_enb, nullptr, p_cback, p_ref));
            base::Bind(&bta_dm_ble_multi_adv_enb, inst_id, nullptr));
    }
}

+3 −3
Original line number Diff line number Diff line
@@ -1055,15 +1055,15 @@ extern void bta_dm_cfg_filter_cond (tBTA_DM_MSG *p_data);
extern void bta_dm_scan_filter_param_setup (tBTA_DM_MSG *p_data);
extern void bta_dm_enable_scan_filter(tBTA_DM_MSG *p_data);
#endif
extern void bta_dm_ble_multi_adv_register(tBTA_BLE_MULTI_ADV_CBACK *p_cback);
extern void btm_dm_ble_multi_adv_disable(uint8_t inst_id);
extern void bta_dm_ble_multi_adv_data(uint8_t inst_id, bool is_scan_rsp,
                                      tBTA_BLE_AD_MASK data_mask,
                                      tBTA_BLE_ADV_DATA data);
extern void bta_dm_ble_multi_adv_upd_param(uint8_t inst_id,
                                           tBTA_BLE_ADV_PARAMS *p_params);
extern void bta_dm_ble_multi_adv_enb(tBTA_BLE_ADV_PARAMS *p_params,
                                     tBTA_BLE_MULTI_ADV_CBACK *p_cback,
                                     void *p_ref);
extern void bta_dm_ble_multi_adv_enb(uint8_t inst_id,
                                     tBTA_BLE_ADV_PARAMS *p_params);

extern void bta_dm_ble_setup_storage(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_enable_batch_scan(tBTA_DM_MSG * p_data);
+13 −6
Original line number Diff line number Diff line
@@ -909,12 +909,13 @@ typedef void (tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data);
#define BTA_BLE_MULTI_ADV_DISABLE_EVT       2
#define BTA_BLE_MULTI_ADV_PARAM_EVT         3
#define BTA_BLE_MULTI_ADV_DATA_EVT          4
#define BTA_BLE_MULTI_ADV_REG_EVT           5

typedef uint8_t tBTA_BLE_MULTI_ADV_EVT;

/* multi adv callback */
typedef void (tBTA_BLE_MULTI_ADV_CBACK)(tBTA_BLE_MULTI_ADV_EVT event,
                                        uint8_t inst_id, void *p_ref, tBTA_STATUS status);
                                        uint8_t inst_id, tBTA_STATUS status);
typedef uint32_t tBTA_DM_BLE_REF_VALUE;

#define BTA_DM_BLE_PF_ENABLE_EVT       BTM_BLE_PF_ENABLE
@@ -2045,6 +2046,14 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask,
*******************************************************************************/
extern void BTA_DmBleBroadcast (bool start);

/*******************************************************************************
**
** Register an advertising instance, status will be returned in |p_cback|
** callback, with assigned id, if operation succeeds. Instance is freed when
** advertising is disabled by calling |BTA_BleDisableAdvInstance|, or when any
** of the operations fails.
*******************************************************************************/
extern void BTA_BleAdvRegisterInstance(tBTA_BLE_MULTI_ADV_CBACK *p_cback);

/*******************************************************************************
**
@@ -2052,15 +2061,13 @@ extern void BTA_DmBleBroadcast (bool start);
**
** Description      This function enables the Multi ADV instance feature
**
** Parameters       p_params Pointer to ADV param user defined structure
**                  p_cback  Pointer to Multi ADV callback structure
**                  p_ref - Reference pointer
** Parameters       inst_id Instance ID
**                  p_params Pointer to ADV param user defined structure
**
** Returns          None
**
*******************************************************************************/
extern void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
                                tBTA_BLE_MULTI_ADV_CBACK *p_cback,void *p_ref);
extern void BTA_BleEnableAdvInstance(uint8_t inst_id, tBTA_BLE_ADV_PARAMS *p_params);

/*******************************************************************************
**
+0 −5
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ typedef struct

typedef struct
{
    int8_t *clntif_map;
    // Includes the stored data for standard LE instance
    btgatt_multi_adv_inst_cb *inst_cb;

@@ -73,10 +72,6 @@ extern btgatt_multi_adv_common_data *btif_obtain_multi_adv_data_cb();

extern void btif_gattc_incr_app_count(void);
extern void btif_gattc_decr_app_count(void);
extern int btif_multi_adv_add_instid_map(int advertiser_id, int inst_id,
        bool gen_temp_instid);
extern int btif_multi_adv_instid_for_clientif(int advertiser_id);
extern int btif_gattc_obtain_idx_for_datacb(int value, int clnt_inst_index);
extern void btif_gattc_clear_clientif(int advertiser_id, bool stop_timer);
extern void btif_gattc_cleanup_inst_cb(int inst_id, bool stop_timer);
extern void btif_gattc_cleanup_multi_inst_cb(btgatt_multi_adv_inst_cb *p_inst_cb,
Loading