Modified the logic of advertisement slot allocation
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-event-receiver.c
index 719681c..9247eb8 100644 (file)
@@ -39,6 +39,7 @@
 #include "bt-hal-adapter-le.h"
 #include "bt-hal-gatt-server.h"
 #include "bt-hal-gatt-client.h"
+#include "bt-hal-adapter-dbus-handler.h"
 
 #define BASELEN_PROP_CHANGED (sizeof(struct hal_ev_adapter_props_changed) \
                + sizeof(struct hal_property))
@@ -110,6 +111,8 @@ static void __bt_hal_send_hf_audio_connection_state_event(gboolean connected, co
 static void __bt_hal_send_hf_connection_state_event(gboolean connected, const char *address);
 static void __bt_hal_send_device_trusted_profile_changed_event(uint32_t trust_val, const char *address);
 static void __bt_hal_handle_adv_report(GVariant *msg, const char *path);
+static void __bt_hal_handle_gatts_mtu_changed_event(char *address, int mtu);
+
 
 static gboolean __bt_hal_discovery_finished_cb(gpointer user_data)
 {
@@ -162,7 +165,7 @@ static int __bt_hal_parse_event(GVariant *msg)
 
 static int __bt_hal_get_owner_info(GVariant *msg, char **name, char **previous, char **current)
 {
-       g_variant_get(msg, "(sss)", name, previous, current);
+       g_variant_get(msg, "(&s&s&s)", name, previous, current);
        return BT_HAL_ERROR_NONE;
 }
 
@@ -482,6 +485,43 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
        DBG("-");
 }
 
+static void __bt_hal_flight_ps_mode_cb(keynode_t *node, void *data)
+{
+       gboolean flight_mode = FALSE;
+       int type;
+       DBG_SECURE("HAL callback hit");
+       DBG_SECURE("key=%s", vconf_keynode_get_name(node));
+       type = vconf_keynode_get_type(node);
+       if (type == VCONF_TYPE_BOOL) {
+               flight_mode = vconf_keynode_get_bool(node);
+               if (flight_mode != TRUE) {
+                       ERR("Ignore the event");
+                       return;
+               }
+               else {
+                       ERR("Flight Mode == TRUE");
+               }
+       } else {
+               ERR("Invaild vconf key type : %d", type);
+               return;
+       }
+       DBG("Enabling core now");
+       _bt_hal_enable_core();
+}
+
+static void _bt_hal_register_vconf_handler(void)
+{
+       DBG("+");
+
+       if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+               (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
+                       ERR("Unable to register key handler");
+       DBG("Telephony is disabled");
+       if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
+               (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
+                       ERR("Unable to register key handler");
+}
+
 void _bt_hal_handle_adapter_event(GVariant *msg, const char *member)
 {
        DBG("+");
@@ -499,7 +539,7 @@ void _bt_hal_handle_adapter_event(GVariant *msg, const char *member)
                int slot_id;
                gboolean status = FALSE;
                g_variant_get(msg, "(ib)", &slot_id, &status);
-               DBG("Advertising Enabled : slot_id [%d]  status [%d]", slot_id, status);
+               DBG("Advertising Enabled : server_slot_id [%d]  status [%d]", slot_id, status);
                /* Send event to application */
                _bt_hal_set_advertising_status(slot_id, status);
        } else if (strcasecmp(member, "RssiEnabled") == 0) {
@@ -989,17 +1029,23 @@ static gboolean __bt_hal_event_manager(gpointer data)
                char *previous = NULL;
                char *current = NULL;
 
+               if (g_strcmp0(g_variant_get_type_string(param->parameters), "(sss)") != 0) {
+                       ERR("Invalid variant format");
+                       return FALSE;
+               }
+
                /* TODO: Handle Name Owener changed Signal */
                if (__bt_hal_get_owner_info(param->parameters, &name, &previous, &current)) {
                        DBG("Fail to get the owner info");
                        return FALSE;
                }
-               if (current && *current != '\0') {
-                       g_free(name);
-                       g_free(previous);
-                       g_free(current);
+
+               if (*current != '\0')
                        return FALSE;
-               }
+
+               if (name == NULL)
+                       return FALSE;
+
                if (strcasecmp(name, BT_HAL_BLUEZ_NAME) == 0) {
                        DBG("Bluetoothd is terminated");
 
@@ -1007,10 +1053,6 @@ static gboolean __bt_hal_event_manager(gpointer data)
                        _bt_hal_le_deinit();
                }
                INFO("Name Owner changed [%s]", name);
-               g_free(name);
-               g_free(previous);
-               g_free(current);
-
        } else if (g_strcmp0(param->interface_name, BT_HAL_PROPERTIES_INTERFACE) == 0) {
                DBG("Manager Event: Interface Name: BT_HAL_PROPERTIES_INTERFACE");
                __bt_hal_handle_property_changed_event(param->parameters, param->object_path);
@@ -1451,6 +1493,9 @@ int _bt_hal_initialize_event_receiver(handle_stack_msg cb)
 
        /*TODO: Initialize Obexd Event receiver */
 
+       /* Initialize event receiver for flight mode  */
+       _bt_hal_register_vconf_handler();
+
        event_cb = cb;
        DBG("-");
 
@@ -2034,6 +2079,20 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                }
                g_free(address);
                g_free(profile_uuid);
+       } else if (strcasecmp(member, "AttMtuChanged") == 0) {
+               char *address;
+               guint16 mtu = 0;
+
+               address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE);
+
+               DBG("Member: [%s]", member);
+
+               _bt_hal_convert_device_path_to_address(path, address);
+               g_variant_get(msg, "(q)", &mtu);
+
+               __bt_hal_handle_gatts_mtu_changed_event(address, mtu);
+
+               g_free(address);
        } else if (strcasecmp(member, "AdvReport") == 0) {
                DBG("Member: [%s]", member);
                __bt_hal_handle_adv_report(msg, path);
@@ -2089,6 +2148,27 @@ static void __bt_hal_handle_adv_report(GVariant *msg, const char *path)
        g_variant_unref(value);
 }
 
+static void __bt_hal_handle_gatts_mtu_changed_event(char *address, int mtu)
+{
+       uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
+       struct hal_ev_gatt_server_mtu_changed *ev = (void *)buf;
+       size_t size = 0;
+
+       if (!gatt_event_cb)
+               return;
+
+       memset(buf, 0, sizeof(buf));
+       size = sizeof(*ev);
+
+       DBG("Address: %s, mtu: %d", address, mtu);
+
+       ev->conn_id = _bt_get_remote_gatt_client_conn_id(address);
+       ev->mtu = mtu;
+
+       DBG("Send GATT server mtu changed event to HAL, size: [%zd]", size);
+       gatt_event_cb(HAL_EV_GATT_SERVER_MTU_CHANGED, buf, size);
+}
+
 /* AVRCP Controller Role(Remote:AVRCP Target) Events */
 static void __bt_hal_send_avrcp_ctrl_connection_state_event(gboolean connected, const char *address)
 {