{
int result;
- BT_INFO("");
+ BT_INFO_C("### Enable adapter");
retv_if(bluetooth_check_adapter() == BLUETOOTH_ADAPTER_ENABLED,
BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED);
{
int result;
- BT_INFO("");
+ BT_INFO_C("### Disable adapter");
BT_CHECK_ENABLED(return);
BT_INIT_PARAMS();
{
int result;
- BT_INFO("");
+ BT_INFO("Recover adapter");
BT_CHECK_ENABLED(return);
BT_INIT_PARAMS();
g_variant_get(reply, "(b)", &is_supported);
*ibr_supported = is_supported;
- BT_DBG("%s", *ibr_supported ? "Supported":"Not Supported");
+ BT_DBG("%s", *ibr_supported ? "Supported" : "Not Supported");
g_variant_unref(reply);
return ret;
sizeof(bluetooth_device_address_t));
result = _bt_send_request_async(BT_BLUEZ_SERVICE,
- BT_AVRCP_TARGET_DISCONNECT,in_param1,
+ BT_AVRCP_TARGET_DISCONNECT, in_param1,
in_param2, in_param3, in_param4,
user_info->cb, user_info->user_data);
ret_if(addr == NULL);
len = strlen(address);
- ret_if(len != BT_ADDRESS_STRING_SIZE- 1);
+ ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
strncpy(addr, address, len);
result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
if (!result) {
- if (err != NULL)
- BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
- else
+ if (err != NULL) {
+ if (!g_strrstr(err->message, "ServiceUnknown"))
+ BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
+ } else {
BT_ERR("Fail to get DefaultAdapter");
+ }
goto fail;
}
return result;
}
+BT_EXPORT_API int bluetooth_get_is_alias_set(const bluetooth_device_address_t *device_address,
+ gboolean *is_alias_set)
+{
+ int result;
+
+ BT_CHECK_PARAMETER(device_address, return);
+ BT_CHECK_PARAMETER(is_alias_set, 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));
+
+ result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_IS_ALIAS_SET,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ if (result == BLUETOOTH_ERROR_NONE)
+ *is_alias_set = g_array_index(out_param, gboolean, 0);
+
+ BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ return result;
+}
+
BT_EXPORT_API int bluetooth_get_remote_device(const bluetooth_device_address_t *device_address)
{
return BLUETOOTH_ERROR_NONE;
#ifdef RFCOMM_DIRECT
_bt_rfcomm_server_free_all();
#endif
- bluetooth_hid_device_deactivate();
+
+ _bluetooth_hid_free_hid_info();
+
BT_DBG("-");
return FALSE;
}
g_variant_get(parameters, "(i&s@ay)", &result, &char_handle, &char_value_var);
len = g_variant_get_size(char_value_var);
- ret_if (char_value_var == NULL);
+ ret_if(char_value_var == NULL);
if (len > 0)
value = (char *)g_variant_get_data(char_value_var);
result, &profile_info,
event_info->cb, event_info->user_data);
}
- if (trust & (PROFILE_SUPPORTED <<2 )) { /* Bit 2 & 3 - for MAP Supported */
+ if (trust & (PROFILE_SUPPORTED << 2)) { /* Bit 2 & 3 - for MAP Supported */
profile_info.profile = TRUSTED_PROFILE_MAP;
profile_info.supported = TRUE;
- if (trust & (1 <<3 )) /* Bit 3 - for PBAP Trusted */
+ if (trust & (1 << 3)) /* Bit 3 - for PBAP Trusted */
profile_info.trusted = TRUE;
else
profile_info.trusted = FALSE;
result, &profile_info,
event_info->cb, event_info->user_data);
}
- if (trust & (PROFILE_SUPPORTED <<4 )) { /* Bit 4 & 5- for SAP Supported */
+ if (trust & (PROFILE_SUPPORTED << 4)) { /* Bit 4 & 5- for SAP Supported */
profile_info.profile = TRUSTED_PROFILE_SAP;
profile_info.supported = TRUE;
- if (trust & (1 <<5 )) /* Bit 5 - for SAP Trusted */
+ if (trust & (1 << 5)) /* Bit 5 - for SAP Trusted */
profile_info.trusted = TRUE;
else
profile_info.trusted = FALSE;
success = !result;
- for(i = 0; i < count; i++)
+ for (i = 0; i < count; i++)
BT_DBG("%s", list[i]);
BT_DBG("address: %s, result: %d, count: %d, success: %d",
list = (gchar **)g_variant_get_strv(string_var, &count);
success = !result;
- for(i = 0; i < count; i++)
+ for (i = 0; i < count; i++)
BT_DBG("%s", list[i]);
BT_DBG("address: %s success: %d", address, success);
memset(service, 0, sizeof(bt_gatt_service_property_t));
while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
- if (!g_strcmp0(key,"UUID")) {
+ if (!g_strcmp0(key, "UUID")) {
char *name = NULL;
- service->uuid = g_variant_dup_string(value,&len);
+ service->uuid = g_variant_dup_string(value, &len);
_bt_get_uuid_specification_name(service->uuid, &name);
BT_INFO("======> Service : %s [%s]", service->uuid, name);
g_free(name);
- } else if(!g_strcmp0(key, "Primary")) {
+ } else if (!g_strcmp0(key, "Primary")) {
service->primary = g_variant_get_boolean(value);
} else if (!g_strcmp0(key, "Includes")) {
service->char_handle.handle =
__get_string_array_from_gptr_array(gp_array);
}
- BT_DBG("Characteristics count : %d",service->char_handle.count);
+ BT_DBG("Characteristics count : %d", service->char_handle.count);
g_ptr_array_free(gp_array, TRUE);
g_variant_iter_free(char_iter);
}
g_strfreev(svc_char.handle_info.handle);
g_free(svc_char.service_handle);
g_variant_iter_free(char_iter);
+ g_variant_unref(value);
g_object_unref(proxy);
}
retv_if(permission == NULL, ret);
- BT_INFO("permission = %s",permission);
+ BT_INFO("permission = %s", permission);
if (!g_strcmp0(permission, "broadcast")) {
ret = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_BROADCAST;
characteristic->handle = g_strdup(char_handle);
while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
- if (!g_strcmp0(key,"UUID")) {
+ if (!g_strcmp0(key, "UUID")) {
char *name = NULL;
- characteristic->uuid = g_variant_dup_string(value,&len);
+ characteristic->uuid = g_variant_dup_string(value, &len);
_bt_get_uuid_specification_name(characteristic->uuid, &name);
BT_INFO("Characteristic : %s [%s]", characteristic->uuid, name);
g_free(name);
- } else if(!g_strcmp0(key, "Value")) {
+ } else if (!g_strcmp0(key, "Value")) {
gb_array = g_byte_array_new();
g_variant_get(value, "ay", &char_value_iter);
while (g_variant_iter_loop(char_value_iter, "y", &char_value)) {
bluetooth_gatt_free_char_property(&characteristic);
g_variant_iter_free(char_iter);
+ g_variant_unref(value);
g_free(user_data);
}
descriptor->handle = g_strdup(descriptor_handle);
while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
- if (!g_strcmp0(key,"UUID")) {
+ if (!g_strcmp0(key, "UUID")) {
char *name = NULL;
- descriptor->uuid = g_variant_dup_string(value,&len);
+ descriptor->uuid = g_variant_dup_string(value, &len);
_bt_get_uuid_specification_name(descriptor->uuid, &name);
- BT_INFO("Descriptor : %s [%s]",descriptor->uuid, name);
+ BT_INFO("Descriptor : %s [%s]", descriptor->uuid, name);
g_free(name);
} else if (!g_strcmp0(key, "Value")) {
gb_array = g_byte_array_new();
g_variant_get(value, "ay", &desc_value_iter);
- while(g_variant_iter_loop(desc_value_iter, "y", &char_value)) {
- BT_DBG("value of descriptor = %d",char_value);
+ while (g_variant_iter_loop(desc_value_iter, "y", &char_value)) {
+ BT_DBG("value of descriptor = %d", char_value);
g_byte_array_append(gb_array, &char_value, 1);
}
g_variant_iter_free(desc_value_iter);
bluetooth_gatt_free_char_property(&characteristic);
g_variant_iter_free(char_iter);
+ g_variant_unref(value);
BT_DBG("-");
}
error->code, error->message);
g_clear_error(&error);
}
+ } else {
+ g_variant_unref(result);
}
}
error->code, error->message);
g_clear_error(&error);
}
+ } else {
+ g_variant_unref(result);
}
}
g_error_free(err);
}
} else {
- g_variant_get (result, "(hh)", &index1, &index2);
+ g_variant_get(result, "(hh)", &index1, &index2);
int fd1 = g_unix_fd_list_get(out_fd_list, index1, NULL);
int fd2 = g_unix_fd_list_get(out_fd_list, index2, NULL);
conn_info.socket_fd = info->intr_fd;
else
conn_info.socket_fd = info->ctrl_fd;
- _bt_convert_addr_string_to_type (conn_info.device_addr.addr , info->address);
+ _bt_convert_addr_string_to_type(conn_info.device_addr.addr, info->address);
if (result == BLUETOOTH_ERROR_NONE)
BT_INFO_C("Connected [HID Device]");
g_free(info);
}
+static gboolean __is_error_by_disconnect(GError *err)
+{
+ return !g_strcmp0(err->message, "Connection reset by peer") ||
+ !g_strcmp0(err->message, "Connection timed out") ||
+ !g_strcmp0(err->message, "Software caused connection abort");
+}
+
static gboolean __received_cb(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
if (data.address)
g_free((char *)data.address);
} else {
- BT_INFO("Error while reading data");
+ BT_ERR("Error while reading data %d [%s]", status, info->address);
+ if (err) {
+ BT_ERR("IO Channel read error [%s]", err->message);
+ if (status == G_IO_STATUS_ERROR &&
+ __is_error_by_disconnect(err)) {
+ BT_DBG("cond : %d", cond);
+ g_error_free(err);
+ __hid_disconnect(info);
+ return FALSE;
+ }
+ g_error_free(err);
+ } else if (status == G_IO_STATUS_EOF) {
+ __hid_disconnect(info);
+ return FALSE;
+ }
}
return TRUE;
}
return info;
}
+void _bluetooth_hid_free_hid_info(void)
+{
+ if (hid_info == NULL) {
+ BT_DBG("hid_info is already NULL");
+ return;
+ }
+
+ __free_hid_info(hid_info);
+ hid_info = NULL;
+}
+
BT_EXPORT_API int bluetooth_hid_device_init(hid_cb_func_ptr callback_ptr, void *user_data)
{
int ret;
profile_info.uuid = hid_info->uuid;
BT_INFO("uuid %s", profile_info.uuid);
- result = _bt_register_profile_platform(&profile_info, FALSE);
+ result = _bt_register_profile(&profile_info, FALSE);
return result;
}
_bt_unregister_profile(hid_info->path);
- __free_hid_info(hid_info);
- hid_info = NULL;
+ _bluetooth_hid_free_hid_info();
+
return BLUETOOTH_ERROR_NONE;
}
}
BT_EXPORT_API int bluetooth_hid_device_disconnect(const char *remote_addr)
{
+ BT_CHECK_PARAMETER(remote_addr, return);
+
if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_DISCONNECT)
== BLUETOOTH_ERROR_PERMISSION_DEINED) {
BT_ERR("Don't have a privilege to use this API");
int written = 0;
hid_connected_device_info_t *info = NULL;
+ BT_CHECK_PARAMETER(remote_addr, return);
+
switch (privilege_token_send_mouse) {
case 0:
result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_SEND_MOUSE_EVENT);
int written = 0;
hid_connected_device_info_t *info = NULL;
+ BT_CHECK_PARAMETER(remote_addr, return);
+
switch (privilege_token_send_key) {
case 0:
result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_SEND_KEY_EVENT);
return BLUETOOTH_ERROR_INVALID_PARAM;
}
+ BT_CHECK_PARAMETER(remote_addr, return);
+
switch (privilege_token_reply) {
case 0:
result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_SEND_REPLY_TO_REPORT);
}
BT_INFO("htype %d ptype %d", htype, ptype);
- switch(htype) {
+ switch (htype) {
case HTYPE_TRANS_GET_REPORT: {
- switch(ptype) {
+ switch (ptype) {
case PTYPE_DATA_RTYPE_INPUT: {
output_report.type = BT_HID_TRANS_DATA |
BT_HID_DATA_RTYPE_INPUT;
typedef struct {
char bt_addr[BT_ADDRESS_STRING_SIZE];
int fd;
- int watch_id;
+ guint watch_id;
gboolean disconnected;
} rfcomm_conn_info_t;
if (conn == NULL)
return;
- if (conn->fd > 0)
- close(conn->fd);
if (conn->watch_id > 0) {
g_source_remove(conn->watch_id);
conn->watch_id = 0;
}
+
g_free(conn);
BT_DBG("-");
bluetooth_rfcomm_disconnection_t disconn_info;
bt_event_info_t *event_info = NULL;
+
if (conn_info->disconnected == FALSE)
return;
+
event_info = _bt_event_get_cb_data(BT_RFCOMM_CLIENT_EVENT);
if (event_info == NULL) {
+ __rfcomm_remove_conn_info_t(info, conn_info->bt_addr);
+
if (info->rfcomm_conns == NULL)
rfcomm_cb_data_remove(info);
return;
}
+
memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
disconn_info.device_role = RFCOMM_ROLE_CLIENT;
g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
- BT_DBG("Disconnected FD [%d]", conn_info->fd);
_bt_convert_addr_string_to_type(disconn_info.device_addr.addr,
conn_info->bt_addr);
+ BT_DBG("Disconnected FD [%d]", conn_info->fd);
disconn_info.socket_fd = conn_info->fd;
BT_DBG("Disconnection Result[%d] BT_ADDRESS[%s] UUID[%s] FD[%d]",
BLUETOOTH_ERROR_NONE, &disconn_info,
event_info->cb, event_info->user_data);
- if (conn_info) {
- BT_DBG("List is present deleting it");
- __rfcomm_remove_conn_info_t(info, conn_info->bt_addr);
- }
+ __rfcomm_remove_conn_info_t(info, conn_info->bt_addr);
+
if (info->rfcomm_conns == NULL)
rfcomm_cb_data_remove(info);
static gboolean __rfcomm_client_disconnect(gpointer user_data)
{
- rfcomm_cb_data_t *info = (rfcomm_cb_data_t *) user_data;
+ rfcomm_cb_data_t *info = (rfcomm_cb_data_t *)user_data;
+
BT_INFO_C("### Disconnected [RFCOMM Client]");
+
retv_if(info == NULL, FALSE);
if (g_slist_find(rfcomm_clients, info) == NULL) {
return FALSE;
}
info->idle_id = 0;
+
g_slist_foreach(info->rfcomm_conns,
- (GFunc) _bt_rfcomm_disconnect_conn_info, info);
+ (GFunc)_bt_rfcomm_disconnect_conn_info, info);
+
BT_DBG("-");
return FALSE;
}
fd = g_io_channel_unix_get_fd(chan);
if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
BT_ERR_C("RFComm Client disconnected: %d", fd);
+
conn_info = __get_conn_info_from_fd(info, fd);
if (conn_info == NULL) {
BT_ERR("No Connection info found with FD [%d]", fd);
return FALSE;
}
- conn_info->disconnected = TRUE;
+
+ if (conn_info->disconnected == FALSE) {
+ close(conn_info->fd);
+ conn_info->disconnected = TRUE;
+ }
__rfcomm_client_disconnect(info);
return FALSE;
}
__is_error_by_disconnect(err)) {
BT_ERR("cond : %d", cond);
g_error_free(err);
+
conn_info = __get_conn_info_from_fd(info, fd);
if (conn_info == NULL) {
BT_ERR("No Connection info found with FD [%d]", fd);
return FALSE;
}
- conn_info->disconnected = TRUE;
+
+ if (conn_info->disconnected == FALSE) {
+ close(conn_info->fd);
+ conn_info->disconnected = TRUE;
+ }
__rfcomm_client_disconnect(info);
return FALSE;
}
{
GError *error = NULL;
+ GVariant *value;
rfcomm_cb_data_t *cb_data;
char dev_address[BT_ADDRESS_STRING_SIZE];
const char *path;
cb_data = user_data;
- if (!g_dbus_proxy_call_finish(proxy, res, &error)) {
+ value = g_dbus_proxy_call_finish(proxy, res, &error);
+ if (value == NULL) {
int result;
g_dbus_error_strip_remote_error(error);
BT_ERR("Error : %s \n", error->message);
__rfcomm_client_connected_cb(cb_data, dev_address, result);
g_error_free(error);
+ } else {
+ g_variant_unref(value);
}
+
if (proxy)
g_object_unref(proxy);
rfcomm_cb_data_t *cb_data;
int ret = 0;
GError *err = NULL;
+ GVariant *value;
bt_register_profile_info_t info = {0};
int result = BLUETOOTH_ERROR_NONE;
char dev_address[BT_ADDRESS_STRING_SIZE];
_bt_convert_device_path_to_address(path, dev_address);
BT_DBG("Device Adress [%s]", dev_address);
- g_dbus_proxy_call_finish(proxy, res, &err);
+ value = g_dbus_proxy_call_finish(proxy, res, &err);
if (proxy)
g_object_unref(proxy);
+ if (value)
+ g_variant_unref(value);
if (err != NULL) {
g_dbus_error_strip_remote_error(err);
cb_data->object_id = object_id;
cb_data->id = id;
}
+
conn = g_new0(rfcomm_conn_info_t, 1);
conn->fd = -1;
_bt_convert_addr_type_to_string(conn->bt_addr,
BT_DBG("Connecting to %s uuid %s", conn->bt_addr, remote_uuid);
cb_data->rfcomm_conns = g_slist_append(cb_data->rfcomm_conns, conn);
+
ret = _bt_discover_services(conn->bt_addr, (char *)remote_uuid,
__bt_discover_service_response_cb, cb_data);
if (ret != BLUETOOTH_ERROR_NONE) {
rfcomm_cb_data_remove(cb_data);
return BLUETOOTH_ERROR_INTERNAL;
}
+
if (g_slist_find(rfcomm_clients, cb_data) == NULL) {
BT_INFO("Adding callback information to rfcomm_clients");
rfcomm_clients = g_slist_append(rfcomm_clients, cb_data);
#ifdef RFCOMM_DIRECT
rfcomm_cb_data_t *info;
rfcomm_conn_info_t *conn_info;
+
BT_INFO_C("### Disconnect RFCOMM");
+
BT_CHECK_ENABLED(return);
if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_SOCKET_DISCONNECT)
return BLUETOOTH_ERROR_PERMISSION_DEINED;
}
+ BT_DBG("Requested FD %d", socket_fd);
if (socket_fd < 0) {
BT_ERR("Invalid FD");
return BLUETOOTH_ERROR_INVALID_PARAM;
BT_DBG("Could not find in client, so check in server");
return bluetooth_rfcomm_server_disconnect(socket_fd);
}
+
conn_info = __get_conn_info_from_fd(info, socket_fd);
if (conn_info == NULL) {
- BT_ERR("FATAL Error");
+ BT_ERR("Could not find connection info");
return BLUETOOTH_ERROR_INTERNAL;
}
- if (conn_info->watch_id <= 0) {
+
+ if (conn_info->watch_id == 0 || conn_info->disconnected) {
BT_ERR("Invalid state");
return BLUETOOTH_ERROR_NOT_CONNECTED;
}
+
+ close(conn_info->fd);
conn_info->disconnected = TRUE;
- close(socket_fd);
+
BT_INFO("conn_info %s", conn_info->bt_addr);
_bt_disconnect_profile(conn_info->bt_addr, info->uuid, NULL, NULL);
+
+ /*
+ * ToDo : If idle_id is not zero, it means disconnect request is
+ * going on. Such a case, in-progress error should be returned.
+ */
if (info->idle_id == 0)
info->idle_id = g_idle_add(__rfcomm_client_disconnect, info);
static GSList *rfcomm_nodes;
typedef struct {
+ bluetooth_device_address_t addr;
+ int fd;
+ guint watch_id;
+ gboolean disconnected;
+} rfcomm_conn_t;
+
+typedef struct {
guint object_id;
gchar *path;
int id;
char *uuid;
- int fd;
- GIOChannel *data_io;
- guint data_id;
- bluetooth_device_address_t addr;
+ GSList *rfcomm_conns;
guint disconnect_idle_id;
} rfcomm_info_t;
static rfcomm_info_t *__find_rfcomm_info_with_fd(int fd)
{
GSList *l;
+ GSList *ll;
for (l = rfcomm_nodes; l != NULL; l = l->next) {
rfcomm_info_t *info = l->data;
- if (info->fd == fd)
- return info;
+ for (ll = info->rfcomm_conns; ll; ll = ll->next) {
+ rfcomm_conn_t *conn = ll->data;
+
+ if (conn && conn->fd == fd)
+ return info;
+ }
}
return NULL;
return NULL;
}
+static rfcomm_conn_t *__find_rfcomm_conn_with_fd(rfcomm_info_t *info,
+ int fd)
+{
+ GSList *l;
+ rfcomm_conn_t *conn;
+
+ for (l = info->rfcomm_conns; l; l = l->next) {
+ conn = l->data;
+
+ if (conn && conn->fd == fd)
+ return conn;
+ }
+
+ return NULL;
+}
+
+static void __rfcomm_remove_conn(rfcomm_info_t *info, int fd)
+{
+ rfcomm_conn_t *conn;
+
+ conn = __find_rfcomm_conn_with_fd(info, fd);
+ if (conn == NULL)
+ return;
+
+ info->rfcomm_conns = g_slist_remove(info->rfcomm_conns, conn);
+
+ if (conn->watch_id > 0)
+ g_source_remove(conn->watch_id);
+ g_free(conn);
+}
+
gboolean _check_uuid_path(char *path, char *uuid)
{
rfcomm_info_t *info = NULL;
return FALSE;
}
-static void __connected_cb(rfcomm_info_t *info, bt_event_info_t *event_info)
+static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn,
+ bt_event_info_t *event_info)
{
bluetooth_rfcomm_connection_t conn_info;
memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
+
conn_info.device_role = RFCOMM_ROLE_SERVER;
g_strlcpy(conn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
- conn_info.socket_fd = info->fd;
- conn_info.device_addr = info->addr;
+ conn_info.socket_fd = conn->fd;
+ conn_info.device_addr = conn->addr;
conn_info.server_id = info->id;
BT_INFO_C("### Connected [RFCOMM Server]");
event_info->cb, event_info->user_data);
}
-static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
+static void __rfcomm_server_disconnect_conn(rfcomm_conn_t *conn,
+ rfcomm_info_t *info)
{
bluetooth_rfcomm_disconnection_t disconn_info;
- int fd = info->fd;
bt_event_info_t *event_info;
- BT_INFO_C("### Disconnected [RFCOMM Server]");
+ if (conn == NULL)
+ return;
- if (info->data_id > 0) {
- g_source_remove(info->data_id);
- info->data_id = 0;
- }
+ if (conn->disconnected == FALSE)
+ return;
- if (info->fd >= 0) {
- close(info->fd);
- info->fd = -1;
+ if (conn->watch_id > 0) {
+ g_source_remove(conn->watch_id);
+ conn->watch_id = 0;
}
- if (info->data_io) {
- g_io_channel_shutdown(info->data_io, TRUE, NULL);
- g_io_channel_unref(info->data_io);
- info->data_io = NULL;
- }
- info->disconnect_idle_id = 0;
event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
- if (event_info == NULL)
- return FALSE;
+ if (event_info == NULL) {
+ __rfcomm_remove_conn(info, conn->fd);
+ return;
+ }
memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
disconn_info.device_role = RFCOMM_ROLE_SERVER;
g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
- disconn_info.socket_fd = fd;
- disconn_info.device_addr = info->addr;
+ disconn_info.device_addr = conn->addr;
+
+ BT_DBG("Disconnected FD [%d]", conn->fd);
+ disconn_info.socket_fd = conn->fd;
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
BLUETOOTH_ERROR_NONE, &disconn_info,
event_info->cb, event_info->user_data);
+ __rfcomm_remove_conn(info, conn->fd);
+}
+
+static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
+{
+ BT_INFO_C("### Disconnected [RFCOMM Server]");
+
+ if (g_slist_find(rfcomm_nodes, info) == NULL) {
+ BT_INFO("rfcomm resource is already freed");
+ return FALSE;
+ }
+
+ info->disconnect_idle_id = 0;
+
+ g_slist_foreach(info->rfcomm_conns,
+ (GFunc)__rfcomm_server_disconnect_conn, info);
+
BT_DBG("-");
return FALSE;
}
gsize len = 0;
int result = BLUETOOTH_ERROR_NONE;
rfcomm_info_t *info = data;
+ rfcomm_conn_t *conn;
bt_event_info_t *event_info;
bluetooth_rfcomm_received_data_t data_r;
GIOStatus status = G_IO_STATUS_NORMAL;
GError *err = NULL;
+ int fd;
retv_if(info == NULL, FALSE);
- event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
-
+ fd = g_io_channel_unix_get_fd(chan);
if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
- BT_ERR_C("RFComm Server disconnected: %d", info->fd);
+ BT_ERR_C("RFComm Server disconnected: %d", fd);
if (info->disconnect_idle_id > 0) {
BT_INFO("Disconnect idle still not process remove source");
info->disconnect_idle_id = 0;
}
+ conn = __find_rfcomm_conn_with_fd(info, fd);
+ if (conn == NULL) {
+ BT_ERR("No Connection info found with FD [%d]", fd);
+ return FALSE;
+ }
+
+ if (conn->disconnected == FALSE) {
+ close(conn->fd);
+ conn->disconnected = TRUE;
+ }
__rfcomm_server_disconnect(info);
return FALSE;
}
buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
status = g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
- &len, &err);
+ &len, &err);
if (status != G_IO_STATUS_NORMAL) {
BT_ERR("IO Channel read is failed with %d", status);
g_free(buffer);
- if (err) {
- BT_ERR("IO Channel read error [%s]", err->message);
- if (status == G_IO_STATUS_ERROR &&
- __is_error_by_disconnect(err)) {
- BT_ERR("cond : %d", cond);
- g_error_free(err);
- if (info->disconnect_idle_id > 0) {
- BT_INFO("Disconnect idle still not process remove source");
- g_source_remove(info->disconnect_idle_id);
- info->disconnect_idle_id = 0;
- }
- __rfcomm_server_disconnect(info);
+ if (!err)
+ return TRUE;
+
+ BT_ERR("IO Channel read error [%s]", err->message);
+ if (status == G_IO_STATUS_ERROR &&
+ __is_error_by_disconnect(err)) {
+ BT_ERR("cond : %d", cond);
+ g_error_free(err);
+
+ if (info->disconnect_idle_id > 0) {
+ BT_INFO("Disconnect idle still not process remove source");
+ g_source_remove(info->disconnect_idle_id);
+ info->disconnect_idle_id = 0;
+ }
+
+ conn = __find_rfcomm_conn_with_fd(info, fd);
+ if (conn == NULL) {
+ BT_ERR("No Connection info found with FD [%d]", fd);
return FALSE;
}
- g_error_free(err);
+
+ if (conn->disconnected == FALSE) {
+ close(conn->fd);
+ conn->disconnected = TRUE;
+ }
+ __rfcomm_server_disconnect(info);
+ return FALSE;
}
+ g_error_free(err);
return TRUE;
}
if (len == 0)
BT_ERR("Length is zero");
+ event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
if (event_info == NULL) {
g_free(buffer);
return TRUE;
}
- data_r.socket_fd = info->fd;
+ data_r.socket_fd = fd;
data_r.buffer_size = len;
data_r.buffer = buffer;
int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
{
rfcomm_info_t *info;
+ rfcomm_conn_t *conn;
+ GIOChannel *data_io;
bt_event_info_t *event_info;
BT_DBG("%s %d", path, fd);
if (info == NULL)
return -1;
- info->fd = fd;
- memcpy(&info->addr, addr, sizeof(bluetooth_device_address_t));
+ conn = g_new0(rfcomm_conn_t, 1);
+ conn->fd = fd;
+ memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
+ info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
- info->data_io = g_io_channel_unix_new(info->fd);
+ data_io = g_io_channel_unix_new(conn->fd);
- g_io_channel_set_encoding(info->data_io, NULL, NULL);
- g_io_channel_set_flags(info->data_io, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_channel_set_encoding(data_io, NULL, NULL);
+ g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
- info->data_id = g_io_add_watch(info->data_io,
+ conn->watch_id = g_io_add_watch(data_io,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
__data_received_cb, info);
+ g_io_channel_unref(data_io);
+
event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
if (event_info) {
- __connected_cb(info, event_info);
+ __connected_cb(info, conn, event_info);
}
return 0;
__rfcomm_delete_id(id);
return NULL;
}
- info = g_new(rfcomm_info_t, 1);
+ info = g_new0(rfcomm_info_t, 1);
info->object_id = (guint)object_id;
info->path = path;
info->id = id;
- info->fd = -1;
rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
return info;
}
-static rfcomm_info_t *__register_method_2(const char *path,const char *bus_name)
+static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
{
rfcomm_info_t *info;
int object_id;
if (object_id < 0) {
return NULL;
}
- info = g_new(rfcomm_info_t, 1);
+ info = g_new0(rfcomm_info_t, 1);
info->object_id = (guint)object_id;
info->path = g_strdup(path);
info->id = -1;
- info->fd = -1;
rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
return info;
}
-void free_rfcomm_info(rfcomm_info_t *info)
+void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
{
- bt_event_info_t *event_info;
+ if (conn->disconnected == FALSE) {
+ close(conn->fd);
+ conn->disconnected = TRUE;
+ }
+ __rfcomm_server_disconnect_conn(conn, info);
+}
+void free_rfcomm_info(rfcomm_info_t *info)
+{
BT_DBG("");
+
if (info->disconnect_idle_id > 0) {
BT_INFO("Disconnect idle still not process remove source");
g_source_remove(info->disconnect_idle_id);
__rfcomm_delete_id(info->id);
_bt_unregister_gdbus(info->object_id);
- if (info->fd >= 0) {
- event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
- if (event_info)
- BT_DBG("event type %d", event_info->event_type);
- __rfcomm_server_disconnect(info);
- }
+ g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
g_free(info->path);
g_free(info->uuid);
}
-BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int socket_fd)
+BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
{
#ifdef RFCOMM_DIRECT
rfcomm_info_t *info;
return BLUETOOTH_ERROR_PERMISSION_DEINED;
}
- if (socket_fd < 0) {
- BT_ERR("Invalid FD");
+ if (id < 0) {
+ BT_ERR("Invalid ID");
return BLUETOOTH_ERROR_INVALID_PARAM;
}
#ifdef RFCOMM_DIRECT
- BT_INFO("RFCOMM Remove socket request from app, fd=[%d]", socket_fd);
+ BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
- info = __find_rfcomm_info_with_id(socket_fd);
+ info = __find_rfcomm_info_with_id(id);
if (info == NULL)
return BLUETOOTH_ERROR_INVALID_PARAM;
BT_INIT_PARAMS();
BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
- g_array_append_vals(in_param1, &socket_fd, sizeof(int));
+ g_array_append_vals(in_param1, &id, sizeof(int));
result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET,
in_param1, in_param2, in_param3, in_param4, &out_param);
BT_DBG("result: %x", result);
if (result == BLUETOOTH_ERROR_NONE) {
- _bt_remove_server(socket_fd);
+ _bt_remove_server(id);
}
BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
{
#ifdef RFCOMM_DIRECT
rfcomm_info_t *info;
+ rfcomm_conn_t *conn;
char address[20];
if (info == NULL)
return BLUETOOTH_ERROR_INVALID_PARAM;
- if (info->data_io == NULL)
+ conn = __find_rfcomm_conn_with_fd(info, socket_fd);
+ if (conn == NULL)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+
+ if (conn->watch_id == 0 || conn->disconnected)
return BLUETOOTH_ERROR_NOT_CONNECTED;
- g_io_channel_shutdown(info->data_io, TRUE, NULL);
- g_io_channel_unref(info->data_io);
- info->data_io = NULL;
+ close(conn->fd);
+ conn->disconnected = TRUE;
+
+ _bt_convert_addr_type_to_string(address, conn->addr.addr);
- _bt_convert_addr_type_to_string(address, info->addr.addr);
BT_DBG("Address %s", address);
_bt_disconnect_profile(address, info->uuid, NULL, NULL);
- info->disconnect_idle_id = g_idle_add((GSourceFunc)
- __rfcomm_server_disconnect, info);
+ if (info->disconnect_idle_id == 0)
+ info->disconnect_idle_id = g_idle_add(
+ (GSourceFunc)__rfcomm_server_disconnect, info);
BT_DBG("-");
return BLUETOOTH_ERROR_NONE;
BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
{
GSList *l;
+ GSList *ll;
rfcomm_info_t *info;
- char connected_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
- char input_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
+ rfcomm_conn_t *conn;
BT_CHECK_PARAMETER(device_address, return);
BT_CHECK_PARAMETER(connected, return);
- _bt_convert_addr_type_to_string(input_addr, (unsigned char *)device_address->addr);
-
*connected = FALSE;
- for (l = rfcomm_nodes; l != NULL; l = l->next) {
+ for (l = rfcomm_nodes; l; l = l->next) {
info = l->data;
- if (info == NULL)
+ if (info == NULL || info->rfcomm_conns == NULL)
continue;
- _bt_convert_addr_type_to_string(connected_addr, info->addr.addr);
- if (g_strcmp0(connected_addr, input_addr) == 0) {
+ for (ll = info->rfcomm_conns; ll; ll = ll->next) {
+ conn = ll->data;
+
+ if (memcmp(device_address, &conn->addr,
+ sizeof(bluetooth_device_address_t)))
+ continue;
+
*connected = TRUE;
return BLUETOOTH_ERROR_NONE;
}
return BLUETOOTH_ERROR_NONE;
}
-BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int socket_fd, int max_pending_connection)
+BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
{
#ifdef RFCOMM_DIRECT
rfcomm_info_t *info;
#endif
BT_CHECK_ENABLED(return);
- if (socket_fd < 0) {
- BT_ERR("Invalid FD");
+ if (id < 0) {
+ BT_ERR("Invalid ID");
return BLUETOOTH_ERROR_INVALID_PARAM;
}
#ifdef RFCOMM_DIRECT
BT_INFO("RFCOMM Listen & accept from app");
- info = __find_rfcomm_info_with_id(socket_fd);
+ info = __find_rfcomm_info_with_id(id);
if (info == NULL)
return BLUETOOTH_ERROR_INVALID_PARAM;
BT_INIT_PARAMS();
BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
- g_array_append_vals(in_param1, &socket_fd, sizeof(int));
+ g_array_append_vals(in_param1, &id, sizeof(int));
g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
#endif
}
-BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid, int max_pending_connection, const char *bus_name, const char *path)
+BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
+ int max_pending_connection,
+ const char *bus_name, const char *path)
{
#ifdef RFCOMM_DIRECT
rfcomm_info_t *info;
#endif
}
-BT_EXPORT_API int bluetooth_rfcomm_listen(int socket_fd, int max_pending_connection)
+BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
{
#ifdef RFCOMM_DIRECT
rfcomm_info_t *info;
#endif
BT_CHECK_ENABLED(return);
+ if (id < 0) {
+ BT_ERR("Invalid ID");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
#ifdef TIZEN_DPM_ENABLE
if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
}
#endif
- if (socket_fd < 0) {
- BT_ERR("Invalid FD");
- return BLUETOOTH_ERROR_INVALID_PARAM;
- }
-
#ifdef RFCOMM_DIRECT
BT_INFO("RFCOMM Listen");
- info = __find_rfcomm_info_with_id(socket_fd);
+ info = __find_rfcomm_info_with_id(id);
if (info == NULL)
return BLUETOOTH_ERROR_INVALID_PARAM;
return result;
return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
- info->path, socket_fd);
+ info->path, id);
#else
BT_INIT_PARAMS();
BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
- g_array_append_vals(in_param1, &socket_fd, sizeof(int));
+ g_array_append_vals(in_param1, &id, sizeof(int));
g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
BT_DBG("result: %x", result);
if (result == BLUETOOTH_ERROR_NONE) {
- _bt_add_server(socket_fd);
+ _bt_add_server(id);
}
BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
if (is_initialized == TRUE) {
BT_ERR("Bluetooth telephony already initilized");
- return BLUETOOTH_TELEPHONY_ERROR_ALREADY_INITIALIZED;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
is_initialized = TRUE;
/* Call Path */
snprintf(telephony_info.call_path, sizeof(telephony_info.call_path),
CSD_CALL_APP_PATH, getpid());
- BT_DBG("Call Path = %s", telephony_info.call_path);
+ BT_INFO("Call Path = %s", telephony_info.call_path);
memset(telephony_info.address, 0x00, sizeof(telephony_info.address));
if (__bluetooth_telephony_proxy_init()) {
#define BT_CHECK_ENABLED_INTERNAL(func) \
do { \
- if (_bt_check_enabled_internal() == FALSE) \
- { \
+ if (_bt_check_enabled_internal() == FALSE) { \
BT_ERR("BT BREDR is not enabled"); \
func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
} \
gboolean _check_uuid_path(char *path, char *uuid);
#endif
+void _bluetooth_hid_free_hid_info(void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
#define _bt_send_request(a, b, format ...) ( \
{ \
- if (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE) \
+ if ((a != BT_CHECK_PRIVILEGE && (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE)) && \
+ (b != BT_GET_LOCAL_NAME && b != BT_GET_LOCAL_ADDRESS && \
+ b != BT_GET_BONDED_DEVICE && b != BT_IS_DEVICE_CONNECTED && \
+ b != BT_GET_BONDED_DEVICES && b != BT_GET_DISCOVERABLE_MODE)) \
BT_INFO_C("Sync Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
else \
BT_DBG("Sync Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
#define _bt_send_request_async(a, b, format ...) ( \
{ \
- if (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE) \
+ if ((a != BT_CHECK_PRIVILEGE && (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE)) && \
+ (b != BT_GET_LOCAL_NAME && b != BT_GET_LOCAL_ADDRESS && \
+ b != BT_GET_BONDED_DEVICE && b != BT_IS_DEVICE_CONNECTED && \
+ b != BT_GET_BONDED_DEVICES && b != BT_GET_DISCOVERABLE_MODE)) \
BT_INFO_C("Async Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
else \
BT_DBG("Async Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
}
break;
}
+ case BT_GET_IS_ALIAS_SET: {
+ bluetooth_device_address_t address = { {0} };
+ gboolean is_alias_set = FALSE;
+
+ __bt_service_get_parameters(in_param1,
+ &address, sizeof(bluetooth_device_address_t));
+
+ result = _bt_is_alias_set(&address, &is_alias_set);
+ if (result == BLUETOOTH_ERROR_NONE)
+ g_array_append_vals(*out_param1, &is_alias_set, sizeof(gboolean));
+
+ break;
+ }
case BT_BOND_DEVICE: {
bluetooth_device_address_t address = { {0} };
case BT_IS_CONNECTABLE:
case BT_GET_BONDED_DEVICES:
case BT_GET_BONDED_DEVICE:
+ case BT_GET_IS_ALIAS_SET:
case BT_IS_DEVICE_CONNECTED:
case BT_GET_SPEAKER_GAIN:
case BT_SET_SPEAKER_GAIN:
__bt_register_adv_slot_owner(sender, adv_handle, slot_id);
le_adv_slot[slot_id].is_advertising = enable;
- BT_INFO("Set advertising [%d]", enable);
+ BT_INFO_C("### Set advertising [%d]", enable);
if (ret)
g_variant_unref(ret);
max = params->interval_max / BT_ADV_INTERVAL_SPLIT;
ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingParameters",
- g_variant_new("(uuuui)", min, max,
+ g_variant_new("(uuuui)", min, max,
params->filter_policy, params->type,
slot_id), G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
le_adv_slot[0].hold_timer_id = g_timeout_add(2000,
__bt_hold_current_advertising_timeout_cb, NULL);
+ } else {
+ BT_ERR("It's NOT advertising");
+ return BLUETOOTH_ERROR_NOT_IN_OPERATION;
}
return BLUETOOTH_ERROR_NONE;
return BLUETOOTH_ERROR_INTERNAL;
}
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL) {
BT_ERR("conn == NULL");
g_free(device_path);
GDBusProxy *proxy;
GDBusConnection *conn;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (!conn)
return NULL;
BT_CHECK_PARAMETER(device_path, return);
BT_CHECK_PARAMETER(dev_info, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
} else if (!g_strcmp0(key, "Name")) {
if (!name)
g_variant_get(value, "s", &name);
- } else if(!g_strcmp0(key, "IsAliasSet")) {
- dev_info->is_alias_set = g_variant_get_boolean(value);
} else if (!g_strcmp0(key, "Class")) {
cod = g_variant_get_uint32(value);
} else if (!g_strcmp0(key, "Connected")) {
/* Send disabled event */
_bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
- g_variant_new_int32(result));
+ g_variant_new("(i)", result));
}
void *_bt_get_adapter_agent(void)
}
#endif
+int _bt_enable_adapter_check_status(void)
+{
+ bt_status_t status = _bt_adapter_get_status();
+ bt_le_status_t le_status = _bt_adapter_get_le_status();
+
+ BT_DBG("");
+
+ if (status == BT_ACTIVATING) {
+ BT_ERR("Enabling in progress");
+ return BLUETOOTH_ERROR_IN_PROGRESS;
+ }
+
+ if (status == BT_ACTIVATED) {
+ BT_ERR("Already enabled");
+ return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
+ }
+
+ if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
+ BT_ERR("Disabling in progress");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
int _bt_enable_adapter(void)
{
GDBusProxy *proxy;
BT_DBG("");
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
return BLUETOOTH_ERROR_NONE;
}
+int _bt_disable_adapter_check_status(void)
+{
+ bt_status_t status = _bt_adapter_get_status();
+
+ BT_DBG("");
+
+ if (status == BT_DEACTIVATING) {
+ BT_DBG("Disabling in progress");
+ return BLUETOOTH_ERROR_IN_PROGRESS;
+ }
+
+ if (status == BT_DEACTIVATED) {
+ BT_DBG("Already disabled");
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
int _bt_disable_adapter(void)
{
BT_DBG("+");
GVariantIter *iter = NULL;
GError *error = NULL;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
manager_proxy = _bt_get_manager_proxy();
GDBusProxy *device_proxy = NULL;
gboolean is_connected = FALSE;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
manager_proxy = _bt_get_manager_proxy();
return ret;
}
+int _bt_is_alias_set(bluetooth_device_address_t *device_address, gboolean *is_alias_set)
+{
+ char *object_path = NULL;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gboolean alias_set = FALSE;
+
+ GDBusConnection *conn;
+ GDBusProxy *device_proxy;
+ GError *error = NULL;
+ GVariant *result = NULL;
+ GVariant *temp = NULL;
+
+
+ BT_CHECK_PARAMETER(device_address, return);
+ BT_CHECK_PARAMETER(is_alias_set, return);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ object_path = _bt_get_device_object_path(address);
+ retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
+
+ conn = _bt_gdbus_get_system_gconn();
+ if (conn == NULL) {
+ g_free(object_path);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ BT_BLUEZ_NAME,
+ object_path,
+ BT_PROPERTIES_INTERFACE,
+ NULL, NULL);
+ if (device_proxy == NULL) {
+ g_free(object_path);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "IsAliasSet"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (!result) {
+ BT_ERR("Error occured in Proxy call");
+ if (error != NULL) {
+ BT_ERR("Getting is_alias_set property failed: [%s]\n", error->message);
+ g_error_free(error);
+ }
+ g_object_unref(device_proxy);
+ g_free(object_path);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_variant_get(result, "(v)", &temp);
+ alias_set = g_variant_get_boolean(temp);
+ *is_alias_set = alias_set;
+ BT_DBG("address: [%s] | *is_alias_set: %s", address, *is_alias_set ? "TRUE" : "FALSE");
+ g_variant_unref(temp);
+ g_variant_unref(result);
+ g_object_unref(device_proxy);
+
+ g_free(object_path);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
int _bt_get_timeout_value(int *timeout)
{
time_t current_time;
int result = BLUETOOTH_ERROR_NONE;
bt_service_alarm_t *alarm = NULL;
- if(!call_back || !alarm_id)
+ if (!call_back || !alarm_id)
return BLUETOOTH_ERROR_INVALID_PARAM;
if (!alarm_mgr.is_alarm_initialized) {
result = alarmmgr_init("bt-service");
if (result != 0) {
- BT_ERR("Failed to initialize alarm = %d",result);
+ BT_ERR("Failed to initialize alarm = %d", result);
result = BLUETOOTH_ERROR_INTERNAL;
goto finish;
}
result = alarmmgr_set_cb(alarm_cb, NULL);
if (result != 0) {
- BT_ERR("Failed to set the callback = %d",result);
+ BT_ERR("Failed to set the callback = %d", result);
result = BLUETOOTH_ERROR_INTERNAL;
goto finish;
}
}
alarm = g_malloc0(sizeof(bt_service_alarm_t));
- if(!alarm)
+ if (!alarm)
return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, timeout,
0, NULL, alarm_id);
if (result != 0) {
- BT_ERR("Failed to create alarm error = %d",result);
+ BT_ERR("Failed to create alarm error = %d", result);
result = BLUETOOTH_ERROR_INTERNAL;
g_free(alarm);
goto finish;
int _bt_adapter_request_delayed(int function)
{
- bt_status_t status = _bt_adapter_get_status();
- bt_le_status_t le_status = _bt_adapter_get_le_status();
+ int ret;
switch (function) {
case BT_ENABLE_ADAPTER:
- if (status == BT_ACTIVATING) {
- BT_ERR("Enabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (status == BT_ACTIVATED) {
- BT_ERR("Already enabled");
- return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
- }
-
- if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
- BT_ERR("Disabling in progress");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
+ ret = _bt_enable_adapter_check_status();
+ if (ret == BLUETOOTH_ERROR_NONE)
+ _bt_adapter_set_status(BT_ACTIVATING);
+ else
+ return ret;
break;
case BT_DISABLE_ADAPTER:
- if (status == BT_DEACTIVATING) {
- BT_DBG("Disabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (status == BT_DEACTIVATED) {
- BT_DBG("Already disabled");
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
+ ret = _bt_disable_adapter_check_status();
+ if (ret == BLUETOOTH_ERROR_NONE)
+ _bt_adapter_set_status(BT_DEACTIVATING);
+ else
+ return ret;
break;
default:
_bt_audio_connect(pdata->req_id,
BT_AUDIO_A2DP,
&device_address,
- pdata->out_param);
+ NULL);
g_free(pdata->address);
g_free(pdata);
}
if (func_data->pending != BT_PENDING_NONE && g_error == NULL) {
-
bluetooth_device_address_t device_address;
_bt_convert_addr_string_to_type(device_address.addr,
func_data->address);
pdata = g_new0(bt_audio_function_data_t, 1);
pdata->req_id = func_data->req_id;
- pdata->out_param = func_data->out_param;
pdata->address = strdup(func_data->address);
pdata->pending = func_data->pending;
} else
goto check_req_info;
} else {
-
if (_bt_is_service_connected(func_data->address
, BT_AUDIO_HSP)) {
_bt_audio_disconnect(func_data->req_id,
- BT_AUDIO_HSP,
- &device_address,
- func_data->out_param);
+ BT_AUDIO_HSP, &device_address, NULL);
} else
goto check_req_info;
}
_bt_convert_addr_string_to_type(device_address.addr,
g_wait_data->address);
_bt_audio_connect(g_wait_data->req_id, g_wait_data->type,
- &device_address, g_wait_data->out_param1);
+ &device_address, NULL);
}
/* Event will be sent by the event reciever */
#endif
static int __bt_is_headset_connected(int type, int req_id,
- const char *address, GArray *out_param1)
+ const char *address)
{
gboolean connected = FALSE;
char connected_address[BT_ADDRESS_STRING_SIZE + 1];
g_wait_data->req_id = req_id;
g_wait_data->type = type;
g_wait_data->ag_flag = FALSE;
- g_wait_data->out_param1 = out_param1;
/* Set disconnection type */
__bt_set_headset_disconnection_type(connected_address);
return value;
}
-
-
static int __bt_is_headset_connecting(int type)
{
bt_connected_headset_data_t *connected_device = NULL;
return BLUETOOTH_ERROR_NONE;
}
-
int __bt_is_headset_disconnecting(int type)
{
bt_connected_headset_data_t *connected_device = NULL;
return BLUETOOTH_ERROR_NONE;
}
-
void _bt_set_audio_wait_data_flag(gboolean flag)
{
BT_DBG("_bt_set_audio_wait_data_flag \n");
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- g_conn = _bt_get_system_gconn();
+ g_conn = _bt_gdbus_get_system_gconn();
retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
func_data->req_id = request_id;
func_data->type = type;
func_data->pending = BT_PENDING_NONE;
- func_data->out_param = out_param1;
result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_HFP_HS, &hfp_hs_restricted);
if (result != BLUETOOTH_ERROR_NONE)
}
BT_INFO("Connecting to service %s", uuid);
- value = __bt_is_headset_connected(type, request_id, address, out_param1);
+ value = __bt_is_headset_connected(type, request_id, address);
if (value == BLUETOOTH_ERROR_ALREADY_CONNECT) {
return BLUETOOTH_ERROR_ALREADY_CONNECT;
return BLUETOOTH_ERROR_IN_PROGRESS;
}
+ if (out_param1)
+ g_array_free(out_param1, TRUE);
+
return BLUETOOTH_ERROR_NONE;
fail:
- g_array_append_vals(out_param1, address,
- BT_ADDRESS_STR_LEN);
+ if (out_param1 != NULL)
+ g_array_append_vals(out_param1, address,
+ BT_ADDRESS_STR_LEN);
return result;
}
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- g_conn = _bt_get_system_gconn();
+ g_conn = _bt_gdbus_get_system_gconn();
retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
func_data->address = g_strdup(address);
func_data->req_id = request_id;
func_data->pending = BT_PENDING_NONE;
- func_data->out_param = out_param1;
func_data->type = type;
switch (type) {
}
_bt_add_headset_to_list(type, BT_STATE_DISCONNECTING, address);
+ if (out_param1)
+ g_array_free(out_param1, TRUE);
+
return BLUETOOTH_ERROR_NONE;
fail:
if (out_param1 != NULL)
goto fail;
}
- g_conn = _bt_get_system_gconn();
+ g_conn = _bt_gdbus_get_system_gconn();
if (g_conn == NULL) {
result = BLUETOOTH_ERROR_INTERNAL;
goto fail;
return ret;
}
g_free(uuid);
+ if (out_param1)
+ g_array_free(out_param1, TRUE);
+
return BLUETOOTH_ERROR_NONE;
fail:
if (out_param1 != NULL)
goto fail;
}
- g_conn = _bt_get_system_gconn();
+ g_conn = _bt_gdbus_get_system_gconn();
if (g_conn == NULL) {
result = BLUETOOTH_ERROR_INTERNAL;
goto fail;
return ret;
}
g_free(uuid);
+ if (out_param1)
+ g_array_free(out_param1, TRUE);
+
return BLUETOOTH_ERROR_NONE;
fail:
if (out_param1 != NULL)
BT_DBG("+\n");
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
BT_DBG("Content Protection status = [%d]", status);
g_dbus_error_strip_remote_error(err);
BT_INFO("Auto_connect_request Dbus Call Error: %s", err->message);
- if (strcmp("Host is down", err->message))
- {
+ if (strcmp("Host is down", err->message)) {
BT_INFO("Fail reason is not 'Host Down'. Terminate auto connect");
_bt_audio_stop_auto_connect();
vconf_set_str(BT_LAST_CONNECTED_DEVICE, "");
BT_INFO("Command [%s]", name);
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
control_path = __bt_get_control_device_path();
retv_if(control_path == NULL, NULL);
BT_DBG("control_path = %s", control_path);
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
proxy = g_dbus_proxy_new_sync(conn,
case SHUFFLE:
case SCAN:
case STATUS:
- name =(char *)g_variant_get_data(reply);
+ name = (char *)g_variant_get_data(reply);
if (name)
*value = __bt_media_attrval_to_val(type, name);
BT_INFO("Type[%s] and Value[%s]", __bt_media_type_to_str(type), name);
BT_DBG("Value : %s ", value_string);
metadata->title = g_strdup(value_string);
} else if (strcasecmp(key, "Artist") == 0) {
- value_string =(char *)g_variant_get_string(value, NULL);
+ value_string = (char *)g_variant_get_string(value, NULL);
BT_DBG("Value : %s ", value_string);
metadata->artist = g_strdup(value_string);
} else if (strcasecmp(key, "Album") == 0) {
- value_string =(char *)g_variant_get_string(value, NULL);
+ value_string = (char *)g_variant_get_string(value, NULL);
BT_DBG("Value : %s ", value_string);
metadata->album = g_strdup(value_string);
} else if (strcasecmp(key, "Genre") == 0) {
- value_string =(char *)g_variant_get_string(value, NULL);
+ value_string = (char *)g_variant_get_string(value, NULL);
BT_DBG("Value : %s ", value_string);
metadata->genre = g_strdup(value_string);
} else if (strcasecmp(key, "Duration") == 0) {
retv_if(metadata == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
control_path = __bt_get_control_device_path();
{ STATUS_INVALID, "" }
};
-static GDBusConnection *bt_gdbus_conn = NULL;
static guint avrcp_reg_id = 0;
/* Introspection data exposed from bt-service */
int _bt_register_media_player(void)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
gchar *adapter_path;
gboolean shuffle_status;
gchar *path;
player_settings.position = 0;
shuffle_status = FALSE;
- if (bt_gdbus_conn == NULL) {
- bt_gdbus_conn = _bt_get_system_gconn();
- retv_if(bt_gdbus_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- }
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
node_info = __bt_avrcp_create_method_node_info(
bt_avrcp_bluez_introspection_xml);
if (node_info == NULL)
return BLUETOOTH_ERROR_INTERNAL;
- avrcp_reg_id = g_dbus_connection_register_object(bt_gdbus_conn,
+ avrcp_reg_id = g_dbus_connection_register_object(g_conn,
BT_MEDIA_OBJECT_PATH,
node_info->interfaces[0],
&method_table,
adapter_path = _bt_get_adapter_path();
retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
- proxy = g_dbus_proxy_new_sync(bt_gdbus_conn,
+ proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
BT_BLUEZ_NAME, adapter_path,
BT_MEDIA_INTERFACE, NULL, &error);
static void __bt_avrcp_unregister_object_path(void)
{
+ GDBusConnection *g_conn;
+
+ g_conn = _bt_gdbus_get_system_gconn();
+ ret_if(g_conn == NULL);
+
if (avrcp_reg_id > 0) {
- g_dbus_connection_unregister_object(bt_gdbus_conn,
+ g_dbus_connection_unregister_object(g_conn,
avrcp_reg_id);
avrcp_reg_id = 0;
}
int _bt_unregister_media_player(void)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
GDBusProxy *proxy;
gchar *adapter_path;
GVariant *ret;
gchar *path;
int result = BLUETOOTH_ERROR_NONE;
- retv_if(bt_gdbus_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
adapter_path = _bt_get_adapter_path();
if (adapter_path == NULL) {
result = BLUETOOTH_ERROR_INTERNAL;
goto FAIL;
}
- proxy = g_dbus_proxy_new_sync(bt_gdbus_conn,
+ g_conn = _bt_gdbus_get_system_gconn();
+ if (g_conn == NULL) {
+ BT_ERR("g_conn is NULL");
+ g_free(adapter_path);
+ result = BLUETOOTH_ERROR_INTERNAL;
+ goto FAIL;
+ }
+
+ proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
BT_BLUEZ_NAME, adapter_path,
BT_MEDIA_INTERFACE, NULL, &error);
FAIL:
__bt_avrcp_unregister_object_path();
- if (bt_gdbus_conn) {
- g_object_unref(bt_gdbus_conn);
- bt_gdbus_conn = NULL;
- }
-
BT_DBG("-");
return result;
}
{
BT_DBG("+");
char *interface = BT_MEDIA_PLAYER_INTERFACE;
- GDBusConnection *conn;
+ GDBusConnection *g_conn;
GError *error = NULL;
GVariantBuilder *builder = NULL;
GVariantBuilder *inner_builder = NULL;
retv_if(meta_data == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = bt_gdbus_conn;
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+ g_conn = _bt_gdbus_get_system_gconn();;
+ retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add(builder, "{sv}",
"Metadata", g_variant_new("a{sv}", inner_builder));
- ret = g_dbus_connection_emit_signal(conn, NULL, BT_MEDIA_OBJECT_PATH,
+ ret = g_dbus_connection_emit_signal(g_conn, NULL, BT_MEDIA_OBJECT_PATH,
DBUS_INTERFACE_PROPERTIES,
"PropertiesChanged",
g_variant_new("(sa{sv})",
int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties)
{
BT_DBG("+");
- GDBusConnection *conn;
+ GDBusConnection *g_conn;
int value;
media_metadata_attributes_t meta_data;
gboolean shuffle;
GVariantBuilder *builder = NULL;
GVariant *children[1];
- conn = bt_gdbus_conn;
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+ g_conn = _bt_gdbus_get_system_gconn();;
+ retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
switch (type) {
case REPEAT:
value = properties->repeat;
- if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+ if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
BT_MEDIA_PLAYER_INTERFACE, "LoopStatus",
g_variant_new_string(loopstatus_settings[value].property))) {
BT_ERR("Error sending the PropertyChanged signal \n");
else
shuffle = TRUE;
- if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+ if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
BT_MEDIA_PLAYER_INTERFACE, "Shuffle",
g_variant_new_boolean(shuffle))) {
BT_ERR("Error sending the PropertyChanged signal \n");
break;
case STATUS:
value = properties->status;
- if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+ if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
BT_MEDIA_PLAYER_INTERFACE, "PlaybackStatus",
g_variant_new_string(player_status[value].property))) {
BT_ERR("Error sending the PropertyChanged signal \n");
break;
case POSITION:
value = properties->position;
- if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+ if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
BT_MEDIA_PLAYER_INTERFACE, "Position",
g_variant_new_uint32(value))) {
BT_ERR("Error sending the PropertyChanged signal \n");
"xesam:trackNumber", g_variant_new_int32(meta_data.number));
g_variant_builder_add(builder, "{sv}",
- "mpris:lenght", g_variant_new_int64(meta_data.duration));
+ "mpris:length", g_variant_new_int64(meta_data.duration));
- if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+ if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
BT_MEDIA_PLAYER_INTERFACE, "Metadata",
g_variant_new("a{sv}", builder))) {
BT_ERR("Error sending the PropertyChanged signal \n");
static GDBusProxy *adapter_properties_proxy;
-static GDBusConnection *system_gconn = NULL;
-
GDBusConnection *_bt_gdbus_init_system_gconn(void)
{
GError *error = NULL;
dbus_threads_init_default();
- if (system_gconn != NULL)
- return system_gconn;
+ if (system_conn != NULL)
+ return system_conn;
- system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!system_gconn) {
+ if (!system_conn) {
BT_ERR("Unable to connect to dbus: %s", error->message);
g_clear_error(&error);
}
- return system_gconn;
+ return system_conn;
}
GDBusConnection *_bt_gdbus_get_system_gconn(void)
GDBusConnection *local_system_gconn = NULL;
GError *error = NULL;
- if (system_gconn == NULL) {
- system_gconn = _bt_gdbus_init_system_gconn();
- } else if (g_dbus_connection_is_closed(system_gconn)) {
-
+ if (system_conn == NULL) {
+ system_conn = _bt_gdbus_init_system_gconn();
+ } else if (g_dbus_connection_is_closed(system_conn)) {
local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!local_system_gconn) {
g_clear_error(&error);
}
- system_gconn = local_system_gconn;
+ system_conn = local_system_gconn;
}
- return system_gconn;
+ return system_conn;
+}
+
+GDBusConnection *_bt_gdbus_init_session_gconn(void)
+{
+ GError *error = NULL;
+
+ if (!g_thread_supported()) {
+ g_thread_init(NULL);
+ }
+
+ dbus_threads_init_default();
+
+ if (session_conn != NULL)
+ return session_conn;
+
+ session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+ if (!session_conn) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+
+ return session_conn;
+}
+
+GDBusConnection *_bt_gdbus_get_session_gconn(void)
+{
+ GDBusConnection *local_session_gconn = NULL;
+ GError *error = NULL;
+
+ if (session_conn == NULL) {
+ session_conn = _bt_gdbus_init_session_gconn();
+ } else if (g_dbus_connection_is_closed(session_conn)) {
+ local_session_gconn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+ if (!local_session_gconn) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+
+ session_conn = local_session_gconn;
+ }
+
+ return session_conn;
}
static GDBusProxy *__bt_init_manager_proxy(void)
{
+ GDBusConnection *g_conn;
GDBusProxy *proxy;
- if (system_conn == NULL) {
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
- retv_if(system_conn == NULL, NULL);
- }
+ dbus_threads_init_default();
+
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, NULL);
- proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_BLUEZ_NAME,
BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
static GDBusProxy *__bt_init_adapter_proxy(void)
{
+ GDBusConnection *g_conn;
GDBusProxy *manager_proxy;
GDBusProxy *proxy;
char *adapter_path = NULL;
- if (system_conn == NULL) {
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
- retv_if(system_conn == NULL, NULL);
- }
+ dbus_threads_init_default();
+
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
retv_if(manager_proxy == NULL, NULL);
adapter_path = _bt_get_adapter_path();
retv_if(adapter_path == NULL, NULL);
- proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_BLUEZ_NAME,
adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
static GDBusProxy *__bt_init_adapter_properties_proxy(void)
{
+ GDBusConnection *g_conn;
GDBusProxy *manager_proxy;
GDBusProxy *proxy;
char *adapter_path = NULL;
- if (system_conn == NULL) {
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
- retv_if(system_conn == NULL, NULL);
- }
+ dbus_threads_init_default();
+
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
retv_if(manager_proxy == NULL, NULL);
adapter_path = _bt_get_adapter_path();
retv_if(adapter_path == NULL, NULL);
- proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_BLUEZ_NAME,
adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
return proxy;
}
-GDBusConnection *__bt_init_system_gconn(void)
-{
- if (system_conn == NULL)
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-
- return system_conn;
-}
-
-GDBusConnection *__bt_init_session_conn(void)
-{
- if (session_conn == NULL)
- session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
-
- return session_conn;
-}
-
-GDBusConnection *_bt_get_session_gconn(void)
-{
- return (session_conn) ? session_conn : __bt_init_session_conn();
-}
-
-GDBusConnection *_bt_get_system_gconn(void)
-{
- return (system_conn) ? system_conn : __bt_init_system_gconn();
-}
-
-GDBusConnection *_bt_get_system_conn(void)
-{
- GDBusConnection *g_conn;
-
- if (system_conn == NULL) {
- g_conn = __bt_init_system_gconn();
- } else {
- g_conn = system_conn;
- }
-
- if (!g_conn) {
- BT_ERR("Unable to get dbus connection");
- return NULL;
- }
-
- return g_conn;
-}
-
GDBusProxy *_bt_get_manager_proxy(void)
{
if (manager_proxy) {
GVariantIter *iter = NULL;
char *adapter_path = NULL;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
ret_if(addr == NULL);
len = strlen(address);
- ret_if(len != BT_ADDRESS_STRING_SIZE- 1);
+ ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
strncpy(addr, address, len);
GVariant *result = NULL;
GVariantIter *iter = NULL;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
char * _bt_convert_disc_reason_to_string(int reason)
{
- switch(reason) {
+ switch (reason) {
case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
return "Page timeout";
case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
return ret;
}
-void __bt_get_auth_info(GVariant *reply, char *auth_info)
+void __bt_get_auth_info(GVariant *reply, char *auth_info)
{
int cursor;
GVariant *tmp_value;
guint8 m_value;
int i = 0;
-
- tmp_value = g_variant_lookup_value (reply, "IsAliasSet",
+ tmp_value = g_variant_lookup_value(reply, "IsAliasSet",
G_VARIANT_TYPE_BOOLEAN);
if (tmp_value) {
is_alias_set = g_variant_get_boolean(tmp_value);
char *pin_code;
} bt_pin_code_info_t;
+typedef struct {
+ int req_id;
+ bluetooth_device_address_t bd_addr;
+ gboolean auto_connect;
+} bt_pending_le_conn_info_s;
+
gboolean is_device_creating;
bt_funcion_data_t *bonding_info;
bt_funcion_data_t *searching_info;
bt_funcion_data_t *att_mtu_req_info;
static GSList *pin_info_list = NULL;
+static bt_pending_le_conn_info_s *pending_le_conn_info = NULL;
+static guint pending_le_conn_timer_id = 0;
/* This HID Mouse does not support pairing precedure. need to skip it. */
#define SMB_MOUSE_LAP_ADDR "00:12:A1"
bundle *b = NULL;
GDBusConnection *conn;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL)
return FALSE;
retv_if(object_path == NULL, NULL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL) {
BT_ERR("conn == NULL");
return NULL;
g_variant_unref(tmp_value);
}
- tmp_value = g_variant_lookup_value (value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
+ tmp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
if (tmp_value) {
dev_info->is_alias_set = g_variant_get_boolean(tmp_value);
g_variant_unref(tmp_value);
{
int result = BLUETOOTH_ERROR_NONE;
GError *err = NULL;
+ GVariant *reply;
GVariant *out_param1;
request_info_t *req_info;
bluetooth_device_info_t dev_info;
/* Terminate ALL system popup */
syspopup_destroy_all();
- g_dbus_proxy_call_finish(proxy, res, &err);
+ reply = g_dbus_proxy_call_finish(proxy, res, &err);
+ if (reply)
+ g_variant_unref(reply);
is_device_creating = FALSE;
result = BLUETOOTH_ERROR_HOST_DOWN;
} else if (g_strrstr(err->message, BT_DBUS_TIMEOUT_MESSAGE)) {
BT_INFO("Cancel already running bonding");
- if(__bt_cancel_bonding() != BLUETOOTH_ERROR_NONE) {
+ if (__bt_cancel_bonding() != BLUETOOTH_ERROR_NONE) {
BT_INFO("Error while Cancelling bonding");
/* we need to unref proxy so continue */
}
}
remote_dev_info = _bt_get_remote_device_info(bonding_info->addr);
- if(!remote_dev_info)
+ if (!remote_dev_info)
goto dbus_return;
GVariant *uuids = NULL;
return BLUETOOTH_ERROR_DEVICE_BUSY;
}
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
gpointer user_data)
{
GError *err = NULL;
+ GVariant *reply;
GVariant *out_param1;
int result = BLUETOOTH_ERROR_NONE;
bt_funcion_data_t *unbonding_info;
bluetooth_device_info_t dev_info;
request_info_t *req_info;
- g_dbus_proxy_call_finish(proxy, res, &err);
+ reply = g_dbus_proxy_call_finish(proxy, res, &err);
+ if (reply)
+ g_variant_unref(reply);
unbonding_info = user_data;
goto fail;
}
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL) {
BT_ERR("conn is NULL");
result = BLUETOOTH_ERROR_INTERNAL;
gpointer user_data)
{
GError *err = NULL;
+ GVariant *reply;
GVariant *out_param1;
int result = BLUETOOTH_ERROR_NONE;
bluetooth_device_info_t dev_info;
GVariantBuilder *builder = NULL;
int i = 0;
- g_dbus_proxy_call_finish(proxy, res, &err);
+ reply = g_dbus_proxy_call_finish(proxy, res, &err);
+ if (reply)
+ g_variant_unref(reply);
g_object_unref(proxy);
}
remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
- if(!remote_dev_info)
+ if (!remote_dev_info)
goto dbus_return;
event:
_bt_convert_addr_type_to_string(searching_info->addr,
device_address->addr);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
BT_CHECK_PARAMETER(device_address, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
}
result = g_dbus_proxy_call_sync(device_proxy, "Set",
- g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Trusted", g_variant_new("b",authorize)),
+ g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Trusted", g_variant_new("b", authorize)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
BT_CHECK_PARAMETER(device_address, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
BT_CHECK_PARAMETER(device_address, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
}
}
-int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
- gboolean auto_connect)
+static int __bt_connect_le_device_internal(int req_id, const bluetooth_device_address_t *bd_addr,
+ gboolean auto_connect)
{
char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
gchar *device_path = NULL;
BT_CHECK_PARAMETER(bd_addr, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(device_address,
func_data->req_id = req_id;
- ret = _bt_hold_current_advertising();
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Unable to hold advertising");
- }
-
g_dbus_proxy_call(device_proxy, "ConnectLE",
g_variant_new("(b)", auto_connect),
G_DBUS_CALL_FLAGS_NONE,
return ret;
}
+static gboolean __bt_connect_le_timer_cb(gpointer user_data)
+{
+ BT_INFO("Try to initiate pending LE connection");
+
+ pending_le_conn_timer_id = 0;
+
+ __bt_connect_le_device_internal(pending_le_conn_info->req_id,
+ &pending_le_conn_info->bd_addr,
+ pending_le_conn_info->auto_connect);
+
+ g_free(pending_le_conn_info);
+ pending_le_conn_info = NULL;
+
+ return FALSE;
+}
+
+void _bt_pending_connect_le_device(void)
+{
+ if (pending_le_conn_timer_id > 0) {
+ g_source_remove(pending_le_conn_timer_id);
+ __bt_connect_le_timer_cb(NULL);
+ }
+}
+
+int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
+ gboolean auto_connect)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+
+ ret = _bt_hold_current_advertising();
+ if (ret == BLUETOOTH_ERROR_NONE) {
+ BT_INFO("Current advertising is held");
+ pending_le_conn_info = g_malloc0(sizeof(bt_pending_le_conn_info_s));
+ pending_le_conn_info->req_id = req_id;
+ memcpy(pending_le_conn_info->bd_addr.addr, bd_addr->addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+ pending_le_conn_info->auto_connect = auto_connect;
+
+ pending_le_conn_timer_id =
+ g_timeout_add(1000, __bt_connect_le_timer_cb, NULL);
+
+ return BLUETOOTH_ERROR_NONE;
+ }
+
+ BT_ERR("Unable to hold advertising");
+
+ return __bt_connect_le_device_internal(req_id, bd_addr, auto_connect);
+}
+
int _bt_disconnect_le_device(int req_id,
const bluetooth_device_address_t *bd_addr)
{
BT_CHECK_PARAMETER(bd_addr, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(device_address,
_bt_convert_addr_type_to_string(device_address,
(unsigned char *)bd_addr->addr);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_proxy = _bt_get_adapter_proxy();
_bt_convert_addr_type_to_string(device_address,
(unsigned char *)bd_addr->addr);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_proxy = _bt_get_adapter_proxy();
GVariant *result = NULL;
GError *error = NULL;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
object_path = _bt_get_device_object_path(address);
GDBusProxy *proxy;
GDBusConnection *conn;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
object_path = _bt_get_device_object_path(address);
goto fail;
}
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL) {
BT_ERR("conn NULL");
ret = BLUETOOTH_ERROR_INTERNAL;
bd_addr->addr[4], bd_addr->addr[5],
profile, trust);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, bd_addr->addr);
bd_addr->addr[4], bd_addr->addr[5],
profile, *trust);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, bd_addr->addr);
bd_addr->addr[4], bd_addr->addr[5],
profile, restricted);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, bd_addr->addr);
bd_addr->addr[4], bd_addr->addr[5],
profile, *restricted);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, bd_addr->addr);
goto dbus_return;
if (val) {
- g_variant_get (val, "(qy)", &mtu, &status);
- g_variant_unref (val);
+ g_variant_get(val, "(qy)", &mtu, &status);
+ g_variant_unref(val);
}
BT_DBG("MTU %d, Status %d, %s", mtu, status, att_mtu_req_info->addr);
return BLUETOOTH_ERROR_DEVICE_BUSY;
}
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_proxy = _bt_get_adapter_proxy();
BT_CHECK_PARAMETER(device_address, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
BT_CHECK_PARAMETER(device_address, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
retv_if(!addr, NULL);
bt_le_adv_info_t *adv_info = NULL;
GList *current = g_list_first((GList *)p_adv_ind_list);
- while(current && current->data) {
+ while (current && current->data) {
adv_info = (bt_le_adv_info_t *)current->data;
if (adv_info && !g_strcmp0(adv_info->addr, addr))
return adv_info;
} else if (strcasecmp(key, "UUIDs") == 0) {
char **uuid_value;
gsize size = 0;
- int i =0;
+ int i = 0;
size = g_variant_get_size(val);
if (size > 0) {
*/
_bt_obex_check_pending_transfer(address);
_bt_opp_client_is_sending(&sending);
- if(sending == TRUE)
+ if (sending == TRUE)
_bt_opp_client_check_pending_transfer(address);
}
param = g_variant_new("(isy)", result, address, addr_type);
_bt_audio_connect(wait_list->req_id,
wait_list->type,
&device_address,
- wait_list->out_param1);
+ NULL);
}
} else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
_bt_audio_connect(wait_list->req_id,
wait_list->type,
&device_address,
- wait_list->out_param1);
+ NULL);
/* Now free the wait list */
_bt_rel_wait_data();
}
_bt_convert_addr_string_to_type(device_address.addr,
wait_list->address);
_bt_audio_connect(wait_list->req_id, wait_list->type,
- &device_address, wait_list->out_param1);
+ &device_address, NULL);
_bt_rel_wait_data();
} else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
/* Add data to the connected list */
_bt_audio_connect(wait_list->req_id,
wait_list->type,
&device_address,
- wait_list->out_param1);
+ NULL);
}
g_free(address);
} else if (strcasecmp(value, "Connected") == 0) {
if (accept == GAP_AGENT_ACCEPT) {
g_dbus_method_invocation_return_value(priv->reply_context, NULL);
} else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
- bluetooth_device_address_t addr = {{0,}};
+ bluetooth_device_address_t addr = { { 0, } };
int result;
_bt_convert_addr_string_to_type(addr.addr,
"CanceledbyUser");
break;
case GAP_AGENT_REJECT: {
- bluetooth_device_address_t addr = {{0,}};
+ bluetooth_device_address_t addr = { { 0, } };
int result;
_bt_convert_addr_string_to_type(addr.addr,
}
reply = g_dbus_proxy_call_sync(agent_manager, "UnregisterAgent",
- g_variant_new("o", priv->path),
+ g_variant_new("(o)", priv->path),
G_DBUS_CALL_FLAGS_NONE, -1,
NULL, &error);
g_object_unref(agent_manager);
if (!agent->cb.passkey_func)
return;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL)
return;
if (!priv->cb.passkey_func)
return;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL)
return;
if (!priv->cb.display_func)
return;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL)
return;
if (!priv->cb.confirm_func)
return;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL)
return;
if (!priv->cb.authorize_func)
return;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL)
return;
if (list == NULL) {
BT_INFO("Head Set didn't initiated a2dp connection");
BT_INFO("local device initiating A2DP connection");
+
_bt_audio_connect(0, BT_AUDIO_A2DP,
&conn_info->dev_info.device_address, NULL);
} else {
if (list == NULL) {
BT_INFO("Headset didn't initiated HFP connection");
BT_INFO("local device intiating HFP Connection");
+
_bt_audio_connect(0, BT_AUDIO_HSP,
&conn_info->dev_info.device_address, NULL);
} else {
if (device == NULL)
return;
- dev_list = g_array_new (FALSE, FALSE, sizeof(gchar));
+ dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
_bt_get_bonded_devices(&dev_list);
size = (dev_list->len) / sizeof(bluetooth_device_info_t);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
*/
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
*/
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
GDBusConnection *conn;
GDBusProxy *server_proxy;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_path = _bt_get_adapter_path();
GDBusProxy *server_proxy;
int ret = BLUETOOTH_ERROR_NONE;
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_path = _bt_get_adapter_path();
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
BT_CHECK_PARAMETER(device_address, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_path = _bt_get_adapter_path();
void _bt_obex_set_complete_cb(char *object_path,
bt_obex_complete_cb func, gpointer data)
{
- bt_obex_agent_info *info =__find_obex_agent_info(object_path);;
+ bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
if (info == NULL)
return;
device_path = _bt_get_device_object_path((char *)bdaddress);
retv_if(device_path == NULL, NULL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
BT_INFO("Device_path %s", device_path);
device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
device_path = _bt_get_device_object_path((char *)bdaddress);
ret_if(device_path == NULL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
ret_if(conn == NULL);
BT_INFO("Device_path %s", device_path);
device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
g_variant_unref(temp_value);
DBG_SECURE("Name = %s", name);
}
- temp_value = g_variant_lookup_value (value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
+ temp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
if (temp_value) {
is_alias_set = g_variant_get_boolean(temp_value);
g_variant_unref(temp_value);
GDBusProxy *proxy;
GError *err = NULL;
- conn = _bt_get_session_gconn();
+ conn = _bt_gdbus_get_session_gconn();
retv_if(conn == NULL, NULL);
proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
GDBusConnection *conn;
GDBusProxy *proxy;
GError *err = NULL;
- conn = _bt_get_session_gconn();
+ conn = _bt_gdbus_get_session_gconn();
retv_if(conn == NULL, NULL);
proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
memcpy(agent_info.auth_info->contact_auth_info, auth_info, 5);
session_info = __bt_find_session_by_path((char *)path);
- if(NULL == session_info) {
+ if (NULL == session_info) {
session_info = g_malloc0(sizeof(bt_session_info_t));
session_info->path = g_strdup(path);
session_info->address = g_strdup(bdaddress);
return TRUE;
}
- if(session_info->authorized == FALSE) {
+ if (session_info->authorized == FALSE) {
_bt_launch_system_popup(BT_AGENT_EVENT_EXCHANGE_REQUEST, device_name,
auth_info, NULL, NULL, BT_OBEX_SERVER_AGENT_PATH);
} else {
__bt_free_auth_info(agent_info.auth_info);
agent_info.auth_info = NULL;
- g_variant_builder_unref (builder);
+ g_variant_builder_unref(builder);
_bt_send_event(BT_OPP_SERVER_EVENT,
BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
_bt_send_event(BT_OPP_SERVER_EVENT,
BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
param);
- g_variant_builder_unref (builder);
+ g_variant_builder_unref(builder);
}
param = g_variant_new("(issssstii)", result,
transfer_info->filename,
GError *g_error = NULL;
/* Get the session bus. */
- g_conn = _bt_get_session_gconn();
+ g_conn = _bt_gdbus_get_session_gconn();
retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
_bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, param);
session_info = __bt_find_session_by_path(agent_info.auth_info->transfer_path);
- if(NULL == session_info) {
+
+ if (NULL == session_info)
BT_ERR("Couldn't get the session info from the list");
- } else {
+ else
session_info->authorized = TRUE;
- }
}
int _bt_obex_server_reject_authorize(void)
BT_CHECK_PARAMETER(local_oob_data, return);
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_path = _bt_get_adapter_path();
return BLUETOOTH_ERROR_INTERNAL;
}
- g_variant_get(reply ,"(@ay@ay@ay@ay)", &hash192, &randomizer192,
+ g_variant_get(reply, "(@ay@ay@ay@ay)", &hash192, &randomizer192,
&hash256, &randomizer256);
g_variant_unref(reply);
BT_CHECK_PARAMETER(remote_device_address, return);
BT_CHECK_PARAMETER(remote_oob_data, return);
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_path = _bt_get_adapter_path();
BT_CHECK_PARAMETER(remote_device_address, return);
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
adapter_path = _bt_get_adapter_path();
}
/* Get the session bus. */
- g_conn = _bt_get_session_gconn();
+ g_conn = _bt_gdbus_get_session_gconn();
retv_if(g_conn == NULL, FALSE);
properties_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_OBEXD_DBUS_NAME,
GError *error = NULL;
int result = BLUETOOTH_ERROR_NONE;
GVariant *param = NULL;
- g_dbus_proxy_call_finish(proxy, res, &error);
+ GVariant *reply = NULL;
+
+ reply = g_dbus_proxy_call_finish(proxy, res, &error);
if (proxy)
g_object_unref(proxy);
+ if (reply)
+ g_variant_unref(reply);
if (error) {
BT_ERR("%s", error->message);
GDBusProxy *session_proxy;
GError *err = NULL;
- g_conn = _bt_get_session_gconn();
+ g_conn = _bt_gdbus_get_session_gconn();
retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
retv_if(sending_info->session_path == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
return;
if (file_offset < sending_info->file_count) {
/* Get the session bus. */
- g_conn = _bt_get_session_gconn();
+ g_conn = _bt_gdbus_get_session_gconn();
ret_if(g_conn == NULL);
client_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
/* For IOPT compliance, change "text/x-iMelody" to "audio/imelody"
* because few devices(multimedia players) reject the OPP put for text objects
* since they support only multimedia files exchange */
- if(!strcasecmp(mime_type, "text/x-iMelody")) {
+ if (!strcasecmp(mime_type, "text/x-iMelody")) {
strncpy(mime_type, "audio/imelody", BT_MIME_TYPE_MAX_LEN);
BT_DBG("over writing mime type to = %s", mime_type);
}
- if(!strcasecmp(mime_type, "text/vcard")) {
+ if (!strcasecmp(mime_type, "text/vcard")) {
strncpy(mime_type, "text/x-vcard", BT_MIME_TYPE_MAX_LEN);
BT_DBG("over writing mime type to = %s", mime_type);
}
return;
}
- }else{
+ } else {
file_offset = 0;
__bt_sending_release();
}
BT_CHECK_PARAMETER(file_name_array, return);
/* Get the session bus. */
- g_conn = _bt_get_session_gconn();
+ g_conn = _bt_gdbus_get_session_gconn();
retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
client_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
static char *g_pbap_session_path = NULL;
static char *g_pbap_server_address = NULL;
-static GDBusConnection *dbus_connection = NULL;
static GDBusProxy *g_pbap_proxy = NULL;
static struct {
BT_DBG("Session Path = %s\n", g_pbap_session_path);
result = BLUETOOTH_ERROR_NONE;
g_pbap_server_address = g_strdup(address_string);
+
+ g_variant_unref(value);
}
signal = g_variant_new("(is)", result, address_string);
int _bt_pbap_connect(const bluetooth_device_address_t *address)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
GError *error = NULL;
char address_string[18] = { 0, };
char *ptr = NULL;
_bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
BT_DBG("Address String: %s", address_string);
- dbus_connection = _bt_get_session_gconn();
- if (dbus_connection == NULL) {
- BT_ERR("Couldn't connect to system bus");
+ g_conn = _bt_gdbus_get_session_gconn();
+ if (g_conn == NULL) {
+ BT_ERR("Couldn't connect to session bus");
return EXIT_FAILURE;
}
-
- g_pbap_proxy = g_dbus_proxy_new_sync(dbus_connection,
+ g_pbap_proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
PBAP_OBEX_CLIENT_SERVICE, PBAP_OBEX_CLIENT_PATH,
PBAP_OBEX_CLIENT_INTERFACE, NULL, &error);
result = BLUETOOTH_ERROR_NONE;
selected_path.folder = -1;
selected_path.type = -1;
+
+ g_variant_unref(value);
}
/* If the result is success, the event reciever will send the disconnect event */
transfer_info->filename = (char *)filename;
transfer_info->operation = PULL_ALL;
transfers = g_slist_append(transfers, transfer_info);
+
+ g_variant_unref(value);
}
g_object_unref(proxy);
int source, int type)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
GDBusProxy *g_pbap_session_proxy = NULL;
char address_string[18] = { 0, };
char *source_string = NULL;
BT_DBG("Address[%s] Source[%s] Type[%s]",
address_string, source_string, type_string);
BT_DBG("Session Path = %s\n", g_pbap_session_path);
- g_pbap_session_proxy = g_dbus_proxy_new_sync(dbus_connection,
+
+ g_conn = _bt_gdbus_get_session_gconn();
+ if (g_conn == NULL) {
+ BT_ERR("Couldn't connect to session bus");
+ return 0;
+ }
+ g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
PBAP_SESSION_SERVICE, g_pbap_session_path,
PBAP_SESSION_INTERFACE, NULL, &err);
int source, int type, bt_pbap_pull_parameters_t *app_param)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
GDBusProxy *g_pbap_session_proxy = NULL;
char address_string[18] = { 0, };
char *source_string = NULL;
address_string, source_string, type_string);
BT_DBG("Session Path = %s\n", g_pbap_session_path);
- g_pbap_session_proxy = g_dbus_proxy_new_sync(dbus_connection,
+
+ g_conn = _bt_gdbus_get_session_gconn();
+ if (g_conn == NULL) {
+ BT_ERR("Couldn't connect to session bus");
+ return 0;
+ }
+ g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
PBAP_SESSION_SERVICE, g_pbap_session_path,
PBAP_SESSION_INTERFACE, NULL, &err);
int type, bt_pbap_list_parameters_t *app_param)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
GDBusProxy *g_pbap_session_proxy = NULL;
char address_string[18] = { 0, };
char *source_string = NULL;
address_string, source_string, type_string);
BT_DBG("Session Path = %s\n", g_pbap_session_path);
- g_pbap_session_proxy = g_dbus_proxy_new_sync(dbus_connection,
+
+ g_conn = _bt_gdbus_get_session_gconn();
+ if (g_conn == NULL) {
+ BT_ERR("Couldn't connect to session bus");
+ return 0;
+ }
+ g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
PBAP_SESSION_SERVICE, g_pbap_session_path,
PBAP_SESSION_INTERFACE, NULL, &err);
int source, int type, bt_pbap_pull_vcard_parameters_t *app_param)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
GDBusProxy *g_pbap_session_proxy = NULL;
char address_string[18] = { 0, };
char *source_string = NULL;
address_string, source_string, type_string);
BT_DBG("Session Path = %s\n", g_pbap_session_path);
- g_pbap_session_proxy = g_dbus_proxy_new_sync(dbus_connection,
+
+ g_conn = _bt_gdbus_get_session_gconn();
+ if (g_conn == NULL) {
+ BT_ERR("Couldn't connect to session bus");
+ return 0;
+ }
+ g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
PBAP_SESSION_SERVICE, g_pbap_session_path,
PBAP_SESSION_INTERFACE, NULL, &err);
int source, int type, bt_pbap_search_parameters_t *app_param)
{
BT_DBG("+");
+ GDBusConnection *g_conn;
GDBusProxy *g_pbap_session_proxy = NULL;
char address_string[18] = { 0, };
char *source_string = NULL;
BT_DBG("Session Path = %s\n", g_pbap_session_path);
- g_pbap_session_proxy = g_dbus_proxy_new_sync(dbus_connection,
+ g_conn = _bt_gdbus_get_session_gconn();
+ if (g_conn == NULL) {
+ BT_ERR("Couldn't connect to session bus");
+ return 0;
+ }
+ g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
PBAP_SESSION_SERVICE, g_pbap_session_path,
PBAP_SESSION_INTERFACE, NULL, &err);
int _bt_adapter_request_delayed(int function);
+int _bt_enable_adapter_check_status(void);
+
int _bt_enable_adapter(void);
+int _bt_disable_adapter_check_status(void);
+
+void _bt_keep_bt_status_vconf(void);
+
int _bt_disable_adapter(void);
int _bt_recover_adapter(void);
int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
bluetooth_device_info_t *dev_info);
+int _bt_is_alias_set(bluetooth_device_address_t *device_address, gboolean *is_alias_set);
+
int _bt_get_timeout_value(int *timeout);
gboolean _bt_is_discovering(void);
int disconnection_type;
char *address;
gboolean ag_flag;
- GArray *out_param1;
} bt_headset_wait_t;
typedef struct {
int req_id;
char *address;
bt_pending_request_t pending;
- GArray *out_param;
int type;
} bt_audio_function_data_t;
char *address;
} bt_function_data_t;
-GDBusConnection *_bt_get_system_conn(void);
+GDBusConnection *_bt_gdbus_get_system_gconn(void);
-GDBusConnection *_bt_get_system_gconn(void);
-
-GDBusConnection *_bt_get_session_gconn(void);
+GDBusConnection *_bt_gdbus_get_session_gconn(void);
void *_bt_get_net_conn(void);
gboolean _bt_is_bonding_device_address(const char *address);
+void _bt_pending_connect_le_device(void);
+
int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
gboolean auto_connect);
HTYPE_TRANS_SET_PROTOCOL,
HTYPE_TRANS_DATA,
HTYPE_TRANS_UNKNOWN
-}bt_hid_header_type_t;
+} bt_hid_header_type_t;
/**
* HID Param type
typedef enum {
PTYPE_DATA_RTYPE_INPUT,
PTYPE_DATA_RTYPE_OUTPUT
-}bt_hid_param_type_t;
+} bt_hid_param_type_t;
/**
* Stucture to hid receive data
int bluetooth_get_bonded_device(const bluetooth_device_address_t *device_address,
bluetooth_device_info_t *dev_info);
+
+/**
+ * @fn int bluetooth_get_is_alias_set(const bluetooth_device_address_t *device_address,
+ * gboolean *is_alias_set)
+ * @brief Get is_alias_set property of device
+ *
+ * This API gets is_alias_set property of a bonded device.
+ *
+ * This function is a synchronous call.
+ * Information for is_alias_set property can be obtained only when result code is BLUETOOTH_ERROR_NONE.
+ * If not,there is no valid information in the is_alias_set.
+ *
+ * @return BLUETOOTH_ERROR_NONE - Success \n
+ * BLUETOOTH_ERROR_NOT_SUPPORT - Opreation not supported \n
+ * @remark None
+ @code
+ int ret = 0;
+ gboolean alias_set;
+ bluetooth_device_address_t device_address = {{0x00,0x1C,0x43,0x2B,0x1A,0xE5}};
+
+ ret = bluetooth_get_is_alias_set(&device_address, &alias_set);
+ @endcode
+ */
+int bluetooth_get_is_alias_set(const bluetooth_device_address_t *device_address,
+ gboolean *is_alias_set);
+
/**
* @fn int bluetooth_set_alias(const bluetooth_device_address_t *device_address, const char *alias)
* @brief set alias for bonded device
BT_SEARCH_SERVICE,
BT_CANCEL_SEARCH_SERVICE,
BT_GET_BONDED_DEVICE,
+ BT_GET_IS_ALIAS_SET,
BT_SET_ALIAS,
BT_SET_AUTHORIZATION,
BT_UNSET_AUTHORIZATION,