diff --git a/nimble/host/services/lls/include/services/lls/ble_svc_lls.h b/nimble/host/services/lls/include/services/lls/ble_svc_lls.h index 049ab6fd6..7d1870e8a 100644 --- a/nimble/host/services/lls/include/services/lls/ble_svc_lls.h +++ b/nimble/host/services/lls/include/services/lls/ble_svc_lls.h @@ -40,9 +40,8 @@ uint8_t ble_svc_lls_alert_level_get(void); int ble_svc_lls_alert_level_set(uint8_t alert_level); void ble_svc_lls_on_gap_disconnect(int reason); -int ble_svc_lls_init(struct ble_hs_cfg *cfg, - uint8_t initial_alert_level, - ble_svc_lls_event_fn *cb); +void ble_svc_lls_set_cb(ble_svc_lls_event_fn *cb); +void ble_svc_lls_init(void); #ifdef __cplusplus } diff --git a/nimble/host/services/lls/pkg.yml b/nimble/host/services/lls/pkg.yml index ae786dbca..0a228847c 100644 --- a/nimble/host/services/lls/pkg.yml +++ b/nimble/host/services/lls/pkg.yml @@ -25,7 +25,10 @@ pkg.keywords: - ble - bluetooth - lls - - nimble + - nimble pkg.deps: - net/nimble/host + +pkg.init: + ble_svc_lls_init: 300 diff --git a/nimble/host/services/lls/src/ble_svc_lls.c b/nimble/host/services/lls/src/ble_svc_lls.c index 434814f34..a79fde63b 100644 --- a/nimble/host/services/lls/src/ble_svc_lls.c +++ b/nimble/host/services/lls/src/ble_svc_lls.c @@ -19,11 +19,13 @@ #include #include +#include "sysinit/sysinit.h" #include "host/ble_hs.h" #include "services/lls/ble_svc_lls.h" /* Callback function */ -static ble_svc_lls_event_fn *cb_fn; +static ble_svc_lls_event_fn *ble_svc_lls_cb_fn; + /* Alert level */ static uint8_t ble_svc_lls_alert_level; @@ -42,10 +44,10 @@ static const struct ble_gatt_svc_def ble_svc_lls_defs[] = { { /*** Service: Link Loss Service (LLS). */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = BLE_UUID16(BLE_SVC_LLS_UUID16), + .uuid = BLE_UUID16_DECLARE(BLE_SVC_LLS_UUID16), .characteristics = (struct ble_gatt_chr_def[]) { { /*** Characteristic: Alert Level. */ - .uuid = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL), + .uuid = BLE_UUID16_DECLARE(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL), .access_cb = ble_svc_lls_access, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, }, { @@ -132,7 +134,7 @@ void ble_svc_lls_on_gap_disconnect(int reason) { if (reason == BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) { - cb_fn(ble_svc_lls_alert_level); + ble_svc_lls_cb_fn(ble_svc_lls_alert_level); } } @@ -165,37 +167,26 @@ ble_svc_lls_alert_level_set(uint8_t alert_level) return 0; } +void +ble_svc_lls_set_cb(ble_svc_lls_event_fn *cb) +{ + ble_svc_lls_cb_fn = cb; +} + /** - * Initialize the LLS. The developer must specify the event function - * callback for the LLS to function properly. - * - * @param initial_alert_level The initial alert value to set - * @param cb The callback function to call when - * connection has been lost due to - * link loss + * Initialize the IAS package. */ -int -ble_svc_lls_init(struct ble_hs_cfg *cfg, uint8_t initial_alert_level, - ble_svc_lls_event_fn *cb) +void +ble_svc_lls_init(void) { int rc; - - if (!cb) { - return BLE_HS_EINVAL; - } - ble_svc_lls_alert_level = initial_alert_level; - cb_fn = cb; + /* Ensure this function only gets called by sysinit. */ + SYSINIT_ASSERT_ACTIVE(); - rc = ble_gatts_count_cfg(ble_svc_lls_defs, cfg); - if (rc != 0) { - return rc; - } + rc = ble_gatts_count_cfg(ble_svc_lls_defs); + SYSINIT_PANIC_ASSERT(rc == 0); rc = ble_gatts_add_svcs(ble_svc_lls_defs); - if (rc != 0) { - return rc; - } - - return 0; + SYSINIT_PANIC_ASSERT(rc == 0); } diff --git a/nimble/host/services/tps/src/ble_svc_tps.c b/nimble/host/services/tps/src/ble_svc_tps.c index fe71b7921..86eb139ed 100644 --- a/nimble/host/services/tps/src/ble_svc_tps.c +++ b/nimble/host/services/tps/src/ble_svc_tps.c @@ -41,10 +41,10 @@ static const struct ble_gatt_svc_def ble_svc_tps_defs[] = { { /*** Service: Tx Power Service. */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = BLE_UUID16(BLE_SVC_TPS_UUID16), + .uuid = BLE_UUID16_DECLARE(BLE_SVC_TPS_UUID16), .characteristics = (struct ble_gatt_chr_def[]) { { /*** Characteristic: Tx Power Level. */ - .uuid = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL), + .uuid = BLE_UUID16_DECLARE(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL), .access_cb = ble_svc_tps_access, .flags = BLE_GATT_CHR_F_READ, }, {