Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: GATT: Auto init if bt_gatt_service_register is called #9848

Merged
merged 1 commit into from
Sep 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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