nimble/ll: Refactor ble_ll_scan_set_enable
This is in preparation for adding duration/period support.
Makes disable and already enabled a special case with early exit.
@@ -2724,7 +2724,6 @@ ble_ll_set_ext_scan_params(uint8_t *cmd)
int
ble_ll_scan_set_enable(uint8_t *cmd, uint8_t ext)
{
- int rc;
uint8_t filter_dups;
uint8_t enable;
struct ble_ll_scan_sm *scansm;
@@ -2743,6 +2742,7 @@ ble_ll_scan_set_enable(uint8_t *cmd, uint8_t ext)
scansm = &g_ble_ll_scan_sm;
+ /* we can do that here since value will never change until reset */
scansm->ext_scanning = ext;
if (ext) {
@@ -2754,11 +2754,30 @@ ble_ll_scan_set_enable(uint8_t *cmd, uint8_t ext)
(void) period;
}
- rc = BLE_ERR_SUCCESS;
- if (enable) {
- /* If already enabled, do nothing */
- if (!scansm->scan_enabled) {
+ /* disable*/
+ if (!enable) {
+ if (scansm->scan_enabled) {
+ ble_ll_scan_sm_stop(1);
+ }
+
+ return BLE_ERR_SUCCESS;
+ }
+
+ /* if already enable we just need to update parameters */
+ if (scansm->scan_enabled) {
+ /* Controller does not allow initiating and scanning.*/
+ for (i = 0; i < BLE_LL_SCAN_PHY_NUMBER; i++) {
+ scanphy = &scansm->phy_data[i];
+ if (scanphy->configured &&
+ scanphy->scan_type == BLE_SCAN_TYPE_INITIATE) {
+ return BLE_ERR_CMD_DISALLOWED;
+ }
+ }
+
+ return BLE_ERR_SUCCESS;
+ }
+ scansm->scan_filt_dups = filter_dups;
scansm->cur_phy = PHY_NOT_CONFIGURED;
scansm->next_phy = PHY_NOT_CONFIGURED;
@@ -2776,7 +2795,6 @@ ble_ll_scan_set_enable(uint8_t *cmd, uint8_t ext)
scanphy->scan_window = scanp->scan_window;
scanphy->scan_filt_policy = scanp->scan_filt_policy;
scanphy->own_addr_type = scanp->own_addr_type;
- scansm->scan_filt_dups = filter_dups;
if (scansm->cur_phy == PHY_NOT_CONFIGURED) {
scansm->cur_phy = i;
@@ -2785,25 +2803,7 @@ ble_ll_scan_set_enable(uint8_t *cmd, uint8_t ext)
}
}
- rc = ble_ll_scan_sm_start(scansm);
- } else {
- /* Controller does not allow initiating and scanning.*/
- for (i = 0; i < BLE_LL_SCAN_PHY_NUMBER; i++) {
- scanphy = &scansm->phy_data[i];
- if (scanphy->configured &&
- scanphy->scan_type == BLE_SCAN_TYPE_INITIATE) {
- rc = BLE_ERR_CMD_DISALLOWED;
- break;
- }
- }
- }
- } else {
- if (scansm->scan_enabled) {
- ble_ll_scan_sm_stop(1);
- }
- }
-
- return rc;
+ return ble_ll_scan_sm_start(scansm);
}
/**
