You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/01/22 04:54:09 UTC

[1/4] incubator-mynewt-larva git commit: Allow app to specify scan type, filter policy.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master ac1c39dc1 -> 9bbdfc582


Allow app to specify scan type,filter policy.


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

Branch: refs/heads/master
Commit: 173a7f30e3055722a4ea46a9e671f64f0415381c
Parents: ac1c39d
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 19:05:04 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 19:05:04 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h  |  1 +
 net/nimble/host/src/ble_gap_conn.c      | 68 ++++++++++++++++++++++++----
 net/nimble/host/src/test/ble_gap_test.c | 14 ++++--
 net/nimble/host/src/test/ble_os_test.c  |  8 +++-
 4 files changed, 74 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/173a7f30/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 d2598a7..1d8b3e1 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -150,6 +150,7 @@ int ble_gap_conn_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
 int ble_gap_conn_adv_stop(void);
 int ble_gap_conn_set_adv_fields(struct ble_hs_adv_fields *adv_fields);
 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,
                           ble_gap_conn_fn *cb, void *cb_arg);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/173a7f30/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 1e4946d..d8e3057 100644
--- a/net/nimble/host/src/ble_gap_conn.c
+++ b/net/nimble/host/src/ble_gap_conn.c
@@ -44,6 +44,7 @@
 #define BLE_GAP_CONN_M_STATE_DISC_PARAMS                    0
 #define BLE_GAP_CONN_M_STATE_DISC_ENABLE                    1
 #define BLE_GAP_CONN_M_STATE_DISC_ACKED                     2
+#define BLE_GAP_CONN_M_STATE_DISC_DISABLE                   3
 
 /** Connect master states. */
 #define BLE_GAP_CONN_STATE_M_PENDING                        0
@@ -101,6 +102,8 @@ static struct {
 
         struct {
             uint8_t disc_mode;
+            uint8_t filter_policy;
+            uint8_t scan_type;
             ble_gap_disc_fn *cb;
             void *cb_arg;
         } disc;
@@ -155,6 +158,7 @@ static int ble_gap_conn_adv_data_tx(void *arg);
 static int ble_gap_conn_adv_rsp_data_tx(void *arg);
 static int ble_gap_conn_adv_enable_tx(void *arg);
 static int ble_gap_conn_wl_tx_add(void *arg);
+static int ble_gap_conn_disc_tx_disable(void *arg);
 
 static ble_hci_sched_tx_fn * const ble_gap_conn_dispatch_adv_und[] = {
     [BLE_GAP_CONN_S_STATE_UND_PARAMS]   = ble_gap_conn_adv_params_tx,
@@ -828,22 +832,20 @@ ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt)
 static void
 ble_gap_conn_master_timer_exp(void *arg)
 {
-    int status;
-
     assert(ble_gap_conn_master_in_progress());
 
     switch (ble_gap_conn_master.op) {
     case BLE_GAP_CONN_OP_M_DISC:
         /* When a discovery procedure times out, it is not a failure. */
-        status = 0;
+        ble_gap_conn_master_enqueue(BLE_GAP_CONN_M_STATE_DISC_DISABLE, 1,
+                                    ble_gap_conn_disc_tx_disable, NULL);
         break;
 
     default:
-        status = BLE_HS_ETIMEOUT;
+        ble_gap_conn_master_failed(BLE_HS_ETIMEOUT);
         break;
     }
 
-    ble_gap_conn_master_failed(status);
 }
 
 static void
@@ -1454,6 +1456,38 @@ ble_gap_conn_set_adv_fields(struct ble_hs_adv_fields *adv_fields)
  *****************************************************************************/
 
 static void
+ble_gap_conn_disc_ack_disable(struct ble_hci_ack *ack, void *arg)
+{
+    assert(ble_gap_conn_master.op == BLE_GAP_CONN_OP_M_DISC);
+    assert(ble_gap_conn_master.state == BLE_GAP_CONN_M_STATE_DISC_DISABLE);
+
+    if (ack->bha_status != 0) {
+        ble_gap_conn_master_failed(ack->bha_status);
+    } else {
+        ble_gap_conn_master_failed(0);
+    }
+}
+
+static int
+ble_gap_conn_disc_tx_disable(void *arg)
+{
+    int rc;
+
+    assert(ble_gap_conn_master.op == BLE_GAP_CONN_OP_M_DISC);
+    assert(ble_gap_conn_master.state == BLE_GAP_CONN_M_STATE_DISC_DISABLE);
+
+    ble_hci_ack_set_callback(ble_gap_conn_disc_ack_disable, NULL);
+    rc = host_hci_cmd_le_set_scan_enable(0, 0);
+    if (rc != 0) {
+        /* XXX: What can we do? */
+        ble_gap_conn_master_failed(rc);
+        return rc;
+    }
+
+    return 0;
+}
+
+static void
 ble_gap_conn_disc_ack_enable(struct ble_hci_ack *ack, void *arg)
 {
     assert(ble_gap_conn_master.op == BLE_GAP_CONN_OP_M_DISC);
@@ -1508,11 +1542,12 @@ ble_gap_conn_disc_tx_params(void *arg)
     assert(ble_gap_conn_master.state == BLE_GAP_CONN_M_STATE_DISC_PARAMS);
 
     ble_hci_ack_set_callback(ble_gap_conn_disc_ack_params, NULL);
-    rc = host_hci_cmd_le_set_scan_params(BLE_HCI_SCAN_TYPE_ACTIVE,
-                                         BLE_GAP_SCAN_FAST_INTERVAL_MIN,
-                                         BLE_GAP_SCAN_FAST_WINDOW,
-                                         BLE_HCI_ADV_OWN_ADDR_PUBLIC,
-                                         BLE_HCI_SCAN_FILT_NO_WL);
+    rc = host_hci_cmd_le_set_scan_params(
+        ble_gap_conn_master.disc.scan_type,
+        BLE_GAP_SCAN_FAST_INTERVAL_MIN,
+        BLE_GAP_SCAN_FAST_WINDOW,
+        BLE_HCI_ADV_OWN_ADDR_PUBLIC,
+        ble_gap_conn_master.disc.filter_policy);
     if (rc != 0) {
         ble_gap_conn_master_failed(rc);
         return rc;
@@ -1529,6 +1564,7 @@ ble_gap_conn_disc_tx_params(void *arg)
  */
 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 rc;
@@ -1539,6 +1575,16 @@ ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode,
         return BLE_HS_EINVAL;
     }
 
+    if (scan_type != BLE_HCI_SCAN_TYPE_PASSIVE &&
+        scan_type != BLE_HCI_SCAN_TYPE_ACTIVE) {
+
+        return BLE_HS_EINVAL;
+    }
+
+    if (filter_policy > BLE_HCI_SCAN_FILT_MAX) {
+        return BLE_HS_EINVAL;
+    }
+
     /* Make sure no master connection attempt is already in progress. */
     if (ble_gap_conn_master_in_progress()) {
         return BLE_HS_EALREADY;
@@ -1550,6 +1596,8 @@ ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode,
 
     ble_gap_conn_master.op = BLE_GAP_CONN_OP_M_DISC;
     ble_gap_conn_master.disc.disc_mode = discovery_mode;
+    ble_gap_conn_master.disc.scan_type = scan_type;
+    ble_gap_conn_master.disc.filter_policy = filter_policy;
     ble_gap_conn_master.disc.cb = cb;
     ble_gap_conn_master.disc.cb_arg = cb_arg;
     rc = ble_gap_conn_master_enqueue(BLE_GAP_CONN_M_STATE_DISC_PARAMS, 0,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/173a7f30/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 a2cb9ce..15b3e05 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -468,7 +468,9 @@ ble_gap_test_util_disc(uint8_t disc_mode, uint8_t *peer_addr,
     cmd_idx = 0;
 
     /* Begin the discovery procedure. */
-    rc = ble_gap_conn_disc(0, disc_mode, ble_gap_test_util_disc_cb, NULL);
+    rc = ble_gap_conn_disc(0, disc_mode, BLE_HCI_SCAN_TYPE_ACTIVE,
+                           BLE_HCI_SCAN_FILT_NO_WL, ble_gap_test_util_disc_cb,
+                           NULL);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_conn_master_in_progress());
 
@@ -512,15 +514,17 @@ TEST_CASE(ble_gap_test_case_conn_disc_bad_args)
     ble_gap_test_util_init();
 
     /*** Invalid discovery mode. */
-    rc = ble_gap_conn_disc(0, BLE_GAP_DISC_MODE_NON,
-                           ble_gap_test_util_disc_cb, NULL);
+    rc = ble_gap_conn_disc(0, BLE_GAP_DISC_MODE_NON, BLE_HCI_SCAN_TYPE_ACTIVE,
+                           BLE_HCI_SCAN_FILT_NO_WL, ble_gap_test_util_disc_cb,
+                           NULL);
     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_disc(0, BLE_GAP_DISC_MODE_GEN,
-                           ble_gap_test_util_disc_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);
     TEST_ASSERT(rc == BLE_HS_EALREADY);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/173a7f30/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 d6862d9..034c8fc 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -164,6 +164,7 @@ static void
 ble_gap_gen_disc_test_task_handler(void *arg)
 {
     int cb_called;
+    int rc;
 
     /* Receive acknowledgements for the startup sequence.  We sent the
      * corresponding requests when the host task was started.
@@ -182,8 +183,10 @@ ble_gap_gen_disc_test_task_handler(void *arg)
     TEST_ASSERT(!ble_gap_conn_master_in_progress());
 
     /* Initiate the general discovery procedure with a 200 ms timeout. */
-    ble_gap_conn_disc(200, BLE_GAP_DISC_MODE_GEN,
-                      ble_gap_gen_disc_test_connect_cb, &cb_called);
+    rc = ble_gap_conn_disc(200, BLE_GAP_DISC_MODE_GEN, BLE_HCI_SCAN_TYPE_ACTIVE,
+                           BLE_HCI_SCAN_FILT_NO_WL,
+                           ble_gap_gen_disc_test_connect_cb, &cb_called);
+    TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_hs_conn_first() == NULL);
     TEST_ASSERT(ble_gap_conn_master_in_progress());
     TEST_ASSERT(!cb_called);
@@ -203,6 +206,7 @@ ble_gap_gen_disc_test_task_handler(void *arg)
 
     /* Wait 150 more ms; verify scan completed. */
     os_time_delay(150 * OS_TICKS_PER_SEC / 1000);
+    ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_SET_SCAN_ENABLE, 0);
     TEST_ASSERT(ble_hs_conn_first() == NULL);
     TEST_ASSERT(!ble_gap_conn_master_in_progress());
     TEST_ASSERT(cb_called);


[4/4] incubator-mynewt-larva git commit: bleshell - set advertisement data.

Posted by cc...@apache.org.
bleshell - set advertisement data.


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

Branch: refs/heads/master
Commit: 9bbdfc582d7d2077567cbf3aed26562a2c215c92
Parents: 20097b7
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 19:53:27 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 19:53:27 2016 -0800

----------------------------------------------------------------------
 project/bleshell/src/bleshell_priv.h |  2 +
 project/bleshell/src/cmd.c           | 70 ++++++++++++++++++++++++++++++-
 project/bleshell/src/main.c          | 11 ++++-
 3 files changed, 80 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9bbdfc58/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index 977bf29..3cd944e 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -6,6 +6,7 @@
 
 #include "host/ble_gatt.h"
 struct ble_gap_white_entry;
+struct ble_hs_adv_fields;
 
 #define BLESHELL_MAX_CONNS              8
 
@@ -109,5 +110,6 @@ int bleshell_wl_set(struct ble_gap_white_entry *white_list,
                     int white_list_count);
 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);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9bbdfc58/project/bleshell/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/cmd.c b/project/bleshell/src/cmd.c
index 569e2fc..0b8b374 100644
--- a/project/bleshell/src/cmd.c
+++ b/project/bleshell/src/cmd.c
@@ -664,6 +664,68 @@ cmd_show(int argc, char **argv)
  * $set                                                                      *
  *****************************************************************************/
 
+#define CMD_ADV_DATA_MAX_UUIDS16    8
+//#define CMD_ADV_DATA_MAX_UUIDS128   8
+
+static int
+cmd_set_adv_data(void)
+{
+    static uint16_t uuids16[8];
+    //static uint8_t uuids128[8][16];
+    struct ble_hs_adv_fields adv_fields;
+    uint16_t uuid16;
+    int tmp;
+    int rc;
+
+    memset(&adv_fields, 0, sizeof adv_fields);
+
+    while (1) {
+        uuid16 = parse_arg_uint16("uuid16", &rc);
+        if (rc == 0) {
+            if (adv_fields.num_uuids16 >= CMD_ADV_DATA_MAX_UUIDS16) {
+                return EINVAL;
+            }
+            uuids16[adv_fields.num_uuids16] = uuid16;
+            adv_fields.num_uuids16++;
+        } else if (rc == ENOENT) {
+            break;
+        } else {
+            return rc;
+        }
+    }
+    if (adv_fields.num_uuids16 > 0) {
+        adv_fields.uuids16 = uuids16;
+    }
+
+    tmp = parse_arg_long("uuids16_is_complete", &rc);
+    if (rc == 0) {
+        adv_fields.uuids16_is_complete = !!tmp;
+    } else if (rc != ENOENT) {
+        return rc;
+    }
+
+    adv_fields.name = (uint8_t *)parse_arg_find("name");
+    if (adv_fields.name != NULL) {
+        adv_fields.name_len = strlen((char *)adv_fields.name);
+    }
+
+    tmp = parse_arg_long_bounds("le_role", 0, 0xff, &rc);
+    if (rc == 0) {
+        adv_fields.le_role = tmp;
+        adv_fields.le_role_is_present = 1;
+    } else if (rc != ENOENT) {
+        return rc;
+    }
+
+    rc = bleshell_set_adv_data(&adv_fields);
+    if (rc != 0) {
+        console_printf("error setting advertisement data; rc=%d\n", rc);
+        return rc;
+    }
+
+    return 0;
+}
+
 static int
 cmd_set(int argc, char **argv)
 {
@@ -672,6 +734,11 @@ cmd_set(int argc, char **argv)
     int good;
     int rc;
 
+    if (argc > 1 && strcmp(argv[1], "adv_data") == 0) {
+        rc = cmd_set_adv_data();
+        return rc;
+    }
+
     good = 0;
 
     rc = parse_arg_mac("addr", addr);
@@ -688,8 +755,7 @@ cmd_set(int argc, char **argv)
         if (rc == 0) {
             good = 1;
         }
-    }
-    if (rc != ENOENT) {
+    } else if (rc != ENOENT) {
         return rc;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9bbdfc58/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index ad2a08a..b5160a7 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -913,7 +913,16 @@ bleshell_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
     int rc;
 
     rc = ble_gap_conn_disc(dur_ms, disc_mode, scan_type, filter_policy,
-                           bleshell_on_disc, NULL);
+                           bleshell_on_scan, NULL);
+    return rc;
+}
+
+int
+bleshell_set_adv_data(struct ble_hs_adv_fields *adv_fields)
+{
+    int rc;
+
+    rc = ble_gap_conn_set_adv_fields(adv_fields);
     return rc;
 }
 


[3/4] incubator-mynewt-larva git commit: bleshell - white list, scan, terminate.

Posted by cc...@apache.org.
bleshell - white list, scan, terminate.


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

Branch: refs/heads/master
Commit: 20097b7f0aa6bb17bfbd837a4e6ba363dc7c0f66
Parents: 48c49b6
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 19:33:38 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 19:33:38 2016 -0800

----------------------------------------------------------------------
 project/bleshell/src/bleshell_priv.h |   6 ++
 project/bleshell/src/cmd.c           | 161 ++++++++++++++++++++++++++++--
 project/bleshell/src/main.c          |  66 +++++++++++-
 3 files changed, 221 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/20097b7f/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index 341bba1..977bf29 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -5,6 +5,7 @@
 #include "os/queue.h"
 
 #include "host/ble_gatt.h"
+struct ble_gap_white_entry;
 
 #define BLESHELL_MAX_CONNS              8
 
@@ -103,5 +104,10 @@ 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_cancel(void);
+int bleshell_term_conn(uint16_t conn_handle);
+int bleshell_wl_set(struct ble_gap_white_entry *white_list,
+                    int white_list_count);
+int bleshell_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
+                  uint8_t filter_policy);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/20097b7f/project/bleshell/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/cmd.c b/project/bleshell/src/cmd.c
index 7f36126..569e2fc 100644
--- a/project/bleshell/src/cmd.c
+++ b/project/bleshell/src/cmd.c
@@ -153,7 +153,6 @@ cmd_adv(int argc, char **argv)
         console_printf("invalid 'conn' parameter\n");
         return -1;
     }
-    
 
     disc = parse_arg_kv("disc", cmd_adv_disc_modes);
     if (disc == -1) {
@@ -504,6 +503,68 @@ cmd_read(int argc, char **argv)
 }
 
 /*****************************************************************************
+ * $scan                                                                     *
+ *****************************************************************************/
+
+static struct kv_pair cmd_scan_disc_modes[] = {
+    { "ltd", BLE_GAP_DISC_MODE_LTD },
+    { "gen", BLE_GAP_DISC_MODE_GEN },
+    { NULL }
+};
+
+static struct kv_pair cmd_scan_types[] = {
+    { "passive", BLE_HCI_SCAN_TYPE_PASSIVE },
+    { "active", BLE_HCI_SCAN_TYPE_ACTIVE },
+    { NULL }
+};
+
+static struct kv_pair cmd_scan_filt_policies[] = {
+    { "no_wl", BLE_HCI_SCAN_FILT_NO_WL },
+    { "use_wl", BLE_HCI_SCAN_FILT_USE_WL },
+    { "no_wl_inita", BLE_HCI_SCAN_FILT_NO_WL_INITA },
+    { "use_wl_inita", BLE_HCI_SCAN_FILT_USE_WL_INITA },
+    { NULL }
+};
+
+static int
+cmd_scan(int argc, char **argv)
+{
+    uint32_t dur;
+    int disc;
+    int type;
+    int filt;
+    int rc;
+
+    dur = parse_arg_uint16("dur", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    disc = parse_arg_kv("disc", cmd_scan_disc_modes);
+    if (disc == -1) {
+        return EINVAL;
+    }
+
+    type = parse_arg_kv("type", cmd_scan_types);
+    if (type == -1) {
+        return EINVAL;
+    }
+
+    filt = parse_arg_kv("filt", cmd_scan_filt_policies);
+    if (disc == -1) {
+        return EINVAL;
+    }
+
+    rc = bleshell_scan(dur, disc, type, filt);
+    if (rc != 0) {
+        console_printf("error scanning; rc=%d\n", rc);
+        return rc;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************
  * $show                                                                     *
  *****************************************************************************/
 
@@ -641,6 +702,83 @@ cmd_set(int argc, char **argv)
 }
 
 /*****************************************************************************
+ * $terminate                                                                *
+ *****************************************************************************/
+
+static int
+cmd_term(int argc, char **argv)
+{
+    uint16_t conn_handle;
+    int rc;
+
+    conn_handle = parse_arg_uint16("conn", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bleshell_term_conn(conn_handle);
+    if (rc != 0) {
+        console_printf("error terminating connection; rc=%d\n", rc);
+        return rc;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************
+ * $white list                                                               *
+ *****************************************************************************/
+
+static struct kv_pair cmd_wl_addr_types[] = {
+    { "public",         BLE_HCI_CONN_PEER_ADDR_PUBLIC },
+    { "random",         BLE_HCI_CONN_PEER_ADDR_RANDOM },
+    { NULL }
+};
+
+#define CMD_WL_MAX_SZ   8
+
+static int
+cmd_wl(int argc, char **argv)
+{
+    static struct ble_gap_white_entry white_list[CMD_WL_MAX_SZ];
+    uint8_t addr_type;
+    uint8_t addr[6];
+    int wl_cnt;
+    int rc;
+
+    wl_cnt = 0;
+    while (1) {
+        if (wl_cnt >= CMD_WL_MAX_SZ) {
+            return EINVAL;
+        }
+
+        rc = parse_arg_mac("addr", addr);
+        if (rc == ENOENT) {
+            break;
+        } else if (rc != 0) {
+            return rc;
+        }
+
+        addr_type = parse_arg_kv("addr_type", cmd_wl_addr_types);
+        if (addr_type == -1) {
+            return EINVAL;
+        }
+
+        memcpy(white_list[wl_cnt].addr, addr, 6);
+        white_list[wl_cnt].addr_type = addr_type;
+        wl_cnt++;
+    }
+
+    if (wl_cnt == 0) {
+        return EINVAL;
+    }
+
+    bleshell_wl_set(white_list, wl_cnt);
+
+    return 0;
+}
+
+/*****************************************************************************
  * $write                                                                    *
  *****************************************************************************/
 
@@ -706,15 +844,18 @@ cmd_write(int argc, char **argv)
  *****************************************************************************/
 
 static struct cmd_entry cmd_b_entries[] = {
-    { "adv", cmd_adv },
-    { "conn", cmd_conn },
-    { "disc", cmd_disc },
-    { "find", cmd_find },
-    { "mtu", cmd_mtu },
-    { "read", cmd_read },
-    { "show", cmd_show },
-    { "set", cmd_set },
-    { "write", cmd_write },
+    { "adv",        cmd_adv },
+    { "conn",       cmd_conn },
+    { "disc",       cmd_disc },
+    { "find",       cmd_find },
+    { "mtu",        cmd_mtu },
+    { "read",       cmd_read },
+    { "scan",       cmd_scan },
+    { "show",       cmd_show },
+    { "set",        cmd_set },
+    { "term",       cmd_term },
+    { "wl",         cmd_wl },
+    { "write",      cmd_write },
     { NULL, NULL }
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/20097b7f/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index 598186d..ad2a08a 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -660,6 +660,38 @@ bleshell_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
     return 0;
 }
 
+static void
+bleshell_on_wl_set(int status, void *arg)
+{
+    console_printf("white list set status=%d\n", status);
+}
+
+static void
+bleshell_on_scan(int event, int status, struct ble_gap_disc_desc *desc,
+                 void *arg)
+{
+    switch (event) {
+    case BLE_GAP_EVENT_DISC_SUCCESS:
+        console_printf("received advertisement; event_type=%d addr_type=%d "
+                       "addr=", desc->event_type, desc->addr_type);
+        bleshell_print_bytes(desc->addr, 6);
+        console_printf(" length_data=%d rssi=%d data=", desc->length_data,
+                       desc->rssi);
+        bleshell_print_bytes(desc->data, desc->length_data);
+        /* XXX: Print fields. */
+        console_printf("\n");
+        break;
+
+    case BLE_GAP_EVENT_DISC_FINISHED:
+        console_printf("scanning finished; status=%d\n", status);
+        break;
+
+    default:
+        assert(0);
+        break;
+    }
+}
+
 int
 bleshell_exchange_mtu(uint16_t conn_handle)
 {
@@ -763,8 +795,8 @@ bleshell_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
 {
     int rc;
 
-    rc = ble_gattc_read_uuid(conn_handle, start_handle, end_handle, uuid128,
-                             bleshell_on_read, NULL);
+    rc = ble_gattc_read_by_uuid(conn_handle, start_handle, end_handle, uuid128,
+                                bleshell_on_read, NULL);
     return rc;
 }
 
@@ -855,6 +887,36 @@ bleshell_conn_cancel(void)
     return rc;
 }
 
+int
+bleshell_term_conn(uint16_t conn_handle)
+{
+    int rc;
+
+    rc = ble_gap_conn_terminate(conn_handle);
+    return rc;
+}
+
+int
+bleshell_wl_set(struct ble_gap_white_entry *white_list, int white_list_count)
+{
+    int rc;
+
+    rc = ble_gap_conn_wl_set(white_list, white_list_count, bleshell_on_wl_set,
+                             NULL);
+    return rc;
+}
+
+int
+bleshell_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
+              uint8_t filter_policy)
+{
+    int rc;
+
+    rc = ble_gap_conn_disc(dur_ms, disc_mode, scan_type, filter_policy,
+                           bleshell_on_disc, NULL);
+    return rc;
+}
+
 /**
  * BLE test task 
  * 


[2/4] incubator-mynewt-larva git commit: Fix some typos.

Posted by cc...@apache.org.
Fix some typos.


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

Branch: refs/heads/master
Commit: 48c49b6e500b1927a9acf0df4d377b9c8e5c68d7
Parents: 173a7f3
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 19:15:30 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 19:15:30 2016 -0800

----------------------------------------------------------------------
 net/nimble/include/nimble/hci_common.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/48c49b6e/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 607be2e..caa11ec 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -223,7 +223,7 @@
  *      connectable, directed advertisement shall not be ignored if the InitA
  *      is a resolvable private address.
  *  USE_WL_INITA:
- *      Scanner process advertisements from white list ony. A connectable,
+ *      Scanner process advertisements from white list only. A connectable,
  *      directed advertisement shall not be ignored if the InitA is a
  *      resolvable private address.
  */
@@ -274,7 +274,7 @@
 #define BLE_HCI_EVCODE_CONN_REQUEST         (0x04)
 #define BLE_HCI_EVCODE_DISCONN_CMP          (0x05)
 #define BLE_HCI_EVCODE_AUTH_CMP             (0x06)
-#define BLE_HCI_EVCODE_REM_NAME_REQ_CM P    (0x07)
+#define BLE_HCI_EVCODE_REM_NAME_REQ_CMP     (0x07)
 #define BLE_HCI_EVCODE_ENCRYPT_CHG          (0x08)
 #define BLE_HCI_EVCODE_CHG_LINK_KEY_CMP     (0x09)
 #define BLE_HCI_EVCODE_MASTER_LINK_KEY_CMP  (0x0A)