_bt_rfcomm_server_free_all();
#endif
- _bluetooth_hid_free_hid_info();
+ _bt_hid_free_hid_info();
BT_DBG("-");
return FALSE;
address);
int ctrl = -1, intr = -1;
_bt_hid_device_get_fd(address, &ctrl, &intr);
- if (ctrl != -1 && intr != -1) {
- new_hid_connection(NULL, ctrl, &dev_address);
- new_hid_connection(NULL, intr, &dev_address);
- }
+ if (ctrl != -1 && intr != -1)
+ _bt_hid_new_connection(&dev_address, ctrl, intr);
+ else
+ BT_ERR("fd is invalid.(ctrl=%d, intr=%d)", ctrl, intr);
} else if (strcasecmp(signal_name, BT_INPUT_HID_DEVICE_DISCONNECTED) == 0) {
const char *address = NULL;
g_variant_get(parameters, "(i&s)", &result, &address);
if (strcasecmp(signal_name, "Connected") == 0) {
char *address = NULL;
- g_variant_get(parameters, "(s)", &address);
+ g_variant_get(parameters, "(&s)", &address);
_bt_hf_event_cb(BLUETOOTH_EVENT_HF_CONNECTED,
result, address,
event_info->cb, event_info->user_data);
} else if (strcasecmp(signal_name, "Disconnected") == 0) {
char *address = NULL;
- g_variant_get(parameters, "(s)", &address);
+ g_variant_get(parameters, "(&s)", &address);
_bt_hf_event_cb(BLUETOOTH_EVENT_HF_DISCONNECTED,
result, address,
event_info->cb, event_info->user_data);
}
}
+static void __bt_gatt_get_uuid_from_path(char *path, char **service_uuid)
+{
+ GDBusProxy *proxy = NULL;
+ GError *err = NULL;
+ GDBusConnection *g_conn;
+ GVariant *ret = NULL;
+ GVariant *value = NULL;
+
+ g_conn = _bt_gdbus_get_system_gconn();
+ ret_if(g_conn == NULL);
+
+ proxy = g_dbus_proxy_new_sync(g_conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME,
+ path,
+ BT_PROPERTIES_INTERFACE,
+ NULL, &err);
+
+ ret_if(proxy == NULL);
+
+ ret = g_dbus_proxy_call_sync(proxy, "Get",
+ g_variant_new("(ss)", GATT_SERV_INTERFACE, "UUID"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (err) {
+ BT_ERR("DBus Error : %s", err->message);
+ g_clear_error(&err);
+ } else {
+ g_variant_get(ret, "(v)", &value);
+ *service_uuid = g_variant_dup_string(value, NULL);
+ g_variant_unref(value);
+ g_variant_unref(ret);
+ }
+
+ if (proxy)
+ g_object_unref(proxy);
+
+ return;
+}
+
+
static void __bt_manager_event_filter(GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
BT_INFO("GATT Service [%s] added, but no watcher for %s",
path, secure_address);
return;
- } else
+ } else {
+ char *uuid = NULL;
+ char *name = NULL;
+ __bt_gatt_get_uuid_from_path(path, &uuid);
+ bluetooth_get_uuid_name(uuid, &name);
+
BT_INFO(" ### GATT Service added [%s] [%s]",
- path, secure_address);
+ path, name);
+ g_free(name);
+ g_free(uuid);
+ }
change.svc_path = g_strdup(path);
change.change_type = BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_ADD;
if (g_strcmp0(interface_str, GATT_SERV_INTERFACE) != 0)
continue;
- _bt_convert_addr_type_to_secure_string(secure_address,
- change.device_addr.addr);
- BT_INFO(" ### GATT Service removed [%s] [%s]",
- path, secure_address);
+ BT_INFO(" ### GATT Service removed [%s]", path);
change.svc_path = g_strdup(path);
change.change_type = BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_REMOVE;
static int privilege_token_send_key = 0;
static int privilege_token_reply = 0;
-static gboolean __hid_disconnect(hid_connected_device_info_t *info);
-
-int _bt_hid_device_get_fd(const char *address, int *ctrl, int *intr)
-{
-
- int ret = BLUETOOTH_ERROR_NONE;
- char *adapter_path;
- GVariant *result = NULL;
- GError *err = NULL;
- GDBusConnection *conn;
- GDBusProxy *server_proxy;
- int index1 = 0;
- int index2 = 0;
- GUnixFDList *out_fd_list = NULL;
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_device_object_path((char *)address);
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
- BT_INFO_C("Device : %s", adapter_path);
- server_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- adapter_path, "org.bluez.Input1", NULL, NULL);
- g_free(adapter_path);
-
- if (server_proxy == NULL) {
- BT_ERR("Failed to get the network server proxy\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_with_unix_fd_list_sync(server_proxy, "GetFD",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &out_fd_list,
- NULL,
- &err);
- if (result == NULL) {
- if (err != NULL) {
- g_dbus_error_strip_remote_error(err);
- BT_ERR("INPUT server register Error: %s\n", err->message);
- if (g_strcmp0(err->message, "Already Exists") == 0)
- ret = BLUETOOTH_ERROR_ALREADY_INITIALIZED;
- else
- ret = BLUETOOTH_ERROR_INTERNAL;
-
- g_error_free(err);
- }
- } else {
- 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);
-
- *ctrl = fd1;
- *intr = fd2;
- g_object_unref(out_fd_list);
- g_variant_unref(result);
- }
- g_object_unref(server_proxy);
- return ret;
-}
-
static GVariant* __bt_hid_agent_dbus_send(const char *path,
const char *interface, const char *method,
GError **err, GVariant *parameters)
static void __hid_connected_cb(hid_connected_device_info_t *info,
int result)
{
- bluetooth_hid_request_t conn_info;
+ bluetooth_device_address_t bd_addr;
bt_event_info_t *event_info = NULL;
event_info = _bt_event_get_cb_data(BT_HID_DEVICE_EVENT);
if (event_info == NULL)
return;
- memset(&conn_info, 0x00, sizeof(bluetooth_hid_request_t));
- if (info->intr_fd != -1 && info->ctrl_fd == -1)
- 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);
+ memset(&bd_addr, 0x00, sizeof(bluetooth_device_address_t));
+ _bt_convert_addr_string_to_type(bd_addr.addr, info->address);
if (result == BLUETOOTH_ERROR_NONE)
BT_INFO_C("Connected [HID Device]");
_bt_common_event_cb(BLUETOOTH_HID_DEVICE_CONNECTED,
- result, &conn_info,
+ result, &bd_addr,
event_info->cb, event_info->user_data);
}
g_dbus_error_strip_remote_error(error);
BT_ERR("Error : %s \n", error->message);
- if (g_strcmp0(error->message, "In Progress") == 0)
- result = BLUETOOTH_ERROR_DEVICE_BUSY;
- else
- result = BLUETOOTH_ERROR_INTERNAL;
-
info.ctrl_fd = -1;
info.intr_fd = -1;
path = g_dbus_proxy_get_object_path(proxy);
_bt_convert_device_path_to_address(path, info.address);
- __hid_connected_cb(&info, result);
+ if (g_strcmp0(error->message, "Already Connected") == 0) {
+ bluetooth_device_address_t dev_address = { {0} };
+ int ctrl = -1, intr = -1;
- g_free(info.address);
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ info.address);
+ _bt_hid_device_get_fd(info.address, &ctrl, &intr);
+ if (ctrl != -1 && intr != -1)
+ _bt_hid_new_connection(&dev_address, ctrl, intr);
+ else
+ BT_ERR("fd is invalid.(ctrl=%d, intr=%d)", ctrl, intr);
+ } else {
+ if (g_strcmp0(error->message, "In Progress") == 0)
+ result = BLUETOOTH_ERROR_IN_PROGRESS;
+ else
+ result = BLUETOOTH_ERROR_INTERNAL;
+ __hid_connected_cb(&info, result);
+ }
+
+ g_free(info.address);
g_error_free(error);
} else {
g_variant_unref(ret);
static gboolean __hid_disconnect(hid_connected_device_info_t *info)
{
- bluetooth_hid_request_t disconn_info;
- int fd = info->ctrl_fd;
+ bluetooth_device_address_t bd_addr;
bt_event_info_t *event_info;
BT_INFO_C("Disconnected [HID Device]");
}
info->disconnect_idle_id = 0;
event_info = _bt_event_get_cb_data(BT_HID_DEVICE_EVENT);
- if (event_info == NULL)
- return FALSE;
+ if (event_info != NULL) {
+ memset(&bd_addr, 0x00, sizeof(bluetooth_device_address_t));
+ _bt_convert_addr_string_to_type(bd_addr.addr , info->address);
+ _bt_common_event_cb(BLUETOOTH_HID_DEVICE_DISCONNECTED,
+ BLUETOOTH_ERROR_NONE, &bd_addr,
+ event_info->cb, event_info->user_data);
+ }
- memset(&disconn_info, 0x00, sizeof(bluetooth_hid_request_t));
- disconn_info.socket_fd = fd;
- _bt_convert_addr_string_to_type(disconn_info.device_addr.addr , info->address);
- _bt_common_event_cb(BLUETOOTH_HID_DEVICE_DISCONNECTED,
- BLUETOOTH_ERROR_NONE, &disconn_info,
- event_info->cb, event_info->user_data);
- if (info->address)
- g_free(info->address);
+ g_free(info->address);
g_free(info);
- info = NULL;
- BT_DBG("-");
+
return FALSE;
}
return TRUE;
}
-int new_hid_connection(const char *path, int fd, bluetooth_device_address_t *addr)
-{
- hid_connected_device_info_t *dev_info = NULL;
- char address[18];
-
- _bt_convert_addr_type_to_string((char *)address, addr->addr);
- BT_INFO("Address [%s]", address);
- dev_info = __find_hid_info_with_address(address);
- if (dev_info == NULL) {
- dev_info = (hid_connected_device_info_t *)
- g_malloc0(sizeof(hid_connected_device_info_t));
-
- dev_info->intr_fd = -1;
- dev_info->ctrl_fd = -1;
- dev_info->intr_fd = fd;
- dev_info->address = g_strdup(address);
- dev_info->intr_data_io = g_io_channel_unix_new(dev_info->intr_fd);
- g_io_channel_set_encoding(dev_info->intr_data_io, NULL, NULL);
- g_io_channel_set_flags(dev_info->intr_data_io, G_IO_FLAG_NONBLOCK, NULL);
- g_io_channel_set_close_on_unref(dev_info->intr_data_io, TRUE);
- dev_info->intr_data_id = g_io_add_watch(dev_info->intr_data_io,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- __received_cb, dev_info);
- device_list = g_slist_append(device_list, dev_info);
- } else {
- dev_info->ctrl_fd = fd;
- dev_info->ctrl_data_io = g_io_channel_unix_new(dev_info->ctrl_fd);
- g_io_channel_set_encoding(dev_info->ctrl_data_io, NULL, NULL);
- g_io_channel_set_flags(dev_info->ctrl_data_io, G_IO_FLAG_NONBLOCK, NULL);
- g_io_channel_set_close_on_unref(dev_info->ctrl_data_io, TRUE);
- dev_info->ctrl_data_id = g_io_add_watch(dev_info->ctrl_data_io,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- __received_cb, dev_info);
- }
-
- if (dev_info->ctrl_fd != -1 && dev_info->intr_fd != -1)
- __hid_connected_cb(dev_info, BLUETOOTH_ERROR_NONE);
-
- return 0;
-}
-
static void __free_hid_info(void *data)
{
BT_DBG("");
__hid_disconnect(dev_info);
}
-void _bluetooth_hid_free_hid_info(void)
+int _bt_hid_device_get_fd(const char *address, int *ctrl, int *intr)
+{
+
+ int ret = BLUETOOTH_ERROR_NONE;
+ char *adapter_path;
+ GVariant *result = NULL;
+ GError *err = NULL;
+ GDBusConnection *conn;
+ GDBusProxy *server_proxy;
+ int index1 = 0;
+ int index2 = 0;
+ GUnixFDList *out_fd_list = NULL;
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_path = _bt_get_device_object_path((char *)address);
+ retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+ BT_INFO_C("Device : %s", adapter_path);
+ server_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ adapter_path, "org.bluez.Input1", NULL, NULL);
+ g_free(adapter_path);
+
+ if (server_proxy == NULL) {
+ BT_ERR("Failed to get the network server proxy\n");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ result = g_dbus_proxy_call_with_unix_fd_list_sync(server_proxy, "GetFD",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &out_fd_list,
+ NULL,
+ &err);
+ if (result == NULL) {
+ if (err != NULL) {
+ g_dbus_error_strip_remote_error(err);
+ BT_ERR("INPUT server register Error: %s\n", err->message);
+ if (g_strcmp0(err->message, "Already Exists") == 0)
+ ret = BLUETOOTH_ERROR_ALREADY_INITIALIZED;
+ else
+ ret = BLUETOOTH_ERROR_INTERNAL;
+
+ g_error_free(err);
+ }
+ } else {
+ 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);
+
+ *ctrl = fd1;
+ *intr = fd2;
+ g_object_unref(out_fd_list);
+ g_variant_unref(result);
+ }
+ g_object_unref(server_proxy);
+ return ret;
+}
+
+int _bt_hid_new_connection(bluetooth_device_address_t *addr,
+ int ctrl_fd, int intr_fd)
+{
+ hid_connected_device_info_t *dev_info = NULL;
+ char address[18];
+ char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ _bt_convert_addr_type_to_string((char *)address, addr->addr);
+ _bt_convert_addr_string_to_secure_string(secure_addr, address);
+ BT_INFO("Address [%s]", secure_addr);
+ dev_info = __find_hid_info_with_address(address);
+ if (dev_info != NULL)
+ __free_hid_info(dev_info);
+
+ dev_info = (hid_connected_device_info_t *)
+ g_malloc0(sizeof(hid_connected_device_info_t));
+
+ dev_info->ctrl_fd = ctrl_fd;
+ dev_info->intr_fd = intr_fd;
+ dev_info->address = g_strdup(address);
+ dev_info->ctrl_data_io = g_io_channel_unix_new(dev_info->ctrl_fd);
+ dev_info->intr_data_io = g_io_channel_unix_new(dev_info->intr_fd);
+ g_io_channel_set_encoding(dev_info->ctrl_data_io, NULL, NULL);
+ g_io_channel_set_flags(dev_info->ctrl_data_io, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_channel_set_close_on_unref(dev_info->ctrl_data_io, TRUE);
+ g_io_channel_set_encoding(dev_info->intr_data_io, NULL, NULL);
+ g_io_channel_set_flags(dev_info->intr_data_io, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_channel_set_close_on_unref(dev_info->intr_data_io, TRUE);
+ dev_info->ctrl_data_id = g_io_add_watch(dev_info->ctrl_data_io,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ __received_cb, dev_info);
+ dev_info->intr_data_id = g_io_add_watch(dev_info->intr_data_io,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ __received_cb, dev_info);
+ device_list = g_slist_append(device_list, dev_info);
+
+ __hid_connected_cb(dev_info, BLUETOOTH_ERROR_NONE);
+
+ return 0;
+}
+
+void _bt_hid_free_hid_info(void)
{
g_slist_free_full(device_list, __free_hid_info);
g_variant_unref(reply);
- _bluetooth_hid_free_hid_info();
+ _bt_hid_free_hid_info();
return BLUETOOTH_ERROR_NONE;
}
BT_ERR("Connection Information not found");
return BLUETOOTH_ERROR_INVALID_PARAM;
}
- int socket_fd;
-
- if (info->intr_fd != -1 && info->ctrl_fd == -1)
- socket_fd = info->intr_fd;
- else
- socket_fd = info->ctrl_fd;
- written = write(socket_fd, &send_event, sizeof(send_event));
+ if (info->intr_fd >= 0) {
+ written = write(info->intr_fd, &send_event, sizeof(send_event));
+ } else {
+ BT_ERR("intr_fd(%d) is invalid.", info->intr_fd);
+ __free_hid_info(info);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
return written;
}
return BLUETOOTH_ERROR_INVALID_PARAM;
}
- int socket_fd;
-
- if (info->intr_fd != -1 && info->ctrl_fd == -1)
- socket_fd = info->intr_fd;
- else
- socket_fd = info->ctrl_fd;
+ if (info->intr_fd >= 0) {
+ written = write(info->intr_fd, &send_event, sizeof(send_event));
+ } else {
+ BT_ERR("intr_fd(%d) is invalid.", info->intr_fd);
+ __free_hid_info(info);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
- written = write(socket_fd, &send_event, sizeof(send_event));
return written;
}
{
int result;
int written = 0;
- int socket_fd;
hid_connected_device_info_t *info = NULL;
char *send_event = NULL;
return BLUETOOTH_ERROR_INVALID_PARAM;
}
- if (info->intr_fd != -1 && info->ctrl_fd == -1)
- socket_fd = info->intr_fd;
- else
- socket_fd = info->ctrl_fd;
-
- send_event = g_malloc0(data_len + 2);
-
- send_event[0] = (char)btcode;
- send_event[1] = (char)report_id;
- memcpy(send_event + 2, data, data_len);
+ if (info->intr_fd >= 0) {
+ send_event = g_malloc0(data_len + 2);
- written = write(socket_fd, send_event, data_len + 2);
+ send_event[0] = (char)btcode;
+ send_event[1] = (char)report_id;
+ memcpy(send_event + 2, data, data_len);
- g_free(send_event);
+ written = write(info->intr_fd, send_event, data_len + 2);
+ g_free(send_event);
+ } else {
+ BT_ERR("intr_fd(%d) is invalid.", info->intr_fd);
+ __free_hid_info(info);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
return written;
}
{
int result;
struct reports output_report = { 0 };
- int bytes = BLUETOOTH_ERROR_INTERNAL;
+ int bytes = -1;
hid_connected_device_info_t *info = NULL;
+
+ BT_CHECK_PARAMETER(remote_addr, return);
+
info = __find_hid_info_with_address(remote_addr);
if (info == NULL) {
BT_ERR("Connection Information not found");
return BLUETOOTH_ERROR_INVALID_PARAM;
}
- BT_CHECK_PARAMETER(remote_addr, return);
+ if (info->ctrl_fd < 0) {
+ BT_ERR("ctrl_fd(%d) is invalid.", info->ctrl_fd);
+ __free_hid_info(info);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
switch (privilege_token_reply) {
case 0:
output_report.type = BT_HID_TRANS_DATA |
BT_HID_DATA_RTYPE_INPUT;
memcpy(output_report.rep_data, data, data_len);
- bytes = write(info->intr_fd, &output_report,
+ bytes = write(info->ctrl_fd, &output_report,
sizeof(output_report));
BT_DBG("Bytes Written %d", bytes);
break;
break;
case HTYPE_TRANS_GET_PROTOCOL: {
- BT_DBG("Replying to Get_PROTOCOL");
output_report.type = BT_HID_TRANS_DATA | BT_HID_DATA_RTYPE_OUTPUT;
output_report.rep_data[0] = data[0];
- bytes = write(info->intr_fd, &output_report, 2);
- BT_DBG("Bytes Written %d", bytes);
+ bytes = write(info->ctrl_fd, &output_report, 2);
break;
}
case HTYPE_TRANS_SET_PROTOCOL: {
- BT_DBG("Reply to Set_Protocol");
output_report.type = BT_HID_TRANS_DATA | BT_HID_DATA_RTYPE_INPUT;
memcpy(output_report.rep_data, data, data_len);
bytes = write(info->ctrl_fd, &output_report,
sizeof(output_report));
- BT_DBG("Bytes Written %d", bytes);
break;
}
case HTYPE_TRANS_HANDSHAKE: {
- BT_DBG("Replying Handshake");
output_report.type = BT_HID_TRANS_HANDSHAKE | data[0];
memset(output_report.rep_data, 0, sizeof(output_report.rep_data));
- bytes = write(info->intr_fd, &output_report.type,
+ bytes = write(info->ctrl_fd, &output_report.type,
sizeof(output_report.type));
- BT_DBG("Bytes Written %d", bytes);
break;
}
case HTYPE_TRANS_GET_IDLE: {
- BT_DBG("Replying to Get_IDLE");
output_report.type = BT_HID_TRANS_DATA | BT_HID_DATA_RTYPE_OUTPUT;
output_report.rep_data[0] = data[0];
- bytes = write(info->intr_fd, &output_report, 2);
- BT_DBG("Bytes Written %d", bytes);
+ bytes = write(info->ctrl_fd, &output_report, 2);
break;
}
case HTYPE_TRANS_SET_IDLE: {
- BT_DBG("Reply to Set_IDLE");
output_report.type = BT_HID_TRANS_DATA | BT_HID_DATA_RTYPE_INPUT;
memcpy(output_report.rep_data, data, data_len);
bytes = write(info->ctrl_fd, &output_report,
sizeof(output_report));
- BT_DBG("Bytes Written %d", bytes);
break;
}
break;
}
}
+
+ BT_DBG("Bytes Written %d", bytes);
+
return bytes;
}