Skip to content

Commit

Permalink
Bluetooth: GATT: Auto init if bt_gatt_service_register is called
Browse files Browse the repository at this point in the history
This ensures the core services are always registered first and the
gatt_sc work is initialized.

Fixes #9785

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
Vudentz authored and nashif committed Sep 10, 2018
1 parent b68cf99 commit e3f30be
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static sys_slist_t subscriptions;
static const u16_t gap_appearance = CONFIG_BT_DEVICE_APPEARANCE;

static sys_slist_t db;
static atomic_t init;

static ssize_t read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
Expand Down Expand Up @@ -237,6 +238,10 @@ static void sc_process(struct k_work *work)

void bt_gatt_init(void)
{
if (!atomic_cas(&init, 0, 1)) {
return;
}

/* Register mandatory services */
gatt_register(&gap_svc);
gatt_register(&gatt_svc);
Expand Down Expand Up @@ -297,6 +302,9 @@ int bt_gatt_service_register(struct bt_gatt_service *svc)
__ASSERT(svc->attrs, "invalid parameters\n");
__ASSERT(svc->attr_count, "invalid parameters\n");

/* Init GATT core services */
bt_gatt_init();

/* Do no allow to register mandatory services twice */
if (!bt_uuid_cmp(svc->attrs[0].uuid, BT_UUID_GAP) ||
!bt_uuid_cmp(svc->attrs[0].uuid, BT_UUID_GATT)) {
Expand Down

0 comments on commit e3f30be

Please sign in to comment.