hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/include/net/bluetooth/hci_core.h
....@@ -25,14 +25,19 @@
2525 #ifndef __HCI_CORE_H
2626 #define __HCI_CORE_H
2727
28
+#include <linux/idr.h>
2829 #include <linux/leds.h>
2930 #include <linux/rculist.h>
31
+#include <linux/android_kabi.h>
3032
3133 #include <net/bluetooth/hci.h>
3234 #include <net/bluetooth/hci_sock.h>
3335
3436 /* HCI priority */
3537 #define HCI_PRIO_MAX 7
38
+
39
+/* HCI maximum id value */
40
+#define HCI_MAX_ID 10000
3641
3742 /* HCI Core structures */
3843 struct inquiry_data {
....@@ -88,6 +93,31 @@
8893 unsigned long scan_duration;
8994 };
9095
96
+#define SUSPEND_NOTIFIER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
97
+
98
+enum suspend_tasks {
99
+ SUSPEND_PAUSE_DISCOVERY,
100
+ SUSPEND_UNPAUSE_DISCOVERY,
101
+
102
+ SUSPEND_PAUSE_ADVERTISING,
103
+ SUSPEND_UNPAUSE_ADVERTISING,
104
+
105
+ SUSPEND_SCAN_DISABLE,
106
+ SUSPEND_SCAN_ENABLE,
107
+ SUSPEND_DISCONNECTING,
108
+
109
+ SUSPEND_POWERING_DOWN,
110
+
111
+ SUSPEND_PREPARE_NOTIFIER,
112
+ __SUSPEND_NUM_TASKS
113
+};
114
+
115
+enum suspended_state {
116
+ BT_RUNNING = 0,
117
+ BT_SUSPEND_DISCONNECT,
118
+ BT_SUSPEND_CONFIGURE_WAKE,
119
+};
120
+
91121 struct hci_conn_hash {
92122 struct list_head list;
93123 unsigned int acl_num;
....@@ -103,11 +133,43 @@
103133 u8 bdaddr_type;
104134 };
105135
136
+struct bdaddr_list_with_irk {
137
+ struct list_head list;
138
+ bdaddr_t bdaddr;
139
+ u8 bdaddr_type;
140
+ u8 peer_irk[16];
141
+ u8 local_irk[16];
142
+};
143
+
144
+struct bdaddr_list_with_flags {
145
+ struct list_head list;
146
+ bdaddr_t bdaddr;
147
+ u8 bdaddr_type;
148
+ u32 current_flags;
149
+};
150
+
151
+enum hci_conn_flags {
152
+ HCI_CONN_FLAG_REMOTE_WAKEUP,
153
+ HCI_CONN_FLAG_MAX
154
+};
155
+
156
+#define hci_conn_test_flag(nr, flags) ((flags) & (1U << nr))
157
+
158
+/* Make sure number of flags doesn't exceed sizeof(current_flags) */
159
+static_assert(HCI_CONN_FLAG_MAX < 32);
160
+
106161 struct bt_uuid {
107162 struct list_head list;
108163 u8 uuid[16];
109164 u8 size;
110165 u8 svc_hint;
166
+};
167
+
168
+struct blocked_key {
169
+ struct list_head list;
170
+ struct rcu_head rcu;
171
+ u8 type;
172
+ u8 val[16];
111173 };
112174
113175 struct smp_csrk {
....@@ -180,6 +242,24 @@
180242 #define HCI_MAX_ADV_INSTANCES 5
181243 #define HCI_DEFAULT_ADV_DURATION 2
182244
245
+struct adv_pattern {
246
+ struct list_head list;
247
+ __u8 ad_type;
248
+ __u8 offset;
249
+ __u8 length;
250
+ __u8 value[HCI_MAX_AD_LENGTH];
251
+};
252
+
253
+struct adv_monitor {
254
+ struct list_head patterns;
255
+ bool active;
256
+ __u16 handle;
257
+};
258
+
259
+#define HCI_MIN_ADV_MONITOR_HANDLE 1
260
+#define HCI_MAX_ADV_MONITOR_NUM_HANDLES 32
261
+#define HCI_MAX_ADV_MONITOR_NUM_PATTERNS 16
262
+
183263 #define HCI_MAX_SHORT_NAME_LENGTH 10
184264
185265 /* Min encryption key size to match with SMP */
....@@ -191,6 +271,8 @@
191271 /* Default min/max age of connection information (1s/3s) */
192272 #define DEFAULT_CONN_INFO_MIN_AGE 1000
193273 #define DEFAULT_CONN_INFO_MAX_AGE 3000
274
+/* Default authenticated payload timeout 30s */
275
+#define DEFAULT_AUTH_PAYLOAD_TIMEOUT 0x0bb8
194276
195277 struct amp_assoc {
196278 __u16 len;
....@@ -243,6 +325,7 @@
243325 __u8 stored_num_keys;
244326 __u8 io_capability;
245327 __s8 inq_tx_power;
328
+ __u8 err_data_reporting;
246329 __u16 page_scan_interval;
247330 __u16 page_scan_window;
248331 __u8 page_scan_type;
....@@ -252,6 +335,14 @@
252335 __u8 le_scan_type;
253336 __u16 le_scan_interval;
254337 __u16 le_scan_window;
338
+ __u16 le_scan_int_suspend;
339
+ __u16 le_scan_window_suspend;
340
+ __u16 le_scan_int_discovery;
341
+ __u16 le_scan_window_discovery;
342
+ __u16 le_scan_int_adv_monitor;
343
+ __u16 le_scan_window_adv_monitor;
344
+ __u16 le_scan_int_connect;
345
+ __u16 le_scan_window_connect;
255346 __u16 le_conn_min_interval;
256347 __u16 le_conn_max_interval;
257348 __u16 le_conn_latency;
....@@ -267,6 +358,10 @@
267358 __u16 discov_interleaved_timeout;
268359 __u16 conn_info_min_age;
269360 __u16 conn_info_max_age;
361
+ __u16 auth_payload_timeout;
362
+ __u8 min_enc_key_size;
363
+ __u8 max_enc_key_size;
364
+ __u8 pairing_opts;
270365 __u8 ssp_debug_mode;
271366 __u8 hw_error_code;
272367 __u32 clock;
....@@ -275,6 +370,17 @@
275370 __u16 devid_vendor;
276371 __u16 devid_product;
277372 __u16 devid_version;
373
+
374
+ __u8 def_page_scan_type;
375
+ __u16 def_page_scan_int;
376
+ __u16 def_page_scan_window;
377
+ __u8 def_inq_scan_type;
378
+ __u16 def_inq_scan_int;
379
+ __u16 def_inq_scan_window;
380
+ __u16 def_br_lsto;
381
+ __u16 def_page_timeout;
382
+ __u16 def_multi_adv_rotation_duration;
383
+ __u16 def_le_autoconnect_timeout;
278384
279385 __u16 pkt_type;
280386 __u16 esco_type;
....@@ -370,6 +476,25 @@
370476 void *smp_bredr_data;
371477
372478 struct discovery_state discovery;
479
+
480
+ int discovery_old_state;
481
+ bool discovery_paused;
482
+ int advertising_old_state;
483
+ bool advertising_paused;
484
+
485
+ struct notifier_block suspend_notifier;
486
+ struct work_struct suspend_prepare;
487
+ enum suspended_state suspend_state_next;
488
+ enum suspended_state suspend_state;
489
+ bool scanning_paused;
490
+ bool suspended;
491
+ u8 wake_reason;
492
+ bdaddr_t wake_addr;
493
+ u8 wake_addr_type;
494
+
495
+ wait_queue_head_t suspend_wait_q;
496
+ DECLARE_BITMAP(suspend_tasks, __SUSPEND_NUM_TASKS);
497
+
373498 struct hci_conn_hash conn_hash;
374499
375500 struct list_head mgmt_pending;
....@@ -385,6 +510,7 @@
385510 struct list_head le_conn_params;
386511 struct list_head pend_le_conns;
387512 struct list_head pend_le_reports;
513
+ struct list_head blocked_keys;
388514
389515 struct hci_dev_stats stat;
390516
....@@ -412,6 +538,9 @@
412538 __u16 adv_instance_timeout;
413539 struct delayed_work adv_instance_expire;
414540
541
+ struct idr adv_monitors_idr;
542
+ unsigned int adv_monitors_cnt;
543
+
415544 __u8 irk[16];
416545 __u32 rpa_timeout;
417546 struct delayed_work rpa_expired;
....@@ -419,6 +548,11 @@
419548
420549 #if IS_ENABLED(CONFIG_BT_LEDS)
421550 struct led_trigger *power_led;
551
+#endif
552
+
553
+#if IS_ENABLED(CONFIG_BT_MSFTEXT)
554
+ __u16 msft_opcode;
555
+ void *msft_data;
422556 #endif
423557
424558 int (*open)(struct hci_dev *hdev);
....@@ -432,9 +566,22 @@
432566 int (*post_init)(struct hci_dev *hdev);
433567 int (*set_diag)(struct hci_dev *hdev, bool enable);
434568 int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
569
+ void (*cmd_timeout)(struct hci_dev *hdev);
570
+ bool (*prevent_wake)(struct hci_dev *hdev);
571
+
572
+ ANDROID_KABI_RESERVE(1);
573
+ ANDROID_KABI_RESERVE(2);
574
+ ANDROID_KABI_RESERVE(3);
575
+ ANDROID_KABI_RESERVE(4);
435576 };
436577
437578 #define HCI_PHY_HANDLE(handle) (handle & 0xff)
579
+
580
+enum conn_reasons {
581
+ CONN_REASON_PAIR_DEVICE,
582
+ CONN_REASON_L2CAP_CHAN,
583
+ CONN_REASON_SCO_CONNECT,
584
+};
438585
439586 struct hci_conn {
440587 struct list_head list;
....@@ -472,6 +619,7 @@
472619 __u16 disc_timeout;
473620 __u16 conn_timeout;
474621 __u16 setting;
622
+ __u16 auth_payload_timeout;
475623 __u16 le_conn_min_interval;
476624 __u16 le_conn_max_interval;
477625 __u16 le_conn_interval;
....@@ -479,10 +627,14 @@
479627 __u16 le_supv_timeout;
480628 __u8 le_adv_data[HCI_MAX_AD_LENGTH];
481629 __u8 le_adv_data_len;
630
+ __u8 le_tx_phy;
631
+ __u8 le_rx_phy;
482632 __s8 rssi;
483633 __s8 tx_power;
484634 __s8 max_tx_power;
485635 unsigned long flags;
636
+
637
+ enum conn_reasons conn_reason;
486638
487639 __u32 clock;
488640 __u16 clock_accuracy;
....@@ -517,6 +669,11 @@
517669 void (*connect_cfm_cb) (struct hci_conn *conn, u8 status);
518670 void (*security_cfm_cb) (struct hci_conn *conn, u8 status);
519671 void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason);
672
+
673
+ ANDROID_KABI_RESERVE(1);
674
+ ANDROID_KABI_RESERVE(2);
675
+ ANDROID_KABI_RESERVE(3);
676
+ ANDROID_KABI_RESERVE(4);
520677 };
521678
522679 struct hci_chan {
....@@ -527,6 +684,8 @@
527684 unsigned int sent;
528685 __u8 state;
529686 bool amp;
687
+
688
+ ANDROID_KABI_RESERVE(1);
530689 };
531690
532691 struct hci_conn_params {
....@@ -552,6 +711,9 @@
552711
553712 struct hci_conn *conn;
554713 bool explicit_connect;
714
+ u32 current_flags;
715
+
716
+ ANDROID_KABI_RESERVE(1);
555717 };
556718
557719 extern struct list_head hci_dev_list;
....@@ -571,6 +733,7 @@
571733 do { \
572734 hci_dev_clear_flag(hdev, HCI_LE_SCAN); \
573735 hci_dev_clear_flag(hdev, HCI_LE_ADV); \
736
+ hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);\
574737 hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); \
575738 } while (0)
576739
....@@ -908,12 +1071,14 @@
9081071
9091072 struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
9101073 u8 dst_type, u8 sec_level,
911
- u16 conn_timeout);
1074
+ u16 conn_timeout,
1075
+ enum conn_reasons conn_reason);
9121076 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
9131077 u8 dst_type, u8 sec_level, u16 conn_timeout,
9141078 u8 role, bdaddr_t *direct_rpa);
9151079 struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
916
- u8 sec_level, u8 auth_type);
1080
+ u8 sec_level, u8 auth_type,
1081
+ enum conn_reasons conn_reason);
9171082 struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
9181083 __u16 setting);
9191084 int hci_conn_check_link_mode(struct hci_conn *conn);
....@@ -1050,6 +1215,14 @@
10501215 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
10511216 __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
10521217 __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
1218
+
1219
+static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
1220
+{
1221
+#if IS_ENABLED(CONFIG_BT_MSFTEXT)
1222
+ hdev->msft_opcode = opcode;
1223
+#endif
1224
+}
1225
+
10531226 int hci_dev_open(__u16 dev);
10541227 int hci_dev_close(__u16 dev);
10551228 int hci_dev_do_close(struct hci_dev *hdev);
....@@ -1065,8 +1238,22 @@
10651238
10661239 struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list,
10671240 bdaddr_t *bdaddr, u8 type);
1241
+struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk(
1242
+ struct list_head *list, bdaddr_t *bdaddr,
1243
+ u8 type);
1244
+struct bdaddr_list_with_flags *
1245
+hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr,
1246
+ u8 type);
10681247 int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1248
+int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1249
+ u8 type, u8 *peer_irk, u8 *local_irk);
1250
+int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr,
1251
+ u8 type, u32 flags);
10691252 int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1253
+int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1254
+ u8 type);
1255
+int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr,
1256
+ u8 type);
10701257 void hci_bdaddr_list_clear(struct list_head *list);
10711258
10721259 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
....@@ -1102,6 +1289,8 @@
11021289 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
11031290 u8 addr_type, u8 val[16], bdaddr_t *rpa);
11041291 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
1292
+bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]);
1293
+void hci_blocked_keys_clear(struct hci_dev *hdev);
11051294 void hci_smp_irks_clear(struct hci_dev *hdev);
11061295
11071296 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
....@@ -1124,6 +1313,12 @@
11241313 u16 timeout, u16 duration);
11251314 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);
11261315 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
1316
+
1317
+void hci_adv_monitors_clear(struct hci_dev *hdev);
1318
+void hci_free_adv_monitor(struct adv_monitor *monitor);
1319
+int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
1320
+int hci_remove_adv_monitor(struct hci_dev *hdev, u16 handle);
1321
+bool hci_is_adv_monitoring(struct hci_dev *hdev);
11271322
11281323 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
11291324
....@@ -1187,6 +1382,9 @@
11871382 #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
11881383 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
11891384
1385
+/* Use LL Privacy based address resolution if supported */
1386
+#define use_ll_privacy(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1387
+
11901388 /* Use ext scanning if set ext scan param and ext scan enable is supported */
11911389 #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
11921390 ((dev)->commands[37] & 0x40))
....@@ -1236,6 +1434,8 @@
12361434 __u8 encrypt);
12371435 void (*key_change_cfm) (struct hci_conn *conn, __u8 status);
12381436 void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role);
1437
+
1438
+ ANDROID_KABI_RESERVE(1);
12391439 };
12401440
12411441 static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status)
....@@ -1464,6 +1664,8 @@
14641664 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
14651665 const void *param, u32 timeout);
14661666
1667
+u32 hci_conn_get_phy(struct hci_conn *conn);
1668
+
14671669 /* ----- HCI Sockets ----- */
14681670 void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
14691671 void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
....@@ -1479,6 +1681,7 @@
14791681 #define HCI_MGMT_NO_HDEV BIT(1)
14801682 #define HCI_MGMT_UNTRUSTED BIT(2)
14811683 #define HCI_MGMT_UNCONFIGURED BIT(3)
1684
+#define HCI_MGMT_HDEV_OPTIONAL BIT(4)
14821685
14831686 struct hci_mgmt_handler {
14841687 int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
....@@ -1493,6 +1696,8 @@
14931696 size_t handler_count;
14941697 const struct hci_mgmt_handler *handlers;
14951698 void (*hdev_init) (struct sock *sk, struct hci_dev *hdev);
1699
+
1700
+ ANDROID_KABI_RESERVE(1);
14961701 };
14971702
14981703 int hci_mgmt_chan_register(struct hci_mgmt_chan *c);
....@@ -1516,6 +1721,8 @@
15161721 #define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04
15171722 #define DISCOV_BREDR_INQUIRY_LEN 0x08
15181723 #define DISCOV_LE_RESTART_DELAY msecs_to_jiffies(200) /* msec */
1724
+#define DISCOV_LE_FAST_ADV_INT_MIN 100 /* msec */
1725
+#define DISCOV_LE_FAST_ADV_INT_MAX 150 /* msec */
15191726
15201727 void mgmt_fill_version_info(void *ver);
15211728 int mgmt_new_settings(struct hci_dev *hdev);
....@@ -1570,6 +1777,9 @@
15701777 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
15711778 u8 addr_type, s8 rssi, u8 *name, u8 name_len);
15721779 void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
1780
+void mgmt_suspending(struct hci_dev *hdev, u8 state);
1781
+void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr,
1782
+ u8 addr_type);
15731783 bool mgmt_powering_down(struct hci_dev *hdev);
15741784 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
15751785 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent);