You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/08 22:54:51 UTC

[01/22] incubator-mynewt-core git commit: added tx power service to profiles

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop fcef18f37 -> 524af89ee


added tx power service to profiles


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/626b219e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/626b219e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/626b219e

Branch: refs/heads/develop
Commit: 626b219e0d0f6cb6e79802ed7e6612b3856363bb
Parents: a0810f7
Author: Brian Giori <br...@gmail.com>
Authored: Wed Jul 27 17:07:11 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Wed Jul 27 17:07:11 2016 -0700

----------------------------------------------------------------------
 .../tps/include/profiles/tps/ble_svc_tps.h      | 31 +++++++
 net/nimble/host/profiles/tps/pkg.yml            | 32 +++++++
 net/nimble/host/profiles/tps/src/ble_svc_tps.c  | 96 ++++++++++++++++++++
 3 files changed, 159 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/626b219e/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h b/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h
new file mode 100644
index 0000000..c1797ae
--- /dev/null
+++ b/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h
@@ -0,0 +1,31 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_SVC_TPS_
+#define H_BLE_SVC_TPS_
+
+struct ble_hs_cfg;
+
+#define BLE_SVC_TPS_UUID16                                      0x1804
+#define BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL                   0x2a07
+
+int ble_svc_tps_init(struct ble_hs_cfg *cfg); 
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/626b219e/net/nimble/host/profiles/tps/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/pkg.yml b/net/nimble/host/profiles/tps/pkg.yml
new file mode 100644
index 0000000..92f43bb
--- /dev/null
+++ b/net/nimble/host/profiles/tps/pkg.yml
@@ -0,0 +1,32 @@
+
+# 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.
+#
+
+pkg.name: net/nimble/host/profiles/tps
+pkg.description: Tx Power Service adopted specification.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble
+    - bluetooth
+    - tps 
+    - nimble
+
+pkg.deps:
+    - net/nimble/host
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/626b219e/net/nimble/host/profiles/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/src/ble_svc_tps.c b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
new file mode 100644
index 0000000..abcd11e
--- /dev/null
+++ b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
@@ -0,0 +1,96 @@
+/**
+ * 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.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include "host/ble_hs.h"
+#include "profiles/tps/ble_svc_tps.h"
+#include "../../../src/ble_hci_priv.h"
+
+int8_t ble_svc_tps_tx_power_level;
+
+/* Access function */
+static int
+ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+static const struct ble_gatt_svc_def ble_svc_tps_defs[] = {
+    {
+        /*** Service: Tx Power Service. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_SVC_TPS_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Alert Level. */
+            .uuid128 = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
+            .access_cb = ble_svc_tps_access,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+/**
+ * Simple read access callback for the tx power level
+ * characteristic.
+ */
+static int
+ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    assert(ctxt->chr == &ble_svc_tps_defs[0].characteristics[0]);
+    switch(ctxt->op) {
+    case BLE_GATT_ACCESS_OP_READ_CHR:
+        ble_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);
+        rc = os_mbuf_append(ctxt->om, &ble_svc_tps_tx_power_level,
+                            sizeof ble_svc_tps_tx_power_level);
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    default:
+        assert(0);
+        break;
+    }
+
+    return 0;
+}
+
+/**
+ * Initialize the TPS. The developer must specify the event function
+ * callback for the TPS to function properly.
+ */
+int
+ble_svc_tps_init(struct ble_hs_cfg *cfg)
+{
+    int rc;
+    rc = ble_gatts_count_cfg(ble_svc_tps_defs, cfg);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_gatts_add_svcs(ble_svc_lls_defs);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}


[11/22] incubator-mynewt-core git commit: Variables declared at top of function scope

Posted by cc...@apache.org.
Variables declared at top of function scope


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/34406078
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/34406078
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/34406078

Branch: refs/heads/develop
Commit: 34406078522a6f7411bf958cadf81e81fabf7383
Parents: ca151c0
Author: Brian Giori <br...@gmail.com>
Authored: Mon Aug 1 14:14:51 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Mon Aug 1 14:14:51 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/profiles/ans/src/ble_svc_ans.c | 43 +++++++++++++--------
 1 file changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34406078/net/nimble/host/profiles/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/src/ble_svc_ans.c b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
index a361abe..2cebd8b 100644
--- a/net/nimble/host/profiles/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
@@ -49,7 +49,12 @@ static uint8_t ble_svc_ans_unr_alert_cnt[BLE_SVC_ANS_CAT_NUM];
 static uint16_t ble_svc_ans_new_alert_val_handle;
 static uint16_t ble_svc_ans_unr_alert_val_handle;
 
-/* Connection handle */
+/* Connection handle 
+ *
+ * TODO: In order to support multiple connections we would need to save
+ *       the handles for every connection, not just the most recent. Then
+ *       we would need to notify each connection when needed.
+ * */
 static uint16_t ble_svc_ans_conn_handle;
 
 /* Access function */
@@ -146,6 +151,12 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
 {
     uint16_t uuid16;
     int rc;
+    
+    /* ANS Control point command and catagory variables */
+    uint8_t cmd_id;
+    uint8_t cat_id;
+    uint8_t cat_bit_mask; 
+    int i;
 
     uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
     assert(uuid16 != 0);
@@ -200,9 +211,8 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
                                        NULL);
 
             /* Get command ID and category ID */
-            uint8_t cmd_id = ble_svc_ans_alert_not_ctrl_pt[0];
-            uint8_t cat_id = ble_svc_ans_alert_not_ctrl_pt[1];
-            uint8_t cat_bit_mask; 
+            cmd_id = ble_svc_ans_alert_not_ctrl_pt[0];
+            cat_id = ble_svc_ans_alert_not_ctrl_pt[1];
 
             /* Set cat_bit_mask to the appropriate bitmask based on cat_id */
             if (cat_id < BLE_SVC_ANS_CAT_NUM) {
@@ -229,7 +239,6 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
             case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE:
                 if (cat_id == 0xff) {
                     /* If cat_id is 0xff, notify on all enabled categories */
-                    int i;
                     for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
                         if ((ble_svc_ans_new_alert_cat >> i) & 0x01) {
                             ble_svc_ans_new_alert_notify(i, NULL);
@@ -242,7 +251,6 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
             case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE:
                 if (cat_id == 0xff) {
                     /* If cat_id is 0xff, notify on all enabled categories */
-                    int i;
                     for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
                         if ((ble_svc_ans_unr_alert_cat >> i) & 0x01) {
                             ble_svc_ans_unr_alert_notify(i);
@@ -296,6 +304,7 @@ int
 ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
 {
     uint8_t cat_bit_mask; 
+    
     if (cat_id < BLE_SVC_ANS_CAT_NUM) {
         cat_bit_mask = (1 << cat_id); 
     } else {
@@ -323,6 +332,7 @@ int
 ble_svc_ans_unr_alert_add(uint8_t cat_id)
 {
     uint8_t cat_bit_mask; 
+    
     if (cat_id < BLE_SVC_ANS_CAT_NUM) {
         cat_bit_mask = pow(2, cat_id);
     } else {
@@ -357,10 +367,11 @@ 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;
 
-    int rc;
     rc = ble_gatts_count_cfg(ble_svc_ans_defs, cfg);
     if (rc != 0) {
         return rc;
@@ -388,6 +399,8 @@ ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t initial_new_alert_cat,
 static int
 ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str)
 {
+    int info_str_len;
+
     /* Clear notification to remove old infomation that may persist */
     memset(&ble_svc_ans_new_alert_val, '\0', 
            BLE_SVC_ANS_NEW_ALERT_MAX_LEN); 
@@ -397,19 +410,18 @@ ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str)
     ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_id];
     
     if (info_str) {
-        int n = strlen(info_str);
-        if (n > BLE_SVC_ANS_INFO_STR_MAX_LEN) {
+        info_str_len = strlen(info_str);
+        if (info_str_len > BLE_SVC_ANS_INFO_STR_MAX_LEN) {
             /* If info_str is longer than the max string length only 
              * write up to the maximum length */
             memcpy(&ble_svc_ans_new_alert_val[2], info_str, 
                    BLE_SVC_ANS_INFO_STR_MAX_LEN);
         } else {
-            memcpy(&ble_svc_ans_new_alert_val[2], info_str, n);
+            memcpy(&ble_svc_ans_new_alert_val[2], info_str, info_str_len);
         }
     }
-    int rc = ble_gattc_notify(ble_svc_ans_conn_handle, 
-                              ble_svc_ans_new_alert_val_handle);
-    return rc;
+    return ble_gattc_notify(ble_svc_ans_conn_handle, 
+                            ble_svc_ans_new_alert_val_handle);
 }
 
 /**
@@ -425,9 +437,8 @@ ble_svc_ans_unr_alert_notify(uint8_t cat_id)
 {
     ble_svc_ans_unr_alert_stat[0] = cat_id;
     ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_id];
-    int rc = ble_gattc_notify(ble_svc_ans_conn_handle, 
-                              ble_svc_ans_unr_alert_val_handle);
-    return rc;
+    return ble_gattc_notify(ble_svc_ans_conn_handle, 
+                            ble_svc_ans_unr_alert_val_handle);
 }
 
 /**


[13/22] incubator-mynewt-core git commit: update include path

Posted by cc...@apache.org.
update include path


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1d68f68f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1d68f68f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1d68f68f

Branch: refs/heads/develop
Commit: 1d68f68fe0c612a3105872d9000b552977cae154
Parents: 64b1cd9
Author: Brian Giori <br...@gmail.com>
Authored: Mon Aug 1 17:16:02 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Mon Aug 1 17:16:02 2016 -0700

----------------------------------------------------------------------
 .../ans/include/profiles/ans/ble_svc_ans.h      | 87 --------------------
 .../ans/include/services/ans/ble_svc_ans.h      | 87 ++++++++++++++++++++
 2 files changed, 87 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d68f68f/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h b/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h
deleted file mode 100644
index eaf102a..0000000
--- a/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * 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.
- */
-
-#ifndef H_BLE_SVC_ANS_
-#define H_BLE_SVC_ANS_
-
-struct ble_hs_cfg;
-
-/* 16 Bit Alert Notification Service UUID */
-#define BLE_SVC_ANS_UUID16                                  0x1811
-
-/* 16 Bit Alert Notification Servivce Characteristic UUIDs */
-#define BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT            0x2a47
-#define BLE_SVC_ANS_CHR_UUID16_NEW_ALERT                    0x2a46
-#define BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT            0x2a48
-#define BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT               0x2a45
-#define BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT            0x2a44
-
-/* Alert Notification Service Category ID Bit Masks 
- *
- * TODO: Add remaining 2 optional categories */
-#define BLE_SVC_ANS_CAT_BM_NONE                             0x00
-#define BLE_SVC_ANS_CAT_BM_SIMPLE_ALERT                     0x01
-#define BLE_SVC_ANS_CAT_BM_EMAIL                            0x02
-#define BLE_SVC_ANS_CAT_BM_NEWS                             0x04
-#define BLE_SVC_ANS_CAT_BM_CALL                             0x08
-#define BLE_SVC_ANS_CAT_BM_MISSED_CALL                      0x10
-#define BLE_SVC_ANS_CAT_BM_SMS                              0x20
-#define BLE_SVC_ANS_CAT_BM_VOICE_MAIL                       0x40
-#define BLE_SVC_ANS_CAT_BM_SCHEDULE                         0x80    
-
-/* Alert Notification Service Category IDs
- *
- * TODO: Add remaining 2 optional categories */
-#define BLE_SVC_ANS_CAT_ID_SIMPLE_ALERT                     0
-#define BLE_SVC_ANS_CAT_ID_EMAIL                            1
-#define BLE_SVC_ANS_CAT_ID_NEWS                             2
-#define BLE_SVC_ANS_CAT_ID_CALL                             3
-#define BLE_SVC_ANS_CAT_ID_MISSED_CALL                      4
-#define BLE_SVC_ANS_CAT_ID_SMS                              5
-#define BLE_SVC_ANS_CAT_ID_VOICE_MAIL                       6
-#define BLE_SVC_ANS_CAT_ID_SCHEDULE                         7
-
-/* Number of valid ANS categories 
- *
- * TODO: Add remaining 2 optional categories */
-#define BLE_SVC_ANS_CAT_NUM                                 8
-
-/* Alert Notification Control Point Command IDs */
-#define BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT                    0
-#define BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT                    1
-#define BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT                   2
-#define BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT                   3
-#define BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE             4
-#define BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE             5
-
-/* Error Defeinitions */
-#define BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED                   0xA0
-
-void ble_svc_ans_on_gap_connect(uint16_t conn_handle);
-
-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);
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d68f68f/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h b/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
new file mode 100644
index 0000000..eaf102a
--- /dev/null
+++ b/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
@@ -0,0 +1,87 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_SVC_ANS_
+#define H_BLE_SVC_ANS_
+
+struct ble_hs_cfg;
+
+/* 16 Bit Alert Notification Service UUID */
+#define BLE_SVC_ANS_UUID16                                  0x1811
+
+/* 16 Bit Alert Notification Servivce Characteristic UUIDs */
+#define BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT            0x2a47
+#define BLE_SVC_ANS_CHR_UUID16_NEW_ALERT                    0x2a46
+#define BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT            0x2a48
+#define BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT               0x2a45
+#define BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT            0x2a44
+
+/* Alert Notification Service Category ID Bit Masks 
+ *
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_BM_NONE                             0x00
+#define BLE_SVC_ANS_CAT_BM_SIMPLE_ALERT                     0x01
+#define BLE_SVC_ANS_CAT_BM_EMAIL                            0x02
+#define BLE_SVC_ANS_CAT_BM_NEWS                             0x04
+#define BLE_SVC_ANS_CAT_BM_CALL                             0x08
+#define BLE_SVC_ANS_CAT_BM_MISSED_CALL                      0x10
+#define BLE_SVC_ANS_CAT_BM_SMS                              0x20
+#define BLE_SVC_ANS_CAT_BM_VOICE_MAIL                       0x40
+#define BLE_SVC_ANS_CAT_BM_SCHEDULE                         0x80    
+
+/* Alert Notification Service Category IDs
+ *
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_ID_SIMPLE_ALERT                     0
+#define BLE_SVC_ANS_CAT_ID_EMAIL                            1
+#define BLE_SVC_ANS_CAT_ID_NEWS                             2
+#define BLE_SVC_ANS_CAT_ID_CALL                             3
+#define BLE_SVC_ANS_CAT_ID_MISSED_CALL                      4
+#define BLE_SVC_ANS_CAT_ID_SMS                              5
+#define BLE_SVC_ANS_CAT_ID_VOICE_MAIL                       6
+#define BLE_SVC_ANS_CAT_ID_SCHEDULE                         7
+
+/* Number of valid ANS categories 
+ *
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_NUM                                 8
+
+/* Alert Notification Control Point Command IDs */
+#define BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT                    0
+#define BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT                    1
+#define BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT                   2
+#define BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT                   3
+#define BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE             4
+#define BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE             5
+
+/* Error Defeinitions */
+#define BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED                   0xA0
+
+void ble_svc_ans_on_gap_connect(uint16_t conn_handle);
+
+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);
+
+#endif
+


[17/22] incubator-mynewt-core git commit: BLE IAS svc - Update to use sysinit.

Posted by cc...@apache.org.
BLE IAS svc - Update to use sysinit.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/bbe1c78a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bbe1c78a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bbe1c78a

Branch: refs/heads/develop
Commit: bbe1c78a1896c1a5f12839514aecba0add6610f4
Parents: 44fffd4
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:15:09 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:15:09 2016 -0800

----------------------------------------------------------------------
 .../ias/include/services/ias/ble_svc_ias.h      |  6 ++--
 net/nimble/host/services/ias/pkg.yml            |  2 ++
 net/nimble/host/services/ias/src/ble_svc_ias.c  | 38 ++++++++++----------
 3 files changed, 22 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bbe1c78a/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h b/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h
index da173cf..b63b458 100644
--- a/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h
+++ b/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h
@@ -20,8 +20,6 @@
 #ifndef H_BLE_IAS_TPS_
 #define H_BLE_IAS_TPS_
 
-struct ble_hs_cfg;
-
 #define BLE_SVC_IAS_UUID16                                      0x1802
 #define BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL                      0x2a06
 
@@ -32,8 +30,8 @@ struct ble_hs_cfg;
 
 typedef int ble_svc_ias_event_fn(uint8_t alert_level); 
 
-int ble_svc_ias_init(struct ble_hs_cfg *cfg, 
-                     ble_svc_ias_event_fn *cb);
+void ble_svc_ias_set_cb(ble_svc_ias_event_fn *cb);
+void ble_svc_ias_init(void);
 
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bbe1c78a/net/nimble/host/services/ias/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/pkg.yml b/net/nimble/host/services/ias/pkg.yml
index 39242f4..3879906 100644
--- a/net/nimble/host/services/ias/pkg.yml
+++ b/net/nimble/host/services/ias/pkg.yml
@@ -30,3 +30,5 @@ pkg.keywords:
 pkg.deps:
     - net/nimble/host
 
+pkg.init_function: ble_svc_ias_init
+pkg.init_stage: 3

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bbe1c78a/net/nimble/host/services/ias/src/ble_svc_ias.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/src/ble_svc_ias.c b/net/nimble/host/services/ias/src/ble_svc_ias.c
index 07b98f1..4af6936 100644
--- a/net/nimble/host/services/ias/src/ble_svc_ias.c
+++ b/net/nimble/host/services/ias/src/ble_svc_ias.c
@@ -19,11 +19,13 @@
 
 #include <assert.h>
 #include <string.h>
+#include "sysinit/sysinit.h"
 #include "host/ble_hs.h"
 #include "services/ias/ble_svc_ias.h"
 
 /* Callback function */
 static ble_svc_ias_event_fn *ble_svc_ias_cb_fn;
+
 /* Alert level */
 static uint8_t ble_svc_ias_alert_level;
 
@@ -114,33 +116,29 @@ ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 /**
- * Initialize the IAS. The developer must specify the event function
- * callback for the IAS to function properly.
+ * Designates the specified function as the IAS callback.  This callback is
+ * necessary for this service to function properly.
  *
  * @param cb                        The callback function to call when 
  *                                      the client signals an alert.
  */
-int
-ble_svc_ias_init(struct ble_hs_cfg *cfg, ble_svc_ias_event_fn *cb)
+void
+ble_svc_ias_set_cb(ble_svc_ias_event_fn *cb)
 {
-    int rc;
-    
-    if (!cb) {
-        return BLE_HS_EINVAL;
-    }
-
     ble_svc_ias_cb_fn = cb;
+}
 
-    rc = ble_gatts_count_cfg(ble_svc_ias_defs, cfg);
-    if (rc != 0) {
-        return rc;
-    }
+/**
+ * Initialize the IAS package.
+ */
+void
+ble_svc_ias_init(void)
+{
+    int rc;
+    
+    rc = ble_gatts_count_cfg(ble_svc_ias_defs);
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gatts_add_svcs(ble_svc_ias_defs);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
+    SYSINIT_PANIC_ASSERT(rc == 0);
 }
-


[21/22] incubator-mynewt-core git commit: BLE TPS service - use sysinit.

Posted by cc...@apache.org.
BLE TPS service - use sysinit.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/58d6bcd1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/58d6bcd1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/58d6bcd1

Branch: refs/heads/develop
Commit: 58d6bcd13c5e57741be1db292de012b5c92daa7a
Parents: 5663384
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:46:40 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:46:40 2016 -0800

----------------------------------------------------------------------
 .../services/tps/include/services/tps/ble_svc_tps.h |  2 +-
 net/nimble/host/services/tps/pkg.yml                |  2 ++
 net/nimble/host/services/tps/src/ble_svc_tps.c      | 16 +++++-----------
 3 files changed, 8 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58d6bcd1/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h b/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h
index c1797ae..ec4cd79 100644
--- a/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h
+++ b/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h
@@ -25,7 +25,7 @@ struct ble_hs_cfg;
 #define BLE_SVC_TPS_UUID16                                      0x1804
 #define BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL                   0x2a07
 
-int ble_svc_tps_init(struct ble_hs_cfg *cfg); 
+void ble_svc_tps_init(void);
 
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58d6bcd1/net/nimble/host/services/tps/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/pkg.yml b/net/nimble/host/services/tps/pkg.yml
index 45d85b6..17b2b87 100644
--- a/net/nimble/host/services/tps/pkg.yml
+++ b/net/nimble/host/services/tps/pkg.yml
@@ -30,3 +30,5 @@ pkg.keywords:
 pkg.deps:
     - net/nimble/host
 
+pkg.init_function: ble_svc_tps_init
+pkg.init_stage: 3

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58d6bcd1/net/nimble/host/services/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/src/ble_svc_tps.c b/net/nimble/host/services/tps/src/ble_svc_tps.c
index 3f241b0..2351a79 100644
--- a/net/nimble/host/services/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/services/tps/src/ble_svc_tps.c
@@ -21,7 +21,6 @@
 #include <string.h>
 #include "host/ble_hs.h"
 #include "services/tps/ble_svc_tps.h"
-#include "../../../src/ble_hci_priv.h"
 
 int8_t ble_svc_tps_tx_power_level;
 
@@ -80,19 +79,14 @@ ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
 /**
  * Initialize the TPS
  */
-int
-ble_svc_tps_init(struct ble_hs_cfg *cfg)
+void
+ble_svc_tps_init(void)
 {
     int rc;
+
     rc = ble_gatts_count_cfg(ble_svc_tps_defs, cfg);
-    if (rc != 0) {
-        return rc;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gatts_add_svcs(ble_svc_tps_defs);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
+    SYSINIT_PANIC_ASSERT(rc == 0);
 }


[09/22] incubator-mynewt-core git commit: Immediate Alert Service implemented.

Posted by cc...@apache.org.
Immediate Alert Service implemented.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5091e748
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5091e748
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5091e748

Branch: refs/heads/develop
Commit: 5091e748508c8a7a9126dd05a9ac8a346c12e97a
Parents: 0de126a
Author: Brian Giori <br...@gmail.com>
Authored: Mon Aug 1 13:40:58 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Mon Aug 1 13:40:58 2016 -0700

----------------------------------------------------------------------
 .../ias/include/profiles/ias/ble_svc_ias.h      |  40 +++++
 net/nimble/host/profiles/ias/pkg.yml            |  32 ++++
 net/nimble/host/profiles/ias/src/ble_svc_ias.c  | 146 +++++++++++++++++++
 3 files changed, 218 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5091e748/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h b/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h
new file mode 100644
index 0000000..da173cf
--- /dev/null
+++ b/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_IAS_TPS_
+#define H_BLE_IAS_TPS_
+
+struct ble_hs_cfg;
+
+#define BLE_SVC_IAS_UUID16                                      0x1802
+#define BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL                      0x2a06
+
+/* Alert level definitions */
+#define BLE_SVC_IAS_ALERT_LEVEL_NO_ALERT                        0
+#define BLE_SVC_IAS_ALERT_LEVEL_MILD_ALERT                      1
+#define BLE_SVC_IAS_ALERT_LEVEL_HIGH_ALERT                      2
+
+typedef int ble_svc_ias_event_fn(uint8_t alert_level); 
+
+int ble_svc_ias_init(struct ble_hs_cfg *cfg, 
+                     ble_svc_ias_event_fn *cb);
+
+#endif
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5091e748/net/nimble/host/profiles/ias/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ias/pkg.yml b/net/nimble/host/profiles/ias/pkg.yml
new file mode 100644
index 0000000..ce05ffe
--- /dev/null
+++ b/net/nimble/host/profiles/ias/pkg.yml
@@ -0,0 +1,32 @@
+
+# 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.
+#
+
+pkg.name: net/nimble/host/profiles/ias
+pkg.description: Immidiate Alert Service.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble 
+    - bluetooth
+    - ias 
+    - nimble
+
+pkg.deps:
+    - net/nimble/host
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5091e748/net/nimble/host/profiles/ias/src/ble_svc_ias.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ias/src/ble_svc_ias.c b/net/nimble/host/profiles/ias/src/ble_svc_ias.c
new file mode 100644
index 0000000..5fce5bd
--- /dev/null
+++ b/net/nimble/host/profiles/ias/src/ble_svc_ias.c
@@ -0,0 +1,146 @@
+/**
+ * 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.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include "host/ble_hs.h"
+#include "profiles/ias/ble_svc_ias.h"
+
+/* Callback function */
+static ble_svc_ias_event_fn *ble_svc_ias_cb_fn;
+/* Alert level */
+static uint8_t ble_svc_ias_alert_level;
+
+/* Write characteristic function */
+static int
+ble_svc_ias_chr_write(struct os_mbuf *om, uint16_t min_len,
+                      uint16_t max_len, void *dst,
+                      uint16_t *len);
+
+/* Access function */
+static int
+ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+static const struct ble_gatt_svc_def ble_svc_ias_defs[] = {
+    {
+        /*** Service: Immediate Alert Service (IAS). */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_SVC_IAS_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Alert Level. */
+            .uuid128 = BLE_UUID16(BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL),
+            .access_cb = ble_svc_ias_access,
+            .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+/**
+ * Writes the received value from a characteristic write to 
+ * the given destination.
+ */
+static int
+ble_svc_ias_chr_write(struct os_mbuf *om, uint16_t min_len, 
+                      uint16_t max_len, void *dst, 
+                      uint16_t *len)
+{
+    uint16_t om_len;
+    int rc; 
+
+    om_len = OS_MBUF_PKTLEN(om);
+    if (om_len < min_len || om_len > max_len) {
+        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    }   
+
+    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
+    if (rc != 0) {
+        return BLE_ATT_ERR_UNLIKELY;
+    }   
+
+    return 0;
+}
+
+/**
+ * Simple write access callback for the alert level
+ * characteristic.
+ */
+static int
+ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    int rc;
+    
+    assert(ctxt->chr == &ble_svc_ias_defs[0].characteristics[0]);
+    
+    switch (ctxt->op) {
+    case BLE_GATT_ACCESS_OP_WRITE_CHR:
+        rc = ble_svc_ias_chr_write(ctxt->om,
+                                   sizeof ble_svc_ias_alert_level,
+                                   sizeof ble_svc_ias_alert_level,
+                                   &ble_svc_ias_alert_level, NULL);
+        /* Call the IAS event function */
+        ble_svc_ias_cb_fn(ble_svc_ias_alert_level);
+        return rc;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+
+    return 0;
+}
+
+/**
+ * Initialize the IAS. The developer must specify the event function
+ * callback for the IAS to function properly.
+ *
+ * @param cb                        The callback function to call when 
+ *                                      the client signals an alert.
+ */
+int
+ble_svc_ias_init(struct ble_hs_cfg *cfg, ble_svc_ias_event_fn *cb)
+{
+    int rc;
+    
+    if (!cb) {
+        return BLE_HS_EINVAL;
+    }
+
+    ble_svc_ias_cb_fn = cb;
+
+    rc = ble_gatts_count_cfg(ble_svc_ias_defs, cfg);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_gatts_add_svcs(ble_svc_ias_defs);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}
+


[18/22] incubator-mynewt-core git commit: This closes #85.

Posted by cc...@apache.org.
This closes #85.

Merge remote-tracking branch 'bgiori/feature-ans' into develop

* bgiori/feature-ans:
  update include path
  moved location to services from profiles
  Variables declared at top of function scope
  updated comments
  Alert Notification Service implemented.
  fixed compilation errors and runs. Untested. Unfinished.
  unfinished changes


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ff4ce466
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ff4ce466
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ff4ce466

Branch: refs/heads/develop
Commit: ff4ce4660d43d3e1d24e3e66f277c0939cd3ff0c
Parents: bbe1c78 1d68f68
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:29:28 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:29:28 2016 -0800

----------------------------------------------------------------------
 .../ans/include/services/ans/ble_svc_ans.h      |  87 ++++
 net/nimble/host/services/ans/pkg.yml            |  31 ++
 net/nimble/host/services/ans/src/ble_svc_ans.c  | 467 +++++++++++++++++++
 3 files changed, 585 insertions(+)
----------------------------------------------------------------------



[07/22] incubator-mynewt-core git commit: Alert Notification Service implemented.

Posted by cc...@apache.org.
Alert Notification Service implemented.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/619af6e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/619af6e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/619af6e8

Branch: refs/heads/develop
Commit: 619af6e8fe9afbc3c23124b6a81a689f903b60e3
Parents: c41f7f3
Author: Brian Giori <br...@gmail.com>
Authored: Fri Jul 29 15:06:26 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Fri Jul 29 15:06:26 2016 -0700

----------------------------------------------------------------------
 .../ans/include/profiles/ans/ble_svc_ans.h      |  45 +--
 net/nimble/host/profiles/ans/src/ble_svc_ans.c  | 308 +++++++++++++------
 2 files changed, 231 insertions(+), 122 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/619af6e8/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h b/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
index c37c977..eaf102a 100644
--- a/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
+++ b/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
@@ -34,31 +34,32 @@ struct ble_hs_cfg;
 
 /* Alert Notification Service Category ID Bit Masks 
  *
- * TODO: Need to add remaining 2 categories */
-#define BLE_SVC_ANS_CAT_F_SIMPLE_ALERT                      0x01
-#define BLE_SVC_ANS_CAT_F_EMAIL                             0x02
-#define BLE_SVC_ANS_CAT_F_NEWS                              0x04
-#define BLE_SVC_ANS_CAT_F_CALL                              0x08
-#define BLE_SVC_ANS_CAT_F_MISSED_CALL                       0x10
-#define BLE_SVC_ANS_CAT_F_SMS                               0x20
-#define BLE_SVC_ANS_CAT_F_VOICE_MAIL                        0x40
-#define BLE_SVC_ANS_CAT_F_SCHEDULE                          0x80    
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_BM_NONE                             0x00
+#define BLE_SVC_ANS_CAT_BM_SIMPLE_ALERT                     0x01
+#define BLE_SVC_ANS_CAT_BM_EMAIL                            0x02
+#define BLE_SVC_ANS_CAT_BM_NEWS                             0x04
+#define BLE_SVC_ANS_CAT_BM_CALL                             0x08
+#define BLE_SVC_ANS_CAT_BM_MISSED_CALL                      0x10
+#define BLE_SVC_ANS_CAT_BM_SMS                              0x20
+#define BLE_SVC_ANS_CAT_BM_VOICE_MAIL                       0x40
+#define BLE_SVC_ANS_CAT_BM_SCHEDULE                         0x80    
 
 /* Alert Notification Service Category IDs
  *
- * TODO: Need to add remaining 2 categories */
-#define BLE_SVC_ANS_CAT_SIMPLE_ALERT                        0
-#define BLE_SVC_ANS_CAT_EMAIL                               1
-#define BLE_SVC_ANS_CAT_NEWS                                2
-#define BLE_SVC_ANS_CAT_CALL                                3
-#define BLE_SVC_ANS_CAT_MISSED_CALL                         4
-#define BLE_SVC_ANS_CAT_SMS                                 5
-#define BLE_SVC_ANS_CAT_VOICE_MAIL                          6
-#define BLE_SVC_ANS_CAT_SCHEDULE                            7
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_ID_SIMPLE_ALERT                     0
+#define BLE_SVC_ANS_CAT_ID_EMAIL                            1
+#define BLE_SVC_ANS_CAT_ID_NEWS                             2
+#define BLE_SVC_ANS_CAT_ID_CALL                             3
+#define BLE_SVC_ANS_CAT_ID_MISSED_CALL                      4
+#define BLE_SVC_ANS_CAT_ID_SMS                              5
+#define BLE_SVC_ANS_CAT_ID_VOICE_MAIL                       6
+#define BLE_SVC_ANS_CAT_ID_SCHEDULE                         7
 
 /* Number of valid ANS categories 
  *
- * TODO: Need to add remaining 2 categories */
+ * TODO: Add remaining 2 optional categories */
 #define BLE_SVC_ANS_CAT_NUM                                 8
 
 /* Alert Notification Control Point Command IDs */
@@ -72,13 +73,15 @@ struct ble_hs_cfg;
 /* Error Defeinitions */
 #define BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED                   0xA0
 
-#define BLE_SVC_ANS_INFO_STR_MAX_LEN                        18
+void ble_svc_ans_on_gap_connect(uint16_t conn_handle);
 
 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);
+int ble_svc_ans_init(struct ble_hs_cfg *cfg, 
+                     uint8_t initial_new_alert_cat,
+                     uint8_t initial_unr_alert_cat);
 
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/619af6e8/net/nimble/host/profiles/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/src/ble_svc_ans.c b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
index 4379cf5..32d3350 100644
--- a/net/nimble/host/profiles/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
@@ -21,60 +21,100 @@
 #include <string.h>
 #include <math.h>
 #include "host/ble_hs.h"
+#include "host/ble_gap.h"
 #include "profiles/ans/ble_svc_ans.h"
 
+
+/* Max length of new alert info string */
+#define BLE_SVC_ANS_INFO_STR_MAX_LEN        18
+/* Max length of a new alert notification, max string length + 2 bytes
+ * for category ID and count. */
+#define BLE_SVC_ANS_NEW_ALERT_MAX_LEN   (BLE_SVC_ANS_INFO_STR_MAX_LEN + 2)
+
+/* Supported categories bitmasks */
+static uint8_t ble_svc_ans_new_alert_cat;
+static uint8_t ble_svc_ans_unr_alert_cat; 
+
+/* Characteristic values */
+static uint8_t ble_svc_ans_new_alert_val[BLE_SVC_ANS_NEW_ALERT_MAX_LEN];
+static uint16_t ble_svc_ans_new_alert_val_len;
+static uint8_t ble_svc_ans_unr_alert_stat[2];
+static uint8_t ble_svc_ans_alert_not_ctrl_pt[2];
+
+/* Alert counts, one value for each category */
+static uint8_t ble_svc_ans_new_alert_cnt[BLE_SVC_ANS_CAT_NUM];
+static uint8_t ble_svc_ans_unr_alert_cnt[BLE_SVC_ANS_CAT_NUM];
+
+/* Charachteristic value handles */
+static uint16_t ble_svc_ans_new_alert_val_handle;
+static uint16_t ble_svc_ans_unr_alert_val_handle;
+
+/* Connection handle */
+static uint16_t ble_svc_ans_conn_handle;
+
 /* Access function */
 static int
 ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
                    struct ble_gatt_access_ctxt *ctxt, void *arg);
 
+/* Notify new alert */
+static int
+ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str);
+
+/* Notify unread alert */
+static int
+ble_svc_ans_unr_alert_notify(uint8_t cat_id);
+
+/* Save written value to local characteristic value */
+static int
+ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, 
+                      void *dst, uint16_t *len);
+
 static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
     {
         /*** Alert Notification Service. */
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(BLE_SVC_ANS_UUID16),
         .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Supported New Alert Catagory 
+            /** Supported New Alert Catagory 
              * 
              * This characteristic exposes what categories of new 
              * alert are supported in the server.
-             * 
-             * */
+             */
             .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT),
             .access_cb = ble_svc_ans_access,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
-            /*** New Alert 
+            /** New Alert 
              *
              * This characteristic exposes information about 
              * the count of new alerts (for a given category).
-             *
-             * */
+             */
             .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_NEW_ALERT),
             .access_cb = ble_svc_ans_access,
+            .val_handle = &ble_svc_ans_new_alert_val_handle,
             .flags = BLE_GATT_CHR_F_NOTIFY,
         }, {
-            /*** Supported Unread Alert Catagory 
+            /** Supported Unread Alert Catagory 
              *
              * This characteristic exposes what categories of 
              * unread alert are supported in the server.
-             *
-             * */
+             */
             .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT),
             .access_cb = ble_svc_ans_access,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
-            /*** Unread Alert Status 
+            /** Unread Alert Status 
              *
              * This characteristic exposes the count of unread 
              * alert events existing in the server.
-             *
-             * */
+             */
             .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT),
             .access_cb = ble_svc_ans_access,
+            .val_handle = &ble_svc_ans_unr_alert_val_handle,
             .flags = BLE_GATT_CHR_F_NOTIFY,
         }, {
-            /*** Alert Notification Control Point 
+            /** Alert Notification Control Point 
              *
              * This characteristic allows the peer device to 
              * enable/disable the alert notification of new alert 
@@ -82,8 +122,7 @@ static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
              * by setting or clearing the notification bit in the 
              * Client Characteristic Configuration for each alert 
              * characteristic.
-             *
-             * */
+             */
             .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT),
             .access_cb = ble_svc_ans_access,
             .flags = BLE_GATT_CHR_F_WRITE,
@@ -97,51 +136,9 @@ static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
     },
 };
 
-static int
-ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
-                      uint16_t max_len, void *dst,
-                      uint16_t *len)
-{
-    uint16_t om_len;
-    int rc;
-
-    om_len = OS_MBUF_PKTLEN(om);
-    if (om_len < min_len || om_len > max_len) {
-        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
-    }
-
-    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
-    if (rc != 0) {
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-
-    return 0;
-}
-
-/* Because the max length of the info string is 18 octets,
- * and the category ID and count take up 2 octets each, we
- * require a maximum of 20 octets of space.
+/**
+ * ANS access function
  */
-#define GATT_SVR_NEW_ALERT_VAL_MAX_LEN   20 
-
-/* Supported new alert categories bitmask */
-static uint8_t ble_svc_ans_new_alert_cat;
-/* New alert value */
-static uint8_t ble_svc_ans_new_alert_val[GATT_SVR_NEW_ALERT_VAL_MAX_LEN];
-static uint16_t ble_svc_ans_new_alert_val_len;
-/* New alert count, one value for each category */
-static uint8_t ble_svc_ans_new_alert_cnt[BLE_SVC_ANS_CAT_NUM];
-
-/* Supported unread alert catagories bitmask */ 
-static uint8_t ble_svc_ans_unr_alert_cat; 
-/* Unread alert status, contains supported catagories and count */
-static uint8_t ble_svc_ans_unr_alert_stat[2];
-/* Count of unread alerts. One value for each category */
-static uint8_t ble_svc_ans_unr_alert_cnt[BLE_SVC_ANS_CAT_NUM];
-
-/* Alert notification control point value */
-static uint8_t ble_svc_ans_alert_not_ctrl_pt[2];
-
 static int
 ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
                           struct ble_gatt_access_ctxt *ctxt,
@@ -205,36 +202,53 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
             /* Get command ID and category ID */
             uint8_t cmd_id = ble_svc_ans_alert_not_ctrl_pt[0];
             uint8_t cat_id = ble_svc_ans_alert_not_ctrl_pt[1];
-            uint8_t cat; 
+            uint8_t cat_bit_mask; 
 
-            /* Set cat to the appropriate bitmask based on cat_id or
-             * return error if the cat_id in an invalid range.
-             */
+            /* Set cat_bit_mask to the appropriate bitmask based on cat_id */
             if (cat_id < BLE_SVC_ANS_CAT_NUM) {
-                cat = (1 << cat_id); 
-            } else if (cat_id == 0xff) {
-                cat = cat_id;
+                cat_bit_mask = (1 << cat_id); 
+            } else if (cat_id == 0xff) { 
+                cat_bit_mask = cat_id;
             } else {
-                return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
+                cat_bit_mask = 0;
             }
-            switch(cmd_id) {
+
+            switch (cmd_id) {
             case BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT:
-                ble_svc_ans_new_alert_cat |= cat; 
+                ble_svc_ans_new_alert_cat |= cat_bit_mask; 
                 break;
             case BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT:
-                ble_svc_ans_unr_alert_cat |= cat;
+                ble_svc_ans_unr_alert_cat |= cat_bit_mask;
                 break;
             case BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT:
-                ble_svc_ans_new_alert_cat &= ~cat;
+                ble_svc_ans_new_alert_cat &= ~cat_bit_mask;
                 break;
             case BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT:
-                ble_svc_ans_unr_alert_cat &= ~cat;
+                ble_svc_ans_unr_alert_cat &= ~cat_bit_mask;
                 break;
             case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE:
-                /* TODO */
+                if (cat_id == 0xff) {
+                    int i;
+                    for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
+                        if ((ble_svc_ans_new_alert_cat >> i) & 0x01) {
+                            ble_svc_ans_new_alert_notify(i, NULL);
+                        }
+                    }
+                } else {
+                    ble_svc_ans_new_alert_notify(cat_id, NULL);
+                }
                 break;
             case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE:
-                /* TODO */
+                if (cat_id == 0xff) {
+                    int i;
+                    for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
+                        if ((ble_svc_ans_unr_alert_cat >> i) & 0x01) {
+                            ble_svc_ans_unr_alert_notify(i);
+                        }
+                    }
+                } else {
+                    ble_svc_ans_unr_alert_notify(cat_id);
+                }
                 break;
             default:
                 return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
@@ -252,18 +266,29 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 /**
- * Adds a new alert to the given category then sets the new 
- * alert val to the category, the new alert count for the given 
- * category, and the given info string. If set up for notification, 
- * setting this value will notify the client.
- * 
- * @param cat_flag              The flag for the category which should
+ * This function must be called with the connection handlewhen a gap 
+ * connect event is received in order to send notifications to the
+ * client
+ *
+ * @params conn_handle          The connection handle for the current
+ *                                  connection.
+ */
+void 
+ble_svc_ans_on_gap_connect(uint16_t conn_handle) 
+{
+    ble_svc_ans_conn_handle = conn_handle;
+}
+
+/**
+ * Adds a new alert to the given category then notifies the client
+ * if the given category is valid and enabled.
+ *
+ * @param cat_flag              The id for the category which should
  *                                  should be incremented and notified
  * @param info_str              The info string to be sent to the client
  *                                  with the notification.
  * 
- * @return 0 if success, BLE_HS_EINVAL if the category is not enabled 
- *         or if the flag is not valid.
+ * @return 0 if success, error code otherwise. 
  */
 int
 ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
@@ -280,23 +305,12 @@ ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
     }
 
     ble_svc_ans_new_alert_cnt[cat_id] += 1;
-    ble_svc_ans_new_alert_val[0] = cat_id;
-    ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_id];
-    int n = sizeof info_str;
-    if (n > BLE_SVC_ANS_INFO_STR_MAX_LEN) {
-        memcpy(&ble_svc_ans_new_alert_val[2], info_str, 
-                BLE_SVC_ANS_INFO_STR_MAX_LEN);
-    } else {
-        memcpy(&ble_svc_ans_new_alert_val[2], info_str, n);
-    }
-    return 0;
+    return ble_svc_ans_new_alert_notify(cat_id, info_str);
 }
 
 /**
- * Adds an unread alert to the given category then sets the unread
- * alert stat to the category and the new unread alert value for
- * the given category. If set up for notification, setting this value
- * will notify the client.
+ * Adds an unread alert to the given category then notifies the client
+ * if the given category is valid and enabled.
  * 
  * @param cat_flag              The flag for the category which should
  *                                  should be incremented and notified
@@ -319,20 +333,32 @@ ble_svc_ans_unr_alert_add(uint8_t cat_id)
     }
 
     ble_svc_ans_unr_alert_cnt[cat_id] += 1;
-    ble_svc_ans_unr_alert_stat[0] = cat_id;
-    ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_id];
-    return 0;
+    return ble_svc_ans_unr_alert_notify(cat_id);
 }
 
 /**
- * Initialize the ANS 
+ * 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 on error.
  */
 int
-ble_svc_ans_init(struct ble_hs_cfg *cfg)
+ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t initial_new_alert_cat,
+                 uint8_t initial_unr_alert_cat)
 {
+    ble_svc_ans_new_alert_cat = initial_new_alert_cat;
+    ble_svc_ans_unr_alert_cat = initial_unr_alert_cat;
+
     int rc;
     rc = ble_gatts_count_cfg(ble_svc_ans_defs, cfg);
     if (rc != 0) {
@@ -347,3 +373,83 @@ ble_svc_ans_init(struct ble_hs_cfg *cfg)
     return 0;
 }
 
+/**
+ * Send a new alert notification to the given category with the 
+ * given info string.
+ *
+ * @param cat_id                The ID of the category to send the 
+ *                                  notification to.
+ * @param info_str              The info string to send with the 
+ *                                  notification
+ *
+ * @return 0 if success, non-zero if error.
+ */
+static int
+ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str)
+{
+    /* Clear notification to remove old infomation that may persist */
+    memset(&ble_svc_ans_new_alert_val, '\0', 
+           BLE_SVC_ANS_NEW_ALERT_MAX_LEN); 
+    
+    /* Set ID and count values */
+    ble_svc_ans_new_alert_val[0] = cat_id;
+    ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_id];
+    
+    if (info_str) {
+        int n = strlen(info_str);
+        if (n > BLE_SVC_ANS_INFO_STR_MAX_LEN) {
+            /* If info_str is longer than the max string length only 
+             * write up to the maximum length */
+            memcpy(&ble_svc_ans_new_alert_val[2], info_str, 
+                   BLE_SVC_ANS_INFO_STR_MAX_LEN);
+        } else {
+            memcpy(&ble_svc_ans_new_alert_val[2], info_str, n);
+        }
+    }
+    int rc = ble_gattc_notify(ble_svc_ans_conn_handle, 
+                              ble_svc_ans_new_alert_val_handle);
+    return rc;
+}
+
+/**
+ * Send an unread alert notification to the given category.
+ *
+ * @param cat_id                The ID of the category to send the
+ *                                  notificaiton to.
+ *
+ * @return 0 if success, non-zero if error.
+ */
+static int
+ble_svc_ans_unr_alert_notify(uint8_t cat_id)
+{
+    ble_svc_ans_unr_alert_stat[0] = cat_id;
+    ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_id];
+    int rc = ble_gattc_notify(ble_svc_ans_conn_handle, 
+                              ble_svc_ans_unr_alert_val_handle);
+    return rc;
+}
+
+/**
+ * Writes the received value from a characteristic write to 
+ * the given destination.
+ */
+static int
+ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
+                      uint16_t max_len, void *dst,
+                      uint16_t *len)
+{
+    uint16_t om_len;
+    int rc;
+
+    om_len = OS_MBUF_PKTLEN(om);
+    if (om_len < min_len || om_len > max_len) {
+        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    }
+
+    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
+    if (rc != 0) {
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+
+    return 0;
+}


[12/22] incubator-mynewt-core git commit: moved location to services from profiles

Posted by cc...@apache.org.
moved location to services from profiles


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/64b1cd98
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/64b1cd98
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/64b1cd98

Branch: refs/heads/develop
Commit: 64b1cd986c864006dc8e644a0e94788302157adc
Parents: 3440607
Author: Brian Giori <br...@gmail.com>
Authored: Mon Aug 1 17:11:54 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Mon Aug 1 17:11:54 2016 -0700

----------------------------------------------------------------------
 .../ans/include/profiles/ans/ble_svc_ans.h      |  87 ----
 net/nimble/host/profiles/ans/pkg.yml            |  31 --
 net/nimble/host/profiles/ans/src/ble_svc_ans.c  | 467 -------------------
 .../ans/include/profiles/ans/ble_svc_ans.h      |  87 ++++
 net/nimble/host/services/ans/pkg.yml            |  31 ++
 net/nimble/host/services/ans/src/ble_svc_ans.c  | 467 +++++++++++++++++++
 6 files changed, 585 insertions(+), 585 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64b1cd98/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h b/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
deleted file mode 100644
index eaf102a..0000000
--- a/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * 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.
- */
-
-#ifndef H_BLE_SVC_ANS_
-#define H_BLE_SVC_ANS_
-
-struct ble_hs_cfg;
-
-/* 16 Bit Alert Notification Service UUID */
-#define BLE_SVC_ANS_UUID16                                  0x1811
-
-/* 16 Bit Alert Notification Servivce Characteristic UUIDs */
-#define BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT            0x2a47
-#define BLE_SVC_ANS_CHR_UUID16_NEW_ALERT                    0x2a46
-#define BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT            0x2a48
-#define BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT               0x2a45
-#define BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT            0x2a44
-
-/* Alert Notification Service Category ID Bit Masks 
- *
- * TODO: Add remaining 2 optional categories */
-#define BLE_SVC_ANS_CAT_BM_NONE                             0x00
-#define BLE_SVC_ANS_CAT_BM_SIMPLE_ALERT                     0x01
-#define BLE_SVC_ANS_CAT_BM_EMAIL                            0x02
-#define BLE_SVC_ANS_CAT_BM_NEWS                             0x04
-#define BLE_SVC_ANS_CAT_BM_CALL                             0x08
-#define BLE_SVC_ANS_CAT_BM_MISSED_CALL                      0x10
-#define BLE_SVC_ANS_CAT_BM_SMS                              0x20
-#define BLE_SVC_ANS_CAT_BM_VOICE_MAIL                       0x40
-#define BLE_SVC_ANS_CAT_BM_SCHEDULE                         0x80    
-
-/* Alert Notification Service Category IDs
- *
- * TODO: Add remaining 2 optional categories */
-#define BLE_SVC_ANS_CAT_ID_SIMPLE_ALERT                     0
-#define BLE_SVC_ANS_CAT_ID_EMAIL                            1
-#define BLE_SVC_ANS_CAT_ID_NEWS                             2
-#define BLE_SVC_ANS_CAT_ID_CALL                             3
-#define BLE_SVC_ANS_CAT_ID_MISSED_CALL                      4
-#define BLE_SVC_ANS_CAT_ID_SMS                              5
-#define BLE_SVC_ANS_CAT_ID_VOICE_MAIL                       6
-#define BLE_SVC_ANS_CAT_ID_SCHEDULE                         7
-
-/* Number of valid ANS categories 
- *
- * TODO: Add remaining 2 optional categories */
-#define BLE_SVC_ANS_CAT_NUM                                 8
-
-/* Alert Notification Control Point Command IDs */
-#define BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT                    0
-#define BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT                    1
-#define BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT                   2
-#define BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT                   3
-#define BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE             4
-#define BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE             5
-
-/* Error Defeinitions */
-#define BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED                   0xA0
-
-void ble_svc_ans_on_gap_connect(uint16_t conn_handle);
-
-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);
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64b1cd98/net/nimble/host/profiles/ans/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/pkg.yml b/net/nimble/host/profiles/ans/pkg.yml
deleted file mode 100644
index 4cff8fd..0000000
--- a/net/nimble/host/profiles/ans/pkg.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# 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.
-#
-
-pkg.name: net/nimble/host/profiles/ans
-pkg.description: Alert Notification Service Server.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - ble 
-    - bluetooth
-    - ans 
-    - nimble 
-
-pkg.deps:
-    - net/nimble/host

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64b1cd98/net/nimble/host/profiles/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/src/ble_svc_ans.c b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
deleted file mode 100644
index 2cebd8b..0000000
--- a/net/nimble/host/profiles/ans/src/ble_svc_ans.c
+++ /dev/null
@@ -1,467 +0,0 @@
-/**
- * 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.
- */
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-#include "host/ble_hs.h"
-#include "host/ble_gap.h"
-#include "profiles/ans/ble_svc_ans.h"
-
-
-/* Max length of new alert info string */
-#define BLE_SVC_ANS_INFO_STR_MAX_LEN        18
-/* Max length of a new alert notification, max string length + 2 bytes
- * for category ID and count. */
-#define BLE_SVC_ANS_NEW_ALERT_MAX_LEN   (BLE_SVC_ANS_INFO_STR_MAX_LEN + 2)
-
-/* Supported categories bitmasks */
-static uint8_t ble_svc_ans_new_alert_cat;
-static uint8_t ble_svc_ans_unr_alert_cat; 
-
-/* Characteristic values */
-static uint8_t ble_svc_ans_new_alert_val[BLE_SVC_ANS_NEW_ALERT_MAX_LEN];
-static uint16_t ble_svc_ans_new_alert_val_len;
-static uint8_t ble_svc_ans_unr_alert_stat[2];
-static uint8_t ble_svc_ans_alert_not_ctrl_pt[2];
-
-/* Alert counts, one value for each category */
-static uint8_t ble_svc_ans_new_alert_cnt[BLE_SVC_ANS_CAT_NUM];
-static uint8_t ble_svc_ans_unr_alert_cnt[BLE_SVC_ANS_CAT_NUM];
-
-/* Charachteristic value handles */
-static uint16_t ble_svc_ans_new_alert_val_handle;
-static uint16_t ble_svc_ans_unr_alert_val_handle;
-
-/* Connection handle 
- *
- * TODO: In order to support multiple connections we would need to save
- *       the handles for every connection, not just the most recent. Then
- *       we would need to notify each connection when needed.
- * */
-static uint16_t ble_svc_ans_conn_handle;
-
-/* Access function */
-static int
-ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
-                   struct ble_gatt_access_ctxt *ctxt, void *arg);
-
-/* Notify new alert */
-static int
-ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str);
-
-/* Notify unread alert */
-static int
-ble_svc_ans_unr_alert_notify(uint8_t cat_id);
-
-/* Save written value to local characteristic value */
-static int
-ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, 
-                      void *dst, uint16_t *len);
-
-static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
-    {
-        /*** Alert Notification Service. */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid128 = BLE_UUID16(BLE_SVC_ANS_UUID16),
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-            /** Supported New Alert Catagory 
-             * 
-             * This characteristic exposes what categories of new 
-             * alert are supported in the server.
-             */
-            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT),
-            .access_cb = ble_svc_ans_access,
-            .flags = BLE_GATT_CHR_F_READ,
-        }, {
-            /** New Alert 
-             *
-             * This characteristic exposes information about 
-             * the count of new alerts (for a given category).
-             */
-            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_NEW_ALERT),
-            .access_cb = ble_svc_ans_access,
-            .val_handle = &ble_svc_ans_new_alert_val_handle,
-            .flags = BLE_GATT_CHR_F_NOTIFY,
-        }, {
-            /** Supported Unread Alert Catagory 
-             *
-             * This characteristic exposes what categories of 
-             * unread alert are supported in the server.
-             */
-            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT),
-            .access_cb = ble_svc_ans_access,
-            .flags = BLE_GATT_CHR_F_READ,
-        }, {
-            /** Unread Alert Status 
-             *
-             * This characteristic exposes the count of unread 
-             * alert events existing in the server.
-             */
-            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT),
-            .access_cb = ble_svc_ans_access,
-            .val_handle = &ble_svc_ans_unr_alert_val_handle,
-            .flags = BLE_GATT_CHR_F_NOTIFY,
-        }, {
-            /** Alert Notification Control Point 
-             *
-             * This characteristic allows the peer device to 
-             * enable/disable the alert notification of new alert 
-             * and unread event more selectively than can be done 
-             * by setting or clearing the notification bit in the 
-             * Client Characteristic Configuration for each alert 
-             * characteristic.
-             */
-            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT),
-            .access_cb = ble_svc_ans_access,
-            .flags = BLE_GATT_CHR_F_WRITE,
-        }, {
-            0, /* No more characteristics in this service. */
-        } },
-    },
-
-    {
-        0, /* No more services. */
-    },
-};
-
-/**
- * ANS access function
- */
-static int
-ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
-                          struct ble_gatt_access_ctxt *ctxt,
-                          void *arg)
-{
-    uint16_t uuid16;
-    int rc;
-    
-    /* ANS Control point command and catagory variables */
-    uint8_t cmd_id;
-    uint8_t cat_id;
-    uint8_t cat_bit_mask; 
-    int i;
-
-    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
-    assert(uuid16 != 0);
-
-    switch (uuid16) {
-    case BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
-        rc = os_mbuf_append(ctxt->om, &ble_svc_ans_new_alert_cat,
-                            sizeof ble_svc_ans_new_alert_cat);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-    case BLE_SVC_ANS_CHR_UUID16_NEW_ALERT:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = ble_svc_ans_chr_write(ctxt->om, 0,
-                                       sizeof ble_svc_ans_new_alert_val,
-                                       ble_svc_ans_new_alert_val,
-                                       &ble_svc_ans_new_alert_val_len);
-            return rc;
-
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            rc = os_mbuf_append(ctxt->om, &ble_svc_ans_new_alert_val,
-                                sizeof ble_svc_ans_new_alert_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    case BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
-        rc = os_mbuf_append(ctxt->om, &ble_svc_ans_unr_alert_cat,
-                            sizeof ble_svc_ans_unr_alert_cat);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-    case BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = ble_svc_ans_chr_write(ctxt->om, 
-                                       sizeof ble_svc_ans_unr_alert_stat, 
-                                       sizeof ble_svc_ans_unr_alert_stat,
-                                       &ble_svc_ans_unr_alert_stat,
-                                       NULL);
-            return rc; 
-        } else {
-            rc = os_mbuf_append(ctxt->om, &ble_svc_ans_unr_alert_stat,
-                                sizeof ble_svc_ans_unr_alert_stat);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    case BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = ble_svc_ans_chr_write(ctxt->om, 
-                                       sizeof ble_svc_ans_alert_not_ctrl_pt, 
-                                       sizeof ble_svc_ans_alert_not_ctrl_pt,
-                                       &ble_svc_ans_alert_not_ctrl_pt,
-                                       NULL);
-
-            /* Get command ID and category ID */
-            cmd_id = ble_svc_ans_alert_not_ctrl_pt[0];
-            cat_id = ble_svc_ans_alert_not_ctrl_pt[1];
-
-            /* Set cat_bit_mask to the appropriate bitmask based on cat_id */
-            if (cat_id < BLE_SVC_ANS_CAT_NUM) {
-                cat_bit_mask = (1 << cat_id); 
-            } else if (cat_id == 0xff) { 
-                cat_bit_mask = cat_id;
-            } else {
-                cat_bit_mask = 0;
-            }
-
-            switch (cmd_id) {
-            case BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT:
-                ble_svc_ans_new_alert_cat |= cat_bit_mask; 
-                break;
-            case BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT:
-                ble_svc_ans_unr_alert_cat |= cat_bit_mask;
-                break;
-            case BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT:
-                ble_svc_ans_new_alert_cat &= ~cat_bit_mask;
-                break;
-            case BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT:
-                ble_svc_ans_unr_alert_cat &= ~cat_bit_mask;
-                break;
-            case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE:
-                if (cat_id == 0xff) {
-                    /* If cat_id is 0xff, notify on all enabled categories */
-                    for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
-                        if ((ble_svc_ans_new_alert_cat >> i) & 0x01) {
-                            ble_svc_ans_new_alert_notify(i, NULL);
-                        }
-                    }
-                } else {
-                    ble_svc_ans_new_alert_notify(cat_id, NULL);
-                }
-                break;
-            case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE:
-                if (cat_id == 0xff) {
-                    /* If cat_id is 0xff, notify on all enabled categories */
-                    for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
-                        if ((ble_svc_ans_unr_alert_cat >> i) & 0x01) {
-                            ble_svc_ans_unr_alert_notify(i);
-                        }
-                    }
-                } else {
-                    ble_svc_ans_unr_alert_notify(cat_id);
-                }
-                break;
-            default:
-                return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
-            }
-            return 0;
-        } else {
-            rc = BLE_ATT_ERR_UNLIKELY;
-        }
-        return rc;
-
-    default:
-        assert(0);
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-}
-
-/**
- * This function must be called with the connection handlewhen a gap 
- * connect event is received in order to send notifications to the
- * client.
- *
- * @params conn_handle          The connection handle for the current
- *                                  connection.
- */
-void 
-ble_svc_ans_on_gap_connect(uint16_t conn_handle) 
-{
-    ble_svc_ans_conn_handle = conn_handle;
-}
-
-/**
- * Adds a new alert to the given category then notifies the client
- * if the given category is valid and enabled.
- *
- * @param cat_flag              The id for the category which should
- *                                  should be incremented and notified
- * @param info_str              The info string to be sent to the client
- *                                  with the notification.
- * 
- * @return 0 on success, non-zero error code otherwise. 
- */
-int
-ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
-{
-    uint8_t cat_bit_mask; 
-    
-    if (cat_id < BLE_SVC_ANS_CAT_NUM) {
-        cat_bit_mask = (1 << cat_id); 
-    } else {
-        return BLE_HS_EINVAL;
-    }
-
-    if ((cat_bit_mask & ble_svc_ans_new_alert_cat) == 0) {
-        return BLE_HS_EINVAL;
-    }
-
-    ble_svc_ans_new_alert_cnt[cat_id] += 1;
-    return ble_svc_ans_new_alert_notify(cat_id, info_str);
-}
-
-/**
- * Adds an unread alert to the given category then notifies the client
- * if the given category is valid and enabled.
- * 
- * @param cat_flag              The flag for the category which should
- *                                  should be incremented and notified
- * 
- * @return 0 on success, non-zero error code otherwise. 
- */
-int
-ble_svc_ans_unr_alert_add(uint8_t cat_id)
-{
-    uint8_t cat_bit_mask; 
-    
-    if (cat_id < BLE_SVC_ANS_CAT_NUM) {
-        cat_bit_mask = pow(2, cat_id);
-    } else {
-        return BLE_HS_EINVAL;
-    }
-
-    if ((cat_bit_mask & ble_svc_ans_unr_alert_cat) == 0) {
-        return BLE_HS_EINVAL;
-    }
-
-    ble_svc_ans_unr_alert_cnt[cat_id] += 1;
-    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.
- *
- * @param cat_id                The ID of the category to send the 
- *                                  notification to.
- * @param info_str              The info string to send with the 
- *                                  notification
- *
- * @return 0 on success, non-zero error code otherwise.
- */
-static int
-ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str)
-{
-    int info_str_len;
-
-    /* Clear notification to remove old infomation that may persist */
-    memset(&ble_svc_ans_new_alert_val, '\0', 
-           BLE_SVC_ANS_NEW_ALERT_MAX_LEN); 
-    
-    /* Set ID and count values */
-    ble_svc_ans_new_alert_val[0] = cat_id;
-    ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_id];
-    
-    if (info_str) {
-        info_str_len = strlen(info_str);
-        if (info_str_len > BLE_SVC_ANS_INFO_STR_MAX_LEN) {
-            /* If info_str is longer than the max string length only 
-             * write up to the maximum length */
-            memcpy(&ble_svc_ans_new_alert_val[2], info_str, 
-                   BLE_SVC_ANS_INFO_STR_MAX_LEN);
-        } else {
-            memcpy(&ble_svc_ans_new_alert_val[2], info_str, info_str_len);
-        }
-    }
-    return ble_gattc_notify(ble_svc_ans_conn_handle, 
-                            ble_svc_ans_new_alert_val_handle);
-}
-
-/**
- * Send an unread alert notification to the given category.
- *
- * @param cat_id                The ID of the category to send the
- *                                  notificaiton to.
- *
- * @return 0 on success, non-zer0 error code otherwise.
- */
-static int
-ble_svc_ans_unr_alert_notify(uint8_t cat_id)
-{
-    ble_svc_ans_unr_alert_stat[0] = cat_id;
-    ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_id];
-    return ble_gattc_notify(ble_svc_ans_conn_handle, 
-                            ble_svc_ans_unr_alert_val_handle);
-}
-
-/**
- * Writes the received value from a characteristic write to 
- * the given destination.
- */
-static int
-ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
-                      uint16_t max_len, void *dst,
-                      uint16_t *len)
-{
-    uint16_t om_len;
-    int rc;
-
-    om_len = OS_MBUF_PKTLEN(om);
-    if (om_len < min_len || om_len > max_len) {
-        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
-    }
-
-    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
-    if (rc != 0) {
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-
-    return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64b1cd98/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h b/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h
new file mode 100644
index 0000000..eaf102a
--- /dev/null
+++ b/net/nimble/host/services/ans/include/profiles/ans/ble_svc_ans.h
@@ -0,0 +1,87 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_SVC_ANS_
+#define H_BLE_SVC_ANS_
+
+struct ble_hs_cfg;
+
+/* 16 Bit Alert Notification Service UUID */
+#define BLE_SVC_ANS_UUID16                                  0x1811
+
+/* 16 Bit Alert Notification Servivce Characteristic UUIDs */
+#define BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT            0x2a47
+#define BLE_SVC_ANS_CHR_UUID16_NEW_ALERT                    0x2a46
+#define BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT            0x2a48
+#define BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT               0x2a45
+#define BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT            0x2a44
+
+/* Alert Notification Service Category ID Bit Masks 
+ *
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_BM_NONE                             0x00
+#define BLE_SVC_ANS_CAT_BM_SIMPLE_ALERT                     0x01
+#define BLE_SVC_ANS_CAT_BM_EMAIL                            0x02
+#define BLE_SVC_ANS_CAT_BM_NEWS                             0x04
+#define BLE_SVC_ANS_CAT_BM_CALL                             0x08
+#define BLE_SVC_ANS_CAT_BM_MISSED_CALL                      0x10
+#define BLE_SVC_ANS_CAT_BM_SMS                              0x20
+#define BLE_SVC_ANS_CAT_BM_VOICE_MAIL                       0x40
+#define BLE_SVC_ANS_CAT_BM_SCHEDULE                         0x80    
+
+/* Alert Notification Service Category IDs
+ *
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_ID_SIMPLE_ALERT                     0
+#define BLE_SVC_ANS_CAT_ID_EMAIL                            1
+#define BLE_SVC_ANS_CAT_ID_NEWS                             2
+#define BLE_SVC_ANS_CAT_ID_CALL                             3
+#define BLE_SVC_ANS_CAT_ID_MISSED_CALL                      4
+#define BLE_SVC_ANS_CAT_ID_SMS                              5
+#define BLE_SVC_ANS_CAT_ID_VOICE_MAIL                       6
+#define BLE_SVC_ANS_CAT_ID_SCHEDULE                         7
+
+/* Number of valid ANS categories 
+ *
+ * TODO: Add remaining 2 optional categories */
+#define BLE_SVC_ANS_CAT_NUM                                 8
+
+/* Alert Notification Control Point Command IDs */
+#define BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT                    0
+#define BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT                    1
+#define BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT                   2
+#define BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT                   3
+#define BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE             4
+#define BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE             5
+
+/* Error Defeinitions */
+#define BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED                   0xA0
+
+void ble_svc_ans_on_gap_connect(uint16_t conn_handle);
+
+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);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64b1cd98/net/nimble/host/services/ans/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/pkg.yml b/net/nimble/host/services/ans/pkg.yml
new file mode 100644
index 0000000..91a92c6
--- /dev/null
+++ b/net/nimble/host/services/ans/pkg.yml
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+
+pkg.name: net/nimble/host/services/ans
+pkg.description: Alert Notification Service Server.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble 
+    - bluetooth
+    - ans 
+    - nimble 
+
+pkg.deps:
+    - net/nimble/host

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64b1cd98/net/nimble/host/services/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/src/ble_svc_ans.c b/net/nimble/host/services/ans/src/ble_svc_ans.c
new file mode 100644
index 0000000..eae4598
--- /dev/null
+++ b/net/nimble/host/services/ans/src/ble_svc_ans.c
@@ -0,0 +1,467 @@
+/**
+ * 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.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+#include "host/ble_hs.h"
+#include "host/ble_gap.h"
+#include "services/ans/ble_svc_ans.h"
+
+
+/* Max length of new alert info string */
+#define BLE_SVC_ANS_INFO_STR_MAX_LEN        18
+/* Max length of a new alert notification, max string length + 2 bytes
+ * for category ID and count. */
+#define BLE_SVC_ANS_NEW_ALERT_MAX_LEN   (BLE_SVC_ANS_INFO_STR_MAX_LEN + 2)
+
+/* Supported categories bitmasks */
+static uint8_t ble_svc_ans_new_alert_cat;
+static uint8_t ble_svc_ans_unr_alert_cat; 
+
+/* Characteristic values */
+static uint8_t ble_svc_ans_new_alert_val[BLE_SVC_ANS_NEW_ALERT_MAX_LEN];
+static uint16_t ble_svc_ans_new_alert_val_len;
+static uint8_t ble_svc_ans_unr_alert_stat[2];
+static uint8_t ble_svc_ans_alert_not_ctrl_pt[2];
+
+/* Alert counts, one value for each category */
+static uint8_t ble_svc_ans_new_alert_cnt[BLE_SVC_ANS_CAT_NUM];
+static uint8_t ble_svc_ans_unr_alert_cnt[BLE_SVC_ANS_CAT_NUM];
+
+/* Charachteristic value handles */
+static uint16_t ble_svc_ans_new_alert_val_handle;
+static uint16_t ble_svc_ans_unr_alert_val_handle;
+
+/* Connection handle 
+ *
+ * TODO: In order to support multiple connections we would need to save
+ *       the handles for every connection, not just the most recent. Then
+ *       we would need to notify each connection when needed.
+ * */
+static uint16_t ble_svc_ans_conn_handle;
+
+/* Access function */
+static int
+ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+/* Notify new alert */
+static int
+ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str);
+
+/* Notify unread alert */
+static int
+ble_svc_ans_unr_alert_notify(uint8_t cat_id);
+
+/* Save written value to local characteristic value */
+static int
+ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, 
+                      void *dst, uint16_t *len);
+
+static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
+    {
+        /*** Alert Notification Service. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_SVC_ANS_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /** Supported New Alert Catagory 
+             * 
+             * This characteristic exposes what categories of new 
+             * alert are supported in the server.
+             */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /** New Alert 
+             *
+             * This characteristic exposes information about 
+             * the count of new alerts (for a given category).
+             */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_NEW_ALERT),
+            .access_cb = ble_svc_ans_access,
+            .val_handle = &ble_svc_ans_new_alert_val_handle,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            /** Supported Unread Alert Catagory 
+             *
+             * This characteristic exposes what categories of 
+             * unread alert are supported in the server.
+             */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /** Unread Alert Status 
+             *
+             * This characteristic exposes the count of unread 
+             * alert events existing in the server.
+             */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT),
+            .access_cb = ble_svc_ans_access,
+            .val_handle = &ble_svc_ans_unr_alert_val_handle,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            /** Alert Notification Control Point 
+             *
+             * This characteristic allows the peer device to 
+             * enable/disable the alert notification of new alert 
+             * and unread event more selectively than can be done 
+             * by setting or clearing the notification bit in the 
+             * Client Characteristic Configuration for each alert 
+             * characteristic.
+             */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_WRITE,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+/**
+ * ANS access function
+ */
+static int
+ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
+                          struct ble_gatt_access_ctxt *ctxt,
+                          void *arg)
+{
+    uint16_t uuid16;
+    int rc;
+    
+    /* ANS Control point command and catagory variables */
+    uint8_t cmd_id;
+    uint8_t cat_id;
+    uint8_t cat_bit_mask; 
+    int i;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT:
+        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+        rc = os_mbuf_append(ctxt->om, &ble_svc_ans_new_alert_cat,
+                            sizeof ble_svc_ans_new_alert_cat);
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    case BLE_SVC_ANS_CHR_UUID16_NEW_ALERT:
+        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = ble_svc_ans_chr_write(ctxt->om, 0,
+                                       sizeof ble_svc_ans_new_alert_val,
+                                       ble_svc_ans_new_alert_val,
+                                       &ble_svc_ans_new_alert_val_len);
+            return rc;
+
+        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+            rc = os_mbuf_append(ctxt->om, &ble_svc_ans_new_alert_val,
+                                sizeof ble_svc_ans_new_alert_val);
+            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+        }
+
+    case BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT:
+        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+        rc = os_mbuf_append(ctxt->om, &ble_svc_ans_unr_alert_cat,
+                            sizeof ble_svc_ans_unr_alert_cat);
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    case BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT:
+        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = ble_svc_ans_chr_write(ctxt->om, 
+                                       sizeof ble_svc_ans_unr_alert_stat, 
+                                       sizeof ble_svc_ans_unr_alert_stat,
+                                       &ble_svc_ans_unr_alert_stat,
+                                       NULL);
+            return rc; 
+        } else {
+            rc = os_mbuf_append(ctxt->om, &ble_svc_ans_unr_alert_stat,
+                                sizeof ble_svc_ans_unr_alert_stat);
+            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+        }
+
+    case BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT:
+        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = ble_svc_ans_chr_write(ctxt->om, 
+                                       sizeof ble_svc_ans_alert_not_ctrl_pt, 
+                                       sizeof ble_svc_ans_alert_not_ctrl_pt,
+                                       &ble_svc_ans_alert_not_ctrl_pt,
+                                       NULL);
+
+            /* Get command ID and category ID */
+            cmd_id = ble_svc_ans_alert_not_ctrl_pt[0];
+            cat_id = ble_svc_ans_alert_not_ctrl_pt[1];
+
+            /* Set cat_bit_mask to the appropriate bitmask based on cat_id */
+            if (cat_id < BLE_SVC_ANS_CAT_NUM) {
+                cat_bit_mask = (1 << cat_id); 
+            } else if (cat_id == 0xff) { 
+                cat_bit_mask = cat_id;
+            } else {
+                cat_bit_mask = 0;
+            }
+
+            switch (cmd_id) {
+            case BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT:
+                ble_svc_ans_new_alert_cat |= cat_bit_mask; 
+                break;
+            case BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT:
+                ble_svc_ans_unr_alert_cat |= cat_bit_mask;
+                break;
+            case BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT:
+                ble_svc_ans_new_alert_cat &= ~cat_bit_mask;
+                break;
+            case BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT:
+                ble_svc_ans_unr_alert_cat &= ~cat_bit_mask;
+                break;
+            case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE:
+                if (cat_id == 0xff) {
+                    /* If cat_id is 0xff, notify on all enabled categories */
+                    for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
+                        if ((ble_svc_ans_new_alert_cat >> i) & 0x01) {
+                            ble_svc_ans_new_alert_notify(i, NULL);
+                        }
+                    }
+                } else {
+                    ble_svc_ans_new_alert_notify(cat_id, NULL);
+                }
+                break;
+            case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE:
+                if (cat_id == 0xff) {
+                    /* If cat_id is 0xff, notify on all enabled categories */
+                    for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
+                        if ((ble_svc_ans_unr_alert_cat >> i) & 0x01) {
+                            ble_svc_ans_unr_alert_notify(i);
+                        }
+                    }
+                } else {
+                    ble_svc_ans_unr_alert_notify(cat_id);
+                }
+                break;
+            default:
+                return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
+            }
+            return 0;
+        } else {
+            rc = BLE_ATT_ERR_UNLIKELY;
+        }
+        return rc;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+}
+
+/**
+ * This function must be called with the connection handlewhen a gap 
+ * connect event is received in order to send notifications to the
+ * client.
+ *
+ * @params conn_handle          The connection handle for the current
+ *                                  connection.
+ */
+void 
+ble_svc_ans_on_gap_connect(uint16_t conn_handle) 
+{
+    ble_svc_ans_conn_handle = conn_handle;
+}
+
+/**
+ * Adds a new alert to the given category then notifies the client
+ * if the given category is valid and enabled.
+ *
+ * @param cat_flag              The id for the category which should
+ *                                  should be incremented and notified
+ * @param info_str              The info string to be sent to the client
+ *                                  with the notification.
+ * 
+ * @return 0 on success, non-zero error code otherwise. 
+ */
+int
+ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
+{
+    uint8_t cat_bit_mask; 
+    
+    if (cat_id < BLE_SVC_ANS_CAT_NUM) {
+        cat_bit_mask = (1 << cat_id); 
+    } else {
+        return BLE_HS_EINVAL;
+    }
+
+    if ((cat_bit_mask & ble_svc_ans_new_alert_cat) == 0) {
+        return BLE_HS_EINVAL;
+    }
+
+    ble_svc_ans_new_alert_cnt[cat_id] += 1;
+    return ble_svc_ans_new_alert_notify(cat_id, info_str);
+}
+
+/**
+ * Adds an unread alert to the given category then notifies the client
+ * if the given category is valid and enabled.
+ * 
+ * @param cat_flag              The flag for the category which should
+ *                                  should be incremented and notified
+ * 
+ * @return 0 on success, non-zero error code otherwise. 
+ */
+int
+ble_svc_ans_unr_alert_add(uint8_t cat_id)
+{
+    uint8_t cat_bit_mask; 
+    
+    if (cat_id < BLE_SVC_ANS_CAT_NUM) {
+        cat_bit_mask = pow(2, cat_id);
+    } else {
+        return BLE_HS_EINVAL;
+    }
+
+    if ((cat_bit_mask & ble_svc_ans_unr_alert_cat) == 0) {
+        return BLE_HS_EINVAL;
+    }
+
+    ble_svc_ans_unr_alert_cnt[cat_id] += 1;
+    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.
+ *
+ * @param cat_id                The ID of the category to send the 
+ *                                  notification to.
+ * @param info_str              The info string to send with the 
+ *                                  notification
+ *
+ * @return 0 on success, non-zero error code otherwise.
+ */
+static int
+ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str)
+{
+    int info_str_len;
+
+    /* Clear notification to remove old infomation that may persist */
+    memset(&ble_svc_ans_new_alert_val, '\0', 
+           BLE_SVC_ANS_NEW_ALERT_MAX_LEN); 
+    
+    /* Set ID and count values */
+    ble_svc_ans_new_alert_val[0] = cat_id;
+    ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_id];
+    
+    if (info_str) {
+        info_str_len = strlen(info_str);
+        if (info_str_len > BLE_SVC_ANS_INFO_STR_MAX_LEN) {
+            /* If info_str is longer than the max string length only 
+             * write up to the maximum length */
+            memcpy(&ble_svc_ans_new_alert_val[2], info_str, 
+                   BLE_SVC_ANS_INFO_STR_MAX_LEN);
+        } else {
+            memcpy(&ble_svc_ans_new_alert_val[2], info_str, info_str_len);
+        }
+    }
+    return ble_gattc_notify(ble_svc_ans_conn_handle, 
+                            ble_svc_ans_new_alert_val_handle);
+}
+
+/**
+ * Send an unread alert notification to the given category.
+ *
+ * @param cat_id                The ID of the category to send the
+ *                                  notificaiton to.
+ *
+ * @return 0 on success, non-zer0 error code otherwise.
+ */
+static int
+ble_svc_ans_unr_alert_notify(uint8_t cat_id)
+{
+    ble_svc_ans_unr_alert_stat[0] = cat_id;
+    ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_id];
+    return ble_gattc_notify(ble_svc_ans_conn_handle, 
+                            ble_svc_ans_unr_alert_val_handle);
+}
+
+/**
+ * Writes the received value from a characteristic write to 
+ * the given destination.
+ */
+static int
+ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
+                      uint16_t max_len, void *dst,
+                      uint16_t *len)
+{
+    uint16_t om_len;
+    int rc;
+
+    om_len = OS_MBUF_PKTLEN(om);
+    if (om_len < min_len || om_len > max_len) {
+        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    }
+
+    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
+    if (rc != 0) {
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+
+    return 0;
+}



[22/22] incubator-mynewt-core git commit: BLE TPS service - Use latest host API.

Posted by cc...@apache.org.
BLE TPS service - Use latest host API.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/524af89e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/524af89e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/524af89e

Branch: refs/heads/develop
Commit: 524af89eee7c166e451eb4f923ffc3d533ad8d12
Parents: 58d6bcd
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:53:40 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:53:40 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/services/tps/src/ble_svc_tps.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/524af89e/net/nimble/host/services/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/src/ble_svc_tps.c b/net/nimble/host/services/tps/src/ble_svc_tps.c
index 2351a79..6987a5d 100644
--- a/net/nimble/host/services/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/services/tps/src/ble_svc_tps.c
@@ -19,9 +19,17 @@
 
 #include <assert.h>
 #include <string.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
 #include "host/ble_hs.h"
 #include "services/tps/ble_svc_tps.h"
 
+/* XXX: We shouldn't be including the host's private header files.  The host
+ * API needs to be updated with a function to query the advertising transmit
+ * power.
+ */
+#include "../src/ble_hs_hci_priv.h"
+
 int8_t ble_svc_tps_tx_power_level;
 
 /* Access function */
@@ -63,7 +71,11 @@ ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
     
     switch (ctxt->op) {
     case BLE_GATT_ACCESS_OP_READ_CHR:
-        ble_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);
+        rc = ble_hs_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);
+        if (rc != 0) {
+            return BLE_ATT_ERR_UNLIKELY;
+        }
+
         rc = os_mbuf_append(ctxt->om, &ble_svc_tps_tx_power_level,
                             sizeof ble_svc_tps_tx_power_level);
         return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
@@ -84,7 +96,7 @@ ble_svc_tps_init(void)
 {
     int rc;
 
-    rc = ble_gatts_count_cfg(ble_svc_tps_defs, cfg);
+    rc = ble_gatts_count_cfg(ble_svc_tps_defs);
     SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gatts_add_svcs(ble_svc_tps_defs);


[06/22] incubator-mynewt-core git commit: coding style changes

Posted by cc...@apache.org.
coding style changes


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/98caf9f2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/98caf9f2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/98caf9f2

Branch: refs/heads/develop
Commit: 98caf9f298499df9571c7ad96bcccbd75586f1e0
Parents: d0b6d35
Author: Brian Giori <br...@gmail.com>
Authored: Thu Jul 28 14:33:34 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Thu Jul 28 14:33:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/profiles/tps/src/ble_svc_tps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98caf9f2/net/nimble/host/profiles/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/src/ble_svc_tps.c b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
index 3e2bf42..e354eec 100644
--- a/net/nimble/host/profiles/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
@@ -60,7 +60,7 @@ ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
 {
     assert(ctxt->chr == &ble_svc_tps_defs[0].characteristics[0]);
     int rc;
-    switch(ctxt->op) {
+    switch (ctxt->op) {
     case BLE_GATT_ACCESS_OP_READ_CHR:
         ble_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);
         rc = os_mbuf_append(ctxt->om, &ble_svc_tps_tx_power_level,


[05/22] incubator-mynewt-core git commit: fixed compilation errors and runs. Untested. Unfinished.

Posted by cc...@apache.org.
fixed compilation errors and runs. Untested. Unfinished.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c41f7f39
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c41f7f39
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c41f7f39

Branch: refs/heads/develop
Commit: c41f7f39bad22610aec5e01b8ace709504aef4a0
Parents: 2aba760
Author: Brian Giori <br...@gmail.com>
Authored: Thu Jul 28 13:46:04 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Thu Jul 28 13:46:04 2016 -0700

----------------------------------------------------------------------
 .../ans/include/profiles/ans/ble_svc_ans.h      | 35 +++----
 net/nimble/host/profiles/ans/pkg.yml            | 31 +++++++
 net/nimble/host/profiles/ans/src/ble_svc_ans.c  | 96 ++++++++------------
 3 files changed, 88 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c41f7f39/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h b/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
index 4cbf6fd..c37c977 100644
--- a/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
+++ b/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
@@ -47,14 +47,14 @@ struct ble_hs_cfg;
 /* Alert Notification Service Category IDs
  *
  * TODO: Need to add remaining 2 categories */
-#define BLE_SVC_ANS_CAT_SIMPLE_ALERT                        0x1
-#define BLE_SVC_ANS_CAT_EMAIL                               0x2
-#define BLE_SVC_ANS_CAT_NEWS                                0x3
-#define BLE_SVC_ANS_CAT_CALL                                0x4
-#define BLE_SVC_ANS_CAT_MISSED_CALL                         0x5
-#define BLE_SVC_ANS_CAT_SMS                                 0x6
-#define BLE_SVC_ANS_CAT_VOICE_MAIL                          0x7
-#define BLE_SVC_ANS_CAT_SCHEDULE                            0x8
+#define BLE_SVC_ANS_CAT_SIMPLE_ALERT                        0
+#define BLE_SVC_ANS_CAT_EMAIL                               1
+#define BLE_SVC_ANS_CAT_NEWS                                2
+#define BLE_SVC_ANS_CAT_CALL                                3
+#define BLE_SVC_ANS_CAT_MISSED_CALL                         4
+#define BLE_SVC_ANS_CAT_SMS                                 5
+#define BLE_SVC_ANS_CAT_VOICE_MAIL                          6
+#define BLE_SVC_ANS_CAT_SCHEDULE                            7
 
 /* Number of valid ANS categories 
  *
@@ -66,16 +66,19 @@ struct ble_hs_cfg;
 #define BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT                    1
 #define BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT                   2
 #define BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT                   3
-#define BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEADIATE            4
-#define BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEADIATE            5
+#define BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE             4
+#define BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE             5
 
-int ble_svc_ans_new_alert_add(uint8_t category_flag, 
-                              char * info_str);
-int ble_svc_ans_unr_alert_add(uint8_t category_flag);
+/* Error Defeinitions */
+#define BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED                   0xA0
 
-int ble_svc_ans_init(struct ble_hs_cfg *cfg, 
-                     uint8_t new_alert_cat,
-                     uint8_t urn_alert_cat);
+#define BLE_SVC_ANS_INFO_STR_MAX_LEN                        18
+
+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);
 
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c41f7f39/net/nimble/host/profiles/ans/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/pkg.yml b/net/nimble/host/profiles/ans/pkg.yml
new file mode 100644
index 0000000..4cff8fd
--- /dev/null
+++ b/net/nimble/host/profiles/ans/pkg.yml
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+
+pkg.name: net/nimble/host/profiles/ans
+pkg.description: Alert Notification Service Server.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble 
+    - bluetooth
+    - ans 
+    - nimble 
+
+pkg.deps:
+    - net/nimble/host

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c41f7f39/net/nimble/host/profiles/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/src/ble_svc_ans.c b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
index a9e259c..4379cf5 100644
--- a/net/nimble/host/profiles/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
@@ -21,7 +21,7 @@
 #include <string.h>
 #include <math.h>
 #include "host/ble_hs.h"
-#include "profiles/ble_svc_ans.h"
+#include "profiles/ans/ble_svc_ans.h"
 
 /* Access function */
 static int
@@ -125,7 +125,7 @@ ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
 #define GATT_SVR_NEW_ALERT_VAL_MAX_LEN   20 
 
 /* Supported new alert categories bitmask */
-static const uint8_t ble_svc_ans_new_alert_cat;
+static uint8_t ble_svc_ans_new_alert_cat;
 /* New alert value */
 static uint8_t ble_svc_ans_new_alert_val[GATT_SVR_NEW_ALERT_VAL_MAX_LEN];
 static uint16_t ble_svc_ans_new_alert_val_len;
@@ -133,7 +133,7 @@ static uint16_t ble_svc_ans_new_alert_val_len;
 static uint8_t ble_svc_ans_new_alert_cnt[BLE_SVC_ANS_CAT_NUM];
 
 /* Supported unread alert catagories bitmask */ 
-static const uint8_t ble_svc_ans_unr_alert_cat; 
+static uint8_t ble_svc_ans_unr_alert_cat; 
 /* Unread alert status, contains supported catagories and count */
 static uint8_t ble_svc_ans_unr_alert_stat[2];
 /* Count of unread alerts. One value for each category */
@@ -143,7 +143,7 @@ static uint8_t ble_svc_ans_unr_alert_cnt[BLE_SVC_ANS_CAT_NUM];
 static uint8_t ble_svc_ans_alert_not_ctrl_pt[2];
 
 static int
-gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
+ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
                           struct ble_gatt_access_ctxt *ctxt,
                           void *arg)
 {
@@ -154,13 +154,13 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
     assert(uuid16 != 0);
 
     switch (uuid16) {
-    case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID:
+    case BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT:
         assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
         rc = os_mbuf_append(ctxt->om, &ble_svc_ans_new_alert_cat,
                             sizeof ble_svc_ans_new_alert_cat);
         return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
 
-    case GATT_SVR_CHR_NEW_ALERT:
+    case BLE_SVC_ANS_CHR_UUID16_NEW_ALERT:
         if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
             rc = ble_svc_ans_chr_write(ctxt->om, 0,
                                        sizeof ble_svc_ans_new_alert_val,
@@ -174,13 +174,13 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
             return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
         }
 
-    case GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID:
+    case BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT:
         assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
         rc = os_mbuf_append(ctxt->om, &ble_svc_ans_unr_alert_cat,
                             sizeof ble_svc_ans_unr_alert_cat);
         return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
 
-    case GATT_SVR_CHR_UNR_ALERT_STAT_UUID:
+    case BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT:
         if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
             rc = ble_svc_ans_chr_write(ctxt->om, 
                                        sizeof ble_svc_ans_unr_alert_stat, 
@@ -194,7 +194,7 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
             return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
         }
 
-    case GATT_SVR_CHR_ALERT_NOT_CTRL_PT:
+    case BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT:
         if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
             rc = ble_svc_ans_chr_write(ctxt->om, 
                                        sizeof ble_svc_ans_alert_not_ctrl_pt, 
@@ -211,7 +211,7 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
              * return error if the cat_id in an invalid range.
              */
             if (cat_id < BLE_SVC_ANS_CAT_NUM) {
-                cat = pow(2, cat_id);
+                cat = (1 << cat_id); 
             } else if (cat_id == 0xff) {
                 cat = cat_id;
             } else {
@@ -221,19 +221,19 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
             case BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT:
                 ble_svc_ans_new_alert_cat |= cat; 
                 break;
-            case BLE_SVC_ANS_CMD_EN_UNR_ALERT_STAT_CAT:
+            case BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT:
                 ble_svc_ans_unr_alert_cat |= cat;
                 break;
             case BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT:
                 ble_svc_ans_new_alert_cat &= ~cat;
                 break;
-            case BLE_SVC_ANS_CMD_DIS_UNR_ALERT_STAT_CAT:
+            case BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT:
                 ble_svc_ans_unr_alert_cat &= ~cat;
                 break;
             case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE:
                 /* TODO */
                 break;
-            case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_STAT_IMMEDIATE:
+            case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE:
                 /* TODO */
                 break;
             default:
@@ -251,14 +251,6 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
     }
 }
 
-/* Helper function to check if power of two to ensure valid flags. 
- */
-uint8_t 
-is_pow_of_two(uint8_t x)
-{
-  return ((x != 0) && ((x & (~x + 1)) == x));
-}
-
 /**
  * Adds a new alert to the given category then sets the new 
  * alert val to the category, the new alert count for the given 
@@ -274,29 +266,32 @@ is_pow_of_two(uint8_t x)
  *         or if the flag is not valid.
  */
 int
-ble_svc_ans_new_alert_add(uint8_t cat_flag, const char * info_str)
+ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
 {
-    if (cat_flag & ble_svc_ans_new_alert_cat == 0) {
+    uint8_t cat_bit_mask; 
+    if (cat_id < BLE_SVC_ANS_CAT_NUM) {
+        cat_bit_mask = (1 << cat_id); 
+    } else {
         return BLE_HS_EINVAL;
     }
 
-    uint8_t cat_idx; 
-    if (is_power_of_two(cat_flag)) {
-        cat_idx = log10(cat_flag)/log10(2);
-    } else {
+    if ((cat_bit_mask & ble_svc_ans_new_alert_cat) == 0) {
         return BLE_HS_EINVAL;
     }
 
-
-
-    ble_svc_ans_new_alert_cnt[cat_idx] += 1;
-    ble_svc_ans_new_alert_val[0] = category;
-    ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_idx];
-    memcpy(&ble_svc_ans_new_alert_val[2], info_str, sizeof(info_str));
+    ble_svc_ans_new_alert_cnt[cat_id] += 1;
+    ble_svc_ans_new_alert_val[0] = cat_id;
+    ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_id];
+    int n = sizeof info_str;
+    if (n > BLE_SVC_ANS_INFO_STR_MAX_LEN) {
+        memcpy(&ble_svc_ans_new_alert_val[2], info_str, 
+                BLE_SVC_ANS_INFO_STR_MAX_LEN);
+    } else {
+        memcpy(&ble_svc_ans_new_alert_val[2], info_str, n);
+    }
     return 0;
 }
 
-
 /**
  * Adds an unread alert to the given category then sets the unread
  * alert stat to the category and the new unread alert value for
@@ -312,47 +307,32 @@ ble_svc_ans_new_alert_add(uint8_t cat_flag, const char * info_str)
 int
 ble_svc_ans_unr_alert_add(uint8_t cat_id)
 {
-    uint8_t cat_flag; 
+    uint8_t cat_bit_mask; 
     if (cat_id < BLE_SVC_ANS_CAT_NUM) {
-        cat = pow(2, cat_id);
+        cat_bit_mask = pow(2, cat_id);
+    } else {
         return BLE_HS_EINVAL;
     }
 
-    /* Set cat to the appropriate bitmask based on cat_id or
-     * return error if the cat_id in an invalid range.
-     */
-    if (cat_id <= BLE_SVC_ANS_CMD_NOT_UNR_ALERT_STAT_IMMEDIATE) {
-    } else if (cat_id == 0xff) {
-        cat = cat_id;
-    } else {
-        return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
-    }
-    uint8_t cat_idx; 
-    if (is_power_of_two(cat_flag)) {
-        cat_idx = log10(cat_flag)/log10(2);
-    } else {
+    if ((cat_bit_mask & ble_svc_ans_unr_alert_cat) == 0) {
         return BLE_HS_EINVAL;
     }
 
-    ble_svc_ans_unr_alert_cnt[cat_idx] += 1;
-    ble_svc_ans_unr_alert_stat[0] = category;
-    ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_idx];
+    ble_svc_ans_unr_alert_cnt[cat_id] += 1;
+    ble_svc_ans_unr_alert_stat[0] = cat_id;
+    ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_id];
     return 0;
 }
 
 /**
- * Initialize the ANS with an initial .
+ * Initialize the ANS 
  * 
  * XXX: We should technically be able to change the new alert and
  *      unread alert catagories when we have no active connections.
  */
 int
-ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t new_alert_cat, 
-        uint8_t unr_alert_cat)
+ble_svc_ans_init(struct ble_hs_cfg *cfg)
 {
-    ble_svc_ans_new_alert_cat = new_alert_cat; 
-    ble_svc_ans_unr_alert_cat = unr_alert_cat;
-
     int rc;
     rc = ble_gatts_count_cfg(ble_svc_ans_defs, cfg);
     if (rc != 0) {


[20/22] incubator-mynewt-core git commit: This closes #84.

Posted by cc...@apache.org.
This closes #84.

Merge remote-tracking branch 'bgiori/feature-tps' into develop

* bgiori/feature-tps:
  moved tps to services dir.
  variables declared at top of function scope
  coding style changes
  updated comments and error return value
  Tx Power Service implementation
  added tx power service to profiles


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5663384b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5663384b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5663384b

Branch: refs/heads/develop
Commit: 5663384b2aebdb19c1f2da2d0052f5f5be893263
Parents: 32b0d33 df94f01
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:41:39 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:41:39 2016 -0800

----------------------------------------------------------------------
 .../tps/include/services/tps/ble_svc_tps.h      | 31 +++++++
 net/nimble/host/services/tps/pkg.yml            | 32 +++++++
 net/nimble/host/services/tps/src/ble_svc_tps.c  | 98 ++++++++++++++++++++
 3 files changed, 161 insertions(+)
----------------------------------------------------------------------



[16/22] incubator-mynewt-core git commit: This closes #87.

Posted by cc...@apache.org.
This closes #87.

Merge remote-tracking branch 'bgiori/feature-ias' into develop

* bgiori/feature-ias:
  update ias package structure into host/services
  Immediate Alert Service implemented.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/44fffd4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/44fffd4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/44fffd4d

Branch: refs/heads/develop
Commit: 44fffd4d28f3b3880db0f3b7dd1deaec6eae35f3
Parents: fcef18f 635dc15
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:01:56 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:01:56 2016 -0800

----------------------------------------------------------------------
 .../ias/include/services/ias/ble_svc_ias.h      |  40 +++++
 net/nimble/host/services/ias/pkg.yml            |  32 ++++
 net/nimble/host/services/ias/src/ble_svc_ias.c  | 146 +++++++++++++++++++
 3 files changed, 218 insertions(+)
----------------------------------------------------------------------



[04/22] incubator-mynewt-core git commit: unfinished changes

Posted by cc...@apache.org.
unfinished changes


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2aba7605
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2aba7605
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2aba7605

Branch: refs/heads/develop
Commit: 2aba7605b377e1046e6b03705a919f2b960ac06a
Parents: 64e5884
Author: Brian Giori <br...@gmail.com>
Authored: Thu Jul 28 11:28:40 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Thu Jul 28 11:28:40 2016 -0700

----------------------------------------------------------------------
 .../ans/include/profiles/ans/ble_svc_ans.h      |  81 ++++
 net/nimble/host/profiles/ans/src/ble_svc_ans.c  | 369 +++++++++++++++++++
 2 files changed, 450 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2aba7605/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h b/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
new file mode 100644
index 0000000..4cbf6fd
--- /dev/null
+++ b/net/nimble/host/profiles/ans/include/profiles/ans/ble_svc_ans.h
@@ -0,0 +1,81 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_SVC_ANS_
+#define H_BLE_SVC_ANS_
+
+struct ble_hs_cfg;
+
+/* 16 Bit Alert Notification Service UUID */
+#define BLE_SVC_ANS_UUID16                                  0x1811
+
+/* 16 Bit Alert Notification Servivce Characteristic UUIDs */
+#define BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT            0x2a47
+#define BLE_SVC_ANS_CHR_UUID16_NEW_ALERT                    0x2a46
+#define BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT            0x2a48
+#define BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT               0x2a45
+#define BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT            0x2a44
+
+/* Alert Notification Service Category ID Bit Masks 
+ *
+ * TODO: Need to add remaining 2 categories */
+#define BLE_SVC_ANS_CAT_F_SIMPLE_ALERT                      0x01
+#define BLE_SVC_ANS_CAT_F_EMAIL                             0x02
+#define BLE_SVC_ANS_CAT_F_NEWS                              0x04
+#define BLE_SVC_ANS_CAT_F_CALL                              0x08
+#define BLE_SVC_ANS_CAT_F_MISSED_CALL                       0x10
+#define BLE_SVC_ANS_CAT_F_SMS                               0x20
+#define BLE_SVC_ANS_CAT_F_VOICE_MAIL                        0x40
+#define BLE_SVC_ANS_CAT_F_SCHEDULE                          0x80    
+
+/* Alert Notification Service Category IDs
+ *
+ * TODO: Need to add remaining 2 categories */
+#define BLE_SVC_ANS_CAT_SIMPLE_ALERT                        0x1
+#define BLE_SVC_ANS_CAT_EMAIL                               0x2
+#define BLE_SVC_ANS_CAT_NEWS                                0x3
+#define BLE_SVC_ANS_CAT_CALL                                0x4
+#define BLE_SVC_ANS_CAT_MISSED_CALL                         0x5
+#define BLE_SVC_ANS_CAT_SMS                                 0x6
+#define BLE_SVC_ANS_CAT_VOICE_MAIL                          0x7
+#define BLE_SVC_ANS_CAT_SCHEDULE                            0x8
+
+/* Number of valid ANS categories 
+ *
+ * TODO: Need to add remaining 2 categories */
+#define BLE_SVC_ANS_CAT_NUM                                 8
+
+/* Alert Notification Control Point Command IDs */
+#define BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT                    0
+#define BLE_SVC_ANS_CMD_EN_UNR_ALERT_CAT                    1
+#define BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT                   2
+#define BLE_SVC_ANS_CMD_DIS_UNR_ALERT_CAT                   3
+#define BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEADIATE            4
+#define BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEADIATE            5
+
+int ble_svc_ans_new_alert_add(uint8_t category_flag, 
+                              char * info_str);
+int ble_svc_ans_unr_alert_add(uint8_t category_flag);
+
+int ble_svc_ans_init(struct ble_hs_cfg *cfg, 
+                     uint8_t new_alert_cat,
+                     uint8_t urn_alert_cat);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2aba7605/net/nimble/host/profiles/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/src/ble_svc_ans.c b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
new file mode 100644
index 0000000..a9e259c
--- /dev/null
+++ b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
@@ -0,0 +1,369 @@
+/**
+ * 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.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+#include "host/ble_hs.h"
+#include "profiles/ble_svc_ans.h"
+
+/* Access function */
+static int
+ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
+    {
+        /*** Alert Notification Service. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_SVC_ANS_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Supported New Alert Catagory 
+             * 
+             * This characteristic exposes what categories of new 
+             * alert are supported in the server.
+             * 
+             * */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** New Alert 
+             *
+             * This characteristic exposes information about 
+             * the count of new alerts (for a given category).
+             *
+             * */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_NEW_ALERT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            /*** Supported Unread Alert Catagory 
+             *
+             * This characteristic exposes what categories of 
+             * unread alert are supported in the server.
+             *
+             * */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Unread Alert Status 
+             *
+             * This characteristic exposes the count of unread 
+             * alert events existing in the server.
+             *
+             * */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            /*** Alert Notification Control Point 
+             *
+             * This characteristic allows the peer device to 
+             * enable/disable the alert notification of new alert 
+             * and unread event more selectively than can be done 
+             * by setting or clearing the notification bit in the 
+             * Client Characteristic Configuration for each alert 
+             * characteristic.
+             *
+             * */
+            .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT),
+            .access_cb = ble_svc_ans_access,
+            .flags = BLE_GATT_CHR_F_WRITE,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+static int
+ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
+                      uint16_t max_len, void *dst,
+                      uint16_t *len)
+{
+    uint16_t om_len;
+    int rc;
+
+    om_len = OS_MBUF_PKTLEN(om);
+    if (om_len < min_len || om_len > max_len) {
+        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    }
+
+    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
+    if (rc != 0) {
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+
+    return 0;
+}
+
+/* Because the max length of the info string is 18 octets,
+ * and the category ID and count take up 2 octets each, we
+ * require a maximum of 20 octets of space.
+ */
+#define GATT_SVR_NEW_ALERT_VAL_MAX_LEN   20 
+
+/* Supported new alert categories bitmask */
+static const uint8_t ble_svc_ans_new_alert_cat;
+/* New alert value */
+static uint8_t ble_svc_ans_new_alert_val[GATT_SVR_NEW_ALERT_VAL_MAX_LEN];
+static uint16_t ble_svc_ans_new_alert_val_len;
+/* New alert count, one value for each category */
+static uint8_t ble_svc_ans_new_alert_cnt[BLE_SVC_ANS_CAT_NUM];
+
+/* Supported unread alert catagories bitmask */ 
+static const uint8_t ble_svc_ans_unr_alert_cat; 
+/* Unread alert status, contains supported catagories and count */
+static uint8_t ble_svc_ans_unr_alert_stat[2];
+/* Count of unread alerts. One value for each category */
+static uint8_t ble_svc_ans_unr_alert_cnt[BLE_SVC_ANS_CAT_NUM];
+
+/* Alert notification control point value */
+static uint8_t ble_svc_ans_alert_not_ctrl_pt[2];
+
+static int
+gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
+                          struct ble_gatt_access_ctxt *ctxt,
+                          void *arg)
+{
+    uint16_t uuid16;
+    int rc;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID:
+        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+        rc = os_mbuf_append(ctxt->om, &ble_svc_ans_new_alert_cat,
+                            sizeof ble_svc_ans_new_alert_cat);
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    case GATT_SVR_CHR_NEW_ALERT:
+        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = ble_svc_ans_chr_write(ctxt->om, 0,
+                                       sizeof ble_svc_ans_new_alert_val,
+                                       ble_svc_ans_new_alert_val,
+                                       &ble_svc_ans_new_alert_val_len);
+            return rc;
+
+        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+            rc = os_mbuf_append(ctxt->om, &ble_svc_ans_new_alert_val,
+                                sizeof ble_svc_ans_new_alert_val);
+            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+        }
+
+    case GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID:
+        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+        rc = os_mbuf_append(ctxt->om, &ble_svc_ans_unr_alert_cat,
+                            sizeof ble_svc_ans_unr_alert_cat);
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    case GATT_SVR_CHR_UNR_ALERT_STAT_UUID:
+        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = ble_svc_ans_chr_write(ctxt->om, 
+                                       sizeof ble_svc_ans_unr_alert_stat, 
+                                       sizeof ble_svc_ans_unr_alert_stat,
+                                       &ble_svc_ans_unr_alert_stat,
+                                       NULL);
+            return rc; 
+        } else {
+            rc = os_mbuf_append(ctxt->om, &ble_svc_ans_unr_alert_stat,
+                                sizeof ble_svc_ans_unr_alert_stat);
+            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+        }
+
+    case GATT_SVR_CHR_ALERT_NOT_CTRL_PT:
+        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = ble_svc_ans_chr_write(ctxt->om, 
+                                       sizeof ble_svc_ans_alert_not_ctrl_pt, 
+                                       sizeof ble_svc_ans_alert_not_ctrl_pt,
+                                       &ble_svc_ans_alert_not_ctrl_pt,
+                                       NULL);
+
+            /* Get command ID and category ID */
+            uint8_t cmd_id = ble_svc_ans_alert_not_ctrl_pt[0];
+            uint8_t cat_id = ble_svc_ans_alert_not_ctrl_pt[1];
+            uint8_t cat; 
+
+            /* Set cat to the appropriate bitmask based on cat_id or
+             * return error if the cat_id in an invalid range.
+             */
+            if (cat_id < BLE_SVC_ANS_CAT_NUM) {
+                cat = pow(2, cat_id);
+            } else if (cat_id == 0xff) {
+                cat = cat_id;
+            } else {
+                return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
+            }
+            switch(cmd_id) {
+            case BLE_SVC_ANS_CMD_EN_NEW_ALERT_CAT:
+                ble_svc_ans_new_alert_cat |= cat; 
+                break;
+            case BLE_SVC_ANS_CMD_EN_UNR_ALERT_STAT_CAT:
+                ble_svc_ans_unr_alert_cat |= cat;
+                break;
+            case BLE_SVC_ANS_CMD_DIS_NEW_ALERT_CAT:
+                ble_svc_ans_new_alert_cat &= ~cat;
+                break;
+            case BLE_SVC_ANS_CMD_DIS_UNR_ALERT_STAT_CAT:
+                ble_svc_ans_unr_alert_cat &= ~cat;
+                break;
+            case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE:
+                /* TODO */
+                break;
+            case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_STAT_IMMEDIATE:
+                /* TODO */
+                break;
+            default:
+                return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
+            }
+            return 0;
+        } else {
+            rc = BLE_ATT_ERR_UNLIKELY;
+        }
+        return rc;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+}
+
+/* Helper function to check if power of two to ensure valid flags. 
+ */
+uint8_t 
+is_pow_of_two(uint8_t x)
+{
+  return ((x != 0) && ((x & (~x + 1)) == x));
+}
+
+/**
+ * Adds a new alert to the given category then sets the new 
+ * alert val to the category, the new alert count for the given 
+ * category, and the given info string. If set up for notification, 
+ * setting this value will notify the client.
+ * 
+ * @param cat_flag              The flag for the category which should
+ *                                  should be incremented and notified
+ * @param info_str              The info string to be sent to the client
+ *                                  with the notification.
+ * 
+ * @return 0 if success, BLE_HS_EINVAL if the category is not enabled 
+ *         or if the flag is not valid.
+ */
+int
+ble_svc_ans_new_alert_add(uint8_t cat_flag, const char * info_str)
+{
+    if (cat_flag & ble_svc_ans_new_alert_cat == 0) {
+        return BLE_HS_EINVAL;
+    }
+
+    uint8_t cat_idx; 
+    if (is_power_of_two(cat_flag)) {
+        cat_idx = log10(cat_flag)/log10(2);
+    } else {
+        return BLE_HS_EINVAL;
+    }
+
+
+
+    ble_svc_ans_new_alert_cnt[cat_idx] += 1;
+    ble_svc_ans_new_alert_val[0] = category;
+    ble_svc_ans_new_alert_val[1] = ble_svc_ans_new_alert_cnt[cat_idx];
+    memcpy(&ble_svc_ans_new_alert_val[2], info_str, sizeof(info_str));
+    return 0;
+}
+
+
+/**
+ * Adds an unread alert to the given category then sets the unread
+ * alert stat to the category and the new unread alert value for
+ * the given category. If set up for notification, setting this value
+ * will notify the client.
+ * 
+ * @param cat_flag              The flag for the category which should
+ *                                  should be incremented and notified
+ * 
+ * @return 0 if success, BLE_HS_EINVAL if the category is not enabled 
+ *         or if the flag is not valid.
+ */
+int
+ble_svc_ans_unr_alert_add(uint8_t cat_id)
+{
+    uint8_t cat_flag; 
+    if (cat_id < BLE_SVC_ANS_CAT_NUM) {
+        cat = pow(2, cat_id);
+        return BLE_HS_EINVAL;
+    }
+
+    /* Set cat to the appropriate bitmask based on cat_id or
+     * return error if the cat_id in an invalid range.
+     */
+    if (cat_id <= BLE_SVC_ANS_CMD_NOT_UNR_ALERT_STAT_IMMEDIATE) {
+    } else if (cat_id == 0xff) {
+        cat = cat_id;
+    } else {
+        return BLE_SVC_ANS_ERR_CMD_NOT_SUPPORTED;
+    }
+    uint8_t cat_idx; 
+    if (is_power_of_two(cat_flag)) {
+        cat_idx = log10(cat_flag)/log10(2);
+    } else {
+        return BLE_HS_EINVAL;
+    }
+
+    ble_svc_ans_unr_alert_cnt[cat_idx] += 1;
+    ble_svc_ans_unr_alert_stat[0] = category;
+    ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_idx];
+    return 0;
+}
+
+/**
+ * Initialize the ANS with an initial .
+ * 
+ * XXX: We should technically be able to change the new alert and
+ *      unread alert catagories when we have no active connections.
+ */
+int
+ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t new_alert_cat, 
+        uint8_t unr_alert_cat)
+{
+    ble_svc_ans_new_alert_cat = new_alert_cat; 
+    ble_svc_ans_unr_alert_cat = unr_alert_cat;
+
+    int rc;
+    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;
+}
+


[02/22] incubator-mynewt-core git commit: Tx Power Service implementation

Posted by cc...@apache.org.
Tx Power Service implementation


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b4ae19f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b4ae19f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b4ae19f0

Branch: refs/heads/develop
Commit: b4ae19f09222d57f5d446d0b163d79ace8725f11
Parents: 626b219
Author: Brian Giori <br...@gmail.com>
Authored: Thu Jul 28 09:37:02 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Thu Jul 28 09:37:02 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/profiles/tps/src/ble_svc_tps.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4ae19f0/net/nimble/host/profiles/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/src/ble_svc_tps.c b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
index abcd11e..7a5bd08 100644
--- a/net/nimble/host/profiles/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
@@ -59,6 +59,7 @@ ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
                    struct ble_gatt_access_ctxt *ctxt, void *arg)
 {
     assert(ctxt->chr == &ble_svc_tps_defs[0].characteristics[0]);
+    int rc;
     switch(ctxt->op) {
     case BLE_GATT_ACCESS_OP_READ_CHR:
         ble_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);
@@ -87,7 +88,7 @@ ble_svc_tps_init(struct ble_hs_cfg *cfg)
         return rc;
     }
 
-    rc = ble_gatts_add_svcs(ble_svc_lls_defs);
+    rc = ble_gatts_add_svcs(ble_svc_tps_defs);
     if (rc != 0) {
         return rc;
     }


[15/22] incubator-mynewt-core git commit: update ias package structure into host/services

Posted by cc...@apache.org.
update ias package structure into host/services


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/635dc153
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/635dc153
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/635dc153

Branch: refs/heads/develop
Commit: 635dc153edc5de4f4389c4878ffbe77b28ff5dd5
Parents: 5091e74
Author: Brian Giori <br...@gmail.com>
Authored: Tue Sep 20 13:42:11 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Tue Sep 20 13:42:11 2016 -0700

----------------------------------------------------------------------
 .../ias/include/profiles/ias/ble_svc_ias.h      |  40 -----
 net/nimble/host/profiles/ias/pkg.yml            |  32 ----
 net/nimble/host/profiles/ias/src/ble_svc_ias.c  | 146 -------------------
 .../ias/include/services/ias/ble_svc_ias.h      |  40 +++++
 net/nimble/host/services/ias/pkg.yml            |  32 ++++
 net/nimble/host/services/ias/src/ble_svc_ias.c  | 146 +++++++++++++++++++
 6 files changed, 218 insertions(+), 218 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/635dc153/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h b/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h
deleted file mode 100644
index da173cf..0000000
--- a/net/nimble/host/profiles/ias/include/profiles/ias/ble_svc_ias.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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.
- */
-
-#ifndef H_BLE_IAS_TPS_
-#define H_BLE_IAS_TPS_
-
-struct ble_hs_cfg;
-
-#define BLE_SVC_IAS_UUID16                                      0x1802
-#define BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL                      0x2a06
-
-/* Alert level definitions */
-#define BLE_SVC_IAS_ALERT_LEVEL_NO_ALERT                        0
-#define BLE_SVC_IAS_ALERT_LEVEL_MILD_ALERT                      1
-#define BLE_SVC_IAS_ALERT_LEVEL_HIGH_ALERT                      2
-
-typedef int ble_svc_ias_event_fn(uint8_t alert_level); 
-
-int ble_svc_ias_init(struct ble_hs_cfg *cfg, 
-                     ble_svc_ias_event_fn *cb);
-
-#endif
-
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/635dc153/net/nimble/host/profiles/ias/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ias/pkg.yml b/net/nimble/host/profiles/ias/pkg.yml
deleted file mode 100644
index ce05ffe..0000000
--- a/net/nimble/host/profiles/ias/pkg.yml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-# 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.
-#
-
-pkg.name: net/nimble/host/profiles/ias
-pkg.description: Immidiate Alert Service.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - ble 
-    - bluetooth
-    - ias 
-    - nimble
-
-pkg.deps:
-    - net/nimble/host
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/635dc153/net/nimble/host/profiles/ias/src/ble_svc_ias.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ias/src/ble_svc_ias.c b/net/nimble/host/profiles/ias/src/ble_svc_ias.c
deleted file mode 100644
index 5fce5bd..0000000
--- a/net/nimble/host/profiles/ias/src/ble_svc_ias.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * 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.
- */
-
-#include <assert.h>
-#include <string.h>
-#include "host/ble_hs.h"
-#include "profiles/ias/ble_svc_ias.h"
-
-/* Callback function */
-static ble_svc_ias_event_fn *ble_svc_ias_cb_fn;
-/* Alert level */
-static uint8_t ble_svc_ias_alert_level;
-
-/* Write characteristic function */
-static int
-ble_svc_ias_chr_write(struct os_mbuf *om, uint16_t min_len,
-                      uint16_t max_len, void *dst,
-                      uint16_t *len);
-
-/* Access function */
-static int
-ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
-                   struct ble_gatt_access_ctxt *ctxt, void *arg);
-
-static const struct ble_gatt_svc_def ble_svc_ias_defs[] = {
-    {
-        /*** Service: Immediate Alert Service (IAS). */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid128 = BLE_UUID16(BLE_SVC_IAS_UUID16),
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Characteristic: Alert Level. */
-            .uuid128 = BLE_UUID16(BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL),
-            .access_cb = ble_svc_ias_access,
-            .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
-        }, {
-            0, /* No more characteristics in this service. */
-        } },
-    },
-
-    {
-        0, /* No more services. */
-    },
-};
-
-/**
- * Writes the received value from a characteristic write to 
- * the given destination.
- */
-static int
-ble_svc_ias_chr_write(struct os_mbuf *om, uint16_t min_len, 
-                      uint16_t max_len, void *dst, 
-                      uint16_t *len)
-{
-    uint16_t om_len;
-    int rc; 
-
-    om_len = OS_MBUF_PKTLEN(om);
-    if (om_len < min_len || om_len > max_len) {
-        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
-    }   
-
-    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
-    if (rc != 0) {
-        return BLE_ATT_ERR_UNLIKELY;
-    }   
-
-    return 0;
-}
-
-/**
- * Simple write access callback for the alert level
- * characteristic.
- */
-static int
-ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
-                   struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
-    int rc;
-    
-    assert(ctxt->chr == &ble_svc_ias_defs[0].characteristics[0]);
-    
-    switch (ctxt->op) {
-    case BLE_GATT_ACCESS_OP_WRITE_CHR:
-        rc = ble_svc_ias_chr_write(ctxt->om,
-                                   sizeof ble_svc_ias_alert_level,
-                                   sizeof ble_svc_ias_alert_level,
-                                   &ble_svc_ias_alert_level, NULL);
-        /* Call the IAS event function */
-        ble_svc_ias_cb_fn(ble_svc_ias_alert_level);
-        return rc;
-
-    default:
-        assert(0);
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-
-    return 0;
-}
-
-/**
- * Initialize the IAS. The developer must specify the event function
- * callback for the IAS to function properly.
- *
- * @param cb                        The callback function to call when 
- *                                      the client signals an alert.
- */
-int
-ble_svc_ias_init(struct ble_hs_cfg *cfg, ble_svc_ias_event_fn *cb)
-{
-    int rc;
-    
-    if (!cb) {
-        return BLE_HS_EINVAL;
-    }
-
-    ble_svc_ias_cb_fn = cb;
-
-    rc = ble_gatts_count_cfg(ble_svc_ias_defs, cfg);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = ble_gatts_add_svcs(ble_svc_ias_defs);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/635dc153/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h b/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h
new file mode 100644
index 0000000..da173cf
--- /dev/null
+++ b/net/nimble/host/services/ias/include/services/ias/ble_svc_ias.h
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_IAS_TPS_
+#define H_BLE_IAS_TPS_
+
+struct ble_hs_cfg;
+
+#define BLE_SVC_IAS_UUID16                                      0x1802
+#define BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL                      0x2a06
+
+/* Alert level definitions */
+#define BLE_SVC_IAS_ALERT_LEVEL_NO_ALERT                        0
+#define BLE_SVC_IAS_ALERT_LEVEL_MILD_ALERT                      1
+#define BLE_SVC_IAS_ALERT_LEVEL_HIGH_ALERT                      2
+
+typedef int ble_svc_ias_event_fn(uint8_t alert_level); 
+
+int ble_svc_ias_init(struct ble_hs_cfg *cfg, 
+                     ble_svc_ias_event_fn *cb);
+
+#endif
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/635dc153/net/nimble/host/services/ias/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/pkg.yml b/net/nimble/host/services/ias/pkg.yml
new file mode 100644
index 0000000..39242f4
--- /dev/null
+++ b/net/nimble/host/services/ias/pkg.yml
@@ -0,0 +1,32 @@
+
+# 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.
+#
+
+pkg.name: net/nimble/host/services/ias
+pkg.description: Immidiate Alert Service Implementation.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble 
+    - bluetooth
+    - ias 
+    - nimble
+
+pkg.deps:
+    - net/nimble/host
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/635dc153/net/nimble/host/services/ias/src/ble_svc_ias.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/src/ble_svc_ias.c b/net/nimble/host/services/ias/src/ble_svc_ias.c
new file mode 100644
index 0000000..07b98f1
--- /dev/null
+++ b/net/nimble/host/services/ias/src/ble_svc_ias.c
@@ -0,0 +1,146 @@
+/**
+ * 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.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include "host/ble_hs.h"
+#include "services/ias/ble_svc_ias.h"
+
+/* Callback function */
+static ble_svc_ias_event_fn *ble_svc_ias_cb_fn;
+/* Alert level */
+static uint8_t ble_svc_ias_alert_level;
+
+/* Write characteristic function */
+static int
+ble_svc_ias_chr_write(struct os_mbuf *om, uint16_t min_len,
+                      uint16_t max_len, void *dst,
+                      uint16_t *len);
+
+/* Access function */
+static int
+ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+static const struct ble_gatt_svc_def ble_svc_ias_defs[] = {
+    {
+        /*** Service: Immediate Alert Service (IAS). */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_SVC_IAS_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Alert Level. */
+            .uuid128 = BLE_UUID16(BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL),
+            .access_cb = ble_svc_ias_access,
+            .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+/**
+ * Writes the received value from a characteristic write to 
+ * the given destination.
+ */
+static int
+ble_svc_ias_chr_write(struct os_mbuf *om, uint16_t min_len, 
+                      uint16_t max_len, void *dst, 
+                      uint16_t *len)
+{
+    uint16_t om_len;
+    int rc; 
+
+    om_len = OS_MBUF_PKTLEN(om);
+    if (om_len < min_len || om_len > max_len) {
+        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    }   
+
+    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
+    if (rc != 0) {
+        return BLE_ATT_ERR_UNLIKELY;
+    }   
+
+    return 0;
+}
+
+/**
+ * Simple write access callback for the alert level
+ * characteristic.
+ */
+static int
+ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    int rc;
+    
+    assert(ctxt->chr == &ble_svc_ias_defs[0].characteristics[0]);
+    
+    switch (ctxt->op) {
+    case BLE_GATT_ACCESS_OP_WRITE_CHR:
+        rc = ble_svc_ias_chr_write(ctxt->om,
+                                   sizeof ble_svc_ias_alert_level,
+                                   sizeof ble_svc_ias_alert_level,
+                                   &ble_svc_ias_alert_level, NULL);
+        /* Call the IAS event function */
+        ble_svc_ias_cb_fn(ble_svc_ias_alert_level);
+        return rc;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+
+    return 0;
+}
+
+/**
+ * Initialize the IAS. The developer must specify the event function
+ * callback for the IAS to function properly.
+ *
+ * @param cb                        The callback function to call when 
+ *                                      the client signals an alert.
+ */
+int
+ble_svc_ias_init(struct ble_hs_cfg *cfg, ble_svc_ias_event_fn *cb)
+{
+    int rc;
+    
+    if (!cb) {
+        return BLE_HS_EINVAL;
+    }
+
+    ble_svc_ias_cb_fn = cb;
+
+    rc = ble_gatts_count_cfg(ble_svc_ias_defs, cfg);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_gatts_add_svcs(ble_svc_ias_defs);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}
+


[14/22] incubator-mynewt-core git commit: moved tps to services dir.

Posted by cc...@apache.org.
moved tps to services dir.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/df94f010
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/df94f010
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/df94f010

Branch: refs/heads/develop
Commit: df94f0101803639aa412193a8eb6f0677ac94c27
Parents: ef3024f
Author: Brian Giori <br...@gmail.com>
Authored: Mon Aug 1 17:20:30 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Mon Aug 1 17:20:30 2016 -0700

----------------------------------------------------------------------
 .../tps/include/profiles/tps/ble_svc_tps.h      | 31 -------
 net/nimble/host/profiles/tps/pkg.yml            | 32 -------
 net/nimble/host/profiles/tps/src/ble_svc_tps.c  | 98 --------------------
 .../tps/include/services/tps/ble_svc_tps.h      | 31 +++++++
 net/nimble/host/services/tps/pkg.yml            | 32 +++++++
 net/nimble/host/services/tps/src/ble_svc_tps.c  | 98 ++++++++++++++++++++
 6 files changed, 161 insertions(+), 161 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/df94f010/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h b/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h
deleted file mode 100644
index c1797ae..0000000
--- a/net/nimble/host/profiles/tps/include/profiles/tps/ble_svc_tps.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.
- */
-
-#ifndef H_BLE_SVC_TPS_
-#define H_BLE_SVC_TPS_
-
-struct ble_hs_cfg;
-
-#define BLE_SVC_TPS_UUID16                                      0x1804
-#define BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL                   0x2a07
-
-int ble_svc_tps_init(struct ble_hs_cfg *cfg); 
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/df94f010/net/nimble/host/profiles/tps/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/pkg.yml b/net/nimble/host/profiles/tps/pkg.yml
deleted file mode 100644
index 92f43bb..0000000
--- a/net/nimble/host/profiles/tps/pkg.yml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-# 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.
-#
-
-pkg.name: net/nimble/host/profiles/tps
-pkg.description: Tx Power Service adopted specification.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - ble
-    - bluetooth
-    - tps 
-    - nimble
-
-pkg.deps:
-    - net/nimble/host
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/df94f010/net/nimble/host/profiles/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/src/ble_svc_tps.c b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
deleted file mode 100644
index fbbd0b5..0000000
--- a/net/nimble/host/profiles/tps/src/ble_svc_tps.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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.
- */
-
-#include <assert.h>
-#include <string.h>
-#include "host/ble_hs.h"
-#include "profiles/tps/ble_svc_tps.h"
-#include "../../../src/ble_hci_priv.h"
-
-int8_t ble_svc_tps_tx_power_level;
-
-/* Access function */
-static int
-ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
-                   struct ble_gatt_access_ctxt *ctxt, void *arg);
-
-static const struct ble_gatt_svc_def ble_svc_tps_defs[] = {
-    {
-        /*** Service: Tx Power Service. */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid128 = BLE_UUID16(BLE_SVC_TPS_UUID16),
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Characteristic: Tx Power Level. */
-            .uuid128 = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
-            .access_cb = ble_svc_tps_access,
-            .flags = BLE_GATT_CHR_F_READ,
-        }, {
-            0, /* No more characteristics in this service. */
-        } },
-    },
-
-    {
-        0, /* No more services. */
-    },
-};
-
-/**
- * Simple read access callback for the tx power level
- * characteristic.
- */
-static int
-ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
-                   struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
-    int rc;
-    
-    assert(ctxt->chr == &ble_svc_tps_defs[0].characteristics[0]);
-    
-    switch (ctxt->op) {
-    case BLE_GATT_ACCESS_OP_READ_CHR:
-        ble_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);
-        rc = os_mbuf_append(ctxt->om, &ble_svc_tps_tx_power_level,
-                            sizeof ble_svc_tps_tx_power_level);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-    default:
-        assert(0);
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-
-    return 0;
-}
-
-/**
- * Initialize the TPS
- */
-int
-ble_svc_tps_init(struct ble_hs_cfg *cfg)
-{
-    int rc;
-    rc = ble_gatts_count_cfg(ble_svc_tps_defs, cfg);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = ble_gatts_add_svcs(ble_svc_tps_defs);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/df94f010/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h b/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h
new file mode 100644
index 0000000..c1797ae
--- /dev/null
+++ b/net/nimble/host/services/tps/include/services/tps/ble_svc_tps.h
@@ -0,0 +1,31 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_SVC_TPS_
+#define H_BLE_SVC_TPS_
+
+struct ble_hs_cfg;
+
+#define BLE_SVC_TPS_UUID16                                      0x1804
+#define BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL                   0x2a07
+
+int ble_svc_tps_init(struct ble_hs_cfg *cfg); 
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/df94f010/net/nimble/host/services/tps/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/pkg.yml b/net/nimble/host/services/tps/pkg.yml
new file mode 100644
index 0000000..45d85b6
--- /dev/null
+++ b/net/nimble/host/services/tps/pkg.yml
@@ -0,0 +1,32 @@
+
+# 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.
+#
+
+pkg.name: net/nimble/host/services/tps
+pkg.description: Tx Power Service adopted specification.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble
+    - bluetooth
+    - tps 
+    - nimble
+
+pkg.deps:
+    - net/nimble/host
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/df94f010/net/nimble/host/services/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/src/ble_svc_tps.c b/net/nimble/host/services/tps/src/ble_svc_tps.c
new file mode 100644
index 0000000..3f241b0
--- /dev/null
+++ b/net/nimble/host/services/tps/src/ble_svc_tps.c
@@ -0,0 +1,98 @@
+/**
+ * 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.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include "host/ble_hs.h"
+#include "services/tps/ble_svc_tps.h"
+#include "../../../src/ble_hci_priv.h"
+
+int8_t ble_svc_tps_tx_power_level;
+
+/* Access function */
+static int
+ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+static const struct ble_gatt_svc_def ble_svc_tps_defs[] = {
+    {
+        /*** Service: Tx Power Service. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_SVC_TPS_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Tx Power Level. */
+            .uuid128 = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
+            .access_cb = ble_svc_tps_access,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+/**
+ * Simple read access callback for the tx power level
+ * characteristic.
+ */
+static int
+ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    int rc;
+    
+    assert(ctxt->chr == &ble_svc_tps_defs[0].characteristics[0]);
+    
+    switch (ctxt->op) {
+    case BLE_GATT_ACCESS_OP_READ_CHR:
+        ble_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);
+        rc = os_mbuf_append(ctxt->om, &ble_svc_tps_tx_power_level,
+                            sizeof ble_svc_tps_tx_power_level);
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+
+    return 0;
+}
+
+/**
+ * Initialize the TPS
+ */
+int
+ble_svc_tps_init(struct ble_hs_cfg *cfg)
+{
+    int rc;
+    rc = ble_gatts_count_cfg(ble_svc_tps_defs, cfg);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_gatts_add_svcs(ble_svc_tps_defs);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}


[03/22] incubator-mynewt-core git commit: updated comments and error return value

Posted by cc...@apache.org.
updated comments and error return value


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d0b6d35a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d0b6d35a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d0b6d35a

Branch: refs/heads/develop
Commit: d0b6d35a879e02dc5bb9c734091c111d1dc10c07
Parents: b4ae19f
Author: Brian Giori <br...@gmail.com>
Authored: Thu Jul 28 09:42:43 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Thu Jul 28 09:44:06 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/profiles/tps/src/ble_svc_tps.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d0b6d35a/net/nimble/host/profiles/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/src/ble_svc_tps.c b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
index 7a5bd08..3e2bf42 100644
--- a/net/nimble/host/profiles/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
@@ -36,7 +36,7 @@ static const struct ble_gatt_svc_def ble_svc_tps_defs[] = {
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(BLE_SVC_TPS_UUID16),
         .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Characteristic: Alert Level. */
+            /*** Characteristic: Tx Power Level. */
             .uuid128 = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
             .access_cb = ble_svc_tps_access,
             .flags = BLE_GATT_CHR_F_READ,
@@ -69,15 +69,14 @@ ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
 
     default:
         assert(0);
-        break;
+        return BLE_ATT_ERR_UNLIKELY;
     }
 
     return 0;
 }
 
 /**
- * Initialize the TPS. The developer must specify the event function
- * callback for the TPS to function properly.
+ * Initialize the TPS
  */
 int
 ble_svc_tps_init(struct ble_hs_cfg *cfg)


[10/22] incubator-mynewt-core git commit: variables declared at top of function scope

Posted by cc...@apache.org.
 variables declared at top of function scope


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ef3024f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ef3024f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ef3024f9

Branch: refs/heads/develop
Commit: ef3024f99d6b805e37b1a8e91057e4992e98b845
Parents: 98caf9f
Author: Brian Giori <br...@gmail.com>
Authored: Mon Aug 1 14:03:38 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Mon Aug 1 14:03:38 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/profiles/tps/src/ble_svc_tps.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef3024f9/net/nimble/host/profiles/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/tps/src/ble_svc_tps.c b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
index e354eec..fbbd0b5 100644
--- a/net/nimble/host/profiles/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/profiles/tps/src/ble_svc_tps.c
@@ -58,8 +58,10 @@ static int
 ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle,
                    struct ble_gatt_access_ctxt *ctxt, void *arg)
 {
-    assert(ctxt->chr == &ble_svc_tps_defs[0].characteristics[0]);
     int rc;
+    
+    assert(ctxt->chr == &ble_svc_tps_defs[0].characteristics[0]);
+    
     switch (ctxt->op) {
     case BLE_GATT_ACCESS_OP_READ_CHR:
         ble_hci_util_read_adv_tx_pwr(&ble_svc_tps_tx_power_level);


[08/22] incubator-mynewt-core git commit: updated comments

Posted by cc...@apache.org.
updated comments


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ca151c07
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ca151c07
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ca151c07

Branch: refs/heads/develop
Commit: ca151c07899733443e657af88b8b2eb10744eac2
Parents: 619af6e
Author: Brian Giori <br...@gmail.com>
Authored: Fri Jul 29 18:09:03 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Fri Jul 29 18:09:03 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/profiles/ans/src/ble_svc_ans.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca151c07/net/nimble/host/profiles/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/ans/src/ble_svc_ans.c b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
index 32d3350..a361abe 100644
--- a/net/nimble/host/profiles/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/profiles/ans/src/ble_svc_ans.c
@@ -228,6 +228,7 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
                 break;
             case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE:
                 if (cat_id == 0xff) {
+                    /* If cat_id is 0xff, notify on all enabled categories */
                     int i;
                     for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
                         if ((ble_svc_ans_new_alert_cat >> i) & 0x01) {
@@ -240,6 +241,7 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
                 break;
             case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE:
                 if (cat_id == 0xff) {
+                    /* If cat_id is 0xff, notify on all enabled categories */
                     int i;
                     for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) {
                         if ((ble_svc_ans_unr_alert_cat >> i) & 0x01) {
@@ -268,7 +270,7 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
 /**
  * This function must be called with the connection handlewhen a gap 
  * connect event is received in order to send notifications to the
- * client
+ * client.
  *
  * @params conn_handle          The connection handle for the current
  *                                  connection.
@@ -288,7 +290,7 @@ ble_svc_ans_on_gap_connect(uint16_t conn_handle)
  * @param info_str              The info string to be sent to the client
  *                                  with the notification.
  * 
- * @return 0 if success, error code otherwise. 
+ * @return 0 on success, non-zero error code otherwise. 
  */
 int
 ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
@@ -315,8 +317,7 @@ ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
  * @param cat_flag              The flag for the category which should
  *                                  should be incremented and notified
  * 
- * @return 0 if success, BLE_HS_EINVAL if the category is not enabled 
- *         or if the flag is not valid.
+ * @return 0 on success, non-zero error code otherwise. 
  */
 int
 ble_svc_ans_unr_alert_add(uint8_t cat_id)
@@ -350,7 +351,7 @@ ble_svc_ans_unr_alert_add(uint8_t cat_id)
  * @param initial_unr_alert_cat     Initial supported unread alert category
  *                                      bitmask.
  *
- * @return 0 on success, non-zero on error.
+ * @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,
@@ -382,7 +383,7 @@ ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t initial_new_alert_cat,
  * @param info_str              The info string to send with the 
  *                                  notification
  *
- * @return 0 if success, non-zero if error.
+ * @return 0 on success, non-zero error code otherwise.
  */
 static int
 ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str)
@@ -417,7 +418,7 @@ ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str)
  * @param cat_id                The ID of the category to send the
  *                                  notificaiton to.
  *
- * @return 0 if success, non-zero if error.
+ * @return 0 on success, non-zer0 error code otherwise.
  */
 static int
 ble_svc_ans_unr_alert_notify(uint8_t cat_id)


[19/22] incubator-mynewt-core git commit: BLE ANS service - Use sysinit.

Posted by cc...@apache.org.
BLE ANS service - Use sysinit.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/32b0d33a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/32b0d33a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/32b0d33a

Branch: refs/heads/develop
Commit: 32b0d33a3a409668e9199c9bb6c28a8f5db3d374
Parents: ff4ce46
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:40:56 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:40:56 2016 -0800

----------------------------------------------------------------------
 .../ans/include/services/ans/ble_svc_ans.h      |  4 +-
 net/nimble/host/services/ans/pkg.yml            |  3 +
 net/nimble/host/services/ans/src/ble_svc_ans.c  | 65 ++++++++------------
 net/nimble/host/services/ans/syscfg.yml         | 25 ++++++++
 4 files changed, 56 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h b/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
index eaf102a..8d3e3cf 100644
--- a/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
+++ b/net/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
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/pkg.yml b/net/nimble/host/services/ans/pkg.yml
index 91a92c6..41a738c 100644
--- a/net/nimble/host/services/ans/pkg.yml
+++ b/net/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

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/src/ble_svc_ans.c b/net/nimble/host/services/ans/src/ble_svc_ans.c
index eae4598..249e2f5 100644
--- a/net/nimble/host/services/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/services/ans/src/ble_svc_ans.c
@@ -20,6 +20,8 @@
 #include <assert.h>
 #include <string.h>
 #include <math.h>
+#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"
@@ -348,44 +350,6 @@ ble_svc_ans_unr_alert_add(uint8_t 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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/syscfg.yml b/net/nimble/host/services/ans/syscfg.yml
new file mode 100644
index 0000000..a77f23d
--- /dev/null
+++ b/net/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