You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/08/03 21:58:06 UTC

[06/13] incubator-mynewt-core git commit: updated lls location to host and new api

updated lls location to host and new 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/ba37dff1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ba37dff1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ba37dff1

Branch: refs/heads/sterly_refactor
Commit: ba37dff1453d9120f01ab429d4bf95f714831a08
Parents: a1f73dc
Author: Brian Giori <br...@gmail.com>
Authored: Wed Jul 27 16:22:25 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Aug 3 14:57:50 2016 -0700

----------------------------------------------------------------------
 .../lls/include/profiles/lls/ble_svc_lls.h      |  44 +++++
 net/nimble/host/profiles/lls/pkg.yml            |  31 +++
 net/nimble/host/profiles/lls/src/ble_svc_lls.c  | 187 +++++++++++++++++++
 .../profiles/include/profiles/ble_svc_lls.h     |  45 -----
 net/nimble/profiles/pkg.yml                     |  31 ---
 net/nimble/profiles/src/ble_svc_lls.c           | 166 ----------------
 6 files changed, 262 insertions(+), 242 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba37dff1/net/nimble/host/profiles/lls/include/profiles/lls/ble_svc_lls.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/lls/include/profiles/lls/ble_svc_lls.h b/net/nimble/host/profiles/lls/include/profiles/lls/ble_svc_lls.h
new file mode 100644
index 0000000..964f8b5
--- /dev/null
+++ b/net/nimble/host/profiles/lls/include/profiles/lls/ble_svc_lls.h
@@ -0,0 +1,44 @@
+/**
+ * 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_LLS_
+#define H_BLE_SVC_LLS_
+
+struct ble_hs_cfg;
+
+#define BLE_SVC_LLS_UUID16                                  0x1803
+#define BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL                  0x2a06
+
+/* Alert level definitions */
+#define BLE_SVC_LLS_ALERT_LEVEL_NO_ALERT                    0
+#define BLE_SVC_LLS_ALERT_LEVEL_MILD_ALERT                  1
+#define BLE_SVC_LLS_ALERT_LEVEL_HIGH_ALERT                  2
+
+typedef int ble_svc_lls_event_fn(uint8_t alert_level); 
+
+uint8_t ble_svc_lls_alert_level_get(void);
+int ble_svc_lls_alert_level_set(uint8_t alert_level);
+void ble_svc_lls_on_gap_event(struct ble_gap_event *event, void *arg); 
+
+int ble_svc_lls_init(struct ble_hs_cfg *cfg, 
+                     uint8_t initial_alert_level,
+                     ble_svc_lls_event_fn *cb);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba37dff1/net/nimble/host/profiles/lls/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/lls/pkg.yml b/net/nimble/host/profiles/lls/pkg.yml
new file mode 100644
index 0000000..5d951b6
--- /dev/null
+++ b/net/nimble/host/profiles/lls/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/lls
+pkg.description: Link Loss Service adopted specification.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble 
+    - bluetooth
+    - lls
+    - nimble 
+
+pkg.deps:
+    - net/nimble/host

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba37dff1/net/nimble/host/profiles/lls/src/ble_svc_lls.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/lls/src/ble_svc_lls.c b/net/nimble/host/profiles/lls/src/ble_svc_lls.c
new file mode 100644
index 0000000..f0fd6f1
--- /dev/null
+++ b/net/nimble/host/profiles/lls/src/ble_svc_lls.c
@@ -0,0 +1,187 @@
+/**
+ * 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/lls/ble_svc_lls.h"
+
+/* Callback function */
+ble_svc_lls_event_fn *cb_fn; 
+/* Alert level */
+uint8_t ble_svc_lls_alert_level;
+
+/* Write characteristic function */
+static int
+ble_svc_lls_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_lls_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_lls_defs[] = {
+    {
+        /*** Service: Link Loss Service (LLS). */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_SVC_LLS_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Alert Level. */
+            .uuid128 = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
+            .access_cb = ble_svc_lls_access,
+            .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+static int
+ble_svc_lls_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 read/write access callback for the alert level
+ * characteristic.
+ */
+static int
+ble_svc_lls_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    assert(ctxt->chr == &ble_svc_lls_defs[0].characteristics[0]);
+    int rc;
+    switch(ctxt->op) {
+    case BLE_GATT_ACCESS_OP_READ_CHR:
+        rc = os_mbuf_append(ctxt->om, &ble_svc_lls_alert_level,
+                            sizeof ble_svc_lls_alert_level);
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    case BLE_GATT_ACCESS_OP_WRITE_CHR:
+        rc = ble_svc_lls_chr_write(ctxt->om, 
+                                sizeof ble_svc_lls_alert_level,
+                                sizeof ble_svc_lls_alert_level,
+                                &ble_svc_lls_alert_level, NULL);
+        return rc; 
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+
+    return 0;
+}
+
+/**
+ * This function is the crux of the link loss service. The application
+ * developer must call this function inside the gap event callback
+ * function when a BLE_GAP_EVENT_DISCONNECT event is received. Here,
+ * we then check if the disconnect reason is due to a timout, and if
+ * so, we call the ble_svc_lls_event_fn callback with the current 
+ * alert level. The actual alert implementation is left up to the 
+ * developer.
+ *
+ * @param event                 The BLE GAP event from the GAP event
+ *                                  callback.
+ * @param arg                   The BLE GAP event arg from the GAP
+ *                                  event callback.
+ */
+void
+ble_svc_lls_on_gap_event(struct ble_gap_event *event, void *arg) {
+    if(event->disconnect.reason == 
+                BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) {
+            cb_fn(ble_svc_lls_alert_level);
+    } 
+}
+
+/**
+ * Get the current alert level.
+ */
+uint8_t
+ble_svc_lls_alert_level_get(void)
+{
+    return ble_svc_lls_alert_level;
+}
+
+/**
+ * Set the current alert level.
+ */
+int
+ble_svc_lls_alert_level_set(uint8_t alert_level)
+{
+    if (alert_level > BLE_SVC_LLS_ALERT_LEVEL_HIGH_ALERT) {
+        return BLE_HS_EINVAL;
+    }
+    
+    memcpy(&ble_svc_lls_alert_level, &alert_level, 
+            sizeof alert_level);
+
+    return 0;
+}
+
+/**
+ * Initialize the LLS. The developer must specify the event function
+ * callback for the LLS to function properly.
+ */
+int
+ble_svc_lls_init(struct ble_hs_cfg *cfg, uint8_t initial_alert_level,
+                 ble_svc_lls_event_fn *cb)
+{
+    if (!cb) {
+        return BLE_HS_EINVAL;
+    }
+    
+    ble_svc_lls_alert_level = initial_alert_level;
+    cb_fn = cb;
+
+    int rc;
+    rc = ble_gatts_count_cfg(ble_svc_lls_defs, cfg);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_gatts_add_svcs(ble_svc_lls_defs);
+    if (rc != 0) {
+        return rc;
+    }
+    
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba37dff1/net/nimble/profiles/include/profiles/ble_svc_lls.h
----------------------------------------------------------------------
diff --git a/net/nimble/profiles/include/profiles/ble_svc_lls.h b/net/nimble/profiles/include/profiles/ble_svc_lls.h
deleted file mode 100644
index dfc7878..0000000
--- a/net/nimble/profiles/include/profiles/ble_svc_lls.h
+++ /dev/null
@@ -1,45 +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_LLS_
-#define H_BLE_SVC_LLS_
-
-struct ble_hs_cfg;
-
-#define BLE_SVC_LLS_UUID16                                  0x1803
-#define BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL                  0x2a06
-
-/* Alert level definitions */
-#define BLE_SVC_LLS_ALERT_LEVEL_NO_ALERT                    0
-#define BLE_SVC_LLS_ALERT_LEVEL_MILD_ALERT                  1
-#define BLE_SVC_LLS_ALERT_LEVEL_HIGH_ALERT                  2
-
-typedef int ble_svc_lls_event_fn(uint8_t alert_level); 
-
-uint8_t ble_svc_lls_alert_level_get(void);
-uint8_t ble_svc_lls_alert_level_set(uint8_t alert_level);
-void ble_svc_lls_on_gap_event(struct ble_gap_event *event, void *arg); 
-
-int ble_svc_lls_register(void);
-int ble_svc_lls_init(struct ble_hs_cfg *cfg, 
-                     uint8_t initial_alert_level,
-                     ble_svc_lls_event_fn *cb);
-
-#endif
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba37dff1/net/nimble/profiles/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/profiles/pkg.yml b/net/nimble/profiles/pkg.yml
deleted file mode 100644
index 89cd9d4..0000000
--- a/net/nimble/profiles/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/profiles
-pkg.description: Adopted profiles/services of the nimble Bluetooth Smart stack.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - ble 
-    - bluetooth
-
-pkg.deps:
-    - sys/stats
-    - libs/os
-    - net/nimble

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba37dff1/net/nimble/profiles/src/ble_svc_lls.c
----------------------------------------------------------------------
diff --git a/net/nimble/profiles/src/ble_svc_lls.c b/net/nimble/profiles/src/ble_svc_lls.c
deleted file mode 100644
index fdfe377..0000000
--- a/net/nimble/profiles/src/ble_svc_lls.c
+++ /dev/null
@@ -1,166 +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/ble_svc_lls.h"
-
-/* Callback function */
-ble_svc_lls_event_fn *cb_fn; 
-/* Alert level */
-uint8_t ble_svc_lls_alert_level;
-
-/* Access function */
-static int
-ble_svc_lls_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_lls_defs[] = {
-    {
-        /*** Service: Link Loss Service (LLS). */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid128 = BLE_UUID16(BLE_SVC_LLS_UUID16),
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Characteristic: Alert Level. */
-            .uuid128 = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
-            .access_cb = ble_svc_lls_access,
-            .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
-        }, {
-            0, /* No more characteristics in this service. */
-        } },
-    },
-
-    {
-        0, /* No more services. */
-    },
-};
-
-/**
- * Simple read/write access callback for the alert level
- * characteristic.
- */
-static int
-ble_svc_lls_access(uint16_t conn_handle, uint16_t attr_handle,
-                   struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
-    assert(ctxt->chr == &ble_svc_lls_defs[0].characteristics[0]);
-    switch(ctxt->op) {
-    case BLE_GATT_ACCESS_OP_READ_CHR:
-        ctxt->att->read.data = &ble_svc_lls_alert_level;
-        ctxt->att->read.len = sizeof ble_svc_lls_alert_level;
-        break;
-
-    case BLE_GATT_ACCESS_OP_WRITE_CHR:
-        if (ctxt->att->write.len != sizeof ble_svc_lls_alert_level) {
-            return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
-        }
-        memcpy(&ble_svc_lls_alert_level, ctxt->att->write.data, 
-            sizeof ble_svc_lls_alert_level);
-        break;
-
-    default:
-        assert(0);
-        break;
-    }
-
-    return 0;
-}
-
-/**
- * This function is the crux of the link loss service. The application
- * developer must call this function inside the gap event callback
- * function when a BLE_GAP_EVENT_DISCONNECT event is received. Here,
- * we then check if the disconnect reason is due to a timout, and if
- * so, we call the ble_svc_lls_event_fn callback with the current 
- * alert level. The actual alert implementation is left up to the 
- * developer.
- *
- * @param event                 The BLE GAP event from the GAP event
- *                                  callback.
- * @param arg                   The BLE GAP event arg from the GAP
- *                                  event callback.
- */
-void
-ble_svc_lls_on_gap_event(struct ble_gap_event *event, void *arg) {
-    if(event->disconnect.reason == 
-                BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) {
-            cb_fn(ble_svc_lls_alert_level);
-    } 
-}
-
-/**
- * Get the current alert level.
- */
-uint8_t
-ble_svc_lls_alert_level_get(void)
-{
-    return ble_svc_lls_alert_level;
-}
-
-/**
- * Set the current alert level.
- */
-int
-ble_svc_lls_alert_level_set(uint8_t alert_level)
-{
-    if (alert_level > BLE_SVC_LLS_ALERT_LEVEL_HIGH_ALERT) {
-        return BLE_HS_EINVAL;
-    }
-    
-    memcpy(&ble_svc_lls_alert_level, &alert_level, 
-            sizeof alert_level);
-
-    return 0;
-}
-
-/**
- * Registers the LLS with the GATT server.
- */
-int
-ble_svc_lls_register(void)
-{
-    int rc;
-
-    rc = ble_gatts_register_svcs(ble_svc_lls_defs, NULL, NULL);
-    return rc;
-}
-
-/**
- * Initialize the LLS. The developer must specify the event function
- * callback for the LLS to function properly.
- */
-int
-ble_svc_lls_init(struct ble_hs_cfg *cfg, uint8_t initial_alert_level,
-                 ble_svc_lls_event_fn *cb)
-{
-    if (*cb) {
-        return BLE_HS_EINVAL;
-    }
-    ble_svc_lls_alert_level = initial_alert_level;
-    cb_fn = cb;
-
-    int rc;
-    rc = ble_gatts_count_cfg(ble_svc_lls_defs, cfg);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}