tools/btpclient: Check if dev is connected in device found ev routine 62/205062/1
authorGrzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
Wed, 28 Feb 2018 12:41:26 +0000 (13:41 +0100)
committerAmit Purwar <amit.purwar@samsung.com>
Mon, 29 Apr 2019 04:19:09 +0000 (09:49 +0530)
Device may be connected while device found event is generated thus thus
btp should generate additional device connected event also.

Change-Id: Ifda6532b03755d24a2392e8d97d55a1a2a8358fa
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
tools/btpclient.c

index 93dc426..daa2e87 100644 (file)
@@ -2402,24 +2402,30 @@ failed:
 
 static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
 {
+       struct btp_device *device = find_device_by_proxy(proxy);
+       struct btp_adapter *adapter = find_adapter_by_device(device);
        struct btp_device_found_ev ev;
-       const char *str;
+       struct btp_gap_device_connected_ev ev_conn;
+       const char *str, *addr_str;
        int16_t rssi;
+       uint8_t address_type;
+       bool connected;
 
-       if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str) ||
-                                               !str2addr(str, ev.address))
+       if (!l_dbus_proxy_get_property(proxy, "Address", "s", &addr_str) ||
+                                       str2ba(addr_str, &ev.address) < 0)
                return;
 
        if (!l_dbus_proxy_get_property(proxy, "AddressType", "s", &str))
                return;
 
-       ev.address_type = strcmp(str, "public") ? BTP_GAP_ADDR_RANDOM :
+       address_type = strcmp(str, "public") ? BTP_GAP_ADDR_RANDOM :
                                                        BTP_GAP_ADDR_PUBLIC;
+       ev.address_type = address_type;
 
        if (!l_dbus_proxy_get_property(proxy, "RSSI", "n", &rssi))
-               return;
-
-       ev.rssi = rssi;
+               ev.rssi = 0x81;
+       else
+               ev.rssi = rssi;
 
        /* TODO Temporary set all flags */
        ev.flags = (BTP_EV_GAP_DEVICE_FOUND_FLAG_RSSI |
@@ -2429,9 +2435,17 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
        /* TODO Add eir to device found event */
        ev.eir_len = 0;
 
-       btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND,
-                                               BTP_INDEX_NON_CONTROLLER,
+       btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND, adapter->index,
                                                sizeof(ev) + ev.eir_len, &ev);
+
+       if (l_dbus_proxy_get_property(proxy, "Connected", "b", &connected) &&
+                                                               connected) {
+               ev_conn.address_type = address_type;
+               str2ba(addr_str, &ev_conn.address);
+
+               btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_CONNECTED,
+                               adapter->index, sizeof(ev_conn), &ev_conn);
+       }
 }
 
 static void btp_gap_device_connection_ev(struct l_dbus_proxy *proxy,