Merge branch 'master' into tizen_2.1
authorDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 19 Mar 2013 06:04:57 +0000 (15:04 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 19 Mar 2013 06:04:57 +0000 (15:04 +0900)
Change-Id: Iaae67b4019fd0604bcd60a7df10fcc5189c0532b

44 files changed:
bluetooth-frwk.manifest
bt-api/bt-adapter.c
bt-api/bt-audio.c
bt-api/bt-avrcp.c
bt-api/bt-common.c
bt-api/bt-device.c
bt-api/bt-gatt.c
bt-api/bt-hdp.c
bt-api/bt-hid.c
bt-api/bt-network.c
bt-api/bt-obex-server.c
bt-api/bt-oob.c
bt-api/bt-opp-client.c
bt-api/bt-rfcomm-client.c
bt-api/bt-rfcomm-server.c
bt-api/bt-telephony.c
bt-api/include/bt-common.h
bt-core/bt_core.c
bt-service/CMakeLists.txt
bt-service/bluetooth-frwk-service.service
bt-service/bt-request-handler.c
bt-service/bt-service-adapter.c
bt-service/bt-service-agent.c
bt-service/bt-service-audio.c
bt-service/bt-service-device.c
bt-service/bt-service-event-receiver.c
bt-service/bt-service-hid.c
bt-service/bt-service-main.c
bt-service/bt-service-network.c
bt-service/bt-service-obex-server.c
bt-service/bt-service-oob.c
bt-service/bt-service-opp-client.c
bt-service/bt-service-rfcomm-client.c
bt-service/bt-service-rfcomm-server.c
bt-service/include/bt-service-audio.h
bt-service/include/bt-service-common.h
bt-service/include/bt-service-obex-server.h
include/bluetooth-api.h
include/bt-internal-types.h
packaging/bluetooth-frwk.spec
test/CMakeLists.txt
test/bluetooth-frwk-test.c
test/gatt-test/CMakeLists.txt [new file with mode: 0644]
test/gatt-test/bluetooth-gatt-test.c [new file with mode: 0644]

index 75b0fa5..b9b83c2 100644 (file)
@@ -1,5 +1,23 @@
 <manifest>
+    <define>
+        <domain name="bt-service"/>
+       <request>
+               <smack request="system::vconf" type="rwxat"/>
+               <smack request="system::share" type="rwxat"/>
+               <smack request="system::media" type="rwxat"/>
+               <smack request="dbus" type="rwx"/>
+               <smack request="device::app_logging" type="w"/>
+               <smack request="syspopup::db" type="rwx"/>
+               <smack request="device::dialout" type="rw"/>
+               <smack request="bt-core" type="rw"/>
+       </request>
+    </define>
+
+    <assign>
+        <filesystem path="/etc/init.d/bluetooth-frwk-service" label="_" exec_label="none" />
+    </assign>
+
     <request>
-        <domain name="_"/>
+        <domain name="bt-service"/>
     </request>
 </manifest>
index ebdfc91..01acfef 100644 (file)
@@ -34,8 +34,8 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list)
        guint size;
        bluetooth_device_info_t info;
 
-       BT_CHECK_PARAMETER(out_param2);
-       BT_CHECK_PARAMETER(dev_list);
+       BT_CHECK_PARAMETER(out_param2, return);
+       BT_CHECK_PARAMETER(dev_list, return);
 
        size = out_param2->len;
        retv_if(size == 0, BLUETOOTH_ERROR_NONE);
@@ -90,7 +90,7 @@ BT_EXPORT_API int bluetooth_disable_adapter(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -103,12 +103,27 @@ BT_EXPORT_API int bluetooth_disable_adapter(void)
        return result;
 }
 
+BT_EXPORT_API int bluetooth_reset_adapter(void)
+{
+       int result;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RESET_ADAPTER,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_get_local_address(bluetooth_device_address_t *local_address)
 {
        int result;
 
-       BT_CHECK_PARAMETER(local_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(local_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -130,8 +145,8 @@ BT_EXPORT_API int bluetooth_get_local_name(bluetooth_device_name_t *local_name)
 {
        int result;
 
-       BT_CHECK_PARAMETER(local_name);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(local_name, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -153,8 +168,8 @@ BT_EXPORT_API int bluetooth_set_local_name(const bluetooth_device_name_t *local_
 {
        int result;
 
-       BT_CHECK_PARAMETER(local_name);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(local_name, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -175,9 +190,9 @@ BT_EXPORT_API int bluetooth_is_service_used(const char *service_uuid,
        int result;
        char uuid[BLUETOOTH_UUID_STRING_MAX];
 
-       BT_CHECK_PARAMETER(service_uuid);
-       BT_CHECK_PARAMETER(used);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(service_uuid, return);
+       BT_CHECK_PARAMETER(used, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -203,7 +218,7 @@ BT_EXPORT_API int bluetooth_get_discoverable_mode(bluetooth_discoverable_mode_t
        int result;
        int timeout = 0;
 
-       BT_CHECK_PARAMETER(discoverable_mode_ptr);
+       BT_CHECK_PARAMETER(discoverable_mode_ptr, return);
 
        /* Requirement in OSP */
        if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) {
@@ -242,7 +257,7 @@ BT_EXPORT_API int bluetooth_set_discoverable_mode(bluetooth_discoverable_mode_t
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -262,8 +277,8 @@ BT_EXPORT_API int bluetooth_get_timeout_value(int *timeout)
 {
        int result;
 
-       BT_CHECK_PARAMETER(timeout);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(timeout, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -286,7 +301,7 @@ BT_EXPORT_API int bluetooth_start_discovery(unsigned short max_response,
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -303,7 +318,7 @@ BT_EXPORT_API int bluetooth_cancel_discovery(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -322,7 +337,7 @@ BT_EXPORT_API int bluetooth_is_discovering(void)
        int result;
        int is_discovering = FALSE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -346,8 +361,8 @@ BT_EXPORT_API int bluetooth_get_bonded_device_list(GPtrArray **dev_list)
 {
        int result;
 
-       BT_CHECK_PARAMETER(dev_list);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(dev_list, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index 450ceab..e1b2130 100644 (file)
@@ -59,8 +59,8 @@ BT_EXPORT_API int bluetooth_audio_connect(bluetooth_device_address_t *remote_add
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -84,8 +84,8 @@ BT_EXPORT_API int bluetooth_audio_disconnect(bluetooth_device_address_t *remote_
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -109,8 +109,8 @@ BT_EXPORT_API int bluetooth_ag_connect(bluetooth_device_address_t *remote_addres
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -134,8 +134,8 @@ BT_EXPORT_API int bluetooth_ag_disconnect(bluetooth_device_address_t *remote_add
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -159,8 +159,8 @@ BT_EXPORT_API int bluetooth_av_connect(bluetooth_device_address_t *remote_addres
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -184,8 +184,8 @@ BT_EXPORT_API int bluetooth_av_disconnect(bluetooth_device_address_t *remote_add
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -208,8 +208,8 @@ BT_EXPORT_API int bluetooth_ag_get_headset_volume(unsigned int *speaker_gain)
 {
        int result;
 
-       BT_CHECK_PARAMETER(speaker_gain);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(speaker_gain, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -231,7 +231,7 @@ BT_EXPORT_API int bluetooth_ag_set_speaker_gain(unsigned int speaker_gain)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index 8e166df..ca33c24 100644 (file)
@@ -62,14 +62,13 @@ BT_EXPORT_API int bluetooth_media_player_deinit(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
-
 BT_EXPORT_API int bluetooth_media_player_change_property(
                        media_player_property_type type,
                        unsigned int value)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -90,8 +89,8 @@ BT_EXPORT_API int bluetooth_media_player_set_properties(
 {
        int result;
 
-       BT_CHECK_PARAMETER(setting);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(setting, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -112,18 +111,23 @@ BT_EXPORT_API int bluetooth_media_player_change_track(
        int result;
        media_metadata_t meta_data;
 
-       BT_CHECK_PARAMETER(metadata);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(metadata, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
        memset(&meta_data, 0x00, sizeof(media_metadata_t));
 
-       g_strlcpy(meta_data.title, metadata->title, BT_NAME_MAX);
-       g_strlcpy(meta_data.artist, metadata->artist, BT_NAME_MAX);
-       g_strlcpy(meta_data.album, metadata->album, BT_NAME_MAX);
-       g_strlcpy(meta_data.genre, metadata->genre, BT_NAME_MAX);
+       if (_bt_copy_utf8_string(meta_data.title, metadata->title, BT_NAME_MAX))
+               BT_DBG("Error in copying Title\n");
+       if (_bt_copy_utf8_string(meta_data.artist, metadata->artist, BT_NAME_MAX))
+               BT_DBG("Error in copying Artist\n");
+       if (_bt_copy_utf8_string(meta_data.album, metadata->album, BT_NAME_MAX))
+               BT_DBG("Error in copying Album\n");
+       if (_bt_copy_utf8_string(meta_data.genre, metadata->genre, BT_NAME_MAX))
+               BT_DBG("Error in copying Genre\n");
+
        meta_data.total_tracks = metadata->total_tracks;
        meta_data.number = metadata->number;
        meta_data.duration = metadata->duration;
index 9629991..4dc7385 100644 (file)
@@ -152,6 +152,31 @@ void _bt_convert_addr_type_to_string(char *address,
                        addr[3], addr[4], addr[5]);
 }
 
+int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
+{
+       int i;
+       char *p = src;
+       char *next;
+       int count;
+
+       if (dest == NULL || src == NULL)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       i = 0;
+       while (*p != '\0' && i < length) {
+               next = g_utf8_next_char(p);
+               count = next - p;
+
+               while (count > 0 && ((i + count) < length)) {
+                       dest[i++] = *p;
+                       p++;
+                       count --;
+               }
+               p = next;
+       }
+       return BLUETOOTH_ERROR_NONE;
+}
+
 int _bt_get_adapter_path(DBusGConnection *conn, char *path)
 {
        GError *err = NULL;
index 118435e..b746e5f 100644 (file)
@@ -29,8 +29,8 @@ BT_EXPORT_API int bluetooth_bond_device(const bluetooth_device_address_t *device
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -53,7 +53,7 @@ BT_EXPORT_API int bluetooth_cancel_bonding(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -71,8 +71,8 @@ BT_EXPORT_API int bluetooth_unbond_device(const bluetooth_device_address_t *devi
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -96,9 +96,9 @@ BT_EXPORT_API int bluetooth_get_bonded_device(const bluetooth_device_address_t *
 {
        int result;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_PARAMETER(dev_info);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(dev_info, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -132,8 +132,8 @@ BT_EXPORT_API int bluetooth_search_service(const bluetooth_device_address_t *dev
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -156,7 +156,7 @@ BT_EXPORT_API int bluetooth_cancel_service_search(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -175,9 +175,9 @@ BT_EXPORT_API int bluetooth_set_alias(const bluetooth_device_address_t *device_a
        int result;
        char alias_name[BLUETOOTH_DEVICE_NAME_LENGTH_MAX];
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_PARAMETER(alias);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(alias, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -199,8 +199,8 @@ BT_EXPORT_API int bluetooth_authorize_device(const bluetooth_device_address_t *d
 {
        int result;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -222,9 +222,9 @@ BT_EXPORT_API int bluetooth_is_device_connected(const bluetooth_device_address_t
 {
        int result;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_PARAMETER(is_connected);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(is_connected, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index 10e1da3..725c2e1 100644 (file)
@@ -39,6 +39,11 @@ typedef struct {
        GObjectClass parent;
 } BluetoothGattServiceClass;
 
+typedef struct {
+       char *char_uuid;
+       char **handle;
+} char_pty_req_t;
+
 GType bluetooth_gatt_service_get_type(void);
 
 #define BLUETOOTH_GATT_TYPE_SERVICE (bluetooth_gatt_service_get_type())
@@ -144,13 +149,17 @@ static char **__get_string_array_from_gptr_array(GPtrArray *gp)
        char **path = NULL;
        int i;
 
-       path = g_malloc0(gp->len * sizeof(char *));
+       if (gp->len == 0)
+               return NULL;
+
+       path = g_malloc0((gp->len + 1) * sizeof(char *));
 
        for (i = 0; i < gp->len; i++) {
                gp_path = g_ptr_array_index(gp, i);
                path[i] = g_strdup(gp_path);
                BT_DBG("path[%d] : [%s]", i, path[i]);
        }
+
        return path;
 }
 
@@ -200,14 +209,153 @@ static void __bluetooth_internal_get_char_cb(DBusGProxy *proxy,
        g_object_unref(proxy);
 }
 
+static void __free_char_req(char_pty_req_t *char_req)
+{
+       g_free(char_req->char_uuid);
+       g_strfreev(char_req->handle);
+       g_free(char_req);
+}
+
+static gboolean __filter_chars_with_uuid(gpointer data)
+{
+       int i = 0;
+       bt_gatt_char_property_t *char_pty;
+       char_pty_req_t *char_req = data;
+       bt_user_info_t *user_info;
+       int ret;
+
+       user_info = _bt_get_user_data(BT_COMMON);
+       if (user_info == NULL) {
+               __free_char_req(char_req);
+               return FALSE;
+       }
+
+       char_pty = g_new0(bt_gatt_char_property_t, 1);
+
+       while (char_req->handle[i] != NULL) {
+               BT_DBG("char_pty[%d] = %s", i, char_req->handle[i]);
+               ret = bluetooth_gatt_get_characteristics_property(char_req->handle[i],
+                                                                       char_pty);
+               if (ret != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("get char property failed");
+                       goto done;
+               }
+
+               if (char_pty->uuid  && g_strstr_len(char_pty->uuid, -1,
+                                               char_req->char_uuid) != NULL) {
+                       BT_DBG("Requested Char recieved");
+                       ret = BLUETOOTH_ERROR_NONE;
+                       break;
+               }
+
+               bluetooth_gatt_free_char_property(char_pty);
+
+               i++;
+       }
+
+done:
+       if (char_req->handle[i] == NULL)
+               ret = BLUETOOTH_ERROR_NOT_FOUND;
+
+       _bt_common_event_cb(BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID, ret,
+                               char_pty, user_info->cb, user_info->user_data);
+
+       g_free(char_pty);
+       __free_char_req(char_req);
+
+       return FALSE;
+}
+
+static void __disc_char_from_uuid_cb(DBusGProxy *proxy,
+                                       DBusGProxyCall *call,
+                                       gpointer user_data)
+{
+       GError *error = NULL;
+       GPtrArray *gp_array = NULL;
+       bt_user_info_t *user_info;
+       char_pty_req_t *char_req = user_data;
+
+       user_info = _bt_get_user_data(BT_COMMON);
+       if (!user_info) {
+               __free_char_req(char_req);
+               return;
+       }
+
+       if (!dbus_g_proxy_end_call(proxy, call, &error,
+               dbus_g_type_get_collection("GPtrArray", DBUS_TYPE_G_OBJECT_PATH),
+               &gp_array, G_TYPE_INVALID)) {
+               BT_ERR("Error : %s \n", error->message);
+               g_error_free(error);
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID,
+                                       BLUETOOTH_ERROR_INTERNAL, NULL,
+                                       user_info->cb, user_info->user_data);
+
+               __free_char_req(char_req);
+               g_object_unref(proxy);
+               return;
+       }
+
+       if (gp_array == NULL) {
+               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID,
+                                       BLUETOOTH_ERROR_NOT_FOUND, NULL,
+                                       user_info->cb, user_info->user_data);
+
+               __free_char_req(char_req);
+               g_object_unref(proxy);
+
+               return;
+       }
+
+       char_req->handle = __get_string_array_from_gptr_array(gp_array);
+
+       __filter_chars_with_uuid(char_req);
+
+       g_ptr_array_free(gp_array, TRUE);
+       g_object_unref(proxy);
+}
+
+
+static int __discover_char_from_uuid(const char *service_handle,
+                                                       const char *char_uuid){
+       DBusGProxy *service_proxy = NULL;
+       DBusGConnection *conn;
+       char_pty_req_t *char_req;
+
+       conn = _bt_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       service_proxy = dbus_g_proxy_new_for_name(conn,
+                                               BT_BLUEZ_NAME, service_handle,
+                                               BLUEZ_CHAR_INTERFACE);
+       retv_if(service_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       char_req = g_new0(char_pty_req_t, 1);
+
+       char_req->char_uuid = g_strdup(char_uuid);
+       BT_DBG("Char uuid %s ", char_uuid);
+
+       if (!dbus_g_proxy_begin_call(service_proxy, "DiscoverCharacteristics",
+                       (DBusGProxyCallNotify)__disc_char_from_uuid_cb,
+                       char_req, NULL, G_TYPE_INVALID)) {
+               __free_char_req(char_req);
+               g_object_unref(service_proxy);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 BT_EXPORT_API int bluetooth_gatt_free_primary_services(bt_gatt_handle_info_t *prim_svc)
 {
        BT_DBG("+");
 
-       BT_CHECK_PARAMETER(prim_svc);
+       BT_CHECK_PARAMETER(prim_svc, return);
 
        g_strfreev(prim_svc->handle);
 
+       memset(prim_svc, 0, sizeof(bt_gatt_handle_info_t));
+
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
@@ -216,11 +364,14 @@ BT_EXPORT_API int bluetooth_gatt_free_service_property(bt_gatt_service_property_
 {
        BT_DBG("+");
 
-       BT_CHECK_PARAMETER(svc_pty);
+       BT_CHECK_PARAMETER(svc_pty, return);
 
        g_free(svc_pty->uuid);
+       g_free(svc_pty->handle);
        g_strfreev(svc_pty->handle_info.handle);
 
+       memset(svc_pty, 0, sizeof(bt_gatt_service_property_t));
+
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
@@ -229,12 +380,15 @@ BT_EXPORT_API int bluetooth_gatt_free_char_property(bt_gatt_char_property_t *cha
 {
        BT_DBG("+");
 
-       BT_CHECK_PARAMETER(char_pty);
+       BT_CHECK_PARAMETER(char_pty, return);
 
        g_free(char_pty->uuid);
        g_free(char_pty->name);
        g_free(char_pty->description);
        g_free(char_pty->val);
+       g_free(char_pty->handle);
+
+       memset(char_pty, 0, sizeof(bt_gatt_char_property_t));
 
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
@@ -256,10 +410,10 @@ BT_EXPORT_API int bluetooth_gatt_get_primary_services(const bluetooth_device_add
 
        BT_DBG("+");
 
-       BT_CHECK_PARAMETER(address);
-       BT_CHECK_PARAMETER(prim_svc);
+       BT_CHECK_PARAMETER(address, return);
+       BT_CHECK_PARAMETER(prim_svc, return);
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        _bt_convert_addr_type_to_string(device_address,
                                (unsigned char *)address->addr);
@@ -319,7 +473,7 @@ BT_EXPORT_API int bluetooth_gatt_get_primary_services(const bluetooth_device_add
 
        prim_svc->count = gp_array->len;
        prim_svc->handle = __get_string_array_from_gptr_array(gp_array);
-       g_ptr_array_free(gp_array, TRUE);
+
        ret = BLUETOOTH_ERROR_NONE;
 done:
        g_hash_table_destroy(hash);
@@ -333,9 +487,9 @@ BT_EXPORT_API int bluetooth_gatt_discover_service_characteristics(const char *se
        char *handle;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(service_handle);
+       BT_CHECK_PARAMETER(service_handle, return);
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        conn = _bt_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -370,10 +524,10 @@ BT_EXPORT_API int bluetooth_gatt_get_service_property(const char *service_handle
        GPtrArray *gp_array  = NULL ;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(service_handle);
-       BT_CHECK_PARAMETER(service);
+       BT_CHECK_PARAMETER(service_handle, return);
+       BT_CHECK_PARAMETER(service, return);
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        conn = _bt_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -397,6 +551,8 @@ BT_EXPORT_API int bluetooth_gatt_get_service_property(const char *service_handle
 
        retv_if(hash == NULL, BLUETOOTH_ERROR_INTERNAL);
 
+       memset(service, 0, sizeof(bt_gatt_service_property_t));
+
        value = g_hash_table_lookup(hash, "UUID");
        service->uuid = value ? g_value_dup_string(value) : NULL;
        if (service->uuid) {
@@ -405,11 +561,12 @@ BT_EXPORT_API int bluetooth_gatt_get_service_property(const char *service_handle
 
        value = g_hash_table_lookup(hash, "Characteristics");
        gp_array = value ? g_value_get_boxed(value) : NULL;
-       if (NULL != gp_array) {
+       if (gp_array) {
                service->handle_info.count = gp_array->len;
                service->handle_info.handle = __get_string_array_from_gptr_array(gp_array);
-               g_ptr_array_free(gp_array, TRUE);
        }
+
+       service->handle = g_strdup(service_handle);
        g_hash_table_destroy(hash);
        return BLUETOOTH_ERROR_NONE;
 }
@@ -420,9 +577,9 @@ BT_EXPORT_API int bluetooth_gatt_watch_characteristics(const char *service_handl
        GError *error = NULL;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(service_handle);
+       BT_CHECK_PARAMETER(service_handle, return);
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_DBG("Entered service handle:%s \n ", service_handle);
 
@@ -458,9 +615,9 @@ BT_EXPORT_API int bluetooth_gatt_unwatch_characteristics(const char *service_han
        GError *error = NULL;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(service_handle);
+       BT_CHECK_PARAMETER(service_handle, return);
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        conn = _bt_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -496,10 +653,10 @@ BT_EXPORT_API int bluetooth_gatt_get_characteristics_property(const char *char_h
        GByteArray *gb_array = NULL;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(char_handle);
-       BT_CHECK_PARAMETER(characteristic);
+       BT_CHECK_PARAMETER(char_handle, return);
+       BT_CHECK_PARAMETER(characteristic, return);
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        conn = _bt_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -523,6 +680,8 @@ BT_EXPORT_API int bluetooth_gatt_get_characteristics_property(const char *char_h
 
        retv_if(hash == NULL, BLUETOOTH_ERROR_INTERNAL);
 
+       memset(characteristic, 0, sizeof(bt_gatt_char_property_t));
+
        value = g_hash_table_lookup(hash, "UUID");
        characteristic->uuid = value ? g_value_dup_string(value) : NULL;
        if (characteristic->uuid) {
@@ -555,12 +714,11 @@ BT_EXPORT_API int bluetooth_gatt_get_characteristics_property(const char *char_h
                        characteristic->val = NULL;
                        characteristic->val_len = 0;
                }
-
-               g_byte_array_free(gb_array, TRUE);
        } else {
                characteristic->val = NULL;
                characteristic->val_len = 0;
        }
+       characteristic->handle = g_strdup(char_handle);
        g_hash_table_destroy(hash);
        return BLUETOOTH_ERROR_NONE;
 }
@@ -574,11 +732,11 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value(const char *char_hand
        GError *error = NULL;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(char_handle);
-       BT_CHECK_PARAMETER(value);
+       BT_CHECK_PARAMETER(char_handle, return);
+       BT_CHECK_PARAMETER(value, return);
        retv_if(length == 0, BLUETOOTH_ERROR_INVALID_PARAM);
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        conn = _bt_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -613,3 +771,93 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value(const char *char_hand
 
        return BLUETOOTH_ERROR_NONE;
 }
+
+BT_EXPORT_API int bluetooth_gatt_get_service_from_uuid(bluetooth_device_address_t *address,
+                                       const char *service_uuid,
+                                       bt_gatt_service_property_t *service)
+{
+       int i;
+       int ret;
+       bt_gatt_handle_info_t prim_svc;
+
+       BT_CHECK_PARAMETER(address, return);
+       BT_CHECK_PARAMETER(service_uuid, return);
+       BT_CHECK_PARAMETER(service, return);
+
+       BT_CHECK_ENABLED(return);
+
+       ret = bluetooth_gatt_get_primary_services(address, &prim_svc);
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Get primary service failed ");
+               return ret;
+       }
+
+       for (i = 0; i < prim_svc.count; i++) {
+
+               BT_DBG("prim_svc [%d] = %s", i, prim_svc.handle[i]);
+
+               ret = bluetooth_gatt_get_service_property(prim_svc.handle[i],
+                                                               service);
+               if (ret != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("Get service property failed ");
+                       bluetooth_gatt_free_primary_services(&prim_svc);
+                       return ret;
+               }
+
+               BT_DBG("Service uuid %s", service->uuid);
+
+               if (g_strstr_len(service->uuid, -1, service_uuid)) {
+                       BT_DBG("Found requested service");
+                       ret = BLUETOOTH_ERROR_NONE;
+                       break;
+               }
+
+               bluetooth_gatt_free_service_property(service);
+       }
+
+       if (i == prim_svc.count)
+               ret = BLUETOOTH_ERROR_NOT_FOUND;
+
+       bluetooth_gatt_free_primary_services(&prim_svc);
+
+       return ret;
+}
+
+BT_EXPORT_API int bluetooth_gatt_get_char_from_uuid(const char *service_handle,
+                                               const char *char_uuid)
+{
+       char **char_handles;
+       char_pty_req_t *char_pty;
+       int i;
+       bt_gatt_service_property_t svc_pty;
+
+       BT_CHECK_PARAMETER(service_handle, return);
+       BT_CHECK_PARAMETER(char_uuid, return);
+
+       BT_CHECK_ENABLED(return);
+
+       if (bluetooth_gatt_get_service_property(service_handle, &svc_pty) !=
+                                                       BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Invalid service");
+               return BLUETOOTH_ERROR_NOT_FOUND;
+       }
+
+       char_handles = svc_pty.handle_info.handle;
+
+       if (char_handles == NULL)
+               return __discover_char_from_uuid(svc_pty.handle, char_uuid);
+
+       char_pty = g_new0(char_pty_req_t, 1);
+
+       char_pty->handle = g_malloc0((svc_pty.handle_info.count + 1) *
+                                                       sizeof(char *));
+       for (i = 0; i < svc_pty.handle_info.count; i++) {
+               char_pty->handle[i] = char_handles[i];
+               BT_DBG("char_path[%d] : [%s]", i, char_pty->handle[i]);
+       }
+       char_pty->char_uuid = g_strdup(char_uuid);
+
+       g_idle_add(__filter_chars_with_uuid, char_pty);
+
+       return BLUETOOTH_ERROR_NONE;
+}
index 23c9cb7..36aa058 100644 (file)
@@ -98,7 +98,7 @@ BT_EXPORT_API int bluetooth_hdp_activate(unsigned short data_type,
 
        BT_DBG("+");
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        /*For source role is mandatory */
        if (role == HDP_ROLE_SOURCE && channel_type == HDP_QOS_ANY) {
@@ -739,8 +739,8 @@ BT_EXPORT_API int bluetooth_hdp_deactivate(const char *app_handle)
 {
        BT_DBG("+");
 
-       BT_CHECK_ENABLED();
-       BT_CHECK_PARAMETER(app_handle);
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(app_handle, return);
 
        return __bt_hdp_internal_destroy_application(app_handle);
 }
@@ -914,7 +914,7 @@ BT_EXPORT_API int bluetooth_hdp_send_data(unsigned int channel_id,
 
        BT_DBG("+");
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        if ((channel_id == 0) || (NULL == buffer) || (size == 0)) {
                BT_DBG("Invalid arguments..\n");
@@ -982,9 +982,9 @@ BT_EXPORT_API int bluetooth_hdp_connect(const char *app_handle,
 
        BT_DBG("+");
 
-       BT_CHECK_ENABLED();
-       BT_CHECK_PARAMETER(app_handle);
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(app_handle, return);
+       BT_CHECK_PARAMETER(device_address, return);
 
        if (channel_type == HDP_QOS_RELIABLE) {
                role = "Reliable";
@@ -1106,8 +1106,8 @@ BT_EXPORT_API int bluetooth_hdp_disconnect(unsigned int channel_id,
 
        BT_DBG("+\n");
 
-       BT_CHECK_ENABLED();
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(device_address, return);
 
        hdp_obj_info_t *info = __bt_hdp_internal_gslist_obj_find_using_fd(channel_id);
        if (NULL == info) {
index a1a06bb..20fe85c 100644 (file)
@@ -64,8 +64,8 @@ BT_EXPORT_API int bluetooth_hid_connect(hid_device_address_t *device_address)
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -89,8 +89,8 @@ BT_EXPORT_API int bluetooth_hid_disconnect(hid_device_address_t *device_address)
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index 64399eb..c7c5b5a 100644 (file)
@@ -28,7 +28,7 @@ BT_EXPORT_API int bluetooth_network_activate_server()
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -45,7 +45,7 @@ BT_EXPORT_API int bluetooth_network_deactivate_server(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -65,8 +65,8 @@ BT_EXPORT_API int bluetooth_network_connect(const bluetooth_device_address_t *de
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -92,8 +92,8 @@ BT_EXPORT_API int bluetooth_network_disconnect(const bluetooth_device_address_t
        int result;
        bt_user_info_t *user_info;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index 24ad868..09088f9 100644 (file)
@@ -34,7 +34,7 @@ BT_EXPORT_API int bluetooth_obex_server_init(const char *dst_path)
        gboolean native_service = TRUE;
        char path[BT_FILE_PATH_MAX];
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        if (_bt_get_obex_server_id() != BT_NO_SERVER)
                return BLUETOOTH_ERROR_AGENT_ALREADY_EXIST;
@@ -74,7 +74,7 @@ BT_EXPORT_API int bluetooth_obex_server_deinit(void)
        int app_pid;
        gboolean native_service = TRUE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        if (_bt_get_obex_server_id() != BT_NATIVE_SERVER)
                return BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST;
@@ -106,7 +106,7 @@ BT_EXPORT_API int bluetooth_obex_server_init_without_agent(const char *dst_path)
        gboolean native_service = FALSE;
        char path[BT_FILE_PATH_MAX];
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        if (_bt_get_obex_server_id() != BT_NO_SERVER)
                return BLUETOOTH_ERROR_AGENT_ALREADY_EXIST;
@@ -146,7 +146,7 @@ BT_EXPORT_API int bluetooth_obex_server_deinit_without_agent(void)
        int app_pid;
        gboolean native_service = FALSE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        /* Can't call this API after using bluetooth_obex_server_init
             in same process */
@@ -241,8 +241,8 @@ BT_EXPORT_API int bluetooth_obex_server_accept_authorize(const char *filename)
        int result;
        char name[BT_FILE_PATH_MAX];
 
-       BT_CHECK_PARAMETER(filename);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(filename, return);
+       BT_CHECK_ENABLED(return);
 
        if (_bt_get_obex_server_id() != BT_NATIVE_SERVER)
                return BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST;
@@ -266,7 +266,7 @@ BT_EXPORT_API int bluetooth_obex_server_reject_authorize(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        if (_bt_get_obex_server_id() != BT_NATIVE_SERVER)
                return BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST;
@@ -289,8 +289,8 @@ BT_EXPORT_API int bluetooth_obex_server_set_destination_path(const char *dst_pat
        gboolean native_service = FALSE;
        char path[BT_FILE_PATH_MAX];
 
-       BT_CHECK_PARAMETER(dst_path);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(dst_path, return);
+       BT_CHECK_ENABLED(return);
 
        server_id = _bt_get_obex_server_id();
 
@@ -320,8 +320,8 @@ BT_EXPORT_API int bluetooth_obex_server_set_root(const char *root)
        int result;
        char root_path[BT_FILE_PATH_MAX];
 
-       BT_CHECK_PARAMETER(root);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(root, return);
+       BT_CHECK_ENABLED(return);
 
        if (_bt_get_obex_server_id() == BT_NO_SERVER)
                return BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST;
@@ -346,7 +346,7 @@ BT_EXPORT_API int bluetooth_obex_server_cancel_transfer(int transfer_id)
        int server_type;
        int service_function = BT_OBEX_SERVER_CANCEL_TRANSFER;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        server_type = _bt_get_obex_server_id();
 
@@ -372,7 +372,7 @@ BT_EXPORT_API int bluetooth_obex_server_cancel_all_transfers(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        if (_bt_get_obex_server_id() == BT_NO_SERVER)
                return BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST;
@@ -388,3 +388,28 @@ BT_EXPORT_API int bluetooth_obex_server_cancel_all_transfers(void)
        return result;
 }
 
+BT_EXPORT_API int bluetooth_obex_server_is_receiving(gboolean *is_receiving)
+{
+       int result;
+
+       *is_receiving = FALSE;
+
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       result = _bt_send_request(BT_OBEX_SERVICE, BT_OBEX_SERVER_IS_RECEIVING,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               *is_receiving = g_array_index(out_param, gboolean, 0);
+       } else {
+               BT_ERR("Fail to send request");
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
index 40ef24a..d2145c4 100644 (file)
@@ -28,8 +28,8 @@ BT_EXPORT_API int bluetooth_oob_read_local_data(bt_oob_data_t *local_oob_data)
 {
        int result;
 
-       BT_CHECK_PARAMETER(local_oob_data);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(local_oob_data, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -53,9 +53,9 @@ BT_EXPORT_API int bluetooth_oob_add_remote_data(
 {
        int result;
 
-       BT_CHECK_PARAMETER(remote_device_address);
-       BT_CHECK_PARAMETER(remote_oob_data);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_device_address, return);
+       BT_CHECK_PARAMETER(remote_oob_data, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -78,8 +78,8 @@ BT_EXPORT_API int bluetooth_oob_remove_remote_data(
 {
        int result;
 
-       BT_CHECK_PARAMETER(remote_device_address);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_device_address, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index f1b3300..e6e980a 100644 (file)
@@ -66,9 +66,9 @@ BT_EXPORT_API int bluetooth_opc_push_files(bluetooth_device_address_t *remote_ad
        bt_user_info_t *user_info;
        char filename[BT_FILE_PATH_MAX];
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_PARAMETER(file_name_array);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_PARAMETER(file_name_array, return);
+       BT_CHECK_ENABLED(return);
 
        __bt_get_file_size(file_name_array, &size, &file_count);
        retv_if(file_count == 0, BLUETOOTH_ERROR_INVALID_PARAM);
@@ -101,7 +101,7 @@ BT_EXPORT_API int bluetooth_opc_cancel_push(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -119,7 +119,7 @@ BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
        int result;
        gboolean exist = FALSE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -138,3 +138,28 @@ BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
        return result;
 }
 
+BT_EXPORT_API int bluetooth_opc_is_sending(gboolean *is_sending)
+{
+       int result;
+
+       *is_sending = FALSE;
+
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               *is_sending = g_array_index(out_param, gboolean, 0);
+       } else {
+               BT_ERR("Fail to send request");
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
index f8b0c4d..e91ff6d 100644 (file)
@@ -34,9 +34,9 @@ BT_EXPORT_API int bluetooth_rfcomm_connect(const bluetooth_device_address_t *rem
        bt_user_info_t *user_info;
        char uuid[BLUETOOTH_UUID_STRING_MAX];
 
-       BT_CHECK_PARAMETER(remote_bt_address);
-       BT_CHECK_PARAMETER(remote_uuid);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_bt_address, return);
+       BT_CHECK_PARAMETER(remote_uuid, return);
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -74,7 +74,7 @@ BT_EXPORT_API gboolean bluetooth_rfcomm_is_client_connected(void)
        int result;
        int connected = FALSE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -101,7 +101,7 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd)
        int result;
        int service_function;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -130,8 +130,8 @@ BT_EXPORT_API int bluetooth_rfcomm_write(int fd, const char *buf, int length)
        int result;
        char *buffer;
 
-       BT_CHECK_PARAMETER(buf);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(buf, return);
+       BT_CHECK_ENABLED(return);
        retv_if(length <= 0, BLUETOOTH_ERROR_INVALID_PARAM);
 
        BT_INIT_PARAMS();
index a6a2350..5396f70 100644 (file)
@@ -33,8 +33,8 @@ BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
        int socket_fd = -1;
        char uuid_str[BLUETOOTH_UUID_STRING_MAX];
 
-       BT_CHECK_ENABLED();
-       BT_CHECK_PARAMETER(uuid);
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(uuid, return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -62,7 +62,7 @@ BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int socket_fd)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -87,7 +87,7 @@ BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -141,7 +141,7 @@ BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int socket_fd, int max_pend
        int result;
        gboolean native_service = TRUE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -165,7 +165,7 @@ BT_EXPORT_API int bluetooth_rfcomm_listen(int socket_fd, int max_pending_connect
        int result;
        gboolean native_service = FALSE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -192,7 +192,7 @@ BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd, int *client_
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -219,7 +219,7 @@ BT_EXPORT_API int bluetooth_rfcomm_reject_connection(int server_fd)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index b1bdca2..43947fb 100644 (file)
@@ -172,6 +172,7 @@ static int __bluetooth_telephony_register(void);
 static int __bluetooth_telephony_unregister(void);
 static int __bluetooth_get_default_adapter_path(DBusGConnection *GConn,
                                                        char *path);
+static gboolean __bluetooth_telephony_is_headset(uint32_t device_class);
 static int __bluetooth_telephony_get_connected_device(void);
 static DBusGProxy *__bluetooth_telephony_get_connected_device_proxy(void);
 
@@ -513,7 +514,7 @@ static DBusHandlerResult __bluetooth_telephony_event_filter(
        if (dbus_message_is_signal(msg, HFP_AGENT_SERVICE,
                                HFP_NREC_STATUS_CHANGE)) {
                __bluetooth_handle_nrec_status_change(msg);
-               return DBUS_HANDLER_RESULT_HANDLED;
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
 
        if (!dbus_message_has_interface(msg, BLUEZ_HEADSET_INTERFACE))
@@ -566,7 +567,7 @@ static DBusHandlerResult __bluetooth_telephony_event_filter(
                        telephony_info.headset_state = BLUETOOTH_STATE_DISCONNETED;
                }
 
-               return DBUS_HANDLER_RESULT_HANDLED;
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
 
        if (g_strcmp0(property, "Connected") == 0) {
@@ -624,7 +625,7 @@ static DBusHandlerResult __bluetooth_telephony_event_filter(
                                        BLUETOOTH_EVENT_TELEPHONY_HFP_DISCONNECTED,
                                        BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
                }
-               return DBUS_HANDLER_RESULT_HANDLED;
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
 
        if (g_strcmp0(property, "SpeakerGain") == 0) {
@@ -642,7 +643,7 @@ static DBusHandlerResult __bluetooth_telephony_event_filter(
                                        BLUETOOTH_TELEPHONY_ERROR_NONE,
                                        (void *)&spkr_gain);
 
-               return DBUS_HANDLER_RESULT_HANDLED;
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
 
        if (g_strcmp0(property, "MicrophoneGain") == 0) {
@@ -660,7 +661,7 @@ static DBusHandlerResult __bluetooth_telephony_event_filter(
                                        BLUETOOTH_TELEPHONY_ERROR_NONE,
                                        (void *)&mic_gain);
 
-               return DBUS_HANDLER_RESULT_HANDLED;
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
 
        if (g_strcmp0(property, "Playing") == 0) {
@@ -694,7 +695,7 @@ static DBusHandlerResult __bluetooth_telephony_event_filter(
                                BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
                }
 
-               return DBUS_HANDLER_RESULT_HANDLED;
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
@@ -870,6 +871,35 @@ static int __bluetooth_get_default_adapter_path(DBusGConnection *GConn,
        return BLUETOOTH_TELEPHONY_ERROR_NONE;
 }
 
+static gboolean __bluetooth_telephony_is_headset(uint32_t device_class)
+{
+       gboolean flag = FALSE;
+       BT_DBG("+");
+
+       switch ((device_class & 0x1f00) >> 8) {
+       case 0x04:
+               switch ((device_class & 0xfc) >> 2) {
+               case 0x01:
+               case 0x02:
+                       flag = TRUE;
+                       break;
+               case 0x06:
+                       flag = TRUE;
+                       break;
+               case 0x0b:
+               case 0x0c:
+               case 0x0d:
+                       break;
+               default:
+                       flag = TRUE;
+                       break;
+               }
+               break;
+       }
+       BT_DBG("-");
+       return flag;
+}
+
 static int __bluetooth_telephony_get_connected_device(void)
 {
        DBusGProxy *list_proxy = NULL;
@@ -880,6 +910,7 @@ static int __bluetooth_telephony_get_connected_device(void)
        GHashTable *list_hash;
        GHashTable *device_hash;
        GValue *value = {0};
+       uint32_t device_class;
        gboolean playing = FALSE;
        gboolean connected = FALSE;
        const gchar *address;
@@ -938,6 +969,18 @@ static int __bluetooth_telephony_get_connected_device(void)
                if (list_hash == NULL)
                        goto done;
 
+               value = g_hash_table_lookup(list_hash, "Class");
+               device_class = value ? g_value_get_uint(value) : 0;
+
+               if (!__bluetooth_telephony_is_headset(device_class)) {
+                       g_object_unref(proxy);
+                       proxy = NULL;
+                       g_free(gp_path);
+                       gp_path = NULL;
+                       g_hash_table_destroy(list_hash);
+                       continue;
+               }
+
                /*Check for Connection*/
                device_proxy = dbus_g_proxy_new_for_name(
                                telephony_dbus_info.conn,
index 693878d..1183ca4 100644 (file)
@@ -107,21 +107,21 @@ extern "C" {
                IP = g_array_new(FALSE, FALSE, sizeof(gchar));  \
        } while (0)
 
-#define BT_CHECK_PARAMETER(arg) \
+#define BT_CHECK_PARAMETER(arg, func) \
        do { \
                if (arg == NULL) \
                { \
                        BT_ERR("INVALID PARAMETER"); \
-                       return BLUETOOTH_ERROR_INVALID_PARAM; \
+                       func BLUETOOTH_ERROR_INVALID_PARAM; \
                } \
        } while (0)
 
-#define BT_CHECK_ENABLED() \
+#define BT_CHECK_ENABLED(func) \
        do { \
                if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) \
                { \
                        BT_ERR("BT is not enabled"); \
-                       return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
+                       func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
                } \
        } while (0)
 
@@ -212,6 +212,8 @@ void _bt_convert_addr_string_to_type(unsigned char *addr,
 void _bt_convert_addr_type_to_string(char *address,
                                unsigned char *addr);
 
+int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
+
 int _bt_get_adapter_path(DBusGConnection *conn, char *path);
 
 DBusGProxy *_bt_get_adapter_proxy(DBusGConnection *conn);
index 0a17410..b206de9 100644 (file)
@@ -39,10 +39,12 @@ static bt_status_t adapter_status = BT_DEACTIVATED;
 
 static void __bt_core_terminate(void)
 {
-       if (main_loop)
+       if (main_loop) {
                g_main_loop_quit(main_loop);
-       else
+       } else {
+               BT_DBG("Terminating bt-core daemon");
                exit(0);
+       }
 }
 
 static void __bt_core_set_status(bt_status_t status)
@@ -394,7 +396,7 @@ static void __bt_core_sigterm_handler(int signo)
        __bt_core_terminate();
 }
 
-int main()
+int main(void)
 {
        DBusGConnection *conn = NULL;
        GError *error = NULL;
@@ -403,7 +405,7 @@ int main()
        DBusGProxy *dbus_proxy = NULL;
        struct sigaction sa;
 
-       BT_DBG("+");
+       BT_DBG("Starting bt-core daemeon");
 
        g_type_init();
 
@@ -415,10 +417,6 @@ int main()
        }
 
        bt_core = g_object_new(BT_CORE_TYPE, NULL);
-       if (bt_core == NULL) {
-               BT_ERR("bt_service is NULL");
-               goto fail;
-       }
 
        dbus_proxy = __bt_core_register(conn, bt_core);
        if (!dbus_proxy) {
@@ -453,6 +451,6 @@ fail:
 
        dbus_g_connection_unref(conn);
 
-       BT_DBG("-");
+       BT_DBG("Terminating bt-core daemon");
        return FALSE;
 }
index 8961e16..a9b292e 100644 (file)
@@ -34,7 +34,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(service_pkgs REQUIRED vconf aul vconf syspopup-caller dbus-glib-1 libprivilege-control status)
+pkg_check_modules(service_pkgs REQUIRED vconf aul vconf syspopup-caller dbus-glib-1 capi-network-tethering
+libprivilege-control status alarm-service)
 
 FOREACH(flag ${service_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall")
index 36fce3d..5127a57 100644 (file)
@@ -7,7 +7,6 @@ After=dbus.service
 [Service]
 Type=dbus
 BusName=org.projectx.bt
-Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/app/dbus/user_bus_socket
 ExecStart=/usr/bin/bt-service
 RemainAfterExit=yes
 
index 1f11666..164e931 100644 (file)
@@ -791,6 +791,15 @@ static int __bt_obexd_request(int function_name,
 
                break;
        }
+       case BT_OBEX_SERVER_IS_RECEIVING: {
+               gboolean is_receiving = FALSE;
+
+               result = _bt_obex_server_is_receiving(&is_receiving);
+
+               g_array_append_vals(*out_param1, &is_receiving,
+                               sizeof(gboolean));
+               break;
+       }
        default:
                BT_ERR("Unknown function!");
                result = BLUETOOTH_ERROR_INTERNAL;
@@ -923,10 +932,6 @@ int _bt_service_register(void)
        }
 
        bt_service = g_object_new(BT_SERVICE_TYPE, NULL);
-       if (bt_service == NULL) {
-               BT_ERR("bt_service is NULL");
-               goto fail;
-       }
 
        dbus_g_connection_register_g_object(conn, BT_SERVICE_PATH,
                                        G_OBJECT(bt_service));
index ab3201f..cd156e0 100644 (file)
 #include <string.h>
 #include <vconf.h>
 #include <status.h>
-#include <aul.h>
 #include <syspopup_caller.h>
+#include <aul.h>
+
+#include "alarm.h"
 
 #include "bluetooth-api.h"
 #include "bt-internal-types.h"
@@ -44,6 +46,8 @@
 typedef struct {
        guint event_id;
        int timeout;
+       time_t start_time;
+       int alarm_id;
 } bt_adapter_timer_t;
 
 bt_adapter_timer_t visible_timer;
@@ -57,41 +61,77 @@ static DBusGProxy *core_proxy = NULL;
 #define BT_CORE_PATH "/org/projectx/bt_core"
 #define BT_CORE_INTERFACE "org.projectx.btcore"
 
-
 static gboolean __bt_timeout_handler(gpointer user_data)
 {
        int result = BLUETOOTH_ERROR_NONE;
+       time_t current_time;
+       int time_diff;
 
-       visible_timer.timeout--;
+       /* Take current time */
+       time(&current_time);
+       time_diff = difftime(current_time, visible_timer.start_time);
 
        /* Send event to application */
        _bt_send_event(BT_ADAPTER_EVENT,
                        BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
                        DBUS_TYPE_INT32, &result,
-                       DBUS_TYPE_INT16, &visible_timer.timeout,
+                       DBUS_TYPE_INT16, &time_diff,
                        DBUS_TYPE_INVALID);
 
-       if (visible_timer.timeout <= 0) {
+       if (visible_timer.timeout <= time_diff) {
                g_source_remove(visible_timer.event_id);
                visible_timer.event_id = 0;
                visible_timer.timeout = 0;
 
                if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
                        BT_DBG("Set vconf failed\n");
-
                return FALSE;
        }
 
        return TRUE;
 }
 
+static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param)
+{
+       BT_DBG("__bt_visibility_alarm_cb \n");
+
+       /* Switch Off visibility in Bluez */
+       _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
+       visible_timer.alarm_id = 0;
+       alarmmgr_fini();
+       return 0;
+}
+
+static void __bt_visibility_alarm_create()
+{
+       alarm_id_t alarm_id;
+       int result;
+
+       result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, visible_timer.timeout,
+                                               0, NULL, &alarm_id);
+       if(result < 0) {
+               BT_DBG("Failed to create alarm error = %d\n", result);
+               alarmmgr_fini();
+       } else {
+               BT_DBG("Alarm created = %d\n", alarm_id);
+               visible_timer.alarm_id = alarm_id;
+       }
+}
+
 int __bt_set_visible_time(int timeout)
 {
+       int result;
+
        if (visible_timer.event_id > 0) {
                g_source_remove(visible_timer.event_id);
                visible_timer.event_id = 0;
        }
 
+       if (visible_timer.alarm_id > 0) {
+               alarmmgr_remove_alarm(visible_timer.alarm_id);
+               visible_timer.alarm_id = 0;
+       }
+
        visible_timer.timeout = timeout;
 
        if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0)
@@ -100,8 +140,21 @@ int __bt_set_visible_time(int timeout)
        if (timeout <= 0)
                return BLUETOOTH_ERROR_NONE;
 
+       /* Take start time */
+       time(&(visible_timer.start_time));
        visible_timer.event_id = g_timeout_add_seconds(1,
-                       __bt_timeout_handler, NULL);
+                               __bt_timeout_handler, NULL);
+
+       /* Set Alarm timer to switch off BT */
+       result = alarmmgr_init("bt-service");
+       if (result != 0)
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       result = alarmmgr_set_cb(__bt_visibility_alarm_cb, NULL);
+       if (result != 0)
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       __bt_visibility_alarm_create();
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -152,8 +205,8 @@ static int __bt_get_bonded_device_info(gchar *device_path,
        int ret;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(device_path);
-       BT_CHECK_PARAMETER(dev_info);
+       BT_CHECK_PARAMETER(device_path, return);
+       BT_CHECK_PARAMETER(dev_info, return);
 
        conn = _bt_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -452,6 +505,9 @@ void _bt_handle_adapter_added(void)
        if (_bt_register_obex_server() != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to init obex server");
 
+       if (_bt_network_activate() != BLUETOOTH_ERROR_NONE)
+               BT_ERR("Fail to activate network");
+
        /* add the vconf noti handler */
        vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
                                        __bt_phone_name_changed_cb, NULL);
@@ -648,7 +704,7 @@ int _bt_check_adapter(int *status)
        DBusGProxy *proxy;
        char *adapter_path = NULL;
 
-       BT_CHECK_PARAMETER(status);
+       BT_CHECK_PARAMETER(status, return);
 
        *status = 0; /* 0: disabled */
 
@@ -676,7 +732,7 @@ int _bt_get_local_address(bluetooth_device_address_t *local_address)
        GValue *value;
        char *address = NULL;
 
-       BT_CHECK_PARAMETER(local_address);
+       BT_CHECK_PARAMETER(local_address, return);
 
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -712,7 +768,7 @@ int _bt_get_local_name(bluetooth_device_name_t *local_name)
        char *ptr = NULL;
        int ret = BLUETOOTH_ERROR_NONE;
 
-       BT_CHECK_PARAMETER(local_name);
+       BT_CHECK_PARAMETER(local_name, return);
 
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -750,7 +806,7 @@ int _bt_set_local_name(char *local_name)
        GError *error = NULL;
        char *ptr = NULL;
 
-       BT_CHECK_PARAMETER(local_name);
+       BT_CHECK_PARAMETER(local_name, return);
 
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -785,8 +841,8 @@ int _bt_is_service_used(char *service_uuid, gboolean *used)
        GValue *value;
        int ret = BLUETOOTH_ERROR_NONE;
 
-       BT_CHECK_PARAMETER(service_uuid);
-       BT_CHECK_PARAMETER(used);
+       BT_CHECK_PARAMETER(service_uuid, return);
+       BT_CHECK_PARAMETER(used, return);
 
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -827,7 +883,7 @@ int _bt_get_discoverable_mode(int *mode)
        GValue *value;
        GValue *timeout_value;
 
-       BT_CHECK_PARAMETER(mode);
+       BT_CHECK_PARAMETER(mode, return);
 
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -936,7 +992,7 @@ int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
        if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
                timeout = -1;
 
-       __bt_set_visible_time(timeout);
+       ret = __bt_set_visible_time(timeout);
 
 done:
        g_value_unset(&val_timeout);
@@ -1053,7 +1109,7 @@ int _bt_get_bonded_devices(GArray **dev_list)
        GError *error = NULL;
        DBusGProxy *proxy;
 
-       BT_CHECK_PARAMETER(dev_list);
+       BT_CHECK_PARAMETER(dev_list, return);
 
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -1102,8 +1158,8 @@ int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
        DBusGProxy *adapter_proxy;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_PARAMETER(dev_info);
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(dev_info, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -1129,9 +1185,16 @@ int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
 
 int _bt_get_timeout_value(int *timeout)
 {
-       *timeout = 0;
+       time_t current_time;
+       int time_diff;
+
+       /* Take current time */
+       time(&current_time);
+       time_diff = difftime(current_time, visible_timer.start_time);
+
+       BT_DBG("Time diff = %d\n", time_diff);
 
-       *timeout = visible_timer.timeout;
+       *timeout = visible_timer.timeout - time_diff;
 
        return BLUETOOTH_ERROR_NONE;
 }
index d4b4d73..6d1f697 100644 (file)
@@ -24,6 +24,7 @@
 #include <stacktrim.h>
 #include <syspopup_caller.h>
 #include <vconf.h>
+#include <tethering.h>
 
 #include "bt-internal-types.h"
 #include "bt-service-common.h"
@@ -33,6 +34,7 @@
 #include "bt-service-event.h"
 #include "bt-service-rfcomm-server.h"
 #include "bt-service-device.h"
+#include "bt-service-audio.h"
 
 #define BT_APP_AUTHENTICATION_TIMEOUT          35
 #define BT_APP_AUTHORIZATION_TIMEOUT           15
 #define SPP_UUID "00001101-0000-1000-8000-00805f9b34fb"
 #define PBAP_UUID "0000112f-0000-1000-8000-00805f9b34fb"
 #define MAP_UUID "00001132-0000-1000-8000-00805f9b34fb"
+#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb"
+#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb"
+#define BNEP_UUID "0000000f-0000-1000-8000-00805f9b34fb"
+#define HID_UUID "00001124-0000-1000-8000-00805f9b34fb"
 
 #define BT_AGENT_OBJECT "/org/bluez/agent/frwk_agent"
 #define BT_AGENT_INTERFACE "org.bluez.Agent"
@@ -52,7 +58,7 @@
 #define BT_AGENT_SIGNAL_OBEX_AUTHORIZE "ObexAuthorize"
 
 #define BT_PIN_MAX_LENGTH 16
-#define BT_PASSKEY_MAX_LENGTH 6
+#define BT_PASSKEY_MAX_LENGTH 4
 
 #define BT_AGENT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
 
@@ -232,9 +238,14 @@ static gboolean __pincode_request(GapAgent *agent, DBusGProxy *device)
                gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, "0000",
                                                                        NULL);
        } else if (__bt_agent_is_hid_keyboard(device_class)) {
-               char str_passkey[7] = { 0 };
+               char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
 
-               __bt_agent_generate_passkey(str_passkey, sizeof(str_passkey));
+               if (__bt_agent_generate_passkey(str_passkey,
+                                       BT_PASSKEY_MAX_LENGTH) != 0) {
+                       gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT,
+                                               "", NULL);
+                       goto done;
+               }
 
                gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT,
                                                        str_passkey, NULL);
@@ -428,6 +439,12 @@ static gboolean __pairing_cancel_request(GapAgent *agent, const char *address)
        return TRUE;
 }
 
+static gboolean __a2dp_authorize_request_check(void)
+{
+       /* Check for existing Media device to disconnect */
+       return _bt_is_headset_type_connected(BT_AUDIO_A2DP, NULL);
+}
+
 static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
                                                        const char *uuid)
 {
@@ -435,17 +452,38 @@ static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
        GValue *value;
        const gchar *address;
        const gchar *name;
+       bool enabled;
        gboolean trust;
        gboolean paired;
+       tethering_h tethering = NULL;
        GError *error = NULL;
+       int ret;
        int result = BLUETOOTH_ERROR_NONE;
        int request_type = BT_AGENT_EVENT_AUTHORIZE_REQUEST;
 
        BT_DBG("+\n");
 
+       BT_DBG("+\n");
+
+       /* Check if already Media connection exsist */
+       if (!strcasecmp(uuid, A2DP_UUID)) {
+               gboolean ret = FALSE;
+
+               ret = __a2dp_authorize_request_check();
+
+               if (ret) {
+                       BT_DBG("Already one A2DP device connected \n");
+                       gap_agent_reply_authorize(agent, GAP_AGENT_REJECT,
+                                             NULL);
+                       goto done;
+               }
+       }
+       /* Check completed */
+
        if (!strcasecmp(uuid, HFP_AUDIO_GATEWAY_UUID) ||
-                                       !strcasecmp(uuid, A2DP_UUID) ||
-                                       !strcasecmp(uuid, AVRCP_TARGET_UUID)) {
+            !strcasecmp(uuid, A2DP_UUID) ||
+             !strcasecmp(uuid, HID_UUID) ||
+              !strcasecmp(uuid, AVRCP_TARGET_UUID)) {
                BT_DBG("Auto accept authorization for audio device (HFP, A2DP, AVRCP) [%s]", uuid);
                gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
                                              NULL);
@@ -453,6 +491,42 @@ static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
                goto done;
        }
 
+       if (!strcasecmp(uuid, NAP_UUID) ||
+            !strcasecmp(uuid, GN_UUID) ||
+             !strcasecmp(uuid, BNEP_UUID)) {
+
+               BT_DBG("Network connection request: %s", uuid);
+               ret = tethering_create(&tethering);
+
+               if (ret != TETHERING_ERROR_NONE) {
+                       BT_ERR("Fail to create tethering: %d", ret);
+                       goto fail;
+               }
+
+               enabled = tethering_is_enabled(tethering, TETHERING_TYPE_BT);
+
+               ret = tethering_destroy(tethering);
+
+               if (ret != TETHERING_ERROR_NONE) {
+                       BT_ERR("Fail to create tethering: %d", ret);
+               }
+
+               if (enabled != true) {
+                       BT_ERR("BT tethering is not enabled");
+                       goto fail;
+               }
+
+               gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
+                                             NULL);
+               goto done;
+fail:
+               gap_agent_reply_authorize(agent, GAP_AGENT_REJECT,
+                     NULL);
+
+               goto done;
+       }
+
+
        dbus_g_proxy_call(device, "GetProperties", &error, G_TYPE_INVALID,
                                dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
                                                                 G_TYPE_VALUE),
@@ -839,15 +913,13 @@ static int __bt_agent_generate_passkey(char *passkey, int size)
        if (random_fd < 0)
                return -1;
 
-       for (i = 0; i < size - 1; i++) {
+       for (i = 0; i < size; i++) {
                len = read(random_fd, &value, sizeof(value));
                passkey[i] = '0' + (value % 10);
        }
 
        close(random_fd);
 
-       passkey[size - 1] = '\0';
-
        BT_DBG("passkey: %s", passkey);
 
        return 0;
index ef41cc0..477438a 100644 (file)
 #include "bt-service-event.h"
 #include "bt-service-util.h"
 
+typedef struct {
+       unsigned int type;
+       int device_state;
+       char device_address[BT_ADDRESS_STRING_SIZE + 1];
+} bt_connected_headset_data_t;
+
+static GList *g_connected_list;
+
+static bt_headset_wait_t *g_wait_data;
+
+static void __bt_remove_device_from_wait_list();
+
+static void __bt_free_wait_data();
+
 static void __bt_audio_request_cb(DBusGProxy *proxy, DBusGProxyCall *call,
                                    gpointer user_data)
 {
@@ -61,10 +75,26 @@ static void __bt_audio_request_cb(DBusGProxy *proxy, DBusGProxyCall *call,
                goto done;
        }
 
-       if (g_error != NULL) {
-               BT_ERR("Audio Connect Dbus Call Error: %s\n", g_error->message);
-               result = BLUETOOTH_ERROR_INTERNAL;
+       if (g_error == NULL)
                goto dbus_return;
+
+       BT_ERR("Audio Connect Dbus Call Error: %s\n", g_error->message);
+
+       result = BLUETOOTH_ERROR_INTERNAL;
+
+       /* Remove the device from the list */
+       _bt_remove_headset_from_list(BT_AUDIO_ALL, func_data->address);
+
+       /* Error, check if any waiting device is there */
+       if (g_wait_data == NULL)
+               goto dbus_return;
+
+       if (g_strcmp0(g_wait_data->address, func_data->address) != 0) {
+               bluetooth_device_address_t device_address;
+               _bt_convert_addr_string_to_type(device_address.addr,
+                                                       g_wait_data->address);
+               _bt_audio_connect(g_wait_data->req_id, g_wait_data->type,
+                               &device_address, g_wait_data->out_param1);
        }
 
        /* Event will be sent by the event reciever */
@@ -132,6 +162,7 @@ static char *__bt_get_audio_path(bluetooth_device_address_t *address)
                                        BT_BLUEZ_NAME,
                                        object_path,
                                        BT_HEADSET_INTERFACE);
+
        retv_if(audio_proxy == NULL, NULL);
 
        g_object_unref(audio_proxy);
@@ -176,6 +207,208 @@ static char *__bt_get_connected_audio_path(void)
        return audio_path;
 }
 
+static void __bt_free_wait_data()
+{
+       if (g_wait_data != NULL) {
+               g_free(g_wait_data->address);
+               g_free(g_wait_data);
+               g_wait_data = NULL;
+       }
+}
+
+static void __bt_remove_device_from_wait_list()
+{
+       /* Before deleting the request update the UI */
+       GArray *out_param_1 = NULL;
+       GArray *out_param_2 = NULL;
+       int result = BLUETOOTH_ERROR_INTERNAL;
+       request_info_t *req_info;
+
+       req_info = _bt_get_request_info(g_wait_data->req_id);
+       if (req_info == NULL) {
+               BT_ERR("req_info == NULL");
+               return;
+       }
+
+       out_param_1 = g_array_new(FALSE, FALSE, sizeof(gchar));
+       out_param_2 = g_array_new(FALSE, FALSE, sizeof(gchar));
+       g_array_append_vals(out_param_1, g_wait_data->address,
+                               BT_ADDRESS_STR_LEN);
+       g_array_append_vals(out_param_2, &result, sizeof(int));
+       dbus_g_method_return(req_info->context,
+                               out_param_1, out_param_2);
+       g_array_free(out_param_1, TRUE);
+       g_array_free(out_param_2, TRUE);
+       _bt_delete_request_list(g_wait_data->req_id);
+}
+
+static void __bt_set_headset_disconnection_type(const char *address)
+{
+       bt_connected_headset_data_t *connected_device;
+       GList *node;
+
+       BT_DBG("__bt_set_headset_disconnection_type \n");
+
+       node = g_list_first(g_connected_list);
+       while (node != NULL) {
+               connected_device = node->data;
+               if (g_strcmp0(connected_device->device_address, address) == 0) {
+                       g_wait_data->disconnection_type = connected_device->type;
+                       return;
+               }
+               node = g_list_next(node);
+       }
+}
+
+gboolean _bt_is_headset_type_connected(int type, char *address)
+{
+       GList *node;
+
+       BT_DBG("_bt_is_headset_type_connected \n");
+
+       node = g_list_first(g_connected_list);
+       while (node != NULL) {
+               bt_connected_headset_data_t *connected_device = node->data;
+
+               if (connected_device->type & type) {
+                       if (address != NULL)
+                               g_strlcpy(address, connected_device->device_address,
+                                               BT_ADDRESS_STRING_SIZE + 1);
+                       return TRUE;
+               }
+
+               node = g_list_next(node);
+       }
+       return FALSE;
+}
+
+static gboolean __bt_is_headset_connected(int type, int req_id,
+                               const char *address, GArray **out_param1)
+{
+       gboolean connected;
+       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+       bluetooth_device_address_t device_address;
+
+       BT_DBG("__bt_is_headset_connected \n");
+
+       /* Check if any other headset is connected */
+       connected = _bt_is_headset_type_connected(type, connected_address);
+
+       if (!connected)
+               return FALSE;
+
+       /* If already one device is waiting, remove current waiting device and add new */
+       if (g_wait_data != NULL) {
+               if (g_strcmp0(g_wait_data->address, address) != 0) {
+                       __bt_remove_device_from_wait_list();
+                       __bt_free_wait_data();
+               }
+       }
+
+       if (g_wait_data == NULL) {
+               g_wait_data = g_malloc0(sizeof(bt_headset_wait_t));
+               g_wait_data->address = g_strdup(address);
+               g_wait_data->req_id = req_id;
+               g_wait_data->type = type;
+               g_wait_data->ag_flag = FALSE;
+               g_wait_data->out_param1 = out_param1;
+
+               /* Set disconnection type */
+               __bt_set_headset_disconnection_type(connected_address);
+       }
+
+       /* Convert BD adress from string type */
+       _bt_convert_addr_string_to_type(device_address.addr, connected_address);
+       _bt_audio_disconnect(0, type, &device_address, NULL);
+       return TRUE;
+}
+
+void _bt_set_audio_wait_data_flag(gboolean flag)
+{
+       BT_DBG("_bt_set_audio_wait_data_flag \n");
+       g_wait_data->ag_flag = flag;
+}
+
+bt_headset_wait_t *_bt_get_audio_wait_data(void)
+{
+       BT_DBG("_bt_get_audio_wait_data \n");
+       return g_wait_data;
+}
+
+void _bt_add_headset_to_list(int type, int status, const char *address)
+{
+       bt_connected_headset_data_t *connected_device;
+       bt_connected_headset_data_t *device;
+       GList *node;
+
+       BT_DBG("_bt_add_headset_to_list \n");
+
+       node = g_list_first(g_connected_list);
+       while (node != NULL) {
+               device = (bt_connected_headset_data_t *)node->data;
+
+               if (g_strcmp0(device->device_address, address) == 0) {
+                       BT_DBG("Address match, update connection type \n");
+                       device->type |= type;
+                       device->device_state = status;
+                       return;
+               }
+               node = g_list_next(node);
+       }
+
+       connected_device = g_malloc0(sizeof(bt_connected_headset_data_t));
+       connected_device->type |= type;
+       connected_device->device_state = status;
+       g_strlcpy(connected_device->device_address, address,
+                               sizeof(connected_device->device_address));
+       g_connected_list = g_list_append(g_connected_list, connected_device);
+}
+
+void _bt_remove_headset_from_list(int type, const char *address)
+{
+       GList *node;
+
+       BT_DBG("_bt_remove_headset_from_list \n");
+
+       node = g_list_first(g_connected_list);
+       while (node != NULL) {
+               bt_connected_headset_data_t *connected_device = node->data;
+
+               if (g_strcmp0(connected_device->device_address, address) != 0) {
+                       node = g_list_next(node);
+                       continue;
+               }
+
+               BT_DBG("Address match \n");
+
+               BT_DBG("Connection type = %x\n", connected_device->type);
+
+               switch (type) {
+               case BT_AUDIO_A2DP:
+                       if (connected_device->type & BT_AUDIO_A2DP)
+                               connected_device->type &= ~(BT_AUDIO_A2DP);
+                       break;
+               case BT_AUDIO_HSP:
+                       if (connected_device->type & BT_AUDIO_HSP)
+                               connected_device->type &= ~(BT_AUDIO_HSP);
+                       break;
+               case BT_AUDIO_ALL:
+                       if (connected_device->type & BT_AUDIO_ALL)
+                               connected_device->type &= ~(BT_AUDIO_ALL);
+                       break;
+               }
+
+               BT_DBG("Connection type = %x\n", connected_device->type);
+
+               if (connected_device->type == 0x00) {
+                       g_connected_list = g_list_remove(g_connected_list, connected_device);
+                       g_free(connected_device);
+               }
+
+               node = g_list_next(node);
+       }
+}
+
 int _bt_audio_connect(int request_id, int type,
                bluetooth_device_address_t *device_address,
                GArray **out_param1)
@@ -189,7 +422,7 @@ int _bt_audio_connect(int request_id, int type,
        DBusGProxy *profile_proxy;
        DBusGConnection *g_conn;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
@@ -209,6 +442,9 @@ int _bt_audio_connect(int request_id, int type,
                goto fail;
        }
 
+       if (__bt_is_headset_connected(type, request_id, address, out_param1))
+               return BLUETOOTH_ERROR_NONE;
+
        adapter_proxy = _bt_get_adapter_proxy();
        if (adapter_proxy == NULL) {
                result = BLUETOOTH_ERROR_INTERNAL;
@@ -258,6 +494,9 @@ int _bt_audio_connect(int request_id, int type,
                result = BLUETOOTH_ERROR_INTERNAL;
                goto fail;
        }
+       /* Add data to the connected list */
+       _bt_add_headset_to_list(type, BT_STATE_CONNECTING, address);
+       __bt_free_wait_data();
 
        return BLUETOOTH_ERROR_NONE;
 fail:
@@ -280,7 +519,7 @@ int _bt_audio_disconnect(int request_id, int type,
        DBusGProxy *profile_proxy;
        DBusGConnection *g_conn;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
@@ -331,22 +570,30 @@ int _bt_audio_disconnect(int request_id, int type,
                goto fail;
        }
 
-       func_data = g_malloc0(sizeof(bt_function_data_t));
-       func_data->address = g_strdup(address);
-       func_data->req_id = request_id;
-
-       if (!dbus_g_proxy_begin_call(profile_proxy, "Disconnect",
-                       (DBusGProxyCallNotify)__bt_audio_request_cb,
-                       func_data, NULL,
-                       G_TYPE_INVALID)) {
-               BT_ERR("Audio disconnect Dbus Call Error");
-               g_object_unref(profile_proxy);
-
-               g_free(func_data->address);
-               g_free(func_data);
-
-               result = BLUETOOTH_ERROR_INTERNAL;
-               goto fail;
+       if (g_wait_data != NULL) {
+               if (!dbus_g_proxy_begin_call(profile_proxy, "Disconnect",
+                               NULL, NULL, NULL, G_TYPE_INVALID)) {
+                       BT_ERR("Audio disconnect Dbus Call Error");
+                       g_object_unref(profile_proxy);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+       } else {
+               func_data = g_malloc0(sizeof(bt_function_data_t));
+               func_data->address = g_strdup(address);
+               func_data->req_id = request_id;
+               if (!dbus_g_proxy_begin_call(profile_proxy, "Disconnect",
+                               (DBusGProxyCallNotify)__bt_audio_request_cb,
+                               func_data, NULL,
+                               G_TYPE_INVALID)) {
+                       BT_ERR("Audio disconnect Dbus Call Error");
+                       g_object_unref(profile_proxy);
+
+                       g_free(func_data->address);
+                       g_free(func_data);
+
+                       result = BLUETOOTH_ERROR_INTERNAL;
+                       goto fail;
+               }
        }
 
        return BLUETOOTH_ERROR_NONE;
index 88183bf..aa10af8 100644 (file)
@@ -336,8 +336,8 @@ static int __bt_retry_bond(void)
 {
        DBusGProxy *adapter_proxy;
 
-       BT_CHECK_PARAMETER(bonding_info);
-       BT_CHECK_PARAMETER(bonding_info->addr);
+       BT_CHECK_PARAMETER(bonding_info, return);
+       BT_CHECK_PARAMETER(bonding_info->addr, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -366,8 +366,8 @@ static int __bt_remove_and_bond(void)
        GError *err = NULL;
        char *device_path = NULL;
 
-       BT_CHECK_PARAMETER(bonding_info);
-       BT_CHECK_PARAMETER(bonding_info->addr);
+       BT_CHECK_PARAMETER(bonding_info, return);
+       BT_CHECK_PARAMETER(bonding_info->addr, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -398,8 +398,8 @@ static int __bt_cancel_and_bond(void)
        DBusGProxy *adapter_proxy;
        GError *err = NULL;
 
-       BT_CHECK_PARAMETER(bonding_info);
-       BT_CHECK_PARAMETER(bonding_info->addr);
+       BT_CHECK_PARAMETER(bonding_info, return);
+       BT_CHECK_PARAMETER(bonding_info->addr, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -441,7 +441,9 @@ static void __bt_bond_device_cb(DBusGProxy *proxy, DBusGProxyCall *call,
        if (bonding_info == NULL) {
                /* Send reply */
                BT_ERR("bonding_info == NULL");
-               goto done;
+               if (err)
+                       g_error_free(err);
+               return;
        }
 
        req_info = _bt_get_request_info(bonding_info->req_id);
@@ -558,7 +560,7 @@ int _bt_bond_device(int request_id,
        void *agent;
        bluetooth_device_info_t dev_info;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        if (bonding_info) {
                BT_ERR("Bonding in progress");
@@ -720,7 +722,7 @@ int _bt_unbond_device(int request_id,
        int result = BLUETOOTH_ERROR_INTERNAL;
        bluetooth_device_info_t dev_info;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -979,7 +981,7 @@ int _bt_search_device(int request_id,
        DBusGConnection *conn;
        int result = BLUETOOTH_ERROR_INTERNAL;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        if (searching_info) {
                BT_ERR("Service searching in progress");
@@ -1101,8 +1103,8 @@ int _bt_set_alias(bluetooth_device_address_t *device_address,
        GValue name = { 0 };
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_PARAMETER(alias);
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(alias, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -1161,7 +1163,7 @@ int _bt_set_authorization(bluetooth_device_address_t *device_address,
        DBusGConnection *conn;
        int ret = BLUETOOTH_ERROR_NONE;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
index 4d2cb76..1251fc8 100644 (file)
@@ -36,6 +36,7 @@
 #include "bt-service-device.h"
 #include "bt-service-obex-server.h"
 #include "bt-service-rfcomm-server.h"
+#include "bt-service-audio.h"
 
 static DBusGConnection *manager_conn;
 static DBusGConnection *obexd_conn;
@@ -277,6 +278,7 @@ void _bt_handle_adapter_event(DBusMessage *msg)
                }
 
                dbus_message_iter_get_basic(&item_iter, &property);
+               BT_DBG("member = PropertyChanged[%s]", property);
 
                ret_if(property == NULL);
 
@@ -376,6 +378,14 @@ void _bt_handle_adapter_event(DBusMessage *msg)
                                        DBUS_TYPE_INT32, &result,
                                        DBUS_TYPE_INT16, &mode,
                                        DBUS_TYPE_INVALID);
+               } else if (strcasecmp(property, "Powered") == 0) {
+                       gboolean powered = FALSE;
+                       dbus_message_iter_next(&item_iter);
+                       dbus_message_iter_recurse(&item_iter, &value_iter);
+                       dbus_message_iter_get_basic(&value_iter, &powered);
+                       BT_DBG("Powered = %d", powered);
+                       if (powered == FALSE)
+                               _bt_disable_adapter();
                }
        } else if (strcasecmp(member, "DeviceFound") == 0) {
                const char *bdaddr;
@@ -766,9 +776,12 @@ void _bt_handle_headset_event(DBusMessage *msg)
 
        ret_if(property == NULL);
 
+       BT_DBG("Property = %s \n", property);
+
        /* We allow only 1 headset connection (HSP or HFP)*/
        if (strcasecmp(property, "Connected") == 0) {
                int event = BLUETOOTH_EVENT_NONE;
+               bt_headset_wait_t *wait_list;
                char *address;
 
                dbus_message_iter_next(&item_iter);
@@ -792,6 +805,29 @@ void _bt_handle_headset_event(DBusMessage *msg)
                        DBUS_TYPE_STRING, &address,
                        DBUS_TYPE_INVALID);
 
+               if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
+                       /* Remove data from the connected list */
+                       _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
+
+                       wait_list = _bt_get_audio_wait_data();
+                       if (wait_list == NULL) {
+                               g_free(address);
+                               return;
+                       }
+
+                       bluetooth_device_address_t device_address;
+
+                       _bt_set_audio_wait_data_flag(TRUE);
+
+                       _bt_convert_addr_string_to_type(device_address.addr,
+                                                       wait_list->address);
+                       _bt_audio_connect(wait_list->req_id, wait_list->type,
+                                       &device_address, wait_list->out_param1);
+               } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
+                       /* Add data to the connected list */
+                       _bt_add_headset_to_list(BT_AUDIO_HSP,
+                                               BT_STATE_CONNECTED, address);
+               }
                g_free(address);
        } else if (strcasecmp(property, "State") == 0) {
                int event = BLUETOOTH_EVENT_NONE;
@@ -809,15 +845,15 @@ void _bt_handle_headset_event(DBusMessage *msg)
 
                /* This code assumes we support only 1 headset connection */
                /* Need to use the headset list, if we support multi-headsets */
-               if (strcasecmp(property, "Playing") == 0) {
+               if (strcasecmp(state, "Playing") == 0) {
                        event = BLUETOOTH_EVENT_AG_AUDIO_CONNECTED;
                        sco_connected = TRUE;
-               } else if (strcasecmp(property, "connected") == 0 ||
-                           strcasecmp(property, "disconnected") == 0) {
+               } else if (strcasecmp(state, "connected") == 0 ||
+                           strcasecmp(state, "disconnected") == 0) {
                        event = BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED;
                        sco_connected = FALSE;
                } else {
-                       BT_ERR("Not handled state");
+                       BT_ERR("Not handled state - %s", state);
                        g_free(address);
                        return;
                }
@@ -882,6 +918,8 @@ void _bt_handle_sink_event(DBusMessage *msg)
        const char *path = dbus_message_get_path(msg);
        const char *property = NULL;
 
+       bt_headset_wait_t *wait_list;
+
        ret_if(member == NULL);
 
        dbus_message_iter_init(msg, &item_iter);
@@ -922,6 +960,53 @@ void _bt_handle_sink_event(DBusMessage *msg)
                        DBUS_TYPE_STRING, &address,
                        DBUS_TYPE_INVALID);
 
+               if (event == BLUETOOTH_EVENT_AV_DISCONNECTED) {
+                       /* Remove data from the connected list */
+                       _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
+                       wait_list = _bt_get_audio_wait_data();
+                       if (wait_list == NULL) {
+                               g_free(address);
+                               return;
+                       }
+
+                       if (((wait_list->type == BT_AUDIO_ALL) &&
+                               (wait_list->ag_flag == TRUE)) ||
+                               (wait_list->type == BT_AUDIO_A2DP) ||
+                               (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
+                               bluetooth_device_address_t device_address;
+                               _bt_convert_addr_string_to_type(
+                                                       device_address.addr,
+                                                       wait_list->address);
+
+                               _bt_audio_connect(wait_list->req_id,
+                                                       wait_list->type,
+                                                       &device_address,
+                                                       wait_list->out_param1);
+                       }
+               } else if (event == BLUETOOTH_EVENT_AV_CONNECTED){
+                       /* Check for existing Media device to disconnect */
+                       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+                       bluetooth_device_address_t device_address;
+                       gboolean connected;
+
+                       connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
+                                                               connected_address);
+                       if (connected) {
+                               /* Match connected device address */
+                               if (g_strcmp0(connected_address, address) != 0) {
+                                       /* Convert BD adress from string type */
+                                       _bt_convert_addr_string_to_type(
+                                                       device_address.addr,
+                                                       connected_address);
+                                       _bt_audio_disconnect(0, BT_AUDIO_A2DP,
+                                                       &device_address, NULL);
+                               }
+                       }
+
+                       /* Add data to the connected list */
+                       _bt_add_headset_to_list(BT_AUDIO_A2DP,
+                                       BT_STATE_CONNECTED, address);
+               }
                g_free(address);
        }
 }
index 4b7a829..bf76219 100644 (file)
@@ -174,7 +174,7 @@ int _bt_hid_connect(int request_id,
        DBusGProxy *hid_proxy;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -223,7 +223,7 @@ int _bt_hid_disconnect(int request_id,
        DBusGProxy *hid_proxy;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
index c3a13f8..911bfa7 100644 (file)
@@ -45,6 +45,8 @@ static void __bt_release_service(void)
        _bt_deinit_proxys();
 
        _bt_clear_request_list();
+
+       BT_DBG("Terminating the bt-service daemon");
 }
 
 static void __bt_sigterm_handler(int signo)
@@ -123,9 +125,10 @@ static gboolean __bt_check_bt_service(void *data)
        return FALSE;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct sigaction sa;
+       BT_DBG("Starting the bt-service daemon");
 
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = __bt_sigterm_handler;
@@ -176,8 +179,6 @@ int main(int argc, char *argv[])
 
        __bt_release_service();
 
-       BT_DBG("-");
-
        return 0;
 }
 
index 81d0d59..7f9d579 100644 (file)
@@ -254,7 +254,7 @@ int _bt_network_connect(int request_id, int role,
        DBusGProxy *profile_proxy;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        switch (role) {
        case BLUETOOTH_NETWORK_PANU_ROLE:
@@ -322,7 +322,7 @@ int _bt_network_disconnect(int request_id,
        DBusGProxy *profile_proxy;
        DBusGConnection *conn;
 
-       BT_CHECK_PARAMETER(device_address);
+       BT_CHECK_PARAMETER(device_address, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
index a9cfb85..e339846 100644 (file)
@@ -239,9 +239,10 @@ static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info,
        GHashTable *hash = NULL;
        GValue *value;
        DBusGProxy *transfer_proxy;
+       char *bdaddress;
 
-       BT_CHECK_PARAMETER(transfer_info);
-       BT_CHECK_PARAMETER(transfer_path);
+       BT_CHECK_PARAMETER(transfer_info, return);
+       BT_CHECK_PARAMETER(transfer_path, return);
 
        transfer_proxy = __bt_get_transfer_proxy(transfer_path);
 
@@ -259,9 +260,13 @@ static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info,
 
        value = g_hash_table_lookup(hash, "Operation");
        transfer_info->type = value ? g_strdup(g_value_get_string(value)) : NULL;
+       if (!transfer_info->type)
+               goto fail;
 
        value = g_hash_table_lookup(hash, "Filename");
        transfer_info->filename = value ? g_strdup(g_value_get_string(value)) : NULL;
+       if (!transfer_info->filename)
+               goto fail;
 
        value = g_hash_table_lookup(hash, "Size");
        transfer_info->file_size  = value ? g_value_get_uint64(value) : 0;
@@ -269,11 +274,23 @@ static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info,
        transfer_info->path = g_strdup(transfer_path);
        transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
 
-       transfer_info->device_name = g_strdup("");
+       value = g_hash_table_lookup(hash, "Address");
+       bdaddress = value ? (char *)g_value_get_string(value) : NULL;
+       if (!bdaddress)
+               goto fail;
 
-       g_hash_table_destroy(hash);
+       transfer_info->device_name = __bt_get_remote_device_name(bdaddress);
+       if (!transfer_info->device_name)
+               transfer_info->device_name = g_strdup(bdaddress);
 
+       g_hash_table_destroy(hash);
+       g_object_unref(transfer_proxy);
        return BLUETOOTH_ERROR_NONE;
+
+fail:
+       g_hash_table_destroy(hash);
+       g_object_unref(transfer_proxy);
+       return BLUETOOTH_ERROR_INTERNAL;
 }
 
 static gboolean __bt_authorize_cb(DBusGMethodInvocation *context,
@@ -619,7 +636,7 @@ int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native)
        char file_path[BT_FILE_PATH_MAX] = { 0 };
        bt_server_info_t *server_info;
 
-       BT_CHECK_PARAMETER(filename);
+       BT_CHECK_PARAMETER(filename, return);
 
        retv_if(agent_info.auth_info == NULL, BLUETOOTH_ERROR_INTERNAL);
 
@@ -674,7 +691,7 @@ int _bt_obex_server_set_destination_path(const char *dest_path,
        DIR *dp = NULL;
        bt_server_info_t *server_info;
 
-       BT_CHECK_PARAMETER(dest_path);
+       BT_CHECK_PARAMETER(dest_path, return);
 
        dp = opendir(dest_path);
 
@@ -705,7 +722,7 @@ int _bt_obex_server_set_root(const char *root)
        GValue folder = { 0 };
        DIR *dp = NULL;
 
-       BT_CHECK_PARAMETER(root);
+       BT_CHECK_PARAMETER(root, return);
 
        retv_if(agent_info.proxy == NULL,
                                BLUETOOTH_ERROR_INTERNAL);
@@ -776,7 +793,7 @@ int _bt_obex_server_cancel_all_transfers(void)
 
 int _bt_obex_server_is_activated(gboolean *activated)
 {
-       BT_CHECK_PARAMETER(activated);
+       BT_CHECK_PARAMETER(activated, return);
 
        if (agent_info.custom_server) {
                *activated = TRUE;
@@ -789,7 +806,7 @@ int _bt_obex_server_is_activated(gboolean *activated)
 
 int _bt_obex_server_check_allocation(gboolean *allocation)
 {
-       BT_CHECK_PARAMETER(allocation);
+       BT_CHECK_PARAMETER(allocation, return);
 
        if (agent_info.native_server || agent_info.custom_server) {
                *allocation = TRUE;
@@ -802,7 +819,7 @@ int _bt_obex_server_check_allocation(gboolean *allocation)
 
 int _bt_obex_server_check_termination(char *sender)
 {
-       BT_CHECK_PARAMETER(sender);
+       BT_CHECK_PARAMETER(sender, return);
 
        if (agent_info.native_server) {
                if (g_strcmp0(sender, agent_info.native_server->sender) == 0) {
@@ -821,6 +838,19 @@ int _bt_obex_server_check_termination(char *sender)
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_obex_server_is_receiving(gboolean *receiving)
+{
+       BT_CHECK_PARAMETER(receiving, return);
+
+       if (transfers == NULL || g_slist_length(transfers) == 0) {
+               *receiving = FALSE;
+       } else {
+               *receiving = TRUE;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data)
 {
        request_info_t *req_info;
index a81e425..9ed31ec 100644 (file)
@@ -38,7 +38,7 @@ int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
        unsigned char *local_randomizer = NULL;
        DBusConnection *conn;
 
-       BT_CHECK_PARAMETER(local_oob_data);
+       BT_CHECK_PARAMETER(local_oob_data, return);
 
        conn = _bt_get_system_conn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -104,8 +104,8 @@ int _bt_oob_add_remote_data(
        unsigned char *remote_randomizer;
        DBusConnection *conn;
 
-       BT_CHECK_PARAMETER(remote_device_address);
-       BT_CHECK_PARAMETER(remote_oob_data);
+       BT_CHECK_PARAMETER(remote_device_address, return);
+       BT_CHECK_PARAMETER(remote_oob_data, return);
 
        conn = _bt_get_system_conn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -169,7 +169,7 @@ int _bt_oob_remove_remote_data(
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
        DBusConnection *conn;
 
-       BT_CHECK_PARAMETER(remote_device_address);
+       BT_CHECK_PARAMETER(remote_device_address, return);
 
        conn = _bt_get_system_conn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
index c0c7d08..575b34e 100644 (file)
@@ -454,8 +454,8 @@ static int __bt_opp_client_start_sending(int request_id, char *address,
        DBusGProxyCall *proxy_call;
        char *agent_path;
 
-       BT_CHECK_PARAMETER(address);
-       BT_CHECK_PARAMETER(file_name_array);
+       BT_CHECK_PARAMETER(address, return);
+       BT_CHECK_PARAMETER(file_name_array, return);
 
        /* Get the session bus. */
        g_conn = _bt_get_session_gconn();
@@ -522,8 +522,8 @@ int _bt_opp_client_push_files(int request_id, DBusGMethodInvocation *context,
        int result = BLUETOOTH_ERROR_NONE;
        int i;
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_PARAMETER(file_path);
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_PARAMETER(file_path, return);
 
        /* Implement the queue */
        _bt_convert_addr_type_to_string(address, remote_address->addr);
@@ -612,7 +612,7 @@ int _bt_opp_client_cancel_all_transfers(void)
 
 int _bt_opp_client_is_sending(gboolean *sending)
 {
-       BT_CHECK_PARAMETER(sending);
+       BT_CHECK_PARAMETER(sending, return);
 
        *sending = sending_info ? TRUE : FALSE;
 
index dfa9681..f0da649 100644 (file)
@@ -517,8 +517,8 @@ int _bt_rfcomm_connect_using_uuid(int request_id,
        gchar *device_path = NULL;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
 
-       BT_CHECK_PARAMETER(address);
-       BT_CHECK_PARAMETER(remote_uuid);
+       BT_CHECK_PARAMETER(address, return);
+       BT_CHECK_PARAMETER(remote_uuid, return);
        retv_if(rfcomm_info != NULL, BLUETOOTH_ERROR_DEVICE_BUSY);
 
        adapter_proxy = _bt_get_adapter_proxy();
@@ -573,7 +573,7 @@ int _bt_rfcomm_connect_using_channel(int request_id,
        gchar *device_path = NULL;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
 
-       BT_CHECK_PARAMETER(address);
+       BT_CHECK_PARAMETER(address, return);
        retv_if(rfcomm_info != NULL, BLUETOOTH_ERROR_DEVICE_BUSY);
 
        adapter_proxy = _bt_get_adapter_proxy();
@@ -711,7 +711,7 @@ int _bt_rfcomm_cancel_connect(void)
 
 int _bt_rfcomm_is_connected(gboolean *connected)
 {
-       BT_CHECK_PARAMETER(connected);
+       BT_CHECK_PARAMETER(connected, return);
 
        *connected = (client_list == NULL || g_slist_length(client_list) == 0) ?
                                        FALSE : TRUE;
@@ -726,8 +726,8 @@ int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address,
        bt_rfcomm_info_t *client_info;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
 
-       BT_CHECK_PARAMETER(device_address);
-       BT_CHECK_PARAMETER(connected);
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(connected, return);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
index bb6354e..4a8695a 100644 (file)
@@ -242,7 +242,7 @@ int _bt_rfcomm_create_socket(char *sender, char *uuid)
        int socket_fd;
        bt_rfcomm_server_info_t *server_info;
 
-       BT_CHECK_PARAMETER(uuid);
+       BT_CHECK_PARAMETER(uuid, return);
 
        server_id = __bt_rfcomm_assign_server_id();
        retv_if(server_id < 0, BLUETOOTH_ERROR_INTERNAL);
@@ -379,7 +379,7 @@ int __bt_rfcomm_server_get_address(bt_rfcomm_server_info_t *server_info)
        DBusConnection *conn;
        const char *property;
 
-       BT_CHECK_PARAMETER(server_info);
+       BT_CHECK_PARAMETER(server_info, return);
 
        /* GetInfo Proxy Part */
        msg = dbus_message_new_method_call(BT_BLUEZ_NAME,
@@ -684,6 +684,8 @@ int _bt_rfcomm_remove_socket(int socket_fd)
 
        server_list = g_slist_remove(server_list, server_info);
 
+       __bt_rfcomm_delete_server_id(server_info->server_id);
+
        g_free(server_info->serial_path);
        g_free(server_info->uuid);
        g_free(server_info->sender);
@@ -763,8 +765,8 @@ int _bt_rfcomm_is_uuid_available(char *uuid, gboolean *available)
        GSList *l;
        bt_rfcomm_server_info_t *server_info;
 
-       BT_CHECK_PARAMETER(uuid);
-       BT_CHECK_PARAMETER(available);
+       BT_CHECK_PARAMETER(uuid, return);
+       BT_CHECK_PARAMETER(available, return);
 
        *available = FALSE;
 
@@ -897,7 +899,7 @@ int _bt_rfcomm_server_disconnect_all_connection(void)
 
 int _bt_rfcomm_server_check_existence(gboolean *existence)
 {
-       BT_CHECK_PARAMETER(existence);
+       BT_CHECK_PARAMETER(existence, return);
 
        if (server_list && g_slist_length(server_list) > 0) {
                *existence = TRUE;
@@ -913,7 +915,7 @@ int _bt_rfcomm_server_check_termination(char *name)
        GSList *l;
        bt_rfcomm_server_info_t *server_info;
 
-       BT_CHECK_PARAMETER(name);
+       BT_CHECK_PARAMETER(name, return);
 
        for (l = server_list; l != NULL; l = l->next) {
                server_info = l->data;
index 53318ce..4f17b2b 100644 (file)
 extern "C" {
 #endif
 
+typedef struct {
+       int req_id;
+       int type;
+       int disconnection_type;
+       char *address;
+       gboolean ag_flag;
+       GArray **out_param1;
+} bt_headset_wait_t;
+
 typedef enum {
-       BT_AUDIO_HSP = 0x00,
+       BT_AUDIO_HSP = 0x01,
        BT_AUDIO_A2DP,
        BT_AUDIO_ALL,
 } bt_audio_type_t;
 
+typedef enum {
+       BT_STATE_NONE = 0x00,
+       BT_STATE_CONNECTING,
+       BT_STATE_CONNECTED,
+} bt_headset_device_state_t;
 
 int _bt_audio_connect(int request_id, int type,
                bluetooth_device_address_t *device_address,
@@ -43,11 +57,19 @@ int _bt_audio_disconnect(int request_id, int type,
                bluetooth_device_address_t *device_address,
                GArray **out_param1);
 
-
 int _bt_audio_get_speaker_gain(unsigned int *gain);
 
 int _bt_audio_set_speaker_gain(unsigned int gain);
 
+void _bt_set_audio_wait_data_flag(gboolean flag);
+
+bt_headset_wait_t *_bt_get_audio_wait_data(void);
+
+void _bt_add_headset_to_list(int type, int status, const char *address);
+
+void _bt_remove_headset_from_list(int type, const char *address);
+
+gboolean _bt_is_headset_type_connected(int type, char *address);
 
 #ifdef __cplusplus
 }
index 3b79f3a..9d69326 100644 (file)
@@ -55,12 +55,12 @@ extern "C" {
                } \
        } while (0)
 
-#define BT_CHECK_PARAMETER(arg) \
+#define BT_CHECK_PARAMETER(arg, func) \
        do { \
                if (arg == NULL) \
                { \
                        BT_ERR("INVALID PARAMETER"); \
-                       return BLUETOOTH_ERROR_INVALID_PARAM; \
+                       func BLUETOOTH_ERROR_INVALID_PARAM; \
                } \
        } while (0)
 
index b409acb..16f5dd3 100644 (file)
@@ -60,6 +60,7 @@ int _bt_obex_server_accept_connection(int request_id);
 
 int _bt_obex_server_reject_connection(void);
 
+int _bt_obex_server_is_receiving(gboolean *receiving);
 
 void _bt_obex_transfer_started(const char *transfer_path);
 
index b790c53..abdd30c 100644 (file)
@@ -291,6 +291,7 @@ typedef enum {
                                /**<Discovered GATT service characteristics event*/
        BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
                                /**<Remote GATT charateristic value changed event*/
+       BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID,
 
        BLUETOOTH_EVENT_AG_CONNECTED = BLUETOOTH_EVENT_AUDIO_BASE, /**<AG service connected event*/
        BLUETOOTH_EVENT_AG_DISCONNECTED, /**<AG service disconnected event*/
@@ -761,6 +762,7 @@ typedef struct {
 
 typedef struct {
        char *uuid;
+       char *handle;
        bt_gatt_handle_info_t handle_info;
 } bt_gatt_service_property_t;
 
@@ -790,6 +792,7 @@ typedef struct {
  */
 
 typedef struct {
+       char *handle;
        char *uuid;
        char *name;
        char *description;
@@ -1030,6 +1033,31 @@ ret = bluetooth_disable_adapter();
  */
 int bluetooth_disable_adapter(void);
 
+/**
+ * @fn int bluetooth_reset_adapter(void)
+ * @brief Reset the Bluetooth H/W and values
+ *
+ *
+ * This function resets Bluetooth protocol stack and hardware. This function is called when
+ * an user want to initialize Bluetooth environment.
+ *
+ * The various error codes are BLUETOOTH_ERROR_NONE for success and BLUETOOTH_ERROR_INTERNAL for
+ * internal error.
+ *
+ * This function is a synchronous call.
+ *
+ * @return     BLUETOOTH_ERROR_NONE - Success\n
+ * @exception   BLUETOOTH_ERROR_INTERNAL - Dbus proxy call is fail
+ * @remark      None
+ * @see         bluetooth_check_adapter, bluetooth_enable_adapter
+@code
+...
+
+int ret = 0;
+ret = bluetooth_reset_adapter();
+@endcode
+ */
+int bluetooth_reset_adapter(void);
 
 /**
  * @fn int bluetooth_is_supported(void)
@@ -2708,6 +2736,23 @@ int bluetooth_opc_cancel_push(void);
 
 gboolean bluetooth_opc_session_is_exist(void);
 
+/**
+ * @fn int bluetooth_opc_is_sending(gboolean *is_sending)
+ * @brief Informs whether opc session exists or not.
+ *
+ * This function is a synchronous call.
+ *
+ * @return   BLUETOOTH_ERROR_NONE  - Success \n
+ *               BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Not enabled \n
+ *               BLUETOOTH_ERROR_INTERNAL \n
+ *
+ * @exception   None
+ * @param[out] is_sending The sending status: (@c TRUE = in sending , @c  false = not in sending)
+ *
+ * @remark       None
+ * @see            None
+ */
+int bluetooth_opc_is_sending(gboolean *is_sending);
 
 /**
  * @fn int bluetooth_obex_server_init(const char *dst_path)
@@ -2979,6 +3024,25 @@ int bluetooth_obex_server_cancel_all_transfers(void);
 
 
 /**
+ * @fn int bluetooth_obex_server_is_receiving(gboolean *is_receiving)
+ * @brief Informs whether obex server is receiving or not.
+ *
+ * This function is a synchronous call.
+ *
+ * @return   BLUETOOTH_ERROR_NONE  - Success \n
+ *               BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Not enabled \n
+ *               BLUETOOTH_ERROR_INTERNAL \n
+ *
+ * @exception   None
+ * @param[out] is_receiving The receiving status: (@c TRUE = in receiving , @c  false = not in receiving)
+ *
+ * @remark       None
+ * @see            None
+ */
+int bluetooth_obex_server_is_receiving(gboolean *is_receiving);
+
+
+/**
  * @fn int bluetooth_oob_read_local_data(bt_oob_data_t *local_oob_data)
  * @brief Read the local Hash and Randmizer.
  *
@@ -3204,6 +3268,56 @@ int bluetooth_gatt_set_characteristics_value(const char *char_handle,
                                                const guint8 *value, int length);
 
 /**
+ * @fn int bluetooth_gatt_get_service_from_uuid(bluetooth_device_address_t *address,
+ *                                     const char *service_uuid,
+ *                                     bt_gatt_service_property_t *service)
+ *
+ * @brief Gets the service property from a device based on a particular uuid
+ *
+ * This function is a synchronous call.
+ *
+ * @return   BLUETOOTH_ERROR_NONE  - Success \n
+ *             BLUETOOTH_ERROR_INTERNAL - Internal Error \n
+ *             BLUETOOTH_ERROR_INVALID_PARAM -Invalid Parameters \n
+ *             BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Adapter is disabled \n
+ *
+ * @exception  None
+ * @param[in]  address - BD address of the remote device
+ * @param[in]  service_uuid - uuid of the service.
+ * @param[out] service - Structure containing the service property.
+ *
+ * @remark     None
+ * @see                None
+ */
+ int bluetooth_gatt_get_service_from_uuid(bluetooth_device_address_t *address,
+                                       const char *service_uuid,
+                                       bt_gatt_service_property_t *service);
+
+/**
+ * @fn int bluetooth_gatt_get_char_from_uuid(const char *service_handle,
+ *                                                     const char *char_uuid)
+ *
+ * @brief Gets the characteristic property from a service based on a particular char uuid
+ *
+ * This function is an asynchronous call.
+ * This API is responded with BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID
+ *
+ * @return   BLUETOOTH_ERROR_NONE  - Success \n
+ *             BLUETOOTH_ERROR_INTERNAL - Internal Error \n
+ *             BLUETOOTH_ERROR_INVALID_PARAM -Invalid Parameters \n
+ *             BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Adapter is disabled \n
+ *
+ * @exception  None
+ * @param[in]  service_handle - Service handle.
+ * @param[in]  uuid - Characteristic uuid.
+ *
+ * @remark     None
+ * @see                None
+ */
+int bluetooth_gatt_get_char_from_uuid(const char *service_handle,
+                                               const char *char_uuid);
+
+/**
  * @fn int bluetooth_gatt_free_primary_services(bt_gatt_handle_info_t *prim_svc);
  *
  * @brief Releases the memory allocated by bluetooth_gatt_get_primary_services()
index 2ee0568..2c7d1e0 100644 (file)
@@ -158,6 +158,7 @@ typedef enum {
        BT_OBEX_SERVER_SET_ROOT,
        BT_OBEX_SERVER_CANCEL_TRANSFER,
        BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS,
+       BT_OBEX_SERVER_IS_RECEIVING,
        BT_RFCOMM_CLIENT_CONNECT = BT_FUNC_RFCOMM_BASE,
        BT_RFCOMM_CLIENT_CANCEL_CONNECT,
        BT_RFCOMM_CLIENT_IS_CONNECTED,
index 4f50161..5bf1f05 100644 (file)
@@ -1,11 +1,13 @@
 Name:       bluetooth-frwk
 Summary:    Bluetooth framework for BlueZ and Obexd. This package is Bluetooth framework based on BlueZ and Obexd stack.
-Version:    0.2.55
-Release:    2
+Version:    0.2.56
+Release:    1
 Group:      TO_BE/FILLED_IN
 License:    Apache License, Version 2.0
 Source0:    %{name}-%{version}.tar.gz
-
+Requires: sys-assert
+Requires: dbus
+Requires: syspopup
 BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(dbus-glib-1)
 BuildRequires:  pkgconfig(dlog)
@@ -15,12 +17,14 @@ BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(libxml-2.0)
 BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(utilX)
+BuildRequires:  pkgconfig(capi-network-tethering)
 BuildRequires:  pkgconfig(libprivilege-control)
 BuildRequires:  pkgconfig(status)
+BuildRequires:  pkgconfig(alarm-service)
 BuildRequires:  cmake
 
-Requires(post): /sbin/ldconfig
-Requires(postun): /sbin/ldconfig
+Requires(post): vconf
+Requires(postun): eglibc
 
 %description
 Bluetooth framework for BlueZ and Obexd. This package is Bluetooth framework based on BlueZ and Obexd stack.
@@ -103,6 +107,7 @@ vconftool set -tf int memory/bluetooth/btsco "0" -g 6520 -i
 %{_libdir}/libbluetooth-api.so
 
 %files service
+%manifest bluetooth-frwk.manifest
 %defattr(-, root, root)
 %{_sysconfdir}/rc.d/init.d/bluetooth-frwk-service
 %{_sysconfdir}/rc.d/rc3.d/S80bluetooth-frwk-service
index 8c7b767..a04a9ff 100644 (file)
@@ -36,3 +36,4 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 
 #ADD_SUBDIRECTORY(media-control)
 #ADD_SUBDIRECTORY(telephony)
+ADD_SUBDIRECTORY(gatt-test)
index 0fbe95c..0e5838b 100644 (file)
@@ -641,6 +641,15 @@ int test_input_callback(void *data)
                        TC_PRT("connected : %d", connected);
                        break;
                }
+               case 28:
+               {
+                       TC_PRT("TC : %s", tc_table[27].tc_name);
+
+                       ret = bluetooth_reset_adapter();
+                       if (ret < 0)
+                               TC_PRT("%s failed with [0x%04x]", tc_table[27].tc_name, ret);
+                       break;
+               }
 
                case 29:
                {
diff --git a/test/gatt-test/CMakeLists.txt b/test/gatt-test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..12f135a
--- /dev/null
@@ -0,0 +1,33 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(bluetooth-gatt-test C)
+
+SET(SRCS bluetooth-gatt-test.c)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../lib)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(package REQUIRED dlog dbus-glib-1 glib-2.0 gthread-2.0)
+
+FOREACH(flag ${package_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-DTARGET")
+       MESSAGE("add -DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${package_LDFLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/../../bt-api -lbluetooth-api)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/test/gatt-test/bluetooth-gatt-test.c b/test/gatt-test/bluetooth-gatt-test.c
new file mode 100644 (file)
index 0000000..1648197
--- /dev/null
@@ -0,0 +1,354 @@
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
+ *              Girishashok Joshi <girish.joshi@samsung.com>
+ *              Chanyeol Park <chanyeol.park@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file       bluetooth-gatt-test.c
+ * @brief      This is the source file for bluetooth framework test suite.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+#include "bluetooth-api.h"
+
+
+#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
+#define TC_PRT(format, args...) PRT(format"\n", ##args)
+
+#define TC_PASS 1
+#define TC_FAIL 0
+
+GMainLoop *main_loop = NULL;
+
+typedef struct
+{
+       const char *tc_name;
+       int tc_code;
+} tc_table_t;
+
+tc_table_t tc_table[] =
+{
+       {"Send alert to remote le device"               , 1},
+       {"Set Link loss alert"          , 2},
+
+       /* -----------------------------------------*/
+       {"Finish"                                       , 0x00ff},
+       {NULL                                   , 0x0000},
+
+};
+
+#define tc_result(success, tc_index) \
+       TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS)?"Success":"Failed"));
+
+char *g_alert_char_handle = NULL;
+guint8 g_alert_level = 0;
+
+#define IMMEDIATE_ALERT_UUID   "00001802-0000-1000-8000-00805f9b34fb"
+#define LINK_LOSS_UUID         "00001803-0000-1000-8000-00805f9b34fb"
+#define ALERT_LEVEL_CHR_UUID   "2a06"
+
+#define BD_ADDR_FILE "/opt/remote-bd"
+
+void tc_usage_print(void)
+{
+       int i = 0;
+
+       while (tc_table[i].tc_name) {
+               if (tc_table[i].tc_code != 0x00ff) {
+                       TC_PRT("Key %d : usage %s", tc_table[i].tc_code,
+                                                       tc_table[i].tc_name);
+               } else {
+                       TC_PRT("Key %d : usage %s\n\n", 0x00ff,
+                                                       tc_table[i].tc_name);
+               }
+
+               i++;
+       }
+}
+
+static void convert_addr_string_to_addr_type(bluetooth_device_address_t *addr,
+                                                       const char *address)
+{
+       char *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
+
+       if (!address || !addr)
+               return;
+
+       addr->addr[0] = strtol(address, &ptr5, 16);
+       addr->addr[1] = strtol(ptr5 + 1, &ptr4, 16);
+       addr->addr[2] = strtol(ptr4 + 1, &ptr3, 16);
+       addr->addr[3] = strtol(ptr3 + 1, &ptr2, 16);
+       addr->addr[4] = strtol(ptr2 + 1, &ptr1, 16);
+       addr->addr[5] = strtol(ptr1 + 1, NULL, 16);
+}
+
+char * get_bd_from_file(char *filename)
+{
+       int fd;
+       char *buf;
+
+       if ((fd = open(filename, O_RDONLY)) < 0) {
+               perror("Can't open file");
+               return NULL;
+       }
+
+       buf = g_malloc0(20);
+
+       if (read(fd, buf, 17) < 17) {
+               perror("Can't load firmware");
+               g_free(buf);
+               close(fd);
+               return NULL;
+       }
+
+       close(fd);
+
+       return buf;
+}
+
+static void __accept_bdaddress(bluetooth_device_address_t *device_address)
+{
+       char str_address[20] = {0};
+       char *addr;
+
+       addr = get_bd_from_file(BD_ADDR_FILE);
+       if (addr) {
+               TC_PRT("Remote bd adress from file: %s", addr);
+               convert_addr_string_to_addr_type(device_address, addr);
+               return;
+       }
+
+       TC_PRT("Enter bd address: ");
+       scanf("%s", str_address);
+       TC_PRT("You have entered bd address %s\n", str_address);
+       convert_addr_string_to_addr_type(device_address, str_address);
+}
+
+static void __accept_alert_level()
+{
+       TC_PRT("Enter alert level \n 0 - no alert 1 - mild alert 2 - High alert : ");
+       scanf("%d", &g_alert_level);
+       TC_PRT("You have selected alert level %d ", g_alert_level);
+}
+
+int test_input_callback(void *data)
+{
+       int ret = 0;
+       int test_id = (int)data;
+       bluetooth_device_address_t device_address;
+       bt_gatt_service_property_t service;
+
+       switch (test_id) {
+       case 0x00ff:
+               TC_PRT("Finished");
+               g_main_loop_quit(main_loop);
+               break;
+       case 1:
+               TC_PRT("Immediate Alert");
+               __accept_bdaddress(&device_address);
+
+               __accept_alert_level();
+
+               if (g_alert_char_handle) {
+                       if (bluetooth_gatt_set_characteristics_value(g_alert_char_handle,
+                                               &g_alert_level, 1) != BLUETOOTH_ERROR_NONE)
+                               TC_PRT("Set char val failed");
+
+                       return 0;
+               }
+
+               ret = bluetooth_gatt_get_service_from_uuid(&device_address,
+                                                       IMMEDIATE_ALERT_UUID,
+                                                       &service);
+               if (ret != BLUETOOTH_ERROR_NONE) {
+                       TC_PRT(" bluetooth_gatt_get_service_from_uuid FAILED");
+                       return 0;
+               }
+
+               ret = bluetooth_gatt_get_char_from_uuid(service.handle,
+                                                       ALERT_LEVEL_CHR_UUID);
+               if (ret != BLUETOOTH_ERROR_NONE) {
+                       TC_PRT(" bluetooth_gatt_get_char_from_uuid FAILED");
+                       return 0;
+               }
+
+               break;
+       case 2:
+               TC_PRT("Proximity Link loss alert");
+               __accept_bdaddress(&device_address);
+
+               __accept_alert_level();
+
+               /* TODO */
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+void startup()
+{
+       TC_PRT("bluetooth framework TC startup");
+
+       if (!g_thread_supported())
+               g_thread_init(NULL);
+
+       dbus_g_thread_init();
+
+       g_type_init();
+       main_loop = g_main_loop_new(NULL, FALSE);
+}
+
+void cleanup()
+{
+       TC_PRT("bluetooth framework TC cleanup");
+       if ( main_loop != NULL)
+               g_main_loop_unref(main_loop);
+}
+
+static void __handle_alert_char(char *char_handle,
+                                       bt_gatt_char_property_t *char_pty)
+{
+       if (char_pty->val == NULL)
+               TC_PRT("Read only char");
+       else
+               TC_PRT("Current Alert level [%d]", char_pty->val[0]);
+
+       g_alert_char_handle = g_strdup(char_handle);
+
+       if (bluetooth_gatt_set_characteristics_value(char_handle,
+                               &g_alert_level, 1) != BLUETOOTH_ERROR_NONE)
+               TC_PRT("Set char val failed");
+
+}
+
+static gboolean __handle_char(char *char_handle,
+                                       bt_gatt_char_property_t *char_pty)
+{
+       TC_PRT("char uuid %s", char_pty->uuid);
+
+       if (g_strstr_len(char_pty->uuid, -1, ALERT_LEVEL_CHR_UUID) != NULL) {
+               TC_PRT("Alert char recieved");
+               __handle_alert_char(char_handle, char_pty);
+               return TRUE;
+       } /* Add else if for other chars*/
+
+       return FALSE;
+}
+
+void bt_event_callback(int event, bluetooth_event_param_t* param,
+                                                       void *user_data)
+{
+       TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+       TC_PRT("bt event callback 0x%04x", event);
+       switch(event) {
+       case BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID:
+       {
+               TC_PRT("BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID");
+               if (param->result != 0) {
+                       TC_PRT("Failed!!!");
+                       return;
+               }
+               bt_gatt_char_property_t *char_pty = param->param_data;
+
+               __handle_char(char_pty->handle, char_pty);
+
+       }
+       break;
+       default:
+               TC_PRT("received event [0x%04x]", event);
+               break;
+       }
+       TC_PRT("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+}
+
+static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+       char buf[10] = {0};
+       unsigned int len = 0;
+       int test_id;
+
+       if (g_io_channel_read(chan, buf, sizeof(buf), &len) !=
+                                                       G_IO_ERROR_NONE) {
+               printf("IO Channel read error");
+               return FALSE;
+       }
+       printf("%s\n",buf);
+       tc_usage_print();
+
+       test_id = atoi(buf);
+
+       if (test_id)
+               g_idle_add(test_input_callback, (void*)test_id);
+
+       return TRUE;
+}
+
+int main()
+{
+       int ret_val;
+       GIOChannel *key_io;
+
+       startup();
+
+       /* Register callback function */
+       TC_PRT("TC : %s", tc_table[0].tc_name);
+       ret_val = bluetooth_register_callback(bt_event_callback, NULL);
+       if (ret_val >= BLUETOOTH_ERROR_NONE) {
+               TC_PRT("bluetooth_register_callback returned Success");
+               tc_result(TC_PASS, 0);
+       } else {
+               TC_PRT("bluetooth_register_callback returned failiure [0x%04x]", ret_val);
+               tc_result(TC_FAIL, 0);
+               return 0;
+       }
+
+       ret_val = bluetooth_check_adapter();
+       if (ret_val < BLUETOOTH_ERROR_NONE) {
+               TC_PRT("bluetooth_check_adapter returned failiure [0x%04x]", ret_val);
+               tc_result(TC_FAIL, 3);
+       } else {
+               TC_PRT("BT state [0x%04x]", ret_val);
+               tc_result(TC_PASS, 3);
+       }
+
+       key_io = g_io_channel_unix_new(fileno(stdin));
+
+       g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+                       key_event_cb, NULL);
+       g_io_channel_unref(key_io);
+
+       g_main_loop_run(main_loop);
+
+       cleanup();
+       return 0;
+}