[Adapt: HAL] Add support for authorization resposne API 28/81728/1
authorAnupam Roy <anupam.r@samsung.com>
Sat, 23 Jul 2016 12:41:02 +0000 (18:11 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Thu, 28 Jul 2016 06:01:30 +0000 (11:31 +0530)
This patch adds support for Authorization Response
API in BT HAL. HAL user can use this API to respond to
the incoming authorization request from devices for
various services like HID, A2DP, AVRCP etc.

Change-Id: I174abfc5263dd9aefb9bd93c384c69eefdbba496
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/bluez_hal/hardware/bluetooth.h
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h
bt-oal/bluez_hal/src/bt-hal-gap-agent.c
bt-oal/bluez_hal/src/bt-hal-gap-agent.h

index 7c5acf2..68ce7e8 100755 (executable)
@@ -650,6 +650,10 @@ typedef struct {
       * Success indicates that the VSC command was sent to controller
       */
     int (*read_energy_info)();
+
+     /* Tizen Specific: Send  service level Authorization response */
+     int (*authorize_response)(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
+                                       uint8_t authorize, uint8_t save_settings);
 } bt_interface_t;
 
 /** TODO: Need to add APIs for Service Discovery, Service authorization and
index 0b5244c..8a76fca 100644 (file)
@@ -285,6 +285,13 @@ static int read_energy_info(void)
        return BT_STATUS_UNSUPPORTED;
 }
 
+static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
+                                    uint8_t authorize, uint8_t save_settings)
+{
+       DBG("+");
+       return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
+}
+
 static const bt_interface_t bluetooth_if = {
        .size = sizeof(bt_interface_t),
        .init = init,
@@ -314,6 +321,7 @@ static const bt_interface_t bluetooth_if = {
        .get_connection_state = get_connection_state,
        .set_os_callouts = set_os_callouts,
        .read_energy_info = read_energy_info,
+       .authorize_response = authorize_response,
 };
 
 static const bt_interface_t *get_bluetooth_interface(void)
index 40684bb..ba1de57 100644 (file)
@@ -377,6 +377,27 @@ fail:
        return result;
 }
 
+int _bt_hal_device_authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
+                                    uint8_t authorize, uint8_t save_settings)
+{
+       int reply = GAP_AGENT_ACCEPT;
+       GapAgentPrivate *agent = _bt_hal_get_adapter_agent();
+       DBG("+");
+
+       if (!agent)
+               return BT_STATUS_FAIL;
+
+       if (!authorize)
+               reply = GAP_AGENT_REJECT;
+       else if (authorize && save_settings)
+               reply = GAP_AGENT_ACCEPT_ALWAYS;
+
+       gap_agent_reply_authorize(agent, reply, NULL);
+
+       DBG("-");
+       return BT_STATUS_SUCCESS;
+}
+
 static void __bt_hal_device_service_search_cb(GDBusProxy *proxy, GAsyncResult *res,
                                         gpointer user_data)
 {
index be1eef4..7896dcf 100644 (file)
@@ -55,6 +55,9 @@ int _bt_hal_device_ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t varian
 
 int _bt_hal_dbus_get_remote_device_services(const bt_bdaddr_t *remote_addr);
 
+int _bt_hal_device_authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
+                                    uint8_t authorize, uint8_t save_settings);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 8be5874..27dcfcc 100644 (file)
@@ -960,3 +960,57 @@ gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
        DBG("-");
        return TRUE;
 }
+
+gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
+                GDBusMethodInvocation *context)
+{
+       gboolean ret = TRUE;
+       GapAgentPrivate *priv = agent;
+       DBG("+");
+
+       /* Fix : NULL_RETURNS */
+       if (priv == NULL)
+               return  FALSE;
+
+       if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
+                       priv->reply_context != NULL) {
+               if (accept == GAP_AGENT_ACCEPT) {
+                       g_dbus_method_invocation_return_value(priv->reply_context, NULL);
+               } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
+                       /* TODO: Enable below logic after set authorization API implementation */
+                       g_dbus_method_invocation_return_value(priv->reply_context, NULL);
+               } else {
+                       switch (accept) {
+                               case GAP_AGENT_CANCEL:
+                                       g_dbus_method_invocation_return_error(priv->reply_context,
+                                                       GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
+                                                       "CanceledbyUser");
+                                       break;
+                               case GAP_AGENT_TIMEOUT:
+                               case GAP_AGENT_REJECT:
+                               default:
+                                       g_dbus_method_invocation_return_error(priv->reply_context,
+                                                       GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
+                                                       "Authorization request rejected");
+                                       break;
+                       }
+               }
+
+               if (context)
+                       g_dbus_method_invocation_return_value(context, NULL);
+       } else {
+               ERR("No context");
+               if (context)
+                       g_dbus_method_invocation_return_error(context,
+                                       GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
+                                       "No context");
+               ret = FALSE;
+       }
+
+       priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
+       priv->reply_context = NULL;
+       memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
+
+       DBG("-");
+       return ret;
+}
index 430c2df..52ecea5 100644 (file)
@@ -108,4 +108,6 @@ gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
 gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
                 GDBusMethodInvocation *context);
 
+gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
+                GDBusMethodInvocation *context);
 #endif //_BT_HAL_GAP_AGENT_H__