#include "bt-event-handler.h"
#include "bluetooth-media-control.h"
-/* auto generated header by bt-request-service.xml*/
-#include "bt-request-service.h"
+#ifdef TIZEN_GATT_CLIENT
+#include "bluetooth-gatt-client-api.h"
+#endif
static GSList *sending_requests;
GDBusProxy *proxy;
GError *err = NULL;
-// service_gconn = _bt_gdbus_get_system_gconn();
- service_gconn = _bt_gdbus_get_session_gconn();
+ service_gconn = _bt_get_system_private_conn();
if (!service_gconn)
return NULL;
proxy = g_dbus_proxy_new_sync(service_gconn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_DBUS_NAME,
BT_SERVICE_PATH,
BT_DBUS_NAME,
{
ret_if(event == NULL);
- BT_DBG("service_function : %x", service_function);
+ BT_DBG("service_function : %s (0x%x)",
+ _bt_convert_service_function_to_string(service_function),
+ service_function);
switch (service_function) {
case BT_BOND_DEVICE:
case BT_BOND_DEVICE_BY_TYPE:
*event = BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED;
ret_if(output == NULL);
*param_data = &g_array_index(output,
- bluetooth_device_info_t, 0);
+ bluetooth_device_address_t, 0);
break;
case BT_SEARCH_SERVICE:
*event_type = BT_ADAPTER_EVENT;
*event = BLUETOOTH_EVENT_SERVICE_SEARCHED;
ret_if(output == NULL);
*param_data = &g_array_index(output,
- bluetooth_device_info_t, 0);
+ bt_sdp_info_t, 0);
break;
case BT_HID_CONNECT:
*event_type = BT_HID_EVENT;
*param_data = &g_array_index(output,
bluetooth_rfcomm_connection_t, 0);
break;
+ case BT_AVRCP_TARGET_CONNECT:
+ *event_type = BT_AVRCP_EVENT;
+ *event = BLUETOOTH_EVENT_AVRCP_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_AVRCP_TARGET_DISCONNECT:
+ *event_type = BT_AVRCP_EVENT;
+ *event = BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
case BT_AVRCP_CONTROL_CONNECT:
*event_type = BT_AVRCP_CONTROL_EVENT;
*event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
ret_if(output == NULL);
*param_data = &g_array_index(output, char, 0);
break;
+ case BT_REQ_ATT_MTU:
+ *event_type = BT_DEVICE_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+#ifdef TIZEN_GATT_CLIENT
+ case BT_CONNECT_LE:
+ *event_type = BT_DEVICE_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_DISCONNECT_LE:
+ *event_type = BT_DEVICE_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+#else
case BT_CONNECT_LE:
*event_type = BT_DEVICE_EVENT;
*event = BLUETOOTH_EVENT_GATT_CONNECTED;
*param_data = &g_array_index(output,
bluetooth_device_address_t, 0);
break;
+#endif
+#ifdef TIZEN_GATT_CLIENT
+ case BT_GATT_READ_CHARACTERISTIC:
+ BT_INFO("BT_GATT_READ_CHARACTERISTIC");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_READ_CHAR;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_char_prop_info_t, 0);
+ break;
+ case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE:
+ BT_INFO("BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_WRITE_CHAR;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_char_prop_info_t, 0);
+ break;
+ case BT_GATT_READ_DESCRIPTOR_VALUE:
+ BT_INFO("BT_GATT_READ_DESCRIPTOR_VALUE");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_READ_DESC;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_desc_prop_info_t, 0);
+ break;
+ case BT_GATT_WRITE_DESCRIPTOR_VALUE:
+ BT_INFO("BT_GATT_WRITE_DESCRIPTOR_VALUE");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_WRITE_DESC;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_desc_prop_info_t, 0);
+ break;
+#endif
+ case BT_TDS_READ_TRANSPORT_DATA:
+ *event_type = BT_TDS_EVENT;
+ *event = BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_TDS_ENABLE_CONTROL_POINT:
+ *event_type = BT_TDS_EVENT;
+ *event = BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_TDS_ACTIVATE_CONTROL_POINT:
+ *event_type = BT_TDS_EVENT;
+ *event = BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_HDP_CONNECT:
+ *event_type = BT_HDP_EVENT;
+ *event = BLUETOOTH_EVENT_HDP_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bt_hdp_connected_t, 0);
+ break;
+ case BT_HDP_DISCONNECT:
+ *event_type = BT_HDP_EVENT;
+ *event = BLUETOOTH_EVENT_HDP_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bt_hdp_disconnected_t, 0);
+ break;
default:
BT_ERR("Unknown function");
return;
}
static void __send_request_cb(GDBusProxy *proxy,
- GAsyncResult *res,
- gpointer user_data)
+ GAsyncResult *res,
+ gpointer user_data)
{
bluetooth_event_param_t bt_event;
bt_req_info_t *cb_data = user_data;
&bt_event.event, &event_type,
&bt_event.param_data);
+ BT_DBG("service_function [%d]", cb_data->service_function);
if (result == BLUETOOTH_ERROR_NONE && out_param1) {
if (cb_data->service_function == BT_OPP_PUSH_FILES) {
request_id = g_array_index(out_param1, int, 0);
BT_DBG("request_id : %d", request_id);
_bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_LIST_FOLDERS) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_LIST_FILTER_FIELDS) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_LIST_MESSAGES) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_GET_MESSAGE) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_PUSH_MESSAGE) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
}
goto done;
}
-
}
if (cb_data->cb == NULL)
/* Only if fail case, call the callback function*/
bt_event.result = result;
- BT_INFO("event_type[%d], result=[%d]", event_type, result);
+ BT_INFO("event_type[%d], result= %s [0x%x]", event_type,
+ _bt_convert_error_to_string(result), result);
if (event_type == BT_ADAPTER_EVENT || event_type == BT_RFCOMM_CLIENT_EVENT) {
((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
&bt_event,
cb_data->user_data);
+ } else if (event_type == BT_TDS_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event,
+ cb_data->user_data);
+ } else if (event_type == BT_HDP_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event, cb_data->user_data);
+ } else if (event_type == BT_AVRCP_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event, cb_data->user_data);
+#ifdef TIZEN_GATT_CLIENT
+ } else if (event_type == BT_GATT_CLIENT_EVENT) {
+ ((gatt_client_cb_func_ptr)cb_data->cb)(bt_event.event,
+ (gatt_client_event_param_t*)&bt_event, cb_data->user_data);
+#endif
} else {
BT_INFO("Not handled event type : %d", event_type);
}
in_param4->data, in_param4->len,
TRUE, NULL, NULL);
param5 = g_variant_new_from_data((const GVariantType *)"ay",
- in_param5->data, in_param5->len,
+ in_param5->data, in_param5->len,
TRUE, NULL, NULL);
ret = g_dbus_proxy_call_sync(proxy, "service_request",
GVariant *param4;
GVariant *param5;
- BT_DBG("service_function : %x", service_function);
+ BT_DBG("service_function : %s (0x%x)",
+ _bt_convert_service_function_to_string(service_function),
+ service_function);
cb_data = g_new0(bt_req_info_t, 1);
return BLUETOOTH_ERROR_NONE;
}
+int _bt_async_send_request_with_unix_fd_list(int service_type, int service_function,
+ GArray *in_param1, GArray *in_param2,
+ GArray *in_param3, GArray *in_param4,
+ void *callback, void *user_data,
+ GUnixFDList *fd_list, GAsyncReadyCallback __async_req_cb)
+{
+ GArray* in_param5 = NULL;
+ bt_req_info_t *cb_data;
+
+ GDBusProxy *proxy;
+ int timeout;
+ GVariant *param1;
+ GVariant *param2;
+ GVariant *param3;
+ GVariant *param4;
+ GVariant *param5;
+
+ BT_DBG("service_function : %d", service_function);
+
+ cb_data = g_new0(bt_req_info_t, 1);
+ cb_data->service_function = service_function;
+ cb_data->cb = callback;
+ cb_data->user_data = user_data;
+
+ switch (service_type) {
+ case BT_BLUEZ_SERVICE:
+ case BT_OBEX_SERVICE:
+ proxy = __bt_gdbus_get_service_proxy();
+ if (!proxy) {
+ g_free(cb_data);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ /* Do not timeout the request in certain cases. Sometime the
+ * request may take undeterministic time to reponse.
+ * (for ex: pairing retry) */
+ if (service_function == BT_BOND_DEVICE ||
+ service_function == BT_BOND_DEVICE_BY_TYPE)
+ timeout = INT_MAX;
+ else
+ timeout = BT_DBUS_TIMEOUT_MAX;
+
+ in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+ param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+ param2 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+ param3 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param3->data, in_param3->len,
+ TRUE, NULL, NULL);
+ param4 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param4->data, in_param4->len,
+ TRUE, NULL, NULL);
+ param5 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param5->data, in_param5->len,
+ TRUE, NULL, NULL);
+
+ g_dbus_proxy_call_with_unix_fd_list(proxy, "service_request",
+ g_variant_new("(iii@ay@ay@ay@ay@ay)",
+ service_type, service_function,
+ BT_ASYNC_REQ, param1, param2,
+ param3, param4, param5),
+ G_DBUS_CALL_FLAGS_NONE,
+ timeout, fd_list, NULL,
+ __async_req_cb, (gpointer)cb_data);
+ sending_requests = g_slist_append(sending_requests, cb_data);
+
+ g_array_free(in_param5, TRUE);
+ break;
+ default:
+ g_free(cb_data);
+ break;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_sync_send_request_with_unix_fd_list(
+ int service_type, int service_function,
+ GArray *in_param1, GArray *in_param2,
+ GArray *in_param3, GArray *in_param4,
+ GUnixFDList *fd_list, GArray **out_param1,
+ GUnixFDList **out_fd_list)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ GError *error = NULL;
+ GArray *in_param5 = NULL;
+
+ GDBusProxy *proxy;
+ GVariant *ret;
+ GVariant *param1;
+ GVariant *param2;
+ GVariant *param3;
+ GVariant *param4;
+ GVariant *param5;
+
+ switch (service_type) {
+ case BT_BLUEZ_SERVICE:
+ case BT_OBEX_SERVICE:
+ case BT_AGENT_SERVICE:
+ case BT_CHECK_PRIVILEGE:
+ proxy = __bt_gdbus_get_service_proxy();
+ if (!proxy)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+ param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+ param2 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+ param3 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param3->data, in_param3->len,
+ TRUE, NULL, NULL);
+ param4 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param4->data, in_param4->len,
+ TRUE, NULL, NULL);
+ param5 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param5->data, in_param5->len,
+ TRUE, NULL, NULL);
+
+ ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, "service_request",
+ g_variant_new("(iii@ay@ay@ay@ay@ay)",
+ service_type, service_function,
+ BT_SYNC_REQ, param1, param2,
+ param3, param4, param5),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ fd_list, out_fd_list, NULL, &error);
+ g_array_free(in_param5, TRUE);
+
+ if (ret == NULL) {
+ /* dBUS-RPC is failed */
+ BT_ERR("dBUS-RPC is failed");
+
+ if (error != NULL) {
+ /* dBUS gives error cause */
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ error->code, error->message);
+
+ g_clear_error(&error);
+ } else {
+ /* dBUS does not give error cause dBUS-RPC is failed */
+ BT_ERR("error returned was NULL");
+ }
+
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ param1 = NULL;
+ g_variant_get(ret, "(iv)", &result, ¶m1);
+
+ if (param1) {
+ *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+ __bt_fill_garray_from_variant(param1, *out_param1);
+ g_variant_unref(param1);
+ }
+
+ g_variant_unref(ret);
+ break;
+ default:
+ BT_ERR("Unknown service type");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return result;
+}