| @@ -25,6 +25,7 @@ · 24 unmodified lines |
| 25 | #ifndef __HCI_CORE_H | 25 | #ifndef __HCI_CORE_H |
| 26 | #define __HCI_CORE_H | 26 | #define __HCI_CORE_H |
| 27 | | 27 | |
| | 28 | #include <linux/idr.h> |
| 28 | #include <linux/leds.h> | 29 | #include <linux/leds.h> |
| 29 | #include <linux/rculist.h> | 30 | #include <linux/rculist.h> |
| 30 | | 31 | |
| @@ -136,6 +137,23 @@ struct bdaddr_list_with_irk { · 105 unmodified lines |
| 136 | u8 local_irk[16]; | 137 | u8 local_irk[16]; |
| 137 | }; | 138 | }; |
| 138 | | 139 | |
| | 140 | struct bdaddr_list_with_flags { |
| | 141 | struct list_head list; |
| | 142 | bdaddr_t bdaddr; |
| | 143 | u8 bdaddr_type; |
| | 144 | u32 current_flags; |
| | 145 | }; |
| | 146 | |
| | 147 | enum hci_conn_flags { |
| | 148 | HCI_CONN_FLAG_REMOTE_WAKEUP, |
| | 149 | HCI_CONN_FLAG_MAX |
| | 150 | }; |
| | 151 | |
| | 152 | #define hci_conn_test_flag(nr, flags) ((flags) & (1U << nr)) |
| | 153 | |
| | 154 | /* Make sure number of flags doesn't exceed sizeof(current_flags) */ |
| | 155 | static_assert(HCI_CONN_FLAG_MAX < 32); |
| | 156 | |
| 139 | struct bt_uuid { | 157 | struct bt_uuid { |
| 140 | struct list_head list; | 158 | struct list_head list; |
| 141 | u8 uuid[16]; | 159 | u8 uuid[16]; |
| @@ -220,6 +238,24 @@ struct adv_info { · 78 unmodified lines |
| 220 | #define HCI_MAX_ADV_INSTANCES 5 | 238 | #define HCI_MAX_ADV_INSTANCES 5 |
| 221 | #define HCI_DEFAULT_ADV_DURATION 2 | 239 | #define HCI_DEFAULT_ADV_DURATION 2 |
| 222 | | 240 | |
| | 241 | struct adv_pattern { |
| | 242 | struct list_head list; |
| | 243 | __u8 ad_type; |
| | 244 | __u8 offset; |
| | 245 | __u8 length; |
| | 246 | __u8 value[HCI_MAX_AD_LENGTH]; |
| | 247 | }; |
| | 248 | |
| | 249 | struct adv_monitor { |
| | 250 | struct list_head patterns; |
| | 251 | bool active; |
| | 252 | __u16 handle; |
| | 253 | }; |
| | 254 | |
| | 255 | #define HCI_MIN_ADV_MONITOR_HANDLE 1 |
| | 256 | #define HCI_MAX_ADV_MONITOR_NUM_HANDLES 32 |
| | 257 | #define HCI_MAX_ADV_MONITOR_NUM_PATTERNS 16 |
| | 258 | |
| 223 | #define HCI_MAX_SHORT_NAME_LENGTH 10 | 259 | #define HCI_MAX_SHORT_NAME_LENGTH 10 |
| 224 | | 260 | |
| 225 | /* Min encryption key size to match with SMP */ | 261 | /* Min encryption key size to match with SMP */ |
| @@ -295,6 +331,14 @@ struct hci_dev { · 69 unmodified lines |
| 295 | __u8 le_scan_type; | 331 | __u8 le_scan_type; |
| 296 | __u16 le_scan_interval; | 332 | __u16 le_scan_interval; |
| 297 | __u16 le_scan_window; | 333 | __u16 le_scan_window; |
| | 334 | __u16 le_scan_int_suspend; |
| | 335 | __u16 le_scan_window_suspend; |
| | 336 | __u16 le_scan_int_discovery; |
| | 337 | __u16 le_scan_window_discovery; |
| | 338 | __u16 le_scan_int_adv_monitor; |
| | 339 | __u16 le_scan_window_adv_monitor; |
| | 340 | __u16 le_scan_int_connect; |
| | 341 | __u16 le_scan_window_connect; |
| 298 | __u16 le_conn_min_interval; | 342 | __u16 le_conn_min_interval; |
| 299 | __u16 le_conn_max_interval; | 343 | __u16 le_conn_max_interval; |
| 300 | __u16 le_conn_latency; | 344 | __u16 le_conn_latency; |
| @@ -323,6 +367,17 @@ struct hci_dev { · 22 unmodified lines |
| 323 | __u16 devid_product; | 367 | __u16 devid_product; |
| 324 | __u16 devid_version; | 368 | __u16 devid_version; |
| 325 | | 369 | |
| | 370 | __u8 def_page_scan_type; |
| | 371 | __u16 def_page_scan_int; |
| | 372 | __u16 def_page_scan_window; |
| | 373 | __u8 def_inq_scan_type; |
| | 374 | __u16 def_inq_scan_int; |
| | 375 | __u16 def_inq_scan_window; |
| | 376 | __u16 def_br_lsto; |
| | 377 | __u16 def_page_timeout; |
| | 378 | __u16 def_multi_adv_rotation_duration; |
| | 379 | __u16 def_le_autoconnect_timeout; |
| | 380 | |
| 326 | __u16 pkt_type; | 381 | __u16 pkt_type; |
| 327 | __u16 esco_type; | 382 | __u16 esco_type; |
| 328 | __u16 link_policy; | 383 | __u16 link_policy; |
| @@ -438,7 +493,6 @@ struct hci_dev { · 109 unmodified lines |
| 438 | struct list_head mgmt_pending; | 493 | struct list_head mgmt_pending; |
| 439 | struct list_head blacklist; | 494 | struct list_head blacklist; |
| 440 | struct list_head whitelist; | 495 | struct list_head whitelist; |
| 441 | struct list_head wakeable; | | |
| 442 | struct list_head uuids; | 496 | struct list_head uuids; |
| 443 | struct list_head link_keys; | 497 | struct list_head link_keys; |
| 444 | struct list_head long_term_keys; | 498 | struct list_head long_term_keys; |
| @@ -477,6 +531,9 @@ struct hci_dev { · 32 unmodified lines |
| 477 | __u16 adv_instance_timeout; | 531 | __u16 adv_instance_timeout; |
| 478 | struct delayed_work adv_instance_expire; | 532 | struct delayed_work adv_instance_expire; |
| 479 | | 533 | |
| | 534 | struct idr adv_monitors_idr; |
| | 535 | unsigned int adv_monitors_cnt; |
| | 536 | |
| 480 | __u8 irk[16]; | 537 | __u8 irk[16]; |
| 481 | __u32 rpa_timeout; | 538 | __u32 rpa_timeout; |
| 482 | struct delayed_work rpa_expired; | 539 | struct delayed_work rpa_expired; |
| @@ -508,6 +565,12 @@ struct hci_dev { · 25 unmodified lines |
| 508 | | 565 | |
| 509 | #define HCI_PHY_HANDLE(handle) (handle & 0xff) | 566 | #define HCI_PHY_HANDLE(handle) (handle & 0xff) |
| 510 | | 567 | |
| | 568 | enum conn_reasons { |
| | 569 | CONN_REASON_PAIR_DEVICE, |
| | 570 | CONN_REASON_L2CAP_CHAN, |
| | 571 | CONN_REASON_SCO_CONNECT, |
| | 572 | }; |
| | 573 | |
| 511 | struct hci_conn { | 574 | struct hci_conn { |
| 512 | struct list_head list; | 575 | struct list_head list; |
| 513 | | 576 | |
| @@ -559,6 +622,8 @@ struct hci_conn { · 45 unmodified lines |
| 559 | __s8 max_tx_power; | 622 | __s8 max_tx_power; |
| 560 | unsigned long flags; | 623 | unsigned long flags; |
| 561 | | 624 | |
| | 625 | enum conn_reasons conn_reason; |
| | 626 | |
| 562 | __u32 clock; | 627 | __u32 clock; |
| 563 | __u16 clock_accuracy; | 628 | __u16 clock_accuracy; |
| 564 | | 629 | |
| @@ -626,7 +691,7 @@ struct hci_conn_params { · 61 unmodified lines |
| 626 | | 691 | |
| 627 | struct hci_conn *conn; | 692 | struct hci_conn *conn; |
| 628 | bool explicit_connect; | 693 | bool explicit_connect; |
| 629 | bool wakeable; | 694 | u32 current_flags; |
| 630 | }; | 695 | }; |
| 631 | | 696 | |
| 632 | extern struct list_head hci_dev_list; | 697 | extern struct list_head hci_dev_list; |
| @@ -984,12 +1049,14 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); · 351 unmodified lines |
| 984 | | 1049 | |
| 985 | struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, | 1050 | struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, |
| 986 | u8 dst_type, u8 sec_level, | 1051 | u8 dst_type, u8 sec_level, |
| 987 | u16 conn_timeout); | 1052 | u16 conn_timeout, |
| | 1053 | enum conn_reasons conn_reason); |
| 988 | struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, | 1054 | struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, |
| 989 | u8 dst_type, u8 sec_level, u16 conn_timeout, | 1055 | u8 dst_type, u8 sec_level, u16 conn_timeout, |
| 990 | u8 role, bdaddr_t *direct_rpa); | 1056 | u8 role, bdaddr_t *direct_rpa); |
| 991 | struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, | 1057 | struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, |
| 992 | u8 sec_level, u8 auth_type); | 1058 | u8 sec_level, u8 auth_type, |
| | 1059 | enum conn_reasons conn_reason); |
| 993 | struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, | 1060 | struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, |
| 994 | __u16 setting); | 1061 | __u16 setting); |
| 995 | int hci_conn_check_link_mode(struct hci_conn *conn); | 1062 | int hci_conn_check_link_mode(struct hci_conn *conn); |
| @@ -1151,12 +1218,19 @@ struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list, · 155 unmodified lines |
| 1151 | struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk( | 1218 | struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk( |
| 1152 | struct list_head *list, bdaddr_t *bdaddr, | 1219 | struct list_head *list, bdaddr_t *bdaddr, |
| 1153 | u8 type); | 1220 | u8 type); |
| | 1221 | struct bdaddr_list_with_flags * |
| | 1222 | hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr, |
| | 1223 | u8 type); |
| 1154 | int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type); | 1224 | int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type); |
| 1155 | int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr, | 1225 | int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr, |
| 1156 | u8 type, u8 *peer_irk, u8 *local_irk); | 1226 | u8 type, u8 *peer_irk, u8 *local_irk); |
| | 1227 | int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr, |
| | 1228 | u8 type, u32 flags); |
| 1157 | int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type); | 1229 | int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type); |
| 1158 | int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr, | 1230 | int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr, |
| 1159 | u8 type); | 1231 | u8 type); |
| | 1232 | int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr, |
| | 1233 | u8 type); |
| 1160 | void hci_bdaddr_list_clear(struct list_head *list); | 1234 | void hci_bdaddr_list_clear(struct list_head *list); |
| 1161 | | 1235 | |
| 1162 | struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, | 1236 | struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, |
| @@ -1217,6 +1291,12 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, · 54 unmodified lines |
| 1217 | int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance); | 1291 | int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance); |
| 1218 | void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired); | 1292 | void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired); |
| 1219 | | 1293 | |
| | 1294 | void hci_adv_monitors_clear(struct hci_dev *hdev); |
| | 1295 | void hci_free_adv_monitor(struct adv_monitor *monitor); |
| | 1296 | int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor); |
| | 1297 | int hci_remove_adv_monitor(struct hci_dev *hdev, u16 handle); |
| | 1298 | bool hci_is_adv_monitoring(struct hci_dev *hdev); |
| | 1299 | |
| 1220 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); | 1300 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); |
| 1221 | | 1301 | |
| 1222 | void hci_init_sysfs(struct hci_dev *hdev); | 1302 | void hci_init_sysfs(struct hci_dev *hdev); |
| @@ -1279,6 +1359,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn); · 56 unmodified lines |
| 1279 | #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \ | 1359 | #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \ |
| 1280 | ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED)) | 1360 | ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED)) |
| 1281 | | 1361 | |
| | 1362 | /* Use LL Privacy based address resolution if supported */ |
| | 1363 | #define use_ll_privacy(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY) |
| | 1364 | |
| 1282 | /* Use ext scanning if set ext scan param and ext scan enable is supported */ | 1365 | /* Use ext scanning if set ext scan param and ext scan enable is supported */ |
| 1283 | #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \ | 1366 | #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \ |
| 1284 | ((dev)->commands[37] & 0x40)) | 1367 | ((dev)->commands[37] & 0x40)) |
| @@ -1387,7 +1470,7 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) · 102 unmodified lines |
| 1387 | __u8 encrypt; | 1470 | __u8 encrypt; |
| 1388 | | 1471 | |
| 1389 | if (conn->state == BT_CONFIG) { | 1472 | if (conn->state == BT_CONFIG) { |
| 1390 | if (status) | 1473 | if (!status) |
| 1391 | conn->state = BT_CONNECTED; | 1474 | conn->state = BT_CONNECTED; |
| 1392 | | 1475 | |
| 1393 | hci_connect_cfm(conn, status); | 1476 | hci_connect_cfm(conn, status); |
| @@ -1402,11 +1485,13 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) · 8 unmodified lines |
| 1402 | else | 1485 | else |
| 1403 | encrypt = 0x01; | 1486 | encrypt = 0x01; |
| 1404 | | 1487 | |
| 1405 | if (conn->sec_level == BT_SECURITY_SDP) | 1488 | if (!status) { |
| 1406 | conn->sec_level = BT_SECURITY_LOW; | 1489 | if (conn->sec_level == BT_SECURITY_SDP) |
| | 1490 | conn->sec_level = BT_SECURITY_LOW; |
| 1407 | | 1491 | |
| 1408 | if (conn->pending_sec_level > conn->sec_level) | 1492 | if (conn->pending_sec_level > conn->sec_level) |
| 1409 | conn->sec_level = conn->pending_sec_level; | 1493 | conn->sec_level = conn->pending_sec_level; |
| | 1494 | } |
| 1410 | | 1495 | |
| 1411 | mutex_lock(&hci_cb_list_lock); | 1496 | mutex_lock(&hci_cb_list_lock); |
| 1412 | list_for_each_entry(cb, &hci_cb_list, list) { | 1497 | list_for_each_entry(cb, &hci_cb_list, list) { |