Skip to content

Commit bd2fbc6

Browse files
mcchou-crjhedberg
authored andcommitted
Bluetooth: Add handler of MGMT_OP_REMOVE_ADV_MONITOR
This adds the request handler of MGMT_OP_REMOVE_ADV_MONITOR command. Note that the controller-based monitoring is not yet in place. This removes the internal monitor(s) without sending HCI traffic, so the request returns immediately. The following test was performed. - Issue btmgmt advmon-remove with valid and invalid handles. Signed-off-by: Miao-chen Chou <mcchou@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent b139553 commit bd2fbc6

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,7 @@ void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
12831283
void hci_adv_monitors_clear(struct hci_dev *hdev);
12841284
void hci_free_adv_monitor(struct adv_monitor *monitor);
12851285
int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
1286+
int hci_remove_adv_monitor(struct hci_dev *hdev, u16 handle);
12861287

12871288
void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
12881289

‎net/bluetooth/hci_core.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,37 @@ int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
30413041
return 0;
30423042
}
30433043

3044+
static int free_adv_monitor(int id, void *ptr, void *data)
3045+
{
3046+
struct hci_dev *hdev = data;
3047+
struct adv_monitor *monitor = ptr;
3048+
3049+
idr_remove(&hdev->adv_monitors_idr, monitor->handle);
3050+
hci_free_adv_monitor(monitor);
3051+
3052+
return 0;
3053+
}
3054+
3055+
/* This function requires the caller holds hdev->lock */
3056+
int hci_remove_adv_monitor(struct hci_dev *hdev, u16 handle)
3057+
{
3058+
struct adv_monitor *monitor;
3059+
3060+
if (handle) {
3061+
monitor = idr_find(&hdev->adv_monitors_idr, handle);
3062+
if (!monitor)
3063+
return -ENOENT;
3064+
3065+
idr_remove(&hdev->adv_monitors_idr, monitor->handle);
3066+
hci_free_adv_monitor(monitor);
3067+
} else {
3068+
/* Remove all monitors if handle is 0. */
3069+
idr_for_each(&hdev->adv_monitors_idr, &free_adv_monitor, hdev);
3070+
}
3071+
3072+
return 0;
3073+
}
3074+
30443075
struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *bdaddr_list,
30453076
bdaddr_t *bdaddr, u8 type)
30463077
{

‎net/bluetooth/mgmt.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static const u16 mgmt_commands[] = {
121121
MGMT_OP_SET_DEVICE_FLAGS,
122122
MGMT_OP_READ_ADV_MONITOR_FEATURES,
123123
MGMT_OP_ADD_ADV_PATTERNS_MONITOR,
124+
MGMT_OP_REMOVE_ADV_MONITOR,
124125
};
125126

126127
static const u16 mgmt_events[] = {
@@ -4118,6 +4119,39 @@ static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev,
41184119
return err;
41194120
}
41204121

4122+
static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev,
4123+
void *data, u16 len)
4124+
{
4125+
struct mgmt_cp_remove_adv_monitor *cp = data;
4126+
struct mgmt_rp_remove_adv_monitor rp;
4127+
u16 handle;
4128+
int err;
4129+
4130+
BT_DBG("request for %s", hdev->name);
4131+
4132+
hci_dev_lock(hdev);
4133+
4134+
handle = __le16_to_cpu(cp->monitor_handle);
4135+
4136+
err = hci_remove_adv_monitor(hdev, handle);
4137+
if (err == -ENOENT) {
4138+
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR,
4139+
MGMT_STATUS_INVALID_INDEX);
4140+
goto unlock;
4141+
}
4142+
4143+
hci_dev_unlock(hdev);
4144+
4145+
rp.monitor_handle = cp->monitor_handle;
4146+
4147+
return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR,
4148+
MGMT_STATUS_SUCCESS, &rp, sizeof(rp));
4149+
4150+
unlock:
4151+
hci_dev_unlock(hdev);
4152+
return err;
4153+
}
4154+
41214155
static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status,
41224156
u16 opcode, struct sk_buff *skb)
41234157
{
@@ -7589,6 +7623,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = {
75897623
{ read_adv_mon_features, MGMT_READ_ADV_MONITOR_FEATURES_SIZE },
75907624
{ add_adv_patterns_monitor,MGMT_ADD_ADV_PATTERNS_MONITOR_SIZE,
75917625
HCI_MGMT_VAR_LEN },
7626+
{ remove_adv_monitor, MGMT_REMOVE_ADV_MONITOR_SIZE },
75927627
};
75937628

75947629
void mgmt_index_added(struct hci_dev *hdev)

0 commit comments

Comments
 (0)