diff options
author | DoHyun Pyun <dh79.pyun@samsung.com> | 2020-03-24 14:46:40 +0900 |
---|---|---|
committer | DoHyun Pyun <dh79.pyun@samsung.com> | 2020-03-24 14:52:22 +0900 |
commit | cabc8e060e0464412403989b81b940289c9c28b0 (patch) | |
tree | f27f4fa6861602724dfaf6587b8dd8050a2dcb79 /src | |
parent | 72b09c371119fccac17dd35ef6046b2e727767fe (diff) | |
download | bluez-cabc8e060e0464412403989b81b940289c9c28b0.tar.gz bluez-cabc8e060e0464412403989b81b940289c9c28b0.tar.bz2 bluez-cabc8e060e0464412403989b81b940289c9c28b0.zip |
Add GetEnergyInfo method for the power management
Change-Id: I46afc2c2575f996723b175a6febbeff0ff5938f1
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/adapter.c | 40 | ||||
-rwxr-xr-x | src/adapter_le_vsc_features.c | 41 | ||||
-rwxr-xr-x | src/adapter_le_vsc_features.h | 28 |
3 files changed, 109 insertions, 0 deletions
diff --git a/src/adapter.c b/src/adapter.c index 52ecbd66..294121b2 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -5913,6 +5913,39 @@ static DBusMessage *adapter_set_manufacturer_data(DBusConnection *conn, return btd_error_failed(msg, "Set manufacturer data failed"); } + +static DBusMessage *adapter_get_energy_info(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + DBusMessage *reply; + uint32_t tx_time = 0; + uint32_t rx_time = 0; + uint32_t idle_time = 0; + uint32_t energy_used = 0; + + if (adapter_le_get_energy_info(&tx_time, &rx_time, + &idle_time, &energy_used) == FALSE) { + error("Fail to send vcs for getting energy info"); + reply = btd_error_not_supported(msg); + goto done; + } + + reply = g_dbus_create_reply(msg, + DBUS_TYPE_UINT32, &tx_time, + DBUS_TYPE_UINT32, &rx_time, + DBUS_TYPE_UINT32, &idle_time, + DBUS_TYPE_UINT32, &energy_used, + DBUS_TYPE_INVALID); + + if (!reply) + reply = btd_error_failed(msg, + "Failed to create reply."); + +done: + return reply; +} + + #endif /* TIZEN_FEATURE_BLUEZ_MODIFY */ static DBusMessage *start_discovery(DBusConnection *conn, @@ -7632,6 +7665,13 @@ static const GDBusMethodTable adapter_methods[] = { { GDBUS_ASYNC_METHOD("CreateDevice", GDBUS_ARGS({ "address", "s" }), NULL, create_device) }, + { GDBUS_METHOD("GetEnergyInfo", + NULL, + GDBUS_ARGS({ "tx_time", "u" }, + { "rx_time", "u" }, + { "idle_time", "u" }, + { "energy_used", "u" }), + adapter_get_energy_info) }, #endif { GDBUS_ASYNC_METHOD("RemoveDevice", GDBUS_ARGS({ "device", "o" }), NULL, remove_device) }, diff --git a/src/adapter_le_vsc_features.c b/src/adapter_le_vsc_features.c index 771a88f0..5d0aee46 100755 --- a/src/adapter_le_vsc_features.c +++ b/src/adapter_le_vsc_features.c @@ -806,5 +806,46 @@ gboolean adapter_le_remove_irk_to_list(const bdaddr_t *bdaddr, uint8_t bdaddr_ty return TRUE; } +gboolean adapter_le_get_energy_info( + uint32_t *tx_time, uint32_t *rx_time, + uint32_t *idle_time, uint32_t *energy_used) +{ + int ret; + + adapter_le_vsc_rp_get_energy_info rp; + memset(&rp, 0, sizeof(rp)); + + DBG(""); + + ret = send_vsc_command(OCF_BCM_LE_GET_ENERGY_INFO, (uint8_t *) NULL, 0, + (uint8_t *) &rp, sizeof(rp)); + if (ret < 0) + return FALSE; + + if (HCI_SUCCESS != rp.status) { + error("Fail to get energy info"); + return FALSE; + } + + DBG("======== BLE energy info ========"); + DBG("Result [%d]", rp.status); + DBG("Total time performing Tx [%d]", rp.tx_time); + DBG("Total time performing Rx [%d]", rp.rx_time); + DBG("Total time in idle [%d]", rp.idle_time); + DBG("Total energy used [%d]", rp.energy_used); + DBG("================================="); + + if (rp.status != 0) { + error("Fail to get energy info: %d", rp.status); + return FALSE; + } + + *tx_time = rp.tx_time; + *rx_time = rp.rx_time; + *idle_time = rp.idle_time; + *energy_used = rp.energy_used; + + return TRUE; +} #endif /* TIZEN_FEATURE_BLUEZ_MODIFY */ diff --git a/src/adapter_le_vsc_features.h b/src/adapter_le_vsc_features.h index 1a74f020..fdccd22d 100755 --- a/src/adapter_le_vsc_features.h +++ b/src/adapter_le_vsc_features.h @@ -480,6 +480,30 @@ typedef struct { uint8_t available_space; } __attribute__ ((packed)) adapter_le_vsc_rp_irk_to_list; +#define OCF_BCM_LE_GET_ENERGY_INFO 0x0159 /* LE Get Energy Information */ + +/***************************************************************************** +** RP for OCF_BCM_LE_GET_ENERGY_INFO +** +*/ + +/** +* +* RP +* +* (1 octet) status : Command complete status +* (4 octet) tx_time : Total time performing Tx +* (4 octet) rx_time : Total time performing Rx +* (4 octet) idle_time : Total time in idle +* (4 octet) energy_used : Total energy used +*/ +typedef struct { + uint8_t status; + uint32_t tx_time; + uint32_t rx_time; + uint32_t idle_time; + uint32_t energy_used; +} __attribute__ ((packed)) adapter_le_vsc_rp_get_energy_info; /***************************************************************************** ** Functions @@ -530,4 +554,8 @@ gboolean adapter_le_add_irk_to_list(const uint8_t *le_irk, const bdaddr_t *bdadd gboolean adapter_le_remove_irk_to_list(const bdaddr_t *bdaddr, uint8_t bdaddr_type); +gboolean adapter_le_get_energy_info(uint32_t *tx_time, uint32_t *rx_time, + uint32_t *idle_time, uint32_t *energy_used); + + #endif /* TIZEN_FEATURE_BLUEZ_MODIFY */ |