Audio connect issue if 2 Headset already connected
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-event-receiver.c
index ced268a..4a75398 100644 (file)
@@ -42,6 +42,8 @@
 #include "bt-service-proximity.h"
 
 #include "bt-service-opp-client.h"
+#include "bt-service-map-client.h"
+#include "bt-service-tds.h"
 
 #ifdef TIZEN_FEATURE_BT_DPM
 #include "bt-service-dpm.h"
@@ -51,6 +53,7 @@
 static GDBusConnection *manager_conn;
 static GDBusConnection *obexd_conn;
 static GDBusConnection *opc_obexd_conn;
+static GDBusConnection *map_obexd_conn;
 
 static GList *p_cache_list = NULL;
 
@@ -77,17 +80,21 @@ typedef enum {
        OBEX_PCSUITE = (1 << 6),
        OBEX_SYNCEVOLUTION = (1 << 7),
        OBEX_MAS = (1 << 8),
+       OBEX_MAP = (1 << 9),
 } bluetooth_obex_connection_type_t;
 
 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
 void _bt_opc_property_changed_event(GVariant *msg, char *path);
+void _bt_map_property_changed_event(GVariant *msg, const char *path);
 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
 void _bt_opp_client_event_deinit(void);
+void _bt_map_client_event_deinit(void);
 void _bt_handle_network_client_event(GVariant *msg_iter,
                                const char *path);
 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
                                const char *path);
+void _bt_map_on_transfer_finished(const char *transfer_object_path, const int error);
 
 static void __bt_free_bt_le_adv_info_t(gpointer data)
 {
@@ -534,18 +541,21 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member)
                param = g_variant_new("(ii)", result,
                                        adv_handle);
 
-#if 0
                const char *sender;
                sender = _bt_get_adv_slot_owner(slot_id);
                _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
                                event,
                                param);
-#else
-               _bt_send_event(BT_ADAPTER_EVENT, event, param);
-#endif
 
-               if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
+               if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) {
+                       char *name = g_strdup(sender);
+
                        _bt_unregister_adv_slot_owner(slot_id);
+
+                       /* Advertising disabled, notify TDS */
+                       _bt_tds_handle_adv_disabled(name, adv_handle);
+                       g_free(name);
+               }
        } else if (strcasecmp(member, "RssiEnabled") == 0) {
                BT_DBG("RSSI Enabled");
                gboolean status = FALSE;
@@ -592,13 +602,13 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member)
                                param);
                g_free(address);
        } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
-               BT_ERR_C("Hardware error received from BLUEZ");
+               BT_ERR_C("### Hardware error received from BLUEZ");
 /* Don't add the recovery logic into platform */
 #if 0
                _bt_recover_adapter();
 #endif
        } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
-               BT_ERR_C("Tx timeout error received from BLUEZ");
+               BT_ERR_C("### Tx timeout error received from BLUEZ");
 /* Don't add the recovery logic into platform */
 #if 0
                _bt_recover_adapter();
@@ -627,6 +637,9 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                        g_variant_get(val, "b", &discovering);
                        /* Send event to application */
                        BT_DBG("Discovering %d", discovering);
+                       if (_bt_adapter_get_status() != BT_ACTIVATED)
+                               return;
+
                        if (discovering == TRUE) {
                                _bt_set_discovery_status(TRUE);
                                param = g_variant_new("(i)", result);
@@ -659,6 +672,11 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                        gboolean le_discovering = FALSE;
 
                        g_variant_get(val, "b", &le_discovering);
+                       BT_DBG("LEDiscovering %d", le_discovering);
+                       if (_bt_adapter_get_status() != BT_ACTIVATED ||
+                               _bt_adapter_get_le_status() != BT_LE_ACTIVATED)
+                               return;
+
                        /* Send event to application */
                        if (le_discovering == TRUE) {
                                _bt_set_le_scan_status(TRUE);
@@ -893,6 +911,7 @@ static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
 
                        _bt_obex_transfer_progress(path, transferred);
                }
+               /* TODO: MAP, "Complete"? see above */
                g_free(property);
                g_variant_unref(val);
                g_variant_unref(child);
@@ -1415,7 +1434,7 @@ void __bt_opc_property_changed_event(GVariant *msg,
        GVariant *child = NULL;
 
        g_variant_iter_init(&value_iter, msg);
-       while ((child = g_variant_iter_next_value(&value_iter))) {
+       if ((child = g_variant_iter_next_value(&value_iter))) {
                g_variant_get(child, "{sv}", &property, &val);
                ret_if(property == NULL);
 
@@ -1462,6 +1481,68 @@ void _bt_opc_property_changed_event(GVariant *msg, char *path)
 }
 
 
+void __bt_map_property_changed_event(GVariant *msg,
+                                               const char *path)
+{
+       BT_DBG("Entered");
+       GVariantIter value_iter;
+       char *property = NULL;
+       GVariant *val = NULL;
+       GVariant *child = NULL;
+
+       g_variant_iter_init(&value_iter, msg);
+       while ((child = g_variant_iter_next_value(&value_iter))) {
+               g_variant_get(child, "{sv}", &property, &val);
+               ret_if(property == NULL);
+
+               if (strcasecmp(property, "Status") == 0) {
+                       char *status = NULL;
+                       g_variant_get(val, "s", &status);
+                       BT_DBG("Status is %s", status);
+
+                       if (strcasecmp(status, "active") == 0) {
+                               BT_DBG("EVENT : STARTED");
+                               // currently doing nothing
+                       } else if (strcasecmp(status, "complete") == 0) {
+                               BT_DBG("EVENT : COMPLETED");
+                               _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_NONE);
+                       } else if (strcasecmp(status, "error") == 0) {
+                               BT_DBG("EVENT : FAILED");
+                               _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_INTERNAL);
+                       }
+                       g_free(status);
+               } else if (strcasecmp(property, "Transferred") == 0) {
+                       guint64 transferred  = 0;
+                       g_variant_get(val, "t", &transferred);
+
+                       BT_DBG("EVENT : PROGRESS CALLBACK");
+                       // currently doing nothing - progress callback type is not used
+               } else {
+                       BT_DBG("OTHER EVENT : property : [%s]", property);
+               }
+               g_free(property);
+               g_variant_unref(child);
+               g_variant_unref(val);
+       }
+}
+
+void _bt_map_property_changed_event(GVariant *msg, const char *path)
+{
+       BT_DBG("Entered _bt_map_property_changed_event");
+       char *interface_name = NULL;
+       GVariant *value = NULL;
+       g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
+       BT_INFO("interface_name = %s", interface_name);
+       if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
+               __bt_map_property_changed_event(value,
+                               path);
+       } else {
+               BT_DBG("interface_name : [%s]", interface_name);
+       }
+       g_variant_unref(value);
+}
+
+
 void _bt_handle_input_event(GVariant *msg, const char *path)
 {
        int result = BLUETOOTH_ERROR_NONE;
@@ -1612,12 +1693,8 @@ void __bt_gatt_char_property_changed_event(GVariant *msg,
 {
        GVariantIter value_iter;
        char *property = NULL;
-       char * char_handle = NULL;
        GVariant *val = NULL;
-       int result = BLUETOOTH_ERROR_NONE;
-       GVariant *param = NULL;
        g_variant_iter_init(&value_iter, msg);
-       char_handle = g_strdup(path);
        while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
                BT_INFO("Property %s", property);
 
@@ -1630,73 +1707,21 @@ void __bt_gatt_char_property_changed_event(GVariant *msg,
                                BT_DBG("notifying is enabled");
                        else
                                BT_DBG("notifying is disabled");
-               } else if (strcasecmp(property, "ChangedValue") == 0) {
-                       int len = 0;
-                       GByteArray *gp_byte_array = NULL;
-                       BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
-
-                       if (val) {
-                               gp_byte_array = g_byte_array_new();
-                               len = g_variant_get_size(val);
-                               BT_DBG("Len = %d", len);
-                               g_byte_array_append(gp_byte_array,
-                                       (const guint8 *) g_variant_get_data(val), len);
-                               if (gp_byte_array->len != 0) {
-                                       GVariant *byte_array = NULL;
-                                       byte_array = g_variant_new_from_data(
-                                                               G_VARIANT_TYPE_BYTESTRING,
-                                                               gp_byte_array->data,
-                                                               gp_byte_array->len,
-                                                               TRUE, NULL, NULL);
-                                       param = g_variant_new("(is@ay)", result, char_handle,
-                                                               byte_array);
-
-                                       /* Send event only registered client */
-                                       _bt_send_char_value_changed_event(param);
-                               }
-                               g_byte_array_free(gp_byte_array, TRUE);
-                       }
                }
        }
-       g_free(char_handle);
 }
 
 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
 {
        ret_if(path == NULL);
-
        if (strcasecmp(member, "GattValueChanged") == 0) {
-
-#if 0 // Debug Only
-               /*** Debug only ***/
-               GVariant *value = NULL;
-               int value_len = 0;
-               char *buffer = NULL;
-
-               g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
-               value_len = g_variant_get_size(value);
-               if (value_len > 0) {
-                       char buf[8 * 5 + 1] = { 0 };
-                       int i;
-                       int to;
-                       buffer = (char *)g_variant_get_data(value);
-                       to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
-
-                       for (i = 0; i < to; i++)
-                               snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
-                       buf[i * 5] = '\0';
-                       BT_DBG("GATT Val[%d] %s", value_len, buf);
-               }
-               g_variant_unref(value);
-               /******/
-#endif
-
-               /* Send event only registered client */
-               _bt_send_char_value_changed_event(msg);
+               /* Check TDS seekers waiting for Indication  */
+               _bt_tds_check_indication(path, msg);
+       } else {
+               BT_INFO("Unhandled event");
        }
 }
 
-
 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
 {
        int event = 0;
@@ -1859,6 +1884,9 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                !addr_type ? dev_name : secure_address);
                g_free(dev_name);
 
+               if (addr_type)
+                       _bt_add_le_connected_dev_info(address);
+
                _bt_logging_connection(TRUE, addr_type);
                param = g_variant_new("(isy)", result, address, addr_type);
                /*Send event to application*/
@@ -1893,7 +1921,9 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                _bt_headset_set_local_connection(FALSE);
                _bt_logging_connection(FALSE, addr_type);
 
-               if (!addr_type) {
+               if (addr_type)
+                       _bt_remove_le_connected_dev_info(address);
+               else {
 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
                        {
                                int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
@@ -1927,6 +1957,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        _bt_opp_client_is_sending(&sending);
                        if (sending == TRUE)
                                _bt_opp_client_check_pending_transfer(address);
+                       /* TODO: MAP? see above */
                }
                param = g_variant_new("(isy)", result, address, addr_type);
                _bt_send_event(BT_DEVICE_EVENT,
@@ -1955,9 +1986,11 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        (state == BT_PROFILE_STATE_CONNECTED)) {
 
                        int event = BLUETOOTH_EVENT_AV_CONNECTED;
-                       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+#ifndef TIZEN_BT_DUAL_HEADSET_CONNECT
                        bluetooth_device_address_t device_address;
+                       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
                        gboolean connected;
+#endif
                        bt_headset_wait_t *wait_list;
                        guint restricted = 0x0;
 
@@ -1979,6 +2012,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        param = g_variant_new("(is)", result, address);
                        _bt_send_event(BT_HEADSET_EVENT, event,
                                param);
+#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
+                       _bt_check_already_connected_headset(BT_AUDIO_A2DP,
+                                               address);
+#else
                        connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
                                                connected_address);
                        if (connected) {
@@ -1990,7 +2027,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                                &device_address, NULL);
                                }
                        }
-
+#endif
                        _bt_add_headset_to_list(BT_AUDIO_A2DP,
                                                BT_STATE_CONNECTED, address);
 
@@ -2130,6 +2167,18 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        param = g_variant_new("(is)", result, address);
                        _bt_send_event(BT_HID_EVENT, event,
                                param);
+
+                       /* Set the vconf value for device */
+                       if (state == BT_PROFILE_STATE_CONNECTED) {
+                               hid_connected_device_count++;
+                               __bt_set_device_values(TRUE,
+                                               VCONFKEY_BT_DEVICE_HID_CONNECTED);
+                       } else {
+                               hid_connected_device_count--;
+                               if (hid_connected_device_count == 0)
+                                       __bt_set_device_values(FALSE,
+                                               VCONFKEY_BT_DEVICE_HID_CONNECTED);
+                       }
                } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
                        if (state == BT_PROFILE_STATE_CONNECTED) {
                                int event;
@@ -2164,7 +2213,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                                &le_dev_info->adv_data_len,
                                                &value);
 
-               ret_if(value == NULL);
+               if (value == NULL) {
+                       _bt_free_le_device_info(le_dev_info);
+                       return;
+               }
 
                _bt_convert_device_path_to_address(path, le_dev_info->address);
 
@@ -2231,6 +2283,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
        } else if  (strcasecmp(member, "IpspStateChanged") == 0) {
                gboolean connected = FALSE;
                char *ifname = NULL;
+               GVariant *ipsp_param = NULL;
 
                g_variant_get(msg, "(bs)", &connected, &ifname);
 
@@ -2243,12 +2296,66 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                BT_DBG("Ipsp BT Interface Name: %s", ifname);
                BT_DBG("address: %s", address);
                param = g_variant_new("(iss)", result, address, ifname);
+               ipsp_param = g_variant_new("(ss)", ifname, address);
+
+               /* Set Ipv6 Addr */
+               GDBusProxy *ipsp_proxy;
+               if (connected) {
+                       BT_DBG("IPSP connected, Set Ipv6 Addr");
+                       ipsp_proxy = _bt_get_ipsp_proxy();
+                       if (ipsp_proxy == NULL) {
+                               BT_ERR("can not get ipsp proxy");
+                               g_free(address);
+                               return;
+                       }
+
+                       g_dbus_proxy_call(ipsp_proxy, "SetIpv6Addr",
+                                       ipsp_param, G_DBUS_CALL_FLAGS_NONE,
+                                       -1, NULL, NULL, NULL);
+               } else {
+                       BT_DBG("IPSP disconnected");
+                       ipsp_proxy = _bt_get_ipsp_proxy();
+                       if (ipsp_proxy == NULL) {
+                               BT_ERR("can not get ipsp proxy");
+                               g_free(address);
+                               return;
+                       }
+
+                       g_dbus_proxy_call(ipsp_proxy, "DisableIpsp",
+                                       NULL, G_DBUS_CALL_FLAGS_NONE,
+                                       -1, NULL, NULL, NULL);
+               }
 
                /* Send event to application */
                _bt_send_event(BT_DEVICE_EVENT,
                                                event,
                                                param);
                g_free(address);
+       } else if (strcasecmp(member, "AttMtuChanged") == 0) {
+               int result = BLUETOOTH_ERROR_NONE;
+               guint16 mtu = 0;
+               guint8 status = 0;
+
+               g_variant_get(msg, "(q)", &mtu);
+
+               address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+               _bt_convert_device_path_to_address(path, address);
+               _bt_convert_addr_string_to_secure_string(secure_address, address);
+               BT_DBG("Address : %s MTU changed : %d", secure_address, mtu);
+
+               param = g_variant_new("(isqy)",
+                       result,
+                       address,
+                       mtu,
+                       status);
+
+               /* Send the event to application */
+               _bt_send_event(BT_DEVICE_EVENT,
+                       BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
+                       param);
+
+               g_free(address);
        }
 }
 
@@ -2362,7 +2469,6 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                                                        wait_list->address);
                        _bt_audio_connect(wait_list->req_id, wait_list->type,
                                        &device_address, NULL);
-                       _bt_rel_wait_data();
                } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
                        /* Add data to the connected list */
                        _bt_add_headset_to_list(BT_AUDIO_HSP,
@@ -2561,6 +2667,7 @@ void _bt_handle_agent_event(GVariant *msg, const char *member)
                _bt_send_event(BT_OPP_SERVER_EVENT,
                        BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
                        param);
+               /* TODO: MAP? see above */
                g_free(address);
                g_free(name);
        } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
@@ -2582,6 +2689,34 @@ void _bt_handle_agent_event(GVariant *msg, const char *member)
        }
 }
 
+void _bt_handle_tds_provider_event(GVariant *msg, const char *member, const char *path)
+{
+       BT_INFO("member: %s, path: %s", member, path);
+
+       ret_if(path == NULL);
+
+       if (strcasecmp(member, "TdsActivationRequested") == 0) {
+               GVariant *value = NULL;
+               int len = 0;
+               unsigned char *buffer = NULL;
+               unsigned char org_id;
+
+               g_variant_get(msg, "(y@ay)", &org_id, &value);
+               BT_DBG("org_id: %.2x", org_id);
+               len = g_variant_get_size(value);
+               if (len > 0) {
+                       int i;
+                       buffer = (unsigned char *)g_variant_get_data(value);
+                       for (i = 0; i < len; i++)
+                               BT_DBG("%.2x", buffer[i]);
+               }
+
+               /* Send event only registered client */
+               _bt_tds_handle_activation_request(path, org_id, buffer, len);
+               g_variant_unref(value);
+       }
+}
+
 static int __bt_get_object_path(GVariant *msg, char **path)
 {
        g_variant_get(msg, "(o*)", path, NULL);
@@ -2801,11 +2936,13 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                        BT_INFO_C("### Bluetoothd is terminated");
                        if (_bt_adapter_get_status() != BT_DEACTIVATING &&
                                _bt_adapter_get_status() != BT_DEACTIVATED) {
-                               BT_INFO_C("### Recover it");
-                               _bt_recover_adapter();
+                               BT_INFO_C("Turn Off Bluetooth");
+                               _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
+                               _bt_disable_cb();
                        }
                        _bt_handle_adapter_removed();
                        __bt_devices_list_free();
+                       _bt_service_adapter_le_deinit();
                }
 
                _bt_obex_server_check_allocation(&value);
@@ -2822,6 +2959,9 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                        _bt_rfcomm_server_check_termination(name);
                }
 
+               /* Reset connection interval */
+               _bt_remove_all_le_conn_param_info(name);
+
                /* Stop advertising started by terminated process */
                _bt_stop_advertising_by_terminated_process(name);
                /* Stop LE Scan */
@@ -2830,6 +2970,9 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                /* Stop the Proximity reporter service */
                _bt_proximity_reporter_stop_by_terminated_process(name);
 
+               /* Stop the Transport Discovery service */
+               _bt_tds_stop_by_terminated_process(name);
+
                g_free(name);
                g_free(previous);
                g_free(current);
@@ -2855,6 +2998,8 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                _bt_handle_agent_event(parameters, signal_name);
        } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
                _bt_handle_device_event(parameters, signal_name, object_path);
+       } else if (g_strcmp0(interface_name, BT_TDS_PROVIDER_INTERFACE) == 0) {
+               _bt_handle_tds_provider_event(parameters, signal_name, object_path);
        } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
                _bt_handle_gatt_event(parameters, signal_name, object_path);
        }
@@ -2900,6 +3045,7 @@ static  void __bt_obexd_event_filter(GDBusConnection *connection,
                BT_INFO("object_path = [%s]", obj_path);
 
                /*Handle OPP_SERVER_CONNECTED_EVENT here */
+               /* TODO: MAP? see above */
                if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
                                strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
                        g_free(obj_path);
@@ -2913,6 +3059,7 @@ static  void __bt_obexd_event_filter(GDBusConnection *connection,
                g_free(obj_path);
        } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
                /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
+               /* TODO: MAP? see above */
                if (__bt_get_object_path(parameters, &obj_path)) {
                        BT_ERR("Fail to get the path");
                        return;
@@ -3063,56 +3210,118 @@ void _bt_opp_client_event_deinit(void)
        }
 }
 
+static  void __bt_map_event_filter(GDBusConnection *connection,
+                                       const gchar *sender_name,
+                                       const gchar *object_path,
+                                       const gchar *interface_name,
+                                       const gchar *signal_name,
+                                       GVariant *parameters,
+                                       gpointer user_data)
+{
+       BT_DBG("Entered __bt_map_event_filter");
+       const char *member = signal_name;
+
+       if (strcasecmp(member, "InterfacesAdded") == 0) {
+               BT_DBG("------------------------------------ADDED------------------------------------");
+               // currently doing nothing
+       } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+               BT_DBG("------------------------------------REMOVED------------------------------------");
+               // TODO check if something should be called here?
+               //_bt_map_on_transfer_finished(object_path, error);
+       } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
+               BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
+               _bt_map_property_changed_event(parameters, object_path);
+       }
+
+       return;
+}
+
+int _bt_map_client_event_init(void)
+{
+       GError *error = NULL;
+
+       if (map_obexd_conn == NULL) {
+               map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+               if (!map_obexd_conn) {
+                       if (error) {
+                               BT_ERR("Unable to connect to dbus: %s", error->message);
+                               g_clear_error(&error);
+                       }
+               return BLUETOOTH_ERROR_INTERNAL;
+               }
+       }
+
+       if (_bt_register_service_event(map_obexd_conn,
+                       BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
+                       g_object_unref(map_obexd_conn);
+                       map_obexd_conn = NULL;
+                       return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_map_client_event_deinit(void)
+{
+       if (map_obexd_conn) {
+               _bt_unregister_service_event(map_obexd_conn,
+                                               BT_MAP_CLIENT_EVENT);
+                g_object_unref(map_obexd_conn);
+                map_obexd_conn = NULL;
+       }
+}
+
 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
                int subscribe)
 {
        if (conn == NULL)
                return -1;
 
-       static int subs_interface_added_id = -1;
-       static int subs_interface_removed_id = -1;
-       static int subs_name_owner_id = -1;
-       static int subs_property_id = -1;
-       static int subs_adapter_id = -1;
-       static int subs_gatt_id = -1;
+       static guint subs_interface_added_id;
+       static guint subs_interface_removed_id;
+       static guint subs_name_owner_id;
+       static guint subs_property_id;
+       static guint subs_adapter_id;
+       static guint subs_gatt_id;
 
        if (subscribe) {
-               if (subs_interface_added_id == -1) {
+               if (subs_interface_added_id == 0) {
                        subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_ADDED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_interface_removed_id == -1) {
+               if (subs_interface_removed_id == 0) {
                        subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_name_owner_id == -1) {
+               if (subs_name_owner_id == 0) {
                        subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_FREEDESKTOP_INTERFACE,
                                BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_property_id == -1) {
+               if (subs_property_id == 0) {
                        subs_property_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_PROPERTIES_INTERFACE,
                                BT_PROPERTIES_CHANGED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_adapter_id == -1) {
+               if (subs_adapter_id == 0) {
                        subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_ADAPTER_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_gatt_id == -1) {
+               if (subs_gatt_id == 0) {
                        subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_GATT_CHAR_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3120,33 +3329,33 @@ int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_interface_added_id != -1) {
+               if (subs_interface_added_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_interface_added_id);
-                       subs_interface_added_id = -1;
+                       subs_interface_added_id = 0;
                }
-               if (subs_interface_removed_id != -1) {
+               if (subs_interface_removed_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_interface_removed_id);
-                       subs_interface_removed_id = -1;
+                       subs_interface_removed_id = 0;
                }
-               if (subs_name_owner_id != -1) {
+               if (subs_name_owner_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_name_owner_id);
-                       subs_name_owner_id = -1;
+                       subs_name_owner_id = 0;
                }
-               if (subs_property_id != -1) {
+               if (subs_property_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_property_id);
-                       subs_property_id = -1;
+                       subs_property_id = 0;
                }
-               if (subs_adapter_id != -1) {
+               if (subs_adapter_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
-                       subs_adapter_id = -1;
+                       subs_adapter_id = 0;
                }
-               if (subs_gatt_id != -1) {
+               if (subs_gatt_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
-                       subs_gatt_id = -1;
+                       subs_gatt_id = 0;
                }
        }
        return 0;
@@ -3158,10 +3367,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_device_id = -1;
+       static guint subs_device_id;
 
        if (subscribe) {
-               if (subs_device_id == -1) {
+               if (subs_device_id == 0) {
                        subs_device_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_DEVICE_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3169,10 +3378,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_device_id != -1) {
+               if (subs_device_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_device_id);
-                       subs_device_id = -1;
+                       subs_device_id = 0;
                }
        }
        return 0;
@@ -3184,10 +3393,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_input_id = -1;
+       static int subs_input_id;
 
        if (subscribe) {
-               if (subs_input_id == -1) {
+               if (subs_input_id == 0) {
                        subs_input_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_INPUT_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3195,10 +3404,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_input_id != -1) {
+               if (subs_input_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_input_id);
-                       subs_input_id = -1;
+                       subs_input_id = 0;
                }
        }
        return 0;
@@ -3210,18 +3419,18 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_serv_id = -1;
-       static int subs_client_id = -1;
+       static guint subs_serv_id;
+       static guint subs_client_id;
 
        if (subscribe) {
-               if (subs_serv_id == -1) {
+               if (subs_serv_id == 0) {
                        subs_serv_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_NETWORK_SERVER_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_client_id == -1) {
+               if (subs_client_id == 0) {
                        subs_client_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_NETWORK_CLIENT_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3229,15 +3438,15 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_serv_id != -1) {
+               if (subs_serv_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_serv_id);
-                       subs_serv_id = -1;
+                       subs_serv_id = 0;
                }
-               if (subs_client_id != -1) {
+               if (subs_client_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_client_id);
-                       subs_client_id = -1;
+                       subs_client_id = 0;
                }
        }
        return 0;
@@ -3249,18 +3458,18 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_headset_id = -1;
-       static int subs_sink_id = -1;
+       static guint subs_headset_id;
+       static guint subs_sink_id;
 
        if (subscribe) {
-               if (subs_headset_id == -1) {
+               if (subs_headset_id == 0) {
                        subs_headset_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_HEADSET_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_sink_id == -1) {
+               if (subs_sink_id == 0) {
                        subs_sink_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_SINK_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3268,15 +3477,15 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_headset_id != -1) {
+               if (subs_headset_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_headset_id);
-                       subs_headset_id = -1;
+                       subs_headset_id = 0;
                }
-               if (subs_sink_id != -1) {
+               if (subs_sink_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_sink_id);
-                       subs_sink_id = -1;
+                       subs_sink_id = 0;
                }
        }
        return 0;
@@ -3288,27 +3497,27 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_opp_server_interface_added_id = -1;
-       static int subs_opp_server_interface_removed_id = -1;
-       static int subs_opp_server_property_id = -1;
+       static guint subs_opp_server_interface_added_id;
+       static guint subs_opp_server_interface_removed_id;
+       static guint subs_opp_server_property_id;
 
 
        if (subscribe) {
-               if (subs_opp_server_interface_added_id == -1) {
+               if (subs_opp_server_interface_added_id == 0) {
                        subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_ADDED, NULL, NULL, 0,
                                __bt_obexd_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_server_interface_removed_id == -1) {
+               if (subs_opp_server_interface_removed_id == 0) {
                        subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_obexd_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_server_property_id == -1) {
+               if (subs_opp_server_property_id == 0) {
                        subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_PROPERTIES_INTERFACE,
                                BT_PROPERTIES_CHANGED, NULL, NULL, 0,
@@ -3316,20 +3525,20 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_opp_server_interface_added_id != -1) {
+               if (subs_opp_server_interface_added_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_server_interface_added_id);
-                       subs_opp_server_interface_added_id = -1;
+                       subs_opp_server_interface_added_id = 0;
                }
-               if (subs_opp_server_interface_removed_id != -1) {
+               if (subs_opp_server_interface_removed_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_server_interface_removed_id);
-                       subs_opp_server_interface_removed_id = -1;
+                       subs_opp_server_interface_removed_id = 0;
                }
-               if (subs_opp_server_property_id != -1) {
+               if (subs_opp_server_property_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_server_property_id);
-                       subs_opp_server_property_id = -1;
+                       subs_opp_server_property_id = 0;
                }
        }
        return 0;
@@ -3341,27 +3550,27 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_opp_client_interface_added_id = -1;
-       static int subs_opp_client_interface_removed_id = -1;
-       static int subs_opp_client_property_id = -1;
+       static guint subs_opp_client_interface_added_id;
+       static guint subs_opp_client_interface_removed_id;
+       static guint subs_opp_client_property_id;
 
 
        if (subscribe) {
-               if (subs_opp_client_interface_added_id == -1) {
+               if (subs_opp_client_interface_added_id == 0) {
                        subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_ADDED, NULL, NULL, 0,
                                __bt_opc_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_client_interface_removed_id == -1) {
+               if (subs_opp_client_interface_removed_id == 0) {
                        subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_opc_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_client_property_id == -1) {
+               if (subs_opp_client_property_id == 0) {
                        subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_PROPERTIES_INTERFACE,
                                BT_PROPERTIES_CHANGED, NULL, NULL, 0,
@@ -3369,20 +3578,73 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_opp_client_interface_added_id != -1) {
+               if (subs_opp_client_interface_added_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_client_interface_added_id);
-                       subs_opp_client_interface_added_id = -1;
+                       subs_opp_client_interface_added_id = 0;
                }
-               if (subs_opp_client_interface_removed_id != -1) {
+               if (subs_opp_client_interface_removed_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_client_interface_removed_id);
-                       subs_opp_client_interface_removed_id = -1;
+                       subs_opp_client_interface_removed_id = 0;
                }
-               if (subs_opp_client_property_id != -1) {
+               if (subs_opp_client_property_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_client_property_id);
-                       subs_opp_client_property_id = -1;
+                       subs_opp_client_property_id = 0;
+               }
+       }
+       return 0;
+}
+
+int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
+               int subscribe)
+{
+       if (conn == NULL)
+               return -1;
+
+       static guint subs_map_client_interface_added_id;
+       static guint subs_map_client_interface_removed_id;
+       static guint subs_map_client_property_id;
+
+
+       if (subscribe) {
+               if (subs_map_client_interface_added_id == 0) {
+                       subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_MANAGER_INTERFACE,
+                               BT_INTERFACES_ADDED, NULL, NULL, 0,
+                               __bt_map_event_filter,
+                               NULL, NULL);
+               }
+               if (subs_map_client_interface_removed_id == 0) {
+                       subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_MANAGER_INTERFACE,
+                               BT_INTERFACES_REMOVED, NULL, NULL, 0,
+                               __bt_map_event_filter,
+                               NULL, NULL);
+               }
+               if (subs_map_client_property_id == 0) {
+                       subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_PROPERTIES_INTERFACE,
+                               BT_PROPERTIES_CHANGED, NULL, NULL, 0,
+                               __bt_map_event_filter,
+                               NULL, NULL);
+               }
+       } else {
+               if (subs_map_client_interface_added_id > 0) {
+                       g_dbus_connection_signal_unsubscribe(conn,
+                                       subs_map_client_interface_added_id);
+                       subs_map_client_interface_added_id = 0;
+               }
+               if (subs_map_client_interface_removed_id > 0) {
+                       g_dbus_connection_signal_unsubscribe(conn,
+                                       subs_map_client_interface_removed_id);
+                       subs_map_client_interface_removed_id = 0;
+               }
+               if (subs_map_client_property_id > 0) {
+                       g_dbus_connection_signal_unsubscribe(conn,
+                                       subs_map_client_property_id);
+                       subs_map_client_property_id = 0;
                }
        }
        return 0;
@@ -3394,18 +3656,18 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_a2dp_source_id = -1;
-       static int subs_a2dp_sink_id = -1;
+       static guint subs_a2dp_source_id;
+       static guint subs_a2dp_sink_id;
 
        if (subscribe) {
-               if (subs_a2dp_source_id == -1) {
+               if (subs_a2dp_source_id == 0) {
                        subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_A2DP_SOURCE_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_opc_event_filter,
                                NULL, NULL);
                }
-               if (subs_a2dp_sink_id == -1) {
+               if (subs_a2dp_sink_id == 0) {
                        subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_SINK_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3413,20 +3675,46 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_a2dp_source_id != -1) {
+               if (subs_a2dp_source_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_a2dp_source_id);
-                       subs_a2dp_source_id = -1;
+                       subs_a2dp_source_id = 0;
                }
-               if (subs_a2dp_sink_id != -1) {
+               if (subs_a2dp_sink_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_a2dp_sink_id);
-                       subs_a2dp_sink_id = -1;
+                       subs_a2dp_sink_id = 0;
                }
        }
        return 0;
 }
 
+int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscribe)
+{
+       if (conn == NULL)
+               return -1;
+
+       static guint subs_custom_id;
+
+       if (subscribe) {
+               if (subs_custom_id == 0) {
+                       subs_custom_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_TDS_PROVIDER_INTERFACE,
+                               NULL, NULL, NULL, 0,
+                               __bt_manager_event_filter,
+                               NULL, NULL);
+               }
+       } else {
+               if (subs_custom_id > 0) {
+                       g_dbus_connection_signal_unsubscribe(conn,
+                                       subs_custom_id);
+                       subs_custom_id = 0;
+               }
+       }
+
+       return 0;
+}
+
 static void __bt_dump_event_filter(GDBusConnection *connection,
                                        const gchar *sender_name,
                                        const gchar *object_path,
@@ -3444,10 +3732,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_source_id = -1;
+       static guint subs_source_id;
 
        if (subscribe) {
-               if (subs_source_id == -1) {
+               if (subs_source_id == 0) {
                        subs_source_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_DUMP_SERVICE_INTERFACE,
                                BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
@@ -3455,10 +3743,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_source_id != -1) {
+               if (subs_source_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_source_id);
-                       subs_source_id = -1;
+                       subs_source_id = 0;
                }
        }
        return 0;
@@ -3486,19 +3774,27 @@ int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
        case BT_HEADSET_EVENT:
                _bt_register_audio_subscribe_signal(g_conn, TRUE);
                break;
-
        case BT_OPP_SERVER_EVENT:
                BT_ERR("BT_OPP_SERVER_EVENT: register service event");
                _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
                break;
+
        case BT_OPP_CLIENT_EVENT:
                BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
                _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
                break;
+       case BT_MAP_CLIENT_EVENT:
+               BT_ERR("BT_MAP_CLIENT_EVENT: register service event");
+               _bt_register_map_client_subscribe_signal(g_conn, TRUE);
+               break;
        case BT_A2DP_SOURCE_EVENT:
                BT_INFO("A2dp Source event");
                _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
                break;
+       case BT_TDS_EVENT:
+               BT_INFO("TDS provider event");
+               _bt_register_tds_provider_subscribe_signal(g_conn, TRUE);
+               break;
        default:
                BT_ERR("Unknown event");
                return BLUETOOTH_ERROR_INTERNAL;
@@ -3527,6 +3823,9 @@ void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
        case BT_OPP_CLIENT_EVENT:
                _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
                break;
+       case BT_MAP_CLIENT_EVENT:
+               _bt_register_map_client_subscribe_signal(g_conn, FALSE);
+               break;
        default:
                BT_ERR("Unknown event");
                return;
@@ -3569,6 +3868,10 @@ static int __bt_init_manager_receiver(void)
                                BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
                goto fail;
 
+       if (_bt_register_service_event(manager_conn,
+                               BT_TDS_EVENT) != BLUETOOTH_ERROR_NONE)
+               goto fail;
+
        __bt_register_dump_subscribe_signal(manager_conn, TRUE);
        return BLUETOOTH_ERROR_NONE;
 fail: