Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next

+260 -20
+1
MAINTAINERS
··· 154 154 L: linux-bluetooth@vger.kernel.org 155 155 S: Maintained 156 156 F: net/6lowpan/ 157 + F: include/net/6lowpan.h 157 158 158 159 6PACK NETWORK DRIVER FOR AX.25 159 160 M: Andreas Koensgen <ajk@comnets.uni-bremen.de>
+4
include/net/bluetooth/hci.h
··· 1074 1074 __le16 num_blocks; 1075 1075 } __packed; 1076 1076 1077 + #define HCI_OP_READ_LOCAL_CODECS 0x100b 1078 + 1077 1079 #define HCI_OP_READ_PAGE_SCAN_ACTIVITY 0x0c1b 1078 1080 struct hci_rp_read_page_scan_activity { 1079 1081 __u8 status; ··· 1171 1169 __u8 status; 1172 1170 __u8 phy_handle; 1173 1171 } __packed; 1172 + 1173 + #define HCI_OP_GET_MWS_TRANSPORT_CONFIG 0x140c 1174 1174 1175 1175 #define HCI_OP_ENABLE_DUT_MODE 0x1803 1176 1176
+3
include/net/bluetooth/hci_core.h
··· 203 203 __u16 page_scan_window; 204 204 __u8 page_scan_type; 205 205 __u8 le_adv_channel_map; 206 + __u16 le_adv_min_interval; 207 + __u16 le_adv_max_interval; 206 208 __u8 le_scan_type; 207 209 __u16 le_scan_interval; 208 210 __u16 le_scan_window; ··· 460 458 enum { 461 459 HCI_AUTO_CONN_DISABLED, 462 460 HCI_AUTO_CONN_REPORT, 461 + HCI_AUTO_CONN_DIRECT, 463 462 HCI_AUTO_CONN_ALWAYS, 464 463 HCI_AUTO_CONN_LINK_LOSS, 465 464 } auto_connect;
+180 -1
net/bluetooth/hci_core.c
··· 970 970 DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get, 971 971 adv_channel_map_set, "%llu\n"); 972 972 973 + static int adv_min_interval_set(void *data, u64 val) 974 + { 975 + struct hci_dev *hdev = data; 976 + 977 + if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval) 978 + return -EINVAL; 979 + 980 + hci_dev_lock(hdev); 981 + hdev->le_adv_min_interval = val; 982 + hci_dev_unlock(hdev); 983 + 984 + return 0; 985 + } 986 + 987 + static int adv_min_interval_get(void *data, u64 *val) 988 + { 989 + struct hci_dev *hdev = data; 990 + 991 + hci_dev_lock(hdev); 992 + *val = hdev->le_adv_min_interval; 993 + hci_dev_unlock(hdev); 994 + 995 + return 0; 996 + } 997 + 998 + DEFINE_SIMPLE_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get, 999 + adv_min_interval_set, "%llu\n"); 1000 + 1001 + static int adv_max_interval_set(void *data, u64 val) 1002 + { 1003 + struct hci_dev *hdev = data; 1004 + 1005 + if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval) 1006 + return -EINVAL; 1007 + 1008 + hci_dev_lock(hdev); 1009 + hdev->le_adv_max_interval = val; 1010 + hci_dev_unlock(hdev); 1011 + 1012 + return 0; 1013 + } 1014 + 1015 + static int adv_max_interval_get(void *data, u64 *val) 1016 + { 1017 + struct hci_dev *hdev = data; 1018 + 1019 + hci_dev_lock(hdev); 1020 + *val = hdev->le_adv_max_interval; 1021 + hci_dev_unlock(hdev); 1022 + 1023 + return 0; 1024 + } 1025 + 1026 + DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get, 1027 + adv_max_interval_set, "%llu\n"); 1028 + 973 1029 static int device_list_show(struct seq_file *f, void *ptr) 974 1030 { 975 1031 struct hci_dev *hdev = f->private; ··· 1623 1567 1624 1568 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { 1625 1569 cp.le = 0x01; 1626 - cp.simul = lmp_le_br_capable(hdev); 1570 + cp.simul = 0x00; 1627 1571 } 1628 1572 1629 1573 if (cp.le != lmp_host_le_capable(hdev)) ··· 1741 1685 /* Set event mask page 2 if the HCI command for it is supported */ 1742 1686 if (hdev->commands[22] & 0x04) 1743 1687 hci_set_event_mask_page_2(req); 1688 + 1689 + /* Read local codec list if the HCI command is supported */ 1690 + if (hdev->commands[29] & 0x20) 1691 + hci_req_add(req, HCI_OP_READ_LOCAL_CODECS, 0, NULL); 1692 + 1693 + /* Get MWS transport configuration if the HCI command is supported */ 1694 + if (hdev->commands[30] & 0x08) 1695 + hci_req_add(req, HCI_OP_GET_MWS_TRANSPORT_CONFIG, 0, NULL); 1744 1696 1745 1697 /* Check for Synchronization Train support */ 1746 1698 if (lmp_sync_train_capable(hdev)) ··· 1889 1825 hdev, &supervision_timeout_fops); 1890 1826 debugfs_create_file("adv_channel_map", 0644, hdev->debugfs, 1891 1827 hdev, &adv_channel_map_fops); 1828 + debugfs_create_file("adv_min_interval", 0644, hdev->debugfs, 1829 + hdev, &adv_min_interval_fops); 1830 + debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, 1831 + hdev, &adv_max_interval_fops); 1892 1832 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev, 1893 1833 &device_list_fops); 1894 1834 debugfs_create_u16("discov_interleaved_timeout", 0644, ··· 3707 3639 list_add(&params->action, &hdev->pend_le_reports); 3708 3640 hci_update_background_scan(hdev); 3709 3641 break; 3642 + case HCI_AUTO_CONN_DIRECT: 3710 3643 case HCI_AUTO_CONN_ALWAYS: 3711 3644 if (!is_connected(hdev, addr, addr_type)) { 3712 3645 list_add(&params->action, &hdev->pend_le_conns); ··· 3983 3914 hdev->sniff_min_interval = 80; 3984 3915 3985 3916 hdev->le_adv_channel_map = 0x07; 3917 + hdev->le_adv_min_interval = 0x0800; 3918 + hdev->le_adv_max_interval = 0x0800; 3986 3919 hdev->le_scan_interval = 0x0060; 3987 3920 hdev->le_scan_window = 0x0030; 3988 3921 hdev->le_conn_min_interval = 0x0028; ··· 5468 5397 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp); 5469 5398 } 5470 5399 5400 + static void add_to_white_list(struct hci_request *req, 5401 + struct hci_conn_params *params) 5402 + { 5403 + struct hci_cp_le_add_to_white_list cp; 5404 + 5405 + cp.bdaddr_type = params->addr_type; 5406 + bacpy(&cp.bdaddr, &params->addr); 5407 + 5408 + hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp); 5409 + } 5410 + 5411 + static u8 update_white_list(struct hci_request *req) 5412 + { 5413 + struct hci_dev *hdev = req->hdev; 5414 + struct hci_conn_params *params; 5415 + struct bdaddr_list *b; 5416 + uint8_t white_list_entries = 0; 5417 + 5418 + /* Go through the current white list programmed into the 5419 + * controller one by one and check if that address is still 5420 + * in the list of pending connections or list of devices to 5421 + * report. If not present in either list, then queue the 5422 + * command to remove it from the controller. 5423 + */ 5424 + list_for_each_entry(b, &hdev->le_white_list, list) { 5425 + struct hci_cp_le_del_from_white_list cp; 5426 + 5427 + if (hci_pend_le_action_lookup(&hdev->pend_le_conns, 5428 + &b->bdaddr, b->bdaddr_type) || 5429 + hci_pend_le_action_lookup(&hdev->pend_le_reports, 5430 + &b->bdaddr, b->bdaddr_type)) { 5431 + white_list_entries++; 5432 + continue; 5433 + } 5434 + 5435 + cp.bdaddr_type = b->bdaddr_type; 5436 + bacpy(&cp.bdaddr, &b->bdaddr); 5437 + 5438 + hci_req_add(req, HCI_OP_LE_DEL_FROM_WHITE_LIST, 5439 + sizeof(cp), &cp); 5440 + } 5441 + 5442 + /* Since all no longer valid white list entries have been 5443 + * removed, walk through the list of pending connections 5444 + * and ensure that any new device gets programmed into 5445 + * the controller. 5446 + * 5447 + * If the list of the devices is larger than the list of 5448 + * available white list entries in the controller, then 5449 + * just abort and return filer policy value to not use the 5450 + * white list. 5451 + */ 5452 + list_for_each_entry(params, &hdev->pend_le_conns, action) { 5453 + if (hci_bdaddr_list_lookup(&hdev->le_white_list, 5454 + &params->addr, params->addr_type)) 5455 + continue; 5456 + 5457 + if (white_list_entries >= hdev->le_white_list_size) { 5458 + /* Select filter policy to accept all advertising */ 5459 + return 0x00; 5460 + } 5461 + 5462 + if (hci_find_irk_by_addr(hdev, &params->addr, 5463 + params->addr_type)) { 5464 + /* White list can not be used with RPAs */ 5465 + return 0x00; 5466 + } 5467 + 5468 + white_list_entries++; 5469 + add_to_white_list(req, params); 5470 + } 5471 + 5472 + /* After adding all new pending connections, walk through 5473 + * the list of pending reports and also add these to the 5474 + * white list if there is still space. 5475 + */ 5476 + list_for_each_entry(params, &hdev->pend_le_reports, action) { 5477 + if (hci_bdaddr_list_lookup(&hdev->le_white_list, 5478 + &params->addr, params->addr_type)) 5479 + continue; 5480 + 5481 + if (white_list_entries >= hdev->le_white_list_size) { 5482 + /* Select filter policy to accept all advertising */ 5483 + return 0x00; 5484 + } 5485 + 5486 + if (hci_find_irk_by_addr(hdev, &params->addr, 5487 + params->addr_type)) { 5488 + /* White list can not be used with RPAs */ 5489 + return 0x00; 5490 + } 5491 + 5492 + white_list_entries++; 5493 + add_to_white_list(req, params); 5494 + } 5495 + 5496 + /* Select filter policy to use white list */ 5497 + return 0x01; 5498 + } 5499 + 5471 5500 void hci_req_add_le_passive_scan(struct hci_request *req) 5472 5501 { 5473 5502 struct hci_cp_le_set_scan_param param_cp; 5474 5503 struct hci_cp_le_set_scan_enable enable_cp; 5475 5504 struct hci_dev *hdev = req->hdev; 5476 5505 u8 own_addr_type; 5506 + u8 filter_policy; 5477 5507 5478 5508 /* Set require_privacy to false since no SCAN_REQ are send 5479 5509 * during passive scanning. Not using an unresolvable address ··· 5585 5413 if (hci_update_random_address(req, false, &own_addr_type)) 5586 5414 return; 5587 5415 5416 + /* Adding or removing entries from the white list must 5417 + * happen before enabling scanning. The controller does 5418 + * not allow white list modification while scanning. 5419 + */ 5420 + filter_policy = update_white_list(req); 5421 + 5588 5422 memset(&param_cp, 0, sizeof(param_cp)); 5589 5423 param_cp.type = LE_SCAN_PASSIVE; 5590 5424 param_cp.interval = cpu_to_le16(hdev->le_scan_interval); 5591 5425 param_cp.window = cpu_to_le16(hdev->le_scan_window); 5592 5426 param_cp.own_address_type = own_addr_type; 5427 + param_cp.filter_policy = filter_policy; 5593 5428 hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp), 5594 5429 &param_cp); 5595 5430
+27 -8
net/bluetooth/hci_event.c
··· 317 317 if (param & SCAN_PAGE) 318 318 set_bit(HCI_PSCAN, &hdev->flags); 319 319 else 320 - clear_bit(HCI_ISCAN, &hdev->flags); 320 + clear_bit(HCI_PSCAN, &hdev->flags); 321 321 322 322 done: 323 323 hci_dev_unlock(hdev); ··· 2259 2259 break; 2260 2260 /* Fall through */ 2261 2261 2262 + case HCI_AUTO_CONN_DIRECT: 2262 2263 case HCI_AUTO_CONN_ALWAYS: 2263 2264 list_del_init(&params->action); 2264 2265 list_add(&params->action, &hdev->pend_le_conns); ··· 4252 4251 u8 addr_type, u8 adv_type) 4253 4252 { 4254 4253 struct hci_conn *conn; 4254 + struct hci_conn_params *params; 4255 4255 4256 4256 /* If the event is not connectable don't proceed further */ 4257 4257 if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND) ··· 4268 4266 if (hdev->conn_hash.le_num_slave > 0) 4269 4267 return; 4270 4268 4271 - /* If we're connectable, always connect any ADV_DIRECT_IND event */ 4272 - if (test_bit(HCI_CONNECTABLE, &hdev->dev_flags) && 4273 - adv_type == LE_ADV_DIRECT_IND) 4274 - goto connect; 4275 - 4276 4269 /* If we're not connectable only connect devices that we have in 4277 4270 * our pend_le_conns list. 4278 4271 */ 4279 - if (!hci_pend_le_action_lookup(&hdev->pend_le_conns, addr, addr_type)) 4272 + params = hci_pend_le_action_lookup(&hdev->pend_le_conns, 4273 + addr, addr_type); 4274 + if (!params) 4280 4275 return; 4281 4276 4282 - connect: 4277 + switch (params->auto_connect) { 4278 + case HCI_AUTO_CONN_DIRECT: 4279 + /* Only devices advertising with ADV_DIRECT_IND are 4280 + * triggering a connection attempt. This is allowing 4281 + * incoming connections from slave devices. 4282 + */ 4283 + if (adv_type != LE_ADV_DIRECT_IND) 4284 + return; 4285 + break; 4286 + case HCI_AUTO_CONN_ALWAYS: 4287 + /* Devices advertising with ADV_IND or ADV_DIRECT_IND 4288 + * are triggering a connection attempt. This means 4289 + * that incoming connectioms from slave device are 4290 + * accepted and also outgoing connections to slave 4291 + * devices are established when found. 4292 + */ 4293 + break; 4294 + default: 4295 + return; 4296 + } 4297 + 4283 4298 conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW, 4284 4299 HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER); 4285 4300 if (!IS_ERR(conn))
+24 -9
net/bluetooth/mgmt.c
··· 1086 1086 return; 1087 1087 1088 1088 memset(&cp, 0, sizeof(cp)); 1089 - cp.min_interval = cpu_to_le16(0x0800); 1090 - cp.max_interval = cpu_to_le16(0x0800); 1089 + cp.min_interval = cpu_to_le16(hdev->le_adv_min_interval); 1090 + cp.max_interval = cpu_to_le16(hdev->le_adv_max_interval); 1091 1091 cp.type = connectable ? LE_ADV_IND : LE_ADV_NONCONN_IND; 1092 1092 cp.own_address_type = own_addr_type; 1093 1093 cp.channel_map = hdev->le_adv_channel_map; ··· 1881 1881 if (cp->val) { 1882 1882 scan = SCAN_PAGE; 1883 1883 } else { 1884 - scan = 0; 1884 + /* If we don't have any whitelist entries just 1885 + * disable all scanning. If there are entries 1886 + * and we had both page and inquiry scanning 1887 + * enabled then fall back to only page scanning. 1888 + * Otherwise no changes are needed. 1889 + */ 1890 + if (list_empty(&hdev->whitelist)) 1891 + scan = SCAN_DISABLED; 1892 + else if (test_bit(HCI_ISCAN, &hdev->flags)) 1893 + scan = SCAN_PAGE; 1894 + else 1895 + goto no_scan_update; 1885 1896 1886 1897 if (test_bit(HCI_ISCAN, &hdev->flags) && 1887 1898 hdev->discov_timeout > 0) ··· 1902 1891 hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); 1903 1892 } 1904 1893 1894 + no_scan_update: 1905 1895 /* If we're going from non-connectable to connectable or 1906 1896 * vice-versa when fast connectable is enabled ensure that fast 1907 1897 * connectable gets disabled. write_fast_connectable won't do ··· 2276 2264 2277 2265 if (val) { 2278 2266 hci_cp.le = val; 2279 - hci_cp.simul = lmp_le_br_capable(hdev); 2267 + hci_cp.simul = 0x00; 2280 2268 } else { 2281 2269 if (test_bit(HCI_LE_ADV, &hdev->dev_flags)) 2282 2270 disable_advertising(&req); ··· 5283 5271 MGMT_STATUS_INVALID_PARAMS, 5284 5272 &cp->addr, sizeof(cp->addr)); 5285 5273 5286 - if (cp->action != 0x00 && cp->action != 0x01) 5274 + if (cp->action != 0x00 && cp->action != 0x01 && cp->action != 0x02) 5287 5275 return cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, 5288 5276 MGMT_STATUS_INVALID_PARAMS, 5289 5277 &cp->addr, sizeof(cp->addr)); ··· 5293 5281 if (cp->addr.type == BDADDR_BREDR) { 5294 5282 bool update_scan; 5295 5283 5296 - /* Only "connect" action supported for now */ 5284 + /* Only incoming connections action is supported for now */ 5297 5285 if (cp->action != 0x01) { 5298 5286 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, 5299 5287 MGMT_STATUS_INVALID_PARAMS, ··· 5319 5307 else 5320 5308 addr_type = ADDR_LE_DEV_RANDOM; 5321 5309 5322 - if (cp->action) 5310 + if (cp->action == 0x02) 5323 5311 auto_conn = HCI_AUTO_CONN_ALWAYS; 5312 + else if (cp->action == 0x01) 5313 + auto_conn = HCI_AUTO_CONN_DIRECT; 5324 5314 else 5325 5315 auto_conn = HCI_AUTO_CONN_REPORT; 5326 5316 ··· 5884 5870 list_del_init(&p->action); 5885 5871 5886 5872 switch (p->auto_connect) { 5873 + case HCI_AUTO_CONN_DIRECT: 5887 5874 case HCI_AUTO_CONN_ALWAYS: 5888 5875 list_add(&p->action, &hdev->pend_le_conns); 5889 5876 break; ··· 5937 5922 lmp_bredr_capable(hdev)) { 5938 5923 struct hci_cp_write_le_host_supported cp; 5939 5924 5940 - cp.le = 1; 5941 - cp.simul = lmp_le_br_capable(hdev); 5925 + cp.le = 0x01; 5926 + cp.simul = 0x00; 5942 5927 5943 5928 /* Check first if we already have the right 5944 5929 * host state (host features set)
+5 -2
net/bluetooth/rfcomm/core.c
··· 1910 1910 /* Get data directly from socket receive queue without copying it. */ 1911 1911 while ((skb = skb_dequeue(&sk->sk_receive_queue))) { 1912 1912 skb_orphan(skb); 1913 - if (!skb_linearize(skb)) 1913 + if (!skb_linearize(skb)) { 1914 1914 s = rfcomm_recv_frame(s, skb); 1915 - else 1915 + if (!s) 1916 + break; 1917 + } else { 1916 1918 kfree_skb(skb); 1919 + } 1917 1920 } 1918 1921 1919 1922 if (s && (sk->sk_state == BT_CLOSED))
+16
net/bluetooth/smp.c
··· 1291 1291 bacpy(&hcon->dst, &smp->remote_irk->bdaddr); 1292 1292 hcon->dst_type = smp->remote_irk->addr_type; 1293 1293 l2cap_conn_update_id_addr(hcon); 1294 + 1295 + /* When receiving an indentity resolving key for 1296 + * a remote device that does not use a resolvable 1297 + * private address, just remove the key so that 1298 + * it is possible to use the controller white 1299 + * list for scanning. 1300 + * 1301 + * Userspace will have been told to not store 1302 + * this key at this point. So it is safe to 1303 + * just remove it. 1304 + */ 1305 + if (!bacmp(&smp->remote_irk->rpa, BDADDR_ANY)) { 1306 + list_del(&smp->remote_irk->list); 1307 + kfree(smp->remote_irk); 1308 + smp->remote_irk = NULL; 1309 + } 1294 1310 } 1295 1311 1296 1312 /* The LTKs and CSRKs should be persistent only if both sides