Add the Rx / Tx / idle time in the battery monitor
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-common.c
index 23e9ab3..2161643 100644 (file)
@@ -133,6 +133,52 @@ bt_user_info_t *_bt_get_user_data(int type)
        return &user_info[type];
 }
 
+int _bt_common_send_rfcomm_rx_details(int len)
+{
+       uid_t uid = getuid();
+       pid_t pid = getpid();
+       int size = len;
+       int ret = BLUETOOTH_ERROR_NONE;
+
+       BT_INFO("+");
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &uid, sizeof(uid_t));
+       g_array_append_vals(in_param2, &pid, sizeof(pid_t));
+       g_array_append_vals(in_param3, &size, sizeof(int));
+
+       ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_SEND_RX_DETAILS,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       BT_INFO("-");
+       return ret;
+}
+
+int _bt_common_send_rfcomm_tx_details(int len)
+{
+       uid_t uid = getuid();
+       pid_t pid = getpid();
+       int size = len;
+       int ret = BLUETOOTH_ERROR_NONE;
+
+       BT_INFO("+");
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &uid, sizeof(uid_t));
+       g_array_append_vals(in_param2, &pid, sizeof(pid_t));
+       g_array_append_vals(in_param3, &size, sizeof(int));
+
+       ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_SEND_TX_DETAILS,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       BT_INFO("-");
+       return ret;
+}
+
 void _bt_common_event_cb(int event, int result, void *param,
                                        void *callback, void *user_data)
 {
@@ -474,6 +520,7 @@ const char *_bt_convert_service_function_to_string(int function)
                {BT_GET_ADVERTISING_DATA, "BT_GET_ADVERTISING_DATA"},
                {BT_SET_ADVERTISING_DATA, "BT_SET_ADVERTISING_DATA"},
                {BT_SET_SCAN_PARAMETERS, "BT_SET_SCAN_PARAMETERS"},
+               {BT_SET_SCAN_TYPE, "BT_SET_SCAN_TYPE"},
                {BT_GET_SCAN_RESPONSE_DATA, "BT_GET_SCAN_RESPONSE_DATA"},
                {BT_SET_SCAN_RESPONSE_DATA, "BT_SET_SCAN_RESPONSE_DATA"},
                {BT_IS_ADVERTISING, "BT_IS_ADVERTISING"},
@@ -487,8 +534,6 @@ const char *_bt_convert_service_function_to_string(int function)
                {BT_REMOVE_WHITE_LIST, "BT_REMOVE_WHITE_LIST"},
                {BT_CLEAR_WHITE_LIST, "BT_CLEAR_WHITE_LIST"},
                {BT_REGISTER_SCAN_FILTER, "BT_REGISTER_SCAN_FILTER"},
-               {BT_UNREGISTER_SCAN_FILTER, "BT_UNREGISTER_SCAN_FILTER"},
-               {BT_UNREGISTER_ALL_SCAN_FILTERS, "BT_UNREGISTER_ALL_SCAN_FILTERS"},
                {BT_IS_SCAN_FILTER_SUPPORTED, "BT_IS_SCAN_FILTER_SUPPORTED"},
                {BT_GET_PROFILE_CONNECTED_DEVICES, "BT_GET_PROFILE_CONNECTED_DEVICES"},
                {BT_ENABLE_FORCE_HCI_DUMP, "BT_ENABLE_FORCE_HCI_DUMP"},
@@ -544,9 +589,14 @@ const char *_bt_convert_service_function_to_string(int function)
                {BT_SET_SPEAKER_GAIN, "BT_SET_SPEAKER_GAIN"},
                {BT_SET_CONTENT_PROTECT, "BT_SET_CONTENT_PROTECT"},
                {BT_AUDIO_SELECT_ROLE, "BT_AUDIO_SELECT_ROLE"},
+               {BT_AUDIO_SET_ABSOLUTE_VOLUME, "BT_AUDIO_SET_ABSOLUTE_VOLUME"},
+               {BT_AUDIO_GET_ABSOLUTE_VOLUME, "BT_AUDIO_GET_ABSOLUTE_VOLUME"},
+               {BT_AUDIO_IS_AVC_ACTIVATED, "BT_AUDIO_IS_AVC_ACTIVATED"},
                {BT_OOB_READ_LOCAL_DATA, "BT_OOB_READ_LOCAL_DATA"},
                {BT_OOB_ADD_REMOTE_DATA, "BT_OOB_ADD_REMOTE_DATA"},
                {BT_OOB_REMOVE_REMOTE_DATA, "BT_OOB_REMOVE_REMOTE_DATA"},
+               {BT_LE_OOB_READ_LOCAL_DATA, "BT_LE_OOB_READ_LOCAL_DATA"},
+               {BT_LE_OOB_ADD_REMOTE_DATA, "BT_LE_OOB_ADD_REMOTE_DATA"},
                {BT_AVRCP_SET_TRACK_INFO, "BT_AVRCP_SET_TRACK_INFO"},
                {BT_AVRCP_SET_PROPERTY, "BT_AVRCP_SET_PROPERTY"},
                {BT_AVRCP_SET_PROPERTIES, "BT_AVRCP_SET_PROPERTIES"},
@@ -555,6 +605,7 @@ const char *_bt_convert_service_function_to_string(int function)
                {BT_AVRCP_TARGET_CONNECT, "BT_AVRCP_TARGET_CONNECT"},
                {BT_AVRCP_TARGET_DISCONNECT, "BT_AVRCP_TARGET_DISCONNECT"},
                {BT_AVRCP_HANDLE_CONTROL, "BT_AVRCP_HANDLE_CONTROL"},
+               {BT_AVRCP_HANDLE_CONTROL_TO_DEST, "BT_AVRCP_HANDLE_CONTROL_TO_DEST"},
                {BT_AVRCP_CONTROL_SET_PROPERTY, "BT_AVRCP_CONTROL_SET_PROPERTY"},
                {BT_AVRCP_CONTROL_GET_PROPERTY, "BT_AVRCP_CONTROL_GET_PROPERTY"},
                {BT_AVRCP_GET_TRACK_INFO, "BT_AVRCP_GET_TRACK_INFO"},
@@ -746,7 +797,6 @@ gboolean _bt_utf8_validate(char *name)
        return TRUE;
 }
 
-
 static GDBusProxy *profile_gproxy;
 static int latest_id = -1;
 #define BT_RFCOMM_ID_MAX 245
@@ -896,7 +946,10 @@ static GDBusProxy *__bt_gdbus_get_profile_proxy(void)
        if (profile_gproxy)
                return profile_gproxy;
 
-       gconn = _bt_get_system_private_conn();
+       /* Shared connection should be used because rfcomm interface was registered
+        * on shared connection not private. Otherwise, dbus rejection is occured
+        * because dbus policy is only applied on shared connection not private. */
+       gconn = _bt_get_system_shared_conn();
        if (gconn == NULL)
                return NULL;
 
@@ -1222,7 +1275,7 @@ int _bt_register_profile_ex(bt_register_profile_info_t *info, gboolean use_defau
                                        NULL, &err);
        if (err) {
                g_dbus_error_strip_remote_error(err);
-               BT_ERR("RegisterProfile failed: %s", err->message);
+               BT_ERR("RegisterProfile2 failed: %s", err->message);
 
                if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
                        result = BLUETOOTH_ERROR_ACCESS_DENIED;
@@ -1290,7 +1343,7 @@ int _bt_register_profile_platform(bt_register_profile_info_t *info, gboolean use
 
        if (err) {
                g_dbus_error_strip_remote_error(err);
-               BT_ERR("RegisterProfile failed: %s", err->message);
+               BT_ERR("RegisterProfile1 failed: %s", err->message);
 
                if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
                        result = BLUETOOTH_ERROR_ACCESS_DENIED;
@@ -1336,6 +1389,32 @@ void _bt_unregister_profile(char *path)
        return;
 }
 
+void _bt_print_api_caller_name(void)
+{
+       FILE *fp = NULL;
+       char *path = NULL;
+       char buf[256] = {0, };
+       char **str_list = NULL;
+
+       path = g_strdup_printf("/proc/%d/cmdline", getpid());
+       fp = fopen(path, "r");
+       if (fp == NULL) {
+               g_free(path);
+               return;
+       }
+
+       if (fgets(buf, 256, fp) != NULL) {
+               str_list = g_strsplit(buf, " ", -1);
+               if (str_list[0] != NULL)
+                       BT_INFO("Caller : %s", str_list[0]);
+               g_strfreev(str_list);
+       }
+
+       fclose(fp);
+       g_free(path);
+       return;
+}
+
 int _bt_connect_profile(char *address, char *uuid, void *cb,
                                                        gpointer func_data)
 {
@@ -1389,6 +1468,8 @@ int _bt_connect_profile(char *address, char *uuid, void *cb,
                        DBUS_TIMEOUT, NULL,
                        (GAsyncReadyCallback)cb,
                        func_data);
+       if (cb == NULL)
+               g_object_unref(proxy);
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1434,6 +1515,8 @@ int _bt_discover_services(char *address, char *uuid, void *cb,
                        DBUS_TIMEOUT, NULL,
                        (GAsyncReadyCallback)cb,
                        func_data);
+       if (cb == NULL)
+               g_object_unref(proxy);
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1654,6 +1737,8 @@ int _bt_disconnect_profile(char *address, char *uuid, void *cb,
                        DBUS_TIMEOUT, NULL,
                        (GAsyncReadyCallback)cb,
                        func_data);
+       if (cb == NULL)
+               g_object_unref(proxy);
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1678,6 +1763,7 @@ int _bt_disconnect_ext_profile(char *address, char *path)
                        g_variant_new("(o)", path),
                        G_DBUS_CALL_FLAGS_NONE,
                        DBUS_TIMEOUT, NULL, NULL, NULL);
+       g_object_unref(proxy);
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1996,7 +2082,7 @@ void _bt_set_adapter_internal_status(gboolean enabled)
 
 BT_EXPORT_API int bluetooth_get_uuid_name(const char *uuid, char **name)
 {
-#define SHORT_UUID_COUNT       162
+#define SHORT_UUID_COUNT       199
 #define LONG_UUID_COUNT                17
 
        int offset = 0;
@@ -2097,6 +2183,17 @@ BT_EXPORT_API int bluetooth_get_uuid_name(const char *uuid, char **name)
                {"181D", "Weight Scale"},
                {"181E", "Bond Management"},
                {"181F", "Continuous Glucose Monitoring"},
+               {"1820", "Internet Protocol Support Service"},
+               {"1821", "Indoor Positioning"},
+               {"1822", "Pulse Oximeter Service"},
+               {"1823", "HTTP Proxy"},
+               {"1824", "Transport Discovery"},
+               {"1825", "Object Transfer Service"},
+               {"1826", "Fitness Machine"},
+               {"1827", "Mesh Provisioning Service"},
+               {"1828", "Mesh Proxy Service"},
+               {"1829", "Reconnection Configuration"},
+               {"183A", "Insulin Delivery"},
 
                /* GATT Declarations */
                {"2800", "Primary Service Declaration"},
@@ -2178,6 +2275,32 @@ BT_EXPORT_API int bluetooth_get_uuid_name(const char *uuid, char **name)
                {"2A68", "Navigation"},
                {"2A6D", "Pressure"},
                {"2A6E", "Temperature"},
+               {"2A8E", "Height"},
+               {"2A90", "Last Name"},
+               {"2A91", "Maximum Recommended Heart Rate"},
+               {"2A92", "Resting Heart Rate"},
+               {"2A98", "Weight"},
+               {"2A9B", "Body Composition Feature"},
+               {"2A9C", "Body Composition Measurement"},
+               {"2A9D", "Weight Measurement"},
+               {"2AA2", "Language"},
+               {"2AA4", "Bond Management Control Point"},
+               {"2AA5", "Bond Management Features"},
+               {"2AA6", "Central Address Resolution"},
+               {"2AAD", "Indoor Positioning Configuration"},
+               {"2AB5", "Location Name"},
+               {"2AB6", "URI"},
+               {"2ABC", "TDS Control Point"},
+               {"2AC9", "Resolvable Private Address Only"},
+               {"2ACC", "Fitness Machine Feature"},
+               {"2ACE", "Cross Trainer Data"},
+               {"2AD3", "Training Status"},
+               {"2AD7", "Supported Heart Rate Range"},
+               {"2AD9", "Fitness Machine Control Point"},
+               {"2ADA", "Fitness Machine Status"},
+               {"2B1D", "RC Feature"},
+               {"2B1E", "RC Settings"},
+               {"2B1F", "Reconnection Configuration Control Point"},
        };
        static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
                // List should be sorted by UUID
@@ -2232,7 +2355,6 @@ BT_EXPORT_API int bluetooth_get_uuid_name(const char *uuid, char **name)
                        start = p + 1;
        }
 
-       BT_INFO("Unknown uuid : %s", uuid);
        *name = g_strdup("Unknown");
        return BLUETOOTH_ERROR_NONE;
 }
@@ -2363,7 +2485,6 @@ BT_EXPORT_API int bluetooth_unregister_callback(void)
 {
        int ret;
 
-
        ret = _bt_deinit_event_handler();
        if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to deinit the event handler");
@@ -2374,8 +2495,15 @@ BT_EXPORT_API int bluetooth_unregister_callback(void)
 
        _bt_set_obex_server_id(BT_NO_SERVER);
 
+       _bt_reset_battery_monitor_info();
+
        _bt_gdbus_deinit_proxys();
 
+       if (profile_gproxy) {
+               g_object_unref(profile_gproxy);
+               profile_gproxy = NULL;
+       }
+
        if (system_private_conn) {
                g_object_unref(system_private_conn);
                system_private_conn = NULL;
@@ -2383,4 +2511,3 @@ BT_EXPORT_API int bluetooth_unregister_callback(void)
 
        return BLUETOOTH_ERROR_NONE;
 }
-