hci_request.c (c74a7469f97c0f40b46e82ee979f9fb1bb6e847c) hci_request.c (45bdd86eafc7d29e0b4b6681bec9c6ab8eddc6bf)
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3
4 Copyright (C) 2014 Intel Corporation
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation;

--- 633 unchanged lines hidden (view full) ---

642
643 memcpy(hdev->eir, cp.data, sizeof(cp.data));
644
645 hci_req_add(req, HCI_OP_WRITE_EIR, sizeof(cp), &cp);
646}
647
648void hci_req_add_le_scan_disable(struct hci_request *req)
649{
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3
4 Copyright (C) 2014 Intel Corporation
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation;

--- 633 unchanged lines hidden (view full) ---

642
643 memcpy(hdev->eir, cp.data, sizeof(cp.data));
644
645 hci_req_add(req, HCI_OP_WRITE_EIR, sizeof(cp), &cp);
646}
647
648void hci_req_add_le_scan_disable(struct hci_request *req)
649{
650 struct hci_cp_le_set_scan_enable cp;
650 struct hci_dev *hdev = req->hdev;
651
651
652 memset(&cp, 0, sizeof(cp));
653 cp.enable = LE_SCAN_DISABLE;
654 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
652 if (use_ext_scan(hdev)) {
653 struct hci_cp_le_set_ext_scan_enable cp;
654
655 memset(&cp, 0, sizeof(cp));
656 cp.enable = LE_SCAN_DISABLE;
657 hci_req_add(req, HCI_OP_LE_SET_EXT_SCAN_ENABLE, sizeof(cp),
658 &cp);
659 } else {
660 struct hci_cp_le_set_scan_enable cp;
661
662 memset(&cp, 0, sizeof(cp));
663 cp.enable = LE_SCAN_DISABLE;
664 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
665 }
655}
656
657static void add_to_white_list(struct hci_request *req,
658 struct hci_conn_params *params)
659{
660 struct hci_cp_le_add_to_white_list cp;
661
662 cp.bdaddr_type = params->addr_type;

--- 99 unchanged lines hidden (view full) ---

762 return 0x01;
763}
764
765static bool scan_use_rpa(struct hci_dev *hdev)
766{
767 return hci_dev_test_flag(hdev, HCI_PRIVACY);
768}
769
666}
667
668static void add_to_white_list(struct hci_request *req,
669 struct hci_conn_params *params)
670{
671 struct hci_cp_le_add_to_white_list cp;
672
673 cp.bdaddr_type = params->addr_type;

--- 99 unchanged lines hidden (view full) ---

773 return 0x01;
774}
775
776static bool scan_use_rpa(struct hci_dev *hdev)
777{
778 return hci_dev_test_flag(hdev, HCI_PRIVACY);
779}
780
781static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
782 u16 window, u8 own_addr_type, u8 filter_policy)
783{
784 struct hci_dev *hdev = req->hdev;
785
786 /* Use ext scanning if set ext scan param and ext scan enable is
787 * supported
788 */
789 if (use_ext_scan(hdev)) {
790 struct hci_cp_le_set_ext_scan_params *ext_param_cp;
791 struct hci_cp_le_set_ext_scan_enable ext_enable_cp;
792 struct hci_cp_le_scan_phy_params *phy_params;
793 u8 data[sizeof(*ext_param_cp) + sizeof(*phy_params) * 2];
794 u32 plen;
795
796 ext_param_cp = (void *)data;
797 phy_params = (void *)ext_param_cp->data;
798
799 memset(ext_param_cp, 0, sizeof(*ext_param_cp));
800 ext_param_cp->own_addr_type = own_addr_type;
801 ext_param_cp->filter_policy = filter_policy;
802
803 plen = sizeof(*ext_param_cp);
804
805 if (scan_1m(hdev) || scan_2m(hdev)) {
806 ext_param_cp->scanning_phys |= LE_SCAN_PHY_1M;
807
808 memset(phy_params, 0, sizeof(*phy_params));
809 phy_params->type = type;
810 phy_params->interval = cpu_to_le16(interval);
811 phy_params->window = cpu_to_le16(window);
812
813 plen += sizeof(*phy_params);
814 phy_params++;
815 }
816
817 if (scan_coded(hdev)) {
818 ext_param_cp->scanning_phys |= LE_SCAN_PHY_CODED;
819
820 memset(phy_params, 0, sizeof(*phy_params));
821 phy_params->type = type;
822 phy_params->interval = cpu_to_le16(interval);
823 phy_params->window = cpu_to_le16(window);
824
825 plen += sizeof(*phy_params);
826 phy_params++;
827 }
828
829 hci_req_add(req, HCI_OP_LE_SET_EXT_SCAN_PARAMS,
830 plen, ext_param_cp);
831
832 memset(&ext_enable_cp, 0, sizeof(ext_enable_cp));
833 ext_enable_cp.enable = LE_SCAN_ENABLE;
834 ext_enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
835
836 hci_req_add(req, HCI_OP_LE_SET_EXT_SCAN_ENABLE,
837 sizeof(ext_enable_cp), &ext_enable_cp);
838 } else {
839 struct hci_cp_le_set_scan_param param_cp;
840 struct hci_cp_le_set_scan_enable enable_cp;
841
842 memset(&param_cp, 0, sizeof(param_cp));
843 param_cp.type = type;
844 param_cp.interval = cpu_to_le16(interval);
845 param_cp.window = cpu_to_le16(window);
846 param_cp.own_address_type = own_addr_type;
847 param_cp.filter_policy = filter_policy;
848 hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
849 &param_cp);
850
851 memset(&enable_cp, 0, sizeof(enable_cp));
852 enable_cp.enable = LE_SCAN_ENABLE;
853 enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
854 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
855 &enable_cp);
856 }
857}
858
770void hci_req_add_le_passive_scan(struct hci_request *req)
771{
859void hci_req_add_le_passive_scan(struct hci_request *req)
860{
772 struct hci_cp_le_set_scan_param param_cp;
773 struct hci_cp_le_set_scan_enable enable_cp;
774 struct hci_dev *hdev = req->hdev;
775 u8 own_addr_type;
776 u8 filter_policy;
777
778 /* Set require_privacy to false since no SCAN_REQ are send
779 * during passive scanning. Not using an non-resolvable address
780 * here is important so that peer devices using direct
781 * advertising with our address will be correctly reported

--- 17 unchanged lines hidden (view full) ---

799 * So instead of using filter polices 0x00 (no whitelist)
800 * and 0x01 (whitelist enabled) use the new filter policies
801 * 0x02 (no whitelist) and 0x03 (whitelist enabled).
802 */
803 if (hci_dev_test_flag(hdev, HCI_PRIVACY) &&
804 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY))
805 filter_policy |= 0x02;
806
861 struct hci_dev *hdev = req->hdev;
862 u8 own_addr_type;
863 u8 filter_policy;
864
865 /* Set require_privacy to false since no SCAN_REQ are send
866 * during passive scanning. Not using an non-resolvable address
867 * here is important so that peer devices using direct
868 * advertising with our address will be correctly reported

--- 17 unchanged lines hidden (view full) ---

886 * So instead of using filter polices 0x00 (no whitelist)
887 * and 0x01 (whitelist enabled) use the new filter policies
888 * 0x02 (no whitelist) and 0x03 (whitelist enabled).
889 */
890 if (hci_dev_test_flag(hdev, HCI_PRIVACY) &&
891 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY))
892 filter_policy |= 0x02;
893
807 memset(&param_cp, 0, sizeof(param_cp));
808 param_cp.type = LE_SCAN_PASSIVE;
809 param_cp.interval = cpu_to_le16(hdev->le_scan_interval);
810 param_cp.window = cpu_to_le16(hdev->le_scan_window);
811 param_cp.own_address_type = own_addr_type;
812 param_cp.filter_policy = filter_policy;
813 hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
814 &param_cp);
815
816 memset(&enable_cp, 0, sizeof(enable_cp));
817 enable_cp.enable = LE_SCAN_ENABLE;
818 enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
819 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
820 &enable_cp);
894 hci_req_start_scan(req, LE_SCAN_PASSIVE, hdev->le_scan_interval,
895 hdev->le_scan_window, own_addr_type, filter_policy);
821}
822
823static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev)
824{
825 u8 instance = hdev->cur_adv_instance;
826 struct adv_info *adv_instance;
827
828 /* Ignore instance 0 */

--- 1106 unchanged lines hidden (view full) ---

1935 hci_dev_lock(hdev);
1936 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1937 hci_dev_unlock(hdev);
1938}
1939
1940static int le_scan_restart(struct hci_request *req, unsigned long opt)
1941{
1942 struct hci_dev *hdev = req->hdev;
896}
897
898static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev)
899{
900 u8 instance = hdev->cur_adv_instance;
901 struct adv_info *adv_instance;
902
903 /* Ignore instance 0 */

--- 1106 unchanged lines hidden (view full) ---

2010 hci_dev_lock(hdev);
2011 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2012 hci_dev_unlock(hdev);
2013}
2014
2015static int le_scan_restart(struct hci_request *req, unsigned long opt)
2016{
2017 struct hci_dev *hdev = req->hdev;
1943 struct hci_cp_le_set_scan_enable cp;
1944
1945 /* If controller is not scanning we are done. */
1946 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
1947 return 0;
1948
1949 hci_req_add_le_scan_disable(req);
1950
2018
2019 /* If controller is not scanning we are done. */
2020 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
2021 return 0;
2022
2023 hci_req_add_le_scan_disable(req);
2024
1951 memset(&cp, 0, sizeof(cp));
1952 cp.enable = LE_SCAN_ENABLE;
1953 cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
1954 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
2025 if (use_ext_scan(hdev)) {
2026 struct hci_cp_le_set_ext_scan_enable ext_enable_cp;
1955
2027
2028 memset(&ext_enable_cp, 0, sizeof(ext_enable_cp));
2029 ext_enable_cp.enable = LE_SCAN_ENABLE;
2030 ext_enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
2031
2032 hci_req_add(req, HCI_OP_LE_SET_EXT_SCAN_ENABLE,
2033 sizeof(ext_enable_cp), &ext_enable_cp);
2034 } else {
2035 struct hci_cp_le_set_scan_enable cp;
2036
2037 memset(&cp, 0, sizeof(cp));
2038 cp.enable = LE_SCAN_ENABLE;
2039 cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
2040 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
2041 }
2042
1956 return 0;
1957}
1958
1959static void le_scan_restart_work(struct work_struct *work)
1960{
1961 struct hci_dev *hdev = container_of(work, struct hci_dev,
1962 le_scan_restart.work);
1963 unsigned long timeout, duration, scan_start, now;

--- 41 unchanged lines hidden (view full) ---

2005unlock:
2006 hci_dev_unlock(hdev);
2007}
2008
2009static int active_scan(struct hci_request *req, unsigned long opt)
2010{
2011 uint16_t interval = opt;
2012 struct hci_dev *hdev = req->hdev;
2043 return 0;
2044}
2045
2046static void le_scan_restart_work(struct work_struct *work)
2047{
2048 struct hci_dev *hdev = container_of(work, struct hci_dev,
2049 le_scan_restart.work);
2050 unsigned long timeout, duration, scan_start, now;

--- 41 unchanged lines hidden (view full) ---

2092unlock:
2093 hci_dev_unlock(hdev);
2094}
2095
2096static int active_scan(struct hci_request *req, unsigned long opt)
2097{
2098 uint16_t interval = opt;
2099 struct hci_dev *hdev = req->hdev;
2013 struct hci_cp_le_set_scan_param param_cp;
2014 struct hci_cp_le_set_scan_enable enable_cp;
2015 u8 own_addr_type;
2016 int err;
2017
2018 BT_DBG("%s", hdev->name);
2019
2020 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) {
2021 hci_dev_lock(hdev);
2022

--- 22 unchanged lines hidden (view full) ---

2045 * address (when privacy feature has been enabled) or non-resolvable
2046 * private address.
2047 */
2048 err = hci_update_random_address(req, true, scan_use_rpa(hdev),
2049 &own_addr_type);
2050 if (err < 0)
2051 own_addr_type = ADDR_LE_DEV_PUBLIC;
2052
2100 u8 own_addr_type;
2101 int err;
2102
2103 BT_DBG("%s", hdev->name);
2104
2105 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) {
2106 hci_dev_lock(hdev);
2107

--- 22 unchanged lines hidden (view full) ---

2130 * address (when privacy feature has been enabled) or non-resolvable
2131 * private address.
2132 */
2133 err = hci_update_random_address(req, true, scan_use_rpa(hdev),
2134 &own_addr_type);
2135 if (err < 0)
2136 own_addr_type = ADDR_LE_DEV_PUBLIC;
2137
2053 memset(&param_cp, 0, sizeof(param_cp));
2054 param_cp.type = LE_SCAN_ACTIVE;
2055 param_cp.interval = cpu_to_le16(interval);
2056 param_cp.window = cpu_to_le16(DISCOV_LE_SCAN_WIN);
2057 param_cp.own_address_type = own_addr_type;
2058
2059 hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
2060 &param_cp);
2061
2062 memset(&enable_cp, 0, sizeof(enable_cp));
2063 enable_cp.enable = LE_SCAN_ENABLE;
2064 enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
2065
2066 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
2067 &enable_cp);
2068
2138 hci_req_start_scan(req, LE_SCAN_ACTIVE, interval, DISCOV_LE_SCAN_WIN,
2139 own_addr_type, 0);
2069 return 0;
2070}
2071
2072static int interleaved_discov(struct hci_request *req, unsigned long opt)
2073{
2074 int err;
2075
2076 BT_DBG("%s", req->hdev->name);

--- 308 unchanged lines hidden ---
2140 return 0;
2141}
2142
2143static int interleaved_discov(struct hci_request *req, unsigned long opt)
2144{
2145 int err;
2146
2147 BT_DBG("%s", req->hdev->name);

--- 308 unchanged lines hidden ---