Repository: incubator-mynewt-core Updated Branches: refs/heads/master 3531ce6d6 -> 69a788967
nimble/controller: Fix setting parameters for scanning Parameters set by HCI LE Set Scan Parameters should be stored and then applied each time scan is enabled using HCI LE Set Scan Enable. This way scan uses proper parameters as set by host. Without this fix scan parameters in SM will be overwritten when initiating new connection. Since also scan type is set to 'initiating' in such case, no advertising reports will be sent to host until scan parameters are set once more by the host. 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/75770c86 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/75770c86 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/75770c86 Branch: refs/heads/master Commit: 75770c86bd1d988e9bb2e2b5af1cd3c9b7af7963 Parents: c82ebd4 Author: Andrzej Kaczmarek <[email protected]> Authored: Tue May 23 10:17:24 2017 +0200 Committer: Andrzej Kaczmarek <[email protected]> Committed: Tue May 23 11:42:01 2017 +0200 ---------------------------------------------------------------------- .../controller/include/controller/ble_ll_scan.h | 9 ++++++ net/nimble/controller/src/ble_ll_scan.c | 34 +++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75770c86/net/nimble/controller/include/controller/ble_ll_scan.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll_scan.h b/net/nimble/controller/include/controller/ble_ll_scan.h index 9524b92..5fc2007 100644 --- a/net/nimble/controller/include/controller/ble_ll_scan.h +++ b/net/nimble/controller/include/controller/ble_ll_scan.h @@ -54,6 +54,15 @@ extern "C" { #define BLE_SCAN_RSP_DATA_MAX_LEN (31) #define BLE_SCAN_MAX_PKT_LEN (37) +struct ble_ll_scan_params +{ + uint8_t scan_type; + uint8_t own_addr_type; + uint8_t scan_filt_policy; + uint16_t scan_itvl; + uint16_t scan_window; +}; + /* Scanning state machine (used when initiating as well) */ struct ble_ll_scan_sm { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75770c86/net/nimble/controller/src/ble_ll_scan.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c index 1b540bc..aee7ddd 100644 --- a/net/nimble/controller/src/ble_ll_scan.c +++ b/net/nimble/controller/src/ble_ll_scan.c @@ -59,6 +59,10 @@ #error "Cannot have more than 255 scan response entries!" #endif + +/* The scanning parameters set by host */ +struct ble_ll_scan_params g_ble_ll_scan_params; + /* The scanning state machine global object */ struct ble_ll_scan_sm g_ble_ll_scan_sm; @@ -1337,6 +1341,7 @@ ble_ll_scan_set_scan_params(uint8_t *cmd) uint16_t scan_itvl; uint16_t scan_window; struct ble_ll_scan_sm *scansm; + struct ble_ll_scan_params *scanp; /* If already enabled, we return an error */ scansm = &g_ble_ll_scan_sm; @@ -1376,12 +1381,13 @@ ble_ll_scan_set_scan_params(uint8_t *cmd) return BLE_ERR_INV_HCI_CMD_PARMS; } - /* Set state machine parameters */ - scansm->scan_type = scan_type; - scansm->scan_itvl = scan_itvl; - scansm->scan_window = scan_window; - scansm->scan_filt_policy = filter_policy; - scansm->own_addr_type = own_addr_type; + /* Store scan parameters */ + scanp = &g_ble_ll_scan_params; + scanp->scan_type = scan_type; + scanp->scan_itvl = scan_itvl; + scanp->scan_window = scan_window; + scanp->scan_filt_policy = filter_policy; + scanp->own_addr_type = own_addr_type; return 0; } @@ -1404,6 +1410,7 @@ ble_ll_scan_set_enable(uint8_t *cmd) uint8_t filter_dups; uint8_t enable; struct ble_ll_scan_sm *scansm; + struct ble_ll_scan_params *scanp; /* Check for valid parameters */ enable = cmd[0]; @@ -1417,7 +1424,13 @@ ble_ll_scan_set_enable(uint8_t *cmd) if (enable) { /* If already enabled, do nothing */ if (!scansm->scan_enabled) { + scanp = &g_ble_ll_scan_params; /* Start the scanning state machine */ + scansm->scan_type = scanp->scan_type; + scansm->scan_itvl = scanp->scan_itvl; + scansm->scan_window = scanp->scan_window; + scansm->scan_filt_policy = scanp->scan_filt_policy; + scansm->own_addr_type = scanp->own_addr_type; scansm->scan_filt_dups = filter_dups; rc = ble_ll_scan_sm_start(scansm); } else { @@ -1592,18 +1605,23 @@ void ble_ll_scan_init(void) { struct ble_ll_scan_sm *scansm; + struct ble_ll_scan_params *scanp; /* Clear state machine in case re-initialized */ scansm = &g_ble_ll_scan_sm; memset(scansm, 0, sizeof(struct ble_ll_scan_sm)); + /* Clear scan parameters in case re-initialized */ + scanp = &g_ble_ll_scan_params; + memset(scanp, 0, sizeof(struct ble_ll_scan_params)); + /* Initialize scanning window end event */ scansm->scan_sched_ev.ev_cb = ble_ll_scan_event_proc; scansm->scan_sched_ev.ev_arg = scansm; /* Set all non-zero default parameters */ - scansm->scan_itvl = BLE_HCI_SCAN_ITVL_DEF; - scansm->scan_window = BLE_HCI_SCAN_WINDOW_DEF; + scanp->scan_itvl = BLE_HCI_SCAN_ITVL_DEF; + scanp->scan_window = BLE_HCI_SCAN_WINDOW_DEF; /* Initialize scanning timer */ os_cputime_timer_init(&scansm->scan_timer, ble_ll_scan_timer_cb, scansm);
