#define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY 2 /* event */
#define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
+#define PROFILE_TRUSTED 0x2 /* This corresponds to binary 0b10*/
+#define PROFILE_BLOCKED 0x1 /* This corresponds to binary 0b01*/
+#define PROFILE_SHOW_AUTH 0x0 /* This corresponds to binary 0b00*/
typedef struct {
int req_id;
return dev_info;
}
-char *_bt_get_bonded_device_name(char *address)
+char *_bt_get_device_name(const char *bdaddress)
{
- bluetooth_device_address_t device_address = { {0} };
- bluetooth_device_info_t dev_info;
+ char *device_path = NULL;
+ const gchar *name = NULL;
+ gchar *dev_name = NULL;
+ gsize name_len = 0;
+ GVariant *result = NULL;
+ GError *err = NULL;
+ GDBusProxy *device_proxy;
+ GDBusConnection *conn;
- retv_if(address == NULL, strdup(""));
+ retv_if(bdaddress == NULL, NULL);
- _bt_convert_addr_string_to_type(device_address.addr, address);
+ device_path = _bt_get_device_object_path((char *)bdaddress);
+ retv_if(device_path == NULL, NULL);
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, NULL);
+ INFO_SECURE("Device_path %s", device_path);
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME, device_path,
+ BT_PROPERTIES_INTERFACE, NULL, &err);
+
+ g_free(device_path);
+ retv_if(device_proxy == NULL, NULL);
+
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Alias"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (err) {
+ BT_ERR("DBus Error : %s", err->message);
+ g_clear_error(&err);
+ } else {
+ GVariant *value;
+ g_variant_get(result, "(v)", &value);
+ name = g_variant_get_string(value, &name_len);
+ INFO_SECURE("Alias Name [%s]", name);
+ if (name_len)
+ dev_name = g_strdup(name);
+ g_variant_unref(value);
+ g_variant_unref(result);
+ }
- _bt_get_bonded_device_info(&device_address, &dev_info);
+ if (name_len == 0) {
+ GVariant *value;
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Name"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (err) {
+ ERR("DBus Error : %s", err->message);
+ g_clear_error(&err);
+ } else {
+ g_variant_get(result, "(v)", &value);
+ name = g_variant_get_string(value, &name_len);
+ INFO_SECURE("Name = %s", name);
+ if (name_len)
+ dev_name = g_strdup(name);
+ g_variant_unref(value);
+ g_variant_unref(result);
+ }
+ }
- return g_strdup(dev_info.device_name.name);
+ g_object_unref(device_proxy);
+ return dev_name;
}
static gboolean __ignore_auto_pairing_request(const char *address)
GDBusProxy *device_proxy;
GError *error = NULL;
GVariant *value;
- GVariant *tmp_value;
GDBusConnection *conn;
GVariant *result = NULL;
int ret = BLUETOOTH_ERROR_NONE;
g_free(object_path);
retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE,
+ "GattConnected"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
return BLUETOOTH_ERROR_INTERNAL;
}
- g_variant_get(result , "(@a{sv})", &value);
+ g_variant_get(result, "(v)", &value);
+ *is_connected = g_variant_get_boolean(value);
g_variant_unref(result);
- tmp_value = g_variant_lookup_value(value, "GattConnected", G_VARIANT_TYPE_BOOLEAN);
- if (tmp_value == NULL) {
- g_object_unref(device_proxy);
- g_variant_unref(value);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- *is_connected = g_variant_get_boolean(tmp_value);
-
BT_DBG("gatt is connected : %d", *is_connected);
- g_variant_unref(tmp_value);
g_variant_unref(value);
g_object_unref(device_proxy);
GDBusProxy *device_proxy;
GError *error = NULL;
GDBusConnection *conn;
- GVariant *tmp_value = NULL;
GVariant *value = NULL;
GVariant *result = NULL;
return BLUETOOTH_ERROR_NONE;
}
- result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Connected"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error != NULL) {
BT_ERR("Error occured in Proxy call [%s]\n", error->message);
g_error_free(error);
g_object_unref(device_proxy);
return BLUETOOTH_ERROR_INTERNAL;
+ } else {
+ g_variant_get(result, "(v)", &value);
+ *connected = g_variant_get_byte(value);
+ g_variant_unref(value);
+ g_variant_unref(result);
}
- g_variant_get(result , "(@a{sv})", &value);
- g_variant_unref(result);
-
- tmp_value = g_variant_lookup_value(value, "Connected", G_VARIANT_TYPE_BYTE);
- if (tmp_value != NULL) {
- *connected = g_variant_get_byte(tmp_value);
- g_variant_unref(tmp_value);
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_NONE;
- } else {
- BT_ERR("g_variant value is NULL");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ g_object_unref(device_proxy);
+ return BLUETOOTH_ERROR_NONE;
}
static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
guint trusted_profile_flag, guint *trusted)
{
- int trust_profile;
+ int trust_profile = FALSE;
*trusted = FALSE;
switch (profile) {
else
return BLUETOOTH_ERROR_NOT_SUPPORT;
break;
+ case TRUSTED_PROFILE_HFP_HF: {
+ guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 6)) >> 6;
+ BT_DBG("trusted_profile_flag %x", trusted_profile_flag);
+ if (flag != PROFILE_BLOCKED)
+ trust_profile = TRUE;
+ else
+ *trusted = FALSE;
+ break;
+ }
+ case TRUSTED_PROFILE_A2DP: {
+ guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 8)) >> 8;
+ BT_DBG("trusted_profile_flag %x", trusted_profile_flag);
+ if (flag != PROFILE_BLOCKED)
+ trust_profile = TRUE;
+ else
+ *trusted = FALSE;
+ break;
+ }
case TRUSTED_PROFILE_ALL: /* Return Flag for All profiles*/
*trusted = trusted_profile_flag;
return BLUETOOTH_ERROR_NONE;
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) {
return g_strdup("00001134-0000-1000-8000-00805f9b34fb");
case TRUSTED_PROFILE_SAP:
return g_strdup("0000112D-0000-1000-8000-00805f9b34fb");
- case TRUSTED_PROFILE_ALL:
- return NULL;
- }
-
- return NULL;
-}
-
-char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile)
-{
- switch (profile) {
- case RESTRICTED_PROFILE_HFP_HS:
+ case TRUSTED_PROFILE_HFP_HF:
return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
- case RESTRICTED_PROFILE_A2DP:
+ case TRUSTED_PROFILE_A2DP:
return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
+ case TRUSTED_PROFILE_ALL:
+ return NULL;
}
return NULL;
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_gdbus_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_gdbus_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)
{
GDBusProxy *device_proxy;
GError *error = NULL;
GVariant *value;
- GVariant *tmp_value;
GDBusConnection *conn;
GVariant *result = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
BT_CHECK_PARAMETER(device_address, return);
g_free(object_path);
retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (result == NULL) {
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- }
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "AttMtu"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("DBus Error : %s", error->message);
+ g_clear_error(&error);
g_object_unref(device_proxy);
return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result , "(@a{sv})", &value);
- g_variant_unref(result);
-
- tmp_value = g_variant_lookup_value(value, "AttMtu", G_VARIANT_TYPE_UINT16);
- if (tmp_value == NULL) {
- g_object_unref(device_proxy);
+ } else {
+ g_variant_get(result, "(v)", &value);
+ *mtu = g_variant_get_uint16(value);
+ BT_DBG("ATT MTU : %d", *mtu);
g_variant_unref(value);
- return BLUETOOTH_ERROR_INTERNAL;
+ g_variant_unref(result);
}
- *mtu = g_variant_get_uint16(tmp_value);
-
- BT_DBG("ATT MTU : %d", *mtu);
-
- g_variant_unref(tmp_value);
- g_variant_unref(value);
g_object_unref(device_proxy);
-
- return ret;
+ return BLUETOOTH_ERROR_NONE;
}
int _bt_get_device_ida(bluetooth_device_address_t *device_address,