Skip to content

Commit 3707096

Browse files
carlescufijhedberg
authored andcommitted
Bluetooth: controller: Correct adv, scan and init state checks
For whitelist and resolving list handling, avoid trying to start the advertiser and scanner roles when they are already running. Additionally, and since simultaneous scanning and initiating is not supported, correctly report this to the host both in the supported states and in the HCI command via an error code, instead of silently disabling scanning. Signed-off-by: Carles Cufi <[email protected]>
1 parent 114db10 commit 3707096

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

subsys/bluetooth/controller/hci/hci.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,12 @@ static void le_read_supp_states(struct net_buf *buf, struct net_buf **evt)
570570
rp = cmd_complete(evt, sizeof(*rp));
571571
rp->status = 0x00;
572572

573-
sys_put_le64(0x000003ffffffffff, rp->le_states);
573+
/* All states and combinations supported except:
574+
* Initiating State + Passive Scanning
575+
* Initiating State + Active Scanning
576+
*/
577+
/*@todo: conditionally disable states based on Kconfig variables */
578+
sys_put_le64(0x000003ffff3fffff, rp->le_states);
574579
}
575580

576581
#if defined(CONFIG_BLUETOOTH_BROADCASTER)

subsys/bluetooth/controller/ll_sw/ctrl.c

+13-16
Original file line numberDiff line numberDiff line change
@@ -8142,7 +8142,7 @@ u32_t radio_adv_enable(u16_t interval, u8_t chl_map, u8_t filter_policy)
81428142
u32_t ret;
81438143

81448144
if (_radio.advertiser.is_enabled) {
8145-
return 1;
8145+
return BT_HCI_ERR_CMD_DISALLOWED;
81468146
}
81478147

81488148
pdu_adv = (struct pdu_adv *)
@@ -8153,19 +8153,19 @@ u32_t radio_adv_enable(u16_t interval, u8_t chl_map, u8_t filter_policy)
81538153
void *link;
81548154

81558155
if (_radio.advertiser.conn) {
8156-
return 1;
8156+
return BT_HCI_ERR_CMD_DISALLOWED;
81578157
}
81588158

81598159
link = mem_acquire(&_radio.link_rx_free);
81608160
if (!link) {
8161-
return 1;
8161+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
81628162
}
81638163

81648164
conn = mem_acquire(&_radio.conn_free);
81658165
if (!conn) {
81668166
mem_release(link, &_radio.link_rx_free);
81678167

8168-
return 1;
8168+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
81698169
}
81708170

81718171
conn->handle = 0xFFFF;
@@ -8347,7 +8347,7 @@ u32_t radio_adv_enable(u16_t interval, u8_t chl_map, u8_t filter_policy)
83478347
mem_release(conn, &_radio.conn_free);
83488348
}
83498349

8350-
return 1;
8350+
return BT_HCI_ERR_CMD_DISALLOWED;
83518351
}
83528352

83538353
u32_t radio_adv_disable(void)
@@ -8375,7 +8375,7 @@ u32_t radio_adv_disable(void)
83758375
}
83768376
}
83778377

8378-
return status;
8378+
return status ? BT_HCI_ERR_CMD_DISALLOWED : 0;
83798379
}
83808380

83818381
u32_t radio_adv_is_enabled(void)
@@ -8408,7 +8408,7 @@ u32_t radio_scan_enable(u8_t type, u8_t init_addr_type, u8_t *init_addr,
84088408
u32_t ret;
84098409

84108410
if (_radio.scanner.is_enabled) {
8411-
return 1;
8411+
return BT_HCI_ERR_CMD_DISALLOWED;
84128412
}
84138413

84148414
_radio.scanner.type = type;
@@ -8479,7 +8479,7 @@ u32_t radio_scan_enable(u8_t type, u8_t init_addr_type, u8_t *init_addr,
84798479
}
84808480

84818481
if (ret_cb != TICKER_STATUS_SUCCESS) {
8482-
return 1;
8482+
return BT_HCI_ERR_CMD_DISALLOWED;
84838483
}
84848484

84858485
_radio.scanner.is_enabled = 1;
@@ -8517,7 +8517,7 @@ u32_t radio_scan_disable(void)
85178517
}
85188518
}
85198519

8520-
return status;
8520+
return status ? BT_HCI_ERR_CMD_DISALLOWED : 0;
85218521
}
85228522

85238523
u32_t radio_scan_is_enabled(void)
@@ -8548,23 +8548,20 @@ u32_t radio_connect_enable(u8_t adv_addr_type, u8_t *adv_addr, u16_t interval,
85488548
void *link;
85498549

85508550
if (_radio.scanner.conn) {
8551-
return 1;
8551+
return BT_HCI_ERR_CMD_DISALLOWED;
85528552
}
85538553

85548554
link = mem_acquire(&_radio.link_rx_free);
85558555
if (!link) {
8556-
return 1;
8556+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
85578557
}
85588558

85598559
conn = mem_acquire(&_radio.conn_free);
85608560
if (!conn) {
85618561
mem_release(link, &_radio.link_rx_free);
8562-
8563-
return 1;
8562+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
85648563
}
85658564

8566-
radio_scan_disable();
8567-
85688565
_radio.scanner.adv_addr_type = adv_addr_type;
85698566
memcpy(&_radio.scanner.adv_addr[0], adv_addr, BDADDR_SIZE);
85708567
_radio.scanner.conn_interval = interval;
@@ -8684,7 +8681,7 @@ u32_t ll_connect_disable(void)
86848681
u32_t status;
86858682

86868683
if (_radio.scanner.conn == 0) {
8687-
return 1;
8684+
return BT_HCI_ERR_CMD_DISALLOWED;
86888685
}
86898686

86908687
status = radio_scan_disable();

subsys/bluetooth/controller/ll_sw/ll_adv.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ u32_t ll_adv_params_set(u16_t interval, u8_t adv_type,
5858
struct pdu_adv *pdu;
5959

6060
if (radio_adv_is_enabled()) {
61-
return 0x0C; /* Command Disallowed */
61+
return BT_HCI_ERR_CMD_DISALLOWED;
6262
}
6363

6464
#if defined(CONFIG_BLUETOOTH_CONTROLLER_ADV_EXT)
@@ -341,9 +341,9 @@ u32_t ll_adv_enable(u8_t enable)
341341
u32_t status;
342342

343343
if (!enable) {
344-
status = radio_adv_disable();
345-
346-
return status;
344+
return radio_adv_disable();
345+
} else if (radio_adv_is_enabled()) {
346+
return 0;
347347
}
348348

349349
/* TODO: move the addr remembered into controller

subsys/bluetooth/controller/ll_sw/ll_master.c

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ u32_t ll_create_connection(u16_t scan_interval, u16_t scan_window,
2222
{
2323
u32_t status;
2424

25+
if (radio_scan_is_enabled()) {
26+
return BT_HCI_ERR_CMD_DISALLOWED;
27+
}
28+
2529
status = radio_connect_enable(peer_addr_type, peer_addr, interval,
2630
latency, timeout);
2731

subsys/bluetooth/controller/ll_sw/ll_scan.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ u32_t ll_scan_params_set(u8_t type, u16_t interval, u16_t window,
3232
u8_t own_addr_type, u8_t filter_policy)
3333
{
3434
if (radio_scan_is_enabled()) {
35-
return 0x0C; /* Command Disallowed */
35+
return BT_HCI_ERR_CMD_DISALLOWED;
3636
}
3737

3838
/* type value:
@@ -61,9 +61,10 @@ u32_t ll_scan_enable(u8_t enable)
6161
u32_t status;
6262

6363
if (!enable) {
64-
status = radio_scan_disable();
65-
66-
return status;
64+
return radio_scan_disable();
65+
} else if (radio_scan_is_enabled()) {
66+
/* Duplicate filtering is processed in the HCI layer */
67+
return 0;
6768
}
6869

6970
status = radio_scan_enable(ll_scan.type, ll_scan.tx_addr,

0 commit comments

Comments
 (0)