Skip to contentSkip to conversation

btdev: Check advertising/scanning states when changing White List

PATCH In review Luiz Augusto von Dentz 2 participants 4 messages Jun 7, 2021 – Jun 9, 2021 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 btdev: Check advertising/scanning states when changing White List

From: Luiz Augusto von Dentz <[email protected]>

White List cannot be changed when advertising/scanning:

• any advertising filter policy uses the White List and advertising is enabled,
• the scanning filter policy uses the White List and scanning is enabled, or
• the initiator filter policy uses the White List and an HCI_LE_Create_Connection or HCI_LE_Extended_Create_Connection command is outstanding.

---
 emulator/btdev.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
emulator/btdev.c +68 -0
index ad5bb8d92..bfee0ed7b 100644
@@ -150,11 +150,13 @@ struct btdev {
 	uint8_t  le_adv_own_addr;
 	uint8_t  le_adv_direct_addr_type;
 	uint8_t  le_adv_direct_addr[6];
+	uint8_t  le_adv_filter_policy;
 	uint8_t  le_scan_data[31];
 	uint8_t  le_scan_data_len;
 	uint8_t  le_scan_enable;
 	uint8_t  le_scan_type;
 	uint8_t  le_scan_own_addr_type;
+	uint8_t  le_scan_filter_policy;
 	uint8_t  le_filter_dup;
 	uint8_t  le_adv_enable;
 	uint8_t  le_periodic_adv_enable;
@@ -3002,6 +3004,7 @@ static int cmd_set_adv_params(struct btdev *dev, const void *data, uint8_t len)
 	dev->le_adv_own_addr = cmd->own_addr_type;
 	dev->le_adv_direct_addr_type = cmd->direct_addr_type;
 	memcpy(dev->le_adv_direct_addr, cmd->direct_addr, 6);
+	dev->le_adv_filter_policy = cmd->filter_policy;
 
 	status = BT_HCI_ERR_SUCCESS;
 
@@ -3223,6 +3226,7 @@ static int cmd_set_scan_params(struct btdev *dev, const void *data, uint8_t len)
 	status = BT_HCI_ERR_SUCCESS;
 	dev->le_scan_type = cmd->type;
 	dev->le_scan_own_addr_type = cmd->own_addr_type;
+	dev->le_scan_filter_policy = cmd->filter_policy;
 
 done:
 	cmd_complete(dev, BT_HCI_CMD_LE_SET_SCAN_PARAMETERS, &status,
@@ -3396,10 +3400,45 @@ static int cmd_read_wl_size(struct btdev *dev, const void *data, uint8_t len)
 	return 0;
 }
 
+static bool wl_can_change(struct btdev *dev)
+{
+	 /* filter policy uses the White List and advertising is enable. */
+	if (dev->le_adv_enable && dev->le_adv_filter_policy)
+		return false;
+
+	/* scanning filter policy uses the White List and scanning is enabled */
+	if (dev->le_scan_enable) {
+		switch (dev->le_scan_filter_policy) {
+		case 0x00:
+			return true;
+		case 0x01:
+			return false;
+		case 0x02:
+			return true;
+		case 0x03:
+			return false;
+		}
+	}
+
+	return true;
+}
+
 static int cmd_wl_clear(struct btdev *dev, const void *data, uint8_t len)
 {
 	uint8_t status;
 
+	/* This command shall not be used when:
+	 * • any advertising filter policy uses the White List and advertising
+	 * is enabled,
+	 * • the scanning filter policy uses the White List and scanning is
+	 * enabled, or
+	 * • the initiator filter policy uses the White List and an
+	 * HCI_LE_Create_Connection or HCI_LE_Extended_Create_Connection
+	 * command is outstanding.
+	 */
+	if (!wl_can_change(dev))
+		return -EPERM;
+
 	wl_clear(dev);
 
 	status = BT_HCI_ERR_SUCCESS;
@@ -3425,6 +3464,18 @@ static int cmd_add_wl(struct btdev *dev, const void *data, uint8_t len)
 	bool exists = false;
 	int i, pos = -1;
 
+	/* This command shall not be used when:
+	 * • any advertising filter policy uses the White List and advertising
+	 * is enabled,
+	 * • the scanning filter policy uses the White List and scanning is
+	 * enabled, or
+	 * • the initiator filter policy uses the White List and an
+	 * HCI_LE_Create_Connection or HCI_LE_Extended_Create_Connection
+	 * command is outstanding.
+	 */
+	if (!wl_can_change(dev))
+		return -EPERM;
+
 	/* Valid range for address type is 0x00 to 0x01 */
 	if (cmd->addr_type > 0x01)
 		return -EINVAL;
@@ -3464,6 +3515,18 @@ static int cmd_remove_wl(struct btdev *dev, const void *data, uint8_t len)
 	int i;
 	char addr[18];
 
+	/* This command shall not be used when:
+	 * • any advertising filter policy uses the White List and advertising
+	 * is enabled,
+	 * • the scanning filter policy uses the White List and scanning is
+	 * enabled, or
+	 * • the initiator filter policy uses the White List and an
+	 * HCI_LE_Create_Connection or HCI_LE_Extended_Create_Connection
+	 * command is outstanding.
+	 */
+	if (!wl_can_change(dev))
+		return -EPERM;
+
 	/* Valid range for address type is 0x00 to 0x01 */
 	if (cmd->addr_type > 0x01)
 		return -EINVAL;
@@ -4120,6 +4183,7 @@ static int cmd_set_ext_adv_params(struct btdev *dev, const void *data,
 	dev->le_adv_own_addr = cmd->own_addr_type;
 	dev->le_adv_direct_addr_type = cmd->peer_addr_type;
 	memcpy(dev->le_adv_direct_addr, cmd->peer_addr, 6);
+	dev->le_adv_filter_policy = cmd->filter_policy;
 
 	rsp.status = BT_HCI_ERR_SUCCESS;
 	rsp.tx_power = 0;
@@ -4380,6 +4444,7 @@ static int cmd_set_ext_scan_params(struct btdev *dev, const void *data,
 		 */
 		dev->le_scan_type = scan->type;
 		dev->le_scan_own_addr_type = cmd->own_addr_type;
+		dev->le_scan_filter_policy = cmd->filter_policy;
 	}
 
 	cmd_complete(dev, BT_HCI_CMD_LE_SET_EXT_SCAN_PARAMS, &status,
@@ -5761,6 +5826,9 @@ static const struct btdev_cmd *default_cmd(struct btdev *btdev, uint16_t opcode,
 		case -EINVAL:
 			status = BT_HCI_ERR_INVALID_PARAMETERS;
 			goto failed;
+		case -EPERM:
+			status = BT_HCI_ERR_COMMAND_DISALLOWED;
+			goto failed;
 		default:
 			status = BT_HCI_ERR_UNSPECIFIED_ERROR;
 			goto failed;
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 2/2 btdev: Check advertising/scanning states when changing Resolving List

From: Luiz Augusto von Dentz <[email protected]>

Resolving List cannot be changed when advertising/scanning:

• Advertising (other than periodic advertising) is enabled,
• Scanning is enabled, or
• an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, or HCI_LE_Periodic_Advertising_Create_Sync command is outstanding.

---
 emulator/btdev.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
emulator/btdev.c +40 -0
index bfee0ed7b..eba9f57f9 100644
@@ -3566,6 +3566,16 @@ static int cmd_add_rl(struct btdev *dev, const void *data, uint8_t len)
 	bool exists = false;
 	int i, pos = -1;
 
+	/* This command shall not be used when address resolution is enabled in
+	 * the Controller and:
+	 * • Advertising (other than periodic advertising) is enabled,
+	 * • Scanning is enabled, or
+	 * • an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection,
+	 * or HCI_LE_Periodic_Advertising_Create_Sync command is outstanding.
+	 */
+	if (dev->le_adv_enable || dev->le_scan_enable)
+		return -EPERM;
+
 	/* Valid range for address type is 0x00 to 0x01 */
 	if (cmd->addr_type > 0x01)
 		return -EINVAL;
@@ -3607,6 +3617,16 @@ static int cmd_remove_rl(struct btdev *dev, const void *data, uint8_t len)
 	uint8_t status;
 	int i;
 
+	/* This command shall not be used when address resolution is enabled in
+	 * the Controller and:
+	 * • Advertising (other than periodic advertising) is enabled,
+	 * • Scanning is enabled, or
+	 * • an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection,
+	 * or HCI_LE_Periodic_Advertising_Create_Sync command is outstanding.
+	 */
+	if (dev->le_adv_enable || dev->le_scan_enable)
+		return -EPERM;
+
 	/* Valid range for address type is 0x00 to 0x01 */
 	if (cmd->addr_type > 0x01)
 		return -EINVAL;
@@ -3634,6 +3654,16 @@ static int cmd_clear_rl(struct btdev *dev, const void *data, uint8_t len)
 {
 	uint8_t status;
 
+	/* This command shall not be used when address resolution is enabled in
+	 * the Controller and:
+	 * • Advertising (other than periodic advertising) is enabled,
+	 * • Scanning is enabled, or
+	 * • an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection,
+	 * or HCI_LE_Periodic_Advertising_Create_Sync command is outstanding.
+	 */
+	if (dev->le_adv_enable || dev->le_scan_enable)
+		return -EPERM;
+
 	rl_clear(dev);
 
 	status = BT_HCI_ERR_SUCCESS;
@@ -3699,6 +3729,16 @@ static int cmd_set_rl_enable(struct btdev *dev, const void *data, uint8_t len)
 	const struct bt_hci_cmd_le_set_resolv_enable *cmd = data;
 	uint8_t status;
 
+	/* This command shall not be used when address resolution is enabled in
+	 * the Controller and:
+	 * • Advertising (other than periodic advertising) is enabled,
+	 * • Scanning is enabled, or
+	 * • an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection,
+	 * or HCI_LE_Periodic_Advertising_Create_Sync command is outstanding.
+	 */
+	if (dev->le_adv_enable || dev->le_scan_enable)
+		return -EPERM;
+
 	/* Valid range for address resolution enable is 0x00 to 0x01 */
 	if (cmd->enable > 0x01)
 		return -EINVAL;
Signature · 1 line
2.31.1
#2 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=495601

---Test result---

Test Summary:

CheckPatch                    PASS      0.53 seconds
GitLint                       PASS      0.20 seconds
Prep - Setup ELL              PASS      40.30 seconds
Build - Prep                  PASS      0.10 seconds
Build - Configure             PASS      7.00 seconds
Build - Make                  PASS      173.43 seconds
Make Check                    PASS      8.70 seconds
Make Distcheck                PASS      204.32 seconds
Build w/ext ELL - Configure   PASS      7.18 seconds
Build w/ext ELL - Make        PASS      163.31 seconds

Details
##############################
Test: CheckPatch - PASS
Desc: Run checkpatch.pl script with rule in .checkpatch.conf

##############################
Test: GitLint - PASS
Desc: Run gitlint with rule in .gitlint

##############################
Test: Prep - Setup ELL - PASS
Desc: Clone, build, and install ELL

##############################
Test: Build - Prep - PASS
Desc: Prepare environment for build

##############################
Test: Build - Configure - PASS
Desc: Configure the BlueZ source tree

##############################
Test: Build - Make - PASS
Desc: Build the BlueZ source tree

##############################
Test: Make Check - PASS
Desc: Run 'make check'

##############################
Test: Make Distcheck - PASS
Desc: Run distcheck to check the distribution

##############################
Test: Build w/ext ELL - Configure - PASS
Desc: Configure BlueZ source with '--enable-external-ell' configuration

##############################
Test: Build w/ext ELL - Make - PASS
Desc: Build BlueZ source with '--enable-external-ell' configuration

---
Regards,
Linux Bluetooth

author maintainer
#3 lore raw

Hi,

Quoted 66 lines · On Tue, Jun 8, 2021 at 9:05 PM <[email protected]> wrote:

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=495601

---Test result---

Test Summary:

CheckPatch                    PASS      0.53 seconds
GitLint                       PASS      0.20 seconds
Prep - Setup ELL              PASS      40.30 seconds
Build - Prep                  PASS      0.10 seconds
Build - Configure             PASS      7.00 seconds
Build - Make                  PASS      173.43 seconds
Make Check                    PASS      8.70 seconds
Make Distcheck                PASS      204.32 seconds
Build w/ext ELL - Configure   PASS      7.18 seconds
Build w/ext ELL - Make        PASS      163.31 seconds

Details
##############################
Test: CheckPatch - PASS
Desc: Run checkpatch.pl script with rule in .checkpatch.conf

##############################
Test: GitLint - PASS
Desc: Run gitlint with rule in .gitlint

##############################
Test: Prep - Setup ELL - PASS
Desc: Clone, build, and install ELL

##############################
Test: Build - Prep - PASS
Desc: Prepare environment for build

##############################
Test: Build - Configure - PASS
Desc: Configure the BlueZ source tree

##############################
Test: Build - Make - PASS
Desc: Build the BlueZ source tree

##############################
Test: Make Check - PASS
Desc: Run 'make check'

##############################
Test: Make Distcheck - PASS
Desc: Run distcheck to check the distribution

##############################
Test: Build w/ext ELL - Configure - PASS
Desc: Configure BlueZ source with '--enable-external-ell' configuration

##############################
Test: Build w/ext ELL - Make - PASS
Desc: Build BlueZ source with '--enable-external-ell' configuration

Quoted 3 lines

---
Regards,
Linux Bluetooth

Pushed.

Signature · 1 line
Luiz Augusto von Dentz