···970970DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get,971971 adv_channel_map_set, "%llu\n");972972973973+static int adv_min_interval_set(void *data, u64 val)974974+{975975+ struct hci_dev *hdev = data;976976+977977+ if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval)978978+ return -EINVAL;979979+980980+ hci_dev_lock(hdev);981981+ hdev->le_adv_min_interval = val;982982+ hci_dev_unlock(hdev);983983+984984+ return 0;985985+}986986+987987+static int adv_min_interval_get(void *data, u64 *val)988988+{989989+ struct hci_dev *hdev = data;990990+991991+ hci_dev_lock(hdev);992992+ *val = hdev->le_adv_min_interval;993993+ hci_dev_unlock(hdev);994994+995995+ return 0;996996+}997997+998998+DEFINE_SIMPLE_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get,999999+ adv_min_interval_set, "%llu\n");10001000+10011001+static int adv_max_interval_set(void *data, u64 val)10021002+{10031003+ struct hci_dev *hdev = data;10041004+10051005+ if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval)10061006+ return -EINVAL;10071007+10081008+ hci_dev_lock(hdev);10091009+ hdev->le_adv_max_interval = val;10101010+ hci_dev_unlock(hdev);10111011+10121012+ return 0;10131013+}10141014+10151015+static int adv_max_interval_get(void *data, u64 *val)10161016+{10171017+ struct hci_dev *hdev = data;10181018+10191019+ hci_dev_lock(hdev);10201020+ *val = hdev->le_adv_max_interval;10211021+ hci_dev_unlock(hdev);10221022+10231023+ return 0;10241024+}10251025+10261026+DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,10271027+ adv_max_interval_set, "%llu\n");10281028+9731029static int device_list_show(struct seq_file *f, void *ptr)9741030{9751031 struct hci_dev *hdev = f->private;···1623156716241568 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) {16251569 cp.le = 0x01;16261626- cp.simul = lmp_le_br_capable(hdev);15701570+ cp.simul = 0x00;16271571 }1628157216291573 if (cp.le != lmp_host_le_capable(hdev))···17411685 /* Set event mask page 2 if the HCI command for it is supported */17421686 if (hdev->commands[22] & 0x04)17431687 hci_set_event_mask_page_2(req);16881688+16891689+ /* Read local codec list if the HCI command is supported */16901690+ if (hdev->commands[29] & 0x20)16911691+ hci_req_add(req, HCI_OP_READ_LOCAL_CODECS, 0, NULL);16921692+16931693+ /* Get MWS transport configuration if the HCI command is supported */16941694+ if (hdev->commands[30] & 0x08)16951695+ hci_req_add(req, HCI_OP_GET_MWS_TRANSPORT_CONFIG, 0, NULL);1744169617451697 /* Check for Synchronization Train support */17461698 if (lmp_sync_train_capable(hdev))···18891825 hdev, &supervision_timeout_fops);18901826 debugfs_create_file("adv_channel_map", 0644, hdev->debugfs,18911827 hdev, &adv_channel_map_fops);18281828+ debugfs_create_file("adv_min_interval", 0644, hdev->debugfs,18291829+ hdev, &adv_min_interval_fops);18301830+ debugfs_create_file("adv_max_interval", 0644, hdev->debugfs,18311831+ hdev, &adv_max_interval_fops);18921832 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,18931833 &device_list_fops);18941834 debugfs_create_u16("discov_interleaved_timeout", 0644,···37073639 list_add(¶ms->action, &hdev->pend_le_reports);37083640 hci_update_background_scan(hdev);37093641 break;36423642+ case HCI_AUTO_CONN_DIRECT:37103643 case HCI_AUTO_CONN_ALWAYS:37113644 if (!is_connected(hdev, addr, addr_type)) {37123645 list_add(¶ms->action, &hdev->pend_le_conns);···39833914 hdev->sniff_min_interval = 80;3984391539853916 hdev->le_adv_channel_map = 0x07;39173917+ hdev->le_adv_min_interval = 0x0800;39183918+ hdev->le_adv_max_interval = 0x0800;39863919 hdev->le_scan_interval = 0x0060;39873920 hdev->le_scan_window = 0x0030;39883921 hdev->le_conn_min_interval = 0x0028;···54685397 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);54695398}5470539954005400+static void add_to_white_list(struct hci_request *req,54015401+ struct hci_conn_params *params)54025402+{54035403+ struct hci_cp_le_add_to_white_list cp;54045404+54055405+ cp.bdaddr_type = params->addr_type;54065406+ bacpy(&cp.bdaddr, ¶ms->addr);54075407+54085408+ hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp);54095409+}54105410+54115411+static u8 update_white_list(struct hci_request *req)54125412+{54135413+ struct hci_dev *hdev = req->hdev;54145414+ struct hci_conn_params *params;54155415+ struct bdaddr_list *b;54165416+ uint8_t white_list_entries = 0;54175417+54185418+ /* Go through the current white list programmed into the54195419+ * controller one by one and check if that address is still54205420+ * in the list of pending connections or list of devices to54215421+ * report. If not present in either list, then queue the54225422+ * command to remove it from the controller.54235423+ */54245424+ list_for_each_entry(b, &hdev->le_white_list, list) {54255425+ struct hci_cp_le_del_from_white_list cp;54265426+54275427+ if (hci_pend_le_action_lookup(&hdev->pend_le_conns,54285428+ &b->bdaddr, b->bdaddr_type) ||54295429+ hci_pend_le_action_lookup(&hdev->pend_le_reports,54305430+ &b->bdaddr, b->bdaddr_type)) {54315431+ white_list_entries++;54325432+ continue;54335433+ }54345434+54355435+ cp.bdaddr_type = b->bdaddr_type;54365436+ bacpy(&cp.bdaddr, &b->bdaddr);54375437+54385438+ hci_req_add(req, HCI_OP_LE_DEL_FROM_WHITE_LIST,54395439+ sizeof(cp), &cp);54405440+ }54415441+54425442+ /* Since all no longer valid white list entries have been54435443+ * removed, walk through the list of pending connections54445444+ * and ensure that any new device gets programmed into54455445+ * the controller.54465446+ *54475447+ * If the list of the devices is larger than the list of54485448+ * available white list entries in the controller, then54495449+ * just abort and return filer policy value to not use the54505450+ * white list.54515451+ */54525452+ list_for_each_entry(params, &hdev->pend_le_conns, action) {54535453+ if (hci_bdaddr_list_lookup(&hdev->le_white_list,54545454+ ¶ms->addr, params->addr_type))54555455+ continue;54565456+54575457+ if (white_list_entries >= hdev->le_white_list_size) {54585458+ /* Select filter policy to accept all advertising */54595459+ return 0x00;54605460+ }54615461+54625462+ if (hci_find_irk_by_addr(hdev, ¶ms->addr,54635463+ params->addr_type)) {54645464+ /* White list can not be used with RPAs */54655465+ return 0x00;54665466+ }54675467+54685468+ white_list_entries++;54695469+ add_to_white_list(req, params);54705470+ }54715471+54725472+ /* After adding all new pending connections, walk through54735473+ * the list of pending reports and also add these to the54745474+ * white list if there is still space.54755475+ */54765476+ list_for_each_entry(params, &hdev->pend_le_reports, action) {54775477+ if (hci_bdaddr_list_lookup(&hdev->le_white_list,54785478+ ¶ms->addr, params->addr_type))54795479+ continue;54805480+54815481+ if (white_list_entries >= hdev->le_white_list_size) {54825482+ /* Select filter policy to accept all advertising */54835483+ return 0x00;54845484+ }54855485+54865486+ if (hci_find_irk_by_addr(hdev, ¶ms->addr,54875487+ params->addr_type)) {54885488+ /* White list can not be used with RPAs */54895489+ return 0x00;54905490+ }54915491+54925492+ white_list_entries++;54935493+ add_to_white_list(req, params);54945494+ }54955495+54965496+ /* Select filter policy to use white list */54975497+ return 0x01;54985498+}54995499+54715500void hci_req_add_le_passive_scan(struct hci_request *req)54725501{54735502 struct hci_cp_le_set_scan_param param_cp;54745503 struct hci_cp_le_set_scan_enable enable_cp;54755504 struct hci_dev *hdev = req->hdev;54765505 u8 own_addr_type;55065506+ u8 filter_policy;5477550754785508 /* Set require_privacy to false since no SCAN_REQ are send54795509 * during passive scanning. Not using an unresolvable address···55855413 if (hci_update_random_address(req, false, &own_addr_type))55865414 return;5587541554165416+ /* Adding or removing entries from the white list must54175417+ * happen before enabling scanning. The controller does54185418+ * not allow white list modification while scanning.54195419+ */54205420+ filter_policy = update_white_list(req);54215421+55885422 memset(¶m_cp, 0, sizeof(param_cp));55895423 param_cp.type = LE_SCAN_PASSIVE;55905424 param_cp.interval = cpu_to_le16(hdev->le_scan_interval);55915425 param_cp.window = cpu_to_le16(hdev->le_scan_window);55925426 param_cp.own_address_type = own_addr_type;54275427+ param_cp.filter_policy = filter_policy;55935428 hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),55945429 ¶m_cp);55955430
+27-8
net/bluetooth/hci_event.c
···317317 if (param & SCAN_PAGE)318318 set_bit(HCI_PSCAN, &hdev->flags);319319 else320320- clear_bit(HCI_ISCAN, &hdev->flags);320320+ clear_bit(HCI_PSCAN, &hdev->flags);321321322322done:323323 hci_dev_unlock(hdev);···22592259 break;22602260 /* Fall through */2261226122622262+ case HCI_AUTO_CONN_DIRECT:22622263 case HCI_AUTO_CONN_ALWAYS:22632264 list_del_init(¶ms->action);22642265 list_add(¶ms->action, &hdev->pend_le_conns);···42524251 u8 addr_type, u8 adv_type)42534252{42544253 struct hci_conn *conn;42544254+ struct hci_conn_params *params;4255425542564256 /* If the event is not connectable don't proceed further */42574257 if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND)···42684266 if (hdev->conn_hash.le_num_slave > 0)42694267 return;4270426842714271- /* If we're connectable, always connect any ADV_DIRECT_IND event */42724272- if (test_bit(HCI_CONNECTABLE, &hdev->dev_flags) &&42734273- adv_type == LE_ADV_DIRECT_IND)42744274- goto connect;42754275-42764269 /* If we're not connectable only connect devices that we have in42774270 * our pend_le_conns list.42784271 */42794279- if (!hci_pend_le_action_lookup(&hdev->pend_le_conns, addr, addr_type))42724272+ params = hci_pend_le_action_lookup(&hdev->pend_le_conns,42734273+ addr, addr_type);42744274+ if (!params)42804275 return;4281427642824282-connect:42774277+ switch (params->auto_connect) {42784278+ case HCI_AUTO_CONN_DIRECT:42794279+ /* Only devices advertising with ADV_DIRECT_IND are42804280+ * triggering a connection attempt. This is allowing42814281+ * incoming connections from slave devices.42824282+ */42834283+ if (adv_type != LE_ADV_DIRECT_IND)42844284+ return;42854285+ break;42864286+ case HCI_AUTO_CONN_ALWAYS:42874287+ /* Devices advertising with ADV_IND or ADV_DIRECT_IND42884288+ * are triggering a connection attempt. This means42894289+ * that incoming connectioms from slave device are42904290+ * accepted and also outgoing connections to slave42914291+ * devices are established when found.42924292+ */42934293+ break;42944294+ default:42954295+ return;42964296+ }42974297+42834298 conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,42844299 HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER);42854300 if (!IS_ERR(conn))
+24-9
net/bluetooth/mgmt.c
···10861086 return;1087108710881088 memset(&cp, 0, sizeof(cp));10891089- cp.min_interval = cpu_to_le16(0x0800);10901090- cp.max_interval = cpu_to_le16(0x0800);10891089+ cp.min_interval = cpu_to_le16(hdev->le_adv_min_interval);10901090+ cp.max_interval = cpu_to_le16(hdev->le_adv_max_interval);10911091 cp.type = connectable ? LE_ADV_IND : LE_ADV_NONCONN_IND;10921092 cp.own_address_type = own_addr_type;10931093 cp.channel_map = hdev->le_adv_channel_map;···18811881 if (cp->val) {18821882 scan = SCAN_PAGE;18831883 } else {18841884- scan = 0;18841884+ /* If we don't have any whitelist entries just18851885+ * disable all scanning. If there are entries18861886+ * and we had both page and inquiry scanning18871887+ * enabled then fall back to only page scanning.18881888+ * Otherwise no changes are needed.18891889+ */18901890+ if (list_empty(&hdev->whitelist))18911891+ scan = SCAN_DISABLED;18921892+ else if (test_bit(HCI_ISCAN, &hdev->flags))18931893+ scan = SCAN_PAGE;18941894+ else18951895+ goto no_scan_update;1885189618861897 if (test_bit(HCI_ISCAN, &hdev->flags) &&18871898 hdev->discov_timeout > 0)···19021891 hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);19031892 }1904189318941894+no_scan_update:19051895 /* If we're going from non-connectable to connectable or19061896 * vice-versa when fast connectable is enabled ensure that fast19071897 * connectable gets disabled. write_fast_connectable won't do···2276226422772265 if (val) {22782266 hci_cp.le = val;22792279- hci_cp.simul = lmp_le_br_capable(hdev);22672267+ hci_cp.simul = 0x00;22802268 } else {22812269 if (test_bit(HCI_LE_ADV, &hdev->dev_flags))22822270 disable_advertising(&req);···52835271 MGMT_STATUS_INVALID_PARAMS,52845272 &cp->addr, sizeof(cp->addr));5285527352865286- if (cp->action != 0x00 && cp->action != 0x01)52745274+ if (cp->action != 0x00 && cp->action != 0x01 && cp->action != 0x02)52875275 return cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,52885276 MGMT_STATUS_INVALID_PARAMS,52895277 &cp->addr, sizeof(cp->addr));···52935281 if (cp->addr.type == BDADDR_BREDR) {52945282 bool update_scan;5295528352965296- /* Only "connect" action supported for now */52845284+ /* Only incoming connections action is supported for now */52975285 if (cp->action != 0x01) {52985286 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,52995287 MGMT_STATUS_INVALID_PARAMS,···53195307 else53205308 addr_type = ADDR_LE_DEV_RANDOM;5321530953225322- if (cp->action)53105310+ if (cp->action == 0x02)53235311 auto_conn = HCI_AUTO_CONN_ALWAYS;53125312+ else if (cp->action == 0x01)53135313+ auto_conn = HCI_AUTO_CONN_DIRECT;53245314 else53255315 auto_conn = HCI_AUTO_CONN_REPORT;53265316···58845870 list_del_init(&p->action);5885587158865872 switch (p->auto_connect) {58735873+ case HCI_AUTO_CONN_DIRECT:58875874 case HCI_AUTO_CONN_ALWAYS:58885875 list_add(&p->action, &hdev->pend_le_conns);58895876 break;···59375922 lmp_bredr_capable(hdev)) {59385923 struct hci_cp_write_le_host_supported cp;5939592459405940- cp.le = 1;59415941- cp.simul = lmp_le_br_capable(hdev);59255925+ cp.le = 0x01;59265926+ cp.simul = 0x00;5942592759435928 /* Check first if we already have the right59445929 * host state (host features set)
+5-2
net/bluetooth/rfcomm/core.c
···19101910 /* Get data directly from socket receive queue without copying it. */19111911 while ((skb = skb_dequeue(&sk->sk_receive_queue))) {19121912 skb_orphan(skb);19131913- if (!skb_linearize(skb))19131913+ if (!skb_linearize(skb)) {19141914 s = rfcomm_recv_frame(s, skb);19151915- else19151915+ if (!s)19161916+ break;19171917+ } else {19161918 kfree_skb(skb);19191919+ }19171920 }1918192119191922 if (s && (sk->sk_state == BT_CLOSED))
+16
net/bluetooth/smp.c
···12911291 bacpy(&hcon->dst, &smp->remote_irk->bdaddr);12921292 hcon->dst_type = smp->remote_irk->addr_type;12931293 l2cap_conn_update_id_addr(hcon);12941294+12951295+ /* When receiving an indentity resolving key for12961296+ * a remote device that does not use a resolvable12971297+ * private address, just remove the key so that12981298+ * it is possible to use the controller white12991299+ * list for scanning.13001300+ *13011301+ * Userspace will have been told to not store13021302+ * this key at this point. So it is safe to13031303+ * just remove it.13041304+ */13051305+ if (!bacmp(&smp->remote_irk->rpa, BDADDR_ANY)) {13061306+ list_del(&smp->remote_irk->list);13071307+ kfree(smp->remote_irk);13081308+ smp->remote_irk = NULL;13091309+ }12941310 }1295131112961312 /* The LTKs and CSRKs should be persistent only if both sides