Skip to content

Commit

Permalink
service: Add initiator argument to service_accept
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Vudentz committed May 12, 2022
1 parent 4423d63 commit cd24715
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ struct bearer_state {
bool bonded;
bool connected;
bool svc_resolved;
bool initiator;
};

struct csrk_info {
Expand Down Expand Up @@ -297,6 +298,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;
Expand Down Expand Up @@ -3256,6 +3267,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);
Expand Down Expand Up @@ -4169,7 +4181,7 @@ static void add_gatt_service(struct gatt_db_attribute *attr, void *user_data)
}

/* 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)
Expand All @@ -4191,7 +4203,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));
}

static void device_remove_gatt_service(struct btd_device *device,
Expand Down Expand Up @@ -5899,6 +5911,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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,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;
Expand All @@ -198,6 +198,8 @@ int service_accept(struct btd_service *service)
return -ECONNABORTED;
}

service->initiator = initiator;

err = service->profile->accept(service);
if (!err)
goto done;
Expand Down
2 changes: 1 addition & 1 deletion src/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit cd24715

Please sign in to comment.