Merge "Mesh: added message response on Node Role" into tizen
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-gatt-service.c
index c65bf82..aaeb320 100644 (file)
@@ -343,18 +343,28 @@ static struct gatt_desc_info *__bt_gatt_find_gatt_desc_info(
 static struct gatt_req_info *__bt_gatt_find_request_info(guint request_id);
 static int __bt_gatt_unregister_service(struct gatt_service_info *svc_info);
 
-static int bluetooth_get_characteristic_fd(int att_handle , char *path)
+static int bluetooth_get_characteristic_fd(int att_handle , char *address)
 {
        GSList *l;
+       int ret = -1;
+
+       BT_DBG("Find FD for address [%s] att_handle [ %d]", address, att_handle);
+
+       /* Check for NULL address */
+       if (g_strcmp0(address, "00:00:00:00:00:00") != 0) {
+               BT_INFO("Unicast address: Use DBUS send indication");
+               return ret;
+       }
 
-       BT_DBG("request found  path [%s] att_handle [ %d]", path, att_handle);
        for (l = gatt_characteristic_server_notify_list; l != NULL; l = l->next) {
                bluetooth_gatt_acquire_notify_info_t *info = l->data;
 
-               if (info->att_hand == att_handle)
+               if (info->att_hand == att_handle) {
+                       BT_INFO("ATT handle Matched: AquireNotify Set: Remote addr[%s]", info->address);
                        return info->write_fd;
+               }
        }
-       return -1;
+       return ret;
 }
 
 static bluetooth_gatt_acquire_notify_info_t * bluetooth_get_characteristic_info_from_path(int att_handle)
@@ -2911,12 +2921,15 @@ BT_EXPORT_API int bluetooth_gatt_server_send_indication(bluetooth_device_address
        g_array_append_vals(in_param3, addr_hex, sizeof(bluetooth_device_address_t));
 
        _bt_convert_addr_type_to_string(addr, addr_hex->addr);
+       BT_INFO("Send Indication to address [%s]", addr);
        fd =  bluetooth_get_characteristic_fd(param->atrribute_handle, addr);
 
        if (fd > -1) {
+               BT_INFO("Acquire Notify FD found: Send Multicast Indication over Socket");
                result  = bluetooth_gatt_write_characteristics_value_to_fd_(fd, att_value->data, att_value->length, NULL);
                param->fd = fd;
        } else {
+               BT_ERR("Acquire Notify FD not found for charatcristic handle: Send DBUS indication");
                result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_SEND_INDICATION,
                                in_param1, in_param2, in_param3, in_param4, &out_param);
        }
@@ -3122,7 +3135,7 @@ void  bluetooth_gatt_server_send_acquire_write_response(GVariant * parameters)
        BT_DBG("GATT Server Acquire Write Offset:    [%d]", offset);
 
 
-       if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipefd) < 0) {
+       if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, pipefd) < 0) {
                        strerror_r(errno, err_msg, sizeof(err_msg));
                        BT_ERR("socketpair(): %s", err_msg);
                        return ;
@@ -3226,13 +3239,17 @@ void  bluetooth_gatt_server_send_acquire_notify_response(GVariant * parameters,
 
        chr_info = bluetooth_get_characteristic_info_from_path(att_han);
        if (!chr_info) {
+               BT_INFO("char info not found for ATT handle [%u]", att_han);
                chr_info = g_malloc0(sizeof(bluetooth_gatt_acquire_notify_info_t));
                chr_info->write_fd = fd;
                chr_info->att_hand = att_han;
+               memcpy(chr_info->address, address, BLUETOOTH_ADDRESS_STRING_LENGTH);
 
                gatt_characteristic_server_notify_list = g_slist_append(gatt_characteristic_server_notify_list, chr_info);
-       } else
+       } else {
+               BT_INFO("Already AcquireNotify Set for this attribute handle by remote Client [%s]", chr_info->address);
                chr_info->write_fd = fd;
+       }
 
        channel = g_io_channel_unix_new(fd);
        chr_info->io_channel = channel;