Skip to content

Commit fe92ee6

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: hci_core: Rework hci_conn_params flags
This reworks hci_conn_params flags to use bitmap_* helpers and add support for setting the supported flags in hdev->conn_flags so it can easily be accessed. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 6f59f99 commit fe92ee6

File tree

5 files changed

+44
-29
lines changed

5 files changed

+44
-29
lines changed

include/net/bluetooth/hci_core.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,21 @@ struct bdaddr_list_with_irk {
152152
u8 local_irk[16];
153153
};
154154

155-
struct bdaddr_list_with_flags {
156-
struct list_head list;
157-
bdaddr_t bdaddr;
158-
u8 bdaddr_type;
159-
u32 current_flags;
160-
};
161-
162155
enum hci_conn_flags {
163156
HCI_CONN_FLAG_REMOTE_WAKEUP,
164-
HCI_CONN_FLAG_MAX
165-
};
166157

167-
#define hci_conn_test_flag(nr, flags) ((flags) & (1U << nr))
158+
__HCI_CONN_NUM_FLAGS,
159+
};
168160

169161
/* Make sure number of flags doesn't exceed sizeof(current_flags) */
170-
static_assert(HCI_CONN_FLAG_MAX < 32);
162+
static_assert(__HCI_CONN_NUM_FLAGS < 32);
163+
164+
struct bdaddr_list_with_flags {
165+
struct list_head list;
166+
bdaddr_t bdaddr;
167+
u8 bdaddr_type;
168+
DECLARE_BITMAP(flags, __HCI_CONN_NUM_FLAGS);
169+
};
171170

172171
struct bt_uuid {
173172
struct list_head list;
@@ -560,6 +559,7 @@ struct hci_dev {
560559
struct rfkill *rfkill;
561560

562561
DECLARE_BITMAP(dev_flags, __HCI_NUM_FLAGS);
562+
DECLARE_BITMAP(conn_flags, __HCI_CONN_NUM_FLAGS);
563563

564564
__s8 adv_tx_power;
565565
__u8 adv_data[HCI_MAX_EXT_AD_LENGTH];
@@ -755,7 +755,7 @@ struct hci_conn_params {
755755

756756
struct hci_conn *conn;
757757
bool explicit_connect;
758-
u32 current_flags;
758+
DECLARE_BITMAP(flags, __HCI_CONN_NUM_FLAGS);
759759
};
760760

761761
extern struct list_head hci_dev_list;

net/bluetooth/hci_core.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -2153,7 +2153,7 @@ int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr,
21532153

21542154
bacpy(&entry->bdaddr, bdaddr);
21552155
entry->bdaddr_type = type;
2156-
entry->current_flags = flags;
2156+
bitmap_from_u64(entry->flags, flags);
21572157

21582158
list_add(&entry->list, list);
21592159

@@ -2629,6 +2629,12 @@ int hci_register_dev(struct hci_dev *hdev)
26292629
if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
26302630
hci_dev_set_flag(hdev, HCI_UNCONFIGURED);
26312631

2632+
/* Mark Remote Wakeup connection flag as supported if driver has wakeup
2633+
* callback.
2634+
*/
2635+
if (hdev->wakeup)
2636+
set_bit(HCI_CONN_FLAG_REMOTE_WAKEUP, hdev->conn_flags);
2637+
26322638
hci_sock_dev_event(hdev, HCI_DEV_REG);
26332639
hci_dev_hold(hdev);
26342640

net/bluetooth/hci_request.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ static int add_to_accept_list(struct hci_request *req,
481481
}
482482

483483
/* During suspend, only wakeable devices can be in accept list */
484-
if (hdev->suspended && !hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP,
485-
params->current_flags))
484+
if (hdev->suspended &&
485+
!test_bit(HCI_CONN_FLAG_REMOTE_WAKEUP, params->flags))
486486
return 0;
487487

488488
*num_entries += 1;

net/bluetooth/hci_sync.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -1623,8 +1623,8 @@ static int hci_le_add_accept_list_sync(struct hci_dev *hdev,
16231623
}
16241624

16251625
/* During suspend, only wakeable devices can be in acceptlist */
1626-
if (hdev->suspended && !hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP,
1627-
params->current_flags))
1626+
if (hdev->suspended &&
1627+
!test_bit(HCI_CONN_FLAG_REMOTE_WAKEUP, params->flags))
16281628
return 0;
16291629

16301630
/* Attempt to program the device in the resolving list first to avoid
@@ -4767,8 +4767,7 @@ static int hci_update_event_filter_sync(struct hci_dev *hdev)
47674767
hci_clear_event_filter_sync(hdev);
47684768

47694769
list_for_each_entry(b, &hdev->accept_list, list) {
4770-
if (!hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP,
4771-
b->current_flags))
4770+
if (!test_bit(HCI_CONN_FLAG_REMOTE_WAKEUP, b->flags))
47724771
continue;
47734772

47744773
bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr);

net/bluetooth/mgmt.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -4349,16 +4349,14 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
43494349
MGMT_STATUS_NOT_SUPPORTED);
43504350
}
43514351

4352-
#define SUPPORTED_DEVICE_FLAGS() ((1U << HCI_CONN_FLAG_MAX) - 1)
4353-
43544352
static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
43554353
u16 data_len)
43564354
{
43574355
struct mgmt_cp_get_device_flags *cp = data;
43584356
struct mgmt_rp_get_device_flags rp;
43594357
struct bdaddr_list_with_flags *br_params;
43604358
struct hci_conn_params *params;
4361-
u32 supported_flags = SUPPORTED_DEVICE_FLAGS();
4359+
u32 supported_flags;
43624360
u32 current_flags = 0;
43634361
u8 status = MGMT_STATUS_INVALID_PARAMS;
43644362

@@ -4367,6 +4365,9 @@ static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
43674365

43684366
hci_dev_lock(hdev);
43694367

4368+
bitmap_to_arr32(&supported_flags, hdev->conn_flags,
4369+
__HCI_CONN_NUM_FLAGS);
4370+
43704371
memset(&rp, 0, sizeof(rp));
43714372

43724373
if (cp->addr.type == BDADDR_BREDR) {
@@ -4376,15 +4377,17 @@ static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
43764377
if (!br_params)
43774378
goto done;
43784379

4379-
current_flags = br_params->current_flags;
4380+
bitmap_to_arr32(&current_flags, br_params->flags,
4381+
__HCI_CONN_NUM_FLAGS);
43804382
} else {
43814383
params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr,
43824384
le_addr_type(cp->addr.type));
43834385

43844386
if (!params)
43854387
goto done;
43864388

4387-
current_flags = params->current_flags;
4389+
bitmap_to_arr32(&current_flags, params->flags,
4390+
__HCI_CONN_NUM_FLAGS);
43884391
}
43894392

43904393
bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
@@ -4422,13 +4425,16 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
44224425
struct bdaddr_list_with_flags *br_params;
44234426
struct hci_conn_params *params;
44244427
u8 status = MGMT_STATUS_INVALID_PARAMS;
4425-
u32 supported_flags = SUPPORTED_DEVICE_FLAGS();
4428+
u32 supported_flags;
44264429
u32 current_flags = __le32_to_cpu(cp->current_flags);
44274430

44284431
bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x",
44294432
&cp->addr.bdaddr, cp->addr.type,
44304433
__le32_to_cpu(current_flags));
44314434

4435+
bitmap_to_arr32(&supported_flags, hdev->conn_flags,
4436+
__HCI_CONN_NUM_FLAGS);
4437+
44324438
if ((supported_flags | current_flags) != supported_flags) {
44334439
bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)",
44344440
current_flags, supported_flags);
@@ -4443,7 +4449,7 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
44434449
cp->addr.type);
44444450

44454451
if (br_params) {
4446-
br_params->current_flags = current_flags;
4452+
bitmap_from_u64(br_params->flags, current_flags);
44474453
status = MGMT_STATUS_SUCCESS;
44484454
} else {
44494455
bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)",
@@ -4453,7 +4459,7 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
44534459
params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr,
44544460
le_addr_type(cp->addr.type));
44554461
if (params) {
4456-
params->current_flags = current_flags;
4462+
bitmap_from_u64(params->flags, current_flags);
44574463
status = MGMT_STATUS_SUCCESS;
44584464
} else {
44594465
bt_dev_warn(hdev, "No such LE device %pMR (0x%x)",
@@ -6979,6 +6985,7 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
69796985
struct hci_conn_params *params;
69806986
int err;
69816987
u32 current_flags = 0;
6988+
u32 supported_flags;
69826989

69836990
bt_dev_dbg(hdev, "sock %p", sk);
69846991

@@ -7050,7 +7057,8 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
70507057
params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr,
70517058
addr_type);
70527059
if (params)
7053-
current_flags = params->current_flags;
7060+
bitmap_to_arr32(&current_flags, params->flags,
7061+
__HCI_CONN_NUM_FLAGS);
70547062
}
70557063

70567064
err = hci_cmd_sync_queue(hdev, add_device_sync, NULL, NULL);
@@ -7059,8 +7067,10 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
70597067

70607068
added:
70617069
device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action);
7070+
bitmap_to_arr32(&supported_flags, hdev->conn_flags,
7071+
__HCI_CONN_NUM_FLAGS);
70627072
device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type,
7063-
SUPPORTED_DEVICE_FLAGS(), current_flags);
7073+
supported_flags, current_flags);
70647074

70657075
err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
70667076
MGMT_STATUS_SUCCESS, &cp->addr,

0 commit comments

Comments
 (0)