Commit d7a5a11d authored by Marcel Holtmann's avatar Marcel Holtmann Committed by Johan Hedberg

Bluetooth: Introduce hci_dev_test_flag helper macro

Instead of manually coding test_bit on hdev->dev_flags all the time,
use hci_dev_test_flag helper macro.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent cc91cb04
...@@ -502,6 +502,8 @@ extern struct list_head hci_cb_list; ...@@ -502,6 +502,8 @@ extern struct list_head hci_cb_list;
extern rwlock_t hci_dev_list_lock; extern rwlock_t hci_dev_list_lock;
extern struct mutex hci_cb_list_lock; extern struct mutex hci_cb_list_lock;
#define hci_dev_test_flag(hdev, nr) test_bit((nr), &(hdev)->dev_flags)
/* ----- HCI interface to upper protocols ----- */ /* ----- HCI interface to upper protocols ----- */
int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
int l2cap_disconn_ind(struct hci_conn *hcon); int l2cap_disconn_ind(struct hci_conn *hcon);
...@@ -598,14 +600,14 @@ enum { ...@@ -598,14 +600,14 @@ enum {
static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
{ {
struct hci_dev *hdev = conn->hdev; struct hci_dev *hdev = conn->hdev;
return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) &&
test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
} }
static inline bool hci_conn_sc_enabled(struct hci_conn *conn) static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
{ {
struct hci_dev *hdev = conn->hdev; struct hci_dev *hdev = conn->hdev;
return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) && return hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
test_bit(HCI_CONN_SC_ENABLED, &conn->flags); test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
} }
...@@ -1025,10 +1027,10 @@ void hci_conn_del_sysfs(struct hci_conn *conn); ...@@ -1025,10 +1027,10 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
#define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE)) #define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE))
#define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR)) #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
#define hdev_is_powered(hdev) (test_bit(HCI_UP, &hdev->flags) && \ #define hdev_is_powered(dev) (test_bit(HCI_UP, &(dev)->flags) && \
!test_bit(HCI_AUTO_OFF, &hdev->dev_flags)) !hci_dev_test_flag(dev, HCI_AUTO_OFF))
#define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \ #define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \
test_bit(HCI_SC_ENABLED, &(dev)->dev_flags)) hci_dev_test_flag(dev, HCI_SC_ENABLED))
/* ----- HCI protocols ----- */ /* ----- HCI protocols ----- */
#define HCI_PROTO_DEFER 0x01 #define HCI_PROTO_DEFER 0x01
......
...@@ -571,7 +571,7 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src) ...@@ -571,7 +571,7 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
list_for_each_entry(d, &hci_dev_list, list) { list_for_each_entry(d, &hci_dev_list, list) {
if (!test_bit(HCI_UP, &d->flags) || if (!test_bit(HCI_UP, &d->flags) ||
test_bit(HCI_USER_CHANNEL, &d->dev_flags) || hci_dev_test_flag(d, HCI_USER_CHANNEL) ||
d->dev_type != HCI_BREDR) d->dev_type != HCI_BREDR)
continue; continue;
...@@ -734,7 +734,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, ...@@ -734,7 +734,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
int err; int err;
/* Let's make sure that le is enabled.*/ /* Let's make sure that le is enabled.*/
if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
if (lmp_le_capable(hdev)) if (lmp_le_capable(hdev))
return ERR_PTR(-ECONNREFUSED); return ERR_PTR(-ECONNREFUSED);
...@@ -799,7 +799,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, ...@@ -799,7 +799,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
* anyway have to disable it in order to start directed * anyway have to disable it in order to start directed
* advertising. * advertising.
*/ */
if (test_bit(HCI_LE_ADV, &hdev->dev_flags)) { if (hci_dev_test_flag(hdev, HCI_LE_ADV)) {
u8 enable = 0x00; u8 enable = 0x00;
hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable), hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
&enable); &enable);
...@@ -810,7 +810,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, ...@@ -810,7 +810,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
/* If we're active scanning most controllers are unable /* If we're active scanning most controllers are unable
* to initiate advertising. Simply reject the attempt. * to initiate advertising. Simply reject the attempt.
*/ */
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags) && if (hci_dev_test_flag(hdev, HCI_LE_SCAN) &&
hdev->le_scan_type == LE_SCAN_ACTIVE) { hdev->le_scan_type == LE_SCAN_ACTIVE) {
skb_queue_purge(&req.cmd_q); skb_queue_purge(&req.cmd_q);
hci_conn_del(conn); hci_conn_del(conn);
...@@ -840,7 +840,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, ...@@ -840,7 +840,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
* handler for scan disabling knows to set the correct discovery * handler for scan disabling knows to set the correct discovery
* state. * state.
*/ */
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) { if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
hci_req_add_le_scan_disable(&req); hci_req_add_le_scan_disable(&req);
set_bit(HCI_LE_SCAN_INTERRUPTED, &hdev->dev_flags); set_bit(HCI_LE_SCAN_INTERRUPTED, &hdev->dev_flags);
} }
...@@ -864,7 +864,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, ...@@ -864,7 +864,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
{ {
struct hci_conn *acl; struct hci_conn *acl;
if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) { if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
if (lmp_bredr_capable(hdev)) if (lmp_bredr_capable(hdev))
return ERR_PTR(-ECONNREFUSED); return ERR_PTR(-ECONNREFUSED);
...@@ -942,7 +942,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn) ...@@ -942,7 +942,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
* Connections is used and the link is encrypted with AES-CCM * Connections is used and the link is encrypted with AES-CCM
* using a P-256 authenticated combination key. * using a P-256 authenticated combination key.
*/ */
if (test_bit(HCI_SC_ONLY, &conn->hdev->flags)) { if (hci_dev_test_flag(conn->hdev, HCI_SC_ONLY)) {
if (!hci_conn_sc_enabled(conn) || if (!hci_conn_sc_enabled(conn) ||
!test_bit(HCI_CONN_AES_CCM, &conn->flags) || !test_bit(HCI_CONN_AES_CCM, &conn->flags) ||
conn->key_type != HCI_LK_AUTH_COMBINATION_P256) conn->key_type != HCI_LK_AUTH_COMBINATION_P256)
......
This diff is collapsed.
...@@ -247,7 +247,7 @@ static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf, ...@@ -247,7 +247,7 @@ static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf,
struct hci_dev *hdev = file->private_data; struct hci_dev *hdev = file->private_data;
char buf[3]; char buf[3];
buf[0] = test_bit(HCI_USE_DEBUG_KEYS, &hdev->dev_flags) ? 'Y': 'N'; buf[0] = hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS) ? 'Y': 'N';
buf[1] = '\n'; buf[1] = '\n';
buf[2] = '\0'; buf[2] = '\0';
return simple_read_from_buffer(user_buf, count, ppos, buf, 2); return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
...@@ -265,7 +265,7 @@ static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf, ...@@ -265,7 +265,7 @@ static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf,
struct hci_dev *hdev = file->private_data; struct hci_dev *hdev = file->private_data;
char buf[3]; char buf[3];
buf[0] = test_bit(HCI_SC_ONLY, &hdev->dev_flags) ? 'Y': 'N'; buf[0] = hci_dev_test_flag(hdev, HCI_SC_ONLY) ? 'Y': 'N';
buf[1] = '\n'; buf[1] = '\n';
buf[2] = '\0'; buf[2] = '\0';
return simple_read_from_buffer(user_buf, count, ppos, buf, 2); return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
......
This diff is collapsed.
...@@ -270,7 +270,7 @@ void hci_req_add_le_passive_scan(struct hci_request *req) ...@@ -270,7 +270,7 @@ void hci_req_add_le_passive_scan(struct hci_request *req)
* and 0x01 (whitelist enabled) use the new filter policies * and 0x01 (whitelist enabled) use the new filter policies
* 0x02 (no whitelist) and 0x03 (whitelist enabled). * 0x02 (no whitelist) and 0x03 (whitelist enabled).
*/ */
if (test_bit(HCI_PRIVACY, &hdev->dev_flags) && if (hci_dev_test_flag(hdev, HCI_PRIVACY) &&
(hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY))
filter_policy |= 0x02; filter_policy |= 0x02;
...@@ -304,7 +304,7 @@ static void set_random_addr(struct hci_request *req, bdaddr_t *rpa) ...@@ -304,7 +304,7 @@ static void set_random_addr(struct hci_request *req, bdaddr_t *rpa)
* In this kind of scenario skip the update and let the random * In this kind of scenario skip the update and let the random
* address be updated at the next cycle. * address be updated at the next cycle.
*/ */
if (test_bit(HCI_LE_ADV, &hdev->dev_flags) || if (hci_dev_test_flag(hdev, HCI_LE_ADV) ||
hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT)) { hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT)) {
BT_DBG("Deferring random address update"); BT_DBG("Deferring random address update");
set_bit(HCI_RPA_EXPIRED, &hdev->dev_flags); set_bit(HCI_RPA_EXPIRED, &hdev->dev_flags);
...@@ -324,7 +324,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, ...@@ -324,7 +324,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
* current RPA has expired or there is something else than * current RPA has expired or there is something else than
* the current RPA in use, then generate a new one. * the current RPA in use, then generate a new one.
*/ */
if (test_bit(HCI_PRIVACY, &hdev->dev_flags)) { if (hci_dev_test_flag(hdev, HCI_PRIVACY)) {
int to; int to;
*own_addr_type = ADDR_LE_DEV_RANDOM; *own_addr_type = ADDR_LE_DEV_RANDOM;
...@@ -385,7 +385,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, ...@@ -385,7 +385,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
*/ */
if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags) || if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags) ||
!bacmp(&hdev->bdaddr, BDADDR_ANY) || !bacmp(&hdev->bdaddr, BDADDR_ANY) ||
(!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags) && (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) &&
bacmp(&hdev->static_addr, BDADDR_ANY))) { bacmp(&hdev->static_addr, BDADDR_ANY))) {
*own_addr_type = ADDR_LE_DEV_RANDOM; *own_addr_type = ADDR_LE_DEV_RANDOM;
if (bacmp(&hdev->static_addr, &hdev->random_addr)) if (bacmp(&hdev->static_addr, &hdev->random_addr))
...@@ -425,7 +425,7 @@ void __hci_update_page_scan(struct hci_request *req) ...@@ -425,7 +425,7 @@ void __hci_update_page_scan(struct hci_request *req)
struct hci_dev *hdev = req->hdev; struct hci_dev *hdev = req->hdev;
u8 scan; u8 scan;
if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
return; return;
if (!hdev_is_powered(hdev)) if (!hdev_is_powered(hdev))
...@@ -434,7 +434,7 @@ void __hci_update_page_scan(struct hci_request *req) ...@@ -434,7 +434,7 @@ void __hci_update_page_scan(struct hci_request *req)
if (mgmt_powering_down(hdev)) if (mgmt_powering_down(hdev))
return; return;
if (test_bit(HCI_CONNECTABLE, &hdev->dev_flags) || if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) ||
disconnected_whitelist_entries(hdev)) disconnected_whitelist_entries(hdev))
scan = SCAN_PAGE; scan = SCAN_PAGE;
else else
...@@ -443,7 +443,7 @@ void __hci_update_page_scan(struct hci_request *req) ...@@ -443,7 +443,7 @@ void __hci_update_page_scan(struct hci_request *req)
if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE)) if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE))
return; return;
if (test_bit(HCI_DISCOVERABLE, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE))
scan |= SCAN_INQUIRY; scan |= SCAN_INQUIRY;
hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
...@@ -471,14 +471,14 @@ void __hci_update_background_scan(struct hci_request *req) ...@@ -471,14 +471,14 @@ void __hci_update_background_scan(struct hci_request *req)
if (!test_bit(HCI_UP, &hdev->flags) || if (!test_bit(HCI_UP, &hdev->flags) ||
test_bit(HCI_INIT, &hdev->flags) || test_bit(HCI_INIT, &hdev->flags) ||
test_bit(HCI_SETUP, &hdev->dev_flags) || hci_dev_test_flag(hdev, HCI_SETUP) ||
test_bit(HCI_CONFIG, &hdev->dev_flags) || hci_dev_test_flag(hdev, HCI_CONFIG) ||
test_bit(HCI_AUTO_OFF, &hdev->dev_flags) || hci_dev_test_flag(hdev, HCI_AUTO_OFF) ||
test_bit(HCI_UNREGISTER, &hdev->dev_flags)) hci_dev_test_flag(hdev, HCI_UNREGISTER))
return; return;
/* No point in doing scanning if LE support hasn't been enabled */ /* No point in doing scanning if LE support hasn't been enabled */
if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED))
return; return;
/* If discovery is active don't interfere with it */ /* If discovery is active don't interfere with it */
...@@ -502,7 +502,7 @@ void __hci_update_background_scan(struct hci_request *req) ...@@ -502,7 +502,7 @@ void __hci_update_background_scan(struct hci_request *req)
*/ */
/* If controller is not scanning we are done. */ /* If controller is not scanning we are done. */
if (!test_bit(HCI_LE_SCAN, &hdev->dev_flags)) if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
return; return;
hci_req_add_le_scan_disable(req); hci_req_add_le_scan_disable(req);
...@@ -524,7 +524,7 @@ void __hci_update_background_scan(struct hci_request *req) ...@@ -524,7 +524,7 @@ void __hci_update_background_scan(struct hci_request *req)
/* If controller is currently scanning, we stop it to ensure we /* If controller is currently scanning, we stop it to ensure we
* don't miss any advertising (due to duplicates filter). * don't miss any advertising (due to duplicates filter).
*/ */
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_LE_SCAN))
hci_req_add_le_scan_disable(req); hci_req_add_le_scan_disable(req);
hci_req_add_le_passive_scan(req); hci_req_add_le_passive_scan(req);
......
...@@ -534,10 +534,10 @@ static int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd, ...@@ -534,10 +534,10 @@ static int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd,
if (!hdev) if (!hdev)
return -EBADFD; return -EBADFD;
if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL))
return -EBUSY; return -EBUSY;
if (test_bit(HCI_UNCONFIGURED, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (hdev->dev_type != HCI_BREDR) if (hdev->dev_type != HCI_BREDR)
...@@ -713,8 +713,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -713,8 +713,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
if (test_bit(HCI_UP, &hdev->flags) || if (test_bit(HCI_UP, &hdev->flags) ||
test_bit(HCI_INIT, &hdev->flags) || test_bit(HCI_INIT, &hdev->flags) ||
test_bit(HCI_SETUP, &hdev->dev_flags) || hci_dev_test_flag(hdev, HCI_SETUP) ||
test_bit(HCI_CONFIG, &hdev->dev_flags)) { hci_dev_test_flag(hdev, HCI_CONFIG)) {
err = -EBUSY; err = -EBUSY;
hci_dev_put(hdev); hci_dev_put(hdev);
goto done; goto done;
......
...@@ -3900,7 +3900,7 @@ static int l2cap_connect_req(struct l2cap_conn *conn, ...@@ -3900,7 +3900,7 @@ static int l2cap_connect_req(struct l2cap_conn *conn,
return -EPROTO; return -EPROTO;
hci_dev_lock(hdev); hci_dev_lock(hdev);
if (test_bit(HCI_MGMT, &hdev->dev_flags) && if (hci_dev_test_flag(hdev, HCI_MGMT) &&
!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags)) !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags))
mgmt_device_connected(hdev, hcon, 0, NULL, 0); mgmt_device_connected(hdev, hcon, 0, NULL, 0);
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
...@@ -6987,10 +6987,10 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon) ...@@ -6987,10 +6987,10 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
conn->local_fixed_chan = L2CAP_FC_SIG_BREDR | L2CAP_FC_CONNLESS; conn->local_fixed_chan = L2CAP_FC_SIG_BREDR | L2CAP_FC_CONNLESS;
if (hcon->type == ACL_LINK && if (hcon->type == ACL_LINK &&
test_bit(HCI_HS_ENABLED, &hcon->hdev->dev_flags)) hci_dev_test_flag(hcon->hdev, HCI_HS_ENABLED))
conn->local_fixed_chan |= L2CAP_FC_A2MP; conn->local_fixed_chan |= L2CAP_FC_A2MP;
if (test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags) && if (hci_dev_test_flag(hcon->hdev, HCI_LE_ENABLED) &&
(bredr_sc_enabled(hcon->hdev) || (bredr_sc_enabled(hcon->hdev) ||
test_bit(HCI_FORCE_BREDR_SMP, &hcon->hdev->dbg_flags))) test_bit(HCI_FORCE_BREDR_SMP, &hcon->hdev->dbg_flags)))
conn->local_fixed_chan |= L2CAP_FC_SMP_BREDR; conn->local_fixed_chan |= L2CAP_FC_SMP_BREDR;
...@@ -7112,7 +7112,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, ...@@ -7112,7 +7112,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
else else
dst_type = ADDR_LE_DEV_RANDOM; dst_type = ADDR_LE_DEV_RANDOM;
if (test_bit(HCI_ADVERTISING, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
role = HCI_ROLE_SLAVE; role = HCI_ROLE_SLAVE;
else else
role = HCI_ROLE_MASTER; role = HCI_ROLE_MASTER;
......
This diff is collapsed.
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#define SMP_TIMEOUT msecs_to_jiffies(30000) #define SMP_TIMEOUT msecs_to_jiffies(30000)
#define AUTH_REQ_MASK(dev) (test_bit(HCI_SC_ENABLED, &(dev)->dev_flags) ? \ #define AUTH_REQ_MASK(dev) (hci_dev_test_flag(dev, HCI_SC_ENABLED) ? \
0x1f : 0x07) 0x1f : 0x07)
#define KEY_DIST_MASK 0x07 #define KEY_DIST_MASK 0x07
...@@ -589,7 +589,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn, ...@@ -589,7 +589,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn,
struct hci_dev *hdev = hcon->hdev; struct hci_dev *hdev = hcon->hdev;
u8 local_dist = 0, remote_dist = 0, oob_flag = SMP_OOB_NOT_PRESENT; u8 local_dist = 0, remote_dist = 0, oob_flag = SMP_OOB_NOT_PRESENT;
if (test_bit(HCI_BONDABLE, &conn->hcon->hdev->dev_flags)) { if (hci_dev_test_flag(hdev, HCI_BONDABLE)) {
local_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN; local_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN;
remote_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN; remote_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN;
authreq |= SMP_AUTH_BONDING; authreq |= SMP_AUTH_BONDING;
...@@ -597,18 +597,18 @@ static void build_pairing_cmd(struct l2cap_conn *conn, ...@@ -597,18 +597,18 @@ static void build_pairing_cmd(struct l2cap_conn *conn,
authreq &= ~SMP_AUTH_BONDING; authreq &= ~SMP_AUTH_BONDING;
} }
if (test_bit(HCI_RPA_RESOLVING, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_RPA_RESOLVING))
remote_dist |= SMP_DIST_ID_KEY; remote_dist |= SMP_DIST_ID_KEY;
if (test_bit(HCI_PRIVACY, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_PRIVACY))
local_dist |= SMP_DIST_ID_KEY; local_dist |= SMP_DIST_ID_KEY;
if (test_bit(HCI_SC_ENABLED, &hdev->dev_flags) && if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
(authreq & SMP_AUTH_SC)) { (authreq & SMP_AUTH_SC)) {
struct oob_data *oob_data; struct oob_data *oob_data;
u8 bdaddr_type; u8 bdaddr_type;
if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) { if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) {
local_dist |= SMP_DIST_LINK_KEY; local_dist |= SMP_DIST_LINK_KEY;
remote_dist |= SMP_DIST_LINK_KEY; remote_dist |= SMP_DIST_LINK_KEY;
} }
...@@ -692,7 +692,7 @@ static void smp_chan_destroy(struct l2cap_conn *conn) ...@@ -692,7 +692,7 @@ static void smp_chan_destroy(struct l2cap_conn *conn)
* support hasn't been explicitly enabled. * support hasn't been explicitly enabled.
*/ */
if (smp->ltk && smp->ltk->type == SMP_LTK_P256_DEBUG && if (smp->ltk && smp->ltk->type == SMP_LTK_P256_DEBUG &&
!test_bit(HCI_KEEP_DEBUG_KEYS, &hcon->hdev->dev_flags)) { !hci_dev_test_flag(hcon->hdev, HCI_KEEP_DEBUG_KEYS)) {
list_del_rcu(&smp->ltk->list); list_del_rcu(&smp->ltk->list);
kfree_rcu(smp->ltk, rcu); kfree_rcu(smp->ltk, rcu);
smp->ltk = NULL; smp->ltk = NULL;
...@@ -1052,7 +1052,7 @@ static void smp_notify_keys(struct l2cap_conn *conn) ...@@ -1052,7 +1052,7 @@ static void smp_notify_keys(struct l2cap_conn *conn)
/* Don't keep debug keys around if the relevant /* Don't keep debug keys around if the relevant
* flag is not set. * flag is not set.
*/ */
if (!test_bit(HCI_KEEP_DEBUG_KEYS, &hdev->dev_flags) && if (!hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS) &&
key->type == HCI_LK_DEBUG_COMBINATION) { key->type == HCI_LK_DEBUG_COMBINATION) {
list_del_rcu(&key->list); list_del_rcu(&key->list);
kfree_rcu(key, rcu); kfree_rcu(key, rcu);
...@@ -1604,15 +1604,15 @@ static void build_bredr_pairing_cmd(struct smp_chan *smp, ...@@ -1604,15 +1604,15 @@ static void build_bredr_pairing_cmd(struct smp_chan *smp,
struct hci_dev *hdev = conn->hcon->hdev; struct hci_dev *hdev = conn->hcon->hdev;
u8 local_dist = 0, remote_dist = 0; u8 local_dist = 0, remote_dist = 0;
if (test_bit(HCI_BONDABLE, &hdev->dev_flags)) { if (hci_dev_test_flag(hdev, HCI_BONDABLE)) {
local_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN; local_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN;
remote_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN; remote_dist = SMP_DIST_ENC_KEY | SMP_DIST_SIGN;
} }
if (test_bit(HCI_RPA_RESOLVING, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_RPA_RESOLVING))
remote_dist |= SMP_DIST_ID_KEY; remote_dist |= SMP_DIST_ID_KEY;
if (test_bit(HCI_PRIVACY, &hdev->dev_flags)) if (hci_dev_test_flag(hdev, HCI_PRIVACY))
local_dist |= SMP_DIST_ID_KEY; local_dist |= SMP_DIST_ID_KEY;
if (!rsp) { if (!rsp) {
...@@ -1664,11 +1664,11 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -1664,11 +1664,11 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
/* We didn't start the pairing, so match remote */ /* We didn't start the pairing, so match remote */
auth = req->auth_req & AUTH_REQ_MASK(hdev); auth = req->auth_req & AUTH_REQ_MASK(hdev);
if (!test_bit(HCI_BONDABLE, &hdev->dev_flags) && if (!hci_dev_test_flag(hdev, HCI_BONDABLE) &&
(auth & SMP_AUTH_BONDING)) (auth & SMP_AUTH_BONDING))
return SMP_PAIRING_NOTSUPP; return SMP_PAIRING_NOTSUPP;
if (test_bit(HCI_SC_ONLY, &hdev->dev_flags) && !(auth & SMP_AUTH_SC)) if (hci_dev_test_flag(hdev, HCI_SC_ONLY) && !(auth & SMP_AUTH_SC))
return SMP_AUTH_REQUIREMENTS; return SMP_AUTH_REQUIREMENTS;
smp->preq[0] = SMP_CMD_PAIRING_REQ; smp->preq[0] = SMP_CMD_PAIRING_REQ;
...@@ -1761,7 +1761,7 @@ static u8 sc_send_public_key(struct smp_chan *smp) ...@@ -1761,7 +1761,7 @@ static u8 sc_send_public_key(struct smp_chan *smp)
BT_DBG(""); BT_DBG("");
if (test_bit(HCI_USE_DEBUG_KEYS, &hdev->dev_flags)) { if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) {
BT_DBG("Using debug keys"); BT_DBG("Using debug keys");
memcpy(smp->local_pk, debug_pk, 64); memcpy(smp->local_pk, debug_pk, 64);
memcpy(smp->local_sk, debug_sk, 32); memcpy(smp->local_sk, debug_sk, 32);
...@@ -1816,7 +1816,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -1816,7 +1816,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
auth = rsp->auth_req & AUTH_REQ_MASK(hdev); auth = rsp->auth_req & AUTH_REQ_MASK(hdev);
if (test_bit(HCI_SC_ONLY, &hdev->dev_flags) && !(auth & SMP_AUTH_SC)) if (hci_dev_test_flag(hdev, HCI_SC_ONLY) && !(auth & SMP_AUTH_SC))
return SMP_AUTH_REQUIREMENTS; return SMP_AUTH_REQUIREMENTS;
smp->prsp[0] = SMP_CMD_PAIRING_RSP; smp->prsp[0] = SMP_CMD_PAIRING_RSP;
...@@ -2086,7 +2086,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -2086,7 +2086,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
auth = rp->auth_req & AUTH_REQ_MASK(hdev); auth = rp->auth_req & AUTH_REQ_MASK(hdev);
if (test_bit(HCI_SC_ONLY, &hdev->dev_flags) && !(auth & SMP_AUTH_SC)) if (hci_dev_test_flag(hdev, HCI_SC_ONLY) && !(auth & SMP_AUTH_SC))
return SMP_AUTH_REQUIREMENTS; return SMP_AUTH_REQUIREMENTS;
if (hcon->io_capability == HCI_IO_NO_INPUT_OUTPUT) if (hcon->io_capability == HCI_IO_NO_INPUT_OUTPUT)
...@@ -2107,7 +2107,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -2107,7 +2107,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
if (!smp) if (!smp)
return SMP_UNSPECIFIED; return SMP_UNSPECIFIED;
if (!test_bit(HCI_BONDABLE, &hcon->hdev->dev_flags) && if (!hci_dev_test_flag(hdev, HCI_BONDABLE) &&
(auth & SMP_AUTH_BONDING)) (auth & SMP_AUTH_BONDING))
return SMP_PAIRING_NOTSUPP; return SMP_PAIRING_NOTSUPP;
...@@ -2141,7 +2141,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level) ...@@ -2141,7 +2141,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
chan = conn->smp; chan = conn->smp;
if (!test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags)) if (!hci_dev_test_flag(hcon->hdev, HCI_LE_ENABLED))
return 1; return 1;
if (smp_sufficient_security(hcon, sec_level, SMP_USE_LTK)) if (smp_sufficient_security(hcon, sec_level, SMP_USE_LTK))
...@@ -2170,7 +2170,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level) ...@@ -2170,7 +2170,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
authreq = seclevel_to_authreq(sec_level); authreq = seclevel_to_authreq(sec_level);
if (test_bit(HCI_SC_ENABLED, &hcon->hdev->dev_flags)) if (hci_dev_test_flag(hcon->hdev, HCI_SC_ENABLED))
authreq |= SMP_AUTH_SC; authreq |= SMP_AUTH_SC;
/* Require MITM if IO Capability allows or the security level /* Require MITM if IO Capability allows or the security level
...@@ -2606,7 +2606,7 @@ static int smp_sig_channel(struct l2cap_chan *chan, struct sk_buff *skb) ...@@ -2606,7 +2606,7 @@ static int smp_sig_channel(struct l2cap_chan *chan, struct sk_buff *skb)
if (skb->len < 1) if (skb->len < 1)
return -EILSEQ; return -EILSEQ;
if (!test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags)) { if (!hci_dev_test_flag(hcon->hdev, HCI_LE_ENABLED)) {
reason = SMP_PAIRING_NOTSUPP; reason = SMP_PAIRING_NOTSUPP;
goto done; goto done;
} }
...@@ -2744,7 +2744,7 @@ static void bredr_pairing(struct l2cap_chan *chan) ...@@ -2744,7 +2744,7 @@ static void bredr_pairing(struct l2cap_chan *chan)
return; return;
/* Secure Connections support must be enabled */ /* Secure Connections support must be enabled */
if (!test_bit(HCI_SC_ENABLED, &hdev->dev_flags)) if (!hci_dev_test_flag(hdev, HCI_SC_ENABLED))
return; return;
/* BR/EDR must use Secure Connections for SMP */ /* BR/EDR must use Secure Connections for SMP */
...@@ -2753,7 +2753,7 @@ static void bredr_pairing(struct l2cap_chan *chan) ...@@ -2753,7 +2753,7 @@ static void bredr_pairing(struct l2cap_chan *chan)
return; return;
/* If our LE support is not enabled don't do anything */ /* If our LE support is not enabled don't do anything */
if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED))
return; return;
/* Don't bother if remote LE support is not enabled */ /* Don't bother if remote LE support is not enabled */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment