You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/05/21 11:42:20 UTC

[GitHub] rymanluk closed pull request #1113: apps/btshell: Add cmd_set_scan_opts command

rymanluk closed pull request #1113: apps/btshell: Add cmd_set_scan_opts command
URL: https://github.com/apache/mynewt-core/pull/1113
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apps/btshell/src/btshell.h b/apps/btshell/src/btshell.h
index f4614c046..8b181f22d 100644
--- a/apps/btshell/src/btshell.h
+++ b/apps/btshell/src/btshell.h
@@ -81,6 +81,11 @@ struct btshell_conn {
     struct btshell_l2cap_coc_list coc_list;
 };
 
+struct btshell_scan_opts {
+    uint16_t limit;
+    uint8_t ignore_legacy:1;
+};
+
 extern struct btshell_conn btshell_conns[MYNEWT_VAL(BLE_MAX_CONNECTIONS)];
 extern int btshell_num_conns;
 
@@ -134,12 +139,13 @@ int btshell_conn_cancel(void);
 int btshell_term_conn(uint16_t conn_handle, uint8_t reason);
 int btshell_wl_set(ble_addr_t *addrs, int addrs_count);
 int btshell_scan(uint8_t own_addr_type, int32_t duration_ms,
-                 const struct ble_gap_disc_params *disc_params);
+                 const struct ble_gap_disc_params *disc_params, void *cb_args);
 int btshell_ext_scan(uint8_t own_addr_type, uint16_t duration, uint16_t period,
                      uint8_t filter_duplicates, uint8_t filter_policy,
                      uint8_t limited,
                      const struct ble_gap_ext_disc_params *uncoded_params,
-                     const struct ble_gap_ext_disc_params *coded_params);
+                     const struct ble_gap_ext_disc_params *coded_params,
+                     void *cb_args);
 int btshell_scan_cancel(void);
 int btshell_update_conn(uint16_t conn_handle,
                          struct ble_gap_upd_params *params);
diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index 118837a7b..123ff2034 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -1064,6 +1064,54 @@ static const struct shell_cmd_help disconnect_help = {
 };
 #endif
 
+/*****************************************************************************
+ * $set-scan-opts                                                            *
+ *****************************************************************************/
+
+static struct btshell_scan_opts g_scan_opts = {
+        .limit = UINT16_MAX,
+        .ignore_legacy = 0,
+};
+
+static int
+cmd_set_scan_opts(int argc, char **argv)
+{
+    int rc;
+
+    rc = parse_arg_all(argc - 1, argv + 1);
+    if (rc != 0) {
+        return rc;
+    }
+
+    g_scan_opts.limit = parse_arg_uint16_dflt("decode_limit", UINT16_MAX, &rc);
+    if (rc != 0) {
+        console_printf("invalid 'decode_limit' parameter\n");
+        return rc;
+    }
+
+    g_scan_opts.ignore_legacy = parse_arg_bool_dflt("ignore_legacy", 0, &rc);
+    if (rc != 0) {
+        console_printf("invalid 'ignore_legacy' parameter\n");
+        return rc;
+    }
+
+    return rc;
+}
+
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+static const struct shell_param set_scan_opts_params[] = {
+    {"decode_limit", "usage: =[0-UINT16_MAX], default: UINT16_MAX"},
+    {"ignore_legacy", "usage: =[0-1], default: 0"},
+    {NULL, NULL}
+};
+
+static const struct shell_cmd_help set_scan_opts_help = {
+    .summary = "set scan options",
+    .usage = NULL,
+    .params = set_scan_opts_params,
+};
+#endif
+
 /*****************************************************************************
  * $scan                                                                     *
  *****************************************************************************/
@@ -1084,6 +1132,8 @@ static struct kv_pair cmd_scan_ext_types[] = {
     { NULL }
 };
 
+static struct btshell_scan_opts g_scan_opts;
+
 static int
 cmd_scan(int argc, char **argv)
 {
@@ -1169,7 +1219,7 @@ cmd_scan(int argc, char **argv)
     }
 
     if (extended == 0) {
-        rc = btshell_scan(own_addr_type, duration_ms, &params);
+        rc = btshell_scan(own_addr_type, duration_ms, &params, &g_scan_opts);
         if (rc != 0) {
             console_printf("error scanning; rc=%d\n", rc);
             return rc;
@@ -1217,17 +1267,20 @@ cmd_scan(int argc, char **argv)
     case 0x01:
         rc = btshell_ext_scan(own_addr_type, duration, period,
                               params.filter_duplicates, params.filter_policy,
-                              params.limited, &uncoded, NULL);
+                              params.limited, &uncoded, NULL,
+                              &g_scan_opts);
         break;
     case 0x02:
         rc = btshell_ext_scan(own_addr_type, duration, period,
                               params.filter_duplicates, params.filter_policy,
-                              params.limited, NULL, &coded);
+                              params.limited, NULL, &coded,
+                              &g_scan_opts);
         break;
     case 0x03:
         rc = btshell_ext_scan(own_addr_type, duration, period,
                               params.filter_duplicates, params.filter_policy,
-                              params.limited, &uncoded, &coded);
+                              params.limited, &uncoded, &coded,
+                              &g_scan_opts);
         break;
     default:
         rc = -1;
@@ -3404,6 +3457,13 @@ static const struct shell_cmd btshell_commands[] = {
         .sc_cmd_func = cmd_show_conn,
 #if MYNEWT_VAL(SHELL_CMD_HELP)
         .help = &gatt_show_conn_help,
+#endif
+    },
+    {
+        .sc_cmd = "set-scan-opts",
+        .sc_cmd_func = cmd_set_scan_opts,
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+        .help = &set_scan_opts_help,
 #endif
     },
     {
diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c
index 0dc6645dc..103668270 100644
--- a/apps/btshell/src/main.c
+++ b/apps/btshell/src/main.c
@@ -898,11 +898,17 @@ btshell_on_write_reliable(uint16_t conn_handle,
 }
 
 static void
-btshell_decode_adv_data(uint8_t *adv_data, uint8_t adv_data_len)
+btshell_decode_adv_data(uint8_t *adv_data, uint8_t adv_data_len, void *arg)
 {
+    struct btshell_scan_opts *scan_opts = arg;
     struct ble_hs_adv_fields fields;
 
     console_printf(" length_data=%d data=", adv_data_len);
+
+    if (scan_opts) {
+        adv_data_len = min(adv_data_len, scan_opts->limit);
+    }
+
     print_bytes(adv_data, adv_data_len);
     console_printf(" fields:\n");
     ble_hs_adv_parse_fields(&fields, adv_data, adv_data_len);
@@ -912,11 +918,16 @@ btshell_decode_adv_data(uint8_t *adv_data, uint8_t adv_data_len)
 
 #if MYNEWT_VAL(BLE_EXT_ADV)
 static void
-btshell_decode_event_type(struct ble_gap_ext_disc_desc *desc)
+btshell_decode_event_type(struct ble_gap_ext_disc_desc *desc, void *arg)
 {
+    struct btshell_scan_opts *scan_opts = arg;
     uint8_t directed = 0;
 
     if (desc->props & BLE_HCI_ADV_LEGACY_MASK) {
+        if (scan_opts && scan_opts->ignore_legacy) {
+            return;
+        }
+
         console_printf("Legacy PDU type %d", desc->legacy_event_type);
         if (desc->legacy_event_type == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
             directed = 1;
@@ -972,7 +983,7 @@ btshell_decode_event_type(struct ble_gap_ext_disc_desc *desc)
         return;
     }
 
-    btshell_decode_adv_data(desc->data, desc->length_data);
+    btshell_decode_adv_data(desc->data, desc->length_data, arg);
 }
 #endif
 
@@ -1008,7 +1019,7 @@ btshell_gap_event(struct ble_gap_event *event, void *arg)
         return 0;
 #if MYNEWT_VAL(BLE_EXT_ADV)
     case BLE_GAP_EVENT_EXT_DISC:
-        btshell_decode_event_type(&event->ext_disc);
+        btshell_decode_event_type(&event->ext_disc, arg);
         return 0;
 #endif
     case BLE_GAP_EVENT_DISC:
@@ -1026,7 +1037,7 @@ btshell_gap_event(struct ble_gap_event *event, void *arg)
                 return 0;
         }
 
-        btshell_decode_adv_data(event->disc.data, event->disc.length_data);
+        btshell_decode_adv_data(event->disc.data, event->disc.length_data, arg);
 
         return 0;
 
@@ -1528,12 +1539,12 @@ btshell_wl_set(ble_addr_t *addrs, int addrs_count)
 
 int
 btshell_scan(uint8_t own_addr_type, int32_t duration_ms,
-             const struct ble_gap_disc_params *disc_params)
+             const struct ble_gap_disc_params *disc_params, void *cb_args)
 {
     int rc;
 
     rc = ble_gap_disc(own_addr_type, duration_ms, disc_params,
-                      btshell_gap_event, NULL);
+                      btshell_gap_event, cb_args);
     return rc;
 }
 
@@ -1542,7 +1553,8 @@ btshell_ext_scan(uint8_t own_addr_type, uint16_t duration, uint16_t period,
                  uint8_t filter_duplicates, uint8_t filter_policy,
                  uint8_t limited,
                  const struct ble_gap_ext_disc_params *uncoded_params,
-                 const struct ble_gap_ext_disc_params *coded_params)
+                 const struct ble_gap_ext_disc_params *coded_params,
+                 void *cb_args)
 {
 #if !MYNEWT_VAL(BLE_EXT_ADV)
     console_printf("BLE extended advertising not supported.");
@@ -1553,7 +1565,7 @@ btshell_ext_scan(uint8_t own_addr_type, uint16_t duration, uint16_t period,
 
     rc = ble_gap_ext_disc(own_addr_type, duration, period, filter_duplicates,
                           filter_policy, limited, uncoded_params, coded_params,
-                          btshell_gap_event, NULL);
+                          btshell_gap_event, cb_args);
     return rc;
 #endif
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services