diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 38f81a566e..3863edb341 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -1356,6 +1356,13 @@ config BT_BLE_FEAT_CTE_CONNECTION_EN help Transmission of CTE by ACL connection +config BT_BLE_FEAT_POWER_CONTROL + bool "Enable BLE power control feature" + depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_BLE_POWER_CONTROL_SUPPORTED) || BT_CONTROLLER_DISABLED)) # NOERROR + default n + help + Enable BLE power control feature + config BT_BLE_HIGH_DUTY_ADV_INTERVAL bool "Enable BLE high duty advertising interval feature" depends on BT_BLE_ENABLED diff --git a/components/bt/host/bluedroid/api/esp_gap_ble_api.c b/components/bt/host/bluedroid/api/esp_gap_ble_api.c index 278b3bd9d1..b4e2f2ff03 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -1803,3 +1803,106 @@ esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask) return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +esp_err_t esp_ble_gap_enhanced_read_transmit_power_level(uint16_t conn_handle, esp_ble_tx_power_phy_t phy) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ENH_READ_TRANS_POWER_LEVEL; + arg.enh_read_trans_pwr_level.conn_handle = conn_handle; + arg.enh_read_trans_pwr_level.phy = phy; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_gap_read_remote_transmit_power_level(uint16_t conn_handle, esp_ble_tx_power_phy_t phy) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_READ_REM_TRANS_POWER_LEVEL; + arg.read_rem_trans_pwr_level.conn_handle = conn_handle; + arg.read_rem_trans_pwr_level.phy = phy; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_gap_set_path_loss_reporting_params(esp_ble_path_loss_rpt_params_t *path_loss_rpt_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_SET_PATH_LOSS_REPORT_PARAMS; + arg.set_path_loss_rpt_params.conn_handle = path_loss_rpt_params->conn_handle; + arg.set_path_loss_rpt_params.high_threshold = path_loss_rpt_params->high_threshold; + arg.set_path_loss_rpt_params.high_hysteresis = path_loss_rpt_params->high_hysteresis; + arg.set_path_loss_rpt_params.low_threshold = path_loss_rpt_params->low_threshold; + arg.set_path_loss_rpt_params.low_hysteresis = path_loss_rpt_params->low_hysteresis; + arg.set_path_loss_rpt_params.min_time_spent = path_loss_rpt_params->min_time_spent; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_gap_set_path_loss_reporting_enable(uint16_t conn_handle, bool enable) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_SET_PATH_LOSS_REPORTING_EN; + arg.set_path_loss_rpt_en.conn_handle = conn_handle; + arg.set_path_loss_rpt_en.enable = enable; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_gap_set_transmit_power_reporting_enable(uint16_t conn_handle, bool local_enable, bool remote_enable) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_SET_TRANS_POWER_REPORTING_EN; + arg.set_trans_pwr_rpting_en.conn_handle = conn_handle; + arg.set_trans_pwr_rpting_en.local_enable = local_enable; + arg.set_trans_pwr_rpting_en.remote_enable = remote_enable; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index 48ebbf52a0..5800625eec 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -232,6 +232,14 @@ typedef enum { ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT, /*!< When set CSA support complete, the event comes */ ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT, /*!< When set vendor event mask complete, the event comes */ ESP_GAP_BLE_VENDOR_HCI_EVT, /*!< When BLE vendor HCI event received, the event comes */ + // BLE power control + ESP_GAP_BLE_ENH_READ_TRANS_PWR_LEVEL_EVT, /*!< When reading the current and maximum transmit power levels of the local Controller complete, the event comes */ + ESP_GAP_BLE_READ_REMOTE_TRANS_PWR_LEVEL_EVT, /*!< When reading the transmit power level used by the remote Controller on the ACL connection complete, the event comes */ + ESP_GAP_BLE_SET_PATH_LOSS_RPTING_PARAMS_EVT, /*!< when set the path loss threshold reporting parameters complete, the event comes */ + ESP_GAP_BLE_SET_PATH_LOSS_RPTING_ENABLE_EVT, /*!< when enable or disable path loss reporting complete, the event comes */ + ESP_GAP_BLE_SET_TRANS_PWR_RPTING_ENABLE_EVT, /*!< when enable or disable the reporting to the local Host of transmit power level changes complete, the event comes */ + ESP_GAP_BLE_PATH_LOSS_THRESHOLD_EVT, /*!< when receive a path loss threshold crossing, the event comes */ + ESP_GAP_BLE_TRANS_PWR_RPTING_EVT, /*!< when receive a transmit power level report, the event comes */ ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */ } esp_gap_ble_cb_event_t; @@ -1078,6 +1086,41 @@ typedef enum{ ESP_BLE_DEVICE_PRIVACY_MODE = 0X01, /*!< Device Privacy Mode for peer device */ } esp_ble_privacy_mode_t; +/** +* @brief path loss report parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t high_threshold; /*!< High threshold for the path loss (dB) */ + uint8_t high_hysteresis; /*!< Hysteresis value for the high threshold (dB) */ + uint8_t low_threshold; /*!< Low threshold for the path loss (dB) */ + uint8_t low_hysteresis; /*!< Hysteresis value for the low threshold (dB) */ + uint16_t min_time_spent; /*!< Minimum time in number of connection events to be observed + once the path loss crosses the threshold before an event is generated */ +} esp_ble_path_loss_rpt_params_t; + +typedef enum { + /*!< No PHY is set, should not be used */ + ESP_BLE_CONN_TX_POWER_PHY_NONE = 0, + /*!< LE 1M PHY */ + ESP_BLE_CONN_TX_POWER_PHY_1M = 0x01, + /*!< LE 2M PHY */ + ESP_BLE_CONN_TX_POWER_PHY_2M = 0x02, + /*!< LE Coded PHY using S=8 coding */ + ESP_BLE_CONN_TX_POWER_PHY_CODED_S8 = 0x03, + /*!< LE Coded PHY using S=2 coding */ + ESP_BLE_CONN_TX_POWER_PHY_CODED_S2 = 0x04, +} esp_ble_tx_power_phy_t; + +typedef enum { + /*!< Low zone entered */ + ESP_BLE_CONN_PATH_LOSS_ZONE_ENTERED_LOW = 0x00, + /*!< Middle zone entered */ + ESP_BLE_CONN_PATH_LOSS_ZONE_ENTERED_MIDDLE = 0x01, + /*!< High zone entered */ + ESP_BLE_CONN_PATH_LOSS_ZONE_ENTERED_HIGH = 0x02, +} esp_ble_path_loss_zone_t; + /** * @brief Gap callback parameters union */ @@ -1597,6 +1640,82 @@ typedef union { uint8_t param_len; /*!< The length of the event parameter buffer */ uint8_t *param_buf; /*!< The pointer of the event parameter buffer */ } vendor_hci_evt; /*!< Event parameter buffer of ESP_GAP_BLE_VENDOR_HCI_EVT */ +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + /** + * @brief ESP_GAP_BLE_ENH_READ_TRANS_PWR_LEVEL_EVT + */ + struct ble_enh_read_trans_pwr_level_param { + esp_bt_status_t status; /*!< Indicate enhance reading transmit power level complete status, status = (controller error code | 0x100) if status is not equal to 0 */ + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t phy; /*!< 1M, 2M, Coded S2 or Coded S8 phy + 0x01: LE 1M PHY + 0x02: LE 2M PHY + 0x03: LE Coded PHY with S=8 data coding + 0x04: LE Coded PHY with S=2 data coding + */ + int8_t cur_tx_pwr_level; /*!< Current transmit power level, Range: -127 to 20, Units: dBm */ + int8_t max_tx_pwr_level; /*!< Maximum transmit power level, Range: -127 to 20, Units: dBm */ + } enh_trans_pwr_level_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_READ_REMOTE_TRANS_PWR_LEVEL_EVT + */ + struct ble_read_remote_trans_pwr_level_param { + esp_bt_status_t status; /*!< Indicate reading remote transmit power level complete status, status = (controller error code | 0x100) if status is not equal to 0 */ + } read_remote_trans_pwr_level_cmpl; /*!< Event parameter of ESP_GAP_BLE_READ_REMOTE_TRANS_PWR_LEVEL_EVT */ + /** + * @brief ESP_GAP_BLE_SET_PATH_LOSS_RPTING_PARAMS_EVT + */ + struct ble_set_path_loss_rpting_param { + esp_bt_status_t status; /*!< Indicate setting path loss reporting paramwters complete status, status = (controller error code | 0x100) if status is not equal to 0 */ + uint16_t conn_handle; /*!< The ACL connection identifier */ + } set_path_loss_rpting_params; /*!< Event parameter of ESP_GAP_BLE_SET_PATH_LOSS_RPTING_PARAMS_EVT */ + /** + * @brief ESP_GAP_BLE_SET_PATH_LOSS_RPTING_ENABLE_EVT + */ + struct ble_set_path_loss_rpting_enable { + esp_bt_status_t status; /*!< Indicate setting path loss reporting enable complete status, status = (controller error code | 0x100) if status is not equal to 0 */ + uint16_t conn_handle; /*!< The ACL connection identifier */ + } set_path_loss_rpting_enable; /*!< Event parameter of ESP_GAP_BLE_SET_PATH_LOSS_RPTING_ENABLE_EVT */ + /** + * @brief ESP_GAP_BLE_SET_TRANS_PWR_RPTING_ENABLE_EVT + */ + struct ble_set_trans_pwr_rpting_enable { + esp_bt_status_t status; /*!< Indicate setting transmit power reporting enable complete status, status = (controller error code | 0x100) if status is not equal to 0 */ + uint16_t conn_handle; /*!< The ACL connection identifier */ + } set_trans_pwr_rpting_enable; /*!< Event parameter of ESP_GAP_BLE_SET_TRANS_PWR_RPTING_ENABLE_EVT */ + /** + * @brief ESP_GAP_BLE_PATH_LOSS_THRESHOLD_EVT + */ + struct ble_path_loss_thres_evt { + uint16_t conn_handle; /*!< The ACL connection identifier */ + uint8_t cur_path_loss; /*!< Current path loss (always zero or positive), Units: dB */ + esp_ble_path_loss_zone_t zone_entered; /*!< which zone was entered. If cur_path_loss is set to 0xFF then zone_entered shall be ignored */ + } path_loss_thres_evt; /*!< Event parameter of ESP_GAP_BLE_PATH_LOSS_THRESHOLD_EVT */ + /** + * @brief ESP_GAP_BLE_TRANS_PWR_RPTING_EVT + */ + struct ble_trans_power_report_evt { + esp_bt_status_t status; /*!< Indicate esp_ble_gap_read_remote_transmit_power_level() command success, status = (controller error code | 0x100) if status is not equal to 0 */ + uint16_t conn_handle; /*!< The ACL connection identifier */ + uint8_t reason; /*!< indicate why the event was sent and the device whose transmit power level is being reported + 0x00: Local transmit power changed + 0x01: Remote transmit power changed + 0x02: esp_ble_gap_read_remote_transmit_power_level() command completed, + In this case, the phy, tx_power_level, tx_power_level_flag and delta parameters shall refer to the remote device */ + esp_ble_tx_power_phy_t phy; /*!< 1M, 2M, Coded S2 or Coded S8 phy + 0x01: LE 1M PHY + 0x02: LE 2M PHY + 0x03: LE Coded PHY with S=8 data coding + 0x04: LE Coded PHY with S=2 data coding */ + int8_t tx_power_level; /*!< Transmit power level, range: -127 to 20, units: dBm + 0x7E: Remote device is not managing power levels on this PHY + 0x7F: Transmit power level is not available */ + uint8_t tx_power_level_flag; /*!< whether the transmit power level that is being reported has reached its minimum and/or maximum level */ + int8_t delta; /*!< Change in transmit power level (positive indicates increased power, negative indicates decreased power, zero indicates unchanged) Units: dB. + 0x7F: Change is not available or is out of range */ + } trans_power_report_evt; /*!< Event parameter of ESP_GAP_BLE_TRANS_PWR_RPTING_EVT */ + +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) } esp_ble_gap_cb_param_t; /** @@ -2810,6 +2929,74 @@ esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select); */ esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask); +/** + * @brief This function is used to read the current and maximum transmit power levels of the local Controller. + * + * + * @param[in] conn_handle: The ACL connection identified. + * @param[in] phy: 1M, 2M, Coded S2 or Coded S8. + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_enhanced_read_transmit_power_level(uint16_t conn_handle, esp_ble_tx_power_phy_t phy); + +/** + * @brief This function is used to read the transmit power level used by the remote Controller on the ACL connection. + * + * + * @param[in] conn_handle: The ACL connection identifier. + * @param[in] phy: 1M, 2M, Coded S2 or Coded S8. + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_read_remote_transmit_power_level(uint16_t conn_handle, esp_ble_tx_power_phy_t phy); + +/** + * @brief This function is used to set the path loss threshold reporting parameters. + * + * + * @param[in] path_loss_rpt_params: The path loss threshold reporting parameters. + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_set_path_loss_reporting_params(esp_ble_path_loss_rpt_params_t *path_loss_rpt_params); + +/** + * @brief This function is used to enable or disable path loss reporting. + * + * + * @param[in] conn_handle: The ACL connection identifier. + * @param[in] enable: Reporting disabled or enabled. + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_set_path_loss_reporting_enable(uint16_t conn_handle, bool enable); + +/** + * @brief This function is used to enable or disable the reporting to the local Host of transmit power level changes in the local and remote Controllers. + * + * + * @param[in] conn_handle: The ACL connection identifier. + * @param[in] local_enable: Disable or enable local transmit power reports. + * @param[in] remote_enable: Disable or enable remote transmit power reports. + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_set_transmit_power_reporting_enable(uint16_t conn_handle, bool local_enable, bool remote_enable); + + #ifdef __cplusplus } #endif diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index d20a009610..b68b81dbf6 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -6259,6 +6259,34 @@ void bta_dm_ble_read_cte_ant_infor(tBTA_DM_MSG *p_data) } #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void bta_dm_api_enh_read_trans_power_level(tBTA_DM_MSG *p_data) +{ + BTM_BleEnhReadTransPowerLevel(p_data->enh_read_trans_pwr_level.conn_handle, p_data->enh_read_trans_pwr_level.phy); +} + +void bta_dm_api_read_rem_trans_power_level(tBTA_DM_MSG *p_data) +{ + BTM_BleReadRemoteTransPwrLevel(p_data->remote_trans_pwr_level.conn_handle, p_data->remote_trans_pwr_level.phy); +} + +void bta_dm_api_set_path_loss_report_params(tBTA_DM_MSG *p_data) +{ + BTM_BleSetPathLossRptParams(p_data->path_loss_rpt_params.conn_handle, p_data->path_loss_rpt_params.high_threshold, p_data->path_loss_rpt_params.high_hysteresis, + p_data->path_loss_rpt_params.low_threshold, p_data->path_loss_rpt_params.low_hysteresis, p_data->path_loss_rpt_params.min_time_spent); +} + +void bta_dm_api_set_path_loss_reporting_en(tBTA_DM_MSG *p_data) +{ + BTM_BleSetPathLossRptEnable(p_data->path_loss_rpt_en.conn_handle, p_data->path_loss_rpt_en.enable); +} + +void bta_dm_api_set_trans_power_reporting_en(tBTA_DM_MSG *p_data) +{ + BTM_BleSetTransPwrRptEnable(p_data->trans_pwr_rpt_en.conn_handle, p_data->trans_pwr_rpt_en.local_enable, p_data->trans_pwr_rpt_en.remote_enable); +} +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #if (BLE_HOST_SETUP_STORAGE_EN == TRUE) /******************************************************************************* ** diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index 0ace88486f..6600eca464 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -3001,6 +3001,79 @@ void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_ } } +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void BTA_DmBleGapEnhReadTransPwrLevel(uint16_t conn_handle, uint8_t phy) +{ + tBTA_DM_API_BLE_ENH_READ_TANS_PWR_LEVEL *p_msg; + + if ((p_msg = (tBTA_DM_API_BLE_ENH_READ_TANS_PWR_LEVEL *)osi_malloc(sizeof(tBTA_DM_API_BLE_ENH_READ_TANS_PWR_LEVEL))) + != NULL) { + p_msg->hdr.event = BTA_DM_API_ENH_READ_TRANS_POWER_LEVEL; + p_msg->conn_handle = conn_handle; + p_msg->phy = phy; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapReadRemoteTransPwrLevel(uint16_t conn_handle, uint8_t phy) +{ + tBTA_DM_API_BLE_READ_REMOTE_TANS_PWR_LEVEL *p_msg; + + if ((p_msg = (tBTA_DM_API_BLE_READ_REMOTE_TANS_PWR_LEVEL *)osi_malloc(sizeof(tBTA_DM_API_BLE_READ_REMOTE_TANS_PWR_LEVEL))) + != NULL) { + p_msg->hdr.event = BTA_DM_API_READ_REM_TRANS_POWER_LEVEL; + p_msg->conn_handle = conn_handle; + p_msg->phy = phy; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapSetPathLossRptParams(uint16_t conn_handle, uint8_t high_threshold, uint8_t high_hysteresis, + uint8_t low_threshold, uint8_t low_hysteresis, uint16_t min_time_spent) +{ + tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_PARAMS))) + != NULL) { + p_msg->hdr.event = BTA_DM_API_SET_PATH_LOSS_REPORT_PARAMS; + p_msg->conn_handle = conn_handle; + p_msg->high_threshold = high_threshold; + p_msg->high_hysteresis = high_hysteresis; + p_msg->low_threshold = low_threshold; + p_msg->low_hysteresis = low_hysteresis; + p_msg->min_time_spent = min_time_spent; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapSetPathLossRptEnable(uint16_t conn_handle, uint8_t enable) +{ + tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_ENABLE *p_msg; + + if ((p_msg = (tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_ENABLE *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_ENABLE))) + != NULL) { + p_msg->hdr.event = BTA_DM_API_SET_PATH_LOSS_REPORTING_EN; + p_msg->conn_handle = conn_handle; + p_msg->enable = enable; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapSetTransPwrRptEnable(uint16_t conn_handle, uint8_t local_enable, uint8_t remote_enable) +{ + tBTA_DM_API_BLE_SET_TRANS_PWR_RPT_ENABLE *p_msg; + + if ((p_msg = (tBTA_DM_API_BLE_SET_TRANS_PWR_RPT_ENABLE *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_TRANS_PWR_RPT_ENABLE))) + != NULL) { + p_msg->hdr.event = BTA_DM_API_SET_TRANS_POWER_REPORTING_EN; + p_msg->conn_handle = conn_handle; + p_msg->local_enable = local_enable; + p_msg->remote_enable = remote_enable; + bta_sys_sendmsg(p_msg); + } +} +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + /******************************************************************************* ** ** Function BTA_VendorInit diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c index dda188e996..798459349f 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c @@ -324,6 +324,13 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { #endif // #if (BLE_FEAT_CTE_CONNECTION_EN == TRUE) bta_dm_ble_read_cte_ant_infor, /* BTA_DM_API_CTE_READ_ANTENNA_INFOR */ #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + bta_dm_api_enh_read_trans_power_level, /* BTA_DM_API_ENH_READ_TRANS_POWER_LEVEL */ + bta_dm_api_read_rem_trans_power_level, /* BTA_DM_API_READ_REM_TRANS_POWER_LEVEL */ + bta_dm_api_set_path_loss_report_params, /* BTA_DM_API_SET_PATH_LOSS_REPORT_PARAMS */ + bta_dm_api_set_path_loss_reporting_en, /* BTA_DM_API_SET_PATH_LOSS_REPORTING_EN */ + bta_dm_api_set_trans_power_reporting_en, /* BTA_DM_API_SET_TRANS_POWER_REPORTING_EN */ +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) }; diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index 2a73fc688e..e88ab17e68 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -318,6 +318,13 @@ enum { #endif // #if (BLE_FEAT_CTE_CONNECTION_EN == TRUE) BTA_DM_API_CTE_READ_ANTENNA_INFOR, #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + BTA_DM_API_ENH_READ_TRANS_POWER_LEVEL, + BTA_DM_API_READ_REM_TRANS_POWER_LEVEL, + BTA_DM_API_SET_PATH_LOSS_REPORT_PARAMS, + BTA_DM_API_SET_PATH_LOSS_REPORTING_EN, + BTA_DM_API_SET_TRANS_POWER_REPORTING_EN, +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) BTA_DM_MAX_EVT }; @@ -1058,6 +1065,43 @@ typedef struct { tBTA_SET_VENDOR_EVT_MASK_CBACK *p_cback; } tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK; +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 phy; +} tBTA_DM_API_BLE_ENH_READ_TANS_PWR_LEVEL; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 phy; +} tBTA_DM_API_BLE_READ_REMOTE_TANS_PWR_LEVEL; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 high_threshold; + UINT8 high_hysteresis; + UINT8 low_threshold; + UINT8 low_hysteresis; + UINT16 min_time_spent; +} tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_PARAMS; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 enable; +} tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_ENABLE; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 local_enable; + UINT8 remote_enable; +} tBTA_DM_API_BLE_SET_TRANS_PWR_RPT_ENABLE; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #endif /* BLE_INCLUDED */ #if (BLE_HOST_REMOVE_AN_ACL_EN == TRUE) @@ -1766,6 +1810,13 @@ typedef union { #endif // #if (BLE_FEAT_CTE_CONNECTION_EN == TRUE) tBTA_DM_BLE_READ_ANT_INFOR read_ant_infor; #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + tBTA_DM_API_BLE_ENH_READ_TANS_PWR_LEVEL enh_read_trans_pwr_level; + tBTA_DM_API_BLE_READ_REMOTE_TANS_PWR_LEVEL remote_trans_pwr_level; + tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_PARAMS path_loss_rpt_params; + tBTA_DM_API_BLE_SET_PATH_LOSS_RPT_ENABLE path_loss_rpt_en; + tBTA_DM_API_BLE_SET_TRANS_PWR_RPT_ENABLE trans_pwr_rpt_en; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) } tBTA_DM_MSG; @@ -2416,4 +2467,12 @@ void bta_dm_ble_set_conn_cte_rsp_en(tBTA_DM_MSG *p_data); void bta_dm_ble_read_cte_ant_infor(tBTA_DM_MSG *p_data); #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void bta_dm_api_enh_read_trans_power_level(tBTA_DM_MSG *p_data); +void bta_dm_api_read_rem_trans_power_level(tBTA_DM_MSG *p_data); +void bta_dm_api_set_path_loss_report_params(tBTA_DM_MSG *p_data); +void bta_dm_api_set_path_loss_reporting_en(tBTA_DM_MSG *p_data); +void bta_dm_api_set_trans_power_reporting_en(tBTA_DM_MSG *p_data); +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #endif /* BTA_DM_INT_H */ diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index eb08bf1ac9..48c3fd0bc4 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -1675,6 +1675,17 @@ typedef struct { #define BTA_BLE_GAP_SET_PAST_PARAMS_COMPLETE_EVT BTM_BLE_GAP_SET_PAST_PARAMS_COMPLETE_EVT #define BTA_BLE_GAP_PERIODIC_ADV_SYNC_TRANS_RECV_EVT BTM_BLE_GAP_PERIODIC_ADV_SYNC_TRANS_RECV_EVT #endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +#define BTA_BLE_GAP_ENH_READ_TRANS_POWER_LEVEL_EVT BTM_BLE_GAP_ENH_READ_TRANS_POWER_LEVEL_EVT +#define BTA_BLE_GAP_READ_REMOTE_TRANS_POWER_LEVEL_EVT BTM_BLE_GAP_READ_REMOTE_TRANS_POWER_LEVEL_EVT +#define BTA_BLE_GAP_SET_PATH_LOSS_REPORTING_PARAMS_EVT BTM_BLE_GAP_SET_PATH_LOSS_REPORTING_PARAMS_EVT +#define BTA_BLE_GAP_SET_PATH_LOSS_REPORTING_ENABLE_EVT BTM_BLE_GAP_SET_PATH_LOSS_REPORTING_ENABLE_EVT +#define BTA_BLE_GAP_SET_TRANS_POWER_REPORTING_ENABLE_EVT BTM_BLE_GAP_SET_TRANS_POWER_REPORTING_ENABLE_EVT +#define BTA_BLE_GAP_PATH_LOSS_THRESHOLD_EVT BTM_BLE_GAP_PATH_LOSS_THRESHOLD_EVT +#define BTA_BLE_GAP_TRANMIT_POWER_REPORTING_EVT BTM_BLE_GAP_TRANMIT_POWER_REPORTING_EVT +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #define BTA_DM_BLE_5_GAP_UNKNOWN_EVT BTM_BLE_5_GAP_UNKNOWN_EVT typedef tBTM_BLE_5_GAP_EVENT tBTA_DM_BLE_5_GAP_EVENT; @@ -3035,6 +3046,15 @@ extern void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTM_SET_CSA_SUPPORT_C extern void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_CBACK *p_callback); +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void BTA_DmBleGapEnhReadTransPwrLevel(uint16_t conn_handle, uint8_t phy); +void BTA_DmBleGapReadRemoteTransPwrLevel(uint16_t conn_handle, uint8_t phy); +void BTA_DmBleGapSetPathLossRptParams(uint16_t conn_handle, uint8_t high_threshold, uint8_t high_hysteresis, + uint8_t low_threshold, uint8_t low_hysteresis, uint16_t min_time_spent); +void BTA_DmBleGapSetPathLossRptEnable(uint16_t conn_handle, uint8_t enable); +void BTA_DmBleGapSetTransPwrRptEnable(uint16_t conn_handle, uint8_t local_enable, uint8_t remote_enable); +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + /******************************************************************************* ** ** Function BTA_DmBleSetStorageParams diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 7dab7edb92..dea9ac7ec0 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1206,6 +1206,51 @@ static void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event, param.past_received.adv_clk_accuracy = params->past_recv.adv_clk_accuracy; break; #endif +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + case BTA_BLE_GAP_ENH_READ_TRANS_POWER_LEVEL_EVT: + msg.act = ESP_GAP_BLE_ENH_READ_TRANS_PWR_LEVEL_EVT; + param.enh_trans_pwr_level_cmpl.status = btc_btm_status_to_esp_status(params->enh_trans_pwr_level_cmpl.status); + param.enh_trans_pwr_level_cmpl.conn_handle = params->enh_trans_pwr_level_cmpl.conn_handle; + param.enh_trans_pwr_level_cmpl.phy = params->enh_trans_pwr_level_cmpl.phy; + param.enh_trans_pwr_level_cmpl.cur_tx_pwr_level = params->enh_trans_pwr_level_cmpl.cur_tx_pwr_level; + param.enh_trans_pwr_level_cmpl.max_tx_pwr_level = params->enh_trans_pwr_level_cmpl.max_tx_pwr_level; + break; + case BTA_BLE_GAP_READ_REMOTE_TRANS_POWER_LEVEL_EVT: + msg.act = ESP_GAP_BLE_READ_REMOTE_TRANS_PWR_LEVEL_EVT; + param.read_remote_trans_pwr_level_cmpl.status = btc_btm_status_to_esp_status(params->remote_pwr_level_cmpl.status); + break; + case BTA_BLE_GAP_SET_PATH_LOSS_REPORTING_PARAMS_EVT: + msg.act = ESP_GAP_BLE_SET_PATH_LOSS_RPTING_PARAMS_EVT; + param.set_path_loss_rpting_params.status = btc_btm_status_to_esp_status(params->path_loss_rpting_params.status); + param.set_path_loss_rpting_params.conn_handle = params->path_loss_rpting_params.conn_handle; + break; + case BTA_BLE_GAP_SET_PATH_LOSS_REPORTING_ENABLE_EVT: + msg.act = ESP_GAP_BLE_SET_PATH_LOSS_RPTING_ENABLE_EVT; + param.set_path_loss_rpting_enable.status = btc_btm_status_to_esp_status(params->path_loss_rpting_enable.status); + param.set_path_loss_rpting_enable.conn_handle = params->path_loss_rpting_enable.conn_handle; + break; + case BTA_BLE_GAP_SET_TRANS_POWER_REPORTING_ENABLE_EVT: + msg.act = ESP_GAP_BLE_SET_TRANS_PWR_RPTING_ENABLE_EVT; + param.set_trans_pwr_rpting_enable.status = btc_btm_status_to_esp_status(params->trans_pwr_rpting_enable.status); + param.set_trans_pwr_rpting_enable.conn_handle = params->trans_pwr_rpting_enable.conn_handle; + break; + case BTA_BLE_GAP_PATH_LOSS_THRESHOLD_EVT: + msg.act = ESP_GAP_BLE_PATH_LOSS_THRESHOLD_EVT; + param.path_loss_thres_evt.conn_handle = params->path_loss_thres_evt.conn_handle; + param.path_loss_thres_evt.cur_path_loss = params->path_loss_thres_evt.cur_path_loss; + param.path_loss_thres_evt.zone_entered = params->path_loss_thres_evt.zone_entered; + break; + case BTA_BLE_GAP_TRANMIT_POWER_REPORTING_EVT: + msg.act = ESP_GAP_BLE_TRANS_PWR_RPTING_EVT; + param.trans_power_report_evt.status = btc_btm_status_to_esp_status(params->trans_pwr_report_evt.status); + param.trans_power_report_evt.conn_handle = params->trans_pwr_report_evt.conn_handle; + param.trans_power_report_evt.reason = params->trans_pwr_report_evt.reason; + param.trans_power_report_evt.phy = params->trans_pwr_report_evt.phy; + param.trans_power_report_evt.tx_power_level = params->trans_pwr_report_evt.tx_power_level; + param.trans_power_report_evt.tx_power_level_flag = params->trans_pwr_report_evt.tx_power_level_flag; + param.trans_power_report_evt.delta = params->trans_pwr_report_evt.delta; + break; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) default: break; } @@ -2529,6 +2574,24 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) case BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK: BTA_DmBleGapSetVendorEventMask(arg->set_vendor_evt_mask.evt_mask, btc_ble_set_vendor_evt_mask_callback); break; +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + case BTC_GAP_BLE_ENH_READ_TRANS_POWER_LEVEL: + BTA_DmBleGapEnhReadTransPwrLevel(arg_5->enh_read_trans_pwr_level.conn_handle, arg_5->enh_read_trans_pwr_level.phy); + break; + case BTC_GAP_BLE_READ_REM_TRANS_POWER_LEVEL: + BTA_DmBleGapReadRemoteTransPwrLevel(arg_5->read_rem_trans_pwr_level.conn_handle, arg_5->read_rem_trans_pwr_level.phy); + break; + case BTC_GAP_BLE_SET_PATH_LOSS_REPORT_PARAMS: + BTA_DmBleGapSetPathLossRptParams(arg_5->set_path_loss_rpt_params.conn_handle, arg_5->set_path_loss_rpt_params.high_threshold, arg_5->set_path_loss_rpt_params.high_hysteresis, + arg_5->set_path_loss_rpt_params.low_threshold, arg_5->set_path_loss_rpt_params.low_hysteresis, arg_5->set_path_loss_rpt_params.min_time_spent); + break; + case BTC_GAP_BLE_SET_PATH_LOSS_REPORTING_EN: + BTA_DmBleGapSetPathLossRptEnable(arg_5->set_path_loss_rpt_en.conn_handle, arg_5->set_path_loss_rpt_en.enable); + break; + case BTC_GAP_BLE_SET_TRANS_POWER_REPORTING_EN: + BTA_DmBleGapSetTransPwrRptEnable(arg_5->set_trans_pwr_rpting_en.conn_handle, arg_5->set_trans_pwr_rpting_en.local_enable, arg_5->set_trans_pwr_rpting_en.remote_enable); + break; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) default: break; } diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h index 988b234205..59499b2248 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -122,6 +122,13 @@ typedef enum { BTC_GAP_BLE_SET_PRIVACY_MODE, BTC_GAP_BLE_SET_CSA_SUPPORT, BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK, +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + BTC_GAP_BLE_ENH_READ_TRANS_POWER_LEVEL, + BTC_GAP_BLE_READ_REM_TRANS_POWER_LEVEL, + BTC_GAP_BLE_SET_PATH_LOSS_REPORT_PARAMS, + BTC_GAP_BLE_SET_PATH_LOSS_REPORTING_EN, + BTC_GAP_BLE_SET_TRANS_POWER_REPORTING_EN, +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) } btc_gap_ble_act_t; /* btc_ble_gap_args_t */ @@ -457,6 +464,38 @@ typedef union { uint8_t phy; uint8_t modulation_index; } dtm_enh_rx_start; +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + // BTC_GAP_BLE_ENH_READ_TRANS_POWER_LEVEL + struct enh_read_trans_pwr_level_args { + uint8_t conn_handle; + uint8_t phy; + } enh_read_trans_pwr_level; + // BTC_GAP_BLE_READ_REM_TRANS_POWER_LEVEL + struct read_rem_trans_pwr_level_args { + uint8_t conn_handle; + uint8_t phy; + } read_rem_trans_pwr_level; + // BTC_GAP_BLE_SET_PATH_LOSS_REPORT_PARAMS + struct set_path_loss_rpt_params_args { + uint16_t conn_handle; + uint8_t high_threshold; + uint8_t high_hysteresis; + uint8_t low_threshold; + uint8_t low_hysteresis; + uint16_t min_time_spent; + } set_path_loss_rpt_params; + // BTC_GAP_BLE_SET_PATH_LOSS_REPORTING_EN + struct set_path_loss_rpt_en_args { + uint16_t conn_handle; + uint8_t enable; + } set_path_loss_rpt_en; + // BTC_GAP_BLE_SET_TRANS_POWER_REPORTING_EN + struct set_trans_pwr_rpting_en_args { + uint16_t conn_handle; + uint8_t local_enable; + uint8_t remote_enable; + } set_trans_pwr_rpting_en; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) } btc_ble_5_gap_args_t; #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index fda9cf7fe9..1d16ae2cee 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -264,6 +264,12 @@ #define UC_BT_BLE_FEAT_CTE_CONNECTION_EN FALSE #endif +#ifdef CONFIG_BT_BLE_FEAT_POWER_CONTROL +#define UC_BT_BLE_FEAT_POWER_CONTROL CONFIG_BT_BLE_FEAT_POWER_CONTROL +#else +#define UC_BT_BLE_FEAT_POWER_CONTROL FALSE +#endif + #ifdef CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL #define UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL #else diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index 9b7a29f5ab..1aabd914b3 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -356,6 +356,12 @@ #define BLE_FEAT_CTE_CONNECTION_EN FALSE #endif +#if (UC_BT_BLE_FEAT_POWER_CONTROL == TRUE) +#define BLE_FEAT_POWER_CONTROL_EN TRUE +#else +#define BLE_FEAT_POWER_CONTROL_EN FALSE +#endif + #if (UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL == TRUE) #define BLE_HIGH_DUTY_ADV_INTERVAL TRUE #else diff --git a/components/bt/host/bluedroid/device/controller.c b/components/bt/host/bluedroid/device/controller.c index 262f9ef616..984caaad07 100644 --- a/components/bt/host/bluedroid/device/controller.c +++ b/components/bt/host/bluedroid/device/controller.c @@ -31,11 +31,7 @@ #include "osi/future.h" #include "config/stack_config.h" #if (BLE_50_FEATURE_SUPPORT == TRUE) -#if (BLE_FEAT_ISO_EN == TRUE) -const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x02\xff\xff\xff\xff" }; -#else -const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x00\x00\xff\xff\xff" }; -#endif // #if (BLE_FEAT_ISO_EN == TRUE) +const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x03\xff\xff\xff\xff" }; #else const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x00\x00\x00\x06\x7f" }; #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index 1c3af49c79..a75d74e0f7 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -1539,3 +1539,127 @@ void btm_ble_periodic_adv_sync_trans_recv_evt(tBTM_BLE_PERIOD_ADV_SYNC_TRANS_REC BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_PERIODIC_ADV_SYNC_TRANS_RECV_EVT, &cb_params); } #endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void BTM_BleEnhReadTransPowerLevel(uint16_t conn_handle, uint8_t phy) +{ + btsnd_hcic_ble_enh_read_trans_power_level(conn_handle, phy); +} + +void BTM_BleReadRemoteTransPwrLevel(uint16_t conn_handle, uint8_t phy) +{ + btsnd_hcic_ble_read_remote_trans_power_level(conn_handle, phy); +} + +void BTM_BleSetPathLossRptParams(uint16_t conn_handle, uint8_t high_threshold, uint8_t high_hysteresis, + uint8_t low_threshold, uint8_t low_hysteresis, uint16_t min_time_spent) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_set_path_loss_rpt_params(conn_handle, high_threshold, high_hysteresis, low_threshold, low_hysteresis, min_time_spent)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err=0x%x", __func__, err); + status = BTM_HCI_ERROR | err; + } + + cb_params.path_loss_rpting_params.status = status; + cb_params.path_loss_rpting_params.conn_handle = conn_handle; + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_SET_PATH_LOSS_REPORTING_PARAMS_EVT, &cb_params); +} + +void BTM_BleSetPathLossRptEnable(uint16_t conn_handle, uint8_t enable) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_set_path_loss_rpt_enable(conn_handle, enable)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err=0x%x", __func__, err); + status = BTM_HCI_ERROR | err; + } + + cb_params.path_loss_rpting_enable.status = status; + cb_params.path_loss_rpting_enable.conn_handle = conn_handle; + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_SET_PATH_LOSS_REPORTING_ENABLE_EVT, &cb_params); +} + +void BTM_BleSetTransPwrRptEnable(uint16_t conn_handle, uint8_t local_enable, uint8_t remote_enable) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_set_trans_pwr_rpt_enable(conn_handle, local_enable, remote_enable)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err=0x%x", __func__, err); + status = BTM_HCI_ERROR | err; + } + + cb_params.trans_pwr_rpting_enable.status = status; + cb_params.trans_pwr_rpting_enable.conn_handle = conn_handle; + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_SET_TRANS_POWER_REPORTING_ENABLE_EVT, &cb_params); +} + +void btm_enh_read_trans_pwr_level_cmpl_evt(uint8_t *p) +{ + uint8_t hci_status; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + STREAM_TO_UINT8(hci_status, p); + STREAM_TO_UINT16(cb_params.enh_trans_pwr_level_cmpl.conn_handle, p); + STREAM_TO_UINT8(cb_params.enh_trans_pwr_level_cmpl.phy, p); + STREAM_TO_UINT8(cb_params.enh_trans_pwr_level_cmpl.cur_tx_pwr_level, p); + STREAM_TO_UINT8(cb_params.enh_trans_pwr_level_cmpl.max_tx_pwr_level, p); + + if(hci_status != HCI_SUCCESS) { + hci_status = BTM_HCI_ERROR | hci_status; + BTM_TRACE_ERROR("%s error status %d", __func__, hci_status); + } + cb_params.enh_trans_pwr_level_cmpl.status = hci_status; + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_ENH_READ_TRANS_POWER_LEVEL_EVT, &cb_params); +} + +void btm_read_remote_trans_pwr_level_cmpl(UINT8 status) +{ + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if (status != HCI_SUCCESS) { + status = (status | BTM_HCI_ERROR); + } + + cb_params.remote_pwr_level_cmpl.status = status; + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_READ_REMOTE_TRANS_POWER_LEVEL_EVT, &cb_params); +} + +void btm_ble_path_loss_threshold_evt(tBTM_BLE_PATH_LOSS_THRESHOLD_EVT *params) +{ + if (!params) { + BTM_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + // If the user has register the callback function, should callback it to the application. + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_PATH_LOSS_THRESHOLD_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)params); +} + +void btm_ble_transmit_power_report_evt(tBTM_BLE_TRANS_POWER_REPORT_EVT *params) +{ + if (!params) { + BTM_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + if (params->status != HCI_SUCCESS) { + params->status = (params->status | BTM_HCI_ERROR); + } + + // If the user has register the callback function, should callback it to the application. + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_TRANMIT_POWER_REPORTING_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)params); +} + +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h index af8755c324..0006aaf7a7 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h @@ -598,6 +598,12 @@ void btm_ble_connless_iq_report_evt(tBTM_BLE_CTE_CONNLESS_IQ_REPORT_EVT *params) void btm_ble_conn_iq_report_evt(tBTM_BLE_CTE_CONN_IQ_REPORT_EVT *params); void btm_ble_cte_req_failed_evt(tBTM_BLE_CTE_REQ_FAILED_EVT *params); #endif // #if (BLE_FEAT_CTE_EN == TRUE) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void btm_ble_path_loss_threshold_evt(tBTM_BLE_PATH_LOSS_THRESHOLD_EVT *params); +void btm_ble_transmit_power_report_evt(tBTM_BLE_TRANS_POWER_REPORT_EVT *params); +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + /* #ifdef __cplusplus } diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index 79bed81df8..06a4540370 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -1117,6 +1117,11 @@ void btm_read_phy_callback(uint8_t hci_status, uint16_t conn_handle, uint8_t tx_ void btm_ble_periodic_adv_sync_trans_complete(UINT16 op_code, UINT8 hci_status, UINT16 conn_handle); #endif void btm_ble_big_sync_terminate_complete(UINT8 hci_status, UINT8 big_handle); + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void btm_enh_read_trans_pwr_level_cmpl_evt(uint8_t *p); +void btm_read_remote_trans_pwr_level_cmpl(UINT8 status); +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) /* Internal functions provided by btm_sco.c ******************************************** */ diff --git a/components/bt/host/bluedroid/stack/btu/btu_hcif.c b/components/bt/host/bluedroid/stack/btu/btu_hcif.c index 682df3703c..495f3c2baf 100644 --- a/components/bt/host/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/host/bluedroid/stack/btu/btu_hcif.c @@ -219,6 +219,11 @@ static void btu_ble_cte_req_failed_evt(UINT8 *p); #endif // #if (BLE_FEAT_CTE_CONNECTION_EN == TRUE) #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +static void btu_ble_path_loss_threshold_evt(UINT8 *p); +static void btu_ble_transmit_power_report_evt(UINT8 *p); +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #if (BLE_42_ADV_EN == TRUE) extern osi_sem_t adv_enable_sem; extern osi_sem_t adv_data_sem; @@ -564,6 +569,14 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg) #endif // #if (BLE_FEAT_CTE_CONNECTION_EN == TRUE) #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + case HCI_BLE_PATH_LOSS_THRESHOLD_EVT: + btu_ble_path_loss_threshold_evt(p); + break; + case HCI_BLE_TRANS_POWER_REPORTING_EVT: + btu_ble_transmit_power_report_evt(p); + break; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) } break; #endif /* BLE_INCLUDED */ @@ -1348,6 +1361,13 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l btm_ble_cte_read_ant_infor_complete(p); break; #endif // #if (BLE_FEAT_CTE_EN == TRUE) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + case HCI_BLE_ENH_READ_TRANS_POWER_LEVEL: + btm_enh_read_trans_pwr_level_cmpl_evt(p); + break; +#endif //#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #endif /* (BLE_INCLUDED == TRUE) */ default: { @@ -1545,6 +1565,11 @@ static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_c break; #endif // #if (BLE_FEAT_ISO_CIG_PERIPHERAL_EN == TRUE) #endif // #if (BLE_FEAT_ISO_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + case HCI_BLE_READ_REMOTE_TRANS_POWER_LEVEL: + btm_read_remote_trans_pwr_level_cmpl(status); + break; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) default: /* If command failed to start, we may need to tell BTM */ if (status != HCI_SUCCESS) { @@ -2975,6 +3000,42 @@ static void btu_ble_cte_req_failed_evt(UINT8 *p) #endif // #if (BLE_FEAT_CTE_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +static void btu_ble_path_loss_threshold_evt(UINT8 *p) +{ + tBTM_BLE_PATH_LOSS_THRESHOLD_EVT path_loss_thres_evt = {0}; + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + STREAM_TO_UINT16(path_loss_thres_evt.conn_handle, p); + STREAM_TO_UINT8(path_loss_thres_evt.cur_path_loss, p); + STREAM_TO_UINT8(path_loss_thres_evt.zone_entered, p); + + btm_ble_path_loss_threshold_evt(&path_loss_thres_evt); +} + +static void btu_ble_transmit_power_report_evt(UINT8 *p) +{ + tBTM_BLE_TRANS_POWER_REPORT_EVT trans_pwr_report_evt = {0}; + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + STREAM_TO_UINT8(trans_pwr_report_evt.status, p); + STREAM_TO_UINT16(trans_pwr_report_evt.conn_handle, p); + STREAM_TO_UINT8(trans_pwr_report_evt.reason, p); + STREAM_TO_UINT8(trans_pwr_report_evt.phy, p); + STREAM_TO_UINT8(trans_pwr_report_evt.tx_power_level, p); + STREAM_TO_UINT8(trans_pwr_report_evt.tx_power_level_flag, p); + STREAM_TO_UINT8(trans_pwr_report_evt.delta, p); + + btm_ble_transmit_power_report_evt(&trans_pwr_report_evt); +} +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + /********************************************** ** End of BLE Events Handler ***********************************************/ diff --git a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c index bc01cd6553..c643cd0457 100644 --- a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c +++ b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c @@ -2641,3 +2641,112 @@ UINT8 btsnd_hcic_ble_read_antenna_info(void) return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); } #endif // #if (BLE_FEAT_CTE_EN == TRUE) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +UINT8 btsnd_hcic_ble_enh_read_trans_power_level(uint16_t conn_handle, uint8_t phy) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("hci enh read trans power level, conn_handle %d phy %d", conn_handle, phy); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ENH_READ_TRANS_PWR_LEVEL); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_ENH_READ_TRANS_POWER_LEVEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENH_READ_TRANS_PWR_LEVEL); + + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, phy); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} + +UINT8 btsnd_hcic_ble_read_remote_trans_power_level(uint16_t conn_handle, uint8_t phy) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("hci read remote trans power level, conn_handle %d phy %d", conn_handle, phy); + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_REMOTE_TRANS_PWR_LEVEL); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_READ_REMOTE_TRANS_POWER_LEVEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_REMOTE_TRANS_PWR_LEVEL); + + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, phy); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + + return TRUE; +} + +UINT8 btsnd_hcic_ble_set_path_loss_rpt_params(uint16_t conn_handle, uint8_t high_threshold, uint8_t high_hysteresis, + uint8_t low_threshold, uint8_t low_hysteresis, uint16_t min_time_spent) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("hci set path loss rpt params, conn_handle %d high_threshold %d high_hysteresis %d low_threshold %d low_hysteresis %d min_time_spent %d", + conn_handle, high_threshold, high_hysteresis, low_threshold, + low_hysteresis, min_time_spent); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_PARAMS); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_SET_PATH_LOSS_REPORTING_PARAMS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_PARAMS); + + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, high_threshold); + UINT8_TO_STREAM(pp, high_hysteresis); + UINT8_TO_STREAM(pp, low_threshold); + UINT8_TO_STREAM(pp, low_hysteresis); + UINT16_TO_STREAM(pp, min_time_spent); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} + +UINT8 btsnd_hcic_ble_set_path_loss_rpt_enable(uint16_t conn_handle, uint8_t enable) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("hci set path loss rpt en, conn_handle %d enable %d", conn_handle, enable); + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_ENABLE); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_SET_PATH_LOSS_REPORTING_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_ENABLE); + + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, enable); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} + +UINT8 btsnd_hcic_ble_set_trans_pwr_rpt_enable(uint16_t conn_handle, uint8_t local_enable, uint8_t remote_enable) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("hci set trans power rpt en, conn_handle %d local_enable %d remote_enable %d", conn_handle, local_enable, remote_enable); + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_TRANS_PWR_REPORTING_ENABLE); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_SET_TRANS_POWER_REPORTING_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_TRANS_PWR_REPORTING_ENABLE); + + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, local_enable); + UINT8_TO_STREAM(pp, remote_enable); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 6e1fee4b59..5f68f02f7a 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -1072,6 +1072,15 @@ typedef void (tBTM_SET_VENDOR_EVT_MASK_CBACK) (tBTM_STATUS status); #define BTM_BLE_GAP_PERIODIC_ADV_SYNC_TRANS_RECV_EVT 39 #endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE) #define BTM_BLE_GAP_SET_PRIVACY_MODE_COMPLETE_EVT 40 +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +#define BTM_BLE_GAP_ENH_READ_TRANS_POWER_LEVEL_EVT 41 +#define BTM_BLE_GAP_READ_REMOTE_TRANS_POWER_LEVEL_EVT 42 +#define BTM_BLE_GAP_SET_PATH_LOSS_REPORTING_PARAMS_EVT 43 +#define BTM_BLE_GAP_SET_PATH_LOSS_REPORTING_ENABLE_EVT 44 +#define BTM_BLE_GAP_SET_TRANS_POWER_REPORTING_ENABLE_EVT 45 +#define BTM_BLE_GAP_PATH_LOSS_THRESHOLD_EVT 46 +#define BTM_BLE_GAP_TRANMIT_POWER_REPORTING_EVT 47 +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) #define BTM_BLE_5_GAP_UNKNOWN_EVT 50 typedef UINT8 tBTM_BLE_5_GAP_EVENT; @@ -1379,6 +1388,52 @@ typedef struct { } tBTM_BLE_PERIOD_ADV_SYNC_TRANS_RECV; #endif //#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +typedef struct { + UINT8 status; + UINT16 conn_handle; + UINT8 phy; + INT8 cur_tx_pwr_level; + INT8 max_tx_pwr_level; +} __attribute__((packed)) tBTM_BLE_ENH_TRANS_PWR_LEVEL_CMPL; + +typedef struct { + UINT8 status; +} __attribute__((packed)) tBTM_BLE_REMOTE_TRANS_PWR_LEVEL_CMPL; + +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_SET_PATH_LOSS_RPTING_PARAMS; + +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_SET_PATH_LOSS_RPTING_ENABLE; + +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_SET_TRANS_POWER_RPTING_ENABLE; + +typedef struct { + UINT16 conn_handle; + UINT8 cur_path_loss; + UINT8 zone_entered; +} __attribute__((packed)) tBTM_BLE_PATH_LOSS_THRESHOLD_EVT; + +typedef struct { + UINT8 status; + UINT16 conn_handle; + UINT8 reason; + UINT8 phy; + INT8 tx_power_level; + UINT8 tx_power_level_flag; + INT8 delta; +} __attribute__((packed)) tBTM_BLE_TRANS_POWER_REPORT_EVT; + +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #if (BLE_FEAT_ISO_EN == TRUE) #if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE) typedef struct { @@ -1733,6 +1788,15 @@ typedef union { tBTM_BLE_SET_PERIOD_ADV_SYNC_TRANS_PARAMS_CMPL set_past_params; tBTM_BLE_PERIOD_ADV_SYNC_TRANS_RECV past_recv; #endif //#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + tBTM_BLE_ENH_TRANS_PWR_LEVEL_CMPL enh_trans_pwr_level_cmpl; + tBTM_BLE_REMOTE_TRANS_PWR_LEVEL_CMPL remote_pwr_level_cmpl; + tBTM_BLE_SET_PATH_LOSS_RPTING_PARAMS path_loss_rpting_params; + tBTM_BLE_SET_PATH_LOSS_RPTING_ENABLE path_loss_rpting_enable; + tBTM_BLE_SET_TRANS_POWER_RPTING_ENABLE trans_pwr_rpting_enable; + tBTM_BLE_PATH_LOSS_THRESHOLD_EVT path_loss_thres_evt; + tBTM_BLE_TRANS_POWER_REPORT_EVT trans_pwr_report_evt; +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) } tBTM_BLE_5_GAP_CB_PARAMS; typedef struct { @@ -3256,4 +3320,14 @@ tBTM_STATUS BTM_BleCteSetConnectionRspEnable(uint16_t conn_handle, uint8_t enabl tBTM_STATUS BTM_BleCteReadAntInfor(void); #endif // #if (BLE_FEAT_CTE_EN == TRUE) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +void BTM_BleEnhReadTransPowerLevel(uint16_t conn_handle, uint8_t phy); +void BTM_BleReadRemoteTransPwrLevel(uint16_t conn_handle, uint8_t phy); +void BTM_BleSetPathLossRptParams(uint16_t conn_handle, uint8_t high_threshold, uint8_t high_hysteresis, + uint8_t low_threshold, uint8_t low_hysteresis, uint16_t min_time_spent); +void BTM_BleSetPathLossRptEnable(uint16_t conn_handle, uint8_t enable); +void BTM_BleSetTransPwrRptEnable(uint16_t conn_handle, uint8_t local_enable, uint8_t remote_enable); +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + #endif diff --git a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h index 9eaf07fcd2..114cd0d37c 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h @@ -428,6 +428,15 @@ #define HCI_BLE_ISO_SET_HOST_FEATURE (0x0074 | HCI_GRP_BLE_CMDS) #define HCI_BLE_ISO_READ_ISO_LINK_QUALITY (0x0075 | HCI_GRP_BLE_CMDS) #define HCI_BLE_ISO_SET_HOST_FEATURE_V2 (0x0097 | HCI_GRP_BLE_CMDS) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +#define HCI_BLE_ENH_READ_TRANS_POWER_LEVEL (0x0076 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_REMOTE_TRANS_POWER_LEVEL (0x0077 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_PATH_LOSS_REPORTING_PARAMS (0x0078 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_PATH_LOSS_REPORTING_ENABLE (0x0079 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_TRANS_POWER_REPORTING_ENABLE (0x007A | HCI_GRP_BLE_CMDS) +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + // Vendor OGF define #define HCI_VENDOR_OGF 0x3F @@ -894,6 +903,11 @@ #define HCI_BLE_CIS_ESTABLISHED_V2_EVT 0x2A #endif // #if (BLE_FEAT_ISO_EN == TRUE) +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +#define HCI_BLE_PATH_LOSS_THRESHOLD_EVT 0x20 +#define HCI_BLE_TRANS_POWER_REPORTING_EVT 0x21 +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) + /* Definitions for LE Channel Map */ #define HCI_BLE_CHNL_MAP_SIZE 5 diff --git a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h index 89158bfc7c..407bc8e430 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h @@ -1211,4 +1211,19 @@ UINT8 btsnd_hcic_ble_conn_cte_rsp_enable(uint16_t conn_hdl, uint8_t enable); #endif // #if (BLE_FEAT_CTE_CONNECTION_EN == TRUE) UINT8 btsnd_hcic_ble_read_antenna_info(void); #endif // #if (BLE_FEAT_CTE_EN == TRUE) + +#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) +#define HCIC_PARAM_SIZE_ENH_READ_TRANS_PWR_LEVEL 3 +#define HCIC_PARAM_SIZE_READ_REMOTE_TRANS_PWR_LEVEL 3 +#define HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_PARAMS 8 +#define HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_ENABLE 3 +#define HCIC_PARAM_SIZE_SET_TRANS_PWR_REPORTING_ENABLE 4 + +UINT8 btsnd_hcic_ble_enh_read_trans_power_level(uint16_t conn_handle, uint8_t phy); +UINT8 btsnd_hcic_ble_read_remote_trans_power_level(uint16_t conn_handle, uint8_t phy); +UINT8 btsnd_hcic_ble_set_path_loss_rpt_params(uint16_t conn_handle, uint8_t high_threshold, uint8_t high_hysteresis, + uint8_t low_threshold, uint8_t low_hysteresis, uint16_t min_time_spent); +UINT8 btsnd_hcic_ble_set_path_loss_rpt_enable(uint16_t conn_handle, uint8_t enable); +UINT8 btsnd_hcic_ble_set_trans_pwr_rpt_enable(uint16_t conn_handle, uint8_t local_enable, uint8_t remote_enable); +#endif // #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) #endif