4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dbus/dbus-glib.h>
22 #include <dbus/dbus-glib-lowlevel.h>
23 #include <dbus/dbus.h>
28 #include "bluetooth-api.h"
29 #include "bluetooth-audio-api.h"
30 #include "bt-internal-types.h"
32 #include "bt-common.h"
33 #include "bt-event-handler.h"
34 #include "bt-request-sender.h"
44 static int obex_server_id;
45 static gboolean is_initialized;
46 static GSList *sending_list = NULL;
47 static GSList *server_list = NULL;
48 static GSList *event_list = NULL;
50 void _bt_add_push_request_id(int request_id)
52 bt_sending_info_t *info;
54 info = g_new0(bt_sending_info_t, 1);
55 info->request_id = request_id;
57 sending_list = g_slist_append(sending_list, info);
60 static gboolean __bt_is_request_id_exist(int request_id)
63 bt_sending_info_t *info;
65 for (l = sending_list; l != NULL; l = g_slist_next(l)) {
70 retv_if(info->request_id == request_id, TRUE);
76 static void __bt_remove_push_request_id(int request_id)
79 bt_sending_info_t *info;
81 for (l = sending_list; l != NULL; l = g_slist_next(l)) {
86 if (info->request_id == request_id) {
87 sending_list = g_slist_remove(sending_list, (void *)info);
94 static void __bt_remove_all_push_request_id(void)
97 bt_sending_info_t *info;
99 for (l = sending_list; l != NULL; l = g_slist_next(l)) {
104 g_slist_free(sending_list);
108 static void __bt_remove_all_server(void)
111 bt_server_info_t *info;
113 for (l = server_list; l != NULL; l = g_slist_next(l)) {
118 g_slist_free(server_list);
122 static gboolean __bt_is_server_exist(int server_fd)
125 bt_server_info_t *info;
127 for (l = server_list; l != NULL; l = g_slist_next(l)) {
132 retv_if(info->server_fd == server_fd, TRUE);
138 static void __bt_get_uuid_info(bluetooth_device_info_t *dev_info,
145 ret_if(dev_info == NULL);
146 ret_if(uuids == NULL);
147 ret_if(uuid_count <= 0);
149 dev_info->service_index = uuid_count;
151 for (i = 0; uuids[i] != NULL && i < uuid_count; i++) {
152 g_strlcpy(dev_info->uuids[i], uuids[i], BLUETOOTH_UUID_STRING_MAX);
154 parts = g_strsplit(uuids[i], "-", -1);
156 if (parts == NULL || parts[0] == NULL) {
161 dev_info->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
166 static bluetooth_device_info_t *__bt_get_device_info_in_message(DBusMessage *msg, int *ret)
168 bluetooth_device_info_t *dev_info;
169 char *address = NULL;
172 unsigned int class = 0;
174 gboolean paired = FALSE;
175 gboolean connected = FALSE;
176 gboolean trust = FALSE;
178 int result = BLUETOOTH_ERROR_NONE;
180 if (!dbus_message_get_args(msg, NULL,
181 DBUS_TYPE_INT32, &result,
182 DBUS_TYPE_STRING, &address,
183 DBUS_TYPE_UINT32, &class,
184 DBUS_TYPE_INT16, &rssi,
185 DBUS_TYPE_STRING, &name,
186 DBUS_TYPE_BOOLEAN, &paired,
187 DBUS_TYPE_BOOLEAN, &connected,
188 DBUS_TYPE_BOOLEAN, &trust,
189 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
191 DBUS_TYPE_INVALID)) {
192 BT_ERR("Unexpected parameters in signal");
196 dev_info = g_malloc0(sizeof(bluetooth_device_info_t));
198 dev_info->rssi = rssi;
199 dev_info->paired = paired;
200 dev_info->connected = connected;
201 dev_info->paired = paired;
202 dev_info->trust = trust;
204 g_strlcpy(dev_info->device_name.name, name, BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
206 _bt_divide_device_class(&dev_info->device_class, class);
208 _bt_convert_addr_string_to_type(dev_info->device_address.addr,
212 __bt_get_uuid_info(dev_info, uuids, uuid_count);
219 static DBusHandlerResult __bt_adapter_event_filter(DBusConnection *conn,
220 DBusMessage *msg, void *data)
222 bt_event_info_t *event_info;
223 int result = BLUETOOTH_ERROR_NONE;
224 const char *member = dbus_message_get_member(msg);
226 event_info = (bt_event_info_t *)data;
227 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
229 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
230 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
232 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
233 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
235 if (!dbus_message_has_path(msg, BT_ADAPTER_PATH))
236 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
239 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
241 if (strcasecmp(member, BT_ENABLED) == 0) {
242 if (!dbus_message_get_args(msg, NULL,
243 DBUS_TYPE_INT32, &result,
244 DBUS_TYPE_INVALID)) {
245 BT_ERR("Unexpected parameters in signal");
246 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
249 if (result == BLUETOOTH_ERROR_NONE) {
250 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
251 BT_ERR("Set vconf failed\n");
254 _bt_common_event_cb(BLUETOOTH_EVENT_ENABLED,
256 event_info->cb, event_info->user_data);
257 } else if (strcasecmp(member, BT_DISABLED) == 0) {
258 _bt_common_event_cb(BLUETOOTH_EVENT_DISABLED,
259 BLUETOOTH_ERROR_NONE, NULL,
260 event_info->cb, event_info->user_data);
262 obex_server_id = BT_NO_SERVER;
263 __bt_remove_all_server();
264 __bt_remove_all_push_request_id();
265 } else if (strcasecmp(member, BT_DISCOVERABLE_MODE_CHANGED) == 0) {
268 if (!dbus_message_get_args(msg, NULL,
269 DBUS_TYPE_INT32, &result,
270 DBUS_TYPE_INT16, &mode,
271 DBUS_TYPE_INVALID)) {
272 BT_ERR("Unexpected parameters in signal");
273 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
276 _bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
278 event_info->cb, event_info->user_data);
279 } else if (strcasecmp(member, BT_DISCOVERABLE_TIMEOUT_CHANGED) == 0) {
282 if (!dbus_message_get_args(msg, NULL,
283 DBUS_TYPE_INT32, &result,
284 DBUS_TYPE_INT16, &timeout,
285 DBUS_TYPE_INVALID)) {
286 BT_ERR("Unexpected parameters in signal");
287 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
290 _bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
292 event_info->cb, event_info->user_data);
293 } else if (strcasecmp(member, BT_ADAPTER_NAME_CHANGED) == 0) {
294 char *adapter_name = NULL;
296 if (!dbus_message_get_args(msg, NULL,
297 DBUS_TYPE_INT32, &result,
298 DBUS_TYPE_STRING, &adapter_name,
299 DBUS_TYPE_INVALID)) {
300 BT_ERR("Unexpected parameters in signal");
301 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
304 _bt_common_event_cb(BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
305 result, adapter_name,
306 event_info->cb, event_info->user_data);
307 } else if (strcasecmp(member, BT_DISCOVERY_STARTED) == 0) {
308 _bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERY_STARTED,
309 BLUETOOTH_ERROR_NONE, NULL,
310 event_info->cb, event_info->user_data);
311 } else if (strcasecmp(member, BT_DISCOVERY_FINISHED) == 0) {
312 if (!dbus_message_get_args(msg, NULL,
313 DBUS_TYPE_INT32, &result,
314 DBUS_TYPE_INVALID)) {
315 BT_ERR("Unexpected parameters in signal");
316 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
319 _bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERY_FINISHED,
321 event_info->cb, event_info->user_data);
322 } else if (strcasecmp(member, BT_DEVICE_FOUND) == 0) {
324 bluetooth_device_info_t *device_info;
326 device_info = __bt_get_device_info_in_message(msg, &result);
327 retv_if(device_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
329 if (strlen(device_info->device_name.name) > 0) {
330 event = BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED;
332 event = BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND;
335 _bt_common_event_cb(event,
337 event_info->cb, event_info->user_data);
340 } else if (strcasecmp(member, BT_BOND_CREATED) == 0) {
341 bluetooth_device_info_t *device_info;
343 device_info = __bt_get_device_info_in_message(msg, &result);
345 _bt_common_event_cb(BLUETOOTH_EVENT_BONDING_FINISHED,
347 event_info->cb, event_info->user_data);
350 } else if (strcasecmp(member, BT_BOND_DESTROYED) == 0) {
351 char *address = NULL;
352 bluetooth_device_address_t dev_address = { {0} };
354 if (!dbus_message_get_args(msg, NULL,
355 DBUS_TYPE_INT32, &result,
356 DBUS_TYPE_STRING, &address,
357 DBUS_TYPE_INVALID)) {
358 BT_ERR("Unexpected parameters in signal");
359 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
362 _bt_convert_addr_string_to_type(dev_address.addr,
365 _bt_common_event_cb(BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
366 result, &dev_address,
367 event_info->cb, event_info->user_data);
368 } else if (strcasecmp(member, BT_SERVICE_SEARCHED) == 0) {
369 bluetooth_device_info_t *device_info;
370 bt_sdp_info_t sdp_info;
372 device_info = __bt_get_device_info_in_message(msg, &result);
374 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
376 sdp_info.service_index = device_info->service_index;
378 memcpy(&sdp_info.device_addr,
379 &device_info->device_address,
380 BLUETOOTH_ADDRESS_LENGTH);
382 memcpy(sdp_info.service_list_array,
383 device_info->service_list_array,
384 BLUETOOTH_MAX_SERVICES_FOR_DEVICE);
386 memcpy(sdp_info.uuids,
388 BLUETOOTH_MAX_SERVICES_FOR_DEVICE * BLUETOOTH_UUID_STRING_MAX);
390 _bt_common_event_cb(BLUETOOTH_EVENT_SERVICE_SEARCHED,
392 event_info->cb, event_info->user_data);
397 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
400 static DBusHandlerResult __bt_device_event_filter(DBusConnection *conn,
401 DBusMessage *msg, void *data)
403 bt_event_info_t *event_info;
404 int result = BLUETOOTH_ERROR_NONE;
405 const char *member = dbus_message_get_member(msg);
407 event_info = (bt_event_info_t *)data;
408 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
410 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
411 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
413 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
414 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
416 if (!dbus_message_has_path(msg, BT_DEVICE_PATH))
417 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
420 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
422 if (strcasecmp(member, BT_DEVICE_CONNECTED) == 0) {
423 char *address = NULL;
424 bluetooth_device_address_t dev_address = { {0} };
426 if (!dbus_message_get_args(msg, NULL,
427 DBUS_TYPE_INT32, &result,
428 DBUS_TYPE_STRING, &address,
429 DBUS_TYPE_INVALID)) {
430 BT_DBG("Unexpected parameters in signal");
431 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
434 _bt_convert_addr_string_to_type(dev_address.addr,
437 _bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_CONNECTED,
438 result, &dev_address,
439 event_info->cb, event_info->user_data);
440 } else if (strcasecmp(member, BT_DEVICE_DISCONNECTED) == 0) {
441 char *address = NULL;
442 bluetooth_device_address_t dev_address = { {0} };
444 if (!dbus_message_get_args(msg, NULL,
445 DBUS_TYPE_INT32, &result,
446 DBUS_TYPE_STRING, &address,
447 DBUS_TYPE_INVALID)) {
448 BT_DBG("Unexpected parameters in signal");
449 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
452 _bt_convert_addr_string_to_type(dev_address.addr,
455 _bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
456 result, &dev_address,
457 event_info->cb, event_info->user_data);
460 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
463 static DBusHandlerResult __bt_hid_event_filter(DBusConnection *conn,
464 DBusMessage *msg, void *data)
466 bt_event_info_t *event_info;
467 int result = BLUETOOTH_ERROR_NONE;
468 const char *member = dbus_message_get_member(msg);
470 event_info = (bt_event_info_t *)data;
471 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
473 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
474 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
476 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
477 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
479 if (!dbus_message_has_path(msg, BT_HID_PATH))
480 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
482 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
484 if (strcasecmp(member, BT_INPUT_CONNECTED) == 0) {
485 char *address = NULL;
486 bluetooth_device_address_t dev_address = { {0} };
488 if (!dbus_message_get_args(msg, NULL,
489 DBUS_TYPE_INT32, &result,
490 DBUS_TYPE_STRING, &address,
491 DBUS_TYPE_INVALID)) {
492 BT_DBG("Unexpected parameters in signal");
493 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
496 _bt_convert_addr_string_to_type(dev_address.addr,
499 _bt_input_event_cb(BLUETOOTH_HID_CONNECTED,
500 result, &dev_address,
501 event_info->cb, event_info->user_data);
502 } else if (strcasecmp(member, BT_INPUT_DISCONNECTED) == 0) {
503 char *address = NULL;
504 bluetooth_device_address_t dev_address = { {0} };
506 if (!dbus_message_get_args(msg, NULL,
507 DBUS_TYPE_INT32, &result,
508 DBUS_TYPE_STRING, &address,
509 DBUS_TYPE_INVALID)) {
510 BT_DBG("Unexpected parameters in signal");
511 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
514 BT_DBG("address: %s", address);
516 _bt_convert_addr_string_to_type(dev_address.addr,
519 _bt_input_event_cb(BLUETOOTH_HID_DISCONNECTED,
520 result, &dev_address,
521 event_info->cb, event_info->user_data);
524 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
527 static DBusHandlerResult __bt_headset_event_filter(DBusConnection *conn,
528 DBusMessage *msg, void *data)
530 bt_event_info_t *event_info;
531 int result = BLUETOOTH_ERROR_NONE;
532 const char *member = dbus_message_get_member(msg);
534 event_info = (bt_event_info_t *)data;
535 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
537 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
538 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
540 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
541 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
543 if (!dbus_message_has_path(msg, BT_HEADSET_PATH))
544 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
546 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
548 if (strcasecmp(member, BT_HEADSET_CONNECTED) == 0) {
549 char *address = NULL;
551 if (!dbus_message_get_args(msg, NULL,
552 DBUS_TYPE_INT32, &result,
553 DBUS_TYPE_STRING, &address,
554 DBUS_TYPE_INVALID)) {
555 BT_ERR("Unexpected parameters in signal");
556 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
559 _bt_headset_event_cb(BLUETOOTH_EVENT_AG_CONNECTED,
561 event_info->cb, event_info->user_data);
562 } else if (strcasecmp(member, BT_HEADSET_DISCONNECTED) == 0) {
563 char *address = NULL;
565 if (!dbus_message_get_args(msg, NULL,
566 DBUS_TYPE_INT32, &result,
567 DBUS_TYPE_STRING, &address,
568 DBUS_TYPE_INVALID)) {
569 BT_ERR("Unexpected parameters in signal");
570 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
573 _bt_headset_event_cb(BLUETOOTH_EVENT_AG_DISCONNECTED,
575 event_info->cb, event_info->user_data);
576 } else if (strcasecmp(member, BT_STEREO_HEADSET_CONNECTED) == 0) {
577 char *address = NULL;
579 if (!dbus_message_get_args(msg, NULL,
580 DBUS_TYPE_INT32, &result,
581 DBUS_TYPE_STRING, &address,
582 DBUS_TYPE_INVALID)) {
583 BT_ERR("Unexpected parameters in signal");
584 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
587 _bt_headset_event_cb(BLUETOOTH_EVENT_AV_CONNECTED,
589 event_info->cb, event_info->user_data);
590 } else if (strcasecmp(member, BT_STEREO_HEADSET_DISCONNECTED) == 0) {
591 char *address = NULL;
593 if (!dbus_message_get_args(msg, NULL,
594 DBUS_TYPE_INT32, &result,
595 DBUS_TYPE_STRING, &address,
596 DBUS_TYPE_INVALID)) {
597 BT_ERR("Unexpected parameters in signal");
598 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
601 _bt_headset_event_cb(BLUETOOTH_EVENT_AV_DISCONNECTED,
603 event_info->cb, event_info->user_data);
604 } else if (strcasecmp(member, BT_SCO_CONNECTED) == 0) {
605 char *address = NULL;
606 bluetooth_device_address_t dev_address = { {0} };
608 if (!dbus_message_get_args(msg, NULL,
609 DBUS_TYPE_INT32, &result,
610 DBUS_TYPE_STRING, &address,
611 DBUS_TYPE_INVALID)) {
612 BT_ERR("Unexpected parameters in signal");
613 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
616 _bt_convert_addr_string_to_type(dev_address.addr,
619 _bt_headset_event_cb(BLUETOOTH_EVENT_AG_AUDIO_CONNECTED,
620 result, &dev_address,
621 event_info->cb, event_info->user_data);
622 } else if (strcasecmp(member, BT_SCO_DISCONNECTED) == 0) {
623 char *address = NULL;
624 bluetooth_device_address_t dev_address = { {0} };
626 if (!dbus_message_get_args(msg, NULL,
627 DBUS_TYPE_INT32, &result,
628 DBUS_TYPE_STRING, &address,
629 DBUS_TYPE_INVALID)) {
630 BT_ERR("Unexpected parameters in signal");
631 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
634 _bt_convert_addr_string_to_type(dev_address.addr,
637 _bt_headset_event_cb(BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED,
638 result, &dev_address,
639 event_info->cb, event_info->user_data);
640 } else if (strcasecmp(member, BT_SPEAKER_GAIN) == 0) {
643 char *address = NULL;
645 if (!dbus_message_get_args(msg, NULL,
646 DBUS_TYPE_INT32, &result,
647 DBUS_TYPE_STRING, &address,
648 DBUS_TYPE_UINT16, &spkr_gain,
649 DBUS_TYPE_INVALID)) {
650 BT_ERR("Unexpected parameters in signal");
651 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
653 gain = (unsigned int)spkr_gain;
655 _bt_headset_event_cb(BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
657 event_info->cb, event_info->user_data);
658 } else if (strcasecmp(member, BT_MICROPHONE_GAIN) == 0) {
661 char *address = NULL;
663 if (!dbus_message_get_args(msg, NULL,
664 DBUS_TYPE_INT32, &result,
665 DBUS_TYPE_STRING, &address,
666 DBUS_TYPE_UINT16, &mic_gain,
667 DBUS_TYPE_INVALID)) {
668 BT_ERR("Unexpected parameters in signal");
669 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
671 gain = (unsigned int)mic_gain;
673 _bt_headset_event_cb(BLUETOOTH_EVENT_AG_MIC_GAIN,
675 event_info->cb, event_info->user_data);
678 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
681 static DBusHandlerResult __bt_network_event_filter(DBusConnection *conn,
682 DBusMessage *msg, void *data)
684 bt_event_info_t *event_info;
685 int result = BLUETOOTH_ERROR_NONE;
686 const char *member = dbus_message_get_member(msg);
688 event_info = (bt_event_info_t *)data;
689 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
691 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
692 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
694 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
695 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
697 if (!dbus_message_has_path(msg, BT_NETWORK_PATH))
698 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
700 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
702 if (strcasecmp(member, BT_NETWORK_CONNECTED) == 0) {
703 char *address = NULL;
704 bluetooth_device_address_t dev_address = { {0} };
706 if (!dbus_message_get_args(msg, NULL,
707 DBUS_TYPE_INT32, &result,
708 DBUS_TYPE_STRING, &address,
709 DBUS_TYPE_INVALID)) {
710 BT_ERR("Unexpected parameters in signal");
711 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
714 _bt_convert_addr_string_to_type(dev_address.addr,
717 _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_CONNECTED,
718 result, &dev_address,
719 event_info->cb, event_info->user_data);
720 } else if (strcasecmp(member, BT_NETWORK_DISCONNECTED) == 0) {
721 char *address = NULL;
722 bluetooth_device_address_t dev_address = { {0} };
724 if (!dbus_message_get_args(msg, NULL,
725 DBUS_TYPE_INT32, &result,
726 DBUS_TYPE_STRING, &address,
727 DBUS_TYPE_INVALID)) {
728 BT_ERR("Unexpected parameters in signal");
729 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
732 _bt_convert_addr_string_to_type(dev_address.addr,
735 _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_DISCONNECTED,
736 result, &dev_address,
737 event_info->cb, event_info->user_data);
738 } else if (strcasecmp(member, BT_NETWORK_SERVER_CONNECTED) == 0) {
740 char *address = NULL;
741 bluetooth_network_device_info_t network_info;
743 if (!dbus_message_get_args(msg, NULL,
744 DBUS_TYPE_INT32, &result,
745 DBUS_TYPE_STRING, &device,
746 DBUS_TYPE_STRING, &address,
747 DBUS_TYPE_INVALID)) {
748 BT_ERR("Unexpected parameters in signal");
749 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
752 memset(&network_info, 0x00, sizeof(bluetooth_network_device_info_t));
754 _bt_convert_addr_string_to_type(network_info.device_address.addr,
757 _bt_print_device_address_t(&network_info.device_address);
758 g_strlcpy(network_info.interface_name, device, BLUETOOTH_INTERFACE_NAME_LENGTH);
760 BT_DBG("name: %s", network_info.interface_name);
762 _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
763 result, &network_info,
764 event_info->cb, event_info->user_data);
765 } else if (strcasecmp(member, BT_NETWORK_SERVER_DISCONNECTED) == 0) {
767 char *address = NULL;
768 bluetooth_network_device_info_t network_info;
770 if (!dbus_message_get_args(msg, NULL,
771 DBUS_TYPE_INT32, &result,
772 DBUS_TYPE_STRING, &device,
773 DBUS_TYPE_STRING, &address,
774 DBUS_TYPE_INVALID)) {
775 BT_ERR("Unexpected parameters in signal");
776 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
779 memset(&network_info, 0x00, sizeof(bluetooth_network_device_info_t));
781 _bt_convert_addr_string_to_type(network_info.device_address.addr,
784 _bt_print_device_address_t(&network_info.device_address);
786 _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
787 result, &network_info,
788 event_info->cb, event_info->user_data);
792 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
795 static DBusHandlerResult __bt_avrcp_event_filter(DBusConnection *conn,
796 DBusMessage *msg, void *data)
798 bt_event_info_t *event_info;
799 int result = BLUETOOTH_ERROR_NONE;
800 const char *member = dbus_message_get_member(msg);
802 event_info = (bt_event_info_t *)data;
803 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
805 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
806 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
808 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
809 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
811 if (!dbus_message_has_path(msg, BT_AVRCP_PATH))
812 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
814 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
816 if (strcasecmp(member, BT_STEREO_HEADSET_CONNECTED) == 0) {
817 char *address = NULL;
819 if (!dbus_message_get_args(msg, NULL,
820 DBUS_TYPE_INT32, &result,
821 DBUS_TYPE_STRING, &address,
822 DBUS_TYPE_INVALID)) {
823 BT_ERR("Unexpected parameters in signal");
824 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
827 _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONNECTED,
829 event_info->cb, event_info->user_data);
830 } else if (strcasecmp(member, BT_STEREO_HEADSET_DISCONNECTED) == 0) {
831 char *address = NULL;
833 if (!dbus_message_get_args(msg, NULL,
834 DBUS_TYPE_INT32, &result,
835 DBUS_TYPE_STRING, &address,
836 DBUS_TYPE_INVALID)) {
837 BT_ERR("Unexpected parameters in signal");
838 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
841 _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_DISCONNECTED,
843 event_info->cb, event_info->user_data);
844 } else if (strcasecmp(member, BT_MEDIA_SHUFFLE_STATUS) == 0) {
846 if (!dbus_message_get_args(msg, NULL,
847 DBUS_TYPE_UINT32, &status,
848 DBUS_TYPE_INVALID)) {
849 BT_ERR("Unexpected parameters in signal");
850 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
852 _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS,
854 event_info->cb, event_info->user_data);
855 } else if (strcasecmp(member, BT_MEDIA_EQUALIZER_STATUS) == 0) {
857 if (!dbus_message_get_args(msg, NULL,
858 DBUS_TYPE_UINT32, &status,
859 DBUS_TYPE_INVALID)) {
860 BT_ERR("Unexpected parameters in signal");
861 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
863 _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS,
865 event_info->cb, event_info->user_data);
866 } else if (strcasecmp(member, BT_MEDIA_REPEAT_STATUS) == 0) {
868 if (!dbus_message_get_args(msg, NULL,
869 DBUS_TYPE_UINT32, &status,
870 DBUS_TYPE_INVALID)) {
871 BT_ERR("Unexpected parameters in signal");
872 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
874 _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS,
876 event_info->cb, event_info->user_data);
877 } else if (strcasecmp(member, BT_MEDIA_SCAN_STATUS) == 0) {
879 if (!dbus_message_get_args(msg, NULL,
880 DBUS_TYPE_UINT32, &status,
881 DBUS_TYPE_INVALID)) {
882 BT_ERR("Unexpected parameters in signal");
883 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
885 _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS,
887 event_info->cb, event_info->user_data);
890 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
893 static DBusHandlerResult __bt_opp_client_event_filter(DBusConnection *conn,
894 DBusMessage *msg, void *data)
896 bt_event_info_t *event_info;
897 int result = BLUETOOTH_ERROR_NONE;
898 const char *member = dbus_message_get_member(msg);
900 event_info = (bt_event_info_t *)data;
901 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
903 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
904 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
906 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
907 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
909 if (!dbus_message_has_path(msg, BT_OPP_CLIENT_PATH))
910 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
912 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
914 if (strcasecmp(member, BT_OPP_CONNECTED) == 0) {
915 char *address = NULL;
917 bluetooth_device_address_t dev_address = { {0} };
919 if (!dbus_message_get_args(msg, NULL,
920 DBUS_TYPE_INT32, &result,
921 DBUS_TYPE_STRING, &address,
922 DBUS_TYPE_INT32, &request_id,
923 DBUS_TYPE_INVALID)) {
924 BT_ERR("Unexpected parameters in signal");
925 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
928 if (__bt_is_request_id_exist(request_id) == FALSE) {
929 BT_ERR("Different request id!");
930 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
933 _bt_convert_addr_string_to_type(dev_address.addr,
936 _bt_common_event_cb(BLUETOOTH_EVENT_OPC_CONNECTED,
937 result, &dev_address,
938 event_info->cb, event_info->user_data);
940 if (result != BLUETOOTH_ERROR_NONE) {
941 __bt_remove_push_request_id(request_id);
943 } else if (strcasecmp(member, BT_OPP_DISCONNECTED) == 0) {
944 char *address = NULL;
946 bluetooth_device_address_t dev_address = { {0} };
948 if (!dbus_message_get_args(msg, NULL,
949 DBUS_TYPE_INT32, &result,
950 DBUS_TYPE_STRING, &address,
951 DBUS_TYPE_INT32, &request_id,
952 DBUS_TYPE_INVALID)) {
953 BT_ERR("Unexpected parameters in signal");
954 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
957 if (__bt_is_request_id_exist(request_id) == FALSE) {
958 BT_ERR("Different request id!");
959 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
962 _bt_convert_addr_string_to_type(dev_address.addr,
965 _bt_common_event_cb(BLUETOOTH_EVENT_OPC_DISCONNECTED,
966 result, &dev_address,
967 event_info->cb, event_info->user_data);
969 __bt_remove_push_request_id(request_id);
970 } else if (strcasecmp(member, BT_TRANSFER_STARTED) == 0) {
971 char *file_name = NULL;
974 bt_opc_transfer_info_t transfer_info;
976 if (!dbus_message_get_args(msg, NULL,
977 DBUS_TYPE_INT32, &result,
978 DBUS_TYPE_STRING, &file_name,
979 DBUS_TYPE_UINT64, &size,
980 DBUS_TYPE_INT32, &request_id,
981 DBUS_TYPE_INVALID)) {
982 BT_ERR("Unexpected parameters in signal");
983 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
986 if (__bt_is_request_id_exist(request_id) == FALSE) {
987 BT_ERR("Different request id!");
988 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
991 memset(&transfer_info, 0x00, sizeof(bt_opc_transfer_info_t));
993 transfer_info.filename = g_strdup(file_name);
994 transfer_info.size = size;
996 _bt_common_event_cb(BLUETOOTH_EVENT_OPC_TRANSFER_STARTED,
997 result, &transfer_info,
998 event_info->cb, event_info->user_data);
1000 g_free(transfer_info.filename);
1001 } else if (strcasecmp(member, BT_TRANSFER_PROGRESS) == 0) {
1002 char *file_name = NULL;
1006 bt_opc_transfer_info_t transfer_info;
1008 if (!dbus_message_get_args(msg, NULL,
1009 DBUS_TYPE_INT32, &result,
1010 DBUS_TYPE_STRING, &file_name,
1011 DBUS_TYPE_UINT64, &size,
1012 DBUS_TYPE_INT32, &progress,
1013 DBUS_TYPE_INT32, &request_id,
1014 DBUS_TYPE_INVALID)) {
1015 BT_ERR("Unexpected parameters in signal");
1016 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1019 if (__bt_is_request_id_exist(request_id) == FALSE) {
1020 BT_ERR("Different request id!");
1021 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1024 memset(&transfer_info, 0x00, sizeof(bt_opc_transfer_info_t));
1026 transfer_info.filename = g_strdup(file_name);
1027 transfer_info.size = size;
1028 transfer_info.percentage = progress;
1030 _bt_common_event_cb(BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS,
1031 result, &transfer_info,
1032 event_info->cb, event_info->user_data);
1034 g_free(transfer_info.filename);
1035 } else if (strcasecmp(member, BT_TRANSFER_COMPLETED) == 0) {
1036 char *file_name = NULL;
1039 bt_opc_transfer_info_t transfer_info;
1041 if (!dbus_message_get_args(msg, NULL,
1042 DBUS_TYPE_INT32, &result,
1043 DBUS_TYPE_STRING, &file_name,
1044 DBUS_TYPE_UINT64, &size,
1045 DBUS_TYPE_INT32, &request_id,
1046 DBUS_TYPE_INVALID)) {
1047 BT_ERR("Unexpected parameters in signal");
1048 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1051 if (__bt_is_request_id_exist(request_id) == FALSE) {
1052 BT_ERR("Different request id!");
1053 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1056 memset(&transfer_info, 0x00, sizeof(bt_opc_transfer_info_t));
1058 transfer_info.filename = g_strdup(file_name);
1059 transfer_info.size = size;
1061 _bt_common_event_cb(BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE,
1062 result, &transfer_info,
1063 event_info->cb, event_info->user_data);
1065 g_free(transfer_info.filename);
1068 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1071 static DBusHandlerResult __bt_opp_server_event_filter(DBusConnection *conn,
1072 DBusMessage *msg, void *data)
1074 bt_event_info_t *event_info;
1075 int result = BLUETOOTH_ERROR_NONE;
1076 const char *member = dbus_message_get_member(msg);
1078 event_info = (bt_event_info_t *)data;
1079 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1081 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
1082 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1084 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
1085 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1087 if (!dbus_message_has_path(msg, BT_OPP_SERVER_PATH))
1088 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1090 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1092 if (strcasecmp(member, BT_TRANSFER_AUTHORIZED) == 0) {
1093 /* Native only event */
1094 char *file_name = NULL;
1096 bt_obex_server_authorize_into_t auth_info;
1098 if (!dbus_message_get_args(msg, NULL,
1099 DBUS_TYPE_INT32, &result,
1100 DBUS_TYPE_STRING, &file_name,
1101 DBUS_TYPE_UINT64, &size,
1102 DBUS_TYPE_INVALID)) {
1103 BT_ERR("Unexpected parameters in signal");
1104 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1107 /* OSP server: Don't get this event */
1108 retv_if(obex_server_id == BT_CUSTOM_SERVER,
1109 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1111 memset(&auth_info, 0x00, sizeof(bt_obex_server_authorize_into_t));
1113 auth_info.filename = g_strdup(file_name);
1114 auth_info.length = size;
1116 _bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE,
1118 event_info->cb, event_info->user_data);
1120 g_free(auth_info.filename);
1121 } else if (strcasecmp(member, BT_CONNECTION_AUTHORIZED) == 0) {
1122 /* OSP only event */
1123 char *address = NULL;
1125 bluetooth_device_address_t dev_address = { {0} };
1127 if (!dbus_message_get_args(msg, NULL,
1128 DBUS_TYPE_INT32, &result,
1129 DBUS_TYPE_STRING, &address,
1130 DBUS_TYPE_STRING, &name,
1131 DBUS_TYPE_INVALID)) {
1132 BT_ERR("Unexpected parameters in signal");
1133 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1136 /* Native server: Don't get this event */
1137 retv_if(obex_server_id == BT_NATIVE_SERVER,
1138 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1140 _bt_convert_addr_string_to_type(dev_address.addr,
1143 _bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
1144 result, &dev_address,
1145 event_info->cb, event_info->user_data);
1146 } else if (strcasecmp(member, BT_TRANSFER_STARTED) == 0) {
1147 char *file_name = NULL;
1149 int transfer_id = 0;
1150 int server_type = 0; /* bt_server_type_t */
1152 bt_obex_server_transfer_info_t transfer_info;
1154 if (!dbus_message_get_args(msg, NULL,
1155 DBUS_TYPE_INT32, &result,
1156 DBUS_TYPE_STRING, &file_name,
1157 DBUS_TYPE_STRING, &type,
1158 DBUS_TYPE_UINT64, &size,
1159 DBUS_TYPE_INT32, &transfer_id,
1160 DBUS_TYPE_INT32, &server_type,
1161 DBUS_TYPE_INVALID)) {
1162 BT_ERR("Unexpected parameters in signal");
1163 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1166 /* Other server's event */
1167 retv_if(obex_server_id != server_type &&
1168 server_type != BT_FTP_SERVER,
1169 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1171 memset(&transfer_info, 0x00, sizeof(bt_obex_server_transfer_info_t));
1173 transfer_info.filename = g_strdup(file_name);
1174 transfer_info.type = g_strdup(type);
1175 transfer_info.file_size = size;
1176 transfer_info.transfer_id = transfer_id;
1178 _bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
1179 result, &transfer_info,
1180 event_info->cb, event_info->user_data);
1182 g_free(transfer_info.filename);
1183 g_free(transfer_info.type);
1184 } else if (strcasecmp(member, BT_TRANSFER_PROGRESS) == 0) {
1185 char *file_name = NULL;
1187 int transfer_id = 0;
1189 int server_type = 0; /* bt_server_type_t */
1191 bt_obex_server_transfer_info_t transfer_info;
1193 if (!dbus_message_get_args(msg, NULL,
1194 DBUS_TYPE_INT32, &result,
1195 DBUS_TYPE_STRING, &file_name,
1196 DBUS_TYPE_STRING, &type,
1197 DBUS_TYPE_UINT64, &size,
1198 DBUS_TYPE_INT32, &transfer_id,
1199 DBUS_TYPE_INT32, &progress,
1200 DBUS_TYPE_INT32, &server_type,
1201 DBUS_TYPE_INVALID)) {
1202 BT_ERR("Unexpected parameters in signal");
1203 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1206 /* Other server's event */
1207 retv_if(obex_server_id != server_type &&
1208 server_type != BT_FTP_SERVER,
1209 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1211 memset(&transfer_info, 0x00, sizeof(bt_obex_server_transfer_info_t));
1213 transfer_info.filename = g_strdup(file_name);
1214 transfer_info.type = g_strdup(type);
1215 transfer_info.file_size = size;
1216 transfer_info.transfer_id = transfer_id;
1217 transfer_info.percentage = progress;
1219 _bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
1220 result, &transfer_info,
1221 event_info->cb, event_info->user_data);
1223 g_free(transfer_info.filename);
1224 g_free(transfer_info.type);
1225 } else if (strcasecmp(member, BT_TRANSFER_COMPLETED) == 0) {
1226 char *file_name = NULL;
1227 char *device_name = NULL;
1229 int transfer_id = 0;
1230 int server_type = 0; /* bt_server_type_t */
1232 bt_obex_server_transfer_info_t transfer_info;
1234 if (!dbus_message_get_args(msg, NULL,
1235 DBUS_TYPE_INT32, &result,
1236 DBUS_TYPE_STRING, &file_name,
1237 DBUS_TYPE_STRING, &type,
1238 DBUS_TYPE_STRING, &device_name,
1239 DBUS_TYPE_UINT64, &size,
1240 DBUS_TYPE_INT32, &transfer_id,
1241 DBUS_TYPE_INT32, &server_type,
1242 DBUS_TYPE_INVALID)) {
1243 BT_ERR("Unexpected parameters in signal");
1244 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1247 /* Other server's event */
1248 retv_if(obex_server_id != server_type &&
1249 server_type != BT_FTP_SERVER,
1250 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1252 memset(&transfer_info, 0x00, sizeof(bt_obex_server_transfer_info_t));
1254 transfer_info.filename = g_strdup(file_name);
1255 transfer_info.type = g_strdup(type);
1256 transfer_info.device_name = g_strdup(device_name);
1257 transfer_info.file_size = size;
1258 transfer_info.transfer_id = transfer_id;
1260 _bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
1261 result, &transfer_info,
1262 event_info->cb, event_info->user_data);
1264 g_free(transfer_info.filename);
1265 g_free(transfer_info.type);
1266 g_free(transfer_info.device_name);
1269 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1272 static DBusHandlerResult __bt_rfcomm_client_event_filter(DBusConnection *conn,
1273 DBusMessage *msg, void *data)
1275 bt_event_info_t *event_info;
1276 int result = BLUETOOTH_ERROR_NONE;
1277 const char *member = dbus_message_get_member(msg);
1279 event_info = (bt_event_info_t *)data;
1280 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1282 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
1283 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1285 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
1286 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1288 if (!dbus_message_has_path(msg, BT_RFCOMM_CLIENT_PATH))
1289 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1291 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1293 if (strcasecmp(member, BT_RFCOMM_CONNECTED) == 0) {
1294 char *address = NULL;
1297 bluetooth_rfcomm_connection_t conn_info;
1299 if (!dbus_message_get_args(msg, NULL,
1300 DBUS_TYPE_INT32, &result,
1301 DBUS_TYPE_STRING, &address,
1302 DBUS_TYPE_STRING, &uuid,
1303 DBUS_TYPE_INT16, &socket_fd,
1304 DBUS_TYPE_INVALID)) {
1305 BT_ERR("Unexpected parameters in signal");
1306 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1309 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1310 conn_info.device_role = RFCOMM_ROLE_CLIENT;
1311 g_strlcpy(conn_info.uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1312 conn_info.socket_fd = socket_fd;
1313 _bt_convert_addr_string_to_type(conn_info.device_addr.addr,
1316 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
1318 event_info->cb, event_info->user_data);
1319 } else if (strcasecmp(member, BT_RFCOMM_DISCONNECTED) == 0) {
1320 char *address = NULL;
1323 bluetooth_rfcomm_disconnection_t disconn_info;
1325 if (!dbus_message_get_args(msg, NULL,
1326 DBUS_TYPE_INT32, &result,
1327 DBUS_TYPE_STRING, &address,
1328 DBUS_TYPE_STRING, &uuid,
1329 DBUS_TYPE_INT16, &socket_fd,
1330 DBUS_TYPE_INVALID)) {
1331 BT_ERR("Unexpected parameters in signal");
1332 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1335 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
1336 disconn_info.device_role = RFCOMM_ROLE_CLIENT;
1337 g_strlcpy(disconn_info.uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1338 disconn_info.socket_fd = socket_fd;
1339 _bt_convert_addr_string_to_type(disconn_info.device_addr.addr,
1342 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
1343 result, &disconn_info,
1344 event_info->cb, event_info->user_data);
1345 } else if (strcasecmp(member, BT_RFCOMM_DATA_RECEIVED) == 0) {
1346 char *buffer = NULL;
1349 bluetooth_rfcomm_received_data_t data_r;
1351 if (!dbus_message_get_args(msg, NULL,
1352 DBUS_TYPE_INT32, &result,
1353 DBUS_TYPE_INT16, &socket_fd,
1354 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
1355 &buffer, &buffer_len,
1356 DBUS_TYPE_INVALID)) {
1357 BT_ERR("Unexpected parameters in signal");
1358 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1361 data_r.socket_fd = socket_fd;
1362 data_r.buffer_size = buffer_len;
1363 data_r.buffer = g_memdup(buffer, buffer_len);
1365 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
1367 event_info->cb, event_info->user_data);
1369 g_free(data_r.buffer);
1372 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1375 static DBusHandlerResult __bt_rfcomm_server_event_filter(DBusConnection *conn,
1376 DBusMessage *msg, void *data)
1378 bt_event_info_t *event_info;
1379 int result = BLUETOOTH_ERROR_NONE;
1380 const char *member = dbus_message_get_member(msg);
1382 event_info = (bt_event_info_t *)data;
1383 retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1385 if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
1386 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1388 if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
1389 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1391 if (!dbus_message_has_path(msg, BT_RFCOMM_SERVER_PATH))
1392 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1394 retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1396 if (strcasecmp(member, BT_RFCOMM_CONNECTED) == 0) {
1397 char *address = NULL;
1400 bluetooth_rfcomm_connection_t conn_info;
1402 if (!dbus_message_get_args(msg, NULL,
1403 DBUS_TYPE_INT32, &result,
1404 DBUS_TYPE_STRING, &address,
1405 DBUS_TYPE_STRING, &uuid,
1406 DBUS_TYPE_INT16, &socket_fd,
1407 DBUS_TYPE_INVALID)) {
1408 BT_ERR("Unexpected parameters in signal");
1409 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1412 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1413 conn_info.device_role = RFCOMM_ROLE_SERVER;
1414 g_strlcpy(conn_info.uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1415 conn_info.socket_fd = socket_fd;
1416 _bt_convert_addr_string_to_type(conn_info.device_addr.addr,
1419 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
1421 event_info->cb, event_info->user_data);
1422 } else if (strcasecmp(member, BT_RFCOMM_DISCONNECTED) == 0) {
1423 char *address = NULL;
1426 bluetooth_rfcomm_disconnection_t disconn_info;
1428 if (!dbus_message_get_args(msg, NULL,
1429 DBUS_TYPE_INT32, &result,
1430 DBUS_TYPE_STRING, &address,
1431 DBUS_TYPE_STRING, &uuid,
1432 DBUS_TYPE_INT16, &socket_fd,
1433 DBUS_TYPE_INVALID)) {
1434 BT_ERR("Unexpected parameters in signal");
1435 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1438 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
1439 disconn_info.device_role = RFCOMM_ROLE_SERVER;
1440 g_strlcpy(disconn_info.uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1441 disconn_info.socket_fd = socket_fd;
1442 _bt_convert_addr_string_to_type(disconn_info.device_addr.addr,
1445 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
1446 result, &disconn_info,
1447 event_info->cb, event_info->user_data);
1448 } else if (strcasecmp(member, BT_CONNECTION_AUTHORIZED) == 0) {
1449 /* OSP only event */
1450 bluetooth_rfcomm_connection_request_t req_ind;
1451 char *address = NULL;
1456 if (!dbus_message_get_args(msg, NULL,
1457 DBUS_TYPE_INT32, &result,
1458 DBUS_TYPE_STRING, &address,
1459 DBUS_TYPE_STRING, &uuid,
1460 DBUS_TYPE_STRING, &name,
1461 DBUS_TYPE_INT16, &socket_fd,
1462 DBUS_TYPE_INVALID)) {
1463 BT_ERR("Unexpected parameters in signal");
1464 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1467 /* Don't send the authorized event to other server */
1468 retv_if(__bt_is_server_exist(socket_fd) == FALSE,
1469 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1471 memset(&req_ind, 0x00, sizeof(bluetooth_rfcomm_connection_request_t));
1472 _bt_convert_addr_string_to_type(req_ind.device_addr.addr,
1475 req_ind.socket_fd = socket_fd;
1477 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
1479 event_info->cb, event_info->user_data);
1480 } else if (strcasecmp(member, BT_RFCOMM_SERVER_REMOVED) == 0) {
1481 /* OSP only event */
1484 if (!dbus_message_get_args(msg, NULL,
1485 DBUS_TYPE_INT32, &result,
1486 DBUS_TYPE_INT16, &socket_fd,
1487 DBUS_TYPE_INVALID)) {
1488 BT_ERR("Unexpected parameters in signal");
1489 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1492 retv_if(__bt_is_server_exist(socket_fd) == FALSE,
1493 DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
1495 _bt_remove_server(socket_fd);
1496 } else if (strcasecmp(member, BT_RFCOMM_DATA_RECEIVED) == 0) {
1497 char *buffer = NULL;
1500 bluetooth_rfcomm_received_data_t data_r;
1502 if (!dbus_message_get_args(msg, NULL,
1503 DBUS_TYPE_INT32, &result,
1504 DBUS_TYPE_INT16, &socket_fd,
1505 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
1506 &buffer, &buffer_len,
1507 DBUS_TYPE_INVALID)) {
1508 BT_ERR("Unexpected parameters in signal");
1509 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1512 data_r.socket_fd = socket_fd;
1513 data_r.buffer_size = buffer_len;
1514 data_r.buffer = g_memdup(buffer, buffer_len);
1516 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
1518 event_info->cb, event_info->user_data);
1520 g_free(data_r.buffer);
1523 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1526 static void __bt_remove_all_events(void)
1529 bt_event_info_t *info;
1531 for (l = event_list; l != NULL; l = g_slist_next(l)) {
1535 _bt_unregister_event(info->event_type);
1538 g_slist_free(event_list);
1542 static gboolean __bt_event_is_registered(int event_type)
1545 bt_event_info_t *info;
1547 for (l = event_list; l != NULL; l = g_slist_next(l)) {
1552 retv_if(info->event_type == event_type, TRUE);
1558 bt_event_info_t* __bt_event_get_cb_data(int event_type)
1561 bt_event_info_t *info;
1563 for (l = event_list; l != NULL; l = g_slist_next(l)) {
1568 if (info->event_type == event_type)
1575 void _bt_add_server(int server_fd)
1577 bt_server_info_t *info;
1579 info = g_new0(bt_server_info_t, 1);
1580 info->server_fd = server_fd;
1582 server_list = g_slist_append(server_list, info);
1585 void _bt_remove_server(int server_fd)
1588 bt_server_info_t *info;
1590 for (l = server_list; l != NULL; l = g_slist_next(l)) {
1595 if (info->server_fd == server_fd) {
1596 server_list = g_slist_remove(server_list, (void *)info);
1603 void _bt_set_obex_server_id(int server_type)
1605 obex_server_id = server_type;
1608 int _bt_get_obex_server_id(void)
1610 return obex_server_id;
1613 int _bt_init_event_handler(void)
1615 if (is_initialized == TRUE) {
1616 BT_ERR("Connection already exist");
1617 return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
1620 __bt_remove_all_events();
1622 is_initialized = TRUE;
1624 return BLUETOOTH_ERROR_NONE;
1627 int _bt_deinit_event_handler(void)
1629 if (is_initialized == FALSE) {
1630 BT_ERR("Connection dose not exist");
1631 return BLUETOOTH_ERROR_INTERNAL;
1634 __bt_remove_all_events();
1636 is_initialized = FALSE;
1638 return BLUETOOTH_ERROR_NONE;
1641 static void __bt_event_data_free(void *data)
1643 bt_event_info_t *cb_data = data;
1645 ret_if(cb_data == NULL);
1648 dbus_connection_unref(cb_data->conn);
1653 int _bt_register_event(int event_type, void *event_cb, void *user_data)
1655 DBusError dbus_error;
1657 DBusConnection *connection_type;
1658 DBusHandleMessageFunction event_func;
1659 bt_event_info_t *cb_data;
1661 if (is_initialized == FALSE)
1662 _bt_init_event_handler();
1664 if (__bt_event_is_registered(event_type) == TRUE) {
1665 BT_ERR("The event is already registed");
1666 return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
1669 switch (event_type) {
1670 case BT_ADAPTER_EVENT:
1671 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1672 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1674 event_func = __bt_adapter_event_filter;
1675 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1678 case BT_DEVICE_EVENT:
1679 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1680 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1682 event_func = __bt_device_event_filter;
1683 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1687 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1688 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1690 event_func = __bt_hid_event_filter;
1691 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1694 case BT_HEADSET_EVENT:
1695 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1696 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1698 event_func = __bt_headset_event_filter;
1699 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1702 case BT_NETWORK_EVENT:
1703 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1704 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1706 event_func = __bt_network_event_filter;
1707 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1710 case BT_AVRCP_EVENT:
1711 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1712 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1714 event_func = __bt_avrcp_event_filter;
1715 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1718 case BT_OPP_CLIENT_EVENT:
1719 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1720 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1722 event_func = __bt_opp_client_event_filter;
1723 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1724 BT_OPP_CLIENT_PATH);
1726 case BT_OPP_SERVER_EVENT:
1727 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1728 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1730 event_func = __bt_opp_server_event_filter;
1731 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1732 BT_OPP_SERVER_PATH);
1734 case BT_RFCOMM_CLIENT_EVENT:
1735 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1736 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1738 event_func = __bt_rfcomm_client_event_filter;
1739 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1740 BT_RFCOMM_CLIENT_PATH);
1742 case BT_RFCOMM_SERVER_EVENT:
1743 connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1744 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1746 event_func = __bt_rfcomm_server_event_filter;
1747 match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
1748 BT_RFCOMM_SERVER_PATH);
1751 BT_ERR("Unknown event");
1752 return BLUETOOTH_ERROR_INTERNAL;
1755 cb_data = g_new0(bt_event_info_t, 1);
1757 cb_data->event_type = event_type;
1758 cb_data->conn = connection_type;
1759 cb_data->func = event_func;
1760 cb_data->cb = event_cb;
1761 cb_data->user_data = user_data;
1763 if (!dbus_connection_add_filter(connection_type, event_func,
1764 (void *)cb_data, __bt_event_data_free)) {
1765 BT_ERR("Fail to add filter");
1769 dbus_error_init(&dbus_error);
1772 dbus_bus_add_match(connection_type, match, &dbus_error);
1774 if (dbus_error_is_set(&dbus_error)) {
1775 BT_ERR("Fail to add match: %s\n", dbus_error.message);
1776 dbus_error_free(&dbus_error);
1782 event_list = g_slist_append(event_list, cb_data);
1784 return BLUETOOTH_ERROR_NONE;
1786 if (connection_type)
1787 dbus_connection_unref(connection_type);
1791 return BLUETOOTH_ERROR_INTERNAL;
1794 int _bt_unregister_event(int event_type)
1796 DBusConnection *connection_type;
1797 DBusHandleMessageFunction event_func;
1798 bt_event_info_t *cb_data;
1800 if (is_initialized == FALSE) {
1801 BT_ERR("Event is not registered");
1802 return BLUETOOTH_ERROR_INTERNAL;
1805 if (__bt_event_is_registered(event_type) == FALSE) {
1806 BT_ERR("Not registered event");
1807 return BLUETOOTH_ERROR_INTERNAL;
1810 cb_data = __bt_event_get_cb_data(event_type);
1812 if (cb_data == NULL) {
1813 BT_ERR("No matched event data");
1814 return BLUETOOTH_ERROR_INTERNAL;
1817 connection_type = cb_data->conn;
1818 event_func = cb_data->func;
1820 event_list = g_slist_remove(event_list, (void *)cb_data);
1822 retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
1823 retv_if(event_func == NULL, BLUETOOTH_ERROR_INTERNAL);
1825 dbus_connection_remove_filter(connection_type, event_func,
1828 return BLUETOOTH_ERROR_NONE;