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/01/22 01:21:43 UTC

[1/3] incubator-mynewt-larva git commit: GATT service.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 9682532d7 -> 04087b3e3


GATT service.


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

Branch: refs/heads/master
Commit: 04087b3e3c67d8cb9e02f8379573ce44f011e8a7
Parents: 430030c
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 16:19:55 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 16:20:52 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h |  3 ++
 project/bleshell/src/bleshell_priv.h    |  1 +
 project/bleshell/src/main.c             |  1 +
 project/bleshell/src/periph.c           | 47 ++++++++++++++++++++++++++--
 4 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/04087b3e/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index 4ecdb98..f6c74d5 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -22,6 +22,9 @@
 struct ble_hs_conn;
 struct ble_att_error_rsp;
 
+#define BLE_GATT_SVC_UUID16                             0x1801
+#define BLE_GATT_CHR_SERVICE_CHANGED_UUID16             0x2a05
+
 /*** @client. */
 struct ble_gatt_error {
     uint16_t status;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/04087b3e/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index 76073f7..341bba1 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -58,6 +58,7 @@ extern const uint16_t bleshell_appearance;
 extern const uint8_t bleshell_privacy_flag;
 extern uint8_t bleshell_reconnect_addr[6];
 extern uint8_t bleshell_pref_conn_params[8];
+uint8_t bleshell_gatt_service_changed[4];
 
 void print_addr(void *addr);
 void print_uuid(void *uuid128);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/04087b3e/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index 324d0da..598186d 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -107,6 +107,7 @@ const uint16_t bleshell_appearance = BSWAP16(BLE_GAP_APPEARANCE_GEN_COMPUTER);
 const uint8_t bleshell_privacy_flag = 0;
 uint8_t bleshell_reconnect_addr[6];
 uint8_t bleshell_pref_conn_params[8];
+uint8_t bleshell_gatt_service_changed[4];
 
 static void
 bleshell_print_error(char *msg, uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/04087b3e/project/bleshell/src/periph.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/periph.c b/project/bleshell/src/periph.c
index debd3f0..68dc8a3 100644
--- a/project/bleshell/src/periph.c
+++ b/project/bleshell/src/periph.c
@@ -25,6 +25,9 @@ static uint16_t periph_chr_lens[3];
 static int
 periph_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
                       union ble_gatt_access_ctxt *ctxt, void *arg);
+static int
+periph_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                       union ble_gatt_access_ctxt *ctxt, void *arg);
 
 static int
 periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
@@ -66,6 +69,19 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
     },
 
     [1] = {
+        /*** 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_GATT_CHR_SERVICE_CHANGED_UUID16),
+            .access_cb = periph_chr_access_gatt,
+            .flags = BLE_GATT_CHR_F_INDICATE,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    [2] = {
         /*** Service 0x1234. */
         .type = BLE_GATT_SVC_TYPE_SECONDARY,
         .uuid128 = BLE_UUID16(PERIPH_SVC1_UUID),
@@ -84,12 +100,12 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
         } },
     },
 
-    [2] = {
+    [3] = {
         /*** Service 0x5678. */
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(PERIPH_SVC2_UUID),
         .includes = (const struct ble_gatt_svc_def *[]) {
-            &periph_svcs[1],
+            &periph_svcs[2],
             NULL,
         },
         .characteristics = (struct ble_gatt_chr_def[]) { {
@@ -227,6 +243,33 @@ periph_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 }
 
 static int
+periph_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                       union ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    uint16_t uuid16;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case BLE_GAP_CHR_UUID16_DEVICE_NAME:
+        assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
+        if (ctxt->chr_access.len != sizeof bleshell_gatt_service_changed) {
+            return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+        }
+        memcpy(bleshell_gatt_service_changed, ctxt->chr_access.data,
+               sizeof bleshell_gatt_service_changed);
+        break;
+
+    default:
+        assert(0);
+        break;
+    }
+
+    return 0;
+}
+
+static int
 periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
                union ble_gatt_access_ctxt *ctxt, void *arg)
 {


[2/3] incubator-mynewt-larva git commit: GAP service.

Posted by cc...@apache.org.
GAP service.


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

Branch: refs/heads/master
Commit: 430030c104c2ed22ab7c6550ca25cdf559b68cdf
Parents: 88dc6a6
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 15:38:07 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 16:20:52 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h |  54 +++++++++++++++
 net/nimble/host/src/ble_gap_conn.c     |  43 +-----------
 net/nimble/include/nimble/hci_common.h |   1 +
 project/bleshell/src/bleshell_priv.h   |   6 ++
 project/bleshell/src/main.c            |  14 ++++
 project/bleshell/src/periph.c          | 100 ++++++++++++++++++++++++++--
 6 files changed, 172 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/430030c1/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index e66adf6..d2598a7 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -22,6 +22,60 @@
 struct hci_le_conn_complete;
 struct hci_conn_update;
 
+/** 30 ms. */
+#define BLE_GAP_ADV_FAST_INTERVAL1_MIN      (30 * 1000 / BLE_HCI_ADV_ITVL)
+
+/** 60 ms. */
+#define BLE_GAP_ADV_FAST_INTERVAL1_MAX      (60 * 1000 / BLE_HCI_ADV_ITVL)
+
+/** 100 ms. */
+#define BLE_GAP_ADV_FAST_INTERVAL2_MIN      (100 * 1000 / BLE_HCI_ADV_ITVL)
+
+/** 150 ms. */
+#define BLE_GAP_ADV_FAST_INTERVAL2_MAX      (150 * 1000 / BLE_HCI_ADV_ITVL)
+
+/** 30 ms; active scanning. */
+#define BLE_GAP_SCAN_FAST_INTERVAL_MIN      (30 * 1000 / BLE_HCI_ADV_ITVL)
+
+/** 60 ms; active scanning. */
+#define BLE_GAP_SCAN_FAST_INTERVAL_MAX      (60 * 1000 / BLE_HCI_ADV_ITVL)
+
+/** 30 ms; active scanning. */
+#define BLE_GAP_SCAN_FAST_WINDOW            (30 * 1000 / BLE_HCI_SCAN_ITVL)
+
+/* 30.72 seconds; active scanning. */
+#define BLE_GAP_SCAN_FAST_PERIOD            (30.72 * 1000)
+
+/** 1.28 seconds; background scanning. */
+#define BLE_GAP_SCAN_SLOW_INTERVAL1         (1280 * 1000 / BLE_HCI_SCAN_ITVL)
+
+/** 11.25 ms; background scanning. */
+#define BLE_GAP_SCAN_SLOW_WINDOW1           (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
+
+/** 10.24 seconds. */
+#define BLE_GAP_GEN_DISC_SCAN_MIN           (10.24 * 1000)
+
+/** 1 second. */
+#define BLE_GAP_CONN_PAUSE_CENTRAL          (1 * 1000)
+
+/** 5 seconds. */
+#define BLE_GAP_CONN_PAUSE_PERIPHERAL       (5 * 1000)
+
+/* 30 ms. */
+#define BLE_GAP_INITIAL_CONN_ITVL_MIN       (30 * 1000 / BLE_HCI_CONN_ITVL)
+
+/* 50 ms. */
+#define BLE_GAP_INITIAL_CONN_ITVL_MAX       (50 * 1000 / BLE_HCI_CONN_ITVL)
+
+#define BLE_GAP_SVC_UUID16                              0x1800
+#define BLE_GAP_CHR_UUID16_DEVICE_NAME                  0x2a00
+#define BLE_GAP_CHR_UUID16_APPEARANCE                   0x2a01
+#define BLE_GAP_CHR_UUID16_PERIPH_PRIV_FLAG             0x2a02
+#define BLE_GAP_CHR_UUID16_RECONNECT_ADDR               0x2a03
+#define BLE_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS      0x2a04
+
+#define BLE_GAP_APPEARANCE_GEN_COMPUTER                 128
+
 #define BLE_GAP_ADDR_TYPE_WL                0xff
 
 #define BLE_GAP_EVENT_CONN                  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/430030c1/net/nimble/host/src/ble_gap_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_conn.c b/net/nimble/host/src/ble_gap_conn.c
index ad6c328..21c80be 100644
--- a/net/nimble/host/src/ble_gap_conn.c
+++ b/net/nimble/host/src/ble_gap_conn.c
@@ -74,45 +74,6 @@
 #define BLE_GAP_CONN_STATE_U_REPLY_ACKED                    3
 #define BLE_GAP_CONN_STATE_U_NEG_REPLY                      4
 
-/** 30 ms. */
-#define BLE_GAP_ADV_FAST_INTERVAL1_MIN      (30 * 1000 / BLE_HCI_ADV_ITVL)
-
-/** 60 ms. */
-#define BLE_GAP_ADV_FAST_INTERVAL1_MAX      (60 * 1000 / BLE_HCI_ADV_ITVL)
-
-/** 100 ms. */
-#define BLE_GAP_ADV_FAST_INTERVAL2_MIN      (100 * 1000 / BLE_HCI_ADV_ITVL)
-
-/** 150 ms. */
-#define BLE_GAP_ADV_FAST_INTERVAL2_MAX      (150 * 1000 / BLE_HCI_ADV_ITVL)
-
-/** 30 ms; active scanning. */
-#define BLE_GAP_SCAN_FAST_INTERVAL_MIN      (30 * 1000 / BLE_HCI_ADV_ITVL)
-
-/** 60 ms; active scanning. */
-#define BLE_GAP_SCAN_FAST_INTERVAL_MAX      (60 * 1000 / BLE_HCI_ADV_ITVL)
-
-/** 30 ms; active scanning. */
-#define BLE_GAP_SCAN_FAST_WINDOW            (30 * 1000 / BLE_HCI_SCAN_ITVL)
-
-/* 30.72 seconds; active scanning. */
-#define BLE_GAP_SCAN_FAST_PERIOD            (30.72 * 1000)
-
-/** 1.28 seconds; background scanning. */
-#define BLE_GAP_SCAN_SLOW_INTERVAL1         (1280 * 1000 / BLE_HCI_SCAN_ITVL)
-
-/** 11.25 ms; background scanning. */
-#define BLE_GAP_SCAN_SLOW_WINDOW1           (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
-
-/** 10.24 seconds. */
-#define BLE_GAP_GEN_DISC_SCAN_MIN           (10.24 * 1000)
-
-/** 1 second. */
-#define BLE_GAP_CONN_PAUSE_CENTRAL          (1 * 1000)
-
-/** 5 seconds. */
-#define BLE_GAP_CONN_PAUSE_PERIPHERAL       (5 * 1000)
-
 /**
  * The maximum amount of user data that can be put into the advertising data.
  * Six bytes are reserved at the end for the flags field and the transmit power
@@ -1638,8 +1599,8 @@ ble_gap_conn_create_tx(void *arg)
                sizeof hcc.peer_addr);
     }
     hcc.own_addr_type = BLE_HCI_ADV_OWN_ADDR_PUBLIC;
-    hcc.conn_itvl_min = 24;
-    hcc.conn_itvl_max = 40;
+    hcc.conn_itvl_min = BLE_GAP_INITIAL_CONN_ITVL_MIN;
+    hcc.conn_itvl_max = BLE_GAP_INITIAL_CONN_ITVL_MAX;
     hcc.conn_latency = 0;
     hcc.supervision_timeout = 0x0100; // XXX
     hcc.min_ce_len = 0x0010; // XXX

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/430030c1/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 528fbeb..607be2e 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -238,6 +238,7 @@
 
 /* Create Connection */
 #define BLE_HCI_CREATE_CONN_LEN             (25)             
+#define BLE_HCI_CONN_ITVL                   (1250)  /* usecs */
 #define BLE_HCI_CONN_FILT_NO_WL             (0)
 #define BLE_HCI_CONN_FILT_USE_WL            (1)
 #define BLE_HCI_CONN_FILT_MAX               (1)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/430030c1/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index 73219b0..76073f7 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -53,6 +53,12 @@ struct bleshell_conn {
 extern struct bleshell_conn bleshell_conns[BLESHELL_MAX_CONNS];
 extern int bleshell_num_conns;
 
+extern const char *bleshell_device_name;
+extern const uint16_t bleshell_appearance;
+extern const uint8_t bleshell_privacy_flag;
+extern uint8_t bleshell_reconnect_addr[6];
+extern uint8_t bleshell_pref_conn_params[8];
+
 void print_addr(void *addr);
 void print_uuid(void *uuid128);
 struct cmd_entry *parse_cmd_find(struct cmd_entry *cmds, char *name);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/430030c1/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index 46ea49b..324d0da 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -35,6 +35,8 @@
 #include "host/ble_gatt.h"
 #include "controller/ble_ll.h"
 
+#define BSWAP16(x)  ((uint16_t)(((x) << 8) | (((x) & 0xff00) >> 8)))
+
 /* Task 1 */
 #define HOST_TASK_PRIO          (1)
 
@@ -100,6 +102,12 @@ static struct os_mempool bleshell_chr_pool;
 static void *bleshell_dsc_mem;
 static struct os_mempool bleshell_dsc_pool;
 
+const char *bleshell_device_name = "mynewt nimble";
+const uint16_t bleshell_appearance = BSWAP16(BLE_GAP_APPEARANCE_GEN_COMPUTER);
+const uint8_t bleshell_privacy_flag = 0;
+uint8_t bleshell_reconnect_addr[6];
+uint8_t bleshell_pref_conn_params[8];
+
 static void
 bleshell_print_error(char *msg, uint16_t conn_handle,
                      struct ble_gatt_error *error)
@@ -979,6 +987,12 @@ main(void)
     rc = cmd_init();
     assert(rc == 0);
 
+    /* Initialize the preferred parameters. */
+    htole16(bleshell_pref_conn_params + 0, BLE_GAP_INITIAL_CONN_ITVL_MIN);
+    htole16(bleshell_pref_conn_params + 2, BLE_GAP_INITIAL_CONN_ITVL_MAX);
+    htole16(bleshell_pref_conn_params + 4, 0);
+    htole16(bleshell_pref_conn_params + 6, BSWAP16(0x100));
+
     /* Start the OS */
     os_start();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/430030c1/project/bleshell/src/periph.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/periph.c b/project/bleshell/src/periph.c
index ce814c1..debd3f0 100644
--- a/project/bleshell/src/periph.c
+++ b/project/bleshell/src/periph.c
@@ -2,6 +2,7 @@
 #include <string.h>
 #include "console/console.h"
 #include "host/ble_hs.h"
+#include "bleshell_priv.h"
 
 #define PERIPH_SVC1_UUID      0x1234
 #define PERIPH_SVC2_UUID      0x5678
@@ -22,11 +23,49 @@ static uint8_t periph_chr_data[3][PERIPH_CHR_MAX_LEN];
 static uint16_t periph_chr_lens[3];
 
 static int
+periph_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                      union ble_gatt_access_ctxt *ctxt, void *arg);
+
+static int
 periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
                union ble_gatt_access_ctxt *ctxt, void *arg);
 
 static const struct ble_gatt_svc_def periph_svcs[] = {
     [0] = {
+        /*** Service: GAP. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_GAP_SVC_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Device Name. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_DEVICE_NAME),
+            .access_cb = periph_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Appearance. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_APPEARANCE),
+            .access_cb = periph_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Peripheral Privacy Flag. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_PERIPH_PRIV_FLAG),
+            .access_cb = periph_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Reconnection Address. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_RECONNECT_ADDR),
+            .access_cb = periph_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_WRITE,
+        }, {
+            /*** Characteristic: Peripheral Preferred Connection Parameters. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS),
+            .access_cb = periph_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    [1] = {
         /*** Service 0x1234. */
         .type = BLE_GATT_SVC_TYPE_SECONDARY,
         .uuid128 = BLE_UUID16(PERIPH_SVC1_UUID),
@@ -41,16 +80,16 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
             .access_cb = periph_gatt_cb,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
-            .uuid128 = NULL, /* No more characteristics in this service. */
+            0, /* No more characteristics in this service. */
         } },
     },
 
-    [1] = {
+    [2] = {
         /*** Service 0x5678. */
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(PERIPH_SVC2_UUID),
         .includes = (const struct ble_gatt_svc_def *[]) {
-            &periph_svcs[0],
+            &periph_svcs[1],
             NULL,
         },
         .characteristics = (struct ble_gatt_chr_def[]) { {
@@ -59,12 +98,12 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
             .access_cb = periph_gatt_cb,
             .flags = CHR_F_FULL_ACCESS,
         }, {
-            .uuid128 = NULL, /* No more characteristics in this service. */
+            0, /* No more characteristics in this service. */
         } },
     },
 
     {
-        .type = BLE_GATT_SVC_TYPE_END, /* No more services. */
+        0, /* No more services. */
     },
 };
 
@@ -137,6 +176,57 @@ periph_gatt_write(uint16_t attr_handle, union ble_gatt_access_ctxt *ctxt,
 }
 
 static int
+periph_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                      union ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    uint16_t uuid16;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case BLE_GAP_CHR_UUID16_DEVICE_NAME:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)bleshell_device_name;
+        ctxt->chr_access.len = strlen(bleshell_device_name);
+        break;
+
+    case BLE_GAP_CHR_UUID16_APPEARANCE:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&bleshell_appearance;
+        ctxt->chr_access.len = sizeof bleshell_appearance;
+        break;
+
+    case BLE_GAP_CHR_UUID16_PERIPH_PRIV_FLAG:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&bleshell_privacy_flag;
+        ctxt->chr_access.len = sizeof bleshell_privacy_flag;
+        break;
+
+    case BLE_GAP_CHR_UUID16_RECONNECT_ADDR:
+        assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
+        if (ctxt->chr_access.len != sizeof bleshell_reconnect_addr) {
+            return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+        }
+        memcpy(bleshell_reconnect_addr, ctxt->chr_access.data,
+               sizeof bleshell_reconnect_addr);
+        break;
+
+    case BLE_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&bleshell_pref_conn_params;
+        ctxt->chr_access.len = sizeof bleshell_pref_conn_params;
+        break;
+
+    default:
+        assert(0);
+        break;
+    }
+
+    return 0;
+}
+
+static int
 periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
                union ble_gatt_access_ctxt *ctxt, void *arg)
 {


[3/3] incubator-mynewt-larva git commit: Make GATT services easier to define.

Posted by cc...@apache.org.
Make GATT services easier to define.

Terminate arrays with 0 rather than named constants.


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

Branch: refs/heads/master
Commit: 88dc6a6a690bc246ef487f444b2c670c7a2ce441
Parents: 9682532
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 15:37:13 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 16:20:52 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h         |  2 +-
 .../host/src/test/ble_gatts_notify_test.c       |  4 +-
 net/nimble/host/src/test/ble_gatts_reg_test.c   | 70 +++++++++-----------
 3 files changed, 33 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/88dc6a6a/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index 818273e..4ecdb98 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -166,9 +166,9 @@ struct ble_gatt_chr_def {
     ble_gatt_chr_flags flags;
 };
 
+#define BLE_GATT_SVC_TYPE_END       0
 #define BLE_GATT_SVC_TYPE_PRIMARY   1
 #define BLE_GATT_SVC_TYPE_SECONDARY 2
-#define BLE_GATT_SVC_TYPE_END       3
 
 struct ble_gatt_svc_def {
     uint8_t type;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/88dc6a6a/net/nimble/host/src/test/ble_gatts_notify_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_notify_test.c b/net/nimble/host/src/test/ble_gatts_notify_test.c
index cdc5a3b..87b7f29 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -53,10 +53,10 @@ static const struct ble_gatt_svc_def ble_gatts_notify_test_svcs[] = { {
         .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY |
                  BLE_GATT_CHR_F_INDICATE,
     }, {
-        .uuid128 = NULL,
+        0
     } },
 }, {
-    .type = BLE_GATT_SVC_TYPE_END,
+    0
 } };
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/88dc6a6a/net/nimble/host/src/test/ble_gatts_reg_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_reg_test.c b/net/nimble/host/src/test/ble_gatts_reg_test.c
index 32281ab..ebd9fd7 100644
--- a/net/nimble/host/src/test/ble_gatts_reg_test.c
+++ b/net/nimble/host/src/test/ble_gatts_reg_test.c
@@ -105,21 +105,11 @@ TEST_CASE(ble_gatts_reg_test_svc_return)
 
     ble_gatts_reg_test_init();
 
-    /*** Missing type. */
-    struct ble_gatt_svc_def svcs_no_type[] = { {
-        .uuid128 = BLE_UUID16(0x1234),
-    }, {
-        .type = BLE_GATT_SVC_TYPE_END,
-    } };
-
-    rc = ble_gatts_register_svcs(svcs_no_type, NULL, NULL);
-    TEST_ASSERT(rc == BLE_HS_EINVAL);
-
     /*** Missing UUID. */
     struct ble_gatt_svc_def svcs_no_uuid[] = { {
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } };
 
     rc = ble_gatts_register_svcs(svcs_no_uuid, NULL, NULL);
@@ -135,7 +125,7 @@ TEST_CASE(ble_gatts_reg_test_svc_return)
         .uuid128 = BLE_UUID16(0x1234),
         .includes = (const struct ble_gatt_svc_def*[]) { svcs_circ + 0, NULL },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } };
 
     rc = ble_gatts_register_svcs(svcs_circ, NULL, NULL);
@@ -150,7 +140,7 @@ TEST_CASE(ble_gatts_reg_test_svc_return)
         .type = BLE_GATT_SVC_TYPE_SECONDARY,
         .uuid128 = BLE_UUID16(0x1234),
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } };
 
     rc = ble_gatts_register_svcs(svcs_good, NULL, NULL);
@@ -171,10 +161,10 @@ TEST_CASE(ble_gatts_reg_test_chr_return)
             .uuid128 = BLE_UUID16(0x1111),
             .flags = BLE_GATT_CHR_F_READ,
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } };
 
     rc = ble_gatts_register_svcs(svcs_no_chr_cb, NULL, NULL);
@@ -189,10 +179,10 @@ TEST_CASE(ble_gatts_reg_test_chr_return)
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } };
 
     rc = ble_gatts_register_svcs(svcs_good, NULL, NULL);
@@ -217,13 +207,13 @@ TEST_CASE(ble_gatts_reg_test_dsc_return)
                 .uuid128 = BLE_UUID16(0x8888),
                 .att_flags = 5,
             }, {
-                .uuid128 = NULL,
+                0
             } },
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } };
 
     rc = ble_gatts_register_svcs(svcs_no_dsc_cb, NULL, NULL);
@@ -242,13 +232,13 @@ TEST_CASE(ble_gatts_reg_test_dsc_return)
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
                 .att_flags = 5,
             }, {
-                .uuid128 = NULL,
+                0
             } },
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } };
 
     rc = ble_gatts_register_svcs(svcs_good, NULL, NULL);
@@ -298,7 +288,7 @@ TEST_CASE(ble_gatts_reg_test_svc_cb)
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(0x1234),
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } });
 
     /*** 3 primary. */
@@ -312,7 +302,7 @@ TEST_CASE(ble_gatts_reg_test_svc_cb)
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(0x3234),
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } });
 
 
@@ -324,7 +314,7 @@ TEST_CASE(ble_gatts_reg_test_svc_cb)
         .type = BLE_GATT_SVC_TYPE_SECONDARY,
         .uuid128 = BLE_UUID16(0x2222),
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } });
 
     /*** 1 primary, 1 secondary, 1 include. */
@@ -338,7 +328,7 @@ TEST_CASE(ble_gatts_reg_test_svc_cb)
             .type = BLE_GATT_SVC_TYPE_SECONDARY,
             .uuid128 = BLE_UUID16(0x2222),
         }, {
-            .type = BLE_GATT_SVC_TYPE_END,
+            0
         }
     };
     ble_gatts_reg_test_misc_svcs(svcs);
@@ -355,10 +345,10 @@ TEST_CASE(ble_gatts_reg_test_chr_cb)
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } });
 
     /*** 3 characteristics. */
@@ -374,7 +364,7 @@ TEST_CASE(ble_gatts_reg_test_chr_cb)
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_WRITE,
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
         .type = BLE_GATT_SVC_TYPE_SECONDARY,
@@ -384,10 +374,10 @@ TEST_CASE(ble_gatts_reg_test_chr_cb)
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } });
 }
 
@@ -406,13 +396,13 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
-                .uuid128 = NULL,
+                0
             } },
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } });
 
     /*** 5 descriptors. */
@@ -428,14 +418,14 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
-                .uuid128 = NULL,
+                0
             } },
         }, {
             .uuid128 = BLE_UUID16(0x2222),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_WRITE,
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
         .type = BLE_GATT_SVC_TYPE_SECONDARY,
@@ -461,13 +451,13 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
-                .uuid128 = NULL,
+                0
             } },
         }, {
-            .uuid128 = NULL,
+            0
         } },
     }, {
-        .type = BLE_GATT_SVC_TYPE_END,
+        0
     } });
 }