Specify the sender(org.bluez) on subscribe to receive only necessary PropertiesChange...
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-gatt.c
index 307b598..61453d1 100644 (file)
@@ -1239,18 +1239,22 @@ static void cb_gatts_connection(int conn_id, int server_if, int connected, bt_bd
        BT_INFO("BTGATT SERVER CONNECTION  connnected:%d, conn_id:%d server_if:%d", connected, conn_id, server_if);
        event_gatts_conn_t *event = g_new0(event_gatts_conn_t, 1);
 
-       for (ins_id = 1 ; ins_id <= NUM_SERVER_INST ; ins_id++) {
-               if ((gatt_servers[ins_id - 1].server_id == server_if)) {
-                       event->server_inst = ins_id;
-                       break;
-               } else {
-                       BT_INFO("Server ID:%d recevied server Id:%d\n", gatt_servers[ins_id - 1].server_id, server_if);
+       if (connected == TRUE) {
+               for (ins_id = 1 ; ins_id <= NUM_SERVER_INST ; ins_id++) {
+                       if ((gatt_servers[ins_id - 1].server_id == server_if)) {
+                               event->server_inst = ins_id;
+                               break;
+                       } else {
+                               BT_INFO("Server ID:%d recevied server Id:%d\n", gatt_servers[ins_id - 1].server_id, server_if);
+                       }
                }
-       }
-       if (ins_id == NUM_SERVER_INST+1) {
-               BT_WARN("Incorrect Server Interface received: %d\n",  server_if);
-               g_free(event);
-               return;
+               if (ins_id == NUM_SERVER_INST+1) {
+                       BT_WARN("Incorrect Server Interface received: %d\n",  server_if);
+                       g_free(event);
+                       return;
+               }
+       } else {
+               /* server_inst is not required in disconnected case */
        }
        memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
        event->conn_id = conn_id;
@@ -1468,8 +1472,6 @@ static void cb_gattc_search_result(int conn_id, btgatt_srvc_id_t *srvc_id)
 {
        char uuid_str[2*BT_UUID_STRING_MAX];
 
-       BT_INFO("BTGATT Client Service Search Result cb, conn_id:%d", conn_id);
-
        uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str);
        BT_INFO("Service=> [%s], Inst_id [%u], Type [%s]",
                uuid_str, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
@@ -1502,9 +1504,9 @@ static void cb_gattc_get_characteristics(int conn_id, int status, btgatt_srvc_id
        char uuid_str2[2*BT_UUID_STRING_MAX];
        char str[50];
 
-       BT_INFO("BTGATT Client Get Characteristic Callback, conn_id:%d, status:%d", conn_id, status);
+       BT_DBG("BTGATT Client Get Characteristic Callback, conn_id:%d, status:%d", conn_id, status);
        uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
-       BT_INFO("Service=> [%s], Inst_id [%u], Type [%s]",
+       BT_DBG("Service=> [%s], Inst_id [%u], Type [%s]",
                uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
 
        event_gattc_characteristic_result_t *event = g_new0(event_gattc_characteristic_result_t, 1);
@@ -1529,12 +1531,12 @@ static void cb_gattc_get_descriptor(int conn_id, int status, btgatt_srvc_id_t *s
        char uuid_str1[2*BT_UUID_STRING_MAX];
        char uuid_str2[2*BT_UUID_STRING_MAX];
        char uuid_str3[2*BT_UUID_STRING_MAX];
-       BT_INFO("BTGATT Client Get Descriptor Callback, conn_id:%d, status:%d", conn_id, status);
+       BT_DBG("BTGATT Client Get Descriptor Callback, conn_id:%d, status:%d", conn_id, status);
        uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
        uuid_to_stringname((oal_uuid_t *)&(char_id->uuid), uuid_str2);
-       BT_INFO("Service=> [%s], Inst_id [%u], Type [%s]",
+       BT_DBG("Service=> [%s], Inst_id [%u], Type [%s]",
                uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
-       BT_INFO("Charac => [%s], Inst_id [%u]", uuid_str2, char_id->inst_id);
+       BT_DBG("Charac => [%s], Inst_id [%u]", uuid_str2, char_id->inst_id);
 
        event_gattc_descriptor_result_t *event = g_new0(event_gattc_descriptor_result_t, 1);
        event->conn_status.conn_id = conn_id;
@@ -1550,12 +1552,12 @@ static void cb_gattc_get_descriptor(int conn_id, int status, btgatt_srvc_id_t *s
        send_event(OAL_EVENT_GATTC_DESC_SERACH_RESULT, event, sizeof(*event));
 }
 
-static void cb_gattc_register_for_notification(int client_if, int registered, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id)
+static void cb_gattc_register_for_notification(int conn_id, int registered, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id)
 {
        char uuid_str1[2*BT_UUID_STRING_MAX];
        char uuid_str2[2*BT_UUID_STRING_MAX];
-       BT_INFO("BTGATT Client Register For Notification Callback, client_if:%d, status:%d, registered: %s",
-               client_if, status, registered == 1 ? "REGISTERED" : "DEREGISTERED");
+       BT_INFO("BTGATT Client Register For Notification Callback, conn_id:%d, status:%d, registered: %s",
+               conn_id, status, registered == 1 ? "REGISTERED" : "DEREGISTERED");
        uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
        uuid_to_stringname((oal_uuid_t *)&(char_id->uuid), uuid_str2);
        BT_INFO("Service=> [%s], Inst_id [%u], Type [%s]", uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
@@ -1563,7 +1565,7 @@ static void cb_gattc_register_for_notification(int client_if, int registered, in
 
        event_gattc_regdereg_notify_t *event = g_new0(event_gattc_regdereg_notify_t, 1);
        oal_event_t event_type = (registered == 1 ? OAL_EVENT_GATTC_NOTIFICATION_REGISTERED : OAL_EVENT_GATTC_NOTIFICATION_DEREGISTERED);
-       event->client_if = client_if;
+       event->conn_id = conn_id;
        event->status = convert_to_oal_status(status);
        memcpy(&(event->srvc_id), srvc_id, sizeof(oal_gatt_srvc_id_t));
        memcpy(&(event->char_id), char_id, sizeof(oal_gatt_id_t));
@@ -1927,7 +1929,7 @@ oal_status_t gattc_get_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id,
 
        OAL_CHECK_PARAMETER(srvc_id, return);
        uuid_to_stringname(&(srvc_id->id.uuid), uuid_str);
-       API_TRACE("Client Get Characteristic, Service_uuid: [%s]", uuid_str);
+       API_TRACE("Client Get Characteristic [%s]", uuid_str);
        CHECK_OAL_GATT_ENABLED();
        CHECK_CLIENT_CONNECTION(conn_id);
        ret = gatt_api->client->get_characteristic(conn_id, (btgatt_srvc_id_t *)srvc_id,
@@ -1962,7 +1964,7 @@ oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id,
        return OAL_STATUS_SUCCESS;
 }
 
-oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
+oal_status_t gattc_register_for_notification(int conn_id, bt_address_t * address,
                        oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
        int ret = OAL_STATUS_SUCCESS;
        char uuid_str1[2*BT_UUID_STRING_MAX];
@@ -1976,9 +1978,9 @@ oal_status_t gattc_register_for_notification(int client_id, bt_address_t * addre
        uuid_to_stringname(&(char_id->uuid), uuid_str2);
        API_TRACE("Client Register Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
        CHECK_OAL_GATT_ENABLED();
-       CHECK_CLIENT_REGISTRATION(client_id);
+       CHECK_CLIENT_CONNECTION(conn_id);
 
-       ret = gatt_api->client->register_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
+       ret = gatt_api->client->register_for_notification(conn_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
        if (ret != BT_STATUS_SUCCESS) {
                BT_ERR("GATT client register notification failed: %s", status2string(ret));
                return convert_to_oal_status(ret);
@@ -1987,7 +1989,7 @@ oal_status_t gattc_register_for_notification(int client_id, bt_address_t * addre
        return OAL_STATUS_SUCCESS;
 }
 
-oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
+oal_status_t gattc_deregister_for_notification(int conn_id, bt_address_t * address,
                        oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
        int ret = OAL_STATUS_SUCCESS;
        char uuid_str1[2*BT_UUID_STRING_MAX];
@@ -2001,9 +2003,9 @@ oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * add
        uuid_to_stringname(&(char_id->uuid), uuid_str2);
        API_TRACE("Client Deregister Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
        CHECK_OAL_GATT_ENABLED();
-       CHECK_CLIENT_REGISTRATION(client_id);
+       CHECK_CLIENT_CONNECTION(conn_id);
 
-       ret = gatt_api->client->deregister_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
+       ret = gatt_api->client->deregister_for_notification(conn_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
        if (ret != BT_STATUS_SUCCESS) {
                BT_ERR("GATT client deregister notification failed: %s", status2string(ret));
                return convert_to_oal_status(ret);