MSFT offloading support for advertisement monitor
Subsystems (4)
cover MSFT offloading support for advertisement monitor
From: Archie Pusaka <[email protected]>
Hi linux-bluetooth,
This series of patches manages the hardware offloading part of MSFT extension API. The full documentation can be accessed by this link:
https://docs.microsoft.com/en-us/windows-hardware/drivers/bluetooth/microsoft-defined-bluetooth-hci-commands-and-events
Only four of the HCI commands are planned to be implemented:HCI_VS_MSFT_Read_Supported_Features (implemented in previous patch), HCI_VS_MSFT_LE_Monitor_Advertisement, HCI_VS_MSFT_LE_Cancel_Monitor_Advertisement, and HCI_VS_MSFT_LE_Set_Advertisement_Filter_Enable.
These are the commands which would be used for advertisement monitor feature. Only if the controller supports the MSFT extension would these commands be sent. Otherwise, software-based monitoring would be performed in the user space instead.
Thanks in advance for your feedback!
Archie
Archie Pusaka (5):
Bluetooth: advmon offload MSFT add rssi support
Bluetooth: advmon offload MSFT add monitor
Bluetooth: advmon offload MSFT remove monitor
Bluetooth: advmon offload MSFT handle controller reset
Bluetooth: advmon offload MSFT handle filter enablement
include/net/bluetooth/hci_core.h | 34 ++- include/net/bluetooth/mgmt.h | 9 + net/bluetooth/hci_core.c | 173 +++++++++--- net/bluetooth/mgmt.c | 263 +++++++++++++----- net/bluetooth/msft.c | 456 ++++++++++++++++++++++++++++++- net/bluetooth/msft.h | 27 ++ 6 files changed, 853 insertions(+), 109 deletions(-)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH 1/5 Bluetooth: advmon offload MSFT add rssi support
From: Archie Pusaka <[email protected]>
MSFT needs rssi parameter for monitoring advertisement packet, therefore we should supply them from mgmt.
---
include/net/bluetooth/hci_core.h | 9 +++++++++ include/net/bluetooth/mgmt.h | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++++++ 3 files changed, 26 insertions(+)
include/net/bluetooth/hci_core.h +9 -0
@@ -246,8 +246,17 @@ struct adv_pattern {__u8 value[HCI_MAX_AD_LENGTH ]; }; +struct adv_rssi_thresholds { +__s8 low_threshold; +__s8 high_threshold; +__u16 low_threshold_timeout; +__u16 high_threshold_timeout; +__u8 sampling_period; +}; +struct adv_monitor {struct list_head patterns; +struct adv_rssi_thresholds rssi;bool active;__u16 handle; };
include/net/bluetooth/mgmt.h +9 -0
@@ -763,9 +763,18 @@ struct mgmt_adv_pattern {__u8 value[31 ]; } __packed; +struct mgmt_adv_rssi_thresholds { +__s8 high_threshold; +__le16 high_threshold_timeout; +__s8 low_threshold; +__le16 low_threshold_timeout; +__u8 sampling_period; +} __packed; +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052struct mgmt_cp_add_adv_patterns_monitor {__u8 pattern_count; +struct mgmt_adv_rssi_thresholds rssi;struct mgmt_adv_pattern patterns[]; } __packed;#define MGMT_ADD_ADV_PATTERNS_MONITOR_SIZE 1
net/bluetooth/mgmt.c +8 -0
@@ -4237,6 +4237,14 @@ static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev,INIT_LIST_HEAD (&m->patterns); m->active = false; + m->rssi.low_threshold = cp->rssi.low_threshold; + m->rssi.low_threshold_timeout = +__le16_to_cpu (cp->rssi.low_threshold_timeout); + m->rssi.high_threshold = cp->rssi.high_threshold; + m->rssi.high_threshold_timeout = +__le16_to_cpu (cp->rssi.high_threshold_timeout); + m->rssi.sampling_period = cp->rssi.sampling_period; +for (i =0 ; i < cp->pattern_count; i++) {if (++mp_cnt >HCI_MAX_ADV_MONITOR_NUM_PATTERNS ) { err = mgmt_cmd_status(sk, hdev->id,
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
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=395361
---Test result---
##############################
Test: CheckPatch - PASS
##############################
Test: CheckGitLint - PASS
##############################
Test: CheckBuildK - PASS
---
Regards,
Linux Bluetooth
Marcel Holtmann
maintainerRe: [PATCH v1 1/5] Bluetooth: advmon offload MSFT add rssi support
In reply to Archie PusakaHi Archie,
Quoted 6 lines
MSFT needs rssi parameter for monitoring advertisement packet, therefore we should supply them from mgmt.
Signed-off-by Archie Pusaka <[email protected]>Reviewed-by Miao-chen Chou <[email protected]>Reviewed-by Yun-Hao Chung <[email protected]>
I don’t need any Reviewed-by if they are not catching an obvious user API breakage.
Quoted 41 lines
---
include/net/bluetooth/hci_core.h | 9 +++++++++ include/net/bluetooth/mgmt.h | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++++++ 3 files changed, 26 insertions(+)include/net/bluetooth/hci_core.h +9
-0@@ -246,8 +246,17 @@ struct adv_pattern {__u8 value[HCI_MAX_AD_LENGTH ]; }; +struct adv_rssi_thresholds { +__s8 low_threshold; +__s8 high_threshold; +__u16 low_threshold_timeout; +__u16 high_threshold_timeout; +__u8 sampling_period; +}; +struct adv_monitor {struct list_head patterns; +struct adv_rssi_thresholds rssi;bool active;__u16 handle; };include/net/bluetooth/mgmt.h +4
-0@@ -763,9 +763,18 @@ struct mgmt_adv_pattern {__u8 value[31 ]; } __packed; +struct mgmt_adv_rssi_thresholds { +__s8 high_threshold; +__le16 high_threshold_timeout; +__s8 low_threshold;
include/net/bluetooth/mgmt.h struct mgmt_adv_pattern { · line 779
Quoted 10 lines
include/net/bluetooth/mgmt.h +5
-0+__le16 low_threshold_timeout; +__u8 sampling_period; +} __packed; +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052struct mgmt_cp_add_adv_patterns_monitor {__u8 pattern_count; +struct mgmt_adv_rssi_thresholds rssi;struct mgmt_adv_pattern patterns[]; } __packed;
This is something we can not do. It breaks an userspace facing API. Is the mgmt opcode 0x0052 in an already released kernel?
Regards
Marcel
Re: [PATCH v1 1/5] Bluetooth: advmon offload MSFT add rssi support
Hi Marcel,
Quoted 49 lines · Marcel Holtmann
Hi Archie,
Quoted 6 lines
MSFT needs rssi parameter for monitoring advertisement packet, therefore we should supply them from mgmt.
Signed-off-by Archie Pusaka <[email protected]>Reviewed-by Miao-chen Chou <[email protected]>Reviewed-by Yun-Hao Chung <[email protected]>I don’t need any Reviewed-by if they are not catching an obvious user API breakage.
Quoted 37 lines
---
include/net/bluetooth/hci_core.h | 9 +++++++++ include/net/bluetooth/mgmt.h | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++++++ 3 files changed, 26 insertions(+)include/net/bluetooth/hci_core.h +9
-0@@ -246,8 +246,17 @@ struct adv_pattern {__u8 value[HCI_MAX_AD_LENGTH ]; }; +struct adv_rssi_thresholds { +__s8 low_threshold; +__s8 high_threshold; +__u16 low_threshold_timeout; +__u16 high_threshold_timeout; +__u8 sampling_period; +}; +struct adv_monitor {struct list_head patterns; +struct adv_rssi_thresholds rssi;bool active;__u16 handle; };include/net/bluetooth/mgmt.h +0
-0@@ -763,9 +763,18 @@ struct mgmt_adv_pattern {__u8 value[31 ]; } __packed;
Quoted 16 lines
Quoted 4 lines
include/net/bluetooth/mgmt.h +4
-0+struct mgmt_adv_rssi_thresholds { +__s8 high_threshold; +__le16 high_threshold_timeout; +__s8 low_threshold;include/net/bluetooth/mgmt.h struct mgmt_adv_pattern { · line 779
Quoted 10 lines
include/net/bluetooth/mgmt.h +5
-0+__le16 low_threshold_timeout; +__u8 sampling_period; +} __packed; +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052struct mgmt_cp_add_adv_patterns_monitor {__u8 pattern_count; +struct mgmt_adv_rssi_thresholds rssi;struct mgmt_adv_pattern patterns[]; } __packed;This is something we can not do. It breaks an userspace facing API. Is the mgmt opcode
0x0052in an already released kernel?
Yes, the opcode does exist in an already released kernel.
The DBus method which accesses this API is put behind the experimental flag, therefore we expect they are flexible enough to support changes. Previously, we already had a discussion in an email thread with the title "Offload RSSI tracking to controller", and the outcome supports this change.
Here is an excerpt of the discussion.
Quoted 38 lines · Miao-chen Chou
Hi Luiz,
Yes, the RSSI is included as a part of the Adv monitor API, and the RSSI tracking is currently implemented (the patch series is still under review) in bluetoothd and used by bluetoothctl (submenu advmon). As mentioned, we are planning to offload the RSSI tracking to the controller as well, so there will be changes to the corresponding MGMT commands. Thanks for your quick feedback!
Regards,
MiaoQuoted 28 lines · Luiz
include/net/bluetooth/mgmt.h +0
-0Hi Miao,I do recall seeing these at D-Bus level, or perhaps it was in use by bluetoothctl commands? Anyway since these are still experimental it should be fine to change them.
________________________________
From: Miao-chen Chou <[email protected]>
Sent: Wednesday, September 30, 2020 12:51 PM
To: Holtmann, Marcel <[email protected]>; Von Dentz, Luiz <[email protected]>
Cc: Alain Michaud <[email protected]>; Yun-hao Chung <[email protected]>; Manish Mandlik <[email protected]>; Archie Pusaka <[email protected]>
Subject: Offload RSSI tracking to controller.Hi Luiz and Marcel,
Going forward to 2020 Q4, we will be working on offloading the content filtering to the controllers based on controll's support of MSFT HCI extension. In the meantime, we are planning to change the existing MGMT commands of Adv monitoring to allow the offloading of RSSI tracking shortly. Here is a snippet of potential changes.
include/net/bluetooth/mgmt.h +6
-0+struct mgmt_adv_rssi_thresholds { +__s8 high_rssi_threshold; +u16 high_rssi_threshold_timeout; +__s8 low_rssi_threshold; +u16 high_rssi_threshold_timeout; +} __packed;struct mgmt_cp_add_adv_patterns_monitor { u8 pattern_count; + struct mgmt_adv_rssi_thresholds rssi_thresholds; struct mgmt_adv_pattern patterns[]; } __packed;
Quoted 4 lines
Quoted 4 lines
Note that as suggested by you, the D-Bus Adv monitor API which accesses these MGMT commands is currently hidden behind the experimental flag, so they are still mutable. We'd like to hear your early feedback on changing the corresponding MGMT commands.
Thanks,
Miao
Thanks,
Archie
Marcel Holtmann
maintainerRe: [PATCH v1 1/5] Bluetooth: advmon offload MSFT add rssi support
Hi Archie,
Quoted 65 lines
Quoted 46 lines
Quoted 6 lines
MSFT needs rssi parameter for monitoring advertisement packet, therefore we should supply them from mgmt.
Signed-off-by Archie Pusaka <[email protected]>Reviewed-by Miao-chen Chou <[email protected]>Reviewed-by Yun-Hao Chung <[email protected]>I don’t need any Reviewed-by if they are not catching an obvious user API breakage.
Quoted 37 lines
---
include/net/bluetooth/hci_core.h | 9 +++++++++ include/net/bluetooth/mgmt.h | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++++++ 3 files changed, 26 insertions(+)include/net/bluetooth/hci_core.h +9
-0@@ -246,8 +246,17 @@ struct adv_pattern {__u8 value[HCI_MAX_AD_LENGTH ]; }; +struct adv_rssi_thresholds { +__s8 low_threshold; +__s8 high_threshold; +__u16 low_threshold_timeout; +__u16 high_threshold_timeout; +__u8 sampling_period; +}; +struct adv_monitor {struct list_head patterns; +struct adv_rssi_thresholds rssi;bool active;__u16 handle; };include/net/bluetooth/mgmt.h +0
-0@@ -763,9 +763,18 @@ struct mgmt_adv_pattern {__u8 value[31 ]; } __packed;Quoted 16 lines
Quoted 4 lines
include/net/bluetooth/mgmt.h +4
-0+struct mgmt_adv_rssi_thresholds { +__s8 high_threshold; +__le16 high_threshold_timeout; +__s8 low_threshold;include/net/bluetooth/mgmt.h struct mgmt_adv_pattern { · line 779
Quoted 10 lines
include/net/bluetooth/mgmt.h +5
-0+__le16 low_threshold_timeout; +__u8 sampling_period; +} __packed; +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052struct mgmt_cp_add_adv_patterns_monitor {__u8 pattern_count; +struct mgmt_adv_rssi_thresholds rssi;struct mgmt_adv_pattern patterns[]; } __packed;This is something we can not do. It breaks an userspace facing API. Is the mgmt opcode
0x0052in an already released kernel?Yes, the opcode does exist in an already released kernel.
Quoted 7 lines
The DBus method which accesses this API is put behind the experimental flag, therefore we expect they are flexible enough to support changes. Previously, we already had a discussion in an email thread with the title "Offload RSSI tracking to controller", and the outcome supports this change.
Here is an excerpt of the discussion.
it doesn’t matter. This is fixed API now and so we can not just change it. The argument above is void. What matters if it is in already released kernel.
Regards
Marcel
Re: [PATCH v1 1/5] Bluetooth: advmon offload MSFT add rssi support
Hi Marcel,
Quoted 74 lines · Marcel Holtmann
Hi Archie,
Quoted 71 lines
Quoted 46 lines
Quoted 6 lines
MSFT needs rssi parameter for monitoring advertisement packet, therefore we should supply them from mgmt.
Signed-off-by Archie Pusaka <[email protected]>Reviewed-by Miao-chen Chou <[email protected]>Reviewed-by Yun-Hao Chung <[email protected]>I don’t need any Reviewed-by if they are not catching an obvious user API breakage.
Quoted 37 lines
---
include/net/bluetooth/hci_core.h | 9 +++++++++ include/net/bluetooth/mgmt.h | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++++++ 3 files changed, 26 insertions(+)include/net/bluetooth/hci_core.h +9
-0@@ -246,8 +246,17 @@ struct adv_pattern {__u8 value[HCI_MAX_AD_LENGTH ]; }; +struct adv_rssi_thresholds { +__s8 low_threshold; +__s8 high_threshold; +__u16 low_threshold_timeout; +__u16 high_threshold_timeout; +__u8 sampling_period; +}; +struct adv_monitor {struct list_head patterns; +struct adv_rssi_thresholds rssi;bool active;__u16 handle; };include/net/bluetooth/mgmt.h +0
-0@@ -763,9 +763,18 @@ struct mgmt_adv_pattern {__u8 value[31 ]; } __packed;Quoted 16 lines
Quoted 4 lines
include/net/bluetooth/mgmt.h +4
-0+struct mgmt_adv_rssi_thresholds { +__s8 high_threshold; +__le16 high_threshold_timeout; +__s8 low_threshold;include/net/bluetooth/mgmt.h struct mgmt_adv_pattern { · line 779
Quoted 10 lines
include/net/bluetooth/mgmt.h +5
-0+__le16 low_threshold_timeout; +__u8 sampling_period; +} __packed; +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052struct mgmt_cp_add_adv_patterns_monitor {__u8 pattern_count; +struct mgmt_adv_rssi_thresholds rssi;struct mgmt_adv_pattern patterns[]; } __packed;This is something we can not do. It breaks an userspace facing API. Is the mgmt opcode
0x0052in an already released kernel?Yes, the opcode does exist in an already released kernel.
The DBus method which accesses this API is put behind the experimental flag, therefore we expect they are flexible enough to support changes. Previously, we already had a discussion in an email thread with the title "Offload RSSI tracking to controller", and the outcome supports this change.
Quoted 3 lines
Quoted 1 line
Here is an excerpt of the discussion.
it doesn’t matter. This is fixed API now and so we can not just change it. The argument above is void. What matters if it is in already released kernel.
If that is the case, do you have a suggestion to allow RSSI to be considered when monitoring advertisement? Would a new MGMT opcode with these parameters suffice?
#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI 0x005?
struct mgmt_cp_add_adv_patterns_monitor {
__u8 pattern_count;
struct mgmt_adv_rssi_thresholds rssi;
struct mgmt_adv_pattern patterns[];
} __packed;Thanks,
Archie
Marcel Holtmann
maintainerRe: [PATCH v1 1/5] Bluetooth: advmon offload MSFT add rssi support
Hi Archie,
Quoted 71 lines
Quoted 71 lines
Quoted 71 lines
Quoted 46 lines
Quoted 6 lines
MSFT needs rssi parameter for monitoring advertisement packet, therefore we should supply them from mgmt.
Signed-off-by Archie Pusaka <[email protected]>Reviewed-by Miao-chen Chou <[email protected]>Reviewed-by Yun-Hao Chung <[email protected]>I don’t need any Reviewed-by if they are not catching an obvious user API breakage.
Quoted 37 lines
---
include/net/bluetooth/hci_core.h | 9 +++++++++ include/net/bluetooth/mgmt.h | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++++++ 3 files changed, 26 insertions(+)include/net/bluetooth/hci_core.h +9
-0@@ -246,8 +246,17 @@ struct adv_pattern {__u8 value[HCI_MAX_AD_LENGTH ]; }; +struct adv_rssi_thresholds { +__s8 low_threshold; +__s8 high_threshold; +__u16 low_threshold_timeout; +__u16 high_threshold_timeout; +__u8 sampling_period; +}; +struct adv_monitor {struct list_head patterns; +struct adv_rssi_thresholds rssi;bool active;__u16 handle; };include/net/bluetooth/mgmt.h +0
-0@@ -763,9 +763,18 @@ struct mgmt_adv_pattern {__u8 value[31 ]; } __packed;Quoted 16 lines
Quoted 4 lines
include/net/bluetooth/mgmt.h +4
-0+struct mgmt_adv_rssi_thresholds { +__s8 high_threshold; +__le16 high_threshold_timeout; +__s8 low_threshold;include/net/bluetooth/mgmt.h struct mgmt_adv_pattern { · line 779
Quoted 10 lines
include/net/bluetooth/mgmt.h +5
-0+__le16 low_threshold_timeout; +__u8 sampling_period; +} __packed; +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052struct mgmt_cp_add_adv_patterns_monitor {__u8 pattern_count; +struct mgmt_adv_rssi_thresholds rssi;struct mgmt_adv_pattern patterns[]; } __packed;This is something we can not do. It breaks an userspace facing API. Is the mgmt opcode
0x0052in an already released kernel?Yes, the opcode does exist in an already released kernel.
The DBus method which accesses this API is put behind the experimental flag, therefore we expect they are flexible enough to support changes. Previously, we already had a discussion in an email thread with the title "Offload RSSI tracking to controller", and the outcome supports this change.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Here is an excerpt of the discussion.
it doesn’t matter. This is fixed API now and so we can not just change it. The argument above is void. What matters if it is in already released kernel.
If that is the case, do you have a suggestion to allow RSSI to be considered when monitoring advertisement? Would a new MGMT opcode with these parameters suffice?
its the only way.
Regards
Marcel
Re: [PATCH v1 1/5] Bluetooth: advmon offload MSFT add rssi support
Hi Marcel,
Quoted 76 lines · Marcel Holtmann
Hi Archie,
Quoted 73 lines
Quoted 73 lines
Quoted 72 lines
Quoted 46 lines
Quoted 6 lines
MSFT needs rssi parameter for monitoring advertisement packet, therefore we should supply them from mgmt.
Signed-off-by Archie Pusaka <[email protected]>Reviewed-by Miao-chen Chou <[email protected]>Reviewed-by Yun-Hao Chung <[email protected]>I don’t need any Reviewed-by if they are not catching an obvious user API breakage.
Quoted 37 lines
---
include/net/bluetooth/hci_core.h | 9 +++++++++ include/net/bluetooth/mgmt.h | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++++++ 3 files changed, 26 insertions(+)include/net/bluetooth/hci_core.h +9
-0@@ -246,8 +246,17 @@ struct adv_pattern {__u8 value[HCI_MAX_AD_LENGTH ]; }; +struct adv_rssi_thresholds { +__s8 low_threshold; +__s8 high_threshold; +__u16 low_threshold_timeout; +__u16 high_threshold_timeout; +__u8 sampling_period; +}; +struct adv_monitor {struct list_head patterns; +struct adv_rssi_thresholds rssi;bool active;__u16 handle; };include/net/bluetooth/mgmt.h +0
-0@@ -763,9 +763,18 @@ struct mgmt_adv_pattern {__u8 value[31 ]; } __packed;Quoted 16 lines
Quoted 4 lines
include/net/bluetooth/mgmt.h +4
-0+struct mgmt_adv_rssi_thresholds { +__s8 high_threshold; +__le16 high_threshold_timeout; +__s8 low_threshold;include/net/bluetooth/mgmt.h struct mgmt_adv_pattern { · line 779
Quoted 10 lines
include/net/bluetooth/mgmt.h +5
-0+__le16 low_threshold_timeout; +__u8 sampling_period; +} __packed; +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052struct mgmt_cp_add_adv_patterns_monitor {__u8 pattern_count; +struct mgmt_adv_rssi_thresholds rssi;struct mgmt_adv_pattern patterns[]; } __packed;This is something we can not do. It breaks an userspace facing API. Is the mgmt opcode
0x0052in an already released kernel?Yes, the opcode does exist in an already released kernel.
The DBus method which accesses this API is put behind the experimental flag, therefore we expect they are flexible enough to support changes. Previously, we already had a discussion in an email thread with the title "Offload RSSI tracking to controller", and the outcome supports this change.
Here is an excerpt of the discussion.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
it doesn’t matter. This is fixed API now and so we can not just change it. The argument above is void. What matters if it is in already released kernel.
If that is the case, do you have a suggestion to allow RSSI to be considered when monitoring advertisement? Would a new MGMT opcode with these parameters suffice?
its the only way.
I will make the necessary changes. Thanks for the confirmation.
Regards,
Archie
Quoted 5 lines
Regards
Marcel
PATCH 2/5 Bluetooth: advmon offload MSFT add monitor
In reply to Archie PusakaFrom: Archie Pusaka <[email protected]>
Enables advertising monitor offloading to the controller, if MSFT extension is supported. The kernel won't adjust the monitor parameters to match what the controller supports - that is the user space's responsibility.
This patch only manages the addition of monitors. Monitor removal is going to be handled by another patch.
---
include/net/bluetooth/hci_core.h | 17 ++- net/bluetooth/hci_core.c | 54 +++++++-- net/bluetooth/mgmt.c | 150 +++++++++++++++-------- net/bluetooth/msft.c | 201 ++++++++++++++++++++++++++++++- net/bluetooth/msft.h | 12 ++ 5 files changed, 369 insertions(+), 65 deletions(-)
include/net/bluetooth/hci_core.h +14 -3
@@ -257,13 +257,20 @@ struct adv_rssi_thresholds {struct adv_monitor {struct list_head patterns;struct adv_rssi_thresholds rssi; -bool active;__u16 handle; + +enum { +ADV_MONITOR_STATE_NOT_REGISTERED , +ADV_MONITOR_STATE_REGISTERED , +ADV_MONITOR_STATE_OFFLOADED + } state; };#define HCI_MIN_ADV_MONITOR_HANDLE 1 -#define HCI_MAX_ADV_MONITOR_NUM_HANDLES 32 +#define HCI_MAX_ADV_MONITOR_NUM_HANDLES 32#define HCI_MAX_ADV_MONITOR_NUM_PATTERNS 16 +#define HCI_ADV_MONITOR_EXT_NONE 1 +#define HCI_ADV_MONITOR_EXT_MSFT 2#define HCI_MAX_SHORT_NAME_LENGTH 10
@@ -1305,9 +1312,12 @@ void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);void hci_adv_monitors_clear (struct hci_dev *hdev);void hci_free_adv_monitor (struct adv_monitor *monitor); -int hci_add_adv_monitor (struct hci_dev *hdev,struct adv_monitor *monitor); +int hci_add_adv_patterns_monitor_complete (struct hci_dev *hdev,u8 status); +bool hci_add_adv_monitor (struct hci_dev *hdev,struct adv_monitor *monitor, +int *err);int hci_remove_adv_monitor (struct hci_dev *hdev,u16 handle);bool hci_is_adv_monitoring (struct hci_dev *hdev); +int hci_get_adv_monitor_offload_ext (struct hci_dev *hdev);void hci_event_packet (struct hci_dev *hdev,struct sk_buff *skb);
@@ -1783,6 +1793,7 @@ void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,void mgmt_advertising_removed (struct sock *sk,struct hci_dev *hdev,u8 instance);int mgmt_phy_configuration_changed (struct hci_dev *hdev,struct sock *skip); +int mgmt_add_adv_patterns_monitor_complete (struct hci_dev *hdev,u8 status);u8 hci_le_conn_update (struct hci_conn *conn,u16 min,u16 max,u16 latency,u16 to_multiplier);
net/bluetooth/hci_core.c +45 -9
78 lines not on this page · raw message
net/bluetooth/mgmt.c +98 -52
232 lines not on this page · raw message
net/bluetooth/msft.c +200 -1
244 lines not on this page · raw message
net/bluetooth/msft.h +12 -0
@@ -12,16 +12,28 @@#if IS_ENABLED (CONFIG_BT_MSFTEXT ) +bool msft_monitor_supported (struct hci_dev *hdev);void msft_do_open (struct hci_dev *hdev);void msft_do_close (struct hci_dev *hdev);void msft_vendor_evt (struct hci_dev *hdev,struct sk_buff *skb);__u64 msft_get_features (struct hci_dev *hdev); +int msft_add_monitor_pattern (struct hci_dev *hdev,struct adv_monitor *monitor);#else +static inline bool msft_monitor_supported (struct hci_dev *hdev) +{ +return false; +} +static inline void msft_do_open (struct hci_dev *hdev) {}static inline void msft_do_close (struct hci_dev *hdev) {}static inline void msft_vendor_evt (struct hci_dev *hdev,struct sk_buff *skb) {}static inline __u64 msft_get_features (struct hci_dev *hdev) {return 0 ; } +static inline int msft_add_monitor_pattern (struct hci_dev *hdev, +struct adv_monitor *monitor) +{ +return -EOPNOTSUPP ; +}#endif
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH 3/5 Bluetooth: advmon offload MSFT remove monitor
In reply to Archie PusakaFrom: Archie Pusaka <[email protected]>
Implements the monitor removal functionality for advertising monitor offloading to MSFT controllers. Supply handle = 0 to remove all monitors.
---
include/net/bluetooth/hci_core.h | 8 +- net/bluetooth/hci_core.c | 119 +++++++++++++++++++++++------ net/bluetooth/mgmt.c | 109 +++++++++++++++++++++----- net/bluetooth/msft.c | 127 ++++++++++++++++++++++++++++++- net/bluetooth/msft.h | 9 +++ 5 files changed, 322 insertions(+), 50 deletions(-)
include/net/bluetooth/hci_core.h +6 -2
@@ -1311,11 +1311,13 @@ int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);void hci_adv_instances_set_rpa_expired (struct hci_dev *hdev,bool rpa_expired);void hci_adv_monitors_clear (struct hci_dev *hdev); -void hci_free_adv_monitor (struct adv_monitor *monitor); +void hci_free_adv_monitor (struct hci_dev *hdev,struct adv_monitor *monitor);int hci_add_adv_patterns_monitor_complete (struct hci_dev *hdev,u8 status); +int hci_remove_adv_monitor_complete (struct hci_dev *hdev,u8 status);bool hci_add_adv_monitor (struct hci_dev *hdev,struct adv_monitor *monitor,int *err); -int hci_remove_adv_monitor (struct hci_dev *hdev,u16 handle); +bool hci_remove_single_adv_monitor (struct hci_dev *hdev,u16 handle,int *err); +bool hci_remove_all_adv_monitor (struct hci_dev *hdev,int *err);bool hci_is_adv_monitoring (struct hci_dev *hdev);int hci_get_adv_monitor_offload_ext (struct hci_dev *hdev);
@@ -1792,8 +1794,10 @@ void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance);void mgmt_advertising_removed (struct sock *sk,struct hci_dev *hdev,u8 instance); +void mgmt_adv_monitor_removed (struct hci_dev *hdev,u16 handle);int mgmt_phy_configuration_changed (struct hci_dev *hdev,struct sock *skip);int mgmt_add_adv_patterns_monitor_complete (struct hci_dev *hdev,u8 status); +int mgmt_remove_adv_monitor_complete (struct hci_dev *hdev,u8 status);u8 hci_le_conn_update (struct hci_conn *conn,u16 min,u16 max,u16 latency,u16 to_multiplier);
net/bluetooth/hci_core.c +96 -23
161 lines not on this page · raw message
net/bluetooth/mgmt.c +88 -21
150 lines not on this page · raw message
net/bluetooth/msft.c +123 -4
160 lines not on this page · raw message
net/bluetooth/msft.h +9 -0
@@ -18,6 +18,8 @@ void msft_do_close(struct hci_dev *hdev);void msft_vendor_evt (struct hci_dev *hdev,struct sk_buff *skb);__u64 msft_get_features (struct hci_dev *hdev);int msft_add_monitor_pattern (struct hci_dev *hdev,struct adv_monitor *monitor); +int msft_remove_monitor (struct hci_dev *hdev,struct adv_monitor *monitor, +u16 handle);#else
@@ -36,4 +38,11 @@ static inline int msft_add_monitor_pattern(struct hci_dev *hdev, return -EOPNOTSUPP; } +static inline bool msft_remove_monitor (struct hci_dev *hdev, +struct adv_monitor *monitor, +u16 handle) +{ +return -EOPNOTSUPP ; +} +#endif
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH 4/5 Bluetooth: advmon offload MSFT handle controller reset
In reply to Archie PusakaFrom: Archie Pusaka <[email protected]>
When the controller is powered off, the registered advertising monitor is removed from the controller. This patch handles the re-registration of those monitors when the power is on.
---
net/bluetooth/msft.c | 79 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 5 deletions(-)
net/bluetooth/msft.c +74 -5
@@ -82,8 +82,15 @@ struct msft_data {struct list_head handle_map;__u16 pending_add_handle;__u16 pending_remove_handle; + +struct { +u8 reregistering:1 ; + } flags; }; +static int __msft_add_monitor_pattern (struct hci_dev *hdev, +struct adv_monitor *monitor); +bool msft_monitor_supported (struct hci_dev *hdev) {return !!(msft_get_features (hdev) &MSFT_FEATURE_MASK_LE_ADV_MONITOR );
@@ -134,6 +141,35 @@ static bool read_supported_features(struct hci_dev *hdev,return false; } +/* This function requires the caller holds hdev->lock */ +static void reregister_monitor_on_restart (struct hci_dev *hdev,int handle) +{ +struct adv_monitor *monitor; +struct msft_data *msft = hdev->msft_data; +int err; + +while (1 ) { + monitor =idr_get_next (&hdev->adv_monitors_idr, &handle); +if (!monitor) { +/* All monitors have been reregistered */ + msft->flags.reregistering = false; +hci_update_background_scan (hdev); +return ; + } + + msft->pending_add_handle = (u16 )handle; + err =__msft_add_monitor_pattern (hdev, monitor); + +/* If success, we return and wait for monitor added callback */ +if (!err) +return ; + +/* Otherwise remove the monitor and keep registering */ +hci_free_adv_monitor (hdev, monitor); + handle++; + } +} +void msft_do_open (struct hci_dev *hdev) {struct msft_data *msft;
@@ -154,12 +190,18 @@ void msft_do_open(struct hci_dev *hdev)INIT_LIST_HEAD (&msft->handle_map); hdev->msft_data = msft; + +if (msft_monitor_supported (hdev)) { + msft->flags.reregistering = true; +reregister_monitor_on_restart (hdev,0 ); + } }void msft_do_close (struct hci_dev *hdev) {struct msft_data *msft = hdev->msft_data;struct msft_monitor_advertisement_handle_data *handle_data, *tmp; +struct adv_monitor *monitor;if (!msft)return ;
@@ -169,6 +211,12 @@ void msft_do_close(struct hci_dev *hdev) hdev->msft_data =NULL ;list_for_each_entry_safe (handle_data, tmp, &msft->handle_map, list) { + monitor =idr_find (&hdev->adv_monitors_idr, + handle_data->mgmt_handle); + +if (monitor && monitor->state ==ADV_MONITOR_STATE_OFFLOADED ) + monitor->state =ADV_MONITOR_STATE_REGISTERED ; +list_del (&handle_data->list);kfree (handle_data); }
@@ -282,9 +330,15 @@ static void msft_le_monitor_advertisement_cb(struct hci_dev *hdev,if (status && monitor)hci_free_adv_monitor (hdev, monitor); +/* If in restart/reregister sequence, keep registering. */ +if (msft->flags.reregistering) +reregister_monitor_on_restart (hdev, + msft->pending_add_handle +1 ); +hci_dev_unlock (hdev); -hci_add_adv_patterns_monitor_complete (hdev, status); +if (!msft->flags.reregistering) +hci_add_adv_patterns_monitor_complete (hdev, status); } static void msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev,
@@ -374,7 +428,8 @@ static bool msft_monitor_pattern_valid(struct adv_monitor *monitor) }/* This function requires the caller holds hdev->lock */ -int msft_add_monitor_pattern (struct hci_dev *hdev,struct adv_monitor *monitor) +static int __msft_add_monitor_pattern (struct hci_dev *hdev, +struct adv_monitor *monitor) {struct msft_cp_le_monitor_advertisement *cp;struct msft_le_monitor_advertisement_pattern_data *pattern_data;
@@ -387,9 +442,6 @@ int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor)u8 pattern_count =0 ;int err =0 ; -if (!msft) -return -EOPNOTSUPP ; -if (!msft_monitor_pattern_valid (monitor))return -EINVAL ;
@@ -434,6 +486,20 @@ int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor)return err; } +/* This function requires the caller holds hdev->lock */ +int msft_add_monitor_pattern (struct hci_dev *hdev,struct adv_monitor *monitor) +{ +struct msft_data *msft = hdev->msft_data; + +if (!msft) +return -EOPNOTSUPP ; + +if (msft->flags.reregistering) +return -EBUSY ; + +return __msft_add_monitor_pattern (hdev, monitor); +} +/* This function requires the caller holds hdev->lock */ int msft_remove_monitor (struct hci_dev *hdev,struct adv_monitor *monitor,u16 handle)
@@ -447,6 +513,9 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor,if (!msft)return -EOPNOTSUPP ; +if (msft->flags.reregistering) +return -EBUSY ; + handle_data =msft_find_handle_data (hdev, monitor->handle, true);/* If no matched handle, just remove without telling controller */
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH 5/5 Bluetooth: advmon offload MSFT handle filter enablement
In reply to Archie PusakaFrom: Archie Pusaka <[email protected]>
Implements the feature to disable/enable the filter used for advertising monitor on MSFT controller, effectively have the same effect as "remove all monitors" and "add all previously removed monitors".
This feature would be needed when suspending, where we would not want to get packets from anything outside the allowlist. Note that the integration with the suspending part is not included in this patch.
---
net/bluetooth/msft.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ net/bluetooth/msft.h | 6 ++++ 2 files changed, 73 insertions(+)
net/bluetooth/msft.c +67 -0
@@ -69,6 +69,17 @@ struct msft_rp_le_cancel_monitor_advertisement {__u8 sub_opcode; } __packed; +#define MSFT_OP_LE_SET_ADVERTISEMENT_FILTER_ENABLE 0x05 +struct msft_cp_le_set_advertisement_filter_enable { +__u8 sub_opcode; +__u8 enable; +} __packed; + +struct msft_rp_le_set_advertisement_filter_enable { +__u8 status; +__u8 sub_opcode; +} __packed; +struct msft_monitor_advertisement_handle_data {__u8 msft_handle;__u16 mgmt_handle;
@@ -85,6 +96,7 @@ struct msft_data {struct {u8 reregistering:1 ; +u8 filter_enabled:1 ; } flags; };
@@ -193,6 +205,7 @@ void msft_do_open(struct hci_dev *hdev)if (msft_monitor_supported (hdev)) { msft->flags.reregistering = true; +msft_set_filter_enable (hdev, true);reregister_monitor_on_restart (hdev,0 ); } }
@@ -398,6 +411,40 @@ static void msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev,hci_remove_adv_monitor_complete (hdev, status); } +static void msft_le_set_advertisement_filter_enable_cb (struct hci_dev *hdev, +u8 status,u16 opcode, +struct sk_buff *skb) +{ +struct msft_cp_le_set_advertisement_filter_enable *cp; +struct msft_rp_le_set_advertisement_filter_enable *rp; +struct msft_data *msft = hdev->msft_data; + + rp = (struct msft_rp_le_set_advertisement_filter_enable *)skb->data; +if (skb->len <sizeof (*rp)) +return ; + +/* Error 0x0C would be returned if the filter enabled status is +* already set to whatever we were trying to set. +* Although the default state should be disabled, some controller set +* the initial value to enabled. Because there is no way to know the +* actual initial value before sending this command, here we also treat +* error 0x0C as success. +*/ +if (status !=0x00 && status !=0x0C ) +return ; + +hci_dev_lock (hdev); + + cp =hci_sent_cmd_data (hdev, hdev->msft_opcode); + msft->flags.filter_enabled = cp->enable; + +if (status ==0x0C ) +bt_dev_warn (hdev,"MSFT filter_enable is already %s" , + cp->enable ?"on" :"off" ); + +hci_dev_unlock (hdev); +} +static bool msft_monitor_rssi_valid (struct adv_monitor *monitor) {struct adv_rssi_thresholds *r = &monitor->rssi;
@@ -534,3 +581,23 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor,return err; } + +int msft_set_filter_enable (struct hci_dev *hdev,bool enable) +{ +struct msft_cp_le_set_advertisement_filter_enable cp; +struct hci_request req; +struct msft_data *msft = hdev->msft_data; +int err; + +if (!msft) +return -EOPNOTSUPP ; + + cp.sub_opcode =MSFT_OP_LE_SET_ADVERTISEMENT_FILTER_ENABLE ; + cp.enable = enable; + +hci_req_init (&req, hdev); +hci_req_add (&req, hdev->msft_opcode,sizeof (cp), &cp); + err =hci_req_run_skb (&req, msft_le_set_advertisement_filter_enable_cb); + +return err; +}
net/bluetooth/msft.h +6 -0
@@ -20,6 +20,7 @@ __u64 msft_get_features(struct hci_dev *hdev);int msft_add_monitor_pattern (struct hci_dev *hdev,struct adv_monitor *monitor);int msft_remove_monitor (struct hci_dev *hdev,struct adv_monitor *monitor,u16 handle); +int msft_set_filter_enable (struct hci_dev *hdev,bool enable);#else
@@ -45,4 +46,9 @@ static inline bool msft_remove_monitor(struct hci_dev *hdev, return -EOPNOTSUPP; } +static inline int msft_set_filter_enable (struct hci_dev *hdev,bool enable) +{ +return -EOPNOTSUPP ; +} +#endif
Signature · 1 line
2.29.2.454.gaff20da3a2-goog