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"
32 #include "bluetooth-gatt-client-api.h"
33 #include "bluetooth-mesh-api.h"
35 static GSList *sending_requests;
37 static GDBusProxy *service_gproxy;
38 static GDBusProxy *service_gproxy_not_autostart;
40 static GDBusProxy *__bt_gdbus_init_service_proxy(void)
42 GDBusConnection *service_gconn;
46 service_gconn = _bt_get_system_common_conn();
51 proxy = g_dbus_proxy_new_sync(service_gconn,
52 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
59 BT_ERR("Unable to create proxy: %s", err->message);
66 service_gproxy = proxy;
71 static GDBusProxy *__bt_gdbus_init_service_proxy_not_autostart(void)
73 GDBusConnection *service_gconn;
77 service_gconn = _bt_get_system_common_conn();
82 /* G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
83 * method call will be failed not auto activation
84 * if service is unavailble. */
85 proxy = g_dbus_proxy_new_sync(service_gconn,
86 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL,
93 BT_ERR("Unable to create proxy: %s", err->message);
100 service_gproxy_not_autostart = proxy;
105 static GDBusProxy *__bt_gdbus_get_service_proxy(void)
107 return (service_gproxy) ? service_gproxy : __bt_gdbus_init_service_proxy();
110 static GDBusProxy *__bt_gdbus_get_service_proxy_not_autostart(void)
112 return (service_gproxy_not_autostart) ? service_gproxy_not_autostart : __bt_gdbus_init_service_proxy_not_autostart();
115 void _bt_gdbus_deinit_proxys(void)
117 if (service_gproxy) {
118 g_object_unref(service_gproxy);
119 service_gproxy = NULL;
123 static void __bt_get_event_info(int service_function, GArray *output,
124 int *event, int *event_type, void **param_data)
126 ret_if(event == NULL);
128 BT_DBG("service_function : %s (0x%x)",
129 _bt_convert_service_function_to_string(service_function),
131 switch (service_function) {
133 case BT_BOND_DEVICE_BY_TYPE:
134 *event_type = BT_ADAPTER_EVENT;
135 *event = BLUETOOTH_EVENT_BONDING_FINISHED;
136 ret_if(output == NULL);
137 *param_data = &g_array_index(output,
138 bluetooth_device_info_t, 0);
140 case BT_UNBOND_DEVICE:
141 *event_type = BT_ADAPTER_EVENT;
142 *event = BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED;
143 ret_if(output == NULL);
144 *param_data = &g_array_index(output,
145 bluetooth_device_address_t, 0);
147 case BT_SEARCH_SERVICE:
148 *event_type = BT_ADAPTER_EVENT;
149 *event = BLUETOOTH_EVENT_SERVICE_SEARCHED;
150 ret_if(output == NULL);
151 *param_data = &g_array_index(output,
155 *event_type = BT_HID_EVENT;
156 *event = BLUETOOTH_HID_CONNECTED;
157 ret_if(output == NULL);
158 *param_data = &g_array_index(output,
159 bluetooth_device_address_t, 0);
161 case BT_HID_DISCONNECT:
162 *event_type = BT_HID_EVENT;
163 *event = BLUETOOTH_HID_DISCONNECTED;
164 ret_if(output == NULL);
165 *param_data = &g_array_index(output,
166 bluetooth_device_address_t, 0);
168 case BT_AUDIO_CONNECT:
170 *event_type = BT_HEADSET_EVENT;
171 *event = BLUETOOTH_EVENT_AG_CONNECTED;
172 ret_if(output == NULL);
173 *param_data = &g_array_index(output, char, 0);
175 case BT_AUDIO_DISCONNECT:
176 case BT_AG_DISCONNECT:
177 *event_type = BT_HEADSET_EVENT;
178 *event = BLUETOOTH_EVENT_AG_DISCONNECTED;
179 ret_if(output == NULL);
180 *param_data = &g_array_index(output, char, 0);
183 *event_type = BT_HEADSET_EVENT;
184 *event = BLUETOOTH_EVENT_AV_CONNECTED;
185 ret_if(output == NULL);
186 *param_data = &g_array_index(output, char, 0);
188 case BT_AV_DISCONNECT:
189 *event_type = BT_HEADSET_EVENT;
190 *event = BLUETOOTH_EVENT_AV_DISCONNECTED;
191 ret_if(output == NULL);
192 *param_data = &g_array_index(output, char, 0);
194 case BT_AV_SOURCE_CONNECT:
195 *event_type = BT_A2DP_SOURCE_EVENT;
196 *event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
197 ret_if(output == NULL);
198 *param_data = &g_array_index(output, char, 0);
200 case BT_AV_SOURCE_DISCONNECT:
201 *event_type = BT_A2DP_SOURCE_EVENT;
202 *event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
203 ret_if(output == NULL);
204 *param_data = &g_array_index(output, char, 0);
207 *event_type = BT_HF_AGENT_EVENT;
208 *event = BLUETOOTH_EVENT_HF_CONNECTED;
209 ret_if(output == NULL);
210 *param_data = &g_array_index(output, char, 0);
212 case BT_HF_DISCONNECT:
213 *event_type = BT_HF_AGENT_EVENT;
214 *event = BLUETOOTH_EVENT_HF_DISCONNECTED;
215 ret_if(output == NULL);
216 *param_data = &g_array_index(output, char, 0);
218 case BT_NETWORK_CONNECT:
219 *event_type = BT_ADAPTER_EVENT;
220 *event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
221 ret_if(output == NULL);
222 *param_data = &g_array_index(output,
223 bluetooth_device_address_t, 0);
225 case BT_NETWORK_DISCONNECT:
226 *event_type = BT_ADAPTER_EVENT;
227 *event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
228 ret_if(output == NULL);
229 *param_data = &g_array_index(output,
230 bluetooth_device_address_t, 0);
232 case BT_RFCOMM_CLIENT_CONNECT:
233 *event_type = BT_RFCOMM_CLIENT_EVENT;
234 *event = BLUETOOTH_EVENT_RFCOMM_CONNECTED;
235 ret_if(output == NULL);
236 *param_data = &g_array_index(output,
237 bluetooth_rfcomm_connection_t, 0);
239 case BT_AVRCP_TARGET_CONNECT:
240 *event_type = BT_AVRCP_EVENT;
241 *event = BLUETOOTH_EVENT_AVRCP_CONNECTED;
242 ret_if(output == NULL);
243 *param_data = &g_array_index(output, char, 0);
245 case BT_AVRCP_TARGET_DISCONNECT:
246 *event_type = BT_AVRCP_EVENT;
247 *event = BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
248 ret_if(output == NULL);
249 *param_data = &g_array_index(output, char, 0);
251 case BT_AVRCP_CONTROL_CONNECT:
252 *event_type = BT_AVRCP_CONTROL_EVENT;
253 *event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
254 ret_if(output == NULL);
255 *param_data = &g_array_index(output, char, 0);
257 case BT_AVRCP_CONTROL_DISCONNECT:
258 *event_type = BT_AVRCP_CONTROL_EVENT;
259 *event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
260 ret_if(output == NULL);
261 *param_data = &g_array_index(output, char, 0);
264 *event_type = BT_DEVICE_EVENT;
265 *event = BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED;
266 ret_if(output == NULL);
267 *param_data = &g_array_index(output,
268 bluetooth_device_address_t, 0);
271 *event_type = BT_DEVICE_EVENT;
272 *event = BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED;
273 ret_if(output == NULL);
274 *param_data = &g_array_index(output,
275 bluetooth_device_address_t, 0);
277 case BT_DISCONNECT_LE:
278 *event_type = BT_DEVICE_EVENT;
279 *event = BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED;
280 ret_if(output == NULL);
281 *param_data = &g_array_index(output,
282 bluetooth_device_address_t, 0);
284 case BT_GATT_READ_CHARACTERISTIC:
285 BT_INFO("BT_GATT_READ_CHARACTERISTIC");
286 *event_type = BT_GATT_CLIENT_EVENT;
287 *event = BLUETOOTH_EVENT_GATT_READ_CHAR;
288 ret_if(output == NULL);
289 *param_data = &g_array_index(output,
290 bluetooth_gatt_client_char_prop_info_t, 0);
292 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE:
293 BT_INFO("BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE");
294 *event_type = BT_GATT_CLIENT_EVENT;
295 *event = BLUETOOTH_EVENT_GATT_WRITE_CHAR;
296 ret_if(output == NULL);
297 *param_data = &g_array_index(output,
298 bluetooth_gatt_client_char_prop_info_t, 0);
300 case BT_GATT_READ_DESCRIPTOR_VALUE:
301 BT_INFO("BT_GATT_READ_DESCRIPTOR_VALUE");
302 *event_type = BT_GATT_CLIENT_EVENT;
303 *event = BLUETOOTH_EVENT_GATT_READ_DESC;
304 ret_if(output == NULL);
305 *param_data = &g_array_index(output,
306 bluetooth_gatt_client_desc_prop_info_t, 0);
308 case BT_GATT_WRITE_DESCRIPTOR_VALUE:
309 BT_INFO("BT_GATT_WRITE_DESCRIPTOR_VALUE");
310 *event_type = BT_GATT_CLIENT_EVENT;
311 *event = BLUETOOTH_EVENT_GATT_WRITE_DESC;
312 ret_if(output == NULL);
313 *param_data = &g_array_index(output,
314 bluetooth_gatt_client_desc_prop_info_t, 0);
316 case BT_TDS_READ_TRANSPORT_DATA:
317 *event_type = BT_TDS_EVENT;
318 *event = BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED;
319 ret_if(output == NULL);
320 *param_data = &g_array_index(output,
321 bluetooth_device_address_t, 0);
323 case BT_TDS_ENABLE_CONTROL_POINT:
324 *event_type = BT_TDS_EVENT;
325 *event = BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED;
326 ret_if(output == NULL);
327 *param_data = &g_array_index(output,
328 bluetooth_device_address_t, 0);
330 case BT_TDS_ACTIVATE_CONTROL_POINT:
331 *event_type = BT_TDS_EVENT;
332 *event = BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT;
333 ret_if(output == NULL);
334 *param_data = &g_array_index(output,
335 bluetooth_device_address_t, 0);
338 *event_type = BT_HDP_EVENT;
339 *event = BLUETOOTH_EVENT_HDP_CONNECTED;
340 ret_if(output == NULL);
341 *param_data = &g_array_index(output,
342 bt_hdp_connected_t, 0);
344 case BT_HDP_DISCONNECT:
345 *event_type = BT_HDP_EVENT;
346 *event = BLUETOOTH_EVENT_HDP_DISCONNECTED;
347 ret_if(output == NULL);
348 *param_data = &g_array_index(output,
349 bt_hdp_disconnected_t, 0);
351 case BT_MESH_NETWORK_PROVISION_DEVICE:
352 *event_type = BT_MESH_EVENT;
353 *event = BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED;
354 ret_if(output == NULL);
355 *param_data = &g_array_index(output,
356 bluetooth_mesh_provisioning_request_t, 0);
358 case BT_MESH_NODE_BROWSE:
359 *event_type = BT_MESH_EVENT;
360 *event = BLUETOOTH_EVENT_MESH_NODE_BROWSED;
361 ret_if(output == NULL);
362 *param_data = &g_array_index(output,
363 bluetooth_mesh_node_discover_t, 0);
365 case BT_MESH_NODE_GET_VENDOR_FEATURES:
366 *event_type = BT_MESH_EVENT;
367 *event = BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES;
368 ret_if(output == NULL);
369 *param_data = &g_array_index(output,
370 bluetooth_mesh_node_features_t, 0);
372 case BT_MESH_NODE_CONFIGURE_KEY:
373 *event_type = BT_MESH_EVENT;
374 *event = BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED;
375 ret_if(output == NULL);
376 *param_data = &g_array_index(output,
377 bluetooth_mesh_key_configure_t, 0);
379 case BT_MESH_NODE_TTL_EXECUTE:
380 *event_type = BT_MESH_EVENT;
381 *event = BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED;
382 ret_if(output == NULL);
383 *param_data = &g_array_index(output,
384 bluetooth_mesh_node_ttl_info_t, 0);
386 case BT_MESH_MODEL_CONFIGURE_APPKEY:
387 *event_type = BT_MESH_EVENT;
388 *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND;
389 ret_if(output == NULL);
390 *param_data = &g_array_index(output,
391 bluetooth_mesh_model_configure_t, 0);
393 case BT_MESH_MODEL_EXECUTE_MSG:
394 *event_type = BT_MESH_EVENT;
395 *event = BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED;
396 ret_if(output == NULL);
397 *param_data = &g_array_index(output,
398 bluetooth_mesh_model_msg_t, 0);
400 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
401 *event_type = BT_MESH_EVENT;
402 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED;
403 ret_if(output == NULL);
404 *param_data = &g_array_index(output,
405 bluetooth_mesh_model_configure_t, 0);
407 case BT_MESH_MODEL_GET_APPKEY_LIST:
408 *event_type = BT_MESH_EVENT;
409 *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST;
410 ret_if(output == NULL);
411 *param_data = &g_array_index(output,
412 bluetooth_mesh_model_configure_t, 0);
414 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
415 *event_type = BT_MESH_EVENT;
416 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST;
417 ret_if(output == NULL);
418 *param_data = &g_array_index(output,
419 bluetooth_mesh_model_configure_t, 0);
421 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
422 *event_type = BT_MESH_EVENT;
423 *event = BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED;
424 ret_if(output == NULL);
425 *param_data = &g_array_index(output,
426 bluetooth_mesh_model_configure_t, 0);
428 case BT_MESH_MODEL_SET_PUBLICATION:
429 *event_type = BT_MESH_EVENT;
430 *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
431 ret_if(output == NULL);
432 *param_data = &g_array_index(output,
433 bluetooth_mesh_model_configure_t, 0);
435 case BT_MESH_MODEL_GET_PUBLICATION:
436 *event_type = BT_MESH_EVENT;
437 *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
438 ret_if(output == NULL);
439 *param_data = &g_array_index(output,
440 bluetooth_mesh_model_configure_t, 0);
443 BT_ERR("Unknown function");
449 out param1: API result
450 out param2: return paramter
453 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
458 size = g_variant_get_size(var);
460 data = (char *)g_variant_get_data(var);
462 param = g_array_append_vals(param, data, size);
467 static void __send_request_cb(GDBusProxy *proxy,
471 bluetooth_event_param_t bt_event;
472 bt_req_info_t *cb_data = user_data;
473 int result = BLUETOOTH_ERROR_NONE;
474 int event_type = BT_ADAPTER_EVENT;
476 GError *error = NULL;
480 GArray *out_param1 = NULL;
481 // GArray *out_param2 = NULL;
484 memset(&bt_event, 0x00, sizeof(bluetooth_event_param_t));
486 value = g_dbus_proxy_call_finish(proxy, res, &error);
489 /* dBUS gives error cause */
490 BT_ERR("D-Bus API failure: message[%s]",
492 g_clear_error(&error);
494 result = BLUETOOTH_ERROR_TIMEOUT;
496 ret_if(cb_data == NULL);
498 __bt_get_event_info(cb_data->service_function, NULL,
499 &bt_event.event, &event_type,
500 &bt_event.param_data);
502 g_variant_get(value, "(iv)", &result, ¶m1);
503 g_variant_unref(value);
506 out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
507 __bt_fill_garray_from_variant(param1, out_param1);
508 g_variant_unref(param1);
512 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
513 // __bt_fill_garray_from_variant(param2, out_param2);
514 // result = g_array_index(out_param2, int, 0);
515 // g_variant_unref(param2);
516 // g_array_free(out_param2, TRUE);
518 // result = BLUETOOTH_ERROR_INTERNAL;
521 ret_if(cb_data == NULL);
523 __bt_get_event_info(cb_data->service_function, out_param1,
524 &bt_event.event, &event_type,
525 &bt_event.param_data);
527 BT_DBG("service_function [%d]", cb_data->service_function);
528 if (result == BLUETOOTH_ERROR_NONE && out_param1) {
529 if (cb_data->service_function == BT_OPP_PUSH_FILES) {
530 request_id = g_array_index(out_param1, int, 0);
531 BT_DBG("request_id : %d", request_id);
532 _bt_add_push_request_id(request_id);
533 } else if (cb_data->service_function == BT_MAP_LIST_FOLDERS) {
534 request_id = g_array_index(out_param1, int, 0);
535 BT_DBG("request_id : %d", request_id);
536 _bt_add_push_request_id(request_id);
537 } else if (cb_data->service_function == BT_MAP_LIST_FILTER_FIELDS) {
538 request_id = g_array_index(out_param1, int, 0);
539 BT_DBG("request_id : %d", request_id);
540 _bt_add_push_request_id(request_id);
541 } else if (cb_data->service_function == BT_MAP_LIST_MESSAGES) {
542 request_id = g_array_index(out_param1, int, 0);
543 BT_DBG("request_id : %d", request_id);
544 _bt_add_push_request_id(request_id);
545 } else if (cb_data->service_function == BT_MAP_GET_MESSAGE) {
546 request_id = g_array_index(out_param1, int, 0);
547 BT_DBG("request_id : %d", request_id);
548 _bt_add_push_request_id(request_id);
549 } else if (cb_data->service_function == BT_MAP_PUSH_MESSAGE) {
550 request_id = g_array_index(out_param1, int, 0);
551 BT_DBG("request_id : %d", request_id);
552 _bt_add_push_request_id(request_id);
559 if (cb_data->cb == NULL)
562 /* Only if fail case, call the callback function*/
563 bt_event.result = result;
564 BT_INFO("event_type[%d], result= %s [0x%x]", event_type,
565 _bt_convert_error_to_string(result), result);
567 if (event_type == BT_ADAPTER_EVENT || event_type == BT_RFCOMM_CLIENT_EVENT) {
568 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
571 } else if (event_type == BT_HID_EVENT) {
572 ((hid_cb_func_ptr)cb_data->cb)(bt_event.event,
573 (hid_event_param_t *)&bt_event,
575 } else if (event_type == BT_HEADSET_EVENT) {
576 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
577 (bt_audio_event_param_t *)&bt_event,
579 } else if (event_type == BT_HF_AGENT_EVENT) {
580 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
581 (bt_audio_event_param_t *)&bt_event,
583 } else if (event_type == BT_AVRCP_CONTROL_EVENT) {
584 ((media_cb_func_ptr)cb_data->cb)(bt_event.event,
585 (media_event_param_t *)&bt_event,
587 } else if (event_type == BT_A2DP_SOURCE_EVENT) {
588 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
589 (bt_audio_event_param_t *)&bt_event,
591 } else if (event_type == BT_DEVICE_EVENT) {
592 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
595 } else if (event_type == BT_TDS_EVENT) {
596 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
599 } else if (event_type == BT_HDP_EVENT) {
600 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
601 &bt_event, cb_data->user_data);
602 } else if (event_type == BT_AVRCP_EVENT) {
603 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
604 &bt_event, cb_data->user_data);
605 } else if (event_type == BT_GATT_CLIENT_EVENT) {
606 ((gatt_client_cb_func_ptr)cb_data->cb)(bt_event.event,
607 (gatt_client_event_param_t*)&bt_event, cb_data->user_data);
608 } else if (event_type == BT_MESH_EVENT) {
609 ((mesh_cb_func_ptr)cb_data->cb)(bt_event.event,
610 (mesh_event_param_t*)&bt_event, cb_data->user_data);
612 BT_INFO("Not handled event type : %d", event_type);
616 g_array_free(out_param1, TRUE);
618 sending_requests = g_slist_remove(sending_requests, (void *)cb_data);
624 int _bt_sync_send_request(int service_type, int service_function,
625 GArray *in_param1, GArray *in_param2,
626 GArray *in_param3, GArray *in_param4,
629 int result = BLUETOOTH_ERROR_NONE;
630 GError *error = NULL;
631 GArray *in_param5 = NULL;
632 // GArray *out_param2 = NULL;
642 switch (service_type) {
643 case BT_BLUEZ_SERVICE:
644 case BT_OBEX_SERVICE:
645 case BT_AGENT_SERVICE:
646 case BT_CHECK_PRIVILEGE:
647 proxy = __bt_gdbus_get_service_proxy();
649 return BLUETOOTH_ERROR_INTERNAL;
651 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
655 param1 = g_variant_new_from_data((const GVariantType *)"ay",
656 in_param1->data, in_param1->len,
658 param2 = g_variant_new_from_data((const GVariantType *)"ay",
659 in_param2->data, in_param2->len,
661 param3 = g_variant_new_from_data((const GVariantType *)"ay",
662 in_param3->data, in_param3->len,
664 param4 = g_variant_new_from_data((const GVariantType *)"ay",
665 in_param4->data, in_param4->len,
667 param5 = g_variant_new_from_data((const GVariantType *)"ay",
668 in_param5->data, in_param5->len,
671 ret = g_dbus_proxy_call_sync(proxy, "service_request",
672 g_variant_new("(iii@ay@ay@ay@ay@ay)",
673 service_type, service_function,
677 G_DBUS_CALL_FLAGS_NONE, -1,
680 g_array_free(in_param5, TRUE);
683 /* dBUS-RPC is failed */
684 BT_ERR("dBUS-RPC is failed");
687 /* dBUS gives error cause */
688 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
689 error->code, error->message);
691 g_clear_error(&error);
693 /* dBUS does not give error cause dBUS-RPC is failed */
694 BT_ERR("error returned was NULL");
697 return BLUETOOTH_ERROR_INTERNAL;
703 g_variant_get(ret, "(iv)", &result, ¶m1);
706 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
707 __bt_fill_garray_from_variant(param1, *out_param1);
708 g_variant_unref(param1);
712 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
713 // __bt_fill_garray_from_variant(param2, out_param2);
714 // result = g_array_index(out_param2, int, 0);
715 // g_variant_unref(param2);
716 // g_array_free(out_param2, TRUE);
718 // result = BLUETOOTH_ERROR_INTERNAL;
721 g_variant_unref(ret);
724 BT_ERR("Unknown service type");
725 return BLUETOOTH_ERROR_INTERNAL;
731 int _bt_async_send_request(int service_type, int service_function,
732 GArray *in_param1, GArray *in_param2,
733 GArray *in_param3, GArray *in_param4,
734 void *callback, void *user_data)
736 GArray* in_param5 = NULL;
737 bt_req_info_t *cb_data;
747 BT_DBG("service_function : %s (0x%x)",
748 _bt_convert_service_function_to_string(service_function),
751 cb_data = g_new0(bt_req_info_t, 1);
753 cb_data->service_function = service_function;
754 cb_data->cb = callback;
755 cb_data->user_data = user_data;
757 switch (service_type) {
758 case BT_BLUEZ_SERVICE:
759 case BT_OBEX_SERVICE:
760 proxy = __bt_gdbus_get_service_proxy();
763 return BLUETOOTH_ERROR_INTERNAL;
766 /* Do not timeout the request in certain cases. Sometime the
767 * request may take undeterministic time to reponse.
768 * (for ex: pairing retry) */
769 timeout = BT_DBUS_TIMEOUT_MAX;
771 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
773 param1 = g_variant_new_from_data((const GVariantType *)"ay",
774 in_param1->data, in_param1->len,
776 param2 = g_variant_new_from_data((const GVariantType *)"ay",
777 in_param2->data, in_param2->len,
779 param3 = g_variant_new_from_data((const GVariantType *)"ay",
780 in_param3->data, in_param3->len,
782 param4 = g_variant_new_from_data((const GVariantType *)"ay",
783 in_param4->data, in_param4->len,
785 param5 = g_variant_new_from_data((const GVariantType *)"ay",
786 in_param5->data, in_param5->len,
789 g_dbus_proxy_call(proxy, "service_request",
790 g_variant_new("(iii@ay@ay@ay@ay@ay)",
791 service_type, service_function,
792 BT_ASYNC_REQ, param1, param2,
793 param3, param4, param5),
794 G_DBUS_CALL_FLAGS_NONE,
796 (GAsyncReadyCallback)__send_request_cb,
798 sending_requests = g_slist_append(sending_requests, cb_data);
800 g_array_free(in_param5, TRUE);
807 return BLUETOOTH_ERROR_NONE;
810 int _bt_async_send_request_with_unix_fd_list(int service_type, int service_function,
811 GArray *in_param1, GArray *in_param2,
812 GArray *in_param3, GArray *in_param4,
813 void *callback, void *user_data,
814 GUnixFDList *fd_list, GAsyncReadyCallback __async_req_cb)
816 GArray* in_param5 = NULL;
817 bt_req_info_t *cb_data;
827 BT_DBG("service_function : %d", service_function);
829 cb_data = g_new0(bt_req_info_t, 1);
830 cb_data->service_function = service_function;
831 cb_data->cb = callback;
832 cb_data->user_data = user_data;
834 switch (service_type) {
835 case BT_BLUEZ_SERVICE:
836 case BT_OBEX_SERVICE:
837 proxy = __bt_gdbus_get_service_proxy();
840 return BLUETOOTH_ERROR_INTERNAL;
843 /* Do not timeout the request in certain cases. Sometime the
844 * request may take undeterministic time to reponse.
845 * (for ex: pairing retry) */
846 if (service_function == BT_BOND_DEVICE ||
847 service_function == BT_BOND_DEVICE_BY_TYPE) {
849 } else if (service_function == BT_L2CAP_LE_CLIENT_CONNECT) {
852 timeout = BT_DBUS_TIMEOUT_MAX;
855 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
857 param1 = g_variant_new_from_data((const GVariantType *)"ay",
858 in_param1->data, in_param1->len,
860 param2 = g_variant_new_from_data((const GVariantType *)"ay",
861 in_param2->data, in_param2->len,
863 param3 = g_variant_new_from_data((const GVariantType *)"ay",
864 in_param3->data, in_param3->len,
866 param4 = g_variant_new_from_data((const GVariantType *)"ay",
867 in_param4->data, in_param4->len,
869 param5 = g_variant_new_from_data((const GVariantType *)"ay",
870 in_param5->data, in_param5->len,
873 g_dbus_proxy_call_with_unix_fd_list(proxy, "service_request",
874 g_variant_new("(iii@ay@ay@ay@ay@ay)",
875 service_type, service_function,
876 BT_ASYNC_REQ, param1, param2,
877 param3, param4, param5),
878 G_DBUS_CALL_FLAGS_NONE,
879 timeout, fd_list, NULL,
880 __async_req_cb, (gpointer)cb_data);
881 sending_requests = g_slist_append(sending_requests, cb_data);
883 g_array_free(in_param5, TRUE);
890 return BLUETOOTH_ERROR_NONE;
893 int _bt_sync_send_request_with_unix_fd_list(
894 int service_type, int service_function,
895 GArray *in_param1, GArray *in_param2,
896 GArray *in_param3, GArray *in_param4,
897 GUnixFDList *fd_list, GArray **out_param1,
898 GUnixFDList **out_fd_list)
900 int result = BLUETOOTH_ERROR_NONE;
901 GError *error = NULL;
902 GArray *in_param5 = NULL;
912 switch (service_type) {
913 case BT_BLUEZ_SERVICE:
914 case BT_OBEX_SERVICE:
915 case BT_AGENT_SERVICE:
916 case BT_CHECK_PRIVILEGE:
917 proxy = __bt_gdbus_get_service_proxy();
919 return BLUETOOTH_ERROR_INTERNAL;
921 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
923 param1 = g_variant_new_from_data((const GVariantType *)"ay",
924 in_param1->data, in_param1->len,
926 param2 = g_variant_new_from_data((const GVariantType *)"ay",
927 in_param2->data, in_param2->len,
929 param3 = g_variant_new_from_data((const GVariantType *)"ay",
930 in_param3->data, in_param3->len,
932 param4 = g_variant_new_from_data((const GVariantType *)"ay",
933 in_param4->data, in_param4->len,
935 param5 = g_variant_new_from_data((const GVariantType *)"ay",
936 in_param5->data, in_param5->len,
939 ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, "service_request",
940 g_variant_new("(iii@ay@ay@ay@ay@ay)",
941 service_type, service_function,
942 BT_SYNC_REQ, param1, param2,
943 param3, param4, param5),
944 G_DBUS_CALL_FLAGS_NONE, -1,
945 fd_list, out_fd_list, NULL, &error);
946 g_array_free(in_param5, TRUE);
949 /* dBUS-RPC is failed */
950 BT_ERR("dBUS-RPC is failed");
953 /* dBUS gives error cause */
954 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
955 error->code, error->message);
957 g_clear_error(&error);
959 /* dBUS does not give error cause dBUS-RPC is failed */
960 BT_ERR("error returned was NULL");
963 return BLUETOOTH_ERROR_INTERNAL;
967 g_variant_get(ret, "(iv)", &result, ¶m1);
970 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
971 __bt_fill_garray_from_variant(param1, *out_param1);
972 g_variant_unref(param1);
975 g_variant_unref(ret);
978 BT_ERR("Unknown service type");
979 return BLUETOOTH_ERROR_INTERNAL;
985 int _bt_sync_send_request_not_autostart(int service_type, int service_function,
986 GArray *in_param1, GArray *in_param2,
987 GArray *in_param3, GArray *in_param4,
990 int result = BLUETOOTH_ERROR_NONE;
991 GError *error = NULL;
992 GArray *in_param5 = NULL;
993 // GArray *out_param2 = NULL;
1003 switch (service_type) {
1004 case BT_BLUEZ_SERVICE:
1005 case BT_OBEX_SERVICE:
1006 case BT_AGENT_SERVICE:
1007 case BT_CHECK_PRIVILEGE:
1008 proxy = __bt_gdbus_get_service_proxy_not_autostart();
1010 return BLUETOOTH_ERROR_INTERNAL;
1012 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
1016 param1 = g_variant_new_from_data((const GVariantType *)"ay",
1017 in_param1->data, in_param1->len,
1019 param2 = g_variant_new_from_data((const GVariantType *)"ay",
1020 in_param2->data, in_param2->len,
1022 param3 = g_variant_new_from_data((const GVariantType *)"ay",
1023 in_param3->data, in_param3->len,
1025 param4 = g_variant_new_from_data((const GVariantType *)"ay",
1026 in_param4->data, in_param4->len,
1028 param5 = g_variant_new_from_data((const GVariantType *)"ay",
1029 in_param5->data, in_param5->len,
1032 ret = g_dbus_proxy_call_sync(proxy, "service_request",
1033 g_variant_new("(iii@ay@ay@ay@ay@ay)",
1034 service_type, service_function,
1035 BT_SYNC_REQ, param1,
1038 G_DBUS_CALL_FLAGS_NONE, -1,
1041 g_array_free(in_param5, TRUE);
1045 g_clear_error(&error);
1046 BT_DBG("bt-service is not available");
1047 return BLUETOOTH_ERROR_INTERNAL;
1053 g_variant_get(ret, "(iv)", &result, ¶m1);
1056 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
1057 __bt_fill_garray_from_variant(param1, *out_param1);
1058 g_variant_unref(param1);
1062 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
1063 // __bt_fill_garray_from_variant(param2, out_param2);
1064 // result = g_array_index(out_param2, int, 0);
1065 // g_variant_unref(param2);
1066 // g_array_free(out_param2, TRUE);
1068 // result = BLUETOOTH_ERROR_INTERNAL;
1071 g_variant_unref(ret);
1074 BT_ERR("Unknown service type");
1075 return BLUETOOTH_ERROR_INTERNAL;