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/23 04:19:58 UTC

[1/8] incubator-mynewt-larva git commit: Fix off-by-one bug in service end handle.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 1ede1c7dc -> 36de15d1f


Fix off-by-one bug in service end handle.


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/4bd7f86a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/4bd7f86a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/4bd7f86a

Branch: refs/heads/master
Commit: 4bd7f86adbcf940cb143f0191338c1bc3a87cd7b
Parents: f16a616
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 19:07:19 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:44 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4bd7f86a/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index e9ffb97..2f1c027 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -33,7 +33,7 @@ static uint16_t ble_att_svr_id;
 
 static struct os_mutex ble_att_svr_list_mutex;
 
-#define BLE_ATT_SVR_NUM_ENTRIES          32
+#define BLE_ATT_SVR_NUM_ENTRIES          128
 static void *ble_att_svr_entry_mem;
 static struct os_mempool ble_att_svr_entry_pool;
 
@@ -184,7 +184,7 @@ ble_att_svr_register_uuid16(uint16_t uuid16, uint8_t flags,
 uint16_t
 ble_att_svr_prev_handle(void)
 {
-    return ble_att_svr_id - 1;
+    return ble_att_svr_id;
 }
 
 /**


[6/8] incubator-mynewt-larva git commit: Reliable Writes GATT procedure.

Posted by cc...@apache.org.
Reliable Writes GATT procedure.


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/5dd3cc0d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/5dd3cc0d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/5dd3cc0d

Branch: refs/heads/master
Commit: 5dd3cc0d6d3917133d84d838706bc3bbc6fe0abb
Parents: 1ede1c7
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 13:09:08 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:44 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h        |   7 +
 net/nimble/host/src/ble_gattc.c                | 273 +++++++++++++++++++-
 net/nimble/host/src/test/ble_gatt_write_test.c | 121 +++++++++
 3 files changed, 391 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/5dd3cc0d/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 849f3a3..67332c4 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -71,6 +71,10 @@ typedef int ble_gatt_mult_attr_fn(uint16_t conn_handle,
                                   uint8_t num_attr_handles,
                                   uint8_t *attr_data, uint16_t attr_data_len,
                                   void *arg);
+typedef int ble_gatt_reliable_attr_fn(uint16_t conn_handle,
+                                      struct ble_gatt_error *error,
+                                      struct ble_gatt_attr *attrs,
+                                      uint8_t num_attrs, void *arg);
 
 typedef int ble_gatt_chr_fn(uint16_t conn_handle, struct ble_gatt_error *error,
                             struct ble_gatt_chr *chr, void *arg);
@@ -115,6 +119,9 @@ int ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
 int ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle,
                          void *value, uint16_t value_len, ble_gatt_attr_fn *cb,
                          void *cb_arg);
+int ble_gattc_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
+                             int num_attrs, ble_gatt_reliable_attr_fn *cb,
+                             void *cb_arg);
 int ble_gattc_read_dsc(uint16_t conn_handle, uint16_t attr_handle,
                        ble_gatt_attr_fn *cb, void *cb_arg);
 int ble_gattc_read_long_dsc(uint16_t conn_handle, uint16_t attr_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/5dd3cc0d/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index c0870ce..864feb6 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -52,8 +52,9 @@
 #define BLE_GATT_OP_WRITE_NO_RSP                11
 #define BLE_GATT_OP_WRITE                       12
 #define BLE_GATT_OP_WRITE_LONG                  13
-#define BLE_GATT_OP_INDICATE                    14
-#define BLE_GATT_OP_MAX                         15
+#define BLE_GATT_OP_WRITE_RELIABLE              14
+#define BLE_GATT_OP_INDICATE                    15
+#define BLE_GATT_OP_MAX                         16
 
 /** Represents an in-progress GATT procedure. */
 struct ble_gattc_proc {
@@ -158,6 +159,14 @@ struct ble_gattc_proc {
         } write_long;
 
         struct {
+            struct ble_gatt_attr *attrs;
+            int num_attrs;
+            int cur_attr;
+            ble_gatt_reliable_attr_fn *cb;
+            void *cb_arg;
+        } write_reliable;
+
+        struct {
             struct ble_gatt_attr attr;
             ble_gatt_attr_fn *cb;
             void *cb_arg;
@@ -205,6 +214,7 @@ static int ble_gattc_read_mult_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_write_no_rsp_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_write_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_write_long_kick(struct ble_gattc_proc *proc);
+static int ble_gattc_write_reliable_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_indicate_kick(struct ble_gattc_proc *proc);
 
 /**
@@ -237,6 +247,8 @@ static void ble_gattc_write_err(struct ble_gattc_proc *proc, int status,
                                 uint16_t att_handle);
 static void ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status,
                                      uint16_t att_handle);
+static void ble_gattc_write_reliable_err(struct ble_gattc_proc *proc,
+                                         int status, uint16_t att_handle);
 static void ble_gattc_indicate_err(struct ble_gattc_proc *proc, int status,
                                    uint16_t att_handle);
 
@@ -297,6 +309,16 @@ static int
 ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc,
                              struct ble_hs_conn *conn, int status);
 
+static int
+ble_gattc_write_reliable_rx_prep(struct ble_gattc_proc *proc,
+                                 struct ble_hs_conn *conn,
+                                 int status,
+                                 struct ble_att_prep_write_cmd *rsp,
+                                 void *attr_data, uint16_t attr_len);
+static int
+ble_gattc_write_reliable_rx_exec(struct ble_gattc_proc *proc,
+                                 struct ble_hs_conn *conn, int status);
+
 
 typedef int ble_gattc_rx_adata_fn(struct ble_gattc_proc *proc,
                                   struct ble_hs_conn *conn,
@@ -322,6 +344,25 @@ struct ble_gattc_rx_attr_entry {
     ble_gattc_rx_attr_fn *cb;
 };
 
+typedef int ble_gattc_rx_prep_fn(struct ble_gattc_proc *proc,
+                                 struct ble_hs_conn *conn,
+                                 int status,
+                                 struct ble_att_prep_write_cmd *rsp,
+                                 void *attr_data, uint16_t attr_len);
+
+struct ble_gattc_rx_prep_entry {
+    uint8_t op;
+    ble_gattc_rx_prep_fn *cb;
+};
+
+typedef int ble_gattc_rx_exec_fn(struct ble_gattc_proc *proc,
+                                 struct ble_hs_conn *conn, int status);
+
+struct ble_gattc_rx_exec_entry {
+    uint8_t op;
+    ble_gattc_rx_exec_fn *cb;
+};
+
 static const struct ble_gattc_rx_adata_entry
     ble_gattc_rx_read_type_elem_entries[] = {
 
@@ -346,6 +387,16 @@ static const struct ble_gattc_rx_attr_entry ble_gattc_rx_read_rsp_entries[] = {
     { BLE_GATT_OP_FIND_INC_SVCS,    ble_gattc_find_inc_svcs_rx_read_rsp },
 };
 
+static const struct ble_gattc_rx_prep_entry ble_gattc_rx_prep_entries[] = {
+    { BLE_GATT_OP_WRITE_LONG,       ble_gattc_write_long_rx_prep },
+    { BLE_GATT_OP_WRITE_RELIABLE,   ble_gattc_write_reliable_rx_prep },
+};
+
+static const struct ble_gattc_rx_exec_entry ble_gattc_rx_exec_entries[] = {
+    { BLE_GATT_OP_WRITE_LONG,       ble_gattc_write_long_rx_exec },
+    { BLE_GATT_OP_WRITE_RELIABLE,   ble_gattc_write_reliable_rx_exec },
+};
+
 /**
  * Dispatch entries - this array maps GATT procedure types to their
  * corresponding kick and error functions.
@@ -410,6 +461,10 @@ static const struct ble_gattc_dispatch_entry {
         .kick_cb = ble_gattc_write_long_kick,
         .err_cb = ble_gattc_write_long_err,
     },
+    [BLE_GATT_OP_WRITE_RELIABLE] = {
+        .kick_cb = ble_gattc_write_reliable_kick,
+        .err_cb = ble_gattc_write_reliable_err,
+    },
     [BLE_GATT_OP_INDICATE] = {
         .kick_cb = ble_gattc_indicate_kick,
         .err_cb = ble_gattc_indicate_err,
@@ -3022,7 +3077,7 @@ err:
 
 /**
  * Handles an incoming execute-write-response for the specified
- * write-long-cahracteristic-values proc.
+ * write-long-characteristic-values proc.
  */
 static int
 ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc,
@@ -3069,6 +3124,195 @@ ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle, void *value,
 }
 
 /*****************************************************************************
+ * $write reliable                                                           *
+ *****************************************************************************/
+
+/**
+ * Calls a write-long-characteristic-value proc's callback with the specified
+ * parameters.  If the proc has no callback, this function is a no-op.
+ *
+ * @return                      The return code of the callback (or 0 if there
+ *                                  is no callback).
+ */
+static int
+ble_gattc_write_reliable_cb(struct ble_gattc_proc *proc, int status,
+                            uint16_t att_handle)
+{
+    int rc;
+
+    if (proc->write_reliable.cb == NULL) {
+        rc = 0;
+    } else {
+        rc = proc->write_reliable.cb(proc->conn_handle,
+                                     ble_gattc_error(status, att_handle),
+                                     proc->write_reliable.attrs,
+                                     proc->write_reliable.num_attrs,
+                                     proc->write_reliable.cb_arg);
+    }
+
+    return rc;
+}
+
+/**
+ * Triggers a pending transmit for the specified
+ * write-reliable-characteristic-value proc.
+ */
+static int
+ble_gattc_write_reliable_kick(struct ble_gattc_proc *proc)
+{
+    struct ble_att_prep_write_cmd prep_req;
+    struct ble_att_exec_write_req exec_req;
+    struct ble_gatt_attr *attr;
+    struct ble_hs_conn *conn;
+    int attr_idx;
+    int rc;
+
+    conn = ble_hs_conn_find(proc->conn_handle);
+    if (conn == NULL) {
+        rc = BLE_HS_ENOTCONN;
+        goto err;
+    }
+
+    attr_idx = proc->write_reliable.cur_attr;
+    if (attr_idx < proc->write_reliable.num_attrs) {
+        attr = proc->write_reliable.attrs + attr_idx;
+        prep_req.bapc_handle = attr->handle;
+        prep_req.bapc_offset = 0;
+        rc = ble_att_clt_tx_prep_write(conn, &prep_req, attr->value,
+                                       attr->value_len);
+    } else {
+        exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_CONFIRM;
+        rc = ble_att_clt_tx_exec_write(conn, &exec_req);
+    }
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    if (ble_gattc_tx_postpone_chk(proc, rc)) {
+        return BLE_HS_EAGAIN;
+    }
+
+    ble_gattc_write_reliable_cb(proc, rc, 0);
+    return BLE_HS_EDONE;
+}
+
+/**
+ * Handles an incoming ATT error response for the specified
+ * write-reliable-characteristic-value proc.
+ */
+static void
+ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status,
+                             uint16_t att_handle)
+{
+    ble_gattc_write_reliable_cb(proc, status, att_handle);
+}
+
+/**
+ * Handles an incoming prepare-write-response for the specified
+ * write-reliable-cahracteristic-values proc.
+ */
+static int
+ble_gattc_write_reliable_rx_prep(struct ble_gattc_proc *proc,
+                                 struct ble_hs_conn *conn,
+                                 int status,
+                                 struct ble_att_prep_write_cmd *rsp,
+                                 void *attr_data, uint16_t attr_len)
+{
+    struct ble_gatt_attr *attr;
+    int rc;
+
+    if (status != 0) {
+        rc = status;
+        goto err;
+    }
+
+    if (proc->write_reliable.cur_attr >= proc->write_reliable.num_attrs) {
+        rc = BLE_HS_EBADDATA;
+        goto err;
+    }
+    attr = proc->write_reliable.attrs + proc->write_reliable.cur_attr;
+
+    /* Verify the response. */
+    if (rsp->bapc_handle != attr->handle) {
+        rc = BLE_HS_EBADDATA;
+        goto err;
+    }
+    if (rsp->bapc_offset != 0) {
+        rc = BLE_HS_EBADDATA;
+        goto err;
+    }
+    if (attr_len != attr->value_len) {
+        rc = BLE_HS_EBADDATA;
+        goto err;
+    }
+    if (memcmp(attr_data, attr->value, attr_len) != 0) {
+        rc = BLE_HS_EBADDATA;
+        goto err;
+    }
+
+    proc->write_reliable.cur_attr++;
+    ble_gattc_proc_set_pending(proc);
+
+    return 0;
+
+err:
+    /* XXX: Might need to cancel pending writes. */
+    ble_gattc_write_reliable_cb(proc, rc, 0);
+    return 1;
+}
+
+/**
+ * Handles an incoming execute-write-response for the specified
+ * write-reliable-characteristic-values proc.
+ */
+static int
+ble_gattc_write_reliable_rx_exec(struct ble_gattc_proc *proc,
+                                 struct ble_hs_conn *conn, int status)
+{
+    ble_gattc_write_reliable_cb(proc, status, 0);
+    return 1;
+}
+
+/**
+ * Initiates GATT procedure: Write Long Characteristic Values.
+ *
+ * @param conn_handle           The connection over which to execute the
+ *                                  procedure.
+ * @param attr_handle           The handle of the characteristic value to write
+ *                                  to.
+ * @param value                 The value to write to the characteristic.
+ * @param value_len             The number of bytes to write.
+ * @param cb                    The function to call to report procedure status
+ *                                  updates; null for no callback.
+ * @param cb_arg                The argument to pass to the callback function.
+ */
+int
+ble_gattc_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
+                         int num_attrs, ble_gatt_reliable_attr_fn *cb,
+                         void *cb_arg)
+{
+    struct ble_gattc_proc *proc;
+    int rc;
+
+    rc = ble_gattc_new_proc(conn_handle, BLE_GATT_OP_WRITE_RELIABLE, &proc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    proc->write_reliable.attrs = attrs;
+    proc->write_reliable.num_attrs = num_attrs;
+    proc->write_reliable.cur_attr = 0;
+    proc->write_reliable.cb = cb;
+    proc->write_reliable.cb_arg = cb_arg;
+    ble_gattc_proc_set_pending(proc);
+
+    return 0;
+}
+
+/*****************************************************************************
  * $notify                                                                   *
  *****************************************************************************/
 
@@ -3720,21 +3964,25 @@ ble_gattc_rx_prep_write_rsp(struct ble_hs_conn *conn, int status,
                             struct ble_att_prep_write_cmd *rsp,
                             void *attr_data, uint16_t attr_data_len)
 {
+    const struct ble_gattc_rx_prep_entry *rx_entry;
     struct ble_gattc_proc *proc;
     struct ble_gattc_proc *prev;
     int rc;
 
     ble_gattc_assert_sanity();
 
-    proc = ble_gattc_proc_find(conn->bhc_handle, BLE_GATT_OP_WRITE_LONG, 1,
-                               &prev);
+    proc = ble_gattc_proc_find(conn->bhc_handle, BLE_GATT_OP_NONE, 1, &prev);
     if (proc == NULL) {
         /* Not expecting a response from this device. */
         return;
     }
+    rx_entry = BLE_GATTC_RX_ENTRY_FIND(proc->op, ble_gattc_rx_prep_entries);
+    if (rx_entry == NULL) {
+        /* Not expecting a response from this device. */
+        return;
+    }
 
-    rc = ble_gattc_write_long_rx_prep(proc, conn, status, rsp, attr_data,
-                                      attr_data_len);
+    rc = rx_entry->cb(proc, conn, status, rsp, attr_data, attr_data_len);
     if (rc != 0) {
         ble_gattc_proc_remove_free(proc, prev);
     }
@@ -3747,20 +3995,25 @@ ble_gattc_rx_prep_write_rsp(struct ble_hs_conn *conn, int status,
 void
 ble_gattc_rx_exec_write_rsp(struct ble_hs_conn *conn, int status)
 {
+    const struct ble_gattc_rx_exec_entry *rx_entry;
     struct ble_gattc_proc *proc;
     struct ble_gattc_proc *prev;
     int rc;
 
     ble_gattc_assert_sanity();
 
-    proc = ble_gattc_proc_find(conn->bhc_handle, BLE_GATT_OP_WRITE_LONG, 1,
-                               &prev);
+    proc = ble_gattc_proc_find(conn->bhc_handle, BLE_GATT_OP_NONE, 1, &prev);
     if (proc == NULL) {
         /* Not expecting a response from this device. */
         return;
     }
+    rx_entry = BLE_GATTC_RX_ENTRY_FIND(proc->op, ble_gattc_rx_exec_entries);
+    if (rx_entry == NULL) {
+        /* Not expecting a response from this device. */
+        return;
+    }
 
-    rc = ble_gattc_write_long_rx_exec(proc, conn, status);
+    rc = rx_entry->cb(proc, conn, status);
     if (rc != 0) {
         ble_gattc_proc_remove_free(proc, prev);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/5dd3cc0d/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
index 7730b4c..019eac8 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -27,11 +27,17 @@
 #include "ble_hs_conn.h"
 #include "ble_hs_test_util.h"
 
+#define BLE_GATT_WRITE_TEST_MAX_ATTRS   128
+
 static int ble_gatt_write_test_cb_called;
 
 static uint8_t ble_gatt_write_test_attr_value[BLE_ATT_ATTR_MAX_LEN];
 static struct ble_gatt_error ble_gatt_write_test_error;
 
+static struct ble_gatt_attr *
+ble_gatt_write_test_attrs[BLE_GATT_WRITE_TEST_MAX_ATTRS];
+static int ble_gatt_write_test_num_attrs;
+
 static void
 ble_gatt_write_test_init(void)
 {
@@ -39,6 +45,7 @@ ble_gatt_write_test_init(void)
 
     ble_hs_test_util_init();
     ble_gatt_write_test_cb_called = 0;
+    ble_gatt_write_test_num_attrs = 0;
 
     for (i = 0; i < sizeof ble_gatt_write_test_attr_value; i++) {
         ble_gatt_write_test_attr_value[i] = i;
@@ -263,6 +270,74 @@ ble_gatt_write_test_misc_long_fail_length(struct ble_hs_conn *conn,
         len - 1);
 }
 
+static int
+ble_gatt_write_test_reliable_cb_good(uint16_t conn_handle,
+                                     struct ble_gatt_error *error,
+                                     struct ble_gatt_attr *attrs,
+                                     uint8_t num_attrs, void *arg)
+{
+    int i;
+
+    TEST_ASSERT_FATAL(num_attrs <= BLE_GATT_WRITE_TEST_MAX_ATTRS);
+
+    TEST_ASSERT(conn_handle == 2);
+
+    ble_gatt_write_test_num_attrs = num_attrs;
+    for (i = 0; i < num_attrs; i++) {
+        ble_gatt_write_test_attrs[i] = attrs + i;
+    }
+
+    ble_gatt_write_test_cb_called = 1;
+
+    return 0;
+}
+
+static void
+ble_gatt_write_test_misc_reliable_good(struct ble_gatt_attr *attrs)
+{
+    struct ble_hs_conn *conn;
+    int num_attrs;
+    int attr_idx;
+    int rc;
+    int i;
+
+    ble_gatt_write_test_init();
+
+    for (num_attrs = 0; attrs[num_attrs].handle != 0; num_attrs++)
+        ;
+
+    conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+                                        NULL, NULL);
+
+    rc = ble_gattc_write_reliable(conn->bhc_handle, attrs, num_attrs,
+                                  ble_gatt_write_test_reliable_cb_good, NULL);
+    TEST_ASSERT(rc == 0);
+
+    for (attr_idx = 0; attr_idx < num_attrs; attr_idx++) {
+        /* Send the pending ATT Prep Write Command. */
+        ble_hs_test_util_tx_all();
+
+        /* Receive Prep Write response. */
+        ble_gatt_write_test_rx_prep_rsp(conn, attrs[attr_idx].handle, 0,
+                                        attrs[attr_idx].value,
+                                        attrs[attr_idx].value_len);
+
+        /* Verify callback hasn't gotten called. */
+        TEST_ASSERT(!ble_gatt_write_test_cb_called);
+    }
+
+    /* Receive Exec Write response. */
+    ble_hs_test_util_tx_all();
+    ble_gatt_write_test_rx_exec_rsp(conn);
+
+    /* Verify callback got called. */
+    TEST_ASSERT(ble_gatt_write_test_cb_called);
+    TEST_ASSERT(ble_gatt_write_test_num_attrs == num_attrs);
+    for (i = 0; i < num_attrs; i++) {
+        TEST_ASSERT(ble_gatt_write_test_attrs[i] == attrs + i);
+    }
+}
+
 TEST_CASE(ble_gatt_write_test_no_rsp)
 {
     int attr_len;
@@ -401,6 +476,51 @@ TEST_CASE(ble_gatt_write_test_long_bad_length)
         ble_gatt_write_test_misc_long_fail_length);
 }
 
+TEST_CASE(ble_gatt_write_test_reliable_good)
+{
+    /*** 1 attribute. */
+    ble_gatt_write_test_misc_reliable_good(
+        ((struct ble_gatt_attr[]) { {
+            .handle = 100,
+            .value_len = 2,
+            .value = (uint8_t[]){ 1, 2 },
+        }, {
+            0
+        } }));
+
+    /*** 2 attributes. */
+    ble_gatt_write_test_misc_reliable_good(
+        ((struct ble_gatt_attr[]) { {
+            .handle = 100,
+            .value_len = 2,
+            .value = (uint8_t[]){ 1,2 },
+        }, {
+            .handle = 113,
+            .value_len = 6,
+            .value = (uint8_t[]){ 5,6,7,8,9,10 },
+        }, {
+            0
+        } }));
+
+    /*** 3 attributes. */
+    ble_gatt_write_test_misc_reliable_good(
+        ((struct ble_gatt_attr[]) { {
+            .handle = 100,
+            .value_len = 2,
+            .value = (uint8_t[]){ 1,2 },
+        }, {
+            .handle = 113,
+            .value_len = 6,
+            .value = (uint8_t[]){ 5,6,7,8,9,10 },
+        }, {
+            .handle = 144,
+            .value_len = 1,
+            .value = (uint8_t[]){ 0xff },
+        }, {
+            0
+        } }));
+}
+
 TEST_SUITE(ble_gatt_write_test_suite)
 {
     ble_gatt_write_test_no_rsp();
@@ -410,6 +530,7 @@ TEST_SUITE(ble_gatt_write_test_suite)
     ble_gatt_write_test_long_bad_offset();
     ble_gatt_write_test_long_bad_value();
     ble_gatt_write_test_long_bad_length();
+    ble_gatt_write_test_reliable_good();
 }
 
 int


[2/8] incubator-mynewt-larva git commit: Allow app to specify conn params.

Posted by cc...@apache.org.
Allow app to specify conn params.


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/eafbdeb0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/eafbdeb0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/eafbdeb0

Branch: refs/heads/master
Commit: eafbdeb0a702f4d8d4727375ee079eae88b62bfb
Parents: 13b1337
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 17:13:10 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:44 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      | 20 ++++++--
 net/nimble/host/src/ble_gap_conn.c          | 60 ++++++++++++++++--------
 net/nimble/host/src/test/ble_gap_test.c     | 28 +++++------
 net/nimble/host/src/test/ble_hs_conn_test.c |  4 +-
 net/nimble/host/src/test/ble_hs_test_util.c |  2 +-
 net/nimble/host/src/test/ble_os_test.c      | 11 +++--
 6 files changed, 80 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/eafbdeb0/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 1d8b3e1..09d7503 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -98,7 +98,18 @@ struct ble_gap_conn_desc {
     uint8_t peer_addr_type;
 };
 
-struct ble_gap_conn_params {
+struct ble_gap_conn_crt_params {
+    uint16_t scan_itvl;
+    uint16_t scan_window;
+    uint16_t itvl_min;
+    uint16_t itvl_max;
+    uint16_t latency;
+    uint16_t supervision_timeout;
+    uint16_t min_ce_len;
+    uint16_t max_ce_len;
+};
+
+struct ble_gap_conn_upd_params {
     uint16_t itvl_min;
     uint16_t itvl_max;
     uint16_t latency;
@@ -109,8 +120,8 @@ struct ble_gap_conn_params {
 
 struct ble_gap_conn_ctxt {
     struct ble_gap_conn_desc desc;
-    struct ble_gap_conn_params *peer_params;
-    struct ble_gap_conn_params *self_params;
+    struct ble_gap_conn_upd_params *peer_params;
+    struct ble_gap_conn_upd_params *self_params;
 };
 
 typedef int ble_gap_conn_fn(int event, int status,
@@ -153,6 +164,7 @@ int ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode,
                       uint8_t scan_type, uint8_t filter_policy,
                       ble_gap_disc_fn *cb, void *cb_arg);
 int ble_gap_conn_initiate(int addr_type, uint8_t *addr,
+                          struct ble_gap_conn_crt_params *params,
                           ble_gap_conn_fn *cb, void *cb_arg);
 int ble_gap_conn_terminate(uint16_t handle);
 int ble_gap_conn_cancel(void);
@@ -160,6 +172,6 @@ int ble_gap_conn_wl_set(struct ble_gap_white_entry *white_list,
                         uint8_t white_list_count, ble_gap_wl_fn *cb,
                         void *cb_arg);
 int ble_gap_conn_update_params(uint16_t conn_handle,
-                               struct ble_gap_conn_params *params);
+                               struct ble_gap_conn_upd_params *params);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/eafbdeb0/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 d8e3057..0101ff0 100644
--- a/net/nimble/host/src/ble_gap_conn.c
+++ b/net/nimble/host/src/ble_gap_conn.c
@@ -17,6 +17,7 @@
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
+#include "bsp/bsp.h"
 #include "os/os.h"
 #include "ble_hs_priv.h"
 #include "host/host_hci.h"
@@ -84,11 +85,22 @@
 
 #define BLE_GAP_CONN_MAX_UPDATES            4
 
+static const struct ble_gap_conn_crt_params ble_gap_conn_params_dflt = {
+    .scan_itvl = 0x0010,
+    .scan_window = 0x0010,
+    .itvl_min = BLE_GAP_INITIAL_CONN_ITVL_MIN,
+    .itvl_max = BLE_GAP_INITIAL_CONN_ITVL_MAX,
+    .latency = 0,
+    .supervision_timeout = 0x0100,
+    .min_ce_len = 0x0010,
+    .max_ce_len = 0x0300,
+};
+
 /**
  * The state of the in-progress master connection.  If no master connection is
  * currently in progress, then the op field is set to BLE_GAP_CONN_OP_NULL.
  */
-static struct {
+static bssnz_t struct {
     uint8_t op;
     uint8_t state;
 
@@ -96,6 +108,7 @@ static struct {
         struct {
             uint8_t addr_type;
             uint8_t addr[6];
+            struct ble_gap_conn_crt_params params;
             ble_gap_conn_fn *cb;
             void *cb_arg;
         } conn;
@@ -114,7 +127,7 @@ static struct {
  * The state of the in-progress slave connection.  If no slave connection is
  * currently in progress, then the op field is set to BLE_GAP_CONN_OP_NULL.
  */
-static struct {
+static bssnz_t struct {
     uint8_t op;
     uint8_t state;
     uint8_t disc_mode;
@@ -130,7 +143,7 @@ static struct {
     uint8_t adv_data[BLE_HCI_MAX_ADV_DATA_LEN];
 } ble_gap_conn_slave;
 
-static struct {
+static bssnz_t struct {
     ble_gap_wl_fn *cb;
     void *cb_arg;
 
@@ -143,7 +156,7 @@ static struct {
 
 struct ble_gap_conn_update_entry {
     SLIST_ENTRY(ble_gap_conn_update_entry) next;
-    struct ble_gap_conn_params params;
+    struct ble_gap_conn_upd_params params;
     uint16_t conn_handle;
     uint8_t state;
 };
@@ -223,8 +236,8 @@ ble_gap_conn_update_find(uint16_t conn_handle)
 
 static int
 ble_gap_conn_call_conn_cb(int event, int status, struct ble_hs_conn *conn,
-                          struct ble_gap_conn_params *self_params,
-                          struct ble_gap_conn_params *peer_params)
+                          struct ble_gap_conn_upd_params *self_params,
+                          struct ble_gap_conn_upd_params *peer_params)
 {
     struct ble_gap_conn_ctxt ctxt;
     ble_gap_conn_fn *cb;
@@ -1643,8 +1656,8 @@ ble_gap_conn_create_tx(void *arg)
     assert(ble_gap_conn_master.op == BLE_GAP_CONN_OP_M_CONN);
     assert(ble_gap_conn_master.state == BLE_GAP_CONN_STATE_M_PENDING);
 
-    hcc.scan_itvl = 0x0010;
-    hcc.scan_window = 0x0010;
+    hcc.scan_itvl = ble_gap_conn_master.conn.params.scan_itvl;
+    hcc.scan_window = ble_gap_conn_master.conn.params.scan_window;
 
     if (ble_gap_conn_master.conn.addr_type == BLE_GAP_ADDR_TYPE_WL) {
         hcc.filter_policy = BLE_HCI_CONN_FILT_USE_WL;
@@ -1657,12 +1670,13 @@ 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 = 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
-    hcc.max_ce_len = 0x0300; // XXX
+    hcc.conn_itvl_min = ble_gap_conn_master.conn.params.itvl_min;
+    hcc.conn_itvl_max = ble_gap_conn_master.conn.params.itvl_max;
+    hcc.conn_latency = ble_gap_conn_master.conn.params.latency;
+    hcc.supervision_timeout =
+        ble_gap_conn_master.conn.params.supervision_timeout;
+    hcc.min_ce_len = ble_gap_conn_master.conn.params.min_ce_len;
+    hcc.max_ce_len = ble_gap_conn_master.conn.params.max_ce_len;
 
     ble_gap_conn_master.state = BLE_GAP_CONN_STATE_M_UNACKED;
     ble_hci_ack_set_callback(ble_gap_conn_create_ack, NULL);
@@ -1692,6 +1706,7 @@ ble_gap_conn_create_tx(void *arg)
  */
 int
 ble_gap_conn_initiate(int addr_type, uint8_t *addr,
+                      struct ble_gap_conn_crt_params *params,
                       ble_gap_conn_fn *cb, void *cb_arg)
 {
     int rc;
@@ -1708,6 +1723,13 @@ ble_gap_conn_initiate(int addr_type, uint8_t *addr,
         return BLE_HS_EALREADY;
     }
 
+    if (params == NULL) {
+        ble_gap_conn_master.conn.params = ble_gap_conn_params_dflt;
+    } else {
+        /* XXX: Verify params. */
+        ble_gap_conn_master.conn.params = *params;
+    }
+
     ble_gap_conn_master.op = BLE_GAP_CONN_OP_M_CONN;
     ble_gap_conn_master.conn.addr_type = addr_type;
     ble_gap_conn_master.conn.cb = cb;
@@ -1858,7 +1880,7 @@ ble_gap_conn_rx_param_req(struct hci_le_conn_param_req *evt)
     struct ble_gap_conn_update_entry *entry;
     struct hci_conn_param_neg_reply neg_reply;
     struct hci_conn_param_reply pos_reply;
-    struct ble_gap_conn_params peer_params;
+    struct ble_gap_conn_upd_params peer_params;
     struct ble_hs_conn *conn;
     int rc;
 
@@ -1971,7 +1993,7 @@ ble_gap_conn_update_tx(void *arg)
 
 int
 ble_gap_conn_update_params(uint16_t conn_handle,
-                           struct ble_gap_conn_params *params)
+                           struct ble_gap_conn_upd_params *params)
 {
     struct ble_gap_conn_update_entry *entry;
     int rc;
@@ -2036,9 +2058,9 @@ ble_gap_conn_init(void)
 
     ble_gap_conn_free_mem();
 
-    ble_gap_conn_master.op = BLE_GAP_CONN_OP_NULL;
-    ble_gap_conn_slave.op = BLE_GAP_CONN_OP_NULL;
-    ble_gap_conn_wl.op = BLE_GAP_CONN_OP_NULL;
+    memset(&ble_gap_conn_master, 0, sizeof ble_gap_conn_master);
+    memset(&ble_gap_conn_slave, 0, sizeof ble_gap_conn_slave);
+    memset(&ble_gap_conn_wl, 0, sizeof ble_gap_conn_wl);
 
     ble_gap_conn_init_slave_params();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/eafbdeb0/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 15b3e05..498cca4 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -396,7 +396,7 @@ TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
     TEST_ASSERT(!ble_gap_conn_wl_busy());
 
     /*** White-list-using connection in progress. */
-    rc = ble_gap_conn_initiate(BLE_GAP_ADDR_TYPE_WL, NULL,
+    rc = ble_gap_conn_initiate(BLE_GAP_ADDR_TYPE_WL, NULL, NULL,
                                ble_gap_test_util_connect_cb, NULL);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_conn_wl_busy());
@@ -520,8 +520,8 @@ TEST_CASE(ble_gap_test_case_conn_disc_bad_args)
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 
     /*** Master operation already in progress. */
-    rc = ble_gap_conn_initiate(BLE_GAP_ADDR_TYPE_WL, NULL,
-                                     ble_gap_test_util_connect_cb, NULL);
+    rc = ble_gap_conn_initiate(BLE_GAP_ADDR_TYPE_WL, NULL, NULL,
+                               ble_gap_test_util_connect_cb, NULL);
     rc = ble_gap_conn_disc(0, BLE_GAP_DISC_MODE_GEN, BLE_HCI_SCAN_TYPE_ACTIVE,
                            BLE_HCI_SCAN_FILT_NO_WL, ble_gap_test_util_disc_cb,
                            NULL);
@@ -646,8 +646,8 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
 
     TEST_ASSERT(!ble_gap_conn_master_in_progress());
 
-    rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC, peer_addr,
-                                     ble_gap_test_util_connect_cb, NULL);
+    rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC, peer_addr, NULL,
+                               ble_gap_test_util_connect_cb, NULL);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(ble_gap_conn_master_in_progress());
@@ -689,21 +689,21 @@ TEST_CASE(ble_gap_test_case_conn_dir_bad_args)
     TEST_ASSERT(!ble_gap_conn_master_in_progress());
 
     /*** Invalid address type. */
-    rc = ble_gap_conn_initiate(5, ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }),
-                                     ble_gap_test_util_connect_cb, NULL);
+    rc = ble_gap_conn_initiate(5, ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }), NULL,
+                               ble_gap_test_util_connect_cb, NULL);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
     TEST_ASSERT(!ble_gap_conn_master_in_progress());
 
     /*** Connection already in progress. */
     rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC,
-                                     ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }),
-                                     ble_gap_test_util_connect_cb, NULL);
+                               ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }), NULL,
+                               ble_gap_test_util_connect_cb, NULL);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_conn_master_in_progress());
 
     rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC,
-                                     ((uint8_t[]){ 2, 3, 4, 5, 6, 7 }),
-                                     ble_gap_test_util_connect_cb, NULL);
+                               ((uint8_t[]){ 2, 3, 4, 5, 6, 7 }), NULL,
+                               ble_gap_test_util_connect_cb, NULL);
     TEST_ASSERT(rc == BLE_HS_EALREADY);
 }
 
@@ -718,8 +718,8 @@ TEST_CASE(ble_gap_test_case_conn_dir_bad_addr)
 
     TEST_ASSERT(!ble_gap_conn_master_in_progress());
 
-    rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC, peer_addr,
-                                     ble_gap_test_util_connect_cb, NULL);
+    rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC, peer_addr, NULL,
+                               ble_gap_test_util_connect_cb, NULL);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(ble_gap_conn_master_in_progress());
@@ -773,7 +773,7 @@ ble_gap_test_util_conn_cancel(uint8_t *peer_addr, int cmd_fail_idx,
     cmd_idx = 0;
 
     /* Begin creating a connection. */
-    rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC, peer_addr,
+    rc = ble_gap_conn_initiate(BLE_ADDR_TYPE_PUBLIC, peer_addr, NULL,
                                ble_gap_test_util_connect_cb, NULL);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_conn_master_in_progress());

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/eafbdeb0/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index deeb903..af517a2 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -45,7 +45,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
     TEST_ASSERT(ble_hs_conn_first() == NULL);
 
     /* Initiate connection. */
-    rc = ble_gap_conn_initiate(0, addr, NULL, NULL);
+    rc = ble_gap_conn_initiate(0, addr, NULL, NULL, NULL);
     TEST_ASSERT(rc == 0);
 
     ble_hci_sched_wakeup();
@@ -92,7 +92,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_hci_errors)
     TEST_ASSERT(ble_hs_conn_first() == NULL);
 
     /* Initiate connection. */
-    rc = ble_gap_conn_initiate(0, addr, NULL, NULL);
+    rc = ble_gap_conn_initiate(0, addr, NULL, NULL, NULL);
     TEST_ASSERT(rc == 0);
 
     ble_hci_sched_wakeup();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/eafbdeb0/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 4775451..f3e5e62 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -68,7 +68,7 @@ ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
     struct ble_hs_conn *conn;
     int rc;
 
-    rc = ble_gap_conn_initiate(0, addr, cb, cb_arg);
+    rc = ble_gap_conn_initiate(0, addr, NULL, cb, cb_arg);
     TEST_ASSERT(rc == 0);
 
     ble_hci_sched_wakeup();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/eafbdeb0/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index 034c8fc..7fede98 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -106,8 +106,8 @@ ble_gap_direct_connect_test_task_handler(void *arg)
     TEST_ASSERT(ble_hs_conn_first() == NULL);
 
     /* Initiate a direct connection. */
-    ble_gap_conn_initiate(0, addr, ble_gap_direct_connect_test_connect_cb,
-                          &cb_called);
+    ble_gap_conn_initiate(0, addr, NULL,
+                          ble_gap_direct_connect_test_connect_cb, &cb_called);
     TEST_ASSERT(ble_hs_conn_first() == NULL);
     TEST_ASSERT(!cb_called);
 
@@ -274,7 +274,8 @@ ble_gap_terminate_test_task_handler(void *arg)
     TEST_ASSERT(!ble_gap_conn_master_in_progress());
 
     /* Create two direct connections. */
-    ble_gap_conn_initiate(0, addr1, ble_gap_terminate_cb, &disconn_handle);
+    ble_gap_conn_initiate(0, addr1, NULL, ble_gap_terminate_cb,
+                          &disconn_handle);
     ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
     memset(&conn_evt, 0, sizeof conn_evt);
     conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
@@ -284,8 +285,8 @@ ble_gap_terminate_test_task_handler(void *arg)
     rc = ble_gap_conn_rx_conn_complete(&conn_evt);
     TEST_ASSERT(rc == 0);
 
-    ble_gap_conn_initiate(0, addr2, ble_gap_terminate_cb,
-                                &disconn_handle);
+    ble_gap_conn_initiate(0, addr2, NULL, ble_gap_terminate_cb,
+                          &disconn_handle);
     ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
     memset(&conn_evt, 0, sizeof conn_evt);
     conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;


[8/8] incubator-mynewt-larva git commit: bleshell - Alert Notification Service.

Posted by cc...@apache.org.
bleshell - Alert Notification 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/36de15d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/36de15d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/36de15d1

Branch: refs/heads/master
Commit: 36de15d1f38f4fed545bb493889afa517be40f89
Parents: e0cdc6f
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 19:08:40 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:45 2016 -0800

----------------------------------------------------------------------
 project/bleshell/src/periph.c | 133 +++++++++++++++++++++++++++++++++----
 1 file changed, 119 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/36de15d1/project/bleshell/src/periph.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/periph.c b/project/bleshell/src/periph.c
index 48fc720..c51270f 100644
--- a/project/bleshell/src/periph.c
+++ b/project/bleshell/src/periph.c
@@ -5,20 +5,27 @@
 #include "host/ble_hs.h"
 #include "bleshell_priv.h"
 
-#define PERIPH_SVC1_UUID      0x1234
-#define PERIPH_SVC2_UUID      0x5678
-#define PERIPH_CHR1_UUID      0x1111
-#define PERIPH_CHR2_UUID      0x1112
-#define PERIPH_CHR3_UUID      0x5555
-
-#define CHR_F_FULL_ACCESS (BLE_GATT_CHR_F_READ              |   \
-                           BLE_GATT_CHR_F_WRITE_NO_RSP      |   \
-                           BLE_GATT_CHR_F_WRITE             |   \
-                           BLE_GATT_CHR_F_NOTIFY            |   \
-                           BLE_GATT_CHR_F_INDICATE)
+#define PERIPH_SVC1_UUID        0x1234
+#define PERIPH_SVC2_UUID        0x5678
+#define PERIPH_CHR1_UUID        0x1111
+#define PERIPH_CHR2_UUID        0x1112
+#define PERIPH_CHR3_UUID        0x5555
+
+#define CHR_F_FULL_ACCESS       (BLE_GATT_CHR_F_READ                |   \
+                                 BLE_GATT_CHR_F_WRITE_NO_RSP        |   \
+                                 BLE_GATT_CHR_F_WRITE               |   \
+                                 BLE_GATT_CHR_F_NOTIFY              |   \
+                                 BLE_GATT_CHR_F_INDICATE)
 
 #define PERIPH_CHR_MAX_LEN  16
 
+#define PERIPH_SVC_ALERT_UUID               0x1811
+#define PERIPH_CHR_SUP_NEW_ALERT_CAT_UUID   0x2A47
+#define PERIPH_CHR_NEW_ALERT                0x2A46
+#define PERIPH_CHR_SUP_UNR_ALERT_CAT_UUID   0x2A48
+#define PERIPH_CHR_UNR_ALERT_STAT_UUID      0x2A45
+#define PERIPH_CHR_ALERT_NOT_CTRL_PT        0x2A44
+
 
 static bssnz_t uint8_t periph_chr_data[3][PERIPH_CHR_MAX_LEN];
 static bssnz_t uint16_t periph_chr_lens[3];
@@ -29,7 +36,9 @@ 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);
-
+static int
+periph_chr_access_alert(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);
@@ -83,6 +92,34 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
     },
 
     [2] = {
+        /*** Alert Notification Service. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(PERIPH_SVC_ALERT_UUID),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            .uuid128 = BLE_UUID16(PERIPH_CHR_SUP_NEW_ALERT_CAT_UUID),
+            .access_cb = periph_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            .uuid128 = BLE_UUID16(PERIPH_CHR_NEW_ALERT),
+            .access_cb = periph_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            .uuid128 = BLE_UUID16(PERIPH_CHR_SUP_UNR_ALERT_CAT_UUID),
+            .access_cb = periph_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            .uuid128 = BLE_UUID16(PERIPH_CHR_UNR_ALERT_STAT_UUID),
+            .access_cb = periph_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            .uuid128 = BLE_UUID16(PERIPH_CHR_ALERT_NOT_CTRL_PT),
+            .access_cb = periph_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_WRITE,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+    [3] = {
         /*** Service 0x1234. */
         .type = BLE_GATT_SVC_TYPE_SECONDARY,
         .uuid128 = BLE_UUID16(PERIPH_SVC1_UUID),
@@ -101,12 +138,12 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
         } },
     },
 
-    [3] = {
+    [4] = {
         /*** Service 0x5678. */
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(PERIPH_SVC2_UUID),
         .includes = (const struct ble_gatt_svc_def *[]) {
-            &periph_svcs[2],
+            &periph_svcs[3],
             NULL,
         },
         .characteristics = (struct ble_gatt_chr_def[]) { {
@@ -125,6 +162,23 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
 };
 
 static int
+periph_chr_write(uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                 uint16_t min_len, uint16_t max_len, void *dst, uint16_t *len)
+{
+    assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
+    if (ctxt->chr_access.len < min_len ||
+        ctxt->chr_access.len > max_len) {
+        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    }
+    memcpy(dst, ctxt->chr_access.data, ctxt->chr_access.len);
+    if (len != NULL) {
+        *len = ctxt->chr_access.len;
+    }
+
+    return 0;
+}
+
+static int
 periph_gatt_read(uint16_t attr_handle, union ble_gatt_access_ctxt *ctxt,
                  void *arg)
 {
@@ -270,6 +324,57 @@ periph_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
     return 0;
 }
 
+#define PERIPH_NEW_ALERT_VAL_MAX_LEN    64
+
+static const uint8_t periph_new_alert_cat = 0x01; /* Simple alert. */
+static uint8_t periph_new_alert_val[PERIPH_NEW_ALERT_VAL_MAX_LEN];
+static uint16_t periph_new_alert_val_len;
+static const uint8_t periph_unr_alert_cat = 0x01; /* Simple alert. */
+static uint16_t periph_unr_alert_stat;
+static uint16_t periph_alert_not_ctrl_pt;
+
+static int
+periph_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                        union ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    uint16_t uuid16;
+    int rc;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case PERIPH_CHR_SUP_NEW_ALERT_CAT_UUID:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&periph_new_alert_cat;
+        ctxt->chr_access.len = sizeof periph_new_alert_cat;
+        return 0;
+
+    case PERIPH_CHR_NEW_ALERT:
+        rc = periph_chr_write(op, ctxt, 0, sizeof periph_new_alert_val,
+                              periph_new_alert_val, &periph_new_alert_val_len);
+        return rc;
+
+    case PERIPH_CHR_SUP_UNR_ALERT_CAT_UUID:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&periph_unr_alert_cat;
+        ctxt->chr_access.len = sizeof periph_unr_alert_cat;
+        return 0;
+
+    case PERIPH_CHR_UNR_ALERT_STAT_UUID:
+        rc = periph_chr_write(op, ctxt, 2, 2, &periph_unr_alert_stat, NULL);
+        return rc;
+
+    case PERIPH_CHR_ALERT_NOT_CTRL_PT:
+        rc = periph_chr_write(op, ctxt, 2, 2, &periph_alert_not_ctrl_pt, NULL);
+        return rc;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+}
+
 static int
 periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
                union ble_gatt_access_ctxt *ctxt, void *arg)


[5/8] incubator-mynewt-larva git commit: Move some global data into bss.nz.

Posted by cc...@apache.org.
Move some global data into bss.nz.


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/0e04c2a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/0e04c2a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/0e04c2a5

Branch: refs/heads/master
Commit: 0e04c2a5cc7c73b38ccaebd0ef2fbfec030604b6
Parents: eafbdeb
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 17:14:46 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:44 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c |  3 ++-
 net/nimble/host/src/ble_hs.c      | 10 ++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0e04c2a5/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index e92f4b9..e9ffb97 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
+#include "bsp/bsp.h"
 #include "os/os.h"
 #include "nimble/ble.h"
 #include "host/ble_uuid.h"
@@ -49,7 +50,7 @@ static void *ble_att_svr_prep_mbuf_mem;
 static struct os_mempool ble_att_svr_prep_mbuf_mempool;
 static struct os_mbuf_pool ble_att_svr_prep_mbuf_pool;
 
-static uint8_t ble_att_svr_flat_buf[BLE_ATT_ATTR_MAX_LEN];
+static bssnz_t uint8_t ble_att_svr_flat_buf[BLE_ATT_ATTR_MAX_LEN];
 
 ble_att_svr_notify_fn *ble_att_svr_notify_cb;
 void *ble_att_svr_notify_cb_arg;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0e04c2a5/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 72d390a..e40ea82 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -16,6 +16,7 @@
 
 #include <assert.h>
 #include <errno.h>
+#include "bsp/bsp.h"
 #include "util/tpq.h"
 #include "os/os.h"
 #include "nimble/hci_transport.h"
@@ -39,13 +40,13 @@
 #endif
 
 static struct os_task ble_hs_task;
-static os_stack_t ble_hs_stack[BLE_HS_STACK_SIZE];
+static os_stack_t ble_hs_stack[BLE_HS_STACK_SIZE] bssnz_t;
 
 #define HCI_CMD_BUFS        (8)
 #define HCI_CMD_BUF_SIZE    (260)       /* XXX: temporary, Fix later */
 struct os_mempool g_hci_cmd_pool;
 static os_membuf_t g_hci_cmd_buf[OS_MEMPOOL_SIZE(HCI_CMD_BUFS,
-                                                 HCI_CMD_BUF_SIZE)];
+                                                 HCI_CMD_BUF_SIZE)] bssnz_t;
 
 /* XXX: this might be transport layer*/
 #define HCI_NUM_OS_EVENTS       (32)
@@ -61,8 +62,9 @@ static os_membuf_t g_hci_cmd_buf[OS_MEMPOOL_SIZE(HCI_CMD_BUFS,
     OS_MEMPOOL_SIZE(BLE_HS_NUM_MBUFS, BLE_HS_MBUF_MEMBLOCK_SIZE)
 
 struct os_mempool g_hci_os_event_pool;
-static os_membuf_t g_hci_os_event_buf[OS_MEMPOOL_SIZE(HCI_NUM_OS_EVENTS,
-                                                      HCI_OS_EVENT_BUF_SIZE)];
+static os_membuf_t
+    g_hci_os_event_buf[OS_MEMPOOL_SIZE(HCI_NUM_OS_EVENTS,
+                                       HCI_OS_EVENT_BUF_SIZE)] bssnz_t;
 
 static os_membuf_t ble_hs_mbuf_mem[BLE_HS_MBUF_MEMPOOL_SIZE];
 static struct os_mempool ble_hs_mbuf_mempool;


[4/8] incubator-mynewt-larva git commit: bleshell - reliable write GATT procedure.

Posted by cc...@apache.org.
bleshell - reliable write GATT procedure.


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/f16a6163
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/f16a6163
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/f16a6163

Branch: refs/heads/master
Commit: f16a6163ba72eb65ee55d35d0ebdfefb794acd81
Parents: 0e04c2a
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 17:15:58 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:44 2016 -0800

----------------------------------------------------------------------
 project/bleshell/src/bleshell_priv.h |  2 +
 project/bleshell/src/cmd.c           | 72 ++++++++++++++++++++++++-------
 project/bleshell/src/main.c          | 55 +++++++++++++++++++----
 project/bleshell/src/periph.c        |  7 +--
 4 files changed, 110 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f16a6163/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index 3cd944e..625e672 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -101,6 +101,8 @@ int bleshell_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
                           void *value, uint16_t value_len);
 int bleshell_write_long(uint16_t conn_handle, uint16_t attr_handle,
                         void *value, uint16_t value_len);
+int bleshell_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
+                            int num_attrs);
 int bleshell_adv_start(int disc, int conn, uint8_t *peer_addr, int addr_type);
 int bleshell_adv_stop(void);
 int bleshell_conn_initiate(int addr_type, uint8_t *peer_addr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f16a6163/project/bleshell/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/cmd.c b/project/bleshell/src/cmd.c
index 0b8b374..a99d9a9 100644
--- a/project/bleshell/src/cmd.c
+++ b/project/bleshell/src/cmd.c
@@ -1,5 +1,6 @@
 #include <errno.h>
 #include <string.h>
+#include "bsp/bsp.h"
 #include "console/console.h"
 #include "shell/shell.h"
 
@@ -9,8 +10,12 @@
 
 #include "bleshell_priv.h"
 
+#define CMD_BUF_SZ      1024
+
 static struct shell_cmd cmd_b;
 
+static bssnz_t uint8_t cmd_buf[CMD_BUF_SZ];
+
 /*****************************************************************************
  * $misc                                                                     *
  *****************************************************************************/
@@ -419,7 +424,7 @@ cmd_mtu(int argc, char **argv)
 static int
 cmd_read(int argc, char **argv)
 {
-    uint16_t attr_handles[CMD_READ_MAX_ATTRS];
+    static uint16_t attr_handles[CMD_READ_MAX_ATTRS];
     uint16_t conn_handle;
     uint16_t start;
     uint16_t end;
@@ -848,14 +853,17 @@ cmd_wl(int argc, char **argv)
  * $write                                                                    *
  *****************************************************************************/
 
+#define CMD_WRITE_MAX_ATTRS 16
+
 static int
 cmd_write(int argc, char **argv)
 {
-    static uint8_t attr_val[BLE_ATT_ATTR_MAX_LEN];
-    static int attr_len;
-
+    static struct ble_gatt_attr attrs[CMD_WRITE_MAX_ATTRS];
     uint16_t attr_handle;
     uint16_t conn_handle;
+    int total_attr_len;
+    int num_attrs;
+    int attr_len;
     int is_long;
     int no_rsp;
     int rc;
@@ -879,24 +887,58 @@ cmd_write(int argc, char **argv)
         return rc;
     }
 
-    attr_handle = parse_arg_long("attr", &rc);
-    if (rc != 0) {
-        return rc;
-    }
+    total_attr_len = 0;
+    num_attrs = 0;
+    while (1) {
+        attr_handle = parse_arg_long("attr", &rc);
+        if (rc == ENOENT) {
+            break;
+        } else if (rc != 0) {
+            return rc;
+        }
 
-    rc = parse_arg_byte_stream("value", sizeof attr_val, attr_val, &attr_len);
-    if (rc != 0) {
-        return rc;
+        rc = parse_arg_byte_stream("value", sizeof cmd_buf - total_attr_len,
+                                   cmd_buf + total_attr_len, &attr_len);
+        if (rc == ENOENT) {
+            break;
+        } else if (rc != 0) {
+            return rc;
+        }
+
+        if (num_attrs >= CMD_WRITE_MAX_ATTRS) {
+            return EINVAL;
+        }
+
+        attrs[num_attrs].handle = attr_handle;
+        attrs[num_attrs].offset = 0;
+        attrs[num_attrs].value_len = attr_len;
+        attrs[num_attrs].value = cmd_buf + total_attr_len;
+
+        total_attr_len += attr_len;
+        num_attrs++;
     }
 
     if (no_rsp) {
-        rc = bleshell_write_no_rsp(conn_handle, attr_handle, attr_val,
-                                   attr_len);
+        if (num_attrs != 1) {
+            return EINVAL;
+        }
+        rc = bleshell_write_no_rsp(conn_handle, attrs[0].handle,
+                                   attrs[0].value, attrs[0].value_len);
     } else if (is_long) {
-        rc = bleshell_write_long(conn_handle, attr_handle, attr_val, attr_len);
+        if (num_attrs != 1) {
+            return EINVAL;
+        }
+        rc = bleshell_write_long(conn_handle, attrs[0].handle,
+                                 attrs[0].value, attrs[0].value_len);
+    } else if (num_attrs > 1) {
+        rc = bleshell_write_reliable(conn_handle, attrs, num_attrs);
+    } else if (num_attrs == 1) {
+        rc = bleshell_write(conn_handle, attrs[0].handle,
+                            attrs[0].value, attrs[0].value_len);
     } else {
-        rc = bleshell_write(conn_handle, attr_handle, attr_val, attr_len);
+        return EINVAL;
     }
+
     if (rc != 0) {
         console_printf("error writing characteristic; rc=%d\n", rc);
         return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f16a6163/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index b5160a7..aeb3cda 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
+#include "bsp/bsp.h"
 #include "os/os.h"
 #include "bsp/bsp.h"
 #include "hal/hal_gpio.h"
@@ -75,14 +76,14 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
 #define BLESHELL_TASK_PRIO              (HOST_TASK_PRIO + 1)
 
 #define BLESHELL_MAX_SVCS               8
-#define BLESHELL_MAX_CHRS               8
-#define BLESHELL_MAX_DSCS               8
+#define BLESHELL_MAX_CHRS               32
+#define BLESHELL_MAX_DSCS               32
 
 uint32_t g_next_os_time;
 int g_bleshell_state;
 struct os_eventq g_bleshell_evq;
 struct os_task bleshell_task;
-os_stack_t bleshell_stack[BLESHELL_STACK_SIZE];
+bssnz_t os_stack_t bleshell_stack[BLESHELL_STACK_SIZE];
 
 struct bleshell_conn ble_shell_conns[BLESHELL_MAX_CONNS];
 int bleshell_num_conns;
@@ -90,7 +91,7 @@ int bleshell_num_conns;
 void
 bletest_inc_adv_pkt_num(void) { }
 
-struct bleshell_conn bleshell_conns[BLESHELL_MAX_CONNS];
+bssnz_t struct bleshell_conn bleshell_conns[BLESHELL_MAX_CONNS];
 int bleshell_num_conns;
 
 static void *bleshell_svc_mem;
@@ -284,7 +285,7 @@ bleshell_svc_add(uint16_t conn_handle, struct ble_gatt_service *gatt_svc)
     if (prev == NULL) {
         SLIST_INSERT_HEAD(&conn->svcs, svc, next);
     } else {
-        SLIST_NEXT(prev, next) = svc;
+        SLIST_INSERT_AFTER(prev, svc, next);
     }
 
     return svc;
@@ -554,12 +555,14 @@ bleshell_on_read(uint16_t conn_handle, struct ble_gatt_error *error,
     if (error != NULL) {
         bleshell_print_error("ERROR READING CHARACTERISTIC", conn_handle,
                              error);
-    } else {
-        console_printf("characteristic read complete; conn_handle=%d "
+    } else if (attr != NULL) {
+        console_printf("characteristic read; conn_handle=%d "
                        "attr_handle=%d len=%d value=", conn_handle,
                        attr->handle, attr->value_len);
         bleshell_print_bytes(attr->value, attr->value_len);
         console_printf("\n");
+    } else {
+        console_printf("characteristic read complete\n");
     }
 
     return 0;
@@ -610,6 +613,31 @@ bleshell_on_write(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
+bleshell_on_write_reliable(uint16_t conn_handle, struct ble_gatt_error *error,
+                           struct ble_gatt_attr *attrs, uint8_t num_attrs,
+                           void *arg)
+{
+    int i;
+
+    if (error != NULL) {
+        bleshell_print_error("ERROR WRITING CHARACTERISTICS RELIABLY",
+                             conn_handle, error);
+    } else {
+        console_printf("characteristic write reliable complete; "
+                       "conn_handle=%d", conn_handle);
+
+        for (i = 0; i < num_attrs; i++) {
+            console_printf(" attr_handle=%d len=%d value=", attrs[i].handle,
+                           attrs[i].value_len);
+            bleshell_print_bytes(attrs[i].value, attrs[i].value_len);
+        }
+        console_printf("\n");
+    }
+
+    return 0;
+}
+
+static int
 bleshell_on_notify(uint16_t conn_handle, uint16_t attr_handle,
                    uint8_t *attr_val, uint16_t attr_len, void *arg)
 {
@@ -850,6 +878,17 @@ bleshell_write_long(uint16_t conn_handle, uint16_t attr_handle, void *value,
 }
 
 int
+bleshell_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
+                        int num_attrs)
+{
+    int rc;
+
+    rc = ble_gattc_write_reliable(conn_handle, attrs, num_attrs,
+                                  bleshell_on_write_reliable, NULL);
+    return rc;
+}
+
+int
 bleshell_adv_stop(void)
 {
     int rc;
@@ -873,7 +912,7 @@ bleshell_conn_initiate(int addr_type, uint8_t *peer_addr)
 {
     int rc;
 
-    rc = ble_gap_conn_initiate(addr_type, peer_addr, bleshell_on_connect,
+    rc = ble_gap_conn_initiate(addr_type, peer_addr, NULL, bleshell_on_connect,
                                NULL);
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f16a6163/project/bleshell/src/periph.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/periph.c b/project/bleshell/src/periph.c
index 68dc8a3..48fc720 100644
--- a/project/bleshell/src/periph.c
+++ b/project/bleshell/src/periph.c
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <string.h>
+#include "bsp/bsp.h"
 #include "console/console.h"
 #include "host/ble_hs.h"
 #include "bleshell_priv.h"
@@ -19,8 +20,8 @@
 #define PERIPH_CHR_MAX_LEN  16
 
 
-static uint8_t periph_chr_data[3][PERIPH_CHR_MAX_LEN];
-static uint16_t periph_chr_lens[3];
+static bssnz_t uint8_t periph_chr_data[3][PERIPH_CHR_MAX_LEN];
+static bssnz_t uint16_t periph_chr_lens[3];
 
 static int
 periph_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
@@ -94,7 +95,7 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
             /*** Characteristic 0x1112. */
             .uuid128 = BLE_UUID16(PERIPH_CHR2_UUID),
             .access_cb = periph_gatt_cb,
-            .flags = BLE_GATT_CHR_F_READ,
+            .flags = CHR_F_FULL_ACCESS,
         }, {
             0, /* No more characteristics in this service. */
         } },


[7/8] incubator-mynewt-larva git commit: bleshell - Allow conn params.

Posted by cc...@apache.org.
bleshell - Allow conn params.


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/e0cdc6f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/e0cdc6f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/e0cdc6f1

Branch: refs/heads/master
Commit: e0cdc6f1cacd70f7af4409d38e6606784fe5ec08
Parents: 4bd7f86
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 19:08:24 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:45 2016 -0800

----------------------------------------------------------------------
 project/bleshell/src/bleshell_priv.h |   8 ++-
 project/bleshell/src/cmd.c           | 103 +++++++++++++++++++++++++++++-
 project/bleshell/src/main.c          |  39 +++++++++--
 project/bleshell/src/parse.c         |  16 +++++
 4 files changed, 157 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/e0cdc6f1/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index 625e672..a3de9d7 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -7,6 +7,8 @@
 #include "host/ble_gatt.h"
 struct ble_gap_white_entry;
 struct ble_hs_adv_fields;
+struct ble_gap_conn_upd_params;
+struct ble_gap_conn_crt_params;
 
 #define BLESHELL_MAX_CONNS              8
 
@@ -70,6 +72,7 @@ char *parse_arg_find(char *key);
 long parse_arg_long_bounds(char *name, long min, long max, int *out_status);
 long parse_arg_long(char *name, int *staus);
 uint16_t parse_arg_uint16(char *name, int *status);
+uint16_t parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status);
 int parse_arg_kv(char *name, struct kv_pair *kvs);
 int parse_arg_byte_stream(char *name, int max_len, uint8_t *dst, int *out_len);
 int parse_arg_mac(char *name, uint8_t *dst);
@@ -105,7 +108,8 @@ int bleshell_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
                             int num_attrs);
 int bleshell_adv_start(int disc, int conn, uint8_t *peer_addr, int addr_type);
 int bleshell_adv_stop(void);
-int bleshell_conn_initiate(int addr_type, uint8_t *peer_addr);
+int bleshell_conn_initiate(int addr_type, uint8_t *peer_addr,
+                           struct ble_gap_conn_crt_params *params);
 int bleshell_conn_cancel(void);
 int bleshell_term_conn(uint16_t conn_handle);
 int bleshell_wl_set(struct ble_gap_white_entry *white_list,
@@ -113,5 +117,7 @@ int bleshell_wl_set(struct ble_gap_white_entry *white_list,
 int bleshell_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
                   uint8_t filter_policy);
 int bleshell_set_adv_data(struct ble_hs_adv_fields *adv_fields);
+int bleshell_update_conn(uint16_t conn_handle,
+                         struct ble_gap_conn_upd_params *params);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/e0cdc6f1/project/bleshell/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/cmd.c b/project/bleshell/src/cmd.c
index a99d9a9..84b1d96 100644
--- a/project/bleshell/src/cmd.c
+++ b/project/bleshell/src/cmd.c
@@ -205,6 +205,7 @@ static struct kv_pair cmd_conn_addr_types[] = {
 static int
 cmd_conn(int argc, char **argv)
 {
+    struct ble_gap_conn_crt_params params;
     uint8_t peer_addr[6];
     int addr_type;
     int rc;
@@ -233,7 +234,49 @@ cmd_conn(int argc, char **argv)
         memset(peer_addr, 0, sizeof peer_addr);
     }
 
-    rc = bleshell_conn_initiate(addr_type, peer_addr);
+    params.scan_itvl = parse_arg_uint16_dflt("scan_itvl", 0x0010, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.scan_window = parse_arg_uint16_dflt("scan_window", 0x0010, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.itvl_min = parse_arg_uint16_dflt(
+        "itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.itvl_max = parse_arg_uint16_dflt(
+        "itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.latency = parse_arg_uint16_dflt("latency", 0, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.supervision_timeout = parse_arg_uint16_dflt("timeout", 0x0100, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.min_ce_len = parse_arg_uint16_dflt("min_ce_len", 0x0010, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.max_ce_len = parse_arg_uint16_dflt("max_ce_len", 0x0300, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bleshell_conn_initiate(addr_type, peer_addr, &params);
     if (rc != 0) {
         return rc;
     }
@@ -797,6 +840,63 @@ cmd_term(int argc, char **argv)
 }
 
 /*****************************************************************************
+ * $update connection parameters                                             *
+ *****************************************************************************/
+
+static int
+cmd_update(int argc, char **argv)
+{
+    struct ble_gap_conn_upd_params params;
+    uint16_t conn_handle;
+    int rc;
+
+    conn_handle = parse_arg_uint16("conn", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.itvl_min = parse_arg_uint16_dflt(
+        "itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.itvl_max = parse_arg_uint16_dflt(
+        "itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.latency = parse_arg_uint16_dflt("latency", 0, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.supervision_timeout = parse_arg_uint16_dflt("timeout", 0x0100, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.min_ce_len = parse_arg_uint16_dflt("min_ce_len", 0x0010, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.max_ce_len = parse_arg_uint16_dflt("max_ce_len", 0x0300, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bleshell_update_conn(conn_handle, &params);
+    if (rc != 0) {
+        console_printf("error updating connection; rc=%d\n", rc);
+        return rc;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************
  * $white list                                                               *
  *****************************************************************************/
 
@@ -962,6 +1062,7 @@ static struct cmd_entry cmd_b_entries[] = {
     { "show",       cmd_show },
     { "set",        cmd_set },
     { "term",       cmd_term },
+    { "update",     cmd_update },
     { "wl",         cmd_wl },
     { "write",      cmd_write },
     { NULL, NULL }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/e0cdc6f1/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index aeb3cda..eee88f6 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -128,6 +128,17 @@ bleshell_print_bytes(uint8_t *bytes, int len)
     }
 }
 
+static void
+bleshell_print_conn_desc(struct ble_gap_conn_desc *desc)
+{
+    console_printf("handle=%d peer_addr_type=%d peer_addr=",
+                   desc->conn_handle, desc->peer_addr_type);
+    bleshell_print_bytes(desc->peer_addr, 6);
+    console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d",
+                   desc->conn_itvl, desc->conn_latency,
+                   desc->supervision_timeout);
+}
+
 static int
 bleshell_conn_find_idx(uint16_t handle)
 {
@@ -658,12 +669,9 @@ bleshell_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
 
     switch (event) {
     case BLE_GAP_EVENT_CONN:
-        console_printf("connection complete; handle=%d status=%d "
-                       "peer_addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
-                       ctxt->desc.conn_handle, status,
-                       ctxt->desc.peer_addr[0], ctxt->desc.peer_addr[1],
-                       ctxt->desc.peer_addr[2], ctxt->desc.peer_addr[3],
-                       ctxt->desc.peer_addr[4], ctxt->desc.peer_addr[5]);
+        console_printf("connection complete; status=%d ", status);
+        bleshell_print_conn_desc(&ctxt->desc);
+        console_printf("\n");
 
         if (status == 0) {
             bleshell_conn_add(&ctxt->desc);
@@ -683,6 +691,12 @@ bleshell_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
         }
 
         break;
+
+    case BLE_GAP_EVENT_CONN_UPDATED:
+        console_printf("connection updated; status=%d ", status);
+        bleshell_print_conn_desc(&ctxt->desc);
+        console_printf("\n");
+        break;
     }
 
     return 0;
@@ -908,7 +922,8 @@ bleshell_adv_start(int disc, int conn, uint8_t *peer_addr, int addr_type)
 }
 
 int
-bleshell_conn_initiate(int addr_type, uint8_t *peer_addr)
+bleshell_conn_initiate(int addr_type, uint8_t *peer_addr,
+                       struct ble_gap_conn_crt_params *params)
 {
     int rc;
 
@@ -965,6 +980,16 @@ bleshell_set_adv_data(struct ble_hs_adv_fields *adv_fields)
     return rc;
 }
 
+int
+bleshell_update_conn(uint16_t conn_handle,
+                     struct ble_gap_conn_upd_params *params)
+{
+    int rc;
+
+    rc = ble_gap_conn_update_params(conn_handle, params);
+    return rc;
+}
+
 /**
  * BLE test task 
  * 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/e0cdc6f1/project/bleshell/src/parse.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/parse.c b/project/bleshell/src/parse.c
index 986e1c4..3d6817f 100644
--- a/project/bleshell/src/parse.c
+++ b/project/bleshell/src/parse.c
@@ -137,6 +137,22 @@ parse_arg_uint16(char *name, int *out_status)
     return parse_arg_long_bounds(name, 0, UINT16_MAX, out_status);
 }
 
+uint16_t
+parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status)
+{
+    uint16_t val;
+    int rc;
+
+    val = parse_arg_uint16(name, &rc);
+    if (rc == ENOENT) {
+        val = dflt;
+        rc = 0;
+    }
+
+    *out_status = rc;
+    return val;
+}
+
 int
 parse_arg_kv(char *name, struct kv_pair *kvs)
 {


[3/8] incubator-mynewt-larva git commit: Add "more convenient" bssnz_t macro.

Posted by cc...@apache.org.
Add "more convenient" bssnz_t macro.


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/13b13374
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/13b13374
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/13b13374

Branch: refs/heads/master
Commit: 13b133748d5a2dea2290c668d7218c38eff66351
Parents: 5dd3cc0
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Jan 22 16:00:38 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Jan 22 19:19:44 2016 -0800

----------------------------------------------------------------------
 hw/bsp/native/include/bsp/bsp.h                     | 3 +++
 hw/bsp/nrf52pdk/include/bsp/bsp.h                   | 6 +++---
 hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h | 3 +++
 hw/bsp/stm32f3discovery/include/bsp/bsp.h           | 3 +++
 4 files changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/13b13374/hw/bsp/native/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/native/include/bsp/bsp.h b/hw/bsp/native/include/bsp/bsp.h
index ce9493c..7ec0898 100644
--- a/hw/bsp/native/include/bsp/bsp.h
+++ b/hw/bsp/native/include/bsp/bsp.h
@@ -25,6 +25,9 @@ extern "C" {
 #define sec_bss_core
 #define sec_bss_nz_core
 
+/* More convenient section placement macros. */
+#define bssnz_t
+
 /* LED pins */
 #define LED_BLINK_PIN   (0x1)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/13b13374/hw/bsp/nrf52pdk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/include/bsp/bsp.h b/hw/bsp/nrf52pdk/include/bsp/bsp.h
index bcc0e05..9708b6b 100644
--- a/hw/bsp/nrf52pdk/include/bsp/bsp.h
+++ b/hw/bsp/nrf52pdk/include/bsp/bsp.h
@@ -26,15 +26,15 @@ extern "C" {
 #define sec_bss_core    __attribute__((section(".bss.core")))
 #define sec_bss_nz_core __attribute__((section(".bss.core.nz")))
 
+/* More convenient section placement macros. */
+#define bssnz_t         sec_bss_nz_core
+
 /* LED pins */
 #define LED_BLINK_PIN   (17)
 
 /* UART info */
 #define CONSOLE_UART    0
 
-/* Declaration of "non-zeroed" bss */
-#define nzbss_t   __attribute__((section(".nzbss")))
-
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/13b13374/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
index 8a8aec5..b81934a 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
+++ b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
@@ -25,6 +25,9 @@ extern "C" {
 #define sec_bss_core    __attribute__((section(".bss.core")))
 #define sec_bss_nz_core __attribute__((section(".bss.core.nz")))
 
+/* More convenient section placement macros. */
+#define bssnz_t         sec_bss_nz_core
+
 /* LED pins */
 #define LED_BLINK_PIN   (45)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/13b13374/hw/bsp/stm32f3discovery/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/include/bsp/bsp.h b/hw/bsp/stm32f3discovery/include/bsp/bsp.h
index cedd67d..d85acaa 100644
--- a/hw/bsp/stm32f3discovery/include/bsp/bsp.h
+++ b/hw/bsp/stm32f3discovery/include/bsp/bsp.h
@@ -25,6 +25,9 @@ extern "C" {
 #define sec_bss_core    __attribute__((section(".bss.core")))
 #define sec_bss_nz_core __attribute__((section(".bss.core.nz")))
 
+/* More convenient section placement macros. */
+#define bssnz_t         sec_bss_nz_core
+
 /* LED pins */
 #define LED_BLINK_PIN   (72)