Skip to content

Commit 5f1764d

Browse files
committed
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next
Johan Hedberg says: ==================== Here's another set of Bluetooth & ieee802154 patches intended for 4.1: - Added support for QCA ROME chipset family in the btusb driver - at86rf230 driver fixes & cleanups - ieee802154 cleanups - Refactoring of Bluetooth mgmt API to allow new users - New setting for static Bluetooth address exposed to user space - Refactoring of hci_dev flags to remove limit of 32 - Remove unnecessary fast-connectable setting usage restrictions - Fix behavior to be consistent when trying to pair already paired device - Service discovery corner-case fixes Please let me know if there are any issues pulling. Thanks. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 2801be4 + b6d595e commit 5f1764d

File tree

23 files changed

+1888
-1386
lines changed

23 files changed

+1888
-1386
lines changed

drivers/bluetooth/btusb.c

Lines changed: 301 additions & 32 deletions
Large diffs are not rendered by default.

drivers/net/ieee802154/at86rf230.c

Lines changed: 154 additions & 72 deletions
Large diffs are not rendered by default.

include/linux/ieee802154.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define IEEE802154_MTU 127
3131
#define IEEE802154_ACK_PSDU_LEN 5
3232
#define IEEE802154_MIN_PSDU_LEN 9
33+
#define IEEE802154_FCS_LEN 2
3334

3435
#define IEEE802154_PAN_ID_BROADCAST 0xffff
3536
#define IEEE802154_ADDR_SHORT_BROADCAST 0xffff
@@ -39,6 +40,7 @@
3940

4041
#define IEEE802154_LIFS_PERIOD 40
4142
#define IEEE802154_SIFS_PERIOD 12
43+
#define IEEE802154_MAX_SIFS_FRAME_SIZE 18
4244

4345
#define IEEE802154_MAX_CHANNEL 26
4446
#define IEEE802154_MAX_PAGE 31

include/net/bluetooth/bluetooth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ void l2cap_exit(void);
354354
int sco_init(void);
355355
void sco_exit(void);
356356

357+
int mgmt_init(void);
358+
void mgmt_exit(void);
359+
357360
void bt_sock_reclassify_lock(struct sock *sk, int proto);
358361

359362
#endif /* __BLUETOOTH_H */

include/net/bluetooth/hci.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,6 @@ enum {
179179
HCI_RESET,
180180
};
181181

182-
/* BR/EDR and/or LE controller flags: the flags defined here should represent
183-
* states configured via debugfs for debugging and testing purposes only.
184-
*/
185-
enum {
186-
HCI_DUT_MODE,
187-
HCI_FORCE_BREDR_SMP,
188-
HCI_FORCE_STATIC_ADDR,
189-
};
190-
191182
/*
192183
* BR/EDR and/or LE controller flags: the flags defined here should represent
193184
* states from the controller.
@@ -217,6 +208,7 @@ enum {
217208
HCI_HS_ENABLED,
218209
HCI_LE_ENABLED,
219210
HCI_ADVERTISING,
211+
HCI_ADVERTISING_CONNECTABLE,
220212
HCI_CONNECTABLE,
221213
HCI_DISCOVERABLE,
222214
HCI_LIMITED_DISCOVERABLE,
@@ -225,13 +217,13 @@ enum {
225217
HCI_FAST_CONNECTABLE,
226218
HCI_BREDR_ENABLED,
227219
HCI_LE_SCAN_INTERRUPTED,
228-
};
229220

230-
/* A mask for the flags that are supposed to remain when a reset happens
231-
* or the HCI device is closed.
232-
*/
233-
#define HCI_PERSISTENT_MASK (BIT(HCI_LE_SCAN) | BIT(HCI_PERIODIC_INQ) | \
234-
BIT(HCI_FAST_CONNECTABLE) | BIT(HCI_LE_ADV))
221+
HCI_DUT_MODE,
222+
HCI_FORCE_BREDR_SMP,
223+
HCI_FORCE_STATIC_ADDR,
224+
225+
__HCI_NUM_FLAGS,
226+
};
235227

236228
/* HCI timeouts */
237229
#define HCI_DISCONN_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */

include/net/bluetooth/hci_core.h

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct discovery_state {
7676
u8 last_adv_data[HCI_MAX_AD_LENGTH];
7777
u8 last_adv_data_len;
7878
bool report_invalid_rssi;
79+
bool result_filtering;
7980
s8 rssi;
8081
u16 uuid_count;
8182
u8 (*uuids)[16];
@@ -352,8 +353,7 @@ struct hci_dev {
352353

353354
struct rfkill *rfkill;
354355

355-
unsigned long dbg_flags;
356-
unsigned long dev_flags;
356+
DECLARE_BITMAP(dev_flags, __HCI_NUM_FLAGS);
357357

358358
struct delayed_work le_scan_disable;
359359
struct delayed_work le_scan_restart;
@@ -501,6 +501,21 @@ extern struct list_head hci_cb_list;
501501
extern rwlock_t hci_dev_list_lock;
502502
extern struct mutex hci_cb_list_lock;
503503

504+
#define hci_dev_set_flag(hdev, nr) set_bit((nr), (hdev)->dev_flags)
505+
#define hci_dev_clear_flag(hdev, nr) clear_bit((nr), (hdev)->dev_flags)
506+
#define hci_dev_change_flag(hdev, nr) change_bit((nr), (hdev)->dev_flags)
507+
#define hci_dev_test_flag(hdev, nr) test_bit((nr), (hdev)->dev_flags)
508+
#define hci_dev_test_and_set_flag(hdev, nr) test_and_set_bit((nr), (hdev)->dev_flags)
509+
#define hci_dev_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), (hdev)->dev_flags)
510+
#define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), (hdev)->dev_flags)
511+
512+
#define hci_dev_clear_volatile_flags(hdev) \
513+
do { \
514+
hci_dev_clear_flag(hdev, HCI_LE_SCAN); \
515+
hci_dev_clear_flag(hdev, HCI_LE_ADV); \
516+
hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); \
517+
} while (0)
518+
504519
/* ----- HCI interface to upper protocols ----- */
505520
int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
506521
int l2cap_disconn_ind(struct hci_conn *hcon);
@@ -525,6 +540,7 @@ static inline void discovery_init(struct hci_dev *hdev)
525540

526541
static inline void hci_discovery_filter_clear(struct hci_dev *hdev)
527542
{
543+
hdev->discovery.result_filtering = false;
528544
hdev->discovery.report_invalid_rssi = true;
529545
hdev->discovery.rssi = HCI_RSSI_INVALID;
530546
hdev->discovery.uuid_count = 0;
@@ -596,14 +612,14 @@ enum {
596612
static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
597613
{
598614
struct hci_dev *hdev = conn->hdev;
599-
return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
615+
return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) &&
600616
test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
601617
}
602618

603619
static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
604620
{
605621
struct hci_dev *hdev = conn->hdev;
606-
return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) &&
622+
return hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
607623
test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
608624
}
609625

@@ -965,6 +981,8 @@ struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
965981
void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
966982
void hci_smp_irks_clear(struct hci_dev *hdev);
967983

984+
bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
985+
968986
void hci_remote_oob_data_clear(struct hci_dev *hdev);
969987
struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
970988
bdaddr_t *bdaddr, u8 bdaddr_type);
@@ -1021,10 +1039,10 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
10211039
#define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE))
10221040
#define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
10231041

1024-
#define hdev_is_powered(hdev) (test_bit(HCI_UP, &hdev->flags) && \
1025-
!test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
1026-
#define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \
1027-
test_bit(HCI_SC_ENABLED, &(dev)->dev_flags))
1042+
#define hdev_is_powered(dev) (test_bit(HCI_UP, &(dev)->flags) && \
1043+
!hci_dev_test_flag(dev, HCI_AUTO_OFF))
1044+
#define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \
1045+
hci_dev_test_flag(dev, HCI_SC_ENABLED))
10281046

10291047
/* ----- HCI protocols ----- */
10301048
#define HCI_PROTO_DEFER 0x01
@@ -1271,6 +1289,27 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
12711289

12721290
void hci_sock_dev_event(struct hci_dev *hdev, int event);
12731291

1292+
#define HCI_MGMT_VAR_LEN (1 << 0)
1293+
#define HCI_MGMT_NO_HDEV (1 << 1)
1294+
#define HCI_MGMT_UNCONFIGURED (1 << 2)
1295+
1296+
struct hci_mgmt_handler {
1297+
int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
1298+
u16 data_len);
1299+
size_t data_len;
1300+
unsigned long flags;
1301+
};
1302+
1303+
struct hci_mgmt_chan {
1304+
struct list_head list;
1305+
unsigned short channel;
1306+
size_t handler_count;
1307+
const struct hci_mgmt_handler *handlers;
1308+
};
1309+
1310+
int hci_mgmt_chan_register(struct hci_mgmt_chan *c);
1311+
void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c);
1312+
12741313
/* Management interface */
12751314
#define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR))
12761315
#define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \
@@ -1290,7 +1329,9 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event);
12901329
#define DISCOV_BREDR_INQUIRY_LEN 0x08
12911330
#define DISCOV_LE_RESTART_DELAY msecs_to_jiffies(200) /* msec */
12921331

1293-
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
1332+
int mgmt_control(struct hci_mgmt_chan *chan, struct sock *sk,
1333+
struct msghdr *msg, size_t msglen);
1334+
12941335
int mgmt_new_settings(struct hci_dev *hdev);
12951336
void mgmt_index_added(struct hci_dev *hdev);
12961337
void mgmt_index_removed(struct hci_dev *hdev);

include/net/bluetooth/mgmt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define MGMT_STATUS_CANCELLED 0x10
4444
#define MGMT_STATUS_INVALID_INDEX 0x11
4545
#define MGMT_STATUS_RFKILLED 0x12
46+
#define MGMT_STATUS_ALREADY_PAIRED 0x13
4647

4748
struct mgmt_hdr {
4849
__le16 opcode;
@@ -98,6 +99,7 @@ struct mgmt_rp_read_index_list {
9899
#define MGMT_SETTING_DEBUG_KEYS 0x00001000
99100
#define MGMT_SETTING_PRIVACY 0x00002000
100101
#define MGMT_SETTING_CONFIGURATION 0x00004000
102+
#define MGMT_SETTING_STATIC_ADDRESS 0x00008000
101103

102104
#define MGMT_OP_READ_INFO 0x0004
103105
#define MGMT_READ_INFO_SIZE 0

net/bluetooth/af_bluetooth.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,13 @@ static int __init bt_init(void)
749749
goto sock_err;
750750
}
751751

752+
err = mgmt_init();
753+
if (err < 0) {
754+
sco_exit();
755+
l2cap_exit();
756+
goto sock_err;
757+
}
758+
752759
return 0;
753760

754761
sock_err:
@@ -763,6 +770,8 @@ static int __init bt_init(void)
763770

764771
static void __exit bt_exit(void)
765772
{
773+
mgmt_exit();
774+
766775
sco_exit();
767776

768777
l2cap_exit();

net/bluetooth/hci_conn.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
571571

572572
list_for_each_entry(d, &hci_dev_list, list) {
573573
if (!test_bit(HCI_UP, &d->flags) ||
574-
test_bit(HCI_USER_CHANNEL, &d->dev_flags) ||
574+
hci_dev_test_flag(d, HCI_USER_CHANNEL) ||
575575
d->dev_type != HCI_BREDR)
576576
continue;
577577

@@ -700,7 +700,7 @@ static void hci_req_directed_advertising(struct hci_request *req,
700700
* and write a new random address. The flag will be set back on
701701
* as soon as the SET_ADV_ENABLE HCI command completes.
702702
*/
703-
clear_bit(HCI_LE_ADV, &hdev->dev_flags);
703+
hci_dev_clear_flag(hdev, HCI_LE_ADV);
704704

705705
/* Set require_privacy to false so that the remote device has a
706706
* chance of identifying us.
@@ -734,7 +734,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
734734
int err;
735735

736736
/* Let's make sure that le is enabled.*/
737-
if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) {
737+
if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
738738
if (lmp_le_capable(hdev))
739739
return ERR_PTR(-ECONNREFUSED);
740740

@@ -799,7 +799,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
799799
* anyway have to disable it in order to start directed
800800
* advertising.
801801
*/
802-
if (test_bit(HCI_LE_ADV, &hdev->dev_flags)) {
802+
if (hci_dev_test_flag(hdev, HCI_LE_ADV)) {
803803
u8 enable = 0x00;
804804
hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
805805
&enable);
@@ -810,7 +810,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
810810
/* If we're active scanning most controllers are unable
811811
* to initiate advertising. Simply reject the attempt.
812812
*/
813-
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags) &&
813+
if (hci_dev_test_flag(hdev, HCI_LE_SCAN) &&
814814
hdev->le_scan_type == LE_SCAN_ACTIVE) {
815815
skb_queue_purge(&req.cmd_q);
816816
hci_conn_del(conn);
@@ -840,9 +840,9 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
840840
* handler for scan disabling knows to set the correct discovery
841841
* state.
842842
*/
843-
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) {
843+
if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
844844
hci_req_add_le_scan_disable(&req);
845-
set_bit(HCI_LE_SCAN_INTERRUPTED, &hdev->dev_flags);
845+
hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED);
846846
}
847847

848848
hci_req_add_le_create_conn(&req, conn);
@@ -864,7 +864,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
864864
{
865865
struct hci_conn *acl;
866866

867-
if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
867+
if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
868868
if (lmp_bredr_capable(hdev))
869869
return ERR_PTR(-ECONNREFUSED);
870870

@@ -942,7 +942,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
942942
* Connections is used and the link is encrypted with AES-CCM
943943
* using a P-256 authenticated combination key.
944944
*/
945-
if (test_bit(HCI_SC_ONLY, &conn->hdev->flags)) {
945+
if (hci_dev_test_flag(conn->hdev, HCI_SC_ONLY)) {
946946
if (!hci_conn_sc_enabled(conn) ||
947947
!test_bit(HCI_CONN_AES_CCM, &conn->flags) ||
948948
conn->key_type != HCI_LK_AUTH_COMBINATION_P256)

0 commit comments

Comments
 (0)