2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include "bluetooth-api.h"
23 #include "bluetooth-hid-api.h"
24 #include "bluetooth-audio-api.h"
25 #include "bt-internal-types.h"
26 #include "bluetooth-ipsp-api.h"
28 #include "bt-common.h"
29 #include "bt-request-sender.h"
30 #include "bt-event-handler.h"
31 #include "bluetooth-media-control.h"
33 #ifdef TIZEN_GATT_CLIENT
34 #include "bluetooth-gatt-client-api.h"
37 #include "bluetooth-mesh-api.h"
39 static GSList *sending_requests;
41 static GDBusProxy *service_gproxy;
43 static GDBusProxy *__bt_gdbus_init_service_proxy(void)
45 GDBusConnection *service_gconn;
49 service_gconn = _bt_get_system_private_conn();
54 proxy = g_dbus_proxy_new_sync(service_gconn,
55 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
62 BT_ERR("Unable to create proxy: %s", err->message);
69 service_gproxy = proxy;
74 static GDBusProxy *__bt_gdbus_get_service_proxy(void)
76 return (service_gproxy) ? service_gproxy : __bt_gdbus_init_service_proxy();
79 void _bt_gdbus_deinit_proxys(void)
82 g_object_unref(service_gproxy);
83 service_gproxy = NULL;
87 static void __bt_get_event_info(int service_function, GArray *output,
88 int *event, int *event_type, void **param_data)
90 ret_if(event == NULL);
92 BT_DBG("service_function : %s (0x%x)",
93 _bt_convert_service_function_to_string(service_function),
95 switch (service_function) {
97 case BT_BOND_DEVICE_BY_TYPE:
98 *event_type = BT_ADAPTER_EVENT;
99 *event = BLUETOOTH_EVENT_BONDING_FINISHED;
100 ret_if(output == NULL);
101 *param_data = &g_array_index(output,
102 bluetooth_device_info_t, 0);
104 case BT_UNBOND_DEVICE:
105 *event_type = BT_ADAPTER_EVENT;
106 *event = BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED;
107 ret_if(output == NULL);
108 *param_data = &g_array_index(output,
109 bluetooth_device_address_t, 0);
111 case BT_SEARCH_SERVICE:
112 *event_type = BT_ADAPTER_EVENT;
113 *event = BLUETOOTH_EVENT_SERVICE_SEARCHED;
114 ret_if(output == NULL);
115 *param_data = &g_array_index(output,
119 *event_type = BT_HID_EVENT;
120 *event = BLUETOOTH_HID_CONNECTED;
121 ret_if(output == NULL);
122 *param_data = &g_array_index(output,
123 bluetooth_device_address_t, 0);
125 case BT_HID_DISCONNECT:
126 *event_type = BT_HID_EVENT;
127 *event = BLUETOOTH_HID_DISCONNECTED;
128 ret_if(output == NULL);
129 *param_data = &g_array_index(output,
130 bluetooth_device_address_t, 0);
132 case BT_AUDIO_CONNECT:
134 *event_type = BT_HEADSET_EVENT;
135 *event = BLUETOOTH_EVENT_AG_CONNECTED;
136 ret_if(output == NULL);
137 *param_data = &g_array_index(output, char, 0);
139 case BT_AUDIO_DISCONNECT:
140 case BT_AG_DISCONNECT:
141 *event_type = BT_HEADSET_EVENT;
142 *event = BLUETOOTH_EVENT_AG_DISCONNECTED;
143 ret_if(output == NULL);
144 *param_data = &g_array_index(output, char, 0);
147 *event_type = BT_HEADSET_EVENT;
148 *event = BLUETOOTH_EVENT_AV_CONNECTED;
149 ret_if(output == NULL);
150 *param_data = &g_array_index(output, char, 0);
152 case BT_AV_DISCONNECT:
153 *event_type = BT_HEADSET_EVENT;
154 *event = BLUETOOTH_EVENT_AV_DISCONNECTED;
155 ret_if(output == NULL);
156 *param_data = &g_array_index(output, char, 0);
158 case BT_AV_SOURCE_CONNECT:
159 *event_type = BT_A2DP_SOURCE_EVENT;
160 *event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
161 ret_if(output == NULL);
162 *param_data = &g_array_index(output, char, 0);
164 case BT_AV_SOURCE_DISCONNECT:
165 *event_type = BT_A2DP_SOURCE_EVENT;
166 *event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
167 ret_if(output == NULL);
168 *param_data = &g_array_index(output, char, 0);
171 *event_type = BT_HF_AGENT_EVENT;
172 *event = BLUETOOTH_EVENT_HF_CONNECTED;
173 ret_if(output == NULL);
174 *param_data = &g_array_index(output, char, 0);
176 case BT_HF_DISCONNECT:
177 *event_type = BT_HF_AGENT_EVENT;
178 *event = BLUETOOTH_EVENT_HF_DISCONNECTED;
179 ret_if(output == NULL);
180 *param_data = &g_array_index(output, char, 0);
182 case BT_NETWORK_CONNECT:
183 *event_type = BT_ADAPTER_EVENT;
184 *event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
185 ret_if(output == NULL);
186 *param_data = &g_array_index(output,
187 bluetooth_device_address_t, 0);
189 case BT_NETWORK_DISCONNECT:
190 *event_type = BT_ADAPTER_EVENT;
191 *event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
192 ret_if(output == NULL);
193 *param_data = &g_array_index(output,
194 bluetooth_device_address_t, 0);
196 case BT_RFCOMM_CLIENT_CONNECT:
197 *event_type = BT_RFCOMM_CLIENT_EVENT;
198 *event = BLUETOOTH_EVENT_RFCOMM_CONNECTED;
199 ret_if(output == NULL);
200 *param_data = &g_array_index(output,
201 bluetooth_rfcomm_connection_t, 0);
203 case BT_AVRCP_TARGET_CONNECT:
204 *event_type = BT_AVRCP_EVENT;
205 *event = BLUETOOTH_EVENT_AVRCP_CONNECTED;
206 ret_if(output == NULL);
207 *param_data = &g_array_index(output, char, 0);
209 case BT_AVRCP_TARGET_DISCONNECT:
210 *event_type = BT_AVRCP_EVENT;
211 *event = BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
212 ret_if(output == NULL);
213 *param_data = &g_array_index(output, char, 0);
215 case BT_AVRCP_CONTROL_CONNECT:
216 *event_type = BT_AVRCP_CONTROL_EVENT;
217 *event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
218 ret_if(output == NULL);
219 *param_data = &g_array_index(output, char, 0);
221 case BT_AVRCP_CONTROL_DISCONNECT:
222 *event_type = BT_AVRCP_CONTROL_EVENT;
223 *event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
224 ret_if(output == NULL);
225 *param_data = &g_array_index(output, char, 0);
228 *event_type = BT_DEVICE_EVENT;
229 *event = BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED;
230 ret_if(output == NULL);
231 *param_data = &g_array_index(output,
232 bluetooth_device_address_t, 0);
234 #ifdef TIZEN_GATT_CLIENT
236 *event_type = BT_DEVICE_EVENT;
237 *event = BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED;
238 ret_if(output == NULL);
239 *param_data = &g_array_index(output,
240 bluetooth_device_address_t, 0);
242 case BT_DISCONNECT_LE:
243 *event_type = BT_DEVICE_EVENT;
244 *event = BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED;
245 ret_if(output == NULL);
246 *param_data = &g_array_index(output,
247 bluetooth_device_address_t, 0);
251 *event_type = BT_DEVICE_EVENT;
252 *event = BLUETOOTH_EVENT_GATT_CONNECTED;
253 ret_if(output == NULL);
254 *param_data = &g_array_index(output,
255 bluetooth_device_address_t, 0);
257 case BT_DISCONNECT_LE:
258 *event_type = BT_DEVICE_EVENT;
259 *event = BLUETOOTH_EVENT_GATT_DISCONNECTED;
260 ret_if(output == NULL);
261 *param_data = &g_array_index(output,
262 bluetooth_device_address_t, 0);
265 #ifdef TIZEN_GATT_CLIENT
266 case BT_GATT_READ_CHARACTERISTIC:
267 BT_INFO("BT_GATT_READ_CHARACTERISTIC");
268 *event_type = BT_GATT_CLIENT_EVENT;
269 *event = BLUETOOTH_EVENT_GATT_READ_CHAR;
270 ret_if(output == NULL);
271 *param_data = &g_array_index(output,
272 bluetooth_gatt_client_char_prop_info_t, 0);
274 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE:
275 BT_INFO("BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE");
276 *event_type = BT_GATT_CLIENT_EVENT;
277 *event = BLUETOOTH_EVENT_GATT_WRITE_CHAR;
278 ret_if(output == NULL);
279 *param_data = &g_array_index(output,
280 bluetooth_gatt_client_char_prop_info_t, 0);
282 case BT_GATT_READ_DESCRIPTOR_VALUE:
283 BT_INFO("BT_GATT_READ_DESCRIPTOR_VALUE");
284 *event_type = BT_GATT_CLIENT_EVENT;
285 *event = BLUETOOTH_EVENT_GATT_READ_DESC;
286 ret_if(output == NULL);
287 *param_data = &g_array_index(output,
288 bluetooth_gatt_client_desc_prop_info_t, 0);
290 case BT_GATT_WRITE_DESCRIPTOR_VALUE:
291 BT_INFO("BT_GATT_WRITE_DESCRIPTOR_VALUE");
292 *event_type = BT_GATT_CLIENT_EVENT;
293 *event = BLUETOOTH_EVENT_GATT_WRITE_DESC;
294 ret_if(output == NULL);
295 *param_data = &g_array_index(output,
296 bluetooth_gatt_client_desc_prop_info_t, 0);
299 case BT_TDS_READ_TRANSPORT_DATA:
300 *event_type = BT_TDS_EVENT;
301 *event = BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED;
302 ret_if(output == NULL);
303 *param_data = &g_array_index(output,
304 bluetooth_device_address_t, 0);
306 case BT_TDS_ENABLE_CONTROL_POINT:
307 *event_type = BT_TDS_EVENT;
308 *event = BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED;
309 ret_if(output == NULL);
310 *param_data = &g_array_index(output,
311 bluetooth_device_address_t, 0);
313 case BT_TDS_ACTIVATE_CONTROL_POINT:
314 *event_type = BT_TDS_EVENT;
315 *event = BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT;
316 ret_if(output == NULL);
317 *param_data = &g_array_index(output,
318 bluetooth_device_address_t, 0);
321 *event_type = BT_HDP_EVENT;
322 *event = BLUETOOTH_EVENT_HDP_CONNECTED;
323 ret_if(output == NULL);
324 *param_data = &g_array_index(output,
325 bt_hdp_connected_t, 0);
327 case BT_HDP_DISCONNECT:
328 *event_type = BT_HDP_EVENT;
329 *event = BLUETOOTH_EVENT_HDP_DISCONNECTED;
330 ret_if(output == NULL);
331 *param_data = &g_array_index(output,
332 bt_hdp_disconnected_t, 0);
334 case BT_MESH_NETWORK_PROVISION_DEVICE:
335 *event_type = BT_MESH_EVENT;
336 *event = BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED;
337 ret_if(output == NULL);
338 *param_data = &g_array_index(output,
339 bluetooth_mesh_provisioning_request_t, 0);
341 case BT_MESH_NODE_BROWSE:
342 *event_type = BT_MESH_EVENT;
343 *event = BLUETOOTH_EVENT_MESH_NODE_BROWSED;
344 ret_if(output == NULL);
345 *param_data = &g_array_index(output,
346 bluetooth_mesh_node_discover_t, 0);
348 case BT_MESH_NODE_GET_VENDOR_FEATURES:
349 *event_type = BT_MESH_EVENT;
350 *event = BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES;
351 ret_if(output == NULL);
352 *param_data = &g_array_index(output,
353 bluetooth_mesh_node_features_t, 0);
355 case BT_MESH_NODE_CONFIGURE_KEY:
356 *event_type = BT_MESH_EVENT;
357 *event = BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED;
358 ret_if(output == NULL);
359 *param_data = &g_array_index(output,
360 bluetooth_mesh_key_configure_t, 0);
362 case BT_MESH_NODE_TTL_EXECUTE:
363 *event_type = BT_MESH_EVENT;
364 *event = BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED;
365 ret_if(output == NULL);
366 *param_data = &g_array_index(output,
367 bluetooth_mesh_node_ttl_info_t, 0);
369 case BT_MESH_MODEL_CONFIGURE_APPKEY:
370 *event_type = BT_MESH_EVENT;
371 *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND;
372 ret_if(output == NULL);
373 *param_data = &g_array_index(output,
374 bluetooth_mesh_model_configure_t, 0);
376 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
377 *event_type = BT_MESH_EVENT;
378 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED;
379 ret_if(output == NULL);
380 *param_data = &g_array_index(output,
381 bluetooth_mesh_model_configure_t, 0);
383 case BT_MESH_MODEL_GET_APPKEY_LIST:
384 *event_type = BT_MESH_EVENT;
385 *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST;
386 ret_if(output == NULL);
387 *param_data = &g_array_index(output,
388 bluetooth_mesh_model_configure_t, 0);
390 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
391 *event_type = BT_MESH_EVENT;
392 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST;
393 ret_if(output == NULL);
394 *param_data = &g_array_index(output,
395 bluetooth_mesh_model_configure_t, 0);
397 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
398 *event_type = BT_MESH_EVENT;
399 *event = BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED;
400 ret_if(output == NULL);
401 *param_data = &g_array_index(output,
402 bluetooth_mesh_model_configure_t, 0);
404 case BT_MESH_MODEL_SET_PUBLICATION:
405 *event_type = BT_MESH_EVENT;
406 *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
407 ret_if(output == NULL);
408 *param_data = &g_array_index(output,
409 bluetooth_mesh_model_configure_t, 0);
411 case BT_MESH_MODEL_GET_PUBLICATION:
412 *event_type = BT_MESH_EVENT;
413 *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
414 ret_if(output == NULL);
415 *param_data = &g_array_index(output,
416 bluetooth_mesh_model_configure_t, 0);
419 BT_ERR("Unknown function");
425 out param1: API result
426 out param2: return paramter
429 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
434 size = g_variant_get_size(var);
436 data = (char *)g_variant_get_data(var);
438 param = g_array_append_vals(param, data, size);
443 static void __send_request_cb(GDBusProxy *proxy,
447 bluetooth_event_param_t bt_event;
448 bt_req_info_t *cb_data = user_data;
449 int result = BLUETOOTH_ERROR_NONE;
450 int event_type = BT_ADAPTER_EVENT;
452 GError *error = NULL;
456 GArray *out_param1 = NULL;
457 // GArray *out_param2 = NULL;
460 memset(&bt_event, 0x00, sizeof(bluetooth_event_param_t));
462 value = g_dbus_proxy_call_finish(proxy, res, &error);
465 /* dBUS gives error cause */
466 BT_ERR("D-Bus API failure: message[%s]",
468 g_clear_error(&error);
470 result = BLUETOOTH_ERROR_TIMEOUT;
472 ret_if(cb_data == NULL);
474 __bt_get_event_info(cb_data->service_function, NULL,
475 &bt_event.event, &event_type,
476 &bt_event.param_data);
478 g_variant_get(value, "(iv)", &result, ¶m1);
479 g_variant_unref(value);
482 out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
483 __bt_fill_garray_from_variant(param1, out_param1);
484 g_variant_unref(param1);
488 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
489 // __bt_fill_garray_from_variant(param2, out_param2);
490 // result = g_array_index(out_param2, int, 0);
491 // g_variant_unref(param2);
492 // g_array_free(out_param2, TRUE);
494 // result = BLUETOOTH_ERROR_INTERNAL;
497 ret_if(cb_data == NULL);
499 __bt_get_event_info(cb_data->service_function, out_param1,
500 &bt_event.event, &event_type,
501 &bt_event.param_data);
503 BT_DBG("service_function [%d]", cb_data->service_function);
504 if (result == BLUETOOTH_ERROR_NONE && out_param1) {
505 if (cb_data->service_function == BT_OPP_PUSH_FILES) {
506 request_id = g_array_index(out_param1, int, 0);
507 BT_DBG("request_id : %d", request_id);
508 _bt_add_push_request_id(request_id);
509 } else if (cb_data->service_function == BT_MAP_LIST_FOLDERS) {
510 request_id = g_array_index(out_param1, int, 0);
511 BT_DBG("request_id : %d", request_id);
512 _bt_add_push_request_id(request_id);
513 } else if (cb_data->service_function == BT_MAP_LIST_FILTER_FIELDS) {
514 request_id = g_array_index(out_param1, int, 0);
515 BT_DBG("request_id : %d", request_id);
516 _bt_add_push_request_id(request_id);
517 } else if (cb_data->service_function == BT_MAP_LIST_MESSAGES) {
518 request_id = g_array_index(out_param1, int, 0);
519 BT_DBG("request_id : %d", request_id);
520 _bt_add_push_request_id(request_id);
521 } else if (cb_data->service_function == BT_MAP_GET_MESSAGE) {
522 request_id = g_array_index(out_param1, int, 0);
523 BT_DBG("request_id : %d", request_id);
524 _bt_add_push_request_id(request_id);
525 } else if (cb_data->service_function == BT_MAP_PUSH_MESSAGE) {
526 request_id = g_array_index(out_param1, int, 0);
527 BT_DBG("request_id : %d", request_id);
528 _bt_add_push_request_id(request_id);
535 if (cb_data->cb == NULL)
538 /* Only if fail case, call the callback function*/
539 bt_event.result = result;
540 BT_INFO("event_type[%d], result= %s [0x%x]", event_type,
541 _bt_convert_error_to_string(result), result);
543 if (event_type == BT_ADAPTER_EVENT || event_type == BT_RFCOMM_CLIENT_EVENT) {
544 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
547 } else if (event_type == BT_HID_EVENT) {
548 ((hid_cb_func_ptr)cb_data->cb)(bt_event.event,
549 (hid_event_param_t *)&bt_event,
551 } else if (event_type == BT_HEADSET_EVENT) {
552 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
553 (bt_audio_event_param_t *)&bt_event,
555 } else if (event_type == BT_HF_AGENT_EVENT) {
556 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
557 (bt_audio_event_param_t *)&bt_event,
559 } else if (event_type == BT_AVRCP_CONTROL_EVENT) {
560 ((media_cb_func_ptr)cb_data->cb)(bt_event.event,
561 (media_event_param_t *)&bt_event,
563 } else if (event_type == BT_A2DP_SOURCE_EVENT) {
564 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
565 (bt_audio_event_param_t *)&bt_event,
567 } else if (event_type == BT_DEVICE_EVENT) {
568 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
571 } else if (event_type == BT_TDS_EVENT) {
572 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
575 } else if (event_type == BT_HDP_EVENT) {
576 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
577 &bt_event, cb_data->user_data);
578 } else if (event_type == BT_AVRCP_EVENT) {
579 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
580 &bt_event, cb_data->user_data);
581 #ifdef TIZEN_GATT_CLIENT
582 } else if (event_type == BT_GATT_CLIENT_EVENT) {
583 ((gatt_client_cb_func_ptr)cb_data->cb)(bt_event.event,
584 (gatt_client_event_param_t*)&bt_event, cb_data->user_data);
586 } else if (event_type == BT_MESH_EVENT) {
587 ((mesh_cb_func_ptr)cb_data->cb)(bt_event.event,
588 (mesh_event_param_t*)&bt_event, cb_data->user_data);
590 BT_INFO("Not handled event type : %d", event_type);
594 g_array_free(out_param1, TRUE);
596 sending_requests = g_slist_remove(sending_requests, (void *)cb_data);
602 int _bt_sync_send_request(int service_type, int service_function,
603 GArray *in_param1, GArray *in_param2,
604 GArray *in_param3, GArray *in_param4,
607 int result = BLUETOOTH_ERROR_NONE;
608 GError *error = NULL;
609 GArray *in_param5 = NULL;
610 // GArray *out_param2 = NULL;
620 switch (service_type) {
621 case BT_BLUEZ_SERVICE:
622 case BT_OBEX_SERVICE:
623 case BT_AGENT_SERVICE:
624 case BT_CHECK_PRIVILEGE:
625 proxy = __bt_gdbus_get_service_proxy();
627 return BLUETOOTH_ERROR_INTERNAL;
629 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
633 param1 = g_variant_new_from_data((const GVariantType *)"ay",
634 in_param1->data, in_param1->len,
636 param2 = g_variant_new_from_data((const GVariantType *)"ay",
637 in_param2->data, in_param2->len,
639 param3 = g_variant_new_from_data((const GVariantType *)"ay",
640 in_param3->data, in_param3->len,
642 param4 = g_variant_new_from_data((const GVariantType *)"ay",
643 in_param4->data, in_param4->len,
645 param5 = g_variant_new_from_data((const GVariantType *)"ay",
646 in_param5->data, in_param5->len,
649 ret = g_dbus_proxy_call_sync(proxy, "service_request",
650 g_variant_new("(iii@ay@ay@ay@ay@ay)",
651 service_type, service_function,
655 G_DBUS_CALL_FLAGS_NONE, -1,
658 g_array_free(in_param5, TRUE);
661 /* dBUS-RPC is failed */
662 BT_ERR("dBUS-RPC is failed");
665 /* dBUS gives error cause */
666 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
667 error->code, error->message);
669 g_clear_error(&error);
671 /* dBUS does not give error cause dBUS-RPC is failed */
672 BT_ERR("error returned was NULL");
675 return BLUETOOTH_ERROR_INTERNAL;
681 g_variant_get(ret, "(iv)", &result, ¶m1);
684 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
685 __bt_fill_garray_from_variant(param1, *out_param1);
686 g_variant_unref(param1);
690 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
691 // __bt_fill_garray_from_variant(param2, out_param2);
692 // result = g_array_index(out_param2, int, 0);
693 // g_variant_unref(param2);
694 // g_array_free(out_param2, TRUE);
696 // result = BLUETOOTH_ERROR_INTERNAL;
699 g_variant_unref(ret);
702 BT_ERR("Unknown service type");
703 return BLUETOOTH_ERROR_INTERNAL;
709 int _bt_async_send_request(int service_type, int service_function,
710 GArray *in_param1, GArray *in_param2,
711 GArray *in_param3, GArray *in_param4,
712 void *callback, void *user_data)
714 GArray* in_param5 = NULL;
715 bt_req_info_t *cb_data;
725 BT_DBG("service_function : %s (0x%x)",
726 _bt_convert_service_function_to_string(service_function),
729 cb_data = g_new0(bt_req_info_t, 1);
731 cb_data->service_function = service_function;
732 cb_data->cb = callback;
733 cb_data->user_data = user_data;
735 switch (service_type) {
736 case BT_BLUEZ_SERVICE:
737 case BT_OBEX_SERVICE:
738 proxy = __bt_gdbus_get_service_proxy();
741 return BLUETOOTH_ERROR_INTERNAL;
744 /* Do not timeout the request in certain cases. Sometime the
745 * request may take undeterministic time to reponse.
746 * (for ex: pairing retry) */
747 if (service_function == BT_BOND_DEVICE ||
748 service_function == BT_BOND_DEVICE_BY_TYPE)
751 timeout = BT_DBUS_TIMEOUT_MAX;
753 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
755 param1 = g_variant_new_from_data((const GVariantType *)"ay",
756 in_param1->data, in_param1->len,
758 param2 = g_variant_new_from_data((const GVariantType *)"ay",
759 in_param2->data, in_param2->len,
761 param3 = g_variant_new_from_data((const GVariantType *)"ay",
762 in_param3->data, in_param3->len,
764 param4 = g_variant_new_from_data((const GVariantType *)"ay",
765 in_param4->data, in_param4->len,
767 param5 = g_variant_new_from_data((const GVariantType *)"ay",
768 in_param5->data, in_param5->len,
771 g_dbus_proxy_call(proxy, "service_request",
772 g_variant_new("(iii@ay@ay@ay@ay@ay)",
773 service_type, service_function,
774 BT_ASYNC_REQ, param1, param2,
775 param3, param4, param5),
776 G_DBUS_CALL_FLAGS_NONE,
778 (GAsyncReadyCallback)__send_request_cb,
780 sending_requests = g_slist_append(sending_requests, cb_data);
782 g_array_free(in_param5, TRUE);
789 return BLUETOOTH_ERROR_NONE;
792 int _bt_async_send_request_with_unix_fd_list(int service_type, int service_function,
793 GArray *in_param1, GArray *in_param2,
794 GArray *in_param3, GArray *in_param4,
795 void *callback, void *user_data,
796 GUnixFDList *fd_list, GAsyncReadyCallback __async_req_cb)
798 GArray* in_param5 = NULL;
799 bt_req_info_t *cb_data;
809 BT_DBG("service_function : %d", service_function);
811 cb_data = g_new0(bt_req_info_t, 1);
812 cb_data->service_function = service_function;
813 cb_data->cb = callback;
814 cb_data->user_data = user_data;
816 switch (service_type) {
817 case BT_BLUEZ_SERVICE:
818 case BT_OBEX_SERVICE:
819 proxy = __bt_gdbus_get_service_proxy();
822 return BLUETOOTH_ERROR_INTERNAL;
825 /* Do not timeout the request in certain cases. Sometime the
826 * request may take undeterministic time to reponse.
827 * (for ex: pairing retry) */
828 if (service_function == BT_BOND_DEVICE ||
829 service_function == BT_BOND_DEVICE_BY_TYPE)
832 timeout = BT_DBUS_TIMEOUT_MAX;
834 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
836 param1 = g_variant_new_from_data((const GVariantType *)"ay",
837 in_param1->data, in_param1->len,
839 param2 = g_variant_new_from_data((const GVariantType *)"ay",
840 in_param2->data, in_param2->len,
842 param3 = g_variant_new_from_data((const GVariantType *)"ay",
843 in_param3->data, in_param3->len,
845 param4 = g_variant_new_from_data((const GVariantType *)"ay",
846 in_param4->data, in_param4->len,
848 param5 = g_variant_new_from_data((const GVariantType *)"ay",
849 in_param5->data, in_param5->len,
852 g_dbus_proxy_call_with_unix_fd_list(proxy, "service_request",
853 g_variant_new("(iii@ay@ay@ay@ay@ay)",
854 service_type, service_function,
855 BT_ASYNC_REQ, param1, param2,
856 param3, param4, param5),
857 G_DBUS_CALL_FLAGS_NONE,
858 timeout, fd_list, NULL,
859 __async_req_cb, (gpointer)cb_data);
860 sending_requests = g_slist_append(sending_requests, cb_data);
862 g_array_free(in_param5, TRUE);
869 return BLUETOOTH_ERROR_NONE;
872 int _bt_sync_send_request_with_unix_fd_list(
873 int service_type, int service_function,
874 GArray *in_param1, GArray *in_param2,
875 GArray *in_param3, GArray *in_param4,
876 GUnixFDList *fd_list, GArray **out_param1,
877 GUnixFDList **out_fd_list)
879 int result = BLUETOOTH_ERROR_NONE;
880 GError *error = NULL;
881 GArray *in_param5 = NULL;
891 switch (service_type) {
892 case BT_BLUEZ_SERVICE:
893 case BT_OBEX_SERVICE:
894 case BT_AGENT_SERVICE:
895 case BT_CHECK_PRIVILEGE:
896 proxy = __bt_gdbus_get_service_proxy();
898 return BLUETOOTH_ERROR_INTERNAL;
900 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
902 param1 = g_variant_new_from_data((const GVariantType *)"ay",
903 in_param1->data, in_param1->len,
905 param2 = g_variant_new_from_data((const GVariantType *)"ay",
906 in_param2->data, in_param2->len,
908 param3 = g_variant_new_from_data((const GVariantType *)"ay",
909 in_param3->data, in_param3->len,
911 param4 = g_variant_new_from_data((const GVariantType *)"ay",
912 in_param4->data, in_param4->len,
914 param5 = g_variant_new_from_data((const GVariantType *)"ay",
915 in_param5->data, in_param5->len,
918 ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, "service_request",
919 g_variant_new("(iii@ay@ay@ay@ay@ay)",
920 service_type, service_function,
921 BT_SYNC_REQ, param1, param2,
922 param3, param4, param5),
923 G_DBUS_CALL_FLAGS_NONE, -1,
924 fd_list, out_fd_list, NULL, &error);
925 g_array_free(in_param5, TRUE);
928 /* dBUS-RPC is failed */
929 BT_ERR("dBUS-RPC is failed");
932 /* dBUS gives error cause */
933 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
934 error->code, error->message);
936 g_clear_error(&error);
938 /* dBUS does not give error cause dBUS-RPC is failed */
939 BT_ERR("error returned was NULL");
942 return BLUETOOTH_ERROR_INTERNAL;
946 g_variant_get(ret, "(iv)", &result, ¶m1);
949 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
950 __bt_fill_garray_from_variant(param1, *out_param1);
951 g_variant_unref(param1);
954 g_variant_unref(ret);
957 BT_ERR("Unknown service type");
958 return BLUETOOTH_ERROR_INTERNAL;