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_EXECUTE_MSG:
377 *event_type = BT_MESH_EVENT;
378 *event = BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED;
379 ret_if(output == NULL);
380 *param_data = &g_array_index(output,
381 bluetooth_mesh_model_msg_t, 0);
383 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
384 *event_type = BT_MESH_EVENT;
385 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED;
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_APPKEY_LIST:
391 *event_type = BT_MESH_EVENT;
392 *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_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_GET_SUBSCRIPTION_LIST:
398 *event_type = BT_MESH_EVENT;
399 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST;
400 ret_if(output == NULL);
401 *param_data = &g_array_index(output,
402 bluetooth_mesh_model_configure_t, 0);
404 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
405 *event_type = BT_MESH_EVENT;
406 *event = BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED;
407 ret_if(output == NULL);
408 *param_data = &g_array_index(output,
409 bluetooth_mesh_model_configure_t, 0);
411 case BT_MESH_MODEL_SET_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);
418 case BT_MESH_MODEL_GET_PUBLICATION:
419 *event_type = BT_MESH_EVENT;
420 *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
421 ret_if(output == NULL);
422 *param_data = &g_array_index(output,
423 bluetooth_mesh_model_configure_t, 0);
426 BT_ERR("Unknown function");
432 out param1: API result
433 out param2: return paramter
436 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
441 size = g_variant_get_size(var);
443 data = (char *)g_variant_get_data(var);
445 param = g_array_append_vals(param, data, size);
450 static void __send_request_cb(GDBusProxy *proxy,
454 bluetooth_event_param_t bt_event;
455 bt_req_info_t *cb_data = user_data;
456 int result = BLUETOOTH_ERROR_NONE;
457 int event_type = BT_ADAPTER_EVENT;
459 GError *error = NULL;
463 GArray *out_param1 = NULL;
464 // GArray *out_param2 = NULL;
467 memset(&bt_event, 0x00, sizeof(bluetooth_event_param_t));
469 value = g_dbus_proxy_call_finish(proxy, res, &error);
472 /* dBUS gives error cause */
473 BT_ERR("D-Bus API failure: message[%s]",
475 g_clear_error(&error);
477 result = BLUETOOTH_ERROR_TIMEOUT;
479 ret_if(cb_data == NULL);
481 __bt_get_event_info(cb_data->service_function, NULL,
482 &bt_event.event, &event_type,
483 &bt_event.param_data);
485 g_variant_get(value, "(iv)", &result, ¶m1);
486 g_variant_unref(value);
489 out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
490 __bt_fill_garray_from_variant(param1, out_param1);
491 g_variant_unref(param1);
495 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
496 // __bt_fill_garray_from_variant(param2, out_param2);
497 // result = g_array_index(out_param2, int, 0);
498 // g_variant_unref(param2);
499 // g_array_free(out_param2, TRUE);
501 // result = BLUETOOTH_ERROR_INTERNAL;
504 ret_if(cb_data == NULL);
506 __bt_get_event_info(cb_data->service_function, out_param1,
507 &bt_event.event, &event_type,
508 &bt_event.param_data);
510 BT_DBG("service_function [%d]", cb_data->service_function);
511 if (result == BLUETOOTH_ERROR_NONE && out_param1) {
512 if (cb_data->service_function == BT_OPP_PUSH_FILES) {
513 request_id = g_array_index(out_param1, int, 0);
514 BT_DBG("request_id : %d", request_id);
515 _bt_add_push_request_id(request_id);
516 } else if (cb_data->service_function == BT_MAP_LIST_FOLDERS) {
517 request_id = g_array_index(out_param1, int, 0);
518 BT_DBG("request_id : %d", request_id);
519 _bt_add_push_request_id(request_id);
520 } else if (cb_data->service_function == BT_MAP_LIST_FILTER_FIELDS) {
521 request_id = g_array_index(out_param1, int, 0);
522 BT_DBG("request_id : %d", request_id);
523 _bt_add_push_request_id(request_id);
524 } else if (cb_data->service_function == BT_MAP_LIST_MESSAGES) {
525 request_id = g_array_index(out_param1, int, 0);
526 BT_DBG("request_id : %d", request_id);
527 _bt_add_push_request_id(request_id);
528 } else if (cb_data->service_function == BT_MAP_GET_MESSAGE) {
529 request_id = g_array_index(out_param1, int, 0);
530 BT_DBG("request_id : %d", request_id);
531 _bt_add_push_request_id(request_id);
532 } else if (cb_data->service_function == BT_MAP_PUSH_MESSAGE) {
533 request_id = g_array_index(out_param1, int, 0);
534 BT_DBG("request_id : %d", request_id);
535 _bt_add_push_request_id(request_id);
542 if (cb_data->cb == NULL)
545 /* Only if fail case, call the callback function*/
546 bt_event.result = result;
547 BT_INFO("event_type[%d], result= %s [0x%x]", event_type,
548 _bt_convert_error_to_string(result), result);
550 if (event_type == BT_ADAPTER_EVENT || event_type == BT_RFCOMM_CLIENT_EVENT) {
551 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
554 } else if (event_type == BT_HID_EVENT) {
555 ((hid_cb_func_ptr)cb_data->cb)(bt_event.event,
556 (hid_event_param_t *)&bt_event,
558 } else if (event_type == BT_HEADSET_EVENT) {
559 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
560 (bt_audio_event_param_t *)&bt_event,
562 } else if (event_type == BT_HF_AGENT_EVENT) {
563 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
564 (bt_audio_event_param_t *)&bt_event,
566 } else if (event_type == BT_AVRCP_CONTROL_EVENT) {
567 ((media_cb_func_ptr)cb_data->cb)(bt_event.event,
568 (media_event_param_t *)&bt_event,
570 } else if (event_type == BT_A2DP_SOURCE_EVENT) {
571 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
572 (bt_audio_event_param_t *)&bt_event,
574 } else if (event_type == BT_DEVICE_EVENT) {
575 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
578 } else if (event_type == BT_TDS_EVENT) {
579 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
582 } else if (event_type == BT_HDP_EVENT) {
583 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
584 &bt_event, cb_data->user_data);
585 } else if (event_type == BT_AVRCP_EVENT) {
586 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
587 &bt_event, cb_data->user_data);
588 #ifdef TIZEN_GATT_CLIENT
589 } else if (event_type == BT_GATT_CLIENT_EVENT) {
590 ((gatt_client_cb_func_ptr)cb_data->cb)(bt_event.event,
591 (gatt_client_event_param_t*)&bt_event, cb_data->user_data);
593 } else if (event_type == BT_MESH_EVENT) {
594 ((mesh_cb_func_ptr)cb_data->cb)(bt_event.event,
595 (mesh_event_param_t*)&bt_event, cb_data->user_data);
597 BT_INFO("Not handled event type : %d", event_type);
601 g_array_free(out_param1, TRUE);
603 sending_requests = g_slist_remove(sending_requests, (void *)cb_data);
609 int _bt_sync_send_request(int service_type, int service_function,
610 GArray *in_param1, GArray *in_param2,
611 GArray *in_param3, GArray *in_param4,
614 int result = BLUETOOTH_ERROR_NONE;
615 GError *error = NULL;
616 GArray *in_param5 = NULL;
617 // GArray *out_param2 = NULL;
627 switch (service_type) {
628 case BT_BLUEZ_SERVICE:
629 case BT_OBEX_SERVICE:
630 case BT_AGENT_SERVICE:
631 case BT_CHECK_PRIVILEGE:
632 proxy = __bt_gdbus_get_service_proxy();
634 return BLUETOOTH_ERROR_INTERNAL;
636 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
640 param1 = g_variant_new_from_data((const GVariantType *)"ay",
641 in_param1->data, in_param1->len,
643 param2 = g_variant_new_from_data((const GVariantType *)"ay",
644 in_param2->data, in_param2->len,
646 param3 = g_variant_new_from_data((const GVariantType *)"ay",
647 in_param3->data, in_param3->len,
649 param4 = g_variant_new_from_data((const GVariantType *)"ay",
650 in_param4->data, in_param4->len,
652 param5 = g_variant_new_from_data((const GVariantType *)"ay",
653 in_param5->data, in_param5->len,
656 ret = g_dbus_proxy_call_sync(proxy, "service_request",
657 g_variant_new("(iii@ay@ay@ay@ay@ay)",
658 service_type, service_function,
662 G_DBUS_CALL_FLAGS_NONE, -1,
665 g_array_free(in_param5, TRUE);
668 /* dBUS-RPC is failed */
669 BT_ERR("dBUS-RPC is failed");
672 /* dBUS gives error cause */
673 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
674 error->code, error->message);
676 g_clear_error(&error);
678 /* dBUS does not give error cause dBUS-RPC is failed */
679 BT_ERR("error returned was NULL");
682 return BLUETOOTH_ERROR_INTERNAL;
688 g_variant_get(ret, "(iv)", &result, ¶m1);
691 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
692 __bt_fill_garray_from_variant(param1, *out_param1);
693 g_variant_unref(param1);
697 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
698 // __bt_fill_garray_from_variant(param2, out_param2);
699 // result = g_array_index(out_param2, int, 0);
700 // g_variant_unref(param2);
701 // g_array_free(out_param2, TRUE);
703 // result = BLUETOOTH_ERROR_INTERNAL;
706 g_variant_unref(ret);
709 BT_ERR("Unknown service type");
710 return BLUETOOTH_ERROR_INTERNAL;
716 int _bt_async_send_request(int service_type, int service_function,
717 GArray *in_param1, GArray *in_param2,
718 GArray *in_param3, GArray *in_param4,
719 void *callback, void *user_data)
721 GArray* in_param5 = NULL;
722 bt_req_info_t *cb_data;
732 BT_DBG("service_function : %s (0x%x)",
733 _bt_convert_service_function_to_string(service_function),
736 cb_data = g_new0(bt_req_info_t, 1);
738 cb_data->service_function = service_function;
739 cb_data->cb = callback;
740 cb_data->user_data = user_data;
742 switch (service_type) {
743 case BT_BLUEZ_SERVICE:
744 case BT_OBEX_SERVICE:
745 proxy = __bt_gdbus_get_service_proxy();
748 return BLUETOOTH_ERROR_INTERNAL;
751 /* Do not timeout the request in certain cases. Sometime the
752 * request may take undeterministic time to reponse.
753 * (for ex: pairing retry) */
754 if (service_function == BT_BOND_DEVICE ||
755 service_function == BT_BOND_DEVICE_BY_TYPE)
758 timeout = BT_DBUS_TIMEOUT_MAX;
760 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
762 param1 = g_variant_new_from_data((const GVariantType *)"ay",
763 in_param1->data, in_param1->len,
765 param2 = g_variant_new_from_data((const GVariantType *)"ay",
766 in_param2->data, in_param2->len,
768 param3 = g_variant_new_from_data((const GVariantType *)"ay",
769 in_param3->data, in_param3->len,
771 param4 = g_variant_new_from_data((const GVariantType *)"ay",
772 in_param4->data, in_param4->len,
774 param5 = g_variant_new_from_data((const GVariantType *)"ay",
775 in_param5->data, in_param5->len,
778 g_dbus_proxy_call(proxy, "service_request",
779 g_variant_new("(iii@ay@ay@ay@ay@ay)",
780 service_type, service_function,
781 BT_ASYNC_REQ, param1, param2,
782 param3, param4, param5),
783 G_DBUS_CALL_FLAGS_NONE,
785 (GAsyncReadyCallback)__send_request_cb,
787 sending_requests = g_slist_append(sending_requests, cb_data);
789 g_array_free(in_param5, TRUE);
796 return BLUETOOTH_ERROR_NONE;
799 int _bt_async_send_request_with_unix_fd_list(int service_type, int service_function,
800 GArray *in_param1, GArray *in_param2,
801 GArray *in_param3, GArray *in_param4,
802 void *callback, void *user_data,
803 GUnixFDList *fd_list, GAsyncReadyCallback __async_req_cb)
805 GArray* in_param5 = NULL;
806 bt_req_info_t *cb_data;
816 BT_DBG("service_function : %d", service_function);
818 cb_data = g_new0(bt_req_info_t, 1);
819 cb_data->service_function = service_function;
820 cb_data->cb = callback;
821 cb_data->user_data = user_data;
823 switch (service_type) {
824 case BT_BLUEZ_SERVICE:
825 case BT_OBEX_SERVICE:
826 proxy = __bt_gdbus_get_service_proxy();
829 return BLUETOOTH_ERROR_INTERNAL;
832 /* Do not timeout the request in certain cases. Sometime the
833 * request may take undeterministic time to reponse.
834 * (for ex: pairing retry) */
835 if (service_function == BT_BOND_DEVICE ||
836 service_function == BT_BOND_DEVICE_BY_TYPE)
839 timeout = BT_DBUS_TIMEOUT_MAX;
841 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
843 param1 = g_variant_new_from_data((const GVariantType *)"ay",
844 in_param1->data, in_param1->len,
846 param2 = g_variant_new_from_data((const GVariantType *)"ay",
847 in_param2->data, in_param2->len,
849 param3 = g_variant_new_from_data((const GVariantType *)"ay",
850 in_param3->data, in_param3->len,
852 param4 = g_variant_new_from_data((const GVariantType *)"ay",
853 in_param4->data, in_param4->len,
855 param5 = g_variant_new_from_data((const GVariantType *)"ay",
856 in_param5->data, in_param5->len,
859 g_dbus_proxy_call_with_unix_fd_list(proxy, "service_request",
860 g_variant_new("(iii@ay@ay@ay@ay@ay)",
861 service_type, service_function,
862 BT_ASYNC_REQ, param1, param2,
863 param3, param4, param5),
864 G_DBUS_CALL_FLAGS_NONE,
865 timeout, fd_list, NULL,
866 __async_req_cb, (gpointer)cb_data);
867 sending_requests = g_slist_append(sending_requests, cb_data);
869 g_array_free(in_param5, TRUE);
876 return BLUETOOTH_ERROR_NONE;
879 int _bt_sync_send_request_with_unix_fd_list(
880 int service_type, int service_function,
881 GArray *in_param1, GArray *in_param2,
882 GArray *in_param3, GArray *in_param4,
883 GUnixFDList *fd_list, GArray **out_param1,
884 GUnixFDList **out_fd_list)
886 int result = BLUETOOTH_ERROR_NONE;
887 GError *error = NULL;
888 GArray *in_param5 = NULL;
898 switch (service_type) {
899 case BT_BLUEZ_SERVICE:
900 case BT_OBEX_SERVICE:
901 case BT_AGENT_SERVICE:
902 case BT_CHECK_PRIVILEGE:
903 proxy = __bt_gdbus_get_service_proxy();
905 return BLUETOOTH_ERROR_INTERNAL;
907 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
909 param1 = g_variant_new_from_data((const GVariantType *)"ay",
910 in_param1->data, in_param1->len,
912 param2 = g_variant_new_from_data((const GVariantType *)"ay",
913 in_param2->data, in_param2->len,
915 param3 = g_variant_new_from_data((const GVariantType *)"ay",
916 in_param3->data, in_param3->len,
918 param4 = g_variant_new_from_data((const GVariantType *)"ay",
919 in_param4->data, in_param4->len,
921 param5 = g_variant_new_from_data((const GVariantType *)"ay",
922 in_param5->data, in_param5->len,
925 ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, "service_request",
926 g_variant_new("(iii@ay@ay@ay@ay@ay)",
927 service_type, service_function,
928 BT_SYNC_REQ, param1, param2,
929 param3, param4, param5),
930 G_DBUS_CALL_FLAGS_NONE, -1,
931 fd_list, out_fd_list, NULL, &error);
932 g_array_free(in_param5, TRUE);
935 /* dBUS-RPC is failed */
936 BT_ERR("dBUS-RPC is failed");
939 /* dBUS gives error cause */
940 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
941 error->code, error->message);
943 g_clear_error(&error);
945 /* dBUS does not give error cause dBUS-RPC is failed */
946 BT_ERR("error returned was NULL");
949 return BLUETOOTH_ERROR_INTERNAL;
953 g_variant_get(ret, "(iv)", &result, ¶m1);
956 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
957 __bt_fill_garray_from_variant(param1, *out_param1);
958 g_variant_unref(param1);
961 g_variant_unref(ret);
964 BT_ERR("Unknown service type");
965 return BLUETOOTH_ERROR_INTERNAL;