Audio : Add the API for setting/getting the restricted connection 61/87261/2
authorHyuk Lee <hyuk0512.lee@samsung.com>
Wed, 7 Sep 2016 07:18:11 +0000 (16:18 +0900)
committerHyuk Lee <hyuk0512.lee@samsung.com>
Thu, 8 Sep 2016 00:26:28 +0000 (09:26 +0900)
Change-Id: I758ce816ebc452d560ae8a71691baf541507a25c
Signed-off-by: Hyuk Lee <hyuk0512.lee@samsung.com>
bt-api/bt-device.c
bt-service/bt-request-handler.c
bt-service/bt-service-device.c
include/bluetooth-api.h
include/bt-internal-types.h

index 2c01b8f..0d80b05 100644 (file)
@@ -718,6 +718,63 @@ BT_EXPORT_API int bluetooth_get_profile_trusted(
        return result;
 }
 
+BT_EXPORT_API int bluetooth_set_profile_restricted(
+               const bluetooth_device_address_t *device_address,
+               int profile, int restricted)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
+       g_array_append_vals(in_param2, &profile, sizeof(int));
+       g_array_append_vals(in_param3, &restricted, sizeof(int));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_SET_PROFILE_RESTRICTED,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               BT_DBG("SUCCESSFUL");
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_get_profile_restricted(
+               const bluetooth_device_address_t *device_address,
+               int profile, int *restricted)
+{
+       int result;
+       int restrict_profile = 0;
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
+       g_array_append_vals(in_param2, &profile, sizeof(int));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_PROFILE_RESTRICTED,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               restrict_profile = g_array_index(out_param, guint, 0);
+               BT_DBG("SUCCESSFUL");
+       }
+       BT_DBG("Restricted %d", restrict_profile);
+       *restricted = restrict_profile;
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_passkey_reply(char *passkey, gboolean reply)
 {
        int result;
index 64041a7..7997afe 100644 (file)
@@ -1003,7 +1003,37 @@ int __bt_bluez_request(int function_name,
 
                break;
        }
+       case BT_SET_PROFILE_RESTRICTED: {
+               bluetooth_device_address_t bd_addr = { {0} };
+               int profile;
+               int restricted;
+
+               __bt_service_get_parameters(in_param1, &bd_addr,
+                               sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2, &profile, sizeof(int));
+               __bt_service_get_parameters(in_param3, &restricted, sizeof(int));
+
+               result = _bt_set_restrict_profile(&bd_addr, profile, restricted);
+               break;
+       }
+       case BT_GET_PROFILE_RESTRICTED: {
+               bluetooth_device_address_t bd_addr = { {0} };
+               int profile;
+               guint restricted_profile = 0;
 
+               __bt_service_get_parameters(in_param1, &bd_addr,
+                               sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2, &profile, sizeof(int));
+
+               result = _bt_get_restrict_profile(&bd_addr, profile, &restricted_profile);
+               BT_DBG("Restricted %d", restricted_profile);
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &restricted_profile,
+                                       sizeof(guint));
+               }
+
+               break;
+       }
        case BT_HID_CONNECT: {
                bluetooth_device_address_t address = { {0} };
 
@@ -2746,6 +2776,7 @@ gboolean __bt_service_check_privilege(int function_name,
         case BT_CLEAR_WHITE_LIST:
         case BT_SET_MANUFACTURER_DATA:
         case BT_SET_SCAN_PARAMETERS:
+        case BT_SET_PROFILE_RESTRICTED:
 
         case BT_CANCEL_SEARCH_SERVICE:
         case BT_ENABLE_RSSI:
@@ -2802,6 +2833,7 @@ gboolean __bt_service_check_privilege(int function_name,
         case BT_GET_ADVERTISING_DATA:
         case BT_GET_SCAN_RESPONSE_DATA:
         case BT_IS_ADVERTISING:
+        case BT_GET_PROFILE_RESTRICTED:
 
         case BT_OBEX_SERVER_ALLOCATE:
         case BT_OBEX_SERVER_DEALLOCATE:
index 42af25f..9a8b1e3 100644 (file)
@@ -2536,6 +2536,29 @@ int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_get_restricted_profile_from_flag(bluetooth_restricted_profile_t profile,
+               guint restricted_profile_flag, guint *restricted)
+{
+       int restrict_profile;
+       *restricted = FALSE;
+
+       switch (profile) {
+       case RESTRICTED_PROFILE_HFP_HS:
+                       restrict_profile = restricted_profile_flag & (1 << 0);
+               break;
+       case RESTRICTED_PROFILE_A2DP:
+                       restrict_profile = restricted_profile_flag & (1 << 2);
+               break;
+       default:
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+
+       if (restrict_profile)
+               *restricted = TRUE;
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
 {
        switch (profile) {
@@ -2552,6 +2575,18 @@ char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
        return NULL;
 }
 
+char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile)
+{
+       switch (profile) {
+       case RESTRICTED_PROFILE_HFP_HS:
+               return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
+       case RESTRICTED_PROFILE_A2DP:
+               return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
+       }
+
+       return NULL;
+}
+
 bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid)
 {
        if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0) {
@@ -2690,6 +2725,132 @@ int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
        return ret;
 }
 
+int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, gboolean restricted)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       char *device_path = NULL;
+       char *uuid = NULL;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       GVariant *reply;
+
+       BT_CHECK_PARAMETER(bd_addr, return);
+       BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
+                       bd_addr->addr[0], bd_addr->addr[1],
+                       bd_addr->addr[2], bd_addr->addr[3],
+                       bd_addr->addr[4], bd_addr->addr[5],
+                       profile, restricted);
+
+       conn = _bt_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+       device_path = _bt_get_device_object_path(address);
+       retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_BLUEZ_NAME, device_path,
+                       BT_DEVICE_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       uuid = _bt_get_restricted_profile_uuid(profile);
+       if (uuid == NULL) {
+               g_object_unref(proxy);
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+
+       reply = g_dbus_proxy_call_sync(proxy, "SetRestrictedProfile",
+                       g_variant_new("(sb)", uuid, restricted),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("Failed to Set Profile Restricted");
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               if (error) {
+                       BT_ERR("Error %s[%s]", error->message, address);
+                       g_error_free(error);
+               }
+               goto finish;
+       }
+       g_variant_unref(reply);
+
+finish:
+       g_free(uuid);
+       return ret;
+}
+
+int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, guint *restricted)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       char *device_path = NULL;
+       guint restricted_profile_flag;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       GVariant *reply;
+
+       BT_CHECK_PARAMETER(bd_addr, return);
+       BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
+                       bd_addr->addr[0], bd_addr->addr[1],
+                       bd_addr->addr[2], bd_addr->addr[3],
+                       bd_addr->addr[4], bd_addr->addr[5],
+                       profile, *restricted);
+
+       conn = _bt_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+       device_path = _bt_get_device_object_path(address);
+       retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_BLUEZ_NAME, device_path,
+                       BT_PROPERTIES_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       reply = g_dbus_proxy_call_sync(proxy, "Get",
+                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "RestrictedProfiles"),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("Failed to Get Profile Restricted");
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               if (error) {
+                       BT_ERR("Error %s[%s]", error->message, address);
+                       g_error_free(error);
+               }
+               *restricted = 0;
+       } else {
+               GVariant *temp;
+               g_variant_get(reply, "(v)", &temp);
+               restricted_profile_flag = g_variant_get_uint32(temp);
+               BT_DBG("Restricted_FLAG %d", restricted_profile_flag);
+
+               ret = _bt_get_restricted_profile_from_flag(profile,
+                               restricted_profile_flag, restricted);
+               g_variant_unref(temp);
+               g_variant_unref(reply);
+       }
+
+       BT_DBG("TRUST %d", *restricted);
+       return ret;
+}
+
 static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                                        gpointer user_data)
 {
index d97a245..2a68318 100644 (file)
@@ -1610,6 +1610,14 @@ typedef enum {
 } bluetooth_trusted_profile_t;
 
 /**
+ * Restricted Profile types
+ */
+typedef enum {
+       RESTRICTED_PROFILE_HFP_HS = 1,
+       RESTRICTED_PROFILE_A2DP,
+} bluetooth_restricted_profile_t;
+
+/**
  * Structure for LE data length change params
  */
 typedef struct {
@@ -2314,6 +2322,52 @@ int bluetooth_get_profile_trusted(
                int profile, int *trust);
 
 /**
+ * @fn int bluetooth_set_profile_restricted(const bluetooth_device_address_t *device_address, int profile, int restricted)
+ * @brief Sets a profile restricted connection for a device
+ *
+ * This function is used to Set a profile as restricted for a device
+ *
+ * This function is a synchronous call.
+ *
+ * @param[in]  device_address  a device address of remote bluetooth device
+ * @param[in]  profile profile which is to be set as restricted[1-HFP_HS, 2-A2DP]
+ * @param[in]  restricted      to set as restricted or not[1-not 0-restricted]
+ *
+ * @return     BLUETOOTH_ERROR_NONE - Success \n
+ *             BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Adapter is not enabled \n
+ *             BLUETOOTH_ERROR_INVALID_PARAM - Bluetooth name parameter is incorrect \n
+ *             BLUETOOTH_ERROR_INTERNAL - The dbus method call is fail \n
+ *
+ * @remark      None
+ */
+int bluetooth_set_profile_restricted(
+               const bluetooth_device_address_t *device_address,
+               int profile, int restricted);
+
+/**
+ * @fn int bluetooth_get_profile_restricted(const bluetooth_device_address_t *device_address, int profile, int *restricted)
+ * @brief Gets a restricted connection state
+ *
+ * This function is used to Get a profile is restricted or not for a device
+ *
+ * This function is a synchronous call.
+ *
+ * @param[in]  device_address  a device address of remote bluetooth device
+ * @param[in]  profile profile whose restricted status is needed[1-HFP_HS, 2-A2DP]
+ * @param[out] restricted      profile is set as restricted or not[1-not 0-restricted]
+ *
+ * @return     BLUETOOTH_ERROR_NONE - Success \n
+ *             BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Adapter is not enabled \n
+ *             BLUETOOTH_ERROR_INVALID_PARAM - Bluetooth name parameter is incorrect \n
+ *             BLUETOOTH_ERROR_INTERNAL - The dbus method call is fail \n
+ *
+ * @remark      None
+ */
+int bluetooth_get_profile_restricted(
+               const bluetooth_device_address_t *device_address,
+               int profile, int *restricted);
+
+/**
  * @fn int bluetooth_get_discoverable_mode(bluetooth_discoverable_mode_t *discoverable_mode_ptr)
  * @brief Get the visibility mode
  *
index 247245e..5687b6f 100644 (file)
@@ -203,6 +203,8 @@ typedef enum {
        BT_UPDATE_LE_CONNECTION_MODE,
        BT_SET_PROFILE_TRUSTED,
        BT_GET_PROFILE_TRUSTED,
+       BT_SET_PROFILE_RESTRICTED,
+       BT_GET_PROFILE_RESTRICTED,
        BT_HID_CONNECT = BT_FUNC_HID_BASE,
        BT_HID_DISCONNECT,
        BT_HID_DEVICE_ACTIVATE,