1 /******************************************************************************
2 *
3 * Copyright 2014 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <string.h>
20 #include "bt_target.h"
21
22 #include "btm_ble_api.h"
23 #include "stack/btm/btm_int_types.h"
24
25 extern tBTM_CB btm_cb;
26
27 tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb;
28
29 /*******************************************************************************
30 *
31 * Function btm_ble_cont_energy_cmpl_cback
32 *
33 * Description Controller VSC complete callback
34 *
35 * Parameters
36 *
37 * Returns void
38 *
39 ******************************************************************************/
btm_ble_cont_energy_cmpl_cback(tBTM_VSC_CMPL * p_params)40 static void btm_ble_cont_energy_cmpl_cback(tBTM_VSC_CMPL* p_params) {
41 uint8_t* p = p_params->p_param_buf;
42 uint16_t len = p_params->param_len;
43 uint32_t total_tx_time = 0, total_rx_time = 0, total_idle_time = 0,
44 total_energy_used = 0;
45
46 if (len < 17) {
47 BTM_TRACE_ERROR("wrong length for btm_ble_cont_energy_cmpl_cback");
48 return;
49 }
50
51 uint8_t raw_status;
52 STREAM_TO_UINT8(raw_status, p);
53 tHCI_STATUS status = to_hci_status_code(raw_status);
54 STREAM_TO_UINT32(total_tx_time, p);
55 STREAM_TO_UINT32(total_rx_time, p);
56 STREAM_TO_UINT32(total_idle_time, p);
57 STREAM_TO_UINT32(total_energy_used, p);
58
59 BTM_TRACE_DEBUG(
60 "energy_info status=%d,tx_t=%ld, rx_t=%ld, ener_used=%ld, idle_t=%ld",
61 status, total_tx_time, total_rx_time, total_energy_used, total_idle_time);
62
63 if (NULL != ble_energy_info_cb.p_ener_cback)
64 ble_energy_info_cb.p_ener_cback(total_tx_time, total_rx_time,
65 total_idle_time, total_energy_used,
66 static_cast<tHCI_STATUS>(status));
67
68 return;
69 }
70
71 /*******************************************************************************
72 *
73 * Function BTM_BleGetEnergyInfo
74 *
75 * Description This function obtains the energy info
76 *
77 * Parameters p_ener_cback - Callback pointer
78 *
79 * Returns status
80 *
81 ******************************************************************************/
BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK * p_ener_cback)82 tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback) {
83 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
84
85 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
86
87 BTM_TRACE_EVENT("BTM_BleGetEnergyInfo");
88
89 if (0 == cmn_ble_vsc_cb.energy_support) {
90 BTM_TRACE_ERROR("Controller does not support get energy info");
91 return BTM_ERR_PROCESSING;
92 }
93
94 ble_energy_info_cb.p_ener_cback = p_ener_cback;
95 BTM_VendorSpecificCommand(HCI_BLE_ENERGY_INFO, 0, NULL,
96 btm_ble_cont_energy_cmpl_cback);
97 return BTM_CMD_STARTED;
98 }
99