service: Add initiator argument to service_accept
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 12 May 2022 00:55:15 +0000 (17:55 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
This adds initiator argument to service_accept so profiles accepting
the connection can use btd_service_is_initiator to determine if the
connection was initiated locally (central) or remotely (peripheral).

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/device.c
src/service.c
src/service.h

index d582e4c..3487fa4 100644 (file)
@@ -177,6 +177,7 @@ struct bearer_state {
        bool bonded;
        bool connected;
        bool svc_resolved;
+       bool initiator;
 };
 
 struct csrk_info {
@@ -452,6 +453,16 @@ static struct bearer_state *get_state(struct btd_device *dev,
                return &dev->le_state;
 }
 
+static bool get_initiator(struct btd_device *dev)
+{
+       if (dev->le_state.connected)
+               return dev->le_state.initiator;
+       if (dev->bredr_state.connected)
+               return dev->bredr_state.initiator;
+
+       return false;
+}
+
 static GSList *find_service_with_profile(GSList *list, struct btd_profile *p)
 {
        GSList *l;
@@ -5696,6 +5707,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
                return;
 
        state->connected = false;
+       state->initiator = false;
        device->general_connect = FALSE;
 
        device_set_svc_refreshed(device, false);
@@ -6706,7 +6718,7 @@ done:
        }
 
        /* Notify driver about the new connection */
-       service_accept(service);
+       service_accept(service, get_initiator(device));
 }
 
 static void device_add_gatt_services(struct btd_device *device)
@@ -6738,7 +6750,7 @@ static void accept_gatt_service(struct gatt_db_attribute *attr, void *user_data)
        if (!l)
                return;
 
-       service_accept(l->data);
+       service_accept(l->data, get_initiator(device));
 }
 #endif
 
@@ -6748,7 +6760,7 @@ static void device_accept_gatt_profiles(struct btd_device *device)
        GSList *l;
 
        for (l = device->services; l != NULL; l = g_slist_next(l))
-               service_accept(l->data);
+               service_accept(l->data, get_initiator(device));
 #else
        gatt_db_foreach_service(device->db, NULL, accept_gatt_service, device);
 #endif
@@ -8925,6 +8937,8 @@ int device_connect_le(struct btd_device *dev)
 
        /* Keep this, so we can cancel the connection */
        dev->att_io = io;
+       /* Set as initiator */
+       dev->le_state.initiator = true;
 
        return 0;
 }
index ae3a074..37c52d8 100755 (executable)
@@ -176,7 +176,7 @@ void service_remove(struct btd_service *service)
        btd_service_unref(service);
 }
 
-int service_accept(struct btd_service *service)
+int service_accept(struct btd_service *service, bool initiator)
 {
        char addr[18];
        int err;
@@ -202,6 +202,8 @@ int service_accept(struct btd_service *service)
                return -ECONNABORTED;
        }
 
+       service->initiator = initiator;
+
        err = service->profile->accept(service);
        if (!err)
                goto done;
index fa930f9..dc0d1d1 100755 (executable)
@@ -35,7 +35,7 @@ struct btd_service *service_create(struct btd_device *device,
 int service_probe(struct btd_service *service);
 void service_remove(struct btd_service *service);
 
-int service_accept(struct btd_service *service);
+int service_accept(struct btd_service *service, bool initiator);
 int service_set_connecting(struct btd_service *service);
 
 /* Connection control API */