[Adapt: HAL]Added rfcomm socket authorization 39/87739/1
authorAtul Rai <a.rai@samsung.com>
Wed, 31 Aug 2016 06:45:01 +0000 (12:15 +0530)
committerAtul Rai <a.rai@samsung.com>
Thu, 1 Sep 2016 05:11:59 +0000 (10:41 +0530)
This patch adds RFCOMM socket authorization event and callback
in Bluez HAL.

Change-Id: Icbb89a30c93fc325f2081a2cadaf3b2b0b361d45
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-oal/bluez_hal/hardware/bluetooth.h
bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/src/bt-hal-agent.c
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/bluez_hal/src/bt-hal-rfcomm-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-rfcomm-dbus-handler.h

index 01c10a3..bcac8fa 100755 (executable)
@@ -486,6 +486,10 @@ typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info);
 /* Service level Authorization request callback */
 typedef void (*authorize_request_callback) (bt_bdaddr_t *remote_bd_addr, bt_service_id_t service_d);
 
+#ifdef TIZEN_BT_HAL
+/* Service level Authorization request callback */
+typedef void (*sock_authorize_request_callback) (bt_bdaddr_t *remote_bd_addr, bt_uuid_t *uuid);
+#endif
 
 /** TODO: Add callbacks for Link Up/Down and other generic
   *  notifications/callbacks */
@@ -513,6 +517,9 @@ typedef struct {
     energy_info_callback energy_info_cb;
     authorize_request_callback authorize_request_cb;
     device_trust_state_changed_callback device_trust_state_changed_cb;
+#ifdef TIZEN_BT_HAL
+    sock_authorize_request_callback socket_authorize_request_cb;
+#endif
 } bt_callbacks_t;
 
 typedef void (*alarm_cb)(void *data);
index 7c9254d..5a5ce42 100644 (file)
@@ -162,6 +162,14 @@ struct hal_ev_authorize_request {
        uint32_t service_id;
 } __attribute__((packed));
 
+#ifdef TIZEN_BT_HAL
+#define HAL_EV_SOCK_AUTHORIZE_REQUEST        0x90
+struct hal_ev_sock_conn_auth {
+        uint8_t uuid[16];
+       uint8_t bdaddr[6];
+} __attribute__((packed));
+#endif //TIZEN_BT_HAL
+
 #define HAL_ACL_STATE_CONNECTED         0x00
 #define HAL_ACL_STATE_DISCONNECTED      0x01
 
index b5c9c99..2a54a8a 100644 (file)
@@ -51,6 +51,7 @@
 #include "bt-hal-dbus-common-utils.h"
 
 #include "bt-hal-adapter-dbus-handler.h"
+#include "bt-hal-rfcomm-dbus-handler.h"
 #include "bt-hal-event-receiver.h"
 
 #include <bt-hal-agent.h>
@@ -233,6 +234,27 @@ static void __bt_hal_send_authorize_request_event(const gchar *address, const ch
 }
 #endif
 
+#ifdef TIZEN_BT_HAL
+static void __bt_hal_send_rfcomm_authorize_request_event(const gchar *address, const char *uuid)
+{
+       struct hal_ev_sock_conn_auth ev;
+
+       DBG("Remote Device address [%s], uuid: %s", address, uuid);
+
+       memset(&ev, 0, sizeof(ev));
+       _bt_convert_addr_string_to_type(ev.bdaddr, address);
+       _bt_convert_uuid_string_to_type(ev.uuid, uuid);
+
+       handle_stack_msg event_cb = _bt_hal_get_stack_message_handler();
+       if (event_cb) {
+               DBG("Sending Socket AUTHORIZE REQUEST");
+               event_cb(HAL_EV_SOCK_AUTHORIZE_REQUEST, (void*)&ev, sizeof(ev));
+       }
+
+       DBG("-");
+}
+#endif
+
 /* Legacy Pairing */
 static void __bt_hal_send_pin_request_event(const gchar *address, const gchar *name,
                uint32_t cod)
@@ -637,6 +659,13 @@ static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *d
                INFO("Device is not Trusted, so prompt user to accept or reject authorization \n");
        }
 
+#ifdef TIZEN_BT_HAL
+       if (_is_rfcomm_server_uuid(uuid)) {
+               __bt_hal_send_rfcomm_authorize_request_event(address, uuid);
+               goto done;
+       }
+#endif
+
        /*
         * TODO: Handling for authorization request for different profiles will be
         * implemented while profiles support is added. For now send all the request
index f4ef1e4..67ecd42 100644 (file)
@@ -657,6 +657,28 @@ static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
        DBG("-");
 }
 
+#ifdef TIZEN_BT_HAL
+static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t len)
+{
+       struct hal_ev_sock_conn_auth *ev = buf;
+       bt_bdaddr_t bd_addr;
+       bt_uuid_t uuid;
+
+       DBG("+");
+
+       memcpy(bd_addr.address, ev->bdaddr, 6);
+       memcpy(uuid.uu, ev->uuid, 16);
+
+       if (!bt_hal_cbacks->socket_authorize_request_cb) {
+               ERR("HAL User socket_authorize_request_cb is not set!!");
+               return;
+       }
+
+       bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid);
+       DBG("-");
+}
+#endif
+
 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
 {
        struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
@@ -794,6 +816,12 @@ static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
                        DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
                        __bt_hal_handle_device_trust_state_changed_event(buf, len);
                        break;
+#ifdef TIZEN_BT_HAL
+               case HAL_EV_SOCK_AUTHORIZE_REQUEST:
+                       DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
+                       __bt_hal_handle_socket_authorize_request_event(buf, len);
+                       break;
+#endif
                default:
                        DBG("Event Currently not handled!!");
                        break;
index 7cda23e..2ee2dc2 100644 (file)
@@ -699,6 +699,8 @@ int __new_server_connection(const char *path, int fd, bt_bdaddr_t *addr)
                return -1;
        }
 
+       /* Remove local reference to client socket fd */
+       close(fd);
        return 0;
 }
 
@@ -925,3 +927,17 @@ int _bt_hal_dbus_handler_rfcomm_listen(const char *svc_name, unsigned char *uuid
        DBG("-");
        return BT_STATUS_SUCCESS;
 }
+
+gboolean _is_rfcomm_server_uuid(const char *uuid)
+{
+       DBG("+");
+
+       if (!uuid)
+               return FALSE;
+
+       if (NULL == __find_rfcomm_server_info_from_uuid(uuid))
+               return FALSE;
+
+       DBG("-");
+       return TRUE;
+}
index 7493421..e4ca6dc 100644 (file)
@@ -39,6 +39,8 @@ int _bt_hal_dbus_handler_rfcomm_connect(
 int _bt_hal_dbus_handler_rfcomm_listen(
        const char *svc_name, unsigned char *uuid, int *sock);
 
+gboolean _is_rfcomm_server_uuid(const char *uuid);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */