Skip to content

Commit 148c7dd

Browse files
Vudentznashif
authored andcommitted
Bluetooth: GATT: Auto init if bt_gatt_service_register is called
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]>
1 parent c2d9807 commit 148c7dd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static sys_slist_t subscriptions;
5050
static const u16_t gap_appearance = CONFIG_BT_DEVICE_APPEARANCE;
5151

5252
static sys_slist_t db;
53+
static atomic_t init;
5354

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

238239
void bt_gatt_init(void)
239240
{
241+
if (!atomic_cas(&init, 0, 1)) {
242+
return;
243+
}
244+
240245
/* Register mandatory services */
241246
gatt_register(&gap_svc);
242247
gatt_register(&gatt_svc);
@@ -297,6 +302,9 @@ int bt_gatt_service_register(struct bt_gatt_service *svc)
297302
__ASSERT(svc->attrs, "invalid parameters\n");
298303
__ASSERT(svc->attr_count, "invalid parameters\n");
299304

305+
/* Init GATT core services */
306+
bt_gatt_init();
307+
300308
/* Do no allow to register mandatory services twice */
301309
if (!bt_uuid_cmp(svc->attrs[0].uuid, BT_UUID_GAP) ||
302310
!bt_uuid_cmp(svc->attrs[0].uuid, BT_UUID_GATT)) {

0 commit comments

Comments
 (0)