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/07/24 19:02:47 UTC

[1/3] incubator-mynewt-core git commit: BLE Host - Fix default ble_hs configuration.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop cc329cf85 -> 195c7d62e


BLE Host - Fix default ble_hs configuration.

This commit includes the following changes:

* Set default max_l2cap_chans to: (3 * max_connections).  This is
  exactly the number of required channels, and is the only logical value
  to use since we don't support connection-oriented channels yet.  Prior
  to this change, this setting was arbitrarily set to 16.

* Set all default GATT server resource counts to 0.  The expectation is
  that these values will be increased as appropriate as GATT services
  are initialized.

* Reduce some overly-ambitious numbers to defaults that are more
  realistic:

      o max_gattc_procs:        16 --> 4
      o max_l2cap_sig_procs:    8  --> 1


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

Branch: refs/heads/develop
Commit: db3c76b3293d05b8b1ad8380384e49e6daf0eea1
Parents: cc329cf
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Jul 24 11:55:06 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sun Jul 24 11:55:06 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_cfg.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/db3c76b3/net/nimble/host/src/ble_hs_cfg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_cfg.c b/net/nimble/host/src/ble_hs_cfg.c
index 6fe0236..87ede16 100644
--- a/net/nimble/host/src/ble_hs_cfg.c
+++ b/net/nimble/host/src/ble_hs_cfg.c
@@ -19,31 +19,38 @@
 
 #include "ble_hs_priv.h"
 
+#if NIMBLE_OPT(CONNECT)
+#define BLE_HS_CFG_MAX_CONNECTIONS NIMBLE_OPT(MAX_CONNECTIONS)
+#else
+#define BLE_HS_CFG_MAX_CONNECTIONS 0
+#endif
+
 const struct ble_hs_cfg ble_hs_cfg_dflt = {
     /** HCI settings. */
     .max_hci_bufs = 8,
 
     /** Connection settings. */
-#if NIMBLE_OPT(CONNECT)
-    .max_connections = NIMBLE_OPT(MAX_CONNECTIONS),
-#else
-    .max_connections = 0,
-#endif
+    .max_connections = BLE_HS_CFG_MAX_CONNECTIONS,
 
     /** GATT server settings. */
-    .max_services = 16,
-    .max_client_configs = 32,
+    /* These get set to zero with the expectation that they will be increased
+     * as needed when each supported GATT service is initialized.
+     */
+    .max_services = 0,
+    .max_client_configs = 0,
 
     /** GATT client settings. */
-    .max_gattc_procs = 16,
+    .max_gattc_procs = 4,
 
     /** ATT server settings. */
-    .max_attrs = 64,
+    /* This is set to 0; see note above re: GATT server settings. */
+    .max_attrs = 0,
     .max_prep_entries = 6,
 
     /** L2CAP settings. */
-    .max_l2cap_chans = 16,
-    .max_l2cap_sig_procs = 8,
+    /* Three channels per connection (sig, att, and sm). */
+    .max_l2cap_chans = 3 * BLE_HS_CFG_MAX_CONNECTIONS,
+    .max_l2cap_sig_procs = 1,
     .max_l2cap_sm_procs = 1,
 
     /** Security manager settings. */
@@ -55,7 +62,8 @@ const struct ble_hs_cfg ble_hs_cfg_dflt = {
     .sm_keypress = 0,
     .sm_our_key_dist = 0,
     .sm_their_key_dist = 0,
-    /** privacy info */
+
+    /** Privacy settings. */
     .rpa_timeout = 300,
 };
 


[3/3] incubator-mynewt-core git commit: bletiny - Allow setting of local random address.

Posted by cc...@apache.org.
bletiny - Allow setting of local random address.


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

Branch: refs/heads/develop
Commit: 195c7d62e6bba1c9e17bd87c6c924e0867475fed
Parents: bbd43f1
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Jul 24 11:51:37 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sun Jul 24 12:02:05 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  3 +-
 apps/bletiny/src/cmd.c     | 73 +++++++++++++++++++++++++++++++++--------
 apps/bletiny/src/parse.c   | 24 +++++++++++---
 3 files changed, 81 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/195c7d62/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 44831be..b8e4864 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -88,7 +88,8 @@ extern struct log bletiny_log;
 const struct cmd_entry *parse_cmd_find(const struct cmd_entry *cmds,
                                        char *name);
 struct kv_pair *parse_kv_find(struct kv_pair *kvs, char *name);
-char *parse_arg_find(char *key);
+int parse_arg_find_idx(const char *key);
+char *parse_arg_extract(const char *key);
 long parse_arg_long_bounds(char *name, long min, long max, int *out_status);
 long parse_arg_long_bounds_default(char *name, long min, long max,
                                    long dflt, int *out_status);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/195c7d62/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 4733076..7671253 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1341,7 +1341,7 @@ cmd_set_adv_data(void)
         return rc;
     }
 
-    adv_fields.name = (uint8_t *)parse_arg_find("name");
+    adv_fields.name = (uint8_t *)parse_arg_extract("name");
     if (adv_fields.name != NULL) {
         adv_fields.name_len = strlen((char *)adv_fields.name);
     }
@@ -1470,7 +1470,7 @@ cmd_set_adv_data(void)
         return rc;
     }
 
-    eddystone_url_full = parse_arg_find("eddystone_url");
+    eddystone_url_full = parse_arg_extract("eddystone_url");
     if (eddystone_url_full != NULL) {
         rc = cmd_parse_eddystone_url(eddystone_url_full, &eddystone_url_scheme,
                                      eddystone_url_body,
@@ -1568,11 +1568,60 @@ cmd_set_sm_data(void)
     return 0;
 }
 
+static struct kv_pair cmd_set_addr_types[] = {
+    { "public",         BLE_ADDR_TYPE_PUBLIC },
+    { "random",         BLE_ADDR_TYPE_RANDOM },
+    { NULL }
+};
+
+static int
+cmd_set_addr(void)
+{
+    uint8_t addr[6];
+    int addr_type;
+    int rc;
+
+    addr_type = parse_arg_kv_default("addr_type", cmd_set_addr_types,
+                                     BLE_ADDR_TYPE_PUBLIC, &rc);
+    if (rc != 0) {
+        console_printf("invalid 'addr_type' parameter\n");
+        return rc;
+    }
+
+    rc = parse_arg_mac("addr", addr);
+    if (rc != 0) {
+        return rc;
+    }
+
+    switch (addr_type) {
+    case BLE_ADDR_TYPE_PUBLIC:
+        /* We shouldn't be writing to the controller's address (g_dev_addr).
+         * There is no standard way to set the local public address, so this is
+         * our only option at the moment.
+         */
+        memcpy(g_dev_addr, addr, 6);
+        ble_hs_id_set_pub(g_dev_addr);
+        break;
+
+    case BLE_ADDR_TYPE_RANDOM:
+        rc = ble_hs_id_set_rnd(addr);
+        if (rc != 0) {
+            return rc;
+        }
+        break;
+
+    default:
+        assert(0);
+        return BLE_HS_EUNKNOWN;
+    }
+
+    return 0;
+}
+
 static int
 cmd_set(int argc, char **argv)
 {
     uint16_t mtu;
-    uint8_t addr[6];
     uint8_t irk[16];
     int good;
     int rc;
@@ -1589,16 +1638,14 @@ cmd_set(int argc, char **argv)
 
     good = 0;
 
-    rc = parse_arg_mac("addr", addr);
-    if (rc == 0) {
+    rc = parse_arg_find_idx("addr");
+    if (rc != -1) {
+        rc = cmd_set_addr();
+        if (rc != 0) {
+            return rc;
+        }
+
         good = 1;
-        /* XXX: There are a lot of problems with this.  This command probably
-         * needs to be removed.
-         */
-        memcpy(g_dev_addr, addr, 6);
-        ble_hs_id_set_pub(g_dev_addr);
-    } else if (rc != ENOENT) {
-        return rc;
     }
 
     mtu = parse_arg_uint16("mtu", &rc);
@@ -2149,7 +2196,7 @@ cmd_passkey(int argc, char **argv)
             break;
 
         case BLE_SM_IOACT_NUMCMP:
-            yesno = parse_arg_find("yesno");
+            yesno = parse_arg_extract("yesno");
             if (yesno == NULL) {
                 return EINVAL;
             }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/195c7d62/apps/bletiny/src/parse.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
index 77fdace..d951d3d 100644
--- a/apps/bletiny/src/parse.c
+++ b/apps/bletiny/src/parse.c
@@ -72,8 +72,22 @@ parse_kv_find(struct kv_pair *kvs, char *name)
     return NULL;
 }
 
+int
+parse_arg_find_idx(const char *key)
+{
+    int i;
+
+    for (i = 0; i < cmd_num_args; i++) {
+        if (strcmp(cmd_args[i][0], key) == 0) {
+            return i;
+        }
+    }
+
+    return -1;
+}
+
 char *
-parse_arg_find(char *key)
+parse_arg_extract(const char *key)
 {
     int i;
 
@@ -111,7 +125,7 @@ parse_arg_long_bounds(char *name, long min, long max, int *out_status)
     char *sval;
     long lval;
 
-    sval = parse_arg_find(name);
+    sval = parse_arg_extract(name);
     if (sval == NULL) {
         *out_status = ENOENT;
         return 0;
@@ -154,7 +168,7 @@ parse_arg_uint64_bounds(char *name, uint64_t min, uint64_t max, int *out_status)
     char *sval;
     uint64_t lval;
 
-    sval = parse_arg_find(name);
+    sval = parse_arg_extract(name);
     if (sval == NULL) {
         *out_status = ENOENT;
         return 0;
@@ -252,7 +266,7 @@ parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status)
     struct kv_pair *kv;
     char *sval;
 
-    sval = parse_arg_find(name);
+    sval = parse_arg_extract(name);
     if (sval == NULL) {
         *out_status = ENOENT;
         return -1;
@@ -324,7 +338,7 @@ parse_arg_byte_stream(char *name, int max_len, uint8_t *dst, int *out_len)
 {
     char *sval;
 
-    sval = parse_arg_find(name);
+    sval = parse_arg_extract(name);
     if (sval == NULL) {
         return ENOENT;
     }


[2/3] incubator-mynewt-core git commit: ble example apps: use dflt ble_hs cfg if possible

Posted by cc...@apache.org.
ble example apps: use dflt ble_hs cfg if possible

Prior to this change, the sampel apps set most of the ble_hs_cfg values
to somewhat arbitrary numbers.  Now, the apps leave most settings with
their default values.  The defaults are more appropriate in terms of the
apps' actual requirements.  This change also makes the apps easier to
copy and paste from for people getting started with NimBLE.


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

Branch: refs/heads/develop
Commit: bbd43f13aff8e34fa2408615fdb44804c881e81e
Parents: db3c76b
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Jul 24 11:59:48 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sun Jul 24 11:59:48 2016 -0700

----------------------------------------------------------------------
 apps/blecent/src/main.c | 12 +++++-------
 apps/bleprph/src/main.c |  6 ------
 apps/bletiny/src/main.c |  5 -----
 3 files changed, 5 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bbd43f13/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 4c1ebe5..a385e4b 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -554,9 +554,7 @@ main(void)
     /* Configure the host. */
     cfg = ble_hs_cfg_dflt;
     cfg.max_hci_bufs = 3;
-    cfg.max_connections = 1;
     cfg.max_gattc_procs = 5;
-    cfg.max_l2cap_chans = 3;
     cfg.max_l2cap_sig_procs = 1;
     cfg.sm_bonding = 1;
     cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
@@ -565,11 +563,11 @@ main(void)
     cfg.store_write_cb = ble_store_ram_write;
 
     /* Populate config with the required GATT server settings. */
-    cfg.max_attrs = 0;
-    cfg.max_services = 0;
-    cfg.max_client_configs = 0;
-    ble_svc_gap_init(&cfg);
-    ble_svc_gatt_init(&cfg);
+    rc = ble_svc_gap_init(&cfg);
+    assert(rc == 0);
+
+    rc = ble_svc_gatt_init(&cfg);
+    assert(rc == 0);
 
     /* Initialize the BLE host. */
     rc = ble_hs_init(&blecent_evq, &cfg);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bbd43f13/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 946e227..be8c1c6 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -368,9 +368,7 @@ main(void)
     /* Initialize the BLE host. */
     cfg = ble_hs_cfg_dflt;
     cfg.max_hci_bufs = 3;
-    cfg.max_connections = 1;
     cfg.max_gattc_procs = 2;
-    cfg.max_l2cap_chans = 3;
     cfg.max_l2cap_sig_procs = 1;
     cfg.sm_bonding = 1;
     cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
@@ -379,10 +377,6 @@ main(void)
     cfg.store_write_cb = ble_store_ram_write;
 
     /* Populate config with the required GATT server settings. */
-    cfg.max_attrs = 0;
-    cfg.max_services = 0;
-    cfg.max_client_configs = 0;
-
     rc = ble_svc_gap_init(&cfg);
     assert(rc == 0);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bbd43f13/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 3432b80..020b415 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1685,16 +1685,11 @@ main(void)
     cfg = ble_hs_cfg_dflt;
     cfg.max_hci_bufs = 3;
     cfg.max_gattc_procs = 2;
-    cfg.max_l2cap_chans = NIMBLE_OPT(MAX_CONNECTIONS) * 3;
     cfg.max_l2cap_sig_procs = 2;
     cfg.store_read_cb = ble_store_ram_read;
     cfg.store_write_cb = ble_store_ram_write;
 
     /* Populate config with the required GATT server settings. */
-    cfg.max_attrs = 0;
-    cfg.max_services = 0;
-    cfg.max_client_configs = 0;
-
     rc = ble_svc_gap_init(&cfg);
     assert(rc == 0);