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/08/10 21:13:55 UTC
[1/2] incubator-mynewt-core git commit: Refactored file structure for
premade services.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 8ec1b8d9a -> e291e12d3
Refactored file structure for premade 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/ddba2ab6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ddba2ab6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ddba2ab6
Branch: refs/heads/develop
Commit: ddba2ab6bacd04aa16151e09b93568b42b4b117e
Parents: 030dcb5
Author: Brian Giori <br...@gmail.com>
Authored: Mon Aug 1 16:44:30 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Mon Aug 1 16:44:30 2016 -0700
----------------------------------------------------------------------
apps/blecent/pkg.yml | 3 +-
apps/blecent/src/main.c | 4 +-
apps/bleprph/pkg.yml | 3 +-
apps/bleprph/src/main.c | 4 +-
apps/bletiny/pkg.yml | 3 +-
apps/bletiny/src/main.c | 4 +-
apps/bleuart/pkg.yml | 3 +-
apps/bleuart/src/main.c | 4 +-
.../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 | 201 -------------------
.../gap/include/services/gap/ble_svc_gap.h | 39 ++++
net/nimble/host/services/gap/pkg.yml | 31 +++
net/nimble/host/services/gap/src/ble_svc_gap.c | 167 +++++++++++++++
.../gatt/include/services/gatt/ble_svc_gatt.h | 29 +++
net/nimble/host/services/gatt/pkg.yml | 31 +++
.../host/services/gatt/src/ble_svc_gatt.c | 90 +++++++++
.../lls/include/services/lls/ble_svc_lls.h | 44 ++++
net/nimble/host/services/lls/pkg.yml | 31 +++
net/nimble/host/services/lls/src/ble_svc_lls.c | 201 +++++++++++++++++++
.../include/services/mandatory/ble_svc_gap.h | 39 ----
.../include/services/mandatory/ble_svc_gatt.h | 10 -
net/nimble/host/services/mandatory/pkg.yml | 32 ---
.../host/services/mandatory/src/ble_svc_gap.c | 167 ---------------
.../host/services/mandatory/src/ble_svc_gatt.c | 90 ---------
25 files changed, 679 insertions(+), 626 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/blecent/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/blecent/pkg.yml b/apps/blecent/pkg.yml
index b1710aa..2fb8be9 100644
--- a/apps/blecent/pkg.yml
+++ b/apps/blecent/pkg.yml
@@ -27,7 +27,8 @@ pkg.deps:
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
- libs/console/full
- libs/baselibc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 3cc0f24..7b43214 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -34,8 +34,8 @@
#include "store/ram/ble_store_ram.h"
/* Mandatory services. */
-#include "services/mandatory/ble_svc_gap.h"
-#include "services/mandatory/ble_svc_gatt.h"
+#include "services/gap/ble_svc_gap.h"
+#include "services/gatt/ble_svc_gatt.h"
/* Application-specified header. */
#include "blecent.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/bleprph/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bleprph/pkg.yml b/apps/bleprph/pkg.yml
index ec75359..f697d83 100644
--- a/apps/bleprph/pkg.yml
+++ b/apps/bleprph/pkg.yml
@@ -27,7 +27,8 @@ pkg.deps:
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
- libs/console/full
- libs/baselibc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 3a3d64a..6a9ae84 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -49,8 +49,8 @@
#include "store/ram/ble_store_ram.h"
/* Mandatory services. */
-#include "services/mandatory/ble_svc_gap.h"
-#include "services/mandatory/ble_svc_gatt.h"
+#include "services/gap/ble_svc_gap.h"
+#include "services/gatt/ble_svc_gatt.h"
/* Application-specified header. */
#include "bleprph.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/bletiny/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bletiny/pkg.yml b/apps/bletiny/pkg.yml
index a3c6ee7..49eba38 100644
--- a/apps/bletiny/pkg.yml
+++ b/apps/bletiny/pkg.yml
@@ -27,7 +27,8 @@ pkg.deps:
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
- libs/console/full
- libs/shell
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 733f8d1..5b1bc8c 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -51,8 +51,8 @@
#include "store/ram/ble_store_ram.h"
/* Mandatory services. */
-#include "services/mandatory/ble_svc_gap.h"
-#include "services/mandatory/ble_svc_gatt.h"
+#include "services/gap/ble_svc_gap.h"
+#include "services/gatt/ble_svc_gatt.h"
/* XXX: An app should not include private headers from a library. The bletiny
* app uses some of nimble's internal details for logging.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/bleuart/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bleuart/pkg.yml b/apps/bleuart/pkg.yml
index a79077f..dbe08cc 100644
--- a/apps/bleuart/pkg.yml
+++ b/apps/bleuart/pkg.yml
@@ -27,7 +27,8 @@ pkg.deps:
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
- libs/console/full
- libs/baselibc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index 24f1a3b..1da0ae8 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -49,8 +49,8 @@
#include "store/ram/ble_store_ram.h"
/* Mandatory services. */
-#include "services/mandatory/ble_svc_gap.h"
-#include "services/mandatory/ble_svc_gatt.h"
+#include "services/gap/ble_svc_gap.h"
+#include "services/gatt/ble_svc_gatt.h"
/** Mbuf settings. */
#define MBUF_NUM_MBUFS (12)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/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
deleted file mode 100644
index 8dee779..0000000
--- a/net/nimble/host/profiles/lls/include/profiles/lls/ble_svc_lls.h
+++ /dev/null
@@ -1,44 +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);
-int ble_svc_lls_alert_level_set(uint8_t alert_level);
-void ble_svc_lls_on_gap_disconnect(int reason);
-
-int ble_svc_lls_init(struct ble_hs_cfg *cfg,
- uint8_t initial_alert_level,
- ble_svc_lls_event_fn *cb);
-
-#endif
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/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
deleted file mode 100644
index 5d951b6..0000000
--- a/net/nimble/host/profiles/lls/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/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/ddba2ab6/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
deleted file mode 100644
index a068828..0000000
--- a/net/nimble/host/profiles/lls/src/ble_svc_lls.c
+++ /dev/null
@@ -1,201 +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/lls/ble_svc_lls.h"
-
-/* Callback function */
-static ble_svc_lls_event_fn *cb_fn;
-/* Alert level */
-static 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. */
- },
-};
-
-/**
- * Writes the received value from a characteristic write to
- * the given destination.
- */
-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 and
- * pass the disconnect reason into this function.
- *
- * 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 reason The reason attatched to the GAP disconnect
- * event.
- */
-void
-ble_svc_lls_on_gap_disconnect(int reason)
-{
- if (reason == BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) {
- cb_fn(ble_svc_lls_alert_level);
- }
-}
-
-/**
- * Gets the current alert level.
- *
- * @return The current alert level
- */
-uint8_t
-ble_svc_lls_alert_level_get(void)
-{
- return ble_svc_lls_alert_level;
-}
-
-/**
- * Sets the current alert level.
- *
- * @return 0 on success, BLE_HS_EINVAL if the given alert level is not valid.
- */
-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.
- *
- * @param initial_alert_level The initial alert value to set
- * @param cb The callback function to call when
- * connection has been lost due to
- * link loss
- */
-int
-ble_svc_lls_init(struct ble_hs_cfg *cfg, uint8_t initial_alert_level,
- ble_svc_lls_event_fn *cb)
-{
- int rc;
-
- if (!cb) {
- return BLE_HS_EINVAL;
- }
-
- ble_svc_lls_alert_level = initial_alert_level;
- cb_fn = cb;
-
- 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/ddba2ab6/net/nimble/host/services/gap/include/services/gap/ble_svc_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gap/include/services/gap/ble_svc_gap.h b/net/nimble/host/services/gap/include/services/gap/ble_svc_gap.h
new file mode 100644
index 0000000..95d4226
--- /dev/null
+++ b/net/nimble/host/services/gap/include/services/gap/ble_svc_gap.h
@@ -0,0 +1,39 @@
+/**
+ * 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_GAP_
+#define H_BLE_SVC_GAP_
+
+struct ble_hs_cfg;
+
+#define BLE_SVC_GAP_UUID16 0x1800
+#define BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME 0x2a00
+#define BLE_SVC_GAP_CHR_UUID16_APPEARANCE 0x2a01
+#define BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG 0x2a02
+#define BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR 0x2a03
+#define BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS 0x2a04
+
+#define BLE_SVC_GAP_APPEARANCE_GEN_COMPUTER 128
+
+const char *ble_svc_gap_device_name(void);
+int ble_svc_gap_device_name_set(const char *name);
+
+int ble_svc_gap_init(struct ble_hs_cfg *cfg);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/gap/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gap/pkg.yml b/net/nimble/host/services/gap/pkg.yml
new file mode 100644
index 0000000..b84e816
--- /dev/null
+++ b/net/nimble/host/services/gap/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/gap
+pkg.description: Implements the GAP Service.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - ble
+ - bluetooth
+ - nimble
+ - gap
+
+pkg.deps:
+ - net/nimble/host
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/gap/src/ble_svc_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gap/src/ble_svc_gap.c b/net/nimble/host/services/gap/src/ble_svc_gap.c
new file mode 100644
index 0000000..1a2e8a4
--- /dev/null
+++ b/net/nimble/host/services/gap/src/ble_svc_gap.c
@@ -0,0 +1,167 @@
+/**
+ * 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/gap/ble_svc_gap.h"
+
+/* XXX: This should be configurable. */
+#define BLE_SVC_GAP_NAME_MAX_LEN 31
+
+static char ble_svc_gap_name[BLE_SVC_GAP_NAME_MAX_LEN + 1] = "nimble";
+static uint16_t ble_svc_gap_appearance;
+static uint8_t ble_svc_gap_privacy_flag;
+static uint8_t ble_svc_gap_reconnect_addr[6];
+static uint8_t ble_svc_gap_pref_conn_params[8];
+
+static int
+ble_svc_gap_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_gap_defs[] = {
+ {
+ /*** Service: GAP. */
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid128 = BLE_UUID16(BLE_SVC_GAP_UUID16),
+ .characteristics = (struct ble_gatt_chr_def[]) { {
+ /*** Characteristic: Device Name. */
+ .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME),
+ .access_cb = ble_svc_gap_access,
+ .flags = BLE_GATT_CHR_F_READ,
+ }, {
+ /*** Characteristic: Appearance. */
+ .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_APPEARANCE),
+ .access_cb = ble_svc_gap_access,
+ .flags = BLE_GATT_CHR_F_READ,
+ }, {
+ /*** Characteristic: Peripheral Privacy Flag. */
+ .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG),
+ .access_cb = ble_svc_gap_access,
+ .flags = BLE_GATT_CHR_F_READ,
+ }, {
+ /*** Characteristic: Reconnection Address. */
+ .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR),
+ .access_cb = ble_svc_gap_access,
+ .flags = BLE_GATT_CHR_F_WRITE,
+ }, {
+ /*** Characteristic: Peripheral Preferred Connection Parameters. */
+ .uuid128 =
+ BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS),
+ .access_cb = ble_svc_gap_access,
+ .flags = BLE_GATT_CHR_F_READ,
+ }, {
+ 0, /* No more characteristics in this service. */
+ } },
+ },
+
+ {
+ 0, /* No more services. */
+ },
+};
+
+static int
+ble_svc_gap_access(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 BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME:
+ assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+ rc = os_mbuf_append(ctxt->om, ble_svc_gap_name,
+ strlen(ble_svc_gap_name));
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+ case BLE_SVC_GAP_CHR_UUID16_APPEARANCE:
+ assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+ rc = os_mbuf_append(ctxt->om, &ble_svc_gap_appearance,
+ sizeof ble_svc_gap_appearance);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+ case BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG:
+ assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+ rc = os_mbuf_append(ctxt->om, &ble_svc_gap_privacy_flag,
+ sizeof ble_svc_gap_privacy_flag);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+ case BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR:
+ assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR);
+ if (OS_MBUF_PKTLEN(ctxt->om) != sizeof ble_svc_gap_reconnect_addr) {
+ return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+ }
+ ble_hs_mbuf_to_flat(ctxt->om, ble_svc_gap_reconnect_addr,
+ sizeof ble_svc_gap_reconnect_addr, NULL);
+ return 0;
+
+ case BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS:
+ assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+ rc = os_mbuf_append(ctxt->om, &ble_svc_gap_pref_conn_params,
+ sizeof ble_svc_gap_pref_conn_params);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
+ }
+}
+
+const char *
+ble_svc_gap_device_name(void)
+{
+ return ble_svc_gap_name;
+}
+
+int
+ble_svc_gap_device_name_set(const char *name)
+{
+ int len;
+
+ len = strlen(name);
+ if (len > BLE_SVC_GAP_NAME_MAX_LEN) {
+ return BLE_HS_EINVAL;
+ }
+
+ memcpy(ble_svc_gap_name, name, len);
+ ble_svc_gap_name[len] = '\0';
+
+ return 0;
+}
+
+int
+ble_svc_gap_init(struct ble_hs_cfg *cfg)
+{
+ int rc;
+
+ rc = ble_gatts_count_cfg(ble_svc_gap_defs, cfg);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_gatts_add_svcs(ble_svc_gap_defs);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h b/net/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h
new file mode 100644
index 0000000..320a3ff
--- /dev/null
+++ b/net/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h
@@ -0,0 +1,29 @@
+/**
+ * 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_GATT_
+#define H_BLE_SVC_GATT_
+
+struct ble_hs_cfg;
+
+#define BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16 0x2a05
+
+int ble_svc_gatt_init(struct ble_hs_cfg *cfg);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/gatt/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gatt/pkg.yml b/net/nimble/host/services/gatt/pkg.yml
new file mode 100644
index 0000000..b8fdabe
--- /dev/null
+++ b/net/nimble/host/services/gatt/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/gatt
+pkg.description: Implements the GATT service.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - ble
+ - bluetooth
+ - nimble
+ - gatt
+
+pkg.deps:
+ - net/nimble/host
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/gatt/src/ble_svc_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gatt/src/ble_svc_gatt.c b/net/nimble/host/services/gatt/src/ble_svc_gatt.c
new file mode 100644
index 0000000..74d3ac9
--- /dev/null
+++ b/net/nimble/host/services/gatt/src/ble_svc_gatt.c
@@ -0,0 +1,90 @@
+/**
+ * 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 "host/ble_hs.h"
+#include "services/gatt/ble_svc_gatt.h"
+
+static int
+ble_svc_gatt_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_gatt_defs[] = {
+ {
+ /*** Service: GATT */
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid128 = BLE_UUID16(BLE_GATT_SVC_UUID16),
+ .characteristics = (struct ble_gatt_chr_def[]) { {
+ .uuid128 = BLE_UUID16(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16),
+ .access_cb = ble_svc_gatt_access,
+ .flags = BLE_GATT_CHR_F_INDICATE,
+ }, {
+ 0, /* No more characteristics in this service. */
+ } },
+ },
+
+ {
+ 0, /* No more services. */
+ },
+};
+
+static int
+ble_svc_gatt_access(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+ uint8_t *u8;
+
+ /* The only operation allowed for this characteristic is indicate. This
+ * access callback gets called by the stack when it needs to read the
+ * characteristic value to populate the outgoing indication command.
+ * Therefore, this callback should only get called during an attempt to
+ * read the characteristic.
+ */
+ assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+ assert(ctxt->chr == &ble_svc_gatt_defs[0].characteristics[0]);
+
+ /* XXX: For now, always respond with 0 (unchanged). */
+ u8 = os_mbuf_extend(ctxt->om, 1);
+ if (u8 == NULL) {
+ return BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
+
+ *u8 = 0;
+
+ return 0;
+}
+
+int
+ble_svc_gatt_init(struct ble_hs_cfg *cfg)
+{
+ int rc;
+
+ rc = ble_gatts_count_cfg(ble_svc_gatt_defs, cfg);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_gatts_add_svcs(ble_svc_gatt_defs);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/lls/include/services/lls/ble_svc_lls.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/lls/include/services/lls/ble_svc_lls.h b/net/nimble/host/services/lls/include/services/lls/ble_svc_lls.h
new file mode 100644
index 0000000..8dee779
--- /dev/null
+++ b/net/nimble/host/services/lls/include/services/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_disconnect(int reason);
+
+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/ddba2ab6/net/nimble/host/services/lls/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/lls/pkg.yml b/net/nimble/host/services/lls/pkg.yml
new file mode 100644
index 0000000..d45c49b
--- /dev/null
+++ b/net/nimble/host/services/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/services/lls
+pkg.description: Link Loss Service Implementation.
+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/ddba2ab6/net/nimble/host/services/lls/src/ble_svc_lls.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/lls/src/ble_svc_lls.c b/net/nimble/host/services/lls/src/ble_svc_lls.c
new file mode 100644
index 0000000..3371fda
--- /dev/null
+++ b/net/nimble/host/services/lls/src/ble_svc_lls.c
@@ -0,0 +1,201 @@
+/**
+ * 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/lls/ble_svc_lls.h"
+
+/* Callback function */
+static ble_svc_lls_event_fn *cb_fn;
+/* Alert level */
+static 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. */
+ },
+};
+
+/**
+ * Writes the received value from a characteristic write to
+ * the given destination.
+ */
+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 and
+ * pass the disconnect reason into this function.
+ *
+ * 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 reason The reason attatched to the GAP disconnect
+ * event.
+ */
+void
+ble_svc_lls_on_gap_disconnect(int reason)
+{
+ if (reason == BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) {
+ cb_fn(ble_svc_lls_alert_level);
+ }
+}
+
+/**
+ * Gets the current alert level.
+ *
+ * @return The current alert level
+ */
+uint8_t
+ble_svc_lls_alert_level_get(void)
+{
+ return ble_svc_lls_alert_level;
+}
+
+/**
+ * Sets the current alert level.
+ *
+ * @return 0 on success, BLE_HS_EINVAL if the given alert level is not valid.
+ */
+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.
+ *
+ * @param initial_alert_level The initial alert value to set
+ * @param cb The callback function to call when
+ * connection has been lost due to
+ * link loss
+ */
+int
+ble_svc_lls_init(struct ble_hs_cfg *cfg, uint8_t initial_alert_level,
+ ble_svc_lls_event_fn *cb)
+{
+ int rc;
+
+ if (!cb) {
+ return BLE_HS_EINVAL;
+ }
+
+ ble_svc_lls_alert_level = initial_alert_level;
+ cb_fn = cb;
+
+ 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/ddba2ab6/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h b/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h
deleted file mode 100644
index 95d4226..0000000
--- a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h
+++ /dev/null
@@ -1,39 +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_GAP_
-#define H_BLE_SVC_GAP_
-
-struct ble_hs_cfg;
-
-#define BLE_SVC_GAP_UUID16 0x1800
-#define BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME 0x2a00
-#define BLE_SVC_GAP_CHR_UUID16_APPEARANCE 0x2a01
-#define BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG 0x2a02
-#define BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR 0x2a03
-#define BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS 0x2a04
-
-#define BLE_SVC_GAP_APPEARANCE_GEN_COMPUTER 128
-
-const char *ble_svc_gap_device_name(void);
-int ble_svc_gap_device_name_set(const char *name);
-
-int ble_svc_gap_init(struct ble_hs_cfg *cfg);
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h b/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h
deleted file mode 100644
index d2438c2..0000000
--- a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef H_BLE_SVC_GATT_
-#define H_BLE_SVC_GATT_
-
-struct ble_hs_cfg;
-
-#define BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16 0x2a05
-
-int ble_svc_gatt_init(struct ble_hs_cfg *cfg);
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/mandatory/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/pkg.yml b/net/nimble/host/services/mandatory/pkg.yml
deleted file mode 100644
index b63c634..0000000
--- a/net/nimble/host/services/mandatory/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/services/mandatory
-pkg.description: Implements the two mandatory GATT services (GAP and GATT).
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
- - ble
- - bluetooth
- - nimble
- - gatt
- - gap
-
-pkg.deps:
- - net/nimble/host
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/mandatory/src/ble_svc_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/src/ble_svc_gap.c b/net/nimble/host/services/mandatory/src/ble_svc_gap.c
deleted file mode 100644
index d49396d..0000000
--- a/net/nimble/host/services/mandatory/src/ble_svc_gap.c
+++ /dev/null
@@ -1,167 +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 "services/mandatory/ble_svc_gap.h"
-
-/* XXX: This should be configurable. */
-#define BLE_SVC_GAP_NAME_MAX_LEN 31
-
-static char ble_svc_gap_name[BLE_SVC_GAP_NAME_MAX_LEN + 1] = "nimble";
-static uint16_t ble_svc_gap_appearance;
-static uint8_t ble_svc_gap_privacy_flag;
-static uint8_t ble_svc_gap_reconnect_addr[6];
-static uint8_t ble_svc_gap_pref_conn_params[8];
-
-static int
-ble_svc_gap_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_gap_defs[] = {
- {
- /*** Service: GAP. */
- .type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_UUID16),
- .characteristics = (struct ble_gatt_chr_def[]) { {
- /*** Characteristic: Device Name. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME),
- .access_cb = ble_svc_gap_access,
- .flags = BLE_GATT_CHR_F_READ,
- }, {
- /*** Characteristic: Appearance. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_APPEARANCE),
- .access_cb = ble_svc_gap_access,
- .flags = BLE_GATT_CHR_F_READ,
- }, {
- /*** Characteristic: Peripheral Privacy Flag. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG),
- .access_cb = ble_svc_gap_access,
- .flags = BLE_GATT_CHR_F_READ,
- }, {
- /*** Characteristic: Reconnection Address. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR),
- .access_cb = ble_svc_gap_access,
- .flags = BLE_GATT_CHR_F_WRITE,
- }, {
- /*** Characteristic: Peripheral Preferred Connection Parameters. */
- .uuid128 =
- BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS),
- .access_cb = ble_svc_gap_access,
- .flags = BLE_GATT_CHR_F_READ,
- }, {
- 0, /* No more characteristics in this service. */
- } },
- },
-
- {
- 0, /* No more services. */
- },
-};
-
-static int
-ble_svc_gap_access(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 BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME:
- assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
- rc = os_mbuf_append(ctxt->om, ble_svc_gap_name,
- strlen(ble_svc_gap_name));
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
- case BLE_SVC_GAP_CHR_UUID16_APPEARANCE:
- assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
- rc = os_mbuf_append(ctxt->om, &ble_svc_gap_appearance,
- sizeof ble_svc_gap_appearance);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
- case BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG:
- assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
- rc = os_mbuf_append(ctxt->om, &ble_svc_gap_privacy_flag,
- sizeof ble_svc_gap_privacy_flag);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
- case BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR:
- assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR);
- if (OS_MBUF_PKTLEN(ctxt->om) != sizeof ble_svc_gap_reconnect_addr) {
- return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
- }
- ble_hs_mbuf_to_flat(ctxt->om, ble_svc_gap_reconnect_addr,
- sizeof ble_svc_gap_reconnect_addr, NULL);
- return 0;
-
- case BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS:
- assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
- rc = os_mbuf_append(ctxt->om, &ble_svc_gap_pref_conn_params,
- sizeof ble_svc_gap_pref_conn_params);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
- default:
- assert(0);
- return BLE_ATT_ERR_UNLIKELY;
- }
-}
-
-const char *
-ble_svc_gap_device_name(void)
-{
- return ble_svc_gap_name;
-}
-
-int
-ble_svc_gap_device_name_set(const char *name)
-{
- int len;
-
- len = strlen(name);
- if (len > BLE_SVC_GAP_NAME_MAX_LEN) {
- return BLE_HS_EINVAL;
- }
-
- memcpy(ble_svc_gap_name, name, len);
- ble_svc_gap_name[len] = '\0';
-
- return 0;
-}
-
-int
-ble_svc_gap_init(struct ble_hs_cfg *cfg)
-{
- int rc;
-
- rc = ble_gatts_count_cfg(ble_svc_gap_defs, cfg);
- if (rc != 0) {
- return rc;
- }
-
- rc = ble_gatts_add_svcs(ble_svc_gap_defs);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddba2ab6/net/nimble/host/services/mandatory/src/ble_svc_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/src/ble_svc_gatt.c b/net/nimble/host/services/mandatory/src/ble_svc_gatt.c
deleted file mode 100644
index 0e8a139..0000000
--- a/net/nimble/host/services/mandatory/src/ble_svc_gatt.c
+++ /dev/null
@@ -1,90 +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 "host/ble_hs.h"
-#include "services/mandatory/ble_svc_gatt.h"
-
-static int
-ble_svc_gatt_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_gatt_defs[] = {
- {
- /*** Service: GATT */
- .type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_GATT_SVC_UUID16),
- .characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid128 = BLE_UUID16(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16),
- .access_cb = ble_svc_gatt_access,
- .flags = BLE_GATT_CHR_F_INDICATE,
- }, {
- 0, /* No more characteristics in this service. */
- } },
- },
-
- {
- 0, /* No more services. */
- },
-};
-
-static int
-ble_svc_gatt_access(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
- uint8_t *u8;
-
- /* The only operation allowed for this characteristic is indicate. This
- * access callback gets called by the stack when it needs to read the
- * characteristic value to populate the outgoing indication command.
- * Therefore, this callback should only get called during an attempt to
- * read the characteristic.
- */
- assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
- assert(ctxt->chr == &ble_svc_gatt_defs[0].characteristics[0]);
-
- /* XXX: For now, always respond with 0 (unchanged). */
- u8 = os_mbuf_extend(ctxt->om, 1);
- if (u8 == NULL) {
- return BLE_ATT_ERR_INSUFFICIENT_RES;
- }
-
- *u8 = 0;
-
- return 0;
-}
-
-int
-ble_svc_gatt_init(struct ble_hs_cfg *cfg)
-{
- int rc;
-
- rc = ble_gatts_count_cfg(ble_svc_gatt_defs, cfg);
- if (rc != 0) {
- return rc;
- }
-
- rc = ble_gatts_add_svcs(ble_svc_gatt_defs);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
[2/2] incubator-mynewt-core git commit: This closes #88. Merge
remote-tracking branch 'bgiori/refactor-services' into develop
Posted by cc...@apache.org.
This closes #88.
Merge remote-tracking branch 'bgiori/refactor-services' into develop
* bgiori/refactor-services:
Refactored file structure for premade 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/e291e12d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e291e12d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e291e12d
Branch: refs/heads/develop
Commit: e291e12d37c24f3124553dea454b303d561a7cb2
Parents: 8ec1b8d ddba2ab
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Aug 10 14:13:31 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Aug 10 14:13:31 2016 -0700
----------------------------------------------------------------------
apps/blecent/pkg.yml | 3 +-
apps/blecent/src/main.c | 4 +-
apps/bleprph/pkg.yml | 3 +-
apps/bleprph/src/main.c | 4 +-
apps/bletiny/pkg.yml | 3 +-
apps/bletiny/src/main.c | 4 +-
apps/bleuart/pkg.yml | 3 +-
apps/bleuart/src/main.c | 4 +-
.../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 | 201 -------------------
.../gap/include/services/gap/ble_svc_gap.h | 39 ++++
net/nimble/host/services/gap/pkg.yml | 31 +++
net/nimble/host/services/gap/src/ble_svc_gap.c | 167 +++++++++++++++
.../gatt/include/services/gatt/ble_svc_gatt.h | 29 +++
net/nimble/host/services/gatt/pkg.yml | 31 +++
.../host/services/gatt/src/ble_svc_gatt.c | 90 +++++++++
.../lls/include/services/lls/ble_svc_lls.h | 44 ++++
net/nimble/host/services/lls/pkg.yml | 31 +++
net/nimble/host/services/lls/src/ble_svc_lls.c | 201 +++++++++++++++++++
.../include/services/mandatory/ble_svc_gap.h | 39 ----
.../include/services/mandatory/ble_svc_gatt.h | 10 -
net/nimble/host/services/mandatory/pkg.yml | 32 ---
.../host/services/mandatory/src/ble_svc_gap.c | 167 ---------------
.../host/services/mandatory/src/ble_svc_gatt.c | 90 ---------
25 files changed, 679 insertions(+), 626 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/blecent/pkg.yml
----------------------------------------------------------------------
diff --cc apps/blecent/pkg.yml
index 3798fee,2fb8be9..b413fad
--- a/apps/blecent/pkg.yml
+++ b/apps/blecent/pkg.yml
@@@ -27,9 -27,9 +27,10 @@@ pkg.deps
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/baselibc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/blecent/src/main.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/bleprph/pkg.yml
----------------------------------------------------------------------
diff --cc apps/bleprph/pkg.yml
index 7c45ee2,f697d83..cfc8e3b
--- a/apps/bleprph/pkg.yml
+++ b/apps/bleprph/pkg.yml
@@@ -27,9 -27,9 +27,10 @@@ pkg.deps
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/baselibc
- libs/newtmgr
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --cc apps/bleprph/src/main.c
index 961ed4b,6a9ae84..b08b077
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@@ -48,13 -49,9 +48,13 @@@
#include "store/ram/ble_store_ram.h"
/* Mandatory services. */
- #include "services/mandatory/ble_svc_gap.h"
- #include "services/mandatory/ble_svc_gatt.h"
+ #include "services/gap/ble_svc_gap.h"
+ #include "services/gatt/ble_svc_gatt.h"
+/* Newtmgr include */
+#include "newtmgr/newtmgr.h"
+#include "nmgrble/newtmgr_ble.h"
+
/* Application-specified header. */
#include "bleprph.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/bletiny/pkg.yml
----------------------------------------------------------------------
diff --cc apps/bletiny/pkg.yml
index 625adc6,49eba38..9a8b08f
--- a/apps/bletiny/pkg.yml
+++ b/apps/bletiny/pkg.yml
@@@ -27,9 -27,9 +27,10 @@@ pkg.deps
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/shell
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/bletiny/src/main.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/bleuart/pkg.yml
----------------------------------------------------------------------
diff --cc apps/bleuart/pkg.yml
index c93011b,dbe08cc..7a7d20e
--- a/apps/bleuart/pkg.yml
+++ b/apps/bleuart/pkg.yml
@@@ -27,9 -27,9 +27,10 @@@ pkg.deps
- sys/log
- net/nimble/controller
- net/nimble/host
- - net/nimble/host/services/mandatory
+ - net/nimble/host/services/gap
+ - net/nimble/host/services/gatt
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/baselibc
- libs/newtmgr
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e291e12d/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --cc apps/bleuart/src/main.c
index 061ab3b,1da0ae8..264be92
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@@ -47,14 -49,9 +47,14 @@@
#include "store/ram/ble_store_ram.h"
/* Mandatory services. */
- #include "services/mandatory/ble_svc_gap.h"
- #include "services/mandatory/ble_svc_gatt.h"
+ #include "services/gap/ble_svc_gap.h"
+ #include "services/gatt/ble_svc_gatt.h"
+/* Newtmgr include */
+#include "newtmgr/newtmgr.h"
+#include "nmgrble/newtmgr_ble.h"
+#include "bleuart/bleuart.h"
+
/** Mbuf settings. */
#define MBUF_NUM_MBUFS (12)
#define MBUF_BUF_SIZE OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)