Enable the connection request event for custom obex server
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-agent.c
index 3b58d5d..4e57787 100644 (file)
@@ -73,8 +73,8 @@
 #define BT_HAL_AGENT_SYSPOPUP_MAX_ATTEMPT 3
 
 #define G_VARIANT_UNREF(variant) \
-        g_variant_unref(variant); \
-        variant = NULL
+       g_variant_unref(variant); \
+       variant = NULL
 #define BT_HAL_MAX_EVENT_STR_LENGTH 50
 
 static void *adapter_agent = NULL;
@@ -93,7 +93,7 @@ static gboolean __bt_hal_passkey_request(GapAgentPrivate *agent, GDBusProxy *dev
 static gboolean __bt_hal_confirm_request(GapAgentPrivate *agent, GDBusProxy *device,
                guint passkey);
 static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
-                                                        const char *uuid);
+                                                               const char *uuid);
 static gboolean __bt_hal_authorize_cancel_request(GapAgentPrivate *agent, const char *address);
 static gboolean __bt_hal_pairing_cancel_request(GapAgentPrivate *agent, const char *address);
 static GVariant *__bt_hal_service_getall(GDBusProxy *device, const char *interface);
@@ -103,12 +103,12 @@ static inline void stack_trim(void);
 static gboolean __bt_hal_device_is_hid_keyboard(unsigned int dev_class);
 static int __bt_hal_device_generate_passkey(char *passkey, int size);
 static gboolean __bt_hal_device_is_auto_response(uint32_t dev_class,
-                const gchar *address, const gchar *name);
+               const gchar *address, const gchar *name);
 static gboolean __bt_hal_device_is_device_blacklisted(const char *address, const char *name);
 static gboolean __bt_hal_find_device_by_address_exactname(char *buffer,
-                const char *address);
+               const char *address);
 static gboolean __bt_hal_find_device_by_partial_name(char *buffer,
-                const char *partial_name);
+               const char *partial_name);
 static void __bt_hal_send_ssp_request_events(const gchar *address, const gchar *name,
                guint passkey, uint32_t cod, unsigned char variant);
 static void __bt_hal_send_authorize_request_event(const gchar *address, const char *uuid);
@@ -327,7 +327,7 @@ void __bt_hal_get_auth_info(GVariant *reply, char *auth_info)
                is_alias_set = FALSE;
        }
        if (is_alias_set == FALSE) {
-               tmp_value = g_variant_lookup_value(reply, "ManufacturerDataLen",
+               tmp_value = g_variant_lookup_value(reply, "LagacyManufacturerDataLen",
                                                                G_VARIANT_TYPE_UINT16);
                if (tmp_value) {
                        manufacturer_data_len = g_variant_get_uint16(tmp_value);
@@ -340,7 +340,7 @@ void __bt_hal_get_auth_info(GVariant *reply, char *auth_info)
                } else
                        manufacturer_data_len = 0;
 
-               tmp_value = g_variant_lookup_value(reply, "ManufacturerData",
+               tmp_value = g_variant_lookup_value(reply, "LagacyManufacturerData",
                                                                G_VARIANT_TYPE_ARRAY);
                if (tmp_value) {
                        if ((manufacturer_data_len == 0) ||
@@ -401,7 +401,7 @@ static gboolean __bt_hal_pincode_request(GapAgentPrivate *agent, GDBusProxy *dev
                goto done;
        }
 
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
 
        tmp_value = g_variant_lookup_value(reply, "Class", G_VARIANT_TYPE_UINT32);
        g_variant_get(tmp_value, "u", &device_class);
@@ -478,7 +478,7 @@ static void __bt_hal_send_ssp_request_events(const gchar *address,
 {
        struct hal_ev_ssp_request ev;
        memset(&ev, 0, sizeof(ev));
-       DBG("sizeof ev [%d]", sizeof(ev));
+       DBG("sizeof ev [%zu]", sizeof(ev));
 
        DBG("Remote Device address [%s]", address);
        DBG("Remote Device Name [%s]", name);
@@ -523,9 +523,9 @@ static gboolean __bt_hal_display_request(GapAgentPrivate *agent, GDBusProxy *dev
                goto done;
        }
 
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
 
-       tmp_value = g_variant_lookup_value (reply, "Address", G_VARIANT_TYPE_STRING);
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
        g_variant_get(tmp_value, "s", &address);
        G_VARIANT_UNREF(tmp_value);
        if (!address) {
@@ -594,9 +594,9 @@ static gboolean __bt_hal_passkey_request(GapAgentPrivate *agent, GDBusProxy *dev
                goto done;
        }
 
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
 
-       tmp_value = g_variant_lookup_value (reply, "Address", G_VARIANT_TYPE_STRING);
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
        g_variant_get(tmp_value, "s", &address);
        G_VARIANT_UNREF(tmp_value);
        if (!address) {
@@ -660,13 +660,13 @@ static gboolean __bt_hal_confirm_request(GapAgentPrivate *agent, GDBusProxy *dev
                                NULL);
                goto done;
        }
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
 
-       tmp_value = g_variant_lookup_value (reply, "Address", G_VARIANT_TYPE_STRING);
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
        g_variant_get(tmp_value, "s", &address);
        G_VARIANT_UNREF(tmp_value);
 
-       tmp_value = g_variant_lookup_value (reply, "Name", G_VARIANT_TYPE_STRING);
+       tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
        g_variant_get(tmp_value, "s", &name);
        G_VARIANT_UNREF(tmp_value);
 
@@ -703,7 +703,7 @@ done:
 }
 
 static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
-                                                        const char *uuid)
+               const char *uuid)
 {
        const gchar *address;
        const gchar *name;
@@ -721,9 +721,9 @@ static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *d
                goto done;
        }
 
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
 
-       tmp_value = g_variant_lookup_value (reply, "Address", G_VARIANT_TYPE_STRING);
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
        g_variant_get(tmp_value, "s", &address);
        G_VARIANT_UNREF(tmp_value);
        if (!address) {
@@ -779,12 +779,18 @@ static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *d
        }
 
 #ifdef TIZEN_BT_HAL
-       if (!strcasecmp(uuid, BT_HAL_OPP_UUID) &&
-               (NULL != _bt_hal_gap_agent_find_osp_server_by_type(
-                               agent->osp_servers, BT_OSP_SERVER_OBEX))) {
-               INFO("OSP server for OPP found, send event");
-               __bt_hal_send_authorize_request_event(address, uuid);
-               goto done;
+       if (!strcasecmp(uuid, BT_HAL_OPP_UUID)) {
+               if (NULL != _bt_hal_gap_agent_find_osp_server_by_type(
+                               agent->osp_servers, BT_OSP_SERVER_OBEX)) {
+                       INFO("OSP server for OPP found, send event");
+                       __bt_hal_send_authorize_request_event(address, uuid);
+                       goto done;
+               } else {
+                       INFO("Native OPP server, auto accept");
+                       gap_agent_reply_authorize(agent,
+                                       GAP_AGENT_ACCEPT, NULL);
+                       goto done;
+               }
        }
 
        if (_is_rfcomm_server_uuid(uuid)) {
@@ -848,19 +854,19 @@ static gboolean __bt_hal_pairing_cancel_request(GapAgentPrivate *agent, const ch
                headed_plugin_info->headed_plugin->bt_destroy_popup_all();
 
        __bt_hal_agent_release_memory();
-        return TRUE;
+       return TRUE;
 }
 
 static gboolean __bt_hal_device_is_hid_keyboard(unsigned int dev_class)
 {
        switch ((dev_class & 0x1f00) >> 8) {
-               case 0x05:
-                       switch ((dev_class & 0xc0) >> 6) {
-                               case 0x01:
-                                       /* input-keyboard" */
-                                       return TRUE;
-                       }
-                       break;
+       case 0x05:
+               switch ((dev_class & 0xc0) >> 6) {
+               case 0x01:
+                       /* input-keyboard" */
+                       return TRUE;
+               }
+               break;
        }
 
        return FALSE;
@@ -1031,47 +1037,47 @@ static gboolean __bt_hal_device_is_auto_response(uint32_t dev_class,
                return FALSE;
 
        switch ((dev_class & 0x1f00) >> 8) {
-               case 0x04:
-                       switch ((dev_class & 0xfc) >> 2) {
-                               case 0x01:
-                               case 0x02:
-                                       /* Headset */
-                                       is_headset = TRUE;
-                                       break;
-                               case 0x06:
-                                       /* Headphone */
-                                       is_headset = TRUE;
-                                       break;
-                               case 0x0b:      /* VCR */
-                               case 0x0c:      /* Video Camera */
-                               case 0x0d:      /* Camcorder */
-                                       break;
-                               default:
-                                       /* Other audio device */
-                                       is_headset = TRUE;
-                                       break;
-                       }
+       case 0x04:
+               switch ((dev_class & 0xfc) >> 2) {
+               case 0x01:
+               case 0x02:
+                       /* Headset */
+                       is_headset = TRUE;
                        break;
-               case 0x05:
-                       switch (dev_class & 0xff) {
-                               case 0x80:  /* 0x80: Pointing device(Mouse) */
-                                       is_mouse = TRUE;
-                                       break;
-
-                               case 0x40: /* 0x40: input device (BT keyboard) */
-
-                                       /* Get the LAP(Lower Address part) */
-                                       g_strlcpy(lap_address, address, sizeof(lap_address));
-
-                                       /* Need to Auto pair the blacklisted Keyboard */
-                                       if (__bt_hal_device_is_device_blacklisted(lap_address, name) != TRUE) {
-                                               DBG("Device is not black listed\n");
-                                               return FALSE;
-                                       } else {
-                                               ERR("Device is black listed\n");
-                                               return TRUE;
-                                       }
+               case 0x06:
+                       /* Headphone */
+                       is_headset = TRUE;
+                       break;
+               case 0x0b:      /* VCR */
+               case 0x0c:      /* Video Camera */
+               case 0x0d:      /* Camcorder */
+                       break;
+               default:
+                       /* Other audio device */
+                       is_headset = TRUE;
+                       break;
+               }
+               break;
+       case 0x05:
+               switch (dev_class & 0xff) {
+               case 0x80:  /* 0x80: Pointing device(Mouse) */
+                       is_mouse = TRUE;
+                       break;
+
+               case 0x40: /* 0x40: input device (BT keyboard) */
+
+                       /* Get the LAP(Lower Address part) */
+                       g_strlcpy(lap_address, address, sizeof(lap_address));
+
+                       /* Need to Auto pair the blacklisted Keyboard */
+                       if (__bt_hal_device_is_device_blacklisted(lap_address, name) != TRUE) {
+                               DBG("Device is not black listed\n");
+                               return FALSE;
+                       } else {
+                               ERR("Device is black listed\n");
+                               return TRUE;
                        }
+               }
        }
 
        if ((!is_headset) && (!is_mouse))
@@ -1126,29 +1132,29 @@ static void __bt_hal_agent_release_memory(void)
 static inline void stack_trim(void)
 {
 #ifdef STACK_FLUSH
-        unsigned int sp;
-        char buf[BUF_SIZE];
-        FILE *file;
-        unsigned int stacktop;
-        int found = 0;
-
-        asm volatile ("mov %0,sp " : "=r"(sp));
-
-        sprintf(buf, "/proc/%d/maps", getpid());
-        file = fopen(buf, "r");
-        while (fgets(buf, BUF_SIZE, file) != NULL) {
-                if (strstr(buf, "[stack]")) {
-                        found = 1;
-                        break;
-                }
-        }
-        fclose(file);
-
-        if (found) {
-                sscanf(buf, "%x-", &stacktop);
-                if (madvise((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp) - stacktop,
-                                                                                MADV_DONTNEED) < 0)
-                        perror("stack madvise fail");
-        }
+       unsigned int sp;
+       char buf[BUF_SIZE];
+       FILE *file;
+       unsigned int stacktop;
+       int found = 0;
+
+       asm volatile ("mov %0,sp " : "=r"(sp));
+
+       sprintf(buf, "/proc/%d/maps", getpid());
+       file = fopen(buf, "r");
+       while (fgets(buf, BUF_SIZE, file) != NULL) {
+               if (strstr(buf, "[stack]")) {
+                       found = 1;
+                       break;
+               }
+       }
+       fclose(file);
+
+       if (found) {
+               sscanf(buf, "%x-", &stacktop);
+               if (madvise((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp) - stacktop,
+                                       MADV_DONTNEED) < 0)
+                       perror("stack madvise fail");
+       }
 #endif
 }