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;
39 static GDBusProxy *__bt_gdbus_init_service_proxy(void)
41 GDBusConnection *service_gconn;
45 service_gconn = _bt_get_system_private_conn();
50 proxy = g_dbus_proxy_new_sync(service_gconn,
51 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
58 BT_ERR("Unable to create proxy: %s", err->message);
65 service_gproxy = proxy;
70 static GDBusProxy *__bt_gdbus_get_service_proxy(void)
72 return (service_gproxy) ? service_gproxy : __bt_gdbus_init_service_proxy();
75 void _bt_gdbus_deinit_proxys(void)
78 g_object_unref(service_gproxy);
79 service_gproxy = NULL;
83 static void __bt_get_event_info(int service_function, GArray *output,
84 int *event, int *event_type, void **param_data)
86 ret_if(event == NULL);
88 BT_DBG("service_function : %s (0x%x)",
89 _bt_convert_service_function_to_string(service_function),
91 switch (service_function) {
93 case BT_BOND_DEVICE_BY_TYPE:
94 *event_type = BT_ADAPTER_EVENT;
95 *event = BLUETOOTH_EVENT_BONDING_FINISHED;
96 ret_if(output == NULL);
97 *param_data = &g_array_index(output,
98 bluetooth_device_info_t, 0);
100 case BT_UNBOND_DEVICE:
101 *event_type = BT_ADAPTER_EVENT;
102 *event = BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED;
103 ret_if(output == NULL);
104 *param_data = &g_array_index(output,
105 bluetooth_device_address_t, 0);
107 case BT_SEARCH_SERVICE:
108 *event_type = BT_ADAPTER_EVENT;
109 *event = BLUETOOTH_EVENT_SERVICE_SEARCHED;
110 ret_if(output == NULL);
111 *param_data = &g_array_index(output,
115 *event_type = BT_HID_EVENT;
116 *event = BLUETOOTH_HID_CONNECTED;
117 ret_if(output == NULL);
118 *param_data = &g_array_index(output,
119 bluetooth_device_address_t, 0);
121 case BT_HID_DISCONNECT:
122 *event_type = BT_HID_EVENT;
123 *event = BLUETOOTH_HID_DISCONNECTED;
124 ret_if(output == NULL);
125 *param_data = &g_array_index(output,
126 bluetooth_device_address_t, 0);
128 case BT_AUDIO_CONNECT:
130 *event_type = BT_HEADSET_EVENT;
131 *event = BLUETOOTH_EVENT_AG_CONNECTED;
132 ret_if(output == NULL);
133 *param_data = &g_array_index(output, char, 0);
135 case BT_AUDIO_DISCONNECT:
136 case BT_AG_DISCONNECT:
137 *event_type = BT_HEADSET_EVENT;
138 *event = BLUETOOTH_EVENT_AG_DISCONNECTED;
139 ret_if(output == NULL);
140 *param_data = &g_array_index(output, char, 0);
143 *event_type = BT_HEADSET_EVENT;
144 *event = BLUETOOTH_EVENT_AV_CONNECTED;
145 ret_if(output == NULL);
146 *param_data = &g_array_index(output, char, 0);
148 case BT_AV_DISCONNECT:
149 *event_type = BT_HEADSET_EVENT;
150 *event = BLUETOOTH_EVENT_AV_DISCONNECTED;
151 ret_if(output == NULL);
152 *param_data = &g_array_index(output, char, 0);
154 case BT_AV_SOURCE_CONNECT:
155 *event_type = BT_A2DP_SOURCE_EVENT;
156 *event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
157 ret_if(output == NULL);
158 *param_data = &g_array_index(output, char, 0);
160 case BT_AV_SOURCE_DISCONNECT:
161 *event_type = BT_A2DP_SOURCE_EVENT;
162 *event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
163 ret_if(output == NULL);
164 *param_data = &g_array_index(output, char, 0);
167 *event_type = BT_HF_AGENT_EVENT;
168 *event = BLUETOOTH_EVENT_HF_CONNECTED;
169 ret_if(output == NULL);
170 *param_data = &g_array_index(output, char, 0);
172 case BT_HF_DISCONNECT:
173 *event_type = BT_HF_AGENT_EVENT;
174 *event = BLUETOOTH_EVENT_HF_DISCONNECTED;
175 ret_if(output == NULL);
176 *param_data = &g_array_index(output, char, 0);
178 case BT_NETWORK_CONNECT:
179 *event_type = BT_ADAPTER_EVENT;
180 *event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
181 ret_if(output == NULL);
182 *param_data = &g_array_index(output,
183 bluetooth_device_address_t, 0);
185 case BT_NETWORK_DISCONNECT:
186 *event_type = BT_ADAPTER_EVENT;
187 *event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
188 ret_if(output == NULL);
189 *param_data = &g_array_index(output,
190 bluetooth_device_address_t, 0);
192 case BT_RFCOMM_CLIENT_CONNECT:
193 *event_type = BT_RFCOMM_CLIENT_EVENT;
194 *event = BLUETOOTH_EVENT_RFCOMM_CONNECTED;
195 ret_if(output == NULL);
196 *param_data = &g_array_index(output,
197 bluetooth_rfcomm_connection_t, 0);
199 case BT_AVRCP_TARGET_CONNECT:
200 *event_type = BT_AVRCP_EVENT;
201 *event = BLUETOOTH_EVENT_AVRCP_CONNECTED;
202 ret_if(output == NULL);
203 *param_data = &g_array_index(output, char, 0);
205 case BT_AVRCP_TARGET_DISCONNECT:
206 *event_type = BT_AVRCP_EVENT;
207 *event = BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
208 ret_if(output == NULL);
209 *param_data = &g_array_index(output, char, 0);
211 case BT_AVRCP_CONTROL_CONNECT:
212 *event_type = BT_AVRCP_CONTROL_EVENT;
213 *event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
214 ret_if(output == NULL);
215 *param_data = &g_array_index(output, char, 0);
217 case BT_AVRCP_CONTROL_DISCONNECT:
218 *event_type = BT_AVRCP_CONTROL_EVENT;
219 *event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
220 ret_if(output == NULL);
221 *param_data = &g_array_index(output, char, 0);
224 *event_type = BT_DEVICE_EVENT;
225 *event = BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED;
226 ret_if(output == NULL);
227 *param_data = &g_array_index(output,
228 bluetooth_device_address_t, 0);
231 *event_type = BT_DEVICE_EVENT;
232 *event = BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED;
233 ret_if(output == NULL);
234 *param_data = &g_array_index(output,
235 bluetooth_device_address_t, 0);
237 case BT_DISCONNECT_LE:
238 *event_type = BT_DEVICE_EVENT;
239 *event = BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED;
240 ret_if(output == NULL);
241 *param_data = &g_array_index(output,
242 bluetooth_device_address_t, 0);
244 case BT_GATT_READ_CHARACTERISTIC:
245 BT_INFO("BT_GATT_READ_CHARACTERISTIC");
246 *event_type = BT_GATT_CLIENT_EVENT;
247 *event = BLUETOOTH_EVENT_GATT_READ_CHAR;
248 ret_if(output == NULL);
249 *param_data = &g_array_index(output,
250 bluetooth_gatt_client_char_prop_info_t, 0);
252 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE:
253 BT_INFO("BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE");
254 *event_type = BT_GATT_CLIENT_EVENT;
255 *event = BLUETOOTH_EVENT_GATT_WRITE_CHAR;
256 ret_if(output == NULL);
257 *param_data = &g_array_index(output,
258 bluetooth_gatt_client_char_prop_info_t, 0);
260 case BT_GATT_READ_DESCRIPTOR_VALUE:
261 BT_INFO("BT_GATT_READ_DESCRIPTOR_VALUE");
262 *event_type = BT_GATT_CLIENT_EVENT;
263 *event = BLUETOOTH_EVENT_GATT_READ_DESC;
264 ret_if(output == NULL);
265 *param_data = &g_array_index(output,
266 bluetooth_gatt_client_desc_prop_info_t, 0);
268 case BT_GATT_WRITE_DESCRIPTOR_VALUE:
269 BT_INFO("BT_GATT_WRITE_DESCRIPTOR_VALUE");
270 *event_type = BT_GATT_CLIENT_EVENT;
271 *event = BLUETOOTH_EVENT_GATT_WRITE_DESC;
272 ret_if(output == NULL);
273 *param_data = &g_array_index(output,
274 bluetooth_gatt_client_desc_prop_info_t, 0);
276 case BT_TDS_READ_TRANSPORT_DATA:
277 *event_type = BT_TDS_EVENT;
278 *event = BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED;
279 ret_if(output == NULL);
280 *param_data = &g_array_index(output,
281 bluetooth_device_address_t, 0);
283 case BT_TDS_ENABLE_CONTROL_POINT:
284 *event_type = BT_TDS_EVENT;
285 *event = BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED;
286 ret_if(output == NULL);
287 *param_data = &g_array_index(output,
288 bluetooth_device_address_t, 0);
290 case BT_TDS_ACTIVATE_CONTROL_POINT:
291 *event_type = BT_TDS_EVENT;
292 *event = BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT;
293 ret_if(output == NULL);
294 *param_data = &g_array_index(output,
295 bluetooth_device_address_t, 0);
298 *event_type = BT_HDP_EVENT;
299 *event = BLUETOOTH_EVENT_HDP_CONNECTED;
300 ret_if(output == NULL);
301 *param_data = &g_array_index(output,
302 bt_hdp_connected_t, 0);
304 case BT_HDP_DISCONNECT:
305 *event_type = BT_HDP_EVENT;
306 *event = BLUETOOTH_EVENT_HDP_DISCONNECTED;
307 ret_if(output == NULL);
308 *param_data = &g_array_index(output,
309 bt_hdp_disconnected_t, 0);
311 case BT_MESH_NETWORK_PROVISION_DEVICE:
312 *event_type = BT_MESH_EVENT;
313 *event = BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED;
314 ret_if(output == NULL);
315 *param_data = &g_array_index(output,
316 bluetooth_mesh_provisioning_request_t, 0);
318 case BT_MESH_NODE_BROWSE:
319 *event_type = BT_MESH_EVENT;
320 *event = BLUETOOTH_EVENT_MESH_NODE_BROWSED;
321 ret_if(output == NULL);
322 *param_data = &g_array_index(output,
323 bluetooth_mesh_node_discover_t, 0);
325 case BT_MESH_NODE_GET_VENDOR_FEATURES:
326 *event_type = BT_MESH_EVENT;
327 *event = BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES;
328 ret_if(output == NULL);
329 *param_data = &g_array_index(output,
330 bluetooth_mesh_node_features_t, 0);
332 case BT_MESH_NODE_CONFIGURE_KEY:
333 *event_type = BT_MESH_EVENT;
334 *event = BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED;
335 ret_if(output == NULL);
336 *param_data = &g_array_index(output,
337 bluetooth_mesh_key_configure_t, 0);
339 case BT_MESH_NODE_TTL_EXECUTE:
340 *event_type = BT_MESH_EVENT;
341 *event = BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED;
342 ret_if(output == NULL);
343 *param_data = &g_array_index(output,
344 bluetooth_mesh_node_ttl_info_t, 0);
346 case BT_MESH_MODEL_CONFIGURE_APPKEY:
347 *event_type = BT_MESH_EVENT;
348 *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND;
349 ret_if(output == NULL);
350 *param_data = &g_array_index(output,
351 bluetooth_mesh_model_configure_t, 0);
353 case BT_MESH_MODEL_EXECUTE_MSG:
354 *event_type = BT_MESH_EVENT;
355 *event = BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED;
356 ret_if(output == NULL);
357 *param_data = &g_array_index(output,
358 bluetooth_mesh_model_msg_t, 0);
360 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
361 *event_type = BT_MESH_EVENT;
362 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED;
363 ret_if(output == NULL);
364 *param_data = &g_array_index(output,
365 bluetooth_mesh_model_configure_t, 0);
367 case BT_MESH_MODEL_GET_APPKEY_LIST:
368 *event_type = BT_MESH_EVENT;
369 *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST;
370 ret_if(output == NULL);
371 *param_data = &g_array_index(output,
372 bluetooth_mesh_model_configure_t, 0);
374 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
375 *event_type = BT_MESH_EVENT;
376 *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST;
377 ret_if(output == NULL);
378 *param_data = &g_array_index(output,
379 bluetooth_mesh_model_configure_t, 0);
381 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
382 *event_type = BT_MESH_EVENT;
383 *event = BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED;
384 ret_if(output == NULL);
385 *param_data = &g_array_index(output,
386 bluetooth_mesh_model_configure_t, 0);
388 case BT_MESH_MODEL_SET_PUBLICATION:
389 *event_type = BT_MESH_EVENT;
390 *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
391 ret_if(output == NULL);
392 *param_data = &g_array_index(output,
393 bluetooth_mesh_model_configure_t, 0);
395 case BT_MESH_MODEL_GET_PUBLICATION:
396 *event_type = BT_MESH_EVENT;
397 *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
398 ret_if(output == NULL);
399 *param_data = &g_array_index(output,
400 bluetooth_mesh_model_configure_t, 0);
403 BT_ERR("Unknown function");
409 out param1: API result
410 out param2: return paramter
413 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
418 size = g_variant_get_size(var);
420 data = (char *)g_variant_get_data(var);
422 param = g_array_append_vals(param, data, size);
427 static void __send_request_cb(GDBusProxy *proxy,
431 bluetooth_event_param_t bt_event;
432 bt_req_info_t *cb_data = user_data;
433 int result = BLUETOOTH_ERROR_NONE;
434 int event_type = BT_ADAPTER_EVENT;
436 GError *error = NULL;
440 GArray *out_param1 = NULL;
441 // GArray *out_param2 = NULL;
444 memset(&bt_event, 0x00, sizeof(bluetooth_event_param_t));
446 value = g_dbus_proxy_call_finish(proxy, res, &error);
449 /* dBUS gives error cause */
450 BT_ERR("D-Bus API failure: message[%s]",
452 g_clear_error(&error);
454 result = BLUETOOTH_ERROR_TIMEOUT;
456 ret_if(cb_data == NULL);
458 __bt_get_event_info(cb_data->service_function, NULL,
459 &bt_event.event, &event_type,
460 &bt_event.param_data);
462 g_variant_get(value, "(iv)", &result, ¶m1);
463 g_variant_unref(value);
466 out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
467 __bt_fill_garray_from_variant(param1, out_param1);
468 g_variant_unref(param1);
472 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
473 // __bt_fill_garray_from_variant(param2, out_param2);
474 // result = g_array_index(out_param2, int, 0);
475 // g_variant_unref(param2);
476 // g_array_free(out_param2, TRUE);
478 // result = BLUETOOTH_ERROR_INTERNAL;
481 ret_if(cb_data == NULL);
483 __bt_get_event_info(cb_data->service_function, out_param1,
484 &bt_event.event, &event_type,
485 &bt_event.param_data);
487 BT_DBG("service_function [%d]", cb_data->service_function);
488 if (result == BLUETOOTH_ERROR_NONE && out_param1) {
489 if (cb_data->service_function == BT_OPP_PUSH_FILES) {
490 request_id = g_array_index(out_param1, int, 0);
491 BT_DBG("request_id : %d", request_id);
492 _bt_add_push_request_id(request_id);
493 } else if (cb_data->service_function == BT_MAP_LIST_FOLDERS) {
494 request_id = g_array_index(out_param1, int, 0);
495 BT_DBG("request_id : %d", request_id);
496 _bt_add_push_request_id(request_id);
497 } else if (cb_data->service_function == BT_MAP_LIST_FILTER_FIELDS) {
498 request_id = g_array_index(out_param1, int, 0);
499 BT_DBG("request_id : %d", request_id);
500 _bt_add_push_request_id(request_id);
501 } else if (cb_data->service_function == BT_MAP_LIST_MESSAGES) {
502 request_id = g_array_index(out_param1, int, 0);
503 BT_DBG("request_id : %d", request_id);
504 _bt_add_push_request_id(request_id);
505 } else if (cb_data->service_function == BT_MAP_GET_MESSAGE) {
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_PUSH_MESSAGE) {
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);
519 if (cb_data->cb == NULL)
522 /* Only if fail case, call the callback function*/
523 bt_event.result = result;
524 BT_INFO("event_type[%d], result= %s [0x%x]", event_type,
525 _bt_convert_error_to_string(result), result);
527 if (event_type == BT_ADAPTER_EVENT || event_type == BT_RFCOMM_CLIENT_EVENT) {
528 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
531 } else if (event_type == BT_HID_EVENT) {
532 ((hid_cb_func_ptr)cb_data->cb)(bt_event.event,
533 (hid_event_param_t *)&bt_event,
535 } else if (event_type == BT_HEADSET_EVENT) {
536 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
537 (bt_audio_event_param_t *)&bt_event,
539 } else if (event_type == BT_HF_AGENT_EVENT) {
540 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
541 (bt_audio_event_param_t *)&bt_event,
543 } else if (event_type == BT_AVRCP_CONTROL_EVENT) {
544 ((media_cb_func_ptr)cb_data->cb)(bt_event.event,
545 (media_event_param_t *)&bt_event,
547 } else if (event_type == BT_A2DP_SOURCE_EVENT) {
548 ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
549 (bt_audio_event_param_t *)&bt_event,
551 } else if (event_type == BT_DEVICE_EVENT) {
552 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
555 } else if (event_type == BT_TDS_EVENT) {
556 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
559 } else if (event_type == BT_HDP_EVENT) {
560 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
561 &bt_event, cb_data->user_data);
562 } else if (event_type == BT_AVRCP_EVENT) {
563 ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
564 &bt_event, cb_data->user_data);
565 } else if (event_type == BT_GATT_CLIENT_EVENT) {
566 ((gatt_client_cb_func_ptr)cb_data->cb)(bt_event.event,
567 (gatt_client_event_param_t*)&bt_event, cb_data->user_data);
568 } else if (event_type == BT_MESH_EVENT) {
569 ((mesh_cb_func_ptr)cb_data->cb)(bt_event.event,
570 (mesh_event_param_t*)&bt_event, cb_data->user_data);
572 BT_INFO("Not handled event type : %d", event_type);
576 g_array_free(out_param1, TRUE);
578 sending_requests = g_slist_remove(sending_requests, (void *)cb_data);
584 int _bt_sync_send_request(int service_type, int service_function,
585 GArray *in_param1, GArray *in_param2,
586 GArray *in_param3, GArray *in_param4,
589 int result = BLUETOOTH_ERROR_NONE;
590 GError *error = NULL;
591 GArray *in_param5 = NULL;
592 // GArray *out_param2 = NULL;
602 switch (service_type) {
603 case BT_BLUEZ_SERVICE:
604 case BT_OBEX_SERVICE:
605 case BT_AGENT_SERVICE:
606 case BT_CHECK_PRIVILEGE:
607 proxy = __bt_gdbus_get_service_proxy();
609 return BLUETOOTH_ERROR_INTERNAL;
611 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
615 param1 = g_variant_new_from_data((const GVariantType *)"ay",
616 in_param1->data, in_param1->len,
618 param2 = g_variant_new_from_data((const GVariantType *)"ay",
619 in_param2->data, in_param2->len,
621 param3 = g_variant_new_from_data((const GVariantType *)"ay",
622 in_param3->data, in_param3->len,
624 param4 = g_variant_new_from_data((const GVariantType *)"ay",
625 in_param4->data, in_param4->len,
627 param5 = g_variant_new_from_data((const GVariantType *)"ay",
628 in_param5->data, in_param5->len,
631 ret = g_dbus_proxy_call_sync(proxy, "service_request",
632 g_variant_new("(iii@ay@ay@ay@ay@ay)",
633 service_type, service_function,
637 G_DBUS_CALL_FLAGS_NONE, -1,
640 g_array_free(in_param5, TRUE);
643 /* dBUS-RPC is failed */
644 BT_ERR("dBUS-RPC is failed");
647 /* dBUS gives error cause */
648 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
649 error->code, error->message);
651 g_clear_error(&error);
653 /* dBUS does not give error cause dBUS-RPC is failed */
654 BT_ERR("error returned was NULL");
657 return BLUETOOTH_ERROR_INTERNAL;
663 g_variant_get(ret, "(iv)", &result, ¶m1);
666 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
667 __bt_fill_garray_from_variant(param1, *out_param1);
668 g_variant_unref(param1);
672 // out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
673 // __bt_fill_garray_from_variant(param2, out_param2);
674 // result = g_array_index(out_param2, int, 0);
675 // g_variant_unref(param2);
676 // g_array_free(out_param2, TRUE);
678 // result = BLUETOOTH_ERROR_INTERNAL;
681 g_variant_unref(ret);
684 BT_ERR("Unknown service type");
685 return BLUETOOTH_ERROR_INTERNAL;
691 int _bt_async_send_request(int service_type, int service_function,
692 GArray *in_param1, GArray *in_param2,
693 GArray *in_param3, GArray *in_param4,
694 void *callback, void *user_data)
696 GArray* in_param5 = NULL;
697 bt_req_info_t *cb_data;
707 BT_DBG("service_function : %s (0x%x)",
708 _bt_convert_service_function_to_string(service_function),
711 cb_data = g_new0(bt_req_info_t, 1);
713 cb_data->service_function = service_function;
714 cb_data->cb = callback;
715 cb_data->user_data = user_data;
717 switch (service_type) {
718 case BT_BLUEZ_SERVICE:
719 case BT_OBEX_SERVICE:
720 proxy = __bt_gdbus_get_service_proxy();
723 return BLUETOOTH_ERROR_INTERNAL;
726 /* Do not timeout the request in certain cases. Sometime the
727 * request may take undeterministic time to reponse.
728 * (for ex: pairing retry) */
729 if (service_function == BT_BOND_DEVICE ||
730 service_function == BT_BOND_DEVICE_BY_TYPE)
733 timeout = BT_DBUS_TIMEOUT_MAX;
735 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
737 param1 = g_variant_new_from_data((const GVariantType *)"ay",
738 in_param1->data, in_param1->len,
740 param2 = g_variant_new_from_data((const GVariantType *)"ay",
741 in_param2->data, in_param2->len,
743 param3 = g_variant_new_from_data((const GVariantType *)"ay",
744 in_param3->data, in_param3->len,
746 param4 = g_variant_new_from_data((const GVariantType *)"ay",
747 in_param4->data, in_param4->len,
749 param5 = g_variant_new_from_data((const GVariantType *)"ay",
750 in_param5->data, in_param5->len,
753 g_dbus_proxy_call(proxy, "service_request",
754 g_variant_new("(iii@ay@ay@ay@ay@ay)",
755 service_type, service_function,
756 BT_ASYNC_REQ, param1, param2,
757 param3, param4, param5),
758 G_DBUS_CALL_FLAGS_NONE,
760 (GAsyncReadyCallback)__send_request_cb,
762 sending_requests = g_slist_append(sending_requests, cb_data);
764 g_array_free(in_param5, TRUE);
771 return BLUETOOTH_ERROR_NONE;
774 int _bt_async_send_request_with_unix_fd_list(int service_type, int service_function,
775 GArray *in_param1, GArray *in_param2,
776 GArray *in_param3, GArray *in_param4,
777 void *callback, void *user_data,
778 GUnixFDList *fd_list, GAsyncReadyCallback __async_req_cb)
780 GArray* in_param5 = NULL;
781 bt_req_info_t *cb_data;
791 BT_DBG("service_function : %d", service_function);
793 cb_data = g_new0(bt_req_info_t, 1);
794 cb_data->service_function = service_function;
795 cb_data->cb = callback;
796 cb_data->user_data = user_data;
798 switch (service_type) {
799 case BT_BLUEZ_SERVICE:
800 case BT_OBEX_SERVICE:
801 proxy = __bt_gdbus_get_service_proxy();
804 return BLUETOOTH_ERROR_INTERNAL;
807 /* Do not timeout the request in certain cases. Sometime the
808 * request may take undeterministic time to reponse.
809 * (for ex: pairing retry) */
810 if (service_function == BT_BOND_DEVICE ||
811 service_function == BT_BOND_DEVICE_BY_TYPE)
814 timeout = BT_DBUS_TIMEOUT_MAX;
816 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
818 param1 = g_variant_new_from_data((const GVariantType *)"ay",
819 in_param1->data, in_param1->len,
821 param2 = g_variant_new_from_data((const GVariantType *)"ay",
822 in_param2->data, in_param2->len,
824 param3 = g_variant_new_from_data((const GVariantType *)"ay",
825 in_param3->data, in_param3->len,
827 param4 = g_variant_new_from_data((const GVariantType *)"ay",
828 in_param4->data, in_param4->len,
830 param5 = g_variant_new_from_data((const GVariantType *)"ay",
831 in_param5->data, in_param5->len,
834 g_dbus_proxy_call_with_unix_fd_list(proxy, "service_request",
835 g_variant_new("(iii@ay@ay@ay@ay@ay)",
836 service_type, service_function,
837 BT_ASYNC_REQ, param1, param2,
838 param3, param4, param5),
839 G_DBUS_CALL_FLAGS_NONE,
840 timeout, fd_list, NULL,
841 __async_req_cb, (gpointer)cb_data);
842 sending_requests = g_slist_append(sending_requests, cb_data);
844 g_array_free(in_param5, TRUE);
851 return BLUETOOTH_ERROR_NONE;
854 int _bt_sync_send_request_with_unix_fd_list(
855 int service_type, int service_function,
856 GArray *in_param1, GArray *in_param2,
857 GArray *in_param3, GArray *in_param4,
858 GUnixFDList *fd_list, GArray **out_param1,
859 GUnixFDList **out_fd_list)
861 int result = BLUETOOTH_ERROR_NONE;
862 GError *error = NULL;
863 GArray *in_param5 = NULL;
873 switch (service_type) {
874 case BT_BLUEZ_SERVICE:
875 case BT_OBEX_SERVICE:
876 case BT_AGENT_SERVICE:
877 case BT_CHECK_PRIVILEGE:
878 proxy = __bt_gdbus_get_service_proxy();
880 return BLUETOOTH_ERROR_INTERNAL;
882 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
884 param1 = g_variant_new_from_data((const GVariantType *)"ay",
885 in_param1->data, in_param1->len,
887 param2 = g_variant_new_from_data((const GVariantType *)"ay",
888 in_param2->data, in_param2->len,
890 param3 = g_variant_new_from_data((const GVariantType *)"ay",
891 in_param3->data, in_param3->len,
893 param4 = g_variant_new_from_data((const GVariantType *)"ay",
894 in_param4->data, in_param4->len,
896 param5 = g_variant_new_from_data((const GVariantType *)"ay",
897 in_param5->data, in_param5->len,
900 ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, "service_request",
901 g_variant_new("(iii@ay@ay@ay@ay@ay)",
902 service_type, service_function,
903 BT_SYNC_REQ, param1, param2,
904 param3, param4, param5),
905 G_DBUS_CALL_FLAGS_NONE, -1,
906 fd_list, out_fd_list, NULL, &error);
907 g_array_free(in_param5, TRUE);
910 /* dBUS-RPC is failed */
911 BT_ERR("dBUS-RPC is failed");
914 /* dBUS gives error cause */
915 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
916 error->code, error->message);
918 g_clear_error(&error);
920 /* dBUS does not give error cause dBUS-RPC is failed */
921 BT_ERR("error returned was NULL");
924 return BLUETOOTH_ERROR_INTERNAL;
928 g_variant_get(ret, "(iv)", &result, ¶m1);
931 *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
932 __bt_fill_garray_from_variant(param1, *out_param1);
933 g_variant_unref(param1);
936 g_variant_unref(ret);
939 BT_ERR("Unknown service type");
940 return BLUETOOTH_ERROR_INTERNAL;