From 0019b41a5c4f65b73c5f03fc862928d1ed0b1422 Mon Sep 17 00:00:00 2001 From: Christopher Collins Date: Tue, 8 Nov 2016 14:40:56 -0800 Subject: [PATCH] BLE ANS service - Use sysinit. X-Original-Commit: 32b0d33a3a409668e9199c9bb6c28a8f5db3d374 --- .../ans/include/services/ans/ble_svc_ans.h | 4 +- nimble/host/services/ans/pkg.yml | 3 + nimble/host/services/ans/src/ble_svc_ans.c | 65 ++++++++----------- nimble/host/services/ans/syscfg.yml | 25 +++++++ 4 files changed, 56 insertions(+), 41 deletions(-) create mode 100644 nimble/host/services/ans/syscfg.yml diff --git a/nimble/host/services/ans/include/services/ans/ble_svc_ans.h b/nimble/host/services/ans/include/services/ans/ble_svc_ans.h index eaf102aa2..8d3e3cf01 100644 --- a/nimble/host/services/ans/include/services/ans/ble_svc_ans.h +++ b/nimble/host/services/ans/include/services/ans/ble_svc_ans.h @@ -79,9 +79,7 @@ int ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str); int ble_svc_ans_unr_alert_add(uint8_t cat_id); -int ble_svc_ans_init(struct ble_hs_cfg *cfg, - uint8_t initial_new_alert_cat, - uint8_t initial_unr_alert_cat); +void ble_svc_ans_init(void); #endif diff --git a/nimble/host/services/ans/pkg.yml b/nimble/host/services/ans/pkg.yml index 91a92c686..41a738ce5 100644 --- a/nimble/host/services/ans/pkg.yml +++ b/nimble/host/services/ans/pkg.yml @@ -29,3 +29,6 @@ pkg.keywords: pkg.deps: - net/nimble/host + +pkg.init_function: ble_svc_ans_init +pkg.init_stage: 3 diff --git a/nimble/host/services/ans/src/ble_svc_ans.c b/nimble/host/services/ans/src/ble_svc_ans.c index eae459856..249e2f561 100644 --- a/nimble/host/services/ans/src/ble_svc_ans.c +++ b/nimble/host/services/ans/src/ble_svc_ans.c @@ -20,6 +20,8 @@ #include #include #include +#include "sysinit/sysinit.h" +#include "syscfg/syscfg.h" #include "host/ble_hs.h" #include "host/ble_gap.h" #include "services/ans/ble_svc_ans.h" @@ -347,44 +349,6 @@ ble_svc_ans_unr_alert_add(uint8_t cat_id) return ble_svc_ans_unr_alert_notify(cat_id); } -/** - * Initialize the ANS with initial values for enabled categories - * for new and unread alert characteristics. Bitwise or the - * catagory bitmasks to enable multiple catagories. - * - * XXX: We should technically be able to change the new alert and - * unread alert catagories when we have no active connections. - * - * @param cfg The host configuration - * @param initial_new_alert_cat Initial supported new alert category - * bitmask. - * @param initial_unr_alert_cat Initial supported unread alert category - * bitmask. - * - * @return 0 on success, non-zero error code otherwise. - */ -int -ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t initial_new_alert_cat, - uint8_t initial_unr_alert_cat) -{ - int rc; - - ble_svc_ans_new_alert_cat = initial_new_alert_cat; - ble_svc_ans_unr_alert_cat = initial_unr_alert_cat; - - rc = ble_gatts_count_cfg(ble_svc_ans_defs, cfg); - if (rc != 0) { - return rc; - } - - rc = ble_gatts_add_svcs(ble_svc_ans_defs); - if (rc != 0) { - return rc; - } - - return 0; -} - /** * Send a new alert notification to the given category with the * given info string. @@ -465,3 +429,28 @@ ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len, return 0; } + +/** + * Initialize the ANS with initial values for enabled categories + * for new and unread alert characteristics. Bitwise or the + * catagory bitmasks to enable multiple catagories. + * + * XXX: We should technically be able to change the new alert and + * unread alert catagories when we have no active connections. + * + * @return 0 on success, non-zero error code otherwise. + */ +void +ble_svc_ans_init(void) +{ + int rc; + + rc = ble_gatts_count_cfg(ble_svc_ans_defs); + SYSINIT_PANIC_ASSERT(rc == 0); + + rc = ble_gatts_add_svcs(ble_svc_ans_defs); + SYSINIT_PANIC_ASSERT(rc == 0); + + ble_svc_ans_new_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_NEW_ALERT_CAT); + ble_svc_ans_unr_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_UNR_ALERT_CAT); +} diff --git a/nimble/host/services/ans/syscfg.yml b/nimble/host/services/ans/syscfg.yml new file mode 100644 index 000000000..a77f23dfb --- /dev/null +++ b/nimble/host/services/ans/syscfg.yml @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +syscfg.defs: + BLE_SVC_ANS_NEW_ALERT_CAT: + description: "Initial supported new alert category bitmask." + value: 0 + + BLE_SVC_ANS_UNR_ALERT_CAT: + description: "Initial supported unread alert category bitmask." + value: 0