2016-09-26 09:37:39 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "common/bt_target.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/bt_types.h"
|
|
|
|
#include "stack/hcimsgs.h"
|
|
|
|
#include "stack/btu.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#include "btm_int.h"
|
|
|
|
//#include "bt_utils.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/hcidefs.h"
|
|
|
|
#include "stack/btm_ble_api.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb;
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_cont_energy_cmpl_cback
|
|
|
|
**
|
|
|
|
** Description Controller VSC complete callback
|
|
|
|
**
|
|
|
|
** Parameters
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_cont_energy_cmpl_cback (tBTM_VSC_CMPL *p_params)
|
|
|
|
{
|
|
|
|
UINT8 *p = p_params->p_param_buf;
|
|
|
|
UINT16 len = p_params->param_len;
|
|
|
|
UINT8 status = 0;
|
|
|
|
UINT32 total_tx_time = 0, total_rx_time = 0, total_idle_time = 0, total_energy_used = 0;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (len < 17) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_TRACE_ERROR("wrong length for btm_ble_cont_energy_cmpl_cback");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
STREAM_TO_UINT8(status, p);
|
|
|
|
STREAM_TO_UINT32(total_tx_time, p);
|
|
|
|
STREAM_TO_UINT32(total_rx_time, p);
|
|
|
|
STREAM_TO_UINT32(total_idle_time, p);
|
|
|
|
STREAM_TO_UINT32(total_energy_used, p);
|
|
|
|
|
2016-12-07 01:11:40 -05:00
|
|
|
BTM_TRACE_DEBUG("energy_info status=%d,tx_t=%u, rx_t=%u, ener_used=%u, idle_t=%u",
|
2016-11-24 13:10:15 -05:00
|
|
|
status, total_tx_time, total_rx_time, total_energy_used, total_idle_time);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2019-03-26 02:46:36 -04:00
|
|
|
if (NULL != ble_energy_info_cb.p_ener_cback) {
|
2016-09-26 09:37:39 -04:00
|
|
|
ble_energy_info_cb.p_ener_cback(total_tx_time, total_rx_time, total_idle_time,
|
2016-11-24 13:10:15 -05:00
|
|
|
total_energy_used, status);
|
2019-03-26 02:46:36 -04:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_BleGetEnergyInfo
|
|
|
|
**
|
|
|
|
** Description This function obtains the energy info
|
|
|
|
**
|
|
|
|
** Parameters p_ener_cback - Callback pointer
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback)
|
|
|
|
{
|
|
|
|
tBTM_STATUS status = BTM_ILLEGAL_VALUE;
|
|
|
|
tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
|
|
|
|
|
|
|
|
BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
|
|
|
|
|
2016-10-11 05:43:36 -04:00
|
|
|
BTM_TRACE_EVENT("BTM_BleGetEnergyInfo\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (0 == cmn_ble_vsc_cb.energy_support) {
|
2016-10-11 05:43:36 -04:00
|
|
|
BTM_TRACE_ERROR("Controller does not support get energy info\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_ERR_PROCESSING;
|
|
|
|
}
|
|
|
|
|
|
|
|
ble_energy_info_cb.p_ener_cback = p_ener_cback;
|
|
|
|
if ((status = BTM_VendorSpecificCommand (HCI_BLE_ENERGY_INFO_OCF, 0, NULL,
|
2016-11-24 13:10:15 -05:00
|
|
|
btm_ble_cont_energy_cmpl_cback)) != BTM_CMD_STARTED) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_TRACE_ERROR("BTM_BleGetEnergyInfo status: %d", status);
|
|
|
|
return BTM_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|